@vivliostyle/print 2.42.1 → 2.43.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 CHANGED
@@ -1,12 +1,12 @@
1
- var Tf=Object.create;var Ur=Object.defineProperty;var If=Object.getOwnPropertyDescriptor;var Af=Object.getOwnPropertyNames;var Ff=Object.getPrototypeOf,Rf=Object.prototype.hasOwnProperty;var Lf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Of=(e,t)=>{for(var i in t)Ur(e,i,{get:t[i],enumerable:!0})},Vl=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Af(t))!Rf.call(e,r)&&r!==i&&Ur(e,r,{get:()=>t[r],enumerable:!(n=If(t,r))||n.enumerable});return e};var Bf=(e,t,i)=>(i=e!=null?Tf(Ff(e)):{},Vl(t||!e||!e.__esModule?Ur(i,"default",{value:e,enumerable:!0}):i,e)),Mf=e=>Vl(Ur({},"__esModule",{value:!0}),e);var Cf=Lf((tS,Sf)=>{"use strict";var _f=Object.create,Cr=Object.defineProperty,Df=Object.getOwnPropertyDescriptor,zf=Object.getOwnPropertyNames,Vf=Object.getPrototypeOf,Uf=Object.prototype.hasOwnProperty,ku=e=>{throw TypeError(e)},$f=(e,t,i)=>t in e?Cr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Wf=(e,t)=>{for(var i in t)Cr(e,i,{get:t[i],enumerable:!0})},Eu=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of zf(t))!Uf.call(e,r)&&r!==i&&Cr(e,r,{get:()=>t[r],enumerable:!(n=Df(t,r))||n.enumerable});return e},Gf=(e,t,i)=>(i=e!=null?_f(Vf(e)):{},Eu(t||!e||!e.__esModule?Cr(i,"default",{value:e,enumerable:!0}):i,e)),jf=e=>Eu(Cr({},"__esModule",{value:!0}),e),c=(e,t,i)=>$f(e,typeof t!="symbol"?t+"":t,i),Ha=(e,t,i)=>t.has(e)||ku("Cannot "+i),$=(e,t,i)=>(Ha(e,t,"read from private field"),i?i.call(e):t.get(e)),ie=(e,t,i)=>t.has(e)?ku("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Ve=(e,t,i,n)=>(Ha(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ne=(e,t,i)=>(Ha(e,t,"access private method"),i),Xf=Hf((e,t)=>{var i=-1,n=1,r=0;function o(k,_,E,L,P){if(k===_)return k?[[r,k]]:[];if(E!=null){var A=he(k,_,E);if(A)return A}var O=l(k,_),z=k.substring(0,O);k=k.substring(O),_=_.substring(O),O=d(k,_);var W=k.substring(k.length-O);k=k.substring(0,k.length-O),_=_.substring(0,_.length-O);var K=s(k,_);return z&&K.unshift([r,z]),W&&K.push([r,W]),S(K,P),L&&f(K),K}function s(k,_){var E;if(!k)return[[n,_]];if(!_)return[[i,k]];var L=k.length>_.length?k:_,P=k.length>_.length?_:k,A=L.indexOf(P);if(A!==-1)return E=[[n,L.substring(0,A)],[r,P],[n,L.substring(A+P.length)]],k.length>_.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,_]];var O=p(k,_);if(O){var z=O[0],W=O[1],K=O[2],Q=O[3],ee=O[4],pe=o(z,K),re=o(W,Q);return pe.concat([[r,ee]],re)}return a(k,_)}function a(k,_){for(var E=k.length,L=_.length,P=Math.ceil((E+L)/2),A=P,O=2*P,z=new Array(O),W=new Array(O),K=0;K<O;K++)z[K]=-1,W[K]=-1;z[A+1]=0,W[A+1]=0;for(var Q=E-L,ee=Q%2!==0,pe=0,re=0,se=0,Me=0,Oe=0;Oe<P;Oe++){for(var fe=-Oe+pe;fe<=Oe-re;fe+=2){var Ee=A+fe,we;fe===-Oe||fe!==Oe&&z[Ee-1]<z[Ee+1]?we=z[Ee+1]:we=z[Ee-1]+1;for(var ue=we-fe;we<E&&ue<L&&k.charAt(we)===_.charAt(ue);)we++,ue++;if(z[Ee]=we,we>E)re+=2;else if(ue>L)pe+=2;else if(ee){var Pe=A+Q-fe;if(Pe>=0&&Pe<O&&W[Pe]!==-1){var ye=E-W[Pe];if(we>=ye)return h(k,_,we,ue)}}}for(var Se=-Oe+se;Se<=Oe-Me;Se+=2){var Pe=A+Se,ye;Se===-Oe||Se!==Oe&&W[Pe-1]<W[Pe+1]?ye=W[Pe+1]:ye=W[Pe-1]+1;for(var ne=ye-Se;ye<E&&ne<L&&k.charAt(E-ye-1)===_.charAt(L-ne-1);)ye++,ne++;if(W[Pe]=ye,ye>E)Me+=2;else if(ne>L)se+=2;else if(!ee){var Ee=A+Q-Se;if(Ee>=0&&Ee<O&&z[Ee]!==-1){var we=z[Ee],ue=A+we-Ee;if(ye=E-ye,we>=ye)return h(k,_,we,ue)}}}}return[[i,k],[n,_]]}function h(k,_,E,L){var P=k.substring(0,E),A=_.substring(0,L),O=k.substring(E),z=_.substring(L),W=o(P,A),K=o(O,z);return W.concat(K)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var E=0,L=Math.min(k.length,_.length),P=L,A=0;E<P;)k.substring(A,P)==_.substring(A,P)?(E=P,A=E):L=P,P=Math.floor((L-E)/2+E);return C(k.charCodeAt(P-1))&&P--,P}function u(k,_){var E=k.length,L=_.length;if(E==0||L==0)return 0;E>L?k=k.substring(E-L):E<L&&(_=_.substring(0,E));var P=Math.min(E,L);if(k==_)return P;for(var A=0,O=1;;){var z=k.substring(P-O),W=_.indexOf(z);if(W==-1)return A;O+=W,(W==0||k.substring(P-O)==_.substring(0,O))&&(A=O,O++)}}function d(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var E=0,L=Math.min(k.length,_.length),P=L,A=0;E<P;)k.substring(k.length-P,k.length-A)==_.substring(_.length-P,_.length-A)?(E=P,A=E):L=P,P=Math.floor((L-E)/2+E);return N(k.charCodeAt(k.length-P))&&P--,P}function p(k,_){var E=k.length>_.length?k:_,L=k.length>_.length?_:k;if(E.length<4||L.length*2<E.length)return null;function P(re,se,Me){for(var Oe=re.substring(Me,Me+Math.floor(re.length/4)),fe=-1,Ee="",we,ue,Pe,ye;(fe=se.indexOf(Oe,fe+1))!==-1;){var Se=l(re.substring(Me),se.substring(fe)),ne=d(re.substring(0,Me),se.substring(0,fe));Ee.length<ne+Se&&(Ee=se.substring(fe-ne,fe)+se.substring(fe,fe+Se),we=re.substring(0,Me-ne),ue=re.substring(Me+Se),Pe=se.substring(0,fe-ne),ye=se.substring(fe+Se))}return Ee.length*2>=re.length?[we,ue,Pe,ye,Ee]:null}var A=P(E,L,Math.ceil(E.length/4)),O=P(E,L,Math.ceil(E.length/2)),z;if(!A&&!O)return null;O?A?z=A[4].length>O[4].length?A:O:z=O:z=A;var W,K,Q,ee;k.length>_.length?(W=z[0],K=z[1],Q=z[2],ee=z[3]):(Q=z[0],ee=z[1],W=z[2],K=z[3]);var pe=z[4];return[W,K,Q,ee,pe]}function f(k){for(var _=!1,E=[],L=0,P=null,A=0,O=0,z=0,W=0,K=0;A<k.length;)k[A][0]==r?(E[L++]=A,O=W,z=K,W=0,K=0,P=k[A][1]):(k[A][0]==n?W+=k[A][1].length:K+=k[A][1].length,P&&P.length<=Math.max(O,z)&&P.length<=Math.max(W,K)&&(k.splice(E[L-1],0,[i,P]),k[E[L-1]+1][0]=n,L--,L--,A=L>0?E[L-1]:-1,O=0,z=0,W=0,K=0,P=null,_=!0)),A++;for(_&&S(k),b(k),A=1;A<k.length;){if(k[A-1][0]==i&&k[A][0]==n){var Q=k[A-1][1],ee=k[A][1],pe=u(Q,ee),re=u(ee,Q);pe>=re?(pe>=Q.length/2||pe>=ee.length/2)&&(k.splice(A,0,[r,ee.substring(0,pe)]),k[A-1][1]=Q.substring(0,Q.length-pe),k[A+1][1]=ee.substring(pe),A++):(re>=Q.length/2||re>=ee.length/2)&&(k.splice(A,0,[r,Q.substring(0,re)]),k[A-1][0]=n,k[A-1][1]=ee.substring(0,ee.length-re),k[A+1][0]=i,k[A+1][1]=Q.substring(re),A++),A++}A++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,x=/\n\r?\n$/,y=/^\r?\n\r?\n/;function b(k){function _(re,se){if(!re||!se)return 6;var Me=re.charAt(re.length-1),Oe=se.charAt(0),fe=Me.match(g),Ee=Oe.match(g),we=fe&&Me.match(m),ue=Ee&&Oe.match(m),Pe=we&&Me.match(w),ye=ue&&Oe.match(w),Se=Pe&&re.match(x),ne=ye&&se.match(y);return Se||ne?5:Pe||ye?4:fe&&!we&&ue?3:we||ue?2:fe||Ee?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var L=k[E-1][1],P=k[E][1],A=k[E+1][1],O=d(L,P);if(O){var z=P.substring(P.length-O);L=L.substring(0,L.length-O),P=z+P.substring(0,P.length-O),A=z+A}for(var W=L,K=P,Q=A,ee=_(L,P)+_(P,A);P.charAt(0)===A.charAt(0);){L+=P.charAt(0),P=P.substring(1)+A.charAt(0),A=A.substring(1);var pe=_(L,P)+_(P,A);pe>=ee&&(ee=pe,W=L,K=P,Q=A)}k[E-1][1]!=W&&(W?k[E-1][1]=W:(k.splice(E-1,1),E--),k[E][1]=K,Q?k[E+1][1]=Q:(k.splice(E+1,1),E--))}E++}}function S(k,_){k.push([r,""]);for(var E=0,L=0,P=0,A="",O="",z;E<k.length;){if(E<k.length-1&&!k[E][1]){k.splice(E,1);continue}switch(k[E][0]){case n:P++,O+=k[E][1],E++;break;case i:L++,A+=k[E][1],E++;break;case r:var W=E-P-L-1;if(_){if(W>=0&&B(k[W][1])){var K=k[W][1].slice(-1);if(k[W][1]=k[W][1].slice(0,-1),A=K+A,O=K+O,!k[W][1]){k.splice(W,1),E--;var Q=W-1;k[Q]&&k[Q][0]===n&&(P++,O=k[Q][1]+O,Q--),k[Q]&&k[Q][0]===i&&(L++,A=k[Q][1]+A,Q--),W=Q}}if(F(k[E][1])){var K=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),A+=K,O+=K}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(A.length>0||O.length>0){A.length>0&&O.length>0&&(z=l(O,A),z!==0&&(W>=0?k[W][1]+=O.substring(0,z):(k.splice(0,0,[r,O.substring(0,z)]),E++),O=O.substring(z),A=A.substring(z)),z=d(O,A),z!==0&&(k[E][1]=O.substring(O.length-z)+k[E][1],O=O.substring(0,O.length-z),A=A.substring(0,A.length-z)));var ee=P+L;A.length===0&&O.length===0?(k.splice(E-ee,ee),E=E-ee):A.length===0?(k.splice(E-ee,ee,[n,O]),E=E-ee+1):O.length===0?(k.splice(E-ee,ee,[i,A]),E=E-ee+1):(k.splice(E-ee,ee,[i,A],[n,O]),E=E-ee+2)}E!==0&&k[E-1][0]===r?(k[E-1][1]+=k[E][1],k.splice(E,1)):E++,P=0,L=0,A="",O="";break}}k[k.length-1][1]===""&&k.pop();var pe=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),pe=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),pe=!0)),E++;pe&&S(k,_)}function C(k){return k>=55296&&k<=56319}function N(k){return k>=56320&&k<=57343}function F(k){return N(k.charCodeAt(0))}function B(k){return C(k.charCodeAt(k.length-1))}function U(k){for(var _=[],E=0;E<k.length;E++)k[E][1].length>0&&_.push(k[E]);return _}function q(k,_,E,L){return B(k)||F(L)?null:U([[r,k],[i,_],[n,E],[r,L]])}function he(k,_,E){var L=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,A=k.length,O=_.length;if(L.length===0&&(P===null||P.length===0)){var z=L.index,W=k.slice(0,z),K=k.slice(z),Q=P?P.index:null;e:{var ee=z+O-A;if(Q!==null&&Q!==ee||ee<0||ee>O)break e;var pe=_.slice(0,ee),re=_.slice(ee);if(re!==K)break e;var se=Math.min(z,ee),Me=W.slice(0,se),Oe=pe.slice(0,se);if(Me!==Oe)break e;var fe=W.slice(se),Ee=pe.slice(se);return q(Me,fe,Ee,K)}e:{if(Q!==null&&Q!==z)break e;var we=z,pe=_.slice(0,we),re=_.slice(we);if(pe!==W)break e;var ue=Math.min(A-we,O-we),Pe=K.slice(K.length-ue),ye=re.slice(re.length-ue);if(Pe!==ye)break e;var fe=K.slice(0,K.length-ue),Ee=re.slice(0,re.length-ue);return q(W,fe,Ee,Pe)}}if(L.length>0&&P&&P.length===0)e:{var Me=k.slice(0,L.index),Pe=k.slice(L.index+L.length),se=Me.length,ue=Pe.length;if(O<se+ue)break e;var Oe=_.slice(0,se),ye=_.slice(O-ue);if(Me!==Oe||Pe!==ye)break e;var fe=k.slice(se,A-ue),Ee=_.slice(se,O-ue);return q(Me,fe,Ee,Pe)}return null}function ae(k,_,E,L){return o(k,_,E,L,!0)}ae.INSERT=n,ae.DELETE=i,ae.EQUAL=r,t.exports=ae}),Pu={};Wf(Pu,{CoreViewer:()=>bf,HOOKS:()=>Yo,Navigation:()=>xf,PageProgression:()=>Wa,PageSide:()=>Iu,PageViewMode:()=>Vx,Profiler:()=>Lu,ReadyState:()=>Au,UserAgentBaseCss:()=>Uc,UserAgentCounterStylesCss:()=>Wc,UserAgentPageCss:()=>Vc,UserAgentTocCss:()=>$c,UserAgentXml:()=>zc,ValidationTxt:()=>Dc,VivliostylePolyfillCss:()=>Hc,VivliostyleViewportCss:()=>_c,VivliostyleViewportScreenCss:()=>Mc,ZoomType:()=>zx,getHooksForName:()=>Dt,isDebug:()=>dr,pageProgressionOf:()=>Tu,plugin:()=>Yf,printHTML:()=>$x,profile:()=>Qf,profiler:()=>xt,registerHook:()=>At,removeHook:()=>Ru,setDebug:()=>Nu});Sf.exports=jf(Pu);var dr=!1;function Nu(e){dr=e}var Wa=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Wa||{});function Tu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Iu=(e=>(e.LEFT="left",e.RIGHT="right",e))(Iu||{}),Au=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Au||{}),Fu=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Fu||{}),qf=class{constructor(e){this.opt_console=e,c(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=$r(arguments);this.consoleDebug(Hr(t)),this.triggerListeners(1,t)}info(...e){let t=$r(arguments);this.consoleInfo(Hr(t)),this.triggerListeners(2,t)}warn(...e){let t=$r(arguments);this.consoleWarn(Hr(t)),this.triggerListeners(3,t)}error(...e){let t=$r(arguments);this.consoleError(Hr(t)),this.triggerListeners(4,t)}};function $r(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Hr(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ var cg=Object.create;var Kr=Object.defineProperty;var dg=Object.getOwnPropertyDescriptor;var pg=Object.getOwnPropertyNames;var fg=Object.getPrototypeOf,gg=Object.prototype.hasOwnProperty;var mg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wg=(e,t)=>{for(var i in t)Kr(e,i,{get:t[i],enumerable:!0})},uh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of pg(t))!gg.call(e,r)&&r!==i&&Kr(e,r,{get:()=>t[r],enumerable:!(n=dg(t,r))||n.enumerable});return e};var yg=(e,t,i)=>(i=e!=null?cg(fg(e)):{},uh(t||!e||!e.__esModule?Kr(i,"default",{value:e,enumerable:!0}):i,e)),vg=e=>uh(Kr({},"__esModule",{value:!0}),e);var sg=mg((GS,og)=>{"use strict";var bg=Object.create,Lr=Object.defineProperty,xg=Object.getOwnPropertyDescriptor,Sg=Object.getOwnPropertyNames,Cg=Object.getPrototypeOf,kg=Object.prototype.hasOwnProperty,Ku=e=>{throw TypeError(e)},Eg=(e,t,i)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Pg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ng=(e,t)=>{for(var i in t)Lr(e,i,{get:t[i],enumerable:!0})},Ju=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Sg(t))!kg.call(e,r)&&r!==i&&Lr(e,r,{get:()=>t[r],enumerable:!(n=xg(t,r))||n.enumerable});return e},Tg=(e,t,i)=>(i=e!=null?bg(Cg(e)):{},Ju(t||!e||!e.__esModule?Lr(i,"default",{value:e,enumerable:!0}):i,e)),Ig=e=>Ju(Lr({},"__esModule",{value:!0}),e),d=(e,t,i)=>Eg(e,typeof t!="symbol"?t+"":t,i),hl=(e,t,i)=>t.has(e)||Ku("Cannot "+i),U=(e,t,i)=>(hl(e,t,"read from private field"),i?i.call(e):t.get(e)),ee=(e,t,i)=>t.has(e)?Ku("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),fe=(e,t,i,n)=>(hl(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),se=(e,t,i)=>(hl(e,t,"access private method"),i),Ag=Pg((e,t)=>{var i=-1,n=1,r=0;function o(k,_,E,O,P){if(k===_)return k?[[r,k]]:[];if(E!=null){var A=ue(k,_,E);if(A)return A}var B=l(k,_),z=k.substring(0,B);k=k.substring(B),_=_.substring(B),B=c(k,_);var W=k.substring(k.length-B);k=k.substring(0,k.length-B),_=_.substring(0,_.length-B);var Z=s(k,_);return z&&Z.unshift([r,z]),W&&Z.push([r,W]),x(Z,P),O&&f(Z),Z}function s(k,_){var E;if(!k)return[[n,_]];if(!_)return[[i,k]];var O=k.length>_.length?k:_,P=k.length>_.length?_:k,A=O.indexOf(P);if(A!==-1)return E=[[n,O.substring(0,A)],[r,P],[n,O.substring(A+P.length)]],k.length>_.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,_]];var B=p(k,_);if(B){var z=B[0],W=B[1],Z=B[2],K=B[3],J=B[4],me=o(z,Z),re=o(W,K);return me.concat([[r,J]],re)}return a(k,_)}function a(k,_){for(var E=k.length,O=_.length,P=Math.ceil((E+O)/2),A=P,B=2*P,z=new Array(B),W=new Array(B),Z=0;Z<B;Z++)z[Z]=-1,W[Z]=-1;z[A+1]=0,W[A+1]=0;for(var K=E-O,J=K%2!==0,me=0,re=0,le=0,De=0,Me=0;Me<P;Me++){for(var we=-Me+me;we<=Me-re;we+=2){var Ne=A+we,ve;we===-Me||we!==Me&&z[Ne-1]<z[Ne+1]?ve=z[Ne+1]:ve=z[Ne-1]+1;for(var ce=ve-we;ve<E&&ce<O&&k.charAt(ve)===_.charAt(ce);)ve++,ce++;if(z[Ne]=ve,ve>E)re+=2;else if(ce>O)me+=2;else if(J){var Te=A+K-we;if(Te>=0&&Te<B&&W[Te]!==-1){var be=E-W[Te];if(ve>=be)return h(k,_,ve,ce)}}}for(var ke=-Me+le;ke<=Me-De;ke+=2){var Te=A+ke,be;ke===-Me||ke!==Me&&W[Te-1]<W[Te+1]?be=W[Te+1]:be=W[Te-1]+1;for(var ne=be-ke;be<E&&ne<O&&k.charAt(E-be-1)===_.charAt(O-ne-1);)be++,ne++;if(W[Te]=be,be>E)De+=2;else if(ne>O)le+=2;else if(!J){var Ne=A+K-ke;if(Ne>=0&&Ne<B&&z[Ne]!==-1){var ve=z[Ne],ce=A+ve-Ne;if(be=E-be,ve>=be)return h(k,_,ve,ce)}}}}return[[i,k],[n,_]]}function h(k,_,E,O){var P=k.substring(0,E),A=_.substring(0,O),B=k.substring(E),z=_.substring(O),W=o(P,A),Z=o(B,z);return W.concat(Z)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var E=0,O=Math.min(k.length,_.length),P=O,A=0;E<P;)k.substring(A,P)==_.substring(A,P)?(E=P,A=E):O=P,P=Math.floor((O-E)/2+E);return C(k.charCodeAt(P-1))&&P--,P}function u(k,_){var E=k.length,O=_.length;if(E==0||O==0)return 0;E>O?k=k.substring(E-O):E<O&&(_=_.substring(0,E));var P=Math.min(E,O);if(k==_)return P;for(var A=0,B=1;;){var z=k.substring(P-B),W=_.indexOf(z);if(W==-1)return A;B+=W,(W==0||k.substring(P-B)==_.substring(0,B))&&(A=B,B++)}}function c(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var E=0,O=Math.min(k.length,_.length),P=O,A=0;E<P;)k.substring(k.length-P,k.length-A)==_.substring(_.length-P,_.length-A)?(E=P,A=E):O=P,P=Math.floor((O-E)/2+E);return N(k.charCodeAt(k.length-P))&&P--,P}function p(k,_){var E=k.length>_.length?k:_,O=k.length>_.length?_:k;if(E.length<4||O.length*2<E.length)return null;function P(re,le,De){for(var Me=re.substring(De,De+Math.floor(re.length/4)),we=-1,Ne="",ve,ce,Te,be;(we=le.indexOf(Me,we+1))!==-1;){var ke=l(re.substring(De),le.substring(we)),ne=c(re.substring(0,De),le.substring(0,we));Ne.length<ne+ke&&(Ne=le.substring(we-ne,we)+le.substring(we,we+ke),ve=re.substring(0,De-ne),ce=re.substring(De+ke),Te=le.substring(0,we-ne),be=le.substring(we+ke))}return Ne.length*2>=re.length?[ve,ce,Te,be,Ne]:null}var A=P(E,O,Math.ceil(E.length/4)),B=P(E,O,Math.ceil(E.length/2)),z;if(!A&&!B)return null;B?A?z=A[4].length>B[4].length?A:B:z=B:z=A;var W,Z,K,J;k.length>_.length?(W=z[0],Z=z[1],K=z[2],J=z[3]):(K=z[0],J=z[1],W=z[2],Z=z[3]);var me=z[4];return[W,Z,K,J,me]}function f(k){for(var _=!1,E=[],O=0,P=null,A=0,B=0,z=0,W=0,Z=0;A<k.length;)k[A][0]==r?(E[O++]=A,B=W,z=Z,W=0,Z=0,P=k[A][1]):(k[A][0]==n?W+=k[A][1].length:Z+=k[A][1].length,P&&P.length<=Math.max(B,z)&&P.length<=Math.max(W,Z)&&(k.splice(E[O-1],0,[i,P]),k[E[O-1]+1][0]=n,O--,O--,A=O>0?E[O-1]:-1,B=0,z=0,W=0,Z=0,P=null,_=!0)),A++;for(_&&x(k),b(k),A=1;A<k.length;){if(k[A-1][0]==i&&k[A][0]==n){var K=k[A-1][1],J=k[A][1],me=u(K,J),re=u(J,K);me>=re?(me>=K.length/2||me>=J.length/2)&&(k.splice(A,0,[r,J.substring(0,me)]),k[A-1][1]=K.substring(0,K.length-me),k[A+1][1]=J.substring(me),A++):(re>=K.length/2||re>=J.length/2)&&(k.splice(A,0,[r,K.substring(0,re)]),k[A-1][0]=n,k[A-1][1]=J.substring(0,J.length-re),k[A+1][0]=i,k[A+1][1]=K.substring(re),A++),A++}A++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,S=/\n\r?\n$/,v=/^\r?\n\r?\n/;function b(k){function _(re,le){if(!re||!le)return 6;var De=re.charAt(re.length-1),Me=le.charAt(0),we=De.match(g),Ne=Me.match(g),ve=we&&De.match(m),ce=Ne&&Me.match(m),Te=ve&&De.match(w),be=ce&&Me.match(w),ke=Te&&re.match(S),ne=be&&le.match(v);return ke||ne?5:Te||be?4:we&&!ve&&ce?3:ve||ce?2:we||Ne?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var O=k[E-1][1],P=k[E][1],A=k[E+1][1],B=c(O,P);if(B){var z=P.substring(P.length-B);O=O.substring(0,O.length-B),P=z+P.substring(0,P.length-B),A=z+A}for(var W=O,Z=P,K=A,J=_(O,P)+_(P,A);P.charAt(0)===A.charAt(0);){O+=P.charAt(0),P=P.substring(1)+A.charAt(0),A=A.substring(1);var me=_(O,P)+_(P,A);me>=J&&(J=me,W=O,Z=P,K=A)}k[E-1][1]!=W&&(W?k[E-1][1]=W:(k.splice(E-1,1),E--),k[E][1]=Z,K?k[E+1][1]=K:(k.splice(E+1,1),E--))}E++}}function x(k,_){k.push([r,""]);for(var E=0,O=0,P=0,A="",B="",z;E<k.length;){if(E<k.length-1&&!k[E][1]){k.splice(E,1);continue}switch(k[E][0]){case n:P++,B+=k[E][1],E++;break;case i:O++,A+=k[E][1],E++;break;case r:var W=E-P-O-1;if(_){if(W>=0&&L(k[W][1])){var Z=k[W][1].slice(-1);if(k[W][1]=k[W][1].slice(0,-1),A=Z+A,B=Z+B,!k[W][1]){k.splice(W,1),E--;var K=W-1;k[K]&&k[K][0]===n&&(P++,B=k[K][1]+B,K--),k[K]&&k[K][0]===i&&(O++,A=k[K][1]+A,K--),W=K}}if(F(k[E][1])){var Z=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),A+=Z,B+=Z}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(A.length>0||B.length>0){A.length>0&&B.length>0&&(z=l(B,A),z!==0&&(W>=0?k[W][1]+=B.substring(0,z):(k.splice(0,0,[r,B.substring(0,z)]),E++),B=B.substring(z),A=A.substring(z)),z=c(B,A),z!==0&&(k[E][1]=B.substring(B.length-z)+k[E][1],B=B.substring(0,B.length-z),A=A.substring(0,A.length-z)));var J=P+O;A.length===0&&B.length===0?(k.splice(E-J,J),E=E-J):A.length===0?(k.splice(E-J,J,[n,B]),E=E-J+1):B.length===0?(k.splice(E-J,J,[i,A]),E=E-J+1):(k.splice(E-J,J,[i,A],[n,B]),E=E-J+2)}E!==0&&k[E-1][0]===r?(k[E-1][1]+=k[E][1],k.splice(E,1)):E++,P=0,O=0,A="",B="";break}}k[k.length-1][1]===""&&k.pop();var me=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),me=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),me=!0)),E++;me&&x(k,_)}function C(k){return k>=55296&&k<=56319}function N(k){return k>=56320&&k<=57343}function F(k){return N(k.charCodeAt(0))}function L(k){return C(k.charCodeAt(k.length-1))}function V(k){for(var _=[],E=0;E<k.length;E++)k[E][1].length>0&&_.push(k[E]);return _}function Y(k,_,E,O){return L(k)||F(O)?null:V([[r,k],[i,_],[n,E],[r,O]])}function ue(k,_,E){var O=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,A=k.length,B=_.length;if(O.length===0&&(P===null||P.length===0)){var z=O.index,W=k.slice(0,z),Z=k.slice(z),K=P?P.index:null;e:{var J=z+B-A;if(K!==null&&K!==J||J<0||J>B)break e;var me=_.slice(0,J),re=_.slice(J);if(re!==Z)break e;var le=Math.min(z,J),De=W.slice(0,le),Me=me.slice(0,le);if(De!==Me)break e;var we=W.slice(le),Ne=me.slice(le);return Y(De,we,Ne,Z)}e:{if(K!==null&&K!==z)break e;var ve=z,me=_.slice(0,ve),re=_.slice(ve);if(me!==W)break e;var ce=Math.min(A-ve,B-ve),Te=Z.slice(Z.length-ce),be=re.slice(re.length-ce);if(Te!==be)break e;var we=Z.slice(0,Z.length-ce),Ne=re.slice(0,re.length-ce);return Y(W,we,Ne,Te)}}if(O.length>0&&P&&P.length===0)e:{var De=k.slice(0,O.index),Te=k.slice(O.index+O.length),le=De.length,ce=Te.length;if(B<le+ce)break e;var Me=_.slice(0,le),be=_.slice(B-ce);if(De!==Me||Te!==be)break e;var we=k.slice(le,A-ce),Ne=_.slice(le,B-ce);return Y(De,we,Ne,Te)}return null}function he(k,_,E,O){return o(k,_,E,O,!0)}he.INSERT=n,he.DELETE=i,he.EQUAL=r,t.exports=he}),Qu={};Ng(Qu,{CoreViewer:()=>ng,HOOKS:()=>bs,Navigation:()=>rg,PageProgression:()=>ul,PageSide:()=>ic,PageViewMode:()=>AS,Profiler:()=>sc,ReadyState:()=>nc,UserAgentBaseCss:()=>fd,UserAgentCounterStylesCss:()=>wd,UserAgentPageCss:()=>pd,UserAgentTocCss:()=>gd,UserAgentXml:()=>dd,ValidationTxt:()=>cd,VivliostylePolyfillCss:()=>md,VivliostyleViewportCss:()=>ud,VivliostyleViewportScreenCss:()=>hd,ZoomType:()=>IS,getHooksForName:()=>Ut,isDebug:()=>xr,pageProgressionOf:()=>tc,plugin:()=>Rg,printHTML:()=>RS,profile:()=>Mg,profiler:()=>Et,registerHook:()=>Ot,removeHook:()=>oc,setDebug:()=>ec});og.exports=Ig(Qu);var xr=!1;function ec(e){xr=e}var ul=(e=>(e.LTR="ltr",e.RTL="rtl",e))(ul||{});function tc(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var ic=(e=>(e.LEFT="left",e.RIGHT="right",e))(ic||{}),nc=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(nc||{}),rc=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(rc||{}),Fg=class{constructor(e){this.opt_console=e,d(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=Jr(arguments);this.consoleDebug(Qr(t)),this.triggerListeners(1,t)}info(...e){let t=Jr(arguments);this.consoleInfo(Qr(t)),this.triggerListeners(2,t)}warn(...e){let t=Jr(arguments);this.consoleWarn(Qr(t)),this.triggerListeners(3,t)}error(...e){let t=Jr(arguments);this.consoleError(Qr(t)),this.triggerListeners(4,t)}};function Jr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Qr(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 j=new qf,Yo=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))(Yo||{}),So={};function At(e,t,i){if(!Yo[e])j.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=So[e];n||(n=So[e]=[]),i?n.unshift(t):n.push(t)}}function Ru(e,t){if(!Yo[e])j.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=So[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Dt(e){return So[e]||[]}var Yf={registerHook:At,removeHook:Ru},Lu=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=Yi,this.registerStartTiming=this.registerStartTiming=Yi,this.registerEndTiming=this.registerEndTiming=Yi}forceRegisterStartTiming(e,t){ms.call(this,e,"start",t)}forceRegisterEndTiming(e,t){ms.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];t+=i,r>1&&(t+=`(${o})`),t+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
- `}}),j.info(t)}disable(){this.registerTiming=Yi,this.registerStartTiming=this.registerStartTiming=Yi,this.registerEndTiming=this.registerEndTiming=Yi}enable(){this.registerTiming=ms,this.registerStartTiming=this.registerStartTiming=Ul,this.registerEndTiming=this.registerEndTiming=Zf}isEnabled(){return this.registerStartTiming===Ul}};function Yi(){}function ms(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[t]));s--)r=null;r||(r={},n.push(r)),r[t]=i}function Ul(e,t){this.registerTiming(e,"start",t)}function Zf(e,t){this.registerTiming(e,"end",t)}var Kf={now:Date.now},Jf=window&&window.performance,xt=new Lu(Jf||Kf);xt.forceRegisterStartTiming("load_vivliostyle");var Qf={profiler:{registerStartTiming:xt.registerStartTiming,registerEndTiming:xt.registerEndTiming,printTimings:xt.printTimings,disable:xt.disable,enable:xt.enable}},Ga=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Co=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Zt="data-adapt-eloff",eg={};function ja(e){return JSON.parse(e)}function Bt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Ou(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Ui=window.location.href;function $l(e){Ui=e}var vi=window.location.href;function Hl(e){vi=e}function tg(e){let t=Ou(e).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function pr(e){return e.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ie(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let s=tg(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Ou(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function ko(e,t){return e.match(/^#/)&&t?Bt(t)+e:Ie(e,t)}function Bu(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function yn(e){let t;return(e=Bu(e))!==e||((t=/^(https?:)\/\/github\.com\/web-platform-tests\/wpt\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/${t[2]?"":"master/"}${t[3]}`:(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(e))?/\.sub\.[^/]+(?:[?#].*)?$/.test(t[2])||(e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/master/${t[2]}`):(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`)),e}function Wl(e){return e==null?e:e.toString()}var ig=class{constructor(){c(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},Mu=["","-webkit-","-moz-"],Ji={};function eo(e,t){return CSS.supports(e+t,"unset")}function ng(e){let t=Ji[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Ji[e]=null,null;case"text-combine-upright":if(eo("-webkit-","text-combine")&&!eo("","text-combine-upright"))return Ji[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Mu)if(eo(i,e))return t=[i+e],Ji[e]=t,t;return j.warn("Property not supported by the browser: ",e),Ji[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=ng(t);if(r)for(let o of r){switch(o){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(o,i)}}function mi(e,t,i){try{let n=Ji[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function _s(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var si=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Xa(e){return`\\${e.charCodeAt(0).toString(16)} `}function bi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Xa)}function kr(e){return e.replace(/[\u0000-\u001F"\\]/g,Xa)}function Gl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function jl(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function rg(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function _u(e,t){function i(n){return rg(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function di(e){return _u(e)}function og(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function sg(e,t){t=typeof t=="string"?t:"\\u";function i(r){return og(r,t)}let n=new RegExp(`${di(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ai(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function Du(e,t){return e-t}function Xl(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function ag(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function ws(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function lg(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var qa=class{constructor(){c(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},_i={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function zu(){return{fontFamily:"serif",lineHeight:1.25,margin:8,hyphenate:!1,columnWidth:25,horizontal:!1,nightMode:!1,spreadView:!1,pageBorder:1,enabledMediaTypes:{vivliostyle:!0,print:!0},defaultPaperSize:void 0}}function Vu(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var hg=zu(),ql={PENDING:{}};function Uu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function ug(e){return`"${kr(`${e}`)}"`}function cg(e){return bi(`${e}`)}function Ds(e,t){return e?`${bi(e)}.${bi(t)}`:bi(t)}var $u=0,zs=class{constructor(e,t){if(this.parent=e,this.resolver=t,c(this,"scopeKey"),c(this,"children",[]),c(this,"zero"),c(this,"one"),c(this,"_true"),c(this,"_false"),c(this,"values",{}),c(this,"funcs",{}),c(this,"builtIns",{}),this.scopeKey=`S${$u++}`,this.zero=new Qe(this,0),this.one=new Qe(this,1),this._true=new Qe(this,!0),this._false=new Qe(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=Uu,i["css-string"]=ug,i["css-name"]=cg,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Re(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function dg(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Hu(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function pg(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function fg(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Wt={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function Wu(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var Vs=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,c(this,"actualPageWidth",null),c(this,"pageWidth"),c(this,"actualPageHeight",null),c(this,"pageHeight"),c(this,"initialFontSize"),c(this,"rootFontSize",null),c(this,"isRelativeRootFontSize",null),c(this,"fontSize"),c(this,"rootLineHeight",null),c(this,"pref"),c(this,"scopes",{}),c(this,"pageAreaWidth",null),c(this,"pageAreaHeight",null),c(this,"pageVertical",null),c(this,"pubTitle",null),c(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=hg}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(Hu(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Wt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let o=e.builtIns[t];if(o){if(n)return e.zero;let s=Array(i.length);for(let a=0;a<i.length;a++)s[a]=i[a].evaluate(this);return new Qe(e,o.apply(this,s))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&t==null)return o!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Ut=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${$u++}`}toString(){let e=new si;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===ql.PENDING?!1:n;{i[this.key]=ql.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},Gu=class extends Ut{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},Zo=class extends Ut{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},ju=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Rn=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Xu=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ya=class extends Zo{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},xi=class extends Gu{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},gg=class extends xi{constructor(e,t){super(e,t)}getOp(){return"not "}},un=class extends Gu{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Za=class extends ju{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},mg=class extends Za{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Ka=class extends ju{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},wg=class extends Ka{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},yg=class extends Ka{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},vg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},bg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},xg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Us=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Ja=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Sg=class extends Rn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},qu=class extends Xu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Yu=class extends Xu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Qa=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Zu=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Ku=class extends Ya{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Er=class extends Ut{constructor(e,t,i){var n;super(e),this.num=t,c(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(bi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Ze=class extends Ut{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},Yl=class extends Ut{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(bi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Re=class extends Ut{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function Cg(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function kg(e,t,i){let n=t;for(let r=0;r<t.length;r++){let o=t[r].expand(e,i);if(t!==n)n[r]=o;else if(o!==t[r]){n=Array(t.length);for(let s=0;s<r;s++)n[s]=t[s];n[r]=o}}return n}var tr=class Ju extends Ut{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Cg(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=kg(t,this.params,i);return n===this.params?this:new Ju(this.scope,this.qualifiedName,n)}},Eg=class Qu extends Ut{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),o=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new Qu(this.scope,n,r,o)}},Qe=class extends Ut{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(kr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Zl=class ec extends Ut{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(kr(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new ec(this.scope,this.name,n)}},Pg=class extends Ut{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},tc=class extends Ut{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function Mt(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new Za(e,t,i)}function te(e,t,i){return t===e.zero?i:i===e.zero?t:new qu(e,t,i)}function ge(e,t,i){return t===e.zero?new un(e,i):i===e.zero?t:new Yu(e,t,i)}function to(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Qa(e,t,i)}function $s(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Zu(e,t,i)}var ui=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Gi=class extends ui{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let o=0;o<i;o++)t[o]=e[o];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new it(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new ci(e.name,t)}visitExpr(e){return e}},nt=class{toString(){let e=new si;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new si;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},ic=class nc extends nt{static get instance(){return this.empty||(this.empty=new nc),this.empty}constructor(){super()}toExpr(t,i){return new Qe(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(ic,"empty");var Ng=ic,Y=Ng.instance,rc=class oc extends nt{static get instance(){return this.slash||(this.slash=new oc),this.slash}constructor(){super()}toExpr(t,i){return new Qe(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(rc,"slash");var Tg=rc,Ln=Tg.instance,X=class extends nt{constructor(e){super(),this.str=e}toExpr(e,t){return new Qe(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(kr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Hs=Object.create(null),de=class extends nt{constructor(e){if(super(),this.name=e,Hs[e])throw new Error("E_INVALID_CALL");Hs[e]=this}toExpr(e,t){return new Qe(e,this.name)}appendTo(e,t){t?e.append(bi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function M(e){let t=Hs[e];return t||(t=new de(e)),t}var R=class extends nt{constructor(e,t){var i;super(),this.num=e,c(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Qa(e,t,new Qe(e,this.num/100)):new Er(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},Ct=class extends nt{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Qe(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Ue=class extends Ct{constructor(e){super(e)}visit(e){return e.visitInt(this)}},sc=class extends nt{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ut=class extends nt{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(kr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},ac=class extends nt{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function el(e,t,i,n){var r,o;let s=t.length;if(s>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<s;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var J=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){el(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},it=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){el(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ci=class extends nt{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(bi(this.name)),e.append("("),el(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},G=class extends nt{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Qe||this.expr instanceof Er?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},Qi=class extends nt{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function at(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function lc(e,t){return new R(at(e,t),"px")}var v={absolute:M("absolute"),all:M("all"),always:M("always"),anywhere:M("anywhere"),auto:M("auto"),avoid:M("avoid"),balance:M("balance"),balance_all:M("balance-all"),block:M("block"),block_end:M("block-end"),block_start:M("block-start"),both:M("both"),bottom:M("bottom"),border_box:M("border-box"),break_all:M("break-all"),break_word:M("break-word"),clip:M("clip"),crop:M("crop"),cross:M("cross"),column:M("column"),discard:M("discard"),exclusive:M("exclusive"),_false:M("false"),fixed:M("fixed"),flex:M("flex"),flow_root:M("flow-root"),footnote:M("footnote"),footer:M("footer"),grid:M("grid"),header:M("header"),hidden:M("hidden"),horizontal_tb:M("horizontal-tb"),inherit:M("inherit"),initial:M("initial"),inline:M("inline"),inline_block:M("inline-block"),inline_end:M("inline-end"),inline_start:M("inline-start"),inside:M("inside"),keep:M("keep"),landscape:M("landscape"),left:M("left"),line:M("line"),list_item:M("list-item"),ltr:M("ltr"),manual:M("manual"),max_content:M("max-content"),min_content:M("min-content"),none:M("none"),normal:M("normal"),oeb_page_foot:M("oeb-page-foot"),oeb_page_head:M("oeb-page-head"),outside:M("outside"),padding_box:M("padding-box"),page:M("page"),relative:M("relative"),revert:M("revert"),right:M("right"),same:M("same"),scale:M("scale"),snap_block:M("snap-block"),snap_inline:M("snap-inline"),solid:M("solid"),spread:M("spread"),_static:M("static"),rtl:M("rtl"),table:M("table"),table_caption:M("table-caption"),table_cell:M("table-cell"),table_footer_group:M("table-footer-group"),table_header_group:M("table-header-group"),table_row:M("table-row"),top:M("top"),transparent:M("transparent"),unset:M("unset"),vertical_lr:M("vertical-lr"),vertical_rl:M("vertical-rl"),visible:M("visible"),_true:M("true")},Kl=new R(100,"%"),Pr=new R(100,"pvw"),Nr=new R(100,"pvh"),Fe=new R(0,"px"),Gx=new ac("U+0-10FFFF"),Jl={"font-size":1,"line-height":2,color:3};function Z(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Ql(e,t){let i=Jl[e]||Number.MAX_VALUE,n=Jl[t]||Number.MAX_VALUE;return i-n}function Qt(e){return e?.length>2&&e.startsWith("--")}var en,tn,nn,hc=class ti{constructor(t,i,n){ie(this,en),ie(this,tn),ie(this,nn),Ve(this,en,Math.round(Math.max(0,Math.min(t,ti.MAX)))),Ve(this,tn,Math.round(Math.max(0,Math.min(i,ti.MAX)))),Ve(this,nn,Math.round(Math.max(0,Math.min(n,ti.MAX))))}static fromInt(t,i,n){return new ti(t,i,n)}offset(t,i,n){return new ti($(this,en)+t,$(this,tn)+i,$(this,nn)+n)}toKey(){return JSON.stringify([$(this,en),$(this,tn),$(this,nn)])}toColorFunc(t){return new ci("color",[new J([M("srgb"),new Ct($(this,en)/ti.MAX),new Ct($(this,tn)/ti.MAX),new Ct($(this,nn)/ti.MAX),...t!==null?[Ln,new Ct(t)]:[]])])}};en=new WeakMap,tn=new WeakMap,nn=new WeakMap,c(hc,"MAX",1e4);var ii=hc;function Ig(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Ai,Fi,Ri,jt,uc=class dt{constructor(t,i,n,r){ie(this,Ai),ie(this,Fi),ie(this,Ri),ie(this,jt),Ve(this,Ai,Math.round(Math.max(0,Math.min(t,dt.MAX)))),Ve(this,Fi,Math.round(Math.max(0,Math.min(i,dt.MAX)))),Ve(this,Ri,Math.round(Math.max(0,Math.min(n,dt.MAX)))),Ve(this,jt,Math.round(Math.max(0,Math.min(r,dt.MAX))))}static fromInt(t,i,n,r){return new dt(t,i,n,r)}static fromNumber(t,i,n,r){return new dt(t*dt.MAX,i*dt.MAX,n*dt.MAX,r*dt.MAX)}toSRGB(){let t=dt.MAX-$(this,jt);return ii.fromInt(ii.MAX-Math.min(ii.MAX,Math.round($(this,Ai)*t/dt.MAX)+$(this,jt)),ii.MAX-Math.min(ii.MAX,Math.round($(this,Fi)*t/dt.MAX)+$(this,jt)),ii.MAX-Math.min(ii.MAX,Math.round($(this,Ri)*t/dt.MAX)+$(this,jt)))}equals(t){return $(this,Ai)===$(t,Ai)&&$(this,Fi)===$(t,Fi)&&$(this,Ri)===$(t,Ri)&&$(this,jt)===$(t,jt)}toJSON(){return{c:$(this,Ai),m:$(this,Fi),y:$(this,Ri),k:$(this,jt)}}};Ai=new WeakMap,Fi=new WeakMap,Ri=new WeakMap,jt=new WeakMap,c(uc,"MAX",1e4);var cc=uc;function Zi(e){return e instanceof Ct?Math.max(0,Math.min(1,e.num)):e instanceof R&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function dc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof J?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=Zi(t[0]),n=Zi(t[1]),r=Zi(t[2]),o=Zi(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===Ln){if(t.length!==6)return null;s=Zi(t[5])}else{if(t.length!==5)return null;s=Zi(t[4])}if(s===null)return null}return{cmyk:cc.fromNumber(i,n,r,o),alpha:s}}function*Ag(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var gi,Eo,pc,eh,fc=class{constructor(){ie(this,Eo),ie(this,gi,new Map)}registerDeviceCmyk(e){let t=dc(e);return t?Ne(this,Eo,pc).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ii.fromInt(t.r,t.g,t.b),r=cc.fromInt(i.c,i.m,i.y,i.k);$(this,gi).set(n.toKey(),r)}}toJSON(){let e={};return $(this,gi).forEach((t,i)=>{e[i]=t.toJSON()}),e}};gi=new WeakMap,Eo=new WeakSet,pc=function(e){let t=e.toSRGB(),i=t.toKey(),n=$(this,gi).get(i);return n?n.equals(e)?t:Ne(this,Eo,eh).call(this,e,t):($(this,gi).set(i,e),t)},eh=function(e,t){for(let i=1;i<=ii.MAX;i++)for(let[n,r,o]of Ag(i)){let s=t.offset(n,r,o),a=s.toKey();if(!$(this,gi).has(a))return $(this,gi).set(a,e),s}return j.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var io,Wn,Gn,gc=class extends Gi{constructor(e){super(),ie(this,io),ie(this,Wn,new Map),ie(this,Gn,!1),Ve(this,io,e??new fc)}reset(){Ve(this,Gn,!1)}hadDeviceCmyk(){return $(this,Gn)}recordConversion(e,t){$(this,Wn).set(e,t)}getConversions(){if($(this,Wn).size===0)return null;let e={};return $(this,Wn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=$(this,io).registerDeviceCmyk(e);return t?(Ve(this,Gn,!0),t):super.visitFunc(e)}};io=new WeakMap,Wn=new WeakMap,Gn=new WeakMap;function mc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Fg(e){return`^${e}`}function th(e){return e.replace(/[\[\]\(\),=;^]/g,Fg)}function Rg(e){return e.substr(1)}function Ws(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Rg)}function Lg(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Ws(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function ih(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Lg(i[2]),e=e.substr(i[0].length)}return t}var nh=class{appendTo(e){e.append("!")}applyTo(e){return!1}},rh=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?e.after=!0:r=s}e.node=r}if(this.id&&(e.after||this.id!=mc(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:j.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},oh=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(t<=o)break;if(!r){t=o;break}t-=o}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(th(this.textBefore)),e.append(","),this.textAfter&&e.append(th(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},sh=class wc{constructor(){c(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,o=[];for(;;){let s;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];s=ih(i[4]),o.push(new rh(a,h,Wl(s.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Ws(h));let l=i[7];l&&(l=Ws(l)),s=ih(i[10]),o.push(new oh(a,h,l,Wl(s.s)));break}case"!":r++,o.push(new nh);break;case"~":case"@":case"":this.steps=o;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new wc,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let o=[],s=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new oh(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:mc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new rh(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new nh),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new si;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}},It=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},wi=class{constructor(e,t){this.x=e,this.y=t}},ys=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},ah=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},ri=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,c(this,"left",null),c(this,"right",null)}};function Og(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Ko=class yc{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new ah(o,a,1,i):h=new ah(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new wi(r.x+t,r.y+i));return new yc(n)}};function lh(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new wi(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Ko(r)}function tl(e,t,i,n){return new Ko([new wi(e,t),new wi(i,t),new wi(i,n),new wi(e,n)])}var Wr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function hh(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function Bg(e,t,i,n){let r,o,s,a;t.high.y<i&&j.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=hh(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=hh(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new Wr(r,o,t.shapeId,-1)),e.push(new Wr(s,a,t.shapeId,1))):(e.push(new Wr(s,a,t.shapeId,-1)),e.push(new Wr(r,o,t.shapeId,1)))}function Mg(e,t,i){let n=t+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let d=e[u];r[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let p=!1;for(s=0;s<t;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=t;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function _g(e,t){return t?Math.ceil(e/t)*t:e}function uh(e,t){return t?Math.floor(e/t)*t:e}function Dg(e){return new wi(e.y,-e.x)}function Po(e){return new It(e.y1,-e.x2,e.y2,-e.x1)}function vc(e){return new It(-e.y2,e.x1,-e.y1,e.x2)}function ch(e){return new Ko(e.points.map(t=>Dg(t)))}function zg(e,t,i,n,r,o){o&&(e=Po(e),t=t.map(y=>ch(y)),i=i.map(y=>ch(y)));let s=t.length,a=i?i.length:0,h=[],l=[],u,d,p;for(u=0;u<s;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+s);let f=l.length;l.sort(Og);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>e.y1&&h.push(new ri(e.y1,m,e.x2,e.x2));let w=0,x=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&x.push(p),w++;for(;w<f||x.length>0;){let y=e.y2,b=Math.min(_g(Math.ceil(m+n),r),e.y2);for(d=0;d<x.length&&y>b;d++)p=x[d],p.low.x==p.high.x?p.high.y<y&&(y=Math.max(uh(p.high.y,r),b)):p.low.x!=p.high.x&&(y=b);for(y>e.y2&&(y=e.y2);w<f&&(p=l[w]).low.y<y;){if(p.high.y<m){w++;continue}if(p.low.y<b)p.low.y==p.high.y&&p.low.y==m||(x.push(p),y=b),w++;else{let N=uh(p.low.y,r);N<y&&(y=N);break}}let S=[];for(d=0;d<x.length;d++)Bg(S,x[d],m,y);S.sort((N,F)=>N.x-F.x||N.lowOrHigh-F.lowOrHigh);let C=Mg(S,s,a);if(C.length==0)h.push(new ri(m,y,e.x2,e.x2));else{let N=0,F=e.x1;for(d=0;d<C.length;d+=2){let B=Math.max(e.x1,C[d]),U=Math.min(e.x2,C[d+1])-B;U>N&&(N=U,F=B)}N==0?h.push(new ri(m,y,e.x2,e.x2)):h.push(new ri(m,y,Math.max(F,e.x1),Math.min(F+N,e.x2)))}if(y==e.y2)break;for(m=y,d=x.length-1;d>=0;d--)x[d].high.y<=y&&x.splice(d,1)}return bc(e,h),h}function bc(e,t){let i=t.length-1,n=new ri(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function xc(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function Vg(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)o=n.y2;return r===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new It(t.x1,i,t.x2,o)}function Ug(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new It(t.x1,o,t.x2,i)}function $g(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=xc(t,r);for(;;){let h=r+s;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<h;d++){let p=t[d];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+o<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=u-o,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Hg(e,t,i,n,r){for(n||(n=[new ri(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let o,s=t.length==0?e.y1:t[t.length-1].y2;s<e.y2&&t.push(new ri(s,e.y2,e.x1,e.x2));let a=xc(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(o=t[a],a++,t.splice(a,0,new ri(h.y1,o.y2,o.x1,o.x2)),o.y2=h.y1);a<t.length&&(o=t[a++],o.y2>h.y2&&(t.splice(a,0,new ri(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}bc(e,t)}var Wg=class extends ui{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Gg(e){if(e){let t=new Wg;try{return e.visit(t),t.propSet}catch(i){j.warn(i,"toSet:")}}return{}}var jg=class extends ui{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function dh(e,t){if(e){let i=new jg(t);try{return e.visit(i),i.value}catch(n){j.warn(n,"toInt: ")}}return t}var Xg=class extends ui{constructor(){super(),c(this,"collect",!1),c(this,"coords",[]),c(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new R(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new wi(e+o[a],t+o[a+1]));return new Ko(s)}break;case"rectangle":if(o.length==4)return tl(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return lh(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return lh(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function Sc(e,t,i,n,r,o){if(e){let s=new Xg;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){j.warn(a,"toShape:")}}return tl(t,i,t+n,i+r)}var qg=class extends ui{constructor(e,t){super(),this.reset=e,this.defaultValue=t,c(this,"counters",Object.create(null)),c(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function vn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new qg(r,o);try{e.visit(s)}catch(a){j.warn(a,"toCounters:")}return s.counters}var Yg=class extends Gi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ut(pr(this.transformer.transformURL(e.url,this.baseUrl)))}};function Pi(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Zg(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function cn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let o=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(s=>Zg(s.substring(1,s.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Kg=class{constructor(e,t){this.targetId=e,this.resolved=t,c(this,"pageCounters",null),c(this,"spineIndex",-1),c(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Jg=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},Qg=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,c(this,"styler",null),c(this,"namedStringValues",Object.create(null)),c(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ie(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let o=this.counterStore.currentPageCounters[e];return o&&o.length?o[o.length-1]:null},n=new Re(this.pageScope,()=>t(i()),`page-counter-${e}`),r=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Re(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],o=r.length?r[r.length-1]:0,s=n?.[e]||[],a=s.length?s[0]:0;return t.length?[o+(t[0]-a),...t.slice(1)]:[o]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?cn(n,t):cn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),o=new Re(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[t]){let a=s[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Re(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,o,h);if(l.length)return i(l);let u=o[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Re(this.pageScope,()=>{if(t==="first-letter"){let o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Co);return l?l[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Re(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Re(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(Du),o=this.counterStore.currentPage;if(!o)return"";let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${Zt}]`)).map(p=>parseInt(p.getAttribute(Zt),10))),h=-1,l=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,d=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${Zt}="${f}"]`);if(!w)l<0&&(l=f);else{let x=o.container.querySelector(`[${Zt}="${s}"]`);if(x||(x=o.container.querySelector(`[${Zt}="0"]`)),x){for(let y=x;y;y=y.firstElementChild)if(y===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=d=f)}return n[{first:h,start:l,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},em=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",Object.create(null)),c(this,"pageCountersById",Object.create(null)),c(this,"pageDocCountersById",Object.create(null)),c(this,"pageTextById",Object.create(null)),c(this,"currentPageDocCounters",null),c(this,"previousPageDocCounters",null),c(this,"currentPageDocCounterChanges",Object.create(null)),c(this,"currentPageDocCounterChangeTypes",Object.create(null)),c(this,"currentPageCounters",Object.create(null)),c(this,"previousPageCounters",Object.create(null)),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",Object.create(null)),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",Object.create(null)),c(this,"resolvedReferences",Object.create(null)),c(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Jg(this,e)}createCounterResolver(e,t,i){return new Qg(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?Pi(this.currentPageDocCounters):null,this.currentPageDocCounters=e?Pi(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[e]}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Pi(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],x=w.length?w[w.length-1]:0,y=g[m]||[],b=y.length?y[y.length-1]:0,S=x-b,C=n[m],N=C==="reset"||C==="set";r[m]={delta:S,reset:N,value:x}}}let o=Object.create(null),s,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(s=vn(g,{reset:!0}))}s&&"pages"in s&&delete s.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=vn(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(s)for(let g in s)u.push(g);if(h)for(let g in h)u.push(g);let d,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(d=vn(g))}d&&"pages"in d&&delete d.pages,d?!("page"in d)&&!(r.page&&r.page.reset)&&(d.page=1):(d=Object.create(null),r.page&&r.page.reset||(d.page=1));for(let g in d)u.push(g);this.setPageControlledCounterNames(u);let f=Pi(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],o[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,s)for(let g in s)this.definePageCounter(g,s[g]);if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}for(let g in d){if(o[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=d[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Pi(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let o=this.referencesToSolve[r];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(r,1),t){let s=t.indexOf(o);s>=0&&t.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Kg(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=Pi(this.currentPageCounters),s=this.currentPageDocCounters?Pi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:cn(u,"content"),before:cn(u,"before"),after:cn(u,"after"),marker:cn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),d.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.currentPage=null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(o=>o+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${zn}]`);for(let n of i){let r=n.getAttribute(zn),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let s=r.container.querySelectorAll(`[${Dn}]`);for(let a of s){let h=a.getAttribute(Dn),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,d=u?.replace(/^page-counters?-/,""),p=o[d];p&&(a.textContent=l.format(p))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(t=t.concat(o))}),t.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Re){if(e.str=="viv-leader"){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute("data-viv-leader",e.key),o.setAttribute("data-viv-leader-value",t),o}else if(e.str.startsWith("running-element-")){let o=t&&i.querySelectorAll(`[${Zt}="${t}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(zn,e.key),o}else if(e.str.startsWith("target-text-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(bs,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?vs:Dn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Dn}]`);for(let r of t){let o=r.getAttribute(Dn),s=this.pageCounterExprs.find(u=>u.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=e.querySelectorAll(`[${zn}]`);for(let r of i)r.setAttribute(ph,!0);let n=e.querySelectorAll(`[${bs}]`);for(let r of n)r.setAttribute(fh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${vs}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(vs),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${ph}]`);for(let s of r){let a=s.getAttribute(zn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(s.textContent=h.format(u[u.length-1]))}}}let o=e.root.querySelectorAll(`[${fh}]`);for(let s of o){let a=s.getAttribute(bs),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new tm(this,e)}},vs="data-vivliostyle-pages-counter",Dn="data-vivliostyle-page-counter",zn="data-vivliostyle-target-counter",bs="data-vivliostyle-target-text",ph="data-vivliostyle-target-counter-in-running",fh="data-vivliostyle-target-text-in-running",tm=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}},im=new Set(["before","after","first-line","first-letter"]),gh=new Set(["media","supports","-epubx-when"]),Cc=new Set([";","}"]),kc=new Set(["{",";","}"]),nm=new Set([";","{","}"]),rm=":where(:scope)",om=":where(:not(*))";function sm(e){let{statements:t,changed:i}=Gs(e,0,e.length,null);return i?t.join(`
5
- `):e}function Gs(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(am(n,o)):r.push(Ec(o)),o.length=0)};for(;a<i&&(a=$i(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let d=xm(e,a,i);if(!d)break;if(n&&!gh.has(d.name)){o.push(Mi(e.slice(a,d.end))),a=d.end;continue}if(h(),d.hasBlock&&gh.has(d.name)){let p=Gs(e,d.blockStart,d.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${d.header} {${lm(p.statements)}}`)}else r.push(Mi(e.slice(a,d.end)));a=d.end;continue}if(n&&pm(e,a,i)){let d=mm(e,a,i);if(!d)break;o.push(Mi(d.text)),a=d.end;continue}h();let l=wm(e,a,i);if(!l){let d=Sm(e,a,i);r.push(Mi(d.text)),a=d.end;continue}if(n&&ym(e,a,l)){let d=bm(e,a,l.end,i);o.push(Mi(d.text)),a=d.end;continue}let u=n?hm(n,l.prelude):Pc(l.prelude);if(u){s||(s=n!=null);let d=Gs(e,l.blockStart,l.blockEnd,u);s||(s=d.changed),d.statements.length===0?r.push(`${u} {}`):r.push(...d.statements)}a=l.end}return h(),{statements:r,changed:s}}function am(e,t){return`${e} { ${Ec(t)} }`}function Ec(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function lm(e){return e.length===0?"":` ${e.join(" ")} `}function hm(e,t){let i=um(e);if(!i)return null;let n=Tc(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=Nc(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function Pc(e){return Nc(e.trim(),rm).text}function um(e){let t=Tc(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!cm(i));return t.length===0?null:`:is(${t.join(", ")})`}function cm(e){let t=0;for(;t<e.length;){let i=Jo(e,t);if(i!=null){t=i;continue}let n=ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,o=Tr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(im.has(s))return!0;t=o;continue}t++}return!1}function Nc(e,t){let i=0,n=!1,r="",o=[],s=dm(t);for(;i<e.length;){let a=Jo(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=ji(e,i,e.length);if(h!=null){r+=e.slice(i,h),i=h;continue}let l=e[i];if(l===":"&&e[i+1]!==":"){let u=i+1,d=Tr(e,u,e.length);if(d>u&&e[d]==="("){o.push(e.slice(u,d).toLowerCase()),r+=e.slice(i,d+1),i=d+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?om:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function dm(e){let t=0;for(;t<e.length;){let i=Jo(e,t);if(i!=null){t=i;continue}let n=ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,o=Tr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function Tc(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=Jo(e,r);if(a!=null){r=a;continue}let h=ji(e,r,e.length);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function pm(e,t,i){let n=t,r=gm(e,n,i);if(r<=n)return!1;let o=$i(e,r,i);if(o>=i||e[o]!==":")return!1;let s=Ir(e,o+1,i,nm);return s?.char==="{"?!fm(e,t,r,o,s.index):!0}function fm(e,t,i,n,r){if($i(e,i,r)!==n)return!1;let o=$i(e,n+1,r);if(o!==n+1||o>=r)return!1;let s=e[o];return s===":"||s==="\\"||/[A-Za-z_-]/.test(s)}function gm(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Tr(e,n,i)}function Tr(e,t,i){let n=t;for(;n<i;){let r=e[n];if(r==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(r))break;n++}return n}function mm(e,t,i){let n=Ir(e,t,i,Cc);if(!n){let o=e.slice(t,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function wm(e,t,i){let n=Ir(e,t,i,kc);if(!n||n.char!=="{")return null;let r=Ic(e,n.index,i);return r<0?null:{prelude:Mi(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function ym(e,t,i){if(!vm(e,t,i.blockStart-1))return!0;let n=$i(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function vm(e,t,i){let n=$i(e,t,i);if(n>=i)return!1;let r=e[n];return r==="&"||r==="."||r==="#"||r===":"||r==="["||r==="|"||r==="*"||r===">"||r==="+"||r==="~"||r==="\\"||/[A-Za-z_-]/.test(r)}function bm(e,t,i,n){let r=$i(e,i,n),o=r<n&&e[r]===";"?r+1:i;return{text:e.slice(t,o),end:o}}function xm(e,t,i){let n=Ir(e,t,i,kc);if(!n)return null;let r=Tr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Mi(e.slice(t,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=Ic(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function Sm(e,t,i){let n=Ir(e,t,i,Cc);if(!n)return{text:e.slice(t,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r),end:r}}function Ir(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=ji(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function Ic(e,t,i){let n=t+1,r=1;for(;n<i;){let o=ji(e,n,i);if(o!=null){n=o;continue}let s=e[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function $i(e,t,i){let n=t;for(;n<i;){let r=e[n];if(Fc(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=Ac(e,n,i);continue}break}return n}function Ac(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function ji(e,t,i){let n=e[t];return n==='"'||n==="'"?Cm(e,t):n==="/"&&e[t+1]==="*"?Ac(e,t,i):null}function Jo(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function Cm(e,t){let i=e[t],n=t+1;for(;n<e.length;){let r=e[n];if(r==="\\"){n+=2;continue}if(r===i)return n+1;n++}return e.length}function Fc(e){return e===" "||e===`
6
- `||e==="\r"||e===" "||e==="\f"}function Mi(e){let t="",i=0,n=!1;for(;i<e.length;){let r=ji(e,i,e.length);if(r!=null&&e[i]!=="/"){n&&t.length>0&&(t+=" ",n=!1),t+=e.slice(i,r),i=r;continue}if(r!=null){n=t.length>0,i=r;continue}let o=e[i];if(Fc(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function km(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function pi(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,km)}var Em=class{constructor(){c(this,"type"),c(this,"precededBySpace",!1),c(this,"num",0),c(this,"text",""),c(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Ke(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Xt=[72,72,72,72,72,72,72,72,72,1,1,72,1,1,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,1,4,34,6,7,8,9,33,10,11,12,13,14,15,16,17,2,2,2,2,2,2,2,2,2,2,18,19,20,21,22,23,24,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,25,29,26,30,3,72,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,27,31,28,32,72];Xt[NaN]=80;var qt=[43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,52,43,43,43,43,39,43,43,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43,43,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,44,43,43,39,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43];qt[NaN]=43;var Pm=[72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,78,59,72,59,59,59,59,59,59,59,59,59,59,72,72,72,72,72,72,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,61,72,72,78,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,72,72,72,72];qt[NaN]=43;var Rc=[35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,57,59,35,58,58,58,58,58,58,58,58,58,58,35,35,35,35,35,35,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,61,35,35,60,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,35,35,35,35];Rc[NaN]=35;var Lc=[45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,53,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,44,45,45,39,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45];Lc[NaN]=45;var js=[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,41,37,37,37,37,37,37,37,37,42,37,39,39,39,39,39,39,39,39,39,39,37,37,37,37,37,37,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,40,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,37];js[NaN]=37;var Xs=[38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,41,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,38,38,38,38,38,38,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,40,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,38];Xs[NaN]=38;var Ni=Ke(35,[61,36]),Nm=Ke(35,[58,77]),Tm=Ke(35,[61,36,124,50]),Im=Ke(35,[38,51]),Am=Ke(35,[42,54]),Fm=Ke(39,[42,55]),Rm=Ke(54,[42,55,47,56]),Lm=Ke(62,[62,82]),Om=Ke(35,[61,36,33,70]),Bm=Ke(62,[45,71]),Mm=Ke(63,[45,81]),xs=Ke(76,[10,72,13,72]),_m=Ke(39,[39,46,10,72,13,72,92,48]),Dm=Ke(39,[34,46,10,72,13,72,92,49]),zm=Ke(39,[39,47,10,74,13,74,92,48]),Vm=Ke(39,[34,47,10,74,13,74,92,49]),mh=Ke(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Um=Ke(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),$m=Ke(39,[39,68,10,74,13,74,92,75,NaN,67]),Hm=Ke(39,[34,68,10,74,13,74,92,75,NaN,67]),Wm=Ke(72,[9,39,10,39,13,39,32,39,41,69]),Gm=15,Vt=class{constructor(e,t){this.input=e,this.handler=t,c(this,"indexMask"),c(this,"buffer"),c(this,"tail",0),c(this,"curr",0),c(this,"position",0),this.indexMask=Gm,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Em}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Xt,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",u=0,d=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,o),a=0):n===Xt&&a===0?(a=54,h=o,l=r.substring(o,o+1),o++):(l=r.substring(h,o),a=54),n=Xt;break;case 1:o++,d=!0;continue;case 2:h=o++,n=js;continue;case 3:a=1,h=o++,n=qt;continue;case 4:h=o++,a=31,n=Ni;continue;case 33:a=2,h=++o,n=_m;continue;case 34:a=2,h=++o,n=Dm;continue;case 6:h=++o,a=7,n=qt;continue;case 7:h=o++,a=32,n=Ni;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=Im;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Ni;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=Rc;continue;case 16:h=o++,n=Pm;continue;case 78:h=o++,a=9,n=qt;continue;case 17:h=o++,a=19,n=Am;continue;case 18:h=o++,a=18,n=Nm;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=Om;continue;case 21:h=o++,a=39,n=Ni;continue;case 22:h=o++,a=37,n=Ni;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=qt;continue;case 25:h=o++,a=14;break;case 26:h=o++,a=15;break;case 27:h=o++,a=12;break;case 28:h=o++,a=13;break;case 29:h=o++,f=h,a=1,n=xs;continue;case 30:h=o++,a=33,n=Ni;continue;case 31:h=o++,a=34,n=Tm;continue;case 32:h=o++,a=35,n=Ni;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,o),10);break;case 38:a=4,u=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,u=parseFloat(r.substring(h,o)),h=o++,n=qt;continue;case 41:a=3,u=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=Xs;continue;case 43:if(l=pi(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=xs;continue;case 45:l=pi(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=pi(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=zm;continue;case 49:f=o,o+=2,n=Vm;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=mh;continue}a=6}break;case 53:if(l=pi(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=mh;continue}a=6}break;case 54:n=Fm,o++;continue;case 55:n=Rm,o++;continue;case 56:n=Xt,o++;continue;case 57:n=Lm,o++,r[o]!==">"&&(a=1,n=qt);continue;case 81:a=51,l=r.substring(h,++o),n=Xt;break;case 82:a=52,l=r.substring(h,++o),n=Xt;break;case 58:a=5,n=js,o++;continue;case 59:a=4,n=Xs,o++;continue;case 60:a=1,n=qt,o++;continue;case 61:a=1,n=xs,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=Um;continue;case 65:h=++o,n=$m;continue;case 66:h=++o,n=Hm;continue;case 67:a=8,l=pi(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=Bm,o++;continue;case 71:n=Mm,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=pi(r.substring(h,o)),o++,n=Wm;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Xt;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=qt;continue}l=pi(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=Lc;continue;default:if(n!==Xt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Xt,d=!1,a=0,h=o,l="",u=0,p=s[e&i]}this.position=o,this.tail=e&i}},Xe=null,qs=null;function Ys(){return Xe}function D(e){if(!Xe)throw new Error("E_TASK_NO_CONTEXT");Xe.name||(Xe.name=e);let t=Xe,i=new Qo(t,t.top,e);return t.top=i,i.state=1,i}function jm(e){return new Ym(e||new qm)}function T(e){return new Zs(e)}function kn(e,t,i){let n=D(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Xm(e,t){return(Xe?Xe.getScheduler():qs||jm()).run(e,t)}var qm=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Ym=class{constructor(e){this.timer=e,c(this,"timeout",1),c(this,"slice",25),c(this,"sliceOverTime",0),c(this,"queue"),c(this,"wakeupTime",null),c(this,"timeoutToken",null),c(this,"inTimeSlice",!1),c(this,"order",0),this.queue=new ig,qs||(qs=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){j.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Zm(this,t||"");i.top=new Qo(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){j.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=Xe;return Xe=i,this.schedule(i.top.suspend("bootstrap")),Xe=n,i}},Oc=class{constructor(e){this.task=e,c(this,"scheduledTime",0),c(this,"order",0),c(this,"result",null),c(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Xe;return Xe=e,e.top.finish(this.result),Xe=t,!0}return!1}cancel(){this.canceled=!0}},Zm=class{constructor(e,t){this.scheduler=e,this.name=t,c(this,"callbacks",[]),c(this,"exception",null),c(this,"running",!0),c(this,"result",null),c(this,"waitTarget",null),c(this,"top",null),c(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Xe&&this.continuation){this.continuation.cancel();let t=new Oc(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=D("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&j.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
3
+ `]).concat(i))),n}var j=new Fg,bs=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))(bs||{}),Uo={};function Ot(e,t,i){if(!bs[e])j.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Uo[e];n||(n=Uo[e]=[]),i?n.unshift(t):n.push(t)}}function oc(e,t){if(!bs[e])j.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Uo[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ut(e){return Uo[e]||[]}var Rg={registerHook:Ot,removeHook:oc},sc=class{constructor(e){this.performanceInstance=e,d(this,"timestamps",{}),d(this,"registerTiming"),d(this,"registerStartTiming"),d(this,"registerEndTiming"),this.registerTiming=tn,this.registerStartTiming=this.registerStartTiming=tn,this.registerEndTiming=this.registerEndTiming=tn}forceRegisterStartTiming(e,t){Gs.call(this,e,"start",t)}forceRegisterEndTiming(e,t){Gs.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];t+=i,r>1&&(t+=`(${o})`),t+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
+ `}}),j.info(t)}disable(){this.registerTiming=tn,this.registerStartTiming=this.registerStartTiming=tn,this.registerEndTiming=this.registerEndTiming=tn}enable(){this.registerTiming=Gs,this.registerStartTiming=this.registerStartTiming=ch,this.registerEndTiming=this.registerEndTiming=Lg}isEnabled(){return this.registerStartTiming===ch}};function tn(){}function Gs(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[t]));s--)r=null;r||(r={},n.push(r)),r[t]=i}function ch(e,t){this.registerTiming(e,"start",t)}function Lg(e,t){this.registerTiming(e,"end",t)}var Og={now:Date.now},Bg=window&&window.performance,Et=new sc(Bg||Og);Et.forceRegisterStartTiming("load_vivliostyle");var Mg={profiler:{registerStartTiming:Et.registerStartTiming,registerEndTiming:Et.registerEndTiming,printTimings:Et.printTimings,disable:Et.disable,enable:Et.enable}},cl=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",$o=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Qt="data-adapt-eloff",_g={};function dl(e){return JSON.parse(e)}function Dt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function ac(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Xi=window.location.href;function dh(e){Xi=e}var Ci=window.location.href;function ph(e){Ci=e}function Dg(e){let t=ac(e).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function Sr(e){return e.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ae(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let s=Dg(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=ac(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function Ho(e,t){return e.match(/^#/)&&t?Dt(t)+e:Ae(e,t)}function lc(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function kn(e){let t;return(e=lc(e))!==e||((t=/^(https?:)\/\/github\.com\/web-platform-tests\/wpt\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/${t[2]?"":"master/"}${t[3]}`:(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(e))?/\.sub\.[^/]+(?:[?#].*)?$/.test(t[2])||(e=`${t[1]}//raw.githack.com/web-platform-tests/wpt/master/${t[2]}`):(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`)),e}function fh(e){return e==null?e:e.toString()}var zg=class{constructor(){d(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},hc=["","-webkit-","-moz-"],sn={};function So(e,t){return CSS.supports(e+t,"unset")}function Vg(e){let t=sn[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return sn[e]=null,null;case"text-combine-upright":if(So("-webkit-","text-combine")&&!So("","text-combine-upright"))return sn[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of hc)if(So(i,e))return t=[i+e],sn[e]=t,t;return j.warn("Property not supported by the browser: ",e),sn[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=Vg(t);if(r)for(let o of r){switch(o){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(o,i)}}function bi(e,t,i){try{let n=sn[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function da(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 pi=class{constructor(){d(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function pl(e){return`\\${e.charCodeAt(0).toString(16)} `}function ki(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,pl)}function Or(e){return e.replace(/[\u0000-\u001F"\\]/g,pl)}function gh(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function mh(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Ug(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function uc(e,t){function i(n){return Ug(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Wo(e){return uc(e)}function $g(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Hg(e,t){t=typeof t=="string"?t:"\\u";function i(r){return $g(r,t)}let n=new RegExp(`${Wo(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function fi(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function cc(e,t){return e-t}function wh(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Wg(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function js(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function Gg(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var fl=class{constructor(){d(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},$i={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function dc(){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 pc(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 jg=dc(),yh={PENDING:{}};function fc(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Xg(e){return`"${Or(`${e}`)}"`}function qg(e){return ki(`${e}`)}function pa(e,t){return e?`${ki(e)}.${ki(t)}`:ki(t)}var gc=0,Go=class{constructor(e,t){if(this.parent=e,this.resolver=t,d(this,"scopeKey"),d(this,"children",[]),d(this,"zero"),d(this,"one"),d(this,"_true"),d(this,"_false"),d(this,"values",{}),d(this,"funcs",{}),d(this,"builtIns",{}),this.scopeKey=`S${gc++}`,this.zero=new et(this,0),this.one=new et(this,1),this._true=new et(this,!0),this._false=new et(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=fc,i["css-string"]=Xg,i["css-name"]=qg,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Le(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 Yg(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function mc(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 Zg(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Kg(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var jt={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 wc(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 fa=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,d(this,"actualPageWidth",null),d(this,"pageWidth"),d(this,"actualPageHeight",null),d(this,"pageHeight"),d(this,"initialFontSize"),d(this,"rootFontSize",null),d(this,"isRelativeRootFontSize",null),d(this,"fontSize"),d(this,"rootLineHeight",null),d(this,"pref"),d(this,"scopes",{}),d(this,"pageAreaWidth",null),d(this,"pageAreaHeight",null),d(this,"pageVertical",null),d(this,"pubTitle",null),d(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=jg}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(mc(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:jt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let o=e.builtIns[t];if(o){if(n)return e.zero;let s=Array(i.length);for(let a=0;a<i.length;a++)s[a]=i[a].evaluate(this);return new et(e,o.apply(this,s))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&t==null)return o!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Ht=class{constructor(e){this.scope=e,d(this,"key"),this.scope=e,this.key=`_${gc++}`}toString(){let e=new pi;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===yh.PENDING?!1:n;{i[this.key]=yh.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},yc=class extends Ht{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)}},xs=class extends Ht{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)}},vc=class extends xs{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Vn=class extends xs{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},bc=class extends xs{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},gl=class extends xs{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ei=class extends yc{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Jg=class extends Ei{constructor(e,t){super(e,t)}getOp(){return"not "}},mn=class extends yc{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},ml=class extends vc{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Qg=class extends ml{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},wl=class extends vc{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},em=class extends wl{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},tm=class extends wl{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},im=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},nm=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},rm=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},ga=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},yl=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},om=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},xc=class extends bc{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Sc=class extends bc{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},vl=class extends gl{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Cc=class extends gl{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},kc=class extends gl{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Br=class extends Ht{constructor(e,t,i){var n;super(e),this.num=t,d(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(ki(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Ke=class extends Ht{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)}},vh=class extends Ht{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(ki(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Le=class extends Ht{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 sm(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function am(e,t,i){let n=t;for(let r=0;r<t.length;r++){let o=t[r].expand(e,i);if(t!==n)n[r]=o;else if(o!==t[r]){n=Array(t.length);for(let s=0;s<r;s++)n[s]=t[s];n[r]=o}}return n}var ur=class Ec extends Ht{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),sm(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=am(t,this.params,i);return n===this.params?this:new Ec(this.scope,this.qualifiedName,n)}},lm=class Pc extends Ht{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),o=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new Pc(this.scope,n,r,o)}},et=class extends Ht{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(Or(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},bh=class Nc extends Ht{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(Or(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 Nc(this.scope,this.name,n)}},hm=class extends Ht{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Tc=class extends Ht{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 zt(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 ml(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new xc(e,t,i)}function ye(e,t,i){return t===e.zero?new mn(e,i):i===e.zero?t:new Sc(e,t,i)}function Co(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new vl(e,t,i)}function ma(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Cc(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}},Ki=class extends Xt{constructor(){super(),d(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let o=0;o<i;o++)t[o]=e[o];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new te(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new rt(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new oi(e.name,t)}visitExpr(e){return e}},ot=class{toString(){let e=new pi;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new pi;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},Ic=class Ac extends ot{static get instance(){return this.empty||(this.empty=new Ac),this.empty}constructor(){super()}toExpr(t,i){return new et(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};d(Ic,"empty");var um=Ic,Be=um.instance,Fc=class Rc extends ot{static get instance(){return this.slash||(this.slash=new Rc),this.slash}constructor(){super()}toExpr(t,i){return new et(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};d(Fc,"slash");var cm=Fc,Un=cm.instance,X=class extends ot{constructor(e){super(),this.str=e}toExpr(e,t){return new et(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(Or(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},wa=Object.create(null),ae=class extends ot{constructor(e){if(super(),this.name=e,wa[e])throw new Error("E_INVALID_CALL");wa[e]=this}toExpr(e,t){return new et(e,this.name)}appendTo(e,t){t?e.append(ki(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function M(e){let t=wa[e];return t||(t=new ae(e)),t}var R=class extends ot{constructor(e,t){var i;super(),this.num=e,d(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new vl(e,t,new et(e,this.num/100)):new Br(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},Nt=class extends ot{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new et(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},lt=class extends Nt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Lc=class extends ot{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},tt=class extends ot{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(Or(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Oc=class extends ot{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function bl(e,t,i,n){var r,o;let s=t.length;if(s>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<s;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var te=class extends ot{constructor(e){super(),this.values=e}appendTo(e,t){bl(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},rt=class extends ot{constructor(e){super(),this.values=e}appendTo(e,t){bl(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},oi=class extends ot{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(ki(this.name)),e.append("("),bl(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},G=class extends ot{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof et||this.expr instanceof Br?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},an=class extends ot{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function ut(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 Bc(e,t){return new R(ut(e,t),"px")}var y={absolute:M("absolute"),all:M("all"),always:M("always"),anywhere:M("anywhere"),auto:M("auto"),avoid:M("avoid"),balance:M("balance"),balance_all:M("balance-all"),block:M("block"),block_end:M("block-end"),block_start:M("block-start"),both:M("both"),bottom:M("bottom"),border_box:M("border-box"),break_all:M("break-all"),break_word:M("break-word"),clip:M("clip"),crop:M("crop"),cross:M("cross"),column:M("column"),discard:M("discard"),exclusive:M("exclusive"),_false:M("false"),fixed:M("fixed"),flex:M("flex"),flow_root:M("flow-root"),footnote:M("footnote"),footer:M("footer"),grid:M("grid"),header:M("header"),hidden:M("hidden"),horizontal_tb:M("horizontal-tb"),inherit:M("inherit"),initial:M("initial"),inline:M("inline"),inline_block:M("inline-block"),inline_end:M("inline-end"),inline_start:M("inline-start"),inside:M("inside"),keep:M("keep"),landscape:M("landscape"),left:M("left"),line:M("line"),list_item:M("list-item"),ltr:M("ltr"),manual:M("manual"),max_content:M("max-content"),min_content:M("min-content"),none:M("none"),normal:M("normal"),oeb_page_foot:M("oeb-page-foot"),oeb_page_head:M("oeb-page-head"),outside:M("outside"),padding_box:M("padding-box"),page:M("page"),relative:M("relative"),revert:M("revert"),right:M("right"),same:M("same"),scale:M("scale"),snap_block:M("snap-block"),snap_inline:M("snap-inline"),solid:M("solid"),spread:M("spread"),_static:M("static"),rtl:M("rtl"),table:M("table"),table_caption:M("table-caption"),table_cell:M("table-cell"),table_footer_group:M("table-footer-group"),table_header_group:M("table-header-group"),table_row:M("table-row"),top:M("top"),transparent:M("transparent"),unset:M("unset"),vertical_lr:M("vertical-lr"),vertical_rl:M("vertical-rl"),visible:M("visible"),_true:M("true")},xh=new R(100,"%"),Mr=new R(100,"pvw"),_r=new R(100,"pvh"),Re=new R(0,"px"),BS=new Oc("U+0-10FFFF"),Sh={"font-size":1,"line-height":2,color:3};function q(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function Ch(e,t){let i=Sh[e]||Number.MAX_VALUE,n=Sh[t]||Number.MAX_VALUE;return i-n}function je(e){return e?.length>2&&e.startsWith("--")}var ln,hn,un,Mc=class si{constructor(t,i,n){ee(this,ln),ee(this,hn),ee(this,un),fe(this,ln,Math.round(Math.max(0,Math.min(t,si.MAX)))),fe(this,hn,Math.round(Math.max(0,Math.min(i,si.MAX)))),fe(this,un,Math.round(Math.max(0,Math.min(n,si.MAX))))}static fromInt(t,i,n){return new si(t,i,n)}offset(t,i,n){return new si(U(this,ln)+t,U(this,hn)+i,U(this,un)+n)}toKey(){return JSON.stringify([U(this,ln),U(this,hn),U(this,un)])}toColorFunc(t){return new oi("color",[new te([M("srgb"),new Nt(U(this,ln)/si.MAX),new Nt(U(this,hn)/si.MAX),new Nt(U(this,un)/si.MAX),...t!==null?[Un,new Nt(t)]:[]])])}};ln=new WeakMap,hn=new WeakMap,un=new WeakMap,d(Mc,"MAX",1e4);var li=Mc;function dm(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Mi,_i,Di,Yt,_c=class gt{constructor(t,i,n,r){ee(this,Mi),ee(this,_i),ee(this,Di),ee(this,Yt),fe(this,Mi,Math.round(Math.max(0,Math.min(t,gt.MAX)))),fe(this,_i,Math.round(Math.max(0,Math.min(i,gt.MAX)))),fe(this,Di,Math.round(Math.max(0,Math.min(n,gt.MAX)))),fe(this,Yt,Math.round(Math.max(0,Math.min(r,gt.MAX))))}static fromInt(t,i,n,r){return new gt(t,i,n,r)}static fromNumber(t,i,n,r){return new gt(t*gt.MAX,i*gt.MAX,n*gt.MAX,r*gt.MAX)}toSRGB(){let t=gt.MAX-U(this,Yt);return li.fromInt(li.MAX-Math.min(li.MAX,Math.round(U(this,Mi)*t/gt.MAX)+U(this,Yt)),li.MAX-Math.min(li.MAX,Math.round(U(this,_i)*t/gt.MAX)+U(this,Yt)),li.MAX-Math.min(li.MAX,Math.round(U(this,Di)*t/gt.MAX)+U(this,Yt)))}equals(t){return U(this,Mi)===U(t,Mi)&&U(this,_i)===U(t,_i)&&U(this,Di)===U(t,Di)&&U(this,Yt)===U(t,Yt)}toJSON(){return{c:U(this,Mi),m:U(this,_i),y:U(this,Di),k:U(this,Yt)}}};Mi=new WeakMap,_i=new WeakMap,Di=new WeakMap,Yt=new WeakMap,d(_c,"MAX",1e4);var Dc=_c;function nn(e){return e instanceof Nt?Math.max(0,Math.min(1,e.num)):e instanceof R&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function zc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof te?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=nn(t[0]),n=nn(t[1]),r=nn(t[2]),o=nn(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===Un){if(t.length!==6)return null;s=nn(t[5])}else{if(t.length!==5)return null;s=nn(t[4])}if(s===null)return null}return{cmyk:Dc.fromNumber(i,n,r,o),alpha:s}}function*pm(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var vi,jo,Vc,kh,Uc=class{constructor(){ee(this,jo),ee(this,vi,new Map)}registerDeviceCmyk(e){let t=zc(e);return t?se(this,jo,Vc).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=li.fromInt(t.r,t.g,t.b),r=Dc.fromInt(i.c,i.m,i.y,i.k);U(this,vi).set(n.toKey(),r)}}toJSON(){let e={};return U(this,vi).forEach((t,i)=>{e[i]=t.toJSON()}),e}};vi=new WeakMap,jo=new WeakSet,Vc=function(e){let t=e.toSRGB(),i=t.toKey(),n=U(this,vi).get(i);return n?n.equals(e)?t:se(this,jo,kh).call(this,e,t):(U(this,vi).set(i,e),t)},kh=function(e,t){for(let i=1;i<=li.MAX;i++)for(let[n,r,o]of pm(i)){let s=t.offset(n,r,o),a=s.toKey();if(!U(this,vi).has(a))return U(this,vi).set(a,e),s}return j.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var ko,tr,ir,$c=class extends Ki{constructor(e){super(),ee(this,ko),ee(this,tr,new Map),ee(this,ir,!1),fe(this,ko,e??new Uc)}reset(){fe(this,ir,!1)}hadDeviceCmyk(){return U(this,ir)}recordConversion(e,t){U(this,tr).set(e,t)}getConversions(){if(U(this,tr).size===0)return null;let e={};return U(this,tr).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=U(this,ko).registerDeviceCmyk(e);return t?(fe(this,ir,!0),t):super.visitFunc(e)}};ko=new WeakMap,tr=new WeakMap,ir=new WeakMap;function Hc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function fm(e){return`^${e}`}function Eh(e){return e.replace(/[\[\]\(\),=;^]/g,fm)}function gm(e){return e.substr(1)}function ya(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,gm)}function mm(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=ya(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Ph(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=mm(i[2]),e=e.substr(i[0].length)}return t}var Nh=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Th=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?e.after=!0:r=s}e.node=r}if(this.id&&(e.after||this.id!=Hc(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:j.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Ih=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(t<=o)break;if(!r){t=o;break}t-=o}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Eh(this.textBefore)),e.append(","),this.textAfter&&e.append(Eh(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Ah=class Wc{constructor(){d(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,o=[];for(;;){let s;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];s=Ph(i[4]),o.push(new Th(a,h,fh(s.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=ya(h));let l=i[7];l&&(l=ya(l)),s=Ph(i[10]),o.push(new Ih(a,h,l,fh(s.s)));break}case"!":r++,o.push(new Nh);break;case"~":case"@":case"":this.steps=o;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new Wc,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let o=[],s=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new Ih(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:Hc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new Th(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Nh),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new pi;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")}},Lt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},xi=class{constructor(e,t){this.x=e,this.y=t}},Xs=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Fh=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},ci=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,d(this,"left",null),d(this,"right",null)}};function wm(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Ss=class Gc{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new Fh(o,a,1,i):h=new Fh(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new xi(r.x+t,r.y+i));return new Gc(n)}};function Rh(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new xi(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Ss(r)}function xl(e,t,i,n){return new Ss([new xi(e,t),new xi(i,t),new xi(i,n),new xi(e,n)])}var eo=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Lh(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 ym(e,t,i,n){let r,o,s,a;t.high.y<i&&j.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Lh(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=Lh(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new eo(r,o,t.shapeId,-1)),e.push(new eo(s,a,t.shapeId,1))):(e.push(new eo(s,a,t.shapeId,-1)),e.push(new eo(r,o,t.shapeId,1)))}function vm(e,t,i){let n=t+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let c=e[u];r[c.shapeId]+=c.winding,o[c.shapeId]+=c.lowOrHigh;let p=!1;for(s=0;s<t;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=t;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(c.x),h=p)}return a}function bm(e,t){return t?Math.ceil(e/t)*t:e}function Oh(e,t){return t?Math.floor(e/t)*t:e}function xm(e){return new xi(e.y,-e.x)}function Xo(e){return new Lt(e.y1,-e.x2,e.y2,-e.x1)}function jc(e){return new Lt(-e.y2,e.x1,-e.y1,e.x2)}function Bh(e){return new Ss(e.points.map(t=>xm(t)))}function Sm(e,t,i,n,r,o){o&&(e=Xo(e),t=t.map(v=>Bh(v)),i=i.map(v=>Bh(v)));let s=t.length,a=i?i.length:0,h=[],l=[],u,c,p;for(u=0;u<s;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+s);let f=l.length;l.sort(wm);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>e.y1&&h.push(new ci(e.y1,m,e.x2,e.x2));let w=0,S=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&S.push(p),w++;for(;w<f||S.length>0;){let v=e.y2,b=Math.min(bm(Math.ceil(m+n),r),e.y2);for(c=0;c<S.length&&v>b;c++)p=S[c],p.low.x==p.high.x?p.high.y<v&&(v=Math.max(Oh(p.high.y,r),b)):p.low.x!=p.high.x&&(v=b);for(v>e.y2&&(v=e.y2);w<f&&(p=l[w]).low.y<v;){if(p.high.y<m){w++;continue}if(p.low.y<b)p.low.y==p.high.y&&p.low.y==m||(S.push(p),v=b),w++;else{let N=Oh(p.low.y,r);N<v&&(v=N);break}}let x=[];for(c=0;c<S.length;c++)ym(x,S[c],m,v);x.sort((N,F)=>N.x-F.x||N.lowOrHigh-F.lowOrHigh);let C=vm(x,s,a);if(C.length==0)h.push(new ci(m,v,e.x2,e.x2));else{let N=0,F=e.x1;for(c=0;c<C.length;c+=2){let L=Math.max(e.x1,C[c]),V=Math.min(e.x2,C[c+1])-L;V>N&&(N=V,F=L)}N==0?h.push(new ci(m,v,e.x2,e.x2)):h.push(new ci(m,v,Math.max(F,e.x1),Math.min(F+N,e.x2)))}if(v==e.y2)break;for(m=v,c=S.length-1;c>=0;c--)S[c].high.y<=v&&S.splice(c,1)}return Xc(e,h),h}function Xc(e,t){let i=t.length-1,n=new ci(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function qc(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function Cm(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)o=n.y2;return r===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new Lt(t.x1,i,t.x2,o)}function km(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new Lt(t.x1,o,t.x2,i)}function Em(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=qc(t,r);for(;;){let h=r+s;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let c=a;c<t.length&&t[c].y1<h;c++){let p=t[c];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+o<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=u-o,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Pm(e,t,i,n,r){for(n||(n=[new ci(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let o,s=t.length==0?e.y1:t[t.length-1].y2;s<e.y2&&t.push(new ci(s,e.y2,e.x1,e.x2));let a=qc(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 ci(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 ci(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}Xc(e,t)}var Nm=class extends Xt{constructor(){super(),d(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Tm(e){if(e){let t=new Nm;try{return e.visit(t),t.propSet}catch(i){j.warn(i,"toSet:")}}return{}}var Im=class extends Xt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Mh(e,t){if(e){let i=new Im(t);try{return e.visit(i),i.value}catch(n){j.warn(n,"toInt: ")}}return t}var Am=class extends Xt{constructor(){super(),d(this,"collect",!1),d(this,"coords",[]),d(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new R(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new xi(e+o[a],t+o[a+1]));return new Ss(s)}break;case"rectangle":if(o.length==4)return xl(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return Rh(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return Rh(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function Yc(e,t,i,n,r,o){if(e){let s=new Am;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){j.warn(a,"toShape:")}}return xl(t,i,t+n,i+r)}var Fm=class extends Xt{constructor(e,t){super(),this.reset=e,this.defaultValue=t,d(this,"counters",Object.create(null)),d(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function En(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new Fm(r,o);try{e.visit(s)}catch(a){j.warn(a,"toCounters:")}return s.counters}var Rm=class extends Ki{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new tt(Sr(this.transformer.transformURL(e.url,this.baseUrl)))}};function Fi(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Lm(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function wn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let o=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(s=>Lm(s.substring(1,s.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Om=class{constructor(e,t){this.targetId=e,this.resolved=t,d(this,"pageCounters",null),d(this,"spineIndex",-1),d(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Bm=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()}},Mm=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,d(this,"styler",null),d(this,"namedStringValues",Object.create(null)),d(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ae(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 Le(this.pageScope,()=>t(i()),`page-counter-${e}`),r=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Le(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],o=r.length?r[r.length-1]:0,s=n?.[e]||[],a=s.length?s[0]:0;return t.length?[o+(t[0]-a),...t.slice(1)]:[o]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?wn(n,t):wn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),o=new Le(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[t]){let a=s[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Le(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,o,h);if(l.length)return i(l);let u=o[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Le(this.pageScope,()=>{if(t==="first-letter"){let o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match($o);return l?l[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Le(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Le(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(cc),o=this.counterStore.currentPage;if(!o)return"";let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${Qt}]`)).map(p=>parseInt(p.getAttribute(Qt),10))),h=-1,l=-1,u=-1,c=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,c=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${Qt}="${f}"]`);if(!w)l<0&&(l=f);else{let S=o.container.querySelector(`[${Qt}="${s}"]`);if(S||(S=o.container.querySelector(`[${Qt}="0"]`)),S){for(let v=S;v;v=v.firstElementChild)if(v===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=c=f)}return n[{first:h,start:l,last:u,"first-except":c}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},_m=class{constructor(e){this.documentURLTransformer=e,d(this,"countersById",Object.create(null)),d(this,"pageCountersById",Object.create(null)),d(this,"pageDocCountersById",Object.create(null)),d(this,"pageTextById",Object.create(null)),d(this,"currentPageDocCounters",null),d(this,"previousPageDocCounters",null),d(this,"currentPageDocCounterChanges",Object.create(null)),d(this,"currentPageDocCounterChangeTypes",Object.create(null)),d(this,"currentPageCounters",Object.create(null)),d(this,"previousPageCounters",Object.create(null)),d(this,"currentPageCountersStack",[]),d(this,"pageIndicesById",Object.create(null)),d(this,"currentPage",null),d(this,"newReferencesOfCurrentPage",[]),d(this,"referencesToSolve",[]),d(this,"referencesToSolveStack",[]),d(this,"unresolvedReferences",Object.create(null)),d(this,"resolvedReferences",Object.create(null)),d(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),d(this,"pagesCounterExprs",[]),d(this,"pageCounterExprs",[]),d(this,"targetCounterExprs",[]),d(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Bm(this,e)}createCounterResolver(e,t,i){return new Mm(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?Fi(this.currentPageDocCounters):null,this.currentPageDocCounters=e?Fi(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[e]}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Fi(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],S=w.length?w[w.length-1]:0,v=g[m]||[],b=v.length?v[v.length-1]:0,x=S-b,C=n[m],N=C==="reset"||C==="set";r[m]={delta:x,reset:N,value:S}}}let o=Object.create(null),s,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(s=En(g,{reset:!0}))}s&&"pages"in s&&delete s.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=En(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(s)for(let g in s)u.push(g);if(h)for(let g in h)u.push(g);let c,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(c=En(g))}c&&"pages"in c&&delete c.pages,c?!("page"in c)&&!(r.page&&r.page.reset)&&(c.page=1):(c=Object.create(null),r.page&&r.page.reset||(c.page=1));for(let g in c)u.push(g);this.setPageControlledCounterNames(u);let f=Fi(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],o[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,s)for(let g in s)this.definePageCounter(g,s[g]);for(let g in c){if(o[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=c[g]}if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Fi(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let o=this.referencesToSolve[r];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(r,1),t){let s=t.indexOf(o);s>=0&&t.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Om(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=Fi(this.currentPageCounters),s=this.currentPageDocCounters?Fi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:wn(u,"content"),before:wn(u,"before"),after:wn(u,"after"),marker:wn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let c=this.unresolvedReferences[a];c||(c=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),c.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.currentPage=null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(o=>o+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${Xn}]`);for(let n of i){let r=n.getAttribute(Xn),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let s=r.container.querySelectorAll(`[${jn}]`);for(let a of s){let h=a.getAttribute(jn),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,c=u?.replace(/^page-counters?-/,""),p=o[c];p&&(a.textContent=l.format(p))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(t=t.concat(o))}),t.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Le){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(`[${Qt}="${t}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(Xn,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(Ys,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?qs:jn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${jn}]`);for(let r of t){let o=r.getAttribute(jn),s=this.pageCounterExprs.find(u=>u.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=e.querySelectorAll(`[${Xn}]`);for(let r of i)r.setAttribute(_h,!0);let n=e.querySelectorAll(`[${Ys}]`);for(let r of n)r.setAttribute(Dh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${qs}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(qs),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${_h}]`);for(let s of r){let a=s.getAttribute(Xn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(s.textContent=h.format(u[u.length-1]))}}}let o=e.root.querySelectorAll(`[${Dh}]`);for(let s of o){let a=s.getAttribute(Ys),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Dm(this,e)}},qs="data-vivliostyle-pages-counter",jn="data-vivliostyle-page-counter",Xn="data-vivliostyle-target-counter",Ys="data-vivliostyle-target-text",_h="data-vivliostyle-target-counter-in-running",Dh="data-vivliostyle-target-text-in-running",Dm=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}},zm=new Set(["before","after","first-line","first-letter"]),zh=new Set(["media","supports","-epubx-when"]),Zc=new Set([";","}"]),Kc=new Set(["{",";","}"]),Vm=new Set([";","{","}"]),Um=":where(:scope)",$m=":where(:not(*))";function Hm(e){let{statements:t,changed:i}=va(e,0,e.length,null);return i?t.join(`
5
+ `):e}function va(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(Wm(n,o)):r.push(Jc(o)),o.length=0)};for(;a<i&&(a=qi(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let c=rw(e,a,i);if(!c)break;if(n&&!zh.has(c.name)){o.push(Ui(e.slice(a,c.end))),a=c.end;continue}if(h(),c.hasBlock&&zh.has(c.name)){let p=va(e,c.blockStart,c.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${c.header} {${Gm(p.statements)}}`)}else r.push(Ui(e.slice(a,c.end)));a=c.end;continue}if(n&&Zm(e,a,i)){let c=Qm(e,a,i);if(!c)break;o.push(Ui(c.text)),a=c.end;continue}h();let l=ew(e,a,i);if(!l){let c=ow(e,a,i);r.push(Ui(c.text)),a=c.end;continue}if(n&&tw(e,a,l)){let c=nw(e,a,l.end,i);o.push(Ui(c.text)),a=c.end;continue}let u=n?jm(n,l.prelude):Qc(l.prelude);if(u){s||(s=n!=null);let c=va(e,l.blockStart,l.blockEnd,u);s||(s=c.changed),c.statements.length===0?r.push(`${u} {}`):r.push(...c.statements)}a=l.end}return h(),{statements:r,changed:s}}function Wm(e,t){return`${e} { ${Jc(t)} }`}function Jc(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function Gm(e){return e.length===0?"":` ${e.join(" ")} `}function jm(e,t){let i=Xm(e);if(!i)return null;let n=td(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=ed(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function Qc(e){return ed(e.trim(),Um).text}function Xm(e){let t=td(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!qm(i));return t.length===0?null:`:is(${t.join(", ")})`}function qm(e){let t=0;for(;t<e.length;){let i=Cs(e,t);if(i!=null){t=i;continue}let n=Ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,o=Dr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(zm.has(s))return!0;t=o;continue}t++}return!1}function ed(e,t){let i=0,n=!1,r="",o=[],s=Ym(t);for(;i<e.length;){let a=Cs(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=Ji(e,i,e.length);if(h!=null){r+=e.slice(i,h),i=h;continue}let l=e[i];if(l===":"&&e[i+1]!==":"){let u=i+1,c=Dr(e,u,e.length);if(c>u&&e[c]==="("){o.push(e.slice(u,c).toLowerCase()),r+=e.slice(i,c+1),i=c+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?$m:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function Ym(e){let t=0;for(;t<e.length;){let i=Cs(e,t);if(i!=null){t=i;continue}let n=Ji(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,o=Dr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function td(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=Cs(e,r);if(a!=null){r=a;continue}let h=Ji(e,r,e.length);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function Zm(e,t,i){let n=t,r=Jm(e,n,i);if(r<=n)return!1;let o=qi(e,r,i);if(o>=i||e[o]!==":")return!1;let s=zr(e,o+1,i,Vm);return s?.char==="{"?!Km(e,t,r,o,s.index):!0}function Km(e,t,i,n,r){if(qi(e,i,r)!==n)return!1;let o=qi(e,n+1,r);if(o!==n+1||o>=r)return!1;let s=e[o];return s===":"||s==="\\"||/[A-Za-z_-]/.test(s)}function Jm(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Dr(e,n,i)}function Dr(e,t,i){let n=t;for(;n<i;){let r=e[n];if(r==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(r))break;n++}return n}function Qm(e,t,i){let n=zr(e,t,i,Zc);if(!n){let o=e.slice(t,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function ew(e,t,i){let n=zr(e,t,i,Kc);if(!n||n.char!=="{")return null;let r=id(e,n.index,i);return r<0?null:{prelude:Ui(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function tw(e,t,i){if(!iw(e,t,i.blockStart-1))return!0;let n=qi(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function iw(e,t,i){let n=qi(e,t,i);if(n>=i)return!1;let r=e[n];return r==="&"||r==="."||r==="#"||r===":"||r==="["||r==="|"||r==="*"||r===">"||r==="+"||r==="~"||r==="\\"||/[A-Za-z_-]/.test(r)}function nw(e,t,i,n){let r=qi(e,i,n),o=r<n&&e[r]===";"?r+1:i;return{text:e.slice(t,o),end:o}}function rw(e,t,i){let n=zr(e,t,i,Kc);if(!n)return null;let r=Dr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Ui(e.slice(t,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=id(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function ow(e,t,i){let n=zr(e,t,i,Zc);if(!n)return{text:e.slice(t,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r),end:r}}function zr(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=Ji(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function id(e,t,i){let n=t+1,r=1;for(;n<i;){let o=Ji(e,n,i);if(o!=null){n=o;continue}let s=e[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function qi(e,t,i){let n=t;for(;n<i;){let r=e[n];if(rd(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=nd(e,n,i);continue}break}return n}function nd(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function Ji(e,t,i){let n=e[t];return n==='"'||n==="'"?sw(e,t):n==="/"&&e[t+1]==="*"?nd(e,t,i):null}function Cs(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function sw(e,t){let i=e[t],n=t+1;for(;n<e.length;){let r=e[n];if(r==="\\"){n+=2;continue}if(r===i)return n+1;n++}return e.length}function rd(e){return e===" "||e===`
6
+ `||e==="\r"||e===" "||e==="\f"}function Ui(e){let t="",i=0,n=!1;for(;i<e.length;){let r=Ji(e,i,e.length);if(r!=null&&e[i]!=="/"){n&&t.length>0&&(t+=" ",n=!1),t+=e.slice(i,r),i=r;continue}if(r!=null){n=t.length>0,i=r;continue}let o=e[i];if(rd(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function aw(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 wi(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,aw)}var lw=class{constructor(){d(this,"type"),d(this,"precededBySpace",!1),d(this,"num",0),d(this,"text",""),d(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Je(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 Zt=[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];Zt[NaN]=80;var Kt=[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];Kt[NaN]=43;var hw=[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];Kt[NaN]=43;var od=[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];od[NaN]=35;var sd=[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];sd[NaN]=45;var ba=[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];ba[NaN]=37;var xa=[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];xa[NaN]=38;var Ri=Je(35,[61,36]),uw=Je(35,[58,77]),cw=Je(35,[61,36,124,50]),dw=Je(35,[38,51]),pw=Je(35,[42,54]),fw=Je(39,[42,55]),gw=Je(54,[42,55,47,56]),mw=Je(62,[62,82]),ww=Je(35,[61,36,33,70]),yw=Je(62,[45,71]),vw=Je(63,[45,81]),Zs=Je(76,[10,72,13,72]),bw=Je(39,[39,46,10,72,13,72,92,48]),xw=Je(39,[34,46,10,72,13,72,92,49]),Sw=Je(39,[39,47,10,74,13,74,92,48]),Cw=Je(39,[34,47,10,74,13,74,92,49]),Vh=Je(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),kw=Je(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]),Ew=Je(39,[39,68,10,74,13,74,92,75,NaN,67]),Pw=Je(39,[34,68,10,74,13,74,92,75,NaN,67]),Nw=Je(72,[9,39,10,39,13,39,32,39,41,69]),Tw=15,vt=class{constructor(e,t){this.input=e,this.handler=t,d(this,"indexMask"),d(this,"buffer"),d(this,"tail",0),d(this,"curr",0),d(this,"position",0),this.indexMask=Tw,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new lw}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=Zt,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",u=0,c=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,o),a=0):n===Zt&&a===0?(a=54,h=o,l=r.substring(o,o+1),o++):(l=r.substring(h,o),a=54),n=Zt;break;case 1:o++,c=!0;continue;case 2:h=o++,n=ba;continue;case 3:a=1,h=o++,n=Kt;continue;case 4:h=o++,a=31,n=Ri;continue;case 33:a=2,h=++o,n=bw;continue;case 34:a=2,h=++o,n=xw;continue;case 6:h=++o,a=7,n=Kt;continue;case 7:h=o++,a=32,n=Ri;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=dw;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Ri;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=od;continue;case 16:h=o++,n=hw;continue;case 78:h=o++,a=9,n=Kt;continue;case 17:h=o++,a=19,n=pw;continue;case 18:h=o++,a=18,n=uw;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=ww;continue;case 21:h=o++,a=39,n=Ri;continue;case 22:h=o++,a=37,n=Ri;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=Kt;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=Zs;continue;case 30:h=o++,a=33,n=Ri;continue;case 31:h=o++,a=34,n=cw;continue;case 32:h=o++,a=35,n=Ri;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,o),10);break;case 38:a=4,u=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,u=parseFloat(r.substring(h,o)),h=o++,n=Kt;continue;case 41:a=3,u=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=xa;continue;case 43:if(l=wi(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=Zs;continue;case 45:l=wi(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=wi(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=Sw;continue;case 49:f=o,o+=2,n=Cw;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=Vh;continue}a=6}break;case 53:if(l=wi(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=Vh;continue}a=6}break;case 54:n=fw,o++;continue;case 55:n=gw,o++;continue;case 56:n=Zt,o++;continue;case 57:n=mw,o++,r[o]!==">"&&(a=1,n=Kt);continue;case 81:a=51,l=r.substring(h,++o),n=Zt;break;case 82:a=52,l=r.substring(h,++o),n=Zt;break;case 58:a=5,n=ba,o++;continue;case 59:a=4,n=xa,o++;continue;case 60:a=1,n=Kt,o++;continue;case 61:a=1,n=Zs,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=kw;continue;case 65:h=++o,n=Ew;continue;case 66:h=++o,n=Pw;continue;case 67:a=8,l=wi(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=yw,o++;continue;case 71:n=vw,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=wi(r.substring(h,o)),o++,n=Nw;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Zt;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=Kt;continue}l=wi(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=sd;continue;default:if(n!==Zt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=c,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Zt,c=!1,a=0,h=o,l="",u=0,p=s[e&i]}this.position=o,this.tail=e&i}},qe=null,Sa=null;function Ca(){return qe}function D(e){if(!qe)throw new Error("E_TASK_NO_CONTEXT");qe.name||(qe.name=e);let t=qe,i=new ks(t,t.top,e);return t.top=i,i.state=1,i}function Iw(e){return new Rw(e||new Fw)}function T(e){return new ka(e)}function Fn(e,t,i){let n=D(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Aw(e,t){return(qe?qe.getScheduler():Sa||Iw()).run(e,t)}var Fw=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Rw=class{constructor(e){this.timer=e,d(this,"timeout",1),d(this,"slice",25),d(this,"sliceOverTime",0),d(this,"queue"),d(this,"wakeupTime",null),d(this,"timeoutToken",null),d(this,"inTimeSlice",!1),d(this,"order",0),this.queue=new zg,Sa||(Sa=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){j.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Lw(this,t||"");i.top=new ks(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){j.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=qe;return qe=i,this.schedule(i.top.suspend("bootstrap")),qe=n,i}},ad=class{constructor(e){this.task=e,d(this,"scheduledTime",0),d(this,"order",0),d(this,"result",null),d(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=qe;return qe=e,e.top.finish(this.result),qe=t,!0}return!1}cancel(){this.canceled=!0}},Lw=class{constructor(e,t){this.scheduler=e,this.name=t,d(this,"callbacks",[]),d(this,"exception",null),d(this,"running",!0),d(this,"result",null),d(this,"waitTarget",null),d(this,"top",null),d(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==qe&&this.continuation){this.continuation.cancel();let t=new ad(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=D("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&j.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
7
7
  ---- async ---
8
8
  `:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
9
- `;e.frameTrace=t}}},Zs=class Bc{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Bc(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Km=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Qo(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return t.state=1,this.frame.parent=t,this.frame.then(i=>{e(i).then(n=>{t.finish(n)})}),t.result()}else return e(this.frame.res)}thenReturn(e){return this.isPending()?this.thenAsync(()=>new Zs(e)):new Zs(e)}thenFinish(e){this.isPending()?this.then(t=>{e.finish(t)}):e.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Qo=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,c(this,"res",null),c(this,"state"),c(this,"callback",null),c(this,"handler",null),this.state=0}checkEnvironment(){if(!Xe)throw new Error("F_TASK_NO_CONTEXT");if(this!==Xe.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Km(this)}finish(e){this.checkEnvironment(),Xe&&!Xe.exception&&(this.res=e),this.state=2;let t=this.parent;if(Xe&&(Xe.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=D("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(j.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=D("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=D("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Xe;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Jm(t,t.top);t.top=n,n.state=1,e(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(e){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let t=new Oc(this.task);return this.task.continuation=t,Xe=null,this.task.waitTarget=e||null,t}},Jm=class extends Qo{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Ar=class{constructor(e,t){this.fetch=e,c(this,"name"),c(this,"arrived",!1),c(this,"resource",null),c(this,"task",null),c(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Ys().getScheduler().run(()=>{let e=D("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){j.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},En=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=D("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()},Mc=`
9
+ `;e.frameTrace=t}}},ka=class ld{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new ld(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Ow=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new ks(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 ka(e)):new ka(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}},ks=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,d(this,"res",null),d(this,"state"),d(this,"callback",null),d(this,"handler",null),this.state=0}checkEnvironment(){if(!qe)throw new Error("F_TASK_NO_CONTEXT");if(this!==qe.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Ow(this)}finish(e){this.checkEnvironment(),qe&&!qe.exception&&(this.res=e),this.state=2;let t=this.parent;if(qe&&(qe.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=D("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(j.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=D("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=D("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=qe;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Bw(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 ad(this.task);return this.task.continuation=t,qe=null,this.task.waitTarget=e||null,t}},Bw=class extends ks{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Vr=class{constructor(e,t){this.fetch=e,d(this,"name"),d(this,"arrived",!1),d(this,"resource",null),d(this,"task",null),d(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Ca().getScheduler().run(()=>{let e=D("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){j.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},Rn=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=D("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()},hd=`
10
10
  @media screen {
11
11
  [data-vivliostyle-viewer-viewport] {
12
12
  background: #aaaaaa;
@@ -75,7 +75,7 @@ var Tf=Object.create;var Ur=Object.defineProperty;var If=Object.getOwnPropertyDe
75
75
  transform-origin: center top;
76
76
  }
77
77
  }
78
- `,_c=`
78
+ `,ud=`
79
79
  [data-vivliostyle-layout-box] {
80
80
  position: absolute;
81
81
  left: 0;
@@ -198,7 +198,7 @@ var Tf=Object.create;var Ur=Object.defineProperty;var If=Object.getOwnPropertyDe
198
198
  break-after: page;
199
199
  }
200
200
  }
201
- `,Dc=`
201
+ `,cd=`
202
202
  /*
203
203
  * Copyright 2013 Google, Inc.
204
204
  * Copyright 2015 Daishinsha Inc.
@@ -264,8 +264,6 @@ caption-side = top | bottom;
264
264
  clip = rect(ALENGTH{4}) | rect(SPACE(ALENGTH{4})) | auto;
265
265
  color = COLOR;
266
266
  LIST_STYLE_TYPE = IDENT;
267
- TYPE_OR_UNIT_IN_ATTR = string | color | url | integer | number | length | angle | time | frequency;
268
- ATTR = attr(SPACE(IDENT TYPE_OR_UNIT_IN_ATTR?) [ STRING | IDENT | COLOR | INT | NUM | PLENGTH | ANGLE | POS_TIME | FREQUENCY]?);
269
267
  CONTENT_LIST = [ STRING | URI | counter(IDENT LIST_STYLE_TYPE?) |
270
268
  counters(IDENT STRING LIST_STYLE_TYPE?) | ATTR |
271
269
  target-counter([ STRING | URI ] IDENT LIST_STYLE_TYPE?) |
@@ -831,7 +829,7 @@ word-wrap = overflow-wrap;
831
829
  [adapt,webkit]start = inline-start;
832
830
  [adapt,webkit]end = inline-end;
833
831
 
834
- `,zc=`
832
+ `,dd=`
835
833
  <!DOCTYPE html>
836
834
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
837
835
  <head>
@@ -855,7 +853,7 @@ word-wrap = overflow-wrap;
855
853
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
856
854
 
857
855
  </body>
858
- </html>`,Vc=`
856
+ </html>`,pd=`
859
857
  @namespace "http://www.w3.org/1999/xhtml";
860
858
 
861
859
  :root {
@@ -978,7 +976,7 @@ word-wrap = overflow-wrap;
978
976
  margin: 10%;
979
977
  }
980
978
  }
981
- `,Uc=String.raw`
979
+ `,fd=String.raw`
982
980
  @namespace "http://www.w3.org/1999/xhtml";
983
981
  @namespace m "http://www.w3.org/1998/Math/MathML";
984
982
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1244,10 +1242,10 @@ ol[type=a], li[type=a] { list-style-type: lower-alpha; }
1244
1242
  ol[type=A], li[type=A] { list-style-type: upper-alpha; }
1245
1243
  ol[type=i], li[type=i] { list-style-type: lower-roman; }
1246
1244
  ol[type=I], li[type=I] { list-style-type: upper-roman; }
1247
- ul[type=none], li[type=none] { list-style-type: none; }
1248
- ul[type=disc], li[type=disc] { list-style-type: disc; }
1249
- ul[type=circle], li[type=circle] { list-style-type: circle; }
1250
- ul[type=square], li[type=square] { list-style-type: square; }
1245
+ ul[type=none i], li[type=none i] { list-style-type: none; }
1246
+ ul[type=disc i], li[type=disc i] { list-style-type: disc; }
1247
+ ul[type=circle i], li[type=circle i] { list-style-type: circle; }
1248
+ ul[type=square i], li[type=square i] { list-style-type: square; }
1251
1249
  u,
1252
1250
  ins {
1253
1251
  text-decoration: underline;
@@ -1409,7 +1407,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1409
1407
  epub|case[required-namespace::supported] ~ epub|default {
1410
1408
  display: none;
1411
1409
  }
1412
- `,$c=`
1410
+ `,gd=`
1413
1411
  @namespace "http://www.w3.org/1999/xhtml";
1414
1412
 
1415
1413
  *:not([data-vivliostyle-role=doc-toc],
@@ -1439,7 +1437,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1439
1437
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1440
1438
  -adapt-behavior: toc-container;
1441
1439
  }
1442
- `,Hc=`
1440
+ `,md=`
1443
1441
  [data-viv-margin-discard~="block-start"] {
1444
1442
  margin-block-start: 0 !important;
1445
1443
  }
@@ -1641,7 +1639,7 @@ span[data-viv-leader] {
1641
1639
  -webkit-initial-letter: var(--viv-initialLetter);
1642
1640
  initial-letter: var(--viv-initialLetter);
1643
1641
  }
1644
- `,Wc=String.raw`
1642
+ `,wd=String.raw`
1645
1643
  @counter-style decimal-leading-zero {
1646
1644
  system: extends decimal;
1647
1645
  pad: 2 '0';
@@ -1865,12 +1863,12 @@ span[data-viv-leader] {
1865
1863
  @counter-style upper-russian {
1866
1864
  system: alphabetic;
1867
1865
  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;
1868
- }`;function es(e,t,i){let n=D("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(s.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(s.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?s.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=Gc([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?j.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):j.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function Gc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Qm(e){let t=D("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function ew(e){return URL.createObjectURL(e)}var il=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Bt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=D("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let o=Ie("user-agent.xml",vi),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(zc)}`),es(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):s&&(a.url=e=o),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Bt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Ar(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Bt(e)]}delete(e){delete this.resources[Bt(e)]}};function tw(e,t){let i=e.responseText;return T(i?ja(i):null)}function iw(){return new il(tw,"text")}function vt(e,t,i){let n=new Ar(()=>{let r=D("loadElement"),o=r.suspend(e),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);else(e.localName==="img"||e.localName==="embed"||e.localName==="object"||e.localName==="iframe")&&(e.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4));return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var wh=0,nw=16777216,jc=33554432,Xc=50331648,qc=67108864,rw=83886080,ow=100663296,ts=class{constructor(e){this.scope=e,c(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return wh;case"User":return ow;default:return rw}}getBaseSpecificity(){switch(this.flavor){case"UA":return wh;case"User":return nw;default:return jc}}},Ks=class extends ts{constructor(){super(null),c(this,"stack",[]),c(this,"tokenizer",null),c(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;j.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},yh=class extends ts{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,c(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Xi=class extends yh{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new yh(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},ze=[],No=[],xe=[],Be=[],Lt=[],ot=[],De=[],Ye=[],be=[],Je=[],lt=[],Ge=[],_e=[],rn=55,on=56,Gr=57;ze[1]=28,ze[36]=29,ze[7]=29,ze[9]=29,ze[14]=29,ze[18]=29,ze[50]=29,ze[20]=30,ze[13]=27,ze[0]=200,No[1]=46,No[0]=200,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[14]=10,ot[18]=14,ot[50]=42,xe[37]=11,xe[23]=12,xe[35]=56,xe[1]=1,xe[36]=3,xe[7]=5,xe[9]=7,xe[14]=9,xe[12]=13,xe[18]=55,xe[50]=58,xe[16]=41,Be[37]=11,Be[23]=12,Be[35]=56,Be[1]=1,Be[36]=3,Be[7]=5,Be[9]=7,Be[14]=9,Be[18]=55,Lt[1]=2,Lt[36]=4,Lt[7]=6,Lt[9]=8,Lt[18]=14,Lt[50]=42,Lt[14]=10,Lt[12]=13,De[1]=15,De[7]=16,De[4]=17,De[5]=18,De[3]=19,De[2]=20,De[8]=21,De[27]=57,De[16]=22,De[19]=23,De[6]=24,De[11]=25,De[17]=26,De[13]=48,De[31]=47,De[23]=54,De[0]=44,Ye[1]=31,Ye[4]=32,Ye[5]=32,Ye[3]=33,Ye[2]=34,Ye[10]=40,Ye[6]=38,Ye[31]=36,Ye[24]=36,Ye[32]=35,be[1]=45,be[16]=37,be[37]=37,be[38]=37,be[47]=37,be[48]=37,be[39]=37,be[49]=37,be[41]=37,be[26]=37,be[25]=37,be[23]=37,be[24]=37,be[19]=37,be[21]=37,be[36]=37,be[18]=37,be[22]=37,be[11]=39,be[12]=43,be[17]=49,Je[0]=200,Je[12]=50,Je[13]=51,Je[14]=50,Je[15]=51,Je[10]=50,Je[11]=51,Je[17]=53,lt[0]=200,lt[12]=50,lt[13]=52,lt[14]=50,lt[15]=51,lt[10]=50,lt[11]=51,lt[17]=53,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,_e[11]=0,_e[16]=0,_e[22]=1,_e[18]=1,_e[26]=2,_e[25]=2,_e[38]=3,_e[37]=3,_e[48]=3,_e[47]=3,_e[39]=3,_e[49]=3,_e[41]=3,_e[23]=4,_e[24]=4,_e[36]=5,_e[19]=5,_e[21]=5,_e[0]=6,_e[rn]=2,_e[on]=2;var Fr=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,c(this,"valStack",[]),c(this,"namespacePrefixToURI",{}),c(this,"defaultNamespaceURI",null),c(this,"propName",null),c(this,"propImportant",!1),c(this,"exprContext"),c(this,"result",null),c(this,"importReady",!1),c(this,"importURL",null),c(this,"importCondition",null),c(this,"errorBrackets",[]),c(this,"ruleStack",[]),c(this,"regionRule",!1),c(this,"pageRule",!1),c(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Y)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],e===")"&&o instanceof Qi){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new J(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=lt);let h=new ci(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof de&&h.values[0].name;(!Qt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=lt)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=lt,null;if(s>1)return new it(this.extractVals(",",n+1));let a=i[0];return a instanceof nt?a:a?new Qi(a.toString()):Y}exprError(e,t){this.actions=this.propName?lt:Je,j.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(e==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new wg(n.getScope(),h,l);a.unshift(u)}return i.push(new G(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new tr(n.getScope(),Ds(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new Zl(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new xi(n.getScope(),r);else if(s==-24)r=new un(n.getScope(),r);else if(s==-Gr)r=new gg(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(_e[e]>_e[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new Za(n.getScope(),o,r);break;case rn:r=new mg(n.getScope(),o,r);break;case on:r=new yg(n.getScope(),o,r);break;case 25:r=new Ka(n.getScope(),o,r);break;case 38:r=new vg(n.getScope(),o,r);break;case 37:r=new xg(n.getScope(),o,r);break;case 48:r=new bg(n.getScope(),o,r);break;case 47:r=new Us(n.getScope(),o,r);break;case 39:case 49:r=new Ja(n.getScope(),o,r);break;case 41:r=new Sg(n.getScope(),o,r);break;case 23:r=new qu(n.getScope(),o,r);break;case 24:r=new Yu(n.getScope(),o,r);break;case 36:r=new Qa(n.getScope(),o,r);break;case 19:r=new Zu(n.getScope(),o,r);break;case 21:r=new Ku(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new Eg(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new Zl(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let u=i.nthToken(1),d=i.nthToken(2);if(u.type===1&&d.type===18)i.consume(),i.consume(),r=u.text,n=d.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(d.type===10||d.type===6))return null;n=e.position+1}}else return null;let o=0,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=t&&r==="selector"&&a>0?"":i.input.substring(n,h).trim();return new Pg(this.handler.getScope(),r,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}skipPseudoFunctionContents(){let e=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(e===0)return!0;e--;break;case 10:case 6:e++;break}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,o=t.type===23||r;if(o&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Mt(i,t,new xi(i,new Ze(i,"pref-horizontal")));break;case"horizontal":t=Mt(i,t,new Ze(i,"pref-horizontal"));break;case"day":t=Mt(i,t,new xi(i,new Ze(i,"pref-night-mode")));break;case"night":t=Mt(i,t,new Ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new G(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,u,d,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===De&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new Qi(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=lt):(this.actions=ot,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=De,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=lt,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=De,h.splice(0,h.length);continue;case 29:this.actions=ot,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(d,l.text),r?this.actions=Be:this.actions=xe,a.consume();break;case 36:s.tagSelector(d,null),r?this.actions=Be:this.actions=xe,a.consume();break;default:this.actions=Je,s.error("E_CSS_NAMESPACE",l)}else this.actions=Je,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=Be:this.actions=xe,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=Be:this.actions=xe,a.consume();break;default:this.actions=Je,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Be:this.actions=xe,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=Be:this.actions=xe,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Be:this.actions=xe;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ot,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=xe:this.actions=Ge;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=ot,s.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Be:this.actions=xe:this.actions=Ge;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)m.push(u.text),a.consume();else break e;break}else break;else break e;default:if(m=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,m),a.consume(),r?this.actions=Be:this.actions=xe;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Je;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=Be:this.actions=xe,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,m),r?this.actions=Be:this.actions=xe,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Je;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=Ge,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=Ge,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=Ge,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(d,p,0,null),r?this.actions=Be:this.actions=xe,a.consume();continue;default:this.actions=Ge,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:s.attributeSelector(d,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=Ge,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=Ge,s.error("E_CSS_ATTR",l);continue}r?this.actions=Be:this.actions=xe,a.consume();continue;case 11:s.childSelector(),this.actions=Lt,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=Lt,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=Lt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=ze,a.consume();continue;case 41:s.nextSelector(),this.actions=ot,a.consume();continue;case 15:h.push(M(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new sc(l.text)),a.consume();continue;case 17:h.push(new Ct(l.num)),a.consume();continue;case 18:h.push(new Ue(l.num)),a.consume();continue;case 19:h.push(new R(l.num,l.text)),a.consume();continue;case 20:h.push(new X(l.text)),a.consume();continue;case 21:h.push(new ut(Ie(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new ac(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Ln),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ye,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new Qi("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?No:ze;continue;case 44:for(a.consume();h.length>0;){let x=h.length;if(g=this.valStackReduce(";",l),!g||h.length===x)break}return t?(this.result=g,!0):(this.propName&&g&&s.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new Ze(s.getScope(),Ds(l.text,u.text))),this.actions=be),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Yl(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new Yl(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==rn&&h[h.length-1]!==on&&(u.type===10||u.type===6)){h.push(-Gr),a.consume();continue}else h.push(new Ze(s.getScope(),l.text));this.actions=be}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=be;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Qe(s.getScope(),l.num)),a.consume(),this.actions=be;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new Er(s.getScope(),l.num,p)),a.consume(),this.actions=be;continue;case 34:h.push(new Qe(s.getScope(),l.text)),a.consume(),this.actions=be;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new tc(s.getScope(),l.num)),a.consume(),this.actions=be);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Ye,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==on&&h[h.length-2]!==-Gr?(this.actions=Ye,this.exprStackReduce(rn,l),h.push(rn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==rn&&h[h.length-2]!==-Gr?(this.actions=Ye,this.exprStackReduce(on,l),h.push(on),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=De),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=ze)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=ze,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=ze,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=be;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=ze,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ye,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Je;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}s.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Je;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Je;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=ot;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=Lt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),s.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ye,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ye,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ye,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,y=null,b=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(y=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)b.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(x,y,b);break;case"-epubx-partition":s.startPartitionRule(x,y,b);break;case"-epubx-partition-group":s.startPartitionGroupRule(x,y,b);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=Ge;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Je;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Je;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=ze;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=ze),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=ot,w=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=ze),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){if(this.actions===Ge)switch(l.type){case 16:this.errorBrackets.length==0&&(s.nextSelector(),w=l.position+1,this.actions=ot),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===ot)s.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(w,l.position);s.pushSelectorText(x),w=l.position+1}if(l.type===16){s.nextSelector(),this.actions=ot,a.consume();continue}else return s.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=xe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=Ge;continue}if(this.actions!==Je&&this.actions!==Ge&&this.actions!==lt){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===De){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Qi(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ye&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=ze,a.consume();continue}else{if(l.type===17&&this.actions==Ye)return this.actions=ze,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=lt:this.actions=Ge;continue}a.consume();continue}}return!1}},Yc=class extends ts{constructor(e){super(null),this.scope=e}error(e,t){j.warn(e,t.toString())}getScope(){return this.scope}};function sw(e,t,i,n,r){let o=Zc(t),s=sm(e.input);return s!==e.input?vh(new Vt(s,o),o,i,n,r):vh(e,o,i,n,r)}function vh(e,t,i,n,r){let o=D("parseStylesheet"),s=new Fr(ze,e,t,i),a=null;return r&&(a=Jc(new Vt(r,t),t,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ie(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let u=D("parseStylesheet.import");return Kc(l,t,null,null).then(()=>{s.importCondition&&t.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,u.finish(!0)}),u.result()}let h=o.timeSlice();if(h.isPending)return h}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function nl(e,t,i,n,r){let o=Zc(t);return kn("parseStylesheetFromText",s=>{let a=new Vt(e,o);sw(a,o,i,n,r).thenFinish(s)},(s,a)=>{j.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Zc(e){if(e instanceof Ks)return e;if(e instanceof Xi){if(e.owner)return e.owner;let t=new Ks;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Kc(e,t,i,n){return kn("parseStylesheetFromURL",r=>{es(e).then(o=>{o.responseText?nl(o.responseText,t,e,i,n).then(s=>{s||j.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{j.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Rr(e,t,i){let n=new Fr(De,t,new Yc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function aw(e,t,i){new Fr(No,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Jc(e,t,i){let n=new Fr(Ye,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var lw={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function hw(e){return!!lw[e]}function uw(e,t,i){if(t instanceof Re&&t.str==="viv-leader")return new G(t);if(i==="content"&&t instanceof Re)return new G(t);let n=t.evaluate(e);switch(typeof n){case"number":return hw(i)?n==Math.round(n)?new Ue(n):new Ct(n):new R(n,"px");case"string":return n?i==="content"?new X(n):Rr(t.scope,new Vt(n,null),""):Y;case"boolean":return n?v._true:v._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}var cw="data-vivliostyle-flow-root";function dw(e){return e.getAttribute(cw)==="true"}function bh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return M(i)}function is(e){return e===v.absolute||e===v.fixed}function To(e){return e instanceof ci&&e.name==="running"}function Qc(e,t,i,n){return e===v.none||(is(t)?(i=v.none,e=bh(e)):(i&&i!==v.none&&!Z(i)||n)&&(e=bh(e))),{display:e,position:t,float:i}}function ed(e,t,i,n){return Qc(e,t,i,n).display===v.block}function ns(e){return e instanceof de||e instanceof J||typeof e=="string"}function Ht(e){if(!ns(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function jn(e){return ns(e)?e.toString().includes("list-item"):!1}function pw(e){if(!ns(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function td(e){if(!ns(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function fw(e,t,i,n,r,o,s){return r=r||o||v.horizontal_tb,!!s||!!i&&i!==v.none&&!Z(i)||is(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!Z(n)||!!o&&r!==o}function gw(e){return e===v.relative||e===v.absolute||e===v.fixed}var Yt=1e5;function rl(e){let t=e.element.style;t.columnGap=`${Yt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function rs(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Io(e){return e.element.style.columnCount==="1"}function mw(e){e.element.setAttribute("data-vivliostyle-column","true")}function fr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Yt)}function id(e,t){let i=fr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Yt),o=r*Yt,s=i*Yt;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=Yt),e.right-=o,e.left-=s):e.left<-Yt/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=Yt),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=Yt),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Js(e,t){for(let i=0;i<e.length;i++)id(e[i],t)}function Tt(e,t,i){let n=e.getElementClientRect(t);if(id(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Lr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return rs(r),e.getElementClientRect(t)}return n}function ww(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function Qs(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function yw(e){if(!e.hasAttribute("data-vivliostyle-column")&&Qs(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Qs(t))return!0;return!1}function Lr(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(Qs(t))return t;if(i.position==="absolute")break}return null}function vw(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!r&&!s)return;let a=Lr(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:d,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>w.bottom+m:g?x.right<w.left-m:x.left>w.right+m)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${Yt}px`)}function jr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?fr(i,e.vertical):0}function nd(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||jr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize);if(r<=0||e.parentElement&&Lr(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(e.style.blockSize=`${r}px`,jr(t)){if(e.style.blockSize=`${n}px`,!jr(t)){let s=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;e.style.blockSize=`${l}px`,jr(t)?h=l:a=l}o=a,e.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/t.clientLayout.layoutUnitPerPixel;o=r+s,e.style.blockSize=`${o}px`}if(isNaN(o)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function bw(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)nd(i,e)}function sn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Ht(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.parentNode.insertBefore(s,o);let a=t.getElementClientRect(s);if(s.remove(),a){let h=[a];Js(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=Tt(t,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return e.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);Js(l,n);let u=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)l=u;else{let d=o?t.getElementComputedStyle(o).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(d=>d.left)):s=Math.max.apply(null,l.map(d=>d.bottom)),s):NaN}}function ea(e,t,i){let n=Io(t);n&&rs(t);let r=t.clientLayout.getElementClientRect(e);n&&rl(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function dn(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function rd(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var Pn="data-adapt-spec";function ol(e){return!!e.getAttribute(Pn)}function Nt(e){return e?.nodeType!==1?!1:ol(e)?!0:od(e)}function od(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function xh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function pn(e){let t=e?.viewNode;return t?.nodeType===1&&ol(t)}function xw(e){return e!=="inline"&&(Ht(e)||td(e))}function Sh(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Ht(i.display))return i;return null}function Sw(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}function sd(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},o=e[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function ad(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=e.replace(s.regexp,s.to);if(a!==e)return a}return e}var ld={"horizontal-tb":{ltr:[{logical:"inline-start",physical:"left"},{logical:"inline-end",physical:"right"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}],rtl:[{logical:"inline-start",physical:"right"},{logical:"inline-end",physical:"left"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}]},"vertical-rl":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]},"vertical-lr":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]}},Cw=sd(ld,!0);function hd(e,t,i){return ad(e,t,i||null,Cw)}var kw=sd(ld,!1);function ud(e,t,i){return ad(e,t,i||null,kw)}var Ew={"horizontal-tb":[{logical:"line-left",physical:"left"},{logical:"line-right",physical:"right"},{logical:"over",physical:"top"},{logical:"under",physical:"bottom"}],"vertical-rl":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}],"vertical-lr":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}]};function Pw(e,t){let i=Ew[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function sl(e,t,i){var n;let r=t,o={width:r.style.width,height:r.style.height};function s(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function fn(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function cd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function dd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function wt(e,t){let i=cd(e);i.includes(t)||(i.push(t),dd(e,i))}function Nw(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Tw(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Ss(e,t){let i=Nw(e);i.includes(t)||(i.push(t),Tw(e,i))}function Iw(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var ta={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function qe(e){return!!ta[e]}var Aw={left:!0,right:!0,recto:!0,verso:!0};function Nn(e){return!!Aw[e]}function Ch(e){return qe(e)&&e!=="column"&&e!=="region"}var Fw={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ao(e){return!!Fw[e]}function tt(e,t){if(e)if(t){if(Nn(t))return t;if(Nn(e))return e;{let i=qe(e),n=qe(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:Ao(t)?t:Ao(e)?e:t}}else return e;else return t}function kh(e){return qe(e)?e:"auto"}At("SIMPLE_PROPERTY",Iw);var ir=Gf(Xf());function Rw(e,t){return(0,ir.default)(e,t,0)}function Eh(e){return e.reduce((t,i)=>i[0]===ir.default.DELETE?t:t+i[1],"")}function Lw(e,t){return pd(e,t,1)}function Ow(e,t){return pd(e,t,-1)}function pd(e,t,i){let n=0,r=0;return e.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case ir.default.INSERT:n++;break;case ir.default.DELETE:n--,r++;break;case ir.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var ia;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(ia||(ia={}));var bn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(bn||(bn={}));var Fo;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Fo||(Fo={}));var zi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||ki.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||ki.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(zi||(zi={}));var ki;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(ki||(ki={}));var li;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(li||(li={}));var Bw={transform:!0,"transform-origin":!0},Mw={top:!0,bottom:!0,left:!0,right:!0},al=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},_w={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function Dw(e,t){let i=_w[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var na=class Xn extends qa{constructor(t,i){super(),this.container=t,this.bleedBox=i,c(this,"pageAreaElement",null),c(this,"delayedItems",[]),c(this,"hrefHandler"),c(this,"elementsById",{}),c(this,"dimensions",{width:0,height:0}),c(this,"isFirstPage",!1),c(this,"isLastPage",!1),c(this,"isBlankPage",!1),c(this,"isAutoPageWidth",!0),c(this,"isAutoPageHeight",!0),c(this,"spineIndex",0),c(this,"position",null),c(this,"offset",-1),c(this,"side",null),c(this,"fetchers",[]),c(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),c(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Xn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Xn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Xn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Xn.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||I(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<t.length;o++){let s=t[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=Dw(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};c(na,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(na,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var fd=na,ft=li.Whitespace;function gd(e){switch(e){case"normal":case"nowrap":return ft.IGNORE;case"pre-line":return ft.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ft.PRESERVE;default:return null}}function Le(e,t){return e?e.nodeType==1?!1:md(e.textContent,t):!0}function md(e,t){switch(t){case ft.PRESERVE:return e.length==0;case ft.NEWLINE:return!!e.match(/^[ \t]*$/);case ft.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var zw=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},Vw=class{constructor(e,t,i,n,r,o,s,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=o,this.repeated=s,this.last=a,this.breakBefore=h,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Uw(e,t){return e.top-t.top}function $w(e,t){return t.right-e.right}function wd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===li.ShadowType.ROOTLESS&&t.shadowType===li.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&ra(e.shadowContext,t.shadowContext)&&ra(e.nodeShadow,t.nodeShadow)&&wd(e.shadowSibling,t.shadowSibling)}function Hi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!wd(e.steps[i],t.steps[i]))return!1;return!0}function Hw(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Ro(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Lo(e,t){let i=new an(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Lo(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=li.ShadowType,no=class{constructor(e,t,i,n,r,o,s){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=o,this.styler=s,c(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&ra(this.parentShadow,e.parentShadow):!1}};function ra(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Ww=class{constructor(e,t){this.outer=e,this.count=t}},an=class yd{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,c(this,"offsetInNode",0),c(this,"after",!1),c(this,"shadowType"),c(this,"shadowContext"),c(this,"nodeShadow",null),c(this,"shadowSibling",null),c(this,"shared",!1),c(this,"inline",!0),c(this,"overflow",!1),c(this,"breakPenalty"),c(this,"display",null),c(this,"floatReference"),c(this,"floatSide",null),c(this,"clearSide",null),c(this,"floatMinWrapBlock",null),c(this,"columnSpan",null),c(this,"captionSide","top"),c(this,"inlineBorderSpacing",0),c(this,"blockBorderSpacing",0),c(this,"flexContainer",!1),c(this,"whitespace"),c(this,"hyphenateCharacter"),c(this,"breakWord"),c(this,"establishesBFC",!1),c(this,"containingBlockForAbsolute",!1),c(this,"breakBefore",null),c(this,"breakAfter",null),c(this,"viewNode",null),c(this,"clearSpacer",null),c(this,"inheritedProps"),c(this,"vertical"),c(this,"direction"),c(this,"firstPseudo"),c(this,"lang",null),c(this,"preprocessedTextContent",null),c(this,"formattingContext"),c(this,"repeatOnBreak",null),c(this,"pluginProps",{}),c(this,"fragmentIndex",1),c(this,"afterIfContinues",null),c(this,"footnotePolicy",null),c(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=bn.FloatReference.INLINE,this.whitespace=i?i.whitespace:ft.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=bn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:ft.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new yd(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,o=[];r.shadowType===li.ShadowType.ROOTLESS&&(r.floatReference!==bn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&o.push(r.toNodePositionStep()),r=r.parent;while(r);let s=this.preprocessedTextContent?Ow(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:s,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Ei=class vd{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new vd(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!Hi(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!Hi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Gw=class bd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new bd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},jw=class xd{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new xd,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Xw=class Sd{constructor(){c(this,"page",0),c(this,"flows",{}),c(this,"flowPositions",{}),c(this,"isBlankPage",!1),c(this,"highestSeenOffset",0),c(this,"highestSeenNode"),c(this,"lookupPositionOffset")}clone(){let t=new Sd;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&Nn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},Cd=class{constructor(e){this.element=e,c(this,"left",0),c(this,"top",0),c(this,"marginLeft",0),c(this,"marginRight",0),c(this,"marginTop",0),c(this,"marginBottom",0),c(this,"borderLeft",0),c(this,"borderRight",0),c(this,"borderTop",0),c(this,"borderBottom",0),c(this,"paddingLeft",0),c(this,"paddingRight",0),c(this,"paddingTop",0),c(this,"paddingBottom",0),c(this,"width",0),c(this,"height",0),c(this,"originX",0),c(this,"originY",0),c(this,"exclusions",null),c(this,"innerShape",null),c(this,"computedBlockSize",0),c(this,"snapWidth",0),c(this,"snapHeight",0),c(this,"snapOffsetX",0),c(this,"snapOffsetY",0),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):tl(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new It(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new It(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Sc(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new It(e,t,e+i,t+n)}},gr=class extends ui{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof ut)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Re&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function kt(e){return e!=null&&e!==Y&&e!==v.normal&&e!==v.none&&!Z(e)}var Te=bn.FloatReference,qw=20;function Yw(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Si(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Cs(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=ud(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=hd(e,r,i),s=Pw(o,r);s==="line-left"?e="left":s==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(j.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var kd=class{constructor(e,t,i,n,r,o){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=o,c(this,"order",null),c(this,"id",null),c(this,"insidePageFloatArea",!1),c(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Zw=class{constructor(){c(this,"floats",[]),c(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Hi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(n=>Hi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},Ed=class{constructor(e,t,i,n,r,o){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=o}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Ph=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Hi(this.nodePosition,e.nodePosition):!1}},ln=class{constructor(e,t,i,n,r,o,s){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,c(this,"children",[]),c(this,"writingMode"),c(this,"direction"),c(this,"invalidated",!1),c(this,"floatStore"),c(this,"forbiddenFloats",[]),c(this,"floatFragments",[]),c(this,"stashedFloatFragments",[]),c(this,"floatAnchors",{}),c(this,"floatsDeferredToNext",[]),c(this,"floatsDeferredFromPrevious"),c(this,"layoutConstraints",[]),c(this,"locked",!1),c(this,"footnoteMaxBlockSize",null),c(this,"ignoreFootnoteAreaMaxHeight",!1),c(this,"footnoteAnchorsSeen",new Set),c(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Z(o)&&o||e&&e.writingMode||v.horizontal_tb,this.direction=!Z(s)&&s||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Zw;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let o=r-1;o>=0;o--){let s=this.children[o];if(s.floatReference===t&&s.flowName===i&&Hi(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,t,i,n),s))return s}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Tn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&t.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var t;if(!("footnotePolicy"in e))return;let i=this;for(;i;)i.footnoteAnchorsSeen.add(e.getId()),i=(t=i.parent)!=null?t:i.outerContext}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t,this.markPageFloatAnchorSeen(e)}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}removeFloatDeferredToNext(e){let t=this.floatsDeferredToNext.findIndex(i=>i.float===e);t>=0&&this.floatsDeferredToNext.splice(t,1)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let o=r.float,s=o.getOrder();s>t&&(!i||s>i.getOrder())&&(i=o)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}hasRootMultiColumnFootnoteContext(){return this.children.some(e=>{let t=0;for(let i of e.children)if(!i.generatingNodePosition&&(t+=1,t>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(e=>e.children.some(t=>{var i;let n=(i=t.getContainer())==null?void 0:i.element;return n!=null&&yw(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<qw?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Te.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if(this.floatReference===Te.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===v.line&&this.footnoteAnchorsSeen.has(t.getId())&&!i){if(this.locked){this.invalidate();return}this.removeFloatDeferredToNext(t),this.forbid(t),this.invalidate();return}}for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return ud(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return hd(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let s of t){let a=this.toLogical(s);i.includes(a)||i.push(a)}let n=[],r=!1,o=!1;for(let s=0;s<i.length;s++){let a=i[s];a.includes("block")?r||(i.slice(s+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(s+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),o=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,o=!0){this.container;let s=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(s,h,i,n,r);if(o&&this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,l,i,n,r,o);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(e,t,i,n,r){this.container;let o=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?o.right:o.top;case"block-end":return this.container.vertical?o.left:o.bottom;case"inline-start":return this.container.vertical?this.container.rtl?o.bottom:o.top:this.container.rtl?o.right:o.left;case"inline-end":return this.container.vertical?this.container.rtl?o.top:o.bottom:this.container.rtl?o.left:o.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var o,s,a,h;this.container;let l=this.container.originX,u=this.container.originY,d=this.container.getPaddingRect(),p={top:d.y1-u,left:d.x1-l,bottom:d.y2-u,right:d.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((s=(o=this.container.element)==null?void 0:o.style)==null?void 0:s.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,x){return m.unit==="%"?x*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[x,y]=this.toLogicalFloatSides(w.floatSide);if(y&&(n&&y.includes("block")===n.includes("block")&&y!==n||r&&y.includes("block")===r.includes("block")&&y!==r))return m;let b=w.area,S=w.continuations[0].float.floatMinWrapBlock,C=b.vertical?b.left+b.getInsetLeft()+b.width+b.getInsetRight():b.top+b.getInsetTop()+b.height+b.getInsetBottom(),N=b.vertical?b.top+b.getInsetTop()+b.height+b.getInsetBottom():b.left+b.getInsetLeft()+b.width+b.getInsetRight(),F=m.top,B=m.left,U=m.bottom,q=m.right,he=m.floatMinWrapBlockStart,ae=m.floatMinWrapBlockEnd;switch(x){case"inline-start":b.vertical?F=Math.max(F,N):B=Math.max(B,N);break;case"block-start":b.vertical?(S&&b.left<q&&(he=f(S,b.rootViewNodes[0],d.x2-d.x1)),q=Math.min(q,b.left)):(S&&C>F&&(he=f(S,b.rootViewNodes[0],d.y2-d.y1)),F=Math.max(F,C));break;case"inline-end":b.vertical?U=Math.min(U,b.top):q=Math.min(q,b.left);break;case"block-end":b.vertical?(S&&C>B&&(ae=f(S,b.rootViewNodes[0],d.x2-d.x1)),B=Math.max(B,C)):(S&&b.top<U&&(ae=f(S,b.rootViewNodes[0],d.y2-d.y1)),U=Math.min(U,b.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:F,left:B,bottom:U,right:q,floatMinWrapBlockStart:he,floatMinWrapBlockEnd:ae}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,o,s){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;e.clientLayout;let h=a.find(C=>C.includes("inline")&&s[C==="inline-start"?"inline-end":"inline-start"]),l=a.find(C=>C.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;e.isFootnote||(u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),d=e.vertical?Math.max(d,e.left+g):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function w(C,N){let F=C(e.bands,N);return F?(e.vertical&&(F=vc(F)),u=e.vertical?Math.min(u,F.x2):Math.max(u,F.y1),d=e.vertical?Math.max(d,F.x1):Math.min(d,F.y2),!0):o}let x,y,b,S;if(r){let C=e.vertical?Po(new It(d,p,u,f)):new It(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Vg,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Ug,C)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),b=(d-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(b=Math.min(b,this.footnoteMaxBlockSize),e.vertical?u=d+b:u=d-b),x=Math.max(0,b-e.getInsetBefore()-e.getInsetAfter()),S=(f-p)*e.getInlineDir(),y=S-e.getInsetStart()-e.getInsetEnd(),!o&&(x<=0||y<=0)))return null}else{let C=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,C)),b=x+e.getInsetBefore()+e.getInsetAfter();let N=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let B=this.container.getPaddingRect(),U=this.container.getBoxDir()*(n-(this.container.vertical?B.x2:B.y1)),q=this.container.getBoxDir()*((this.container.vertical?B.x1:B.y2)-n-b);U<=q?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&N<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=sl(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,S=y+e.getInsetStart()+e.getInsetEnd();let F=(f-p)*e.getInlineDir();if(!o&&F<S)return null}return u-=g,d-=g,p-=m,f-=m,a.some(C=>C==="inline-start"||C==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,y):(a.some(C=>C==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-S*e.getInlineDir(),y),a.some(C=>C==="block-start"||C==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,x):(a.some(C=>C==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-b*e.getBoxDir(),x),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-start")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x1:s.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let o=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.min(r,o):Math.max(r,o):o)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-end")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x2:s.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let o=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.max(r,o):Math.min(r,o):o)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.continuations.some(i(u))}let r=t.getPaddingRect(),o=t.vertical?r.x1:r.y2,s=this;for(;s;){if(s.floatsDeferredToNext.some(i(s)))return o;s=s.parent}function a(l){return l.floatFragments.some(u=>n(u,l))||l.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(s=this;s;s=s.parent)if(s.floatReference===e){if(a(s))return o;break}}t.clientLayout;let h=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<o*t.getBoxDir()?o:h}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=e.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(h(null))||l(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(d=>{switch(d){case"block-start":n[d]=!l(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(h(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let s=n.getLimitValuesInner(t,i);r?e.vertical?(s.right<r.right&&(r.right=s.right,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>r.left&&(r.left=s.left,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>r.top&&(r.top=s.top,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<r.bottom&&(r.bottom=s.bottom,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):r=s,n=n.parent}let o=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=o}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},Vn=[],Tn=class{static register(e){Vn.push(e)}findByNodeContext(e){for(let t=Vn.length-1;t>=0;t--){let i=Vn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Vn.length-1;t>=0;t--){let i=Vn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Kw=class{appliesToNodeContext(e){return Si(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,o=e.toNodePosition(),s=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new kd(o,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),T(h)})}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Ed(o.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return T(void 0)}forbid(e,t){}};Tn.register(new Kw);var Pd="data-vivliostyle-footnote-first-ref",Nd="data-vivliostyle-footnote-referenced";function Oo(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function bt(e){if(e.localName!=="aside")return!1;if(Oo(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Oo(t,"footnote")}function _t(e){if(e.localName!=="a")return!1;if(Oo(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Oo(t,"noteref")}function ll(e,t){if(!_t(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=ko(i,t);return n==="#"?null:n}function Td(e,t,i){let n=ll(e,t);if(!n)return null;let r=i(n);return r&&bt(r)?r:null}function Jw(e,t,i,n,r){if(r.value)return;let o=e.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=ll(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function Nh(e,t,i,n,r){if(e.localName!=="a"||!_t(e))return!0;let o=ll(e,t);if(!o)return!0;Jw(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function hl(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===v.inline?t.createCascadeValue(v.inline,n.priority):null}function Qw(e,t,i,n,r,o,s){if(e.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||e.localName!=="include"||!e.classList.contains("-vivliostyle-footnote-content"))return t;let a=i?.owner;if(!(a instanceof Element)||!_t(a))return t;let h=Td(a,n,r);if(!h)return t;let l=a.getAttribute(o);l?(e.setAttribute(o,l),h.setAttribute(o,l)):(e.removeAttribute(o),h.removeAttribute(o));let u=s.getStyle(h);if(!u)return t;let d={...t},p=hl(u,s),f=s.getProp(u,"footnote-policy"),g=s.getStyleMap(u,"_pseudos"),m=g?.after;if(p&&(d["footnote-display"]=p),f&&(d["footnote-policy"]=f),m){let w=s.getMutableStyleMap(d,"_pseudos");w.after={...m}}return d}function ey(e,t,i,n,r){var o;if(!(i?.type===rt.ROOTED&&bt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=hl(s,r),l=r.getProp(s,"footnote-policy"),u=r.getStyleMap(s,"_pseudos"),d=u?.["footnote-marker"],p=r.getProp(d,"content"),f=r.getProp(d,"list-style-position");if(h&&(a["footnote-display"]=h),l&&(a["footnote-policy"]=l),p&&((o=f?.evaluate)==null?void 0:o.call(f,n,"list-style-position"))===v.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(M("list-item"),0),a["list-style-position"]=r.createCascadeValue(v.outside,0),a["list-style-type"]=r.createCascadeValue(v.none,0),a["list-style-image"]=r.createCascadeValue(v.none,0)}return a}function ty(e,t,i){var n,r;let o=t?.type===rt.ROOTED&&bt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=hl(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function Id(e,t){if(e instanceof G){let i=e.expr.evaluate(t);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):e}return e instanceof J?new J(e.values.map(i=>Id(i,t))):e}function iy(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=Id(n.value,i))}function ny(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!_t(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=e.getElementById(o);if(s&&bt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(Pd,"true")),s.setAttribute(Nd,"true")}}}At("PREPROCESS_SINGLE_DOCUMENT",ny);var ry=Ed,Bo=class Ad extends kd{constructor(t,i,n,r,o,s){super(t,i,"block-end",null,n,o),this.footnotePolicy=r,this.policyAnchorNode=s}isAllowedToPrecede(t){return!(t instanceof Ad)}};function oy(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;t;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(t.localName)&&!t.querySelector("br"))return t;t=t.parentElement}return e}var Th=class extends ry{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Bo?!0:this.getOrder()<e.getOrder()}},sy=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;for(;t;){if(t===this.footnote.policyAnchorNode)return!1;t=t.parentNode}return!0}},ay=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Bo}createPageFloat(e,t,i){var n;let r=Te.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(o)&&(r=Te.PAGE);let s=!!t.generatingNodePosition;s&&r!==Te.PAGE&&(r=Te.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&_t(l)&&(h=l),h=oy(h);let u=new Bo(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=s,s){let d=t.generatingNodePosition;d&&(u.parentPageFloat=t.findPageFloatByNodePosition(d))}return t.addPageFloat(u),T(u)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Th(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Th);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=e.vertical?e.paddingLeft+e.paddingRight+e.borderLeft+e.borderRight:e.paddingTop+e.paddingBottom+e.borderTop+e.borderBottom,l=e.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],u=getComputedStyle(n);for(let d of l){let p=u.getPropertyValue(d);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||I(n,d,`${Math.max(0,f-h)}px`)}}I(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){I(n,"max-block-size",""),I(n,e.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return T(void 0)})}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=new sy(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Tn.register(new ay);var ul=class{calculateOffset(e){return xn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function xn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Or=class extends ul{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,c(this,"overflowIfRepetitiveElementsDropped"),c(this,"isEdgeUpdated",!1),c(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Ao(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=sn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Un=class{find(e){let t=Dt("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},gn=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new Or(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===li.ShadowType.ROOTLESS&&pn(i))return;let o=i.viewNode;((r=o.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let s=o.parentNode;rd(s,o),n&&s.removeChild(o)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),T(!0)}},cl=class{constructor(e){this.parent=e,c(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},dl=new gn,ly=ia.isInstanceOfBlockFormattingContext;At("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,o)=>{let s=e.parent;return!s&&e.formattingContext||s&&e.formattingContext!==s.formattingContext?null:e.establishesBFC||!e.formattingContext&&ed(i,n,r,o)?new cl(s?s.formattingContext:null):null});At("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof cl?dl:null);var pl=class{constructor(){c(this,"initialBreakPositions",null),c(this,"initialStateOfFormattingContext",null),c(this,"initialPosition"),c(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=D("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let o=n.accept(r,t);o=n.postLayout(r,this.initialPosition,t,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},hy=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},oa=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=D("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Le(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?o=t.afterIgnoredTextNode(i):o=t.startIgnoredTextNode(i):i.nodeContext.after?o=t.afterNonElementNode(i):o=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?o=t.afterInlineElementNode(i):o=t.startInlineElementNode(i):i.nodeContext.after?o=t.afterNonInlineElementNode(i):o=t.startNonInlineElementNode(i):i.nodeContext.after?o=t.afterNonDisplayableNode(i):o=t.startNonDisplayableNode(i);let s=(o&&o.isPending()?o:T(!0)).thenAsync(()=>i.break?T(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},nr=class extends hy{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&qe(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:T(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:T(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}},sa=[];function uy(){sa=[]}function Fd(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var cy=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},dy=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Rd=class ro{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=ro.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){ro.fragmentIndices={}}matches(){let t=ro.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Fd(t.fragmentIndex,this.a,this.b)}};c(Rd,"fragmentIndices",{});var os=Rd,Xr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new os(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new dy(e)}static buildAnyMatcher(e){return new cy(e)}},Ld={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},py=["image-resolution","orphans","widows"];function fy(){return Dt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(py))}var gy={"http://www.idpf.org/2007/ops":!0,"http://www.w3.org/1999/xhtml":!0,"http://www.w3.org/2000/svg":!0,"http://www.w3.org/1998/Math/MathML":!0},aa=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],my=["max-%","min-%","%"],Ih=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<aa.length;i++)for(let n=0;n<e.length;n++){let r=aa[i].replace("%",e[n]);t[r]=!0}return t})();function On(e,t){let i={};for(let n of aa)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}for(let n of my)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var Od=On({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Bd=On({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),wy=On({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),yy=On({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),vy=On({inside:"right",outside:"left"},{}),by=On({inside:"left",outside:"right"},{}),V=class la{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new la(i,this.priority)}increaseSpecificity(t){return t==0?this:new la(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Qt(i)?this.value:zo(t,this.value,i,n,r)}isEnabled(t){return!0}},ha=class ua extends V{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new V(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ua(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new ua(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){j.warn(i)}return!1}};function ca(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Gt(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Md={"region-id":!0,"fragment-selector-id":!0},rr="data-viv-footnote-counter";function Mo(e){let t=e.getAttribute(rr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function _d(e,t,i){let n=Mo(e);n[t]=i,e.setAttribute(rr,JSON.stringify(n))}function xy(e,t){var i,n;if(!_t(e)||e.hasAttribute(Pd))return null;let r=Mo(e)[t];if(r)return r;let o=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=ko(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=e.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let u=Mo(l)[t];return u?(_d(e,t,u),u):null}function Sy(e){let t=me(e,"content");return!!t&&kt(t.value)}function Cy(e){return!!Md[e]}function oo(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Di(e){return e.charAt(0)!=="_"&&!Md[e]}function mn(e){return!!Ld[e]||Qt(e)}function me(e,t){return e[t]}function Ci(e,t,i){i?e[t]=i:delete e[t]}function gt(e,t){return e[t]}function ei(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Dd=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function zd(e,t){return e[t]}function Vd(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function _o(e,t,i,n,r,o,s){var a,h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=ei(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),s){let l=Dd(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!oo(l))if(Cy(l)){let u=zd(i,l),d=Vd(t,l);Array.prototype.push.apply(d,u)}else{let u=me(i,l);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Gt(t,l,d,e);let p=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(p)for(let f of p){let g=new V(Y,d.priority);Gt(t,f,g,e)}}}function ky(e,t){let i={};for(let n=0;n<t.length;n++)_o(e,i,t[n],0,null,null,null);return i}function fl(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var Ey=class extends Gi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=me(this.props,"font-size");if(!e.value.isNumeric())return Wt.em;let t=e.value;if(!dg(t.unit))throw new Error("Unexpected state");return t.num*Wt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?da(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?gl(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?zo(this.context,e,this.propName).visit(this):e}};function gl(e,t,i){let n=e.unit,r=e.num;return n==="em"?new R(r*t,"px"):n==="rem"?new R(r*i.fontSize(),"px"):n==="rlh"?new R(r*i.rootLineHeight,"px"):e}function da(e,t,i){e=gl(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new R(r/100*t,"px"):new R(r*i.queryUnitSize(n,!1),"px")}var Bn=class{apply(e){}mergeWith(e){return new Py([this,e])}clone(){return this}},qr=class extends Bn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Py=class Ud extends Bn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Ud([].concat(this.list))}},ml=class extends Bn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){_o(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ke=class extends Bn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Ny=class extends ke{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},Ty=class extends ke{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},Ah=class extends ke{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},Iy=class extends ke{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},Ay=class extends ke{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Fy=class extends ke{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function ss(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let r of e.getAttributeNames())if((r===i||r.endsWith(`:${i}`))&&n(e,r===i?"":e.lookupNamespaceURI(r.split(":")[0]),i))return!0;return!1}var Fh=class extends ke{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},Ry=class extends ke{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},Ly=class extends ke{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>!!gy[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},$n=class extends ke{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){ss(e.currentElement,this.ns,this.name,(t,i,n)=>{var r;return!!((r=t.getAttributeNS(i,n))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},Oy=class extends ke{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Rh=class extends ke{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},By=class extends ke{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},qi=class extends ke{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Fd(e,this.a,this.b)}},My=class extends qi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},pa=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},fa=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},ga=class extends qi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,o=t[n];o||(o=t[n]={}),o[r]=(o[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},_y=class extends ke{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},Dy=class extends ke{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},zy=class extends ke{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Vy=class extends ke{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},et=class extends ke{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},$d=class Hd extends Bn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Hd;return t.applied=this.applied,t}},wl=class extends ke{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new $d;for(let t of e)this.firstActions.push(fl(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof ke?e.getPriority():0))}positive(){return!0}relational(){return!1}},Uy=class extends wl{positive(){return!1}},$y=class extends wl{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},Wd=class extends qi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new $d;for(let n of i)this.firstActions.push(fl(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,o=t.currentId,s=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=o,t.currentClassNames=s,t.currentSiblingOrder=a,u}getPriority(){return 5}},Hy=class extends Wd{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},as=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Wy=class Gd extends as{constructor(t,i,n){super(t,i,n)}fresh(t){return new Gd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},Gy=class jd extends as{constructor(t,i,n){super(t,i,n)}fresh(t){return new jd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},jy=class Xd extends as{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Xd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},Xy=class qd extends as{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new qd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},qy=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Yy=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Zy=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Ky=class extends Gi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ut(e):new ut("about:invalid");case"string":default:return e?new X(e):new X("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof J){let r=e.values[0].values;r.length>=2&&(t=r[1].stringValue()),i=r[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Do(e,t){if(kt(e)){if(e instanceof X)return e.stringValue();if(e instanceof G&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof J)return e.values.map(i=>Do(i,t)).join("")}return""}var mr=class extends Gi{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Do(i,this.cascade.context);return this.cascade.quoteDepth=t,n}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new X("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new X("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new si;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var o,s,a,h,l,u;let d=typeof r=="string",p=w=>d?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&_d(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=xy(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=Mo(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((o=e.currentPageCounters)==null?void 0:o[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((s=e.currentPageDocCounters)==null?void 0:s[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],x=((l=e.currentPageCounters)==null?void 0:l[t])||[],y=x.length?x[x.length-1]:0,b=w.length?w[0]:0,S=m.length?m[0]:0,C=y+(S-b);return g=m.length?[C,...m.slice(1)]:x.length?x:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let a=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),h=this.getPageScope(),l=new Re(h,()=>this.buildCounterText(o,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&o!=null&&o.registerPageCounterExpr){let u=d=>this.formatLastValue(d,n);o.registerPageCounterExpr(i,u,l)}return new G(l)}let s=this.cascade.counters[i];if(s&&s.length){let a=s&&s.length&&s[s.length-1]||0;return new X(this.format(a,n))}else{let a=new G(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new J([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",o=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let u=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),d=this.getPageScope(),p=new Re(d,()=>this.buildCounterText(s,i,r,o,n),u?`page-counters-${i}`:`counters-${i}`);return u&&s!=null&&s.registerPageCounterExpr&&s.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new G(p)}let a=this.cascade.counters[i],h=new si;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new G(this.counterResolver.getPageCountersVal(i,u=>{let d=[];if(u.length)for(let f=0;f<u.length;f++)d.push(this.format(u[f],r));let p=h.toString();return p.length&&d.push(p),d.length?d.join(n):this.format(0,r)}));return new J([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",o=new G(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new J([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),o=e.length>3?e[3].stringValue():"decimal",s=new G(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new J([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof ut?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new G(this.counterResolver.getTargetTextVal(i,n));return new J([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,o,s,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let d=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(d&&this.element)for(let f=0;f<d.length;f++){let g=d[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=gt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=Do(m,this.cascade.context)}}}break;case"first-letter":{let d=gt(this.cascade.currentStyle,"_pseudos"),p=(s=(o=d?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(Co);u=g?g[0]:""}break}return new X(u)}visitFuncLeader(e){let t="";if(e[0]instanceof de)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof X&&(t=e[0].stringValue());return t.length==0?new X(""):new G(new Re(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function ks(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var Jy=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(P){b==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(m);return y==="vertical-rl"||y==="vertical-lr"?b==="rtl"?P.top-=k:P.bottom+=k:b==="rtl"?P.left-=k:P.right+=k,F.left>P.left||F.right<P.right||F.top>P.top||F.bottom<P.bottom},d=function(){let P,A,O=x.repeat(1e4);if(l(O),u())P=1,A=1e4;else return;for(let z=0;z<16;z++){let W="",K=Math.floor((P+A)/2);for(let Q=0;Q<K;Q++)W+=x;if(l(W),u())A=K;else{if(P==K)return;P=K}}l(x)},p=function(P){let A=0,O=m.parentElement;for(;O&&O!==f.viewNode;)A+=i.getComputedInsets(O)[P],O=O.parentElement;return A};var r=l,o=u,s=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:y,direction:b,marginInlineEnd:S}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(x),m.style.display="inline-block",m.style.textIndent="0";let C=Lr(f.viewNode),N=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let F=i.clientLayout.getElementClientRect(f.viewNode),B=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(S),q=[],he=m.parentElement;for(;he.parentElement&&he.parentElement!==f.viewNode;)he=he.parentElement;let ae=he.nextSibling;for(;ae;){if(ae.nodeType===1){let P=ae,{display:A,float:O,position:z}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||z==="absolute"||z==="fixed"){ae=ae.nextSibling;continue}if(Ht(A))q.push(P);else if(pw(A))break}else if(ae.nodeType===3){let P=ae;P.length>0&&q.push(P)}ae=ae.nextSibling}let k=q.reduce((P,A)=>P+ks(A,i.clientLayout,y),0);if(w!=="after"){let P=ks(he,i.clientLayout,y),A=ks(m,i.clientLayout,y);k+=P-A}y==="vertical-rl"||y==="vertical-lr"?(b==="rtl"?F.top+=U:F.bottom-=U,F.top=Math.min(B.top,F.top),F.bottom=Math.max(B.bottom,F.bottom)):(b==="rtl"?F.left+=U:F.right-=U,F.left=Math.min(B.left,F.left),F.right=Math.max(B.right,F.right)),d();let _=i.clientLayout.getElementClientRect(m);b=="rtl"?m.style.float="left":m.style.float="right";let E=i.clientLayout.getElementClientRect(m),L=0;b=="rtl"?y=="vertical-rl"||y=="vertical-lr"?L=_.top-E.top-p("top"):L=_.left-E.left-p("left"):y=="vertical-rl"||y=="vertical-lr"?L=E.bottom-_.bottom-p("bottom"):L=E.right-_.right-p("right"),L-=k,L=Math.max(0,L-.1),m.style.float="",g.style.marginInlineStart=`${L}px`,C&&(N?C.style.columnFill=N:C.style.removeProperty("column-fill"))}};At("POST_LAYOUT_BLOCK",Jy);var yl=1/1048576;function Ki(e,t){for(let i in e)t[i]=e[i].clone()}var Qy=class Yd{constructor(){c(this,"nsCount",0),c(this,"nsPrefix",{}),c(this,"tags",{}),c(this,"nstags",{}),c(this,"epubtypes",{}),c(this,"classes",{}),c(this,"ids",{}),c(this,"pagetypes",{}),c(this,"order",0)}clone(){let t=new Yd;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Ki(this.tags,t.tags),Ki(this.nstags,t.nstags),Ki(this.epubtypes,t.epubtypes),Ki(this.classes,t.classes),Ki(this.ids,t.ids),Ki(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,o,s){return new ev(this,t,i,n,r,o,s)}nextOrder(){return this.order+=yl}},Zd=class Kd{constructor(t,i,n,r,o,s,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=s,this.cmykStore=a,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",Object.create(null)),c(this,"currentElement",null),c(this,"currentElementOffset",null),c(this,"currentStyle",null),c(this,"currentClassNames",null),c(this,"currentLocalName",""),c(this,"currentNamespace",""),c(this,"currentId",""),c(this,"currentXmlId",""),c(this,"currentNSTag",""),c(this,"currentEpubTypes",null),c(this,"currentPageType",null),c(this,"previousPageType",null),c(this,"firstPageType",null),c(this,"pageTypePageIndices",Object.create(null)),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",Object.create(null)),c(this,"lastCounterChanges",[]),c(this,"lastCounterChangeTypes",Object.create(null)),c(this,"counterScoping",[Object.create(null)]),c(this,"quotes"),c(this,"quoteDepth",0),c(this,"lang",""),c(this,"siblingOrderStack",[0]),c(this,"currentSiblingOrder",0),c(this,"siblingTypeCountsStack",[{}]),c(this,"currentSiblingTypeCounts"),c(this,"currentFollowingSiblingOrder",null),c(this,"followingSiblingOrderStack"),c(this,"followingSiblingTypeCountsStack",[{}]),c(this,"currentFollowingSiblingTypeCounts"),c(this,"viewConditions",Object.create(null)),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=t,this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=Xr.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:Xr.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Xr.buildAllMatcher(n):Xr.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=Es,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,o,s,a,h,l;let u=new Set,d=Object.create(null),p=v.inline,f=t.display;if(f&&(p=f.evaluate(this.context)),p===v.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let g=v.inline,m=t.float;m&&(g=m.evaluate(this.context));let w=null,x=null,y=null,b=t["counter-reset"];if(b){let N=b.evaluate(this.context);N&&(w=vn(N,{reset:!0}))}let S=t["counter-set"];if(S){let N=S.evaluate(this.context);N&&(y=vn(N,{defaultValue:0}))}let C=t["counter-increment"];if(C){let N=C.evaluate(this.context);N&&(x=vn(N))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(w||(w=Object.create(null)),w["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),jn(p)&&(x||(x=Object.create(null)),x["list-item"]=(r=x["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((s=(o=this.currentElement)==null?void 0:o.getAttribute("value"))!=null?s:"")&&(y||(y=Object.create(null)),y["list-item"]=this.currentElement.value)),((h=(a=this.currentElement)==null?void 0:a.parentNode)==null?void 0:h.nodeType)===Node.DOCUMENT_NODE&&(w||(w=Object.create(null)),w.footnote===void 0&&(w.footnote=0)),g===v.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(x||(x=Object.create(null)),x.footnote===void 0)){let N=(l=this.currentStyle["counter-increment"])==null?void 0:l.value;(!N||!(N===v.footnote||N instanceof J&&N.values.includes(v.footnote)))&&(x.footnote=1)}if(w)for(let N in w)u.add(N),d[N]="reset";if(x)for(let N in x)u.add(N),d[N]||(d[N]="increment");if(y)for(let N in y)u.add(N),d[N]="set";if(this.lastCounterChanges=Array.from(u),this.lastCounterChangeTypes=d,w)for(let N in w)this.defineCounter(N,w[N]);if(x)for(let N in x){this.counters[N]||this.defineCounter(N,0);let F=this.counters[N];F[F.length-1]+=x[N]}if(y)for(let N in y)if(!this.counters[N])this.defineCounter(N,y[N]);else{let F=this.counters[N];F[F.length-1]=y[N]}if(jn(p)){let N=this.counters["list-item"],F=N[N.length-1];t["ua-list-item-count"]=new V(new Ct(F),0);let B=ei(t,"_pseudos");B.marker||(B.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new mr(this,this.currentElement,this.counterResolver));let n=i.value instanceof it?i.value.values:[i.value];for(let r of n)if(r instanceof J){let o=r.values[0].stringValue(),s=r.values.slice(1).map(a=>Do(a,this.context)).join("");this.counterResolver.setNamedString(o,s,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof ci&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new mr(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var o,s,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=Es;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=Es;let d=_s(i);d&&(this.stack[this.stack.length-1].push(new Yy(this.lang)),this.lang=d.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let x=this.followingSiblingOrderStack;x[x.length-1]!==null?this.currentFollowingSiblingOrder=--x[x.length-1]:this.currentFollowingSiblingOrder=null,x.push(null);let y=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=y[y.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,y.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i);let S=n.quotes,C=null;if(S){let B=S.evaluate(this.context);B&&(C=new Zy(this.quotes),B===v.none?this.quotes=[new X(""),new X("")]:B===v.auto||B===v.initial?this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")]:B instanceof J&&(this.quotes=B.values))}this.pushCounters(this.currentStyle);let N=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||N){let B=Object.create(null);Object.keys(this.counters).forEach(U=>{B[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(N,B)}let F=gt(this.currentStyle,"_pseudos");if(F){let B=!0;for(let U of tv){U||(B=!1);let q=F[U];if(q){let he=(o=me(this.currentStyle,"float"))==null?void 0:o.value,ae=i instanceof Element&&_t(i),k=i instanceof Element&&bt(i),_=!!me(this.currentStyle,"--viv-semantic-footnote-content"),E=he===v.footnote,L=(U==="before"||U==="after")&&(E||k||_)&&!!q.content,P=Sy(q),A=U==="footnote-call"&&ae&&P,O=U==="footnote-marker"&&(k||_)&&P;if((U==="before"||U==="after")&&!(L||kt((s=q.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(q))||U==="marker"&&!jn((a=me(this.currentStyle,"display"))==null?void 0:a.value)||(U==="footnote-call"||U==="footnote-marker")&&he!==v.footnote&&!A&&!O||(U==="footnote-call"||U==="footnote-marker")&&_&&!P)delete F[U];else if(B){if(this.processPseudoelementProps(q,i,U),U==="marker")this.processMarkerPseudoelementProps(q,i,t),delete F[U];else if(U==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(q,"list-style-position",t,i)===v.outside){this.processMarkerPseudoelementProps(q,i,t);let z=q.content;z&&(this.currentStyle["_footnote-marker-content"]=z),this.currentStyle.display=new V(M("list-item"),0),this.currentStyle["list-style-position"]=new V(v.outside,0),this.currentStyle["list-style-type"]=new V(v.none,0),this.currentStyle["list-style-image"]=new V(v.none,0),delete F[U]}}else if(U==="first-letter"&&q["initial-letter"]){let z=q["initial-letter"].evaluate(this.context);z!==v.normal&&!Z(z)&&(this.currentStyle["--viv-initialLetter"]=new V(z,0)),delete q["initial-letter"]}}else this.stack[this.stack.length-2].push(new qy(q,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return kt((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,o,s,a,h;let l=jn((r=this.currentStyle.display)==null?void 0:r.value);if(!kt((o=t.content)==null?void 0:o.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ut)t.content=new V(new J([p,new X(" ")]),0);else if(d instanceof X)t.content=new V(d,0);else if(d instanceof de&&d!==v.none){let f=(a=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new X(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let u=t.content;if(u){let d=u.value;if(kt(d)){let p=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new V(p,0)}}for(let d of Kd.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!Z(f)&&(this.currentStyle[`--viv-marker-${d}`]=new V(f,0))}}if(!Ht((h=me(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==v.outside&&!Z(d)&&(this.currentStyle["list-style-position"]=new V(d,0))}}resolveMarkerContentVal(t){if(t instanceof G){let i=t.expr.evaluate(this.context);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):t}if(t instanceof J){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new J(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let s=n;s;s=s.parentElement){let a=(s===this.currentElement?this.currentStyle:i.getStyle(s,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let o=i.validatorSet;return(r=o?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var o;let s=t[i];if(s){let a=s.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(o=h?.defaultValues[i])!=null?o:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i){for(let n in i)Di(n)&&!Qt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new Ky(t),n=this.currentStyle,r=gt(n,"_pseudos");for(let o in r)this.applyAttrFilterInner(i,r[o]);this.applyAttrFilterInner(i,n)}applyVarFilter(t,i,n){var r,o,s;let a=t[0],h=new cv(t,i,n),l=32,u={};for(let d in a)if(oo(d)){let p=gt(a,d);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Di(d)){let p=me(a,d),f=p.value;for(let g=0;;g++){if(g>=l){f=Y;break}let m=f.visit(h);if(h.error){f=Y,h.error=!1;break}if(m===f)break;f=m}if(f!==p.value){let g=i.validatorSet,m=(r=g?.shorthands[d])==null?void 0:r.clone();if(m)if(Z(f)){for(let w of m.propList){let x=new V(f,p.priority),y=me(a,w);Ci(u,w,ca(this.context,y,x))}delete a[d]}else{let w=Rr(i.scope,new Vt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let x of m.propList){let y=new V((s=(o=m.values[x])!=null?o:g.defaultValues[x])!=null?s:v.initial,p.priority),b=me(a,x);Ci(u,x,ca(this.context,b,y))}delete a[d]}}else a[d]=new V(f,p.priority)}if(u[d]){let g=me(a,d);g&&g.value!==Y&&Gt(u,d,g,this.context)}}for(let d in u)a[d]=u[d]}applyCalcFilter(t,i){let n=new op(i);for(let r in t)if(oo(r)){let o=gt(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Di(r)&&!Qt(r)){let o=me(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new V(s,o.priority))}}applyCmykFilter(t,i){let n=new gc(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(oo(r)){let o=gt(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Di(r)&&!Qt(r)){let o=me(t,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),t[r]=new V(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};c(Zd,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","hyphens","line-height","tab-size","text-combine-upright","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-orientation","text-shadow","text-transform","unicode-bidi","direction","white-space"]);var ev=Zd,Es=[],tv=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ma=null;function iv(e){ma=e}var wr=class extends Xi{constructor(e,t,i,n,r,o,s){super(e,t,s),this.condition=i,this.regionId=r,this.validatorSet=o,c(this,"chain",null),c(this,"specificity",0),c(this,"elementStyle",null),c(this,"conditionCount",0),c(this,"pseudoelement",null),c(this,"selectorFunctionContainsPseudoelement",!1),c(this,"footnoteContent",!1),c(this,"cascade"),c(this,"state"),c(this,"viewConditionId",null),c(this,"insideSelectorRule"),c(this,"invalid",!1),this.cascade=n?n.cascade:ma?ma.clone():new Qy,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=fl(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}invalidContinuationAfterPseudoelement(e){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${e}`),!0):this.selectorFunctionContainsPseudoelement?(this.invalidSelector(`Selector containing pseudo-element followed by ${e}`),!0):!1}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||this.invalidContinuationAfterPseudoelement(t||"*")||(t&&(this.specificity+=1),t&&e?this.chain.push(new Iy(e,t.toLowerCase())):t?this.chain.push(new Ah(t.toLowerCase())):this.chain.push(new Fy(e)))}invalidSelector(e){j.warn(e),this.chain.push(new et("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof In;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new Ny(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Dy);break;case"disabled":this.chain.push(new zy);break;case"checked":this.chain.push(new Vy);break;case"root":case"scope":this.chain.push(new By);break;case"link":this.chain.push(new Ah("a")),this.chain.push(new Fh("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${di(i)}($|\\s)`),r=t[1];this.chain.push(new Ay(n,r,e==="href-role-type"))}else this.chain.push(new et(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new et(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Oy(new RegExp(`^${di(i.toLowerCase())}($|-)`)))}else this.chain.push(new et(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=nv[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new et(""));break}case"first-child":this.chain.push(new Rh);break;case"last-child":this.chain.push(new fa(0,1));break;case"first-of-type":this.chain.push(new pa(0,1));break;case"last-of-type":this.chain.push(new ga(0,1));break;case"only-child":this.chain.push(new Rh),this.chain.push(new fa(0,1));break;case"only-of-type":this.chain.push(new pa(0,1)),this.chain.push(new ga(0,1));break;case"empty":this.chain.push(new _y);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}}pseudoelementSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`::${e}`)){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new et(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new et(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new Ty(e)))}attributeSelector(e,t,i,n){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new Fh(e,t);break;case 39:r=new Ry(e,t,n);break;case 45:!n||n.match(/\s/)?r=new et(""):r=new $n(e,t,new RegExp(`(^|\\s)${di(n)}($|\\s)`));break;case 44:r=new $n(e,t,new RegExp(`^${di(n)}($|-)`));break;case 43:n?r=new $n(e,t,new RegExp(`^${di(n)}`)):r=new et("");break;case 42:n?r=new $n(e,t,new RegExp(`${di(n)}$`)):r=new et("");break;case 46:n?r=new $n(e,t,new RegExp(di(n))):r=new et("");break;case 50:if(n=="supported")r=new Ly(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(r)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Yr++}`;this.processChain(new qr(new Wy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Yr++}`;this.processChain(new qr(new Gy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Yr++}`;this.processChain(new qr(new jy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Yr++}`;this.processChain(new qr(new Xy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new ml(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ha(t,0,this.condition):i=new V(t,0),Vd(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Dt("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:e,value:t,important:i});e=s.name,t=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new ha(t,n,this.condition):new V(t,n);Gt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new In(this);break;case"not":i=new rv(this);break;case"where":i=new ov(this);break;case"has":i=new sv(this);break;case"nth-child":t&&t.length>=2&&(i=new Qd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new av(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},nv={"nth-child":My,"nth-of-type":pa,"nth-last-child":fa,"nth-last-of-type":ga},Yr=0,In=class Jd extends wr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,c(this,"parentChain"),c(this,"chains",[]),c(this,"maxSpecificity",0),c(this,"selectorTexts",[]),c(this,"containsPseudoelementSelector",!1),this.parentChain=t.chain}nextSelector(){this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){var t;this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new $y(this.selectorTexts):this.positive()?new wl(this.chains):new Uy(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new et("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof Jd;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},rv=class extends In{positive(){return!1}forgiving(){return!1}},ov=class extends In{increasingSpecificity(){return!1}},sv=class extends In{relational(){return!0}},Qd=class extends In{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Wd(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}forgiving(){return!0}},av=class extends Qd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Hy(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}},lv=class extends Xi{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new Er(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},so=class extends Xi{constructor(e,t,i,n,r,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=o,c(this,"order"),this.order=0}property(e,t,i){i?j.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=yl;let r=this.condition?new ha(t,n,this.condition):new V(t,n);Gt(this.elementStyle,e,r)}},hv=class extends Yc{constructor(e,t){super(e),this.validatorSet=t,c(this,"elementStyle",{}),c(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?qc:Xc;n+=this.order,this.order+=yl;let r=new V(t,n);Gt(this.elementStyle,e,r)}};function ep(e,t){let i=Dd(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function wa(e,t,i){ep(i,n=>{or(e,n,t)})}function uv(e,t,i,n){let r=new hv(e,t),o=new Vt(n,r);try{aw(o,r,i)}catch(s){j.warn(s,"Style attribute parse error:")}return r.elementStyle}function tp(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function ip(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function ya(e,t,i,n,r){let o={};for(let s in e)Di(s)&&(o[s]=me(e,s));return wa(o,t,e),np(e,i,n,(s,a)=>{or(o,a,t),wa(o,t,a)}),o}function np(e,t,i,n){let r=gt(e,"_regions");if((t||i)&&r){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let s=r[o];s&&n(o,s)}}}function or(e,t,i){for(let n in t)if(Di(n)){let r=me(t,n),o=e[n];e[n]=ca(i,o,r)}}var rp=(e,t,i,n,r,o)=>{var s,a;let h=i?n?wy:Od:n?yy:Bd,l=r?vy:by;for(let u in e){let d=e[u];if(!d)continue;let p=(s=h[u])!=null?s:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>d.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>d.priority))continue;m=Ih[p]?p:Ih[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===v.inside||d.value===v.outside)&&(d=new V(r===(d.value===v.inside)?v.right:v.left,d.priority));t[m]=o(u,d)}},cv=class extends Gi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,r,o;let s=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=(o=(r=this.styler.getStyle(s,!1))==null?void 0:r[e])==null?void 0:o.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof de&&e.values[0].name;return!t||!Qt(t)?(this.error=!0,Y):this.getVarValue(t)||(e.values.length<2?(this.error=!0,Y):e.values.length===2?e.values[1]:new it(e.values.slice(1)))}},op=class extends Gi{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=Rr(this.context.rootScope,new Vt(i,null),"");if(n instanceof G)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new R(r,"px"):/\d[a-z]/i.test(i)||(t=new Ct(r)))}catch(r){j.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Hu(e.unit)||this.context.rootFontSize!=null&&fg(e.unit)?new R(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new R(e.num*this.percentRef/100,"px"):e}};function zo(e,t,i,n,r){try{if(t instanceof G)return t.expr instanceof Re&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:uw(e,t.expr,i);if(t instanceof R||t instanceof ci||t instanceof J||t instanceof it)return t.visit(new op(e,!0,n,r))}catch(o){return j.warn(o),Y}return t}var Lh={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Oh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.none;if(t===v.none)return Lh;let i=t instanceof J?t.values:[t],n=Object.create(Lh);for(let r of i)if(r instanceof de)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function Bh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var dv={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Mh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},_h={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Dh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.normal;if(t===v.normal)return Mh;if(t===v.auto)return _h;let i=t instanceof J?t.values:[t],n=Object.create(Mh);for(let r of i)if(r instanceof de)switch(r.name){case"trim-both":case"trim-auto":return _h;case"space-all":return dv;case"trim-start":n.trimStart=!0,n.spaceFirst=!1;break;case"space-start":n.trimStart=!1,n.spaceFirst=!1;break;case"space-first":n.trimStart=!1,n.spaceFirst=!0;break;case"trim-end":n.trimEnd=!0,n.allowEnd=!1;break;case"space-end":n.trimEnd=!1,n.allowEnd=!1;break;case"allow-end":n.trimEnd=!1,n.allowEnd=!0;break;case"trim-adjacent":n.trimAdjacent=!0;break;case"space-adjacent":n.trimAdjacent=!1;break}return n}var Ps={ideographAlpha:!1,ideographNumeric:!1},pv={ideographAlpha:!0,ideographNumeric:!0};function zh(e){let t=e instanceof nt?e:typeof e=="string"?M(e):v.normal;if(t===v.normal||t===v.auto)return pv;if(t===v.none)return Ps;let i=t instanceof J?t.values:[t],n=Object.create(Ps);for(let r of i)if(r instanceof de)switch(r.name){case"no-autospace":return Ps;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Vh(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Uh(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var fv=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let o=r.length-1;for(let s=0;s<o;s++)n.parentNode.insertBefore(document.createTextNode(r[s]),n);n.textContent=r[o]}}}processGeneratedContent(e,t,i,n,r,o){r=Uh(r);let s=zh(t),a=Dh(i),h=Oh(n);if(Bh(h)&&Vh(s,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!d,m=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||m,g,m,w,x,d,p,s,a,h,r,o),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let u=!e||e.fragmentIndex===1&&f(),d=u||g();function p(y){var b;if(y?.nodeType!==1)return!1;let S=y;if(S.hasAttribute(Pn))return!0;let{position:C,float:N}=(b=S.style)!=null?b:{};return C==="absolute"||C==="fixed"||N&&N!=="none"}function f(){let y=t[0];for(let b=y;;b=b.parent)if(!b||!b.inline){if(b?.fragmentIndex!==1)return!1;break}if(!y.inline)return!0;for(let b=y.viewNode.previousSibling;b;b=b.previousSibling)if(!Le(b,y.whitespace)&&!p(b))return!1;return!0}function g(){var y,b;let S=t[0],C;for(;S&&S.inline&&(C=(y=S.viewNode)==null?void 0:y.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&S.whitespace!==ft.PRESERVE&&(C=C.previousSibling),C)));)S=S.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let N=(b=C.style)==null?void 0:b.display;if(N&&N!=="inline")return!/^(inline|ruby)\b/.test(N)}else if(C.nodeType===Node.TEXT_NODE){if(S.whitespace===ft.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(S.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let m=-1;for(let y=0;y<t.length;y++){let b=t[y];if(!b.after&&b.inline&&!b.display&&b.parent&&b.viewNode.parentNode&&b.viewNode.nodeType===Node.TEXT_NODE&&!Le(b.viewNode,b.whitespace)){let S=function(P){var A,O,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===ft.PRESERVE){if(/\n$/.test(W.textContent))return!0}else if(P.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(W.textContent))return!0;if(((z=W.previousElementSibling)==null?void 0:z.localName)==="br")return Le(W,P.whitespace)}return!1},C=function(P){var A,O,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===ft.PRESERVE){if(/^\n/.test(W.textContent))return!0}else if(P.whitespace===ft.NEWLINE&&/^[ \t\r\n\f]*\n/.test(W.textContent))return!0;if(((z=W.nextElementSibling)==null?void 0:z.localName)==="br")return Le(W,P.whitespace)}return!1};var w=S,x=C;m<0&&(m=y);let N=Uh((o=(n=(i=b.lang)!=null?i:b.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),F=zh(b.inheritedProps["text-autospace"]),B=Dh(b.inheritedProps["text-spacing-trim"]),U=Oh(b.inheritedProps["hanging-punctuation"]);if(Bh(U)&&Vh(F,B)||/\b(flex|grid)\b/.test(b.parent.display))continue;let q=null,he=null,ae=y===m,k=y===m&&u,_=y===m&&d,E=!1,L=!1;for(let P=y-1;P>=0;P--){let A=t[P];if(S(A)){_=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){q=A.viewNode;break}if(((s=A.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&Kt(A.viewNode)==="footnote-call"){if(A.viewNode.contains(b.viewNode))continue;let O=Sw(A.viewNode);if(O){q=O;break}}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||_i[A.viewNode.localName]))break;P===0&&(ae=!0,u&&(k=!0,_=!0))}for(let P=y+1;P<t.length;P++){let A=t[P];if(C(A)){E=!0;break}if(A.viewNode!==b.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){he=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((h=A.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||_i[A.viewNode.localName])){P===t.length-1&&p(A.viewNode)&&(L=!0);break}if(P===t.length-1){E=!0,L=!0;for(let O=A.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){L=!1;break}}}if(((l=b.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=b.parent.viewNode.firstChild;for(;Le(P,b.whitespace);)P=P.nextSibling;b.viewNode===P&&(k=!0)}if(!L){let P=b.parent.viewNode.lastChild;for(;Le(P,b.whitespace);)P=P.previousSibling;b.viewNode===P&&(L=!0)}}if(this.processTextSpacing(b.viewNode,ae,k,_,E,L,q,he,F,B,U,N,b.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,u,d,p){let f=e.textContent,g=e.ownerDocument,m=0,w,x,y;function b(){if(t)return!0;if(!s)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(s));let L=x.getClientRects(),P=L[L.length-1];return P?(m||(m=fr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function S(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;m||(m=fr(E,p)),y||(y=g.createRange(),y.selectNode(a));let L=y.getClientRects()[0];return L?p?E.top+E.height>L.top+E.width||E.left>L.left+L.width-E.width/10||E.left+E.width<L.left+E.width/10:E.left+E.width>L.left+E.height||E.top+E.height<L.top+E.height/10||E.top>L.top+L.height-E.height/10:!1}let C=!1,N=!1,F=!1,B=!1,U;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0,N=!0):o&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,F=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,B=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(U="viv-ts-close",C=!0),C){let E=function(z){let W=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>W},L=function(){return p?P.offsetLeft:P.offsetTop};var q=E,he=L;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(U),A=g.createElement("viv-ts-inner");P.appendChild(A),e.parentNode.insertBefore(P,e),A.appendChild(e);let O=E(A);if(O||N||F||B){if(U==="viv-ts-open"){if(N)P.className="viv-hang-first";else if(i||n)l.trimStart?P.className="viv-ts-trim":P.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&b())P.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||s.parentElement.localName==="viv-ts-inner"&&E(s.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&b()){let z=L();P.className="viv-ts-auto",z===L()&&!b()&&(P.className="viv-ts-trim")}}else if(U==="viv-ts-close"){if(F)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let z=L();B?(P.className=O?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===L()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",z===L()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",z===L()&&(P.className="")):P.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))O&&l.trimAdjacent&&(P.className="viv-ts-trim");else if(B){let z=S(),W=z&&u.allowEnd;W||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?W&&l.trimEnd?P.className="viv-ts-auto":!W&&!S()?P.className="":!z&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):(P.className="viv-ts-space",S()||(l.allowEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!z&&!S()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let z=L();P.className="viv-ts-auto",z===L()&&(P.className="")}}}}let ae=!1;function k(E){var L;let P=(L=E?.ownerDocument.defaultView)==null?void 0:L.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function _(E,L){if(E.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(E);if(parseFloat(O.marginInlineEnd)||parseFloat(O.borderInlineEndWidth)||parseFloat(O.paddingInlineEnd))return!0}let P=E.parentElement;if(P&&!P.contains(L))return _(P,L);if(L.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(L);if(parseFloat(O.marginInlineStart)||parseFloat(O.borderInlineStartWidth)||parseFloat(O.paddingInlineStart))return!0}let A=L.parentElement;return A&&!A.contains(E)?_(E,A):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&k(s.parentElement))&&!_(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ae=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&k(a.parentElement))&&!_(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ae=!0)),m}registerHooks(){At("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),At("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),At("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},vl=new fv;vl.registerHooks();function gv(e){vl.preprocessForTextSpacing(e)}function mv(e,t,i,n,r,o){vl.processGeneratedContent(e,t,i,n,r,o)}var qn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),wv=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],bl="data-adapt-pseudo";function Kt(e){return e.getAttribute(bl)||""}function sr(e,t){e.setAttribute(bl,t)}var Ns=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,c(this,"contentProcessed",{})}getStyle(e,t){let i=Kt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=gt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new V(new Ue(o),0)}return r}processContent(e,t,i){let n=Kt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;kt(r)&&(r.visit(new gr(e,this.context,r,this.exprContentListener)),gv(e))}}},jx=Fo.isInstanceOfAfterIfContinuesLayoutConstraint,yv=os.registerFragmentIndex,Xx=os.clearFragmentIndices,vv=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new xl(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return I(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=qn.createElementNS("http://www.w3.org/1999/xhtml","div");sr(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new Ei(i)}createShadowContext(e){return new no(this.sourceNode,e,null,null,null,li.ShadowType.ROOTED,this.styler)}},bv=class sp{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,c(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new xv(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof sp?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},xv=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function ap(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return T(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=Cv(e,t,n);return t.fragmentLayoutConstraints.push(new bv(e,i,r)),T(e)})}function lp(e,t){return e.thenAsync(i=>ap(i,t))}function Sv(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=ap(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function Cv(e,t,i){let n=e.viewNode;n.appendChild(i);let r=ea(i,t,e.vertical);return n.removeChild(i),r}var kv=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Yn=class extends ul{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,c(this,"alreadyEvaluated",!1),c(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Vo=class extends Cd{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isNonFirstColumn",!1),c(this,"isFloat",!1),c(this,"isFootnote",!1),c(this,"startEdge",0),c(this,"endEdge",0),c(this,"beforeEdge",0),c(this,"afterEdge",0),c(this,"footnoteEdge",0),c(this,"box",null),c(this,"chunkPositions",null),c(this,"bands",null),c(this,"overflown",!1),c(this,"breakPositions",null),c(this,"pageBreakType",null),c(this,"forceNonfitting",!0),c(this,"leftFloatEdge",0),c(this,"rightFloatEdge",0),c(this,"bottommostFloatTop",0),c(this,"stopAtOverflow",!0),c(this,"lastAfterPosition",null),c(this,"fragmentLayoutConstraints",[]),c(this,"pseudoParent",null),c(this,"nodeContextOverflowingDueToRepetitiveElements",null),c(this,"blockDistanceToBlockEndFloats",NaN),c(this,"lastLineStride",0),c(this,"breakAtTheEdgeBeforeFloat",null),mw(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=this.clientLayout.pixelRatio===0?.5:1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}getFloatLayoutUnit(){return this.clientLayout.pixelRatio===0?0:1/(this.clientLayout.pixelRatio||1)}getFloatLayoutTolerance(e){return e||1}isOverflown(e){let t=1.5/(this.clientLayout.pixelRatio||1);return this.almostEquals(e,this.footnoteEdge,t)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=D("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let o=r,s=i[n];if(r=Lo(s,o),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return T(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Lw(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,o=r.match(Co),s=o?o[0].length:0;if(!o&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(Co);if(h){let l=h[0];s=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(s)}}return this.layoutContext.peelOff(e,s)}return T(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=D("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!pn(e)&&((o=e.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let s=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(s);if(fr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,pn(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(Si(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return lp(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=D("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!pn(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(o=>{let s=o;if(s!==e){let a=s;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=s,r.breakLoop();return}pn(s)||t.push(s.copy())}this.nextInTree(s).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Si(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null,a=1.5/(this.clientLayout.pixelRatio||1);for(let p of t){let f=Math.abs(p.x1-i)<a&&Math.abs(p.x2-n)<a?a:void 0;this.almostEquals(p.x1,i,f)?p.x1=i:this.almostEquals(p.x1,n,f)&&(p.x1=n),this.almostEquals(p.x2,n,f)?p.x2=n:this.almostEquals(p.x2,i,f)&&(p.x2=i),this.almostEquals(p.y1,r,f)?p.y1=r:this.almostEquals(p.y1,o,f)&&(p.y1=o),this.almostEquals(p.y2,o,f)?p.y2=o:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=Ga==="webkit"?Math.floor:Math.round,u=t.map(p=>h>0?(l(p.y2/h)-l(p.y1/h))*h:p.y2-p.y1),d=.01;for(let p=0;p<t.length;p++){let f=p<t.length-1?t[p+1].x1:i,g=p<t.length-1?t[p+1].x2:n,m=f-t[p].x1,w=t[p].x2-g,x=0,y=0;m>d?x=1:m<-d&&(x=-1),w>d?y=1:w<-d&&(y=-1);let b=x!==0&&y!==0?x===y?x:0:x||y;if(h>0&&b!==0){let S=b*h;u[p]+S>=0&&(p>=t.length-1||u[p+1]-S>=0)&&(u[p]+=S,p<t.length-1&&(u[p+1]-=S))}}for(let p=0;p<t.length;p++){let f=t[p];f.left=this.createFloat(e,"left",f.x1-i,u[p]),f.right=this.createFloat(e,"right",n-f.x2,u[p]),f.x1<n&&f.x2>i?s=f:s||I(f.right,"float","none")}if(s){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(s!==p&&(p.y2>=o||this.almostEquals(p.y2,o,f))&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let g=t.indexOf(s);g<t.length;g++){let m=t[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),n=1.5/(this.clientLayout.pixelRatio||1);if(i>0&&i<t&&!this.almostEquals(i,t,n)){let r=this.vertical?"width":"height";if(I(this.element,r,`${i}px`),this.vertical){let o=this.left+(t-i);I(this.element,"left",`${o}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&dn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=sn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=sn(e,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(o=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ys(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=D("layoutFloat"),i=e.viewNode,n=Cs(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Tt(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new It(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let S=u.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),u.viewNode.appendChild(S);let C=Tt(this.clientLayout,S,this.vertical);h=Math.max(this.rtl?this.getEndEdge(C):this.getStartEdge(C),h),l=Math.min(this.rtl?this.getStartEdge(C):this.getEndEdge(C),l),u.viewNode.removeChild(S);let N=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+N):h=Math.min(h,l-N),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new It(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=Po(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let S=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+S}if(e.clearSide){let S=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?Cs(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;S!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),S!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let N=C*f;if(p.y1<N){let F=p.y2-p.y1;p.y1=N,p.y2=p.y1+F}}d.y2+=this.getFloatLayoutUnit(),$g(d,this.bands,p,n),this.vertical&&(a=vc(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let S=w.viewNode.ownerDocument.createElement("div");S.style.position="absolute",w.vertical?S.style.right="0":S.style.left="0",S.style.top="0",w.viewNode.appendChild(S),m=Tt(this.clientLayout,S,this.vertical),w.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let S=Math.max(0,m.right-a.x2);I(i,"right",`${S}px`)}else{let S=Math.max(0,a.x1-m.left);I(i,"left",`${S}px`)}let x=Math.max(0,a.y1-m.top);I(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let y=this.vertical?a.x1:a.y2,b=this.vertical?a.x2:a.y1;!this.isOverflown(y)||this.breakPositions.length==0?(this.killFloats(),d=new It(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=Po(d)),Hg(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=b,this.updateMaxReachedAfterEdge(y),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!s.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!s.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!s.hasFloatFragments(),o);if(u){if(e.isFootnote){let d=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(d.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,I(e.element,"width",`${p}px`))}else{let p=parseFloat(d.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,I(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return T(u)})}createPageFloatArea(e,t,i,n,r){let o=this.element.ownerDocument.createElement("div");I(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new ln(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new Nv(t,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>T(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,o,s){let a=this.pageFloatLayoutContext;e=(s?s.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},d=D("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(u.floatArea=p,!p){d.finish(u);return}let f=!1,g=0;d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],x=new Ei(w.nodePosition),y=p.breakPositions?p.breakPositions.length:0;p.layout(x,!0).then(b=>{if(u.newPosition=b,!b||n){if(b&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.length>y&&p.breakPositions.slice(y).some(S=>S instanceof Yn))){f=!0,m.breakLoop();return}g++,m.continueLoop()}else f=!0,m.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&u.newPosition){let m=a.getPageFloatLayoutContext(h.floatReference);if(m.footnoteMaxBlockSize==null){if(m.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,o,s).then(w=>{d.finish(w)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,o,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}d.finish(u)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,o=e.float,s=new Set;for(let u=r;u;u=u.effectiveParent)for(let d of u.floatFragments)d.continuations.some(p=>p.float.insidePageFloatArea)&&s.add(d);r.stashEndFloatFragments(o);function a(u,d){d?r.removePageFloatFragment(d,!0):u&&u.element.parentNode.removeChild(u.element);let p=[];for(let f=r;f;f=f.effectiveParent)for(let g of f.floatFragments)!s.has(g)&&g.continuations.some(m=>m.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(e)}let h=o instanceof Bo,l=D("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let d=u.floatArea,p=u.pageFloatFragment,f=u.newPosition;p?this.layoutStashedPageFloats(o.floatReference,[n]).then(g=>{if(g){let m=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,m),r.discardStashedFragments(o.floatReference),f){let w=new Ph(o,f.primary);r.deferPageFloat(w)}l.finish(!0)}else a(d,p),l.finish(!1)}):(a(d,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=D("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let d=new Tn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,d,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!s)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Kt(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(Pn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=D("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<o.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=sl(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Tn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=Ro(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new Ph(o,s);if(h&&h.hasFloat(o))return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(t.isForbidden(o)||t.hasPrecedingFloatsDeferredToNext(o))return t.deferPageFloat(l),t.registerPageFloatAnchor(o,a.viewNode),T(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let u=p=>{if(!p||p.nodeType!==1)return NaN;let f=Tt(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},d=sn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=o;if(p.footnotePolicy===v.line||isNaN(d)){let f=a;for(;f;){if((f.shadowContext?f.shadowContext.owner:f.sourceNode)===p.policyAnchorNode){let g=u(f.viewNode);isNaN(g)||(d=g);break}f=f.parent}}}return isNaN(d)&&e.floatSide==="footnote"&&(d=u(a.viewNode)),this.isOverflown(d)?T(a):this.layoutPageFloatInner(l,i,d,h).thenAsync(p=>p?e.floatSide==="footnote"||t.generatingNodePosition?T(a):T(null):(t.registerPageFloatAnchor(o,a.viewNode),T(a)))}})}processLineStyling(e,t,i){let n=D("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=e.firstPseudo;return s?.count===0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(u,0).then(d=>{e=d,s=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&_i[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?t=Math.max(t,s):i=Math.min(i,s)}return t+i}layoutBreakableBlock(e){let t=D("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??e),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!dn(n.viewNode)){let l=xn(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=T(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Dt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,o=t[0].boxOffset,s=r,a=t.length-1,h=t[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let u=a;for(;s<u;){let p=s+Math.ceil((u-s)/2);t[p].boxOffset>l?u=p-1:s=p}let d=this.calculateEdge(null,t,s,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(d),o=l,r=s}return{nodeContext:t[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(e,t,i){var n,r,o;let s=this.findEndOfLine(t,e,!0),a=s.nodeContext;if(s.checkPointIndex===0&&s.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,s.index,e,s.checkPointIndex,i)}else{let l=Sh(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof Yn&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(o=a.viewNode)==null?void 0:o.previousSibling;for(;u&&(Le(u,a.parent.whitespace)||Nt(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Dt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Uo.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,o=e,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;o==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=o.nodeType===1?o:null;d?r?r=!1:ol(d)?l=!a:!d.firstChild||_i[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||xw(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(d.localName)||(s=o),o.contains(t)&&(h=!1)):u=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),u||(u=o.nextSibling,u||(r=!0,u=o.parentNode)),o=u}while(l&&h);if(a){n.setEndAfter(s);let u=this.clientLayout.getRangeClientRects(n);Js(u,this.vertical);for(let d=0;d<u.length;d++)i.push(u[d]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?$w:Uw);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(s>0){let d=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/d:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/d:u=1}if(s==0||u>=.6||u>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(t.push(r),s=0),a>=i.length)break}return t.sort(Du),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&fn(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=xn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let s,a;t&&!this.isFootnote?(s=1,a=1):(s=Math.max((o.inheritedProps.widows||2)-0,1),a=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),l=this.findLinePositions(r),u=this.footnoteEdge-h,d=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=d*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=d*(1/0));let g=ai(l.length,y=>{let b=l[y];return this.vertical?b<u||b<=f.edge:b>u||b>=f.edge}),m=g<=0;m&&(g=ai(l.length,y=>this.vertical?l[y]<u:l[y]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(s=0,a=1),g=Math.min(l.length-s,g),g<a)return null;u=l[g-1];let x;if(m?x=f.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,u,t),x){let y=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(y)&&d*(u-y)>0&&(u=y),this.computedBlockSize=d*(u-this.beforeEdge)+p,l.length>=2){let b=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[b]-l[b-1])}}return x}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,sn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Un().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=dl.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let o=e.getMinBreakPenalty();o>i&&(n=Math.min(n,o))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return T(e);let r=D("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return j.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();e=i,o=!0,this.computedBlockSize=n}return this.finishBreak(e,o,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Nt(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!Io(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||fn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");wt(n,"block-end"),t.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let s=e;s;s=s.parent)if(Nt(s.viewNode))return!1;if(dn(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=sn(e,this.clientLayout,0,this.vertical);i();let r=xn(e,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let s=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||dn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=Tt(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),o=this.getBoxDir(),s=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(s)?Cs(s,e.vertical,e.direction,this.layoutContext.page.side):s,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=o*Math.max(l*o,this.leftFloatEdge*o);break;case"right":l=o*Math.max(l*o,this.rightFloatEdge*o);break;default:l=o*Math.max(l*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let d=this.getFloatLayoutUnit(),p=this.leftFloatEdge*o>this.beforeEdge*o||this.rightFloatEdge*o>this.beforeEdge*o;if(d>0&&p){let g=l*o>u*o;l=o*(Math.ceil(l*o/d)+(g?1:0))*d}let f=this.getFloatLayoutTolerance(d);if(r*o+f>l*o)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*o);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=Tt(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(ly(e)||zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(xh(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return T(e);let o=D("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],d=[],p=!1;function f(C){var N,F;if(!(!t||s.isNonFirstColumn||i||!Ch(h))){for(let B=C;B;B=B.parent)if(B.breakBefore==="column"&&(B.breakBefore=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakBefore)==="column"&&(U.style.breakBefore="")}}}function g(C){var N,F;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let B=C;B;B=B.parent)if(B.breakBefore==="column"&&(B.breakBefore=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakBefore)==="column"&&(U.style.breakBefore="")}h=null}}function m(C){var N,F;if(!(i||!Ch(h))){for(let B=C;B;B=B.parent)if(B.breakAfter==="column"&&(B.breakAfter=null),((N=B.viewNode)==null?void 0:N.nodeType)===1){let U=B.viewNode;((F=U.style)==null?void 0:F.breakAfter)==="column"&&(U.style.breakAfter="")}}}function w(C){h=tt(h,C)}function x(){return i?!0:qe(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!y()&&!b():!1}function y(){var C;if(!l||!e||e.floatSide)return!1;for(let N=l;N!=null&&N.parent;N=N.parent){if(N.parent.viewNode&&Nt(N.parent.viewNode))continue;let F=N.after?N.viewNode:(C=N.viewNode)==null?void 0:C.previousSibling;for(;F&&(Le(F,N.parent.whitespace)||Nt(F));)F=F.previousSibling;if(F)return!1}return!0}function b(){var C,N;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Nt(e.parent.viewNode))return!1;let F=!1;for(let B=e;B!=null&&B.parent&&!B.after;B=B.parent){if(B!==e&&Nt(B.viewNode))return!1;let U=(N=B.viewNode)==null?void 0:N.previousSibling;for(;U&&(Le(U,B.parent.whitespace)||Nt(U));)Nt(U)&&(F=!0),U=U.previousSibling;if(U)return!1}return F}let S=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var N;e;){e.formattingContext;let F=new Un().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Le(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ao(h)?h:null),F&&F.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?Sh(l):this.breakPositions[this.breakPositions.length-1]instanceof Yn||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||zi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Le(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),x()?S():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let U=e.viewNode,q=U.style;if(e.after){nd(U,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let he=e.sourceNode;if(he.localName==="svg"||he.localName==="math"||he.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),d.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||F&&F.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(xh(e.viewNode))break;if(x()){S(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,od(e.viewNode)||(l=e.copy(),d.push(l)),w(e.breakAfter),m(e),q&&!Nt(e.viewNode)&&this.hasNonZeroBlockEndInset(q)&&(d=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&qe(h)&&ww(l.viewNode,e.viewNode),(e.pageType!=((N=e.parent)==null?void 0:N.pageType)||!qe(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let he=e.viewNode.localName;if(_i[he]){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}q&&this.hasNonZeroBlockStartInset(q)&&(a=!1,d=[]),p=!0}}while(!1);let B=this.nextInTree(e,a);if(B.isPending()){B.then(U=>{e=U,C.continueLoop()});return}else e=B.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,d,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):qe(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=D("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Le(e.viewNode,e.whitespace))break;if(!e.after){qe(n)&&(this.pageBreakType=n),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=tt(n,e.breakBefore),qe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(qe(n)){this.pageBreakType=n,o.breakLoop();return}n=null}r=!1,n=tt(n,e.breakAfter)}else{n=tt(n,e.breakBefore);let h=e.viewNode.localName;if(_i[h]){qe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){o.breakLoop();return}}r=!0}while(!1);let s=this.layoutContext.nextInTree(e);if(s.isPending()){s.then(a=>{e=a,o.continueLoop()});return}else e=s.get()}t=null,o.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Si(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=D("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let o=e.formattingContext;new Un().find(o).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Un().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new It(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=zg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Un().find(e.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new Yn(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);rl(this);let n=D("layout");return this.openAllViews(e.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new Ev(t,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=T(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(Io(this)&&(bw(this),rs(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new Ei(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=D("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=D("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;e;){let s=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let s=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=s}this.killFloats(),this.init();let i=D("redoLayout"),n=0,r=null,o=!0;return i.loopWithFrame(s=>{if(n<e.length){let a=e[n++];this.layout(a,o).then(h=>{o=!1,h?(r=h,s.breakLoop()):s.continueLoop()});return}s.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(zi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Fo.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}ki.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},xl=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),c(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(o){return Vo.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),T(s)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Or(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return Hi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let o=r.data.slice(e.offsetInNode);if(!md(o,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Le(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Uo=class{breakTextNode(e,t,i,n,r,o){if(t.after)t.offsetInNode=e.length;else{let s=i-t.boxOffset,a=e.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(e,a,s,t):s=this.breakAfterOtherCharacter(e,a,s,t),s>0&&(t=this.updateNodeContext(t,s,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+$h(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&jl(r)&&jl(o)?$h(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Uo,"instance");Uo.instance=new Uo;function $h(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var Ev=class extends pl{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"initialLastLineStride",0),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new Pv(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||uy()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&rd(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},Pv=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return Sv(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},Nv=class extends Vo{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),this.floatSide=e,this.parentContainer=s,c(this,"rootViewNodes",[]),c(this,"floatMargins",[]),c(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),T(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(o,s){o.forEach(a=>{let h=mi(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=s*l/100;I(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(o=>{mi(e,o)==="auto"&&I(e,o,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=mi(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=mi(t,"width");n!==""&&n!=="auto"&&I(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Tt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,d,p;let f=(l=h.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(h);if((f?.getPropertyValue("--viv-footnote-display").trim()||"")==="compact")return!(f?.display==="list-item"&&f.getPropertyValue("list-style-position").trim()==="outside");let g=h.getAttribute(Zt);if(!g||!t||!i)return!1;let m=i.getNodeByOffset(parseInt(g,10));if(!m||m.nodeType!==Node.ELEMENT_NODE)return!1;let w=t.getStyle(m,!1),x=(d=(u=me(w,"footnote-display"))==null?void 0:u.value)==null?void 0:d.toString(),y=!!((p=me(w,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!y});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>o+s&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=Tt(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(t=>Kt(t)==="after")}hasAuthorFootnoteAfterPseudo(e){let t=this.getFootnoteAfterPseudo(e);if(t&&!t.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let i=Array.from(e.children).find(r=>r instanceof Element&&bt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");sr(t,"after"),t.setAttribute("data-vivliostyle-default-footnote-separator","1"),t.style.whiteSpace="normal",t.textContent=" ",e.appendChild(t)}getFootnoteBreakOpportunity(e){let t=e.nextElementSibling;return t!=null&&t.hasAttribute("data-vivliostyle-footnote-break")?t:null}createFootnoteBreakOpportunity(e){let t=e.ownerDocument.createElement("wbr");t.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",t)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[t+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),u=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!d?this.createFootnoteBreakOpportunity(r):p&&d?.remove()}else u&&h.remove(),d?.remove()})}},Wi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,c(this,"formattingContextType","RepetitiveElementsOwner"),c(this,"isRoot",!1),c(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||sa.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new Tv(e,this.rootSourceNode),sa.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},Tv=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,c(this,"headerSourceNode",null),c(this,"footerSourceNode",null),c(this,"headerViewNode",null),c(this,"footerViewNode",null),c(this,"headerNodePosition",null),c(this,"footerNodePosition",null),c(this,"headerHeight",0),c(this,"footerHeight",0),c(this,"isSkipHeader",!1),c(this,"isSkipFooter",!1),c(this,"enableSkippingFooter",!0),c(this,"enableSkippingHeader",!0),c(this,"doneInitialLayout",!1),c(this,"firstContentSourceNode",null),c(this,"lastContentSourceNode",null),c(this,"affectedNodeCache",[]),c(this,"afterLastContentNodeCache",[]),c(this,"allowInsert",!1),c(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Ro(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Ro(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=ea(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=ea(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,o=t.viewNode,s=r.createElement("div");o.appendChild(s);let a=new xl(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Ei(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(s),this.moveChildren(s,o,i),a.getColumn().pageBreakType=h,T(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Pn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},hp=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},up=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},Iv=class extends hp{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Av=class extends up{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Sl(e)),this.processor.doLayout(e,t)}},Sl=class cp{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=ni(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||dn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!pp(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let o=this.getRepetitiveElements();o&&t&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=ni(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return Bv(n,o,i).thenAsync(()=>Mv(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ni(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof cp?ni(this.nodeContext.formattingContext)===ni(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Fv=class extends pl{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new Iv(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Av(this.formattingContext,this.processor))}},Rv=class extends nr{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),T(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),T(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return nr.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?T(!0):nr.prototype.afterNonInlineElementNode.call(this,e)}},Lv=class extends gn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=ni(e.formattingContext);return n.getRootViewNode(e)?(i&&dp(e.parent,t),e.belongsTo(n)?gn.prototype.layout.call(this,e,t,i):new Fv(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=_v(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=ni(e.formattingContext),n=D("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=ni(e.formattingContext),n=new Rv(i,t);return new oa(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ni(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return lp(r,t).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(t.layoutNext(s,!1).then(l=>{s=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||s&&t.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(e,t,i,n){return gn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){gn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ov(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Wi&&!i.belongsTo(n)&&t(n,i)}}function dp(e,t){e&&Ov(e.after?e.parent:e,(i,n)=>{ki.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Sl(n))})}function Bv(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let o=r.viewNode.firstChild;return n.appendHeaderToFragment(r,o,i)}}return T(!0)}function Mv(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return T(!0)}function pp(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function _v(e){let t=e.formattingContext;return!t||!(t instanceof Wi)?null:t}function ni(e){return e instanceof Wi,e}var Dv=new Lv;At("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Wi&&!ki.isInstanceOfTableFormattingContext(e)?Dv:null);var fp=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[]),c(this,"breakBefore",null),c(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},zv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,c(this,"viewElement"),c(this,"colSpan"),c(this,"rowSpan"),c(this,"height",0),c(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},Vv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Uv=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new xl(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},$v=class{constructor(e,t){this.viewNode=e,this.side=t}},Hv=class extends Or{constructor(e,t,i,n){super(e,t,i,n),c(this,"formattingContext"),c(this,"acceptableCellBreakPositions",null),c(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Wv=class extends ul{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,c(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(o=>!!o.nodeContext)&&n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof Yn&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof Or&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Sn=class extends Wi{constructor(e,t){super(e,t),this.tableSourceNode=t,c(this,"formattingContextType","Table"),c(this,"vertical",!1),c(this,"columnCount",-1),c(this,"tableWidth",0),c(this,"captions",[]),c(this,"colGroups",null),c(this,"colWidths",null),c(this,"inlineBorderSpacing",0),c(this,"rows",[]),c(this,"slots",[]),c(this,"cellFragments",[]),c(this,"lastRowViewNode",null),c(this,"cellBreakPositions",[]),c(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){var i;if(!t)return t;switch(e.display){case"table-row":{let n=this.findRowIndexBySourceNode(e.sourceNode);return this.cellBreakPositions.every(r=>this.isPreviousFragmentRowSpanningCellBreakPosition(r,n))&&e.fragmentIndex<=1}case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new fp(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),o=0;for(;r[o];)o++;for(;e<n;e++){r=this.getRowSlots(e);for(let s=o;s<o+t.colSpan;s++){let a=r[s]=new Vv(e,s,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}isPreviousFragmentRowSpanningCellBreakPosition(e,t){let i=e.cell;return t>=0&&i.rowIndex<t&&i.rowIndex+i.rowSpan>t}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Tt(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let o=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!o||t.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),t.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new Gv(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(zi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}ki.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Gv=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=xn(e,n);i=Math.max(i,t(r))}),i}};function Ot(e){return e instanceof Sn,e}function jv(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Xv(e){return e==="table"||e==="inline-table"}function Hh(e){return jv(e)||Xv(e)}function gp(e,t,i){let n=e.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof Sn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof Sn){s=a.formattingContext===t;break}}return s||r==="table-row"&&!Hh(o)||r==="table-cell"&&o!=="table-row"&&!Hh(o)||n.formattingContext instanceof Sn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function mp(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Si(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var qv=class extends nr{constructor(e,t){super(),this.formattingContext=e,this.column=t,c(this,"rowIndex",-1),c(this,"columnIndex",0),c(this,"inRow",!1),c(this,"checkPoints",[]),c(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=gp(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=mp(this.column,e);if(n)return n;let r=e.nodeContext,o=r.display,s=t.getRepetitiveElements();switch(o){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new $v(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new fp(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(o[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let o=t.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=tt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;t.addCell(this.rowIndex,new zv(this.rowIndex,this.columnIndex,o)),this.columnIndex++,bp(o);let s=t.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=tt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=tt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!pn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},wp=class yp extends nr{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,c(this,"inRow",!1),c(this,"currentRowIndex",-1),c(this,"currentColumnIndex",0),c(this,"originalStopAtOverflow"),c(this,"inHeader"),c(this,"inFooter"),c(this,"didExtractRowSpanningCellBreakPositions",!1),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return mp(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,o=t.columnIndex,s=t.colSpan,a=i.viewNode;s>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new Uv(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(bp(a),T(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorSlot.columnIndex===t&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,o=r.rowIndex;if(o<this.currentRowIndex&&o+r.rowSpan>this.currentRowIndex){let s=i[o];s||(s=i[o]=[]),s.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=D("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,u=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=Lo(d[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let f=T(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");I(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return d.forEach(w=>{f=f.thenAsync(()=>{let x=w.cell;m(x.anchorSlot.columnIndex);let y=w.cellNodePosition,b=Lo(y.steps[0],p);return b.offsetInNode=y.offsetInNode,b.after=y.after,b.fragmentIndex=y.steps[0].fragmentIndex+1,o.setCurrent(b,!1).thenAsync(()=>{let S=w.breakChunkPosition;for(let C=0;C<x.colSpan;C++)u.push(g+C);return g+=x.colSpan,this.layoutCell(x,b,S).thenAsync(()=>(b.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,T(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,T(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=tt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=tt(o,s.breakBefore)),!t.leadingEdge&&qe(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),t.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),T(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);yv(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,T(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let o=D("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=T(h.breakChunkPosition)}else s=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=Ro(h,0);return T(new Ei(l))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=gp(t,Ot(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):T(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new Wv(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group")),r&&yp.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else if(r==="table-row"&&!this.inHeader&&!this.inFooter){let o=super.afterNonInlineElementNode(t);return(o&&o.isPending()?o:T(!0)).thenAsync(()=>{if(!t.break){let s=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!s&&h&&!!(a!=null&&a.isFooterRegistered());(s||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return T(!0)})}else return super.afterNonInlineElementNode(t);return T(!0)}};c(wp,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Yv=wp,yr=[];function Zv(e){let t=yr.findIndex(n=>n.root===e),i=yr[t];return i?i.tableLayoutOption:null}function Kv(e){let t=yr.findIndex(i=>i.root===e);t>=0&&yr.splice(t,1)}var vp=class{layoutEntireTable(e,t){let i=Ot(e.formattingContext),n=new qv(i,t);return new oa(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<t;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=s.map(h=>{let l=Tt(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(o),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),t.push(s)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let o=e.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),e.push(s)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=e.getColumnCount();if(!(s>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,t),l.forEach((u,d)=>{I(u,n?"height":"width",`${a[d]}px`)}),h.forEach(u=>{o.appendChild(u.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=Ot(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Zv(e.sourceNode);Kv(e.sourceNode);let r=D("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{var a;let h=s.viewNode,l=i.rows[0];if(l&&qe(l.breakBefore)&&this.hasInFlowContentBefore(h,t)){(a=h.parentNode)==null||a.removeChild(h),t.pageBreakType=l.breakBefore,r.finish(o);return}let u=Tt(t.clientLayout,h,t.vertical),d=t.vertical?u.left:u.bottom;if(d+=(t.vertical?-1:1)*xn(e,t.collectElementsOffset()).current,!t.isOverflown(d)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new tb(o)),r.finish(s);return}this.normalizeColGroups(i,h,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&qe(i.breakBefore)||t<e.rows.length-1&&qe(i.breakAfter)))return!0}return!1}hasInFlowContentBefore(e,t){let i=e;for(;i&&i!==t.element;){let n=i.previousSibling;for(;n;){if(n.nodeType===1&&!Nt(n)||n.nodeType===3&&!Le(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,o)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),I(t,"table-layout","fixed"),I(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=Ot(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new Yv(i,t),s=new oa(o,t.layoutContext),a=D("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ot(e.formattingContext);return n.getRootViewNode(e)?(i&&dp(e.parent,t),new Qv(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Hv(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ts(e),!1}finishBreak(e,t,i,n){let r=Ot(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=r.findRowIndexBySourceNode(t.sourceNode),s;if(t.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=D("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let u=s[h++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),m=new Ei(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),o<u.rowIndex+u.rowSpan-1&&(w.rowSpan=o-u.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Jv(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ts(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Ts(t),r.finishFragment(),dl.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){gn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Jv(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,o=e.column,s=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=Tt(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let u=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;I(s,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(s,"max-height",`${u}px`)}}function bp(e){let t=e.matches("td, th")?e:e.closest("td, th");if(!t||t.style.verticalAlign!=="baseline")return;let i=t.querySelector(".-vivliostyle-table-cell-container");if(!i)return;let n=i.children;if(n.length!==0){for(let r=0;r<n.length;r++){let o=n[r].style.position;if(o!=="absolute"&&o!=="fixed")return}I(i,"display","contents")}}function Ts(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return d+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(d,f):d},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;I(a,e.vertical?"width":"height",`${u}px`)}var Qv=class extends pl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new eb(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new nb(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},eb=class extends hp{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},tb=class extends Or{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new ib(this.position.sourceNode))}},ib=class xp{constructor(t){this.tableRootNode=t,c(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,yr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof xp&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},nb=class extends up{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new rb(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},rb=class Sp extends Sl{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||dn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!pp(t,i,r):!0}nextCandidate(t){let i=Ot(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let o=Ot(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(t,s.breakPosition,n,r)})}),!t){let s=o.getRootViewNode(this.nodeContext);new vp().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ot(this.nodeContext.formattingContext),r=D("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return T(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=Ot(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Sp?Ot(this.nodeContext.formattingContext)===Ot(t.nodeContext.formattingContext):!1}},ob=new vp;function sb(e,t,i,n,r,o){if(!t)return null;if(i===v.table){let s=e.parent;return new Sn(s?s.formattingContext:null,e.sourceNode)}return null}function ab(e){return e instanceof Sn?ob:null}At("RESOLVE_FORMATTING_CONTEXT",sb);At("RESOLVE_LAYOUT_PROCESSOR",ab);function Wh(e){return e.reduce((t,i)=>t+i,0)/e.length}function lb(e){let t=Wh(e);return Wh(e.map(i=>{let n=i-t;return n*n}))}var hb=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function vr(e){return e.vertical?e.width:e.height}function br(e,t){e.vertical?e.width=t:e.height=t}var Cp=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=vr(e)}balanceColumns(e){let t=D("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new hb(e,t)}preBalance(e){}postBalance(){br(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let o=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},va=1;function kp(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+va}function Ep(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+va))-va;n<vr(t)?br(t,n):br(t,vr(t)-1)}var ub=class extends Cp{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,c(this,"originalPosition",null),c(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);br(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return Gh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return kp(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Gh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):vr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Ep(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,vr(this.layoutContainer)+this.originalContainerBlockSize*.1);br(this.layoutContainer,t)}}};function Gh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>t>o.computedBlockSize+r)}var cb=class extends Cp{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return lb(t)}hasNextCandidate(e){return kp(e)}updateCondition(e){Ep(e,this.layoutContainer)}};function db(e,t,i,n,r,o,s){if(t===v.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new ub(i,n,r,e):t===v.balance_all?new cb(i,n,r):(v.balance,null)}}var pb=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],fb=new Set(pb);function gb(e){return!(e.toLowerCase()==="none"||fb.has(e))}var mb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],wb=new Set(mb),yb=["fixed","extends"],vb=new Set(yb),qx=Symbol();function Br(e){return e instanceof de&&e.name.toLowerCase()!=="none"}function Pp(e){return e.name}function bb(e){if(e instanceof de)return wb.has(e.name);if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof de){let n=t.name;return vb.has(n)&&(n==="fixed"&&i instanceof Ue||n==="extends"&&Br(i))}}return!1}function xb(e){let t=ht(e,"system");return t instanceof de&&t.name==="cyclic"}function Sb(e){let t=ht(e,"system");if(t instanceof de&&t.name==="fixed")return!0;if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="fixed"&&n instanceof Ue}return!1}function Cb(e){let t=ht(e,"system");return t instanceof de?1:t.values[1].num}function kb(e){let t=ht(e,"system");return t instanceof de&&t.name==="alphabetic"}function Eb(e){let t=ht(e,"system");return t instanceof de&&t.name==="numeric"}function Pb(e){let t=ht(e,"system");return t instanceof de&&t.name==="additive"}function Nb(e){let t=ht(e,"system");if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="extends"&&Br(n)}return!1}function Tb(e){let t=ht(e,"system");return Pp(t.values[1])}function zt(e){return e instanceof X||e instanceof de}function oi(e){return e instanceof X?e.str:e.name}function Np(e){if(zt(e))return!0;if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];return zt(t)&&zt(i)}return!1}function Ib(e){if(zt(e))return{prefix:oi(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:oi(t),suffix:oi(i)}}}function jh(e){return e instanceof Ue||e instanceof de&&e.name==="infinite"}function $o(e,t){return e instanceof Ue?e.num:t?-1/0:1/0}var Yx=Symbol();function ba(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(jh(t)&&jh(i)))return!1;let n=$o(t,!0),r=$o(i,!1);return!(n>r)}function Ab(e){return{lower:$o(e.values[0],!0),upper:$o(e.values[1],!1)}}function Tp(e){return e instanceof de&&e.name==="auto"||ba(e)||e instanceof it&&e.values.length>=1&&e.values.every(t=>ba(t))}function Fb(e){return e instanceof de?null:(ba(e)?[e]:e.values).map(t=>Ab(t))}var Zx=Symbol();function Ho(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Ue&&t.num>=0&&zt(i)||zt(t)&&i instanceof Ue&&i.num>=0}function Wo(e){let[t,i]=e.values;return t instanceof Ue?[t.num,oi(i)]:[i.num,oi(t)]}function Ip(e){return Ho(e)}function Rb(e){let[t,i]=Wo(e);return{minLength:t,symbol:i}}function Ap(e){return zt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>zt(t))}function Lb(e){return zt(e)?[oi(e)]:e.values.map(t=>oi(t))}var Kx=Symbol();function Fp(e){if(Ho(e))return!0;if(e instanceof it&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!Ho(i))return!1;let[n]=Wo(i);if(n>=t)return!1;t=n}return!0}return!1}function Ob(e){if(Ho(e)){let[t,i]=Wo(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Wo(t);return{weight:i,symbol:n}})}var Bb=["auto","bullets","numbers","words","spell-out"],Mb=new Set(Bb);function _b(e){return e instanceof de&&Mb.has(e.name)||Br(e)}function Db(e,t){switch(e){case"system":return bb(t);case"negative":return Np(t);case"prefix":case"suffix":return zt(t);case"range":return Tp(t);case"pad":return Ip(t);case"fallback":return Br(t);case"symbols":return Ap(t);case"additive-symbols":return Fp(t);case"speak-as":return _b(t);default:return!0}}function ht(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function zb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function An(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var ao,lo,ho,uo,co,po,fo,go,xa,Sa,Ca,ka,Ea,Pa,Na,pt,Is,Rp,Lp,Xh,qh,As,Yh,Zn,fi=class Li{constructor(t,i){ie(this,pt),c(this,"_store"),ie(this,ao),ie(this,lo),ie(this,ho),ie(this,uo),ie(this,co),ie(this,po),ie(this,fo),ie(this,go),this._store=t;let n=ht(i,"negative");Ve(this,ao,n&&Np(n)?Ib(n):null);let r=ht(i,"prefix");Ve(this,lo,r&&zt(r)?oi(r):null);let o=ht(i,"suffix");Ve(this,ho,o&&zt(o)?oi(o):null);let s=ht(i,"range");Ve(this,uo,s&&Tp(s)?Fb(s):null);let a=ht(i,"pad");Ve(this,co,a&&Ip(a)?Rb(a):null);let h=ht(i,"fallback");Ve(this,po,h&&Br(h)?Pp(h):null);let l=ht(i,"symbols");Ve(this,fo,l&&Ap(l)?Lb(l):null);let u=ht(i,"additive-symbols");Ve(this,go,u&&Fp(u)?Ob(u):null)}static create(t,i){return xb(i)?new Ti(t,i):Sb(i)?new Vb(t,i):kb(i)?new $b(t,i):Eb(i)?new Zh(t,i):Pb(i)?new Hb(t,i):Nb(i)?new Wb(t,i):new Ub(t,i)}static createDecimal(t){return new Zh(t,$(Li,xa))}static createDisc(t){return new Ti(t,$(Li,Sa))}static createSquare(t){return new Ti(t,$(Li,Ca))}static createCircle(t){return new Ti(t,$(Li,ka))}static createDisclosureOpen(t){return new Ti(t,$(Li,Ea))}static createDisclosureClosed(t){return new Ti(t,$(this,Pa))}static createNone(t){return new Ti(t,$(Li,Na))}static get CHINESE_LONGHAND_NAMES(){return Kh.NAMES}static createChineseLonghand(t,i){return new Kh(t,i)}static createEthiopicNumeric(t){return new jb(t)}_getNegative(){return $(this,ao)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return $(this,lo)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return $(this,ho)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return $(this,uo)}static _getRangeFrom(t){return t._getRange()}_getPad(){return $(this,co)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get($(this,po)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return $(this,fo)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return $(this,go)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Ne(this,pt,Zn).call(this,t,new Set)}formatMarker(t){return Ne(this,pt,Rp).call(this)+this.format(t)+Ne(this,pt,Lp).call(this)}};ao=new WeakMap,lo=new WeakMap,ho=new WeakMap,uo=new WeakMap,co=new WeakMap,po=new WeakMap,fo=new WeakMap,go=new WeakMap,xa=new WeakMap,Sa=new WeakMap,Ca=new WeakMap,ka=new WeakMap,Ea=new WeakMap,Pa=new WeakMap,Na=new WeakMap,pt=new WeakSet,Is=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Rp=function(){var e;return(e=this._getPrefix())!=null?e:""},Lp=function(){var e;return(e=this._getSuffix())!=null?e:". "},Xh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},qh=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},As=function(){var e;return(e=this._getFallback())!=null?e:An(this._store)},Yh=function(e,t){let{minLength:i,symbol:n}=Ne(this,pt,qh).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=Ne(this,pt,Is).call(this),s=t?[...r].length+(o?[...o].length:0):0,a=i-[...e].length-s;if(a<=0)return e;let h=[...n].length,l=Math.ceil(a/h);return n.repeat(l)+e},Zn=function(e,t){var i,n,r;if(t.has(this))return Ne(i=An(this._store),pt,Zn).call(i,e,new Set);if(t.add(this),!zb(e,Ne(this,pt,Xh).call(this))){let l=Ne(this,pt,As).call(this);return Ne(n=l,pt,Zn).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=Ne(this,pt,As).call(this);return Ne(r=l,pt,Zn).call(r,e,t)}let h=Ne(this,pt,Yh).call(this,a,o);if(o){let{prefix:l,suffix:u}=Ne(this,pt,Is).call(this);h=l+h+(u??"")}return h},ie(fi,xa,{system:new V(M("numeric"),0),symbols:new V(new J([new X("0"),new X("1"),new X("2"),new X("3"),new X("4"),new X("5"),new X("6"),new X("7"),new X("8"),new X("9")]),0)}),ie(fi,Sa,{system:new V(M("cyclic"),0),symbols:new V(new X("\u2022"),0),suffix:new V(new X(" "),0)}),ie(fi,Ca,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25AA"),0),suffix:new V(new X(" "),0)}),ie(fi,ka,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25E6"),0),suffix:new V(new X(" "),0)}),ie(fi,Ea,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25BE"),0),suffix:new V(new X(" "),0)}),ie(fi,Pa,{system:new V(M("cyclic"),0),symbols:new V(new X("\u25B8"),0),suffix:new V(new X(" "),0)}),ie(fi,Na,{system:new V(M("cyclic"),0),symbols:new V(new X(""),0),suffix:new V(new X(""),0)});var ce=fi,Ti=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},mo,Vb=class extends ce{constructor(e,t){super(e,t),ie(this,mo),Ve(this,mo,Cb(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-$(this,mo);return(t=i[n])!=null?t:null}};mo=new WeakMap;var Ub=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},$b=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},Zh=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},Hb=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(o=>o.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},ar,yt,Pt,Op=class extends ce{constructor(t,i){super(t,i),ie(this,yt),ie(this,ar);let n=Tb(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Ve(this,ar,r):Ve(this,ar,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(Ne(this,yt,Pt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(Ne(this,yt,Pt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(Ne(this,yt,Pt).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(Ne(this,yt,Pt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(Ne(this,yt,Pt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(Ne(this,yt,Pt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(Ne(this,yt,Pt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(Ne(this,yt,Pt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(Ne(this,yt,Pt).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(Ne(this,yt,Pt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(Ne(this,yt,Pt).call(this),t)}};ar=new WeakMap,yt=new WeakSet,Pt=function(e=new Set){var t;if(e.has(this))return An(this._store);e.add(this);let i=this._store.get($(this,ar));return i?i instanceof Op?Ne(t=i,yt,Pt).call(t,e):i:An(this._store)};var Wb=Op,Gb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Fs,Rs,Zr,Ls,Ta,wo,Rt=class Bp extends ce{constructor(t,i){let{chars:n,descriptors:r}=$(Bp,Ta).get(i);super(t,r),ie(this,wo),Ve(this,wo,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=$(this,wo);if(t===0)return i.digits[0];let n=[],r=0,o=t;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:d}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};Fs=new WeakMap,Rs=new WeakMap,Zr=new WeakMap,Ls=new WeakMap,Ta=new WeakMap,wo=new WeakMap,ie(Rt,Fs,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ie(Rt,Rs,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ie(Rt,Zr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),ie(Rt,Ls,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(M("cjk-decimal"),0),range:new V(new J([new Ue(-9999),new Ue(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),c(Rt,"NAMES",new Set(Gb)),ie(Rt,Ta,new Map([["simp-chinese-informal",$(Rt,Fs)],["simp-chinese-formal",$(Rt,Rs)],["trad-chinese-informal",$(Rt,Zr)],["trad-chinese-formal",$(Rt,Ls)],["cjk-ideographic",$(Rt,Zr)]]));var Kh=Rt,Ia,Aa,Go,Fa,Ra,hn=class Oi extends ce{constructor(t){super(t,$(Oi,Ia))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return $(Oi,Go)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),d=a%10;o+=$(Oi,Aa)[u]+$(Oi,Go)[d]}h?a!==0&&(o+=$(Oi,Fa)):s!==0&&(o+=$(Oi,Ra))}return o}};Ia=new WeakMap,Aa=new WeakMap,Go=new WeakMap,Fa=new WeakMap,Ra=new WeakMap,ie(hn,Ia,{range:new V(new J([new Ue(1),M("infinite")]),0),suffix:new V(new X("/ "),0)}),ie(hn,Aa,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ie(hn,Go,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ie(hn,Fa,"\u137B"),ie(hn,Ra,"\u137C");var jb=hn,Ae,Xb=class{constructor(){ie(this,Ae),Ve(this,Ae,new Map),$(this,Ae).set("none",ce.createNone($(this,Ae))),$(this,Ae).set("decimal",ce.createDecimal($(this,Ae))),$(this,Ae).set("disc",ce.createDisc($(this,Ae))),$(this,Ae).set("square",ce.createSquare($(this,Ae))),$(this,Ae).set("circle",ce.createCircle($(this,Ae))),$(this,Ae).set("disclosure-open",ce.createDisclosureOpen($(this,Ae))),$(this,Ae).set("disclosure-closed",ce.createDisclosureClosed($(this,Ae)));for(let e of ce.CHINESE_LONGHAND_NAMES)$(this,Ae).set(e,ce.createChineseLonghand($(this,Ae),e));$(this,Ae).set("ethiopic-numeric",ce.createEthiopicNumeric($(this,Ae)))}define(e,t){if(!gb(e))return null;let i=ce.create($(this,Ae),t);return $(this,Ae).set(e,i),i}getStyle(e){var t;return(t=$(this,Ae).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:An($(this,Ae))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:An($(this,Ae))).formatMarker(t)}};Ae=new WeakMap;var Os=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},qb=class{constructor(){c(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new Os(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new Os(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Os(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ai(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ai(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Yb(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Zb=class La{constructor(t,i,n,r,o,s,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=o,this.atBlockStart=s,this.atFlowStart=a,this.isParentBoxDisplayed=h,c(this,"flowName"),c(this,"isBlockValue",null),c(this,"hasBoxValue",null),c(this,"styleValues",{}),c(this,"beforeBox",null),c(this,"afterBox",null),c(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new La(t,l.before,n,!1,o,this.isBlock(),a,!0),d=u.styleValue("content");kt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=tt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&qe(this.breakBefore)&&(o.breakBefore=tt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new La(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");kt(s)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=ed(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!To(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Kb=class{constructor(e){this.context=e,c(this,"stack",[]),c(this,"atBlockStart",!0),c(this,"atFlowStart",!0),c(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new Zb(this.context,e,t,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=gd(i);n&&!Le(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=tt(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},Jh=class{constructor(e,t,i,n,r,o,s,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=o,this.counterListener=s,c(this,"root"),c(this,"cascadeHolder"),c(this,"last"),c(this,"rootStyle",{}),c(this,"styleMap",{}),c(this,"counterSnapshots",[]),c(this,"flows",{}),c(this,"flowChunks",[]),c(this,"flowListener",null),c(this,"flowToReach",null),c(this,"idToReach",null),c(this,"cascade"),c(this,"offsetMap"),c(this,"primary",!0),c(this,"primaryStack",[]),c(this,"rootBackgroundAssigned",!1),c(this,"rootLayoutAssigned",!1),c(this,"lastOffset"),c(this,"breakBeforeValues",{}),c(this,"boxStack"),c(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,s,a,e.lang,h,l),this.offsetMap=new qb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Kb(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(d,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new V(r,jc))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)mn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!Z(n)||r&&!Z(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Qh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Qh[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Z(n.value)){let a=n.evaluate(this.context);if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*Wt.lh/Wt.em;break;default:{let l=Wt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,s=e["line-height"];if(s&&!Z(s.value)){let a=s.evaluate(this.context);if(a instanceof Ct)this.context.rootLineHeight=a.num*o;else if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=Wt[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return uv(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Yb(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=ai(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,u=l&&!Z(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let s=me(o,"flow-into"),a=s?s.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=Gg(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=dh(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=dh(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new zw(e,m)}let g=new Vw(e,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(qe(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=tt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;this.last;){let o=this.last.firstChild;if(o==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let s=this.boxStack.pop(this.lastOffset),a=null;if(s.afterBox){let h=s.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,s.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(s):s.afterBox.offset,s.flowName),a=s.afterBox.getBreakValue("after")}a=tt(a,s.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,s.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let s=this.last,a=this.getAttrStyle(s);this.primaryStack.push(this.primary),this.cascade.pushElement(this,s,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=s.getAttribute("id")||s.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&s.localName=="body"&&s.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,s,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,s===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,s===this.root),s===this.xmldoc.body&&(l.breakBefore=tt(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||s===this.xmldoc.body){let p=a.page,f=p&&!Z(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}return Number.POSITIVE_INFINITY}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Qh=["column-count","column-width","column-fill"],wn=class{constructor(e){this.validator=e,c(this,"success",null),c(this,"failure",null),c(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Ii=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Hn=class Mp{constructor(){c(this,"nodes",[]),c(this,"connections",[]),c(this,"match",[]),c(this,"nomatch",[]),c(this,"error",[]),c(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Mp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new wn(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Ii(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,o=new wn(eu);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,r);let s=new Ii(r,!0),a=new Ii(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(s)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new wn(eu);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ii(0,!0),r=new Ii(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new wn(t));let n=new Ii(i,!0),r=new Ii(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof We}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<t.connections.length;o++){let s=t.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+r);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+r);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Jb=1,_p=2,Dp=4,Bi=8,yo=16,Oa=32,vo=64,zp=128,Kn=256,Jn=512,Ba=1024,Vp=2048,Up=4096,$p=8192,Hp=class extends ui{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},We=class Wp extends Hp{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Jb?t:null}visitSlash(t){return this.allowed&Vp?t:null}visitStr(t){return this.allowed&_p?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Dp||this.allowed&vo&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Jn)?t.unit=="%"&&this.allowed&Ba?t:null:t.num<0&&!(this.allowed&Kn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Jn?t:null:t.num<=0&&!(this.allowed&Kn)?null:this.allowed&yo?t:null}visitInt(t){return t.num==0?this.allowed&Jn?t:null:t.num<=0&&!(this.allowed&Kn)?null:this.allowed&(Oa|yo)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&vo&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&zp?t:null}visitURange(t){return this.allowed&Up?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&vo){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&dc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&$p){let i=t.visit(new gc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Bi|yo|Oa|Kn|Jn|Ba)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Wp(this.allowed|t.allowed,i,n)}},le=Object.create(null),eu=new We(0,le,le),Cl=class extends Hp{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new wn(null),this.failureTerminal=new wn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=e.length){r=r.failure;continue}let h=e[o],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(o==0&&!t&&r.validator instanceof lr&&this instanceof lr){if(l=new J(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof kl&&this instanceof lr){if(l=new it(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<o;u++)n[u]=e[u]}e!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:o==e.length)?n:null}validateSingle(e){let t=this.validateList([e],!1,0);return t?t[0]:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},lr=class extends Cl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new J(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof kl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new it(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},kl=class extends Cl{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new it(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},Qb=class extends Cl{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ci(e.name,t):null}},Gp=class{tryParse(e,t,i){return t}success(e,t){}},jp=class extends Gp{constructor(e,t){super(),this.name=t,c(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,o=r>1?new J(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},e0=class extends jp{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},t0=class extends Gp{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Ln){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let o=1;o<this.nodes.length&&t<e.length&&(r=this.nodes[o].tryParse(e,t,i),r!=t);o++)t=r;return t}},El=class extends ui{constructor(){super(...arguments),c(this,"syntax",null),c(this,"propList",null),c(this,"error",!1),c(this,"values",{}),c(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new jp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Mn=class extends El{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},Xp=class extends El{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new e0(this.validatorSet,this.propList)}},i0=class extends El{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Ln){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let o=[e[n],e[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},n0=class extends Mn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let o=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,s=e[r];s||(s=[],e[r]=s),s.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof it?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new it(t[i]);return null}},r0=class extends Mn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"])){let s=this.values["font-weight"],a=s instanceof ci&&s.name==="calc"?e.indexOf(s):-1;if(a>=0&&e[a].visit(r["font-size"]))delete this.values["font-weight"],t=a;else return this.error=!0,t}if(this.values["font-size"]=e[t++],e[t]===Ln){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new J(e.slice(t,e.length));return o.visit(r["font-family"])?(this.values["font-family"]=o,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new it(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},o0=class extends Mn{validateList(e){if(e.length===1&&e[0]instanceof de)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[M("no-autospace"),M("space-all")];break}return super.validateList(e)}},s0=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],a0=class extends Mn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)s0.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},tu={SIMPLE:Mn,INSETS:Xp,INSETS_SLASH:i0,COMMA:n0,FONT:r0,TEXT_SPACING:o0,ALL:a0},l0=["initial-letter"],h0=class{constructor(){c(this,"validators",{}),c(this,"prefixes",{}),c(this,"defaultValues",{}),c(this,"namedValidators",{}),c(this,"systemFonts",{}),c(this,"shorthands",{}),c(this,"layoutProps",{}),c(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new R(t.num,t.text);else if(t.type==7)i=new sc(t.text);else if(t.type==1)i=M(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Hn;if(e=="||"){for(let r=0;r<t.length;r++){let o=new Hn;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new Hn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Hn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Hn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new kl(t);break;case"SPACE":i=new lr(t);break;default:i=new Qb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new We(vo,le,le)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new We($p,le,le)),this.namedValidators.POS_INT=this.primitive(new We(Oa,le,le)),this.namedValidators.POS_NUM=this.primitive(new We(yo,le,le)),this.namedValidators.POS_PERCENTAGE=this.primitive(new We(Bi,le,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new We(Kn,le,le)),this.namedValidators.ZERO=this.primitive(new We(Jn,le,le)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new We(Ba,le,le)),this.namedValidators.POS_LENGTH=this.primitive(new We(Bi,le,{em:Y,ex:Y,ch:Y,rem:Y,lh:Y,rlh:Y,vw:Y,vh:Y,vi:Y,vb:Y,vmin:Y,vmax:Y,pvw:Y,pvh:Y,pvi:Y,pvb:Y,pvmin:Y,pvmax:Y,cm:Y,mm:Y,in:Y,px:Y,pt:Y,pc:Y,q:Y})),this.namedValidators.POS_ANGLE=this.primitive(new We(Bi,le,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new We(Bi,le,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new We(Bi,le,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new We(Bi,le,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new We(zp,le,le)),this.namedValidators.URANGE=this.primitive(new We(Up,le,le)),this.namedValidators.IDENT=this.primitive(new We(Dp,le,le)),this.namedValidators.STRING=this.primitive(new We(_p,le,le)),this.namedValidators.SLASH=this.primitive(new We(Vp,le,le));let e={"font-family":M("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(s)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,s=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(s||h(" "),this.isBuiltIn(u.text)){let d=this.namedValidators[u.text];if(!d)throw new Error(`'${u.text}' unexpected`);i.push(d.clone())}else{let d={};d[u.text.toLowerCase()]=M(u.text),i.push(this.primitive(new We(0,d,le)))}s=!1;break;case 5:{let d={};d[`${u.num}`]=new Ue(u.num),i.push(this.primitive(new We(0,d,le))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],s=!0;break;case 15:{o=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(o),r=d.op,s=!1;break}case 11:{o=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,o)),r=d.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let d=u.num,p=d;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new lr(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(M(n.text));break;case 4:i.push(new Ct(n.num));break;case 5:i.push(new Ue(n.num));break;case 3:i.push(new R(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new J(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&tu[i.text]?(n=new tu[i.text],e.consume()):n=new Mn,n.setOwner(this);let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])o.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Xp){let l=this.shorthands[i.text];o.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let l=new t0(o,s),u=a.pop();o=u.syntax,s=u.slash,o.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n}}parse(e){let t=new Vt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(t=this.defaultValues[s])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(Qt(e)||r==="font-face"||c0(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Db(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let o="",s=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(o=a[1],e=a[2]);let h=this.prefixes[e];if(!h||!h[o]){CSS.supports(s,t.toString())?n.simpleProperty(s,t,i):o&&!Mu.includes(`-${o}-`)||n.unknownProperty(s,t);return}else if(l0.includes(e)&&!Object.keys(h).some(u=>eo(u?`-${u}-`:"",e))){n.unknownProperty(s,t);return}let l=this.validators[e];if(l){let u=Z(t)||t.isExpr()?t:t.visit(l);u?n.simpleProperty(e,u,i):!o&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(s,t)}else{let u=this.shorthands[e].clone();Z(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(s,t))}}};function qp(){let e=new h0;return e.initBuiltInValidators(),e.parse(Dc),e}var u0=class extends ui{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function c0(e){let t=new u0;return e.visit(t),t.varFound}var Qx=`OTTO${new Date().valueOf()}`;function Pl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function d0(e){let t=new si;for(let i of Pl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function p0(e,t){let i={};for(let n in e)i[n]=me(e,n).evaluate(t,n);return i}var Yp=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=d0(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new si;i.append(`@font-face {
1866
+ }`;function Es(e,t,i){let n=D("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(s.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(s.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?s.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=yd([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?j.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):j.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function yd(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Mw(e){let t=D("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function _w(e){return URL.createObjectURL(e)}var Sl=class{constructor(e,t){this.parser=e,this.type=t,d(this,"resources",{}),d(this,"fetchers",{})}load(e,t,i){e=Dt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=D("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let o=Ae("user-agent.xml",Ci),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(dd)}`),Es(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):s&&(a.url=e=o),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Dt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Vr(()=>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 Dw(e,t){let i=e.responseText;return T(i?dl(i):null)}function zw(){return new Sl(Dw,"text")}function Ct(e,t,i){let n=new Vr(()=>{let r=D("loadElement"),o=r.suspend(e),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);else(e.localName==="img"||e.localName==="embed"||e.localName==="object"||e.localName==="iframe")&&(e.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4));return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Uh=0,Vw=16777216,vd=33554432,bd=50331648,xd=67108864,Uw=83886080,$w=100663296,Ps=class{constructor(e){this.scope=e,d(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n,r){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Uh;case"User":return $w;default:return Uw}}getBaseSpecificity(){switch(this.flavor){case"UA":return Uh;case"User":return Vw;default:return vd}}},Ea=class extends Ps{constructor(){super(null),d(this,"stack",[]),d(this,"tokenizer",null),d(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;j.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n,r){this.slave.attributeSelector(e,t,i,n,r)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},$h=class extends Ps{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,d(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Qi=class extends $h{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new $h(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},$e=[],qo=[],Ce=[],_e=[],Mt=[],at=[],Ue=[],Ze=[],Se=[],Qe=[],ct=[],Ge=[],Ve=[],cn=55,dn=56,to=57;$e[1]=28,$e[36]=29,$e[7]=29,$e[9]=29,$e[14]=29,$e[18]=29,$e[50]=29,$e[20]=30,$e[13]=27,$e[0]=200,qo[1]=46,qo[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[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,_e[37]=11,_e[23]=12,_e[35]=56,_e[1]=1,_e[36]=3,_e[7]=5,_e[9]=7,_e[14]=9,_e[18]=55,Mt[1]=2,Mt[36]=4,Mt[7]=6,Mt[9]=8,Mt[18]=14,Mt[50]=42,Mt[14]=10,Mt[12]=13,Ue[1]=15,Ue[7]=16,Ue[4]=17,Ue[5]=18,Ue[3]=19,Ue[2]=20,Ue[8]=21,Ue[27]=57,Ue[16]=22,Ue[19]=23,Ue[6]=24,Ue[11]=25,Ue[17]=26,Ue[13]=48,Ue[31]=47,Ue[23]=54,Ue[0]=44,Ze[1]=31,Ze[4]=32,Ze[5]=32,Ze[3]=33,Ze[2]=34,Ze[10]=40,Ze[6]=38,Ze[31]=36,Ze[24]=36,Ze[32]=35,Se[1]=45,Se[16]=37,Se[37]=37,Se[38]=37,Se[47]=37,Se[48]=37,Se[39]=37,Se[49]=37,Se[41]=37,Se[26]=37,Se[25]=37,Se[23]=37,Se[24]=37,Se[19]=37,Se[21]=37,Se[36]=37,Se[18]=37,Se[22]=37,Se[11]=39,Se[12]=43,Se[17]=49,Qe[0]=200,Qe[12]=50,Qe[13]=51,Qe[14]=50,Qe[15]=51,Qe[10]=50,Qe[11]=51,Qe[17]=53,ct[0]=200,ct[12]=50,ct[13]=52,ct[14]=50,ct[15]=51,ct[10]=50,ct[11]=51,ct[17]=53,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[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[cn]=2,Ve[dn]=2;var Ur=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,d(this,"valStack",[]),d(this,"namespacePrefixToURI",{}),d(this,"defaultNamespaceURI",null),d(this,"propName",null),d(this,"propImportant",!1),d(this,"exprContext"),d(this,"result",null),d(this,"importReady",!1),d(this,"importURL",null),d(this,"importCondition",null),d(this,"errorBrackets",[]),d(this,"ruleStack",[]),d(this,"regionRule",!1),d(this,"pageRule",!1),d(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Be)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],e===")"&&o instanceof an){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new te(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){if(e!=")"&&t.type!==0)return this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=ct,null;let h=new oi(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof ae&&h.values[0].name;je(l)||(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=ct)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=ct,null;if(s>1)return new rt(this.extractVals(",",n+1));let a=i[0];return a instanceof ot?a:a?new an(a.toString()):Be}exprError(e,t){this.actions=this.propName?ct:Qe,j.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(e==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new em(n.getScope(),h,l);a.unshift(u)}return i.push(new G(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new ur(n.getScope(),pa(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new bh(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new Ei(n.getScope(),r);else if(s==-24)r=new mn(n.getScope(),r);else if(s==-to)r=new Jg(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Ve[e]>Ve[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new ml(n.getScope(),o,r);break;case cn:r=new Qg(n.getScope(),o,r);break;case dn:r=new tm(n.getScope(),o,r);break;case 25:r=new wl(n.getScope(),o,r);break;case 38:r=new im(n.getScope(),o,r);break;case 37:r=new rm(n.getScope(),o,r);break;case 48:r=new nm(n.getScope(),o,r);break;case 47:r=new ga(n.getScope(),o,r);break;case 39:case 49:r=new yl(n.getScope(),o,r);break;case 41:r=new om(n.getScope(),o,r);break;case 23:r=new xc(n.getScope(),o,r);break;case 24:r=new Sc(n.getScope(),o,r);break;case 36:r=new vl(n.getScope(),o,r);break;case 19:r=new Cc(n.getScope(),o,r);break;case 21:r=new kc(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new lm(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new bh(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),r=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,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=i.input.substring(n,h),u=t&&r==="selector"&&a>0?"":je(r)?l:l.trim();return new hm(this.handler.getScope(),r,u,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}skipPseudoFunctionContents(){let e=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(e===0)return!0;e--;break;case 10:case 6:e++;break}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,o=t.type===23||r;if(o&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=zt(i,t,new Ei(i,new Ke(i,"pref-horizontal")));break;case"horizontal":t=zt(i,t,new Ke(i,"pref-horizontal"));break;case"day":t=zt(i,t,new Ei(i,new Ke(i,"pref-night-mode")));break;case"night":t=zt(i,t,new Ke(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new G(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,u,c,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===Ue&&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 an(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=ct):(this.actions=at,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ue,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=ct,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ue,h.splice(0,h.length);continue;case 29:this.actions=at,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),c=this.namespacePrefixToURI[l.text],c!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(c,l.text),r?this.actions=_e:this.actions=Ce,a.consume();break;case 36:s.tagSelector(c,null),r?this.actions=_e:this.actions=Ce,a.consume();break;default:this.actions=Qe,s.error("E_CSS_NAMESPACE",l)}else this.actions=Qe,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=_e:this.actions=Ce,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=Ge,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=_e:this.actions=Ce,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=_e:this.actions=Ce,a.consume();break;default:this.actions=Qe,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=_e:this.actions=Ce,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=_e:this.actions=Ce,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=_e:this.actions=Ce,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=_e:this.actions=Ce;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=Ce:this.actions=Ge;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=at,s.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=_e:this.actions=Ce:this.actions=Ge;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)m.push(u.text),a.consume();else break e;break}else break;else break e;default:if(m=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,m),a.consume(),r?this.actions=_e:this.actions=Ce;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Qe;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=_e:this.actions=Ce,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,m),r?this.actions=_e:this.actions=Ce,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Qe;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:{if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=Ge,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(c=p&&this.namespacePrefixToURI[p],c===void 0){this.actions=Ge,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=Ge,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else c="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(c,p,0,null,null),r?this.actions=_e:this.actions=Ce,a.consume();continue;default:this.actions=Ge,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}let S=p,v=null;switch(l.type){case 1:case 2:{let b=l.text;if(a.consume(),l=a.token(),l.type==1){let x=l.text.toLowerCase();(x=="i"||x=="s")&&(v=x,a.consume(),l=a.token())}s.attributeSelector(c,S,f,b,v);break}default:this.actions=Ge,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=Ge,s.error("E_CSS_ATTR",l);continue}r?this.actions=_e:this.actions=Ce,a.consume();continue}case 11:s.childSelector(),this.actions=Mt,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=Mt,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=Mt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=$e,a.consume();continue;case 41:s.nextSelector(),this.actions=at,a.consume();continue;case 15:h.push(M(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Lc(l.text)),a.consume();continue;case 17:h.push(new Nt(l.num)),a.consume();continue;case 18:h.push(new lt(l.num)),a.consume();continue;case 19:h.push(new R(l.num,l.text)),a.consume();continue;case 20:h.push(new X(l.text)),a.consume();continue;case 21:h.push(new tt(Ae(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Oc(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Un),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ze,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new an("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?qo:$e;continue;case 44:for(a.consume();h.length>0;){let S=h.length;if(g=this.valStackReduce(";",l),!g||h.length===S)break}return t?(this.result=g,!0):(this.propName&&g&&s.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new Ke(s.getScope(),pa(l.text,u.text))),this.actions=Se),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new vh(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new vh(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==cn&&h[h.length-1]!==dn&&(u.type===10||u.type===6)){h.push(-to),a.consume();continue}else h.push(new Ke(s.getScope(),l.text));this.actions=Se}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=Se;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new et(s.getScope(),l.num)),a.consume(),this.actions=Se;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new Br(s.getScope(),l.num,p)),a.consume(),this.actions=Se;continue;case 34:h.push(new et(s.getScope(),l.text)),a.consume(),this.actions=Se;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Tc(s.getScope(),l.num)),a.consume(),this.actions=Se);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Ze,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==dn&&h[h.length-2]!==-to?(this.actions=Ze,this.exprStackReduce(cn,l),h.push(cn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==cn&&h[h.length-2]!==-to?(this.actions=Ze,this.exprStackReduce(dn,l),h.push(dn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Ue),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=$e)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=$e,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=$e,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let S=this.readSupportsTest(l);if(S){h.push(S),this.actions=Se;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=$e,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ze,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Qe;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}s.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Qe;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Qe;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=Mt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let S=l.text;a.consume(),a.consume(),s.startFootnoteRule(S),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ze,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ze,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ze,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let S=null,v=null,b=[];for(l.type==1&&(S=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(v=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)b.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(S,v,b);break;case"-epubx-partition":s.startPartitionRule(S,v,b);break;case"-epubx-partition-group":s.startPartitionGroupRule(S,v,b);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=Ge;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Qe;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Qe;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=$e;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=$e),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=at,w=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=$e),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){if(this.actions===Ge)switch(l.type){case 16:this.errorBrackets.length==0&&(s.nextSelector(),w=l.position+1,this.actions=at),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===at)s.error("E_CSS_SYNTAX",l);else{let S=a.input.substring(w,l.position);s.pushSelectorText(S),w=l.position+1}if(l.type===16){s.nextSelector(),this.actions=at,a.consume();continue}else return s.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}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=Ge;continue}if(this.actions!==Qe&&this.actions!==Ge&&this.actions!==ct){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===Ue){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new an(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ze&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=$e,a.consume();continue}else{if(l.type===17&&this.actions==Ze)return this.actions=$e,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=ct:this.actions=Ge;continue}a.consume();continue}}return!1}},Sd=class extends Ps{constructor(e){super(null),this.scope=e}error(e,t){j.warn(e,t.toString())}getScope(){return this.scope}};function Hw(e,t,i,n,r){let o=Cd(t),s=Hm(e.input);return s!==e.input?Hh(new vt(s,o),o,i,n,r):Hh(e,o,i,n,r)}function Hh(e,t,i,n,r){let o=D("parseStylesheet"),s=new Ur($e,e,t,i),a=null;return r&&(a=Ed(new vt(r,t),t,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ae(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let u=D("parseStylesheet.import");return kd(l,t,null,null).then(()=>{s.importCondition&&t.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,u.finish(!0)}),u.result()}let h=o.timeSlice();if(h.isPending)return h}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function Cl(e,t,i,n,r){let o=Cd(t);return Fn("parseStylesheetFromText",s=>{let a=new vt(e,o);Hw(a,o,i,n,r).thenFinish(s)},(s,a)=>{j.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Cd(e){if(e instanceof Ea)return e;if(e instanceof Qi){if(e.owner)return e.owner;let t=new Ea;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function kd(e,t,i,n){return Fn("parseStylesheetFromURL",r=>{Es(e).then(o=>{o.responseText?Cl(o.responseText,t,e,i,n).then(s=>{s||j.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{j.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Ti(e,t,i){let n=new Ur(Ue,t,new Sd(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Ww(e,t,i){new Ur(qo,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Ed(e,t,i){let n=new Ur(Ze,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Gw={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function jw(e){return!!Gw[e]}function Xw(e,t,i){if(t instanceof Le&&t.str==="viv-leader")return new G(t);if(i==="content"&&t instanceof Le)return new G(t);let n=t.evaluate(e);switch(typeof n){case"number":return jw(i)?n==Math.round(n)?new lt(n):new Nt(n):new R(n,"px");case"string":return n?i==="content"?new X(n):Ti(t.scope,new vt(n,null),""):Be;case"boolean":return n?y._true:y._false;case"undefined":return Be}throw new Error("E_UNEXPECTED")}var qw="data-vivliostyle-flow-root";function Yw(e){return e.getAttribute(qw)==="true"}function Wh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return M(i)}function Ns(e){return e===y.absolute||e===y.fixed}function Yo(e){return e instanceof oi&&e.name==="running"}function Pd(e,t,i,n){return e===y.none||(Ns(t)?(i=y.none,e=Wh(e)):(i&&i!==y.none&&!q(i)||n)&&(e=Wh(e))),{display:e,position:t,float:i}}function Nd(e,t,i,n){return Pd(e,t,i,n).display===y.block}function Ts(e){return e instanceof ae||e instanceof te||typeof e=="string"}function Gt(e){if(!Ts(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 nr(e){return Ts(e)?e.toString().includes("list-item"):!1}function Zw(e){if(!Ts(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Td(e){if(!Ts(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 Kw(e,t,i,n,r,o,s){return r=r||o||y.horizontal_tb,!!s||!!i&&i!==y.none&&!q(i)||Ns(t)||e===y.inline_block||e===y.table_cell||e===y.table_caption||e==y.flex||e==y.grid||e==y.flow_root||(e===y.block||e===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!q(n)||!!o&&r!==o}function Jw(e){return e===y.relative||e===y.absolute||e===y.fixed}var Jt=1e5;function kl(e){let t=e.element.style;t.columnGap=`${Jt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Is(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Zo(e){return e.element.style.columnCount==="1"}function Qw(e){e.element.setAttribute("data-vivliostyle-column","true")}function Cr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Jt)}function Id(e,t){let i=Cr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Jt),o=r*Jt,s=i*Jt;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=Jt),e.right-=o,e.left-=s):e.left<-Jt/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=Jt),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=Jt),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Pa(e,t){for(let i=0;i<e.length;i++)Id(e[i],t)}function Rt(e,t,i){let n=e.getElementClientRect(t);if(Id(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!$r(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Is(r),e.getElementClientRect(t)}return n}function ey(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function Na(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function ty(e){if(!e.hasAttribute("data-vivliostyle-column")&&Na(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Na(t))return!0;return!1}function $r(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(Na(t))return t;if(i.position==="absolute")break}return null}function iy(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!r&&!s)return;let a=$r(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:c,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(c)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),S=i.getBoundingClientRect();(f?S.top>w.bottom+m:g?S.right<w.left-m:S.left>w.right+m)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${Jt}px`)}function io(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?Cr(i,e.vertical):0}function Ad(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||io(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize);if(r<=0||e.parentElement&&$r(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(e.style.blockSize=`${r}px`,io(t)){if(e.style.blockSize=`${n}px`,!io(t)){let s=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;e.style.blockSize=`${l}px`,io(t)?h=l:a=l}o=a,e.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/t.clientLayout.layoutUnitPerPixel;o=r+s,e.style.blockSize=`${o}px`}if(isNaN(o)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function ny(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)Ad(i,e)}function pn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Gt(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.parentNode.insertBefore(s,o);let a=t.getElementClientRect(s);if(s.remove(),a){let h=[a];Pa(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=Rt(t,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return e.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);Pa(l,n);let u=l.filter(c=>c.right>c.left&&c.bottom>c.top);if(u.length>0)l=u;else{let c=o?t.getElementComputedStyle(o).whiteSpace:"";l=c==="pre"||c==="pre-wrap"||c==="pre-line"||c==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(c=>c.left)):s=Math.max.apply(null,l.map(c=>c.bottom)),s):NaN}}function Ta(e,t,i){let n=Zo(t);n&&Is(t);let r=t.clientLayout.getElementClientRect(e);n&&kl(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function yn(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Fd(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var Ln="data-adapt-spec";function El(e){return!!e.getAttribute(Ln)}function Ft(e){return e?.nodeType!==1?!1:El(e)?!0:Rd(e)}function Rd(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function Gh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function vn(e){let t=e?.viewNode;return t?.nodeType===1&&El(t)}function ry(e){return e!=="inline"&&(Gt(e)||Td(e))}function jh(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))&&Gt(i.display))return i;return null}function oy(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}function Ld(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},o=e[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Od(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=e.replace(s.regexp,s.to);if(a!==e)return a}return e}var Bd={"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"}]}},sy=Ld(Bd,!0);function Md(e,t,i){return Od(e,t,i||null,sy)}var ay=Ld(Bd,!1);function _d(e,t,i){return Od(e,t,i||null,ay)}var ly={"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 hy(e,t){let i=ly[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 Pl(e,t,i){var n;let r=t,o={width:r.style.width,height:r.style.height};function s(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let c={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),c[p]=parseFloat(f)}return c}function bn(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 Dd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function zd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function xt(e,t){let i=Dd(e);i.includes(t)||(i.push(t),zd(e,i))}function uy(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function cy(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Ks(e,t){let i=uy(e);i.includes(t)||(i.push(t),cy(e,i))}function dy(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===y.always?y.page:i,important:e.important};default:return e}}var Ia={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ye(e){return!!Ia[e]}var py={left:!0,right:!0,recto:!0,verso:!0};function On(e){return!!py[e]}function Xh(e){return Ye(e)&&e!=="column"&&e!=="region"}var fy={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ko(e){return!!fy[e]}function nt(e,t){if(e)if(t){if(On(t))return t;if(On(e))return e;{let i=Ye(e),n=Ye(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:Ko(t)?t:Ko(e)?e:t}}else return e;else return t}function qh(e){return Ye(e)?e:"auto"}Ot("SIMPLE_PROPERTY",dy);var cr=Tg(Ag());function gy(e,t){return(0,cr.default)(e,t,0)}function Yh(e){return e.reduce((t,i)=>i[0]===cr.default.DELETE?t:t+i[1],"")}function my(e,t){return Vd(e,t,1)}function wy(e,t){return Vd(e,t,-1)}function Vd(e,t,i){let n=0,r=0;return e.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case cr.default.INSERT:n++;break;case cr.default.DELETE:n--,r++;break;case cr.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Aa;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Aa||(Aa={}));var Pn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(Pn||(Pn={}));var Jo;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Jo||(Jo={}));var Wi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||Ii.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||Ii.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Wi||(Wi={}));var Ii;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(Ii||(Ii={}));var gi;(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={}))})(gi||(gi={}));var yy={transform:!0,"transform-origin":!0},vy={top:!0,bottom:!0,left:!0,right:!0},Nl=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},by={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 xy(e,t){let i=by[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Fa=class rr extends fl{constructor(t,i){super(),this.container=t,this.bleedBox=i,d(this,"pageAreaElement",null),d(this,"delayedItems",[]),d(this,"hrefHandler"),d(this,"elementsById",{}),d(this,"dimensions",{width:0,height:0}),d(this,"isFirstPage",!1),d(this,"isLastPage",!1),d(this,"isBlankPage",!1),d(this,"isAutoPageWidth",!0),d(this,"isAutoPageHeight",!0),d(this,"spineIndex",0),d(this,"position",null),d(this,"offset",-1),d(this,"side",null),d(this,"fetchers",[]),d(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),d(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(rr.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(rr.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(rr.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(rr.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||I(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<t.length;o++){let s=t[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=xy(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};d(Fa,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),d(Fa,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Ud=Fa,yt=gi.Whitespace;function $d(e){switch(e){case"normal":case"nowrap":return yt.IGNORE;case"pre-line":return yt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return yt.PRESERVE;default:return null}}function Oe(e,t){return e?e.nodeType==1?!1:Hd(e.textContent,t):!0}function Hd(e,t){switch(t){case yt.PRESERVE:return e.length==0;case yt.NEWLINE:return!!e.match(/^[ \t]*$/);case yt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var Sy=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,d(this,"forcedBreakOffsets",[]),d(this,"formattingContext",null)}},Cy=class{constructor(e,t,i,n,r,o,s,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=o,this.repeated=s,this.last=a,this.breakBefore=h,d(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function ky(e,t){return e.top-t.top}function Ey(e,t){return t.right-e.right}function Wd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===gi.ShadowType.ROOTLESS&&t.shadowType===gi.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Ra(e.shadowContext,t.shadowContext)&&Ra(e.nodeShadow,t.nodeShadow)&&Wd(e.shadowSibling,t.shadowSibling)}function Yi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!Wd(e.steps[i],t.steps[i]))return!1;return!0}function Py(e){return{steps:[{node:e,shadowType:st.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Qo(e,t){return{steps:[{node:e.sourceNode,shadowType:st.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function es(e,t){let i=new fn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?es(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var st=gi.ShadowType,Eo=class{constructor(e,t,i,n,r,o,s){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=o,this.styler=s,d(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Ra(this.parentShadow,e.parentShadow):!1}};function Ra(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Ny=class{constructor(e,t){this.outer=e,this.count=t}},fn=class Gd{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,d(this,"offsetInNode",0),d(this,"after",!1),d(this,"shadowType"),d(this,"shadowContext"),d(this,"nodeShadow",null),d(this,"shadowSibling",null),d(this,"shared",!1),d(this,"inline",!0),d(this,"overflow",!1),d(this,"breakPenalty"),d(this,"display",null),d(this,"floatReference"),d(this,"floatSide",null),d(this,"clearSide",null),d(this,"floatMinWrapBlock",null),d(this,"columnSpan",null),d(this,"captionSide","top"),d(this,"inlineBorderSpacing",0),d(this,"blockBorderSpacing",0),d(this,"flexContainer",!1),d(this,"whitespace"),d(this,"hyphenateCharacter"),d(this,"breakWord"),d(this,"establishesBFC",!1),d(this,"containingBlockForAbsolute",!1),d(this,"breakBefore",null),d(this,"breakAfter",null),d(this,"viewNode",null),d(this,"clearSpacer",null),d(this,"inheritedProps"),d(this,"vertical"),d(this,"direction"),d(this,"firstPseudo"),d(this,"lang",null),d(this,"preprocessedTextContent",null),d(this,"formattingContext"),d(this,"repeatOnBreak",null),d(this,"pluginProps",{}),d(this,"fragmentIndex",1),d(this,"afterIfContinues",null),d(this,"footnotePolicy",null),d(this,"pageType"),this.shadowType=st.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Pn.FloatReference.INLINE,this.whitespace=i?i.whitespace:yt.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=Pn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:yt.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 Gd(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,o=[];r.shadowType===gi.ShadowType.ROOTLESS&&(r.floatReference!==Pn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&o.push(r.toNodePositionStep()),r=r.parent;while(r);let s=this.preprocessedTextContent?wy(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:s,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Ai=class jd{constructor(t){this.primary=t,d(this,"floats",null)}clone(){let t=new jd(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(!Yi(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(!Yi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Ty=class Xd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Xd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Iy=class qd{constructor(){d(this,"positions",[]),d(this,"startBreakType",null),d(this,"breakAfter",null)}clone(){let t=new qd,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Ay=class Yd{constructor(){d(this,"page",0),d(this,"flows",{}),d(this,"flowPositions",{}),d(this,"isBlankPage",!1),d(this,"highestSeenOffset",0),d(this,"highestSeenNode"),d(this,"lookupPositionOffset")}clone(){let t=new Yd;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&On(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},Zd=class{constructor(e){this.element=e,d(this,"left",0),d(this,"top",0),d(this,"marginLeft",0),d(this,"marginRight",0),d(this,"marginTop",0),d(this,"marginBottom",0),d(this,"borderLeft",0),d(this,"borderRight",0),d(this,"borderTop",0),d(this,"borderBottom",0),d(this,"paddingLeft",0),d(this,"paddingRight",0),d(this,"paddingTop",0),d(this,"paddingBottom",0),d(this,"width",0),d(this,"height",0),d(this,"originX",0),d(this,"originY",0),d(this,"exclusions",null),d(this,"innerShape",null),d(this,"computedBlockSize",0),d(this,"snapWidth",0),d(this,"snapHeight",0),d(this,"snapOffsetX",0),d(this,"snapOffsetY",0),d(this,"vertical",!1),d(this,"rtl",!1),d(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):xl(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 Lt(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 Lt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Yc(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 Lt(e,t,e+i,t+n)}},kr=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 tt)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Le&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Tt(e){return e!=null&&e!==Be&&e!==y.normal&&e!==y.none&&!q(e)}var Ie=Pn.FloatReference,Fy=20;function Ry(e){switch(e){case"inline":return Ie.INLINE;case"column":return Ie.COLUMN;case"region":return Ie.REGION;case"page":return Ie.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Pi(e){switch(e){case Ie.INLINE:return!1;case Ie.COLUMN:case Ie.REGION:case Ie.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Js(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=_d(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Md(e,r,i),s=hy(o,r);s==="line-left"?e="left":s==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(j.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Kd=class{constructor(e,t,i,n,r,o){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=o,d(this,"order",null),d(this,"id",null),d(this,"insidePageFloatArea",!1),d(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Ly=class{constructor(){d(this,"floats",[]),d(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Yi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(n=>Yi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},Jd=class{constructor(e,t,i,n,r,o){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=o}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Zh=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Yi(this.nodePosition,e.nodePosition):!1}},gn=class{constructor(e,t,i,n,r,o,s){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,d(this,"children",[]),d(this,"writingMode"),d(this,"direction"),d(this,"invalidated",!1),d(this,"floatStore"),d(this,"forbiddenFloats",[]),d(this,"floatFragments",[]),d(this,"stashedFloatFragments",[]),d(this,"floatAnchors",{}),d(this,"floatsDeferredToNext",[]),d(this,"floatsDeferredFromPrevious"),d(this,"layoutConstraints",[]),d(this,"locked",!1),d(this,"footnoteMaxBlockSize",null),d(this,"ignoreFootnoteAreaMaxHeight",!1),d(this,"footnoteAnchorsSeen",new Set),d(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!q(o)&&o||e&&e.writingMode||y.horizontal_tb,this.direction=!q(s)&&s||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new Ly;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let o=r-1;o>=0;o--){let s=this.children[o];if(s.floatReference===t&&s.flowName===i&&Yi(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,t,i,n),s))return s}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Bn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&t.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var t;if(!("footnotePolicy"in e))return;let i=this;for(;i;)i.footnoteAnchorsSeen.add(e.getId()),i=(t=i.parent)!=null?t:i.outerContext}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t,this.markPageFloatAnchorSeen(e)}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}removeFloatDeferredToNext(e){let t=this.floatsDeferredToNext.findIndex(i=>i.float===e);t>=0&&this.floatsDeferredToNext.splice(t,1)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let o=r.float,s=o.getOrder();s>t&&(!i||s>i.getOrder())&&(i=o)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}hasRootMultiColumnFootnoteContext(){return this.children.some(e=>{let t=0;for(let i of e.children)if(!i.generatingNodePosition&&(t+=1,t>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(e=>e.children.some(t=>{var i;let n=(i=t.getContainer())==null?void 0:i.element;return n!=null&&ty(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Fy?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Ie.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if(this.floatReference===Ie.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===y.line&&this.footnoteAnchorsSeen.has(t.getId())&&!i){if(this.locked){this.invalidate();return}this.removeFloatDeferredToNext(t),this.forbid(t),this.invalidate();return}}for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return _d(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Md(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let s of t){let a=this.toLogical(s);i.includes(a)||i.push(a)}let n=[],r=!1,o=!1;for(let s=0;s<i.length;s++){let a=i[s];a.includes("block")?r||(i.slice(s+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(s+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),o=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,o=!0){this.container;let s=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(s,h,i,n,r);if(o&&this.parent&&this.parent.container){let c=this.parent.getLimitValue(a,l,i,n,r,o);switch(a){case"top":return Math.max(u,c);case"left":return Math.max(u,c);case"bottom":return Math.min(u,c);case"right":return Math.min(u,c);default:}}return u}getLimitValueInner(e,t,i,n,r){this.container;let o=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?o.right:o.top;case"block-end":return this.container.vertical?o.left:o.bottom;case"inline-start":return this.container.vertical?this.container.rtl?o.bottom:o.top:this.container.rtl?o.right:o.left;case"inline-end":return this.container.vertical?this.container.rtl?o.top:o.bottom:this.container.rtl?o.left:o.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var o,s,a,h;this.container;let l=this.container.originX,u=this.container.originY,c=this.container.getPaddingRect(),p={top:c.y1-u,left:c.x1-l,bottom:c.y2-u,right:c.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((s=(o=this.container.element)==null?void 0:o.style)==null?void 0:s.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,S){return m.unit==="%"?S*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[S,v]=this.toLogicalFloatSides(w.floatSide);if(v&&(n&&v.includes("block")===n.includes("block")&&v!==n||r&&v.includes("block")===r.includes("block")&&v!==r))return m;let b=w.area,x=w.continuations[0].float.floatMinWrapBlock,C=b.vertical?b.left+b.getInsetLeft()+b.width+b.getInsetRight():b.top+b.getInsetTop()+b.height+b.getInsetBottom(),N=b.vertical?b.top+b.getInsetTop()+b.height+b.getInsetBottom():b.left+b.getInsetLeft()+b.width+b.getInsetRight(),F=m.top,L=m.left,V=m.bottom,Y=m.right,ue=m.floatMinWrapBlockStart,he=m.floatMinWrapBlockEnd;switch(S){case"inline-start":b.vertical?F=Math.max(F,N):L=Math.max(L,N);break;case"block-start":b.vertical?(x&&b.left<Y&&(ue=f(x,b.rootViewNodes[0],c.x2-c.x1)),Y=Math.min(Y,b.left)):(x&&C>F&&(ue=f(x,b.rootViewNodes[0],c.y2-c.y1)),F=Math.max(F,C));break;case"inline-end":b.vertical?V=Math.min(V,b.top):Y=Math.min(Y,b.left);break;case"block-end":b.vertical?(x&&C>L&&(he=f(x,b.rootViewNodes[0],c.x2-c.x1)),L=Math.max(L,C)):(x&&b.top<V&&(he=f(x,b.rootViewNodes[0],c.y2-c.y1)),V=Math.min(V,b.top));break;default:throw new Error(`Unknown logical float side: ${S}`)}return{top:F,left:L,bottom:V,right:Y,floatMinWrapBlockStart:ue,floatMinWrapBlockEnd:he}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,o,s){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;e.clientLayout;let h=a.find(C=>C.includes("inline")&&s[C==="inline-start"?"inline-end":"inline-start"]),l=a.find(C=>C.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),c=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;e.isFootnote||(u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),c=e.vertical?Math.max(c,e.left+g):Math.min(c,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function w(C,N){let F=C(e.bands,N);return F?(e.vertical&&(F=jc(F)),u=e.vertical?Math.min(u,F.x2):Math.max(u,F.y1),c=e.vertical?Math.max(c,F.x1):Math.min(c,F.y2),!0):o}let S,v,b,x;if(r){let C=e.vertical?Xo(new Lt(c,p,u,f)):new Lt(p,u,f,c);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Cm,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(km,C)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),b=(c-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(b=Math.min(b,this.footnoteMaxBlockSize),e.vertical?u=c+b:u=c-b),S=Math.max(0,b-e.getInsetBefore()-e.getInsetAfter()),x=(f-p)*e.getInlineDir(),v=x-e.getInsetStart()-e.getInsetEnd(),!o&&(S<=0||v<=0)))return null}else{let C=e.getContentBlockMarginAfter();S=Math.max(0,e.computedBlockSize+Math.min(0,C)),b=S+e.getInsetBefore()+e.getInsetAfter();let N=(c-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let L=this.container.getPaddingRect(),V=this.container.getBoxDir()*(n-(this.container.vertical?L.x2:L.y1)),Y=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-n-b);V<=Y?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&N<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?v=Pl(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?v=e.getContentInlineSize():v=e.vertical?e.height:e.width,x=v+e.getInsetStart()+e.getInsetEnd();let F=(f-p)*e.getInlineDir();if(!o&&F<x)return null}return u-=g,c-=g,p-=m,f-=m,a.some(C=>C==="inline-start"||C==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,v):(a.some(C=>C==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-x*e.getInlineDir(),v),a.some(C=>C==="block-start"||C==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,S):(a.some(C=>C==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(c-b*e.getBoxDir(),S),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-start")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x1:s.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let o=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.min(r,o):Math.max(r,o):o)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-end")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x2:s.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let o=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.max(r,o):Math.min(r,o):o)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.continuations.some(i(u))}let r=t.getPaddingRect(),o=t.vertical?r.x1:r.y2,s=this;for(;s;){if(s.floatsDeferredToNext.some(i(s)))return o;s=s.parent}function a(l){return l.floatFragments.some(u=>n(u,l))||l.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(s=this;s;s=s.parent)if(s.floatReference===e){if(a(s))return o;break}}t.clientLayout;let h=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<o*t.getBoxDir()?o:h}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=e.getOrder();function h(c){return p=>(!c||p.floatSide.includes(c))&&p.getOrder()<a}function l(c,p){return c.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(c,p){let f=c.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let c=this;c;c=c.parent)if(c.floatReference===i){(c.floatFragments.some(h(null))||l(c,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(c=>{switch(c){case"block-start":n[c]=!l(this,c);break;case"block-end":n[c]=!u(this,c);break;case"inline-start":case"inline-end":n[c]=!this.floatFragments.some(h(c));break;default:throw new Error(`Unexpected side: ${c}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let s=n.getLimitValuesInner(t,i);r?e.vertical?(s.right<r.right&&(r.right=s.right,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>r.left&&(r.left=s.left,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>r.top&&(r.top=s.top,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<r.bottom&&(r.bottom=s.bottom,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):r=s,n=n.parent}let o=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=o}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},qn=[],Bn=class{static register(e){qn.push(e)}findByNodeContext(e){for(let t=qn.length-1;t>=0;t--){let i=qn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=qn.length-1;t>=0;t--){let i=qn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Oy=class{appliesToNodeContext(e){return Pi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,o=e.toNodePosition(),s=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new Kd(o,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),T(h)})}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Jd(o.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return T(void 0)}forbid(e,t){}};Bn.register(new Oy);var Qd="data-vivliostyle-footnote-first-ref",ep="data-vivliostyle-footnote-referenced";function ts(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function kt(e){if(e.localName!=="aside")return!1;if(ts(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return ts(t,"footnote")}function Vt(e){if(e.localName!=="a")return!1;if(ts(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return ts(t,"noteref")}function Tl(e,t){if(!Vt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=Ho(i,t);return n==="#"?null:n}function tp(e,t,i){let n=Tl(e,t);if(!n)return null;let r=i(n);return r&&kt(r)?r:null}function By(e,t,i,n,r){if(r.value)return;let o=e.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=Tl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function Kh(e,t,i,n,r){if(e.localName!=="a"||!Vt(e))return!0;let o=Tl(e,t);if(!o)return!0;By(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function Il(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===y.inline?t.createCascadeValue(y.inline,n.priority):null}function My(e,t,i,n,r,o,s){if(e.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||e.localName!=="include"||!e.classList.contains("-vivliostyle-footnote-content"))return t;let a=i?.owner;if(!(a instanceof Element)||!Vt(a))return t;let h=tp(a,n,r);if(!h)return t;let l=a.getAttribute(o);l?(e.setAttribute(o,l),h.setAttribute(o,l)):(e.removeAttribute(o),h.removeAttribute(o));let u=s.getStyle(h);if(!u)return t;let c={...t},p=Il(u,s),f=s.getProp(u,"footnote-policy"),g=s.getStyleMap(u,"_pseudos"),m=g?.after;if(p&&(c["footnote-display"]=p),f&&(c["footnote-policy"]=f),m){let w=s.getMutableStyleMap(c,"_pseudos");w.after={...m}}return c}function _y(e,t,i,n,r){var o;if(!(i?.type===st.ROOTED&&kt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=Il(s,r),l=r.getProp(s,"footnote-policy"),u=r.getStyleMap(s,"_pseudos"),c=u?.["footnote-marker"],p=r.getProp(c,"content"),f=r.getProp(c,"list-style-position");if(h&&(a["footnote-display"]=h),l&&(a["footnote-policy"]=l),p&&((o=f?.evaluate)==null?void 0:o.call(f,n,"list-style-position"))===y.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(M("list-item"),0),a["list-style-position"]=r.createCascadeValue(y.outside,0),a["list-style-type"]=r.createCascadeValue(y.none,0),a["list-style-image"]=r.createCascadeValue(y.none,0)}return a}function Dy(e,t,i){var n,r;let o=t?.type===st.ROOTED&&kt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=Il(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function ip(e,t){if(e instanceof G){let i=e.expr.evaluate(t);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):e}return e instanceof te?new te(e.values.map(i=>ip(i,t))):e}function zy(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=ip(n.value,i))}function Vy(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Vt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=e.getElementById(o);if(s&&kt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(Qd,"true")),s.setAttribute(ep,"true")}}}Ot("PREPROCESS_SINGLE_DOCUMENT",Vy);var Uy=Jd,is=class np extends Kd{constructor(t,i,n,r,o,s){super(t,i,"block-end",null,n,o),this.footnotePolicy=r,this.policyAnchorNode=s}isAllowedToPrecede(t){return!(t instanceof np)}};function $y(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;t;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(t.localName)&&!t.querySelector("br"))return t;t=t.parentElement}return e}var Jh=class extends Uy{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof is?!0:this.getOrder()<e.getOrder()}},Hy=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;for(;t;){if(t===this.footnote.policyAnchorNode)return!1;t=t.parentNode}return!0}},Wy=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof is}createPageFloat(e,t,i){var n;let r=Ie.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Ie.PAGE).hasSameContainerAs(o)&&(r=Ie.PAGE);let s=!!t.generatingNodePosition;s&&r!==Ie.PAGE&&(r=Ie.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Vt(l)&&(h=l),h=$y(h);let u=new is(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=s,s){let c=t.generatingNodePosition;c&&(u.parentPageFloat=t.findPageFloatByNodePosition(c))}return t.addPageFloat(u),T(u)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new Jh(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Jh);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=e.vertical?e.paddingLeft+e.paddingRight+e.borderLeft+e.borderRight:e.paddingTop+e.paddingBottom+e.borderTop+e.borderBottom,l=e.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],u=getComputedStyle(n);for(let c of l){let p=u.getPropertyValue(c);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||I(n,c,`${Math.max(0,f-h)}px`)}}I(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){I(n,"max-block-size",""),I(n,e.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return T(void 0)})}forbid(e,t){let i=e;switch(i.footnotePolicy){case y.line:{let n=new Hy(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Bn.register(new Wy);var Al=class{calculateOffset(e){return Nn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Nn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Hr=class extends Al{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,d(this,"overflowIfRepetitiveElementsDropped"),d(this,"isEdgeUpdated",!1),d(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Ko(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=pn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Yn=class{find(e){let t=Ut("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()}`)}},xn=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new Hr(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===gi.ShadowType.ROOTLESS&&vn(i))return;let o=i.viewNode;((r=o.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let s=o.parentNode;Fd(s,o),n&&s.removeChild(o)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),T(!0)}},Fl=class{constructor(e){this.parent=e,d(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Rl=new xn,Gy=Aa.isInstanceOfBlockFormattingContext;Ot("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,o)=>{let s=e.parent;return!s&&e.formattingContext||s&&e.formattingContext!==s.formattingContext?null:e.establishesBFC||!e.formattingContext&&Nd(i,n,r,o)?new Fl(s?s.formattingContext:null):null});Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Fl?Rl:null);var Ll=class{constructor(){d(this,"initialBreakPositions",null),d(this,"initialStateOfFormattingContext",null),d(this,"initialPosition"),d(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=D("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let o=n.accept(r,t);o=n.postLayout(r,this.initialPosition,t,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},jy=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){}},La=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=D("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Oe(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?o=t.afterIgnoredTextNode(i):o=t.startIgnoredTextNode(i):i.nodeContext.after?o=t.afterNonElementNode(i):o=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?o=t.afterInlineElementNode(i):o=t.startInlineElementNode(i):i.nodeContext.after?o=t.afterNonInlineElementNode(i):o=t.startNonInlineElementNode(i):i.nodeContext.after?o=t.afterNonDisplayableNode(i):o=t.startNonDisplayableNode(i);let s=(o&&o.isPending()?o:T(!0)).thenAsync(()=>i.break?T(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},dr=class extends jy{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&&Ye(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:T(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:T(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}},Oa=[];function Xy(){Oa=[]}var no;function ro(e){if(e==="")return 0;if(no===void 0){let i=Intl.Segmenter;no=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(no===null)return[...e].length;let t=0;for(let i of no.segment(e))t++;return t}var qy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Yy=new Set(qy);function Zy(e){return!(e.toLowerCase()==="none"||Yy.has(e))}var Ky=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Jy=new Set(Ky),Qy=["fixed","extends"],ev=new Set(Qy),MS=Symbol();function Wr(e){return e instanceof ae&&e.name.toLowerCase()!=="none"}function rp(e){return e.name}function tv(e){if(e instanceof ae)return Jy.has(e.name);if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof ae){let n=t.name;return ev.has(n)&&(n==="fixed"&&i instanceof lt||n==="extends"&&Wr(i))}}return!1}function iv(e){let t=dt(e,"system");return t instanceof ae&&t.name==="cyclic"}function nv(e){let t=dt(e,"system");if(t instanceof ae&&t.name==="fixed")return!0;if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="fixed"&&n instanceof lt}return!1}function rv(e){let t=dt(e,"system");return t instanceof ae?1:t.values[1].num}function ov(e){let t=dt(e,"system");return t instanceof ae&&t.name==="alphabetic"}function sv(e){let t=dt(e,"system");return t instanceof ae&&t.name==="numeric"}function av(e){let t=dt(e,"system");return t instanceof ae&&t.name==="additive"}function lv(e){let t=dt(e,"system");if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="extends"&&Wr(n)}return!1}function hv(e){let t=dt(e,"system");return rp(t.values[1])}function $t(e){return e instanceof X||e instanceof ae}function di(e){return e instanceof X?e.str:e.name}function op(e){if($t(e))return!0;if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];return $t(t)&&$t(i)}return!1}function uv(e){if($t(e))return{prefix:di(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:di(t),suffix:di(i)}}}function Qh(e){return e instanceof lt||e instanceof ae&&e.name==="infinite"}function ns(e,t){return e instanceof lt?e.num:t?-1/0:1/0}var _S=Symbol();function Ba(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Qh(t)&&Qh(i)))return!1;let n=ns(t,!0),r=ns(i,!1);return!(n>r)}function cv(e){return{lower:ns(e.values[0],!0),upper:ns(e.values[1],!1)}}function sp(e){return e instanceof ae&&e.name==="auto"||Ba(e)||e instanceof rt&&e.values.length>=1&&e.values.every(t=>Ba(t))}function dv(e){return e instanceof ae?null:(Ba(e)?[e]:e.values).map(t=>cv(t))}var DS=Symbol();function rs(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof lt&&t.num>=0&&$t(i)||$t(t)&&i instanceof lt&&i.num>=0}function os(e){let[t,i]=e.values;return t instanceof lt?[t.num,di(i)]:[i.num,di(t)]}function ap(e){return rs(e)}function pv(e){let[t,i]=os(e);return{minLength:t,symbol:i}}function lp(e){return $t(e)||e instanceof te&&e.values.length>=1&&e.values.every(t=>$t(t))}function fv(e){return $t(e)?[di(e)]:e.values.map(t=>di(t))}var zS=Symbol();function hp(e){if(rs(e))return!0;if(e instanceof rt&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!rs(i))return!1;let[n]=os(i);if(n>=t)return!1;t=n}return!0}return!1}function gv(e){if(rs(e)){let[t,i]=os(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=os(t);return{weight:i,symbol:n}})}var mv=["auto","bullets","numbers","words","spell-out"],wv=new Set(mv);function yv(e){return e instanceof ae&&wv.has(e.name)||Wr(e)}function vv(e,t){switch(e){case"system":return tv(t);case"negative":return op(t);case"prefix":case"suffix":return $t(t);case"range":return sp(t);case"pad":return ap(t);case"fallback":return Wr(t);case"symbols":return lp(t);case"additive-symbols":return hp(t);case"speak-as":return yv(t);default:return!0}}function dt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function bv(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Mn(e){let t=e.get("decimal");return t||(t=pe.createDecimal(e),e.set("decimal",t)),t}var Po,No,To,Io,Ao,Fo,Ro,Lo,oo,hi,up,so,cp,ao,dp,lo,pp,ho,fp,uo,gp,co,mp,wt,Qs,wp,yp,eu,tu,ea,iu,or,ze=class zi{constructor(t,i){ee(this,wt),d(this,"_store"),ee(this,Po),ee(this,No),ee(this,To),ee(this,Io),ee(this,Ao),ee(this,Fo),ee(this,Ro),ee(this,Lo),this._store=t;let n=dt(i,"negative");fe(this,Po,n&&op(n)?uv(n):null);let r=dt(i,"prefix");fe(this,No,r&&$t(r)?di(r):null);let o=dt(i,"suffix");fe(this,To,o&&$t(o)?di(o):null);let s=dt(i,"range");fe(this,Io,s&&sp(s)?dv(s):null);let a=dt(i,"pad");fe(this,Ao,a&&ap(a)?pv(a):null);let h=dt(i,"fallback");fe(this,Fo,h&&Wr(h)?rp(h):null);let l=dt(i,"symbols");fe(this,Ro,l&&lp(l)?fv(l):null);let u=dt(i,"additive-symbols");fe(this,Lo,u&&hp(u)?gv(u):null)}static create(t,i){return iv(i)?new Li(t,i):nv(i)?new xv(t,i):ov(i)?new Cv(t,i):sv(i)?new nu(t,i):av(i)?new kv(t,i):lv(i)?new Ev(t,i):new Sv(t,i)}static createDecimal(t){var i;return new nu(t,se(i=zi,hi,up).call(i))}static createDisc(t){var i;return new Li(t,se(i=zi,hi,cp).call(i))}static createSquare(t){var i;return new Li(t,se(i=zi,hi,dp).call(i))}static createCircle(t){var i;return new Li(t,se(i=zi,hi,pp).call(i))}static createDisclosureOpen(t){var i;return new Li(t,se(i=zi,hi,fp).call(i))}static createDisclosureClosed(t){return new Li(t,se(this,hi,gp).call(this))}static createNone(t){var i;return new Li(t,se(i=zi,hi,mp).call(i))}static get CHINESE_LONGHAND_NAMES(){return ru.NAMES}static createChineseLonghand(t,i){return new ru(t,i)}static createEthiopicNumeric(t){return new Nv(t)}_getNegative(){return U(this,Po)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return U(this,No)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return U(this,To)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return U(this,Io)}static _getRangeFrom(t){return t._getRange()}_getPad(){return U(this,Ao)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(U(this,Fo)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return U(this,Ro)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return U(this,Lo)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return se(this,wt,or).call(this,t,new Set)}formatMarker(t){return se(this,wt,wp).call(this)+this.format(t)+se(this,wt,yp).call(this)}};Po=new WeakMap,No=new WeakMap,To=new WeakMap,Io=new WeakMap,Ao=new WeakMap,Fo=new WeakMap,Ro=new WeakMap,Lo=new WeakMap,oo=new WeakMap,hi=new WeakSet,up=function(){var e;return(e=U(ze,oo))!=null?e:fe(ze,oo,{system:new $(M("numeric"),0),symbols:new $(new te([new X("0"),new X("1"),new X("2"),new X("3"),new X("4"),new X("5"),new X("6"),new X("7"),new X("8"),new X("9")]),0)})},so=new WeakMap,cp=function(){var e;return(e=U(ze,so))!=null?e:fe(ze,so,{system:new $(M("cyclic"),0),symbols:new $(new X("\u2022"),0),suffix:new $(new X(" "),0)})},ao=new WeakMap,dp=function(){var e;return(e=U(ze,ao))!=null?e:fe(ze,ao,{system:new $(M("cyclic"),0),symbols:new $(new X("\u25AA"),0),suffix:new $(new X(" "),0)})},lo=new WeakMap,pp=function(){var e;return(e=U(ze,lo))!=null?e:fe(ze,lo,{system:new $(M("cyclic"),0),symbols:new $(new X("\u25E6"),0),suffix:new $(new X(" "),0)})},ho=new WeakMap,fp=function(){var e;return(e=U(ze,ho))!=null?e:fe(ze,ho,{system:new $(M("cyclic"),0),symbols:new $(new X("\u25BE"),0),suffix:new $(new X(" "),0)})},uo=new WeakMap,gp=function(){var e;return(e=U(ze,uo))!=null?e:fe(ze,uo,{system:new $(M("cyclic"),0),symbols:new $(new X("\u25B8"),0),suffix:new $(new X(" "),0)})},co=new WeakMap,mp=function(){var e;return(e=U(ze,co))!=null?e:fe(ze,co,{system:new $(M("cyclic"),0),symbols:new $(new X(""),0),suffix:new $(new X(""),0)})},wt=new WeakSet,Qs=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},wp=function(){var e;return(e=this._getPrefix())!=null?e:""},yp=function(){var e;return(e=this._getSuffix())!=null?e:". "},eu=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},tu=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},ea=function(){var e;return(e=this._getFallback())!=null?e:Mn(this._store)},iu=function(e,t){let{minLength:i,symbol:n}=se(this,wt,tu).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=se(this,wt,Qs).call(this),s=t?ro(r)+(o?ro(o):0):0,a=i-ro(e)-s;if(a<=0)return e;let h=ro(n),l=Math.ceil(a/h);return n.repeat(l)+e},or=function(e,t){var i,n,r;if(t.has(this))return se(i=Mn(this._store),wt,or).call(i,e,new Set);if(t.add(this),!bv(e,se(this,wt,eu).call(this))){let l=se(this,wt,ea).call(this);return se(n=l,wt,or).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=se(this,wt,ea).call(this);return se(r=l,wt,or).call(r,e,t)}let h=se(this,wt,iu).call(this,a,o);if(o){let{prefix:l,suffix:u}=se(this,wt,Qs).call(this);h=l+h+(u??"")}return h},ee(ze,hi),ee(ze,oo,null),ee(ze,so,null),ee(ze,ao,null),ee(ze,lo,null),ee(ze,ho,null),ee(ze,uo,null),ee(ze,co,null);var pe=ze,Li=class extends pe{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]}},Oo,xv=class extends pe{constructor(e,t){super(e,t),ee(this,Oo),fe(this,Oo,rv(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-U(this,Oo);return(t=i[n])!=null?t:null}};Oo=new WeakMap;var Sv=class extends pe{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Cv=class extends pe{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},nu=class extends pe{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},kv=class extends pe{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(o=>o.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},pr,St,At,vp=class extends pe{constructor(t,i){super(t,i),ee(this,St),ee(this,pr);let n=hv(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?fe(this,pr,r):fe(this,pr,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:pe._getNegativeFrom(se(this,St,At).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:pe._getPrefixFrom(se(this,St,At).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:pe._getSuffixFrom(se(this,St,At).call(this))}_getAutoRange(){return pe._getAutoRangeFrom(se(this,St,At).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:pe._getRangeFrom(se(this,St,At).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:pe._getPadFrom(se(this,St,At).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:pe._getFallbackFrom(se(this,St,At).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:pe._getSymbolsFrom(se(this,St,At).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:pe._getAdditiveSymbolsFrom(se(this,St,At).call(this))}_usesNegativeSign(t){return pe._useNegativeSignFrom(se(this,St,At).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:pe._generateInitialRepresentationFrom(se(this,St,At).call(this),t)}};pr=new WeakMap,St=new WeakSet,At=function(e=new Set){var t;if(e.has(this))return Mn(this._store);e.add(this);let i=this._store.get(U(this,pr));return i?i instanceof vp?se(t=i,St,At).call(t,e):i:Mn(this._store)};var Ev=vp,Pv=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"];function Zn(e){return{suffix:new $(new X("\u3001"),0),fallback:new $(M("cjk-decimal"),0),range:new $(new te([new lt(-9999),new lt(9999)]),0),negative:new $(new X(e),0)}}var ta,ia,po,na,fo,Ma,bp,Bo,mt=class xp extends pe{constructor(t,i){var n;let{chars:r,descriptors:o}=se(n=xp,Ma,bp).call(n).get(i);super(t,o),ee(this,Bo),fe(this,Bo,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=U(this,Bo);if(t===0)return i.digits[0];let n=[],r=0,o=t;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:c}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&c===1?a+=i.markers[c]:(a+=i.digits[u],c>0&&(a+=i.markers[c])))}return a}};ta=new WeakMap,ia=new WeakMap,po=new WeakMap,na=new WeakMap,fo=new WeakMap,Ma=new WeakSet,bp=function(){var e;return(e=U(mt,fo))!=null?e:fe(mt,fo,new Map([["simp-chinese-informal",{chars:U(mt,ta),descriptors:Zn("\u8D1F")}],["simp-chinese-formal",{chars:U(mt,ia),descriptors:Zn("\u8D1F")}],["trad-chinese-informal",{chars:U(mt,po),descriptors:Zn("\u8CA0")}],["trad-chinese-formal",{chars:U(mt,na),descriptors:Zn("\u8CA0")}],["cjk-ideographic",{chars:U(mt,po),descriptors:Zn("\u8CA0")}]]))},Bo=new WeakMap,ee(mt,Ma),ee(mt,ta,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ee(mt,ia,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ee(mt,po,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ee(mt,na,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),d(mt,"NAMES",new Set(Pv)),ee(mt,fo,null);var ru=mt,go,_a,Sp,Da,ss,za,Va,ai=class Vi extends pe{constructor(t){var i;super(t,se(i=Vi,_a,Sp).call(i))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return U(Vi,ss)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),c=a%10;o+=U(Vi,Da)[u]+U(Vi,ss)[c]}h?a!==0&&(o+=U(Vi,za)):s!==0&&(o+=U(Vi,Va))}return o}};go=new WeakMap,_a=new WeakSet,Sp=function(){var e;return(e=U(ai,go))!=null?e:fe(ai,go,{range:new $(new te([new lt(1),M("infinite")]),0),suffix:new $(new X("/ "),0)})},Da=new WeakMap,ss=new WeakMap,za=new WeakMap,Va=new WeakMap,ee(ai,_a),ee(ai,go,null),ee(ai,Da,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ee(ai,ss,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ee(ai,za,"\u137B"),ee(ai,Va,"\u137C");var Nv=ai,Fe,Tv=class{constructor(){ee(this,Fe),fe(this,Fe,new Map),U(this,Fe).set("none",pe.createNone(U(this,Fe))),U(this,Fe).set("decimal",pe.createDecimal(U(this,Fe))),U(this,Fe).set("disc",pe.createDisc(U(this,Fe))),U(this,Fe).set("square",pe.createSquare(U(this,Fe))),U(this,Fe).set("circle",pe.createCircle(U(this,Fe))),U(this,Fe).set("disclosure-open",pe.createDisclosureOpen(U(this,Fe))),U(this,Fe).set("disclosure-closed",pe.createDisclosureClosed(U(this,Fe)));for(let e of pe.CHINESE_LONGHAND_NAMES)U(this,Fe).set(e,pe.createChineseLonghand(U(this,Fe),e));U(this,Fe).set("ethiopic-numeric",pe.createEthiopicNumeric(U(this,Fe)))}define(e,t){if(!Zy(e))return null;let i=pe.create(U(this,Fe),t);return U(this,Fe).set(e,i),i}getStyle(e){var t;return(t=U(this,Fe).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Mn(U(this,Fe))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Mn(U(this,Fe))).formatMarker(t)}};Fe=new WeakMap;var Sn=class{constructor(e){this.validator=e,d(this,"success",null),d(this,"failure",null),d(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Oi=class{constructor(e,t){this.where=e,this.success=t,d(this,"what",-1)}},Kn=class Cp{constructor(){d(this,"nodes",[]),d(this,"connections",[]),d(this,"match",[]),d(this,"nomatch",[]),d(this,"error",[]),d(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Cp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Sn(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Oi(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,o=new Sn(ou);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,r);let s=new Oi(r,!0),a=new Oi(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(s)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new Sn(ou);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Oi(0,!0),r=new Oi(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new Sn(t));let n=new Oi(i,!0),r=new Oi(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof de}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<t.connections.length;o++){let s=t.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+r);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+r);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Iv=1,as=2,kp=4,yi=8,Gi=16,_n=32,Tn=64,ls=128,ti=256,ii=512,hs=1024,Ep=2048,Pp=4096,us=8192,Ol=class extends Xt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},de=class Np extends Ol{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Iv?t:null}visitSlash(t){return this.allowed&Ep?t:null}visitStr(t){return this.allowed&as?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&kp||this.allowed&Tn&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&ii)?t.unit=="%"&&this.allowed&hs?t:null:t.num<0&&!(this.allowed&ti)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&ii?t:null:t.num<=0&&!(this.allowed&ti)?null:this.allowed&Gi?t:null}visitInt(t){return t.num==0?this.allowed&ii?t:null:t.num<=0&&!(this.allowed&ti)?null:this.allowed&(_n|Gi)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Tn&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&ls?t:null}visitURange(t){return this.allowed&Pp?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(t.name.toLowerCase()==="attr"){let i=Dl(t);if(i&&Ov(i.type,this.allowed,this.units))return t}if(this.allowed&Tn){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&zc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&us){let i=t.visit(new $c);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(yi|Gi|_n|ti|ii|hs)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Np(this.allowed|t.allowed,i,n)}},Q=Object.create(null),Av=Gi|ti|ii,Fv=_n|ti|ii,Bi=yi|ti|ii|hs;function Gr(e){let t=Object.create(null);for(let i of e)t[i]=Be;return t}var As=Gr(["%"]),Fs=Gr(["em","ex","ch","rem","lh","rlh","vw","vh","vi","vb","vmin","vmax","pvw","pvh","pvi","pvb","pvmin","pvmax","cm","mm","in","px","pt","pc","q"]),Tp={...Fs,...As},Bl=Gr(["deg","grad","rad","turn"]),Ml=Gr(["s","ms"]),_l=Gr(["hz","khz"]);function Rv(e){return e.replace(/\s+/g,"").toLowerCase()}function Rs(e){return e.toLowerCase()}function Lv(e){if(e instanceof ae)switch(e.name.toLowerCase()){case"string":case"raw-string":return{kind:"string"};case"url":return{kind:"url"};case"color":case"integer":case"number":case"length":case"angle":case"time":case"frequency":return{kind:"syntax",syntax:`<${e.name.toLowerCase()}>`};default:return{kind:"unit",unit:Rs(e.name)}}if(e instanceof oi&&e.name.toLowerCase()==="type"){if(e.values.length!==1)return null;let t=Rv(e.values[0].stringValue());return t?{kind:"syntax",syntax:t}:null}return null}function Dl(e){var t;if(e.name.toLowerCase()!=="attr"||e.values.length<1||e.values.length>2)return null;let i,n={kind:"string"},r=e.values[0];if(r instanceof ae)i=r.name;else if(r instanceof te){let o=r.values;if(o.length<1||o.length>2||!(o[0]instanceof ae)||(i=o[0].name,o.length===2&&(n=Lv(o[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(t=e.values[1])!=null?t:null}}function Ip(e,t){return!!e[Rs(t)]}function rn(e,t){return Object.keys(t).some(i=>Ip(e,i))}function Ov(e,t,i){switch(e.kind){case"string":return!!(t&as);case"url":return!!(t&(ls|us));case"unit":return Ip(i,e.unit);case"syntax":switch(e.syntax){case"<string>":return!!(t&as);case"<url>":return!!(t&(ls|us));case"<color>":return!!(t&Tn);case"<integer>":return!!(t&(_n|Gi|ti|ii));case"<number>":return!!(t&(Gi|_n|ti|ii));case"<length>":return rn(i,Fs);case"<length-percentage>":return rn(i,Tp);case"<percentage>":return rn(i,As);case"<angle>":return rn(i,Bl);case"<time>":return rn(i,Ml);case"<frequency>":return rn(i,_l);default:return!1}}return!1}function Ua(e){switch(e.kind){case"string":return null;case"url":return null;case"unit":return new de(Bi,Q,{[Rs(e.unit)]:Be});case"syntax":switch(e.syntax){case"<color>":return new de(Tn,Q,Q);case"<integer>":return new de(Fv,Q,Q);case"<number>":return new de(Av,Q,Q);case"<length>":return new de(Bi,Q,Fs);case"<length-percentage>":return new de(Bi,Q,Tp);case"<percentage>":return new de(Bi,Q,As);case"<angle>":return new de(Bi,Q,Bl);case"<time>":return new de(Bi,Q,Ml);case"<frequency>":return new de(Bi,Q,_l);default:return null}}return null}function Bv(e){switch(e.kind){case"string":case"url":case"unit":return!0;case"syntax":return e.syntax==="<string>"||e.syntax==="<url>"||!!Ua(e)}return!1}function Mv(e){switch(e.kind){case"url":return new tt("about:invalid");case"string":return new X("");default:return y.unset}}function _v(e,t,i){if(t==null)return null;switch(i.kind){case"string":return new X(t);case"url":return t?new tt(t):new tt("about:invalid");case"unit":{let n=Ti(e,new vt(`${t.trim()}${Rs(i.unit)}`,null),""),r=Ua(i);return n&&r?n.visit(r):null}case"syntax":{if(i.syntax==="<string>")return new X(t);if(i.syntax==="<url>")return t?new tt(t):new tt("about:invalid");let n=Ti(e,new vt(t,null),""),r=Ua(i);return n&&r?n.visit(r):null}}return null}var ou=new de(0,Q,Q),zl=class extends Ol{constructor(e){super(),d(this,"successTerminal"),d(this,"failureTerminal"),d(this,"first"),this.successTerminal=new Sn(null),this.failureTerminal=new Sn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=e.length){r=r.failure;continue}let h=e[o],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(o==0&&!t&&r.validator instanceof fr&&this instanceof fr){if(l=new te(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof Vl&&this instanceof fr){if(l=new rt(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<o;u++)n[u]=e[u]}e!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:o==e.length)?n:null}validateSingle(e){let t=this.validateList([e],!1,0);return t?t[0]:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},fr=class extends zl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new te(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Vl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new rt(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Vl=class extends zl{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 rt(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}},Dv=class extends zl{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 oi(e.name,t):null}},su=class extends Ol{validateSingle(e){return null}visitFunc(e){let t=Dl(e);return t&&Bv(t.type)?e:null}},Ap=class{tryParse(e,t,i){return t}success(e,t){}},Fp=class extends Ap{constructor(e,t){super(),this.name=t,d(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,o=r>1?new te(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},zv=class extends Fp{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}},Vv=class extends Ap{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Un){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let o=1;o<this.nodes.length&&t<e.length&&(r=this.nodes[o].tryParse(e,t,i),r!=t);o++)t=r;return t}},Ls=class extends Xt{constructor(){super(...arguments),d(this,"syntax",null),d(this,"propList",null),d(this,"error",!1),d(this,"values",{}),d(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Fp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},$n=class extends Ls{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},Rp=class extends Ls{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 zv(this.validatorSet,this.propList)}},Uv=class extends Ls{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Un){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let o=[e[n],e[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},$v=class extends $n{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let o=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,s=e[r];s||(s=[],e[r]=s),s.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof rt?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 rt(t[i]);return null}},Hv=class extends $n{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"])){let s=this.values["font-weight"],a=s instanceof oi&&s.name==="calc"?e.indexOf(s):-1;if(a>=0&&e[a].visit(r["font-size"]))delete this.values["font-weight"],t=a;else return this.error=!0,t}if(this.values["font-size"]=e[t++],e[t]===Un){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new te(e.slice(t,e.length));return o.visit(r["font-family"])?(this.values["font-family"]=o,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new rt(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}},Wv=class extends $n{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=[y.auto,y.auto];break;case"none":e=[M("no-autospace"),M("space-all")];break}return super.validateList(e)}},Gv=class extends Ls{constructor(e,t=[]){super(),this.name=e,this.propList=t}clone(){let e=new this.constructor(this.name,[...this.propList]);return e.validatorSet=this.validatorSet,e}validateValueText(e){let t=this.validatorSet.expandBrowserShorthand(this.name,e);if(!t)return this.error=!0,!1;this.propList=t.propList,this.values={};for(let i of t.propList){let n=t.values[i];if(!n)continue;let r=Ti(this.validatorSet.scope,new vt(n,null),"");if(!r)return this.error=!0,!1;this.values[i]=r}return this.error=!1,!0}validateList(e){let t=e.length===1?e[0].toString():new te(e).toString();return this.validateValueText(t)?e.length:0}visitCommaList(e){return this.validateValueText(e.toString()),null}},au=["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","inset-block-start","inset-block-end","inset-inline-start","inset-inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Lp=class extends $n{constructor(){super()}refreshPropList(){this.propList=this.validatorSet.getPropertiesForAll()}init(e,t){super.init(e,t)}validateList(e){return this.error=!0,0}},lu={SIMPLE:$n,INSETS:Rp,INSETS_SLASH:Uv,COMMA:$v,FONT:Hv,TEXT_SPACING:Wv,ALL:Lp},jv=["initial-letter"],Xv=class{constructor(){d(this,"validators",{}),d(this,"prefixes",{}),d(this,"defaultValues",{}),d(this,"namedValidators",{}),d(this,"systemFonts",{}),d(this,"shorthands",{}),d(this,"layoutProps",{}),d(this,"backgroundProps",{}),d(this,"scope",new Go(null)),d(this,"browserShorthandStyle",null),d(this,"browserShorthandMisses",{}),d(this,"browserPropertyNamesForAll",null),d(this,"allPropertyNames",null)}invalidateAllPropertyNames(){this.allPropertyNames=null}getBrowserPropertyNamesForAll(){if(this.browserPropertyNamesForAll)return this.browserPropertyNamesForAll;if(typeof document>"u"||typeof getComputedStyle!="function")return null;let e=document.documentElement;if(!e)return null;let t=getComputedStyle(e),i=[];for(let n=0;n<t.length;n++){let r=t.item(n);!r||je(r)||au.includes(r)||i.push(r)}return this.browserPropertyNamesForAll=i,this.browserPropertyNamesForAll}getPropertiesForAll(){if(this.allPropertyNames)return this.allPropertyNames;let e=new Set;for(let n in this.validators)au.includes(n)||e.add(n);let t=this.getBrowserPropertyNamesForAll();if(t)for(let n of t)this.shorthands[n]||e.add(n);let i=Array.from(e);return t&&(this.allPropertyNames=i),i}getBrowserShorthandStyle(){return this.browserShorthandStyle!==null?this.browserShorthandStyle:typeof document>"u"?null:(this.browserShorthandStyle=document.createElement("div").style,this.browserShorthandStyle)}expandBrowserShorthand(e,t){let i=this.getBrowserShorthandStyle();if(!i)return null;i.cssText="",i.setProperty(e,t);let n=Array.from({length:i.length},(o,s)=>i.item(s)).filter(o=>!!o);if(!n.length||n.length===1&&n[0]===e.toLowerCase())return null;let r={};for(let o of n)r[o]=i.getPropertyValue(o);return{propList:n,values:r}}getShorthand(e,t){if(je(e))return null;let i=this.shorthands[e];if(i)return i instanceof Lp&&!this.allPropertyNames&&i.refreshPropList(),i;if(this.browserShorthandMisses[e]||t==null)return null;let n=this.expandBrowserShorthand(e,typeof t=="string"?t:t.toString());if(!n)return(typeof t=="string"?!/\bvar\(/i.test(t):!hu(t))&&(this.browserShorthandMisses[e]=!0),null;let r=new Gv(e,n.propList);return r.setOwner(this),this.shorthands[e]=r,this.invalidateAllPropertyNames(),r}addReplacement(e,t){let i;if(t.type==3)i=new R(t.num,t.text);else if(t.type==7)i=new Lc(t.text);else if(t.type==1)i=M(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Kn;if(e=="||"){for(let r=0;r<t.length;r++){let o=new Kn;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new Kn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Kn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Kn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Vl(t);break;case"SPACE":i=new fr(t);break;case"attr":i=new su;break;default:i=new Dv(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new de(Tn,Q,Q)),this.namedValidators.ATTR=this.primitive(new su),this.namedValidators.IMAGE_FUNCTION=this.primitive(new de(us,Q,Q)),this.namedValidators.POS_INT=this.primitive(new de(_n,Q,Q)),this.namedValidators.POS_NUM=this.primitive(new de(Gi,Q,Q)),this.namedValidators.POS_PERCENTAGE=this.primitive(new de(yi,Q,As)),this.namedValidators.NEGATIVE=this.primitive(new de(ti,Q,Q)),this.namedValidators.ZERO=this.primitive(new de(ii,Q,Q)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new de(hs,Q,Q)),this.namedValidators.POS_LENGTH=this.primitive(new de(yi,Q,Fs)),this.namedValidators.POS_ANGLE=this.primitive(new de(yi,Q,Bl)),this.namedValidators.POS_TIME=this.primitive(new de(yi,Q,Ml)),this.namedValidators.FREQUENCY=this.primitive(new de(yi,Q,_l)),this.namedValidators.RESOLUTION=this.primitive(new de(yi,Q,{dpi:Be,dpcm:Be,dppx:Be})),this.namedValidators.URI=this.primitive(new de(ls,Q,Q)),this.namedValidators.URANGE=this.primitive(new de(Pp,Q,Q)),this.namedValidators.IDENT=this.primitive(new de(kp,Q,Q)),this.namedValidators.STRING=this.primitive(new de(as,Q,Q)),this.namedValidators.SLASH=this.primitive(new de(Ep,Q,Q));let e={"font-family":M("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(s)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,s=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(s||h(" "),this.isBuiltIn(u.text)){let c=this.namedValidators[u.text];if(!c)throw new Error(`'${u.text}' unexpected`);i.push(c.clone())}else{let c={};c[u.text.toLowerCase()]=M(u.text),i.push(this.primitive(new de(0,c,Q)))}s=!1;break;case 5:{let c={};c[`${u.num}`]=new lt(u.num),i.push(this.primitive(new de(0,c,Q))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],s=!0;break;case 15:{o=a();let c=n.pop();if(c.b!="[")throw new Error("']' unexpected");i=c.vals,i.push(o),r=c.op,s=!1;break}case 11:{o=a();let c=n.pop();if(c.b!="(")throw new Error("')' unexpected");i=c.vals,i.push(this.newFunc(c.fn,o)),r=c.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let c=u.num,p=c;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),c,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new fr(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(M(n.text));break;case 4:i.push(new Nt(n.num));break;case 5:i.push(new lt(n.num));break;case 3:i.push(new R(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new te(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&lu[i.text]?(n=new lu[i.text],e.consume()):n=new $n,n.setOwner(this);let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])o.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Rp){let l=this.shorthands[i.text];o.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let l=new Vv(o,s),u=a.pop();o=u.syntax,s=u.slash,o.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n,this.invalidateAllPropertyNames()}}parse(e){let t=new vt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(t=this.defaultValues[s])!=null?t:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){var r,o;let s=n.ruleType;if(je(e)||s==="font-face"){n.simpleProperty(e,t,i);return}if(s==="counter-style"){vv(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let a="",h=e;e=e.toLowerCase();let l=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);l&&(a=l[1],e=l[2]);let u=a?h:e;if(hu(t)){this.getShorthand(u,t),n.simpleProperty(h,t,i);return}let c=this.prefixes[e];if(!c||!c[a]){if(CSS.supports(h,t.toString())){let f=(r=this.getShorthand(u,t))==null?void 0:r.clone();f?q(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t)):n.simpleProperty(h,t,i)}else a&&!hc.includes(`-${a}-`)||n.unknownProperty(h,t);return}else if(jv.includes(e)&&!Object.keys(c).some(f=>So(f?`-${f}-`:"",e))){n.unknownProperty(h,t);return}let p=this.validators[e];if(p){let f=q(t)||t.isExpr()?t:t.visit(p);f?n.simpleProperty(e,f,i):!a&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(h,t)}else{let f=(o=this.getShorthand(e,t))==null?void 0:o.clone();if(!f){n.unknownProperty(h,t);return}q(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t))}}};function Op(){let e=new Xv;return e.initBuiltInValidators(),e.parse(cd),e}var qv=class extends Xt{constructor(){super(...arguments),d(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function hu(e){let t=new qv;return e.visit(t),t.varFound}function Bp(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Yv=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Zv=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Mp=class Mo{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Mo.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Mo.fragmentIndices={}}matches(){let t=Mo.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Bp(t.fragmentIndex,this.a,this.b)}};d(Mp,"fragmentIndices",{});var Os=Mp,mo=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Os(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Zv(e)}static buildAnyMatcher(e){return new Yv(e)}},_p={"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},Kv=["image-resolution","orphans","widows"];function Jv(){return Ut("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Kv))}var Qv={"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},$a=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],eb=["max-%","min-%","%"],uu=(()=>{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<$a.length;i++)for(let n=0;n<e.length;n++){let r=$a[i].replace("%",e[n]);t[r]=!0}return t})();function Hn(e,t){let i={};for(let n of $a)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}for(let n of eb)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var Dp=Hn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),zp=Hn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),tb=Hn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),ib=Hn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),nb=Hn({inside:"right",outside:"left"},{}),rb=Hn({inside:"left",outside:"right"},{}),$=class Ha{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 Ha(i,this.priority)}increaseSpecificity(t){return t==0?this:new Ha(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&je(i)?this.value:fs(t,this.value,i,n,r)}isEnabled(t){return!0}},Wa=class Ga extends ${constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new $(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Ga(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Ga(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){j.warn(i)}return!1}};function ja(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function qt(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Vp={"region-id":!0,"fragment-selector-id":!0},gr="data-viv-footnote-counter";function cs(e){let t=e.getAttribute(gr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function Up(e,t,i){let n=cs(e);n[t]=i,e.setAttribute(gr,JSON.stringify(n))}function ob(e,t){var i,n;if(!Vt(e)||e.hasAttribute(Qd))return null;let r=cs(e)[t];if(r)return r;let o=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=Ho(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=e.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let u=cs(l)[t];return u?(Up(e,t,u),u):null}function sb(e){let t=ge(e,"content");return!!t&&Tt(t.value)}function ab(e){return!!Vp[e]}function _o(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Hi(e){return e.charAt(0)!=="_"&&!Vp[e]}function Cn(e){return!!_p[e]||je(e)}function ge(e,t){return e[t]}function Ni(e,t,i){i?e[t]=i:delete e[t]}function pt(e,t){return e[t]}function ri(e,t){let i=e[t];return i||(i={},e[t]=i),i}var $p=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Hp(e,t){return e[t]}function Wp(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function ds(e,t,i,n,r,o,s){var a,h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=ri(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),s){let l=$p(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!_o(l))if(ab(l)){let u=Hp(i,l),c=Wp(t,l);Array.prototype.push.apply(c,u)}else{let u=ge(i,l);if(!u.isEnabled(e))continue;let c=u.increaseSpecificity(n);qt(t,l,c,e);let p=(a=e.style)==null?void 0:a.validatorSet,f=(h=p?.getShorthand(l,c.value))==null?void 0:h.propList;if(f)for(let g of f){let m=new $(Be,c.priority);qt(t,g,m,e)}}}function lb(e,t){let i={};for(let n=0;n<t.length;n++)ds(e,i,t[n],0,null,null,null);return i}function Ul(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var hb=class extends Ki{constructor(e,t){super(),this.props=e,this.context=t,d(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ge(this.props,"font-size");if(!e.value.isNumeric())return jt.em;let t=e.value;if(!Yg(t.unit))throw new Error("Unexpected state");return t.num*jt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Xa(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?$l(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?fs(this.context,e,this.propName).visit(this):e}};function $l(e,t,i){let n=e.unit,r=e.num;return n==="em"?new R(r*t,"px"):n==="rem"?new R(r*i.fontSize(),"px"):n==="rlh"?new R(r*i.rootLineHeight,"px"):e}function Xa(e,t,i){e=$l(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new R(r/100*t,"px"):new R(r*i.queryUnitSize(n,!1),"px")}var Wn=class{apply(e){}mergeWith(e){return new ub([this,e])}clone(){return this}},wo=class extends Wn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},ub=class Gp extends Wn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Gp([].concat(this.list))}},Hl=class extends Wn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){ds(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Pe=class extends Wn{constructor(){super(),d(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},cb=class extends Pe{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}},db=class extends Pe{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}},cu=class extends Pe{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}},pb=class extends Pe{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}},fb=class extends Pe{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},gb=class extends Pe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Bs(e,t,i,n){var r;if(!e)return!1;let o=((r=e.ownerDocument)==null?void 0:r.contentType)==="text/html",s=o?Er(i):i;if(t!==null){let a=e.getAttributeNodeNS(t||null,s);return!!a&&n(a)}for(let a of Array.from(e.attributes))if((o?Er(a.localName):a.localName)===s&&n(a))return!0;return!1}function Er(e){return e.replace(/[A-Z]/g,t=>t.toLowerCase())}function jp(e){return e==="i"}function Jn(e,t){return Array.from(e,i=>{let n=Wo(i);if(!jp(t))return n;let r=Er(i),o=r.toUpperCase();return r!==o&&/^[a-z]$/i.test(i)?`[${r}${o}]`:n}).join("")}function Qn(e){return new RegExp(e)}function mb(e,t,i){return jp(i)?Er(e)===Er(t):e===t}var du=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Bs(e.currentElement,this.ns,this.name,()=>!0)&&this.chained.apply(e)}},wb=class extends Pe{constructor(e,t,i,n=null){super(),this.ns=e,this.name=t,this.value=i,this.caseSensitivity=n}apply(e){Bs(e.currentElement,this.ns,this.name,t=>mb(t.value,this.value,this.caseSensitivity))&&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}},yb=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Bs(e.currentElement,this.ns,this.name,t=>!!Qv[t.value])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},er=class extends Pe{constructor(e,t,i,n=null){super(),this.ns=e,this.name=t,this.regexp=i,this.caseSensitivity=n}apply(e){Bs(e.currentElement,this.ns,this.name,t=>!!t.value.match(this.regexp))&&this.chained.apply(e)}},vb=class extends Pe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},pu=class extends Pe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},bb=class extends Pe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},en=class extends Pe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Bp(e,this.a,this.b)}},xb=class extends en{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},qa=class extends en{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}},Ya=class extends en{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}},Za=class extends en{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,o=t[n];o||(o=t[n]={}),o[r]=(o[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},Sb=class extends Pe{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}},Cb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},kb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Eb=class extends Pe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},it=class extends Pe{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}},Xp=class qp extends Wn{constructor(){super(),d(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new qp;return t.applied=this.applied,t}},Wl=class extends Pe{constructor(e){super(),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Xp;for(let t of e)this.firstActions.push(Ul(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 Pe?e.getPriority():0))}positive(){return!0}relational(){return!1}},Pb=class extends Wl{positive(){return!1}},Nb=class extends Wl{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},Yp=class extends en{constructor(e,t,i){super(e,t),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Xp;for(let n of i)this.firstActions.push(Ul(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,o=t.currentId,s=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let c of this.firstActions)if(c.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=o,t.currentClassNames=s,t.currentSiblingOrder=a,u}getPriority(){return 5}},Tb=class extends Yp{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},Ms=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)}},Ib=class Zp extends Ms{constructor(t,i,n){super(t,i,n)}fresh(t){return new Zp(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}},Ab=class Kp extends Ms{constructor(t,i,n){super(t,i,n)}fresh(t){return new Kp(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)}},Fb=class Jp extends Ms{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new Jp(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)}},Rb=class Qp extends Ms{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new Qp(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}},Lb=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}},Ob=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}},Bb=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}},Mb=class extends Ki{constructor(e,t,i,n){super(),this.element=e,this.scope=t,this.propName=i,this.validatorSet=n,d(this,"hadAttrFunction",!1)}validatePropertyValue(e){var t,i;if(q(e))return e;let n=(t=this.validatorSet)==null?void 0:t.validators[this.propName];return n?(i=e.visit(n))!=null?i:y.unset:!this.propName||CSS.supports(this.propName,e.toString())?e:y.unset}visitFunc(e){var t;if(e.name.toLowerCase()!=="attr")return super.visitFunc(e);this.hadAttrFunction=!0;let i=Dl(e);if(!i)return super.visitFunc(e);let n=((t=i.fallback)!=null?t:Mv(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:_v(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function ps(e,t){if(Tt(e)){if(e instanceof X)return e.stringValue();if(e instanceof G&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof te)return e.values.map(i=>ps(i,t)).join("")}return""}var Pr=class extends Ki{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=ps(i,this.cascade.context);return this.cascade.quoteDepth=t,n}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new X("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new X("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new pi;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var o,s,a,h,l,u;let c=typeof r=="string",p=w=>c?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&Up(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=ob(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=cs(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((o=e.currentPageCounters)==null?void 0:o[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((s=e.currentPageDocCounters)==null?void 0:s[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],S=((l=e.currentPageCounters)==null?void 0:l[t])||[],v=S.length?S[S.length-1]:0,b=w.length?w[0]:0,x=m.length?m[0]:0,C=v+(x-b);return g=m.length?[C,...m.slice(1)]:S.length?S:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let a=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),h=this.getPageScope(),l=new Le(h,()=>this.buildCounterText(o,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&o!=null&&o.registerPageCounterExpr){let u=c=>this.formatLastValue(c,n);o.registerPageCounterExpr(i,u,l)}return new G(l)}let s=this.cascade.counters[i];if(s&&s.length){let a=s&&s.length&&s[s.length-1]||0;return new X(this.format(a,n))}else{let a=new G(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new te([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",o=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let u=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),c=this.getPageScope(),p=new Le(c,()=>this.buildCounterText(s,i,r,o,n),u?`page-counters-${i}`:`counters-${i}`);return u&&s!=null&&s.registerPageCounterExpr&&s.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new G(p)}let a=this.cascade.counters[i],h=new pi;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new G(this.counterResolver.getPageCountersVal(i,u=>{let c=[];if(u.length)for(let f=0;f<u.length;f++)c.push(this.format(u[f],r));let p=h.toString();return p.length&&c.push(p),c.length?c.join(n):this.format(0,r)}));return new te([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof tt?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",o=new G(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new te([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof tt?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),o=e.length>3?e[3].stringValue():"decimal",s=new G(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new te([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof tt?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new G(this.counterResolver.getTargetTextVal(i,n));return new te([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new G(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,o,s,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let c=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(c&&this.element)for(let f=0;f<c.length;f++){let g=c[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=pt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=ps(m,this.cascade.context)}}}break;case"first-letter":{let c=pt(this.cascade.currentStyle,"_pseudos"),p=(s=(o=c?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=c?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match($o);u=g?g[0]:""}break}return new X(u)}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 X&&(t=e[0].stringValue());return t.length==0?new X(""):new G(new Le(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 ra(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var _b=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(P){b==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(m);return v==="vertical-rl"||v==="vertical-lr"?b==="rtl"?P.top-=k:P.bottom+=k:b==="rtl"?P.left-=k:P.right+=k,F.left>P.left||F.right<P.right||F.top>P.top||F.bottom<P.bottom},c=function(){let P,A,B=S.repeat(1e4);if(l(B),u())P=1,A=1e4;else return;for(let z=0;z<16;z++){let W="",Z=Math.floor((P+A)/2);for(let K=0;K<Z;K++)W+=S;if(l(W),u())A=Z;else{if(P==Z)return;P=Z}}l(S)},p=function(P){let A=0,B=m.parentElement;for(;B&&B!==f.viewNode;)A+=i.getComputedInsets(B)[P],B=B.parentElement;return A};var r=l,o=u,s=c,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),S=g.getAttribute("data-viv-leader-value"),{writingMode:v,direction:b,marginInlineEnd:x}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(S),m.style.display="inline-block",m.style.textIndent="0";let C=$r(f.viewNode),N=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let F=i.clientLayout.getElementClientRect(f.viewNode),L=i.clientLayout.getElementClientRect(m),V=i.parseComputedLength(x),Y=[],ue=m.parentElement;for(;ue.parentElement&&ue.parentElement!==f.viewNode;)ue=ue.parentElement;let he=ue.nextSibling;for(;he;){if(he.nodeType===1){let P=he,{display:A,float:B,position:z}=i.clientLayout.getElementComputedStyle(P);if(B!=="none"||z==="absolute"||z==="fixed"){he=he.nextSibling;continue}if(Gt(A))Y.push(P);else if(Zw(A))break}else if(he.nodeType===3){let P=he;P.length>0&&Y.push(P)}he=he.nextSibling}let k=Y.reduce((P,A)=>P+ra(A,i.clientLayout,v),0);if(w!=="after"){let P=ra(ue,i.clientLayout,v),A=ra(m,i.clientLayout,v);k+=P-A}v==="vertical-rl"||v==="vertical-lr"?(b==="rtl"?F.top+=V:F.bottom-=V,F.top=Math.min(L.top,F.top),F.bottom=Math.max(L.bottom,F.bottom)):(b==="rtl"?F.left+=V:F.right-=V,F.left=Math.min(L.left,F.left),F.right=Math.max(L.right,F.right)),c();let _=i.clientLayout.getElementClientRect(m);b=="rtl"?m.style.float="left":m.style.float="right";let E=i.clientLayout.getElementClientRect(m),O=0;b=="rtl"?v=="vertical-rl"||v=="vertical-lr"?O=_.top-E.top-p("top"):O=_.left-E.left-p("left"):v=="vertical-rl"||v=="vertical-lr"?O=E.bottom-_.bottom-p("bottom"):O=E.right-_.right-p("right"),O-=k,O=Math.max(0,O-.1),m.style.float="",g.style.marginInlineStart=`${O}px`,C&&(N?C.style.columnFill=N:C.style.removeProperty("column-fill"))}};Ot("POST_LAYOUT_BLOCK",_b);var Gl=1/1048576;function on(e,t){for(let i in e)t[i]=e[i].clone()}var Db=class ef{constructor(){d(this,"nsCount",0),d(this,"nsPrefix",{}),d(this,"tags",{}),d(this,"nstags",{}),d(this,"epubtypes",{}),d(this,"classes",{}),d(this,"ids",{}),d(this,"pagetypes",{}),d(this,"order",0)}clone(){let t=new ef;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return on(this.tags,t.tags),on(this.nstags,t.nstags),on(this.epubtypes,t.epubtypes),on(this.classes,t.classes),on(this.ids,t.ids),on(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,o,s){return new zb(this,t,i,n,r,o,s)}nextOrder(){return this.order+=Gl}},tf=class nf{constructor(t,i,n,r,o,s,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=s,this.cmykStore=a,d(this,"code"),d(this,"stack",[[],[]]),d(this,"conditions",Object.create(null)),d(this,"currentElement",null),d(this,"currentElementOffset",null),d(this,"currentStyle",null),d(this,"currentClassNames",null),d(this,"currentLocalName",""),d(this,"currentNamespace",""),d(this,"currentId",""),d(this,"currentXmlId",""),d(this,"currentNSTag",""),d(this,"currentEpubTypes",null),d(this,"currentPageType",null),d(this,"previousPageType",null),d(this,"firstPageType",null),d(this,"pageTypePageIndices",Object.create(null)),d(this,"isFirst",!0),d(this,"isRoot",!0),d(this,"counters",Object.create(null)),d(this,"lastCounterChanges",[]),d(this,"lastCounterChangeTypes",Object.create(null)),d(this,"counterScoping",[Object.create(null)]),d(this,"quotes"),d(this,"quoteDepth",0),d(this,"lang",""),d(this,"siblingOrderStack",[0]),d(this,"currentSiblingOrder",0),d(this,"siblingTypeCountsStack",[{}]),d(this,"currentSiblingTypeCounts"),d(this,"currentFollowingSiblingOrder",null),d(this,"followingSiblingOrderStack"),d(this,"followingSiblingTypeCountsStack",[{}]),d(this,"currentFollowingSiblingTypeCounts"),d(this,"viewConditions",Object.create(null)),d(this,"dependentConditions",[]),d(this,"elementStack"),this.code=t,this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=mo.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:mo.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:mo.buildAllMatcher(n):mo.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=oa,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,o,s,a,h,l;let u=new Set,c=Object.create(null),p=y.inline,f=t.display;if(f&&(p=f.evaluate(this.context)),p===y.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let g=y.inline,m=t.float;m&&(g=m.evaluate(this.context));let w=null,S=null,v=null,b=t["counter-reset"];if(b){let N=b.evaluate(this.context);N&&(w=En(N,{reset:!0}))}let x=t["counter-set"];if(x){let N=x.evaluate(this.context);N&&(v=En(N,{defaultValue:0}))}let C=t["counter-increment"];if(C){let N=C.evaluate(this.context);N&&(S=En(N))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(w||(w=Object.create(null)),w["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),nr(p)&&(S||(S=Object.create(null)),S["list-item"]=(r=S["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((s=(o=this.currentElement)==null?void 0:o.getAttribute("value"))!=null?s:"")&&(v||(v=Object.create(null)),v["list-item"]=this.currentElement.value)),((h=(a=this.currentElement)==null?void 0:a.parentNode)==null?void 0:h.nodeType)===Node.DOCUMENT_NODE&&(w||(w=Object.create(null)),w.footnote===void 0&&(w.footnote=0)),g===y.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(S||(S=Object.create(null)),S.footnote===void 0)){let N=(l=this.currentStyle["counter-increment"])==null?void 0:l.value;(!N||!(N===y.footnote||N instanceof te&&N.values.includes(y.footnote)))&&(S.footnote=1)}if(w)for(let N in w)u.add(N),c[N]="reset";if(S)for(let N in S)u.add(N),c[N]||(c[N]="increment");if(v)for(let N in v)u.add(N),c[N]="set";if(this.lastCounterChanges=Array.from(u),this.lastCounterChangeTypes=c,w)for(let N in w)this.defineCounter(N,w[N]);if(S)for(let N in S){this.counters[N]||this.defineCounter(N,0);let F=this.counters[N];F[F.length-1]+=S[N]}if(v)for(let N in v)if(!this.counters[N])this.defineCounter(N,v[N]);else{let F=this.counters[N];F[F.length-1]=v[N]}if(nr(p)){let N=this.counters["list-item"],F=N[N.length-1];t["ua-list-item-count"]=new $(new Nt(F),0);let L=ri(t,"_pseudos");L.marker||(L.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new Pr(this,this.currentElement,this.counterResolver));let n=i.value instanceof rt?i.value.values:[i.value];for(let r of n)if(r instanceof te){let o=r.values[0].stringValue(),s=r.values.slice(1).map(a=>ps(a,this.context)).join("");this.counterResolver.setNamedString(o,s,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof oi&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new Pr(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var o,s,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=oa;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=oa;let c=da(i);c&&(this.stack[this.stack.length-1].push(new Ob(this.lang)),this.lang=c.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let S=this.followingSiblingOrderStack;S[S.length-1]!==null?this.currentFollowingSiblingOrder=--S[S.length-1]:this.currentFollowingSiblingOrder=null,S.push(null);let v=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=v[v.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,v.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i,t);let x=n.quotes,C=null;if(x){let L=x.evaluate(this.context);L&&(C=new Bb(this.quotes),L===y.none?this.quotes=[new X(""),new X("")]:L===y.auto||L===y.initial?this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")]:L instanceof te&&(this.quotes=L.values))}this.pushCounters(this.currentStyle);let N=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||N){let L=Object.create(null);Object.keys(this.counters).forEach(V=>{L[V]=Array.from(this.counters[V])}),this.counterListener.countersOfId(N,L)}let F=pt(this.currentStyle,"_pseudos");if(F){let L=!0;for(let V of Vb){V||(L=!1);let Y=F[V];if(Y){let ue=(o=ge(this.currentStyle,"float"))==null?void 0:o.value,he=i instanceof Element&&Vt(i),k=i instanceof Element&&kt(i),_=!!ge(this.currentStyle,"--viv-semantic-footnote-content"),E=ue===y.footnote,O=(V==="before"||V==="after")&&(E||k||_)&&!!Y.content,P=sb(Y),A=V==="footnote-call"&&he&&P,B=V==="footnote-marker"&&(k||_)&&P;if((V==="before"||V==="after")&&!(O||Tt((s=Y.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(Y))||V==="marker"&&!nr((a=ge(this.currentStyle,"display"))==null?void 0:a.value)||(V==="footnote-call"||V==="footnote-marker")&&ue!==y.footnote&&!A&&!B||(V==="footnote-call"||V==="footnote-marker")&&_&&!P)delete F[V];else if(L){if(this.processPseudoelementProps(Y,i,V),V==="marker")this.processMarkerPseudoelementProps(Y,i,t),delete F[V];else if(V==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(Y,"list-style-position",t,i)===y.outside){this.processMarkerPseudoelementProps(Y,i,t);let z=Y.content;z&&(this.currentStyle["_footnote-marker-content"]=z),this.currentStyle.display=new $(M("list-item"),0),this.currentStyle["list-style-position"]=new $(y.outside,0),this.currentStyle["list-style-type"]=new $(y.none,0),this.currentStyle["list-style-image"]=new $(y.none,0),delete F[V]}}else if(V==="first-letter"&&Y["initial-letter"]){let z=Y["initial-letter"].evaluate(this.context);z!==y.normal&&!q(z)&&(this.currentStyle["--viv-initialLetter"]=new $(z,0)),delete Y["initial-letter"]}}else this.stack[this.stack.length-2].push(new Lb(Y,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return Tt((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,o,s,a,h;let l=nr((r=this.currentStyle.display)==null?void 0:r.value);if(!Tt((o=t.content)==null?void 0:o.value)&&l){let c=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof tt)t.content=new $(new te([p,new X(" ")]),0);else if(c instanceof X)t.content=new $(c,0);else if(c instanceof ae&&c!==y.none){let f=(a=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=c.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new $(new X(this.counterStyleStore.formatMarker(c.name,f)),0))}}}let u=t.content;if(u){let c=u.value;if(Tt(c)){let p=this.resolveMarkerContentVal(c);this.currentStyle["--viv-marker-content"]=new $(p,0)}}for(let c of nf.markerAllowedProps){let p=t[c];if(p){let f=p.evaluate(this.context,c);f&&!q(f)&&(this.currentStyle[`--viv-marker-${c}`]=new $(f,0))}}if(!Gt((h=ge(this.currentStyle,"display"))==null?void 0:h.value)){let c=this.getInheritedPropertyValue("list-style-position",n,i);c&&c!==y.outside&&!q(c)&&(this.currentStyle["list-style-position"]=new $(c,0))}}resolveMarkerContentVal(t){if(t instanceof G){let i=t.expr.evaluate(this.context);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):t}if(t instanceof te){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new te(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let s=n;s;s=s.parentElement){let a=(s===this.currentElement?this.currentStyle:i.getStyle(s,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===y.inherit||h===y.unset||h===y.revert)continue;if(h===y.initial)break;return h}}let o=i.validatorSet;return(r=o?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var o;let s=t[i];if(s){let a=s.evaluate(this.context,i);if(a!==y.inherit&&a!==y.unset&&a!==y.revert){if(a===y.initial){let h=n.validatorSet;return(o=h?.defaultValues[i])!=null?o:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i,n){let r=t.scope,o=t.validatorSet;for(let s in n)if(Hi(s)&&!je(s)){let a=n[s],h=new Mb(i,r,s,o),l=a.filterValue(h);if(!h.hadAttrFunction){n[s]=l;continue}let u=h.validatePropertyValue(l.value);n[s]=u===l.value?l:new $(u,l.priority)}}applyAttrFilter(t,i){let n=this.currentStyle,r=pt(n,"_pseudos");for(let o in r)this.applyAttrFilterInner(i,t,r[o]);this.applyAttrFilterInner(i,t,n)}applyVarFilter(t,i,n){let r=t[0],o=t.map(c=>({...c})),s=32,a={},h=pt(r,"_pseudos"),l=Object.keys(r).filter(Hi),u=c=>{var p,f,g;let m=ge(r,c),w=m.value,S=je(c)?o:t,v=new Zb(S,i,n,je(c)?c:null);je(c)&&v.getFallbackCycleMembers(w,S,n)&&(w=y.initial);for(let b=0;;b++){if(b>=s){w=je(c)?y.initial:Be;break}let x=w.visit(v);if(v.error){w=je(c)?y.initial:Be,v.error=!1;break}if(x===w)break;w=x}if(w!==m.value){let b=i.validatorSet,x=(p=b?.getShorthand(c,w))==null?void 0:p.clone();if(x)if(q(w)){for(let C of x.propList){let N=new $(w,m.priority),F=ge(r,C);Ni(a,C,ja(this.context,F,N))}delete r[c]}else{let C=Ti(i.scope,new vt(w.toString(),null),"");if(C&&(C.visit(x),!x.error)){for(let N of x.propList){let F=new $((g=(f=x.values[N])!=null?f:b.defaultValues[N])!=null?g:y.initial,m.priority),L=ge(r,N);Ni(a,N,ja(this.context,L,F))}delete r[c]}}else r[c]=new $(w,m.priority)}if(a[c]){let b=ge(r,c);b&&b.value!==Be&&qt(a,c,b,this.context)}};for(let c in r)if(_o(c)){if(c==="_pseudos")continue;let p=pt(r,c);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}for(let c of l)je(c)&&u(c);for(let c of l)je(c)||u(c);if(h)for(let c in h)this.applyVarFilter([h[c],...t],i,n);for(let c in a)r[c]=a[c]}applyCalcFilter(t,i){let n=new df(i);for(let r in t)if(_o(r)){let o=pt(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Hi(r)&&!je(r)){let o=ge(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new $(s,o.priority))}}applyCmykFilter(t,i){let n=new $c(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(_o(r)){let o=pt(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Hi(r)&&!je(r)){let o=ge(t,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),t[r]=new $(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};d(tf,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","hyphens","line-height","tab-size","text-combine-upright","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-orientation","text-shadow","text-transform","unicode-bidi","direction","white-space"]);var zb=tf,oa=[],Vb=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],Ka=null;function Ub(e){Ka=e}var Nr=class extends Qi{constructor(e,t,i,n,r,o,s){super(e,t,s),this.condition=i,this.regionId=r,this.validatorSet=o,d(this,"chain",null),d(this,"specificity",0),d(this,"elementStyle",null),d(this,"conditionCount",0),d(this,"pseudoelement",null),d(this,"selectorFunctionContainsPseudoelement",!1),d(this,"footnoteContent",!1),d(this,"cascade"),d(this,"state"),d(this,"viewConditionId",null),d(this,"insideSelectorRule"),d(this,"invalid",!1),this.cascade=n?n.cascade:Ka?Ka.clone():new Db,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Ul(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}invalidContinuationAfterPseudoelement(e){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${e}`),!0):this.selectorFunctionContainsPseudoelement?(this.invalidSelector(`Selector containing pseudo-element followed by ${e}`),!0):!1}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||this.invalidContinuationAfterPseudoelement(t||"*")||(t&&(this.specificity+=1),t&&e?this.chain.push(new pb(e,t.toLowerCase())):t?this.chain.push(new cu(t.toLowerCase())):this.chain.push(new gb(e)))}invalidSelector(e){j.warn(e),this.chain.push(new it("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Dn;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new cb(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Cb);break;case"disabled":this.chain.push(new kb);break;case"checked":this.chain.push(new Eb);break;case"root":case"scope":this.chain.push(new bb);break;case"link":this.chain.push(new cu("a")),this.chain.push(new du("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${Wo(i)}($|\\s)`),r=t[1];this.chain.push(new fb(n,r,e==="href-role-type"))}else this.chain.push(new it(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new it(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new vb(new RegExp(`^${Wo(i.toLowerCase())}($|-)`)))}else this.chain.push(new it(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=$b[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new it(""));break}case"first-child":this.chain.push(new pu);break;case"last-child":this.chain.push(new Ya(0,1));break;case"first-of-type":this.chain.push(new qa(0,1));break;case"last-of-type":this.chain.push(new Za(0,1));break;case"only-child":this.chain.push(new pu),this.chain.push(new Ya(0,1));break;case"only-of-type":this.chain.push(new qa(0,1)),this.chain.push(new Za(0,1));break;case"empty":this.chain.push(new Sb);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}}pseudoelementSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`::${e}`)){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new it(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new it(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new db(e)))}attributeSelector(e,t,i,n,r){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,n=n||"";let o;switch(i){case 0:o=new du(e,t);break;case 39:o=new wb(e,t,n,r??null);break;case 45:!n||n.match(/\s/)?o=new it(""):o=new er(e,t,Qn(`(^|\\s)${Jn(n,r??null)}($|\\s)`),r??null);break;case 44:o=new er(e,t,Qn(`^${Jn(n,r??null)}($|-)`),r??null);break;case 43:n?o=new er(e,t,Qn(`^${Jn(n,r??null)}`),r??null):o=new it("");break;case 42:n?o=new er(e,t,Qn(`${Jn(n,r??null)}$`),r??null):o=new it("");break;case 46:n?o=new er(e,t,Qn(Jn(n,r??null)),r??null):o=new it("");break;case 50:if(n=="supported")o=new yb(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(o)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${yo++}`;this.processChain(new wo(new Ib(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${yo++}`;this.processChain(new wo(new Ab(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${yo++}`;this.processChain(new wo(new Fb(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${yo++}`;this.processChain(new wo(new Rb(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new Hl(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Wa(t,0,this.condition):i=new $(t,0),Wp(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===y.oeb_page_head||t===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new te([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),Ut("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:e,value:t,important:i});e=s.name,t=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new Wa(t,n,this.condition):new $(t,n);qt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Dn(this);break;case"not":i=new Hb(this);break;case"where":i=new Wb(this);break;case"has":i=new Gb(this);break;case"nth-child":t&&t.length>=2&&(i=new of(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new jb(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},$b={"nth-child":xb,"nth-of-type":qa,"nth-last-child":Ya,"nth-last-of-type":Za},yo=0,Dn=class rf extends Nr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,d(this,"parentChain"),d(this,"chains",[]),d(this,"maxSpecificity",0),d(this,"selectorTexts",[]),d(this,"containsPseudoelementSelector",!1),this.parentChain=t.chain}nextSelector(){this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){var t;this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Nb(this.selectorTexts):this.positive()?new Wl(this.chains):new Pb(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new it("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof rf;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Hb=class extends Dn{positive(){return!1}forgiving(){return!1}},Wb=class extends Dn{increasingSpecificity(){return!1}},Gb=class extends Dn{relational(){return!0}},of=class extends Dn{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Yp(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new it("")),this.owner.popHandler()}forgiving(){return!0}},jb=class extends of{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Tb(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new it("")),this.owner.popHandler()}},Xb=class extends Qi{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new Br(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Do=class extends Qi{constructor(e,t,i,n,r,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=o,d(this,"order"),this.order=0}property(e,t,i){i?j.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Gl;let r=this.condition?new Wa(t,n,this.condition):new $(t,n);qt(this.elementStyle,e,r)}},qb=class extends Sd{constructor(e,t){super(e),this.validatorSet=t,d(this,"elementStyle",{}),d(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){j.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){j.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?xd:bd;n+=this.order,this.order+=Gl;let r=new $(t,n);qt(this.elementStyle,e,r)}};function sf(e,t){let i=$p(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Ja(e,t,i){sf(i,n=>{mr(e,n,t)})}function Yb(e,t,i,n){let r=new qb(e,t),o=new vt(n,r);try{Ww(o,r,i)}catch(s){j.warn(s,"Style attribute parse error:")}return r.elementStyle}function af(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.vertical_rl}return i}function lf(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.rtl}return i}function Qa(e,t,i,n,r){let o={};for(let s in e)Hi(s)&&(o[s]=ge(e,s));return Ja(o,t,e),hf(e,i,n,(s,a)=>{mr(o,a,t),Ja(o,t,a)}),o}function hf(e,t,i,n){let r=pt(e,"_regions");if((t||i)&&r){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let s=r[o];s&&n(o,s)}}}function mr(e,t,i){for(let n in t)if(Hi(n)){let r=ge(t,n),o=e[n];e[n]=ja(i,o,r)}}var uf=(e,t,i,n,r,o)=>{var s,a;let h=i?n?tb:Dp:n?ib:zp,l=r?nb:rb;for(let u in e){let c=e[u];if(!c)continue;let p=(s=h[u])!=null?s:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>c.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>c.priority))continue;m=uu[p]?p:uu[f]?f:u}else m=u,u.startsWith("text-align")&&(c.value===y.inside||c.value===y.outside)&&(c=new $(r===(c.value===y.inside)?y.right:y.left,c.priority));t[m]=o(u,c)}},Zb=class cf extends Ki{constructor(t,i,n,r=null){super(),this.elementStyles=t,this.styler=i,this.element=n,this.currentCustomPropertyName=r,d(this,"resolvingCustomProperties",[]),d(this,"varResolutionState",{cycleMembers:new Set}),r&&this.resolvingCustomProperties.push(r)}getRawCustomPropertyLookup(t,i,n){var r,o;let s=n??this.styler.root;if(i!=null&&i.length){for(let a=0;a<i.length;a++){let h=(r=i[a][t])==null?void 0:r.value;if(h){if(h===y.initial)return{found:!0,value:null,elementStyles:i.slice(a),element:n};if(!(h===y.inherit||h===y.unset||h===y.revert))return{found:!0,value:h,elementStyles:i.slice(a),element:n}}}n&&(s=n.parentElement)}for(;s;s=s.parentElement){let a=this.styler.getStyle(s,!1),h=(o=a?.[t])==null?void 0:o.value;if(h){if(h===y.initial)return{found:!0,value:null,elementStyles:a?[a]:[],element:s};if(!(h===y.inherit||h===y.unset||h===y.revert))return{found:!0,value:h,elementStyles:a?[a]:[],element:s}}}return{found:!1,value:null,elementStyles:[],element:null}}collectReferencedCustomProperties(t){let i=new Set;class n extends Xt{visitFunc(o){let s=o.values[0]instanceof ae&&o.values[0].name;return o.name==="var"&&s&&je(s)&&i.add(s),super.visitFunc(o)}}return t.visit(new n),Array.from(i)}findReferencedCycleStart(t,i,n,r=new Set){for(let o of this.collectReferencedCustomProperties(t)){if(this.resolvingCustomProperties.includes(o))return o;if(r.has(o))continue;r.add(o);let s=this.getRawCustomPropertyLookup(o,i,n),a=s.value&&this.findReferencedCycleStart(s.value,s.elementStyles,s.element,r);if(a)return a}return null}getFallbackCycleMembers(t,i,n){let r=null,o=this;class s extends Xt{visitFunc(l){if(l.name==="var")for(let u of l.values.slice(1)){let c=o.findReferencedCycleStart(u,i,n);if(c)return r=c,null}return super.visitFunc(l)}}if(t.visit(new s),!r)return null;let a=this.resolvingCustomProperties.indexOf(r);return new Set(this.resolvingCustomProperties.slice(a))}resolveCustomProperty(t,i,n,r){if(!i)return{found:!1,value:null,continueLookup:!1};if(i===y.initial)return{found:!0,value:null,continueLookup:!1};if(i===y.inherit||i===y.unset||i===y.revert)return{found:!0,value:null,continueLookup:!0};let o=this.getFallbackCycleMembers(i,n,r);return o?(o.forEach(s=>this.varResolutionState.cycleMembers.add(s)),{found:!0,value:null,continueLookup:!1}):{found:!0,value:this.resolveReferencedCustomProperty(t,i,n,r),continueLookup:!1}}resolveReferencedCustomProperty(t,i,n,r){let o=this.resolvingCustomProperties.indexOf(t);if(o>=0)return this.resolvingCustomProperties.slice(o).forEach(c=>this.varResolutionState.cycleMembers.add(c)),null;let s=new Set(this.varResolutionState.cycleMembers);this.varResolutionState.cycleMembers=new Set;let a=new cf(n,this.styler,r,t);a.resolvingCustomProperties=this.resolvingCustomProperties,a.resolvingCustomProperties.push(t),a.varResolutionState=this.varResolutionState;let h=i,l=32;for(let c=0;;c++){if(c>=l){h=null;break}let p=h.visit(a);if(a.error){h=null;break}if(p===h)break;h=p}let u=this.varResolutionState.cycleMembers;return this.varResolutionState.cycleMembers=new Set([...s,...u]),this.resolvingCustomProperties.pop(),u.has(t)?null:h}getVarValue(t){var i,n,r,o;let s=(i=this.element)!=null?i:this.styler.root;if((n=this.elementStyles)!=null&&n.length){for(let a=0;a<this.elementStyles.length;a++){let h=this.elementStyles[a],l=this.resolveCustomProperty(t,(r=h[t])==null?void 0:r.value,this.elementStyles.slice(a),this.element);if(l.found){if(l.value)return l.value;if(!l.continueLookup)return null}}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=this.styler.getStyle(s,!1),h=this.resolveCustomProperty(t,(o=a?.[t])==null?void 0:o.value,a?[a]:[],s);if(h.found){if(h.value)return h.value;if(!h.continueLookup)return null}}return null}visitFunc(t){if(t.name!=="var")return super.visitFunc(t);let i=t.values[0]instanceof ae&&t.values[0].name;return!i||!je(i)?(this.error=!0,Be):this.getVarValue(i)||(this.currentCustomPropertyName&&this.varResolutionState.cycleMembers.has(this.currentCustomPropertyName)?(this.error=!0,Be):t.values.length<2?(this.error=!0,Be):t.values.length===2?t.values[1]:new rt(t.values.slice(1)))}},df=class extends Ki{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=Ti(this.context.rootScope,new vt(i,null),"");if(n instanceof G)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new R(r,"px"):/\d[a-z]/i.test(i)||(t=new Nt(r)))}catch(r){j.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&mc(e.unit)||this.context.rootFontSize!=null&&Kg(e.unit)?new R(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new R(e.num*this.percentRef/100,"px"):e}};function fs(e,t,i,n,r){try{if(t instanceof G)return t.expr instanceof Le&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Xw(e,t.expr,i);if(t instanceof R||t instanceof oi||t instanceof te||t instanceof rt)return t.visit(new df(e,!0,n,r))}catch(o){return j.warn(o),Be}return t}var fu={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function gu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.none;if(t===y.none)return fu;let i=t instanceof te?t.values:[t],n=Object.create(fu);for(let r of i)if(r instanceof ae)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function mu(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Kb={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},wu={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},yu={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function vu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.normal;if(t===y.normal)return wu;if(t===y.auto)return yu;let i=t instanceof te?t.values:[t],n=Object.create(wu);for(let r of i)if(r instanceof ae)switch(r.name){case"trim-both":case"trim-auto":return yu;case"space-all":return Kb;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 sa={ideographAlpha:!1,ideographNumeric:!1},Jb={ideographAlpha:!0,ideographNumeric:!0};function bu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.normal;if(t===y.normal||t===y.auto)return Jb;if(t===y.none)return sa;let i=t instanceof te?t.values:[t],n=Object.create(sa);for(let r of i)if(r instanceof ae)switch(r.name){case"no-autospace":return sa;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function xu(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Su(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 Qb=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let o=r.length-1;for(let s=0;s<o;s++)n.parentNode.insertBefore(document.createTextNode(r[s]),n);n.textContent=r[o]}}}processGeneratedContent(e,t,i,n,r,o){r=Su(r);let s=bu(t),a=vu(i),h=gu(n);if(mu(h)&&xu(s,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),c=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!c,m=!c||/\n$/.test(c.textContent),w=!p||/^\n/.test(p.textContent),S=!p;this.processTextSpacing(f,g||m,g,m,w,S,c,p,s,a,h,r,o),c=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let u=!e||e.fragmentIndex===1&&f(),c=u||g();function p(v){var b;if(v?.nodeType!==1)return!1;let x=v;if(x.hasAttribute(Ln))return!0;let{position:C,float:N}=(b=x.style)!=null?b:{};return C==="absolute"||C==="fixed"||N&&N!=="none"}function f(){let v=t[0];for(let b=v;;b=b.parent)if(!b||!b.inline){if(b?.fragmentIndex!==1)return!1;break}if(!v.inline)return!0;for(let b=v.viewNode.previousSibling;b;b=b.previousSibling)if(!Oe(b,v.whitespace)&&!p(b))return!1;return!0}function g(){var v,b;let x=t[0],C;for(;x&&x.inline&&(C=(v=x.viewNode)==null?void 0:v.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&x.whitespace!==yt.PRESERVE&&(C=C.previousSibling),C)));)x=x.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let N=(b=C.style)==null?void 0:b.display;if(N&&N!=="inline")return!/^(inline|ruby)\b/.test(N)}else if(C.nodeType===Node.TEXT_NODE){if(x.whitespace===yt.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(x.whitespace===yt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let m=-1;for(let v=0;v<t.length;v++){let b=t[v];if(!b.after&&b.inline&&!b.display&&b.parent&&b.viewNode.parentNode&&b.viewNode.nodeType===Node.TEXT_NODE&&!Oe(b.viewNode,b.whitespace)){let x=function(P){var A,B,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((B=P.viewNode)==null?void 0:B.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===yt.PRESERVE){if(/\n$/.test(W.textContent))return!0}else if(P.whitespace===yt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(W.textContent))return!0;if(((z=W.previousElementSibling)==null?void 0:z.localName)==="br")return Oe(W,P.whitespace)}return!1},C=function(P){var A,B,z;if(((A=P.viewNode)==null?void 0:A.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((B=P.viewNode)==null?void 0:B.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===yt.PRESERVE){if(/^\n/.test(W.textContent))return!0}else if(P.whitespace===yt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(W.textContent))return!0;if(((z=W.nextElementSibling)==null?void 0:z.localName)==="br")return Oe(W,P.whitespace)}return!1};var w=x,S=C;m<0&&(m=v);let N=Su((o=(n=(i=b.lang)!=null?i:b.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),F=bu(b.inheritedProps["text-autospace"]),L=vu(b.inheritedProps["text-spacing-trim"]),V=gu(b.inheritedProps["hanging-punctuation"]);if(mu(V)&&xu(F,L)||/\b(flex|grid)\b/.test(b.parent.display))continue;let Y=null,ue=null,he=v===m,k=v===m&&u,_=v===m&&c,E=!1,O=!1;for(let P=v-1;P>=0;P--){let A=t[P];if(x(A)){_=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){Y=A.viewNode;break}if(((s=A.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&ei(A.viewNode)==="footnote-call"){if(A.viewNode.contains(b.viewNode))continue;let B=oy(A.viewNode);if(B){Y=B;break}}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||$i[A.viewNode.localName]))break;P===0&&(he=!0,u&&(k=!0,_=!0))}for(let P=v+1;P<t.length;P++){let A=t[P];if(C(A)){E=!0;break}if(A.viewNode!==b.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){ue=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((h=A.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(A.viewNode.localName==="br"||$i[A.viewNode.localName])){P===t.length-1&&p(A.viewNode)&&(O=!0);break}if(P===t.length-1){E=!0,O=!0;for(let B=A.viewNode.nextSibling;B;B=B.nextSibling)if(!p(B)){O=!1;break}}}if(((l=b.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=b.parent.viewNode.firstChild;for(;Oe(P,b.whitespace);)P=P.nextSibling;b.viewNode===P&&(k=!0)}if(!O){let P=b.parent.viewNode.lastChild;for(;Oe(P,b.whitespace);)P=P.previousSibling;b.viewNode===P&&(O=!0)}}if(this.processTextSpacing(b.viewNode,he,k,_,E,O,Y,ue,F,L,V,N,b.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,u,c,p){let f=e.textContent,g=e.ownerDocument,m=0,w,S,v;function b(){if(t)return!0;if(!s)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;S||(S=g.createRange(),S.selectNode(s));let O=S.getClientRects(),P=O[O.length-1];return P?(m||(m=Cr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function x(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;m||(m=Cr(E,p)),v||(v=g.createRange(),v.selectNode(a));let O=v.getClientRects()[0];return O?p?E.top+E.height>O.top+E.width||E.left>O.left+O.width-E.width/10||E.left+E.width<O.left+E.width/10:E.left+E.width>O.left+E.height||E.top+E.height<O.top+E.height/10||E.top>O.top+O.height-E.height/10:!1}let C=!1,N=!1,F=!1,L=!1,V;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(V="viv-ts-open",C=!0,N=!0):o&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(V="viv-ts-close",C=!0,F=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(V="viv-ts-close",C=!0,L=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(V="viv-ts-open",C=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||c==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||c!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(V="viv-ts-close",C=!0),C){let E=function(z){let W=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>W},O=function(){return p?P.offsetLeft:P.offsetTop};var Y=E,ue=O;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(V),A=g.createElement("viv-ts-inner");P.appendChild(A),e.parentNode.insertBefore(P,e),A.appendChild(e);let B=E(A);if(B||N||F||L){if(V==="viv-ts-open"){if(N)P.className="viv-hang-first";else if(i||n)l.trimStart?P.className="viv-ts-trim":P.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&b())P.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||s.parentElement.localName==="viv-ts-inner"&&E(s.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&b()){let z=O();P.className="viv-ts-auto",z===O()&&!b()&&(P.className="viv-ts-trim")}}else if(V==="viv-ts-close"){if(F)P.className=B?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let z=O();L?(P.className=B?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===O()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",z===O()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",z===O()&&(P.className="")):P.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))B&&l.trimAdjacent&&(P.className="viv-ts-trim");else if(L){let z=x(),W=z&&u.allowEnd;W||(P.className=B?"viv-hang-end":"viv-hang-end viv-hang-hw"),B?W&&l.trimEnd?P.className="viv-ts-auto":!W&&!x()?P.className="":!z&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",x()||(P.className="viv-hang-end")):(P.className="viv-ts-space",x()||(l.allowEnd?(P.className="viv-ts-auto",x()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!z&&!x()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(x())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let z=O();P.className="viv-ts-auto",z===O()&&(P.className="")}}}}let he=!1;function k(E){var O;let P=(O=E?.ownerDocument.defaultView)==null?void 0:O.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function _(E,O){if(E.nodeType===Node.ELEMENT_NODE){let B=g.defaultView.getComputedStyle(E);if(parseFloat(B.marginInlineEnd)||parseFloat(B.borderInlineEndWidth)||parseFloat(B.paddingInlineEnd))return!0}let P=E.parentElement;if(P&&!P.contains(O))return _(P,O);if(O.nodeType===Node.ELEMENT_NODE){let B=g.defaultView.getComputedStyle(O);if(parseFloat(B.marginInlineStart)||parseFloat(B.borderInlineStartWidth)||parseFloat(B.paddingInlineStart))return!0}let A=O.parentElement;return A&&!A.contains(E)?_(E,A):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&k(s.parentElement))&&!_(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),he=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&k(a.parentElement))&&!_(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),he=!0)),m}registerHooks(){Ot("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Ot("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Ot("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},jl=new Qb;jl.registerHooks();function e0(e){jl.preprocessForTextSpacing(e)}function t0(e,t,i,n,r,o){jl.processGeneratedContent(e,t,i,n,r,o)}var sr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),i0=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],Xl="data-adapt-pseudo";function ei(e){return e.getAttribute(Xl)||""}function wr(e,t){e.setAttribute(Xl,t)}var aa=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,d(this,"contentProcessed",{})}getStyle(e,t){let i=ei(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=pt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new $(new lt(o),0)}return r}processContent(e,t,i){let n=ei(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;Tt(r)&&(r.visit(new kr(e,this.context,r,this.exprContentListener)),e0(e))}}},US=Jo.isInstanceOfAfterIfContinuesLayoutConstraint,n0=Os.registerFragmentIndex,$S=Os.clearFragmentIndices,r0=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new ql(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return I(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=sr.createElementNS("http://www.w3.org/1999/xhtml","div");wr(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 Ai(i)}createShadowContext(e){return new Eo(this.sourceNode,e,null,null,null,gi.ShadowType.ROOTED,this.styler)}},o0=class pf{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,d(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new s0(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof pf?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},s0=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 ff(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return T(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=l0(e,t,n);return t.fragmentLayoutConstraints.push(new o0(e,i,r)),T(e)})}function gf(e,t){return e.thenAsync(i=>ff(i,t))}function a0(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=ff(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function l0(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Ta(i,t,e.vertical);return n.removeChild(i),r}var h0=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},ar=class extends Al{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,d(this,"alreadyEvaluated",!1),d(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},gs=class extends Zd{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,d(this,"last"),d(this,"viewDocument"),d(this,"flowRootFormattingContext",null),d(this,"isNonFirstColumn",!1),d(this,"isFloat",!1),d(this,"isFootnote",!1),d(this,"startEdge",0),d(this,"endEdge",0),d(this,"beforeEdge",0),d(this,"afterEdge",0),d(this,"footnoteEdge",0),d(this,"box",null),d(this,"chunkPositions",null),d(this,"bands",null),d(this,"overflown",!1),d(this,"breakPositions",null),d(this,"pageBreakType",null),d(this,"forceNonfitting",!0),d(this,"leftFloatEdge",0),d(this,"rightFloatEdge",0),d(this,"bottommostFloatTop",0),d(this,"stopAtOverflow",!0),d(this,"lastAfterPosition",null),d(this,"fragmentLayoutConstraints",[]),d(this,"pseudoParent",null),d(this,"nodeContextOverflowingDueToRepetitiveElements",null),d(this,"blockDistanceToBlockEndFloats",NaN),d(this,"lastLineStride",0),d(this,"breakAtTheEdgeBeforeFloat",null),Qw(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=this.clientLayout.pixelRatio===0?.5:1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}getFloatLayoutUnit(){return this.clientLayout.pixelRatio===0?0:1/(this.clientLayout.pixelRatio||1)}getFloatLayoutTolerance(e){return e||1}isOverflown(e){let t=1.5/(this.clientLayout.pixelRatio||1);return this.almostEquals(e,this.footnoteEdge,t)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=D("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let o=r,s=i[n];if(r=es(s,o),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return T(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?my(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,o=r.match($o),s=o?o[0].length:0;if(!o&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match($o);if(h){let l=h[0];s=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(s)}}return this.layoutContext.peelOff(e,s)}return T(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=D("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!vn(e)&&((o=e.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let s=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(s);if(Cr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,vn(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(Pi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return gf(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=D("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!vn(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(o=>{let s=o;if(s!==e){let a=s;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=s,r.breakLoop();return}vn(s)||t.push(s.copy())}this.nextInTree(s).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Pi(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null,a=1.5/(this.clientLayout.pixelRatio||1);for(let p of t){let f=Math.abs(p.x1-i)<a&&Math.abs(p.x2-n)<a?a:void 0;this.almostEquals(p.x1,i,f)?p.x1=i:this.almostEquals(p.x1,n,f)&&(p.x1=n),this.almostEquals(p.x2,n,f)?p.x2=n:this.almostEquals(p.x2,i,f)&&(p.x2=i),this.almostEquals(p.y1,r,f)?p.y1=r:this.almostEquals(p.y1,o,f)&&(p.y1=o),this.almostEquals(p.y2,o,f)?p.y2=o:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=cl==="webkit"?Math.floor:Math.round,u=t.map(p=>h>0?(l(p.y2/h)-l(p.y1/h))*h:p.y2-p.y1),c=.01;for(let p=0;p<t.length;p++){let f=p<t.length-1?t[p+1].x1:i,g=p<t.length-1?t[p+1].x2:n,m=f-t[p].x1,w=t[p].x2-g,S=0,v=0;m>c?S=1:m<-c&&(S=-1),w>c?v=1:w<-c&&(v=-1);let b=S!==0&&v!==0?S===v?S:0:S||v;if(h>0&&b!==0){let x=b*h;u[p]+x>=0&&(p>=t.length-1||u[p+1]-x>=0)&&(u[p]+=x,p<t.length-1&&(u[p+1]-=x))}}for(let p=0;p<t.length;p++){let f=t[p];f.left=this.createFloat(e,"left",f.x1-i,u[p]),f.right=this.createFloat(e,"right",n-f.x2,u[p]),f.x1<n&&f.x2>i?s=f:s||I(f.right,"float","none")}if(s){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(s!==p&&(p.y2>=o||this.almostEquals(p.y2,o,f))&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let g=t.indexOf(s);g<t.length;g++){let m=t[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),n=1.5/(this.clientLayout.pixelRatio||1);if(i>0&&i<t&&!this.almostEquals(i,t,n)){let r=this.vertical?"width":"height";if(I(this.element,r,`${i}px`),this.vertical){let o=this.left+(t-i);I(this.element,"left",`${o}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&yn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=pn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=pn(e,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(o=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new Xs(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new Xs(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new Xs(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=D("layoutFloat"),i=e.viewNode,n=Js(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Rt(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new Lt(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let x=u.viewNode.ownerDocument.createElement("div");x.style.left="0px",x.style.top="0px",this.vertical?(x.style.bottom="0px",x.style.width="1px"):(x.style.right="0px",x.style.height="1px"),u.viewNode.appendChild(x);let C=Rt(this.clientLayout,x,this.vertical);h=Math.max(this.rtl?this.getEndEdge(C):this.getStartEdge(C),h),l=Math.min(this.rtl?this.getStartEdge(C):this.getEndEdge(C),l),u.viewNode.removeChild(x);let N=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+N):h=Math.min(h,l-N),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let c=new Lt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=Xo(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let x=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+x}if(e.clearSide){let x=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?Js(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;x!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),x!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let N=C*f;if(p.y1<N){let F=p.y2-p.y1;p.y1=N,p.y2=p.y1+F}}c.y2+=this.getFloatLayoutUnit(),Em(c,this.bands,p,n),this.vertical&&(a=jc(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let x=w.viewNode.ownerDocument.createElement("div");x.style.position="absolute",w.vertical?x.style.right="0":x.style.left="0",x.style.top="0",w.viewNode.appendChild(x),m=Rt(this.clientLayout,x,this.vertical),w.viewNode.removeChild(x)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let x=Math.max(0,m.right-a.x2);I(i,"right",`${x}px`)}else{let x=Math.max(0,a.x1-m.left);I(i,"left",`${x}px`)}let S=Math.max(0,a.y1-m.top);I(i,"top",`${S}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let v=this.vertical?a.x1:a.y2,b=this.vertical?a.x2:a.y1;!this.isOverflown(v)||this.breakPositions.length==0?(this.killFloats(),c=new Lt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(c=Xo(c)),Pm(c,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=v:this.rightFloatEdge=v,this.bottommostFloatTop=b,this.updateMaxReachedAfterEdge(v),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!s.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!s.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!s.hasFloatFragments(),o);if(u){if(e.isFootnote){let c=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(c.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,I(e.element,"width",`${p}px`))}else{let p=parseFloat(c.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,I(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return T(u)})}createPageFloatArea(e,t,i,n,r){let o=this.element.ownerDocument.createElement("div");I(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new gn(null,Ie.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new d0(t,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>T(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,o,s){let a=this.pageFloatLayoutContext;e=(s?s.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},c=D("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(u.floatArea=p,!p){c.finish(u);return}let f=!1,g=0;c.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],S=new Ai(w.nodePosition),v=p.breakPositions?p.breakPositions.length:0;p.layout(S,!0).then(b=>{if(u.newPosition=b,!b||n){if(b&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.length>v&&p.breakPositions.slice(v).some(x=>x instanceof ar))){f=!0,m.breakLoop();return}g++,m.continueLoop()}else f=!0,m.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&u.newPosition){let m=a.getPageFloatLayoutContext(h.floatReference);if(m.footnoteMaxBlockSize==null){if(m.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,o,s).then(w=>{c.finish(w)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,o,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}c.finish(u)})}),c.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,o=e.float,s=new Set;for(let u=r;u;u=u.effectiveParent)for(let c of u.floatFragments)c.continuations.some(p=>p.float.insidePageFloatArea)&&s.add(c);r.stashEndFloatFragments(o);function a(u,c){c?r.removePageFloatFragment(c,!0):u&&u.element.parentNode.removeChild(u.element);let p=[];for(let f=r;f;f=f.effectiveParent)for(let g of f.floatFragments)!s.has(g)&&g.continuations.some(m=>m.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(e)}let h=o instanceof is,l=D("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let c=u.floatArea,p=u.pageFloatFragment,f=u.newPosition;p?this.layoutStashedPageFloats(o.floatReference,[n]).then(g=>{if(g){let m=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,m),r.discardStashedFragments(o.floatReference),f){let w=new Zh(o,f.primary);r.deferPageFloat(w)}l.finish(!0)}else a(c,p),l.finish(!1)}):(a(c,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=D("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let c=new Bn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,c,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!s)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&ei(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(Ln,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=D("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Ie.REGION);return r.getContainer().width<o.getContainer().width&&e===Ie.COLUMN?t===y.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=Pl(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Ie.REGION):n.finish(e)}):t===y.all?n.finish(Ie.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Bn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=Qo(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new Zh(o,s);if(h&&h.hasFloat(o))return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(t.isForbidden(o)||t.hasPrecedingFloatsDeferredToNext(o))return t.deferPageFloat(l),t.registerPageFloatAnchor(o,a.viewNode),T(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let u=p=>{if(!p||p.nodeType!==1)return NaN;let f=Rt(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},c=pn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=o;if(p.footnotePolicy===y.line||isNaN(c)){let f=a;for(;f;){if((f.shadowContext?f.shadowContext.owner:f.sourceNode)===p.policyAnchorNode){let g=u(f.viewNode);isNaN(g)||(c=g);break}f=f.parent}}}return isNaN(c)&&e.floatSide==="footnote"&&(c=u(a.viewNode)),this.isOverflown(c)?T(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?e.floatSide==="footnote"||t.generatingNodePosition?T(a):T(null):(t.registerPageFloatAnchor(o,a.viewNode),T(a)))}})}processLineStyling(e,t,i){let n=D("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=e.firstPseudo;return s?.count===0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(u,0).then(c=>{e=c,s=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&$i[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?t=Math.max(t,s):i=Math.min(i,s)}return t+i}layoutBreakableBlock(e){let t=D("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??e),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!yn(n.viewNode)){let l=Nn(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=T(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Ut("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,o=t[0].boxOffset,s=r,a=t.length-1,h=t[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let u=a;for(;s<u;){let p=s+Math.ceil((u-s)/2);t[p].boxOffset>l?u=p-1:s=p}let c=this.calculateEdge(null,t,s,l);if(this.vertical?c<=n:c>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(c),o=l,r=s}return{nodeContext:t[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(e,t,i){var n,r,o;let s=this.findEndOfLine(t,e,!0),a=s.nodeContext;if(s.checkPointIndex===0&&s.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,s.index,e,s.checkPointIndex,i)}else{let l=jh(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof ar&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(o=a.viewNode)==null?void 0:o.previousSibling;for(;u&&(Oe(u,a.parent.whitespace)||Ft(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Ut("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,ms.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,o=e,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;o==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let c=o.nodeType===1?o:null;c?r?r=!1:El(c)?l=!a:!c.firstChild||$i[c.localName]||/^r(uby|[bt]c?)$/.test(c.localName)||ry(this.clientLayout.getElementComputedStyle(c).display)?(l=!a,l?(c.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(c.localName)||(s=o),o.contains(t)&&(h=!1)):u=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),u||(u=o.nextSibling,u||(r=!0,u=o.parentNode)),o=u}while(l&&h);if(a){n.setEndAfter(s);let u=this.clientLayout.getRangeClientRects(n);Pa(u,this.vertical);for(let c=0;c<u.length;c++)i.push(u[c]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Ey:ky);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(s>0){let c=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/c:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/c:u=1}if(s==0||u>=.6||u>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(t.push(r),s=0),a>=i.length)break}return t.sort(cc),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&bn(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=Nn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let s,a;t&&!this.isFootnote?(s=1,a=1):(s=Math.max((o.inheritedProps.widows||2)-0,1),a=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),l=this.findLinePositions(r),u=this.footnoteEdge-h,c=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=c*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=c*(1/0));let g=fi(l.length,v=>{let b=l[v];return this.vertical?b<u||b<=f.edge:b>u||b>=f.edge}),m=g<=0;m&&(g=fi(l.length,v=>this.vertical?l[v]<u:l[v]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(s=0,a=1),g=Math.min(l.length-s,g),g<a)return null;u=l[g-1];let S;if(m?S=f.checkPoint:S=this.findAcceptableBreakInside(e.checkPoints,u,t),S){let v=this.getAfterEdgeOfBlockContainer(S);if(!isNaN(v)&&c*(u-v)>0&&(u=v),this.computedBlockSize=c*(u-this.beforeEdge)+p,l.length>=2){let b=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[b]-l[b-1])}}return S}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,pn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Yn().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Rl.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let o=e.getMinBreakPenalty();o>i&&(n=Math.min(n,o))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return T(e);let r=D("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return j.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();e=i,o=!0,this.computedBlockSize=n}return this.finishBreak(e,o,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Ft(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!Zo(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||bn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");xt(n,"block-end"),t.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let s=e;s;s=s.parent)if(Ft(s.viewNode))return!1;if(yn(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=pn(e,this.clientLayout,0,this.vertical);i();let r=Nn(e,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let s=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||yn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Ie.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=Rt(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),o=this.getBoxDir(),s=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(s)?Js(s,e.vertical,e.direction,this.layoutContext.page.side):s,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=o*Math.max(l*o,this.leftFloatEdge*o);break;case"right":l=o*Math.max(l*o,this.rightFloatEdge*o);break;default:l=o*Math.max(l*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let c=this.getFloatLayoutUnit(),p=this.leftFloatEdge*o>this.beforeEdge*o||this.rightFloatEdge*o>this.beforeEdge*o;if(c>0&&p){let g=l*o>u*o;l=o*(Math.ceil(l*o/c)+(g?1:0))*c}let f=this.getFloatLayoutTolerance(c);if(r*o+f>l*o)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*o);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=Rt(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Gy(e)||Wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(Gh(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return T(e);let o=D("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],c=[],p=!1;function f(C){var N,F;if(!(!t||s.isNonFirstColumn||i||!Xh(h))){for(let L=C;L;L=L.parent)if(L.breakBefore==="column"&&(L.breakBefore=null),((N=L.viewNode)==null?void 0:N.nodeType)===1){let V=L.viewNode;((F=V.style)==null?void 0:F.breakBefore)==="column"&&(V.style.breakBefore="")}}}function g(C){var N,F;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let L=C;L;L=L.parent)if(L.breakBefore==="column"&&(L.breakBefore=null),((N=L.viewNode)==null?void 0:N.nodeType)===1){let V=L.viewNode;((F=V.style)==null?void 0:F.breakBefore)==="column"&&(V.style.breakBefore="")}h=null}}function m(C){var N,F;if(!(i||!Xh(h))){for(let L=C;L;L=L.parent)if(L.breakAfter==="column"&&(L.breakAfter=null),((N=L.viewNode)==null?void 0:N.nodeType)===1){let V=L.viewNode;((F=V.style)==null?void 0:F.breakAfter)==="column"&&(V.style.breakAfter="")}}}function w(C){h=nt(h,C)}function S(){return i?!0:Ye(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!v()&&!b():!1}function v(){var C;if(!l||!e||e.floatSide)return!1;for(let N=l;N!=null&&N.parent;N=N.parent){if(N.parent.viewNode&&Ft(N.parent.viewNode))continue;let F=N.after?N.viewNode:(C=N.viewNode)==null?void 0:C.previousSibling;for(;F&&(Oe(F,N.parent.whitespace)||Ft(F));)F=F.previousSibling;if(F)return!1}return!0}function b(){var C,N;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Ft(e.parent.viewNode))return!1;let F=!1;for(let L=e;L!=null&&L.parent&&!L.after;L=L.parent){if(L!==e&&Ft(L.viewNode))return!1;let V=(N=L.viewNode)==null?void 0:N.previousSibling;for(;V&&(Oe(V,L.parent.whitespace)||Ft(V));)Ft(V)&&(F=!0),V=V.previousSibling;if(V)return!1}return F}let x=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var N;e;){e.formattingContext;let F=new Yn().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Oe(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){S()?x():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ko(h)?h:null),F&&F.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?jh(l):this.breakPositions[this.breakPositions.length-1]instanceof ar||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||Wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Oe(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),S()?x():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let V=e.viewNode,Y=V.style;if(e.after){Ad(V,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let ue=e.sourceNode;if(ue.localName==="svg"||ue.localName==="math"||ue.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),c.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||F&&F.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(Gh(e.viewNode))break;if(S()){x(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,Rd(e.viewNode)||(l=e.copy(),c.push(l)),w(e.breakAfter),m(e),Y&&!Ft(e.viewNode)&&this.hasNonZeroBlockEndInset(Y)&&(c=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Ye(h)&&ey(l.viewNode,e.viewNode),(e.pageType!=((N=e.parent)==null?void 0:N.pageType)||!Ye(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let ue=e.viewNode.localName;if($i[ue]){S()?x():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}Y&&this.hasNonZeroBlockStartInset(Y)&&(a=!1,c=[]),p=!0}}while(!1);let L=this.nextInTree(e,a);if(L.isPending()){L.then(V=>{e=V,C.continueLoop()});return}else e=L.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,c,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Ye(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=D("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Oe(e.viewNode,e.whitespace))break;if(!e.after){Ye(n)&&(this.pageBreakType=n),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=nt(n,e.breakBefore),Ye(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ye(n)){this.pageBreakType=n,o.breakLoop();return}n=null}r=!1,n=nt(n,e.breakAfter)}else{n=nt(n,e.breakBefore);let h=e.viewNode.localName;if($i[h]){Ye(n)&&(this.pageBreakType=n),o.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){o.breakLoop();return}}r=!0}while(!1);let s=this.layoutContext.nextInTree(e);if(s.isPending()){s.then(a=>{e=a,o.continueLoop()});return}else e=s.get()}t=null,o.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Pi(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Ie.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=D("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let o=e.formattingContext;new Yn().find(o).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Yn().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new Lt(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Sm(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Yn().find(e.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new ar(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);kl(this);let n=D("layout");return this.openAllViews(e.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new u0(t,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=T(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(Zo(this)&&(ny(this),Is(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new Ai(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=D("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=D("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;e;){let s=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let s=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=s}this.killFloats(),this.init();let i=D("redoLayout"),n=0,r=null,o=!0;return i.loopWithFrame(s=>{if(n<e.length){let a=e[n++];this.layout(a,o).then(h=>{o=!1,h?(r=h,s.breakLoop()):s.continueLoop()});return}s.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Jo.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Ii.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},ql=class{constructor(e,t,i){d(this,"startNodeContexts",[]),d(this,"column"),d(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(o){return gs.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),T(s)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Hr(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return Yi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let o=r.data.slice(e.offsetInNode);if(!Hd(o,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Oe(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},ms=class{breakTextNode(e,t,i,n,r,o){if(t.after)t.offsetInNode=e.length;else{let s=i-t.boxOffset,a=e.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(e,a,s,t):s=this.breakAfterOtherCharacter(e,a,s,t),s>0&&(t=this.updateNodeContext(t,s,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+Cu(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&mh(r)&&mh(o)?Cu(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};d(ms,"instance");ms.instance=new ms;function Cu(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var u0=class extends Ll{constructor(e,t){super(),this.leadingEdge=e,d(this,"breakAfter"),d(this,"initialPageBreakType",null),d(this,"initialComputedBlockSize",0),d(this,"initialOverflown",!1),d(this,"initialLastLineStride",0),d(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new c0(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Xy()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Fd(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},c0=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return a0(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},d0=class extends gs{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),this.floatSide=e,this.parentContainer=s,d(this,"rootViewNodes",[]),d(this,"floatMargins",[]),d(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),T(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(o,s){o.forEach(a=>{let h=bi(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=s*l/100;I(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(o=>{bi(e,o)==="auto"&&I(e,o,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=bi(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=bi(t,"width");n!==""&&n!=="auto"&&I(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Rt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,c,p;let f=(l=h.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(h);if((f?.getPropertyValue("--viv-footnote-display").trim()||"")==="compact")return!(f?.display==="list-item"&&f.getPropertyValue("list-style-position").trim()==="outside");let g=h.getAttribute(Qt);if(!g||!t||!i)return!1;let m=i.getNodeByOffset(parseInt(g,10));if(!m||m.nodeType!==Node.ELEMENT_NODE)return!1;let w=t.getStyle(m,!1),S=(c=(u=ge(w,"footnote-display"))==null?void 0:u.value)==null?void 0:c.toString(),v=!!((p=ge(w,"--viv-marker-content"))!=null&&p.value);return S==="compact"&&!v});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>o+s&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=Rt(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(t=>ei(t)==="after")}hasAuthorFootnoteAfterPseudo(e){let t=this.getFootnoteAfterPseudo(e);if(t&&!t.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let i=Array.from(e.children).find(r=>r instanceof Element&&kt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");wr(t,"after"),t.setAttribute("data-vivliostyle-default-footnote-separator","1"),t.style.whiteSpace="normal",t.textContent=" ",e.appendChild(t)}getFootnoteBreakOpportunity(e){let t=e.nextElementSibling;return t!=null&&t.hasAttribute("data-vivliostyle-footnote-break")?t:null}createFootnoteBreakOpportunity(e){let t=e.ownerDocument.createElement("wbr");t.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",t)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[t+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),u=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),c=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!c?this.createFootnoteBreakOpportunity(r):p&&c?.remove()}else u&&h.remove(),c?.remove()})}},Zi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,d(this,"formattingContextType","RepetitiveElementsOwner"),d(this,"isRoot",!1),d(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||Oa.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new p0(e,this.rootSourceNode),Oa.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},p0=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,d(this,"headerSourceNode",null),d(this,"footerSourceNode",null),d(this,"headerViewNode",null),d(this,"footerViewNode",null),d(this,"headerNodePosition",null),d(this,"footerNodePosition",null),d(this,"headerHeight",0),d(this,"footerHeight",0),d(this,"isSkipHeader",!1),d(this,"isSkipFooter",!1),d(this,"enableSkippingFooter",!0),d(this,"enableSkippingHeader",!0),d(this,"doneInitialLayout",!1),d(this,"firstContentSourceNode",null),d(this,"lastContentSourceNode",null),d(this,"affectedNodeCache",[]),d(this,"afterLastContentNodeCache",[]),d(this,"allowInsert",!1),d(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Qo(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Qo(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Ta(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Ta(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,o=t.viewNode,s=r.createElement("div");o.appendChild(s);let a=new ql(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Ai(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(s),this.moveChildren(s,o,i),a.getColumn().pageBreakType=h,T(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Ln,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},mf=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},wf=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},f0=class extends mf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},g0=class extends wf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Yl(e)),this.processor.doLayout(e,t)}},Yl=class yf{constructor(t){d(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),d(this,"nodeContext");let i=ui(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||yn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!bf(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let o=this.getRepetitiveElements();o&&t&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=ui(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return b0(n,o,i).thenAsync(()=>x0(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ui(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof yf?ui(this.nodeContext.formattingContext)===ui(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},m0=class extends Ll{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 f0(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new g0(this.formattingContext,this.processor))}},w0=class extends dr{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),T(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),T(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return dr.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?T(!0):dr.prototype.afterNonInlineElementNode.call(this,e)}},y0=class extends xn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=ui(e.formattingContext);return n.getRootViewNode(e)?(i&&vf(e.parent,t),e.belongsTo(n)?xn.prototype.layout.call(this,e,t,i):new m0(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=S0(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=ui(e.formattingContext),n=D("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=ui(e.formattingContext),n=new w0(i,t);return new La(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ui(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return gf(r,t).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(t.layoutNext(s,!1).then(l=>{s=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||s&&t.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(e,t,i,n){return xn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){xn.prototype.clearOverflownViewNodes(e,t,i,n)}};function v0(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Zi&&!i.belongsTo(n)&&t(n,i)}}function vf(e,t){e&&v0(e.after?e.parent:e,(i,n)=>{Ii.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Yl(n))})}function b0(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let o=r.viewNode.firstChild;return n.appendHeaderToFragment(r,o,i)}}return T(!0)}function x0(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return T(!0)}function bf(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function S0(e){let t=e.formattingContext;return!t||!(t instanceof Zi)?null:t}function ui(e){return e instanceof Zi,e}var C0=new y0;Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Zi&&!Ii.isInstanceOfTableFormattingContext(e)?C0:null);var xf=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,d(this,"cells",[]),d(this,"breakBefore",null),d(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},k0=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,d(this,"viewElement"),d(this,"colSpan"),d(this,"rowSpan"),d(this,"height",0),d(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},E0=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},P0=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,d(this,"pseudoColumn"),d(this,"empty",!1),this.pseudoColumn=new ql(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},N0=class{constructor(e,t){this.viewNode=e,this.side=t}},T0=class extends Hr{constructor(e,t,i,n){super(e,t,i,n),d(this,"formattingContext"),d(this,"acceptableCellBreakPositions",null),d(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},I0=class extends Al{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,d(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(o=>!!o.nodeContext)&&n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof ar&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof Hr&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},In=class extends Zi{constructor(e,t){super(e,t),this.tableSourceNode=t,d(this,"formattingContextType","Table"),d(this,"vertical",!1),d(this,"columnCount",-1),d(this,"tableWidth",0),d(this,"captions",[]),d(this,"colGroups",null),d(this,"colWidths",null),d(this,"inlineBorderSpacing",0),d(this,"rows",[]),d(this,"slots",[]),d(this,"cellFragments",[]),d(this,"lastRowViewNode",null),d(this,"cellBreakPositions",[]),d(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){var i;if(!t)return t;switch(e.display){case"table-row":{let n=this.findRowIndexBySourceNode(e.sourceNode);return this.cellBreakPositions.every(r=>this.isPreviousFragmentRowSpanningCellBreakPosition(r,n))&&e.fragmentIndex<=1}case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new xf(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),o=0;for(;r[o];)o++;for(;e<n;e++){r=this.getRowSlots(e);for(let s=o;s<o+t.colSpan;s++){let a=r[s]=new E0(e,s,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}isPreviousFragmentRowSpanningCellBreakPosition(e,t){let i=e.cell;return t>=0&&i.rowIndex<t&&i.rowIndex+i.rowSpan>t}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Rt(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let o=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!o||t.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),t.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new A0(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}Ii.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},A0=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=Nn(e,n);i=Math.max(i,t(r))}),i}};function _t(e){return e instanceof In,e}function F0(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function R0(e){return e==="table"||e==="inline-table"}function ku(e){return F0(e)||R0(e)}function Sf(e,t,i){let n=e.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof In)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof In){s=a.formattingContext===t;break}}return s||r==="table-row"&&!ku(o)||r==="table-cell"&&o!=="table-row"&&!ku(o)||n.formattingContext instanceof In&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function Cf(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Pi(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var L0=class extends dr{constructor(e,t){super(),this.formattingContext=e,this.column=t,d(this,"rowIndex",-1),d(this,"columnIndex",0),d(this,"inRow",!1),d(this,"checkPoints",[]),d(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=Sf(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Cf(this.column,e);if(n)return n;let r=e.nodeContext,o=r.display,s=t.getRepetitiveElements();switch(o){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new N0(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new xf(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(o[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let o=t.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=nt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;t.addCell(this.rowIndex,new k0(this.rowIndex,this.columnIndex,o)),this.columnIndex++,Nf(o);let s=t.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=nt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=nt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!vn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},kf=class Ef extends dr{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,d(this,"inRow",!1),d(this,"currentRowIndex",-1),d(this,"currentColumnIndex",0),d(this,"originalStopAtOverflow"),d(this,"inHeader"),d(this,"inFooter"),d(this,"didExtractRowSpanningCellBreakPositions",!1),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return Cf(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,o=t.columnIndex,s=t.colSpan,a=i.viewNode;s>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new P0(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(Nf(a),T(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorSlot.columnIndex===t&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,o=r.rowIndex;if(o<this.currentRowIndex&&o+r.rowSpan>this.currentRowIndex){let s=i[o];s||(s=i[o]=[]),s.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(c=>c+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=D("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,u=[];return n.forEach(c=>{h=h.thenAsync(()=>{let p=es(c[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let f=T(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let S=p.viewNode.ownerDocument.createElement("td");I(S,"padding","0"),p.viewNode.appendChild(S)}g++}}return c.forEach(w=>{f=f.thenAsync(()=>{let S=w.cell;m(S.anchorSlot.columnIndex);let v=w.cellNodePosition,b=es(v.steps[0],p);return b.offsetInNode=v.offsetInNode,b.after=v.after,b.fragmentIndex=v.steps[0].fragmentIndex+1,o.setCurrent(b,!1).thenAsync(()=>{let x=w.breakChunkPosition;for(let C=0;C<S.colSpan;C++)u.push(g+C);return g+=S.colSpan,this.layoutCell(S,b,x).thenAsync(()=>(b.viewNode.rowSpan=S.rowIndex+S.rowSpan-this.currentRowIndex+r-l,T(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,T(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=nt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=nt(o,s.breakBefore)),!t.leadingEdge&&Ye(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),t.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),T(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);n0(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,T(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let o=D("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=T(h.breakChunkPosition)}else s=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=Qo(h,0);return T(new Ai(l))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=Sf(t,_t(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):T(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new I0(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group")),r&&Ef.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else if(r==="table-row"&&!this.inHeader&&!this.inFooter){let o=super.afterNonInlineElementNode(t);return(o&&o.isPending()?o:T(!0)).thenAsync(()=>{if(!t.break){let s=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!s&&h&&!!(a!=null&&a.isFooterRegistered());(s||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return T(!0)})}else return super.afterNonInlineElementNode(t);return T(!0)}};d(kf,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var O0=kf,Tr=[];function B0(e){let t=Tr.findIndex(n=>n.root===e),i=Tr[t];return i?i.tableLayoutOption:null}function M0(e){let t=Tr.findIndex(i=>i.root===e);t>=0&&Tr.splice(t,1)}var Pf=class{layoutEntireTable(e,t){let i=_t(e.formattingContext),n=new L0(i,t);return new La(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<t;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=s.map(h=>{let l=Rt(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(o),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),t.push(s)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let o=e.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),e.push(s)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=e.getColumnCount();if(!(s>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,t),l.forEach((u,c)=>{I(u,n?"height":"width",`${a[c]}px`)}),h.forEach(u=>{o.appendChild(u.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=_t(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=B0(e.sourceNode);M0(e.sourceNode);let r=D("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{var a;let h=s.viewNode,l=i.rows[0];if(l&&Ye(l.breakBefore)&&this.hasInFlowContentBefore(h,t)){(a=h.parentNode)==null||a.removeChild(h),t.pageBreakType=l.breakBefore,r.finish(o);return}let u=Rt(t.clientLayout,h,t.vertical),c=t.vertical?u.left:u.bottom;if(c+=(t.vertical?-1:1)*Nn(e,t.collectElementsOffset()).current,!t.isOverflown(c)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new V0(o)),r.finish(s);return}this.normalizeColGroups(i,h,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&Ye(i.breakBefore)||t<e.rows.length-1&&Ye(i.breakAfter)))return!0}return!1}hasInFlowContentBefore(e,t){let i=e;for(;i&&i!==t.element;){let n=i.previousSibling;for(;n;){if(n.nodeType===1&&!Ft(n)||n.nodeType===3&&!Oe(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,o)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),I(t,"table-layout","fixed"),I(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=_t(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new O0(i,t),s=new La(o,t.layoutContext),a=D("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=_t(e.formattingContext);if(n.getRootViewNode(e)){if(i){let r=n.getRepetitiveElements();r&&e.sourceNode!==n.tableSourceNode&&!e.after&&!r.isFooterRegistered()&&r.preventSkippingHeader(),vf(e.parent,t)}return new D0(n,this).layout(e,t)}else return t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new T0(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return la(e),!1}finishBreak(e,t,i,n){let r=_t(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=r.findRowIndexBySourceNode(t.sourceNode),s;if(t.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=D("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let u=s[h++],c=r.getCellFragmentOfCell(u),p=c.findAcceptableBreakPosition().nodeContext,f=c.cellNodeContext,g=f.toNodePosition(),m=new Ai(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;c.column.layoutContext.processFragmentedBlockEdge(c.cellNodeContext),o<u.rowIndex+u.rowSpan-1&&(w.rowSpan=o-u.rowIndex+1),c.empty?l.continueLoop():c.pseudoColumn.finishBreak(p,!1,!0).then(()=>{_0(c,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),la(t),r.finishFragment(),a.finish(!0)}),a.result()}}return la(t),r.finishFragment(),Rl.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){xn.prototype.clearOverflownViewNodes(e,t,i,n)}};function _0(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,o=e.column,s=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=Rt(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let u=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;I(s,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(s,"max-height",`${u}px`)}}function Nf(e){let t=e.matches("td, th")?e:e.closest("td, th");if(!t||t.style.verticalAlign!=="baseline")return;let i=t.querySelector(".-vivliostyle-table-cell-container");if(!i)return;let n=i.children;if(n.length!==0){for(let r=0;r<n.length;r++){let o=n[r].style.position;if(o!=="absolute"&&o!=="fixed")return}I(i,"display","contents")}}function la(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((c,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return c+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((c,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(c,f):c},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let c=a;c&&c!==t.lastElementChild;c=c.nextElementSibling)if(c.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=c;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;I(a,e.vertical?"width":"height",`${u}px`)}var D0=class extends Ll{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new z0(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new $0(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()}},z0=class extends mf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},V0=class extends Hr{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new U0(this.position.sourceNode))}},U0=class Tf{constructor(t){this.tableRootNode=t,d(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,Tr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof Tf&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},$0=class extends wf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new H0(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},H0=class If extends Yl{constructor(t){super(t),d(this,"flagmentLayoutConstraintType","TableRow"),d(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||yn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!bf(t,i,r):!0}nextCandidate(t){let i=_t(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let o=_t(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(t,s.breakPosition,n,r)})}),!t){let s=o.getRootViewNode(this.nodeContext);new Pf().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=_t(this.nodeContext.formattingContext),r=D("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return T(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=_t(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof If?_t(this.nodeContext.formattingContext)===_t(t.nodeContext.formattingContext):!1}},W0=new Pf;function G0(e,t,i,n,r,o){if(!t)return null;if(i===y.table){let s=e.parent;return new In(s?s.formattingContext:null,e.sourceNode)}return null}function j0(e){return e instanceof In?W0:null}Ot("RESOLVE_FORMATTING_CONTEXT",G0);Ot("RESOLVE_LAYOUT_PROCESSOR",j0);function Eu(e){return e.reduce((t,i)=>t+i,0)/e.length}function X0(e){let t=Eu(e);return Eu(e.map(i=>{let n=i-t;return n*n}))}var q0=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function Ir(e){return e.vertical?e.width:e.height}function Ar(e,t){e.vertical?e.width=t:e.height=t}var Af=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,d(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Ir(e)}balanceColumns(e){let t=D("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new q0(e,t)}preBalance(e){}postBalance(){Ar(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let o=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},el=1;function Ff(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+el}function Rf(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+el))-el;n<Ir(t)?Ar(t,n):Ar(t,Ir(t)-1)}var Y0=class extends Af{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,d(this,"originalPosition",null),d(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);Ar(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 Pu(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Ff(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Pu(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Ir(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Rf(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Ir(this.layoutContainer)+this.originalContainerBlockSize*.1);Ar(this.layoutContainer,t)}}};function Pu(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>t>o.computedBlockSize+r)}var Z0=class extends Af{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 X0(t)}hasNextCandidate(e){return Ff(e)}updateCondition(e){Rf(e,this.layoutContainer)}};function K0(e,t,i,n,r,o,s){if(t===y.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new Y0(i,n,r,e):t===y.balance_all?new Z0(i,n,r):(y.balance,null)}}var ha=class{constructor(e,t,i){d(this,"endStuckFixed"),d(this,"endFixed"),d(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},J0=class{constructor(){d(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new ha(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 ha(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new ha(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=fi(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=fi(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Q0(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var ex=class tl{constructor(t,i,n,r,o,s,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=o,this.atBlockStart=s,this.atFlowStart=a,this.isParentBoxDisplayed=h,d(this,"flowName"),d(this,"isBlockValue",null),d(this,"hasBoxValue",null),d(this,"styleValues",{}),d(this,"beforeBox",null),d(this,"afterBox",null),d(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new tl(t,l.before,n,!1,o,this.isBlock(),a,!0),c=u.styleValue("content");Tt(c)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=nt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ye(this.breakBefore)&&(o.breakBefore=nt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new tl(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");Tt(s)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Nd(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!Yo(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},tx=class{constructor(e){this.context=e,d(this,"stack",[]),d(this,"atBlockStart",!0),d(this,"atFlowStart",!0),d(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==y.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new ex(this.context,e,t,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",y.normal).toString(),n=$d(i);n&&!Oe(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=nt(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!")}},Nu=class{constructor(e,t,i,n,r,o,s,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=o,this.counterListener=s,d(this,"root"),d(this,"cascadeHolder"),d(this,"last"),d(this,"rootStyle",{}),d(this,"styleMap",{}),d(this,"counterSnapshots",[]),d(this,"flows",{}),d(this,"flowChunks",[]),d(this,"flowListener",null),d(this,"flowToReach",null),d(this,"idToReach",null),d(this,"cascade"),d(this,"offsetMap"),d(this,"primary",!0),d(this,"primaryStack",[]),d(this,"rootBackgroundAssigned",!1),d(this,"rootLayoutAssigned",!1),d(this,"lastOffset"),d(this,"breakBeforeValues",{}),d(this,"boxStack"),d(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,s,a,e.lang,h,l),this.offsetMap=new J0;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new tx(n),this.offsetMap.addStuckRange(u);let c=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,c,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(c,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=c,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new $(r,vd))}}}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)Cn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!q(n)||r&&!q(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Tu.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Tu[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!q(n.value)){let a=n.evaluate(this.context);if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*jt.lh/jt.em;break;default:{let l=jt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,s=e["line-height"];if(s&&!q(s.value)){let a=s.evaluate(this.context);if(a instanceof Nt)this.context.rootLineHeight=a.num*o;else if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=jt[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return Yb(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Q0(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=fi(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,u=l&&!q(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let s=ge(o,"flow-into"),a=s?s.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=Tm(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=Mh(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let c=t["flow-priority"];c&&(r=Mh(c.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Sy(e,m)}let g=new Cy(e,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ye(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=nt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;this.last;){let o=this.last.firstChild;if(o==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let s=this.boxStack.pop(this.lastOffset),a=null;if(s.afterBox){let h=s.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,s.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(s):s.afterBox.offset,s.flowName),a=s.afterBox.getBreakValue("after")}a=nt(a,s.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,s.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let s=this.last,a=this.getAttrStyle(s);this.primaryStack.push(this.primary),this.cascade.pushElement(this,s,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=s.getAttribute("id")||s.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&s.localName=="body"&&s.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,s,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,s===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,s===this.root),s===this.xmldoc.body&&(l.breakBefore=nt(l.flowChunk.breakBefore,l.breakBefore));let c=this.boxStack.nearestBlockStartOffset(l);if(c===0||s===this.xmldoc.body){let p=a.page,f=p&&!q(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,c,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?c:l.offset,l.flowName)}if(this.primary&&l.displayValue()===y.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&c===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}return Number.POSITIVE_INFINITY}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Tu=["column-count","column-width","column-fill"],HS=`OTTO${new Date().valueOf()}`;function Zl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function ix(e){let t=new pi;for(let i of Zl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function nx(e,t){let i={};for(let n in e)i[n]=ge(e,n).evaluate(t,n);return i}var Lf=class{constructor(e){this.properties=e,d(this,"fontTraitKey"),d(this,"src"),d(this,"blobURLs",[]),d(this,"blobs",[]),d(this,"family"),this.fontTraitKey=ix(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 pi;i.append(`@font-face {
1869
1867
  font-family: `),i.append(this.family),i.append(`;
1870
- `);for(let n of Pl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1871
- `);if(t){i.append('src: url("');let n=ew(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1868
+ `);for(let n of Zl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1869
+ `);if(t){i.append('src: url("');let n=_w(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1872
1870
  }
1873
- `),i.toString()}},f0=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof it){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(M(r)),i.push(n)}return new it(i)}else{let t=this.familyMap[e.stringValue()];return t?new it([M(t),e]):e}}},g0=class{constructor(e,t,i){this.head=e,this.body=t,c(this,"srcURLMap",{}),c(this,"familyPrefix"),c(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=D("initFont"),r=e.src,o={};for(let l of Pl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=M(s);let a=new Yp(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),j.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{t.registerFamily(e,o),j.debug("Found already-loaded font:",i)}):(r=new Ar(()=>{let o=D("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?es(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(o)})}):this.initFont(e,null,t).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){j.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return En(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return T(!0);let i=D("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},hi=!0;function m0(e){hi=e}var Vi=[];function iu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Zp(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function Nl(e,t,i){if(!hi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Zp(e.ownerDocument).includes(e))return T(!1);let n=e.textContent,r=e.src,o=e.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&e.async&&!s,h=(o&&!a||r&&e.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Kp(t)||(t.onload=null),l)return Vi.some(d=>iu(d,e))||Vi.push(e),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&iu(d,e)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=h,u.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(j.debug("script:",r),r){let d=vt(u);return t.document.head.appendChild(u),En([d])}else return t.document.head.appendChild(u),T(!0)}function w0(e,t){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let u of Object.values(l))r(u)},o=s=>{if(s instanceof ml)r(s.style);else if(s instanceof Bn||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(t.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of e.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function y0(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=w0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function v0(e,t,i){if(!hi)return T(!1);let n=Zp(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?y0(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=D("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Nl(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Vi.push(u),h=!0),n.length===0&&r&&(j.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function b0(e){if(!hi)return T(!1);let t=D("loadScripts");return t.loop(()=>Vi.length===0?T(!1):Nl(Vi.shift(),e,{atEnd:!0}).thenReturn(Vi.length>0)).then(()=>{j.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),j.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Kp(e){return hi?Vi.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var x0=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Xa),S0=e=>`"${x0(e)}"`,Bs=(e,t,i)=>S0(i.transformURL(pi(String(e)),t)),C0=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${Bs(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${Bs(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${Bs(r,t,i)}`),k0={},E0=new Set(["base","body","head","html","link","meta","script","style","title"]);function P0(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Ma=class Qn extends qa{constructor(t,i,n,r,o,s,a,h,l,u,d,p,f,g,m,w=new Map,x={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=o,this.xmldoc=s,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=x,c(this,"document"),c(this,"exprContentListener"),c(this,"computedStyleParentFontSizeOverride",null),c(this,"computedStyleParentLineHeightOverride",null),c(this,"nodeContext",null),c(this,"viewRoot",null),c(this,"isFootnote",!1),c(this,"sourceNode",null),c(this,"offsetInNode",0),c(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new Qn(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!_t(t)||!Nh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(rr);if(!i)return;let n=Td(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(rr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,u;let d=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!d)return h;let p=[],f=qn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,m=_t(t)&&!!d["footnote-call"]&&kt((l=d["footnote-call"].content)==null?void 0:l.value);for(let y of wv){let b;if(y){if(!d[y])continue;let S=bt(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(y=="footnote-call"&&!_t(t)||y=="footnote-marker"&&!(S||C||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(y.match(/^first-/)){let N=r.display;if(!N||N===v.inline)continue;let F=t.firstElementChild;if(F&&Le(F.previousSibling)){let B=o.getStyle(F,!1);if(B){let U=me(B,"display");if(U!=null&&U.value&&U.value!==v.inline)continue}}}if(y==="before"||y==="after"||y==="footnote-call"||y==="footnote-marker"){let N=d[y].content,F=(y==="before"||y==="after")&&(r.float===v.footnote||S||C)&&!!N;if(!N||!kt(N.value)&&!F)continue}p.push(y),b=qn.createElementNS("http://www.w3.org/1999/xhtml","span"),sr(b,y)}else{if(m)continue;b=qn.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(b),y.match(/^first-/)&&(g=b)}if(!p.length)return h;let w=new Ns(t,n,o,s,this.exprContentListener),x=new no(t,f,null,a,h,rt.ROOTLESS,w);return h||x}getPseudoMap(t,i,n,r,o){let s=gt(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};or(l,s[h],o),wa(l,o,s[h]),np(s[h],i,n,(u,d)=>{or(l,d,o),ep(d,p=>{or(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=D("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);o=new no(n,l,h,r,o,i,u)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=D("createShadows"),l=null,u=r.template,d;if(u instanceof ut||u===v.footnote)if(u!==v.footnote||Nh(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof ut?u.url:Ie("user-agent.xml#footnote",vi);d=this.createRefShadow(p,rt.ROOTLESS,t,a,l)}else d=T(l);else d=T(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=ko(m,w.url),f=this.createRefShadow(m,rt.ROOTED,t,a,p))}f==null&&(f=T(p));let g=null;f.then(m=>{if(r.display===v.table_cell){let w=Ie("user-agent.xml#table-cell",vi);g=this.createRefShadow(w,rt.ROOTLESS,t,a,m)}else g=T(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,o,s,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var o;let s=this.context,a=ya(n,s,this.regionIds,this.isFootnote,this.nodeContext),h=!((o=this.nodeContext)!=null&&o.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=tp(a,s,t);let u=!h&&t!==l;i=ip(a,s,i);let d=(x,y)=>{let b;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(b=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(b=s.pageAreaWidth));let S=y.evaluate(s,x,b,t);return x=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},p=!!new Ze(s.style.pageScope,"left-page").evaluate(s);if(rp(a,r,t,i,p,d),u){let x=r[t?"height":"width"];(!x||x===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(To(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Qc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{w[x]&&(r[x]=w[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&_t(w)){let x=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let y=ko(x,this.xmldoc.url),b=this.xmldoc.getElement(y);b&&bt(b)&&((n=b.parentNode)==null?void 0:n.nodeType)===1&&(r=b.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,x=!!w&&l.type==rt.ROOTED&&bt(r);if(!w||l.type==rt.ROOTLESS||x){let y=(l?l.styler:this.styler).getStyle(r,!1);o.push(y),s=s||_s(r)}w&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let d=new Set;if(o.length>0){let w=o[0],x=ya(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let y in x){if(!mn(y))continue;let b=x[y].evaluate(this.context,y);b&&b!==v.inherit&&b!==v.unset&&b!==v.revert&&b!==Y&&d.add(y)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new V(new R(f,"px"),0)};p&&(g["line-height"]=new V(new Ct(this.context.pref.lineHeight),0));let m=new Ey(g,this.context);for(let w=o.length-1;w>=0;--w){let x=o[w],y=[];for(let C in x)mn(C)&&y.push(C);y.sort(Ql);let b,S;for(let C of y){if(w>0&&h&&C.startsWith("--viv-marker-")||w>0&&d.has(C))continue;m.setPropName(C);let N=me(x,C),F=N;if(N.value===v.initial)delete g[C];else if(!Z(N.value)){if(C==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)F=new V(new R(this.context.rootFontSize,"px"),N.priority);else if(C==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&N.value instanceof R&&(N.value.unit==="lh"||N.value.unit==="rlh"))F=new V(new R(this.context.rootLineHeight,"px"),N.priority);else if(w===0&&N.value instanceof R&&N.value.unit==="lh"){let B=this.getLineHeightUnitSize(C,b,S);B!=null&&(F=new V(new R(N.value.num*B,"px"),N.priority))}else Qt(C)||(F=N.filterValue(m));C==="font-size"?b=F.value:C==="line-height"&&(S=F.value),g[C]=F}}}for(let w in t)mn(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ie(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=_s(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=fy().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let o=t[r];if(o){if(Z(o))o===v.initial&&(n[r]=void 0);else if(o instanceof Ue)n[r]=o.num;else if(o instanceof de)n[r]=o.name;else if(o instanceof R){let s=o;switch(s.unit){case"dpi":case"dpcm":case"dppx":n[r]=s.num*Wt[s.unit];break;default:n[r]=o}}else n[r]=o;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,o,s){let a=Dt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,o,s);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let o=!0,s=D("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(this.syncSemanticFootnoteCounterToTarget(a),!this.nodeContext.shadowContext){let S=this.xmldoc.getElementOffset(a);os.registerFragmentIndex(S,this.nodeContext.fragmentIndex,0)}let u={},d={getStyle:S=>this.styler.getStyle(S,!1),getProp:(S,C)=>S?me(S,C):null,getStyleMap:(S,C)=>gt(S,C),getMutableStyleMap:(S,C)=>ei(S,C),createCascadeValue:(S,C)=>new V(S,C),filterFootnoteMarkerContent:(S,C)=>S.filterValue(new mr(this.styler.cascade,C,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!Z(f.value)&&f.value!==v.none&&g&&!Z(g.value)?Yw(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===rt.ROOTED&&bt(a);if(this.nodeContext.parent&&(To(p?.value)||m&&Si(m)||w)){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}l=Qw(a,l,this.nodeContext.shadowContext,this.xmldoc.url,S=>this.xmldoc.getElement(S),rr,d),l=ey(a,l,this.nodeContext.shadowContext,this.context,d),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),m&&Si(m)&&u.display===v.block&&(u.display=v.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let x=u["flow-into"];if(x&&x.toString()!=this.flowName)return s.finish(!1),s.result();if(hi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Nl(a,this.viewport.window).thenFinish(s),s.result();let y=u.display;if(bt(a)&&!w&&a.hasAttribute(Nd)&&(y=u.display=v.none),Z(y)&&(y===v.initial||y===v.unset?y=v.inline:y===v.inherit?y=((n=this.nodeContext.parent)==null?void 0:n.display)&&M((r=this.nodeContext.parent)==null?void 0:r.display):y=null),y===v.none)return s.finish(!1),s.result();let b=this.nodeContext.parent==null;return this.nodeContext.flexContainer=y===v.flex,this.createShadows(a,b,l,u,h,this.context,this.nodeContext.shadowContext).then(S=>{var C;this.nodeContext.nodeShadow=S;let N=u.position,F=u.float,B=u.clear,U=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,q=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:U,he=dw(a),ae=u["column-count"],k=u["column-width"],_=ae&&ae!==v.auto&&!Z(ae)||k&&k!==v.auto&&!Z(k);this.nodeContext.establishesBFC=fw(y,N,F,u.overflow,U,q,_||he),this.nodeContext.containingBlockForAbsolute=gw(N),this.nodeContext.isInsideBFC()&&F!==v.footnote&&!(m&&Si(m))&&(F=null,B=null);let E=null,L=!1,P=this.isFootnote&&(!((C=this.nodeContext)!=null&&C.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),A=ty(a,this.nodeContext.shadowContext,d);iy(A.sourceStyle,u,this.context),E=A.footnoteDisplay;let O=F instanceof J||F===v.left||F===v.right||F===v.top||F===v.bottom||F===v.inline_start||F===v.inline_end||F===v.block_start||F===v.block_end||F===v.snap_block||F===v.snap_inline||F===v.inside||F===v.outside||F===v.footnote;if(F&&(delete u.float,F===v.footnote))if(E=u["footnote-display"]||E,L=!!u["--viv-marker-content"],P){O=!1;let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),y=L?M("list-item"):H==="inline"||H==="compact"?v.inline:v.block,u.display=y}else u.display=v.inline;if(P&&bt(a)){L=L||!!u["--viv-marker-content"];let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),L&&(y=u.display=M("list-item")),!L&&(H==="inline"||H==="compact")&&(y=u.display=v.inline)}B&&(B===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(B=M(this.nodeContext.parent.clearSide)),(B===v.left||B===v.right||B===v.top||B===v.bottom||B===v.inline_start||B===v.inline_end||B===v.block_start||B===v.block_end||B===v.inside||B===v.outside||B===v.both||B===v.all||B===v.same||B===v.column||B===v.region||B===v.page)&&(delete u.clear,(O||u.display&&u.display!=v.inline)&&(this.nodeContext.clearSide=B.toString())));let z=jn(y)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),W=u["break-inside"];(O||W&&!Z(W)&&W!==v.auto)&&this.nodeContext.breakPenalty++,y&&y!==v.inline&&Ht(y)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!O&&!y||Ht(y)||td(y),this.nodeContext.display=y?y.toString():"inline",this.nodeContext.floatSide=O?F.toString():null,this.nodeContext.floatReference=m||Te.INLINE;let K=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=K&&!Z(K)?K:null;let Q=this.isInsideNonRootMultiColumn(),ee=u["column-span"];if(this.nodeContext.columnSpan=!Q&&ee&&!Z(ee)?ee:null,!this.nodeContext.inline){let H=u["break-after"];H&&!Z(H)&&!(Q&&H===v.column)&&(this.nodeContext.breakAfter=H.toString(),ta[this.nodeContext.breakAfter]&&(u["break-after"]=v.column));let Ft=u["break-before"];Ft&&!Z(Ft)&&!(Q&&Ft===v.column)&&(this.nodeContext.breakBefore=Ft.toString(),ta[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let $t=u.page,Et=$t&&!Z($t)&&$t.toString();!Et&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||y===v.table_header_group||y===v.table_footer_group)&&(Et=this.styler.cascade.currentPageType),!Et||Et.toLowerCase()==="auto"?Et=this.nodeContext.pageType:this.nodeContext.pageType=Et,this.styler.cascade.currentPageType!==Et&&!(!Et&&u.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!Nn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Et!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Et)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let pe=u["border-collapse"];if(!pe||pe===M("separate")){let H=u["border-spacing"],Ft,$t;H&&(H instanceof J?(Ft=H.values[0],$t=H.values[1]):Ft=$t=H,Ft.isNumeric()&&(this.nodeContext.inlineBorderSpacing=at(Ft,this.context)),$t.isNumeric()&&(this.nodeContext.blockBorderSpacing=at($t,this.context)))}let re=u["footnote-policy"]||A.footnotePolicy;re&&!Z(re)&&(u["--viv-footnote-policy"]=re),this.nodeContext.footnotePolicy=re&&!Z(re)?re:null;let se=u["x-first-pseudo"];if(se){let H=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Ww(H,se.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Me=u["white-space"];if(Me){let H=gd(Me.toString());H!==null&&(this.nodeContext.whitespace=H)}let Oe=u["hyphenate-character"];Oe&&Oe instanceof X&&(this.nodeContext.hyphenateCharacter=Oe.str);let fe=u["word-break"],Ee=u["line-break"],we=u["overflow-wrap"];(fe===v.break_all||Ee===v.anywhere||we===v.break_word||we===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,y,N,F,b),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let ue=!1,Pe=null,ye=[],Se=a.namespaceURI,ne=a.localName,_r=ne;Se=="http://www.w3.org/1999/xhtml"?(E0.has(ne)?ne="div":ne=="vide_"?ne="video":ne=="audi_"?ne="audio":ne=="object"&&(ue=!!this.customRenderer),a.hasAttribute(bl)&&a.hasAttribute("src")&&u.content instanceof ut&&(ne="img")):Se=="http://www.idpf.org/2007/ops"?(ne="span",Se="http://www.w3.org/1999/xhtml"):Se=="http://www.pyroxy.com/ns/shadow"?(Se="http://www.w3.org/1999/xhtml",ne=this.nodeContext.inline?"span":"div"):ue=!!this.customRenderer,z?t?(ne="li",u["--viv-marker-content"]&&(u["list-style-type"]=v.none,u["list-style-image"]=v.none)):(y=Ht(y)?v.inline:v.block,u.display=y,ne="div"):ne=="body"||ne=="li"?ne="div":ne=="q"&&(ne="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(ue=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(ue=!0);let us;if(ue){let H=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;us=this.customRenderer(a,H,u)}else us=T(null);us.then(H=>{var Ft,$t,Et,Bl,Ml;if(H)ue&&(o=H.getAttribute("data-adapt-process-children")=="true");else if(u.display===v.none){s.finish(!1);return}else H=this.createElement(Se,ne);if(!b&&_&&u["column-fill"]===v.auto){let $e=this.nodeContext.vertical?u.width:u.height;(!$e||$e===v.auto||Z($e))&&(H.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=v.balance)}ne!=_r&&(H.setAttribute("data-vivliostyle-original-tag",_r),(_r==="html"||_r==="body")&&(H.role="presentation")),ne=="a"&&H.addEventListener("click",this.page.hrefHandler,!1),Pe&&(this.applyPseudoelementStyle(this.nodeContext,"inner",Pe),H.appendChild(Pe)),H.localName=="iframe"&&H.namespaceURI=="http://www.w3.org/1999/xhtml"&&P0(H);let Dr=this.nodeContext.inheritedProps["image-resolution"],cs=[],ds=u.width,ps=u.height,Ef=a.getAttribute("width"),Pf=a.getAttribute("height"),fs=ds===v.auto||!ds&&!Ef,gs=ps===v.auto||!ps&&!Pf,_l=a.attributes,Nf=_l.length,_n=null,Dl=null;y===v.table_cell&&((Et=($t=(Ft=this.nodeContext.parent)==null?void 0:Ft.viewNode)==null?void 0:$t.lastElementChild)==null?void 0:Et.localName)==="a"&&H.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let $e=0;$e<Nf;$e++){let mt=_l[$e],st=mt.namespaceURI,oe=mt.localName,Ce=mt.nodeValue;if(st){if(st=="http://www.w3.org/2000/xmlns/")continue;st=="http://www.w3.org/1999/xlink"&&oe=="href"&&(Ce=this.documentURLTransformer.transformURL(this.resolveURL(Ce),this.xmldoc.url))}else{if(!hi&&oe.match(/^on/)||oe=="style")continue;if(oe==="media"&&ne==="source"&&Se==="http://www.w3.org/1999/xhtml"&&((Bl=a.parentElement)==null?void 0:Bl.localName)==="picture")try{let He=this.context.rootScope,ct=new ts(He),Vr=new Vt(Ce,ct),zl=Jc(Vr,ct,"");if(zl){if(zl.toExpr().evaluate(this.context))continue;Ce="not all"}}catch{}if((oe=="id"||oe=="name")&&t){let He=this.documentURLTransformer.transformFragment(Ce,this.xmldoc.url);H.setAttribute(oe,Ce),H.setAttribute("data-vivliostyle-id",He);let ct=H.ownerDocument.createElement("a");ct.setAttribute(oe,He),ct.setAttribute(Pn,"1"),ct.style.position="absolute",H.appendChild(ct),this.page.registerElementWithId(H,He);continue}if(oe=="src"||oe=="href"||oe=="poster")Ce=this.resolveURL(Ce),oe==="href"?Ce=this.documentURLTransformer.transformURL(Ce,this.xmldoc.url):Ce=pr(Ce),oe==="src"&&(Ce=Bu(Ce));else if(oe=="srcset")Ce=Ce.split(",").map(He=>{let ct=He.trim().split(/\s+/),Vr=pr(this.resolveURL(ct[0]));return ct.length>1?`${Vr} ${ct.slice(1).join(" ")}`:Vr}).join(",");else if(oe==="data"&&ue&&ne==="object"&&H.hasAttribute("data"))continue;if(oe==="poster"&&ne==="video"&&Se==="http://www.w3.org/1999/xhtml"){let He=new Image,ct=vt(He,Ce);fs&&gs?(ye.push(ct),cs.push({image:He,element:H,fetcher:ct})):this.page.fetchers.push(ct)}}if(Se=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(Ce=C0(Ce,this.xmldoc.url,this.documentURLTransformer)),st){let He=k0[st];He&&(oe=`${He}:${oe}`)}if(oe=="src"&&!st&&(ne=="img"||ne=="input")&&Se=="http://www.w3.org/1999/xhtml")_n=Ce;else if(oe=="alt"&&!st&&ne=="img"&&Se=="http://www.w3.org/1999/xhtml")Dl=Ce;else if(oe=="href"&&ne=="image"&&Se=="http://www.w3.org/2000/svg"&&(st=="http://www.w3.org/1999/xlink"||!st))st||H.setAttribute(oe,Ce),this.page.fetchers.push(vt(H,Ce));else if(st)H.setAttributeNS(st,oe,Ce);else try{H.setAttribute(oe,Ce)}catch(He){j.warn(He)}}if(_n){let $e=ne==="input"?new Image:H,mt=vt($e,_n,Dl);$e!==H&&(H.src=_n);let st=()=>{var oe,Ce;if(u.position===v.fixed)return!0;for(let He=(oe=this.nodeContext.parent)==null?void 0:oe.viewNode;He&&He!==this.viewRoot;He=He.parentElement)if(((Ce=He.style)==null?void 0:Ce.position)==="fixed")return!0;return!1};!fs&&!gs&&!(()=>{let oe=this.nodeContext.vertical?ds:ps;return oe instanceof R&&oe.unit==="%"})()&&!st()?this.page.fetchers.push(mt):(fs&&gs&&Dr&&Dr!==1&&cs.push({image:$e,element:H,fetcher:mt}),ye.push(mt))}else!_n&&ne==="img"&&Se==="http://www.w3.org/1999/xhtml"&&(H.srcset||((Ml=a.parentElement)==null?void 0:Ml.localName)==="picture")&&this.page.fetchers.push(vt(H));delete u.content;let zr=u["--viv-marker-content"];if(zr){let $e=zr instanceof J?zr.values:[zr];for(let mt of $e)mt instanceof ut&&mt.url&&ye.push(vt(new Image,mt.url))}if(H.localName==="object"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("data")&&this.page.fetchers.push(vt(H)),H.localName==="embed"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")&&this.page.fetchers.push(vt(H)),H.localName==="iframe"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")){let $e=H;$e.loading==="lazy"&&($e.loading="eager"),this.page.fetchers.push(vt(H))}if(this.preprocessElementStyle(u),this.applyComputedStyles(H,u),this.nodeContext.inline)t||(wt(H,"inline-start"),fn(H)&&wt(H,"clone"));else if(t){if(!is(u.position)){let $e=u["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),st=mt!==null,oe=mt==="auto";($e===v.discard&&st||$e!==v.keep&&oe&&!this.nodeContext.floatSide)&&Ss(H,"block-start")}}else{let $e=this.nodeContext.vertical?"width":"height";mi(H,$e)&&I(H,$e,this.nodeContext.display==="table-row"?"0.01px":""),wt(H,"block-start"),fn(H)&&wt(H,"clone"),Ss(H,"block-start")}z&&u["ua-list-item-count"]&&H.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=H,ye.length?En(ye).then(()=>{Dr>0&&this.modifyElemDimensionWithImageResolution(cs,Dr,u,this.nodeContext.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Le(r,n.parent.whitespace)||Nt(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Lr(i))}getBreakTypeAt(t){var i,n,r,o,s;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(qe(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let u=this.viewport.window.getComputedStyle(l),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=l?.firstChild;for(;f&&(Le(f,h.parent.whitespace)||!h.floatSide&&Nt(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(s=(o=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:s.startBreakType;return qe(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let s=new Ns(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new vv(t,s)}}isSVGUrlAttribute(t){return Qn.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=at(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=at(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=at(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=at(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||v.none,d=n["max-height"]||v.none;if(u===v.none&&d===v.none)I(l,"max-width",`${a}px`);else if(u!==v.none&&d===v.none)I(l,"width",`${a}px`);else if(u===v.none&&d!==v.none)I(l,"height",`${h}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?I(l,"max-width",`${Math.min(a,at(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,at(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Fe,d=n["min-height"]||Fe;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,at(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,at(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Dt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof Wi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.formattingContext;this.nodeContext.formattingContext=new Wi(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||Z(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=D("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Eh(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let t,i=t=this.sourceNode.textContent,n=D("preprocessTextContent"),r=Dt("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=r.length?T(!1):r[o++](this.nodeContext,i).thenAsync(s=>(i=s,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Rw(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=D("createNodeView"),r,o=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=T(!0)):r=this.createTextNodeView(),r.then(s=>{var a;if(o=s,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(d,p)=>d?.nodeType===1&&Kt(d)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Le(this.viewNode))&&!u.hasChildNodes()&&cd(u).includes("block-start")&&wt(u,"text-start"),u.appendChild(this.viewNode),vw(this.viewNode))}n.finish(o)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):T(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,o,s,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.subShadow.root,s=n.subShadow.type,s==rt.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,s=rt.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:o?t=null:(t=t.parent.modify(),t.after=!0),o){let l=new an(o,r,i);return l.shadowContext=a,l.shadowType=s,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=rt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let r=t.nodeShadow.root;if(t.nodeShadow.type==rt.ROOTLESS&&(r=r.firstChild),r){let o=new an(r,t,i);return o.shadowContext=t.nodeShadow,o.shadowType=t.nodeShadow.type,this.processShadowContent(o)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new an(n,t,i));if(t.sourceNode.nodeType!=1){let r=Eh(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let o=r;return Kt(o)==="footnote-call"&&o.getAttribute(Qn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&bt(i)}insertFootnoteCall(t){var i,n;let r=D("insertFootnoteCall"),o=qn.createElementNS("http://www.w3.org/1999/xhtml","span");sr(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(Qn.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new an(o,t.parent,t.boxOffset);a.inline=!0;let h=new Ns(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new no(t.sourceNode,o,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,rt.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return T(n);let r=D("nextInTree");return this.setCurrent(n,!0,i).then(o=>{if((!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let s=this.findImmediateFootnoteCallSibling(n);s!=null&&s.parentNode&&s.parentNode.removeChild(s),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){hr(t,this.page)}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i["border-image-source"];a&&this.addImageFetchers(a);let h=i["list-style-image"];h&&this.addImageFetchers(h);let l=i["mask-image"];l&&this.addImageFetchers(l);let u=i["clip-path"];u&&this.addImageFetchers(u);let d=i.filter;d&&this.addImageFetchers(d);let p=i["shape-outside"];p&&this.addImageFetchers(p);let f=i["--viv-marker-content"];f&&this.addImageFetchers(f);let g=i.position===v.relative,m=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),w=Object.keys(i);w.sort(Ql);let x,y;for(let b of w){if(T0[b])continue;let S=i[b];if(!(!S||S===Y&&!Qt(b))){if(S=S.visit(new Yg(this.xmldoc.url,this.documentURLTransformer)),S instanceof R)if(S.unit==="em"){let C=this.getEmUnitSize(b,x);C!=null&&(S=new R(S.num*C,"px"))}else if(S.unit==="lh"){let C=this.getLineHeightUnitSize(b,x,y);C!=null&&(S=new R(S.num*C,"px"))}else Wu(S.unit)&&(S=lc(S,this.context));if((b==="font-size"||b==="line-height")&&(b==="font-size"?x=S:y=S,this.viewport.layoutUnitAdj&&S instanceof R&&S.unit!=="%"&&S.unit!=="em"&&S.unit!=="lh"&&(S=new Qi(`calc(${S.toString()} - var(--viv-layoutUnitAdj))`))),Bw[b]||g&&Mw[b]){this.page.delayedItems.push(new al(t,b,S));continue}m&&this.page.pageAreaElement&&mn(b)?(I(this.page.pageAreaElement.parentElement.parentElement,b,S.toString()),b!=="writing-mode"&&b!=="direction"&&I(this.viewport.layoutBox,b,S.toString())):I(t,b,S.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(t,i){var n,r,o;let s=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var t,i,n;return((n=(i=(t=this.nodeContext)==null?void 0:t.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(t){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:t?this.parsePlusLayoutUnitAdj(t.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:t?this.parsePlusLayoutUnitAdj(t.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(t,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let u=null;if(n)if(n instanceof Ct||n instanceof R&&(n.unit==="em"||n.unit==="%"))u=n instanceof R&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof R&&n.unit!=="lh"){let d=this.context.queryUnitSize(n.unit,!1);if(d!=null)return n.num*d}return null}if(u==null)for(let d=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;d&&d.nodeType===1;d=d.parentNode){let p=(s=d?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(u=parseFloat(p));break}}if(u!=null){if(i&&!(i instanceof R))return null;let d=h.fontSize;if(i instanceof R){let p=da(i,d,this.context).num;return typeof p!="number"||isNaN(p)?null:u*p}else return d==null?null:u*d}return l}getEmUnitSize(t,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(t==="font-size"||i==null)return r;if(i instanceof R){let o=da(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),s=gt(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;kt(h)&&(h.visit(new gr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=D("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t&&t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new an(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=s),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return T(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=gt(this.cascadedPageStyle,qo);p&&p.area&&(a=p.area)}let h=gt(a,"_pseudos");t=this.computeStyle(t,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new R(l.fontSize,"px")),delete o.content;let u=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!me(f,"display"),m={},w=this.createElement("http://www.w3.org/1999/xhtml","span");sr(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,m),g||(m.display=v.block);let x=me(f,"content");if(x){let b=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=x.filterValue(new mr(this.styler.cascade,b,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let y=m.content;if(kt(y)){y.visit(new gr(w,this.context,y,this.exprContentListener));let b=w.querySelectorAll("img[src]");for(let C=0;C<b.length;C++){let N=b[C],F=N.getAttribute("src");if(!F)continue;let B=vt(N,F);s.push(B),this.page.fetchers.push(B)}let S=w.getAttribute("src");if(S){let C=w.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",S),w.appendChild(C));let N=vt(C,S);s.push(N),this.page.fetchers.push(N)}}delete m.content,this.applyComputedStyles(w,m)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=d}return s.length?En(s).thenReturn(t):T(t)}processFragmentedBlockEdge(t){var i,n,r;let o=!t.inline&&t.after?t.parent:t,s=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=me(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Ht(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(wt(l,"inline-end"),fn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;wt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(mi(l,u)&&I(l,u,""),wt(l,"block-end"),!a++&&h!==o){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?dd(p,["block-start","text-start","block-end","text-end","justify"]):(wt(l,"text-end"),wt(l,"justify")):wt(l,"text-end")}else wt(l,"text-end")}fn(l)&&wt(l,"clone"),Ss(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||_i[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&Le(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(Pn)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Le(l.nextSibling))?i(l):!1}return!(!s||Ht(s))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Le(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,o=t.unit;if(pg(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,gl(t,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Kt(n)===Kt(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!Kt(t)}};c(Ma,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),c(Ma,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var N0=Ma,T0={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},I0=class{constructor(e){c(this,"layoutBox"),c(this,"window"),c(this,"pixelRatio"),c(this,"scaleRatio"),c(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.subtractOffsets(n,i))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},jo=class{constructor(e,t,i,n,r,o){if(this.window=e,this.fontSize=t,this.pixelRatio=i,c(this,"document"),c(this,"root"),c(this,"outerZoomBox"),c(this,"contentContainer"),c(this,"layoutBox"),c(this,"width"),c(this,"height"),c(this,"scaleRatio",1),c(this,"layoutUnitPerPixel",64),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Ga){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=o||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!o&&u)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function hr(e,t){if(e instanceof it)for(let i of e.values)hr(i,t);else if(e instanceof ut){let i=pr(e.url);t.fetchers.push(vt(new Image,i))}else if(e instanceof ci)for(let i of e.values)hr(i,t);else if(e instanceof J)for(let i of e.values)hr(i,t)}var A0=1,ls=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,c(this,"specified",{}),c(this,"children",[]),c(this,"pageMaster",null),c(this,"index",0),c(this,"key"),c(this,"_scope"),this._scope=e,this.key=`p${A0++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},F0=class extends ls{constructor(e){super(e,null,null,[],null),this.specified.width=new V(Pr,0),this.specified.height=new V(Nr,0)}},nu=class extends zs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Jp=class Qp extends ls{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),this.condition=s,this.specificity=a,c(this,"keyMap",{}),t instanceof nu||(this._scope=new nu(t,this)),this.pageMaster=this,this.specified.width=new V(Pr,0),this.specified.height=new V(Nr,0),this.specified["wrap-flow"]=new V(v.auto,0),this.specified.position=new V(v.relative,0),this.specified.overflow=new V(v.visible,0)}createInstance(t){return new Il(t,this)}clone(t){let i=new Qp(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},ef=class tf extends ls{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new V(v.auto,0)}createInstance(t){return new M0(t,this)}clone(t){let i=new tf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Mr=class nf extends ls{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Fn(t,this)}clone(t){let i=new nf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function R0(e,t,i){return!t||Z(t)?new Qe(e,i):t.toExpr(e,e.zero)}function ve(e,t,i){return!t||t===v.auto||Z(t)?null:t.toExpr(e,i)}function L0(e,t,i){return!t||t===v.normal||Z(t)?null:t.toExpr(e,i)}function St(e,t,i){return!t||t===v.auto||Z(t)?e.zero:t.toExpr(e,i)}function ru(e,t,i){return!t||Z(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Jt(e,t,i,n){return!t||i===v.none||Z(t)?e.zero:t.toExpr(e,n)}function rf(e,t,i){return!t||Z(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var hs=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,c(this,"cascaded",{}),c(this,"style",{}),c(this,"autoWidth",null),c(this,"autoHeight",null),c(this,"children",[]),c(this,"isAutoWidth",!1),c(this,"isAutoHeight",!1),c(this,"isTopDependentOnAutoHeight",!1),c(this,"isRightDependentOnAutoWidth",!1),c(this,"calculatedWidth",0),c(this,"calculatedHeight",0),c(this,"pageMasterInstance",null),c(this,"namedValues",{}),c(this,"namedFuncs",{}),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"suppressEmptyBoxGeneration",!1),c(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return te(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let r=this.vertical?Od:Bd;n=e;for(let o in r)n=n.replace(o,r[o])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new tc(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=ge(i,to(i,new tr(i,"min",[n,r]),te(i,o,s)),s);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=rf(e,t.enabled,e._true),n=ve(e,t.page,e.zero);if(n){let s=new Ze(e,"page-number");i=Mt(e,i,new Ja(e,n,s))}let r=ve(e,t["min-page-width"],e.zero);r&&(i=Mt(e,i,new Us(e,new Ze(e,"page-width"),r)));let o=ve(e,t["min-page-height"],e.zero);o&&(i=Mt(e,i,new Us(e,new Ze(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new G(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ve(e,t.left,i),r=ve(e,t["margin-left"],i),o=Jt(e,t["border-left-width"],t["border-left-style"],i),s=St(e,t["padding-left"],i),a=ve(e,t.width,i),h=ve(e,t["max-width"],i),l=St(e,t["padding-right"],i),u=Jt(e,t["border-right-width"],t["border-right-style"],i),d=ve(e,t["margin-right"],i),p=ve(e,t.right,i),f=te(e,o,s),g=te(e,o,l);if(n&&p&&a){let x=ge(e,i,te(e,a,te(e,te(e,n,f),g)));r?d?p=ge(e,x,d):d=ge(e,x,te(e,p,r)):(x=ge(e,x,p),d?r=ge(e,x,d):(r=to(e,x,new Qe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let x=ge(e,i,te(e,te(e,r,f),te(e,d,g)));this.isAutoWidth&&(h||(h=ge(e,x,n||p)),!this.vertical&&(ve(e,t["column-width"],null)||ve(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ge(e,x,te(e,n,a))):a=ge(e,x,te(e,n,p)):n=ge(e,x,te(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=St(e,m,i);t.left=new G(n),t["margin-left"]=new G(r),t["border-left-width"]=new G(o),t["padding-left"]=new G(s),t.width=new G(a),t["max-width"]=new G(h||a),t["padding-right"]=new G(l),t["border-right-width"]=new G(u),t["margin-right"]=new G(d),t.right=new G(p),t["snap-width"]=new G(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=ve(e,t.top,n),o=ve(e,t["margin-top"],i),s=Jt(e,t["border-top-width"],t["border-top-style"],i),a=St(e,t["padding-top"],i),h=ve(e,t.height,n),l=ve(e,t["max-height"],n),u=St(e,t["padding-bottom"],i),d=Jt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=ve(e,t["margin-bottom"],i),f=ve(e,t.bottom,n),g=te(e,s,a),m=te(e,d,u);if(r&&f&&h){let y=ge(e,n,te(e,h,te(e,te(e,r,g),m)));o?p?f=ge(e,y,o):p=ge(e,y,te(e,f,o)):(y=ge(e,y,f),p?o=ge(e,y,p):(o=to(e,y,new Qe(e,.5)),p=o))}else{o||(o=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let y=ge(e,n,te(e,te(e,o,g),te(e,p,m)));this.isAutoHeight&&(l||(l=ge(e,y,r||f)),this.vertical&&(ve(e,t["column-width"],null)||ve(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ge(e,y,te(e,r,h))):h=ge(e,y,te(e,f,r)):r=ge(e,y,te(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=St(e,w,i);t.top=new G(r),t["margin-top"]=new G(o),t["border-top-width"]=new G(s),t["padding-top"]=new G(a),t.height=new G(h),t["max-height"]=new G(l||h),t["padding-bottom"]=new G(u),t["border-bottom-width"]=new G(d),t["margin-bottom"]=new G(p),t.bottom=new G(f),t["snap-height"]=new G(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ve(e,t[this.vertical?"height":"width"],null),n=ve(e,t["column-width"],i),r=ve(e,t["column-count"],null),o=L0(e,t["column-gap"],null);o||(o=new Er(e,1,"em")),n&&!r&&(r=new tr(e,"floor",[$s(e,te(e,i,o),te(e,n,o))]),r=new tr(e,"max",[e.one,r])),r||(r=e.one),n=ge(e,$s(e,te(e,i,o),r),o),t["column-width"]=new G(n),t["column-count"]=new G(r),t["column-gap"]=new G(o)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=ya(this.cascaded,e,r,!1,null);this.vertical=tp(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=ip(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===v.border_box;let s=!!(e instanceof Ll&&e.currentLayoutPosition&&new Ze(i,"left-page").evaluate(e));rp(o,n,this.vertical,this.rtl,s,(a,h)=>h.value),this.autoWidth=new Re(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Re(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&mn(t)&&this.pageMasterInstance instanceof Cn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new R(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=zo(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=zo(e,r,t,o)}return at(r,e)}getSpecial(e,t){let i=zd(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(e,"");o&&o!==Y&&n.push(o)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&Wu(r.unit)&&(r=lc(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new al(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),o=this.getPropAsNumber(e,"border-left-width"),s=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,s),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),s=this.getPropAsNumber(e,"border-right-width");if(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${o}px`),I(t.element,"border-right-width",`${s}px`),t.marginRight=r,t.borderRight=s,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,o+=t.snapOffsetX)}t.paddingRight=o,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),s=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=s,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,o+=t.snapOffsetY)}t.paddingTop=o,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${o}px`),I(t.element,"border-top-width",`${s}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;I(t.element,"height",`${o}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(t.element,"border-bottom-width",`${r}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){I(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let o=0;o<ou.length;o++)this.propagateProperty(e,t,ou[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<au.length;r++)this.propagateProperty(e,t,au[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==v.auto&&!Z(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==v.auto&&!Z(a)};for(let o=0;o<lu.length;o++){let s=lu[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;I(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,u,d,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let x=(this.vertical||!n)&&this.isAutoHeight,y=(!this.vertical||!n)&&this.isAutoWidth,b=null;if(y||x){y&&I(t.element,"width","auto"),x&&I(t.element,"height","auto");let S=n&&Io(n);S&&rs(n),b=o.getElementClientRect(n?n.element:t.element),S&&rl(n),y&&(this.calculatedWidth=Math.ceil(b.right-b.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=b.bottom-b.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let S=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),N=this.getProp(e,"column-rule-color");if(S>0&&C&&C!=v.none&&N!=v.transparent){let F=this.getPropAsNumber(e,"column-gap"),B=this.vertical?t.height:t.width,U=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),q=t.getPaddingRect(),he=n,ae=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(B+F)*k/r-F/2+t.paddingTop-S/2:(B+F)*k/r-F/2+t.paddingLeft-S/2,E=this.vertical?q.y1+_+S/2:q.x1+_+S/2,L=(d=(u=(l=he.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(u,E),P=(g=(f=(p=he.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),A=isFinite(L)?this.vertical?L-q.x1:L-q.y1:NaN,O=isFinite(P)?this.vertical?P-q.x1:P-q.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),W=z>0?z:this.vertical?n.width:n.height,K=Math.max(U>0?U:0,0),Q=K+W,ee=Math.max(K,isFinite(this.vertical?O:A)?Math.max(0,this.vertical?O:A):0),pe=Math.min(Q,isFinite(this.vertical?A:O)?Math.max(0,this.vertical?A:O):Q),re=Math.max(0,pe-ee),se=t.element.ownerDocument.createElement("div");I(se,"position","absolute"),I(se,this.vertical?"left":"top",`${ee}px`),I(se,this.vertical?"top":"left",`${_}px`),I(se,this.vertical?"height":"width","0px"),I(se,this.vertical?"width":"height",`${re}px`),I(se,ae,`${S}px ${C.toString()}${N?` ${N.toString()}`:""}`),t.element.insertBefore(se,t.element.firstChild)}}}for(let S=0;S<su.length;S++)this.propagateProperty(e,t,su[S],s);for(let S of O0){let C=this.getProp(e,S);C&&hr(C,i)}for(let S=0;S<hu.length;S++)this.propagateDelayedProperty(e,t,hu[S],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof Cn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Di(o)&&Ci(i,o,me(n,o));if(this.pageBox.pseudoName==Tl)for(let o in t)(o.match(/^background-/)||o=="writing-mode")&&(i[o]=t[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in t)!o.match(/^background-/)&&o!="writing-mode"&&(i[o]=t[o]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new mr(e,null,e.counterResolver))),this.init(e.context);for(let o of this.pageBox.children)o.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},ou=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],su=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],O0=["background-image","border-image-source","filter"],au=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],lu=["width","height","image-resolution","object-fit","object-position"],hu=["transform","transform-origin"],Tl="background-host",B0=class extends hs{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},Il=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Mt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},M0=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Fn=class extends hs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof de&&(n=[t]),t instanceof it&&(n=t.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof de){let s=Ds(n[o].name,"enabled"),a=new Ze(r,s);i&&(a=new xi(r,a)),e=Mt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=rf(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=R0(t,i["flow-from"],"body"),o=new tr(t,"has-content",[r]);e=Mt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(t,null):t._true;o=Mt(t,o,e),this.pageMasterInstance.style.enabled=new G(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof hf||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},Al=class extends Xi{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new V(t,i?Xc:qc)}},of=class extends Al{constructor(e,t,i,n){super(e,t,i,n)}},_0=class sf extends Al{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new V(Kl,0),n.specified.height=new V(Kl,0)}startPartitionRule(t,i,n){let r=new Mr(this.scope,t,i,n,this.target),o=new of(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new ef(this.scope,t,i,n,this.target),o=new sf(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},D0=class extends Al{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Mr(this.scope,e,t,i,this.target),r=new of(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new ef(this.scope,e,t,i,this.target),r=new _0(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function af(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var z0={a10:{width:new R(26,"mm"),height:new R(37,"mm")},a9:{width:new R(37,"mm"),height:new R(52,"mm")},a8:{width:new R(52,"mm"),height:new R(74,"mm")},a7:{width:new R(74,"mm"),height:new R(105,"mm")},a6:{width:new R(105,"mm"),height:new R(148,"mm")},a5:{width:new R(148,"mm"),height:new R(210,"mm")},a4:{width:new R(210,"mm"),height:new R(297,"mm")},a3:{width:new R(297,"mm"),height:new R(420,"mm")},a2:{width:new R(420,"mm"),height:new R(594,"mm")},a1:{width:new R(594,"mm"),height:new R(841,"mm")},a0:{width:new R(841,"mm"),height:new R(1189,"mm")},b10:{width:new R(31,"mm"),height:new R(44,"mm")},b9:{width:new R(44,"mm"),height:new R(62,"mm")},b8:{width:new R(62,"mm"),height:new R(88,"mm")},b7:{width:new R(88,"mm"),height:new R(125,"mm")},b6:{width:new R(125,"mm"),height:new R(176,"mm")},b5:{width:new R(176,"mm"),height:new R(250,"mm")},b4:{width:new R(250,"mm"),height:new R(353,"mm")},b3:{width:new R(353,"mm"),height:new R(500,"mm")},b2:{width:new R(500,"mm"),height:new R(707,"mm")},b1:{width:new R(707,"mm"),height:new R(1e3,"mm")},b0:{width:new R(1e3,"mm"),height:new R(1414,"mm")},c10:{width:new R(28,"mm"),height:new R(40,"mm")},c9:{width:new R(40,"mm"),height:new R(57,"mm")},c8:{width:new R(57,"mm"),height:new R(81,"mm")},c7:{width:new R(81,"mm"),height:new R(114,"mm")},c6:{width:new R(114,"mm"),height:new R(162,"mm")},c5:{width:new R(162,"mm"),height:new R(229,"mm")},c4:{width:new R(229,"mm"),height:new R(324,"mm")},c3:{width:new R(324,"mm"),height:new R(458,"mm")},c2:{width:new R(458,"mm"),height:new R(648,"mm")},c1:{width:new R(648,"mm"),height:new R(917,"mm")},c0:{width:new R(917,"mm"),height:new R(1297,"mm")},"jis-b10":{width:new R(32,"mm"),height:new R(45,"mm")},"jis-b9":{width:new R(45,"mm"),height:new R(64,"mm")},"jis-b8":{width:new R(64,"mm"),height:new R(91,"mm")},"jis-b7":{width:new R(91,"mm"),height:new R(128,"mm")},"jis-b6":{width:new R(128,"mm"),height:new R(182,"mm")},"jis-b5":{width:new R(182,"mm"),height:new R(257,"mm")},"jis-b4":{width:new R(257,"mm"),height:new R(364,"mm")},"jis-b3":{width:new R(364,"mm"),height:new R(515,"mm")},"jis-b2":{width:new R(515,"mm"),height:new R(728,"mm")},"jis-b1":{width:new R(728,"mm"),height:new R(1030,"mm")},"jis-b0":{width:new R(1030,"mm"),height:new R(1456,"mm")},letter:{width:new R(8.5,"in"),height:new R(11,"in")},legal:{width:new R(8.5,"in"),height:new R(14,"in")},ledger:{width:new R(11,"in"),height:new R(17,"in")}},V0=new R(.24,"pt"),eS=new R(3,"mm"),U0=new R(10,"mm"),$0=new R(13,"mm");function Xo(e){let t={width:Pr,height:Nr,bleed:Fe,bleedOffset:Fe,cropOffset:Fe},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,u,d;if(l.isSpaceList()?(u=l.values[0],d=l.values[1]):(u=l,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&z0[u.name.toLowerCase()];p&&(d&&d===v.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,o=n&&!Z(n.value)?n.value:v.none,s=r&&!Z(r.value)?r.value:v.auto;if(s===v.auto){if(o!==v.none){let l=!1;o.isSpaceList()?l=o.values.some(u=>u===v.crop):l=o===v.crop,l&&(t.bleed=new R(6,"pt"))}}else s.isNumeric()&&(t.bleed=s);let a=e["crop-offset"],h=a&&!Z(a.value)?a.value:v.auto;return h===v.auto?o!==v.none&&(t.bleedOffset=$0):h.isNumeric()&&(t.cropOffset=h),t}function uu(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),o=n+r,s=e.width;s===Pr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:i.pageWidth=s.num*t.queryUnitSize(s.unit,!1);let a=e.height;return a===Nr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function lf(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function ur(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var _a=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(_a||{});function H0(e,t,i,n,r,o,s){let a=r;a<=o+2*Wt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,u=lf(e,l,l),d=[[0,o+r],[r,o+r],[r,o+r-a]],p=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=ur(e,i,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=ur(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${s}px`}),u}var xr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(xr||{});function W0(e,t,i,n,r,o){let s=r*2,a,h;t==="top"||t==="bottom"?(a=s,h=r):(a=r,h=s);let l=lf(e,a,h),u=ur(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let d=ur(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=ur(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(xr).forEach(g=>{let m=xr[g];m===t?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function G0(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let m=s.value;m instanceof J?m.values.forEach(w=>{w===v.crop?r=!0:w===v.cross&&(o=!0)}):m===v.crop?r=!0:m===v.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,u=at(V0,n),d=Math.max(0,t.bleedOffset-at(U0,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:v.auto;r&&Object.keys(_a).forEach(m=>{let w=_a[m],x=H0(l,w,u,g,p,a,d);h.appendChild(x)}),o&&Object.keys(xr).forEach(m=>{let w=xr[m],x=W0(l,w,u,g,p,d);h.appendChild(x)})}var Da=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),Fl={"top-left-corner":{order:1,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"top-left":{order:2,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"top-center":{order:3,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"top-right":{order:4,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"top-right-corner":{order:5,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"right-top":{order:6,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"start"},"right-middle":{order:7,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"center"},"right-bottom":{order:8,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"end"},"bottom-right-corner":{order:9,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"bottom-right":{order:10,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"bottom-center":{order:11,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"bottom-left":{order:12,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"bottom-left-corner":{order:13,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"left-bottom":{order:14,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"end"},"left-middle":{order:15,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"center"},"left-top":{order:16,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"start"}},j0=(()=>{let e=Fl;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Rl="vivliostyle-page-rule-master",Sr="_marginBoxes",qo="_footnoteArea",hf=class extends Jp{constructor(e,t,i){super(e,null,Rl,[],t,null,0),c(this,"pageMarginBoxes",{});let n=Xo(i),r=new X0(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Sr];t&&j0.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Y0(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new V(v.relative,0),this.specified.width=new V(t.width,0),this.specified.height=new V(t.height,0);for(let i in e)!Da[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Cn(e,this)}},X0=class extends Mr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new q0(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new V(v.auto,0),this.specified["z-index"]=new V(new Ue(0),0),this.specified.position=new V(v.absolute,0),this.specified.overflow=new V(v.visible,0);for(let t in Da)Da.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new K0(e,this)}},q0=class extends Mr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new V(M("body"),0)}createInstance(e){return new uf(e,this)}},Y0=class extends Mr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[Sr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Ld[i]||r&&r.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Y&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new cf(e,this)}},Cn=class extends Il{constructor(e,t){super(e,t),c(this,"pageAreaDimension",null),c(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=Fe,e["margin-left"]=Fe,e["border-left-width"]=Fe,e["padding-left"]=Fe,e["padding-right"]=Fe,e["border-right-width"]=Fe,e["margin-right"]=Fe,e.right=Fe}initVertical(){let e=this.style;e.top=Fe,e["margin-top"]=Fe,e["border-top-width"]=Fe,e["padding-top"]=Fe,e["padding-bottom"]=Fe,e["border-bottom-width"]=Fe,e["margin-bottom"]=Fe,e.bottom=Fe}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new G(e.borderBoxWidth),t.height=new G(e.borderBoxHeight),t["padding-left"]=new G(e.marginLeft),t["padding-right"]=new G(e.marginRight),t["padding-top"]=new G(e.marginTop),t["padding-bottom"]=new G(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},u={},d={};for(let b in e){let S=Fl[b];if(S){let C=e[b],N=this.pageMarginBoxInstances[b],F=new bo(C,N.style,t,h,r);l[S.positionAlongVariableDimension]=C,u[S.positionAlongVariableDimension]=N,d[S.positionAlongVariableDimension]=F}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,m={};Object.keys(l).forEach(b=>{let S=b,C=ve(h,u[S].style[t?"max-width":"max-height"],i.extent);if(C){let N=C.evaluate(n);if(f[S]>N){let F=d[S]=new cu(l[S],u[S].style,t,h,r,N);m[S]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[o,s,a].forEach(b=>{var S;f[b]=(S=m[b])!=null?S:f[b]}));let w={};Object.keys(l).forEach(b=>{let S=b,C=ve(h,u[S].style[t?"min-width":"min-height"],i.extent);if(C){let N=C.evaluate(n);if(f[S]<N){let F=d[S]=new cu(l[S],u[S].style,t,h,r,N);w[S]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[o,s,a].forEach(b=>{f[b]=w[b]||f[b]}));let x=p.start+p.extent,y=p.start+(p.start+p.extent);[o,s,a].forEach(b=>{let S=f[b];if(S!=null){let C=l[b],N=0;switch(b){case o:N=t?C.left:C.top;break;case s:N=(y-S)/2;break;case a:N=x-S;break}t?C.setHorizontalPosition(N,S-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(N,S-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,o=e.end,s={};if(r){let a=[n,o],h=new Z0(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-u)/2,0);n&&(s.start=n.hasAutoSize()?d:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?d:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof bo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof bo&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},bo=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===v.auto||Z(o),this.minMaxFitContent=o instanceof de&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=s[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=sl(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},Z0=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},cu=class extends bo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),c(this,"fixedSize"),this.fixedSize=o}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},K0=class extends Fn{constructor(e,t){super(e,t),c(this,"borderBoxWidth",null),c(this,"borderBoxHeight",null),c(this,"contentBoxWidth",null),c(this,"contentBoxHeight",null),c(this,"marginTop",null),c(this,"marginRight",null),c(this,"marginBottom",null),c(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=i[s].toExpr(n,null),h=ve(n,t[s],a),l=ve(n,t[`margin-${r}`],a),u=ve(n,t[`margin-${o}`],a),d=St(n,t[`padding-${r}`],a),p=St(n,t[`padding-${o}`],a),f=Jt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Jt(n,t[`border-${o}-width`],t[`border-${o}-style`],a),m=te(n,te(n,f,d),te(n,g,p)),w,x,y;return h?(this.borderBoxSizing?(x=h,y=ge(n,x,m)):(y=h,x=te(n,y,m)),w=ge(n,a,x),!l&&!u?(l=to(n,w,new Qe(n,.5)),u=l):l?u=ge(n,w,l):l=ge(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=te(n,l,u),x=ge(n,a,w),y=ge(n,x,m),h=this.borderBoxSizing?x:y),t[r]=new G(l),t[o]=new G(u),t[`margin-${r}`]=Fe,t[`margin-${o}`]=Fe,t[`border-${r}-width`]=new G(f),t[`border-${o}-width`]=new G(g),t[`padding-${r}`]=new G(d),t[`padding-${o}`]=new G(p),t[s]=new G(h),t[`max-${s}`]=new G(h),{borderBoxExtent:x,contentBoxExtent:y,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},uf=class extends Fn{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new G(this.parentInstance.contentBoxWidth),e["margin-left"]=new G(new un(i,t.left.toExpr(i,null))),e["margin-right"]=new G(new un(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new G(this.parentInstance.contentBoxHeight),e["margin-top"]=new G(new un(i,t.top.toExpr(i,null))),e["margin-bottom"]=new G(new un(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},cf=class extends Fn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Fl[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){I(t,"display","flex"),I(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===M("middle")?n="center":i===M("top")?n="flex-start":i===M("bottom")&&(n="flex-end"),n&&I(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ut||r instanceof G&&r.expr instanceof Re&&r.expr.str.startsWith("running-element-")){let o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),I(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ve(n,i[s],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new G(u);else if(l){let d=St(n,i[`margin-${r}`],h),p=St(n,i[`margin-${o}`],h),f=St(n,i[`padding-${r}`],h),g=St(n,i[`padding-${o}`],h),m=Jt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Jt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),x=te(n,l,te(n,this.borderBoxSizing?n.zero:te(n,te(n,f,g),te(n,m,w)),te(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new G(te(n,u,$s(n,ge(n,h,x),new Qe(n,2))));break;case"end":i[r]=new G(ge(n,te(n,u,h),x));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,o=e.inside,s=e.outside,a=e.extent,h=t[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=ru(n,i[`margin-${o}`],h),u=ru(n,i[`margin-${s}`],h),d=St(n,i[`padding-${o}`],h),p=St(n,i[`padding-${s}`],h),f=Jt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=Jt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=ve(n,i[a],h),w=null;function x(y){if(w)return w;w={extent:m?m.evaluate(y):null,marginInside:l?l.evaluate(y):null,marginOutside:u?u.evaluate(y):null};let b=h.evaluate(y),S=0;return r||[f,d,p,g].forEach(C=>{C&&(S+=C.evaluate(y))}),(w.marginInside===null||w.marginOutside===null)&&S+w.extent+w.marginInside+w.marginOutside>b&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=b-S-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=b-S-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=b-S-w.extent-w.marginInside:w.marginInside=w.marginOutside=(b-S-w.extent)/2),w}i[a]=new G(new Re(n,function(){let y=x(this).extent;return y===null?"auto":y},a)),i[`margin-${o}`]=new G(new Re(n,function(){let y=x(this).marginInside;return y===null?"auto":y},`margin-${o}`)),i[`margin-${s}`]=new G(new Re(n,function(){let y=x(this).marginOutside;return y===null?"auto":y},`margin-${s}`)),o==="left"?i.left=new G(te(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new G(te(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,o,s){super.finishContainer(e,t,i,n,r,o,s);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof de&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let b=this.getProp(e,"margin-left"),S=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);I(t.element,"right",`${C}px`),(b===v.auto||S!==v.auto)&&I(t.element,"margin-left","auto"),S===v.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(S===v.auto||b!==v.auto)&&I(t.element,"margin-right","auto"),b===v.auto&&I(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof de&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,x=this.getPropAsNumber(e,"min-height"),y=this.getPropAsNumber(e,"max-height");if(w||x||y){w&&I(t.element,"height",w),x&&I(t.element,"min-height",`${x}px`),y&&I(t.element,"max-height",`${y}px`);let b=this.getProp(e,"margin-top"),S=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);I(t.element,"bottom",`${C}px`),(b===v.auto||S!==v.auto)&&I(t.element,"margin-top","auto"),S===v.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(S===v.auto||b!==v.auto)&&I(t.element,"margin-bottom","auto"),b===v.auto&&I(t.element,"margin-top","auto"))}}},J0=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,c(this,"pageMasterCache",{}),c(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ze(e,"page-number"),r=new Ja(e,new Ku(e,n,new Qe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new xi(e,r)),e.defineName("verso-page",r),(t.pageProgression||af(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new xi(e,r))):(e.defineName("left-page",new xi(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),r=this.pageMasterCache[n];return r||(i.pseudoName===Tl?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof V?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new hf(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Rl}),n=i.specified,r=e.size;if(r&&!Z(r.value)){let s=Xo(e),a=r.priority;Gt(n,"width",new V(s.width,a),this.context),Gt(n,"height",new V(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(e[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},Q0=class extends ke{constructor(e){super(),this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},ex=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},tx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},ix=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},nx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},rx=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},ox=class extends ke{constructor(e){super(),this.scope=e}apply(e){new Ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},sx=class extends qi{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},ax=class extends qi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},lx=class extends ml{constructor(e,t){super(e,t,null,null,null)}apply(e){hx(e.context,e.currentStyle,this.style,this.specificity,e)}};function hx(e,t,i,n,r){_o(e,t,i,n,null,null,null);let o=i[Sr];if(o){let a=ei(t,Sr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),_o(e,l,o[h],n,null,null,null)}}let s=i[qo];if(s){let a=ei(t,qo);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=s[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof V&&Gt(l,p,f)}let d=gt(u,"_pseudos");if(d){let p=ei(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=d[f];for(let w in m)if(m.hasOwnProperty(w)){let x=m[w];x instanceof V&&Gt(g,w,x)}}}}}}var ux=class extends wr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new Q0(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new ax(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new sx(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new ex(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new tx(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new ix(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new nx(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new rx(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new ox(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(o=>o.selectors===null))return;super.simpleProperty(e,t,i);let n=me(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{Ci(r[o],e,n)});else if(e==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=new V(n.value,n.priority+s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?Gt(l,e,a):(l=r[h]={},Ci(l,e,a),o&&["bleed","marks"].forEach(u=>{o[u]&&Ci(l,u,o[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new lx(this.elementStyle,e)}startFootnoteRule(e){let t=ei(this.elementStyle,qo),i=t.area;if(i||(i={},t.area=i),e){let r=ei(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new df(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=ei(this.elementStyle,Sr),i=t[e];i||(i={},t[e]=i);let n=new cx(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},cx=class extends Xi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(t,n);Ci(this.boxStyle,e,r)}},df=class extends Xi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(t,n);Ci(this.areaStyle,e,r)}},pf=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,c(this,"lang",null),c(this,"totalOffset",-1),c(this,"root"),c(this,"body"),c(this,"head"),c(this,"last"),c(this,"lastOffset",1),c(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Zt,"0")}doc(){return new gf([this.document])}getElementOffset(e){let t=e.getAttribute(Zt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(Zt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=ai(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},za=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(za||{});function Kr(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let o=r.documentElement,s="parsererror";if(o.localName===s)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===s)return null}else return null;return r}function dx(e){let t=e.contentType;if(t){let n=Object.keys(za);for(let r=0;r<n.length;r++)if(za[n[r]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function ff(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=dx(e);if(i=Kr(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Kr(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Kr(o,"image/svg+xml",r))}i||(i=Kr(o,"text/html",r))}}let n=i?new pf(t,e.url,i):null;return T(n)}function px(){return new il(ff,"document")}var fx=class Va{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Va(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Va(n=>{if(!this.check(n))return!1;let r=new gf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},du=new fx(e=>!0),gf=class Ua{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Ua(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new Ua(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},gx=new Ar(()=>{let e=D("uaStylesheetBase"),t=qp(),i=Ie("user-agent-base.css",vi),n=new wr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),iv(n.cascade),nl(Uc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function mx(){return gx.get()}var wx=class extends so{constructor(e,t,i,n,r,o){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=o}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||j.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},yx=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=o,this.footnoteProps=s,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,c(this,"fontDeobfuscator"),c(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Re(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Re(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Vs(this.rootScope,e,t,i),o=ky(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let u=Wt.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=u/i,i=u,e*=l,t*=l),s&&a){let d=at(s.evaluate(r,"width"),r),p=at(a.evaluate(r,"height"),r);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function pu(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function fu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var Ll=class extends Vs{constructor(e,t,i,n,r,o,s,a,h,l,u,d,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=o,this.customRenderer=s,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=u,this.cmykStore=d,c(this,"lang"),c(this,"primaryFlows",{body:!0}),c(this,"rootPageBoxInstance",null),c(this,"styler",null),c(this,"stylerMap",null),c(this,"currentLayoutPosition",null),c(this,"layoutPositionAtPageStart",null),c(this,"currentCascadedPageStyle",null),c(this,"lookupOffset",0),c(this,"faces"),c(this,"pageBoxInstances",{}),c(this,"pageManager",null),c(this,"rootPageFloatLayoutContext"),c(this,"pageBreaks",{}),c(this,"pageProgression",null),c(this,"isVersoFirstPage",!1),c(this,"blankPageAtStart",!1),c(this,"pageSheetSize",{}),c(this,"pageSheetHeight",0),c(this,"pageSheetWidth",0),c(this,"semanticFootnoteFirstRefOffsets",new Map),c(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),c(this,"pageGroupPageCounts",Object.create(null)),c(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new f0(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new ln(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=me(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=D("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Jh(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=af(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new B0(r);let o=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new J0(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let s=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=p0(h.properties,this),u=new Yp(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{v0(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l);let u=uu(Xo(l),this);this.pageSheetSize[h]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Vs(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Jh(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,o,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new jw,i.flowPositions[e.flowName]=n);let r=Hw(e.element),o=new Ei(r),s=new Gw(o,e);n.positions.push(s)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class r{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let o=new r,s=Rr(this.style.rootScope,new Vt(t,null),"");return s?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,s,!1,o),n):!1}evalSupportsSelector(e){class t extends mf{errorMsg(...s){}}let i=new t(null),n=Pc(e),r=new Vt(n+"{}",i);return new Fr(ze,r,i,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!i.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,r=n.steps[0].node,o=n.offsetInNode,s=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,s=!1,o=0;let h=this.xmldoc.getNodeOffset(r,o,s);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let o=0;o<r.positions.length;o++){let s=r.positions[o].chunkPosition.primary,a=this.getNodePositionOffset(s);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,o=t<=r,s=n===i&&o?this.getFirstInFlowChildElement(i):n;if(!s)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(s),h=t;return o&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(s)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(s)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),o=t<=r;return n===i&&o?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return qe(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=me(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=me(e,"page");if(!t)return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),o=this.xmldoc.body||this.xmldoc.root,s=this.xmldoc.getElementOffset(o);if(i<=s&&e===o||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),o=Nn(i)&&!this.matchPageSide(i)&&!r,s=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!o,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&s;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let d=h;for(;d;){let p=this.getPageGroupPageType(d);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(d)||0;(g>0||s&&(u||this.shouldStartPageGroup(d,p,a)))&&(g+=1,f.set(d,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(d===this.xmldoc.root)break;d=d.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Le(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!Z(r)?r:v.static;if(To(o)||is(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!Z(s)?s:v.none)===v.none}isInlineLevelElement(e){return Ht(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!Z(n)?n:v.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let o=this.getConsumedOffset(r);o<i&&(i=o)}}return i}dumpLocation(e){j.debug("Location - page",this.currentLayoutPosition.page),j.debug(" current:",e),j.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)j.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ze(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,o=i.startBreakType;i.startBreakType=kh(tt(o,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let o=0;o<n.length;o++){if(r=n[o],r.pageBox.pseudoName===Rl)continue;let s=1;r.pageBox.pseudoName===Tl&&!(this.actualPageWidth&&this.actualPageHeight)&&(s=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(s=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(s*l/(h*h)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===v._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let o=ai(r.length,l=>r[l]>n)-1,s=r[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return s<h?!1:h<s?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new cl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new ln(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Te.PAGE)return!1;let d=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},o=D("layoutDeferredPageFloats"),s=!1,a=0;return o.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let d=new Tn().findByFloat(u),p=d.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,d,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(s=!0,t.validate());h.continueLoop()})}).then(()=>{s&&t.invalidate(),o.finish(!0)}),o.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Ei(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return i?(this.setFormattingContextToColumn(e,t),e.init(),this.layoutDeferredPageFloats(e)):T(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=D("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],o=[],s=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-o.length>0;){let h=0;for(;o.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(o.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,s,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(s=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){o.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-o.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=kh(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{var a;if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,u)=>r.includes(u)||!o.includes(u)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let h=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(h),e.computedBlockSize===0){let l=e.pageFloatLayoutContext,u=l;for(;u;){let d=u.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(d.length>0&&!u.ignoreFootnoteAreaMaxHeight&&d.some(p=>{let f=getComputedStyle(p.area.element),g=m=>m!==""&&m!=="none";return g(f.getPropertyValue("max-block-size"))||g(p.area.vertical?f.maxWidth:f.maxHeight)})){u.ignoreFootnoteAreaMaxHeight=!0;for(let p of d){l.removePageFloatFragment(p,!0);let f=(a=p.continuations[0])==null?void 0:a.float;f&&u.removeFloatDeferredToNext(f)}l.invalidate();break}u=u.parent}}}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new kv([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,u,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,m=r.element,w=new ln(a,Te.COLUMN,null,s,null,null,null),x=this.currentLayoutPosition.clone(),y=D("createAndLayoutColumn"),b;return y.loopWithFrame(S=>{let C=this.createLayoutConstraint(w);if(h>1){let N=this.viewport.document.createElement("div");if(I(N,"position","absolute"),m.appendChild(N),b=new Vo(N,p,this.clientLayout,C,w),b.isNonFirstColumn=o>0,b.forceNonfitting=f,b.vertical=r.vertical,b.rtl=r.rtl,b.snapHeight=r.snapHeight,b.snapWidth=r.snapWidth,r.vertical){let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingTop,B=parseFloat(m.style.width);b.setHorizontalPosition(r.paddingLeft+B-r.width,r.width),b.setVerticalPosition(F,u)}else{let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingLeft;b.setVerticalPosition(r.paddingTop,r.height),b.setHorizontalPosition(F,u)}b.originX=t,b.originY=i}else b=new Vo(m,p,this.clientLayout,C,w),b.isNonFirstColumn=!1,b.copyFrom(r);b.exclusions=g?[]:n.concat(),b.innerShape=d,w.setContainer(b),(b.vertical?b.height:b.width)>=0?this.layoutColumn(b,s).then(()=>{w.isInvalidated()||w.finish(),b.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(b.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),b.element!==m&&m.removeChild(b.element),S.continueLoop()):S.breakLoop()}):(w.finish(),S.breakLoop())}).then(()=>{y.finish(b)}),y.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof uf||t instanceof Il&&!(t instanceof Cn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Fn;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new ln(e,Te.REGION,i,n,null,r,o)}layoutFlowColumnsWithBalancing(e,t,i,n,r,o,s,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(o,t,s,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,u,s,a,h,d).thenAsync(f=>T(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return T(null);if(h<=1)return T(f.columns);let g=t.getProp(this,"column-fill")||v.balance,m=this.currentLayoutPosition.flowPositions[a],w=db(h,g,p,u,s,f.columns,m);return w?(d=!1,o.lock(),u.lock(),w.balanceColumns(f).thenAsync(x=>(o.unlock(),o.validate(),u.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(f.columns)})}layoutFlowColumns(e,t,i,n,r,o,s,a,h,l,u){let d=D("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=pu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),y=Sc(x,0,0,a.width,a.height,this),b=new N0(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),S=0,C=null,N=[];return d.loopWithFrame(F=>{this.createAndLayoutColumn(t,i,n,r,a,S++,h,s,l,g,m,y,b,u).then(B=>{if(o.isInvalidated()){N=null,F.breakLoop();return}if((B.pageBreakType&&B.pageBreakType!=="column"||S===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){S=0,this.currentLayoutPosition=p.clone(),fu(f),s.validate(),s.isLocked()?(N=null,F.breakLoop()):F.continueLoop();return}C=B,N[S-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(S=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?F.continueLoop():F.breakLoop()})}).then(()=>{d.finish(N)}),d.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return T(!0);let h=D("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof cf?"complementary":"presentation";let p=t.getProp(this,"position");I(d,"position",p?p.name:"absolute");let f=t instanceof Cn;t instanceof Fn?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new Cd(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=o,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof Cn&&(g.width<=0||g.height<=0)&&j.warn("Negative or zero page area size"),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(s,t,g);let m,w=!1;if(!u||!u.isIdent()){let x=[],y=t.getProp(this,"content");if(y instanceof G&&y.expr instanceof Re&&y.expr.str.startsWith("running-element-"))y.visit(new gr(d,this,y,this.counterStore.getExprContentListener()));else if(kt(y)){let b="span";y instanceof ut&&(b="img");let S=this.viewport.document.createElement(b);y.visit(new gr(S,this,y,this.counterStore.getExprContentListener())),d.appendChild(S),b=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces);let C=S.querySelectorAll("img[src]");for(let F=0;F<C.length;F++){let B=C[F],U=B.getAttribute("src");if(!U)continue;let q=vt(B,U);x.push(q),e.fetchers.push(q)}let N=S.getAttribute("src");if(N){let F=S.querySelector("img");F||(F=S);let B=vt(F,N);x.push(B),e.fetchers.push(B)}b=="span"&&mv(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(d),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=x.length?En(x).thenReturn(!0):T(!0)}else if(this.pageBreaks[u.toString()])s.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=T(!0);else{let x=D("layoutContainer.inner"),y=u.toString(),b=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,y,b).then(S=>{if(!s.isInvalidated()){let C=S[0];C.element===d&&(g=C),g.computedBlockSize=Math.max.apply(null,S.map(F=>F.computedBlockSize)),t.finishContainer(this,g,e,C,b,this.clientLayout,this.faces);let N=this.currentLayoutPosition.flowPositions[y];N&&N.breakAfter==="region"&&(N.breakAfter=null)}x.finish(!0)}),m=x.result()}return m.then(()=>{if(s.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let y=t.getProp(this,"shape-outside"),b=g.getOuterShape(y,this);o.push(b)}}else if(t.children.length==0){i.removeChild(d),h.finish(!0);return}let x=f?0:t.children.length-1;h.loop(()=>{for(;x>=0&&x<t.children.length;){let y=t.children[f?x++:x--],b=this.layoutContainer(e,y,d,n,r,o,s);if(b.isPending())return b.thenAsync(()=>T(!s.isInvalidated()));if(s.isInvalidated())break}return T(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i,n,r,o;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Xw,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let a=1e4;if(t.page>a)throw new Error(`Too many pages generated (over ${a} pages)`);let h=t.startSideOfFlow("body");t.isBlankPage=Nn(h)&&this.matchPageSide(h),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=pu(t),u=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!s){let x=new Ze(this.style.pageScope,"left-page");e.side=x.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let d=this.selectPageMaster(u);if(!d)return T(null);let p=0;if(!s){e.setAutoPageWidth(d.pageBox.specified.width.value===Pr),e.setAutoPageHeight(d.pageBox.specified.height.value===Nr);let{counterOffset:x,changeOffset:y}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(x)||(x=this.lookupOffset,y=this.lookupOffset),isFinite(x)&&this.styler.styleUntil(x,0);let b=this.styler.getCounterSnapshotAtOffset(x),S=y===x?b:this.styler.getCounterSnapshotAtOffset(y);b||(b=this.styler.getLastCounterSnapshot()),S||(S=b),this.counterStore.setCurrentPageDocCounters((r=b?.counters)!=null?r:null,(o=S?.changes)!=null?o:null,S?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let C=uu(Xo(u),this);this.setPageSizeAndBleed(C,e),G0(u,C,e,this),p=C.bleedOffset+C.bleed}let f=!s&&d.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=f!=v.horizontal_tb;let g=d.getProp(this,"direction")||v.ltr,m=new ln(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,f,g),w=D("layoutNextPage");return w.loopWithFrame(x=>{this.layoutContainer(e,d,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),fu(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);x.continueLoop()}else x.breakLoop()})}).then(()=>{d.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(y=>{let b=t.flowPositions[y],S=b.breakAfter;S&&(S==="page"||!this.matchPageSide(S))&&(b.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let x=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(x,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},vx=class $a extends wr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Jp(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new D0(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Mt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new $a(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new lv(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new so(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new wx(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new so(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new so(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ei(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new df(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new ux(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(wr.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",M(t)),this.endRule();let i=new $a(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},mf=class extends Ks{constructor(e){super(),this.validatorSet=e,c(this,"rootScope"),c(this,"pageScope"),c(this,"rootBox"),c(this,"cascadeParserHandler"),c(this,"regionCount",0),c(this,"fontFaces",[]),c(this,"counterStyles",new Xb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new zs(null),this.pageScope=new zs(this.rootScope),this.rootBox=new F0(this.rootScope),this.cascadeParserHandler=new vx(this,null,null,null),this.slave=this.cascadeParserHandler}};function bx(e,t){return t.parseOPSResource(e)}var xx=class extends il{constructor(e){super(bx,"document"),this.fontDeobfuscator=e,c(this,"styleByKey",{}),c(this,"styleFetcherByKey",{}),c(this,"styleByDocURL",{}),c(this,"triggersByDocURL",{}),c(this,"validatorSet",null),c(this,"styleSheets",[]),c(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=D("OPSDocStore.init");return this.validatorSet=qp(),mx().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ie(yn(t),Ui)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ie(yn(t),Ui)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=D("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return ff(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Dt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){j.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),x=f.getAttribute("ref");g&&m&&w&&x&&s.push({observer:g,event:m,action:w,ref:x})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ie("user-agent-page.css",vi),text:Vc,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-counter-styles.css",vi),text:Wc,flavor:"UA",classes:null,media:null}),n)h.push({url:Ie("user-agent-toc.css",vi),text:$c,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),x=f.getAttribute("media"),y=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:y?w:null,media:x})}else if(m=="link"){let w=f.getAttribute("href"),x=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),y=f.getAttribute("class"),b=f.getAttribute("media");if(w&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||y)){let S=Ie(w,i),C=f.getAttribute("title");h.push({url:S,text:null,classes:C?y:null,media:b,flavor:"Author"})}}else m=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new Ar(()=>{let p=D("fetchStylesheet"),f=0,g=new mf(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?nl(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Kc(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new yx(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},cr="\u25B8",gu="\u25BE",Sx="\u25B9";function Ol(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function Cx(e){let t=Ol(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var kx=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=s,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=Vu(o),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;mi(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),mi(n,"position","static")=="absolute"&&(I(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Fe,r.padding=Fe,r["padding-inline-start"]=new R(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new R(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Fe;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Le(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=cr&&(l.textContent=cr,I(l,"cursor","pointer"),l.addEventListener("click",Ex,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),o.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Sx,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return T(h)}}showTOC(e,t,i,n,r){if(this.page)return T(this.page);let o=D("showTOC"),s=new fd(e,e);this.page=s;let a=Bt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Ol(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new jo(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(h),p=new Ll(l,h,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(e,2),o.finish(s)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Ex(e){let t=e.target,i=t.textContent==cr;t.textContent=i?gu:cr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==gu){a.textContent=cr,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Jr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Px(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function Nx(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Bt(e))}var mu=class extends xx{constructor(){super(null),c(this,"plainXMLStore"),c(this,"jsonStore"),c(this,"opfByURL",{}),c(this,"primaryOPFByEPubURL",{}),c(this,"deobfuscators",{}),c(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=px(),this.jsonStore=iw()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new xo(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=D("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):Nx(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):es(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}j.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=D("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of r)if(o){this.loadOPF(e,o).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return T(n);let r=D("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new xo(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(s=>{n.initWithXMLDoc(o,s).then(()=>{r.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=D("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new xo(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=ja(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ie(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&Ol(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=D("EPUBDocStore.load"),n=Bt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(Ui)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?j.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Ui.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?j.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?j.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):j.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Bt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=D("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let r=i.width-0,o=i.height-0;if(r&&o){let s=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${o}px;}`+(s?`@page{size:${r}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},wu=class{constructor(){c(this,"id",null),c(this,"src",""),c(this,"mediaType",null),c(this,"title",null),c(this,"itemRefElement",null),c(this,"spineIndex",-1),c(this,"compressedSize",0),c(this,"compressed",null),c(this,"epage",0),c(this,"epageCount",0),c(this,"startPage",null),c(this,"skipPagesBefore",null),c(this,"itemProperties"),this.itemProperties=eg}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ie(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=ag(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function Tx(e){return e.id}function Ix(e){return t=>{let i=D("deobfuscator");return Ax("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Qm(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Gc([a,o]))})}),i.result()}}function Ax(e,t){let i=D("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var yi={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},er="http://idpf.org/epub/vocab/package/meta/#",je={language:`${yi.dcterms}language`,title:`${yi.dcterms}title`,creator:`${yi.dcterms}creator`,layout:`${yi.rendition}layout`,titleType:`${er}title-type`,displaySeq:`${er}display-seq`,alternateScript:`${er}alternate-script`,role:`${er}role`};function Fx(e,t){let i={};return(n,r)=>{var o,s,a,h,l,u;let d,p,f=n.r||i,g=r.r||i;if(e==je.title&&(d=((o=f[je.titleType])==null?void 0:o[0].v)=="main",p=((s=g[je.titleType])==null?void 0:s[0].v)=="main",d!=p))return d?-1:1;let m=parseInt((a=f[je.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[je.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=je.language&&t&&(d=((l=f[je.language]||f[je.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[je.language]||g[je.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function Rx(e,t){let i;if(!t)i=yi;else{i={};for(let p in yi)i[p]=yi[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:er;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:yi.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),s=ws(o,d=>d.refines),a=d=>lg(d,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=s[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:je.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:je.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=ws(w,y=>y.name);m.r=a(x)}return m})),h=a(ws(o,d=>d.refines?null:d.name)),l=null;h[je.language]&&(l=h[je.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(Fx(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function Lx(){let e=window.MathJax;return e?e.Hub:null}var yu={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Ms="viv-id-",xo=class{constructor(e,t){this.store=e,this.pubURL=t,c(this,"opfXML",null),c(this,"encXML",null),c(this,"items",null),c(this,"spine",null),c(this,"itemMap",null),c(this,"itemMapByPath",null),c(this,"uid",null),c(this,"bindings",{}),c(this,"lang",null),c(this,"epageCount",0),c(this,"prePaginated",!1),c(this,"epageIsRenderedPage",!0),c(this,"epageCountCallback",null),c(this,"metadata",{}),c(this,"toc",null),c(this,"cover",null),c(this,"fallbackMap",{}),c(this,"pageProgression",null),c(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let o=r+(n?`#${n}`:"");return Ms+_u(o,":")}transformURL(n,r){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let s=o[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(o[2]);if(s&&e.spine.some(h=>h.src===s))return`#${this.transformFragment(a,s)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Ms)===0&&(n=n.substring(Ms.length));let r=sg(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ie("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new wu,u=h;l.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!yu[l.mediaType]&&(r[l.src]=d),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Xl(this.items,Tx),this.itemMapByPath=Xl(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(yu[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=Tu(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(du.withChild("EncryptionMethod",du.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=Rx(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[je.language]&&(this.lang=this.metadata[je.language][0].v),this.metadata[je.layout]&&(this.prePaginated=this.metadata[je.layout][0].v==="pre-paginated"),s.length>0&&this.uid){let h=Ix(this.uid);for(let l=0;l<s.length;l++)this.store.deobfuscators[this.pubURL+s[l]]=h}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let t=0,i=0,n=D("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(s=>{let a=1800,h=s.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(s.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new pf(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new wu;r.initWithParam(n),r.id;let o=i.document.createElement("itemref");o.setAttribute("idref",r.id),i.root.appendChild(o),r.itemRefElement=o,this.itemMap[r.id]=r;let s=this.getPathFromURL(n.url);s==null&&(s=n.url),this.itemMapByPath[s]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):T(null)}initWithWebPubManifest(e,t,i){var n,r,o,s;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[je.title]=(Array.isArray(a)?a:[a]).map(x=>{var y;return{v:(y=x.value)!=null?y:x}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(x=>x.content);h&&h.length!==0&&(this.metadata[je.creator]=(Array.isArray(h)?h:[h]).map(x=>{var y;return{v:(y=x.name)!=null?y:x}}));let l=e.inLanguage||((s=e.metadata)==null?void 0:s.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[je.language]=(Array.isArray(l)?l:[l]).map(x=>({v:x})));let u=Bt(this.pubURL),d=this.getPathFromURL(u),p=d!==null?encodeURI(d):/^(?:about:|blob:)/i.test(u)?u:null;if(!e.readingOrder&&t&&p!==null){e.readingOrder=[p];for(let x of Cx(t)){let y=x.getAttribute("href");if(/^(https?:)?\/\//.test(y)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(y))continue;let b=Bt(Ie(y,this.pubURL)),S=this.getPathFromURL(b),C=S!==null?encodeURI(S):b;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,m=-1;[e.readingOrder,e.resources].forEach(x=>{x instanceof Array&&x.forEach(y=>{let b=x===e.readingOrder,S=typeof y=="string"?y:y.url||y.href,C=typeof y=="string"?"":y.encodingFormat||y.href&&y.type||"";if(b||C==="text/html"||C==="application/xhtml+xml"||!C&&y.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(S)){let N=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,F={url:Ie(yn(S),N),index:g++,startPage:null,skipPagesBefore:null};y.rel==="contents"&&m===-1&&(m=F.index),f.push(F)}})});let w=D("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var x,y;m!==-1&&(this.toc=this.items[m]),this.toc||(this.toc=i?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[d]);let b=(y=e.readingOrder)==null?void 0:y.length;b&&b<this.items.length&&this.items.splice(b),w.finish(!0)}),w.result()}getCFI(e,t){let i=this.spine[e],n=D("getCFI");return this.store.load(i.src).then(r=>{let o=r.getNodeByOffset(t),s=null;if(o){let a=r.getNodeOffset(o,0,!1),h=t-a,l=new sh;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),s=l.toString()}n.finish(s)}),n.result()}resolveFragment(e){return kn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new sh;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let o=r.node,s=o.getAttribute("idref");if(o.localName!="itemref"||!s||!this.itemMap[s]){t.finish(null);return}n=this.itemMap[s],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let o=i.navigate(r.document),s=r.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:s,pageIndex:-1})})},(t,i)=>{j.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return kn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let o=this.spine[r];(!o||o.epageCount==0)&&(o=this.spine[--r]);let s=Math.floor(e-o.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:s});return}let i=ai(this.spine.length,r=>{let o=this.spine[r];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let s=r.getTotalOffset();o=Math.round(s*e/n.epageCount),o==s&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{j.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return T(n)}if(e.offsetInItem<=0)return T(t.epage);let i=D("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),o=Math.min(r,e.offsetInItem);i.finish(t.epage+o*t.epageCount/r)}),i.result()}},Qr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),Ox=class{constructor(e,t,i,n,r,o){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"cmykStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),c(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=Vu(n),this.clientLayout=new I0(t),this.counterStore=new em(e.documentURLTransformer),this.cmykStore=new fc,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return T(!0);let i=D("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<e;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(e=n[r])!=null?e:0;t+=Math.min(o,s)}return t}reportPaginationProgress(e,t){let i=Dt("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),o=r;t&&(o=e.instance.getPosition(t,!0)),o<0&&(o=0),o>r&&(o=r);let s=this.paginationProgress.renderedOffsetsBySpine[n];s!=null&&o<s&&(o=s),this.paginationProgress.renderedOffsetsBySpine[n]=o;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let d={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(d)}catch(f){j.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,u=n.offset!==t.offset,d=s&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,!s&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||o)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Jr(n));let r=Jr(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return T(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let o=e.pages[t.page],s=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||s,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,o,a,s,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=D("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),s=0,a=t;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let d=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:d.currentPageType,previousPageType:d.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=Px(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,x=u.instance.scopes;u.instance.scopes={};let y=l.pageIndex<u.pages.length-1,b=!!u.pages[l.pageIndex]&&y,S=b?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let C=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,C).then(N=>{b&&u.instance.endIsolatedRootPageFloatLayoutContext(S);let F=d.currentPageType;d.currentPageType=f.currentPageType,d.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=x;let B=Jr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),N.pageAndPosition.position.spineIndex===a.spineIndex&&N.pageAndPosition.position.pageIndex===i&&(a=N.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&F!==N.pageAndPosition.page.pageType&&(d.currentPageType=a.pageType);let U=u!==e,q=u.pages.length,he=u.layoutPositions[q],ae=u.instance.hasActiveRootPageFloatLayoutContext();if(he&&!ae){let k=U?Jr(this.counterStore.currentPageCounters):null;U&&(this.counterStore.currentPageCounters=B);let _=q;this.renderSinglePage(u,he).then(()=>{U&&this.markSpineItemCompleteIfReady(u);let E=u.pages.length-_;if(U&&E>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,E),this.counterStore.updateTargetCounterNodesInPages(u.pages);let L=u.item.spineIndex;for(let P=L+1;P<this.spineItems.length;P++){let A=this.spineItems[P];if(A){A.item.epage+=E;for(let O of A.pageCounterStarts)O!=null&&O.page&&(O.page=O.page.map(z=>z+E));this.counterStore.updatePageCounterNodesInPages(A.pages,A.pageCounterStarts)}}if(k){let P=k.page;P&&(k.page=P.map(A=>A+E))}}k&&(this.counterStore.currentPageCounters=k),h.continueLoop()});return}U&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=D("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),o=this.preparePageCountersForRender(e,n),s=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,o,s,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,o,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(d=>{i.finish({pageAndPosition:Qr(d,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=ai(t.layoutPositions.length,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=D("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(Qr(r,o))})})}),i.result()}renderPage(e){let t=D("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){t.finish(Qr(s,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){s=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){t.finish(Qr(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=D("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=D("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,o=0;t&&(o=n);let s;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=D("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return T(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return T({left:null,right:null});let n=D("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(s=>{let a=this.getPage(e),h=s&&s.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,t);return s.thenAsync(a=>a?s:r)}else return T(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,t):T(null)):r}navigateToEPage(e,t,i){let n=D("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=D("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!bt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ie(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!_t(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ie(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){j.debug("Navigate to",e);let n=this.opf.getPathFromURL(Bt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let s=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],e=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return T(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=e.indexOf("#");if(s>=0)return this.navigateToFragment(e.substr(s+1),t,i)}return T(null)}let o=D("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",dr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new fd(n,r);if(o.spineIndex=e.item.spineIndex,o.position=t,o.offset=e.instance.getPosition(t),o.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=Uu(this.viewport.width,this.viewport.height,i.width,i.height),a=Rr(null,new Vt(s,null),"");o.delayedItems.push(new al(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ie(r,e.url);let s=t.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=Gl(r),l=Gl(s),u=new si;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),u.append("="),u.append(encodeURIComponent(w)))}}o.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&o.setAttribute("width",d);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",pr(r)),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=Lx();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=D("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(s)}),l.result()}return T(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ie(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):T(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return T(null);let t=this.spineItems[e];if(t)return T(t);let i=D("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),u=this.makeCustomRenderer(s),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new jo(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let b=g&&g.pageCounterStarts[g.pages.length-1],S=b&&b.page;if(S&&S.length)w=S[S.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?m:C[C.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let x=new Ll(l,s,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);x.pref=this.pref;let y=this.opf.metadata&&this.opf.metadata[je.title];x.pubTitle=y&&y[0]&&y[0].v||"",x.docTitle=r.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),t={item:r,xmldoc:s,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(b=>{b.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let n=D("showTOC");this.tocView||(this.tocView=new kx(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),dr||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},vu="data-vivliostyle-viewer-status",Bx="data-vivliostyle-spread-view",wf=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(wf||{}),Mx=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,c(this,"fontMapper"),c(this,"kick"),c(this,"sendCommand"),c(this,"resizeListener"),c(this,"hyperlinkListener"),c(this,"pageRuleStyleElement"),c(this,"pageSheetSizeAlreadySet",!1),c(this,"renderTask",null),c(this,"actions"),c(this,"readyState"),c(this,"packageURL"),c(this,"opf"),c(this,"touchActive"),c(this,"touchX"),c(this,"touchY"),c(this,"needResize"),c(this,"resized"),c(this,"needRefresh"),c(this,"viewportSize"),c(this,"currentPage"),c(this,"currentSpread"),c(this,"pagePosition"),c(this,"fontSize"),c(this,"zoom"),c(this,"fitToScreen"),c(this,"pageViewMode"),c(this,"waitForLoading"),c(this,"renderAllPages"),c(this,"pref"),c(this,"pageSizes"),c(this,"pixelRatio"),c(this,"pixelRatioLimit"),c(this,"viewport"),c(this,"opfView"),c(this,"cmykReserveMap"),c(this,"cmykReserveMapUrl");let r=t.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",Mc),o("vivliostyle-viewport-css",_c),o("vivliostyle-polyfill-css",Hc),t.setAttribute("data-vivliostyle-viewer-viewport",!0),dr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(vu,"loading"),this.fontMapper=new g0(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=s=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=zu(),this.pageSizes=[],this.pixelRatioLimit=Ga==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Fu;j.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),j.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),j.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),j.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(vu,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){xt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=D("loadPublication");return this.configure(e).then(()=>{let s=new mu;s.init(n,r).then(()=>{let a=Ie(yn(t),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(e){xt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,o=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=D("loadXML");return this.configure(e).then(()=>{let a=new mu;a.init(r,o).then(()=>{let h=t.map((l,u)=>({url:Ie(yn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new xo(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,T(!0))):t=T(!0),t.thenAsync(()=>(xt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let o=Wt[r];if(o)return t*o}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&($l(e.userAgentRootURL.replace(/resources\/?$/,"")),Hl(e.userAgentRootURL)),typeof e.rootURL=="string"&&($l(e.rootURL),Hl(`${Ui}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==hi&&(m0(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),T(!0)}configurePlugins(e){Dt("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=D("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?En(i.fetchers):T(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new jo(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new jo(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return e!=null&&(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(Bx,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let m=g*.75;return Math.ceil(m)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),u=s(h),d=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,T(!0);let t=Ie(yn(this.cmykReserveMapUrl),Ui),i=D("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Ig(n)?this.cmykReserveMap=n:(j.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new Ox(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?T(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,T(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new bu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Ys().getScheduler().run(()=>kn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,xt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),xt.registerEndTiming("render (resize)"),hi&&Kp(this.window)?b0(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof bu)xt.registerEndTiming("render (resize)"),j.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=D("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return T(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=D("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=D("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=T(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return T(!0)}else if(i=="hide")return T(!0);if(n&&i!="show")return this.opfView.hideTOC(),T(!0);{let o=D("showTOC");return this.opfView.showTOC(t).then(s=>{if(s){if(r&&(s.listeners={}),t){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return kn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(j.error("No such action:",t),i.finish(!0))},(i,n)=>{j.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=xu(e),i=null,n=this;Xm(()=>{let r=D("commandLoop"),o=Ys().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),T(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=D("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=xu(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},yf=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(yf||{}),bu=class vf extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,vf.prototype),this.stack=new Error().stack}};function xu(e){return typeof e=="string"?ja(e):e}var Su=Wa;function _x(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Cu(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var bf=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),Nu(e.debug),this.adaptViewer_=new Mx(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=_x(),t&&this.setOptions(t),this.eventTarget=new qa,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Cu(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function o(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Dx(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Cu(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===Su.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Su.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function Dx(e){function t(n){return typeof n=="number"?n:null}function i(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(e)?e.map(i):e?[i(e)]:null}var xf=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(xf||{}),zx=yf,Vx=wf;xt.forceRegisterEndTiming("load_vivliostyle");var Ux=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){c(this,"htmlDoc"),c(this,"title"),c(this,"printCallback"),c(this,"errorCallback"),c(this,"hideIframe"),c(this,"removeIframe"),c(this,"iframe"),c(this,"iframeWin"),c(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1871
+ `),i.toString()}},rx=class{constructor(e){this.deobfuscator=e,d(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof rt){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(M(r)),i.push(n)}return new rt(i)}else{let t=this.familyMap[e.stringValue()];return t?new rt([M(t),e]):e}}},ox=class{constructor(e,t,i){this.head=e,this.body=t,d(this,"srcURLMap",{}),d(this,"familyPrefix"),d(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=D("initFont"),r=e.src,o={};for(let l of Zl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=M(s);let a=new Lf(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),j.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{t.registerFamily(e,o),j.debug("Found already-loaded font:",i)}):(r=new Vr(()=>{let o=D("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?Es(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(o)})}):this.initFont(e,null,t).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){j.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return Rn(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return T(!0);let i=D("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},mi=!0;function sx(e){mi=e}var ji=[];function Iu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Of(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 Kl(e,t,i){if(!mi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Of(e.ownerDocument).includes(e))return T(!1);let n=e.textContent,r=e.src,o=e.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&e.async&&!s,h=(o&&!a||r&&e.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Bf(t)||(t.onload=null),l)return ji.some(c=>Iu(c,e))||ji.push(e),T(!0);for(let c of t.document.head.getElementsByTagName("script"))c.hasAttribute("data-vivliostyle-scripting")&&Iu(c,e)&&t.document.head.removeChild(c);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=h,u.setAttribute("data-vivliostyle-scripting","true");for(let c of e.attributes)["src","async","defer"].includes(c.name)||u.setAttribute(c.name,c.value);if(j.debug("script:",r),r){let c=Ct(u);return t.document.head.appendChild(u),Rn([c])}else return t.document.head.appendChild(u),T(!0)}function ax(e,t){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let u of Object.values(l))r(u)},o=s=>{if(s instanceof Hl)r(s.style);else if(s instanceof Wn||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(t.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of e.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function lx(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=ax(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function hx(e,t,i){if(!mi)return T(!1);let n=Of(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?lx(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=D("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var c,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(c=t.FontJSON)!=null&&c.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Kl(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(ji.push(u),h=!0),n.length===0&&r&&(j.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function ux(e){if(!mi)return T(!1);let t=D("loadScripts");return t.loop(()=>ji.length===0?T(!1):Kl(ji.shift(),e,{atEnd:!0}).thenReturn(ji.length>0)).then(()=>{j.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),j.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Bf(e){return mi?ji.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var cx=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,pl),dx=e=>`"${cx(e)}"`,ua=(e,t,i)=>dx(i.transformURL(wi(String(e)),t)),px=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${ua(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${ua(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${ua(r,t,i)}`),fx={},gx=new Set(["base","body","head","html","link","meta","script","style","title"]);function mx(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 il=class lr extends fl{constructor(t,i,n,r,o,s,a,h,l,u,c,p,f,g,m,w=new Map,S={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=o,this.xmldoc=s,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=c,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=S,d(this,"document"),d(this,"exprContentListener"),d(this,"computedStyleParentFontSizeOverride",null),d(this,"computedStyleParentLineHeightOverride",null),d(this,"nodeContext",null),d(this,"viewRoot",null),d(this,"isFootnote",!1),d(this,"sourceNode",null),d(this,"offsetInNode",0),d(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new lr(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!Vt(t)||!Kh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(gr);if(!i)return;let n=tp(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(gr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,u;let c=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!c)return h;let p=[],f=sr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,m=Vt(t)&&!!c["footnote-call"]&&Tt((l=c["footnote-call"].content)==null?void 0:l.value);for(let v of i0){let b;if(v){if(!c[v])continue;let x=kt(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(v=="footnote-call"&&!Vt(t)||v=="footnote-marker"&&!(x||C||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(v.match(/^first-/)){let N=r.display;if(!N||N===y.inline)continue;let F=t.firstElementChild;if(F&&Oe(F.previousSibling)){let L=o.getStyle(F,!1);if(L){let V=ge(L,"display");if(V!=null&&V.value&&V.value!==y.inline)continue}}}if(v==="before"||v==="after"||v==="footnote-call"||v==="footnote-marker"){let N=c[v].content,F=(v==="before"||v==="after")&&(r.float===y.footnote||x||C)&&!!N;if(!N||!Tt(N.value)&&!F)continue}p.push(v),b=sr.createElementNS("http://www.w3.org/1999/xhtml","span"),wr(b,v)}else{if(m)continue;b=sr.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(b),v.match(/^first-/)&&(g=b)}if(!p.length)return h;let w=new aa(t,n,o,s,this.exprContentListener),S=new Eo(t,f,null,a,h,st.ROOTLESS,w);return h||S}getPseudoMap(t,i,n,r,o){let s=pt(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};mr(l,s[h],o),Ja(l,o,s[h]),hf(s[h],i,n,(u,c)=>{mr(l,c,o),sf(c,p=>{mr(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=D("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);o=new Eo(n,l,h,r,o,i,u)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=D("createShadows"),l=null,u=r.template,c;if(u instanceof tt||u===y.footnote)if(u!==y.footnote||Kh(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof tt?u.url:Ae("user-agent.xml#footnote",Ci);c=this.createRefShadow(p,st.ROOTLESS,t,a,l)}else c=T(l);else c=T(l);return c.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=Ho(m,w.url),f=this.createRefShadow(m,st.ROOTED,t,a,p))}f==null&&(f=T(p));let g=null;f.then(m=>{if(r.display===y.table_cell){let w=Ae("user-agent.xml#table-cell",Ci);g=this.createRefShadow(w,st.ROOTLESS,t,a,m)}else g=T(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,o,s,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var o;let s=this.context,a=Qa(n,s,this.regionIds,this.isFootnote,this.nodeContext),h=!((o=this.nodeContext)!=null&&o.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=af(a,s,t);let u=!h&&t!==l;i=lf(a,s,i);let c=(S,v)=>{let b;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(S)&&(b=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(S)&&(b=s.pageAreaWidth));let x=v.evaluate(s,S,b,t);return S=="font-family"&&(x=this.docFaces.filterFontFamily(x)),x},p=!!new Ke(s.style.pageScope,"left-page").evaluate(s);if(uf(a,r,t,i,p,c),u){let S=r[t?"height":"width"];(!S||S===y.auto)&&(r[t?"height":"width"]=y.max_content)}if(Yo(r.position))return r.position=y.fixed,r.visibility=y.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),w=Pd(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(S=>{w[S]&&(r[S]=w[S])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&Vt(w)){let S=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(S){let v=Ho(S,this.xmldoc.url),b=this.xmldoc.getElement(v);b&&kt(b)&&((n=b.parentNode)==null?void 0:n.nodeType)===1&&(r=b.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,S=!!w&&l.type==st.ROOTED&&kt(r);if(!w||l.type==st.ROOTLESS||S){let v=(l?l.styler:this.styler).getStyle(r,!1);o.push(v),s=s||da(r)}w&&!S?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let c=new Set;if(o.length>0){let w=o[0],S=Qa(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let v in S){if(!Cn(v))continue;let b=S[v].evaluate(this.context,v);b&&b!==y.inherit&&b!==y.unset&&b!==y.revert&&b!==Be&&c.add(v)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new $(new R(f,"px"),0)};p&&(g["line-height"]=new $(new Nt(this.context.pref.lineHeight),0));let m=new hb(g,this.context);for(let w=o.length-1;w>=0;--w){let S=o[w],v=[];for(let C in S)Cn(C)&&v.push(C);v.sort(Ch);let b,x;for(let C of v){if(w>0&&h&&C.startsWith("--viv-marker-")||w>0&&c.has(C))continue;m.setPropName(C);let N=ge(S,C),F=N;if(N.value===y.initial)delete g[C];else if(!q(N.value)){if(C==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)F=new $(new R(this.context.rootFontSize,"px"),N.priority);else if(C==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&N.value instanceof R&&(N.value.unit==="lh"||N.value.unit==="rlh"))F=new $(new R(this.context.rootLineHeight,"px"),N.priority);else if(w===0&&N.value instanceof R&&N.value.unit==="lh"){let L=this.getLineHeightUnitSize(C,b,x);L!=null&&(F=new $(new R(N.value.num*L,"px"),N.priority))}else je(C)||(F=N.filterValue(m));C==="font-size"?b=F.value:C==="line-height"&&(x=F.value),g[C]=F}}}for(let w in t)Cn(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ae(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=da(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Jv().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let o=t[r];if(o){if(q(o))o===y.initial&&(n[r]=void 0);else if(o instanceof lt)n[r]=o.num;else if(o instanceof ae)n[r]=o.name;else if(o instanceof R){let s=o;switch(s.unit){case"dpi":case"dpcm":case"dppx":n[r]=s.num*jt[s.unit];break;default:n[r]=o}}else n[r]=o;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,o,s){let a=Ut("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,o,s);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let o=!0,s=D("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(this.syncSemanticFootnoteCounterToTarget(a),!this.nodeContext.shadowContext){let x=this.xmldoc.getElementOffset(a);Os.registerFragmentIndex(x,this.nodeContext.fragmentIndex,0)}let u={},c={getStyle:x=>this.styler.getStyle(x,!1),getProp:(x,C)=>x?ge(x,C):null,getStyleMap:(x,C)=>pt(x,C),getMutableStyleMap:(x,C)=>ri(x,C),createCascadeValue:(x,C)=>new $(x,C),filterFootnoteMarkerContent:(x,C)=>x.filterValue(new Pr(this.styler.cascade,C,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!q(f.value)&&f.value!==y.none&&g&&!q(g.value)?Ry(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===st.ROOTED&&kt(a);if(this.nodeContext.parent&&(Yo(p?.value)||m&&Pi(m)||w)){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}l=My(a,l,this.nodeContext.shadowContext,this.xmldoc.url,x=>this.xmldoc.getElement(x),gr,c),l=_y(a,l,this.nodeContext.shadowContext,this.context,c),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),m&&Pi(m)&&u.display===y.block&&(u.display=y.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let S=u["flow-into"];if(S&&S.toString()!=this.flowName)return s.finish(!1),s.result();if(mi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Kl(a,this.viewport.window).thenFinish(s),s.result();let v=u.display;if(kt(a)&&!w&&a.hasAttribute(ep)&&(v=u.display=y.none),q(v)&&(v===y.initial||v===y.unset?v=y.inline:v===y.inherit?v=((n=this.nodeContext.parent)==null?void 0:n.display)&&M((r=this.nodeContext.parent)==null?void 0:r.display):v=null),v===y.none)return s.finish(!1),s.result();let b=this.nodeContext.parent==null;return this.nodeContext.flexContainer=v===y.flex,this.createShadows(a,b,l,u,h,this.context,this.nodeContext.shadowContext).then(x=>{var C;this.nodeContext.nodeShadow=x;let N=u.position,F=u.float,L=u.clear,V=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,Y=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:V,ue=Yw(a),he=u["column-count"],k=u["column-width"],_=he&&he!==y.auto&&!q(he)||k&&k!==y.auto&&!q(k);this.nodeContext.establishesBFC=Kw(v,N,F,u.overflow,V,Y,_||ue),this.nodeContext.containingBlockForAbsolute=Jw(N),this.nodeContext.isInsideBFC()&&F!==y.footnote&&!(m&&Pi(m))&&(F=null,L=null);let E=null,O=!1,P=this.isFootnote&&(!((C=this.nodeContext)!=null&&C.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),A=Dy(a,this.nodeContext.shadowContext,c);zy(A.sourceStyle,u,this.context),E=A.footnoteDisplay;let B=F instanceof te||F===y.left||F===y.right||F===y.top||F===y.bottom||F===y.inline_start||F===y.inline_end||F===y.block_start||F===y.block_end||F===y.snap_block||F===y.snap_inline||F===y.inside||F===y.outside||F===y.footnote;if(F&&(delete u.float,F===y.footnote))if(E=u["footnote-display"]||E,O=!!u["--viv-marker-content"],P){B=!1;let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),v=O?M("list-item"):H==="inline"||H==="compact"?y.inline:y.block,u.display=v}else u.display=y.inline;if(P&&kt(a)){O=O||!!u["--viv-marker-content"];let H=E?.toString();H&&(u["--viv-footnote-display"]=M(H)),O&&(v=u.display=M("list-item")),!O&&(H==="inline"||H==="compact")&&(v=u.display=y.inline)}L&&(L===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(L=M(this.nodeContext.parent.clearSide)),(L===y.left||L===y.right||L===y.top||L===y.bottom||L===y.inline_start||L===y.inline_end||L===y.block_start||L===y.block_end||L===y.inside||L===y.outside||L===y.both||L===y.all||L===y.same||L===y.column||L===y.region||L===y.page)&&(delete u.clear,(B||u.display&&u.display!=y.inline)&&(this.nodeContext.clearSide=L.toString())));let z=nr(v)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),W=u["break-inside"];(B||W&&!q(W)&&W!==y.auto)&&this.nodeContext.breakPenalty++,v&&v!==y.inline&&Gt(v)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!B&&!v||Gt(v)||Td(v),this.nodeContext.display=v?v.toString():"inline",this.nodeContext.floatSide=B?F.toString():null,this.nodeContext.floatReference=m||Ie.INLINE;let Z=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=Z&&!q(Z)?Z:null;let K=this.isInsideNonRootMultiColumn(),J=u["column-span"];if(this.nodeContext.columnSpan=!K&&J&&!q(J)?J:null,!this.nodeContext.inline){let H=u["break-after"];H&&!q(H)&&!(K&&H===y.column)&&(this.nodeContext.breakAfter=H.toString(),Ia[this.nodeContext.breakAfter]&&(u["break-after"]=y.column));let Bt=u["break-before"];Bt&&!q(Bt)&&!(K&&Bt===y.column)&&(this.nodeContext.breakBefore=Bt.toString(),Ia[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Wt=u.page,It=Wt&&!q(Wt)&&Wt.toString();!It&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||v===y.table_header_group||v===y.table_footer_group)&&(It=this.styler.cascade.currentPageType),!It||It.toLowerCase()==="auto"?It=this.nodeContext.pageType:this.nodeContext.pageType=It,this.styler.cascade.currentPageType!==It&&!(!It&&u.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!On(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),It!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=It)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let me=u["border-collapse"];if(!me||me===M("separate")){let H=u["border-spacing"],Bt,Wt;H&&(H instanceof te?(Bt=H.values[0],Wt=H.values[1]):Bt=Wt=H,Bt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=ut(Bt,this.context)),Wt.isNumeric()&&(this.nodeContext.blockBorderSpacing=ut(Wt,this.context)))}let re=u["footnote-policy"]||A.footnotePolicy;re&&!q(re)&&(u["--viv-footnote-policy"]=re),this.nodeContext.footnotePolicy=re&&!q(re)?re:null;let le=u["x-first-pseudo"];if(le){let H=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Ny(H,le.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let De=u["white-space"];if(De){let H=$d(De.toString());H!==null&&(this.nodeContext.whitespace=H)}let Me=u["hyphenate-character"];Me&&Me instanceof X&&(this.nodeContext.hyphenateCharacter=Me.str);let we=u["word-break"],Ne=u["line-break"],ve=u["overflow-wrap"];(we===y.break_all||Ne===y.anywhere||ve===y.break_word||ve===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,v,N,F,b),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let ce=!1,Te=null,be=[],ke=a.namespaceURI,ne=a.localName,Xr=ne;ke=="http://www.w3.org/1999/xhtml"?(gx.has(ne)?ne="div":ne=="vide_"?ne="video":ne=="audi_"?ne="audio":ne=="object"&&(ce=!!this.customRenderer),a.hasAttribute(Xl)&&a.hasAttribute("src")&&u.content instanceof tt&&(ne="img")):ke=="http://www.idpf.org/2007/ops"?(ne="span",ke="http://www.w3.org/1999/xhtml"):ke=="http://www.pyroxy.com/ns/shadow"?(ke="http://www.w3.org/1999/xhtml",ne=this.nodeContext.inline?"span":"div"):ce=!!this.customRenderer,z?t?(ne="li",u["--viv-marker-content"]&&(u["list-style-type"]=y.none,u["list-style-image"]=y.none)):(v=Gt(v)?y.inline:y.block,u.display=v,ne="div"):ne=="body"||ne=="li"?ne="div":ne=="q"&&(ne="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(ce=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(ce=!0);let zs;if(ce){let H=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;zs=this.customRenderer(a,H,u)}else zs=T(null);zs.then(H=>{var Bt,Wt,It,oh,sh;if(H)ce&&(o=H.getAttribute("data-adapt-process-children")=="true");else if(u.display===y.none){s.finish(!1);return}else H=this.createElement(ke,ne);if(!b&&_&&u["column-fill"]===y.auto){let He=this.nodeContext.vertical?u.width:u.height;(!He||He===y.auto||q(He))&&(H.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=y.balance)}ne!=Xr&&(H.setAttribute("data-vivliostyle-original-tag",Xr),(Xr==="html"||Xr==="body")&&(H.role="presentation")),ne=="a"&&H.addEventListener("click",this.page.hrefHandler,!1),Te&&(this.applyPseudoelementStyle(this.nodeContext,"inner",Te),H.appendChild(Te)),H.localName=="iframe"&&H.namespaceURI=="http://www.w3.org/1999/xhtml"&&mx(H);let qr=this.nodeContext.inheritedProps["image-resolution"],Vs=[],Us=u.width,$s=u.height,lg=a.getAttribute("width"),hg=a.getAttribute("height"),Hs=Us===y.auto||!Us&&!lg,Ws=$s===y.auto||!$s&&!hg,ah=a.attributes,ug=ah.length,Gn=null,lh=null;v===y.table_cell&&((It=(Wt=(Bt=this.nodeContext.parent)==null?void 0:Bt.viewNode)==null?void 0:Wt.lastElementChild)==null?void 0:It.localName)==="a"&&H.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let He=0;He<ug;He++){let bt=ah[He],ht=bt.namespaceURI,oe=bt.localName,Ee=bt.nodeValue;if(ht){if(ht=="http://www.w3.org/2000/xmlns/")continue;ht=="http://www.w3.org/1999/xlink"&&oe=="href"&&(Ee=this.documentURLTransformer.transformURL(this.resolveURL(Ee),this.xmldoc.url))}else{if(!mi&&oe.match(/^on/)||oe=="style")continue;if(oe==="media"&&ne==="source"&&ke==="http://www.w3.org/1999/xhtml"&&((oh=a.parentElement)==null?void 0:oh.localName)==="picture")try{let We=this.context.rootScope,ft=new Ps(We),Zr=new vt(Ee,ft),hh=Ed(Zr,ft,"");if(hh){if(hh.toExpr().evaluate(this.context))continue;Ee="not all"}}catch{}if((oe=="id"||oe=="name")&&t){let We=this.documentURLTransformer.transformFragment(Ee,this.xmldoc.url);H.setAttribute(oe,Ee),H.setAttribute("data-vivliostyle-id",We);let ft=H.ownerDocument.createElement("a");ft.setAttribute(oe,We),ft.setAttribute(Ln,"1"),ft.style.position="absolute",H.appendChild(ft),this.page.registerElementWithId(H,We);continue}if(oe=="src"||oe=="href"||oe=="poster")Ee=this.resolveURL(Ee),oe==="href"?Ee=this.documentURLTransformer.transformURL(Ee,this.xmldoc.url):Ee=Sr(Ee),oe==="src"&&(Ee=lc(Ee));else if(oe=="srcset")Ee=Ee.split(",").map(We=>{let ft=We.trim().split(/\s+/),Zr=Sr(this.resolveURL(ft[0]));return ft.length>1?`${Zr} ${ft.slice(1).join(" ")}`:Zr}).join(",");else if(oe==="data"&&ce&&ne==="object"&&H.hasAttribute("data"))continue;if(oe==="poster"&&ne==="video"&&ke==="http://www.w3.org/1999/xhtml"){let We=new Image,ft=Ct(We,Ee);Hs&&Ws?(be.push(ft),Vs.push({image:We,element:H,fetcher:ft})):this.page.fetchers.push(ft)}}if(ke=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(Ee=px(Ee,this.xmldoc.url,this.documentURLTransformer)),ht){let We=fx[ht];We&&(oe=`${We}:${oe}`)}if(oe=="src"&&!ht&&(ne=="img"||ne=="input")&&ke=="http://www.w3.org/1999/xhtml")Gn=Ee;else if(oe=="alt"&&!ht&&ne=="img"&&ke=="http://www.w3.org/1999/xhtml")lh=Ee;else if(oe=="href"&&ne=="image"&&ke=="http://www.w3.org/2000/svg"&&(ht=="http://www.w3.org/1999/xlink"||!ht))ht||H.setAttribute(oe,Ee),this.page.fetchers.push(Ct(H,Ee));else if(ht)H.setAttributeNS(ht,oe,Ee);else try{H.setAttribute(oe,Ee)}catch(We){j.warn(We)}}if(Gn){let He=ne==="input"?new Image:H,bt=Ct(He,Gn,lh);He!==H&&(H.src=Gn);let ht=()=>{var oe,Ee;if(u.position===y.fixed)return!0;for(let We=(oe=this.nodeContext.parent)==null?void 0:oe.viewNode;We&&We!==this.viewRoot;We=We.parentElement)if(((Ee=We.style)==null?void 0:Ee.position)==="fixed")return!0;return!1};!Hs&&!Ws&&!(()=>{let oe=this.nodeContext.vertical?Us:$s;return oe instanceof R&&oe.unit==="%"})()&&!ht()?this.page.fetchers.push(bt):(Hs&&Ws&&qr&&qr!==1&&Vs.push({image:He,element:H,fetcher:bt}),be.push(bt))}else!Gn&&ne==="img"&&ke==="http://www.w3.org/1999/xhtml"&&(H.srcset||((sh=a.parentElement)==null?void 0:sh.localName)==="picture")&&this.page.fetchers.push(Ct(H));delete u.content;let Yr=u["--viv-marker-content"];if(Yr){let He=Yr instanceof te?Yr.values:[Yr];for(let bt of He)bt instanceof tt&&bt.url&&be.push(Ct(new Image,bt.url))}if(H.localName==="object"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("data")&&this.page.fetchers.push(Ct(H)),H.localName==="embed"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")&&this.page.fetchers.push(Ct(H)),H.localName==="iframe"&&H.namespaceURI==="http://www.w3.org/1999/xhtml"&&H.hasAttribute("src")){let He=H;He.loading==="lazy"&&(He.loading="eager"),this.page.fetchers.push(Ct(H))}if(this.preprocessElementStyle(u),this.applyComputedStyles(H,u),this.nodeContext.inline)t||(xt(H,"inline-start"),bn(H)&&xt(H,"clone"));else if(t){if(!Ns(u.position)){let He=u["margin-break"],bt=this.getBreakTypeAt(this.nodeContext),ht=bt!==null,oe=bt==="auto";(He===y.discard&&ht||He!==y.keep&&oe&&!this.nodeContext.floatSide)&&Ks(H,"block-start")}}else{let He=this.nodeContext.vertical?"width":"height";bi(H,He)&&I(H,He,this.nodeContext.display==="table-row"?"0.01px":""),xt(H,"block-start"),bn(H)&&xt(H,"clone"),Ks(H,"block-start")}z&&u["ua-list-item-count"]&&H.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=H,be.length?Rn(be).then(()=>{qr>0&&this.modifyElemDimensionWithImageResolution(Vs,qr,u,this.nodeContext.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Oe(r,n.parent.whitespace)||Ft(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&$r(i))}getBreakTypeAt(t){var i,n,r,o,s;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Ye(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let u=this.viewport.window.getComputedStyle(l),c=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(c||p)return null;let f=l?.firstChild;for(;f&&(Oe(f,h.parent.whitespace)||!h.floatSide&&Ft(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(s=(o=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:s.startBreakType;return Ye(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let s=new aa(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new r0(t,s)}}isSVGUrlAttribute(t){return lr.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=ut(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=ut(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(h+=ut(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(h+=ut(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||y.none,c=n["max-height"]||y.none;if(u===y.none&&c===y.none)I(l,"max-width",`${a}px`);else if(u!==y.none&&c===y.none)I(l,"width",`${a}px`);else if(u===y.none&&c!==y.none)I(l,"height",`${h}px`);else{u.isNumeric(),c.isNumeric();let p=u,f=c;p.unit!=="%"?I(l,"max-width",`${Math.min(a,ut(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,ut(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Re,c=n["min-height"]||Re;u.isNumeric(),u.isNumeric();let p=u,f=c;p.num===0&&f.num===0?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,ut(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,ut(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Ut("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof Zi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.formattingContext;this.nodeContext.formattingContext=new Zi(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==y.none&&((i===y.auto||q(i))&&(t.display===y.table_header_group?i=y.header:t.display===y.table_footer_group?i=y.footer:i=y.none),i&&i!==y.none)?i.toString():null}createTextNodeView(){let t=D("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Yh(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let t,i=t=this.sourceNode.textContent,n=D("preprocessTextContent"),r=Ut("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=r.length?T(!1):r[o++](this.nodeContext,i).thenAsync(s=>(i=s,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=gy(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=D("createNodeView"),r,o=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=T(!0)):r=this.createTextNodeView(),r.then(s=>{var a;if(o=s,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(c,p)=>c?.nodeType===1&&ei(c)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Oe(this.viewNode))&&!u.hasChildNodes()&&Dd(u).includes("block-start")&&xt(u,"text-start"),u.appendChild(this.viewNode),iy(this.viewNode))}n.finish(o)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):T(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,o,s,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.subShadow.root,s=n.subShadow.type,s==st.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,s=st.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 fn(o,r,i);return l.shadowContext=a,l.shadowType=s,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=st.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let r=t.nodeShadow.root;if(t.nodeShadow.type==st.ROOTLESS&&(r=r.firstChild),r){let o=new fn(r,t,i);return o.shadowContext=t.nodeShadow,o.shadowType=t.nodeShadow.type,this.processShadowContent(o)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new fn(n,t,i));if(t.sourceNode.nodeType!=1){let r=Yh(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let o=r;return ei(o)==="footnote-call"&&o.getAttribute(lr.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&kt(i)}insertFootnoteCall(t){var i,n;let r=D("insertFootnoteCall"),o=sr.createElementNS("http://www.w3.org/1999/xhtml","span");wr(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(lr.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new fn(o,t.parent,t.boxOffset);a.inline=!0;let h=new aa(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Eo(t.sourceNode,o,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,st.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return T(n);let r=D("nextInTree");return this.setCurrent(n,!0,i).then(o=>{if((!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let s=this.findImmediateFootnoteCallSibling(n);s!=null&&s.parentNode&&s.parentNode.removeChild(s),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){yr(t,this.page)}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i["border-image-source"];a&&this.addImageFetchers(a);let h=i["list-style-image"];h&&this.addImageFetchers(h);let l=i["mask-image"];l&&this.addImageFetchers(l);let u=i["clip-path"];u&&this.addImageFetchers(u);let c=i.filter;c&&this.addImageFetchers(c);let p=i["shape-outside"];p&&this.addImageFetchers(p);let f=i["--viv-marker-content"];f&&this.addImageFetchers(f);let g=i.position===y.relative,m=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),w=Object.keys(i);w.sort(Ch);let S,v;for(let b of w){if(yx[b])continue;let x=i[b];if(!(!x||x===Be&&!je(b))){if(x=x.visit(new Rm(this.xmldoc.url,this.documentURLTransformer)),x instanceof R)if(x.unit==="em"){let C=this.getEmUnitSize(b,S);C!=null&&(x=new R(x.num*C,"px"))}else if(x.unit==="lh"){let C=this.getLineHeightUnitSize(b,S,v);C!=null&&(x=new R(x.num*C,"px"))}else wc(x.unit)&&(x=Bc(x,this.context));if((b==="font-size"||b==="line-height")&&(b==="font-size"?S=x:v=x,this.viewport.layoutUnitAdj&&x instanceof R&&x.unit!=="%"&&x.unit!=="em"&&x.unit!=="lh"&&(x=new an(`calc(${x.toString()} - var(--viv-layoutUnitAdj))`))),yy[b]||g&&vy[b]){this.page.delayedItems.push(new Nl(t,b,x));continue}m&&this.page.pageAreaElement&&Cn(b)?(I(this.page.pageAreaElement.parentElement.parentElement,b,x.toString()),b!=="writing-mode"&&b!=="direction"&&I(this.viewport.layoutBox,b,x.toString())):I(t,b,x.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(t,i){var n,r,o;let s=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var t,i,n;return((n=(i=(t=this.nodeContext)==null?void 0:t.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(t){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:t?this.parsePlusLayoutUnitAdj(t.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:t?this.parsePlusLayoutUnitAdj(t.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(t,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let u=null;if(n)if(n instanceof Nt||n instanceof R&&(n.unit==="em"||n.unit==="%"))u=n instanceof R&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof R&&n.unit!=="lh"){let c=this.context.queryUnitSize(n.unit,!1);if(c!=null)return n.num*c}return null}if(u==null)for(let c=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;c&&c.nodeType===1;c=c.parentNode){let p=(s=c?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(u=parseFloat(p));break}}if(u!=null){if(i&&!(i instanceof R))return null;let c=h.fontSize;if(i instanceof R){let p=Xa(i,c,this.context).num;return typeof p!="number"||isNaN(p)?null:u*p}else return c==null?null:u*c}return l}getEmUnitSize(t,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(t==="font-size"||i==null)return r;if(i instanceof R){let o=Xa(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),s=pt(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;Tt(h)&&(h.visit(new kr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=D("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let c=t.viewNode.textContent;t.viewNode.textContent=c.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let c=t.viewNode.parentNode;c&&c.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t&&t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new fn(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=s),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let c=this.setCurrent(t,!1);if(c.isPending())return c}return T(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=pt(this.cascadedPageStyle,vs);p&&p.area&&(a=p.area)}let h=pt(a,"_pseudos");t=this.computeStyle(t,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new R(l.fontSize,"px")),delete o.content;let u=this.computedStyleParentFontSizeOverride,c=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ge(f,"display"),m={},w=this.createElement("http://www.w3.org/1999/xhtml","span");wr(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,m),g||(m.display=y.block);let S=ge(f,"content");if(S){let b=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=S.filterValue(new Pr(this.styler.cascade,b,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let v=m.content;if(Tt(v)){v.visit(new kr(w,this.context,v,this.exprContentListener));let b=w.querySelectorAll("img[src]");for(let C=0;C<b.length;C++){let N=b[C],F=N.getAttribute("src");if(!F)continue;let L=Ct(N,F);s.push(L),this.page.fetchers.push(L)}let x=w.getAttribute("src");if(x){let C=w.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",x),w.appendChild(C));let N=Ct(C,x);s.push(N),this.page.fetchers.push(N)}}delete m.content,this.applyComputedStyles(w,m)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=c}return s.length?Rn(s).thenReturn(t):T(t)}processFragmentedBlockEdge(t){var i,n,r;let o=!t.inline&&t.after?t.parent:t,s=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=ge(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Gt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(xt(l,"inline-end"),bn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;xt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(bi(l,u)&&I(l,u,""),xt(l,"block-end"),!a++&&h!==o){let{textAlign:c}=this.viewport.window.getComputedStyle(l);if(c==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?zd(p,["block-start","text-start","block-end","text-end","justify"]):(xt(l,"text-end"),xt(l,"justify")):xt(l,"text-end")}else xt(l,"text-end")}bn(l)&&xt(l,"clone"),Ks(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||$i[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&Oe(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let c=i(u);if(c||c===null)return null}return!1}if(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(Ln)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Oe(l.nextSibling))?i(l):!1}return!(!s||Gt(s))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Oe(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,o=t.unit;if(Zg(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,$l(t,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&ei(n)===ei(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!ei(t)}};d(il,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),d(il,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var wx=il,yx={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},vx=class{constructor(e){d(this,"layoutBox"),d(this,"window"),d(this,"pixelRatio"),d(this,"scaleRatio"),d(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.subtractOffsets(n,i))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},ws=class{constructor(e,t,i,n,r,o){if(this.window=e,this.fontSize=t,this.pixelRatio=i,d(this,"document"),d(this,"root"),d(this,"outerZoomBox"),d(this,"contentContainer"),d(this,"layoutBox"),d(this,"width"),d(this,"height"),d(this,"scaleRatio",1),d(this,"layoutUnitPerPixel",64),d(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),cl){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=o||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!o&&u)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function yr(e,t){if(e instanceof rt)for(let i of e.values)yr(i,t);else if(e instanceof tt){let i=Sr(e.url);t.fetchers.push(Ct(new Image,i))}else if(e instanceof oi)for(let i of e.values)yr(i,t);else if(e instanceof te)for(let i of e.values)yr(i,t)}var bx=1,_s=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,d(this,"specified",{}),d(this,"children",[]),d(this,"pageMaster",null),d(this,"index",0),d(this,"key"),d(this,"_scope"),this._scope=e,this.key=`p${bx++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},xx=class extends _s{constructor(e){super(e,null,null,[],null),this.specified.width=new $(Mr,0),this.specified.height=new $(_r,0)}},Au=class extends Go{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Mf=class _f extends _s{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),this.condition=s,this.specificity=a,d(this,"keyMap",{}),t instanceof Au||(this._scope=new Au(t,this)),this.pageMaster=this,this.specified.width=new $(Mr,0),this.specified.height=new $(_r,0),this.specified["wrap-flow"]=new $(y.auto,0),this.specified.position=new $(y.relative,0),this.specified.overflow=new $(y.visible,0)}createInstance(t){return new Ql(t,this)}clone(t){let i=new _f(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}},Df=class zf extends _s{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new $(y.auto,0)}createInstance(t){return new Px(t,this)}clone(t){let i=new zf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},jr=class Vf extends _s{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new zn(t,this)}clone(t){let i=new Vf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Sx(e,t,i){return!t||q(t)?new et(e,i):t.toExpr(e,e.zero)}function xe(e,t,i){return!t||t===y.auto||q(t)?null:t.toExpr(e,i)}function Cx(e,t,i){return!t||t===y.normal||q(t)?null:t.toExpr(e,i)}function Pt(e,t,i){return!t||t===y.auto||q(t)?e.zero:t.toExpr(e,i)}function Fu(e,t,i){return!t||q(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function ni(e,t,i,n){return!t||i===y.none||q(t)?e.zero:t.toExpr(e,n)}function Uf(e,t,i){return!t||q(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var Ds=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,d(this,"cascaded",{}),d(this,"style",{}),d(this,"autoWidth",null),d(this,"autoHeight",null),d(this,"children",[]),d(this,"isAutoWidth",!1),d(this,"isAutoHeight",!1),d(this,"isTopDependentOnAutoHeight",!1),d(this,"isRightDependentOnAutoWidth",!1),d(this,"calculatedWidth",0),d(this,"calculatedHeight",0),d(this,"pageMasterInstance",null),d(this,"namedValues",{}),d(this,"namedFuncs",{}),d(this,"vertical",!1),d(this,"rtl",!1),d(this,"suppressEmptyBoxGeneration",!1),d(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return ie(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let r=this.vertical?Dp:zp;n=e;for(let o in r)n=n.replace(o,r[o])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Tc(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=ye(i,Co(i,new ur(i,"min",[n,r]),ie(i,o,s)),s);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Uf(e,t.enabled,e._true),n=xe(e,t.page,e.zero);if(n){let s=new Ke(e,"page-number");i=zt(e,i,new yl(e,n,s))}let r=xe(e,t["min-page-width"],e.zero);r&&(i=zt(e,i,new ga(e,new Ke(e,"page-width"),r)));let o=xe(e,t["min-page-height"],e.zero);o&&(i=zt(e,i,new ga(e,new Ke(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new G(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=xe(e,t.left,i),r=xe(e,t["margin-left"],i),o=ni(e,t["border-left-width"],t["border-left-style"],i),s=Pt(e,t["padding-left"],i),a=xe(e,t.width,i),h=xe(e,t["max-width"],i),l=Pt(e,t["padding-right"],i),u=ni(e,t["border-right-width"],t["border-right-style"],i),c=xe(e,t["margin-right"],i),p=xe(e,t.right,i),f=ie(e,o,s),g=ie(e,o,l);if(n&&p&&a){let S=ye(e,i,ie(e,a,ie(e,ie(e,n,f),g)));r?c?p=ye(e,S,c):c=ye(e,S,ie(e,p,r)):(S=ye(e,S,p),c?r=ye(e,S,c):(r=Co(e,S,new et(e,.5)),c=r))}else{r||(r=e.zero),c||(c=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let S=ye(e,i,ie(e,ie(e,r,f),ie(e,c,g)));this.isAutoWidth&&(h||(h=ye(e,S,n||p)),!this.vertical&&(xe(e,t["column-width"],null)||xe(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ye(e,S,ie(e,n,a))):a=ye(e,S,ie(e,n,p)):n=ye(e,S,ie(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=Pt(e,m,i);t.left=new G(n),t["margin-left"]=new G(r),t["border-left-width"]=new G(o),t["padding-left"]=new G(s),t.width=new G(a),t["max-width"]=new G(h||a),t["padding-right"]=new G(l),t["border-right-width"]=new G(u),t["margin-right"]=new G(c),t.right=new G(p),t["snap-width"]=new G(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=xe(e,t.top,n),o=xe(e,t["margin-top"],i),s=ni(e,t["border-top-width"],t["border-top-style"],i),a=Pt(e,t["padding-top"],i),h=xe(e,t.height,n),l=xe(e,t["max-height"],n),u=Pt(e,t["padding-bottom"],i),c=ni(e,t["border-bottom-width"],t["border-bottom-style"],i),p=xe(e,t["margin-bottom"],i),f=xe(e,t.bottom,n),g=ie(e,s,a),m=ie(e,c,u);if(r&&f&&h){let v=ye(e,n,ie(e,h,ie(e,ie(e,r,g),m)));o?p?f=ye(e,v,o):p=ye(e,v,ie(e,f,o)):(v=ye(e,v,f),p?o=ye(e,v,p):(o=Co(e,v,new et(e,.5)),p=o))}else{o||(o=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let v=ye(e,n,ie(e,ie(e,o,g),ie(e,p,m)));this.isAutoHeight&&(l||(l=ye(e,v,r||f)),this.vertical&&(xe(e,t["column-width"],null)||xe(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ye(e,v,ie(e,r,h))):h=ye(e,v,ie(e,f,r)):r=ye(e,v,ie(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),S=Pt(e,w,i);t.top=new G(r),t["margin-top"]=new G(o),t["border-top-width"]=new G(s),t["padding-top"]=new G(a),t.height=new G(h),t["max-height"]=new G(l||h),t["padding-bottom"]=new G(u),t["border-bottom-width"]=new G(c),t["margin-bottom"]=new G(p),t.bottom=new G(f),t["snap-height"]=new G(S)}initColumns(){let e=this.pageBox.scope,t=this.style,i=xe(e,t[this.vertical?"height":"width"],null),n=xe(e,t["column-width"],i),r=xe(e,t["column-count"],null),o=Cx(e,t["column-gap"],null);o||(o=new Br(e,1,"em")),n&&!r&&(r=new ur(e,"floor",[ma(e,ie(e,i,o),ie(e,n,o))]),r=new ur(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,ma(e,ie(e,i,o),r),o),t["column-width"]=new G(n),t["column-count"]=new G(r),t["column-gap"]=new G(o)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=Qa(this.cascaded,e,r,!1,null);this.vertical=af(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=lf(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===y.border_box;let s=!!(e instanceof nh&&e.currentLayoutPosition&&new Ke(i,"left-page").evaluate(e));uf(o,n,this.vertical,this.rtl,s,(a,h)=>h.value),this.autoWidth=new Le(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Le(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&Cn(t)&&this.pageMasterInstance instanceof An&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new R(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=fs(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=fs(e,r,t,o)}return ut(r,e)}getSpecial(e,t){let i=Hp(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(e,"");o&&o!==Be&&n.push(o)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&wc(r.unit)&&(r=Bc(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new Nl(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),o=this.getPropAsNumber(e,"border-left-width"),s=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,s),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),s=this.getPropAsNumber(e,"border-right-width");if(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${o}px`),I(t.element,"border-right-width",`${s}px`),t.marginRight=r,t.borderRight=s,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,o+=t.snapOffsetX)}t.paddingRight=o,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),s=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=s,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,o+=t.snapOffsetY)}t.paddingTop=o,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${o}px`),I(t.element,"border-top-width",`${s}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;I(t.element,"height",`${o}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(t.element,"border-bottom-width",`${r}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){I(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let o=0;o<Ru.length;o++)this.propagateProperty(e,t,Ru[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<Ou.length;r++)this.propagateProperty(e,t,Ou[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!q(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!q(a)};for(let o=0;o<Bu.length;o++){let s=Bu[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;I(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,u,c,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let S=(this.vertical||!n)&&this.isAutoHeight,v=(!this.vertical||!n)&&this.isAutoWidth,b=null;if(v||S){v&&I(t.element,"width","auto"),S&&I(t.element,"height","auto");let x=n&&Zo(n);x&&Is(n),b=o.getElementClientRect(n?n.element:t.element),x&&kl(n),v&&(this.calculatedWidth=Math.ceil(b.right-b.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),S&&(this.calculatedHeight=b.bottom-b.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let x=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),N=this.getProp(e,"column-rule-color");if(x>0&&C&&C!=y.none&&N!=y.transparent){let F=this.getPropAsNumber(e,"column-gap"),L=this.vertical?t.height:t.width,V=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),Y=t.getPaddingRect(),ue=n,he=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(L+F)*k/r-F/2+t.paddingTop-x/2:(L+F)*k/r-F/2+t.paddingLeft-x/2,E=this.vertical?Y.y1+_+x/2:Y.x1+_+x/2,O=(c=(u=(l=ue.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:c.call(u,E),P=(g=(f=(p=ue.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),A=isFinite(O)?this.vertical?O-Y.x1:O-Y.y1:NaN,B=isFinite(P)?this.vertical?P-Y.x1:P-Y.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),W=z>0?z:this.vertical?n.width:n.height,Z=Math.max(V>0?V:0,0),K=Z+W,J=Math.max(Z,isFinite(this.vertical?B:A)?Math.max(0,this.vertical?B:A):0),me=Math.min(K,isFinite(this.vertical?A:B)?Math.max(0,this.vertical?A:B):K),re=Math.max(0,me-J),le=t.element.ownerDocument.createElement("div");I(le,"position","absolute"),I(le,this.vertical?"left":"top",`${J}px`),I(le,this.vertical?"top":"left",`${_}px`),I(le,this.vertical?"height":"width","0px"),I(le,this.vertical?"width":"height",`${re}px`),I(le,he,`${x}px ${C.toString()}${N?` ${N.toString()}`:""}`),t.element.insertBefore(le,t.element.firstChild)}}}for(let x=0;x<Lu.length;x++)this.propagateProperty(e,t,Lu[x],s);for(let x of kx){let C=this.getProp(e,x);C&&yr(C,i)}for(let x=0;x<Mu.length;x++)this.propagateDelayedProperty(e,t,Mu[x],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof An&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Hi(o)&&Ni(i,o,ge(n,o));if(this.pageBox.pseudoName==Jl)for(let o in t)(o.match(/^background-/)||o=="writing-mode")&&(i[o]=t[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in t)!o.match(/^background-/)&&o!="writing-mode"&&(i[o]=t[o]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new Pr(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)}},Ru=["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"],Lu=["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"],kx=["background-image","border-image-source","filter"],Ou=["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-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-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","text-box-trim","text-box-edge","text-justify"],Bu=["width","height","image-resolution","object-fit","object-position"],Mu=["transform","transform-origin"],Jl="background-host",Ex=class extends Ds{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)}},Ql=class extends Ds{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=zt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Px=class extends Ds{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},zn=class extends Ds{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 rt&&(n=t.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof ae){let s=pa(n[o].name,"enabled"),a=new Ke(r,s);i&&(a=new Ei(r,a)),e=zt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Uf(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Sx(t,i["flow-from"],"body"),o=new ur(t,"has-content",[r]);e=zt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(t,null):t._true;o=zt(t,o,e),this.pageMasterInstance.style.enabled=new G(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof jf||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},eh=class extends Qi{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new $(t,i?bd:xd)}},$f=class extends eh{constructor(e,t,i,n){super(e,t,i,n)}},Nx=class Hf extends eh{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new $(xh,0),n.specified.height=new $(xh,0)}startPartitionRule(t,i,n){let r=new jr(this.scope,t,i,n,this.target),o=new $f(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new Df(this.scope,t,i,n,this.target),o=new Hf(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},Tx=class extends eh{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new jr(this.scope,e,t,i,this.target),r=new $f(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Df(this.scope,e,t,i,this.target),r=new Nx(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function Wf(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===y.vertical_lr||n!==y.vertical_rl&&r!==y.rtl?"ltr":"rtl"}var Ix={a10:{width:new R(26,"mm"),height:new R(37,"mm")},a9:{width:new R(37,"mm"),height:new R(52,"mm")},a8:{width:new R(52,"mm"),height:new R(74,"mm")},a7:{width:new R(74,"mm"),height:new R(105,"mm")},a6:{width:new R(105,"mm"),height:new R(148,"mm")},a5:{width:new R(148,"mm"),height:new R(210,"mm")},a4:{width:new R(210,"mm"),height:new R(297,"mm")},a3:{width:new R(297,"mm"),height:new R(420,"mm")},a2:{width:new R(420,"mm"),height:new R(594,"mm")},a1:{width:new R(594,"mm"),height:new R(841,"mm")},a0:{width:new R(841,"mm"),height:new R(1189,"mm")},b10:{width:new R(31,"mm"),height:new R(44,"mm")},b9:{width:new R(44,"mm"),height:new R(62,"mm")},b8:{width:new R(62,"mm"),height:new R(88,"mm")},b7:{width:new R(88,"mm"),height:new R(125,"mm")},b6:{width:new R(125,"mm"),height:new R(176,"mm")},b5:{width:new R(176,"mm"),height:new R(250,"mm")},b4:{width:new R(250,"mm"),height:new R(353,"mm")},b3:{width:new R(353,"mm"),height:new R(500,"mm")},b2:{width:new R(500,"mm"),height:new R(707,"mm")},b1:{width:new R(707,"mm"),height:new R(1e3,"mm")},b0:{width:new R(1e3,"mm"),height:new R(1414,"mm")},c10:{width:new R(28,"mm"),height:new R(40,"mm")},c9:{width:new R(40,"mm"),height:new R(57,"mm")},c8:{width:new R(57,"mm"),height:new R(81,"mm")},c7:{width:new R(81,"mm"),height:new R(114,"mm")},c6:{width:new R(114,"mm"),height:new R(162,"mm")},c5:{width:new R(162,"mm"),height:new R(229,"mm")},c4:{width:new R(229,"mm"),height:new R(324,"mm")},c3:{width:new R(324,"mm"),height:new R(458,"mm")},c2:{width:new R(458,"mm"),height:new R(648,"mm")},c1:{width:new R(648,"mm"),height:new R(917,"mm")},c0:{width:new R(917,"mm"),height:new R(1297,"mm")},"jis-b10":{width:new R(32,"mm"),height:new R(45,"mm")},"jis-b9":{width:new R(45,"mm"),height:new R(64,"mm")},"jis-b8":{width:new R(64,"mm"),height:new R(91,"mm")},"jis-b7":{width:new R(91,"mm"),height:new R(128,"mm")},"jis-b6":{width:new R(128,"mm"),height:new R(182,"mm")},"jis-b5":{width:new R(182,"mm"),height:new R(257,"mm")},"jis-b4":{width:new R(257,"mm"),height:new R(364,"mm")},"jis-b3":{width:new R(364,"mm"),height:new R(515,"mm")},"jis-b2":{width:new R(515,"mm"),height:new R(728,"mm")},"jis-b1":{width:new R(728,"mm"),height:new R(1030,"mm")},"jis-b0":{width:new R(1030,"mm"),height:new R(1456,"mm")},letter:{width:new R(8.5,"in"),height:new R(11,"in")},legal:{width:new R(8.5,"in"),height:new R(14,"in")},ledger:{width:new R(11,"in"),height:new R(17,"in")}},Ax=new R(.24,"pt"),WS=new R(3,"mm"),Fx=new R(10,"mm"),Rx=new R(13,"mm");function ys(e){let t={width:Mr,height:_r,bleed:Re,bleedOffset:Re,cropOffset:Re},i=e.size;if(!(!i||i.value===y.auto)){let l=i.value,u,c;if(l.isSpaceList()?(u=l.values[0],c=l.values[1]):(u=l,c=null),u.isNumeric())t.width=u,t.height=c||u;else{let p=u.name&&Ix[u.name.toLowerCase()];p&&(c&&c===y.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,o=n&&!q(n.value)?n.value:y.none,s=r&&!q(r.value)?r.value:y.auto;if(s===y.auto){if(o!==y.none){let l=!1;o.isSpaceList()?l=o.values.some(u=>u===y.crop):l=o===y.crop,l&&(t.bleed=new R(6,"pt"))}}else s.isNumeric()&&(t.bleed=s);let a=e["crop-offset"],h=a&&!q(a.value)?a.value:y.auto;return h===y.auto?o!==y.none&&(t.bleedOffset=Rx):h.isNumeric()&&(t.cropOffset=h),t}function _u(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),o=n+r,s=e.width;s===Mr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:i.pageWidth=s.num*t.queryUnitSize(s.unit,!1);let a=e.height;return a===_r?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function Gf(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 vr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===y.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var nl=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(nl||{});function Lx(e,t,i,n,r,o,s){let a=r;a<=o+2*jt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,u=Gf(e,l,l),c=[[0,o+r],[r,o+r],[r,o+r-a]],p=c.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=vr(e,i,n);f.setAttribute("points",c.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=vr(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${s}px`}),u}var Fr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Fr||{});function Ox(e,t,i,n,r,o){let s=r*2,a,h;t==="top"||t==="bottom"?(a=s,h=r):(a=r,h=s);let l=Gf(e,a,h),u=vr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let c=vr(e,i,n);c.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(c);let p=vr(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Fr).forEach(g=>{let m=Fr[g];m===t?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function Bx(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let m=s.value;m instanceof te?m.values.forEach(w=>{w===y.crop?r=!0:w===y.cross&&(o=!0)}):m===y.crop?r=!0:m===y.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,u=ut(Ax,n),c=Math.max(0,t.bleedOffset-ut(Fx,n)),p=t.bleedOffset-c,f=e["crop-marks-line-color"],g=f&&!q(f.value)?f.value:y.auto;r&&Object.keys(nl).forEach(m=>{let w=nl[m],S=Lx(l,w,u,g,p,a,c);h.appendChild(S)}),o&&Object.keys(Fr).forEach(m=>{let w=Fr[m],S=Ox(l,w,u,g,p,c);h.appendChild(S)})}var rl=(()=>{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})(),th={"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"}},Mx=(()=>{let e=th;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),ih="vivliostyle-page-rule-master",Rr="_marginBoxes",vs="_footnoteArea",jf=class extends Mf{constructor(e,t,i){super(e,null,ih,[],t,null,0),d(this,"pageMarginBoxes",{});let n=ys(i),r=new _x(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Rr];t&&Mx.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new zx(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new $(y.relative,0),this.specified.width=new $(t.width,0),this.specified.height=new $(t.height,0);for(let i in e)!rl[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new An(e,this)}},_x=class extends jr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new Dx(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new $(y.auto,0),this.specified["z-index"]=new $(new lt(0),0),this.specified.position=new $(y.absolute,0),this.specified.overflow=new $(y.visible,0);for(let t in rl)rl.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new Ux(e,this)}},Dx=class extends jr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new $(M("body"),0)}createInstance(e){return new Xf(e,this)}},zx=class extends jr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[Rr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(_p[i]||r&&r.value===y.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Be&&n.value!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new qf(e,this)}},An=class extends Ql{constructor(e,t){super(e,t),d(this,"pageAreaDimension",null),d(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=Re,e["margin-left"]=Re,e["border-left-width"]=Re,e["padding-left"]=Re,e["padding-right"]=Re,e["border-right-width"]=Re,e["margin-right"]=Re,e.right=Re}initVertical(){let e=this.style;e.top=Re,e["margin-top"]=Re,e["border-top-width"]=Re,e["padding-top"]=Re,e["padding-bottom"]=Re,e["border-bottom-width"]=Re,e["margin-bottom"]=Re,e.bottom=Re}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new G(e.borderBoxWidth),t.height=new G(e.borderBoxHeight),t["padding-left"]=new G(e.marginLeft),t["padding-right"]=new G(e.marginRight),t["padding-top"]=new G(e.marginTop),t["padding-bottom"]=new G(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},u={},c={};for(let b in e){let x=th[b];if(x){let C=e[b],N=this.pageMarginBoxInstances[b],F=new zo(C,N.style,t,h,r);l[x.positionAlongVariableDimension]=C,u[x.positionAlongVariableDimension]=N,c[x.positionAlongVariableDimension]=F}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,m={};Object.keys(l).forEach(b=>{let x=b,C=xe(h,u[x].style[t?"max-width":"max-height"],i.extent);if(C){let N=C.evaluate(n);if(f[x]>N){let F=c[x]=new Du(l[x],u[x].style,t,h,r,N);m[x]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,[o,s,a].forEach(b=>{var x;f[b]=(x=m[b])!=null?x:f[b]}));let w={};Object.keys(l).forEach(b=>{let x=b,C=xe(h,u[x].style[t?"min-width":"min-height"],i.extent);if(C){let N=C.evaluate(n);if(f[x]<N){let F=c[x]=new Du(l[x],u[x].style,t,h,r,N);w[x]=F.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),[o,s,a].forEach(b=>{f[b]=w[b]||f[b]}));let S=p.start+p.extent,v=p.start+(p.start+p.extent);[o,s,a].forEach(b=>{let x=f[b];if(x!=null){let C=l[b],N=0;switch(b){case o:N=t?C.left:C.top;break;case s:N=(v-x)/2;break;case a:N=S-x;break}t?C.setHorizontalPosition(N,x-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(N,x-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,o=e.end,s={};if(r){let a=[n,o],h=new Vx(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),c=Math.max((t-u)/2,0);n&&(s.start=n.hasAutoSize()?c:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?c:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof zo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof zo&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},zo=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,d(this,"hasAutoSize_"),d(this,"size",null),d(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===y.auto||q(o),this.minMaxFitContent=o instanceof ae&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=s[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Pl(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()}},Vx=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}},Du=class extends zo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),d(this,"fixedSize"),this.fixedSize=o}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},Ux=class extends zn{constructor(e,t){super(e,t),d(this,"borderBoxWidth",null),d(this,"borderBoxHeight",null),d(this,"contentBoxWidth",null),d(this,"contentBoxHeight",null),d(this,"marginTop",null),d(this,"marginRight",null),d(this,"marginBottom",null),d(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=i[s].toExpr(n,null),h=xe(n,t[s],a),l=xe(n,t[`margin-${r}`],a),u=xe(n,t[`margin-${o}`],a),c=Pt(n,t[`padding-${r}`],a),p=Pt(n,t[`padding-${o}`],a),f=ni(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=ni(n,t[`border-${o}-width`],t[`border-${o}-style`],a),m=ie(n,ie(n,f,c),ie(n,g,p)),w,S,v;return h?(this.borderBoxSizing?(S=h,v=ye(n,S,m)):(v=h,S=ie(n,v,m)),w=ye(n,a,S),!l&&!u?(l=Co(n,w,new et(n,.5)),u=l):l?u=ye(n,w,l):l=ye(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=ie(n,l,u),S=ye(n,a,w),v=ye(n,S,m),h=this.borderBoxSizing?S:v),t[r]=new G(l),t[o]=new G(u),t[`margin-${r}`]=Re,t[`margin-${o}`]=Re,t[`border-${r}-width`]=new G(f),t[`border-${o}-width`]=new G(g),t[`padding-${r}`]=new G(c),t[`padding-${o}`]=new G(p),t[s]=new G(h),t[`max-${s}`]=new G(h),{borderBoxExtent:S,contentBoxExtent:v,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},Xf=class extends zn{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new G(this.parentInstance.contentBoxWidth),e["margin-left"]=new G(new mn(i,t.left.toExpr(i,null))),e["margin-right"]=new G(new mn(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=y.solid,e["border-right-style"]=y.solid,e["border-left-color"]=y.transparent,e["border-right-color"]=y.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new G(this.parentInstance.contentBoxHeight),e["margin-top"]=new G(new mn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new G(new mn(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=y.solid,e["border-bottom-style"]=y.solid,e["border-top-color"]=y.transparent,e["border-bottom-color"]=y.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},qf=class extends zn{constructor(e,t){super(e,t),d(this,"boxInfo"),d(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=th[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){I(t,"display","flex"),I(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===M("middle")?n="center":i===M("top")?n="flex-start":i===M("bottom")&&(n="flex-end"),n&&I(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof tt||r instanceof G&&r.expr instanceof Le&&r.expr.str.startsWith("running-element-")){let o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),I(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=xe(n,i[s],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new G(u);else if(l){let c=Pt(n,i[`margin-${r}`],h),p=Pt(n,i[`margin-${o}`],h),f=Pt(n,i[`padding-${r}`],h),g=Pt(n,i[`padding-${o}`],h),m=ni(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=ni(n,i[`border-${o}-width`],i[`border-${o}-style`],h),S=ie(n,l,ie(n,this.borderBoxSizing?n.zero:ie(n,ie(n,f,g),ie(n,m,w)),ie(n,c,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new G(ie(n,u,ma(n,ye(n,h,S),new et(n,2))));break;case"end":i[r]=new G(ye(n,ie(n,u,h),S));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,o=e.inside,s=e.outside,a=e.extent,h=t[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=Fu(n,i[`margin-${o}`],h),u=Fu(n,i[`margin-${s}`],h),c=Pt(n,i[`padding-${o}`],h),p=Pt(n,i[`padding-${s}`],h),f=ni(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=ni(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=xe(n,i[a],h),w=null;function S(v){if(w)return w;w={extent:m?m.evaluate(v):null,marginInside:l?l.evaluate(v):null,marginOutside:u?u.evaluate(v):null};let b=h.evaluate(v),x=0;return r||[f,c,p,g].forEach(C=>{C&&(x+=C.evaluate(v))}),(w.marginInside===null||w.marginOutside===null)&&x+w.extent+w.marginInside+w.marginOutside>b&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=b-x-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=b-x-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=b-x-w.extent-w.marginInside:w.marginInside=w.marginOutside=(b-x-w.extent)/2),w}i[a]=new G(new Le(n,function(){let v=S(this).extent;return v===null?"auto":v},a)),i[`margin-${o}`]=new G(new Le(n,function(){let v=S(this).marginInside;return v===null?"auto":v},`margin-${o}`)),i[`margin-${s}`]=new G(new Le(n,function(){let v=S(this).marginOutside;return v===null?"auto":v},`margin-${s}`)),o==="left"?i.left=new G(ie(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new G(ie(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,o,s){super.finishContainer(e,t,i,n,r,o,s);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let u=this.parentInstance.pageAreaDimension,c=this.getProp(e,"width"),p=c instanceof ae&&(c.name==="min-content"||c.name==="max-content"||c.name==="fit-content")?c.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let b=this.getProp(e,"margin-left"),x=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);I(t.element,"right",`${C}px`),(b===y.auto||x!==y.auto)&&I(t.element,"margin-left","auto"),x===y.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(x===y.auto||b!==y.auto)&&I(t.element,"margin-right","auto"),b===y.auto&&I(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof ae&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,S=this.getPropAsNumber(e,"min-height"),v=this.getPropAsNumber(e,"max-height");if(w||S||v){w&&I(t.element,"height",w),S&&I(t.element,"min-height",`${S}px`),v&&I(t.element,"max-height",`${v}px`);let b=this.getProp(e,"margin-top"),x=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);I(t.element,"bottom",`${C}px`),(b===y.auto||x!==y.auto)&&I(t.element,"margin-top","auto"),x===y.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(x===y.auto||b!==y.auto)&&I(t.element,"margin-bottom","auto"),b===y.auto&&I(t.element,"margin-top","auto"))}}},$x=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,d(this,"pageMasterCache",{}),d(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Ke(e,"page-number"),r=new yl(e,new kc(e,n,new et(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ei(e,r)),e.defineName("verso-page",r),(t.pageProgression||Wf(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new Ei(e,r))):(e.defineName("left-page",new Ei(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),r=this.pageMasterCache[n];return r||(i.pseudoName===Jl?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof $?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new jf(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:ih}),n=i.specified,r=e.size;if(r&&!q(r.value)){let s=ys(e),a=r.priority;qt(n,"width",new $(s.width,a),this.context),qt(n,"height",new $(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(e[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},Hx=class extends Pe{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}},Wx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Gx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},jx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Xx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},qx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Yx=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Ke(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Zx=class extends en{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}},Kx=class extends en{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},Jx=class extends Hl{constructor(e,t){super(e,t,null,null,null)}apply(e){Qx(e.context,e.currentStyle,this.style,this.specificity,e)}};function Qx(e,t,i,n,r){ds(e,t,i,n,null,null,null);let o=i[Rr];if(o){let a=ri(t,Rr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),ds(e,l,o[h],n,null,null,null)}}let s=i[vs];if(s){let a=ri(t,vs);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=s[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof $&&qt(l,p,f)}let c=pt(u,"_pseudos");if(c){let p=ri(l,"_pseudos");for(let f in c)if(c.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=c[f];for(let w in m)if(m.hasOwnProperty(w)){let S=m[w];S instanceof $&&qt(g,w,S)}}}}}}var eS=class extends Nr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,d(this,"currentPageSelectors",[]),d(this,"currentNamedPageSelector",""),d(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new Hx(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new Kx(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Zx(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 Wx(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Gx(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new jx(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Xx(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new qx(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Yx(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(o=>o.selectors===null))return;super.simpleProperty(e,t,i);let n=ge(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{Ni(r[o],e,n)});else if(e==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=new $(n.value,n.priority+s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?qt(l,e,a):(l=r[h]={},Ni(l,e,a),o&&["bleed","marks"].forEach(u=>{o[u]&&Ni(l,u,o[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Jx(this.elementStyle,e)}startFootnoteRule(e){let t=ri(this.elementStyle,vs),i=t.area;if(i||(i={},t.area=i),e){let r=ri(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new Yf(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=ri(this.elementStyle,Rr),i=t[e];i||(i={},t[e]=i);let n=new tS(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},tS=class extends Qi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new $(t,n);Ni(this.boxStyle,e,r)}},Yf=class extends Qi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new $(t,n);Ni(this.areaStyle,e,r)}},Zf=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,d(this,"lang",null),d(this,"totalOffset",-1),d(this,"root"),d(this,"body"),d(this,"head"),d(this,"last"),d(this,"lastOffset",1),d(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Qt,"0")}doc(){return new Jf([this.document])}getElementOffset(e){let t=e.getAttribute(Qt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(Qt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=fi(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},ol=(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))(ol||{});function vo(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let o=r.documentElement,s="parsererror";if(o.localName===s)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===s)return null}else return null;return r}function iS(e){let t=e.contentType;if(t){let n=Object.keys(ol);for(let r=0;r<n.length;r++)if(ol[n[r]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Kf(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=iS(e);if(i=vo(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=vo(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=vo(o,"image/svg+xml",r))}i||(i=vo(o,"text/html",r))}}let n=i?new Zf(t,e.url,i):null;return T(n)}function nS(){return new Sl(Kf,"document")}var rS=class sl{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new sl(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new sl(n=>{if(!this.check(n))return!1;let r=new Jf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},zu=new rS(e=>!0),Jf=class al{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 al(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new al(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},oS=new Vr(()=>{let e=D("uaStylesheetBase"),t=Op(),i=Ae("user-agent-base.css",Ci),n=new Nr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Ub(n.cascade),Cl(fd,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function sS(){return oS.get()}var aS=class extends Do{constructor(e,t,i,n,r,o){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=o}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||j.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},lS=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=o,this.footnoteProps=s,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,d(this,"fontDeobfuscator"),d(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(c);return p.matchPageSide(f.startSideOfFlow(c))&&f.hasContent(c,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Le(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Le(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new fa(this.rootScope,e,t,i),o=lb(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let u=jt.em;if((h?h.evaluate(r,"text-zoom"):null)===y.scale&&(l=u/i,i=u,e*=l,t*=l),s&&a){let c=ut(s.evaluate(r,"width"),r),p=ut(a.evaluate(r,"height"),r);if(c>0&&p>0)return{width:n&&n.spreadView?(c+n.pageBorder)*2:c,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function Vu(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function Uu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var nh=class extends fa{constructor(e,t,i,n,r,o,s,a,h,l,u,c,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=o,this.customRenderer=s,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=u,this.cmykStore=c,d(this,"lang"),d(this,"primaryFlows",{body:!0}),d(this,"rootPageBoxInstance",null),d(this,"styler",null),d(this,"stylerMap",null),d(this,"currentLayoutPosition",null),d(this,"layoutPositionAtPageStart",null),d(this,"currentCascadedPageStyle",null),d(this,"lookupOffset",0),d(this,"faces"),d(this,"pageBoxInstances",{}),d(this,"pageManager",null),d(this,"rootPageFloatLayoutContext"),d(this,"pageBreaks",{}),d(this,"pageProgression",null),d(this,"isVersoFirstPage",!1),d(this,"blankPageAtStart",!1),d(this,"pageSheetSize",{}),d(this,"pageSheetHeight",0),d(this,"pageSheetWidth",0),d(this,"invalidPageAreaOnCurrentPage",!1),d(this,"repeatedInvalidPageAreaLayoutPosition",null),d(this,"semanticFootnoteFirstRefOffsets",new Map),d(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),d(this,"pageGroupPageCounts",Object.create(null)),d(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new rx(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new gn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=ge(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==y.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=D("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Nu(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=Wf(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Ex(r);let o=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new $x(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let s=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=nx(h.properties,this),u=new Lf(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{hx(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l);let u=_u(ys(l),this);this.pageSheetSize[h]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new fa(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Nu(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,o,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new Iy,i.flowPositions[e.flowName]=n);let r=Py(e.element),o=new Ai(r),s=new Ty(o,e);n.positions.push(s)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;if(je(e))return typeof CSS<"u"&&CSS.supports(`(${e}:${t})`);let n=!0;class r{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let o=new r,s=Ti(this.style.rootScope,new vt(t,null),"");return s?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,s,!1,o),n):!1}evalSupportsSelector(e){class t extends Qf{errorMsg(...s){}}let i=new t(null),n=Qc(e),r=new vt(n+"{}",i);return new Ur($e,r,i,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!i.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,r=n.steps[0].node,o=n.offsetInNode,s=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,s=!1,o=0;let h=this.xmldoc.getNodeOffset(r,o,s);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let o=0;o<r.positions.length;o++){let s=r.positions[o].chunkPosition.primary,a=this.getNodePositionOffset(s);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,o=t<=r,s=n===i&&o?this.getFirstInFlowChildElement(i):n;if(!s)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(s),h=t;return o&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(s)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(s)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),o=t<=r;return n===i&&o?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return Ye(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ge(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ge(e,"page");if(!t||q(t.value))return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPageStartPageType(e){let t=this.getPageStartOffset(e,!0),i=this.getPageStartElement(e,t);for(;i;){let n=this.styler.getStyle(i,!1),r=n&&ge(n,"page");if(r&&!q(r.value)){let o=r.evaluate(this,"page").toString();if(o&&o.toLowerCase()!=="auto")return o}if(i===this.xmldoc.root)break;i=i.parentElement}return""}getPageStartPageTypeOverride(e){if(this.getPageStartPageType(e)!=="")return;let t=this.getPageStartOffset(e,!0),i=this.getPageStartElement(e,t);for(;i&&(i=this.getFirstInFlowChildElement(i),!!i);){let n=this.getPageGroupPageType(i);if(n)return n}return""}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),o=this.xmldoc.body||this.xmldoc.root,s=this.xmldoc.getElementOffset(o);if(i<=s&&e===o||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),o=On(i)&&!this.matchPageSide(i)&&!r,s=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!o,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&s;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let c=h;for(;c;){let p=this.getPageGroupPageType(c);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(c)||0;(g>0||s&&(u||this.shouldStartPageGroup(c,p,a)))&&(g+=1,f.set(c,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(c===this.xmldoc.root)break;c=c.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Oe(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===y.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!q(r)?r:y.static;if(Yo(o)||Ns(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!q(s)?s:y.none)===y.none}isInlineLevelElement(e){return Gt(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!q(n)?n:y.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let o=this.getConsumedOffset(r);o<i&&(i=o)}}return i}dumpLocation(e){j.debug("Location - page",this.currentLayoutPosition.page),j.debug(" current:",e),j.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)j.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Ke(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,o=i.startBreakType;i.startBreakType=qh(nt(o,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let o=0;o<n.length;o++){if(r=n[o],r.pageBox.pseudoName===ih)continue;let s=1;r.pageBox.pseudoName===Jl&&!(this.actualPageWidth&&this.actualPageHeight)&&(s=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(s=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(s*l/(h*h)),c=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=c,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===y._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let o=fi(r.length,l=>r[l]>n)-1,s=r[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return s<h?!1:h<s?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Fl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new gn(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Ie.PAGE)return!1;let c=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=c?this.getConsumedOffset(c):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},o=D("layoutDeferredPageFloats"),s=!1,a=0;return o.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let c=new Bn().findByFloat(u),p=c.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,c,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(s=!0,t.validate());h.continueLoop()})}).then(()=>{s&&t.invalidate(),o.finish(!0)}),o.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Ai(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return i?(this.setFormattingContextToColumn(e,t),e.init(),this.layoutDeferredPageFloats(e)):T(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=D("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],o=[],s=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-o.length>0;){let h=0;for(;o.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(o.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,c=!0;if(e.layout(l.chunkPosition,s,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(s=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){o.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-o.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=qh(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,c?c=!1:a.continueLoop()}),c){c=!1;return}}a.breakLoop()}).then(()=>{var a;if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,u)=>r.includes(u)||!o.includes(u)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let h=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(h),e.computedBlockSize===0){let l=e.pageFloatLayoutContext,u=l;for(;u;){let c=u.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(c.length>0&&!u.ignoreFootnoteAreaMaxHeight&&c.some(p=>{let f=getComputedStyle(p.area.element),g=m=>m!==""&&m!=="none";return g(f.getPropertyValue("max-block-size"))||g(p.area.vertical?f.maxWidth:f.maxHeight)})){u.ignoreFootnoteAreaMaxHeight=!0;for(let p of c){l.removePageFloatFragment(p,!0);let f=(a=p.continuations[0])==null?void 0:a.float;f&&u.removeFloatDeferredToNext(f)}l.invalidate();break}u=u.parent}}}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new h0([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,u,c,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,m=r.element,w=new gn(a,Ie.COLUMN,null,s,null,null,null),S=this.currentLayoutPosition.clone(),v=D("createAndLayoutColumn"),b;return v.loopWithFrame(x=>{let C=this.createLayoutConstraint(w);if(h>1){let N=this.viewport.document.createElement("div");if(I(N,"position","absolute"),m.appendChild(N),b=new gs(N,p,this.clientLayout,C,w),b.isNonFirstColumn=o>0,b.forceNonfitting=f,b.vertical=r.vertical,b.rtl=r.rtl,b.snapHeight=r.snapHeight,b.snapWidth=r.snapWidth,r.vertical){let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingTop,L=parseFloat(m.style.width);b.setHorizontalPosition(r.paddingLeft+L-r.width,r.width),b.setVerticalPosition(F,u)}else{let F=(r.rtl?h-o-1:o)*(u+l)+r.paddingLeft;b.setVerticalPosition(r.paddingTop,r.height),b.setHorizontalPosition(F,u)}b.originX=t,b.originY=i}else b=new gs(m,p,this.clientLayout,C,w),b.isNonFirstColumn=!1,b.copyFrom(r);b.exclusions=g?[]:n.concat(),b.innerShape=c,w.setContainer(b),(b.vertical?b.height:b.width)>=0?this.layoutColumn(b,s).then(()=>{w.isInvalidated()||w.finish(),b.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(b.pageFloatLayoutContext.validate(),this.currentLayoutPosition=S.clone(),b.element!==m&&m.removeChild(b.element),x.continueLoop()):x.breakLoop()}):(w.finish(),x.breakLoop())}).then(()=>{v.finish(b)}),v.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Xf||t instanceof Ql&&!(t instanceof An))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof zn;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new gn(e,Ie.REGION,i,n,null,r,o)}layoutFlowColumnsWithBalancing(e,t,i,n,r,o,s,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(o,t,s,a),c=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,u,s,a,h,c).thenAsync(f=>T(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return T(null);if(h<=1)return T(f.columns);let g=t.getProp(this,"column-fill")||y.balance,m=this.currentLayoutPosition.flowPositions[a],w=K0(h,g,p,u,s,f.columns,m);return w?(c=!1,o.lock(),u.lock(),w.balanceColumns(f).thenAsync(S=>(o.unlock(),o.validate(),u.unlock(),this.currentLayoutPosition=S.position,T(S.columns)))):T(f.columns)})}layoutFlowColumns(e,t,i,n,r,o,s,a,h,l,u){let c=D("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=Vu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),S=t.getProp(this,"shape-inside"),v=Yc(S,0,0,a.width,a.height,this),b=new wx(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),x=0,C=null,N=[];return c.loopWithFrame(F=>{this.createAndLayoutColumn(t,i,n,r,a,x++,h,s,l,g,m,v,b,u).then(L=>{if(o.isInvalidated()){N=null,F.breakLoop();return}if((L.pageBreakType&&L.pageBreakType!=="column"||x===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){x=0,this.currentLayoutPosition=p.clone(),Uu(f),s.validate(),s.isLocked()?(N=null,F.breakLoop()):F.continueLoop();return}C=L,N[x-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(x=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),x<l?F.continueLoop():F.breakLoop()})}).then(()=>{c.finish(N)}),c.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return T(!0);let h=D("layoutContainer"),l=t.getProp(this,"wrap-flow")===y.auto,u=t.getProp(this,"flow-from"),c=this.viewport.document.createElement("div");c.role=t instanceof qf?"complementary":"presentation";let p=t.getProp(this,"position");I(c,"position",p?p.name:"absolute");let f=t instanceof An;t instanceof zn?i.appendChild(c):i.insertBefore(c,i.firstChild);let g=new Zd(c);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=o,t.prepareContainer(this,g,e,this.faces,this.clientLayout),(g.width<=0||g.height<=0)&&(t instanceof An||u&&u.isIdent())&&(this.invalidPageAreaOnCurrentPage=!0,j.warn("Negative or zero page area size")),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(s,t,g);let m,w=!1;if(!u||!u.isIdent()){let S=[],v=t.getProp(this,"content");if(v instanceof G&&v.expr instanceof Le&&v.expr.str.startsWith("running-element-"))v.visit(new kr(c,this,v,this.counterStore.getExprContentListener()));else if(Tt(v)){let b="span";v instanceof tt&&(b="img");let x=this.viewport.document.createElement(b);v.visit(new kr(x,this,v,this.counterStore.getExprContentListener())),c.appendChild(x),b=="img"&&t.transferSingleUriContentProps(this,x,this.faces),t.transferContentProps(this,g,e,this.faces);let C=x.querySelectorAll("img[src]");for(let F=0;F<C.length;F++){let L=C[F],V=L.getAttribute("src");if(!V)continue;let Y=Ct(L,V);S.push(Y),e.fetchers.push(Y)}let N=x.getAttribute("src");if(N){let F=x.querySelector("img");F||(F=x);let L=Ct(F,N);S.push(L),e.fetchers.push(L)}b=="span"&&t0(x,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(c),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=S.length?Rn(S).thenReturn(!0):T(!0)}else if(this.pageBreaks[u.toString()])s.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=T(!0);else{let S=D("layoutContainer.inner"),v=u.toString(),b=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,v,b).then(x=>{if(!s.isInvalidated()){let C=x[0];C.element===c&&(g=C),g.computedBlockSize=Math.max.apply(null,x.map(F=>F.computedBlockSize)),t.finishContainer(this,g,e,C,b,this.clientLayout,this.faces);let N=this.currentLayoutPosition.flowPositions[v];N&&N.breakAfter==="region"&&(N.breakAfter=null)}S.finish(!0)}),m=S.result()}return m.then(()=>{if(s.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let v=t.getProp(this,"shape-outside"),b=g.getOuterShape(v,this);o.push(b)}}else if(t.children.length==0){i.removeChild(c),h.finish(!0);return}let S=f?0:t.children.length-1;h.loop(()=>{for(;S>=0&&S<t.children.length;){let v=t.children[f?S++:S--],b=this.layoutContainer(e,v,c,n,r,o,s);if(b.isPending())return b.thenAsync(()=>T(!s.isInvalidated()));if(s.isInvalidated())break}return T(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}hasSameFlowPositions(e,t){if(e===t)return!0;if(!e||!t)return!1;let i=Object.keys(e.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!e.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}checkRepeatedInvalidPageArea(e){let t=this.invalidPageAreaOnCurrentPage;if(this.invalidPageAreaOnCurrentPage=!1,!t){this.repeatedInvalidPageAreaLayoutPosition=null;return}if(e.isBlankPage||this.noMorePrimaryFlows(e))return;if(!this.hasSameFlowPositions(this.layoutPositionAtPageStart,e)){this.repeatedInvalidPageAreaLayoutPosition=null;return}let i=!!this.repeatedInvalidPageAreaLayoutPosition&&this.hasSameFlowPositions(this.repeatedInvalidPageAreaLayoutPosition,this.layoutPositionAtPageStart);if(this.repeatedInvalidPageAreaLayoutPosition=this.layoutPositionAtPageStart.clone(),i)throw new Error("Negative or zero page area size")}layoutNextPage(e,t){var i,n,r,o;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Ay,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),this.invalidPageAreaOnCurrentPage=!1,t=this.currentLayoutPosition;let a=t.startSideOfFlow("body");t.isBlankPage=On(a)&&this.matchPageSide(a),e.isBlankPage=t.isBlankPage,t.page++;let h=this.getPageStartPageTypeOverride(t);h===""?e.pageType="":h&&(e.pageType=h),e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=Vu(t),u=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!s){let S=new Ke(this.style.pageScope,"left-page");e.side=S.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(u);if(!c)return T(null);let p=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===Mr),e.setAutoPageHeight(c.pageBox.specified.height.value===_r);let{counterOffset:S,changeOffset:v}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(S)||(S=this.lookupOffset,v=this.lookupOffset),isFinite(S)&&this.styler.styleUntil(S,0);let b=this.styler.getCounterSnapshotAtOffset(S),x=v===S?b:this.styler.getCounterSnapshotAtOffset(v);b||(b=this.styler.getLastCounterSnapshot()),x||(x=b);let C=x&&x.offset===v?x:null;this.counterStore.setCurrentPageDocCounters((r=b?.counters)!=null?r:null,(o=C?.changes)!=null?o:null,C?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let N=_u(ys(u),this);this.setPageSizeAndBleed(N,e),Bx(u,N,e,this),p=N.bleedOffset+N.bleed}let f=!s&&c.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=f!=y.horizontal_tb;let g=c.getProp(this,"direction")||y.ltr,m=new gn(this.rootPageFloatLayoutContext,Ie.PAGE,null,null,null,f,g),w=D("layoutNextPage");return w.loopWithFrame(S=>{this.layoutContainer(e,c,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Uu(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);S.continueLoop()}else S.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,this.checkRepeatedInvalidPageArea(t),Object.keys(t.flowPositions).forEach(v=>{let b=t.flowPositions[v],x=b.breakAfter;x&&(x==="page"||!this.matchPageSide(x))&&(b.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let S=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(S,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},hS=class ll extends Nr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,d(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Mf(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Tx(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=zt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new ll(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Xb(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Do(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new aS(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 Do(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Do(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ri(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new Yf(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new eS(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Nr.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",M(t)),this.endRule();let i=new ll(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Qf=class extends Ea{constructor(e){super(),this.validatorSet=e,d(this,"rootScope"),d(this,"pageScope"),d(this,"rootBox"),d(this,"cascadeParserHandler"),d(this,"regionCount",0),d(this,"fontFaces",[]),d(this,"counterStyles",new Tv),d(this,"footnoteProps",{}),d(this,"flowProps",{}),d(this,"viewportProps",[]),d(this,"pageProps",{}),this.rootScope=new Go(null),this.pageScope=new Go(this.rootScope),this.rootBox=new xx(this.rootScope),this.cascadeParserHandler=new hS(this,null,null,null),this.slave=this.cascadeParserHandler}};function uS(e,t){return t.parseOPSResource(e)}var cS=class extends Sl{constructor(e){super(uS,"document"),this.fontDeobfuscator=e,d(this,"styleByKey",{}),d(this,"styleFetcherByKey",{}),d(this,"styleByDocURL",{}),d(this,"triggersByDocURL",{}),d(this,"validatorSet",null),d(this,"styleSheets",[]),d(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=D("OPSDocStore.init");return this.validatorSet=Op(),sS().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=Ae(kn(t),Xi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ae(kn(t),Xi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=D("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return Kf(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Ut("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){j.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),S=f.getAttribute("ref");g&&m&&w&&S&&s.push({observer:g,event:m,action:w,ref:S})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ae("user-agent-page.css",Ci),text:pd,flavor:"UA",classes:null,media:null}),h.push({url:Ae("user-agent-counter-styles.css",Ci),text:wd,flavor:"UA",classes:null,media:null}),n)h.push({url:Ae("user-agent-toc.css",Ci),text:gd,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),S=f.getAttribute("media"),v=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:v?w:null,media:S})}else if(m=="link"){let w=f.getAttribute("href"),S=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),v=f.getAttribute("class"),b=f.getAttribute("media");if(w&&S!=null&&S.includes("stylesheet")&&(!S.includes("alternate")||v)){let x=Ae(w,i),C=f.getAttribute("title");h.push({url:x,text:null,classes:C?v:null,media:b,flavor:"Author"})}}else m=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let c=this.styleFetcherByKey[l];c||(c=new Vr(()=>{let p=D("fetchStylesheet"),f=0,g=new Qf(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Cl(m.text,g,m.url,m.classes,m.media).thenReturn(!0):kd(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new lS(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=c,c.start()),c.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},br="\u25B8",$u="\u25BE",dS="\u25B9";function rh(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function pS(e){let t=rh(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var fS=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=s,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,d(this,"pref"),d(this,"page",null),d(this,"instance",null),this.pref=pc(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;bi(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),bi(n,"position","static")=="absolute"&&(I(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-node":r.display=y.block,r.margin=Re,r.padding=Re,r["padding-inline-start"]=new R(1.25,"em");break;case"toc-node-first-child":r.display=y.inline_block,r.margin=new R(.2,"em"),r["vertical-align"]=y.top,r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-container":r.padding=Re;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Oe(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=br&&(l.textContent=br,I(l,"cursor","pointer"),l.addEventListener("click",gS,!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=dS,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return T(h)}}showTOC(e,t,i,n,r){if(this.page)return T(this.page);let o=D("showTOC"),s=new Ud(e,e);this.page=s;let a=Dt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of rh(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new ws(t.window,u.fontSize,0,e,u.width,u.height);let c=this.makeCustomRenderer(h),p=new nh(l,h,this.lang,t,this.clientLayout,this.fontMapper,c,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(e,2),o.finish(s)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function gS(e){let t=e.target,i=t.textContent==br;t.textContent=i?$u:br;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==$u){a.textContent=br,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function bo(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function mS(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function wS(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Dt(e))}var Hu=class extends cS{constructor(){super(null),d(this,"plainXMLStore"),d(this,"jsonStore"),d(this,"opfByURL",{}),d(this,"primaryOPFByEPubURL",{}),d(this,"deobfuscators",{}),d(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=nS(),this.jsonStore=zw()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new Vo(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=D("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):wS(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):Es(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}j.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=D("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of r)if(o){this.loadOPF(e,o).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return T(n);let r=D("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new Vo(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(s=>{n.initWithXMLDoc(o,s).then(()=>{r.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=D("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new Vo(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=dl(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ae(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&rh(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=D("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(Xi)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?j.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Xi.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?j.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?j.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):j.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Dt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=D("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let r=i.width-0,o=i.height-0;if(r&&o){let s=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${o}px;}`+(s?`@page{size:${r}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},Wu=class{constructor(){d(this,"id",null),d(this,"src",""),d(this,"mediaType",null),d(this,"title",null),d(this,"itemRefElement",null),d(this,"spineIndex",-1),d(this,"compressedSize",0),d(this,"compressed",null),d(this,"epage",0),d(this,"epageCount",0),d(this,"startPage",null),d(this,"skipPagesBefore",null),d(this,"itemProperties"),this.itemProperties=_g}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ae(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Wg(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 yS(e){return e.id}function vS(e){return t=>{let i=D("deobfuscator");return bS("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Mw(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(yd([a,o]))})}),i.result()}}function bS(e,t){let i=D("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var Si={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"},hr="http://idpf.org/epub/vocab/package/meta/#",Xe={language:`${Si.dcterms}language`,title:`${Si.dcterms}title`,creator:`${Si.dcterms}creator`,layout:`${Si.rendition}layout`,titleType:`${hr}title-type`,displaySeq:`${hr}display-seq`,alternateScript:`${hr}alternate-script`,role:`${hr}role`};function xS(e,t){let i={};return(n,r)=>{var o,s,a,h,l,u;let c,p,f=n.r||i,g=r.r||i;if(e==Xe.title&&(c=((o=f[Xe.titleType])==null?void 0:o[0].v)=="main",p=((s=g[Xe.titleType])==null?void 0:s[0].v)=="main",c!=p))return c?-1:1;let m=parseInt((a=f[Xe.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[Xe.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=Xe.language&&t&&(c=((l=f[Xe.language]||f[Xe.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[Xe.language]||g[Xe.alternateScript])==null?void 0:u[0].v)==t,c!=p)?c?-1:1:n.o-r.o}}function SS(e,t){let i;if(!t)i=Si;else{i={};for(let p in Si)i[p]=Si[p];let c;for(;(c=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(c[0].length),i[c[1]]=c[2]}let n=c=>{if(c){let p=c.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:hr;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(c=>{if(c.localName=="meta"){let p=n(c.getAttribute("property"));if(p)return{name:p,value:c.textContent,id:c.getAttribute("id"),order:r++,refines:c.getAttribute("refines"),lang:null,scheme:n(c.getAttribute("scheme")),role:null}}else if(c.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Si.dcterms+c.localName,order:r++,lang:c.getAttribute("xml:lang"),value:c.textContent,id:c.getAttribute("id"),refines:null,scheme:null,role:c.getAttribute("role")||c.getAttribute("opf:role")};return null}),s=js(o,c=>c.refines),a=c=>Gg(c,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=s[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:Xe.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:Xe.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let S=js(w,v=>v.name);m.r=a(S)}return m})),h=a(js(o,c=>c.refines?null:c.name)),l=null;h[Xe.language]&&(l=h[Xe.language][0].v);let u=c=>{for(let p in c){let f=c[p];f.sort(xS(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function CS(){let e=window.MathJax;return e?e.Hub:null}var Gu={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},ca="viv-id-",Vo=class{constructor(e,t){this.store=e,this.pubURL=t,d(this,"opfXML",null),d(this,"encXML",null),d(this,"items",null),d(this,"spine",null),d(this,"itemMap",null),d(this,"itemMapByPath",null),d(this,"uid",null),d(this,"bindings",{}),d(this,"lang",null),d(this,"epageCount",0),d(this,"prePaginated",!1),d(this,"epageIsRenderedPage",!0),d(this,"epageCountCallback",null),d(this,"metadata",{}),d(this,"toc",null),d(this,"cover",null),d(this,"fallbackMap",{}),d(this,"pageProgression",null),d(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let o=r+(n?`#${n}`:"");return ca+uc(o,":")}transformURL(n,r){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let s=o[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(o[2]);if(s&&e.spine.some(h=>h.src===s))return`#${this.transformFragment(a,s)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(ca)===0&&(n=n.substring(ca.length));let r=Hg(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ae("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new Wu,u=h;l.initWithElement(u,e.url);let c=u.getAttribute("fallback");return c&&!Gu[l.mediaType]&&(r[l.src]=c),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=wh(this.items,yS),this.itemMapByPath=wh(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(Gu[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,c=u.getAttribute("idref"),p=this.itemMap[c];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=tc(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(zu.withChild("EncryptionMethod",zu.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=SS(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Xe.language]&&(this.lang=this.metadata[Xe.language][0].v),this.metadata[Xe.layout]&&(this.prePaginated=this.metadata[Xe.layout][0].v==="pre-paginated"),s.length>0&&this.uid){let h=vS(this.uid);for(let l=0;l<s.length;l++)this.store.deobfuscators[this.pubURL+s[l]]=h}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let t=0,i=0,n=D("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(s=>{let a=1800,h=s.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(s.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Zf(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Wu;r.initWithParam(n),r.id;let o=i.document.createElement("itemref");o.setAttribute("idref",r.id),i.root.appendChild(o),r.itemRefElement=o,this.itemMap[r.id]=r;let s=this.getPathFromURL(n.url);s==null&&(s=n.url),this.itemMapByPath[s]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):T(null)}initWithWebPubManifest(e,t,i){var n,r,o,s;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Xe.title]=(Array.isArray(a)?a:[a]).map(S=>{var v;return{v:(v=S.value)!=null?v:S}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(S=>S.content);h&&h.length!==0&&(this.metadata[Xe.creator]=(Array.isArray(h)?h:[h]).map(S=>{var v;return{v:(v=S.name)!=null?v:S}}));let l=e.inLanguage||((s=e.metadata)==null?void 0:s.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Xe.language]=(Array.isArray(l)?l:[l]).map(S=>({v:S})));let u=Dt(this.pubURL),c=this.getPathFromURL(u),p=c!==null?encodeURI(c):/^(?:about:|blob:)/i.test(u)?u:null;if(!e.readingOrder&&t&&p!==null){e.readingOrder=[p];for(let S of pS(t)){let v=S.getAttribute("href");if(/^(https?:)?\/\//.test(v)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(v))continue;let b=Dt(Ae(v,this.pubURL)),x=this.getPathFromURL(b),C=x!==null?encodeURI(x):b;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,m=-1;[e.readingOrder,e.resources].forEach(S=>{S instanceof Array&&S.forEach(v=>{let b=S===e.readingOrder,x=typeof v=="string"?v:v.url||v.href,C=typeof v=="string"?"":v.encodingFormat||v.href&&v.type||"";if(b||C==="text/html"||C==="application/xhtml+xml"||!C&&v.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(x)){let N=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,F={url:Ae(kn(x),N),index:g++,startPage:null,skipPagesBefore:null};v.rel==="contents"&&m===-1&&(m=F.index),f.push(F)}})});let w=D("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var S,v;m!==-1&&(this.toc=this.items[m]),this.toc||(this.toc=i?(S=this.items)==null?void 0:S[0]:this.itemMapByPath[c]);let b=(v=e.readingOrder)==null?void 0:v.length;b&&b<this.items.length&&this.items.splice(b),w.finish(!0)}),w.result()}getCFI(e,t){let i=this.spine[e],n=D("getCFI");return this.store.load(i.src).then(r=>{let o=r.getNodeByOffset(t),s=null;if(o){let a=r.getNodeOffset(o,0,!1),h=t-a,l=new Ah;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),s=l.toString()}n.finish(s)}),n.result()}resolveFragment(e){return Fn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Ah;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let o=r.node,s=o.getAttribute("idref");if(o.localName!="itemref"||!s||!this.itemMap[s]){t.finish(null);return}n=this.itemMap[s],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let o=i.navigate(r.document),s=r.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:s,pageIndex:-1})})},(t,i)=>{j.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Fn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let o=this.spine[r];(!o||o.epageCount==0)&&(o=this.spine[--r]);let s=Math.floor(e-o.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:s});return}let i=fi(this.spine.length,r=>{let o=this.spine[r];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let s=r.getTotalOffset();o=Math.round(s*e/n.epageCount),o==s&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{j.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return T(n)}if(e.offsetInItem<=0)return T(t.epage);let i=D("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),o=Math.min(r,e.offsetInItem);i.finish(t.epage+o*t.epageCount/r)}),i.result()}},xo=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),kS=class{constructor(e,t,i,n,r,o){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,d(this,"spineItems",[]),d(this,"spineItemLoadingContinuations",[]),d(this,"pref"),d(this,"clientLayout"),d(this,"counterStore"),d(this,"cmykStore"),d(this,"tocAutohide",!1),d(this,"tocVisible",!1),d(this,"tocView"),d(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=pc(n),this.clientLayout=new vx(t),this.counterStore=new _m(e.documentURLTransformer),this.cmykStore=new Uc,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return T(!0);let i=D("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<e;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(e=n[r])!=null?e:0;t+=Math.min(o,s)}return t}reportPaginationProgress(e,t){let i=Ut("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),o=r;t&&(o=e.instance.getPosition(t,!0)),o<0&&(o=0),o>r&&(o=r);let s=this.paginationProgress.renderedOffsetsBySpine[n];s!=null&&o<s&&(o=s),this.paginationProgress.renderedOffsetsBySpine[n]=o;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let c={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(c)}catch(f){j.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,u=n.offset!==t.offset,c=s&&!u&&i>0;if(a=n.pageType!=null&&(c||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,s){let p=e.instance.getPageStartPageTypeOverride(t.position);p===""?t.pageType="":p&&(t.pageType=p)}if(!s&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||o)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=bo(n));let r=bo(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return T(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let o=e.pages[t.page],s=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||s,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,o,a,s,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=D("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),s=0,a=t;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let c=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:c.currentPageType,previousPageType:c.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=mS(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,S=u.instance.scopes;u.instance.scopes={};let v=l.pageIndex<u.pages.length-1,b=!!u.pages[l.pageIndex]&&v,x=b?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let C=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,C).then(N=>{b&&u.instance.endIsolatedRootPageFloatLayoutContext(x);let F=c.currentPageType;c.currentPageType=f.currentPageType,c.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=S;let L=bo(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),N.pageAndPosition.position.spineIndex===a.spineIndex&&N.pageAndPosition.position.pageIndex===i&&(a=N.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&F!==N.pageAndPosition.page.pageType&&(c.currentPageType=a.pageType);let V=u!==e,Y=u.pages.length,ue=u.layoutPositions[Y],he=u.instance.hasActiveRootPageFloatLayoutContext();if(ue&&!he){let k=V?bo(this.counterStore.currentPageCounters):null;V&&(this.counterStore.currentPageCounters=L);let _=Y;this.renderSinglePage(u,ue).then(()=>{V&&this.markSpineItemCompleteIfReady(u);let E=u.pages.length-_;if(V&&E>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,E),this.counterStore.updateTargetCounterNodesInPages(u.pages);let O=u.item.spineIndex;for(let P=O+1;P<this.spineItems.length;P++){let A=this.spineItems[P];if(A){A.item.epage+=E;for(let B of A.pageCounterStarts)B!=null&&B.page&&(B.page=B.page.map(z=>z+E));this.counterStore.updatePageCounterNodesInPages(A.pages,A.pageCounterStarts)}}if(k){let P=k.page;P&&(k.page=P.map(A=>A+E))}}k&&(this.counterStore.currentPageCounters=k),h.continueLoop()});return}V&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=D("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),o=this.preparePageCountersForRender(e,n),s=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,o,s,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,o,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(c=>{i.finish({pageAndPosition:xo(c,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=fi(t.layoutPositions.length,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=D("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(xo(r,o))})})}),i.result()}renderPage(e){let t=D("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){t.finish(xo(s,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){s=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){t.finish(xo(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=D("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=D("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,o=0;t&&(o=n);let s;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=D("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return T(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return T({left:null,right:null});let n=D("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(s=>{let a=this.getPage(e),h=s&&s.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,t);return s.thenAsync(a=>a?s:r)}else return T(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,t):T(null)):r}navigateToEPage(e,t,i){let n=D("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=D("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!kt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ae(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!Vt(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ae(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){j.debug("Navigate to",e);let n=this.opf.getPathFromURL(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 s=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],e=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return T(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=e.indexOf("#");if(s>=0)return this.navigateToFragment(e.substr(s+1),t,i)}return T(null)}let o=D("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",xr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new Ud(n,r);if(o.spineIndex=e.item.spineIndex,o.position=t,o.offset=e.instance.getPosition(t),o.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=fc(this.viewport.width,this.viewport.height,i.width,i.height),a=Ti(null,new vt(s,null),"");o.delayedItems.push(new Nl(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ae(r,e.url);let s=t.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=gh(r),l=gh(s),u=new pi;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),u.append("="),u.append(encodeURIComponent(w)))}}o.setAttribute("src",u.toString());let c=t.getAttribute("width");c&&o.setAttribute("width",c);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",Sr(r)),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=CS();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=D("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(s)}),l.result()}return T(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ae(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):T(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return T(null);let t=this.spineItems[e];if(t)return T(t);let i=D("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),u=this.makeCustomRenderer(s),c=this.viewport,p=l.sizeViewport(c.width,c.height,c.fontSize,this.pref);(p.width!=c.width||p.height!=c.height||p.fontSize!=c.fontSize)&&(c=new ws(c.window,p.fontSize,c.pixelRatio,c.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let b=g&&g.pageCounterStarts[g.pages.length-1],x=b&&b.page;if(x&&x.length)w=x[x.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?m:C[C.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let S=new nh(l,s,this.opf.lang,c,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);S.pref=this.pref;let v=this.opf.metadata&&this.opf.metadata[Xe.title];S.pubTitle=v&&v[0]&&v[0].v||"",S.docTitle=r.title||"",S.init().then(()=>{!this.opf.pageProgression&&S.pageProgression&&(this.opf.pageProgression=S.pageProgression),t={item:r,xmldoc:s,instance:S,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(b=>{b.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let n=D("showTOC");this.tocView||(this.tocView=new fS(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),xr||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},ju="data-vivliostyle-viewer-status",ES="data-vivliostyle-spread-view",eg=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(eg||{}),PS=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,d(this,"fontMapper"),d(this,"kick"),d(this,"sendCommand"),d(this,"resizeListener"),d(this,"hyperlinkListener"),d(this,"pageRuleStyleElement"),d(this,"pageSheetSizeAlreadySet",!1),d(this,"renderTask",null),d(this,"actions"),d(this,"readyState"),d(this,"packageURL"),d(this,"opf"),d(this,"touchActive"),d(this,"touchX"),d(this,"touchY"),d(this,"needResize"),d(this,"resized"),d(this,"needRefresh"),d(this,"viewportSize"),d(this,"currentPage"),d(this,"currentSpread"),d(this,"pagePosition"),d(this,"fontSize"),d(this,"zoom"),d(this,"fitToScreen"),d(this,"pageViewMode"),d(this,"waitForLoading"),d(this,"renderAllPages"),d(this,"pref"),d(this,"pageSizes"),d(this,"pixelRatio"),d(this,"pixelRatioLimit"),d(this,"viewport"),d(this,"opfView"),d(this,"cmykReserveMap"),d(this,"cmykReserveMapUrl");let r=t.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",hd),o("vivliostyle-viewport-css",ud),o("vivliostyle-polyfill-css",md),t.setAttribute("data-vivliostyle-viewer-viewport",!0),xr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ju,"loading"),this.fontMapper=new ox(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=s=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=dc(),this.pageSizes=[],this.pixelRatioLimit=cl==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=rc;j.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),j.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),j.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),j.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(ju,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){Et.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=D("loadPublication");return this.configure(e).then(()=>{let s=new Hu;s.init(n,r).then(()=>{let a=Ae(kn(t),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(e){Et.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,o=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=D("loadXML");return this.configure(e).then(()=>{let a=new Hu;a.init(r,o).then(()=>{let h=t.map((l,u)=>({url:Ae(kn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Vo(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,T(!0))):t=T(!0),t.thenAsync(()=>(Et.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let o=jt[r];if(o)return t*o}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(dh(e.userAgentRootURL.replace(/resources\/?$/,"")),ph(e.userAgentRootURL)),typeof e.rootURL=="string"&&(dh(e.rootURL),ph(`${Xi}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!==mi&&(sx(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),T(!0)}configurePlugins(e){Ut("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=D("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?Rn(i.fetchers):T(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new ws(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new ws(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(ES,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let m=g*.75;return Math.ceil(m)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),u=s(h),c=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-c}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,T(!0);let t=Ae(kn(this.cmykReserveMapUrl),Xi),i=D("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{dm(n)?this.cmykReserveMap=n:(j.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new kS(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?T(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,T(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Xu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Ca().getScheduler().run(()=>Fn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,Et.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),Et.registerEndTiming("render (resize)"),mi&&Bf(this.window)?ux(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 Xu)Et.registerEndTiming("render (resize)"),j.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=D("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return T(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=D("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=D("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=T(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return T(!0)}else if(i=="hide")return T(!0);if(n&&i!="show")return this.opfView.hideTOC(),T(!0);{let o=D("showTOC");return this.opfView.showTOC(t).then(s=>{if(s){if(r&&(s.listeners={}),t){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return Fn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(j.error("No such action:",t),i.finish(!0))},(i,n)=>{j.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=qu(e),i=null,n=this;Aw(()=>{let r=D("commandLoop"),o=Ca().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),T(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=D("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=qu(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},tg=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(tg||{}),Xu=class ig extends Error{constructor(){super(),d(this,"name","RenderingCanceledError"),d(this,"message","Page rendering has been canceled"),d(this,"stack"),Object.setPrototypeOf(this,ig.prototype),this.stack=new Error().stack}};function qu(e){return typeof e=="string"?dl(e):e}var Yu=ul;function NS(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Zu(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 ng=class{constructor(e,t){this.settings=e,d(this,"initialized",!1),d(this,"adaptViewer_"),d(this,"options"),d(this,"eventTarget"),d(this,"readyState"),ec(e.debug),this.adaptViewer_=new PS(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=NS(),t&&this.setOptions(t),this.eventTarget=new fl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Zu(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function o(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:TS(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Zu(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()===Yu.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Yu.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function TS(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 rg=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(rg||{}),IS=tg,AS=eg;Et.forceRegisterEndTiming("load_vivliostyle");var FS=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){d(this,"htmlDoc"),d(this,"title"),d(this,"printCallback"),d(this,"errorCallback"),d(this,"hideIframe"),d(this,"removeIframe"),d(this,"iframe"),d(this,"iframeWin"),d(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1874
1872
  <!DOCTYPE html>
1875
1873
  <html data-vivliostyle-paginated="true">
1876
1874
  <head>
@@ -1898,6 +1896,6 @@ span[data-viv-leader] {
1898
1896
  <body onload='parent.printInstance.runInIframe(window)'>
1899
1897
  <div id="vivliostyle-viewer-viewport"></div>
1900
1898
  </body>
1901
- </html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new bf({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1902
- `);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function $x(e,t){new Ux(e,t).init()}});var Hx={};Of(Hx,{printHTML:()=>kf.printHTML});module.exports=Mf(Hx);var kf=Bf(Cf());
1899
+ </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 ng({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1900
+ `);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 RS(e,t){new FS(e,t).init()}});var LS={};wg(LS,{printHTML:()=>ag.printHTML});module.exports=vg(LS);var ag=yg(sg());
1903
1901
  //# sourceMappingURL=index.cjs.js.map