@vivliostyle/print 2.42.0 → 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.es6.js CHANGED
@@ -1,12 +1,12 @@
1
- var gf=Object.create;var Al=Object.defineProperty;var mf=Object.getOwnPropertyDescriptor;var wf=Object.getOwnPropertyNames;var yf=Object.getPrototypeOf,vf=Object.prototype.hasOwnProperty;var bf=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xf=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of wf(t))!vf.call(e,r)&&r!==i&&Al(e,r,{get:()=>t[r],enumerable:!(n=mf(t,r))||n.enumerable});return e};var Sf=(e,t,i)=>(i=e!=null?gf(yf(e)):{},xf(t||!e||!e.__esModule?Al(i,"default",{value:e,enumerable:!0}):i,e));var cf=bf((Ox,uf)=>{"use strict";var Cf=Object.create,yr=Object.defineProperty,kf=Object.getOwnPropertyDescriptor,Ef=Object.getOwnPropertyNames,Pf=Object.getPrototypeOf,Nf=Object.prototype.hasOwnProperty,pu=e=>{throw TypeError(e)},Tf=(e,t,i)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,If=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Af=(e,t)=>{for(var i in t)yr(e,i,{get:t[i],enumerable:!0})},fu=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ef(t))!Nf.call(e,r)&&r!==i&&yr(e,r,{get:()=>t[r],enumerable:!(n=kf(t,r))||n.enumerable});return e},Ff=(e,t,i)=>(i=e!=null?Cf(Pf(e)):{},fu(t||!e||!e.__esModule?yr(i,"default",{value:e,enumerable:!0}):i,e)),Rf=e=>fu(yr({},"__esModule",{value:!0}),e),d=(e,t,i)=>Tf(e,typeof t!="symbol"?t+"":t,i),Ma=(e,t,i)=>t.has(e)||pu("Cannot "+i),U=(e,t,i)=>(Ma(e,t,"read from private field"),i?i.call(e):t.get(e)),ne=(e,t,i)=>t.has(e)?pu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),De=(e,t,i,n)=>(Ma(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ee=(e,t,i)=>(Ma(e,t,"access private method"),i),Lf=If((e,t)=>{var i=-1,n=1,r=0;function o(k,M,E,L,P){if(k===M)return k?[[r,k]]:[];if(E!=null){var I=Se(k,M,E);if(I)return I}var O=l(k,M),z=k.substring(0,O);k=k.substring(O),M=M.substring(O),O=c(k,M);var $=k.substring(k.length-O);k=k.substring(0,k.length-O),M=M.substring(0,M.length-O);var K=s(k,M);return z&&K.unshift([r,z]),$&&K.push([r,$]),C(K,P),L&&f(K),K}function s(k,M){var E;if(!k)return[[n,M]];if(!M)return[[i,k]];var L=k.length>M.length?k:M,P=k.length>M.length?M:k,I=L.indexOf(P);if(I!==-1)return E=[[n,L.substring(0,I)],[r,P],[n,L.substring(I+P.length)]],k.length>M.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,M]];var O=p(k,M);if(O){var z=O[0],$=O[1],K=O[2],J=O[3],Q=O[4],de=o(z,K),re=o($,J);return de.concat([[r,Q]],re)}return a(k,M)}function a(k,M){for(var E=k.length,L=M.length,P=Math.ceil((E+L)/2),I=P,O=2*P,z=new Array(O),$=new Array(O),K=0;K<O;K++)z[K]=-1,$[K]=-1;z[I+1]=0,$[I+1]=0;for(var J=E-L,Q=J%2!==0,de=0,re=0,oe=0,Oe=0,Re=0;Re<P;Re++){for(var pe=-Re+de;pe<=Re-re;pe+=2){var Ce=I+pe,me;pe===-Re||pe!==Re&&z[Ce-1]<z[Ce+1]?me=z[Ce+1]:me=z[Ce-1]+1;for(var he=me-pe;me<E&&he<L&&k.charAt(me)===M.charAt(he);)me++,he++;if(z[Ce]=me,me>E)re+=2;else if(he>L)de+=2;else if(Q){var ke=I+J-pe;if(ke>=0&&ke<O&&$[ke]!==-1){var we=E-$[ke];if(me>=we)return h(k,M,me,he)}}}for(var Te=-Re+oe;Te<=Re-Oe;Te+=2){var ke=I+Te,we;Te===-Re||Te!==Re&&$[ke-1]<$[ke+1]?we=$[ke+1]:we=$[ke-1]+1;for(var te=we-Te;we<E&&te<L&&k.charAt(E-we-1)===M.charAt(L-te-1);)we++,te++;if($[ke]=we,we>E)Oe+=2;else if(te>L)oe+=2;else if(!Q){var Ce=I+J-Te;if(Ce>=0&&Ce<O&&z[Ce]!==-1){var me=z[Ce],he=I+me-Ce;if(we=E-we,me>=we)return h(k,M,me,he)}}}}return[[i,k],[n,M]]}function h(k,M,E,L){var P=k.substring(0,E),I=M.substring(0,L),O=k.substring(E),z=M.substring(L),$=o(P,I),K=o(O,z);return $.concat(K)}function l(k,M){if(!k||!M||k.charAt(0)!==M.charAt(0))return 0;for(var E=0,L=Math.min(k.length,M.length),P=L,I=0;E<P;)k.substring(I,P)==M.substring(I,P)?(E=P,I=E):L=P,P=Math.floor((L-E)/2+E);return S(k.charCodeAt(P-1))&&P--,P}function u(k,M){var E=k.length,L=M.length;if(E==0||L==0)return 0;E>L?k=k.substring(E-L):E<L&&(M=M.substring(0,E));var P=Math.min(E,L);if(k==M)return P;for(var I=0,O=1;;){var z=k.substring(P-O),$=M.indexOf(z);if($==-1)return I;O+=$,($==0||k.substring(P-O)==M.substring(0,O))&&(I=O,O++)}}function c(k,M){if(!k||!M||k.slice(-1)!==M.slice(-1))return 0;for(var E=0,L=Math.min(k.length,M.length),P=L,I=0;E<P;)k.substring(k.length-P,k.length-I)==M.substring(M.length-P,M.length-I)?(E=P,I=E):L=P,P=Math.floor((L-E)/2+E);return F(k.charCodeAt(k.length-P))&&P--,P}function p(k,M){var E=k.length>M.length?k:M,L=k.length>M.length?M:k;if(E.length<4||L.length*2<E.length)return null;function P(re,oe,Oe){for(var Re=re.substring(Oe,Oe+Math.floor(re.length/4)),pe=-1,Ce="",me,he,ke,we;(pe=oe.indexOf(Re,pe+1))!==-1;){var Te=l(re.substring(Oe),oe.substring(pe)),te=c(re.substring(0,Oe),oe.substring(0,pe));Ce.length<te+Te&&(Ce=oe.substring(pe-te,pe)+oe.substring(pe,pe+Te),me=re.substring(0,Oe-te),he=re.substring(Oe+Te),ke=oe.substring(0,pe-te),we=oe.substring(pe+Te))}return Ce.length*2>=re.length?[me,he,ke,we,Ce]:null}var I=P(E,L,Math.ceil(E.length/4)),O=P(E,L,Math.ceil(E.length/2)),z;if(!I&&!O)return null;O?I?z=I[4].length>O[4].length?I:O:z=O:z=I;var $,K,J,Q;k.length>M.length?($=z[0],K=z[1],J=z[2],Q=z[3]):(J=z[0],Q=z[1],$=z[2],K=z[3]);var de=z[4];return[$,K,J,Q,de]}function f(k){for(var M=!1,E=[],L=0,P=null,I=0,O=0,z=0,$=0,K=0;I<k.length;)k[I][0]==r?(E[L++]=I,O=$,z=K,$=0,K=0,P=k[I][1]):(k[I][0]==n?$+=k[I][1].length:K+=k[I][1].length,P&&P.length<=Math.max(O,z)&&P.length<=Math.max($,K)&&(k.splice(E[L-1],0,[i,P]),k[E[L-1]+1][0]=n,L--,L--,I=L>0?E[L-1]:-1,O=0,z=0,$=0,K=0,P=null,M=!0)),I++;for(M&&C(k),v(k),I=1;I<k.length;){if(k[I-1][0]==i&&k[I][0]==n){var J=k[I-1][1],Q=k[I][1],de=u(J,Q),re=u(Q,J);de>=re?(de>=J.length/2||de>=Q.length/2)&&(k.splice(I,0,[r,Q.substring(0,de)]),k[I-1][1]=J.substring(0,J.length-de),k[I+1][1]=Q.substring(de),I++):(re>=J.length/2||re>=Q.length/2)&&(k.splice(I,0,[r,J.substring(0,re)]),k[I-1][0]=n,k[I-1][1]=Q.substring(0,Q.length-re),k[I+1][0]=i,k[I+1][1]=J.substring(re),I++),I++}I++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,x=/\n\r?\n$/,b=/^\r?\n\r?\n/;function v(k){function M(re,oe){if(!re||!oe)return 6;var Oe=re.charAt(re.length-1),Re=oe.charAt(0),pe=Oe.match(g),Ce=Re.match(g),me=pe&&Oe.match(m),he=Ce&&Re.match(m),ke=me&&Oe.match(w),we=he&&Re.match(w),Te=ke&&re.match(x),te=we&&oe.match(b);return Te||te?5:ke||we?4:pe&&!me&&he?3:me||he?2:pe||Ce?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var L=k[E-1][1],P=k[E][1],I=k[E+1][1],O=c(L,P);if(O){var z=P.substring(P.length-O);L=L.substring(0,L.length-O),P=z+P.substring(0,P.length-O),I=z+I}for(var $=L,K=P,J=I,Q=M(L,P)+M(P,I);P.charAt(0)===I.charAt(0);){L+=P.charAt(0),P=P.substring(1)+I.charAt(0),I=I.substring(1);var de=M(L,P)+M(P,I);de>=Q&&(Q=de,$=L,K=P,J=I)}k[E-1][1]!=$&&($?k[E-1][1]=$:(k.splice(E-1,1),E--),k[E][1]=K,J?k[E+1][1]=J:(k.splice(E+1,1),E--))}E++}}function C(k,M){k.push([r,""]);for(var E=0,L=0,P=0,I="",O="",z;E<k.length;){if(E<k.length-1&&!k[E][1]){k.splice(E,1);continue}switch(k[E][0]){case n:P++,O+=k[E][1],E++;break;case i:L++,I+=k[E][1],E++;break;case r:var $=E-P-L-1;if(M){if($>=0&&D(k[$][1])){var K=k[$][1].slice(-1);if(k[$][1]=k[$][1].slice(0,-1),I=K+I,O=K+O,!k[$][1]){k.splice($,1),E--;var J=$-1;k[J]&&k[J][0]===n&&(P++,O=k[J][1]+O,J--),k[J]&&k[J][0]===i&&(L++,I=k[J][1]+I,J--),$=J}}if(A(k[E][1])){var K=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),I+=K,O+=K}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(I.length>0||O.length>0){I.length>0&&O.length>0&&(z=l(O,I),z!==0&&($>=0?k[$][1]+=O.substring(0,z):(k.splice(0,0,[r,O.substring(0,z)]),E++),O=O.substring(z),I=I.substring(z)),z=c(O,I),z!==0&&(k[E][1]=O.substring(O.length-z)+k[E][1],O=O.substring(0,O.length-z),I=I.substring(0,I.length-z)));var Q=P+L;I.length===0&&O.length===0?(k.splice(E-Q,Q),E=E-Q):I.length===0?(k.splice(E-Q,Q,[n,O]),E=E-Q+1):O.length===0?(k.splice(E-Q,Q,[i,I]),E=E-Q+1):(k.splice(E-Q,Q,[i,I],[n,O]),E=E-Q+2)}E!==0&&k[E-1][0]===r?(k[E-1][1]+=k[E][1],k.splice(E,1)):E++,P=0,L=0,I="",O="";break}}k[k.length-1][1]===""&&k.pop();var de=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),de=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),de=!0)),E++;de&&C(k,M)}function S(k){return k>=55296&&k<=56319}function F(k){return k>=56320&&k<=57343}function A(k){return F(k.charCodeAt(0))}function D(k){return S(k.charCodeAt(k.length-1))}function H(k){for(var M=[],E=0;E<k.length;E++)k[E][1].length>0&&M.push(k[E]);return M}function q(k,M,E,L){return D(k)||A(L)?null:H([[r,k],[i,M],[n,E],[r,L]])}function Se(k,M,E){var L=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,I=k.length,O=M.length;if(L.length===0&&(P===null||P.length===0)){var z=L.index,$=k.slice(0,z),K=k.slice(z),J=P?P.index:null;e:{var Q=z+O-I;if(J!==null&&J!==Q||Q<0||Q>O)break e;var de=M.slice(0,Q),re=M.slice(Q);if(re!==K)break e;var oe=Math.min(z,Q),Oe=$.slice(0,oe),Re=de.slice(0,oe);if(Oe!==Re)break e;var pe=$.slice(oe),Ce=de.slice(oe);return q(Oe,pe,Ce,K)}e:{if(J!==null&&J!==z)break e;var me=z,de=M.slice(0,me),re=M.slice(me);if(de!==$)break e;var he=Math.min(I-me,O-me),ke=K.slice(K.length-he),we=re.slice(re.length-he);if(ke!==we)break e;var pe=K.slice(0,K.length-he),Ce=re.slice(0,re.length-he);return q($,pe,Ce,ke)}}if(L.length>0&&P&&P.length===0)e:{var Oe=k.slice(0,L.index),ke=k.slice(L.index+L.length),oe=Oe.length,he=ke.length;if(O<oe+he)break e;var Re=M.slice(0,oe),we=M.slice(O-he);if(Oe!==Re||ke!==we)break e;var pe=k.slice(oe,I-he),Ce=M.slice(oe,O-he);return q(Oe,pe,Ce,ke)}return null}function se(k,M,E,L){return o(k,M,E,L,!0)}se.INSERT=n,se.DELETE=i,se.EQUAL=r,t.exports=se}),gu={};Af(gu,{CoreViewer:()=>lf,HOOKS:()=>$o,Navigation:()=>hf,PageProgression:()=>_a,PageSide:()=>yu,PageViewMode:()=>vx,Profiler:()=>Su,ReadyState:()=>vu,UserAgentBaseCss:()=>Fc,UserAgentCounterStylesCss:()=>Oc,UserAgentPageCss:()=>Ac,UserAgentTocCss:()=>Rc,UserAgentXml:()=>Ic,ValidationTxt:()=>Tc,VivliostylePolyfillCss:()=>Lc,VivliostyleViewportCss:()=>Nc,VivliostyleViewportScreenCss:()=>Pc,ZoomType:()=>yx,getHooksForName:()=>Ot,isDebug:()=>lr,pageProgressionOf:()=>wu,plugin:()=>Bf,printHTML:()=>xx,profile:()=>zf,profiler:()=>vt,registerHook:()=>Nt,removeHook:()=>xu,setDebug:()=>mu});uf.exports=Rf(gu);var lr=!1;function mu(e){lr=e}var _a=(e=>(e.LTR="ltr",e.RTL="rtl",e))(_a||{});function wu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var yu=(e=>(e.LEFT="left",e.RIGHT="right",e))(yu||{}),vu=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(vu||{}),bu=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(bu||{}),Of=class{constructor(e){this.opt_console=e,d(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=Br(arguments);this.consoleDebug(Mr(t)),this.triggerListeners(1,t)}info(...e){let t=Br(arguments);this.consoleInfo(Mr(t)),this.triggerListeners(2,t)}warn(...e){let t=Br(arguments);this.consoleWarn(Mr(t)),this.triggerListeners(3,t)}error(...e){let t=Br(arguments);this.consoleError(Mr(t)),this.triggerListeners(4,t)}};function Br(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Mr(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ var hg=Object.create;var hh=Object.defineProperty;var ug=Object.getOwnPropertyDescriptor;var cg=Object.getOwnPropertyNames;var dg=Object.getPrototypeOf,pg=Object.prototype.hasOwnProperty;var fg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var gg=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of cg(t))!pg.call(e,r)&&r!==i&&hh(e,r,{get:()=>t[r],enumerable:!(n=ug(t,r))||n.enumerable});return e};var mg=(e,t,i)=>(i=e!=null?hg(dg(e)):{},gg(t||!e||!e.__esModule?hh(i,"default",{value:e,enumerable:!0}):i,e));var og=fg(($S,rg)=>{"use strict";var wg=Object.create,Lr=Object.defineProperty,yg=Object.getOwnPropertyDescriptor,vg=Object.getOwnPropertyNames,bg=Object.getPrototypeOf,xg=Object.prototype.hasOwnProperty,Zu=e=>{throw TypeError(e)},Sg=(e,t,i)=>t in e?Lr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Cg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),kg=(e,t)=>{for(var i in t)Lr(e,i,{get:t[i],enumerable:!0})},Ku=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of vg(t))!xg.call(e,r)&&r!==i&&Lr(e,r,{get:()=>t[r],enumerable:!(n=yg(t,r))||n.enumerable});return e},Eg=(e,t,i)=>(i=e!=null?wg(bg(e)):{},Ku(t||!e||!e.__esModule?Lr(i,"default",{value:e,enumerable:!0}):i,e)),Pg=e=>Ku(Lr({},"__esModule",{value:!0}),e),d=(e,t,i)=>Sg(e,typeof t!="symbol"?t+"":t,i),ll=(e,t,i)=>t.has(e)||Zu("Cannot "+i),U=(e,t,i)=>(ll(e,t,"read from private field"),i?i.call(e):t.get(e)),ee=(e,t,i)=>t.has(e)?Zu("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),fe=(e,t,i,n)=>(ll(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),se=(e,t,i)=>(ll(e,t,"access private method"),i),Ng=Cg((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}),Ju={};kg(Ju,{CoreViewer:()=>ig,HOOKS:()=>vs,Navigation:()=>ng,PageProgression:()=>hl,PageSide:()=>tc,PageViewMode:()=>NS,Profiler:()=>oc,ReadyState:()=>ic,UserAgentBaseCss:()=>pd,UserAgentCounterStylesCss:()=>md,UserAgentPageCss:()=>dd,UserAgentTocCss:()=>fd,UserAgentXml:()=>cd,ValidationTxt:()=>ud,VivliostylePolyfillCss:()=>gd,VivliostyleViewportCss:()=>hd,VivliostyleViewportScreenCss:()=>ld,ZoomType:()=>PS,getHooksForName:()=>Ut,isDebug:()=>xr,pageProgressionOf:()=>ec,plugin:()=>Ig,printHTML:()=>IS,profile:()=>Lg,profiler:()=>Et,registerHook:()=>Ot,removeHook:()=>rc,setDebug:()=>Qu});rg.exports=Pg(Ju);var xr=!1;function Qu(e){xr=e}var hl=(e=>(e.LTR="ltr",e.RTL="rtl",e))(hl||{});function ec(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var tc=(e=>(e.LEFT="left",e.RIGHT="right",e))(tc||{}),ic=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(ic||{}),nc=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(nc||{}),Tg=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=Kr(arguments);this.consoleDebug(Jr(t)),this.triggerListeners(1,t)}info(...e){let t=Kr(arguments);this.consoleInfo(Jr(t)),this.triggerListeners(2,t)}warn(...e){let t=Kr(arguments);this.consoleWarn(Jr(t)),this.triggerListeners(3,t)}error(...e){let t=Kr(arguments);this.consoleError(Jr(t)),this.triggerListeners(4,t)}};function Kr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Jr(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 G=new Of,$o=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))($o||{}),mo={};function Nt(e,t,i){if(!$o[e])G.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=mo[e];n||(n=mo[e]=[]),i?n.unshift(t):n.push(t)}}function xu(e,t){if(!$o[e])G.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=mo[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ot(e){return mo[e]||[]}var Bf={registerHook:Nt,removeHook:xu},Su=class{constructor(e){this.performanceInstance=e,d(this,"timestamps",{}),d(this,"registerTiming"),d(this,"registerStartTiming"),d(this,"registerEndTiming"),this.registerTiming=Xi,this.registerStartTiming=this.registerStartTiming=Xi,this.registerEndTiming=this.registerEndTiming=Xi}forceRegisterStartTiming(e,t){us.call(this,e,"start",t)}forceRegisterEndTiming(e,t){us.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];t+=i,r>1&&(t+=`(${o})`),t+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
- `}}),G.info(t)}disable(){this.registerTiming=Xi,this.registerStartTiming=this.registerStartTiming=Xi,this.registerEndTiming=this.registerEndTiming=Xi}enable(){this.registerTiming=us,this.registerStartTiming=this.registerStartTiming=Fl,this.registerEndTiming=this.registerEndTiming=Mf}isEnabled(){return this.registerStartTiming===Fl}};function Xi(){}function us(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[t]));s--)r=null;r||(r={},n.push(r)),r[t]=i}function Fl(e,t){this.registerTiming(e,"start",t)}function Mf(e,t){this.registerTiming(e,"end",t)}var _f={now:Date.now},Df=window&&window.performance,vt=new Su(Df||_f);vt.forceRegisterStartTiming("load_vivliostyle");var zf={profiler:{registerStartTiming:vt.registerStartTiming,registerEndTiming:vt.registerEndTiming,printTimings:vt.printTimings,disable:vt.disable,enable:vt.enable}},Da=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",wo=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,jt="data-adapt-eloff",Vf={};function za(e){return JSON.parse(e)}function qt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Cu(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var zi=window.location.href;function Rl(e){zi=e}var mi=window.location.href;function Ll(e){mi=e}function Uf(e){let t=Cu(e).match(/^(https?:\/\/raw\.githubusercontent\.com\/web-platform-tests\/wpt\/master)(?:\/|$)/);return t?t[1]:null}function Ne(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let s=Uf(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Cu(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function yo(e,t){return e.match(/^#/)&&t?qt(t)+e:Ne(e,t)}function mn(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/web-platform-tests/wpt/master/${t[2]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function Ol(e){return e==null?e:e.toString()}var Hf=class{constructor(){d(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},ku=["","-webkit-","-moz-"],Zi={};function Xr(e,t){return CSS.supports(e+t,"unset")}function $f(e){let t=Zi[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Zi[e]=null,null;case"text-combine-upright":if(Xr("-webkit-","text-combine")&&!Xr("","text-combine-upright"))return Zi[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of ku)if(Xr(i,e))return t=[i+e],Zi[e]=t,t;return G.warn("Property not supported by the browser: ",e),Zi[e]=null,null}function N(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=$f(t);if(r)for(let o of r){switch(o){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(o,i)}}function pi(e,t,i){try{let n=Zi[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function As(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var ri=class{constructor(){d(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Eu(e){return`\\${e.charCodeAt(0).toString(16)} `}function wi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Eu)}function vr(e){return e.replace(/[\u0000-\u001F"\\]/g,Eu)}function Bl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Ml(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Wf(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Pu(e,t){function i(n){return Wf(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function hi(e){return Pu(e)}function Gf(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function jf(e,t){t=typeof t=="string"?t:"\\u";function i(r){return Gf(r,t)}let n=new RegExp(`${hi(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function oi(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function Nu(e,t){return e-t}function _l(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Xf(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function cs(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function qf(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Va=class{constructor(){d(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},Bi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Tu(){return{fontFamily:"serif",lineHeight:1.25,margin:8,hyphenate:!1,columnWidth:25,horizontal:!1,nightMode:!1,spreadView:!1,pageBorder:1,enabledMediaTypes:{vivliostyle:!0,print:!0},defaultPaperSize:void 0}}function Iu(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var Yf=Tu(),Dl={PENDING:{}};function Au(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Zf(e){return`"${vr(`${e}`)}"`}function Kf(e){return wi(`${e}`)}function Fs(e,t){return e?`${wi(e)}.${wi(t)}`:wi(t)}var Fu=0,Rs=class{constructor(e,t){if(this.parent=e,this.resolver=t,d(this,"scopeKey"),d(this,"children",[]),d(this,"zero"),d(this,"one"),d(this,"_true"),d(this,"_false"),d(this,"values",{}),d(this,"funcs",{}),d(this,"builtIns",{}),this.scopeKey=`S${Fu++}`,this.zero=new Ke(this,0),this.one=new Ke(this,1),this._true=new Ke(this,!0),this._false=new Ke(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=Au,i["css-string"]=Zf,i["css-name"]=Kf,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Fe(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function Jf(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Ru(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function Qf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function eg(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var zt={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function Lu(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var Ls=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,d(this,"actualPageWidth",null),d(this,"pageWidth"),d(this,"actualPageHeight",null),d(this,"pageHeight"),d(this,"initialFontSize"),d(this,"rootFontSize",null),d(this,"isRelativeRootFontSize",null),d(this,"fontSize"),d(this,"rootLineHeight",null),d(this,"pref"),d(this,"scopes",{}),d(this,"pageAreaWidth",null),d(this,"pageAreaHeight",null),d(this,"pageVertical",null),d(this,"pubTitle",null),d(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=Yf}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(Ru(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:zt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let o=e.builtIns[t];if(o){if(n)return e.zero;let s=Array(i.length);for(let a=0;a<i.length;a++)s[a]=i[a].evaluate(this);return new Ke(e,o.apply(this,s))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&t==null)return o!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Mt=class{constructor(e){this.scope=e,d(this,"key"),this.scope=e,this.key=`_${Fu++}`}toString(){let e=new ri;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===Dl.PENDING?!1:n;{i[this.key]=Dl.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},Ou=class extends Mt{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},Wo=class extends Mt{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},Bu=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},An=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Mu=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ua=class extends Wo{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},yi=class extends Ou{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},tg=class extends yi{constructor(e,t){super(e,t)}getOp(){return"not "}},ln=class extends Ou{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Ha=class extends Bu{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},ig=class extends Ha{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},$a=class extends Bu{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},ng=class extends $a{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},rg=class extends $a{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},og=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},sg=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},ag=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Os=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Wa=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},lg=class extends An{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},_u=class extends Mu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Du=class extends Mu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Ga=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},zu=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Vu=class extends Ua{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},br=class extends Mt{constructor(e,t,i){var n;super(e),this.num=t,d(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(wi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},qe=class extends Mt{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},zl=class extends Mt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(wi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Fe=class extends Mt{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function hg(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function ug(e,t,i){let n=t;for(let r=0;r<t.length;r++){let o=t[r].expand(e,i);if(t!==n)n[r]=o;else if(o!==t[r]){n=Array(t.length);for(let s=0;s<r;s++)n[s]=t[s];n[r]=o}}return n}var Kn=class Uu extends Mt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),hg(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=ug(t,this.params,i);return n===this.params?this:new Uu(this.scope,this.qualifiedName,n)}},cg=class Hu extends Mt{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),o=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new Hu(this.scope,n,r,o)}},Ke=class extends Mt{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(vr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Vl=class $u extends Mt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(vr(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new $u(this.scope,this.name,n)}},dg=class extends Mt{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Wu=class extends Mt{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function Rt(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new Ha(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new _u(e,t,i)}function fe(e,t,i){return t===e.zero?new ln(e,i):i===e.zero?t:new Du(e,t,i)}function qr(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Ga(e,t,i)}function Bs(e,t,i){return t===e.zero?e.zero:i===e.one?t:new zu(e,t,i)}var li=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Hi=class extends li{constructor(){super(),d(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let o=0;o<i;o++)t[o]=e[o];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new ee(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new it(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new $i(e.name,t)}visitExpr(e){return e}},nt=class{toString(){let e=new ri;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new ri;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},Gu=class ju extends nt{static get instance(){return this.empty||(this.empty=new ju),this.empty}constructor(){super()}toExpr(t,i){return new Ke(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};d(Gu,"empty");var pg=Gu,Y=pg.instance,Xu=class qu extends nt{static get instance(){return this.slash||(this.slash=new qu),this.slash}constructor(){super()}toExpr(t,i){return new Ke(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};d(Xu,"slash");var fg=Xu,Fn=fg.instance,X=class extends nt{constructor(e){super(),this.str=e}toExpr(e,t){return new Ke(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(vr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Ms=Object.create(null),ce=class extends nt{constructor(e){if(super(),this.name=e,Ms[e])throw new Error("E_INVALID_CALL");Ms[e]=this}toExpr(e,t){return new Ke(e,this.name)}appendTo(e,t){t?e.append(wi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=Ms[e];return t||(t=new ce(e)),t}var R=class extends nt{constructor(e,t){var i;super(),this.num=e,d(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Ga(e,t,new Ke(e,this.num/100)):new br(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},xt=class extends nt{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Ke(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},ze=class extends xt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Yu=class extends nt{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ht=class extends nt{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(vr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Zu=class extends nt{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ja(e,t,i,n){var r,o;let s=t.length;if(s>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<s;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var ee=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){ja(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},it=class extends nt{constructor(e){super(),this.values=e}appendTo(e,t){ja(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},$i=class extends nt{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(wi(this.name)),e.append("("),ja(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},W=class extends nt{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Ke||this.expr instanceof br?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},Ki=class extends nt{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function st(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function Ku(e,t){return new R(st(e,t),"px")}var y={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),inside:B("inside"),keep:B("keep"),landscape:B("landscape"),left:B("left"),line:B("line"),list_item:B("list-item"),ltr:B("ltr"),manual:B("manual"),max_content:B("max-content"),min_content:B("min-content"),none:B("none"),normal:B("normal"),oeb_page_foot:B("oeb-page-foot"),oeb_page_head:B("oeb-page-head"),outside:B("outside"),padding_box:B("padding-box"),page:B("page"),relative:B("relative"),revert:B("revert"),right:B("right"),same:B("same"),scale:B("scale"),snap_block:B("snap-block"),snap_inline:B("snap-inline"),solid:B("solid"),spread:B("spread"),_static:B("static"),rtl:B("rtl"),table:B("table"),table_caption:B("table-caption"),table_cell:B("table-cell"),table_footer_group:B("table-footer-group"),table_header_group:B("table-header-group"),table_row:B("table-row"),top:B("top"),transparent:B("transparent"),unset:B("unset"),vertical_lr:B("vertical-lr"),vertical_rl:B("vertical-rl"),visible:B("visible"),_true:B("true")},Ul=new R(100,"%"),xr=new R(100,"pvw"),Sr=new R(100,"pvh"),Ae=new R(0,"px"),kx=new Zu("U+0-10FFFF"),Hl={"font-size":1,"line-height":2,color:3};function Z(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function $l(e,t){let i=Hl[e]||Number.MAX_VALUE,n=Hl[t]||Number.MAX_VALUE;return i-n}function Zt(e){return e?.length>2&&e.startsWith("--")}var Ji,Qi,en,Ju=class Jt{constructor(t,i,n){ne(this,Ji),ne(this,Qi),ne(this,en),De(this,Ji,Math.round(Math.max(0,Math.min(t,Jt.MAX)))),De(this,Qi,Math.round(Math.max(0,Math.min(i,Jt.MAX)))),De(this,en,Math.round(Math.max(0,Math.min(n,Jt.MAX))))}static fromInt(t,i,n){return new Jt(t,i,n)}offset(t,i,n){return new Jt(U(this,Ji)+t,U(this,Qi)+i,U(this,en)+n)}toKey(){return JSON.stringify([U(this,Ji),U(this,Qi),U(this,en)])}toColorFunc(t){return new $i("color",[new ee([B("srgb"),new xt(U(this,Ji)/Jt.MAX),new xt(U(this,Qi)/Jt.MAX),new xt(U(this,en)/Jt.MAX),...t!==null?[Fn,new xt(t)]:[]])])}};Ji=new WeakMap,Qi=new WeakMap,en=new WeakMap,d(Ju,"MAX",1e4);var ei=Ju;function gg(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Ii,Ai,Fi,Ht,Qu=class ut{constructor(t,i,n,r){ne(this,Ii),ne(this,Ai),ne(this,Fi),ne(this,Ht),De(this,Ii,Math.round(Math.max(0,Math.min(t,ut.MAX)))),De(this,Ai,Math.round(Math.max(0,Math.min(i,ut.MAX)))),De(this,Fi,Math.round(Math.max(0,Math.min(n,ut.MAX)))),De(this,Ht,Math.round(Math.max(0,Math.min(r,ut.MAX))))}static fromInt(t,i,n,r){return new ut(t,i,n,r)}static fromNumber(t,i,n,r){return new ut(t*ut.MAX,i*ut.MAX,n*ut.MAX,r*ut.MAX)}toSRGB(){let t=ut.MAX-U(this,Ht);return ei.fromInt(ei.MAX-Math.min(ei.MAX,Math.round(U(this,Ii)*t/ut.MAX)+U(this,Ht)),ei.MAX-Math.min(ei.MAX,Math.round(U(this,Ai)*t/ut.MAX)+U(this,Ht)),ei.MAX-Math.min(ei.MAX,Math.round(U(this,Fi)*t/ut.MAX)+U(this,Ht)))}equals(t){return U(this,Ii)===U(t,Ii)&&U(this,Ai)===U(t,Ai)&&U(this,Fi)===U(t,Fi)&&U(this,Ht)===U(t,Ht)}toJSON(){return{c:U(this,Ii),m:U(this,Ai),y:U(this,Fi),k:U(this,Ht)}}};Ii=new WeakMap,Ai=new WeakMap,Fi=new WeakMap,Ht=new WeakMap,d(Qu,"MAX",1e4);var ec=Qu;function qi(e){return e instanceof xt?Math.max(0,Math.min(1,e.num)):e instanceof R&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function tc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof ee?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=qi(t[0]),n=qi(t[1]),r=qi(t[2]),o=qi(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===Fn){if(t.length!==6)return null;s=qi(t[5])}else{if(t.length!==5)return null;s=qi(t[4])}if(s===null)return null}return{cmyk:ec.fromNumber(i,n,r,o),alpha:s}}function*mg(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var di,vo,ic,Wl,nc=class{constructor(){ne(this,vo),ne(this,di,new Map)}registerDeviceCmyk(e){let t=tc(e);return t?Ee(this,vo,ic).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ei.fromInt(t.r,t.g,t.b),r=ec.fromInt(i.c,i.m,i.y,i.k);U(this,di).set(n.toKey(),r)}}toJSON(){let e={};return U(this,di).forEach((t,i)=>{e[i]=t.toJSON()}),e}};di=new WeakMap,vo=new WeakSet,ic=function(e){let t=e.toSRGB(),i=t.toKey(),n=U(this,di).get(i);return n?n.equals(e)?t:Ee(this,vo,Wl).call(this,e,t):(U(this,di).set(i,e),t)},Wl=function(e,t){for(let i=1;i<=ei.MAX;i++)for(let[n,r,o]of mg(i)){let s=t.offset(n,r,o),a=s.toKey();if(!U(this,di).has(a))return U(this,di).set(a,e),s}return G.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Yr,Un,Hn,rc=class extends Hi{constructor(e){super(),ne(this,Yr),ne(this,Un,new Map),ne(this,Hn,!1),De(this,Yr,e??new nc)}reset(){De(this,Hn,!1)}hadDeviceCmyk(){return U(this,Hn)}recordConversion(e,t){U(this,Un).set(e,t)}getConversions(){if(U(this,Un).size===0)return null;let e={};return U(this,Un).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=U(this,Yr).registerDeviceCmyk(e);return t?(De(this,Hn,!0),t):super.visitFunc(e)}};Yr=new WeakMap,Un=new WeakMap,Hn=new WeakMap;function oc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function wg(e){return`^${e}`}function Gl(e){return e.replace(/[\[\]\(\),=;^]/g,wg)}function yg(e){return e.substr(1)}function _s(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,yg)}function vg(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=_s(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function jl(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=vg(i[2]),e=e.substr(i[0].length)}return t}var Xl=class{appendTo(e){e.append("!")}applyTo(e){return!1}},ql=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?e.after=!0:r=s}e.node=r}if(this.id&&(e.after||this.id!=oc(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:G.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Yl=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(t<=o)break;if(!r){t=o;break}t-=o}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Gl(this.textBefore)),e.append(","),this.textAfter&&e.append(Gl(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Zl=class sc{constructor(){d(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,o=[];for(;;){let s;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];s=jl(i[4]),o.push(new ql(a,h,Ol(s.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=_s(h));let l=i[7];l&&(l=_s(l)),s=jl(i[10]),o.push(new Yl(a,h,l,Ol(s.s)));break}case"!":r++,o.push(new Xl);break;case"~":case"@":case"":this.steps=o;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new sc,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let o=[],s=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new Yl(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:oc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new ql(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Xl),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new ri;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}},Pt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},fi=class{constructor(e,t){this.x=e,this.y=t}},ds=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Kl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},ii=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,d(this,"left",null),d(this,"right",null)}};function bg(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Go=class ac{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new Kl(o,a,1,i):h=new Kl(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new fi(r.x+t,r.y+i));return new ac(n)}};function Jl(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new fi(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Go(r)}function Xa(e,t,i,n){return new Go([new fi(e,t),new fi(i,t),new fi(i,n),new fi(e,n)])}var _r=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Ql(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function xg(e,t,i,n){let r,o,s,a;t.high.y<i&&G.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Ql(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=Ql(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new _r(r,o,t.shapeId,-1)),e.push(new _r(s,a,t.shapeId,1))):(e.push(new _r(s,a,t.shapeId,-1)),e.push(new _r(r,o,t.shapeId,1)))}function Sg(e,t,i){let n=t+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let c=e[u];r[c.shapeId]+=c.winding,o[c.shapeId]+=c.lowOrHigh;let p=!1;for(s=0;s<t;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=t;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(c.x),h=p)}return a}function Cg(e,t){return t?Math.ceil(e/t)*t:e}function eh(e,t){return t?Math.floor(e/t)*t:e}function kg(e){return new fi(e.y,-e.x)}function bo(e){return new Pt(e.y1,-e.x2,e.y2,-e.x1)}function lc(e){return new Pt(-e.y2,e.x1,-e.y1,e.x2)}function th(e){return new Go(e.points.map(t=>kg(t)))}function Eg(e,t,i,n,r,o){o&&(e=bo(e),t=t.map(b=>th(b)),i=i.map(b=>th(b)));let s=t.length,a=i?i.length:0,h=[],l=[],u,c,p;for(u=0;u<s;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+s);let f=l.length;l.sort(bg);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>e.y1&&h.push(new ii(e.y1,m,e.x2,e.x2));let w=0,x=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&x.push(p),w++;for(;w<f||x.length>0;){let b=e.y2,v=Math.min(Cg(Math.ceil(m+n),r),e.y2);for(c=0;c<x.length&&b>v;c++)p=x[c],p.low.x==p.high.x?p.high.y<b&&(b=Math.max(eh(p.high.y,r),v)):p.low.x!=p.high.x&&(b=v);for(b>e.y2&&(b=e.y2);w<f&&(p=l[w]).low.y<b;){if(p.high.y<m){w++;continue}if(p.low.y<v)p.low.y==p.high.y&&p.low.y==m||(x.push(p),b=v),w++;else{let F=eh(p.low.y,r);F<b&&(b=F);break}}let C=[];for(c=0;c<x.length;c++)xg(C,x[c],m,b);C.sort((F,A)=>F.x-A.x||F.lowOrHigh-A.lowOrHigh);let S=Sg(C,s,a);if(S.length==0)h.push(new ii(m,b,e.x2,e.x2));else{let F=0,A=e.x1;for(c=0;c<S.length;c+=2){let D=Math.max(e.x1,S[c]),H=Math.min(e.x2,S[c+1])-D;H>F&&(F=H,A=D)}F==0?h.push(new ii(m,b,e.x2,e.x2)):h.push(new ii(m,b,Math.max(A,e.x1),Math.min(A+F,e.x2)))}if(b==e.y2)break;for(m=b,c=x.length-1;c>=0;c--)x[c].high.y<=b&&x.splice(c,1)}return hc(e,h),h}function hc(e,t){let i=t.length-1,n=new ii(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function uc(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function Pg(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)o=n.y2;return r===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new Pt(t.x1,i,t.x2,o)}function Ng(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new Pt(t.x1,o,t.x2,i)}function Tg(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=uc(t,r);for(;;){let h=r+s;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let c=a;c<t.length&&t[c].y1<h;c++){let p=t[c];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+o<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=u-o,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Ig(e,t,i,n,r){for(n||(n=[new ii(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let o,s=t.length==0?e.y1:t[t.length-1].y2;s<e.y2&&t.push(new ii(s,e.y2,e.x1,e.x2));let a=uc(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(o=t[a],a++,t.splice(a,0,new ii(h.y1,o.y2,o.x1,o.x2)),o.y2=h.y1);a<t.length&&(o=t[a++],o.y2>h.y2&&(t.splice(a,0,new ii(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}hc(e,t)}var Ag=class extends li{constructor(){super(),d(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Fg(e){if(e){let t=new Ag;try{return e.visit(t),t.propSet}catch(i){G.warn(i,"toSet:")}}return{}}var Rg=class extends li{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function ih(e,t){if(e){let i=new Rg(t);try{return e.visit(i),i.value}catch(n){G.warn(n,"toInt: ")}}return t}var Lg=class extends li{constructor(){super(),d(this,"collect",!1),d(this,"coords",[]),d(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new R(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new fi(e+o[a],t+o[a+1]));return new Go(s)}break;case"rectangle":if(o.length==4)return Xa(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return Jl(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return Jl(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function cc(e,t,i,n,r,o){if(e){let s=new Lg;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){G.warn(a,"toShape:")}}return Xa(t,i,t+n,i+r)}var Og=class extends li{constructor(e,t){super(),this.reset=e,this.defaultValue=t,d(this,"counters",Object.create(null)),d(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function wn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new Og(r,o);try{e.visit(s)}catch(a){G.warn(a,"toCounters:")}return s.counters}var Bg=class extends Hi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ht(this.transformer.transformURL(e.url,this.baseUrl))}};function ki(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Mg(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function hn(e,t){var i,n;if(t==="content"){let r=e.cloneNode(!0);return r.querySelectorAll("[data-adapt-pseudo]").forEach(o=>o.remove()),r.textContent||""}else if(t==="marker"){let r=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(r)return r.textContent||"";let o=(n=(i=e.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(e))==null?void 0:n.getPropertyValue("--viv-marker-content");if(o){let s=o.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(s&&s.length>0)return s.map(a=>Mg(a.substring(1,a.length-1))).join("")}return""}else{let r=e.querySelector(`[data-adapt-pseudo="${t}"]`);return r&&r.textContent||""}}var _g=class{constructor(e,t){this.targetId=e,this.resolved=t,d(this,"pageCounters",null),d(this,"spineIndex",-1),d(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Dg=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},zg=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,d(this,"styler",null),d(this,"namedStringValues",Object.create(null)),d(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ne(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let o=this.counterStore.currentPageCounters[e];return o&&o.length?o[o.length-1]:null},n=new Fe(this.pageScope,()=>t(i()),`page-counter-${e}`),r=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Fe(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],o=r.length?r[r.length-1]:0,s=n?.[e]||[],a=s.length?s[0]:0;return t.length?[o+(t[0]-a),...t.slice(1)]:[o]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?hn(n,t):hn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),o=new Fe(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[t]){let a=s[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Fe(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,o,h);if(l.length)return i(l);let u=o[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Fe(this.pageScope,()=>{if(t==="first-letter"){let o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(wo);return l?l[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Fe(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Fe(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(Nu),o=this.counterStore.currentPage;if(!o)return"";let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${jt}]`)).map(p=>parseInt(p.getAttribute(jt),10))),h=-1,l=-1,u=-1,c=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,c=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${jt}="${f}"]`);if(!w)l<0&&(l=f);else{let x=o.container.querySelector(`[${jt}="${s}"]`);if(x||(x=o.container.querySelector(`[${jt}="0"]`)),x){for(let b=x;b;b=b.firstElementChild)if(b===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=c=f)}return n[{first:h,start:l,last:u,"first-except":c}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},Vg=class{constructor(e){this.documentURLTransformer=e,d(this,"countersById",Object.create(null)),d(this,"pageCountersById",Object.create(null)),d(this,"pageDocCountersById",Object.create(null)),d(this,"pageTextById",Object.create(null)),d(this,"currentPageDocCounters",null),d(this,"previousPageDocCounters",null),d(this,"currentPageDocCounterChanges",Object.create(null)),d(this,"currentPageDocCounterChangeTypes",Object.create(null)),d(this,"currentPageCounters",Object.create(null)),d(this,"previousPageCounters",Object.create(null)),d(this,"currentPageCountersStack",[]),d(this,"pageIndicesById",Object.create(null)),d(this,"currentPage",null),d(this,"newReferencesOfCurrentPage",[]),d(this,"referencesToSolve",[]),d(this,"referencesToSolveStack",[]),d(this,"unresolvedReferences",Object.create(null)),d(this,"resolvedReferences",Object.create(null)),d(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),d(this,"pagesCounterExprs",[]),d(this,"pageCounterExprs",[]),d(this,"targetCounterExprs",[]),d(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Dg(this,e)}createCounterResolver(e,t,i){return new zg(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?ki(this.currentPageDocCounters):null,this.currentPageDocCounters=e?ki(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[e]}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=ki(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],x=w.length?w[w.length-1]:0,b=g[m]||[],v=b.length?b[b.length-1]:0,C=x-v,S=n[m],F=S==="reset"||S==="set";r[m]={delta:C,reset:F,value:x}}}let o=Object.create(null),s,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(s=wn(g,{reset:!0}))}s&&"pages"in s&&delete s.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=wn(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(s)for(let g in s)u.push(g);if(h)for(let g in h)u.push(g);let c,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(c=wn(g))}c&&"pages"in c&&delete c.pages,c?!("page"in c)&&!(r.page&&r.page.reset)&&(c.page=1):(c=Object.create(null),r.page&&r.page.reset||(c.page=1));for(let g in c)u.push(g);this.setPageControlledCounterNames(u);let f=ki(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],o[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,s)for(let g in s)this.definePageCounter(g,s[g]);if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}for(let g in c){if(o[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=c[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=ki(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let o=this.referencesToSolve[r];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(r,1),t){let s=t.indexOf(o);s>=0&&t.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new _g(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=ki(this.currentPageCounters),s=this.currentPageDocCounters?ki(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:hn(u,"content"),before:hn(u,"before"),after:hn(u,"after"),marker:hn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let c=this.unresolvedReferences[a];c||(c=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),c.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.currentPage=null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(o=>o+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${Mn}]`);for(let n of i){let r=n.getAttribute(Mn),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let s=r.container.querySelectorAll(`[${Bn}]`);for(let a of s){let h=a.getAttribute(Bn),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,c=u?.replace(/^page-counters?-/,""),p=o[c];p&&(a.textContent=l.format(p))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(t=t.concat(o))}),t.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Fe){if(e.str=="viv-leader"){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute("data-viv-leader",e.key),o.setAttribute("data-viv-leader-value",t),o}else if(e.str.startsWith("running-element-")){let o=t&&i.querySelectorAll(`[${jt}="${t}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(Mn,e.key),o}else if(e.str.startsWith("target-text-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(fs,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?ps:Bn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Bn}]`);for(let r of t){let o=r.getAttribute(Bn),s=this.pageCounterExprs.find(u=>u.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=e.querySelectorAll(`[${Mn}]`);for(let r of i)r.setAttribute(nh,!0);let n=e.querySelectorAll(`[${fs}]`);for(let r of n)r.setAttribute(rh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${ps}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(ps),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${nh}]`);for(let s of r){let a=s.getAttribute(Mn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(s.textContent=h.format(u[u.length-1]))}}}let o=e.root.querySelectorAll(`[${rh}]`);for(let s of o){let a=s.getAttribute(fs),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Ug(this,e)}},ps="data-vivliostyle-pages-counter",Bn="data-vivliostyle-page-counter",Mn="data-vivliostyle-target-counter",fs="data-vivliostyle-target-text",nh="data-vivliostyle-target-counter-in-running",rh="data-vivliostyle-target-text-in-running",Ug=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}},Hg=new Set(["before","after","first-line","first-letter"]),$g=new Set(["media","supports","-epubx-when"]),dc=new Set([";","}"]),pc=new Set(["{",";","}"]),Wg=new Set([";","{","}"]),Gg=":where(:scope)",jg=":where(:not(*))";function Xg(e){let{statements:t,changed:i}=Ds(e,0,e.length,null);return i?t.join(`
5
- `):e}function Ds(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(qg(n,o)):r.push(fc(o)),o.length=0)};for(;a<i&&(a=vc(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){h();let c=rm(e,a,i);if(!c)break;if(c.hasBlock&&$g.has(c.name)){let p=Ds(e,c.blockStart,c.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${c.header} {${Yg(p.statements)}}`)}else r.push(Jn(e.slice(a,c.end)));a=c.end;continue}if(n&&em(e,a,i)){let c=im(e,a,i);if(!c)break;o.push(Jn(c.text)),a=c.end;continue}h();let l=nm(e,a,i);if(!l){let c=om(e,a,i);r.push(Jn(c.text)),a=c.end;continue}let u=n?Zg(n,l.prelude):gc(l.prelude);if(u){s||(s=n!=null);let c=Ds(e,l.blockStart,l.blockEnd,u);s||(s=c.changed),c.statements.length===0?r.push(`${u} {}`):r.push(...c.statements)}a=l.end}return h(),{statements:r,changed:s}}function qg(e,t){return`${e} { ${fc(t)} }`}function fc(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function Yg(e){return e.length===0?"":` ${e.join(" ")} `}function Zg(e,t){let i=Kg(e);if(!i)return null;let n=wc(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=mc(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function gc(e){return mc(e.trim(),Gg).text}function Kg(e){let t=wc(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!Jg(i));return t.length===0?null:`:is(${t.join(", ")})`}function Jg(e){let t=0;for(;t<e.length;){let i=jo(e,t);if(i!=null){t=i;continue}let n=Wi(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,o=Cr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(Hg.has(s))return!0;t=o;continue}t++}return!1}function mc(e,t){let i=0,n=!1,r="",o=[],s=Qg(t);for(;i<e.length;){let a=jo(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=Wi(e,i,e.length);if(h!=null){r+=e.slice(i,h),i=h;continue}let l=e[i];if(l===":"&&e[i+1]!==":"){let u=i+1,c=Cr(e,u,e.length);if(c>u&&e[c]==="("){o.push(e.slice(u,c).toLowerCase()),r+=e.slice(i,c+1),i=c+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?jg:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function Qg(e){let t=0;for(;t<e.length;){let i=jo(e,t);if(i!=null){t=i;continue}let n=Wi(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,o=Cr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function wc(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=jo(e,r);if(a!=null){r=a;continue}let h=Wi(e,r,e.length);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function em(e,t,i){let n=t,r=tm(e,n,i);if(r<=n)return!1;let o=vc(e,r,i);if(o>=i||e[o]!==":")return!1;if(e[t]==="-"&&e[t+1]==="-")return!0;let s=kr(e,o+1,i,Wg);return!s||s.char!=="{"}function tm(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Cr(e,n,i)}function Cr(e,t,i){let n=t;for(;n<i;){let r=e[n];if(r==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(r))break;n++}return n}function im(e,t,i){let n=kr(e,t,i,dc);if(!n){let o=e.slice(t,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function nm(e,t,i){let n=kr(e,t,i,pc);if(!n||n.char!=="{")return null;let r=yc(e,n.index,i);return r<0?null:{prelude:Jn(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function rm(e,t,i){let n=kr(e,t,i,pc);if(!n)return null;let r=Cr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Jn(e.slice(t,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=yc(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function om(e,t,i){let n=kr(e,t,i,dc);if(!n)return{text:e.slice(t,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r),end:r}}function kr(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=Wi(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function yc(e,t,i){let n=t+1,r=1;for(;n<i;){let o=Wi(e,n,i);if(o!=null){n=o;continue}let s=e[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function vc(e,t,i){let n=t;for(;n<i;){let r=e[n];if(xc(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=bc(e,n,i);continue}break}return n}function bc(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function Wi(e,t,i){let n=e[t];return n==='"'||n==="'"?sm(e,t):n==="/"&&e[t+1]==="*"?bc(e,t,i):null}function jo(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function sm(e,t){let i=e[t],n=t+1;for(;n<e.length;){let r=e[n];if(r==="\\"){n+=2;continue}if(r===i)return n+1;n++}return e.length}function xc(e){return e===" "||e===`
6
- `||e==="\r"||e===" "||e==="\f"}function Jn(e){let t="",i=0,n=!1;for(;i<e.length;){let r=Wi(e,i,e.length);if(r!=null&&e[i]!=="/"){n&&t.length>0&&(t+=" ",n=!1),t+=e.slice(i,r),i=r;continue}if(r!=null){n=t.length>0,i=r;continue}let o=e[i];if(xc(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function am(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function Ei(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,am)}var lm=class{constructor(){d(this,"type"),d(this,"precededBySpace",!1),d(this,"num",0),d(this,"text",""),d(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Ye(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Qt=[72,72,72,72,72,72,72,72,72,1,1,72,1,1,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,1,4,34,6,7,8,9,33,10,11,12,13,14,15,16,17,2,2,2,2,2,2,2,2,2,2,18,19,20,21,22,23,24,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,25,29,26,30,3,72,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,27,31,28,32,72];Qt[NaN]=80;var $t=[43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,52,43,43,43,43,39,43,43,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43,43,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,44,43,43,39,43,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,43,43,43,43,43];$t[NaN]=43;var hm=[72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,78,59,72,59,59,59,59,59,59,59,59,59,59,72,72,72,72,72,72,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,61,72,72,78,72,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,72,72,72,72,72];$t[NaN]=43;var Sc=[35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,35,57,59,35,58,58,58,58,58,58,58,58,58,58,35,35,35,35,35,35,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,61,35,35,60,35,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,35,35,35,35,35];Sc[NaN]=35;var Cc=[45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,73,45,45,45,45,45,45,45,53,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45,45,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,44,45,45,39,45,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,45,45,45,45,45];Cc[NaN]=45;var zs=[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,41,37,37,37,37,37,37,37,37,42,37,39,39,39,39,39,39,39,39,39,39,37,37,37,37,37,37,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,40,37,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,37,37,37,37,37];zs[NaN]=37;var Vs=[38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,38,41,38,38,38,38,38,38,38,38,38,38,39,39,39,39,39,39,39,39,39,39,38,38,38,38,38,38,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,40,38,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,38,38,38,38,38];Vs[NaN]=38;var Pi=Ye(35,[61,36]),um=Ye(35,[58,77]),cm=Ye(35,[61,36,124,50]),dm=Ye(35,[38,51]),pm=Ye(35,[42,54]),fm=Ye(39,[42,55]),gm=Ye(54,[42,55,47,56]),mm=Ye(62,[62,82]),wm=Ye(35,[61,36,33,70]),ym=Ye(62,[45,71]),vm=Ye(63,[45,81]),gs=Ye(76,[10,72,13,72]),bm=Ye(39,[39,46,10,72,13,72,92,48]),xm=Ye(39,[34,46,10,72,13,72,92,49]),Sm=Ye(39,[39,47,10,74,13,74,92,48]),Cm=Ye(39,[34,47,10,74,13,74,92,49]),oh=Ye(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),km=Ye(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),Em=Ye(39,[39,68,10,74,13,74,92,75,NaN,67]),Pm=Ye(39,[34,68,10,74,13,74,92,75,NaN,67]),Nm=Ye(72,[9,39,10,39,13,39,32,39,41,69]),Tm=15,Vt=class{constructor(e,t){this.input=e,this.handler=t,d(this,"indexMask"),d(this,"buffer"),d(this,"tail",0),d(this,"curr",0),d(this,"position",0),this.indexMask=Tm,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new lm}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Qt,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",u=0,c=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:l=r.substring(h,o),isNaN(g)?a=0:a=54,n=Qt;break;case 1:o++,c=!0;continue;case 2:h=o++,n=zs;continue;case 3:a=1,h=o++,n=$t;continue;case 4:h=o++,a=31,n=Pi;continue;case 33:a=2,h=++o,n=bm;continue;case 34:a=2,h=++o,n=xm;continue;case 6:h=++o,a=7,n=$t;continue;case 7:h=o++,a=32,n=Pi;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=dm;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Pi;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=Sc;continue;case 16:h=o++,n=hm;continue;case 78:h=o++,a=9,n=$t;continue;case 17:h=o++,a=19,n=pm;continue;case 18:h=o++,a=18,n=um;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=wm;continue;case 21:h=o++,a=39,n=Pi;continue;case 22:h=o++,a=37,n=Pi;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=$t;continue;case 25:h=o++,a=14;break;case 26:h=o++,a=15;break;case 27:h=o++,a=12;break;case 28:h=o++,a=13;break;case 29:h=o++,f=h,a=1,n=gs;continue;case 30:h=o++,a=33,n=Pi;continue;case 31:h=o++,a=34,n=cm;continue;case 32:h=o++,a=35,n=Pi;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,o),10);break;case 38:a=4,u=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,u=parseFloat(r.substring(h,o)),h=o++,n=$t;continue;case 41:a=3,u=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=Vs;continue;case 43:if(l=Ei(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=gs;continue;case 45:l=Ei(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=Ei(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=Sm;continue;case 49:f=o,o+=2,n=Cm;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=oh;continue}a=6}break;case 53:if(l=Ei(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=oh;continue}a=6}break;case 54:n=fm,o++;continue;case 55:n=gm,o++;continue;case 56:n=Qt,o++;continue;case 57:n=mm,o++,r[o]!==">"&&(a=1,n=$t);continue;case 81:a=51,l=r.substring(h,++o),n=Qt;break;case 82:a=52,l=r.substring(h,++o),n=Qt;break;case 58:a=5,n=zs,o++;continue;case 59:a=4,n=Vs,o++;continue;case 60:a=1,n=$t,o++;continue;case 61:a=1,n=gs,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=km;continue;case 65:h=++o,n=Em;continue;case 66:h=++o,n=Pm;continue;case 67:a=8,l=Ei(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=ym,o++;continue;case 71:n=vm,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=Ei(r.substring(h,o)),o++,n=Nm;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Qt;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=$t;continue}l=Ei(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=Cc;continue;default:if(n!==Qt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=c,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Qt,c=!1,p=s[e&i]}this.position=o,this.tail=e&i}},We=null,Us=null;function Hs(){return We}function _(e){if(!We)throw new Error("E_TASK_NO_CONTEXT");We.name||(We.name=e);let t=We,i=new Xo(t,t.top,e);return t.top=i,i.state=1,i}function Im(e){return new Rm(e||new Fm)}function T(e){return new $s(e)}function Sn(e,t,i){let n=_(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Am(e,t){return(We?We.getScheduler():Us||Im()).run(e,t)}var Fm=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Rm=class{constructor(e){this.timer=e,d(this,"timeout",1),d(this,"slice",25),d(this,"sliceOverTime",0),d(this,"queue"),d(this,"wakeupTime",null),d(this,"timeoutToken",null),d(this,"inTimeSlice",!1),d(this,"order",0),this.queue=new Hf,Us||(Us=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){G.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Lm(this,t||"");i.top=new Xo(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){G.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=We;return We=i,this.schedule(i.top.suspend("bootstrap")),We=n,i}},kc=class{constructor(e){this.task=e,d(this,"scheduledTime",0),d(this,"order",0),d(this,"result",null),d(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=We;return We=e,e.top.finish(this.result),We=t,!0}return!1}cancel(){this.canceled=!0}},Lm=class{constructor(e,t){this.scheduler=e,this.name=t,d(this,"callbacks",[]),d(this,"exception",null),d(this,"running",!0),d(this,"result",null),d(this,"waitTarget",null),d(this,"top",null),d(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==We&&this.continuation){this.continuation.cancel();let t=new kc(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=_("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&G.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
3
+ `]).concat(i))),n}var j=new Tg,vs=(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))(vs||{}),Vo={};function Ot(e,t,i){if(!vs[e])j.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Vo[e];n||(n=Vo[e]=[]),i?n.unshift(t):n.push(t)}}function rc(e,t){if(!vs[e])j.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Vo[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ut(e){return Vo[e]||[]}var Ig={registerHook:Ot,removeHook:rc},oc=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){Ws.call(this,e,"start",t)}forceRegisterEndTiming(e,t){Ws.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=Ws,this.registerStartTiming=this.registerStartTiming=uh,this.registerEndTiming=this.registerEndTiming=Ag}isEnabled(){return this.registerStartTiming===uh}};function tn(){}function Ws(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 uh(e,t){this.registerTiming(e,"start",t)}function Ag(e,t){this.registerTiming(e,"end",t)}var Fg={now:Date.now},Rg=window&&window.performance,Et=new oc(Rg||Fg);Et.forceRegisterStartTiming("load_vivliostyle");var Lg={profiler:{registerStartTiming:Et.registerStartTiming,registerEndTiming:Et.registerEndTiming,printTimings:Et.printTimings,disable:Et.disable,enable:Et.enable}},ul=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Uo=/^[\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",Og={};function cl(e){return JSON.parse(e)}function Dt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function sc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Xi=window.location.href;function ch(e){Xi=e}var Ci=window.location.href;function dh(e){Ci=e}function Bg(e){let t=sc(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=Bg(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=sc(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 $o(e,t){return e.match(/^#/)&&t?Dt(t)+e:Ae(e,t)}function ac(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function kn(e){let t;return(e=ac(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 ph(e){return e==null?e:e.toString()}var Mg=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}},lc=["","-webkit-","-moz-"],sn={};function xo(e,t){return CSS.supports(e+t,"unset")}function _g(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(xo("-webkit-","text-combine")&&!xo("","text-combine-upright"))return sn[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of lc)if(xo(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=_g(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 ca(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 dl(e){return`\\${e.charCodeAt(0).toString(16)} `}function ki(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,dl)}function Or(e){return e.replace(/[\u0000-\u001F"\\]/g,dl)}function fh(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function gh(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Dg(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function hc(e,t){function i(n){return Dg(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Ho(e){return hc(e)}function zg(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Vg(e,t){t=typeof t=="string"?t:"\\u";function i(r){return zg(r,t)}let n=new RegExp(`${Ho(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 uc(e,t){return e-t}function mh(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Ug(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Gs(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 $g(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var pl=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 cc(){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 dc(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=cc(),wh={PENDING:{}};function pc(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Wg(e){return`"${Or(`${e}`)}"`}function Gg(e){return ki(`${e}`)}function da(e,t){return e?`${ki(e)}.${ki(t)}`:ki(t)}var fc=0,Wo=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${fc++}`,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=pc,i["css-string"]=Wg,i["css-name"]=Gg,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 jg(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function gc(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 Xg(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function qg(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 mc(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 pa=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=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(gc(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=`_${fc++}`}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===wh.PENDING?!1:n;{i[this.key]=wh.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}},wc=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)}},bs=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)}},yc=class extends bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Vn=class extends bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},vc=class extends bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},fl=class extends bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ei=class extends wc{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Yg=class extends Ei{constructor(e,t){super(e,t)}getOp(){return"not "}},mn=class extends wc{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},gl=class extends yc{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Zg=class extends gl{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},ml=class extends yc{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Kg=class extends ml{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},Jg=class extends ml{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Qg=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},em=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},tm=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},fa=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},wl=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},im=class extends Vn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},bc=class extends vc{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},xc=class extends vc{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},yl=class extends fl{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Sc=class extends fl{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Cc=class extends fl{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)}},yh=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 nm(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function rm(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 kc extends Ht{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),nm(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=rm(t,this.params,i);return n===this.params?this:new kc(this.scope,this.qualifiedName,n)}},om=class Ec 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 Ec(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}},vh=class Pc 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 Pc(this.scope,this.name,n)}},sm=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)}},Nc=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 gl(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new bc(e,t,i)}function ye(e,t,i){return t===e.zero?new mn(e,i):i===e.zero?t:new xc(e,t,i)}function So(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new yl(e,t,i)}function ga(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Sc(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}},Tc=class Ic extends ot{static get instance(){return this.empty||(this.empty=new Ic),this.empty}constructor(){super()}toExpr(t,i){return new et(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};d(Tc,"empty");var am=Tc,Be=am.instance,Ac=class Fc extends ot{static get instance(){return this.slash||(this.slash=new Fc),this.slash}constructor(){super()}toExpr(t,i){return new et(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};d(Ac,"slash");var lm=Ac,Un=lm.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)}},ma=Object.create(null),ae=class extends ot{constructor(e){if(super(),this.name=e,ma[e])throw new Error("E_INVALID_CALL");ma[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=ma[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 yl(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)}},Rc=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)}},Lc=class extends ot{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function vl(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){vl(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){vl(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("("),vl(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 Oc(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")},bh=new R(100,"%"),Mr=new R(100,"pvw"),_r=new R(100,"pvh"),Re=new R(0,"px"),RS=new Lc("U+0-10FFFF"),xh={"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 Sh(e,t){let i=xh[e]||Number.MAX_VALUE,n=xh[t]||Number.MAX_VALUE;return i-n}function je(e){return e?.length>2&&e.startsWith("--")}var ln,hn,un,Bc=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(Bc,"MAX",1e4);var li=Bc;function hm(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,Mc=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(Mc,"MAX",1e4);var _c=Mc;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 Dc(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:_c.fromNumber(i,n,r,o),alpha:s}}function*um(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,Go,zc,Ch,Vc=class{constructor(){ee(this,Go),ee(this,vi,new Map)}registerDeviceCmyk(e){let t=Dc(e);return t?se(this,Go,zc).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=_c.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,Go=new WeakSet,zc=function(e){let t=e.toSRGB(),i=t.toKey(),n=U(this,vi).get(i);return n?n.equals(e)?t:se(this,Go,Ch).call(this,e,t):(U(this,vi).set(i,e),t)},Ch=function(e,t){for(let i=1;i<=li.MAX;i++)for(let[n,r,o]of um(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 Co,tr,ir,Uc=class extends Ki{constructor(e){super(),ee(this,Co),ee(this,tr,new Map),ee(this,ir,!1),fe(this,Co,e??new Vc)}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,Co).registerDeviceCmyk(e);return t?(fe(this,ir,!0),t):super.visitFunc(e)}};Co=new WeakMap,tr=new WeakMap,ir=new WeakMap;function $c(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function cm(e){return`^${e}`}function kh(e){return e.replace(/[\[\]\(\),=;^]/g,cm)}function dm(e){return e.substr(1)}function wa(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,dm)}function pm(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=wa(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Eh(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=pm(i[2]),e=e.substr(i[0].length)}return t}var Ph=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Nh=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!=$c(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}},Th=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(kh(this.textBefore)),e.append(","),this.textAfter&&e.append(kh(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Ih=class Hc{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=Eh(i[4]),o.push(new Nh(a,h,ph(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=wa(h));let l=i[7];l&&(l=wa(l)),s=Eh(i[10]),o.push(new Th(a,h,l,ph(s.s)));break}case"!":r++,o.push(new Ph);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 Hc,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 Th(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:$c(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new Nh(u,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Ph),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}},js=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}},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 fm(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var xs=class Wc{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 xi(r.x+t,r.y+i));return new Wc(n)}};function Fh(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 xs(r)}function bl(e,t,i,n){return new xs([new xi(e,t),new xi(i,t),new xi(i,n),new xi(e,n)])}var Qr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Rh(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 gm(e,t,i,n){let r,o,s,a;t.high.y<i&&j.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Rh(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=Rh(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new Qr(r,o,t.shapeId,-1)),e.push(new Qr(s,a,t.shapeId,1))):(e.push(new Qr(s,a,t.shapeId,-1)),e.push(new Qr(r,o,t.shapeId,1)))}function mm(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 wm(e,t){return t?Math.ceil(e/t)*t:e}function Lh(e,t){return t?Math.floor(e/t)*t:e}function ym(e){return new xi(e.y,-e.x)}function jo(e){return new Lt(e.y1,-e.x2,e.y2,-e.x1)}function Gc(e){return new Lt(-e.y2,e.x1,-e.y1,e.x2)}function Oh(e){return new xs(e.points.map(t=>ym(t)))}function vm(e,t,i,n,r,o){o&&(e=jo(e),t=t.map(v=>Oh(v)),i=i.map(v=>Oh(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(fm);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(wm(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(Lh(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=Lh(p.low.y,r);N<v&&(v=N);break}}let x=[];for(c=0;c<S.length;c++)gm(x,S[c],m,v);x.sort((N,F)=>N.x-F.x||N.lowOrHigh-F.lowOrHigh);let C=mm(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 jc(e,h),h}function jc(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 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 bm(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 xm(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 Sm(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 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 Cm(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=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 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););}jc(e,t)}var km=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 Em(e){if(e){let t=new km;try{return e.visit(t),t.propSet}catch(i){j.warn(i,"toSet:")}}return{}}var Pm=class extends Xt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Bh(e,t){if(e){let i=new Pm(t);try{return e.visit(i),i.value}catch(n){j.warn(n,"toInt: ")}}return t}var Nm=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 xs(s)}break;case"rectangle":if(o.length==4)return bl(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return Fh(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return Fh(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function qc(e,t,i,n,r,o){if(e){let s=new Nm;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){j.warn(a,"toShape:")}}return bl(t,i,t+n,i+r)}var Tm=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 Tm(r,o);try{e.visit(s)}catch(a){j.warn(a,"toCounters:")}return s.counters}var Im=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 Am(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=>Am(s.substring(1,s.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Fm=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}},Rm=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()}},Lm=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(Uo);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(uc),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)}},Om=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 Rm(this,e)}createCounterResolver(e,t,i){return new Lm(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 Fm(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(qs,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?Xs: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(Mh,!0);let n=e.querySelectorAll(`[${qs}]`);for(let r of n)r.setAttribute(_h,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${Xs}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(Xs),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${Mh}]`);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(`[${_h}]`);for(let s of o){let a=s.getAttribute(qs),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 Bm(this,e)}},Xs="data-vivliostyle-pages-counter",jn="data-vivliostyle-page-counter",Xn="data-vivliostyle-target-counter",qs="data-vivliostyle-target-text",Mh="data-vivliostyle-target-counter-in-running",_h="data-vivliostyle-target-text-in-running",Bm=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}},Mm=new Set(["before","after","first-line","first-letter"]),Dh=new Set(["media","supports","-epubx-when"]),Yc=new Set([";","}"]),Zc=new Set(["{",";","}"]),_m=new Set([";","{","}"]),Dm=":where(:scope)",zm=":where(:not(*))";function Vm(e){let{statements:t,changed:i}=ya(e,0,e.length,null);return i?t.join(`
5
+ `):e}function ya(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(Um(n,o)):r.push(Kc(o)),o.length=0)};for(;a<i&&(a=qi(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let c=tw(e,a,i);if(!c)break;if(n&&!Dh.has(c.name)){o.push(Ui(e.slice(a,c.end))),a=c.end;continue}if(h(),c.hasBlock&&Dh.has(c.name)){let p=ya(e,c.blockStart,c.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${c.header} {${$m(p.statements)}}`)}else r.push(Ui(e.slice(a,c.end)));a=c.end;continue}if(n&&Xm(e,a,i)){let c=Zm(e,a,i);if(!c)break;o.push(Ui(c.text)),a=c.end;continue}h();let l=Km(e,a,i);if(!l){let c=iw(e,a,i);r.push(Ui(c.text)),a=c.end;continue}if(n&&Jm(e,a,l)){let c=ew(e,a,l.end,i);o.push(Ui(c.text)),a=c.end;continue}let u=n?Hm(n,l.prelude):Jc(l.prelude);if(u){s||(s=n!=null);let c=ya(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 Um(e,t){return`${e} { ${Kc(t)} }`}function Kc(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function $m(e){return e.length===0?"":` ${e.join(" ")} `}function Hm(e,t){let i=Wm(e);if(!i)return null;let n=ed(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=Qc(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function Jc(e){return Qc(e.trim(),Dm).text}function Wm(e){let t=ed(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!Gm(i));return t.length===0?null:`:is(${t.join(", ")})`}function Gm(e){let t=0;for(;t<e.length;){let i=Ss(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(Mm.has(s))return!0;t=o;continue}t++}return!1}function Qc(e,t){let i=0,n=!1,r="",o=[],s=jm(t);for(;i<e.length;){let a=Ss(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")?zm:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function jm(e){let t=0;for(;t<e.length;){let i=Ss(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 ed(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=Ss(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 Xm(e,t,i){let n=t,r=Ym(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,_m);return s?.char==="{"?!qm(e,t,r,o,s.index):!0}function qm(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 Ym(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 Zm(e,t,i){let n=zr(e,t,i,Yc);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 Km(e,t,i){let n=zr(e,t,i,Zc);if(!n||n.char!=="{")return null;let r=td(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 Jm(e,t,i){if(!Qm(e,t,i.blockStart-1))return!0;let n=qi(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function Qm(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 ew(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 tw(e,t,i){let n=zr(e,t,i,Zc);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=td(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function iw(e,t,i){let n=zr(e,t,i,Yc);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 td(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(nd(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=id(e,n,i);continue}break}return n}function id(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==="'"?nw(e,t):n==="/"&&e[t+1]==="*"?id(e,t,i):null}function Ss(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function nw(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 nd(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(nd(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function rw(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,rw)}var ow=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 sw=[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 rd=[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];rd[NaN]=35;var od=[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];od[NaN]=45;var va=[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];va[NaN]=37;var ba=[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];ba[NaN]=38;var Ri=Je(35,[61,36]),aw=Je(35,[58,77]),lw=Je(35,[61,36,124,50]),hw=Je(35,[38,51]),uw=Je(35,[42,54]),cw=Je(39,[42,55]),dw=Je(54,[42,55,47,56]),pw=Je(62,[62,82]),fw=Je(35,[61,36,33,70]),gw=Je(62,[45,71]),mw=Je(63,[45,81]),Ys=Je(76,[10,72,13,72]),ww=Je(39,[39,46,10,72,13,72,92,48]),yw=Je(39,[34,46,10,72,13,72,92,49]),vw=Je(39,[39,47,10,74,13,74,92,48]),bw=Je(39,[34,47,10,74,13,74,92,49]),zh=Je(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),xw=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]),Sw=Je(39,[39,68,10,74,13,74,92,75,NaN,67]),Cw=Je(39,[34,68,10,74,13,74,92,75,NaN,67]),kw=Je(72,[9,39,10,39,13,39,32,39,41,69]),Ew=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=Ew,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new ow}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=va;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=ww;continue;case 34:a=2,h=++o,n=yw;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=hw;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=rd;continue;case 16:h=o++,n=sw;continue;case 78:h=o++,a=9,n=Kt;continue;case 17:h=o++,a=19,n=uw;continue;case 18:h=o++,a=18,n=aw;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=fw;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=Ys;continue;case 30:h=o++,a=33,n=Ri;continue;case 31:h=o++,a=34,n=lw;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=ba;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=Ys;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=vw;continue;case 49:f=o,o+=2,n=bw;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=zh;continue}a=6}break;case 53:if(l=wi(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=zh;continue}a=6}break;case 54:n=cw,o++;continue;case 55:n=dw,o++;continue;case 56:n=Zt,o++;continue;case 57:n=pw,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=va,o++;continue;case 59:a=4,n=ba,o++;continue;case 60:a=1,n=Kt,o++;continue;case 61:a=1,n=Ys,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=xw;continue;case 65:h=++o,n=Sw;continue;case 66:h=++o,n=Cw;continue;case 67:a=8,l=wi(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=gw,o++;continue;case 71:n=mw,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=kw;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=od;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,xa=null;function Sa(){return qe}function D(e){if(!qe)throw new Error("E_TASK_NO_CONTEXT");qe.name||(qe.name=e);let t=qe,i=new Cs(t,t.top,e);return t.top=i,i.state=1,i}function Pw(e){return new Iw(e||new Tw)}function T(e){return new Ca(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 Nw(e,t){return(qe?qe.getScheduler():xa||Pw()).run(e,t)}var Tw=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Iw=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 Mg,xa||(xa=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 Aw(this,t||"");i.top=new Cs(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}},sd=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}},Aw=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 sd(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}}},$s=class Ec{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Ec(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Om=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Xo(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return t.state=1,this.frame.parent=t,this.frame.then(i=>{e(i).then(n=>{t.finish(n)})}),t.result()}else return e(this.frame.res)}thenReturn(e){return this.isPending()?this.thenAsync(()=>new $s(e)):new $s(e)}thenFinish(e){this.isPending()?this.then(t=>{e.finish(t)}):e.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Xo=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,d(this,"res",null),d(this,"state"),d(this,"callback",null),d(this,"handler",null),this.state=0}checkEnvironment(){if(!We)throw new Error("F_TASK_NO_CONTEXT");if(this!==We.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Om(this)}finish(e){this.checkEnvironment(),We&&!We.exception&&(this.res=e),this.state=2;let t=this.parent;if(We&&(We.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=_("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(G.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=_("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=_("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=We;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Bm(t,t.top);t.top=n,n.state=1,e(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(e){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let t=new kc(this.task);return this.task.continuation=t,We=null,this.task.waitTarget=e||null,t}},Bm=class extends Xo{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Er=class{constructor(e,t){this.fetch=e,d(this,"name"),d(this,"arrived",!1),d(this,"resource",null),d(this,"task",null),d(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Hs().getScheduler().run(()=>{let e=_("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){G.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},Cn=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=_("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()},Pc=`
9
+ `;e.frameTrace=t}}},Ca=class ad{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new ad(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Fw=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Cs(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 Ca(e)):new Ca(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}},Cs=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 Fw(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 Rw(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 sd(this.task);return this.task.continuation=t,qe=null,this.task.waitTarget=e||null,t}},Rw=class extends Cs{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=Sa().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()},ld=`
10
10
  @media screen {
11
11
  [data-vivliostyle-viewer-viewport] {
12
12
  background: #aaaaaa;
@@ -75,7 +75,7 @@ var gf=Object.create;var Al=Object.defineProperty;var mf=Object.getOwnPropertyDe
75
75
  transform-origin: center top;
76
76
  }
77
77
  }
78
- `,Nc=`
78
+ `,hd=`
79
79
  [data-vivliostyle-layout-box] {
80
80
  position: absolute;
81
81
  left: 0;
@@ -198,7 +198,7 @@ var gf=Object.create;var Al=Object.defineProperty;var mf=Object.getOwnPropertyDe
198
198
  break-after: page;
199
199
  }
200
200
  }
201
- `,Tc=`
201
+ `,ud=`
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
- `,Ic=`
832
+ `,cd=`
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>`,Ac=`
856
+ </html>`,dd=`
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
- `,Fc=String.raw`
979
+ `,pd=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
- `,Rc=`
1410
+ `,fd=`
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
- `,Lc=`
1440
+ `,gd=`
1443
1441
  [data-viv-margin-discard~="block-start"] {
1444
1442
  margin-block-start: 0 !important;
1445
1443
  }
@@ -1611,13 +1609,37 @@ span[data-viv-leader] {
1611
1609
  [style*="--viv-marker-text-combine-upright"]::marker {
1612
1610
  text-combine-upright: var(--viv-marker-text-combine-upright);
1613
1611
  }
1612
+ [style*="--viv-marker-text-orientation"]::marker {
1613
+ text-orientation: var(--viv-marker-text-orientation);
1614
+ }
1615
+ [style*="--viv-marker-hyphens"]::marker {
1616
+ hyphens: var(--viv-marker-hyphens);
1617
+ }
1618
+ [style*="--viv-marker-line-height"]::marker {
1619
+ line-height: var(--viv-marker-line-height);
1620
+ }
1621
+ [style*="--viv-marker-tab-size"]::marker {
1622
+ tab-size: var(--viv-marker-tab-size);
1623
+ }
1624
+ [style*="--viv-marker-text-emphasis-style"]::marker {
1625
+ text-emphasis-style: var(--viv-marker-text-emphasis-style);
1626
+ }
1627
+ [style*="--viv-marker-text-emphasis-color"]::marker {
1628
+ text-emphasis-color: var(--viv-marker-text-emphasis-color);
1629
+ }
1630
+ [style*="--viv-marker-text-emphasis-position"]::marker {
1631
+ text-emphasis-position: var(--viv-marker-text-emphasis-position);
1632
+ }
1633
+ [style*="--viv-marker-text-shadow"]::marker {
1634
+ text-shadow: var(--viv-marker-text-shadow);
1635
+ }
1614
1636
 
1615
1637
  /* initial-letter */
1616
1638
  [style*="--viv-initialLetter"]:has(>[data-adapt-pseudo="first-letter"])::first-letter {
1617
1639
  -webkit-initial-letter: var(--viv-initialLetter);
1618
1640
  initial-letter: var(--viv-initialLetter);
1619
1641
  }
1620
- `,Oc=String.raw`
1642
+ `,md=String.raw`
1621
1643
  @counter-style decimal-leading-zero {
1622
1644
  system: extends decimal;
1623
1645
  pad: 2 '0';
@@ -1841,12 +1863,12 @@ span[data-viv-leader] {
1841
1863
  @counter-style upper-russian {
1842
1864
  system: alphabetic;
1843
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;
1844
- }`;function qo(e,t,i){let n=_("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(s.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(s.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?s.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=Bc([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?G.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):G.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function Bc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Mm(e){let t=_("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function _m(e){return URL.createObjectURL(e)}var qa=class{constructor(e,t){this.parser=e,this.type=t,d(this,"resources",{}),d(this,"fetchers",{})}load(e,t,i){e=qt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=_("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let o=Ne("user-agent.xml",mi),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(Ic)}`),qo(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):s&&(a.url=e=o),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=qt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Er(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[qt(e)]}delete(e){delete this.resources[qt(e)]}};function Dm(e,t){let i=e.responseText;return T(i?za(i):null)}function zm(){return new qa(Dm,"text")}function Wt(e,t,i){let n=new Er(()=>{let r=_("loadElement"),o=r.suspend(e),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var sh=0,Vm=16777216,Mc=33554432,_c=50331648,Dc=67108864,Um=83886080,Hm=100663296,Ya=class{constructor(e){this.scope=e,d(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return sh;case"User":return Hm;default:return Um}}getBaseSpecificity(){switch(this.flavor){case"UA":return sh;case"User":return Vm;default:return Mc}}},Ws=class extends Ya{constructor(){super(null),d(this,"stack",[]),d(this,"tokenizer",null),d(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;G.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},ah=class extends Ya{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,d(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Gi=class extends ah{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new ah(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},_e=[],xo=[],be=[],Le=[],At=[],ot=[],Me=[],je=[],ve=[],Ze=[],at=[],He=[],Be=[],tn=55,nn=56,Dr=57;_e[1]=28,_e[36]=29,_e[7]=29,_e[9]=29,_e[14]=29,_e[18]=29,_e[50]=29,_e[20]=30,_e[13]=27,_e[0]=200,xo[1]=46,xo[0]=200,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[14]=10,ot[18]=14,ot[50]=42,be[37]=11,be[23]=12,be[35]=56,be[1]=1,be[36]=3,be[7]=5,be[9]=7,be[14]=9,be[12]=13,be[18]=55,be[50]=58,be[16]=41,Le[37]=11,Le[23]=12,Le[35]=56,Le[1]=1,Le[36]=3,Le[7]=5,Le[9]=7,Le[14]=9,Le[18]=55,At[1]=2,At[36]=4,At[7]=6,At[9]=8,At[18]=14,At[50]=42,At[14]=10,At[12]=13,Me[1]=15,Me[7]=16,Me[4]=17,Me[5]=18,Me[3]=19,Me[2]=20,Me[8]=21,Me[27]=57,Me[16]=22,Me[19]=23,Me[6]=24,Me[11]=25,Me[17]=26,Me[13]=48,Me[31]=47,Me[23]=54,Me[0]=44,je[1]=31,je[4]=32,je[5]=32,je[3]=33,je[2]=34,je[10]=40,je[6]=38,je[31]=36,je[24]=36,je[32]=35,ve[1]=45,ve[16]=37,ve[37]=37,ve[38]=37,ve[47]=37,ve[48]=37,ve[39]=37,ve[49]=37,ve[41]=37,ve[26]=37,ve[25]=37,ve[23]=37,ve[24]=37,ve[19]=37,ve[21]=37,ve[36]=37,ve[18]=37,ve[22]=37,ve[11]=39,ve[12]=43,ve[17]=49,Ze[0]=200,Ze[12]=50,Ze[13]=51,Ze[14]=50,Ze[15]=51,Ze[10]=50,Ze[11]=51,Ze[17]=53,at[0]=200,at[12]=50,at[13]=52,at[14]=50,at[15]=51,at[10]=50,at[11]=51,at[17]=53,He[0]=200,He[12]=50,He[13]=51,He[14]=50,He[15]=51,He[10]=50,He[11]=51,Be[11]=0,Be[16]=0,Be[22]=1,Be[18]=1,Be[26]=2,Be[25]=2,Be[38]=3,Be[37]=3,Be[48]=3,Be[47]=3,Be[39]=3,Be[49]=3,Be[41]=3,Be[23]=4,Be[24]=4,Be[36]=5,Be[19]=5,Be[21]=5,Be[0]=6,Be[tn]=2,Be[nn]=2;var Pr=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,d(this,"valStack",[]),d(this,"namespacePrefixToURI",{}),d(this,"defaultNamespaceURI",null),d(this,"propName",null),d(this,"propImportant",!1),d(this,"exprContext"),d(this,"result",null),d(this,"importReady",!1),d(this,"importURL",null),d(this,"importCondition",null),d(this,"errorBrackets",[]),d(this,"ruleStack",[]),d(this,"regionRule",!1),d(this,"pageRule",!1),d(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Y)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],e===")"&&o instanceof Ki){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new ee(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=at);let h=new $i(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof ce&&h.values[0].name;(!Zt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=at)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=at,null;if(s>1)return new it(this.extractVals(",",n+1));let a=i[0];return a instanceof nt?a:a?new Ki(a.toString()):Y}exprError(e,t){this.actions=this.propName?at:Ze,G.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(e==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new ng(n.getScope(),h,l);a.unshift(u)}return i.push(new W(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new Kn(n.getScope(),Fs(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new Vl(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new yi(n.getScope(),r);else if(s==-24)r=new ln(n.getScope(),r);else if(s==-Dr)r=new tg(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Be[e]>Be[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new Ha(n.getScope(),o,r);break;case tn:r=new ig(n.getScope(),o,r);break;case nn:r=new rg(n.getScope(),o,r);break;case 25:r=new $a(n.getScope(),o,r);break;case 38:r=new og(n.getScope(),o,r);break;case 37:r=new ag(n.getScope(),o,r);break;case 48:r=new sg(n.getScope(),o,r);break;case 47:r=new Os(n.getScope(),o,r);break;case 39:case 49:r=new Wa(n.getScope(),o,r);break;case 41:r=new lg(n.getScope(),o,r);break;case 23:r=new _u(n.getScope(),o,r);break;case 24:r=new Du(n.getScope(),o,r);break;case 36:r=new Ga(n.getScope(),o,r);break;case 19:r=new zu(n.getScope(),o,r);break;case 21:r=new Vu(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new cg(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new Vl(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let u=i.nthToken(1),c=i.nthToken(2);if(u.type===1&&c.type===18)i.consume(),i.consume(),r=u.text,n=c.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(c.type===10||c.type===6))return null;n=e.position+1}}else return null;let o=0,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=t&&r==="selector"&&a>0?"":i.input.substring(n,h).trim();return new dg(this.handler.getScope(),r,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}skipPseudoFunctionContents(){let e=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(e===0)return!0;e--;break;case 10:case 6:e++;break}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,o=t.type===23||r;if(o&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Rt(i,t,new yi(i,new qe(i,"pref-horizontal")));break;case"horizontal":t=Rt(i,t,new qe(i,"pref-horizontal"));break;case"day":t=Rt(i,t,new yi(i,new qe(i,"pref-night-mode")));break;case"night":t=Rt(i,t,new qe(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new W(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,u,c,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===Me&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new Ki(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=at):(this.actions=ot,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Me,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=at,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Me,h.splice(0,h.length);continue;case 29:this.actions=ot,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=He,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),c=this.namespacePrefixToURI[l.text],c!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(c,l.text),r?this.actions=Le:this.actions=be,a.consume();break;case 36:s.tagSelector(c,null),r?this.actions=Le:this.actions=be,a.consume();break;default:this.actions=Ze,s.error("E_CSS_NAMESPACE",l)}else this.actions=Ze,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Le:this.actions=be,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=He,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=Le:this.actions=be,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=Le:this.actions=be,a.consume();break;default:this.actions=Ze,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Le:this.actions=be,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=Le:this.actions=be,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=Le:this.actions=be,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Le:this.actions=be;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ot,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=be:this.actions=He;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=ot,s.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Le:this.actions=be:this.actions=He;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)m.push(u.text),a.consume();else break e;break}else break;else break e;default:if(m=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,m),a.consume(),r?this.actions=Le:this.actions=be;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Ze;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=Le:this.actions=be,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,m),r?this.actions=Le:this.actions=be,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Ze;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=He,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(c=p&&this.namespacePrefixToURI[p],c===void 0){this.actions=He,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=He,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else c="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(c,p,0,null),r?this.actions=Le:this.actions=be,a.consume();continue;default:this.actions=He,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:s.attributeSelector(c,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=He,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=He,s.error("E_CSS_ATTR",l);continue}r?this.actions=Le:this.actions=be,a.consume();continue;case 11:s.childSelector(),this.actions=At,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=At,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=At,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=_e,a.consume();continue;case 41:s.nextSelector(),this.actions=ot,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Yu(l.text)),a.consume();continue;case 17:h.push(new xt(l.num)),a.consume();continue;case 18:h.push(new ze(l.num)),a.consume();continue;case 19:h.push(new R(l.num,l.text)),a.consume();continue;case 20:h.push(new X(l.text)),a.consume();continue;case 21:h.push(new ht(Ne(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Zu(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Fn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=je,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new Ki("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?xo:_e;continue;case 44:for(a.consume();h.length>0;){let x=h.length;if(g=this.valStackReduce(";",l),!g||h.length===x)break}return t?(this.result=g,!0):(this.propName&&g&&s.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new qe(s.getScope(),Fs(l.text,u.text))),this.actions=ve),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new zl(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new zl(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==tn&&h[h.length-1]!==nn&&(u.type===10||u.type===6)){h.push(-Dr),a.consume();continue}else h.push(new qe(s.getScope(),l.text));this.actions=ve}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ve;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Ke(s.getScope(),l.num)),a.consume(),this.actions=ve;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new br(s.getScope(),l.num,p)),a.consume(),this.actions=ve;continue;case 34:h.push(new Ke(s.getScope(),l.text)),a.consume(),this.actions=ve;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Wu(s.getScope(),l.num)),a.consume(),this.actions=ve);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=je,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==nn&&h[h.length-2]!==-Dr?(this.actions=je,this.exprStackReduce(tn,l),h.push(tn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==tn&&h[h.length-2]!==-Dr?(this.actions=je,this.exprStackReduce(nn,l),h.push(nn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Me),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=_e)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=_e,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=_e,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=ve;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=_e,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=je,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Ze;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}s.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Ze;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Ze;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=ot;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=At;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),s.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=je,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=je,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=je,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,b=null,v=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(b=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)v.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(x,b,v);break;case"-epubx-partition":s.startPartitionRule(x,b,v);break;case"-epubx-partition-group":s.startPartitionGroupRule(x,b,v);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=He;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Ze;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Ze;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=_e;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=_e),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=ot,w=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=_e),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){if(this.actions===He)switch(l.type){case 16:this.errorBrackets.length==0&&(s.nextSelector(),w=l.position+1,this.actions=ot),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===ot)s.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(w,l.position);s.pushSelectorText(x),w=l.position+1}if(l.type===16){s.nextSelector(),this.actions=ot,a.consume();continue}else return s.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=be;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=He;continue}if(this.actions!==Ze&&this.actions!==He&&this.actions!==at){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===Me){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ki(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==je&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=_e,a.consume();continue}else{if(l.type===17&&this.actions==je)return this.actions=_e,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=at:this.actions=He;continue}a.consume();continue}}return!1}},zc=class extends Ya{constructor(e){super(null),this.scope=e}error(e,t){G.warn(e,t.toString())}getScope(){return this.scope}};function $m(e,t,i,n,r){let o=Vc(t),s=Xg(e.input);return s!==e.input?lh(new Vt(s,o),o,i,n,r):lh(e,o,i,n,r)}function lh(e,t,i,n,r){let o=_("parseStylesheet"),s=new Pr(_e,e,t,i),a=null;return r&&(a=Gm(new Vt(r,t),t,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ne(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let u=_("parseStylesheet.import");return Uc(l,t,null,null).then(()=>{s.importCondition&&t.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,u.finish(!0)}),u.result()}let h=o.timeSlice();if(h.isPending)return h}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function Za(e,t,i,n,r){let o=Vc(t);return Sn("parseStylesheetFromText",s=>{let a=new Vt(e,o);$m(a,o,i,n,r).thenFinish(s)},(s,a)=>{G.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Vc(e){if(e instanceof Ws)return e;if(e instanceof Gi){if(e.owner)return e.owner;let t=new Ws;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Uc(e,t,i,n){return Sn("parseStylesheetFromURL",r=>{qo(e).then(o=>{o.responseText?Za(o.responseText,t,e,i,n).then(s=>{s||G.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{G.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Nr(e,t,i){let n=new Pr(Me,t,new zc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Wm(e,t,i){new Pr(xo,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Gm(e,t,i){let n=new Pr(je,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var jm={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Xm(e){return!!jm[e]}function qm(e,t,i){if(t instanceof Fe&&t.str==="viv-leader")return new W(t);if(i==="content"&&t instanceof Fe)return new W(t);let n=t.evaluate(e);switch(typeof n){case"number":return Xm(i)?n==Math.round(n)?new ze(n):new xt(n):new R(n,"px");case"string":return n?i==="content"?new X(n):Nr(t.scope,new Vt(n,null),""):Y;case"boolean":return n?y._true:y._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}var Ym="data-vivliostyle-flow-root";function Zm(e){return e.getAttribute(Ym)==="true"}function hh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function Yo(e){return e===y.absolute||e===y.fixed}function So(e){return e instanceof $i&&e.name==="running"}function Hc(e,t,i,n){return e===y.none||(Yo(t)?(i=y.none,e=hh(e)):(i&&i!==y.none&&!Z(i)||n)&&(e=hh(e))),{display:e,position:t,float:i}}function $c(e,t,i,n){return Hc(e,t,i,n).display===y.block}function Zo(e){return e instanceof ce||e instanceof ee||typeof e=="string"}function Dt(e){if(!Zo(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function $n(e){return Zo(e)?e.toString().includes("list-item"):!1}function Km(e){if(!Zo(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Wc(e){if(!Zo(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Jm(e,t,i,n,r,o,s){return r=r||o||y.horizontal_tb,!!s||!!i&&i!==y.none&&!Z(i)||Yo(t)||e===y.inline_block||e===y.table_cell||e===y.table_caption||e==y.flex||e==y.grid||e==y.flow_root||(e===y.block||e===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!Z(n)||!!o&&r!==o}function Qm(e){return e===y.relative||e===y.absolute||e===y.fixed}var Gt=1e5;function Ka(e){let t=e.element.style;t.columnGap=`${Gt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ko(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Co(e){return e.element.style.columnCount==="1"}function ew(e){e.element.setAttribute("data-vivliostyle-column","true")}function hr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Gt)}function Gc(e,t){let i=hr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Gt),o=r*Gt,s=i*Gt;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=Gt),e.right-=o,e.left-=s):e.left<-Gt/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=Gt),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=Gt),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Gs(e,t){for(let i=0;i<e.length;i++)Gc(e[i],t)}function Et(e,t,i){let n=e.getElementClientRect(t);if(Gc(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Jo(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Ko(r),e.getElementClientRect(t)}return n}function tw(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function js(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function iw(e){if(!e.hasAttribute("data-vivliostyle-column")&&js(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&js(t))return!0;return!1}function Jo(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(js(t))return t;if(i.position==="absolute")break}return null}function nw(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!r&&!s)return;let a=Jo(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:c,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(c)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>w.bottom+m:g?x.right<w.left-m:x.left>w.right+m)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${Gt}px`)}function zr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?hr(i,e.vertical):0}function jc(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||zr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize),o=NaN;if(e.style.blockSize=`${r}px`,zr(t)){if(e.style.blockSize=`${n}px`,!zr(t)){let s=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;e.style.blockSize=`${l}px`,zr(t)?h=l:a=l}o=a,e.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/t.clientLayout.layoutUnitPerPixel;o=r+s,e.style.blockSize=`${o}px`}if(isNaN(o)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function rw(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)jc(i,e)}function rn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Dt(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.parentNode.insertBefore(s,o);let a=t.getElementClientRect(s);if(s.remove(),a){let h=[a];Gs(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=Et(t,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return e.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);Gs(l,n);let u=l.filter(c=>c.right>c.left&&c.bottom>c.top);if(u.length>0)l=u;else{let c=o?t.getElementComputedStyle(o).whiteSpace:"";l=c==="pre"||c==="pre-wrap"||c==="pre-line"||c==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(c=>c.left)):s=Math.max.apply(null,l.map(c=>c.bottom)),s):NaN}}function Xs(e,t,i){let n=Co(t);n&&Ko(t);let r=t.clientLayout.getElementClientRect(e);n&&Ka(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function un(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Xc(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var kn="data-adapt-spec";function Ja(e){return!!e.getAttribute(kn)}function ci(e){return e?.nodeType!==1?!1:Ja(e)?!0:qc(e)}function qc(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function uh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function cn(e){let t=e?.viewNode;return t?.nodeType===1&&Ja(t)}function ow(e){return e!=="inline"&&(Dt(e)||Wc(e))}function ch(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Dt(i.display))return i;return null}function sw(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}function Yc(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},o=e[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Zc(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=e.replace(s.regexp,s.to);if(a!==e)return a}return e}var Kc={"horizontal-tb":{ltr:[{logical:"inline-start",physical:"left"},{logical:"inline-end",physical:"right"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}],rtl:[{logical:"inline-start",physical:"right"},{logical:"inline-end",physical:"left"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}]},"vertical-rl":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]},"vertical-lr":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]}},aw=Yc(Kc,!0);function Jc(e,t,i){return Zc(e,t,i||null,aw)}var lw=Yc(Kc,!1);function Qc(e,t,i){return Zc(e,t,i||null,lw)}var hw={"horizontal-tb":[{logical:"line-left",physical:"left"},{logical:"line-right",physical:"right"},{logical:"over",physical:"top"},{logical:"under",physical:"bottom"}],"vertical-rl":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}],"vertical-lr":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}]};function uw(e,t){let i=hw[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function Qa(e,t,i){var n;let r=t,o={width:r.style.width,height:r.style.height};function s(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let c={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),c[p]=parseFloat(f)}return c}function dn(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function ed(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function td(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function mt(e,t){let i=ed(e);i.includes(t)||(i.push(t),td(e,i))}function cw(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function dw(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function ms(e,t){let i=cw(e);i.includes(t)||(i.push(t),dw(e,i))}function pw(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===y.always?y.page:i,important:e.important};default:return e}}var qs={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Xe(e){return!!qs[e]}var fw={left:!0,right:!0,recto:!0,verso:!0};function En(e){return!!fw[e]}function dh(e){return Xe(e)&&e!=="column"&&e!=="region"}var gw={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ko(e){return!!gw[e]}function tt(e,t){if(e)if(t){if(En(t))return t;if(En(e))return e;{let i=Xe(e),n=Xe(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:ko(t)?t:ko(e)?e:t}}else return e;else return t}function ph(e){return Xe(e)?e:"auto"}Nt("SIMPLE_PROPERTY",pw);var Qn=Ff(Lf());function mw(e,t){return(0,Qn.default)(e,t,0)}function fh(e){return e.reduce((t,i)=>i[0]===Qn.default.DELETE?t:t+i[1],"")}function ww(e,t){return id(e,t,1)}function yw(e,t){return id(e,t,-1)}function id(e,t,i){let n=0,r=0;return e.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case Qn.default.INSERT:n++;break;case Qn.default.DELETE:n--,r++;break;case Qn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Ys;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Ys||(Ys={}));var yn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(yn||(yn={}));var Eo;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Eo||(Eo={}));var _i;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||xi.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||xi.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(_i||(_i={}));var xi;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(xi||(xi={}));var si;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(si||(si={}));var vw={transform:!0,"transform-origin":!0},bw={top:!0,bottom:!0,left:!0,right:!0},el=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},xw={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function Sw(e,t){let i=xw[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Zs=class Wn extends Va{constructor(t,i){super(),this.container=t,this.bleedBox=i,d(this,"pageAreaElement",null),d(this,"delayedItems",[]),d(this,"hrefHandler"),d(this,"elementsById",{}),d(this,"dimensions",{width:0,height:0}),d(this,"isFirstPage",!1),d(this,"isLastPage",!1),d(this,"isBlankPage",!1),d(this,"isAutoPageWidth",!0),d(this,"isAutoPageHeight",!0),d(this,"spineIndex",0),d(this,"position",null),d(this,"offset",-1),d(this,"side",null),d(this,"fetchers",[]),d(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),d(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Wn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Wn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Wn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Wn.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||N(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<t.length;o++){let s=t[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=Sw(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};d(Zs,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),d(Zs,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var nd=Zs,dt=si.Whitespace;function rd(e){switch(e){case"normal":case"nowrap":return dt.IGNORE;case"pre-line":return dt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return dt.PRESERVE;default:return null}}function Ve(e,t){return e?e.nodeType==1?!1:od(e.textContent,t):!0}function od(e,t){switch(t){case dt.PRESERVE:return e.length==0;case dt.NEWLINE:return!!e.match(/^[ \t]*$/);case dt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var Cw=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,d(this,"forcedBreakOffsets",[]),d(this,"formattingContext",null)}},kw=class{constructor(e,t,i,n,r,o,s,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=o,this.repeated=s,this.last=a,this.breakBefore=h,d(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Ew(e,t){return e.top-t.top}function Pw(e,t){return t.right-e.right}function sd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===si.ShadowType.ROOTLESS&&t.shadowType===si.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Ks(e.shadowContext,t.shadowContext)&&Ks(e.nodeShadow,t.nodeShadow)&&sd(e.shadowSibling,t.shadowSibling)}function Vi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!sd(e.steps[i],t.steps[i]))return!1;return!0}function Nw(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Po(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function No(e,t){let i=new on(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?No(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=si.ShadowType,Zr=class{constructor(e,t,i,n,r,o,s){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=o,this.styler=s,d(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Ks(this.parentShadow,e.parentShadow):!1}};function Ks(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Tw=class{constructor(e,t){this.outer=e,this.count=t}},on=class ad{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,d(this,"offsetInNode",0),d(this,"after",!1),d(this,"shadowType"),d(this,"shadowContext"),d(this,"nodeShadow",null),d(this,"shadowSibling",null),d(this,"shared",!1),d(this,"inline",!0),d(this,"overflow",!1),d(this,"breakPenalty"),d(this,"display",null),d(this,"floatReference"),d(this,"floatSide",null),d(this,"clearSide",null),d(this,"floatMinWrapBlock",null),d(this,"columnSpan",null),d(this,"captionSide","top"),d(this,"inlineBorderSpacing",0),d(this,"blockBorderSpacing",0),d(this,"flexContainer",!1),d(this,"whitespace"),d(this,"hyphenateCharacter"),d(this,"breakWord"),d(this,"establishesBFC",!1),d(this,"containingBlockForAbsolute",!1),d(this,"breakBefore",null),d(this,"breakAfter",null),d(this,"viewNode",null),d(this,"clearSpacer",null),d(this,"inheritedProps"),d(this,"vertical"),d(this,"direction"),d(this,"firstPseudo"),d(this,"lang",null),d(this,"preprocessedTextContent",null),d(this,"formattingContext"),d(this,"repeatOnBreak",null),d(this,"pluginProps",{}),d(this,"fragmentIndex",1),d(this,"afterIfContinues",null),d(this,"footnotePolicy",null),d(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=yn.FloatReference.INLINE,this.whitespace=i?i.whitespace:dt.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=yn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:dt.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new ad(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,o=[];r.shadowType===si.ShadowType.ROOTLESS&&(r.floatReference!==yn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&o.push(r.toNodePositionStep()),r=r.parent;while(r);let s=this.preprocessedTextContent?yw(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:s,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Si=class ld{constructor(t){this.primary=t,d(this,"floats",null)}clone(){let t=new ld(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!Vi(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!Vi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Iw=class hd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new hd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Aw=class ud{constructor(){d(this,"positions",[]),d(this,"startBreakType",null),d(this,"breakAfter",null)}clone(){let t=new ud,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Fw=class cd{constructor(){d(this,"page",0),d(this,"flows",{}),d(this,"flowPositions",{}),d(this,"isBlankPage",!1),d(this,"highestSeenOffset",0),d(this,"highestSeenNode"),d(this,"lookupPositionOffset")}clone(){let t=new cd;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&En(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},dd=class{constructor(e){this.element=e,d(this,"left",0),d(this,"top",0),d(this,"marginLeft",0),d(this,"marginRight",0),d(this,"marginTop",0),d(this,"marginBottom",0),d(this,"borderLeft",0),d(this,"borderRight",0),d(this,"borderTop",0),d(this,"borderBottom",0),d(this,"paddingLeft",0),d(this,"paddingRight",0),d(this,"paddingTop",0),d(this,"paddingBottom",0),d(this,"width",0),d(this,"height",0),d(this,"originX",0),d(this,"originY",0),d(this,"exclusions",null),d(this,"innerShape",null),d(this,"computedBlockSize",0),d(this,"snapWidth",0),d(this,"snapHeight",0),d(this,"snapOffsetX",0),d(this,"snapOffsetY",0),d(this,"vertical",!1),d(this,"rtl",!1),d(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,N(this.element,"top",`${e}px`),N(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,N(this.element,"left",`${e}px`),N(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):Xa(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new Pt(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new Pt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return cc(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new Pt(e,t,e+i,t+n)}},ur=class extends li{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof ht)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Fe&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function St(e){return e!=null&&e!==Y&&e!==y.normal&&e!==y.none&&!Z(e)}var Pe=yn.FloatReference,Rw=20;function Lw(e){switch(e){case"inline":return Pe.INLINE;case"column":return Pe.COLUMN;case"region":return Pe.REGION;case"page":return Pe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function vi(e){switch(e){case Pe.INLINE:return!1;case Pe.COLUMN:case Pe.REGION:case Pe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function ws(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Qc(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Jc(e,r,i),s=uw(o,r);s==="line-left"?e="left":s==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(G.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var pd=class{constructor(e,t,i,n,r,o){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=o,d(this,"order",null),d(this,"id",null),d(this,"insidePageFloatArea",!1),d(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Ow=class{constructor(){d(this,"floats",[]),d(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Vi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(n=>Vi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},fd=class{constructor(e,t,i,n,r,o){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=o}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},gh=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Vi(this.nodePosition,e.nodePosition):!1}},sn=class{constructor(e,t,i,n,r,o,s){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,d(this,"children",[]),d(this,"writingMode"),d(this,"direction"),d(this,"invalidated",!1),d(this,"floatStore"),d(this,"forbiddenFloats",[]),d(this,"floatFragments",[]),d(this,"stashedFloatFragments",[]),d(this,"floatAnchors",{}),d(this,"floatsDeferredToNext",[]),d(this,"floatsDeferredFromPrevious"),d(this,"layoutConstraints",[]),d(this,"locked",!1),d(this,"footnoteMaxBlockSize",null),d(this,"ignoreFootnoteAreaMaxHeight",!1),d(this,"footnoteAnchorsSeen",new Set),d(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Z(o)&&o||e&&e.writingMode||y.horizontal_tb,this.direction=!Z(s)&&s||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new Ow;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let o=r-1;o>=0;o--){let s=this.children[o];if(s.floatReference===t&&s.flowName===i&&Vi(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,t,i,n),s))return s}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Pn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&t.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var t;if(!("footnotePolicy"in e))return;let i=this;for(;i;)i.footnoteAnchorsSeen.add(e.getId()),i=(t=i.parent)!=null?t:i.outerContext}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t,this.markPageFloatAnchorSeen(e)}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}removeFloatDeferredToNext(e){let t=this.floatsDeferredToNext.findIndex(i=>i.float===e);t>=0&&this.floatsDeferredToNext.splice(t,1)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let o=r.float,s=o.getOrder();s>t&&(!i||s>i.getOrder())&&(i=o)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}hasRootMultiColumnFootnoteContext(){return this.children.some(e=>{let t=0;for(let i of e.children)if(!i.generatingNodePosition&&(t+=1,t>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(e=>e.children.some(t=>{var i;let n=(i=t.getContainer())==null?void 0:i.element;return n!=null&&iw(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Rw?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Pe.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float;if(this.floatReference===Pe.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===y.line&&this.footnoteAnchorsSeen.has(t.getId())){if(this.locked){this.invalidate();return}this.removeFloatDeferredToNext(t),this.forbid(t),this.invalidate();return}}for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return Qc(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Jc(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let s of t){let a=this.toLogical(s);i.includes(a)||i.push(a)}let n=[],r=!1,o=!1;for(let s=0;s<i.length;s++){let a=i[s];a.includes("block")?r||(i.slice(s+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(s+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),o=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,o=!0){this.container;let s=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(s,h,i,n,r);if(o&&this.parent&&this.parent.container){let c=this.parent.getLimitValue(a,l,i,n,r,o);switch(a){case"top":return Math.max(u,c);case"left":return Math.max(u,c);case"bottom":return Math.min(u,c);case"right":return Math.min(u,c);default:}}return u}getLimitValueInner(e,t,i,n,r){this.container;let o=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?o.right:o.top;case"block-end":return this.container.vertical?o.left:o.bottom;case"inline-start":return this.container.vertical?this.container.rtl?o.bottom:o.top:this.container.rtl?o.right:o.left;case"inline-end":return this.container.vertical?this.container.rtl?o.top:o.bottom:this.container.rtl?o.left:o.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var o,s,a,h;this.container;let l=this.container.originX,u=this.container.originY,c=this.container.getPaddingRect(),p={top:c.y1-u,left:c.x1-l,bottom:c.y2-u,right:c.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((s=(o=this.container.element)==null?void 0:o.style)==null?void 0:s.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,x){return m.unit==="%"?x*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[x,b]=this.toLogicalFloatSides(w.floatSide);if(b&&(n&&b.includes("block")===n.includes("block")&&b!==n||r&&b.includes("block")===r.includes("block")&&b!==r))return m;let v=w.area,C=w.continuations[0].float.floatMinWrapBlock,S=v.vertical?v.left+v.getInsetLeft()+v.width+v.getInsetRight():v.top+v.getInsetTop()+v.height+v.getInsetBottom(),F=v.vertical?v.top+v.getInsetTop()+v.height+v.getInsetBottom():v.left+v.getInsetLeft()+v.width+v.getInsetRight(),A=m.top,D=m.left,H=m.bottom,q=m.right,Se=m.floatMinWrapBlockStart,se=m.floatMinWrapBlockEnd;switch(x){case"inline-start":v.vertical?A=Math.max(A,F):D=Math.max(D,F);break;case"block-start":v.vertical?(C&&v.left<q&&(Se=f(C,v.rootViewNodes[0],c.x2-c.x1)),q=Math.min(q,v.left)):(C&&S>A&&(Se=f(C,v.rootViewNodes[0],c.y2-c.y1)),A=Math.max(A,S));break;case"inline-end":v.vertical?H=Math.min(H,v.top):q=Math.min(q,v.left);break;case"block-end":v.vertical?(C&&S>D&&(se=f(C,v.rootViewNodes[0],c.x2-c.x1)),D=Math.max(D,S)):(C&&v.top<H&&(se=f(C,v.rootViewNodes[0],c.y2-c.y1)),H=Math.min(H,v.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:A,left:D,bottom:H,right:q,floatMinWrapBlockStart:Se,floatMinWrapBlockEnd:se}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,o,s){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;e.clientLayout;let h=a.find(S=>S.includes("inline")&&s[S==="inline-start"?"inline-end":"inline-start"]),l=a.find(S=>S.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),c=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;e.isFootnote||(u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),c=e.vertical?Math.max(c,e.left+g):Math.min(c,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function w(S,F){let A=S(e.bands,F);return A?(e.vertical&&(A=lc(A)),u=e.vertical?Math.min(u,A.x2):Math.max(u,A.y1),c=e.vertical?Math.max(c,A.x1):Math.min(c,A.y2),!0):o}let x,b,v,C;if(r){let S=e.vertical?bo(new Pt(c,p,u,f)):new Pt(p,u,f,c);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(Pg,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Ng,S)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),v=(c-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(v=Math.min(v,this.footnoteMaxBlockSize),e.vertical?u=c+v:u=c-v),x=Math.max(0,v-e.getInsetBefore()-e.getInsetAfter()),C=(f-p)*e.getInlineDir(),b=C-e.getInsetStart()-e.getInsetEnd(),!o&&(x<=0||b<=0)))return null}else{let S=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,S)),v=x+e.getInsetBefore()+e.getInsetAfter();let F=(c-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let D=this.container.getPaddingRect(),H=this.container.getBoxDir()*(n-(this.container.vertical?D.x2:D.y1)),q=this.container.getBoxDir()*((this.container.vertical?D.x1:D.y2)-n-v);H<=q?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&F<v)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?b=Qa(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?b=e.getContentInlineSize():b=e.vertical?e.height:e.width,C=b+e.getInsetStart()+e.getInsetEnd();let A=(f-p)*e.getInlineDir();if(!o&&A<C)return null}return u-=g,c-=g,p-=m,f-=m,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,b):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-C*e.getInlineDir(),b),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,x):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(c-v*e.getBoxDir(),x),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-start")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x1:s.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let o=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.min(r,o):Math.max(r,o):o)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-end")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x2:s.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let o=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.max(r,o):Math.min(r,o):o)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.continuations.some(i(u))}let r=t.getPaddingRect(),o=t.vertical?r.x1:r.y2,s=this;for(;s;){if(s.floatsDeferredToNext.some(i(s)))return o;s=s.parent}function a(l){return l.floatFragments.some(u=>n(u,l))||l.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(s=this;s;s=s.parent)if(s.floatReference===e){if(a(s))return o;break}}t.clientLayout;let h=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<o*t.getBoxDir()?o:h}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=e.getOrder();function h(c){return p=>(!c||p.floatSide.includes(c))&&p.getOrder()<a}function l(c,p){return c.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(c,p){let f=c.parent;return!!f&&(f.floatFragments.some(h(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let c=this;c;c=c.parent)if(c.floatReference===i){(c.floatFragments.some(h(null))||l(c,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(c=>{switch(c){case"block-start":n[c]=!l(this,c);break;case"block-end":n[c]=!u(this,c);break;case"inline-start":case"inline-end":n[c]=!this.floatFragments.some(h(c));break;default:throw new Error(`Unexpected side: ${c}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let s=n.getLimitValuesInner(t,i);r?e.vertical?(s.right<r.right&&(r.right=s.right,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>r.left&&(r.left=s.left,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>r.top&&(r.top=s.top,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<r.bottom&&(r.bottom=s.bottom,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):r=s,n=n.parent}let o=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=o}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},_n=[],Pn=class{static register(e){_n.push(e)}findByNodeContext(e){for(let t=_n.length-1;t>=0;t--){let i=_n[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=_n.length-1;t>=0;t--){let i=_n[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Bw=class{appliesToNodeContext(e){return vi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,o=e.toNodePosition(),s=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new pd(o,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),T(h)})}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new fd(o.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return T(void 0)}forbid(e,t){}};Pn.register(new Bw);var gd="data-vivliostyle-footnote-first-ref",md="data-vivliostyle-footnote-referenced";function To(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function yt(e){if(e.localName!=="aside")return!1;if(To(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return To(t,"footnote")}function Lt(e){if(e.localName!=="a")return!1;if(To(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return To(t,"noteref")}function tl(e,t){if(!Lt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=yo(i,t);return n==="#"?null:n}function wd(e,t,i){let n=tl(e,t);if(!n)return null;let r=i(n);return r&&yt(r)?r:null}function Mw(e,t,i,n,r){if(r.value)return;let o=e.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=tl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function mh(e,t,i,n,r){if(e.localName!=="a"||!Lt(e))return!0;let o=tl(e,t);if(!o)return!0;Mw(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function il(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===y.inline?t.createCascadeValue(y.inline,n.priority):null}function _w(e,t,i,n,r,o,s){if(e.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||e.localName!=="include"||!e.classList.contains("-vivliostyle-footnote-content"))return t;let a=i?.owner;if(!(a instanceof Element)||!Lt(a))return t;let h=wd(a,n,r);if(!h)return t;let l=a.getAttribute(o);l?(e.setAttribute(o,l),h.setAttribute(o,l)):(e.removeAttribute(o),h.removeAttribute(o));let u=s.getStyle(h);if(!u)return t;let c={...t},p=il(u,s),f=s.getProp(u,"footnote-policy"),g=s.getStyleMap(u,"_pseudos"),m=g?.after;if(p&&(c["footnote-display"]=p),f&&(c["footnote-policy"]=f),m){let w=s.getMutableStyleMap(c,"_pseudos");w.after={...m}}return c}function Dw(e,t,i,n,r){var o;if(!(i?.type===rt.ROOTED&&yt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=il(s,r),l=r.getProp(s,"footnote-policy"),u=r.getStyleMap(s,"_pseudos"),c=u?.["footnote-marker"],p=r.getProp(c,"content"),f=r.getProp(c,"list-style-position");if(h&&(a["footnote-display"]=h),l&&(a["footnote-policy"]=l),p&&((o=f?.evaluate)==null?void 0:o.call(f,n,"list-style-position"))===y.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(B("list-item"),0),a["list-style-position"]=r.createCascadeValue(y.outside,0),a["list-style-type"]=r.createCascadeValue(y.none,0),a["list-style-image"]=r.createCascadeValue(y.none,0)}return a}function zw(e,t,i){var n,r;let o=t?.type===rt.ROOTED&&yt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=il(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function yd(e,t){if(e instanceof W){let i=e.expr.evaluate(t);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):e}return e instanceof ee?new ee(e.values.map(i=>yd(i,t))):e}function Vw(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=yd(n.value,i))}function Uw(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Lt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=e.getElementById(o);if(s&&yt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(gd,"true")),s.setAttribute(md,"true")}}}Nt("PREPROCESS_SINGLE_DOCUMENT",Uw);var Hw=fd,Io=class vd extends pd{constructor(t,i,n,r,o,s){super(t,i,"block-end",null,n,o),this.footnotePolicy=r,this.policyAnchorNode=s}isAllowedToPrecede(t){return!(t instanceof vd)}};function $w(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;for(;t;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(t.localName)&&!t.querySelector("br"))return t;t=t.parentElement}return e}var wh=class extends Hw{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Io?!0:this.getOrder()<e.getOrder()}},Ww=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;for(;t;){if(t===this.footnote.policyAnchorNode)return!1;t=t.parentNode}return!0}},Gw=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Io}createPageFloat(e,t,i){var n;let r=Pe.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Pe.PAGE).hasSameContainerAs(o)&&(r=Pe.PAGE);let s=!!t.generatingNodePosition;s&&r!==Pe.PAGE&&(r=Pe.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Lt(l)&&(h=l),h=$w(h);let u=new Io(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=s,s){let c=t.generatingNodePosition;c&&(u.parentPageFloat=t.findPageFloatByNodePosition(c))}return t.addPageFloat(u),T(u)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new wh(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof wh);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=e.vertical?e.paddingLeft+e.paddingRight+e.borderLeft+e.borderRight:e.paddingTop+e.paddingBottom+e.borderTop+e.borderBottom,l=e.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],u=getComputedStyle(n);for(let c of l){let p=u.getPropertyValue(c);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||N(n,c,`${Math.max(0,f-h)}px`)}}N(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){N(n,"max-block-size",""),N(n,e.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return T(void 0)})}forbid(e,t){let i=e;switch(i.footnotePolicy){case y.line:{let n=new Ww(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Pn.register(new Gw);var nl=class{calculateOffset(e){return vn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function vn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Tr=class extends nl{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,d(this,"overflowIfRepetitiveElementsDropped"),d(this,"isEdgeUpdated",!1),d(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(ko(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=rn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Dn=class{find(e){let t=Ot("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},pn=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new Tr(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===si.ShadowType.ROOTLESS&&cn(i))return;let o=i.viewNode;((r=o.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let s=o.parentNode;Xc(s,o),n&&s.removeChild(o)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),T(!0)}},rl=class{constructor(e){this.parent=e,d(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},ol=new pn,jw=Ys.isInstanceOfBlockFormattingContext;Nt("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,o)=>{let s=e.parent;return!s&&e.formattingContext||s&&e.formattingContext!==s.formattingContext?null:e.establishesBFC||!e.formattingContext&&$c(i,n,r,o)?new rl(s?s.formattingContext:null):null});Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof rl?ol:null);var sl=class{constructor(){d(this,"initialBreakPositions",null),d(this,"initialStateOfFormattingContext",null),d(this,"initialPosition"),d(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=_("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let o=n.accept(r,t);o=n.postLayout(r,this.initialPosition,t,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},Xw=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},Js=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=_("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ve(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?o=t.afterIgnoredTextNode(i):o=t.startIgnoredTextNode(i):i.nodeContext.after?o=t.afterNonElementNode(i):o=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?o=t.afterInlineElementNode(i):o=t.startInlineElementNode(i):i.nodeContext.after?o=t.afterNonInlineElementNode(i):o=t.startNonInlineElementNode(i):i.nodeContext.after?o=t.afterNonDisplayableNode(i):o=t.startNonDisplayableNode(i);let s=(o&&o.isPending()?o:T(!0)).thenAsync(()=>i.break?T(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},er=class extends Xw{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&Xe(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:T(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:T(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=tt(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}},Qs=[];function qw(){Qs=[]}function bd(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Yw=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Zw=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},xd=class Kr{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Kr.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Kr.fragmentIndices={}}matches(){let t=Kr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&bd(t.fragmentIndex,this.a,this.b)}};d(xd,"fragmentIndices",{});var Qo=xd,Vr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Qo(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Zw(e)}static buildAnyMatcher(e){return new Yw(e)}},Sd={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},Kw=["image-resolution","orphans","widows"];function Jw(){return Ot("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Kw))}var Qw={"http://www.idpf.org/2007/ops":!0,"http://www.w3.org/1999/xhtml":!0,"http://www.w3.org/2000/svg":!0,"http://www.w3.org/1998/Math/MathML":!0},ea=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],ey=["max-%","min-%","%"],yh=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<ea.length;i++)for(let n=0;n<e.length;n++){let r=ea[i].replace("%",e[n]);t[r]=!0}return t})();function Rn(e,t){let i={};for(let n of ea)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}for(let n of ey)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var Cd=Rn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),kd=Rn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),ty=Rn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),iy=Rn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),ny=Rn({inside:"right",outside:"left"},{}),ry=Rn({inside:"left",outside:"right"},{}),V=class ta{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ta(i,this.priority)}increaseSpecificity(t){return t==0?this:new ta(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Zt(i)?this.value:Lo(t,this.value,i,n,r)}isEnabled(t){return!0}},ia=class na extends V{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new V(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new na(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new na(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){G.warn(i)}return!1}};function ra(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Ut(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Ed={"region-id":!0,"fragment-selector-id":!0},tr="data-viv-footnote-counter";function Ao(e){let t=e.getAttribute(tr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function Pd(e,t,i){let n=Ao(e);n[t]=i,e.setAttribute(tr,JSON.stringify(n))}function oy(e,t){var i,n;if(!Lt(e)||e.hasAttribute(gd))return null;let r=Ao(e)[t];if(r)return r;let o=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=yo(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=e.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let u=Ao(l)[t];return u?(Pd(e,t,u),u):null}function sy(e){let t=ge(e,"content");return!!t&&St(t.value)}function ay(e){return!!Ed[e]}function Jr(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Mi(e){return e.charAt(0)!=="_"&&!Ed[e]}function fn(e){return!!Sd[e]||Zt(e)}function ge(e,t){return e[t]}function bi(e,t,i){i?e[t]=i:delete e[t]}function pt(e,t){return e[t]}function Kt(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Nd=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Td(e,t){return e[t]}function Id(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Fo(e,t,i,n,r,o,s){var a,h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=Kt(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),s){let l=Nd(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!Jr(l))if(ay(l)){let u=Td(i,l),c=Id(t,l);Array.prototype.push.apply(c,u)}else{let u=ge(i,l);if(!u.isEnabled(e))continue;let c=u.increaseSpecificity(n);Ut(t,l,c,e);let p=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(p)for(let f of p){let g=new V(Y,c.priority);Ut(t,f,g,e)}}}function ly(e,t){let i={};for(let n=0;n<t.length;n++)Fo(e,i,t[n],0,null,null,null);return i}function al(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var hy=class extends Hi{constructor(e,t){super(),this.props=e,this.context=t,d(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ge(this.props,"font-size");if(!e.value.isNumeric())return zt.em;let t=e.value;if(!Jf(t.unit))throw new Error("Unexpected state");return t.num*zt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?oa(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ll(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Lo(this.context,e,this.propName).visit(this):e}};function ll(e,t,i){let n=e.unit,r=e.num;return n==="em"?new R(r*t,"px"):n==="rem"?new R(r*i.fontSize(),"px"):n==="rlh"?new R(r*i.rootLineHeight,"px"):e}function oa(e,t,i){e=ll(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new R(r/100*t,"px"):new R(r*i.queryUnitSize(n,!1),"px")}var Ln=class{apply(e){}mergeWith(e){return new uy([this,e])}clone(){return this}},Ur=class extends Ln{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},uy=class Ad extends Ln{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Ad([].concat(this.list))}},hl=class extends Ln{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){Fo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},xe=class extends Ln{constructor(){super(),d(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},cy=class extends xe{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},dy=class extends xe{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},vh=class extends xe{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},py=class extends xe{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},fy=class extends xe{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},gy=class extends xe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function es(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let r of e.getAttributeNames())if((r===i||r.endsWith(`:${i}`))&&n(e,r===i?"":e.lookupNamespaceURI(r.split(":")[0]),i))return!0;return!1}var bh=class extends xe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},my=class extends xe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},wy=class extends xe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>!!Qw[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},zn=class extends xe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){es(e.currentElement,this.ns,this.name,(t,i,n)=>{var r;return!!((r=t.getAttributeNS(i,n))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},yy=class extends xe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},xh=class extends xe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},vy=class extends xe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},ji=class extends xe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return bd(e,this.a,this.b)}},by=class extends ji{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},sa=class extends ji{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},aa=class extends ji{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},la=class extends ji{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,o=t[n];o||(o=t[n]={}),o[r]=(o[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},xy=class extends xe{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},Sy=class extends xe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Cy=class extends xe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},ky=class extends xe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},et=class extends xe{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},Fd=class Rd extends Ln{constructor(){super(),d(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Rd;return t.applied=this.applied,t}},ul=class extends xe{constructor(e){super(),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Fd;for(let t of e)this.firstActions.push(al(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof xe?e.getPriority():0))}positive(){return!0}relational(){return!1}},Ey=class extends ul{positive(){return!1}},Py=class extends ul{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},Ld=class extends ji{constructor(e,t,i){super(e,t),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new Fd;for(let n of i)this.firstActions.push(al(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,o=t.currentId,s=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let c of this.firstActions)if(c.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=o,t.currentClassNames=s,t.currentSiblingOrder=a,u}getPriority(){return 5}},Ny=class extends Ld{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},ts=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Ty=class Od extends ts{constructor(t,i,n){super(t,i,n)}fresh(t){return new Od(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},Iy=class Bd extends ts{constructor(t,i,n){super(t,i,n)}fresh(t){return new Bd(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},Ay=class Md extends ts{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new Md(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},Fy=class _d extends ts{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new _d(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},Ry=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Ly=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Oy=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},By=class extends Hi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ht(e):new ht("about:invalid");case"string":default:return e?new X(e):new X("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof ee){let r=e.values[0].values;r.length>=2&&(t=r[1].stringValue()),i=r[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Ro(e,t){if(St(e)){if(e instanceof X)return e.stringValue();if(e instanceof W&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof ee)return e.values.map(i=>Ro(i,t)).join("")}return""}var cr=class extends Hi{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Ro(i,this.cascade.context);return this.cascade.quoteDepth=t,n}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new X("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new X("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new ri;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var o,s,a,h,l,u;let c=typeof r=="string",p=w=>c?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&Pd(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=oy(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=Ao(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((o=e.currentPageCounters)==null?void 0:o[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((s=e.currentPageDocCounters)==null?void 0:s[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],x=((l=e.currentPageCounters)==null?void 0:l[t])||[],b=x.length?x[x.length-1]:0,v=w.length?w[0]:0,C=m.length?m[0]:0,S=b+(C-v);return g=m.length?[S,...m.slice(1)]:x.length?x:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let a=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),h=this.getPageScope(),l=new Fe(h,()=>this.buildCounterText(o,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&o!=null&&o.registerPageCounterExpr){let u=c=>this.formatLastValue(c,n);o.registerPageCounterExpr(i,u,l)}return new W(l)}let s=this.cascade.counters[i];if(s&&s.length){let a=s&&s.length&&s[s.length-1]||0;return new X(this.format(a,n))}else{let a=new W(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new ee([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",o=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let u=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),c=this.getPageScope(),p=new Fe(c,()=>this.buildCounterText(s,i,r,o,n),u?`page-counters-${i}`:`counters-${i}`);return u&&s!=null&&s.registerPageCounterExpr&&s.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new W(p)}let a=this.cascade.counters[i],h=new ri;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new W(this.counterResolver.getPageCountersVal(i,u=>{let c=[];if(u.length)for(let f=0;f<u.length;f++)c.push(this.format(u[f],r));let p=h.toString();return p.length&&c.push(p),c.length?c.join(n):this.format(0,r)}));return new ee([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ht?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",o=new W(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new ee([o])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ht?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),o=e.length>3?e[3].stringValue():"decimal",s=new W(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new ee([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof ht?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new W(this.counterResolver.getTargetTextVal(i,n));return new ee([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new W(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new W(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,o,s,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let c=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(c&&this.element)for(let f=0;f<c.length;f++){let g=c[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=pt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=Ro(m,this.cascade.context)}}}break;case"first-letter":{let c=pt(this.cascade.currentStyle,"_pseudos"),p=(s=(o=c?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=c?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(wo);u=g?g[0]:""}break}return new X(u)}visitFuncLeader(e){let t="";if(e[0]instanceof ce)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof X&&(t=e[0].stringValue());return t.length==0?new X(""):new W(new Fe(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function ys(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var My=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(P){v==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(m);return b==="vertical-rl"||b==="vertical-lr"?v==="rtl"?P.top-=k:P.bottom+=k:v==="rtl"?P.left-=k:P.right+=k,A.left>P.left||A.right<P.right||A.top>P.top||A.bottom<P.bottom},c=function(){let P,I,O=x.repeat(1e4);if(l(O),u())P=1,I=1e4;else return;for(let z=0;z<16;z++){let $="",K=Math.floor((P+I)/2);for(let J=0;J<K;J++)$+=x;if(l($),u())I=K;else{if(P==K)return;P=K}}l(x)},p=function(P){let I=0,O=m.parentElement;for(;O&&O!==f.viewNode;)I+=i.getComputedInsets(O)[P],O=O.parentElement;return I};var r=l,o=u,s=c,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:b,direction:v,marginInlineEnd:C}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(x),m.style.display="inline-block",m.style.textIndent="0";let S=Jo(f.viewNode),F=S?.style.columnFill||null;S&&(S.style.columnFill="auto");let A=i.clientLayout.getElementClientRect(f.viewNode),D=i.clientLayout.getElementClientRect(m),H=i.parseComputedLength(C),q=[],Se=m.parentElement;for(;Se.parentElement&&Se.parentElement!==f.viewNode;)Se=Se.parentElement;let se=Se.nextSibling;for(;se;){if(se.nodeType===1){let P=se,{display:I,float:O,position:z}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||z==="absolute"||z==="fixed"){se=se.nextSibling;continue}if(Dt(I))q.push(P);else if(Km(I))break}else if(se.nodeType===3){let P=se;P.length>0&&q.push(P)}se=se.nextSibling}let k=q.reduce((P,I)=>P+ys(I,i.clientLayout,b),0);if(w!=="after"){let P=ys(Se,i.clientLayout,b),I=ys(m,i.clientLayout,b);k+=P-I}b==="vertical-rl"||b==="vertical-lr"?(v==="rtl"?A.top+=H:A.bottom-=H,A.top=Math.min(D.top,A.top),A.bottom=Math.max(D.bottom,A.bottom)):(v==="rtl"?A.left+=H:A.right-=H,A.left=Math.min(D.left,A.left),A.right=Math.max(D.right,A.right)),c();let M=i.clientLayout.getElementClientRect(m);v=="rtl"?m.style.float="left":m.style.float="right";let E=i.clientLayout.getElementClientRect(m),L=0;v=="rtl"?b=="vertical-rl"||b=="vertical-lr"?L=M.top-E.top-p("top"):L=M.left-E.left-p("left"):b=="vertical-rl"||b=="vertical-lr"?L=E.bottom-M.bottom-p("bottom"):L=E.right-M.right-p("right"),L-=k,L=Math.max(0,L-.1),m.style.float="",g.style.marginInlineStart=`${L}px`,S&&(F?S.style.columnFill=F:S.style.removeProperty("column-fill"))}};Nt("POST_LAYOUT_BLOCK",My);var cl=1/1048576;function Yi(e,t){for(let i in e)t[i]=e[i].clone()}var _y=class Dd{constructor(){d(this,"nsCount",0),d(this,"nsPrefix",{}),d(this,"tags",{}),d(this,"nstags",{}),d(this,"epubtypes",{}),d(this,"classes",{}),d(this,"ids",{}),d(this,"pagetypes",{}),d(this,"order",0)}clone(){let t=new Dd;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Yi(this.tags,t.tags),Yi(this.nstags,t.nstags),Yi(this.epubtypes,t.epubtypes),Yi(this.classes,t.classes),Yi(this.ids,t.ids),Yi(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,o,s){return new Dy(this,t,i,n,r,o,s)}nextOrder(){return this.order+=cl}},zd=class Vd{constructor(t,i,n,r,o,s,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=s,this.cmykStore=a,d(this,"code"),d(this,"stack",[[],[]]),d(this,"conditions",Object.create(null)),d(this,"currentElement",null),d(this,"currentElementOffset",null),d(this,"currentStyle",null),d(this,"currentClassNames",null),d(this,"currentLocalName",""),d(this,"currentNamespace",""),d(this,"currentId",""),d(this,"currentXmlId",""),d(this,"currentNSTag",""),d(this,"currentEpubTypes",null),d(this,"currentPageType",null),d(this,"previousPageType",null),d(this,"firstPageType",null),d(this,"pageTypePageIndices",Object.create(null)),d(this,"isFirst",!0),d(this,"isRoot",!0),d(this,"counters",Object.create(null)),d(this,"lastCounterChanges",[]),d(this,"lastCounterChangeTypes",Object.create(null)),d(this,"counterScoping",[Object.create(null)]),d(this,"quotes"),d(this,"quoteDepth",0),d(this,"lang",""),d(this,"siblingOrderStack",[0]),d(this,"currentSiblingOrder",0),d(this,"siblingTypeCountsStack",[{}]),d(this,"currentSiblingTypeCounts"),d(this,"currentFollowingSiblingOrder",null),d(this,"followingSiblingOrderStack"),d(this,"followingSiblingTypeCountsStack",[{}]),d(this,"currentFollowingSiblingTypeCounts"),d(this,"viewConditions",Object.create(null)),d(this,"dependentConditions",[]),d(this,"elementStack"),this.code=t,this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=Vr.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:Vr.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Vr.buildAllMatcher(n):Vr.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=vs,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,o,s,a,h;let l=new Set,u=Object.create(null),c=y.inline,p=t.display;if(p&&(c=p.evaluate(this.context)),c===y.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let f=y.inline,g=t.float;g&&(f=g.evaluate(this.context));let m=null,w=null,x=null,b=t["counter-reset"];if(b){let S=b.evaluate(this.context);S&&(m=wn(S,{reset:!0}))}let v=t["counter-set"];if(v){let S=v.evaluate(this.context);S&&(x=wn(S,{defaultValue:0}))}let C=t["counter-increment"];if(C){let S=C.evaluate(this.context);S&&(w=wn(S))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),$n(c)&&(w||(w=Object.create(null)),w["list-item"]=(r=w["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((s=(o=this.currentElement)==null?void 0:o.getAttribute("value"))!=null?s:"")&&(x||(x=Object.create(null)),x["list-item"]=this.currentElement.value)),((a=this.currentElement)==null?void 0:a.parentNode.nodeType)===Node.DOCUMENT_NODE&&(m||(m=Object.create(null)),m.footnote===void 0&&(m.footnote=0)),f===y.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(w||(w=Object.create(null)),w.footnote===void 0)){let S=(h=this.currentStyle["counter-increment"])==null?void 0:h.value;(!S||!(S===y.footnote||S instanceof ee&&S.values.includes(y.footnote)))&&(w.footnote=1)}if(m)for(let S in m)l.add(S),u[S]="reset";if(w)for(let S in w)l.add(S),u[S]||(u[S]="increment");if(x)for(let S in x)l.add(S),u[S]="set";if(this.lastCounterChanges=Array.from(l),this.lastCounterChangeTypes=u,m)for(let S in m)this.defineCounter(S,m[S]);if(w)for(let S in w){this.counters[S]||this.defineCounter(S,0);let F=this.counters[S];F[F.length-1]+=w[S]}if(x)for(let S in x)if(!this.counters[S])this.defineCounter(S,x[S]);else{let F=this.counters[S];F[F.length-1]=x[S]}if($n(c)){let S=this.counters["list-item"],F=S[S.length-1];t["ua-list-item-count"]=new V(new xt(F),0);let A=Kt(t,"_pseudos");A.marker||(A.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new cr(this,this.currentElement,this.counterResolver));let n=i.value instanceof it?i.value.values:[i.value];for(let r of n)if(r instanceof ee){let o=r.values[0].stringValue(),s=r.values.slice(1).map(a=>Ro(a,this.context)).join("");this.counterResolver.setNamedString(o,s,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof $i&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new cr(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var o,s,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=vs;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=vs;let c=As(i);c&&(this.stack[this.stack.length-1].push(new Ly(this.lang)),this.lang=c.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let x=this.followingSiblingOrderStack;x[x.length-1]!==null?this.currentFollowingSiblingOrder=--x[x.length-1]:this.currentFollowingSiblingOrder=null,x.push(null);let b=this.followingSiblingTypeCountsStack,v=this.currentFollowingSiblingTypeCounts=b[b.length-1];v&&v[this.currentNamespace]&&v[this.currentNamespace][this.currentLocalName]--,b.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i);let C=n.quotes,S=null;if(C){let D=C.evaluate(this.context);D&&(S=new Oy(this.quotes),D===y.none?this.quotes=[new X(""),new X("")]:D===y.auto||D===y.initial?this.quotes=[new X("\u201C"),new X("\u201D"),new X("\u2018"),new X("\u2019")]:D instanceof ee&&(this.quotes=D.values))}this.pushCounters(this.currentStyle);let F=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||F){let D=Object.create(null);Object.keys(this.counters).forEach(H=>{D[H]=Array.from(this.counters[H])}),this.counterListener.countersOfId(F,D)}let A=pt(this.currentStyle,"_pseudos");if(A){let D=!0;for(let H of zy){H||(D=!1);let q=A[H];if(q){let Se=(o=ge(this.currentStyle,"float"))==null?void 0:o.value,se=i instanceof Element&&Lt(i),k=i instanceof Element&&yt(i),M=!!ge(this.currentStyle,"--viv-semantic-footnote-content"),E=Se===y.footnote,L=(H==="before"||H==="after")&&(E||k||M)&&!!q.content,P=sy(q),I=H==="footnote-call"&&se&&P,O=H==="footnote-marker"&&(k||M)&&P;if((H==="before"||H==="after")&&!(L||St((s=q.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(q))||H==="marker"&&!$n((a=ge(this.currentStyle,"display"))==null?void 0:a.value)||(H==="footnote-call"||H==="footnote-marker")&&Se!==y.footnote&&!I&&!O||(H==="footnote-call"||H==="footnote-marker")&&M&&!P)delete A[H];else if(D){if(this.processPseudoelementProps(q,i,H),H==="marker")this.processMarkerPseudoelementProps(q,i,t),delete A[H];else if(H==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(q,"list-style-position",t,i)===y.outside){this.processMarkerPseudoelementProps(q,i,t);let z=q.content;z&&(this.currentStyle["_footnote-marker-content"]=z),this.currentStyle.display=new V(B("list-item"),0),this.currentStyle["list-style-position"]=new V(y.outside,0),this.currentStyle["list-style-type"]=new V(y.none,0),this.currentStyle["list-style-image"]=new V(y.none,0),delete A[H]}}else if(H==="first-letter"&&q["initial-letter"]){let z=q["initial-letter"].evaluate(this.context);z!==y.normal&&!Z(z)&&(this.currentStyle["--viv-initialLetter"]=new V(z,0)),delete q["initial-letter"]}}else this.stack[this.stack.length-2].push(new Ry(q,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return St((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,o,s,a,h;let l=$n((r=this.currentStyle.display)==null?void 0:r.value);if(!St((o=t.content)==null?void 0:o.value)&&l){let c=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ht)t.content=new V(new ee([p,new X(" ")]),0);else if(c instanceof X)t.content=new V(c,0);else if(c instanceof ce&&c!==y.none){let f=(a=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=c.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new X(this.counterStyleStore.formatMarker(c.name,f)),0))}}}let u=t.content;if(u){let c=u.value;if(St(c)){let p=this.resolveMarkerContentVal(c);this.currentStyle["--viv-marker-content"]=new V(p,0)}}for(let c of Vd.markerAllowedProps){let p=t[c];if(p){let f=p.evaluate(this.context,c);f&&!Z(f)&&(this.currentStyle[`--viv-marker-${c}`]=new V(f,0))}}if(!Dt((h=ge(this.currentStyle,"display"))==null?void 0:h.value)){let c=this.getInheritedPropertyValue("list-style-position",n,i);c&&c!==y.outside&&!Z(c)&&(this.currentStyle["list-style-position"]=new V(c,0))}}resolveMarkerContentVal(t){if(t instanceof W){let i=t.expr.evaluate(this.context);return typeof i=="string"?new X(i):typeof i=="number"?new X(String(i)):t}if(t instanceof ee){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new ee(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let s=n;s;s=s.parentElement){let a=(s===this.currentElement?this.currentStyle:i.getStyle(s,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===y.inherit||h===y.unset||h===y.revert)continue;if(h===y.initial)break;return h}}let o=i.validatorSet;return(r=o?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var o;let s=t[i];if(s){let a=s.evaluate(this.context,i);if(a!==y.inherit&&a!==y.unset&&a!==y.revert){if(a===y.initial){let h=n.validatorSet;return(o=h?.defaultValues[i])!=null?o:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i){for(let n in i)Mi(n)&&!Zt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new By(t),n=this.currentStyle,r=pt(n,"_pseudos");for(let o in r)this.applyAttrFilterInner(i,r[o]);this.applyAttrFilterInner(i,n)}applyVarFilter(t,i,n){var r,o,s;let a=t[0],h=new Yy(t,i,n),l=32,u={};for(let c in a)if(Jr(c)){let p=pt(a,c);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Mi(c)){let p=ge(a,c),f=p.value;for(let g=0;;g++){if(g>=l){f=Y;break}let m=f.visit(h);if(h.error){f=Y,h.error=!1;break}if(m===f)break;f=m}if(f!==p.value){let g=i.validatorSet,m=(r=g?.shorthands[c])==null?void 0:r.clone();if(m)if(Z(f)){for(let w of m.propList){let x=new V(f,p.priority),b=ge(a,w);bi(u,w,ra(this.context,b,x))}delete a[c]}else{let w=Nr(i.scope,new Vt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let x of m.propList){let b=new V((s=(o=m.values[x])!=null?o:g.defaultValues[x])!=null?s:y.initial,p.priority),v=ge(a,x);bi(u,x,ra(this.context,v,b))}delete a[c]}}else a[c]=new V(f,p.priority)}if(u[c]){let g=ge(a,c);g&&g.value!==Y&&Ut(u,c,g,this.context)}}for(let c in u)a[c]=u[c]}applyCalcFilter(t,i){let n=new qd(i);for(let r in t)if(Jr(r)){let o=pt(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Mi(r)&&!Zt(r)){let o=ge(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new V(s,o.priority))}}applyCmykFilter(t,i){let n=new rc(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(Jr(r)){let o=pt(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Mi(r)&&!Zt(r)){let o=ge(t,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),t[r]=new V(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};d(zd,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var Dy=zd,vs=[],zy=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ha=null;function Vy(e){ha=e}var dr=class extends Gi{constructor(e,t,i,n,r,o,s){super(e,t,s),this.condition=i,this.regionId=r,this.validatorSet=o,d(this,"chain",null),d(this,"specificity",0),d(this,"elementStyle",null),d(this,"conditionCount",0),d(this,"pseudoelement",null),d(this,"selectorFunctionContainsPseudoelement",!1),d(this,"footnoteContent",!1),d(this,"cascade"),d(this,"state"),d(this,"viewConditionId",null),d(this,"insideSelectorRule"),d(this,"invalid",!1),this.cascade=n?n.cascade:ha?ha.clone():new _y,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=al(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}invalidContinuationAfterPseudoelement(e){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${e}`),!0):this.selectorFunctionContainsPseudoelement?(this.invalidSelector(`Selector containing pseudo-element followed by ${e}`),!0):!1}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||this.invalidContinuationAfterPseudoelement(t||"*")||(t&&(this.specificity+=1),t&&e?this.chain.push(new py(e,t.toLowerCase())):t?this.chain.push(new vh(t.toLowerCase())):this.chain.push(new gy(e)))}invalidSelector(e){G.warn(e),this.chain.push(new et("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Nn;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new cy(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Sy);break;case"disabled":this.chain.push(new Cy);break;case"checked":this.chain.push(new ky);break;case"root":case"scope":this.chain.push(new vy);break;case"link":this.chain.push(new vh("a")),this.chain.push(new bh("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${hi(i)}($|\\s)`),r=t[1];this.chain.push(new fy(n,r,e==="href-role-type"))}else this.chain.push(new et(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new et(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new yy(new RegExp(`^${hi(i.toLowerCase())}($|-)`)))}else this.chain.push(new et(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Uy[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new et(""));break}case"first-child":this.chain.push(new xh);break;case"last-child":this.chain.push(new aa(0,1));break;case"first-of-type":this.chain.push(new sa(0,1));break;case"last-of-type":this.chain.push(new la(0,1));break;case"only-child":this.chain.push(new xh),this.chain.push(new aa(0,1));break;case"only-of-type":this.chain.push(new sa(0,1)),this.chain.push(new la(0,1));break;case"empty":this.chain.push(new xy);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}}pseudoelementSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`::${e}`)){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new et(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new et(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new dy(e)))}attributeSelector(e,t,i,n){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new bh(e,t);break;case 39:r=new my(e,t,n);break;case 45:!n||n.match(/\s/)?r=new et(""):r=new zn(e,t,new RegExp(`(^|\\s)${hi(n)}($|\\s)`));break;case 44:r=new zn(e,t,new RegExp(`^${hi(n)}($|-)`));break;case 43:n?r=new zn(e,t,new RegExp(`^${hi(n)}`)):r=new et("");break;case 42:n?r=new zn(e,t,new RegExp(`${hi(n)}$`)):r=new et("");break;case 46:n?r=new zn(e,t,new RegExp(hi(n))):r=new et("");break;case 50:if(n=="supported")r=new wy(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(r)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Hr++}`;this.processChain(new Ur(new Ty(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Hr++}`;this.processChain(new Ur(new Iy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Hr++}`;this.processChain(new Ur(new Ay(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Hr++}`;this.processChain(new Ur(new Fy(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new hl(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ia(t,0,this.condition):i=new V(t,0),Id(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===y.oeb_page_head||t===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new ee([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),Ot("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:e,value:t,important:i});e=s.name,t=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new ia(t,n,this.condition):new V(t,n);Ut(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Nn(this);break;case"not":i=new Hy(this);break;case"where":i=new $y(this);break;case"has":i=new Wy(this);break;case"nth-child":t&&t.length>=2&&(i=new Hd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Gy(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},Uy={"nth-child":by,"nth-of-type":sa,"nth-last-child":aa,"nth-last-of-type":la},Hr=0,Nn=class Ud extends dr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,d(this,"parentChain"),d(this,"chains",[]),d(this,"maxSpecificity",0),d(this,"selectorTexts",[]),d(this,"containsPseudoelementSelector",!1),this.parentChain=t.chain}nextSelector(){this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){var t;this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Py(this.selectorTexts):this.positive()?new ul(this.chains):new Ey(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new et("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof Ud;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Hy=class extends Nn{positive(){return!1}forgiving(){return!1}},$y=class extends Nn{increasingSpecificity(){return!1}},Wy=class extends Nn{relational(){return!0}},Hd=class extends Nn{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Ld(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}forgiving(){return!0}},Gy=class extends Hd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Ny(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}},jy=class extends Gi{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new br(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Qr=class extends Gi{constructor(e,t,i,n,r,o){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=o,d(this,"order"),this.order=0}property(e,t,i){i?G.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){G.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){G.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=cl;let r=this.condition?new ia(t,n,this.condition):new V(t,n);Ut(this.elementStyle,e,r)}},Xy=class extends zc{constructor(e,t){super(e),this.validatorSet=t,d(this,"elementStyle",{}),d(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){G.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){G.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Dc:_c;n+=this.order,this.order+=cl;let r=new V(t,n);Ut(this.elementStyle,e,r)}};function $d(e,t){let i=Nd(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function ua(e,t,i){$d(i,n=>{ir(e,n,t)})}function qy(e,t,i,n){let r=new Xy(e,t),o=new Vt(n,r);try{Wm(o,r,i)}catch(s){G.warn(s,"Style attribute parse error:")}return r.elementStyle}function Wd(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.vertical_rl}return i}function Gd(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.rtl}return i}function ca(e,t,i,n,r){let o={};for(let s in e)Mi(s)&&(o[s]=ge(e,s));return ua(o,t,e),jd(e,i,n,(s,a)=>{ir(o,a,t),ua(o,t,a)}),o}function jd(e,t,i,n){let r=pt(e,"_regions");if((t||i)&&r){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let s=r[o];s&&n(o,s)}}}function ir(e,t,i){for(let n in t)if(Mi(n)){let r=ge(t,n),o=e[n];e[n]=ra(i,o,r)}}var Xd=(e,t,i,n,r,o)=>{var s,a;let h=i?n?ty:Cd:n?iy:kd,l=r?ny:ry;for(let u in e){let c=e[u];if(!c)continue;let p=(s=h[u])!=null?s:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>c.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>c.priority))continue;m=yh[p]?p:yh[f]?f:u}else m=u,u.startsWith("text-align")&&(c.value===y.inside||c.value===y.outside)&&(c=new V(r===(c.value===y.inside)?y.right:y.left,c.priority));t[m]=o(u,c)}},Yy=class extends Hi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,r,o;let s=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=(o=(r=this.styler.getStyle(s,!1))==null?void 0:r[e])==null?void 0:o.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof ce&&e.values[0].name;return!t||!Zt(t)?(this.error=!0,Y):this.getVarValue(t)||(e.values.length<2?(this.error=!0,Y):e.values.length===2?e.values[1]:new it(e.values.slice(1)))}},qd=class extends Hi{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=Nr(this.context.rootScope,new Vt(i,null),"");if(n instanceof W)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new R(r,"px"):/\d[a-z]/i.test(i)||(t=new xt(r)))}catch(r){G.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Ru(e.unit)||this.context.rootFontSize!=null&&eg(e.unit)?new R(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new R(e.num*this.percentRef/100,"px"):e}};function Lo(e,t,i,n,r){try{if(t instanceof W)return t.expr instanceof Fe&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:qm(e,t.expr,i);if(t instanceof R||t instanceof $i||t instanceof ee||t instanceof it)return t.visit(new qd(e,!0,n,r))}catch(o){return G.warn(o),Y}return t}var Sh={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Ch(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.none;if(t===y.none)return Sh;let i=t instanceof ee?t.values:[t],n=Object.create(Sh);for(let r of i)if(r instanceof ce)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function kh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Zy={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Eh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Ph={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Nh(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.normal;if(t===y.normal)return Eh;if(t===y.auto)return Ph;let i=t instanceof ee?t.values:[t],n=Object.create(Eh);for(let r of i)if(r instanceof ce)switch(r.name){case"trim-both":case"trim-auto":return Ph;case"space-all":return Zy;case"trim-start":n.trimStart=!0,n.spaceFirst=!1;break;case"space-start":n.trimStart=!1,n.spaceFirst=!1;break;case"space-first":n.trimStart=!1,n.spaceFirst=!0;break;case"trim-end":n.trimEnd=!0,n.allowEnd=!1;break;case"space-end":n.trimEnd=!1,n.allowEnd=!1;break;case"allow-end":n.trimEnd=!1,n.allowEnd=!0;break;case"trim-adjacent":n.trimAdjacent=!0;break;case"space-adjacent":n.trimAdjacent=!1;break}return n}var bs={ideographAlpha:!1,ideographNumeric:!1},Ky={ideographAlpha:!0,ideographNumeric:!0};function Th(e){let t=e instanceof nt?e:typeof e=="string"?B(e):y.normal;if(t===y.normal||t===y.auto)return Ky;if(t===y.none)return bs;let i=t instanceof ee?t.values:[t],n=Object.create(bs);for(let r of i)if(r instanceof ce)switch(r.name){case"no-autospace":return bs;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Ih(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ah(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var Jy=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let o=r.length-1;for(let s=0;s<o;s++)n.parentNode.insertBefore(document.createTextNode(r[s]),n);n.textContent=r[o]}}}processGeneratedContent(e,t,i,n,r,o){r=Ah(r);let s=Th(t),a=Nh(i),h=Ch(n);if(kh(h)&&Ih(s,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),c=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!c,m=!c||/\n$/.test(c.textContent),w=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||m,g,m,w,x,c,p,s,a,h,r,o),c=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let u=!e||e.fragmentIndex===1&&f(),c=u||g();function p(b){var v;if(b?.nodeType!==1)return!1;let C=b;if(C.hasAttribute(kn))return!0;let{position:S,float:F}=(v=C.style)!=null?v:{};return S==="absolute"||S==="fixed"||F&&F!=="none"}function f(){let b=t[0];for(let v=b;;v=v.parent)if(!v||!v.inline){if(v?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let v=b.viewNode.previousSibling;v;v=v.previousSibling)if(!Ve(v,b.whitespace)&&!p(v))return!1;return!0}function g(){var b,v;let C=t[0],S;for(;C&&C.inline&&(S=(b=C.viewNode)==null?void 0:b.previousSibling,!(S&&(S.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(S.textContent)&&C.whitespace!==dt.PRESERVE&&(S=S.previousSibling),S)));)C=C.parent;for(;S;){if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let F=(v=S.style)==null?void 0:v.display;if(F&&F!=="inline")return!/^(inline|ruby)\b/.test(F)}else if(S.nodeType===Node.TEXT_NODE){if(C.whitespace===dt.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(C.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}S=S.lastChild}return!1}let m=-1;for(let b=0;b<t.length;b++){let v=t[b];if(!v.after&&v.inline&&!v.display&&v.parent&&v.viewNode.parentNode&&v.viewNode.nodeType===Node.TEXT_NODE&&!Ve(v.viewNode,v.whitespace)){let C=function(P){var I,O,z;if(((I=P.viewNode)==null?void 0:I.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let $=P.viewNode;if(P.whitespace===dt.PRESERVE){if(/\n$/.test($.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test($.textContent))return!0;if(((z=$.previousElementSibling)==null?void 0:z.localName)==="br")return Ve($,P.whitespace)}return!1},S=function(P){var I,O,z;if(((I=P.viewNode)==null?void 0:I.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let $=P.viewNode;if(P.whitespace===dt.PRESERVE){if(/^\n/.test($.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/^[ \t\r\n\f]*\n/.test($.textContent))return!0;if(((z=$.nextElementSibling)==null?void 0:z.localName)==="br")return Ve($,P.whitespace)}return!1};var w=C,x=S;m<0&&(m=b);let F=Ah((o=(n=(i=v.lang)!=null?i:v.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),A=Th(v.inheritedProps["text-autospace"]),D=Nh(v.inheritedProps["text-spacing-trim"]),H=Ch(v.inheritedProps["hanging-punctuation"]);if(kh(H)&&Ih(A,D)||/\b(flex|grid)\b/.test(v.parent.display))continue;let q=null,Se=null,se=b===m,k=b===m&&u,M=b===m&&c,E=!1,L=!1;for(let P=b-1;P>=0;P--){let I=t[P];if(C(I)){M=!0;break}if(!I.display&&I.viewNode.nodeType===Node.TEXT_NODE&&I.viewNode.textContent.length>0){q=I.viewNode;break}if(((s=I.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&Xt(I.viewNode)==="footnote-call"){if(I.viewNode.contains(v.viewNode))continue;let O=sw(I.viewNode);if(O){q=O;break}}if(I.display&&!/^(inline|ruby)\b/.test(I.display)||((a=I.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(I.viewNode.localName==="br"||Bi[I.viewNode.localName]))break;P===0&&(se=!0,u&&(k=!0,M=!0))}for(let P=b+1;P<t.length;P++){let I=t[P];if(S(I)){E=!0;break}if(I.viewNode!==v.viewNode&&!I.display&&I.viewNode.nodeType===Node.TEXT_NODE&&I.viewNode.textContent.length>0){Se=I.viewNode;break}if(I.display&&!/^(inline|ruby)\b/.test(I.display)||((h=I.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(I.viewNode.localName==="br"||Bi[I.viewNode.localName])){P===t.length-1&&p(I.viewNode)&&(L=!0);break}if(P===t.length-1){E=!0,L=!0;for(let O=I.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){L=!1;break}}}if(((l=v.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=v.parent.viewNode.firstChild;for(;Ve(P,v.whitespace);)P=P.nextSibling;v.viewNode===P&&(k=!0)}if(!L){let P=v.parent.viewNode.lastChild;for(;Ve(P,v.whitespace);)P=P.previousSibling;v.viewNode===P&&(L=!0)}}if(this.processTextSpacing(v.viewNode,se,k,M,E,L,q,Se,A,D,H,F,v.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,u,c,p){let f=e.textContent,g=e.ownerDocument,m=0,w,x,b;function v(){if(t)return!0;if(!s)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(s));let L=x.getClientRects(),P=L[L.length-1];return P?(m||(m=hr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function C(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;m||(m=hr(E,p)),b||(b=g.createRange(),b.selectNode(a));let L=b.getClientRects()[0];return L?p?E.top+E.height>L.top+E.width||E.left>L.left+L.width-E.width/10||E.left+E.width<L.left+E.width/10:E.left+E.width>L.left+E.height||E.top+E.height<L.top+E.height/10||E.top>L.top+L.height-E.height/10:!1}let S=!1,F=!1,A=!1,D=!1,H;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(H="viv-ts-open",S=!0,F=!0):o&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(H="viv-ts-close",S=!0,A=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(H="viv-ts-close",S=!0,D=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(H="viv-ts-open",S=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||c==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||c!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(H="viv-ts-close",S=!0),S){let E=function(z){let $=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>$},L=function(){return p?P.offsetLeft:P.offsetTop};var q=E,Se=L;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(H),I=g.createElement("viv-ts-inner");P.appendChild(I),e.parentNode.insertBefore(P,e),I.appendChild(e);let O=E(I);if(O||F||A||D){if(H==="viv-ts-open"){if(F)P.className="viv-hang-first";else if(i||n)l.trimStart?P.className="viv-ts-trim":P.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&v())P.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||s.parentElement.localName==="viv-ts-inner"&&E(s.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&v()){let z=L();P.className="viv-ts-auto",z===L()&&!v()&&(P.className="viv-ts-trim")}}else if(H==="viv-ts-close"){if(A)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let z=L();D?(P.className=O?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===L()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",z===L()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",z===L()&&(P.className="")):P.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))O&&l.trimAdjacent&&(P.className="viv-ts-trim");else if(D){let z=C(),$=z&&u.allowEnd;$||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?$&&l.trimEnd?P.className="viv-ts-auto":!$&&!C()?P.className="":!z&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",C()||(P.className="viv-hang-end")):(P.className="viv-ts-space",C()||(l.allowEnd?(P.className="viv-ts-auto",C()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!z&&!C()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(C())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let z=L();P.className="viv-ts-auto",z===L()&&(P.className="")}}}}let se=!1;function k(E){var L;let P=(L=E?.ownerDocument.defaultView)==null?void 0:L.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function M(E,L){if(E.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(E);if(parseFloat(O.marginInlineEnd)||parseFloat(O.borderInlineEndWidth)||parseFloat(O.paddingInlineEnd))return!0}let P=E.parentElement;if(P&&!P.contains(L))return M(P,L);if(L.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(L);if(parseFloat(O.marginInlineStart)||parseFloat(O.borderInlineStartWidth)||parseFloat(O.paddingInlineStart))return!0}let I=L.parentElement;return I&&!I.contains(E)?M(E,I):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&k(s.parentElement))&&!M(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),se=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&k(a.parentElement))&&!M(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),se=!0)),m}registerHooks(){Nt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Nt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Nt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},dl=new Jy;dl.registerHooks();function Qy(e){dl.preprocessForTextSpacing(e)}function ev(e,t,i,n,r,o){dl.processGeneratedContent(e,t,i,n,r,o)}var Gn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),tv=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],pl="data-adapt-pseudo";function Xt(e){return e.getAttribute(pl)||""}function nr(e,t){e.setAttribute(pl,t)}var xs=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,d(this,"contentProcessed",{})}getStyle(e,t){let i=Xt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=pt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new V(new ze(o),0)}return r}processContent(e,t,i){let n=Xt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;St(r)&&(r.visit(new ur(e,this.context,r,this.exprContentListener)),Qy(e))}}},Ex=Eo.isInstanceOfAfterIfContinuesLayoutConstraint,iv=Qo.registerFragmentIndex,Px=Qo.clearFragmentIndices,nv=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new fl(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return N(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=Gn.createElementNS("http://www.w3.org/1999/xhtml","div");nr(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new Si(i)}createShadowContext(e){return new Zr(this.sourceNode,e,null,null,null,si.ShadowType.ROOTED,this.styler)}},rv=class Yd{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,d(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new ov(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Yd?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},ov=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function Zd(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return T(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=av(e,t,n);return t.fragmentLayoutConstraints.push(new rv(e,i,r)),T(e)})}function Kd(e,t){return e.thenAsync(i=>Zd(i,t))}function sv(e,t){let i=_("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Zd(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function av(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Xs(i,t,e.vertical);return n.removeChild(i),r}var lv=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},eo=class extends nl{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,d(this,"alreadyEvaluated",!1),d(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Oo=class extends dd{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,d(this,"last"),d(this,"viewDocument"),d(this,"flowRootFormattingContext",null),d(this,"isNonFirstColumn",!1),d(this,"isFloat",!1),d(this,"isFootnote",!1),d(this,"startEdge",0),d(this,"endEdge",0),d(this,"beforeEdge",0),d(this,"afterEdge",0),d(this,"footnoteEdge",0),d(this,"box",null),d(this,"chunkPositions",null),d(this,"bands",null),d(this,"overflown",!1),d(this,"breakPositions",null),d(this,"pageBreakType",null),d(this,"forceNonfitting",!0),d(this,"leftFloatEdge",0),d(this,"rightFloatEdge",0),d(this,"bottommostFloatTop",0),d(this,"stopAtOverflow",!0),d(this,"lastAfterPosition",null),d(this,"fragmentLayoutConstraints",[]),d(this,"pseudoParent",null),d(this,"nodeContextOverflowingDueToRepetitiveElements",null),d(this,"blockDistanceToBlockEndFloats",NaN),d(this,"lastLineStride",0),d(this,"breakAtTheEdgeBeforeFloat",null),ew(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}isOverflown(e){return this.almostEquals(e,this.footnoteEdge)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=_("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let o=r,s=i[n];if(r=No(s,o),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return T(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?ww(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,o=r.match(wo),s=o?o[0].length:0;if(!o&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(wo);if(h){let l=h[0];s=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(s)}}return this.layoutContext.peelOff(e,s)}return T(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=_("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!cn(e)&&((o=e.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let s=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(s);if(hr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,cn(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(vi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return Kd(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=_("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!cn(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(o=>{let s=o;if(s!==e){let a=s;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=s,r.breakLoop();return}cn(s)||t.push(s.copy())}this.nextInTree(s).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(vi(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),N(r,"height",`${i}px`),N(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),N(r,"width",`${i}px`),N(r,"height",`${n}px`)),N(r,"float",t),N(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null;for(let c of t)this.almostEquals(c.x1,i)?c.x1=i:this.almostEquals(c.x1,n)&&(c.x1=n),this.almostEquals(c.x2,n)?c.x2=n:this.almostEquals(c.x2,i)&&(c.x2=i),this.almostEquals(c.y1,r)?c.y1=r:this.almostEquals(c.y1,o)&&(c.y1=o),this.almostEquals(c.y2,o)?c.y2=o:this.almostEquals(c.y2,r)&&(c.y2=r);let a=1/(this.clientLayout.pixelRatio||1),h=Da==="webkit"?Math.floor:Math.round,l=t.map(c=>(h(c.y2/a)-h(c.y1/a))*a),u=.01;for(let c=0;c<t.length;c++){let p=c<t.length-1?t[c+1].x1:i,f=c<t.length-1?t[c+1].x2:n,g=p-t[c].x1,m=t[c].x2-f,w=0,x=0;g>u?w=1:g<-u&&(w=-1),m>u?x=1:m<-u&&(x=-1);let b=w!==0&&x!==0?w===x?w:0:w||x;if(b!==0){let v=b*a;l[c]+v>=0&&(c>=t.length-1||l[c+1]-v>=0)&&(l[c]+=v,c<t.length-1&&(l[c+1]-=v))}}for(let c=0;c<t.length;c++){let p=t[c];p.left=this.createFloat(e,"left",p.x1-i,l[c]),p.right=this.createFloat(e,"right",n-p.x2,l[c]),p.x1<n&&p.x2>i?s=p:s||N(p.right,"float","none")}if(s){let c=t[t.length-1];if(s!==c&&c.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let p=t.indexOf(s);p<t.length;p++){let f=t[p];this.element.removeChild(f.left),this.element.removeChild(f.right),f.left=null,f.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge);if(i>0&&i<t&&!this.almostEquals(i,t)){let n=this.vertical?"width":"height";if(N(this.element,n,`${i}px`),this.vertical){let r=this.left+(t-i);N(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&un(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=rn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=rn(e,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(o=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ds(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ds(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ds(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=_("layoutFloat"),i=e.viewNode,n=ws(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return N(i,"float","none"),N(i,"display","inline-block"),N(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Et(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new Pt(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let C=u.viewNode.ownerDocument.createElement("div");C.style.left="0px",C.style.top="0px",this.vertical?(C.style.bottom="0px",C.style.width="1px"):(C.style.right="0px",C.style.height="1px"),u.viewNode.appendChild(C);let S=Et(this.clientLayout,C,this.vertical);h=Math.max(this.rtl?this.getEndEdge(S):this.getStartEdge(S),h),l=Math.min(this.rtl?this.getStartEdge(S):this.getEndEdge(S),l),u.viewNode.removeChild(C);let F=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+F):h=Math.min(h,l-F),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let c=new Pt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=bo(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let C=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+C}if(e.clearSide){let C=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?ws(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,S=this.beforeEdge;C!=="right"&&(S=f*Math.max(S*f,this.leftFloatEdge*f)),C!=="left"&&(S=f*Math.max(S*f,this.rightFloatEdge*f));let F=S*f;if(p.y1<F){let A=p.y2-p.y1;p.y1=F,p.y2=p.y1+A}}c.y2+=1/(this.clientLayout.pixelRatio||1),Tg(c,this.bands,p,n),this.vertical&&(a=lc(p));let g=this.getComputedInsets(i);N(i,"width",`${a.x2-a.x1-g.left-g.right}px`),N(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),N(i,"position","absolute"),e.display,N(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let C=w.viewNode.ownerDocument.createElement("div");C.style.position="absolute",w.vertical?C.style.right="0":C.style.left="0",C.style.top="0",w.viewNode.appendChild(C),m=Et(this.clientLayout,C,this.vertical),w.viewNode.removeChild(C)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let C=Math.max(0,m.right-a.x2);N(i,"right",`${C}px`)}else{let C=Math.max(0,a.x1-m.left);N(i,"left",`${C}px`)}let x=Math.max(0,a.y1-m.top);N(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,v=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),c=new Pt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(c=bo(c)),Ig(c,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=v,this.updateMaxReachedAfterEdge(b),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!s.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!s.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!s.hasFloatFragments(),o);if(u){if(e.isFootnote){let c=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(c.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,N(e.element,"width",`${p}px`))}else{let p=parseFloat(c.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,N(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return T(u)})}createPageFloatArea(e,t,i,n,r){let o=this.element.ownerDocument.createElement("div");N(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new sn(null,Pe.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new cv(t,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>T(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,o,s){let a=this.pageFloatLayoutContext;e=(s?s.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},c=_("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(u.floatArea=p,!p){c.finish(u);return}let f=!1,g=0;c.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],x=new Si(w.nodePosition);p.layout(x,!0).then(b=>{u.newPosition=b,!b||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&u.newPosition){let m=a.getPageFloatLayoutContext(h.floatReference);if(m.footnoteMaxBlockSize==null){if(m.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,o,s).then(w=>{c.finish(w)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,o,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}c.finish(u)})}),c.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,o=e.float,s=new Set;for(let u=r;u;u=u.effectiveParent)for(let c of u.floatFragments)c.continuations.some(p=>p.float.insidePageFloatArea)&&s.add(c);r.stashEndFloatFragments(o);function a(u,c){c?r.removePageFloatFragment(c,!0):u&&u.element.parentNode.removeChild(u.element);let p=[];for(let f=r;f;f=f.effectiveParent)for(let g of f.floatFragments)!s.has(g)&&g.continuations.some(m=>m.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(e)}let h=o instanceof Io,l=_("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let c=u.floatArea,p=u.pageFloatFragment,f=u.newPosition;p?this.layoutStashedPageFloats(o.floatReference,[n]).then(g=>{if(g){let m=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,m),r.discardStashedFragments(o.floatReference),f){let w=new gh(o,f.primary);r.deferPageFloat(w)}l.finish(!0)}else a(c,p),l.finish(!1)}):(a(c,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=_("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let c=new Pn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,c,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!s)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Xt(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(kn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=_("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Pe.REGION);return r.getContainer().width<o.getContainer().width&&e===Pe.COLUMN?t===y.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=Qa(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Pe.REGION):n.finish(e)}):t===y.all?n.finish(Pe.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Pn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=Po(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new gh(o,s);if(h&&h.hasFloat(o))return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(t.isForbidden(o)||t.hasPrecedingFloatsDeferredToNext(o))return t.deferPageFloat(l),t.registerPageFloatAnchor(o,a.viewNode),T(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let u=rn(a,this.clientLayout,0,this.vertical);if(isNaN(u)&&e.floatSide==="footnote"){let c=a.viewNode;if(c&&c.nodeType===1){let p=Et(this.clientLayout,c,this.vertical);p.right>=p.left&&p.bottom>=p.top&&(u=this.vertical?p.left:p.bottom)}}return this.isOverflown(u)?T(a):this.layoutPageFloatInner(l,i,u,h).thenAsync(c=>c?e.floatSide==="footnote"||t.generatingNodePosition?T(a):T(null):(t.registerPageFloatAnchor(o,a.viewNode),T(a)))}})}processLineStyling(e,t,i){let n=_("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=e.firstPseudo;return s.count==0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(u,0).then(c=>{e=c,s=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Bi[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?t=Math.max(t,s):i=Math.min(i,s)}return t+i}layoutBreakableBlock(e){let t=_("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??e),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!un(n.viewNode)){let l=vn(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=T(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Ot("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,o=t[0].boxOffset,s=r,a=t.length-1,h=t[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let u=a;for(;s<u;){let p=s+Math.ceil((u-s)/2);t[p].boxOffset>l?u=p-1:s=p}let c=this.calculateEdge(null,t,s,l);if(this.vertical?c<=n:c>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(c),o=l,r=s}return{nodeContext:t[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(e,t,i){var n,r,o;let s=this.findEndOfLine(t,e,!0),a=s.nodeContext;if(s.checkPointIndex===0&&s.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,s.index,e,s.checkPointIndex,i)}else{let l=ch(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof eo&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(o=a.viewNode)==null?void 0:o.previousSibling;for(;u&&(Ve(u,a.parent.whitespace)||ci(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Ot("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Bo.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,o=e,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;o==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let c=o.nodeType===1?o:null;c?r?r=!1:Ja(c)?l=!a:!c.firstChild||Bi[c.localName]||/^r(uby|[bt]c?)$/.test(c.localName)||ow(this.clientLayout.getElementComputedStyle(c).display)?(l=!a,l?(c.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(c.localName)||(s=o),o.contains(t)&&(h=!1)):u=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),u||(u=o.nextSibling,u||(r=!0,u=o.parentNode)),o=u}while(l&&h);if(a){n.setEndAfter(s);let u=this.clientLayout.getRangeClientRects(n);Gs(u,this.vertical);for(let c=0;c<u.length;c++)i.push(u[c]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Pw:Ew);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(s>0){let c=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/c:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/c:u=1}if(s==0||u>=.6||u>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(t.push(r),s=0),a>=i.length)break}return t.sort(Nu),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&dn(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=vn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let s,a;t&&!this.isFootnote?(s=1,a=1):(s=Math.max((o.inheritedProps.widows||2)-0,1),a=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),l=this.findLinePositions(r),u=this.footnoteEdge-h,c=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=c*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=c*(1/0));let g=oi(l.length,b=>{let v=l[b];return this.vertical?v<u||v<=f.edge:v>u||v>=f.edge}),m=g<=0;m&&(g=oi(l.length,b=>this.vertical?l[b]<u:l[b]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(s=0,a=1),g=Math.min(l.length-s,g),g<a)return null;u=l[g-1];let x;if(m?x=f.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,u,t),x){let b=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(b)&&c*(u-b)>0&&(u=b),this.computedBlockSize=c*(u-this.beforeEdge)+p,l.length>=2){let v=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[v]-l[v-1])}}return x}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,rn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Dn().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=ol.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let o=e.getMinBreakPenalty();o>i&&(n=Math.min(n,o))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return T(e);let r=_("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return G.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();e=i,o=!0,this.computedBlockSize=n}return this.finishBreak(e,o,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(ci(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!Co(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||dn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");mt(n,"block-end"),t.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let s=e;s;s=s.parent)if(ci(s.viewNode))return!1;if(un(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=rn(e,this.clientLayout,0,this.vertical);i();let r=vn(e,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let s=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||un(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Pe.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=Et(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),o=this.getBoxDir(),s=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(s)?ws(s,e.vertical,e.direction,this.layoutContext.page.side):s,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=o*Math.max(l*o,this.leftFloatEdge*o);break;case"right":l=o*Math.max(l*o,this.rightFloatEdge*o);break;default:l=o*Math.max(l*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let c=1/(this.clientLayout.pixelRatio||1),p=l*o>u*o;l=o*(Math.ceil(l*o/c)+(p?1:0))*c;let f=c;if(r*o+f>l*o)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*o);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=Et(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(jw(e)||_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(uh(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return T(e);let o=_("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],c=[],p=!1;function f(C){var S,F;if(!(!t||s.isNonFirstColumn||i||!dh(h))){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakBefore)==="column"&&(D.style.breakBefore="")}}}function g(C){var S,F;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakBefore)==="column"&&(D.style.breakBefore="")}h=null}}function m(C){var S,F;if(!(i||!dh(h))){for(let A=C;A;A=A.parent)if(A.breakAfter==="column"&&(A.breakAfter=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let D=A.viewNode;((F=D.style)==null?void 0:F.breakAfter)==="column"&&(D.style.breakAfter="")}}}function w(C){h=tt(h,C)}function x(){return i?!0:Xe(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!b():!1}function b(){var C;if(!l||!e||e.floatSide)return!1;for(let S=l;S!=null&&S.parent;S=S.parent){if(S.parent.viewNode&&ci(S.parent.viewNode))continue;let F=S.after?S.viewNode:(C=S.viewNode)==null?void 0:C.previousSibling;for(;F&&(Ve(F,S.parent.whitespace)||ci(F));)F=F.previousSibling;if(F)return!1}return!0}let v=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var S;e;){e.formattingContext;let F=new Dn().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){x()?v():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=ko(h)?h:null),F&&F.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?ch(l):this.breakPositions[this.breakPositions.length-1]instanceof eo||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||_i.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ve(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),x()?v():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let D=e.viewNode,H=D.style;if(e.after){jc(D,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let q=e.sourceNode;if(q.localName==="svg"||q.localName==="math"||q.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),c.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||F&&F.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(uh(e.viewNode))break;if(x()){v(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,qc(e.viewNode)||(l=e.copy(),c.push(l)),w(e.breakAfter),m(e),H&&!ci(e.viewNode)&&this.hasNonZeroBlockEndInset(H)&&(c=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Xe(h)&&tw(l.viewNode,e.viewNode),(e.pageType!=((S=e.parent)==null?void 0:S.pageType)||!Xe(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let q=e.viewNode.localName;if(Bi[q]){x()?v():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}H&&this.hasNonZeroBlockStartInset(H)&&(a=!1,c=[]),p=!0}}while(!1);let A=this.nextInTree(e,a);if(A.isPending()){A.then(D=>{e=D,C.continueLoop()});return}else e=A.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,c,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Xe(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=_("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace))break;if(!e.after){Xe(n)&&(this.pageBreakType=n),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=tt(n,e.breakBefore),Xe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Xe(n)){this.pageBreakType=n,o.breakLoop();return}n=null}r=!1,n=tt(n,e.breakAfter)}else{n=tt(n,e.breakBefore);let h=e.viewNode.localName;if(Bi[h]){Xe(n)&&(this.pageBreakType=n),o.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){o.breakLoop();return}}r=!0}while(!1);let s=this.layoutContext.nextInTree(e);if(s.isPending()){s.then(a=>{e=a,o.continueLoop()});return}else e=s.get()}t=null,o.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(vi(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Pe.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=_("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let o=e.formattingContext;new Dn().find(o).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Dn().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new Pt(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Eg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],N(this.element,"width",`${this.width}px`),N(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Dn().find(e.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new eo(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);Ka(this);let n=_("layout");return this.openAllViews(e.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new hv(t,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=T(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(Co(this)&&(rw(this),Ko(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(N(this.element,"width",`${this.width}px`),N(this.element,"left",`${this.left}px`)):N(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new Si(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=_("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=_("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;e;){let s=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let s=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=s}this.killFloats(),this.init();let i=_("redoLayout"),n=0,r=null,o=!0;return i.loopWithFrame(s=>{if(n<e.length){let a=e[n++];this.layout(a,o).then(h=>{o=!1,h?(r=h,s.breakLoop()):s.continueLoop()});return}s.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(_i.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Eo.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}xi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},fl=class{constructor(e,t,i){d(this,"startNodeContexts",[]),d(this,"column"),d(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(o){return Oo.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),T(s)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Tr(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return Vi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let o=r.data.slice(e.offsetInNode);if(!od(o,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Ve(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Bo=class{breakTextNode(e,t,i,n,r,o){if(t.after)t.offsetInNode=e.length;else{let s=i-t.boxOffset,a=e.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(e,a,s,t):s=this.breakAfterOtherCharacter(e,a,s,t),s>0&&(t=this.updateNodeContext(t,s,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+Fh(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Ml(r)&&Ml(o)?Fh(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};d(Bo,"instance");Bo.instance=new Bo;function Fh(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var hv=class extends sl{constructor(e,t){super(),this.leadingEdge=e,d(this,"breakAfter"),d(this,"initialPageBreakType",null),d(this,"initialComputedBlockSize",0),d(this,"initialOverflown",!1),d(this,"initialLastLineStride",0),d(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new uv(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||qw()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Xc(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},uv=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=_("DefaultLayoutMode.doLayout");return sv(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},cv=class extends Oo{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),this.floatSide=e,this.parentContainer=s,d(this,"rootViewNodes",[]),d(this,"floatMargins",[]),d(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),T(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(o,s){o.forEach(a=>{let h=pi(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=s*l/100;N(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(o=>{pi(e,o)==="auto"&&N(e,o,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=pi(t,"height");n!==""&&n!=="auto"&&N(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=pi(t,"width");n!==""&&n!=="auto"&&N(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Et(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,c,p;let f=(l=h.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(h);if((f?.getPropertyValue("--viv-footnote-display").trim()||"")==="compact")return!(f?.display==="list-item"&&f.getPropertyValue("list-style-position").trim()==="outside");let g=h.getAttribute(jt);if(!g||!t||!i)return!1;let m=i.getNodeByOffset(parseInt(g,10));if(!m||m.nodeType!==Node.ELEMENT_NODE)return!1;let w=t.getStyle(m,!1),x=(c=(u=ge(w,"footnote-display"))==null?void 0:u.value)==null?void 0:c.toString(),b=!!((p=ge(w,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!b});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{N(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);N(l,"display","inline-block"),N(l,"position","absolute"),N(l,"visibility","hidden"),N(l,"white-space","nowrap"),N(l,"max-width","none"),N(l,"left","0"),N(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>o+s&&(N(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=Et(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(t=>Xt(t)==="after")}hasAuthorFootnoteAfterPseudo(e){let t=this.getFootnoteAfterPseudo(e);if(t&&!t.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let i=Array.from(e.children).find(r=>r instanceof Element&&yt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");nr(t,"after"),t.setAttribute("data-vivliostyle-default-footnote-separator","1"),t.style.whiteSpace="normal",t.textContent=" ",e.appendChild(t)}getFootnoteBreakOpportunity(e){let t=e.nextElementSibling;return t!=null&&t.hasAttribute("data-vivliostyle-footnote-break")?t:null}createFootnoteBreakOpportunity(e){let t=e.ownerDocument.createElement("wbr");t.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",t)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[t+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),u=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),c=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!c?this.createFootnoteBreakOpportunity(r):p&&c?.remove()}else u&&h.remove(),c?.remove()})}},Ui=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,d(this,"formattingContextType","RepetitiveElementsOwner"),d(this,"isRoot",!1),d(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||Qs.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new dv(e,this.rootSourceNode),Qs.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},dv=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,d(this,"headerSourceNode",null),d(this,"footerSourceNode",null),d(this,"headerViewNode",null),d(this,"footerViewNode",null),d(this,"headerNodePosition",null),d(this,"footerNodePosition",null),d(this,"headerHeight",0),d(this,"footerHeight",0),d(this,"isSkipHeader",!1),d(this,"isSkipFooter",!1),d(this,"enableSkippingFooter",!0),d(this,"enableSkippingHeader",!0),d(this,"doneInitialLayout",!1),d(this,"firstContentSourceNode",null),d(this,"lastContentSourceNode",null),d(this,"affectedNodeCache",[]),d(this,"afterLastContentNodeCache",[]),d(this,"allowInsert",!1),d(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Po(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Po(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Xs(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Xs(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,o=t.viewNode,s=r.createElement("div");o.appendChild(s);let a=new fl(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Si(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(s),this.moveChildren(s,o,i),a.getColumn().pageBreakType=h,T(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(kn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Jd=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},Qd=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},pv=class extends Jd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},fv=class extends Qd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new gl(e)),this.processor.doLayout(e,t)}},gl=class ep{constructor(t){d(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),d(this,"nodeContext");let i=ti(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||un(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!ip(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let o=this.getRepetitiveElements();o&&t&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=ti(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return vv(n,o,i).thenAsync(()=>bv(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ti(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof ep?ti(this.nodeContext.formattingContext)===ti(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},gv=class extends sl{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new pv(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new fv(this.formattingContext,this.processor))}},mv=class extends er{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),T(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),T(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return er.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?T(!0):er.prototype.afterNonInlineElementNode.call(this,e)}},wv=class extends pn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=ti(e.formattingContext);return n.getRootViewNode(e)?(i&&tp(e.parent,t),e.belongsTo(n)?pn.prototype.layout.call(this,e,t,i):new gv(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=xv(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=ti(e.formattingContext),n=_("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=ti(e.formattingContext),n=new mv(i,t);return new Js(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ti(e.formattingContext),n=_("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Kd(r,t).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(t.layoutNext(s,!1).then(l=>{s=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||s&&t.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(e,t,i,n){return pn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){pn.prototype.clearOverflownViewNodes(e,t,i,n)}};function yv(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Ui&&!i.belongsTo(n)&&t(n,i)}}function tp(e,t){e&&yv(e.after?e.parent:e,(i,n)=>{xi.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new gl(n))})}function vv(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let o=r.viewNode.firstChild;return n.appendHeaderToFragment(r,o,i)}}return T(!0)}function bv(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return T(!0)}function ip(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function xv(e){let t=e.formattingContext;return!t||!(t instanceof Ui)?null:t}function ti(e){return e instanceof Ui,e}var Sv=new wv;Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ui&&!xi.isInstanceOfTableFormattingContext(e)?Sv:null);var np=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,d(this,"cells",[]),d(this,"breakBefore",null),d(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Cv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,d(this,"viewElement"),d(this,"colSpan"),d(this,"rowSpan"),d(this,"height",0),d(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},kv=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Ev=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,d(this,"pseudoColumn"),d(this,"empty",!1),this.pseudoColumn=new fl(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&N(e,"vertical-align","top"),i&&i!=="normal"&&N(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return N(e,"vertical-align",t),i&&i!=="normal"&&N(e,"align-content",i),n}},Pv=class{constructor(e,t){this.viewNode=e,this.side=t}},Nv=class extends Tr{constructor(e,t,i,n){super(e,t,i,n),d(this,"formattingContext"),d(this,"acceptableCellBreakPositions",null),d(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Tv=class extends nl{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,d(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(o=>!!o.nodeContext)&&n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof eo&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof Tr&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},bn=class extends Ui{constructor(e,t){super(e,t),this.tableSourceNode=t,d(this,"formattingContextType","Table"),d(this,"vertical",!1),d(this,"columnCount",-1),d(this,"tableWidth",0),d(this,"captions",[]),d(this,"colGroups",null),d(this,"colWidths",null),d(this,"inlineBorderSpacing",0),d(this,"rows",[]),d(this,"slots",[]),d(this,"cellFragments",[]),d(this,"lastRowViewNode",null),d(this,"cellBreakPositions",[]),d(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){var i;if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0&&e.fragmentIndex<=1;case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new np(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),o=0;for(;r[o];)o++;for(;e<n;e++){r=this.getRowSlots(e);for(let s=o;s<o+t.colSpan;s++){let a=r[s]=new kv(e,s,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Et(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let o=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!o||t.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),t.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new Iv(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(_i.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}xi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Iv=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=vn(e,n);i=Math.max(i,t(r))}),i}};function Ft(e){return e instanceof bn,e}function Av(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Fv(e){return e==="table"||e==="inline-table"}function Rh(e){return Av(e)||Fv(e)}function rp(e,t,i){let n=e.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof bn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bn){s=a.formattingContext===t;break}}return s||r==="table-row"&&!Rh(o)||r==="table-cell"&&o!=="table-row"&&!Rh(o)||n.formattingContext instanceof bn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function op(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(vi(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var Rv=class extends er{constructor(e,t){super(),this.formattingContext=e,this.column=t,d(this,"rowIndex",-1),d(this,"columnIndex",0),d(this,"inRow",!1),d(this,"checkPoints",[]),d(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=rp(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=op(this.column,e);if(n)return n;let r=e.nodeContext,o=r.display,s=t.getRepetitiveElements();switch(o){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new Pv(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new np(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(o[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let o=t.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=tt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;t.addCell(this.rowIndex,new Cv(this.rowIndex,this.columnIndex,o)),this.columnIndex++;let s=t.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=tt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=tt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!cn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},sp=class ap extends er{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,d(this,"inRow",!1),d(this,"currentRowIndex",-1),d(this,"currentColumnIndex",0),d(this,"originalStopAtOverflow"),d(this,"inHeader"),d(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return op(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,o=t.columnIndex,s=t.colSpan,a=i.viewNode;s>1&&(N(a,"box-sizing","border-box"),N(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new Ev(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenReturn(!0)}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorSlot.columnIndex===t&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],o=r.cell,s=o.rowIndex;if(s<this.currentRowIndex&&s+o.rowSpan>this.currentRowIndex){let a=i[s];a||(a=i[s]=[]),a.push(r),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(c=>c+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=_("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,u=[];return n.forEach(c=>{h=h.thenAsync(()=>{let p=No(c[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let f=T(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");N(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return c.forEach(w=>{f=f.thenAsync(()=>{let x=w.cell;m(x.anchorSlot.columnIndex);let b=w.cellNodePosition,v=No(b.steps[0],p);return v.offsetInNode=b.offsetInNode,v.after=b.after,v.fragmentIndex=b.steps[0].fragmentIndex+1,o.setCurrent(v,!1).thenAsync(()=>{let C=w.breakChunkPosition;for(let S=0;S<x.colSpan;S++)u.push(g+S);return g+=x.colSpan,this.layoutCell(x,v,C).thenAsync(()=>(v.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,T(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,T(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=tt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=tt(o,s.breakBefore)),!t.leadingEdge&&Xe(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),t.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),T(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);iv(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,T(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let o=_("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=T(h.breakChunkPosition)}else s=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=Po(h,0);return T(new Si(l))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=rp(t,Ft(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):T(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new Tv(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):N(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):N(i.viewNode,"display","table-row-group")),r&&ap.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return T(!0)}};d(sp,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Lv=sp,pr=[];function Ov(e){let t=pr.findIndex(n=>n.root===e),i=pr[t];return i?i.tableLayoutOption:null}function Bv(e){let t=pr.findIndex(i=>i.root===e);t>=0&&pr.splice(t,1)}var lp=class{layoutEntireTable(e,t){let i=Ft(e.formattingContext),n=new Rv(i,t);return new Js(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<t;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=s.map(h=>{let l=Et(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(o),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),t.push(s)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let o=e.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),e.push(s)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=e.getColumnCount();if(!(s>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,t),l.forEach((u,c)=>{N(u,n?"height":"width",`${a[c]}px`)}),h.forEach(u=>{o.appendChild(u.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=Ft(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Ov(e.sourceNode);Bv(e.sourceNode);let r=_("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{let a=s.viewNode,h=Et(t.clientLayout,a,t.vertical),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*vn(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new zv(o)),r.finish(s);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&Xe(i.breakBefore)||t<e.rows.length-1&&Xe(i.breakAfter)))return!0}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,o)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),N(t,"table-layout","fixed"),N(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=Ft(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new Lv(i,t),s=new Js(o,t.layoutContext),a=_("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ft(e.formattingContext);return n.getRootViewNode(e)?(i&&tp(e.parent,t),new _v(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Nv(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ss(e),!1}finishBreak(e,t,i,n){let r=Ft(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=r.findRowIndexBySourceNode(t.sourceNode),s;if(t.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=_("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let u=s[h++],c=r.getCellFragmentOfCell(u),p=c.findAcceptableBreakPosition().nodeContext,f=c.cellNodeContext,g=f.toNodePosition(),m=new Si(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:u});let w=f.viewNode;c.column.layoutContext.processFragmentedBlockEdge(c.cellNodeContext),o<u.rowIndex+u.rowSpan-1&&(w.rowSpan=o-u.rowIndex+1),c.empty?l.continueLoop():c.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Mv(c,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ss(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Ss(t),r.finishFragment(),ol.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){pn.prototype.clearOverflownViewNodes(e,t,i,n)}};function Mv(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,o=e.column,s=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=Et(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let u=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;N(s,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;N(s,"max-height",`${u}px`)}}function Ss(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((c,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return c+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((c,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(c,f):c},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let c=a;c&&c!==t.lastElementChild;c=c.nextElementSibling)if(c.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=c;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;N(a,e.vertical?"width":"height",`${u}px`)}var _v=class extends sl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Dv(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Uv(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},Dv=class extends Jd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},zv=class extends Tr{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new Vv(this.position.sourceNode))}},Vv=class hp{constructor(t){this.tableRootNode=t,d(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,pr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof hp&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Uv=class extends Qd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Hv(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Hv=class up extends gl{constructor(t){super(t),d(this,"flagmentLayoutConstraintType","TableRow"),d(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||un(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!ip(t,i,r):!0}nextCandidate(t){let i=Ft(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let o=Ft(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(t,s.breakPosition,n,r)})}),!t){let s=o.getRootViewNode(this.nodeContext);new lp().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ft(this.nodeContext.formattingContext),r=_("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return T(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=Ft(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof up?Ft(this.nodeContext.formattingContext)===Ft(t.nodeContext.formattingContext):!1}},$v=new lp;function Wv(e,t,i,n,r,o){if(!t)return null;if(i===y.table){let s=e.parent;return new bn(s?s.formattingContext:null,e.sourceNode)}return null}function Gv(e){return e instanceof bn?$v:null}Nt("RESOLVE_FORMATTING_CONTEXT",Wv);Nt("RESOLVE_LAYOUT_PROCESSOR",Gv);function Lh(e){return e.reduce((t,i)=>t+i,0)/e.length}function jv(e){let t=Lh(e);return Lh(e.map(i=>{let n=i-t;return n*n}))}var Xv=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function fr(e){return e.vertical?e.width:e.height}function gr(e,t){e.vertical?e.width=t:e.height=t}var cp=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,d(this,"originalContainerBlockSize"),this.originalContainerBlockSize=fr(e)}balanceColumns(e){let t=_("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new Xv(e,t)}preBalance(e){}postBalance(){gr(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let o=r+n-t;N(i.element,"width",`${t}px`),N(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(N(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},da=1;function dp(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+da}function pp(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+da))-da;n<fr(t)?gr(t,n):gr(t,fr(t)-1)}var qv=class extends cp{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,d(this,"originalPosition",null),d(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);gr(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return Oh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return dp(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Oh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):fr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)pp(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,fr(this.layoutContainer)+this.originalContainerBlockSize*.1);gr(this.layoutContainer,t)}}};function Oh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>t>o.computedBlockSize+r)}var Yv=class extends cp{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return jv(t)}hasNextCandidate(e){return dp(e)}updateCondition(e){pp(e,this.layoutContainer)}};function Zv(e,t,i,n,r,o,s){if(t===y.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new qv(i,n,r,e):t===y.balance_all?new Yv(i,n,r):(y.balance,null)}}var Kv=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Jv=new Set(Kv);function Qv(e){return!(e.toLowerCase()==="none"||Jv.has(e))}var eb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],tb=new Set(eb),ib=["fixed","extends"],nb=new Set(ib),Nx=Symbol();function Ir(e){return e instanceof ce&&e.name.toLowerCase()!=="none"}function fp(e){return e.name}function rb(e){if(e instanceof ce)return tb.has(e.name);if(e instanceof ee&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof ce){let n=t.name;return nb.has(n)&&(n==="fixed"&&i instanceof ze||n==="extends"&&Ir(i))}}return!1}function ob(e){let t=lt(e,"system");return t instanceof ce&&t.name==="cyclic"}function sb(e){let t=lt(e,"system");if(t instanceof ce&&t.name==="fixed")return!0;if(t instanceof ee&&t.values.length===2){let[i,n]=t.values;return i instanceof ce&&i.name==="fixed"&&n instanceof ze}return!1}function ab(e){let t=lt(e,"system");return t instanceof ce?1:t.values[1].num}function lb(e){let t=lt(e,"system");return t instanceof ce&&t.name==="alphabetic"}function hb(e){let t=lt(e,"system");return t instanceof ce&&t.name==="numeric"}function ub(e){let t=lt(e,"system");return t instanceof ce&&t.name==="additive"}function cb(e){let t=lt(e,"system");if(t instanceof ee&&t.values.length===2){let[i,n]=t.values;return i instanceof ce&&i.name==="extends"&&Ir(n)}return!1}function db(e){let t=lt(e,"system");return fp(t.values[1])}function Bt(e){return e instanceof X||e instanceof ce}function ni(e){return e instanceof X?e.str:e.name}function gp(e){if(Bt(e))return!0;if(e instanceof ee&&e.values.length===2){let t=e.values[0],i=e.values[1];return Bt(t)&&Bt(i)}return!1}function pb(e){if(Bt(e))return{prefix:ni(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:ni(t),suffix:ni(i)}}}function Bh(e){return e instanceof ze||e instanceof ce&&e.name==="infinite"}function Mo(e,t){return e instanceof ze?e.num:t?-1/0:1/0}var Tx=Symbol();function pa(e){if(!(e instanceof ee&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Bh(t)&&Bh(i)))return!1;let n=Mo(t,!0),r=Mo(i,!1);return!(n>r)}function fb(e){return{lower:Mo(e.values[0],!0),upper:Mo(e.values[1],!1)}}function mp(e){return e instanceof ce&&e.name==="auto"||pa(e)||e instanceof it&&e.values.length>=1&&e.values.every(t=>pa(t))}function gb(e){return e instanceof ce?null:(pa(e)?[e]:e.values).map(t=>fb(t))}var Ix=Symbol();function _o(e){if(!(e instanceof ee&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof ze&&t.num>=0&&Bt(i)||Bt(t)&&i instanceof ze&&i.num>=0}function Do(e){let[t,i]=e.values;return t instanceof ze?[t.num,ni(i)]:[i.num,ni(t)]}function wp(e){return _o(e)}function mb(e){let[t,i]=Do(e);return{minLength:t,symbol:i}}function yp(e){return Bt(e)||e instanceof ee&&e.values.length>=1&&e.values.every(t=>Bt(t))}function wb(e){return Bt(e)?[ni(e)]:e.values.map(t=>ni(t))}var Ax=Symbol();function vp(e){if(_o(e))return!0;if(e instanceof it&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!_o(i))return!1;let[n]=Do(i);if(n>=t)return!1;t=n}return!0}return!1}function yb(e){if(_o(e)){let[t,i]=Do(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Do(t);return{weight:i,symbol:n}})}var vb=["auto","bullets","numbers","words","spell-out"],bb=new Set(vb);function xb(e){return e instanceof ce&&bb.has(e.name)||Ir(e)}function Sb(e,t){switch(e){case"system":return rb(t);case"negative":return gp(t);case"prefix":case"suffix":return Bt(t);case"range":return mp(t);case"pad":return wp(t);case"fallback":return Ir(t);case"symbols":return yp(t);case"additive-symbols":return vp(t);case"speak-as":return xb(t);default:return!0}}function lt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function Cb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Tn(e){let t=e.get("decimal");return t||(t=ue.createDecimal(e),e.set("decimal",t)),t}var to,io,no,ro,oo,so,ao,lo,fa,ga,ma,wa,ya,va,ba,ct,Cs,bp,xp,Mh,_h,ks,Dh,jn,ui=class Ri{constructor(t,i){ne(this,ct),d(this,"_store"),ne(this,to),ne(this,io),ne(this,no),ne(this,ro),ne(this,oo),ne(this,so),ne(this,ao),ne(this,lo),this._store=t;let n=lt(i,"negative");De(this,to,n&&gp(n)?pb(n):null);let r=lt(i,"prefix");De(this,io,r&&Bt(r)?ni(r):null);let o=lt(i,"suffix");De(this,no,o&&Bt(o)?ni(o):null);let s=lt(i,"range");De(this,ro,s&&mp(s)?gb(s):null);let a=lt(i,"pad");De(this,oo,a&&wp(a)?mb(a):null);let h=lt(i,"fallback");De(this,so,h&&Ir(h)?fp(h):null);let l=lt(i,"symbols");De(this,ao,l&&yp(l)?wb(l):null);let u=lt(i,"additive-symbols");De(this,lo,u&&vp(u)?yb(u):null)}static create(t,i){return ob(i)?new Ni(t,i):sb(i)?new kb(t,i):lb(i)?new Pb(t,i):hb(i)?new zh(t,i):ub(i)?new Nb(t,i):cb(i)?new Tb(t,i):new Eb(t,i)}static createDecimal(t){return new zh(t,U(Ri,fa))}static createDisc(t){return new Ni(t,U(Ri,ga))}static createSquare(t){return new Ni(t,U(Ri,ma))}static createCircle(t){return new Ni(t,U(Ri,wa))}static createDisclosureOpen(t){return new Ni(t,U(Ri,ya))}static createDisclosureClosed(t){return new Ni(t,U(this,va))}static createNone(t){return new Ni(t,U(Ri,ba))}static get CHINESE_LONGHAND_NAMES(){return Vh.NAMES}static createChineseLonghand(t,i){return new Vh(t,i)}static createEthiopicNumeric(t){return new Ab(t)}_getNegative(){return U(this,to)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return U(this,io)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return U(this,no)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return U(this,ro)}static _getRangeFrom(t){return t._getRange()}_getPad(){return U(this,oo)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(U(this,so)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return U(this,ao)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return U(this,lo)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Ee(this,ct,jn).call(this,t,new Set)}formatMarker(t){return Ee(this,ct,bp).call(this)+this.format(t)+Ee(this,ct,xp).call(this)}};to=new WeakMap,io=new WeakMap,no=new WeakMap,ro=new WeakMap,oo=new WeakMap,so=new WeakMap,ao=new WeakMap,lo=new WeakMap,fa=new WeakMap,ga=new WeakMap,ma=new WeakMap,wa=new WeakMap,ya=new WeakMap,va=new WeakMap,ba=new WeakMap,ct=new WeakSet,Cs=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},bp=function(){var e;return(e=this._getPrefix())!=null?e:""},xp=function(){var e;return(e=this._getSuffix())!=null?e:". "},Mh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},_h=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},ks=function(){var e;return(e=this._getFallback())!=null?e:Tn(this._store)},Dh=function(e,t){let{minLength:i,symbol:n}=Ee(this,ct,_h).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=Ee(this,ct,Cs).call(this),s=t?[...r].length+(o?[...o].length:0):0,a=i-[...e].length-s;if(a<=0)return e;let h=[...n].length,l=Math.ceil(a/h);return n.repeat(l)+e},jn=function(e,t){var i,n,r;if(t.has(this))return Ee(i=Tn(this._store),ct,jn).call(i,e,new Set);if(t.add(this),!Cb(e,Ee(this,ct,Mh).call(this))){let l=Ee(this,ct,ks).call(this);return Ee(n=l,ct,jn).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=Ee(this,ct,ks).call(this);return Ee(r=l,ct,jn).call(r,e,t)}let h=Ee(this,ct,Dh).call(this,a,o);if(o){let{prefix:l,suffix:u}=Ee(this,ct,Cs).call(this);h=l+h+(u??"")}return h},ne(ui,fa,{system:new V(B("numeric"),0),symbols:new V(new ee([new X("0"),new X("1"),new X("2"),new X("3"),new X("4"),new X("5"),new X("6"),new X("7"),new X("8"),new X("9")]),0)}),ne(ui,ga,{system:new V(B("cyclic"),0),symbols:new V(new X("\u2022"),0),suffix:new V(new X(" "),0)}),ne(ui,ma,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25AA"),0),suffix:new V(new X(" "),0)}),ne(ui,wa,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25E6"),0),suffix:new V(new X(" "),0)}),ne(ui,ya,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25BE"),0),suffix:new V(new X(" "),0)}),ne(ui,va,{system:new V(B("cyclic"),0),symbols:new V(new X("\u25B8"),0),suffix:new V(new X(" "),0)}),ne(ui,ba,{system:new V(B("cyclic"),0),symbols:new V(new X(""),0),suffix:new V(new X(""),0)});var ue=ui,Ni=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},ho,kb=class extends ue{constructor(e,t){super(e,t),ne(this,ho),De(this,ho,ab(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-U(this,ho);return(t=i[n])!=null?t:null}};ho=new WeakMap;var Eb=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Pb=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},zh=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},Nb=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(o=>o.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},rr,wt,kt,Sp=class extends ue{constructor(t,i){super(t,i),ne(this,wt),ne(this,rr);let n=db(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?De(this,rr,r):De(this,rr,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ue._getNegativeFrom(Ee(this,wt,kt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ue._getPrefixFrom(Ee(this,wt,kt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ue._getSuffixFrom(Ee(this,wt,kt).call(this))}_getAutoRange(){return ue._getAutoRangeFrom(Ee(this,wt,kt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ue._getRangeFrom(Ee(this,wt,kt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ue._getPadFrom(Ee(this,wt,kt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ue._getFallbackFrom(Ee(this,wt,kt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ue._getSymbolsFrom(Ee(this,wt,kt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ue._getAdditiveSymbolsFrom(Ee(this,wt,kt).call(this))}_usesNegativeSign(t){return ue._useNegativeSignFrom(Ee(this,wt,kt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ue._generateInitialRepresentationFrom(Ee(this,wt,kt).call(this),t)}};rr=new WeakMap,wt=new WeakSet,kt=function(e=new Set){var t;if(e.has(this))return Tn(this._store);e.add(this);let i=this._store.get(U(this,rr));return i?i instanceof Sp?Ee(t=i,wt,kt).call(t,e):i:Tn(this._store)};var Tb=Sp,Ib=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Es,Ps,$r,Ns,xa,uo,It=class Cp extends ue{constructor(t,i){let{chars:n,descriptors:r}=U(Cp,xa).get(i);super(t,r),ne(this,uo),De(this,uo,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=U(this,uo);if(t===0)return i.digits[0];let n=[],r=0,o=t;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:c}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&c===1?a+=i.markers[c]:(a+=i.digits[u],c>0&&(a+=i.markers[c])))}return a}};Es=new WeakMap,Ps=new WeakMap,$r=new WeakMap,Ns=new WeakMap,xa=new WeakMap,uo=new WeakMap,ne(It,Es,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ne(It,Ps,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8D1F"),0)}}),ne(It,$r,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),ne(It,Ns,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new X("\u3001"),0),fallback:new V(B("cjk-decimal"),0),range:new V(new ee([new ze(-9999),new ze(9999)]),0),negative:new V(new X("\u8CA0"),0)}}),d(It,"NAMES",new Set(Ib)),ne(It,xa,new Map([["simp-chinese-informal",U(It,Es)],["simp-chinese-formal",U(It,Ps)],["trad-chinese-informal",U(It,$r)],["trad-chinese-formal",U(It,Ns)],["cjk-ideographic",U(It,$r)]]));var Vh=It,Sa,Ca,zo,ka,Ea,an=class Li extends ue{constructor(t){super(t,U(Li,Sa))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return U(Li,zo)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),c=a%10;o+=U(Li,Ca)[u]+U(Li,zo)[c]}h?a!==0&&(o+=U(Li,ka)):s!==0&&(o+=U(Li,Ea))}return o}};Sa=new WeakMap,Ca=new WeakMap,zo=new WeakMap,ka=new WeakMap,Ea=new WeakMap,ne(an,Sa,{range:new V(new ee([new ze(1),B("infinite")]),0),suffix:new V(new X("/ "),0)}),ne(an,Ca,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ne(an,zo,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ne(an,ka,"\u137B"),ne(an,Ea,"\u137C");var Ab=an,Ie,Fb=class{constructor(){ne(this,Ie),De(this,Ie,new Map),U(this,Ie).set("none",ue.createNone(U(this,Ie))),U(this,Ie).set("decimal",ue.createDecimal(U(this,Ie))),U(this,Ie).set("disc",ue.createDisc(U(this,Ie))),U(this,Ie).set("square",ue.createSquare(U(this,Ie))),U(this,Ie).set("circle",ue.createCircle(U(this,Ie))),U(this,Ie).set("disclosure-open",ue.createDisclosureOpen(U(this,Ie))),U(this,Ie).set("disclosure-closed",ue.createDisclosureClosed(U(this,Ie)));for(let e of ue.CHINESE_LONGHAND_NAMES)U(this,Ie).set(e,ue.createChineseLonghand(U(this,Ie),e));U(this,Ie).set("ethiopic-numeric",ue.createEthiopicNumeric(U(this,Ie)))}define(e,t){if(!Qv(e))return null;let i=ue.create(U(this,Ie),t);return U(this,Ie).set(e,i),i}getStyle(e){var t;return(t=U(this,Ie).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Tn(U(this,Ie))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Tn(U(this,Ie))).formatMarker(t)}};Ie=new WeakMap;var Ts=class{constructor(e,t,i){d(this,"endStuckFixed"),d(this,"endFixed"),d(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Rb=class{constructor(){d(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new Ts(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new Ts(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Ts(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=oi(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=oi(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function Lb(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Ob=class Pa{constructor(t,i,n,r,o,s,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=o,this.atBlockStart=s,this.atFlowStart=a,this.isParentBoxDisplayed=h,d(this,"flowName"),d(this,"isBlockValue",null),d(this,"hasBoxValue",null),d(this,"styleValues",{}),d(this,"beforeBox",null),d(this,"afterBox",null),d(this,"breakBefore",null),this.flowName=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new Pa(t,l.before,n,!1,o,this.isBlock(),a,!0),c=u.styleValue("content");St(c)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=tt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Xe(this.breakBefore)&&(o.breakBefore=tt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new Pa(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");St(s)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=$c(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!So(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Bb=class{constructor(e){this.context=e,d(this,"stack",[]),d(this,"atBlockStart",!0),d(this,"atFlowStart",!0),d(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==y.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new Ob(this.context,e,t,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",y.normal).toString(),n=rd(i);n&&!Ve(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=tt(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},Uh=class{constructor(e,t,i,n,r,o,s,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=o,this.counterListener=s,d(this,"root"),d(this,"cascadeHolder"),d(this,"last"),d(this,"rootStyle",{}),d(this,"styleMap",{}),d(this,"counterSnapshots",[]),d(this,"flows",{}),d(this,"flowChunks",[]),d(this,"flowListener",null),d(this,"flowToReach",null),d(this,"idToReach",null),d(this,"cascade"),d(this,"offsetMap"),d(this,"primary",!0),d(this,"primaryStack",[]),d(this,"rootBackgroundAssigned",!1),d(this,"rootLayoutAssigned",!1),d(this,"lastOffset"),d(this,"breakBeforeValues",{}),d(this,"boxStack"),d(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,s,a,e.lang,h,l),this.offsetMap=new Rb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Bb(n),this.offsetMap.addStuckRange(u);let c=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,c,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(c,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=c,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new V(r,Mc))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)fn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!Z(n)||r&&!Z(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Hh.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Hh[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Z(n.value)){let a=n.evaluate(this.context);if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*zt.lh/zt.em;break;default:{let l=zt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,s=e["line-height"];if(s&&!Z(s.value)){let a=s.evaluate(this.context);if(a instanceof xt)this.context.rootLineHeight=a.num*o;else if(a instanceof R){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=zt[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return qy(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Lb(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=oi(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,u=l&&!Z(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let s=ge(o,"flow-into"),a=s?s.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=Fg(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=ih(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let c=t["flow-priority"];c&&(r=ih(c.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Cw(e,m)}let g=new kw(e,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Xe(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=tt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;;){let o=this.last.firstChild;if(o==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let s=this.boxStack.pop(this.lastOffset),a=null;if(s.afterBox){let h=s.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,s.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(s):s.afterBox.offset,s.flowName),a=s.afterBox.getBreakValue("after")}a=tt(a,s.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,s.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let s=this.last,a=this.getAttrStyle(s);this.primaryStack.push(this.primary),this.cascade.pushElement(this,s,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=s.getAttribute("id")||s.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&s.localName=="body"&&s.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,s,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,s===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,s===this.root),s===this.xmldoc.body&&(l.breakBefore=tt(l.flowChunk.breakBefore,l.breakBefore));let c=this.boxStack.nearestBlockStartOffset(l);if(c===0||s===this.xmldoc.body){let p=a.page,f=p&&!Z(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,c,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?c:l.offset,l.flowName)}if(this.primary&&l.displayValue()===y.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&c===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Hh=["column-count","column-width","column-fill"],gn=class{constructor(e){this.validator=e,d(this,"success",null),d(this,"failure",null),d(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Ti=class{constructor(e,t){this.where=e,this.success=t,d(this,"what",-1)}},Vn=class kp{constructor(){d(this,"nodes",[]),d(this,"connections",[]),d(this,"match",[]),d(this,"nomatch",[]),d(this,"error",[]),d(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new kp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new gn(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Ti(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,o=new gn($h);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,r);let s=new Ti(r,!0),a=new Ti(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(s)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new gn($h);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ti(0,!0),r=new Ti(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new gn(t));let n=new Ti(i,!0),r=new Ti(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof Ue}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<t.connections.length;o++){let s=t.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+r);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+r);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Mb=1,Ep=2,Pp=4,Oi=8,co=16,Na=32,po=64,Np=128,Xn=256,qn=512,Ta=1024,Tp=2048,Ip=4096,Ap=8192,Fp=class extends li{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Ue=class Rp extends Fp{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Mb?t:null}visitSlash(t){return this.allowed&Tp?t:null}visitStr(t){return this.allowed&Ep?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Pp||this.allowed&po&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&qn)?t.unit=="%"&&this.allowed&Ta?t:null:t.num<0&&!(this.allowed&Xn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&qn?t:null:t.num<=0&&!(this.allowed&Xn)?null:this.allowed&co?t:null}visitInt(t){return t.num==0?this.allowed&qn?t:null:t.num<=0&&!(this.allowed&Xn)?null:this.allowed&(Na|co)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&po&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Np?t:null}visitURange(t){return this.allowed&Ip?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&po){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&tc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Ap){let i=t.visit(new rc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Oi|co|Na|Xn|qn|Ta)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Rp(this.allowed|t.allowed,i,n)}},ae=Object.create(null),$h=new Ue(0,ae,ae),ml=class extends Fp{constructor(e){super(),d(this,"successTerminal"),d(this,"failureTerminal"),d(this,"first"),this.successTerminal=new gn(null),this.failureTerminal=new gn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=e.length){r=r.failure;continue}let h=e[o],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(o==0&&!t&&r.validator instanceof or&&this instanceof or){if(l=new ee(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof wl&&this instanceof or){if(l=new it(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<o;u++)n[u]=e[u]}e!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:o==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},or=class extends ml{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ee(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof wl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new it(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},wl=class extends ml{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new it(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},_b=class extends ml{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new $i(e.name,t):null}},Lp=class{tryParse(e,t,i){return t}success(e,t){}},Op=class extends Lp{constructor(e,t){super(),this.name=t,d(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,o=r>1?new ee(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},Db=class extends Op{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},zb=class extends Lp{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Fn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let o=1;o<this.nodes.length&&t<e.length&&(r=this.nodes[o].tryParse(e,t,i),r!=t);o++)t=r;return t}},yl=class extends li{constructor(){super(...arguments),d(this,"syntax",null),d(this,"propList",null),d(this,"error",!1),d(this,"values",{}),d(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Op(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},On=class extends yl{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},Bp=class extends yl{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new Db(this.validatorSet,this.propList)}},Vb=class extends yl{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Fn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let o=[e[n],e[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},Ub=class extends On{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let o=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,s=e[r];s||(s=[],e[r]=s),s.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof it?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new it(t[i]);return null}},Hb=class extends On{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===Fn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new ee(e.slice(t,e.length));return o.visit(r["font-family"])?(this.values["font-family"]=o,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new it(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},$b=class extends On{validateList(e){if(e.length===1&&e[0]instanceof ce)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[y.auto,y.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},Wb=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Gb=class extends On{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Wb.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Wh={SIMPLE:On,INSETS:Bp,INSETS_SLASH:Vb,COMMA:Ub,FONT:Hb,TEXT_SPACING:$b,ALL:Gb},jb=["initial-letter"],Xb=class{constructor(){d(this,"validators",{}),d(this,"prefixes",{}),d(this,"defaultValues",{}),d(this,"namedValidators",{}),d(this,"systemFonts",{}),d(this,"shorthands",{}),d(this,"layoutProps",{}),d(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new R(t.num,t.text);else if(t.type==7)i=new Yu(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Vn;if(e=="||"){for(let r=0;r<t.length;r++){let o=new Vn;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new Vn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Vn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Vn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new wl(t);break;case"SPACE":i=new or(t);break;default:i=new _b(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Ue(po,ae,ae)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Ue(Ap,ae,ae)),this.namedValidators.POS_INT=this.primitive(new Ue(Na,ae,ae)),this.namedValidators.POS_NUM=this.primitive(new Ue(co,ae,ae)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Ue(Oi,ae,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new Ue(Xn,ae,ae)),this.namedValidators.ZERO=this.primitive(new Ue(qn,ae,ae)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Ue(Ta,ae,ae)),this.namedValidators.POS_LENGTH=this.primitive(new Ue(Oi,ae,{em:Y,ex:Y,ch:Y,rem:Y,lh:Y,rlh:Y,vw:Y,vh:Y,vi:Y,vb:Y,vmin:Y,vmax:Y,pvw:Y,pvh:Y,pvi:Y,pvb:Y,pvmin:Y,pvmax:Y,cm:Y,mm:Y,in:Y,px:Y,pt:Y,pc:Y,q:Y})),this.namedValidators.POS_ANGLE=this.primitive(new Ue(Oi,ae,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new Ue(Oi,ae,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new Ue(Oi,ae,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new Ue(Oi,ae,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new Ue(Np,ae,ae)),this.namedValidators.URANGE=this.primitive(new Ue(Ip,ae,ae)),this.namedValidators.IDENT=this.primitive(new Ue(Pp,ae,ae)),this.namedValidators.STRING=this.primitive(new Ue(Ep,ae,ae)),this.namedValidators.SLASH=this.primitive(new Ue(Tp,ae,ae));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(s)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,s=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(s||h(" "),this.isBuiltIn(u.text)){let c=this.namedValidators[u.text];if(!c)throw new Error(`'${u.text}' unexpected`);i.push(c.clone())}else{let c={};c[u.text.toLowerCase()]=B(u.text),i.push(this.primitive(new Ue(0,c,ae)))}s=!1;break;case 5:{let c={};c[`${u.num}`]=new ze(u.num),i.push(this.primitive(new Ue(0,c,ae))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],s=!0;break;case 15:{o=a();let c=n.pop();if(c.b!="[")throw new Error("']' unexpected");i=c.vals,i.push(o),r=c.op,s=!1;break}case 11:{o=a();let c=n.pop();if(c.b!="(")throw new Error("')' unexpected");i=c.vals,i.push(this.newFunc(c.fn,o)),r=c.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let c=u.num,p=c;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),c,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new or(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(B(n.text));break;case 4:i.push(new xt(n.num));break;case 5:i.push(new ze(n.num));break;case 3:i.push(new R(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new ee(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Wh[i.text]?(n=new Wh[i.text],e.consume()):n=new On,n.setOwner(this);let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])o.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Bp){let l=this.shorthands[i.text];o.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let l=new zb(o,s),u=a.pop();o=u.syntax,s=u.slash,o.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n}}parse(e){let t=new Vt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(t=this.defaultValues[s])!=null?t:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(Zt(e)||r==="font-face"||Yb(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Sb(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let o="",s=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(o=a[1],e=a[2]);let h=this.prefixes[e];if(!h||!h[o]){CSS.supports(s,t.toString())?n.simpleProperty(s,t,i):o&&!ku.includes(`-${o}-`)||n.unknownProperty(s,t);return}else if(jb.includes(e)&&!Object.keys(h).some(u=>Xr(u?`-${u}-`:"",e))){n.unknownProperty(s,t);return}let l=this.validators[e];if(l){let u=Z(t)||t.isExpr()?t:t.visit(l);u?n.simpleProperty(e,u,i):!o&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(s,t)}else{let u=this.shorthands[e].clone();Z(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(s,t))}}};function Mp(){let e=new Xb;return e.initBuiltInValidators(),e.parse(Tc),e}var qb=class extends li{constructor(){super(...arguments),d(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function Yb(e){let t=new qb;return e.visit(t),t.varFound}var Rx=`OTTO${new Date().valueOf()}`;function vl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Zb(e){let t=new ri;for(let i of vl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Kb(e,t){let i={};for(let n in e)i[n]=ge(e,n).evaluate(t,n);return i}var _p=class{constructor(e){this.properties=e,d(this,"fontTraitKey"),d(this,"src"),d(this,"blobURLs",[]),d(this,"blobs",[]),d(this,"family"),this.fontTraitKey=Zb(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new ri;i.append(`@font-face {
1866
+ }`;function ks(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=wd([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 wd(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Lw(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 Ow(e){return URL.createObjectURL(e)}var xl=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(cd)}`),ks(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 Bw(e,t){let i=e.responseText;return T(i?cl(i):null)}function Mw(){return new xl(Bw,"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 Vh=0,_w=16777216,yd=33554432,vd=50331648,bd=67108864,Dw=83886080,zw=100663296,Es=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 Vh;case"User":return zw;default:return Dw}}getBaseSpecificity(){switch(this.flavor){case"UA":return Vh;case"User":return _w;default:return yd}}},ka=class extends Es{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)}},Uh=class extends Es{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 Uh{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Uh(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},$e=[],Xo=[],Ce=[],_e=[],Mt=[],at=[],Ue=[],Ze=[],Se=[],Qe=[],ct=[],Ge=[],Ve=[],cn=55,dn=56,eo=57;$e[1]=28,$e[36]=29,$e[7]=29,$e[9]=29,$e[14]=29,$e[18]=29,$e[50]=29,$e[20]=30,$e[13]=27,$e[0]=200,Xo[1]=46,Xo[0]=200,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 Kg(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(),da(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new vh(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==-eo)r=new Yg(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 gl(n.getScope(),o,r);break;case cn:r=new Zg(n.getScope(),o,r);break;case dn:r=new Jg(n.getScope(),o,r);break;case 25:r=new ml(n.getScope(),o,r);break;case 38:r=new Qg(n.getScope(),o,r);break;case 37:r=new tm(n.getScope(),o,r);break;case 48:r=new em(n.getScope(),o,r);break;case 47:r=new fa(n.getScope(),o,r);break;case 39:case 49:r=new wl(n.getScope(),o,r);break;case 41:r=new im(n.getScope(),o,r);break;case 23:r=new bc(n.getScope(),o,r);break;case 24:r=new xc(n.getScope(),o,r);break;case 36:r=new yl(n.getScope(),o,r);break;case 19:r=new Sc(n.getScope(),o,r);break;case 21:r=new Cc(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new om(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new vh(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 sm(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 Rc(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 Lc(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?Xo:$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(),da(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 yh(s.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new yh(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(-eo),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 Nc(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]!==-eo?(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]!==-eo?(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}},xd=class extends Es{constructor(e){super(null),this.scope=e}error(e,t){j.warn(e,t.toString())}getScope(){return this.scope}};function Vw(e,t,i,n,r){let o=Sd(t),s=Vm(e.input);return s!==e.input?$h(new vt(s,o),o,i,n,r):$h(e,o,i,n,r)}function $h(e,t,i,n,r){let o=D("parseStylesheet"),s=new Ur($e,e,t,i),a=null;return r&&(a=kd(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 Cd(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 Sl(e,t,i,n,r){let o=Sd(t);return Fn("parseStylesheetFromText",s=>{let a=new vt(e,o);Vw(a,o,i,n,r).thenFinish(s)},(s,a)=>{j.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Sd(e){if(e instanceof ka)return e;if(e instanceof Qi){if(e.owner)return e.owner;let t=new ka;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Cd(e,t,i,n){return Fn("parseStylesheetFromURL",r=>{ks(e).then(o=>{o.responseText?Sl(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 xd(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Uw(e,t,i){new Ur(Xo,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function kd(e,t,i){let n=new Ur(Ze,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var $w={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Hw(e){return!!$w[e]}function Ww(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 Hw(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 Gw="data-vivliostyle-flow-root";function jw(e){return e.getAttribute(Gw)==="true"}function Hh(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return M(i)}function Ps(e){return e===y.absolute||e===y.fixed}function qo(e){return e instanceof oi&&e.name==="running"}function Ed(e,t,i,n){return e===y.none||(Ps(t)?(i=y.none,e=Hh(e)):(i&&i!==y.none&&!q(i)||n)&&(e=Hh(e))),{display:e,position:t,float:i}}function Pd(e,t,i,n){return Ed(e,t,i,n).display===y.block}function Ns(e){return e instanceof ae||e instanceof te||typeof e=="string"}function Gt(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 nr(e){return Ns(e)?e.toString().includes("list-item"):!1}function Xw(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 Nd(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 qw(e,t,i,n,r,o,s){return r=r||o||y.horizontal_tb,!!s||!!i&&i!==y.none&&!q(i)||Ps(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 Yw(e){return e===y.relative||e===y.absolute||e===y.fixed}var Jt=1e5;function Cl(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 Ts(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Yo(e){return e.element.style.columnCount==="1"}function Zw(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 Td(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 Ea(e,t){for(let i=0;i<e.length;i++)Td(e[i],t)}function Rt(e,t,i){let n=e.getElementClientRect(t);if(Td(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!$r(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Ts(r),e.getElementClientRect(t)}return n}function Kw(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 Pa(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function Jw(e){if(!e.hasAttribute("data-vivliostyle-column")&&Pa(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Pa(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(Pa(t))return t;if(i.position==="absolute")break}return null}function Qw(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 to(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?Cr(i,e.vertical):0}function Id(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||to(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`,to(t)){if(e.style.blockSize=`${n}px`,!to(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`,to(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 ey(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)Id(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];Ea(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);Ea(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 Na(e,t,i){let n=Yo(t);n&&Ts(t);let r=t.clientLayout.getElementClientRect(e);n&&Cl(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 Ad(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 kl(e){return!!e.getAttribute(Ln)}function Ft(e){return e?.nodeType!==1?!1:kl(e)?!0:Fd(e)}function Fd(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 Wh(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&&kl(t)}function ty(e){return e!=="inline"&&(Gt(e)||Nd(e))}function Gh(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 iy(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 Rd(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 Ld(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 Od={"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"}]}},ny=Rd(Od,!0);function Bd(e,t,i){return Ld(e,t,i||null,ny)}var ry=Rd(Od,!1);function Md(e,t,i){return Ld(e,t,i||null,ry)}var oy={"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 sy(e,t){let i=oy[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 El(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 _d(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 xt(e,t){let i=_d(e);i.includes(t)||(i.push(t),Dd(e,i))}function ay(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function ly(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Zs(e,t){let i=ay(e);i.includes(t)||(i.push(t),ly(e,i))}function hy(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 Ta={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ye(e){return!!Ta[e]}var uy={left:!0,right:!0,recto:!0,verso:!0};function On(e){return!!uy[e]}function jh(e){return Ye(e)&&e!=="column"&&e!=="region"}var cy={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Zo(e){return!!cy[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:Zo(t)?t:Zo(e)?e:t}}else return e;else return t}function Xh(e){return Ye(e)?e:"auto"}Ot("SIMPLE_PROPERTY",hy);var cr=Eg(Ng());function dy(e,t){return(0,cr.default)(e,t,0)}function qh(e){return e.reduce((t,i)=>i[0]===cr.default.DELETE?t:t+i[1],"")}function py(e,t){return zd(e,t,1)}function fy(e,t){return zd(e,t,-1)}function zd(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 Ia;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Ia||(Ia={}));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 Ko;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Ko||(Ko={}));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 gy={transform:!0,"transform-origin":!0},my={top:!0,bottom:!0,left:!0,right:!0},Pl=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},wy={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 yy(e,t){let i=wy[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Aa=class rr extends pl{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=yy(a,s.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(s.event,l,!1)}}}};d(Aa,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),d(Aa,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Vd=Aa,yt=gi.Whitespace;function Ud(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:$d(e.textContent,t):!0}function $d(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 vy=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,d(this,"forcedBreakOffsets",[]),d(this,"formattingContext",null)}},by=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 xy(e,t){return e.top-t.top}function Sy(e,t){return t.right-e.right}function Hd(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&&Fa(e.shadowContext,t.shadowContext)&&Fa(e.nodeShadow,t.nodeShadow)&&Hd(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(!Hd(e.steps[i],t.steps[i]))return!1;return!0}function Cy(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 Jo(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 Qo(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?Qo(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var st=gi.ShadowType,ko=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&&Fa(this.parentShadow,e.parentShadow):!1}};function Fa(e,t){return e===t||!!e&&!!t&&e.equals(t)}var ky=class{constructor(e,t){this.outer=e,this.count=t}},fn=class Wd{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 Wd(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?fy(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 Gd{constructor(t){this.primary=t,d(this,"floats",null)}clone(){let t=new Gd(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}},Ey=class jd{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new jd(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Py=class Xd{constructor(){d(this,"positions",[]),d(this,"startBreakType",null),d(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}},Ny=class qd{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 qd;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}},Yd=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):bl(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 qc(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,Ty=20;function Iy(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 Ks(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Md(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Bd(e,r,i),s=sy(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 Zd=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}},Ay=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}},Kd=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}},Yh=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 Ay;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&&Jw(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Ty?!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 Md(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Bd(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=Gc(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?jo(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(bm,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(xm,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=El(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}`)}},Fy=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 Zd(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 Kd(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 Fy);var Jd="data-vivliostyle-footnote-first-ref",Qd="data-vivliostyle-footnote-referenced";function es(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function kt(e){if(e.localName!=="aside")return!1;if(es(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return es(t,"footnote")}function Vt(e){if(e.localName!=="a")return!1;if(es(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return es(t,"noteref")}function Nl(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=$o(i,t);return n==="#"?null:n}function ep(e,t,i){let n=Nl(e,t);if(!n)return null;let r=i(n);return r&&kt(r)?r:null}function Ry(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=Nl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function Zh(e,t,i,n,r){if(e.localName!=="a"||!Vt(e))return!0;let o=Nl(e,t);if(!o)return!0;Ry(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function Tl(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 Ly(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=ep(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=Tl(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 Oy(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=Tl(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 By(e,t,i){var n,r;let o=t?.type===st.ROOTED&&kt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=Tl(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function tp(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=>tp(i,t))):e}function My(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=tp(n.value,i))}function _y(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(Jd,"true")),s.setAttribute(Qd,"true")}}}Ot("PREPROCESS_SINGLE_DOCUMENT",_y);var Dy=Kd,ts=class ip extends Zd{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 ip)}};function zy(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 Kh=class extends Dy{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof ts?!0:this.getOrder()<e.getOrder()}},Vy=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}},Uy=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof ts}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=zy(h);let u=new ts(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 Kh(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Kh);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 Vy(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Bn.register(new Uy);var Il=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 Il{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(Zo(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;Ad(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)}},Al=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){}},Fl=new xn,$y=Ia.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&&Pd(i,n,r,o)?new Al(s?s.formattingContext:null):null});Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Al?Fl:null);var Rl=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)}},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){}},Ra=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 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&&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)))}},La=[];function Wy(){La=[]}var io;function no(e){if(e==="")return 0;if(io===void 0){let i=Intl.Segmenter;io=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(io===null)return[...e].length;let t=0;for(let i of io.segment(e))t++;return t}var Gy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],jy=new Set(Gy);function Xy(e){return!(e.toLowerCase()==="none"||jy.has(e))}var qy=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Yy=new Set(qy),Zy=["fixed","extends"],Ky=new Set(Zy),LS=Symbol();function Wr(e){return e instanceof ae&&e.name.toLowerCase()!=="none"}function np(e){return e.name}function Jy(e){if(e instanceof ae)return Yy.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 Ky.has(n)&&(n==="fixed"&&i instanceof lt||n==="extends"&&Wr(i))}}return!1}function Qy(e){let t=dt(e,"system");return t instanceof ae&&t.name==="cyclic"}function ev(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 tv(e){let t=dt(e,"system");return t instanceof ae?1:t.values[1].num}function iv(e){let t=dt(e,"system");return t instanceof ae&&t.name==="alphabetic"}function nv(e){let t=dt(e,"system");return t instanceof ae&&t.name==="numeric"}function rv(e){let t=dt(e,"system");return t instanceof ae&&t.name==="additive"}function ov(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 sv(e){let t=dt(e,"system");return np(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 rp(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 av(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 Jh(e){return e instanceof lt||e instanceof ae&&e.name==="infinite"}function is(e,t){return e instanceof lt?e.num:t?-1/0:1/0}var OS=Symbol();function Oa(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Jh(t)&&Jh(i)))return!1;let n=is(t,!0),r=is(i,!1);return!(n>r)}function lv(e){return{lower:is(e.values[0],!0),upper:is(e.values[1],!1)}}function op(e){return e instanceof ae&&e.name==="auto"||Oa(e)||e instanceof rt&&e.values.length>=1&&e.values.every(t=>Oa(t))}function hv(e){return e instanceof ae?null:(Oa(e)?[e]:e.values).map(t=>lv(t))}var BS=Symbol();function ns(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 rs(e){let[t,i]=e.values;return t instanceof lt?[t.num,di(i)]:[i.num,di(t)]}function sp(e){return ns(e)}function uv(e){let[t,i]=rs(e);return{minLength:t,symbol:i}}function ap(e){return $t(e)||e instanceof te&&e.values.length>=1&&e.values.every(t=>$t(t))}function cv(e){return $t(e)?[di(e)]:e.values.map(t=>di(t))}var MS=Symbol();function lp(e){if(ns(e))return!0;if(e instanceof rt&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!ns(i))return!1;let[n]=rs(i);if(n>=t)return!1;t=n}return!0}return!1}function dv(e){if(ns(e)){let[t,i]=rs(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=rs(t);return{weight:i,symbol:n}})}var pv=["auto","bullets","numbers","words","spell-out"],fv=new Set(pv);function gv(e){return e instanceof ae&&fv.has(e.name)||Wr(e)}function mv(e,t){switch(e){case"system":return Jy(t);case"negative":return rp(t);case"prefix":case"suffix":return $t(t);case"range":return op(t);case"pad":return sp(t);case"fallback":return Wr(t);case"symbols":return ap(t);case"additive-symbols":return lp(t);case"speak-as":return gv(t);default:return!0}}function dt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function wv(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 Eo,Po,No,To,Io,Ao,Fo,Ro,ro,hi,hp,oo,up,so,cp,ao,dp,lo,pp,ho,fp,uo,gp,wt,Js,mp,wp,Qh,eu,Qs,tu,or,ze=class zi{constructor(t,i){ee(this,wt),d(this,"_store"),ee(this,Eo),ee(this,Po),ee(this,No),ee(this,To),ee(this,Io),ee(this,Ao),ee(this,Fo),ee(this,Ro),this._store=t;let n=dt(i,"negative");fe(this,Eo,n&&rp(n)?av(n):null);let r=dt(i,"prefix");fe(this,Po,r&&$t(r)?di(r):null);let o=dt(i,"suffix");fe(this,No,o&&$t(o)?di(o):null);let s=dt(i,"range");fe(this,To,s&&op(s)?hv(s):null);let a=dt(i,"pad");fe(this,Io,a&&sp(a)?uv(a):null);let h=dt(i,"fallback");fe(this,Ao,h&&Wr(h)?np(h):null);let l=dt(i,"symbols");fe(this,Fo,l&&ap(l)?cv(l):null);let u=dt(i,"additive-symbols");fe(this,Ro,u&&lp(u)?dv(u):null)}static create(t,i){return Qy(i)?new Li(t,i):ev(i)?new yv(t,i):iv(i)?new bv(t,i):nv(i)?new iu(t,i):rv(i)?new xv(t,i):ov(i)?new Sv(t,i):new vv(t,i)}static createDecimal(t){var i;return new iu(t,se(i=zi,hi,hp).call(i))}static createDisc(t){var i;return new Li(t,se(i=zi,hi,up).call(i))}static createSquare(t){var i;return new Li(t,se(i=zi,hi,cp).call(i))}static createCircle(t){var i;return new Li(t,se(i=zi,hi,dp).call(i))}static createDisclosureOpen(t){var i;return new Li(t,se(i=zi,hi,pp).call(i))}static createDisclosureClosed(t){return new Li(t,se(this,hi,fp).call(this))}static createNone(t){var i;return new Li(t,se(i=zi,hi,gp).call(i))}static get CHINESE_LONGHAND_NAMES(){return nu.NAMES}static createChineseLonghand(t,i){return new nu(t,i)}static createEthiopicNumeric(t){return new kv(t)}_getNegative(){return U(this,Eo)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return U(this,Po)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return U(this,No)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return U(this,To)}static _getRangeFrom(t){return t._getRange()}_getPad(){return U(this,Io)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(U(this,Ao)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return U(this,Fo)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return U(this,Ro)}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,mp).call(this)+this.format(t)+se(this,wt,wp).call(this)}};Eo=new WeakMap,Po=new WeakMap,No=new WeakMap,To=new WeakMap,Io=new WeakMap,Ao=new WeakMap,Fo=new WeakMap,Ro=new WeakMap,ro=new WeakMap,hi=new WeakSet,hp=function(){var e;return(e=U(ze,ro))!=null?e:fe(ze,ro,{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)})},oo=new WeakMap,up=function(){var e;return(e=U(ze,oo))!=null?e:fe(ze,oo,{system:new $(M("cyclic"),0),symbols:new $(new X("\u2022"),0),suffix:new $(new X(" "),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("\u25AA"),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("\u25E6"),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("\u25BE"),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("\u25B8"),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(""),0),suffix:new $(new X(""),0)})},wt=new WeakSet,Js=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},mp=function(){var e;return(e=this._getPrefix())!=null?e:""},wp=function(){var e;return(e=this._getSuffix())!=null?e:". "},Qh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},eu=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},Qs=function(){var e;return(e=this._getFallback())!=null?e:Mn(this._store)},tu=function(e,t){let{minLength:i,symbol:n}=se(this,wt,eu).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=se(this,wt,Js).call(this),s=t?no(r)+(o?no(o):0):0,a=i-no(e)-s;if(a<=0)return e;let h=no(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),!wv(e,se(this,wt,Qh).call(this))){let l=se(this,wt,Qs).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,Qs).call(this);return se(r=l,wt,or).call(r,e,t)}let h=se(this,wt,tu).call(this,a,o);if(o){let{prefix:l,suffix:u}=se(this,wt,Js).call(this);h=l+h+(u??"")}return h},ee(ze,hi),ee(ze,ro,null),ee(ze,oo,null),ee(ze,so,null),ee(ze,ao,null),ee(ze,lo,null),ee(ze,ho,null),ee(ze,uo,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]}},Lo,yv=class extends pe{constructor(e,t){super(e,t),ee(this,Lo),fe(this,Lo,tv(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,Lo);return(t=i[n])!=null?t:null}};Lo=new WeakMap;var vv=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)}},bv=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}},iu=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}},xv=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,yp=class extends pe{constructor(t,i){super(t,i),ee(this,St),ee(this,pr);let n=sv(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 yp?se(t=i,St,At).call(t,e):i:Mn(this._store)};var Sv=yp,Cv=["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 ea,ta,co,ia,po,Ba,vp,Oo,mt=class bp extends pe{constructor(t,i){var n;let{chars:r,descriptors:o}=se(n=bp,Ba,vp).call(n).get(i);super(t,o),ee(this,Oo),fe(this,Oo,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=U(this,Oo);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}};ea=new WeakMap,ta=new WeakMap,co=new WeakMap,ia=new WeakMap,po=new WeakMap,Ba=new WeakSet,vp=function(){var e;return(e=U(mt,po))!=null?e:fe(mt,po,new Map([["simp-chinese-informal",{chars:U(mt,ea),descriptors:Zn("\u8D1F")}],["simp-chinese-formal",{chars:U(mt,ta),descriptors:Zn("\u8D1F")}],["trad-chinese-informal",{chars:U(mt,co),descriptors:Zn("\u8CA0")}],["trad-chinese-formal",{chars:U(mt,ia),descriptors:Zn("\u8CA0")}],["cjk-ideographic",{chars:U(mt,co),descriptors:Zn("\u8CA0")}]]))},Oo=new WeakMap,ee(mt,Ba),ee(mt,ea,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ee(mt,ta,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ee(mt,co,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ee(mt,ia,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),d(mt,"NAMES",new Set(Cv)),ee(mt,po,null);var nu=mt,fo,Ma,xp,_a,os,Da,za,ai=class Vi extends pe{constructor(t){var i;super(t,se(i=Vi,Ma,xp).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,os)[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,_a)[u]+U(Vi,os)[c]}h?a!==0&&(o+=U(Vi,Da)):s!==0&&(o+=U(Vi,za))}return o}};fo=new WeakMap,Ma=new WeakSet,xp=function(){var e;return(e=U(ai,fo))!=null?e:fe(ai,fo,{range:new $(new te([new lt(1),M("infinite")]),0),suffix:new $(new X("/ "),0)})},_a=new WeakMap,os=new WeakMap,Da=new WeakMap,za=new WeakMap,ee(ai,Ma),ee(ai,fo,null),ee(ai,_a,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ee(ai,os,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ee(ai,Da,"\u137B"),ee(ai,za,"\u137C");var kv=ai,Fe,Ev=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(!Xy(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 Sp{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 Sp;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(ru);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(ru);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]}},Pv=1,ss=2,Cp=4,yi=8,Gi=16,_n=32,Tn=64,as=128,ti=256,ii=512,ls=1024,kp=2048,Ep=4096,hs=8192,Ll=class extends Xt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},de=class Pp extends Ll{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Pv?t:null}visitSlash(t){return this.allowed&kp?t:null}visitStr(t){return this.allowed&ss?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Cp||this.allowed&Tn&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&ii)?t.unit=="%"&&this.allowed&ls?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&as?t:null}visitURange(t){return this.allowed&Ep?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(t.name.toLowerCase()==="attr"){let i=_l(t);if(i&&Fv(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)")&&Dc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&hs){let i=t.visit(new Uc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(yi|Gi|_n|ti|ii|ls)?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 Pp(this.allowed|t.allowed,i,n)}},Q=Object.create(null),Nv=Gi|ti|ii,Tv=_n|ti|ii,Bi=yi|ti|ii|ls;function Gr(e){let t=Object.create(null);for(let i of e)t[i]=Be;return t}var Is=Gr(["%"]),As=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"]),Np={...As,...Is},Ol=Gr(["deg","grad","rad","turn"]),Bl=Gr(["s","ms"]),Ml=Gr(["hz","khz"]);function Iv(e){return e.replace(/\s+/g,"").toLowerCase()}function Fs(e){return e.toLowerCase()}function Av(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:Fs(e.name)}}if(e instanceof oi&&e.name.toLowerCase()==="type"){if(e.values.length!==1)return null;let t=Iv(e.values[0].stringValue());return t?{kind:"syntax",syntax:t}:null}return null}function _l(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=Av(o[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(t=e.values[1])!=null?t:null}}function Tp(e,t){return!!e[Fs(t)]}function rn(e,t){return Object.keys(t).some(i=>Tp(e,i))}function Fv(e,t,i){switch(e.kind){case"string":return!!(t&ss);case"url":return!!(t&(as|hs));case"unit":return Tp(i,e.unit);case"syntax":switch(e.syntax){case"<string>":return!!(t&ss);case"<url>":return!!(t&(as|hs));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,As);case"<length-percentage>":return rn(i,Np);case"<percentage>":return rn(i,Is);case"<angle>":return rn(i,Ol);case"<time>":return rn(i,Bl);case"<frequency>":return rn(i,Ml);default:return!1}}return!1}function Va(e){switch(e.kind){case"string":return null;case"url":return null;case"unit":return new de(Bi,Q,{[Fs(e.unit)]:Be});case"syntax":switch(e.syntax){case"<color>":return new de(Tn,Q,Q);case"<integer>":return new de(Tv,Q,Q);case"<number>":return new de(Nv,Q,Q);case"<length>":return new de(Bi,Q,As);case"<length-percentage>":return new de(Bi,Q,Np);case"<percentage>":return new de(Bi,Q,Is);case"<angle>":return new de(Bi,Q,Ol);case"<time>":return new de(Bi,Q,Bl);case"<frequency>":return new de(Bi,Q,Ml);default:return null}}return null}function Rv(e){switch(e.kind){case"string":case"url":case"unit":return!0;case"syntax":return e.syntax==="<string>"||e.syntax==="<url>"||!!Va(e)}return!1}function Lv(e){switch(e.kind){case"url":return new tt("about:invalid");case"string":return new X("");default:return y.unset}}function Ov(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()}${Fs(i.unit)}`,null),""),r=Va(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=Va(i);return n&&r?n.visit(r):null}}return null}var ru=new de(0,Q,Q),Dl=class extends Ll{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 zl&&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 Dl{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 zl){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)}},zl=class extends Dl{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}},Bv=class extends Dl{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}},ou=class extends Ll{validateSingle(e){return null}visitFunc(e){let t=_l(e);return t&&Rv(t.type)?e:null}},Ip=class{tryParse(e,t,i){return t}success(e,t){}},Ap=class extends Ip{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}},Mv=class extends Ap{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}},_v=class extends Ip{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==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}},Rs=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 Ap(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 Rs{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}},Fp=class extends Rs{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 Mv(this.validatorSet,this.propList)}},Dv=class extends Rs{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}},zv=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}},Vv=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}},Uv=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)}},$v=class extends Rs{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}},su=["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"],Rp=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}},au={SIMPLE:$n,INSETS:Fp,INSETS_SLASH:Dv,COMMA:zv,FONT:Vv,TEXT_SPACING:Uv,ALL:Rp},Hv=["initial-letter"],Wv=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 Wo(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)||su.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)su.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 Rp&&!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):!lu(t))&&(this.browserShorthandMisses[e]=!0),null;let r=new $v(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 Rc(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 zl(t);break;case"SPACE":i=new fr(t);break;case"attr":i=new ou;break;default:i=new Bv(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 ou),this.namedValidators.IMAGE_FUNCTION=this.primitive(new de(hs,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,Is)),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(ls,Q,Q)),this.namedValidators.POS_LENGTH=this.primitive(new de(yi,Q,As)),this.namedValidators.POS_ANGLE=this.primitive(new de(yi,Q,Ol)),this.namedValidators.POS_TIME=this.primitive(new de(yi,Q,Bl)),this.namedValidators.FREQUENCY=this.primitive(new de(yi,Q,Ml)),this.namedValidators.RESOLUTION=this.primitive(new de(yi,Q,{dpi:Be,dpcm:Be,dppx:Be})),this.namedValidators.URI=this.primitive(new de(as,Q,Q)),this.namedValidators.URANGE=this.primitive(new de(Ep,Q,Q)),this.namedValidators.IDENT=this.primitive(new de(Cp,Q,Q)),this.namedValidators.STRING=this.primitive(new de(ss,Q,Q)),this.namedValidators.SLASH=this.primitive(new de(kp,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&&au[i.text]?(n=new au[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 Fp){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 _v(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"){mv(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(lu(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&&!lc.includes(`-${a}-`)||n.unknownProperty(h,t);return}else if(Hv.includes(e)&&!Object.keys(c).some(f=>xo(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 Lp(){let e=new Wv;return e.initBuiltInValidators(),e.parse(ud),e}var Gv=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 lu(e){let t=new Gv;return e.visit(t),t.varFound}function Op(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var jv=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Xv=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Bp=class Bo{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Bo.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Bo.fragmentIndices={}}matches(){let t=Bo.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Op(t.fragmentIndex,this.a,this.b)}};d(Bp,"fragmentIndices",{});var Ls=Bp,go=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Ls(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Xv(e)}static buildAnyMatcher(e){return new jv(e)}},Mp={"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},qv=["image-resolution","orphans","widows"];function Yv(){return Ut("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(qv))}var Zv={"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},Ua=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Kv=["max-%","min-%","%"],hu=(()=>{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<Ua.length;i++)for(let n=0;n<e.length;n++){let r=Ua[i].replace("%",e[n]);t[r]=!0}return t})();function Hn(e,t){let i={};for(let n of Ua)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 Kv)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var _p=Hn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Dp=Hn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Jv=Hn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Qv=Hn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),eb=Hn({inside:"right",outside:"left"},{}),tb=Hn({inside:"left",outside:"right"},{}),$=class $a{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 $a(i,this.priority)}increaseSpecificity(t){return t==0?this:new $a(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&je(i)?this.value:ps(t,this.value,i,n,r)}isEnabled(t){return!0}},Ha=class Wa 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 Wa(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Wa(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){j.warn(i)}return!1}};function Ga(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 zp={"region-id":!0,"fragment-selector-id":!0},gr="data-viv-footnote-counter";function us(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 Vp(e,t,i){let n=us(e);n[t]=i,e.setAttribute(gr,JSON.stringify(n))}function ib(e,t){var i,n;if(!Vt(e)||e.hasAttribute(Jd))return null;let r=us(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=$o(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=us(l)[t];return u?(Vp(e,t,u),u):null}function nb(e){let t=ge(e,"content");return!!t&&Tt(t.value)}function rb(e){return!!zp[e]}function Mo(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Hi(e){return e.charAt(0)!=="_"&&!zp[e]}function Cn(e){return!!Mp[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 Up=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function $p(e,t){return e[t]}function Hp(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function cs(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=Up(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!Mo(l))if(rb(l)){let u=$p(i,l),c=Hp(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 ob(e,t){let i={};for(let n=0;n<t.length;n++)cs(e,i,t[n],0,null,null,null);return i}function Vl(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 sb=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(!jg(t.unit))throw new Error("Unexpected state");return t.num*jt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?ja(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Ul(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?ps(this.context,e,this.propName).visit(this):e}};function Ul(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 ja(e,t,i){e=Ul(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 ab([this,e])}clone(){return this}},mo=class extends Wn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},ab=class Wp 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 Wp([].concat(this.list))}},$l=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){cs(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}},lb=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}},hb=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}},uu=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}},ub=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}},cb=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)}}}},db=class extends Pe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Os(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 Gp(e){return e==="i"}function Jn(e,t){return Array.from(e,i=>{let n=Ho(i);if(!Gp(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 pb(e,t,i){return Gp(i)?Er(e)===Er(t):e===t}var cu=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Os(e.currentElement,this.ns,this.name,()=>!0)&&this.chained.apply(e)}},fb=class extends Pe{constructor(e,t,i,n=null){super(),this.ns=e,this.name=t,this.value=i,this.caseSensitivity=n}apply(e){Os(e.currentElement,this.ns,this.name,t=>pb(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}},gb=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Os(e.currentElement,this.ns,this.name,t=>!!Zv[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){Os(e.currentElement,this.ns,this.name,t=>!!t.value.match(this.regexp))&&this.chained.apply(e)}},mb=class extends Pe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},du=class extends Pe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},wb=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 Op(e,this.a,this.b)}},yb=class extends en{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},Xa=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}},qa=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}},Ya=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}},vb=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}},bb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},xb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Sb=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}},jp=class Xp extends Wn{constructor(){super(),d(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Xp;return t.applied=this.applied,t}},Hl=class extends Pe{constructor(e){super(),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new jp;for(let t of e)this.firstActions.push(Vl(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}},Cb=class extends Hl{positive(){return!1}},kb=class extends Hl{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}},qp=class extends en{constructor(e,t,i){super(e,t),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new jp;for(let n of i)this.firstActions.push(Vl(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}},Eb=class extends qp{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}},Bs=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)}},Pb=class Yp extends Bs{constructor(t,i,n){super(t,i,n)}fresh(t){return new Yp(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}},Nb=class Zp extends Bs{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):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},Tb=class Kp extends Bs{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new Kp(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)}},Ib=class Jp extends Bs{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&&(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}},Ab=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}},Fb=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}},Rb=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}},Lb=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=_l(e);if(!i)return super.visitFunc(e);let n=((t=i.fallback)!=null?t:Lv(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:Ov(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function ds(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=>ds(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=ds(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&&Vp(this.element,t,w)};if(this.pseudoName==="footnote-call"&&this.element){let w=ib(this.element,t);if(w)return p(w)}if(this.pseudoName==="footnote-marker"&&this.element){let w=us(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=ds(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(Uo);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 na(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 Ob=(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(Xw(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+na(A,i.clientLayout,v),0);if(w!=="after"){let P=na(ue,i.clientLayout,v),A=na(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",Ob);var Wl=1/1048576;function on(e,t){for(let i in e)t[i]=e[i].clone()}var Bb=class Qp{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 Qp;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 Mb(this,t,i,n,r,o,s)}nextOrder(){return this.order+=Wl}},ef=class tf{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=go.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]:go.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:go.buildAllMatcher(n):go.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=ra,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=>ds(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=ra;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=ra;let c=ca(i);c&&(this.stack[this.stack.length-1].push(new Fb(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 Rb(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 _b){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=nb(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 Ab(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 tf.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 Lb(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 Xb(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,Ga(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,Ga(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(Mo(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 cf(i);for(let r in t)if(Mo(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 Uc(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(Mo(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(ef,"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 Mb=ef,ra=[],_b=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],Za=null;function Db(e){Za=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:Za?Za.clone():new Bb,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Vl(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 ub(e,t.toLowerCase())):t?this.chain.push(new uu(t.toLowerCase())):this.chain.push(new db(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 lb(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new bb);break;case"disabled":this.chain.push(new xb);break;case"checked":this.chain.push(new Sb);break;case"root":case"scope":this.chain.push(new wb);break;case"link":this.chain.push(new uu("a")),this.chain.push(new cu("","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)${Ho(i)}($|\\s)`),r=t[1];this.chain.push(new cb(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 mb(new RegExp(`^${Ho(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=zb[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 du);break;case"last-child":this.chain.push(new qa(0,1));break;case"first-of-type":this.chain.push(new Xa(0,1));break;case"last-of-type":this.chain.push(new Ya(0,1));break;case"only-child":this.chain.push(new du),this.chain.push(new qa(0,1));break;case"only-of-type":this.chain.push(new Xa(0,1)),this.chain.push(new Ya(0,1));break;case"empty":this.chain.push(new vb);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 hb(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 cu(e,t);break;case 39:o=new fb(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 gb(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${wo++}`;this.processChain(new mo(new Pb(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${wo++}`;this.processChain(new mo(new Nb(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${wo++}`;this.processChain(new mo(new Tb(e,this.viewConditionId,null))),this.chain=[new it(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${wo++}`;this.processChain(new mo(new Ib(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 $l(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Ha(t,0,this.condition):i=new $(t,0),Hp(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 Ha(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 Vb(this);break;case"where":i=new Ub(this);break;case"has":i=new $b(this);break;case"nth-child":t&&t.length>=2&&(i=new rf(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Hb(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},zb={"nth-child":yb,"nth-of-type":Xa,"nth-last-child":qa,"nth-last-of-type":Ya},wo=0,Dn=class nf 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 kb(this.selectorTexts):this.positive()?new Hl(this.chains):new Cb(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 nf;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}},Vb=class extends Dn{positive(){return!1}forgiving(){return!1}},Ub=class extends Dn{increasingSpecificity(){return!1}},$b=class extends Dn{relational(){return!0}},rf=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 qp(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new it("")),this.owner.popHandler()}forgiving(){return!0}},Hb=class extends rf{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Eb(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new it("")),this.owner.popHandler()}},Wb=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))}}},_o=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+=Wl;let r=this.condition?new Ha(t,n,this.condition):new $(t,n);qt(this.elementStyle,e,r)}},Gb=class extends xd{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?bd:vd;n+=this.order,this.order+=Wl;let r=new $(t,n);qt(this.elementStyle,e,r)}};function of(e,t){let i=Up(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Ka(e,t,i){of(i,n=>{mr(e,n,t)})}function jb(e,t,i,n){let r=new Gb(e,t),o=new vt(n,r);try{Uw(o,r,i)}catch(s){j.warn(s,"Style attribute parse error:")}return r.elementStyle}function sf(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 af(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 Ja(e,t,i,n,r){let o={};for(let s in e)Hi(s)&&(o[s]=ge(e,s));return Ka(o,t,e),lf(e,i,n,(s,a)=>{mr(o,a,t),Ka(o,t,a)}),o}function lf(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]=Ga(i,o,r)}}var hf=(e,t,i,n,r,o)=>{var s,a;let h=i?n?Jv:_p:n?Qv:Dp,l=r?eb:tb;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=hu[p]?p:hu[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)}},Xb=class uf 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 uf(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)))}},cf=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&&gc(e.unit)||this.context.rootFontSize!=null&&qg(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 ps(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:Ww(e,t.expr,i);if(t instanceof R||t instanceof oi||t instanceof te||t instanceof rt)return t.visit(new cf(e,!0,n,r))}catch(o){return j.warn(o),Be}return t}var pu={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function fu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.none;if(t===y.none)return pu;let i=t instanceof te?t.values:[t],n=Object.create(pu);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 gu(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var qb={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},mu={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},wu={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function yu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.normal;if(t===y.normal)return mu;if(t===y.auto)return wu;let i=t instanceof te?t.values:[t],n=Object.create(mu);for(let r of i)if(r instanceof ae)switch(r.name){case"trim-both":case"trim-auto":return wu;case"space-all":return qb;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 oa={ideographAlpha:!1,ideographNumeric:!1},Yb={ideographAlpha:!0,ideographNumeric:!0};function vu(e){let t=e instanceof ot?e:typeof e=="string"?M(e):y.normal;if(t===y.normal||t===y.auto)return Yb;if(t===y.none)return oa;let i=t instanceof te?t.values:[t],n=Object.create(oa);for(let r of i)if(r instanceof ae)switch(r.name){case"no-autospace":return oa;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function bu(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function xu(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 Zb=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=xu(r);let s=vu(t),a=yu(i),h=fu(n);if(gu(h)&&bu(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=xu((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=vu(b.inheritedProps["text-autospace"]),L=yu(b.inheritedProps["text-spacing-trim"]),V=fu(b.inheritedProps["hanging-punctuation"]);if(gu(V)&&bu(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=iy(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)}},Gl=new Zb;Gl.registerHooks();function Kb(e){Gl.preprocessForTextSpacing(e)}function Jb(e,t,i,n,r,o){Gl.processGeneratedContent(e,t,i,n,r,o)}var sr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Qb=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],jl="data-adapt-pseudo";function ei(e){return e.getAttribute(jl)||""}function wr(e,t){e.setAttribute(jl,t)}var sa=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)),Kb(e))}}},DS=Ko.isInstanceOfAfterIfContinuesLayoutConstraint,e0=Ls.registerFragmentIndex,zS=Ls.clearFragmentIndices,t0=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=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 ko(this.sourceNode,e,null,null,null,gi.ShadowType.ROOTED,this.styler)}},i0=class df{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 n0(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof df?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},n0=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 pf(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=o0(e,t,n);return t.fragmentLayoutConstraints.push(new i0(e,i,r)),T(e)})}function ff(e,t){return e.thenAsync(i=>pf(i,t))}function r0(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=pf(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function o0(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Na(i,t,e.vertical);return n.removeChild(i),r}var s0=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},ar=class extends Il{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]}},fs=class extends Yd{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),Zw(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=Qo(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?py(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(Uo),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(Uo);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 ff(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=ul==="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 js(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 js(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 js(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=Ks(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=jo(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)?Ks(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(),Sm(c,this.bands,p,n),this.vertical&&(a=Gc(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=jo(c)),Cm(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 h0(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 ts,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 Yh(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=El(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=Jo(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new Yh(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=Gh(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,gs.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:kl(c)?l=!a:!c.firstChild||$i[c.localName]||/^r(uby|[bt]c?)$/.test(c.localName)||ty(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);Ea(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?Sy:xy);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(uc),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=Fl.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(!Yo(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)?Ks(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!!($y(e)||Wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(Wh(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||!jh(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||!jh(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=Zo(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?Gh(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){Id(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(Wh(e.viewNode))break;if(S()){x(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,Fd(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)&&Kw(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=vm(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);Cl(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 a0(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(Yo(this)&&(ey(this),Ts(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(Ko.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Ii.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},Xl=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 fs.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(!$d(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}},gs=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+Su(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&&gh(r)&&gh(o)?Su(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};d(gs,"instance");gs.instance=new gs;function Su(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var a0=class extends Rl{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 l0(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Wy()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Ad(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}},l0=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return r0(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}},h0=class extends fs{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||La.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new u0(e,this.rootSourceNode),La.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},u0=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=Jo(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Jo(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Na(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Na(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 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}},gf=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}},mf=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},c0=class extends gf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},d0=class extends mf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new ql(e)),this.processor.doLayout(e,t)}},ql=class wf{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?!vf(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 w0(n,o,i).thenAsync(()=>y0(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return ui(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof wf?ui(this.nodeContext.formattingContext)===ui(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},p0=class extends Rl{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 c0(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new d0(this.formattingContext,this.processor))}},f0=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)}},g0=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&&yf(e.parent,t),e.belongsTo(n)?xn.prototype.layout.call(this,e,t,i):new p0(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=v0(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 f0(i,t);return new Ra(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=ui(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return ff(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 m0(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 yf(e,t){e&&m0(e.after?e.parent:e,(i,n)=>{Ii.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new ql(n))})}function w0(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 y0(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 vf(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function v0(e){let t=e.formattingContext;return!t||!(t instanceof Zi)?null:t}function ui(e){return e instanceof Zi,e}var b0=new g0;Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Zi&&!Ii.isInstanceOfTableFormattingContext(e)?b0:null);var bf=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))}},x0=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}},S0=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},C0=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,d(this,"pseudoColumn"),d(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}},k0=class{constructor(e,t){this.viewNode=e,this.side=t}},E0=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)}},P0=class extends Il{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 bf(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 S0(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 N0(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)}},N0=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 T0(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function I0(e){return e==="table"||e==="inline-table"}function Cu(e){return T0(e)||I0(e)}function xf(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"&&!Cu(o)||r==="table-cell"&&o!=="table-row"&&!Cu(o)||n.formattingContext instanceof In&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function Sf(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 A0=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=xf(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Sf(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 k0(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 bf(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 x0(this.rowIndex,this.columnIndex,o)),this.columnIndex++,Pf(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=[]}},Cf=class kf 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 Sf(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 C0(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(()=>(Pf(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=Qo(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=Qo(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);e0(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=Jo(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=xf(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 P0(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&&kf.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(Cf,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var F0=Cf,Tr=[];function R0(e){let t=Tr.findIndex(n=>n.root===e),i=Tr[t];return i?i.tableLayoutOption:null}function L0(e){let t=Tr.findIndex(i=>i.root===e);t>=0&&Tr.splice(t,1)}var Ef=class{layoutEntireTable(e,t){let i=_t(e.formattingContext),n=new A0(i,t);return new Ra(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=R0(e.sourceNode);L0(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 _0(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 F0(i,t),s=new Ra(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(),yf(e.parent,t)}return new B0(n,this).layout(e,t)}else return t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new E0(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return aa(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(()=>{O0(c,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),aa(t),r.finishFragment(),a.finish(!0)}),a.result()}}return aa(t),r.finishFragment(),Fl.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){xn.prototype.clearOverflownViewNodes(e,t,i,n)}};function O0(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 Pf(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 aa(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 B0=class extends Rl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new M0(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new z0(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()}},M0=class extends gf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},_0=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 D0(this.position.sourceNode))}},D0=class Nf{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 Nf&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},z0=class extends mf{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new V0(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},V0=class Tf extends ql{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?!vf(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 Ef().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 Tf?_t(this.nodeContext.formattingContext)===_t(t.nodeContext.formattingContext):!1}},U0=new Ef;function $0(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 H0(e){return e instanceof In?U0:null}Ot("RESOLVE_FORMATTING_CONTEXT",$0);Ot("RESOLVE_LAYOUT_PROCESSOR",H0);function ku(e){return e.reduce((t,i)=>t+i,0)/e.length}function W0(e){let t=ku(e);return ku(e.map(i=>{let n=i-t;return n*n}))}var G0=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 If=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 G0(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)}},Qa=1;function Af(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+Qa}function Ff(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+Qa))-Qa;n<Ir(t)?Ar(t,n):Ar(t,Ir(t)-1)}var j0=class extends If{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 Eu(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Af(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Eu(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Ir(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Ff(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Ir(this.layoutContainer)+this.originalContainerBlockSize*.1);Ar(this.layoutContainer,t)}}};function Eu(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 X0=class extends If{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 W0(t)}hasNextCandidate(e){return Af(e)}updateCondition(e){Ff(e,this.layoutContainer)}};function q0(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 j0(i,n,r,e):t===y.balance_all?new X0(i,n,r):(y.balance,null)}}var la=class{constructor(e,t,i){d(this,"endStuckFixed"),d(this,"endFixed"),d(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Y0=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 la(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 la(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new la(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 Z0(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var K0=class el{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 el(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 el(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=Pd(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!qo(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}},J0=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 K0(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=Ud(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!")}},Pu=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 Y0;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new J0(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,yd))}}}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<Nu.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Nu[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 jb(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Z0(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=Em(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(o=Bh(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let c=t["flow-priority"];c&&(r=Bh(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 vy(e,m)}let g=new by(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){}},Nu=["column-count","column-width","column-fill"],VS=`OTTO${new Date().valueOf()}`;function Yl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Q0(e){let t=new pi;for(let i of Yl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function ex(e,t){let i={};for(let n in e)i[n]=ge(e,n).evaluate(t,n);return i}var Rf=class{constructor(e){this.properties=e,d(this,"fontTraitKey"),d(this,"src"),d(this,"blobURLs",[]),d(this,"blobs",[]),d(this,"family"),this.fontTraitKey=Q0(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 {
1845
1867
  font-family: `),i.append(this.family),i.append(`;
1846
- `);for(let n of vl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1847
- `);if(t){i.append('src: url("');let n=_m(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1868
+ `);for(let n of Yl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1869
+ `);if(t){i.append('src: url("');let n=Ow(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1848
1870
  }
1849
- `),i.toString()}},Jb=class{constructor(e){this.deobfuscator=e,d(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof it){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(B(r)),i.push(n)}return new it(i)}else{let t=this.familyMap[e.stringValue()];return t?new it([B(t),e]):e}}},Qb=class{constructor(e,t,i){this.head=e,this.body=t,d(this,"srcURLMap",{}),d(this,"familyPrefix"),d(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=_("initFont"),r=e.src,o={};for(let l of vl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=B(s);let a=new _p(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),G.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{t.registerFamily(e,o),G.debug("Found already-loaded font:",i)}):(r=new Er(()=>{let o=_("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?qo(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(o)})}):this.initFont(e,null,t).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){G.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return Cn(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return T(!0);let i=_("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},e0=1,is=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,d(this,"specified",{}),d(this,"children",[]),d(this,"pageMaster",null),d(this,"index",0),d(this,"key"),d(this,"_scope"),this._scope=e,this.key=`p${e0++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},t0=class extends is{constructor(e){super(e,null,null,[],null),this.specified.width=new V(xr,0),this.specified.height=new V(Sr,0)}},Gh=class extends Rs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Dp=class zp extends is{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),this.condition=s,this.specificity=a,d(this,"keyMap",{}),t instanceof Gh||(this._scope=new Gh(t,this)),this.pageMaster=this,this.specified.width=new V(xr,0),this.specified.height=new V(Sr,0),this.specified["wrap-flow"]=new V(y.auto,0),this.specified.position=new V(y.relative,0),this.specified.overflow=new V(y.visible,0)}createInstance(t){return new xl(t,this)}clone(t){let i=new zp(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},Vp=class Up extends is{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new V(y.auto,0)}createInstance(t){return new o0(t,this)}clone(t){let i=new Up(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Ar=class Hp extends is{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new In(t,this)}clone(t){let i=new Hp(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function i0(e,t,i){return!t||Z(t)?new Ke(e,i):t.toExpr(e,e.zero)}function ye(e,t,i){return!t||t===y.auto||Z(t)?null:t.toExpr(e,i)}function n0(e,t,i){return!t||t===y.normal||Z(t)?null:t.toExpr(e,i)}function bt(e,t,i){return!t||t===y.auto||Z(t)?e.zero:t.toExpr(e,i)}function jh(e,t,i){return!t||Z(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function Yt(e,t,i,n){return!t||i===y.none||Z(t)?e.zero:t.toExpr(e,n)}function $p(e,t,i){return!t||Z(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var ns=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,d(this,"cascaded",{}),d(this,"style",{}),d(this,"autoWidth",null),d(this,"autoHeight",null),d(this,"children",[]),d(this,"isAutoWidth",!1),d(this,"isAutoHeight",!1),d(this,"isTopDependentOnAutoHeight",!1),d(this,"isRightDependentOnAutoWidth",!1),d(this,"calculatedWidth",0),d(this,"calculatedHeight",0),d(this,"pageMasterInstance",null),d(this,"namedValues",{}),d(this,"namedFuncs",{}),d(this,"vertical",!1),d(this,"rtl",!1),d(this,"suppressEmptyBoxGeneration",!1),d(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return ie(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let r=this.vertical?Cd:kd;n=e;for(let o in r)n=n.replace(o,r[o])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Wu(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=fe(i,qr(i,new Kn(i,"min",[n,r]),ie(i,o,s)),s);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=$p(e,t.enabled,e._true),n=ye(e,t.page,e.zero);if(n){let s=new qe(e,"page-number");i=Rt(e,i,new Wa(e,n,s))}let r=ye(e,t["min-page-width"],e.zero);r&&(i=Rt(e,i,new Os(e,new qe(e,"page-width"),r)));let o=ye(e,t["min-page-height"],e.zero);o&&(i=Rt(e,i,new Os(e,new qe(e,"page-height"),o))),i=this.boxSpecificEnabled(i),t.enabled=new W(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ye(e,t.left,i),r=ye(e,t["margin-left"],i),o=Yt(e,t["border-left-width"],t["border-left-style"],i),s=bt(e,t["padding-left"],i),a=ye(e,t.width,i),h=ye(e,t["max-width"],i),l=bt(e,t["padding-right"],i),u=Yt(e,t["border-right-width"],t["border-right-style"],i),c=ye(e,t["margin-right"],i),p=ye(e,t.right,i),f=ie(e,o,s),g=ie(e,o,l);if(n&&p&&a){let x=fe(e,i,ie(e,a,ie(e,ie(e,n,f),g)));r?c?p=fe(e,x,c):c=fe(e,x,ie(e,p,r)):(x=fe(e,x,p),c?r=fe(e,x,c):(r=qr(e,x,new Ke(e,.5)),c=r))}else{r||(r=e.zero),c||(c=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let x=fe(e,i,ie(e,ie(e,r,f),ie(e,c,g)));this.isAutoWidth&&(h||(h=fe(e,x,n||p)),!this.vertical&&(ye(e,t["column-width"],null)||ye(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=fe(e,x,ie(e,n,a))):a=fe(e,x,ie(e,n,p)):n=fe(e,x,ie(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=bt(e,m,i);t.left=new W(n),t["margin-left"]=new W(r),t["border-left-width"]=new W(o),t["padding-left"]=new W(s),t.width=new W(a),t["max-width"]=new W(h||a),t["padding-right"]=new W(l),t["border-right-width"]=new W(u),t["margin-right"]=new W(c),t.right=new W(p),t["snap-width"]=new W(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=ye(e,t.top,n),o=ye(e,t["margin-top"],i),s=Yt(e,t["border-top-width"],t["border-top-style"],i),a=bt(e,t["padding-top"],i),h=ye(e,t.height,n),l=ye(e,t["max-height"],n),u=bt(e,t["padding-bottom"],i),c=Yt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=ye(e,t["margin-bottom"],i),f=ye(e,t.bottom,n),g=ie(e,s,a),m=ie(e,c,u);if(r&&f&&h){let b=fe(e,n,ie(e,h,ie(e,ie(e,r,g),m)));o?p?f=fe(e,b,o):p=fe(e,b,ie(e,f,o)):(b=fe(e,b,f),p?o=fe(e,b,p):(o=qr(e,b,new Ke(e,.5)),p=o))}else{o||(o=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let b=fe(e,n,ie(e,ie(e,o,g),ie(e,p,m)));this.isAutoHeight&&(l||(l=fe(e,b,r||f)),this.vertical&&(ye(e,t["column-width"],null)||ye(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=fe(e,b,ie(e,r,h))):h=fe(e,b,ie(e,f,r)):r=fe(e,b,ie(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=bt(e,w,i);t.top=new W(r),t["margin-top"]=new W(o),t["border-top-width"]=new W(s),t["padding-top"]=new W(a),t.height=new W(h),t["max-height"]=new W(l||h),t["padding-bottom"]=new W(u),t["border-bottom-width"]=new W(c),t["margin-bottom"]=new W(p),t.bottom=new W(f),t["snap-height"]=new W(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ye(e,t[this.vertical?"height":"width"],null),n=ye(e,t["column-width"],i),r=ye(e,t["column-count"],null),o=n0(e,t["column-gap"],null);o||(o=new br(e,1,"em")),n&&!r&&(r=new Kn(e,"floor",[Bs(e,ie(e,i,o),ie(e,n,o))]),r=new Kn(e,"max",[e.one,r])),r||(r=e.one),n=fe(e,Bs(e,ie(e,i,o),r),o),t["column-width"]=new W(n),t["column-count"]=new W(r),t["column-gap"]=new W(o)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=ca(this.cascaded,e,r,!1,null);this.vertical=Wd(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Gd(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===y.border_box;let s=!!(e instanceof Pl&&e.currentLayoutPosition&&new qe(i,"left-page").evaluate(e));Xd(o,n,this.vertical,this.rtl,s,(a,h)=>h.value),this.autoWidth=new Fe(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Fe(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&fn(t)&&this.pageMasterInstance instanceof xn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new R(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=Lo(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=Lo(e,r,t,o)}return st(r,e)}getSpecial(e,t){let i=Td(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(e,"");o&&o!==Y&&n.push(o)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&Lu(r.unit)&&(r=Ku(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),N(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new el(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),o=this.getPropAsNumber(e,"border-left-width"),s=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,s),N(t.element,"margin-left",`${n}px`),N(t.element,"padding-left",`${r}px`),N(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),s=this.getPropAsNumber(e,"border-right-width");if(N(t.element,"margin-right",`${r}px`),N(t.element,"padding-right",`${o}px`),N(t.element,"border-right-width",`${s}px`),t.marginRight=r,t.borderRight=s,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,o+=t.snapOffsetX)}t.paddingRight=o,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),s=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=s,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,o+=t.snapOffsetY)}t.paddingTop=o,N(t.element,"top",`${n}px`),N(t.element,"margin-top",`${r}px`),N(t.element,"padding-top",`${o}px`),N(t.element,"border-top-width",`${s}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;N(t.element,"height",`${o}px`),N(t.element,"margin-bottom",`${i}px`),N(t.element,"padding-bottom",`${n}px`),N(t.element,"border-bottom-width",`${r}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){N(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,N(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){N(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");N(t.element,"right",`${n}px`),N(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&N(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&N(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let o=0;o<Xh.length;o++)this.propagateProperty(e,t,Xh[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<Yh.length;r++)this.propagateProperty(e,t,Yh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;N(r,"text-overflow","inherit"),N(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!Z(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!Z(a)};for(let o=0;o<Zh.length;o++){let s=Zh[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;N(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,u,c,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let x=(this.vertical||!n)&&this.isAutoHeight,b=(!this.vertical||!n)&&this.isAutoWidth,v=null;if(b||x){b&&N(t.element,"width","auto"),x&&N(t.element,"height","auto");let C=n&&Co(n);C&&Ko(n),v=o.getElementClientRect(n?n.element:t.element),C&&Ka(n),b&&(this.calculatedWidth=Math.ceil(v.right-v.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=v.bottom-v.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let C=this.getPropAsNumber(e,"column-rule-width"),S=this.getProp(e,"column-rule-style"),F=this.getProp(e,"column-rule-color");if(C>0&&S&&S!=y.none&&F!=y.transparent){let A=this.getPropAsNumber(e,"column-gap"),D=this.vertical?t.height:t.width,H=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),q=t.getPaddingRect(),Se=n,se=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let M=this.vertical?(D+A)*k/r-A/2+t.paddingTop-C/2:(D+A)*k/r-A/2+t.paddingLeft-C/2,E=this.vertical?q.y1+M+C/2:q.x1+M+C/2,L=(c=(u=(l=Se.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:c.call(u,E),P=(g=(f=(p=Se.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),I=isFinite(L)?this.vertical?L-q.x1:L-q.y1:NaN,O=isFinite(P)?this.vertical?P-q.x1:P-q.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),$=z>0?z:this.vertical?n.width:n.height,K=Math.max(H>0?H:0,0),J=K+$,Q=Math.max(K,isFinite(this.vertical?O:I)?Math.max(0,this.vertical?O:I):0),de=Math.min(J,isFinite(this.vertical?I:O)?Math.max(0,this.vertical?I:O):J),re=Math.max(0,de-Q),oe=t.element.ownerDocument.createElement("div");N(oe,"position","absolute"),N(oe,this.vertical?"left":"top",`${Q}px`),N(oe,this.vertical?"top":"left",`${M}px`),N(oe,this.vertical?"height":"width","0px"),N(oe,this.vertical?"width":"height",`${re}px`),N(oe,se,`${C}px ${S.toString()}${F?` ${F.toString()}`:""}`),t.element.insertBefore(oe,t.element.firstChild)}}}for(let C=0;C<qh.length;C++)this.propagateProperty(e,t,qh[C],s);for(let C=0;C<Kh.length;C++)this.propagateDelayedProperty(e,t,Kh[C],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof xn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Mi(o)&&bi(i,o,ge(n,o));if(this.pageBox.pseudoName==bl)for(let o in t)(o.match(/^background-/)||o=="writing-mode")&&(i[o]=t[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in t)!o.match(/^background-/)&&o!="writing-mode"&&(i[o]=t[o]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new cr(e,null,e.counterResolver))),this.init(e.context);for(let o of this.pageBox.children)o.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Xh=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],qh=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],Yh=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],Zh=["width","height","image-resolution","object-fit","object-position"],Kh=["transform","transform-origin"],bl="background-host",r0=class extends ns{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},xl=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Rt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},o0=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},In=class extends ns{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ce&&(n=[t]),t instanceof it&&(n=t.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof ce){let s=Fs(n[o].name,"enabled"),a=new qe(r,s);i&&(a=new yi(r,a)),e=Rt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=$p(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=i0(t,i["flow-from"],"body"),o=new Kn(t,"has-content",[r]);e=Rt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(t,null):t._true;o=Rt(t,o,e),this.pageMasterInstance.style.enabled=new W(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof qp||(N(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},Sl=class extends Gi{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new V(t,i?_c:Dc)}},Wp=class extends Sl{constructor(e,t,i,n){super(e,t,i,n)}},s0=class Gp extends Sl{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new V(Ul,0),n.specified.height=new V(Ul,0)}startPartitionRule(t,i,n){let r=new Ar(this.scope,t,i,n,this.target),o=new Wp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new Vp(this.scope,t,i,n,this.target),o=new Gp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},a0=class extends Sl{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Ar(this.scope,e,t,i,this.target),r=new Wp(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Vp(this.scope,e,t,i,this.target),r=new s0(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function jp(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===y.vertical_lr||n!==y.vertical_rl&&r!==y.rtl?"ltr":"rtl"}var l0={a10:{width:new R(26,"mm"),height:new R(37,"mm")},a9:{width:new R(37,"mm"),height:new R(52,"mm")},a8:{width:new R(52,"mm"),height:new R(74,"mm")},a7:{width:new R(74,"mm"),height:new R(105,"mm")},a6:{width:new R(105,"mm"),height:new R(148,"mm")},a5:{width:new R(148,"mm"),height:new R(210,"mm")},a4:{width:new R(210,"mm"),height:new R(297,"mm")},a3:{width:new R(297,"mm"),height:new R(420,"mm")},a2:{width:new R(420,"mm"),height:new R(594,"mm")},a1:{width:new R(594,"mm"),height:new R(841,"mm")},a0:{width:new R(841,"mm"),height:new R(1189,"mm")},b10:{width:new R(31,"mm"),height:new R(44,"mm")},b9:{width:new R(44,"mm"),height:new R(62,"mm")},b8:{width:new R(62,"mm"),height:new R(88,"mm")},b7:{width:new R(88,"mm"),height:new R(125,"mm")},b6:{width:new R(125,"mm"),height:new R(176,"mm")},b5:{width:new R(176,"mm"),height:new R(250,"mm")},b4:{width:new R(250,"mm"),height:new R(353,"mm")},b3:{width:new R(353,"mm"),height:new R(500,"mm")},b2:{width:new R(500,"mm"),height:new R(707,"mm")},b1:{width:new R(707,"mm"),height:new R(1e3,"mm")},b0:{width:new R(1e3,"mm"),height:new R(1414,"mm")},c10:{width:new R(28,"mm"),height:new R(40,"mm")},c9:{width:new R(40,"mm"),height:new R(57,"mm")},c8:{width:new R(57,"mm"),height:new R(81,"mm")},c7:{width:new R(81,"mm"),height:new R(114,"mm")},c6:{width:new R(114,"mm"),height:new R(162,"mm")},c5:{width:new R(162,"mm"),height:new R(229,"mm")},c4:{width:new R(229,"mm"),height:new R(324,"mm")},c3:{width:new R(324,"mm"),height:new R(458,"mm")},c2:{width:new R(458,"mm"),height:new R(648,"mm")},c1:{width:new R(648,"mm"),height:new R(917,"mm")},c0:{width:new R(917,"mm"),height:new R(1297,"mm")},"jis-b10":{width:new R(32,"mm"),height:new R(45,"mm")},"jis-b9":{width:new R(45,"mm"),height:new R(64,"mm")},"jis-b8":{width:new R(64,"mm"),height:new R(91,"mm")},"jis-b7":{width:new R(91,"mm"),height:new R(128,"mm")},"jis-b6":{width:new R(128,"mm"),height:new R(182,"mm")},"jis-b5":{width:new R(182,"mm"),height:new R(257,"mm")},"jis-b4":{width:new R(257,"mm"),height:new R(364,"mm")},"jis-b3":{width:new R(364,"mm"),height:new R(515,"mm")},"jis-b2":{width:new R(515,"mm"),height:new R(728,"mm")},"jis-b1":{width:new R(728,"mm"),height:new R(1030,"mm")},"jis-b0":{width:new R(1030,"mm"),height:new R(1456,"mm")},letter:{width:new R(8.5,"in"),height:new R(11,"in")},legal:{width:new R(8.5,"in"),height:new R(14,"in")},ledger:{width:new R(11,"in"),height:new R(17,"in")}},h0=new R(.24,"pt"),Lx=new R(3,"mm"),u0=new R(10,"mm"),c0=new R(13,"mm");function Vo(e){let t={width:xr,height:Sr,bleed:Ae,bleedOffset:Ae,cropOffset:Ae},i=e.size;if(!(!i||i.value===y.auto)){let l=i.value,u,c;if(l.isSpaceList()?(u=l.values[0],c=l.values[1]):(u=l,c=null),u.isNumeric())t.width=u,t.height=c||u;else{let p=u.name&&l0[u.name.toLowerCase()];p&&(c&&c===y.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,o=n&&!Z(n.value)?n.value:y.none,s=r&&!Z(r.value)?r.value:y.auto;if(s===y.auto){if(o!==y.none){let l=!1;o.isSpaceList()?l=o.values.some(u=>u===y.crop):l=o===y.crop,l&&(t.bleed=new R(6,"pt"))}}else s.isNumeric()&&(t.bleed=s);let a=e["crop-offset"],h=a&&!Z(a.value)?a.value:y.auto;return h===y.auto?o!==y.none&&(t.bleedOffset=c0):h.isNumeric()&&(t.cropOffset=h),t}function Jh(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),o=n+r,s=e.width;s===xr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:i.pageWidth=s.num*t.queryUnitSize(s.unit,!1);let a=e.height;return a===Sr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function Xp(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function sr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===y.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var Ia=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Ia||{});function d0(e,t,i,n,r,o,s){let a=r;a<=o+2*zt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,u=Xp(e,l,l),c=[[0,o+r],[r,o+r],[r,o+r-a]],p=c.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=sr(e,i,n);f.setAttribute("points",c.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=sr(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${s}px`}),u}var mr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(mr||{});function p0(e,t,i,n,r,o){let s=r*2,a,h;t==="top"||t==="bottom"?(a=s,h=r):(a=r,h=s);let l=Xp(e,a,h),u=sr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let c=sr(e,i,n);c.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(c);let p=sr(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(mr).forEach(g=>{let m=mr[g];m===t?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function f0(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let m=s.value;m instanceof ee?m.values.forEach(w=>{w===y.crop?r=!0:w===y.cross&&(o=!0)}):m===y.crop?r=!0:m===y.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,u=st(h0,n),c=Math.max(0,t.bleedOffset-st(u0,n)),p=t.bleedOffset-c,f=e["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:y.auto;r&&Object.keys(Ia).forEach(m=>{let w=Ia[m],x=d0(l,w,u,g,p,a,c);h.appendChild(x)}),o&&Object.keys(mr).forEach(m=>{let w=mr[m],x=p0(l,w,u,g,p,c);h.appendChild(x)})}var Aa=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),Cl={"top-left-corner":{order:1,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"top-left":{order:2,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"top-center":{order:3,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"top-right":{order:4,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"top-right-corner":{order:5,isInTopRow:!0,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"right-top":{order:6,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"start"},"right-middle":{order:7,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"center"},"right-bottom":{order:8,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:"end"},"bottom-right-corner":{order:9,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!0,positionAlongVariableDimension:null},"bottom-right":{order:10,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"end"},"bottom-center":{order:11,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"center"},"bottom-left":{order:12,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!1,isInRightColumn:!1,positionAlongVariableDimension:"start"},"bottom-left-corner":{order:13,isInTopRow:!1,isInBottomRow:!0,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:null},"left-bottom":{order:14,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"end"},"left-middle":{order:15,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"center"},"left-top":{order:16,isInTopRow:!1,isInBottomRow:!1,isInLeftColumn:!0,isInRightColumn:!1,positionAlongVariableDimension:"start"}},g0=(()=>{let e=Cl;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),kl="vivliostyle-page-rule-master",wr="_marginBoxes",Uo="_footnoteArea",qp=class extends Dp{constructor(e,t,i){super(e,null,kl,[],t,null,0),d(this,"pageMarginBoxes",{});let n=Vo(i),r=new m0(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[wr];t&&g0.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new y0(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new V(y.relative,0),this.specified.width=new V(t.width,0),this.specified.height=new V(t.height,0);for(let i in e)!Aa[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new xn(e,this)}},m0=class extends Ar{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new w0(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new V(y.auto,0),this.specified["z-index"]=new V(new ze(0),0),this.specified.position=new V(y.absolute,0),this.specified.overflow=new V(y.visible,0);for(let t in Aa)Aa.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new b0(e,this)}},w0=class extends Ar{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new V(B("body"),0)}createInstance(e){return new Yp(e,this)}},y0=class extends Ar{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[wr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Sd[i]||r&&r.value===y.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Y&&n.value!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new Zp(e,this)}},xn=class extends xl{constructor(e,t){super(e,t),d(this,"pageAreaDimension",null),d(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=Ae,e["margin-left"]=Ae,e["border-left-width"]=Ae,e["padding-left"]=Ae,e["padding-right"]=Ae,e["border-right-width"]=Ae,e["margin-right"]=Ae,e.right=Ae}initVertical(){let e=this.style;e.top=Ae,e["margin-top"]=Ae,e["border-top-width"]=Ae,e["padding-top"]=Ae,e["padding-bottom"]=Ae,e["border-bottom-width"]=Ae,e["margin-bottom"]=Ae,e.bottom=Ae}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new W(e.borderBoxWidth),t.height=new W(e.borderBoxHeight),t["padding-left"]=new W(e.marginLeft),t["padding-right"]=new W(e.marginRight),t["padding-top"]=new W(e.marginTop),t["padding-bottom"]=new W(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},u={},c={};for(let v in e){let C=Cl[v];if(C){let S=e[v],F=this.pageMarginBoxInstances[v],A=new fo(S,F.style,t,h,r);l[C.positionAlongVariableDimension]=S,u[C.positionAlongVariableDimension]=F,c[C.positionAlongVariableDimension]=A}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,m={};Object.keys(l).forEach(v=>{let C=v,S=ye(h,u[C].style[t?"max-width":"max-height"],i.extent);if(S){let F=S.evaluate(n);if(f[C]>F){let A=c[C]=new Qh(l[C],u[C].style,t,h,r,F);m[C]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,[o,s,a].forEach(v=>{var C;f[v]=(C=m[v])!=null?C:f[v]}));let w={};Object.keys(l).forEach(v=>{let C=v,S=ye(h,u[C].style[t?"min-width":"min-height"],i.extent);if(S){let F=S.evaluate(n);if(f[C]<F){let A=c[C]=new Qh(l[C],u[C].style,t,h,r,F);w[C]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),[o,s,a].forEach(v=>{f[v]=w[v]||f[v]}));let x=p.start+p.extent,b=p.start+(p.start+p.extent);[o,s,a].forEach(v=>{let C=f[v];if(C!=null){let S=l[v],F=0;switch(v){case o:F=t?S.left:S.top;break;case s:F=(b-C)/2;break;case a:F=x-C;break}t?S.setHorizontalPosition(F,C-S.getInsetLeft()-S.getInsetRight()):S.setVerticalPosition(F,C-S.getInsetTop()-S.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,o=e.end,s={};if(r){let a=[n,o],h=new v0(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),c=Math.max((t-u)/2,0);n&&(s.start=n.hasAutoSize()?c:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?c:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof fo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof fo&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},fo=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,d(this,"hasAutoSize_"),d(this,"size",null),d(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===y.auto||Z(o),this.minMaxFitContent=o instanceof ce&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=s[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Qa(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},v0=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},Qh=class extends fo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),d(this,"fixedSize"),this.fixedSize=o}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},b0=class extends In{constructor(e,t){super(e,t),d(this,"borderBoxWidth",null),d(this,"borderBoxHeight",null),d(this,"contentBoxWidth",null),d(this,"contentBoxHeight",null),d(this,"marginTop",null),d(this,"marginRight",null),d(this,"marginBottom",null),d(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=i[s].toExpr(n,null),h=ye(n,t[s],a),l=ye(n,t[`margin-${r}`],a),u=ye(n,t[`margin-${o}`],a),c=bt(n,t[`padding-${r}`],a),p=bt(n,t[`padding-${o}`],a),f=Yt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Yt(n,t[`border-${o}-width`],t[`border-${o}-style`],a),m=ie(n,ie(n,f,c),ie(n,g,p)),w,x,b;return h?(this.borderBoxSizing?(x=h,b=fe(n,x,m)):(b=h,x=ie(n,b,m)),w=fe(n,a,x),!l&&!u?(l=qr(n,w,new Ke(n,.5)),u=l):l?u=fe(n,w,l):l=fe(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=ie(n,l,u),x=fe(n,a,w),b=fe(n,x,m),h=this.borderBoxSizing?x:b),t[r]=new W(l),t[o]=new W(u),t[`margin-${r}`]=Ae,t[`margin-${o}`]=Ae,t[`border-${r}-width`]=new W(f),t[`border-${o}-width`]=new W(g),t[`padding-${r}`]=new W(c),t[`padding-${o}`]=new W(p),t[s]=new W(h),t[`max-${s}`]=new W(h),{borderBoxExtent:x,contentBoxExtent:b,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},Yp=class extends In{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new W(this.parentInstance.contentBoxWidth),e["margin-left"]=new W(new ln(i,t.left.toExpr(i,null))),e["margin-right"]=new W(new ln(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=y.solid,e["border-right-style"]=y.solid,e["border-left-color"]=y.transparent,e["border-right-color"]=y.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new W(this.parentInstance.contentBoxHeight),e["margin-top"]=new W(new ln(i,t.top.toExpr(i,null))),e["margin-bottom"]=new W(new ln(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=y.solid,e["border-bottom-style"]=y.solid,e["border-top-color"]=y.transparent,e["border-bottom-color"]=y.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},Zp=class extends In{constructor(e,t){super(e,t),d(this,"boxInfo"),d(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Cl[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){N(t,"display","flex"),N(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&N(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ht||r instanceof W&&r.expr instanceof Fe&&r.expr.str.startsWith("running-element-")){let o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),N(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ye(n,i[s],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new W(u);else if(l){let c=bt(n,i[`margin-${r}`],h),p=bt(n,i[`margin-${o}`],h),f=bt(n,i[`padding-${r}`],h),g=bt(n,i[`padding-${o}`],h),m=Yt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Yt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),x=ie(n,l,ie(n,this.borderBoxSizing?n.zero:ie(n,ie(n,f,g),ie(n,m,w)),ie(n,c,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new W(ie(n,u,Bs(n,fe(n,h,x),new Ke(n,2))));break;case"end":i[r]=new W(fe(n,ie(n,u,h),x));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,o=e.inside,s=e.outside,a=e.extent,h=t[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=jh(n,i[`margin-${o}`],h),u=jh(n,i[`margin-${s}`],h),c=bt(n,i[`padding-${o}`],h),p=bt(n,i[`padding-${s}`],h),f=Yt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=Yt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=ye(n,i[a],h),w=null;function x(b){if(w)return w;w={extent:m?m.evaluate(b):null,marginInside:l?l.evaluate(b):null,marginOutside:u?u.evaluate(b):null};let v=h.evaluate(b),C=0;return r||[f,c,p,g].forEach(S=>{S&&(C+=S.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&C+w.extent+w.marginInside+w.marginOutside>v&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=v-C-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=v-C-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=v-C-w.extent-w.marginInside:w.marginInside=w.marginOutside=(v-C-w.extent)/2),w}i[a]=new W(new Fe(n,function(){let b=x(this).extent;return b===null?"auto":b},a)),i[`margin-${o}`]=new W(new Fe(n,function(){let b=x(this).marginInside;return b===null?"auto":b},`margin-${o}`)),i[`margin-${s}`]=new W(new Fe(n,function(){let b=x(this).marginOutside;return b===null?"auto":b},`margin-${s}`)),o==="left"?i.left=new W(ie(n,t.marginLeft,t.borderBoxWidth)):o==="top"&&(i.top=new W(ie(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,o,s){super.finishContainer(e,t,i,n,r,o,s);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let u=this.parentInstance.pageAreaDimension,c=this.getProp(e,"width"),p=c instanceof ce&&(c.name==="min-content"||c.name==="max-content"||c.name==="fit-content")?c.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&N(t.element,"width",p),f&&N(t.element,"min-width",`${f}px`),g&&N(t.element,"max-width",`${g}px`);let v=this.getProp(e,"margin-left"),C=this.getProp(e,"margin-right");if(l.isInLeftColumn){let S=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);N(t.element,"right",`${S}px`),(v===y.auto||C!==y.auto)&&N(t.element,"margin-left","auto"),C===y.auto&&N(t.element,"margin-right","auto")}else l.isInRightColumn&&(N(t.element,"right","0"),(C===y.auto||v!==y.auto)&&N(t.element,"margin-right","auto"),v===y.auto&&N(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof ce&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,x=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||x||b){w&&N(t.element,"height",w),x&&N(t.element,"min-height",`${x}px`),b&&N(t.element,"max-height",`${b}px`);let v=this.getProp(e,"margin-top"),C=this.getProp(e,"margin-bottom");if(l.isInTopRow){let S=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);N(t.element,"bottom",`${S}px`),(v===y.auto||C!==y.auto)&&N(t.element,"margin-top","auto"),C===y.auto&&N(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(N(t.element,"bottom","0"),(C===y.auto||v!==y.auto)&&N(t.element,"margin-bottom","auto"),v===y.auto&&N(t.element,"margin-top","auto"))}}},x0=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,d(this,"pageMasterCache",{}),d(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new qe(e,"page-number"),r=new Wa(e,new Vu(e,n,new Ke(e,2)),i?e.one:e.zero);e.defineName("recto-page",new yi(e,r)),e.defineName("verso-page",r),(t.pageProgression||jp(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new yi(e,r))):(e.defineName("left-page",new yi(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),r=this.pageMasterCache[n];return r||(i.pseudoName===bl?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof V?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new qp(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:kl}),n=i.specified,r=e.size;if(r&&!Z(r.value)){let s=Vo(e),a=r.priority;Ut(n,"width",new V(s.width,a),this.context),Ut(n,"height",new V(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(e[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},S0=class extends xe{constructor(e){super(),this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},C0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},k0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},E0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},P0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},N0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},T0=class extends xe{constructor(e){super(),this.scope=e}apply(e){new qe(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},I0=class extends ji{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},A0=class extends ji{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},F0=class extends hl{constructor(e,t){super(e,t,null,null,null)}apply(e){R0(e.context,e.currentStyle,this.style,this.specificity,e)}};function R0(e,t,i,n,r){Fo(e,t,i,n,null,null,null);let o=i[wr];if(o){let a=Kt(t,wr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),Fo(e,l,o[h],n,null,null,null)}}let s=i[Uo];if(s){let a=Kt(t,Uo);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=s[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof V&&Ut(l,p,f)}let c=pt(u,"_pseudos");if(c){let p=Kt(l,"_pseudos");for(let f in c)if(c.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=c[f];for(let w in m)if(m.hasOwnProperty(w)){let x=m[w];x instanceof V&&Ut(g,w,x)}}}}}}var L0=class extends dr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,d(this,"currentPageSelectors",[]),d(this,"currentNamedPageSelector",""),d(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new S0(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new A0(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new I0(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new C0(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new k0(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new E0(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new P0(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new N0(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new T0(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(o=>o.selectors===null))return;super.simpleProperty(e,t,i);let n=ge(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{bi(r[o],e,n)});else if(e==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=new V(n.value,n.priority+s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?Ut(l,e,a):(l=r[h]={},bi(l,e,a),o&&["bleed","marks"].forEach(u=>{o[u]&&bi(l,u,o[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new F0(this.elementStyle,e)}startFootnoteRule(e){let t=Kt(this.elementStyle,Uo),i=t.area;if(i||(i={},t.area=i),e){let r=Kt(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new Kp(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=Kt(this.elementStyle,wr),i=t[e];i||(i={},t[e]=i);let n=new O0(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},O0=class extends Gi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(t,n);bi(this.boxStyle,e,r)}},Kp=class extends Gi{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(t,n);bi(this.areaStyle,e,r)}},ai=!0;function B0(e){ai=e}var Di=[];function eu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Jp(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function El(e,t,i){if(!ai||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Jp(e.ownerDocument).includes(e))return T(!1);let n=e.textContent,r=e.src,o=e.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&e.async&&!s,h=(o&&!a||r&&e.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Qp(t)||(t.onload=null),l)return Di.some(c=>eu(c,e))||Di.push(e),T(!0);for(let c of t.document.head.getElementsByTagName("script"))c.hasAttribute("data-vivliostyle-scripting")&&eu(c,e)&&t.document.head.removeChild(c);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=h,u.setAttribute("data-vivliostyle-scripting","true");for(let c of e.attributes)["src","async","defer"].includes(c.name)||u.setAttribute(c.name,c.value);if(G.debug("script:",r),r){let c=Wt(u);return t.document.head.appendChild(u),Cn([c])}else return t.document.head.appendChild(u),T(!0)}function M0(e,t){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let u of Object.values(l))r(u)},o=s=>{if(s instanceof hl)r(s.style);else if(s instanceof Ln||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(t.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of e.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function _0(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=M0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function D0(e,t,i){if(!ai)return T(!1);let n=Jp(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?_0(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=_("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var c,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(c=t.FontJSON)!=null&&c.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return El(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Di.push(u),h=!0),n.length===0&&r&&(G.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function z0(e){if(!ai)return T(!1);let t=_("loadScripts");return t.loop(()=>Di.length===0?T(!1):El(Di.shift(),e,{atEnd:!0}).thenReturn(Di.length>0)).then(()=>{G.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),G.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Qp(e){return ai?Di.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var V0=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url("${i.transformURL(r,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url('${i.transformURL(r,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${i.transformURL(r,t)}`),U0={};function H0(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Fa=class Yn extends Va{constructor(t,i,n,r,o,s,a,h,l,u,c,p,f,g,m,w=new Map,x={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=o,this.xmldoc=s,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=c,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=x,d(this,"document"),d(this,"exprContentListener"),d(this,"computedStyleParentFontSizeOverride",null),d(this,"computedStyleParentLineHeightOverride",null),d(this,"nodeContext",null),d(this,"viewRoot",null),d(this,"isFootnote",!1),d(this,"sourceNode",null),d(this,"offsetInNode",0),d(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new Yn(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!Lt(t)||!mh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(tr);if(!i)return;let n=wd(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(tr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,u;let c=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!c)return h;let p=[],f=Gn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,m=Lt(t)&&!!c["footnote-call"]&&St((l=c["footnote-call"].content)==null?void 0:l.value);for(let b of tv){let v;if(b){if(!c[b])continue;let C=yt(t),S=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(b=="footnote-call"&&!Lt(t)||b=="footnote-marker"&&!(C||S||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(b.match(/^first-/)){let F=r.display;if(!F||F===y.inline)continue;let A=t.firstElementChild;if(A&&Ve(A.previousSibling)){let D=o.getStyle(A,!1);if(D){let H=ge(D,"display");if(H!=null&&H.value&&H.value!==y.inline)continue}}}if(b==="before"||b==="after"||b==="footnote-call"||b==="footnote-marker"){let F=c[b].content,A=(b==="before"||b==="after")&&(r.float===y.footnote||C||S)&&!!F;if(!F||!St(F.value)&&!A)continue}p.push(b),v=Gn.createElementNS("http://www.w3.org/1999/xhtml","span"),nr(v,b)}else{if(m)continue;v=Gn.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(v),b.match(/^first-/)&&(g=v)}if(!p.length)return h;let w=new xs(t,n,o,s,this.exprContentListener),x=new Zr(t,f,null,a,h,rt.ROOTLESS,w);return h||x}getPseudoMap(t,i,n,r,o){let s=pt(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};ir(l,s[h],o),ua(l,o,s[h]),jd(s[h],i,n,(u,c)=>{ir(l,c,o),$d(c,p=>{ir(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=_("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);o=new Zr(n,l,h,r,o,i,u)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=_("createShadows"),l=null,u=r.template,c;if(u instanceof ht||u===y.footnote)if(u!==y.footnote||mh(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof ht?u.url:Ne("user-agent.xml#footnote",mi);c=this.createRefShadow(p,rt.ROOTLESS,t,a,l)}else c=T(l);else c=T(l);return c.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=yo(m,w.url),f=this.createRefShadow(m,rt.ROOTED,t,a,p))}f==null&&(f=T(p));let g=null;f.then(m=>{if(r.display===y.table_cell){let w=Ne("user-agent.xml#table-cell",mi);g=this.createRefShadow(w,rt.ROOTLESS,t,a,m)}else g=T(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,o,s,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var o;let s=this.context,a=ca(n,s,this.regionIds,this.isFootnote,this.nodeContext),h=!((o=this.nodeContext)!=null&&o.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=Wd(a,s,t);let u=!h&&t!==l;i=Gd(a,s,i);let c=(x,b)=>{let v;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(v=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(v=s.pageAreaWidth));let C=b.evaluate(s,x,v,t);return x=="font-family"&&(C=this.docFaces.filterFontFamily(C)),C},p=!!new qe(s.style.pageScope,"left-page").evaluate(s);if(Xd(a,r,t,i,p,c),u){let x=r[t?"height":"width"];(!x||x===y.auto)&&(r[t?"height":"width"]=y.max_content)}if(So(r.position))return r.position=y.fixed,r.visibility=y.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),w=Hc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{w[x]&&(r[x]=w[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&Lt(w)){let x=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let b=yo(x,this.xmldoc.url),v=this.xmldoc.getElement(b);v&&yt(v)&&((n=v.parentNode)==null?void 0:n.nodeType)===1&&(r=v.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,x=!!w&&l.type==rt.ROOTED&&yt(r);if(!w||l.type==rt.ROOTLESS||x){let b=(l?l.styler:this.styler).getStyle(r,!1);o.push(b),s=s||As(r)}w&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let c=new Set;if(o.length>0){let w=o[0],x=ca(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let b in x){if(!fn(b))continue;let v=x[b].evaluate(this.context,b);v&&v!==y.inherit&&v!==y.unset&&v!==y.revert&&v!==Y&&c.add(b)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new V(new R(f,"px"),0)};p&&(g["line-height"]=new V(new xt(this.context.pref.lineHeight),0));let m=new hy(g,this.context);for(let w=o.length-1;w>=0;--w){let x=o[w],b=[];for(let S in x)fn(S)&&b.push(S);b.sort($l);let v,C;for(let S of b){if(w>0&&h&&S.startsWith("--viv-marker-")||w>0&&c.has(S))continue;m.setPropName(S);let F=ge(x,S),A=F;if(F.value===y.initial)delete g[S];else if(!Z(F.value)){if(S==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)A=new V(new R(this.context.rootFontSize,"px"),F.priority);else if(S==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&F.value instanceof R&&(F.value.unit==="lh"||F.value.unit==="rlh"))A=new V(new R(this.context.rootLineHeight,"px"),F.priority);else if(w===0&&F.value instanceof R&&F.value.unit==="lh"){let D=this.getLineHeightUnitSize(S,v,C);D!=null&&(A=new V(new R(F.value.num*D,"px"),F.priority))}else Zt(S)||(A=F.filterValue(m));S==="font-size"?v=A.value:S==="line-height"&&(C=A.value),g[S]=A}}}for(let w in t)fn(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ne(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=As(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Jw().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let o=t[r];if(o){if(Z(o))o===y.initial&&(n[r]=void 0);else if(o instanceof ze)n[r]=o.num;else if(o instanceof ce)n[r]=o.name;else if(o instanceof R){let s=o;switch(s.unit){case"dpi":case"dpcm":case"dppx":n[r]=s.num*zt[s.unit];break;default:n[r]=o}}else n[r]=o;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,o,s){let a=Ot("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,o,s);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let o=!0,s=_("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(this.syncSemanticFootnoteCounterToTarget(a),!this.nodeContext.shadowContext){let C=this.xmldoc.getElementOffset(a);Qo.registerFragmentIndex(C,this.nodeContext.fragmentIndex,0)}let u={},c={getStyle:C=>this.styler.getStyle(C,!1),getProp:(C,S)=>C?ge(C,S):null,getStyleMap:(C,S)=>pt(C,S),getMutableStyleMap:(C,S)=>Kt(C,S),createCascadeValue:(C,S)=>new V(C,S),filterFootnoteMarkerContent:(C,S)=>C.filterValue(new cr(this.styler.cascade,S,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let C=this.inheritFromSourceParent(l);l=C.elementStyle,this.nodeContext.lang=C.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!Z(f.value)&&f.value!==y.none&&g&&!Z(g.value)?Lw(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===rt.ROOTED&&yt(a);if(this.nodeContext.parent&&(So(p?.value)||m&&vi(m)||w)){let C=this.inheritFromSourceParent(l);l=C.elementStyle,this.nodeContext.lang=C.lang}l=_w(a,l,this.nodeContext.shadowContext,this.xmldoc.url,C=>this.xmldoc.getElement(C),tr,c),l=Dw(a,l,this.nodeContext.shadowContext,this.context,c),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),m&&vi(m)&&u.display===y.block&&(u.display=y.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let x=u["flow-into"];if(x&&x.toString()!=this.flowName)return s.finish(!1),s.result();if(ai&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return El(a,this.viewport.window).thenFinish(s),s.result();let b=u.display;if(yt(a)&&!w&&a.hasAttribute(md)&&(b=u.display=y.none),Z(b)&&(b===y.initial||b===y.unset?b=y.inline:b===y.inherit?b=((n=this.nodeContext.parent)==null?void 0:n.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):b=null),b===y.none)return s.finish(!1),s.result();let v=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===y.flex,this.createShadows(a,v,l,u,h,this.context,this.nodeContext.shadowContext).then(C=>{var S;this.nodeContext.nodeShadow=C;let F=u.position,A=u.float,D=u.clear,H=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,q=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:H,Se=Zm(a),se=u["column-count"],k=u["column-width"],M=se&&se!==y.auto&&!Z(se)||k&&k!==y.auto&&!Z(k);this.nodeContext.establishesBFC=Jm(b,F,A,u.overflow,H,q,M||Se),this.nodeContext.containingBlockForAbsolute=Qm(F),this.nodeContext.isInsideBFC()&&A!==y.footnote&&!(m&&vi(m))&&(A=null,D=null);let E=null,L=!1,P=this.isFootnote&&(!((S=this.nodeContext)!=null&&S.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),I=zw(a,this.nodeContext.shadowContext,c);Vw(I.sourceStyle,u,this.context),E=I.footnoteDisplay;let O=A instanceof ee||A===y.left||A===y.right||A===y.top||A===y.bottom||A===y.inline_start||A===y.inline_end||A===y.block_start||A===y.block_end||A===y.snap_block||A===y.snap_inline||A===y.inside||A===y.outside||A===y.footnote;if(A&&(delete u.float,A===y.footnote))if(E=u["footnote-display"]||E,L=!!u["--viv-marker-content"],P){O=!1;let j=E?.toString();j&&(u["--viv-footnote-display"]=B(j)),b=L?B("list-item"):j==="inline"||j==="compact"?y.inline:y.block,u.display=b}else u.display=y.inline;if(P&&yt(a)){L=L||!!u["--viv-marker-content"];let j=E?.toString();j&&(u["--viv-footnote-display"]=B(j)),L&&(b=u.display=B("list-item")),!L&&(j==="inline"||j==="compact")&&(b=u.display=y.inline)}D&&(D===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(D=B(this.nodeContext.parent.clearSide)),(D===y.left||D===y.right||D===y.top||D===y.bottom||D===y.inline_start||D===y.inline_end||D===y.block_start||D===y.block_end||D===y.inside||D===y.outside||D===y.both||D===y.all||D===y.same||D===y.column||D===y.region||D===y.page)&&(delete u.clear,(O||u.display&&u.display!=y.inline)&&(this.nodeContext.clearSide=D.toString())));let z=$n(b)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),$=u["break-inside"];(O||$&&!Z($)&&$!==y.auto)&&this.nodeContext.breakPenalty++,b&&b!==y.inline&&Dt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!O&&!b||Dt(b)||Wc(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=O?A.toString():null,this.nodeContext.floatReference=m||Pe.INLINE;let K=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=K&&!Z(K)?K:null;let J=this.isInsideNonRootMultiColumn(),Q=u["column-span"];if(this.nodeContext.columnSpan=!J&&Q&&!Z(Q)?Q:null,!this.nodeContext.inline){let j=u["break-after"];j&&!Z(j)&&!(J&&j===y.column)&&(this.nodeContext.breakAfter=j.toString(),qs[this.nodeContext.breakAfter]&&(u["break-after"]=y.column));let Tt=u["break-before"];Tt&&!Z(Tt)&&!(J&&Tt===y.column)&&(this.nodeContext.breakBefore=Tt.toString(),qs[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let _t=u.page,Ct=_t&&!Z(_t)&&_t.toString();!Ct&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===y.table_header_group||b===y.table_footer_group)&&(Ct=this.styler.cascade.currentPageType),!Ct||Ct.toLowerCase()==="auto"?Ct=this.nodeContext.pageType:this.nodeContext.pageType=Ct,this.styler.cascade.currentPageType!==Ct&&!(!Ct&&u.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!En(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Ct!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Ct)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let de=u["border-collapse"];if(!de||de===B("separate")){let j=u["border-spacing"],Tt,_t;j&&(j instanceof ee?(Tt=j.values[0],_t=j.values[1]):Tt=_t=j,Tt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=st(Tt,this.context)),_t.isNumeric()&&(this.nodeContext.blockBorderSpacing=st(_t,this.context)))}let re=u["footnote-policy"]||I.footnotePolicy;re&&!Z(re)&&(u["--viv-footnote-policy"]=re),this.nodeContext.footnotePolicy=re&&!Z(re)?re:null;let oe=u["x-first-pseudo"];if(oe){let j=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Tw(j,oe.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Oe=u["white-space"];if(Oe){let j=rd(Oe.toString());j!==null&&(this.nodeContext.whitespace=j)}let Re=u["hyphenate-character"];Re&&Re instanceof X&&(this.nodeContext.hyphenateCharacter=Re.str);let pe=u["word-break"],Ce=u["line-break"],me=u["overflow-wrap"];(pe===y.break_all||Ce===y.anywhere||me===y.break_word||me===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,F,A,v),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let he=!1,ke=null,we=[],Te=a.namespaceURI,te=a.localName,Fr=te;Te=="http://www.w3.org/1999/xhtml"?(te=="html"||te=="body"||te=="script"||te=="link"||te=="meta"?te="div":te=="vide_"?te="video":te=="audi_"?te="audio":te=="object"&&(he=!!this.customRenderer),a.hasAttribute(pl)&&a.hasAttribute("src")&&u.content instanceof ht&&(te="img")):Te=="http://www.idpf.org/2007/ops"?(te="span",Te="http://www.w3.org/1999/xhtml"):Te=="http://www.pyroxy.com/ns/shadow"?(Te="http://www.w3.org/1999/xhtml",te=this.nodeContext.inline?"span":"div"):he=!!this.customRenderer,z?t?(te="li",u["--viv-marker-content"]&&(u["list-style-type"]=y.none,u["list-style-image"]=y.none)):(b=Dt(b)?y.inline:y.block,u.display=b,te="div"):te=="body"||te=="li"?te="div":te=="q"&&(te="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(he=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(he=!0);let rs;if(he){let j=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;rs=this.customRenderer(a,j,u)}else rs=T(null);rs.then(j=>{var Tt,_t,Ct;if(j)he&&(o=j.getAttribute("data-adapt-process-children")=="true");else if(u.display===y.none){s.finish(!1);return}else j=this.createElement(Te,te);if(!v&&M&&u["column-fill"]===y.auto){let Je=this.nodeContext.vertical?u.width:u.height;(!Je||Je===y.auto||Z(Je))&&(j.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=y.balance)}te!=Fr&&(j.setAttribute("data-vivliostyle-original-tag",Fr),(Fr==="html"||Fr==="body")&&(j.role="presentation")),te=="a"&&j.addEventListener("click",this.page.hrefHandler,!1),ke&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ke),j.appendChild(ke)),j.localName=="iframe"&&j.namespaceURI=="http://www.w3.org/1999/xhtml"&&H0(j);let Rr=this.nodeContext.inheritedProps["image-resolution"],os=[],ss=u.width,as=u.height,df=a.getAttribute("width"),pf=a.getAttribute("height"),ls=ss===y.auto||!ss&&!df,hs=as===y.auto||!as&&!pf,Tl=a.attributes,ff=Tl.length,Lr=null,Il=null;b===y.table_cell&&((Ct=(_t=(Tt=this.nodeContext.parent)==null?void 0:Tt.viewNode)==null?void 0:_t.lastElementChild)==null?void 0:Ct.localName)==="a"&&j.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Je=0;Je<ff;Je++){let ft=Tl[Je],gt=ft.namespaceURI,le=ft.localName,Ge=ft.nodeValue;if(gt){if(gt=="http://www.w3.org/2000/xmlns/")continue;gt=="http://www.w3.org/1999/xlink"&&le=="href"&&(Ge=this.documentURLTransformer.transformURL(this.resolveURL(Ge),this.xmldoc.url))}else{if(!ai&&le.match(/^on/)||le=="style")continue;if((le=="id"||le=="name")&&t){let Qe=this.documentURLTransformer.transformFragment(Ge,this.xmldoc.url);j.setAttribute(le,Ge),j.setAttribute("data-vivliostyle-id",Qe);let Ci=j.ownerDocument.createElement("a");Ci.setAttribute(le,Qe),Ci.setAttribute(kn,"1"),Ci.style.position="absolute",j.appendChild(Ci),this.page.registerElementWithId(j,Qe);continue}if(le=="src"||le=="href"||le=="poster")Ge=this.resolveURL(Ge),le==="href"&&(Ge=this.documentURLTransformer.transformURL(Ge,this.xmldoc.url));else if(le=="srcset")Ge=Ge.split(",").map(Qe=>this.resolveURL(Qe.trim())).join(",");else if(le==="data"&&he&&te==="object"&&j.hasAttribute("data"))continue;if(le==="poster"&&te==="video"&&Te==="http://www.w3.org/1999/xhtml"&&ls&&hs){let Qe=new Image,Ci=Wt(Qe,Ge);we.push(Ci),os.push({image:Qe,element:j,fetcher:Ci})}}if(Te=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(le)&&(le=le.toLowerCase()),this.isSVGUrlAttribute(le)&&(Ge=V0(Ge,this.xmldoc.url,this.documentURLTransformer)),gt){let Qe=U0[gt];Qe&&(le=`${Qe}:${le}`)}if(le=="src"&&!gt&&(te=="img"||te=="input")&&Te=="http://www.w3.org/1999/xhtml")Lr=Ge;else if(le=="alt"&&!gt&&te=="img"&&Te=="http://www.w3.org/1999/xhtml")Il=Ge;else if(le=="href"&&te=="image"&&Te=="http://www.w3.org/2000/svg"&&gt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Wt(j,Ge));else if(gt)j.setAttributeNS(gt,le,Ge);else try{j.setAttribute(le,Ge)}catch(Qe){G.warn(Qe)}}if(Lr){let Je=te==="input"?new Image:j,ft=Wt(Je,Lr,Il);Je!==j&&(j.src=Lr);let gt=()=>{var le,Ge;if(u.position===y.fixed)return!0;for(let Qe=(le=this.nodeContext.parent)==null?void 0:le.viewNode;Qe&&Qe!==this.viewRoot;Qe=Qe.parentElement)if(((Ge=Qe.style)==null?void 0:Ge.position)==="fixed")return!0;return!1};!ls&&!hs&&!(()=>{let le=this.nodeContext.vertical?ss:as;return le instanceof R&&le.unit==="%"})()&&!gt()?this.page.fetchers.push(ft):(ls&&hs&&Rr&&Rr!==1&&os.push({image:Je,element:j,fetcher:ft}),we.push(ft))}delete u.content;let Or=u["--viv-marker-content"];if(Or){let Je=Or instanceof ee?Or.values:[Or];for(let ft of Je)ft instanceof ht&&ft.url&&we.push(Wt(new Image,ft.url))}if(this.preprocessElementStyle(u),this.applyComputedStyles(j,u),this.nodeContext.inline)t||(mt(j,"inline-start"),dn(j)&&mt(j,"clone"));else if(t){if(!Yo(u.position)){let Je=u["margin-break"],ft=this.getBreakTypeAt(this.nodeContext),gt=ft!==null,le=ft==="auto";(Je===y.discard&&gt||Je!==y.keep&&le&&!this.nodeContext.floatSide)&&ms(j,"block-start")}}else{let Je=this.nodeContext.vertical?"width":"height";pi(j,Je)&&N(j,Je,this.nodeContext.display==="table-row"?"0.01px":""),mt(j,"block-start"),dn(j)&&mt(j,"clone"),ms(j,"block-start")}z&&u["ua-list-item-count"]&&j.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=j,we.length?Cn(we).then(()=>{Rr>0&&this.modifyElemDimensionWithImageResolution(os,Rr,u,this.nodeContext.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Ve(r,n.parent.whitespace)||ci(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Jo(i))}getBreakTypeAt(t){var i,n,r,o,s;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Xe(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let u=this.viewport.window.getComputedStyle(l),c=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(c||p)return null;let f=l?.firstChild;for(;f&&(Ve(f,h.parent.whitespace)||!h.floatSide&&ci(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(s=(o=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:s.startBreakType;return Xe(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let s=new xs(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new nv(t,s)}}isSVGUrlAttribute(t){return Yn.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=st(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=st(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(h+=st(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(h+=st(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||y.none,c=n["max-height"]||y.none;if(u===y.none&&c===y.none)N(l,"max-width",`${a}px`);else if(u!==y.none&&c===y.none)N(l,"width",`${a}px`);else if(u===y.none&&c!==y.none)N(l,"height",`${h}px`);else{u.isNumeric(),c.isNumeric();let p=u,f=c;p.unit!=="%"?N(l,"max-width",`${Math.min(a,st(p,this.context))}px`):f.unit!=="%"?N(l,"max-height",`${Math.min(h,st(f,this.context))}px`):r?N(l,"height",`${h}px`):N(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ae,c=n["min-height"]||Ae;u.isNumeric(),u.isNumeric();let p=u,f=c;p.num===0&&f.num===0?N(l,"min-width",`${a}px`):p.num!==0&&f.num===0?N(l,"width",`${a}px`):p.num===0&&f.num!==0?N(l,"height",`${h}px`):p.unit!=="%"?N(l,"min-width",`${Math.max(a,st(p,this.context))}px`):f.unit!=="%"?N(l,"min-height",`${Math.max(h,st(f,this.context))}px`):r?N(l,"height",`${h}px`):N(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Ot("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof Ui&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.formattingContext;this.nodeContext.formattingContext=new Ui(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==y.none&&((i===y.auto||Z(i))&&(t.display===y.table_header_group?i=y.header:t.display===y.table_footer_group?i=y.footer:i=y.none),i&&i!==y.none)?i.toString():null}createTextNodeView(){let t=_("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=fh(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let t,i=t=this.sourceNode.textContent,n=_("preprocessTextContent"),r=Ot("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=r.length?T(!1):r[o++](this.nodeContext,i).thenAsync(s=>(i=s,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=mw(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=_("createNodeView"),r,o=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=T(!0)):r=this.createTextNodeView(),r.then(s=>{var a;if(o=s,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(c,p)=>c?.nodeType===1&&Xt(c)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Ve(this.viewNode))&&!u.hasChildNodes()&&ed(u).includes("block-start")&&mt(u,"text-start"),u.appendChild(this.viewNode),nw(this.viewNode))}n.finish(o)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):T(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,o,s,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.subShadow.root,s=n.subShadow.type,s==rt.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,s=rt.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:o?t=null:(t=t.parent.modify(),t.after=!0),o){let l=new on(o,r,i);return l.shadowContext=a,l.shadowType=s,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=rt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let r=t.nodeShadow.root;if(t.nodeShadow.type==rt.ROOTLESS&&(r=r.firstChild),r){let o=new on(r,t,i);return o.shadowContext=t.nodeShadow,o.shadowType=t.nodeShadow.type,this.processShadowContent(o)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new on(n,t,i));if(t.sourceNode.nodeType!=1){let r=fh(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let o=r;return Xt(o)==="footnote-call"&&o.getAttribute(Yn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&yt(i)}insertFootnoteCall(t){var i,n;let r=_("insertFootnoteCall"),o=Gn.createElementNS("http://www.w3.org/1999/xhtml","span");nr(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(Yn.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new on(o,t.parent,t.boxOffset);a.inline=!0;let h=new xs(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Zr(t.sourceNode,o,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,rt.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return T(n);let r=_("nextInTree");return this.setCurrent(n,!0,i).then(o=>{if((!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let s=this.findImmediateFootnoteCallSibling(n);s!=null&&s.parentNode&&s.parentNode.removeChild(s),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){if(t instanceof it){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ht){let i=t.url;this.page.fetchers.push(Wt(new Image,i))}}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i.position===y.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),l=Object.keys(i);l.sort($l);let u,c;for(let p of l){if(W0[p])continue;let f=i[p];if(!(!f||f===Y&&!Zt(p))){if(f=f.visit(new Bg(this.xmldoc.url,this.documentURLTransformer)),f instanceof R)if(f.unit==="em"){let g=this.getEmUnitSize(p,u);g!=null&&(f=new R(f.num*g,"px"))}else if(f.unit==="lh"){let g=this.getLineHeightUnitSize(p,u,c);g!=null&&(f=new R(f.num*g,"px"))}else Lu(f.unit)&&(f=Ku(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:c=f,this.viewport.layoutUnitAdj&&f instanceof R&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new Ki(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),vw[p]||a&&bw[p]){this.page.delayedItems.push(new el(t,p,f));continue}h&&this.page.pageAreaElement&&fn(p)?(N(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()),p!=="writing-mode"&&p!=="direction"&&N(this.viewport.layoutBox,p,f.toString())):N(t,p,f.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(t,i){var n,r,o;let s=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var t,i,n;return((n=(i=(t=this.nodeContext)==null?void 0:t.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(t){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:t?this.parsePlusLayoutUnitAdj(t.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:t?this.parsePlusLayoutUnitAdj(t.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(t,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let u=null;if(n)if(n instanceof xt||n instanceof R&&(n.unit==="em"||n.unit==="%"))u=n instanceof R&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof R&&n.unit!=="lh"){let c=this.context.queryUnitSize(n.unit,!1);if(c!=null)return n.num*c}return null}if(u==null)for(let c=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;c&&c.nodeType===1;c=c.parentNode){let p=(s=c?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(u=parseFloat(p));break}}if(u!=null){if(i&&!(i instanceof R))return null;let c=h.fontSize;if(i instanceof R){let p=oa(i,c,this.context).num;return typeof p!="number"||isNaN(p)?null:u*p}else return c==null?null:u*c}return l}getEmUnitSize(t,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(t==="font-size"||i==null)return r;if(i instanceof R){let o=oa(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),s=pt(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;St(h)&&(h.visit(new ur(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=_("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let c=t.viewNode.textContent;t.viewNode.textContent=c.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let c=t.viewNode.parentNode;c&&c.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new on(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=s),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let c=this.setCurrent(t,!1);if(c.isPending())return c}return T(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=pt(this.cascadedPageStyle,Uo);p&&p.area&&(a=p.area)}let h=pt(a,"_pseudos");t=this.computeStyle(t,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new R(l.fontSize,"px")),delete o.content;let u=this.computedStyleParentFontSizeOverride,c=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ge(f,"display"),m={},w=this.createElement("http://www.w3.org/1999/xhtml","span");nr(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,m),g||(m.display=y.block);let x=ge(f,"content");if(x){let v=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=x.filterValue(new cr(this.styler.cascade,v,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let b=m.content;if(St(b)){b.visit(new ur(w,this.context,b,this.exprContentListener));let v=w.querySelectorAll("img[src]");for(let S=0;S<v.length;S++){let F=v[S],A=F.getAttribute("src");if(!A)continue;let D=Wt(F,A);s.push(D),this.page.fetchers.push(D)}let C=w.getAttribute("src");if(C){let S=w.querySelector("img");S||(S=this.document.createElement("img"),S.setAttribute("src",C),w.appendChild(S));let F=Wt(S,C);s.push(F),this.page.fetchers.push(F)}}delete m.content,this.applyComputedStyles(w,m)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=c}return s.length?Cn(s).thenReturn(t):T(t)}processFragmentedBlockEdge(t){var i,n,r;let o=!t.inline&&t.after?t.parent:t,s=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=ge(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Dt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(mt(l,"inline-end"),dn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;mt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(pi(l,u)&&N(l,u,""),mt(l,"block-end"),!a++&&h!==o){let{textAlign:c}=this.viewport.window.getComputedStyle(l);if(c==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?td(p,["block-start","text-start","block-end","text-end","justify"]):(mt(l,"text-end"),mt(l,"justify")):mt(l,"text-end")}else mt(l,"text-end")}dn(l)&&mt(l,"clone"),ms(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||Bi[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&Ve(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let c=i(u);if(c||c===null)return null}return!1}if(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(kn)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Ve(l.nextSibling))?i(l):!1}return!(!s||Dt(s))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ve(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,o=t.unit;if(Qf(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,ll(t,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Xt(n)===Xt(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!Xt(t)}};d(Fa,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),d(Fa,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var $0=Fa,W0={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},G0=class{constructor(e){d(this,"layoutBox"),d(this,"window"),d(this,"pixelRatio"),d(this,"scaleRatio"),d(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.subtractOffsets(n,i))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},Ho=class{constructor(e,t,i,n,r,o){if(this.window=e,this.fontSize=t,this.pixelRatio=i,d(this,"document"),d(this,"root"),d(this,"outerZoomBox"),d(this,"contentContainer"),d(this,"layoutBox"),d(this,"width"),d(this,"height"),d(this,"scaleRatio",1),d(this,"layoutUnitPerPixel",64),d(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(N(this.root,"--viv-outputPixelRatio",`${i}`),N(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Da){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&N(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=o||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!o&&u)&&(this.height=l.height)}resetZoom(){N(this.outerZoomBox,"width",""),N(this.outerZoomBox,"height",""),N(this.contentContainer,"width",""),N(this.contentContainer,"height",""),N(this.contentContainer,"transform","")}zoom(e,t,i){N(this.root,"--viv-outputScale",`${i}`),N(this.outerZoomBox,"width",`${e*i}px`),N(this.outerZoomBox,"height",`${t*i}px`),N(this.contentContainer,"width",`${e}px`),N(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},ef=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,d(this,"lang",null),d(this,"totalOffset",-1),d(this,"root"),d(this,"body"),d(this,"head"),d(this,"last"),d(this,"lastOffset",1),d(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(jt,"0")}doc(){return new nf([this.document])}getElementOffset(e){let t=e.getAttribute(jt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(jt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=oi(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Ra=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(Ra||{});function Wr(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let o=r.documentElement,s="parsererror";if(o.localName===s)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===s)return null}else return null;return r}function j0(e){let t=e.contentType;if(t){let n=Object.keys(Ra);for(let r=0;r<n.length;r++)if(Ra[n[r]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function tf(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=j0(e);if(i=Wr(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Wr(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Wr(o,"image/svg+xml",r))}i||(i=Wr(o,"text/html",r))}}let n=i?new ef(t,e.url,i):null;return T(n)}function X0(){return new qa(tf,"document")}var q0=class La{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new La(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new La(n=>{if(!this.check(n))return!1;let r=new nf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},tu=new q0(e=>!0),nf=class Oa{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Oa(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new Oa(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},Y0=new Er(()=>{let e=_("uaStylesheetBase"),t=Mp(),i=Ne("user-agent-base.css",mi),n=new dr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Vy(n.cascade),Za(Fc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Z0(){return Y0.get()}var K0=class extends Qr{constructor(e,t,i,n,r,o){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=o}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||G.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},J0=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=o,this.footnoteProps=s,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,d(this,"fontDeobfuscator"),d(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(c);return p.matchPageSide(f.startSideOfFlow(c))&&f.hasContent(c,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Fe(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Fe(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Ls(this.rootScope,e,t,i),o=ly(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let u=zt.em;if((h?h.evaluate(r,"text-zoom"):null)===y.scale&&(l=u/i,i=u,e*=l,t*=l),s&&a){let c=st(s.evaluate(r,"width"),r),p=st(a.evaluate(r,"height"),r);if(c>0&&p>0)return{width:n&&n.spreadView?(c+n.pageBorder)*2:c,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function iu(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function nu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var Pl=class extends Ls{constructor(e,t,i,n,r,o,s,a,h,l,u,c,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=o,this.customRenderer=s,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=u,this.cmykStore=c,d(this,"lang"),d(this,"primaryFlows",{body:!0}),d(this,"rootPageBoxInstance",null),d(this,"styler",null),d(this,"stylerMap",null),d(this,"currentLayoutPosition",null),d(this,"layoutPositionAtPageStart",null),d(this,"currentCascadedPageStyle",null),d(this,"lookupOffset",0),d(this,"faces"),d(this,"pageBoxInstances",{}),d(this,"pageManager",null),d(this,"rootPageFloatLayoutContext"),d(this,"pageBreaks",{}),d(this,"pageProgression",null),d(this,"isVersoFirstPage",!1),d(this,"blankPageAtStart",!1),d(this,"pageSheetSize",{}),d(this,"pageSheetHeight",0),d(this,"pageSheetWidth",0),d(this,"semanticFootnoteFirstRefOffsets",new Map),d(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),d(this,"pageGroupPageCounts",Object.create(null)),d(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new Jb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new sn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=ge(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==y.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=_("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Uh(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=jp(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new r0(r);let o=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new x0(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let s=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Kb(h.properties,this),u=new _p(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{D0(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l);let u=Jh(Vo(l),this);this.pageSheetSize[h]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Ls(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Uh(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,o,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new Aw,i.flowPositions[e.flowName]=n);let r=Nw(e.element),o=new Si(r),s=new Iw(o,e);n.positions.push(s)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class r{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let o=new r,s=Nr(this.style.rootScope,new Vt(t,null),"");return s?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,s,!1,o),n):!1}evalSupportsSelector(e){class t extends rf{errorMsg(...s){}}let i=new t(null),n=gc(e),r=new Vt(n+"{}",i);return new Pr(_e,r,i,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!i.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,r=n.steps[0].node,o=n.offsetInNode,s=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,s=!1,o=0;let h=this.xmldoc.getNodeOffset(r,o,s);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let o=0;o<r.positions.length;o++){let s=r.positions[o].chunkPosition.primary,a=this.getNodePositionOffset(s);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,o=t<=r,s=n===i&&o?this.getFirstInFlowChildElement(i):n;if(!s)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(s),h=t;return o&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(s)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(s)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),o=t<=r;return n===i&&o?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return Xe(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ge(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ge(e,"page");if(!t)return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),o=this.xmldoc.body||this.xmldoc.root,s=this.xmldoc.getElementOffset(o);if(i<=s&&e===o||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),o=En(i)&&!this.matchPageSide(i)&&!r,s=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!o,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&s;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let c=h;for(;c;){let p=this.getPageGroupPageType(c);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(c)||0;(g>0||s&&(u||this.shouldStartPageGroup(c,p,a)))&&(g+=1,f.set(c,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(c===this.xmldoc.root)break;c=c.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Ve(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===y.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!Z(r)?r:y.static;if(So(o)||Yo(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!Z(s)?s:y.none)===y.none}isInlineLevelElement(e){return Dt(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!Z(n)?n:y.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let o=this.getConsumedOffset(r);o<i&&(i=o)}}return i}dumpLocation(e){G.debug("Location - page",this.currentLayoutPosition.page),G.debug(" current:",e),G.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)G.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new qe(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,o=i.startBreakType;i.startBreakType=ph(tt(o,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let o=0;o<n.length;o++){if(r=n[o],r.pageBox.pseudoName===kl)continue;let s=1;r.pageBox.pseudoName===bl&&!(this.actualPageWidth&&this.actualPageHeight)&&(s=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(s=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(s*l/(h*h)),c=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=c,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===y._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let o=oi(r.length,l=>r[l]>n)-1,s=r[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return s<h?!1:h<s?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new rl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new sn(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Pe.PAGE)return!1;let c=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=c?this.getConsumedOffset(c):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},o=_("layoutDeferredPageFloats"),s=!1,a=0;return o.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let c=new Pn().findByFloat(u),p=c.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,c,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(s=!0,t.validate());h.continueLoop()})}).then(()=>{s&&t.invalidate(),o.finish(!0)}),o.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Si(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return i?(this.setFormattingContextToColumn(e,t),e.init(),this.layoutDeferredPageFloats(e)):T(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=_("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],o=[],s=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-o.length>0;){let h=0;for(;o.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(o.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,c=!0;if(e.layout(l.chunkPosition,s,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(s=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){o.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-o.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=ph(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,c?c=!1:a.continueLoop()}),c){c=!1;return}}a.breakLoop()}).then(()=>{var a;if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,u)=>r.includes(u)||!o.includes(u)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let h=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(h),e.computedBlockSize===0){let l=e.pageFloatLayoutContext,u=l;for(;u;){let c=u.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(c.length>0&&!u.ignoreFootnoteAreaMaxHeight&&c.some(p=>{let f=getComputedStyle(p.area.element),g=m=>m!==""&&m!=="none";return g(f.getPropertyValue("max-block-size"))||g(p.area.vertical?f.maxWidth:f.maxHeight)})){u.ignoreFootnoteAreaMaxHeight=!0;for(let p of c){l.removePageFloatFragment(p,!0);let f=(a=p.continuations[0])==null?void 0:a.float;f&&u.removeFloatDeferredToNext(f)}l.invalidate();break}u=u.parent}}}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new lv([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,u,c,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=r.element,w=new sn(a,Pe.COLUMN,null,s,null,null,null),x=this.currentLayoutPosition.clone(),b=_("createAndLayoutColumn"),v;return b.loopWithFrame(C=>{let S=this.createLayoutConstraint(w);if(h>1){let F=this.viewport.document.createElement("div");if(N(F,"position","absolute"),m.appendChild(F),v=new Oo(F,p,this.clientLayout,S,w),v.isNonFirstColumn=o>0,v.forceNonfitting=f,v.vertical=r.vertical,v.rtl=r.rtl,v.snapHeight=r.snapHeight,v.snapWidth=r.snapWidth,r.vertical){let A=(r.rtl?h-o-1:o)*(u+l)+r.paddingTop,D=parseFloat(m.style.width);v.setHorizontalPosition(r.paddingLeft+D-r.width,r.width),v.setVerticalPosition(A,u)}else{let A=(r.rtl?h-o-1:o)*(u+l)+r.paddingLeft;v.setVerticalPosition(r.paddingTop,r.height),v.setHorizontalPosition(A,u)}v.originX=t,v.originY=i}else v=new Oo(m,p,this.clientLayout,S,w),v.isNonFirstColumn=!1,v.copyFrom(r);v.exclusions=g?[]:n.concat(),v.innerShape=c,w.setContainer(v),(v.vertical?v.height:v.width)>=0?this.layoutColumn(v,s).then(()=>{w.isInvalidated()||w.finish(),v.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(v.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),v.element!==m&&m.removeChild(v.element),C.continueLoop()):C.breakLoop()}):(w.finish(),C.breakLoop())}).then(()=>{b.finish(v)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Yp||t instanceof xl&&!(t instanceof xn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof In;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new sn(e,Pe.REGION,i,n,null,r,o)}layoutFlowColumnsWithBalancing(e,t,i,n,r,o,s,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(o,t,s,a),c=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,u,s,a,h,c).thenAsync(f=>T(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return T(null);if(h<=1)return T(f.columns);let g=t.getProp(this,"column-fill")||y.balance,m=this.currentLayoutPosition.flowPositions[a],w=Zv(h,g,p,u,s,f.columns,m);return w?(c=!1,o.lock(),u.lock(),w.balanceColumns(f).thenAsync(x=>(o.unlock(),o.validate(),u.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(f.columns)})}layoutFlowColumns(e,t,i,n,r,o,s,a,h,l,u){let c=_("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=iu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),b=cc(x,0,0,a.width,a.height,this),v=new $0(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),C=0,S=null,F=[];return c.loopWithFrame(A=>{this.createAndLayoutColumn(t,i,n,r,a,C++,h,s,l,g,m,b,v,u).then(D=>{if(o.isInvalidated()){F=null,A.breakLoop();return}if((D.pageBreakType&&D.pageBreakType!=="column"||C===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),nu(f),s.validate(),s.isLocked()?(F=null,A.breakLoop()):A.continueLoop();return}S=D,F[C-1]=S,S.pageBreakType&&S.pageBreakType!="column"&&(C=l,S.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),C<l?A.continueLoop():A.breakLoop()})}).then(()=>{c.finish(F)}),c.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return T(!0);let h=_("layoutContainer"),l=t.getProp(this,"wrap-flow")===y.auto,u=t.getProp(this,"flow-from"),c=this.viewport.document.createElement("div");c.role=t instanceof Zp?"complementary":"presentation";let p=t.getProp(this,"position");N(c,"position",p?p.name:"absolute");let f=t instanceof xn;t instanceof In?i.appendChild(c):i.insertBefore(c,i.firstChild);let g=new dd(c);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=o,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof xn&&(g.width<=0||g.height<=0)&&G.warn("Negative or zero page area size"),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(s,t,g);let m,w=!1;if(!u||!u.isIdent()){let x=[],b=t.getProp(this,"content");if(b instanceof W&&b.expr instanceof Fe&&b.expr.str.startsWith("running-element-"))b.visit(new ur(c,this,b,this.counterStore.getExprContentListener()));else if(St(b)){let v="span";b instanceof ht&&(v="img");let C=this.viewport.document.createElement(v);b.visit(new ur(C,this,b,this.counterStore.getExprContentListener())),c.appendChild(C),v=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,g,e,this.faces);let S=C.querySelectorAll("img[src]");for(let A=0;A<S.length;A++){let D=S[A],H=D.getAttribute("src");if(!H)continue;let q=Wt(D,H);x.push(q),e.fetchers.push(q)}let F=C.getAttribute("src");if(F){let A=C.querySelector("img");A||(A=C);let D=Wt(A,F);x.push(D),e.fetchers.push(D)}v=="span"&&ev(C,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(c),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=x.length?Cn(x).thenReturn(!0):T(!0)}else if(this.pageBreaks[u.toString()])s.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=T(!0);else{let x=_("layoutContainer.inner"),b=u.toString(),v=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,b,v).then(C=>{if(!s.isInvalidated()){let S=C[0];S.element===c&&(g=S),g.computedBlockSize=Math.max.apply(null,C.map(A=>A.computedBlockSize)),t.finishContainer(this,g,e,S,v,this.clientLayout,this.faces);let F=this.currentLayoutPosition.flowPositions[b];F&&F.breakAfter==="region"&&(F.breakAfter=null)}x.finish(!0)}),m=x.result()}return m.then(()=>{if(s.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let b=t.getProp(this,"shape-outside"),v=g.getOuterShape(b,this);o.push(v)}}else if(t.children.length==0){i.removeChild(c),h.finish(!0);return}let x=f?0:t.children.length-1;h.loop(()=>{for(;x>=0&&x<t.children.length;){let b=t.children[f?x++:x--],v=this.layoutContainer(e,b,c,n,r,o,s);if(v.isPending())return v.thenAsync(()=>T(!s.isInvalidated()));if(s.isInvalidated())break}return T(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i,n,r,o;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Fw,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let a=1e4;if(t.page>a)throw new Error(`Too many pages generated (over ${a} pages)`);let h=t.startSideOfFlow("body");t.isBlankPage=En(h)&&this.matchPageSide(h),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=iu(t),u=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!s){let x=new qe(this.style.pageScope,"left-page");e.side=x.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(u);if(!c)return T(null);let p=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===xr),e.setAutoPageHeight(c.pageBox.specified.height.value===Sr);let{counterOffset:x,changeOffset:b}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(x)||(x=this.lookupOffset,b=this.lookupOffset),isFinite(x)&&this.styler.styleUntil(x,0);let v=this.styler.getCounterSnapshotAtOffset(x),C=b===x?v:this.styler.getCounterSnapshotAtOffset(b);v||(v=this.styler.getLastCounterSnapshot()),C||(C=v),this.counterStore.setCurrentPageDocCounters((r=v?.counters)!=null?r:null,(o=C?.changes)!=null?o:null,C?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let S=Jh(Vo(u),this);this.setPageSizeAndBleed(S,e),f0(u,S,e,this),p=S.bleedOffset+S.bleed}let f=!s&&c.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=f!=y.horizontal_tb;let g=c.getProp(this,"direction")||y.ltr,m=new sn(this.rootPageFloatLayoutContext,Pe.PAGE,null,null,null,f,g),w=_("layoutNextPage");return w.loopWithFrame(x=>{this.layoutContainer(e,c,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),nu(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);x.continueLoop()}else x.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(b=>{let v=t.flowPositions[b],C=v.breakAfter;C&&(C==="page"||!this.matchPageSide(C))&&(v.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let x=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(x,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},Q0=class Ba extends dr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,d(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Dp(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new a0(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Rt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Ba(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new jy(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Qr(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new K0(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new Qr(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Qr(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=Kt(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new Kp(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new L0(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(dr.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Ba(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},rf=class extends Ws{constructor(e){super(),this.validatorSet=e,d(this,"rootScope"),d(this,"pageScope"),d(this,"rootBox"),d(this,"cascadeParserHandler"),d(this,"regionCount",0),d(this,"fontFaces",[]),d(this,"counterStyles",new Fb),d(this,"footnoteProps",{}),d(this,"flowProps",{}),d(this,"viewportProps",[]),d(this,"pageProps",{}),this.rootScope=new Rs(null),this.pageScope=new Rs(this.rootScope),this.rootBox=new t0(this.rootScope),this.cascadeParserHandler=new Q0(this,null,null,null),this.slave=this.cascadeParserHandler}};function ex(e,t){return t.parseOPSResource(e)}var tx=class extends qa{constructor(e){super(ex,"document"),this.fontDeobfuscator=e,d(this,"styleByKey",{}),d(this,"styleFetcherByKey",{}),d(this,"styleByDocURL",{}),d(this,"triggersByDocURL",{}),d(this,"validatorSet",null),d(this,"styleSheets",[]),d(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=_("OPSDocStore.init");return this.validatorSet=Mp(),Z0().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ne(mn(t),zi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ne(mn(t),zi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=_("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return tf(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Ot("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){G.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),x=f.getAttribute("ref");g&&m&&w&&x&&s.push({observer:g,event:m,action:w,ref:x})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ne("user-agent-page.css",mi),text:Ac,flavor:"UA",classes:null,media:null}),h.push({url:Ne("user-agent-counter-styles.css",mi),text:Oc,flavor:"UA",classes:null,media:null}),n)h.push({url:Ne("user-agent-toc.css",mi),text:Rc,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),x=f.getAttribute("media"),b=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:x})}else if(m=="link"){let w=f.getAttribute("href"),x=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),b=f.getAttribute("class"),v=f.getAttribute("media");if(w&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||b)){let C=Ne(w,i),S=f.getAttribute("title");h.push({url:C,text:null,classes:S?b:null,media:v,flavor:"Author"})}}else m=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let c=this.styleFetcherByKey[l];c||(c=new Er(()=>{let p=_("fetchStylesheet"),f=0,g=new rf(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Za(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Uc(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new J0(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=c,c.start()),c.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},ar="\u25B8",ru="\u25BE",ix="\u25B9";function Nl(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function nx(e){let t=Nl(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var rx=class{constructor(e,t,i,n,r,o,s,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=s,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,d(this,"pref"),d(this,"page",null),d(this,"instance",null),this.pref=Iu(o),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;pi(n,"height","auto")!="auto"&&(N(n,"height","auto"),this.setAutoHeight(n,t)),pi(n,"position","static")=="absolute"&&(N(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-node":r.display=y.block,r.margin=Ae,r.padding=Ae,r["padding-inline-start"]=new R(1.25,"em");break;case"toc-node-first-child":r.display=y.inline_block,r.margin=new R(.2,"em"),r["vertical-align"]=y.top,r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-container":r.padding=Ae;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Ve(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=ar&&(l.textContent=ar,N(l,"cursor","pointer"),l.addEventListener("click",ox,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),o.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=ix,N(l,"margin","0.2em 0 0 -1em"),N(l,"margin-inline-start","-1em"),N(l,"margin-inline-end","0"),N(l,"display","inline-block"),N(l,"width","1em"),N(l,"text-align","center"),N(l,"vertical-align","top"),N(l,"cursor","default"),N(l,"font-family","Menlo,sans-serif"),h.appendChild(l),N(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){N(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return T(h)}}showTOC(e,t,i,n,r){if(this.page)return T(this.page);let o=_("showTOC"),s=new nd(e,e);this.page=s;let a=qt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of Nl(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new Ho(t.window,u.fontSize,0,e,u.width,u.height);let c=this.makeCustomRenderer(h),p=new Pl(l,h,this.lang,t,this.clientLayout,this.fontMapper,c,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(e,2),o.finish(s)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function ox(e){let t=e.target,i=t.textContent==ar;t.textContent=i?ru:ar;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==ru){a.textContent=ar,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Gr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function sx(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}var ou=class extends tx{constructor(){super(null),d(this,"plainXMLStore"),d(this,"jsonStore"),d(this,"opfByURL",{}),d(this,"primaryOPFByEPubURL",{}),d(this,"deobfuscators",{}),d(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=X0(),this.jsonStore=zm()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new go(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=_("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):/\.(x?html?|xht)(?:[#?]|$)/i.test(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):qo(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}G.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=_("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of r)if(o){this.loadOPF(e,o).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return T(n);let r=_("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new go(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(s=>{n.initWithXMLDoc(o,s).then(()=>{r.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=_("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new go(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=za(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ne(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&Nl(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=_("EPUBDocStore.load"),n=qt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(zi)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?G.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&zi.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?G.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?G.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):G.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=qt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=_("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let r=i.width-0,o=i.height-0;if(r&&o){let s=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${o}px;}`+(s?`@page{size:${r}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},su=class{constructor(){d(this,"id",null),d(this,"src",""),d(this,"mediaType",null),d(this,"title",null),d(this,"itemRefElement",null),d(this,"spineIndex",-1),d(this,"compressedSize",0),d(this,"compressed",null),d(this,"epage",0),d(this,"epageCount",0),d(this,"startPage",null),d(this,"skipPagesBefore",null),d(this,"itemProperties"),this.itemProperties=Vf}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ne(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Xf(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function ax(e){return e.id}function lx(e){return t=>{let i=_("deobfuscator");return hx("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Mm(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Bc([a,o]))})}),i.result()}}function hx(e,t){let i=_("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var gi={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},Zn="http://idpf.org/epub/vocab/package/meta/#",$e={language:`${gi.dcterms}language`,title:`${gi.dcterms}title`,creator:`${gi.dcterms}creator`,layout:`${gi.rendition}layout`,titleType:`${Zn}title-type`,displaySeq:`${Zn}display-seq`,alternateScript:`${Zn}alternate-script`,role:`${Zn}role`};function ux(e,t){let i={};return(n,r)=>{var o,s,a,h,l,u;let c,p,f=n.r||i,g=r.r||i;if(e==$e.title&&(c=((o=f[$e.titleType])==null?void 0:o[0].v)=="main",p=((s=g[$e.titleType])==null?void 0:s[0].v)=="main",c!=p))return c?-1:1;let m=parseInt((a=f[$e.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[$e.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=$e.language&&t&&(c=((l=f[$e.language]||f[$e.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[$e.language]||g[$e.alternateScript])==null?void 0:u[0].v)==t,c!=p)?c?-1:1:n.o-r.o}}function cx(e,t){let i;if(!t)i=gi;else{i={};for(let p in gi)i[p]=gi[p];let c;for(;(c=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(c[0].length),i[c[1]]=c[2]}let n=c=>{if(c){let p=c.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:Zn;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(c=>{if(c.localName=="meta"){let p=n(c.getAttribute("property"));if(p)return{name:p,value:c.textContent,id:c.getAttribute("id"),order:r++,refines:c.getAttribute("refines"),lang:null,scheme:n(c.getAttribute("scheme")),role:null}}else if(c.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:gi.dcterms+c.localName,order:r++,lang:c.getAttribute("xml:lang"),value:c.textContent,id:c.getAttribute("id"),refines:null,scheme:null,role:c.getAttribute("role")||c.getAttribute("opf:role")};return null}),s=cs(o,c=>c.refines),a=c=>qf(c,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=s[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:$e.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:$e.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=cs(w,b=>b.name);m.r=a(x)}return m})),h=a(cs(o,c=>c.refines?null:c.name)),l=null;h[$e.language]&&(l=h[$e.language][0].v);let u=c=>{for(let p in c){let f=c[p];f.sort(ux(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function dx(){let e=window.MathJax;return e?e.Hub:null}var au={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Is="viv-id-",go=class{constructor(e,t){this.store=e,this.pubURL=t,d(this,"opfXML",null),d(this,"encXML",null),d(this,"items",null),d(this,"spine",null),d(this,"itemMap",null),d(this,"itemMapByPath",null),d(this,"uid",null),d(this,"bindings",{}),d(this,"lang",null),d(this,"epageCount",0),d(this,"prePaginated",!1),d(this,"epageIsRenderedPage",!0),d(this,"epageCountCallback",null),d(this,"metadata",{}),d(this,"toc",null),d(this,"cover",null),d(this,"fallbackMap",{}),d(this,"pageProgression",null),d(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let o=r+(n?`#${n}`:"");return Is+Pu(o,":")}transformURL(n,r){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let s=o[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(o[2]);if(s&&e.spine.some(h=>h.src===s))return`#${this.transformFragment(a,s)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Is)===0&&(n=n.substring(Is.length));let r=jf(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ne("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new su,u=h;l.initWithElement(u,e.url);let c=u.getAttribute("fallback");return c&&!au[l.mediaType]&&(r[l.src]=c),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=_l(this.items,ax),this.itemMapByPath=_l(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(au[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,c=u.getAttribute("idref"),p=this.itemMap[c];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=wu(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(tu.withChild("EncryptionMethod",tu.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=cx(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[$e.language]&&(this.lang=this.metadata[$e.language][0].v),this.metadata[$e.layout]&&(this.prePaginated=this.metadata[$e.layout][0].v==="pre-paginated"),s.length>0&&this.uid){let h=lx(this.uid);for(let l=0;l<s.length;l++)this.store.deobfuscators[this.pubURL+s[l]]=h}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let t=0,i=0,n=_("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(s=>{let a=1800,h=s.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(s.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new ef(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new su;r.initWithParam(n),r.id;let o=i.document.createElement("itemref");o.setAttribute("idref",r.id),i.root.appendChild(o),r.itemRefElement=o,this.itemMap[r.id]=r;let s=this.getPathFromURL(n.url);s==null&&(s=n.url),this.itemMapByPath[s]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):T(null)}initWithWebPubManifest(e,t,i){var n,r,o,s;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[$e.title]=(Array.isArray(a)?a:[a]).map(m=>{var w;return{v:(w=m.value)!=null?w:m}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).map(m=>m.content);h&&h.length!==0&&(this.metadata[$e.creator]=(Array.isArray(h)?h:[h]).map(m=>{var w;return{v:(w=m.name)!=null?w:m}}));let l=e.inLanguage||((s=e.metadata)==null?void 0:s.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[$e.language]=(Array.isArray(l)?l:[l]).map(m=>({v:m})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let m of nx(t)){let w=m.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let x=qt(Ne(w,this.pubURL)),b=this.getPathFromURL(x),v=b!==null?encodeURI(b):x;e.readingOrder.indexOf(v)==-1&&e.readingOrder.push(v)}}let c=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(w=>{let x=m===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,v=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(x||v==="text/html"||v==="application/xhtml+xml"||!v&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let C=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,S={url:Ne(mn(b),C),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=S.index),c.push(S)}})});let g=_("initWithWebPubManifest");return this.initWithChapters(c).then(()=>{var m,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(m=this.items)==null?void 0:m[0]:this.itemMapByPath[u]);let x=(w=e.readingOrder)==null?void 0:w.length;x&&x<this.items.length&&this.items.splice(x),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=_("getCFI");return this.store.load(i.src).then(r=>{let o=r.getNodeByOffset(t),s=null;if(o){let a=r.getNodeOffset(o,0,!1),h=t-a,l=new Zl;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),s=l.toString()}n.finish(s)}),n.result()}resolveFragment(e){return Sn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Zl;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let o=r.node,s=o.getAttribute("idref");if(o.localName!="itemref"||!s||!this.itemMap[s]){t.finish(null);return}n=this.itemMap[s],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let o=i.navigate(r.document),s=r.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:s,pageIndex:-1})})},(t,i)=>{G.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Sn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let o=this.spine[r];(!o||o.epageCount==0)&&(o=this.spine[--r]);let s=Math.floor(e-o.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:s});return}let i=oi(this.spine.length,r=>{let o=this.spine[r];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let s=r.getTotalOffset();o=Math.round(s*e/n.epageCount),o==s&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{G.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return T(n)}if(e.offsetInItem<=0)return T(t.epage);let i=_("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),o=Math.min(r,e.offsetInItem);i.finish(t.epage+o*t.epageCount/r)}),i.result()}},jr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),px=class{constructor(e,t,i,n,r,o){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,d(this,"spineItems",[]),d(this,"spineItemLoadingContinuations",[]),d(this,"pref"),d(this,"clientLayout"),d(this,"counterStore"),d(this,"cmykStore"),d(this,"tocAutohide",!1),d(this,"tocVisible",!1),d(this,"tocView"),d(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=Iu(n),this.clientLayout=new G0(t),this.counterStore=new Vg(e.documentURLTransformer),this.cmykStore=new nc,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return T(!0);let i=_("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<e;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(e=n[r])!=null?e:0;t+=Math.min(o,s)}return t}reportPaginationProgress(e,t){let i=Ot("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),o=r;t&&(o=e.instance.getPosition(t,!0)),o<0&&(o=0),o>r&&(o=r);let s=this.paginationProgress.renderedOffsetsBySpine[n];s!=null&&o<s&&(o=s),this.paginationProgress.renderedOffsetsBySpine[n]=o;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let c={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(c)}catch(f){G.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,u=n.offset!==t.offset,c=s&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(c||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,!s&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||o)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Gr(n));let r=Gr(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return T(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let o=e.pages[t.page],s=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||s,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,o,a,s,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=_("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),s=0,a=t;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let c=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:c.currentPageType,previousPageType:c.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=sx(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,x=u.instance.scopes;u.instance.scopes={};let b=l.pageIndex<u.pages.length-1,v=!!u.pages[l.pageIndex]&&b,C=v?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let S=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,S).then(F=>{v&&u.instance.endIsolatedRootPageFloatLayoutContext(C);let A=c.currentPageType;c.currentPageType=f.currentPageType,c.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=x;let D=Gr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),F.pageAndPosition.position.spineIndex===a.spineIndex&&F.pageAndPosition.position.pageIndex===i&&(a=F.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&A!==F.pageAndPosition.page.pageType&&(c.currentPageType=a.pageType);let H=u!==e,q=u.pages.length,Se=u.layoutPositions[q],se=u.instance.hasActiveRootPageFloatLayoutContext();if(Se&&!se){let k=H?Gr(this.counterStore.currentPageCounters):null;H&&(this.counterStore.currentPageCounters=D);let M=q;this.renderSinglePage(u,Se).then(()=>{H&&this.markSpineItemCompleteIfReady(u);let E=u.pages.length-M;if(H&&E>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,E),this.counterStore.updateTargetCounterNodesInPages(u.pages);let L=u.item.spineIndex;for(let P=L+1;P<this.spineItems.length;P++){let I=this.spineItems[P];if(I){I.item.epage+=E;for(let O of I.pageCounterStarts)O!=null&&O.page&&(O.page=O.page.map(z=>z+E));this.counterStore.updatePageCounterNodesInPages(I.pages,I.pageCounterStarts)}}if(k){let P=k.page;P&&(k.page=P.map(I=>I+E))}}k&&(this.counterStore.currentPageCounters=k),h.continueLoop()});return}H&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=_("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),o=this.preparePageCountersForRender(e,n),s=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,o,s,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,o,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(c=>{i.finish({pageAndPosition:jr(c,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=oi(t.layoutPositions.length,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=_("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(jr(r,o))})})}),i.result()}renderPage(e){let t=_("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){t.finish(jr(s,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){s=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){t.finish(jr(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=_("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=_("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,o=0;t&&(o=n);let s;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=_("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return T(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return T({left:null,right:null});let n=_("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(s=>{let a=this.getPage(e),h=s&&s.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,t);return s.thenAsync(a=>a?s:r)}else return T(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,t):T(null)):r}navigateToEPage(e,t,i){let n=_("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=_("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!yt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ne(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!Lt(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ne(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){G.debug("Navigate to",e);let n=this.opf.getPathFromURL(qt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let s=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],e=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return T(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=e.indexOf("#");if(s>=0)return this.navigateToFragment(e.substr(s+1),t,i)}return T(null)}let o=_("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",lr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new nd(n,r);if(o.spineIndex=e.item.spineIndex,o.position=t,o.offset=e.instance.getPosition(t),o.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=Au(this.viewport.width,this.viewport.height,i.width,i.height),a=Nr(null,new Vt(s,null),"");o.delayedItems.push(new el(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ne(r,e.url);let s=t.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=Bl(r),l=Bl(s),u=new ri;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),u.append("="),u.append(encodeURIComponent(w)))}}o.setAttribute("src",u.toString());let c=t.getAttribute("width");c&&o.setAttribute("width",c);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",r),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=dx();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=_("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(s)}),l.result()}return T(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ne(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):T(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return T(null);let t=this.spineItems[e];if(t)return T(t);let i=_("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),u=this.makeCustomRenderer(s),c=this.viewport,p=l.sizeViewport(c.width,c.height,c.fontSize,this.pref);(p.width!=c.width||p.height!=c.height||p.fontSize!=c.fontSize)&&(c=new Ho(c.window,p.fontSize,c.pixelRatio,c.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let v=g&&g.pageCounterStarts[g.pages.length-1],C=v&&v.page;if(C&&C.length)w=C[C.length-1]+1;else{let S=this.counterStore.currentPageCounters.page;w=!S||!S.length?m:S[S.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let x=new Pl(l,s,this.opf.lang,c,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);x.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[$e.title];x.pubTitle=b&&b[0]&&b[0].v||"",x.docTitle=r.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),t={item:r,xmldoc:s,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(v=>{v.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let n=_("showTOC");this.tocView||(this.tocView=new rx(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),lr||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},lu="data-vivliostyle-viewer-status",fx="data-vivliostyle-spread-view",of=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(of||{}),gx=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,d(this,"fontMapper"),d(this,"kick"),d(this,"sendCommand"),d(this,"resizeListener"),d(this,"hyperlinkListener"),d(this,"pageRuleStyleElement"),d(this,"pageSheetSizeAlreadySet",!1),d(this,"renderTask",null),d(this,"actions"),d(this,"readyState"),d(this,"packageURL"),d(this,"opf"),d(this,"touchActive"),d(this,"touchX"),d(this,"touchY"),d(this,"needResize"),d(this,"resized"),d(this,"needRefresh"),d(this,"viewportSize"),d(this,"currentPage"),d(this,"currentSpread"),d(this,"pagePosition"),d(this,"fontSize"),d(this,"zoom"),d(this,"fitToScreen"),d(this,"pageViewMode"),d(this,"waitForLoading"),d(this,"renderAllPages"),d(this,"pref"),d(this,"pageSizes"),d(this,"pixelRatio"),d(this,"pixelRatioLimit"),d(this,"viewport"),d(this,"opfView"),d(this,"cmykReserveMap"),d(this,"cmykReserveMapUrl");let r=t.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",Pc),o("vivliostyle-viewport-css",Nc),o("vivliostyle-polyfill-css",Lc),t.setAttribute("data-vivliostyle-viewer-viewport",!0),lr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(lu,"loading"),this.fontMapper=new Qb(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=s=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Tu(),this.pageSizes=[],this.pixelRatioLimit=Da==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=bu;G.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),G.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),G.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),G.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(lu,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){vt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=_("loadPublication");return this.configure(e).then(()=>{let s=new ou;s.init(n,r).then(()=>{let a=Ne(mn(t),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(e){vt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,o=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=_("loadXML");return this.configure(e).then(()=>{let a=new ou;a.init(r,o).then(()=>{let h=t.map((l,u)=>({url:Ne(mn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new go(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,T(!0))):t=T(!0),t.thenAsync(()=>(vt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let o=zt[r];if(o)return t*o}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Rl(e.userAgentRootURL.replace(/resources\/?$/,"")),Ll(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Rl(e.rootURL),Ll(`${zi}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==ai&&(B0(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),T(!0)}configurePlugins(e){Ot("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{N(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),N(e.container,"visibility","visible"),N(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=_("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?Cn(i.fetchers):T(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new Ho(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Ho(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return e!=null&&(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(fx,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let m=g*.75;return Math.ceil(m)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),u=s(h),c=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${u}pt; margin: 0 ${-c}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,T(!0);let t=Ne(mn(this.cmykReserveMapUrl),zi),i=_("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{gg(n)?this.cmykReserveMap=n:(G.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new px(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?T(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,T(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new hu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Hs().getScheduler().run(()=>Sn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,vt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),vt.registerEndTiming("render (resize)"),ai&&Qp(this.window)?z0(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof hu)vt.registerEndTiming("render (resize)"),G.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=_("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return T(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=_("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=_("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=T(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return T(!0)}else if(i=="hide")return T(!0);if(n&&i!="show")return this.opfView.hideTOC(),T(!0);{let o=_("showTOC");return this.opfView.showTOC(t).then(s=>{if(s){if(r&&(s.listeners={}),t){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return Sn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(G.error("No such action:",t),i.finish(!0))},(i,n)=>{G.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=uu(e),i=null,n=this;Am(()=>{let r=_("commandLoop"),o=Hs().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),T(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=_("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=uu(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},sf=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(sf||{}),hu=class af extends Error{constructor(){super(),d(this,"name","RenderingCanceledError"),d(this,"message","Page rendering has been canceled"),d(this,"stack"),Object.setPrototypeOf(this,af.prototype),this.stack=new Error().stack}};function uu(e){return typeof e=="string"?za(e):e}var cu=_a;function mx(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function du(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var lf=class{constructor(e,t){this.settings=e,d(this,"initialized",!1),d(this,"adaptViewer_"),d(this,"options"),d(this,"eventTarget"),d(this,"readyState"),mu(e.debug),this.adaptViewer_=new gx(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=mx(),t&&this.setOptions(t),this.eventTarget=new Va,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},du(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function o(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:wx(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},du(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===cu.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===cu.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function wx(e){function t(n){return typeof n=="number"?n:null}function i(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(e)?e.map(i):e?[i(e)]:null}var hf=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(hf||{}),yx=sf,vx=of;vt.forceRegisterEndTiming("load_vivliostyle");var bx=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){d(this,"htmlDoc"),d(this,"title"),d(this,"printCallback"),d(this,"errorCallback"),d(this,"hideIframe"),d(this,"removeIframe"),d(this,"iframe"),d(this,"iframeWin"),d(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1871
+ `),i.toString()}},tx=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}}},ix=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 Yl(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=M(s);let a=new Rf(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?ks(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 nx(e){mi=e}var ji=[];function Tu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Lf(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 Zl(e,t,i){if(!mi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Lf(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(Of(t)||(t.onload=null),l)return ji.some(c=>Tu(c,e))||ji.push(e),T(!0);for(let c of t.document.head.getElementsByTagName("script"))c.hasAttribute("data-vivliostyle-scripting")&&Tu(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 rx(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 $l)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 ox(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=rx(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function sx(e,t,i){if(!mi)return T(!1);let n=Lf(e);if(n.length===0)return T(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),o=r?ox(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 Zl(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 ax(e){if(!mi)return T(!1);let t=D("loadScripts");return t.loop(()=>ji.length===0?T(!1):Zl(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 Of(e){return mi?ji.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var lx=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,dl),hx=e=>`"${lx(e)}"`,ha=(e,t,i)=>hx(i.transformURL(wi(String(e)),t)),ux=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${ha(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${ha(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${ha(r,t,i)}`),cx={},dx=new Set(["base","body","head","html","link","meta","script","style","title"]);function px(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 tl=class lr extends pl{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)||!Zh(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(gr);if(!i)return;let n=ep(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 Qb){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 sa(t,n,o,s,this.exprContentListener),S=new ko(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),Ka(l,o,s[h]),lf(s[h],i,n,(u,c)=>{mr(l,c,o),of(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 ko(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||Zh(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=$o(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=Ja(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=sf(a,s,t);let u=!h&&t!==l;i=af(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(hf(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(qo(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=Ed(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=$o(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||ca(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=Ja(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 sb(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(Sh);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=ca(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Yv().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);Ls.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)?Iy(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===st.ROOTED&&kt(a);if(this.nodeContext.parent&&(qo(p?.value)||m&&Pi(m)||w)){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}l=Ly(a,l,this.nodeContext.shadowContext,this.xmldoc.url,x=>this.xmldoc.getElement(x),gr,c),l=Oy(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 Zl(a,this.viewport.window).thenFinish(s),s.result();let v=u.display;if(kt(a)&&!w&&a.hasAttribute(Qd)&&(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=jw(a),he=u["column-count"],k=u["column-width"],_=he&&he!==y.auto&&!q(he)||k&&k!==y.auto&&!q(k);this.nodeContext.establishesBFC=qw(v,N,F,u.overflow,V,Y,_||ue),this.nodeContext.containingBlockForAbsolute=Yw(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=By(a,this.nodeContext.shadowContext,c);My(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)||Nd(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(),Ta[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(),Ta[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 ky(H,le.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let De=u["white-space"];if(De){let H=Ud(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"?(dx.has(ne)?ne="div":ne=="vide_"?ne="video":ne=="audi_"?ne="audio":ne=="object"&&(ce=!!this.customRenderer),a.hasAttribute(jl)&&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 Ds;if(ce){let H=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;Ds=this.customRenderer(a,H,u)}else Ds=T(null);Ds.then(H=>{var Bt,Wt,It,rh,oh;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"&&px(H);let qr=this.nodeContext.inheritedProps["image-resolution"],zs=[],Vs=u.width,Us=u.height,sg=a.getAttribute("width"),ag=a.getAttribute("height"),$s=Vs===y.auto||!Vs&&!sg,Hs=Us===y.auto||!Us&&!ag,sh=a.attributes,lg=sh.length,Gn=null,ah=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<lg;He++){let bt=sh[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"&&((rh=a.parentElement)==null?void 0:rh.localName)==="picture")try{let We=this.context.rootScope,ft=new Es(We),Zr=new vt(Ee,ft),lh=kd(Zr,ft,"");if(lh){if(lh.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=ac(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);$s&&Hs?(be.push(ft),zs.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=ux(Ee,this.xmldoc.url,this.documentURLTransformer)),ht){let We=cx[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")ah=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,ah);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};!$s&&!Hs&&!(()=>{let oe=this.nodeContext.vertical?Vs:Us;return oe instanceof R&&oe.unit==="%"})()&&!ht()?this.page.fetchers.push(bt):($s&&Hs&&qr&&qr!==1&&zs.push({image:He,element:H,fetcher:bt}),be.push(bt))}else!Gn&&ne==="img"&&ke==="http://www.w3.org/1999/xhtml"&&(H.srcset||((oh=a.parentElement)==null?void 0:oh.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(!Ps(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)&&Zs(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"),Zs(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(zs,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 sa(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new t0(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=qh(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=dy(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()&&_d(u).includes("block-start")&&xt(u,"text-start"),u.appendChild(this.viewNode),Qw(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=qh(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 sa(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new ko(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(Sh);let S,v;for(let b of w){if(gx[b])continue;let x=i[b];if(!(!x||x===Be&&!je(b))){if(x=x.visit(new Im(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 mc(x.unit)&&(x=Oc(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))`))),gy[b]||g&&my[b]){this.page.delayedItems.push(new Pl(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=ja(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=ja(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,ys);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?Dd(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"),Zs(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(Xg(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,Ul(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(tl,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),d(tl,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var fx=tl,gx={"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},mx=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}},ms=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),ul){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 wx=1,Ms=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${wx++}`,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})}},yx=class extends Ms{constructor(e){super(e,null,null,[],null),this.specified.width=new $(Mr,0),this.specified.height=new $(_r,0)}},Iu=class extends Wo{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}}},Bf=class Mf extends Ms{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 Iu||(this._scope=new Iu(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 Jl(t,this)}clone(t){let i=new Mf(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}},_f=class Df extends Ms{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 Cx(t,this)}clone(t){let i=new Df(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},jr=class zf extends Ms{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 zf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function vx(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 bx(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 Au(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 Vf(e,t,i){return!t||q(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var _s=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?_p:Dp;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 Nc(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=ye(i,So(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=Vf(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 wl(e,n,s))}let r=xe(e,t["min-page-width"],e.zero);r&&(i=zt(e,i,new fa(e,new Ke(e,"page-width"),r)));let o=xe(e,t["min-page-height"],e.zero);o&&(i=zt(e,i,new fa(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=So(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=So(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=bx(e,t["column-gap"],null);o||(o=new Br(e,1,"em")),n&&!r&&(r=new ur(e,"floor",[ga(e,ie(e,i,o),ie(e,n,o))]),r=new ur(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,ga(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=Ja(this.cascaded,e,r,!1,null);this.vertical=sf(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=af(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 ih&&e.currentLayoutPosition&&new Ke(i,"left-page").evaluate(e));hf(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=ps(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=ps(e,r,t,o)}return ut(r,e)}getSpecial(e,t){let i=$p(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()&&mc(r.unit)&&(r=Oc(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 Pl(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<Fu.length;o++)this.propagateProperty(e,t,Fu[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<Lu.length;r++)this.propagateProperty(e,t,Lu[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<Ou.length;o++){let s=Ou[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&&Yo(n);x&&Ts(n),b=o.getElementClientRect(n?n.element:t.element),x&&Cl(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<Ru.length;x++)this.propagateProperty(e,t,Ru[x],s);for(let x of xx){let C=this.getProp(e,x);C&&yr(C,i)}for(let x=0;x<Bu.length;x++)this.propagateDelayedProperty(e,t,Bu[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==Kl)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)}},Fu=["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"],Ru=["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"],xx=["background-image","border-image-source","filter"],Lu=["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"],Ou=["width","height","image-resolution","object-fit","object-position"],Bu=["transform","transform-origin"],Kl="background-host",Sx=class extends _s{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)}},Jl=class extends _s{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){}},Cx=class extends _s{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},zn=class extends _s{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=da(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=Vf(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=vx(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 Gf||(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)}},Ql=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?vd:bd)}},Uf=class extends Ql{constructor(e,t,i,n){super(e,t,i,n)}},kx=class $f extends Ql{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new $(bh,0),n.specified.height=new $(bh,0)}startPartitionRule(t,i,n){let r=new jr(this.scope,t,i,n,this.target),o=new Uf(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new _f(this.scope,t,i,n,this.target),o=new $f(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},Ex=class extends Ql{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 Uf(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new _f(this.scope,e,t,i,this.target),r=new kx(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function Hf(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 Px={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")}},Nx=new R(.24,"pt"),US=new R(3,"mm"),Tx=new R(10,"mm"),Ix=new R(13,"mm");function ws(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&&Px[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=Ix):h.isNumeric()&&(t.cropOffset=h),t}function Mu(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 Wf(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 il=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(il||{});function Ax(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=Wf(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 Fx(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=Wf(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 Rx(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(Nx,n),c=Math.max(0,t.bleedOffset-ut(Tx,n)),p=t.bleedOffset-c,f=e["crop-marks-line-color"],g=f&&!q(f.value)?f.value:y.auto;r&&Object.keys(il).forEach(m=>{let w=il[m],S=Ax(l,w,u,g,p,a,c);h.appendChild(S)}),o&&Object.keys(Fr).forEach(m=>{let w=Fr[m],S=Fx(l,w,u,g,p,c);h.appendChild(S)})}var nl=(()=>{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})(),eh={"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"}},Lx=(()=>{let e=eh;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),th="vivliostyle-page-rule-master",Rr="_marginBoxes",ys="_footnoteArea",Gf=class extends Bf{constructor(e,t,i){super(e,null,th,[],t,null,0),d(this,"pageMarginBoxes",{});let n=ws(i),r=new Ox(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Rr];t&&Lx.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Mx(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)!nl[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new An(e,this)}},Ox=class extends jr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new Bx(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 nl)nl.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new Dx(e,this)}},Bx=class extends jr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new $(M("body"),0)}createInstance(e){return new jf(e,this)}},Mx=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];(Mp[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 Xf(e,this)}},An=class extends Jl{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=eh[b];if(x){let C=e[b],N=this.pageMarginBoxInstances[b],F=new Do(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 _u(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 _u(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 _x(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 Do&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Do&&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)}},Do=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=El(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()}},_x=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}},_u=class extends Do{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()}},Dx=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=So(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)}},jf=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}},Xf=class extends zn{constructor(e,t){super(e,t),d(this,"boxInfo"),d(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=eh[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,ga(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=Au(n,i[`margin-${o}`],h),u=Au(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"))}}},zx=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 wl(e,new Cc(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||Hf(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===Kl?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 Gf(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:th}),n=i.specified,r=e.size;if(r&&!q(r.value)){let s=ws(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}},Vx=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}},Ux=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}},$x=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}},Hx=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}},Wx=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}},Gx=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}},jx=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}},Xx=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}},qx=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}},Yx=class extends $l{constructor(e,t){super(e,t,null,null,null)}apply(e){Zx(e.context,e.currentStyle,this.style,this.specificity,e)}};function Zx(e,t,i,n,r){cs(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),cs(e,l,o[h],n,null,null,null)}}let s=i[ys];if(s){let a=ri(t,ys);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 Kx=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 Vx(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 qx(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Xx(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 Ux(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new $x(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Hx(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Wx(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Gx(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new jx(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 Yx(this.elementStyle,e)}startFootnoteRule(e){let t=ri(this.elementStyle,ys),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 qf(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 Jx(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Jx=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)}},qf=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)}},Yf=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 Kf([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}},rl=(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))(rl||{});function yo(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 Qx(e){let t=e.contentType;if(t){let n=Object.keys(rl);for(let r=0;r<n.length;r++)if(rl[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 Zf(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=Qx(e);if(i=yo(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=yo(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=yo(o,"image/svg+xml",r))}i||(i=yo(o,"text/html",r))}}let n=i?new Yf(t,e.url,i):null;return T(n)}function eS(){return new xl(Zf,"document")}var tS=class ol{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new ol(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new ol(n=>{if(!this.check(n))return!1;let r=new Kf([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Du=new tS(e=>!0),Kf=class sl{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 sl(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 sl(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)}},iS=new Vr(()=>{let e=D("uaStylesheetBase"),t=Lp(),i=Ae("user-agent-base.css",Ci),n=new Nr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Db(n.cascade),Sl(pd,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function nS(){return iS.get()}var rS=class extends _o{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}`)}},oS=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 pa(this.rootScope,e,t,i),o=ob(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 zu(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 Vu(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var ih=class extends pa{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 tx(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 Pu(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=Hf(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Sx(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 zx(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=ex(h.properties,this),u=new Rf(l);s.push(u)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{sx(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=Mu(ws(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 pa(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 Pu(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 Py,i.flowPositions[e.flowName]=n);let r=Cy(e.element),o=new Ai(r),s=new Ey(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 Jf{errorMsg(...s){}}let i=new t(null),n=Jc(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(qo(o)||Ps(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=Xh(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===th)continue;let s=1;r.pageBox.pseudoName===Kl&&!(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 Al(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=Xh(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 s0([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 fs(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 fs(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 jf||t instanceof Jl&&!(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=q0(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=zu(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=qc(S,0,0,a.width,a.height,this),b=new fx(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(),Vu(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 Xf?"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 Yd(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"&&Jb(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 Ny,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=zu(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=Mu(ws(u),this);this.setPageSizeAndBleed(N,e),Rx(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(),Vu(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`}},sS=class al 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 Bf(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Ex(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 al(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Wb(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new _o(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new rS(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 _o(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new _o(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 qf(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Kx(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 al(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Jf=class extends ka{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 Ev),d(this,"footnoteProps",{}),d(this,"flowProps",{}),d(this,"viewportProps",[]),d(this,"pageProps",{}),this.rootScope=new Wo(null),this.pageScope=new Wo(this.rootScope),this.rootBox=new yx(this.rootScope),this.cascadeParserHandler=new sS(this,null,null,null),this.slave=this.cascadeParserHandler}};function aS(e,t){return t.parseOPSResource(e)}var lS=class extends xl{constructor(e){super(aS,"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=Lp(),nS().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 Zf(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:dd,flavor:"UA",classes:null,media:null}),h.push({url:Ae("user-agent-counter-styles.css",Ci),text:md,flavor:"UA",classes:null,media:null}),n)h.push({url:Ae("user-agent-toc.css",Ci),text:fd,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 Jf(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Sl(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Cd(m.url,g,m.classes,m.media)}return T(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new oS(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",Uu="\u25BE",hS="\u25B9";function nh(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 uS(e){let t=nh(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var cS=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=dc(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",dS,!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=hS,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 Vd(e,e);this.page=s;let a=Dt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of nh(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new ms(t.window,u.fontSize,0,e,u.width,u.height);let c=this.makeCustomRenderer(h),p=new ih(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 dS(e){let t=e.target,i=t.textContent==br;t.textContent=i?Uu: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==Uu){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 vo(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function pS(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function fS(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Dt(e))}var $u=class extends lS{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=eS(),this.jsonStore=Mw()}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 zo(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):fS(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):ks(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 zo(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 zo(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=cl(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&&nh(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""}},Hu=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=Og}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=Ug(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 gS(e){return e.id}function mS(e){return t=>{let i=D("deobfuscator");return wS("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Lw(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(wd([a,o]))})}),i.result()}}function wS(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 yS(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 vS(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=Gs(o,c=>c.refines),a=c=>$g(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=Gs(w,v=>v.name);m.r=a(S)}return m})),h=a(Gs(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(yS(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function bS(){let e=window.MathJax;return e?e.Hub:null}var Wu={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},ua="viv-id-",zo=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 ua+hc(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(ua)===0&&(n=n.substring(ua.length));let r=Vg(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 Hu,u=h;l.initWithElement(u,e.url);let c=u.getAttribute("fallback");return c&&!Wu[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=mh(this.items,gS),this.itemMapByPath=mh(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(Wu[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=ec(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=vS(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=mS(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 Yf(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Hu;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 uS(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 Ih;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 Ih;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()}},bo=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),xS=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=dc(n),this.clientLayout=new mx(t),this.counterStore=new Om(e.documentURLTransformer),this.cmykStore=new Vc,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=vo(n));let r=vo(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=pS(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=vo(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?vo(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:bo(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(bo(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(bo(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(bo(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 Vd(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=pc(this.viewport.width,this.viewport.height,i.width,i.height),a=Ti(null,new vt(s,null),"");o.delayedItems.push(new Pl(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=fh(r),l=fh(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=bS();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 ms(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 ih(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 cS(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()}},Gu="data-vivliostyle-viewer-status",SS="data-vivliostyle-spread-view",Qf=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Qf||{}),CS=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",ld),o("vivliostyle-viewport-css",hd),o("vivliostyle-polyfill-css",gd),t.setAttribute("data-vivliostyle-viewer-viewport",!0),xr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(Gu,"loading"),this.fontMapper=new ix(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=cc(),this.pageSizes=[],this.pixelRatioLimit=ul==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=nc;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(Gu,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 $u;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 $u;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 zo(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"&&(ch(e.userAgentRootURL.replace(/resources\/?$/,"")),dh(e.userAgentRootURL)),typeof e.rootURL=="string"&&(ch(e.rootURL),dh(`${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&&(nx(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 ms(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new ms(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(SS,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=>{hm(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 xS(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 ju),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Sa().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&&Of(this.window)?ax(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 ju)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=Xu(e),i=null,n=this;Nw(()=>{let r=D("commandLoop"),o=Sa().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}},eg=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(eg||{}),ju=class tg extends Error{constructor(){super(),d(this,"name","RenderingCanceledError"),d(this,"message","Page rendering has been canceled"),d(this,"stack"),Object.setPrototypeOf(this,tg.prototype),this.stack=new Error().stack}};function Xu(e){return typeof e=="string"?cl(e):e}var qu=hl;function kS(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Yu(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 ig=class{constructor(e,t){this.settings=e,d(this,"initialized",!1),d(this,"adaptViewer_"),d(this,"options"),d(this,"eventTarget"),d(this,"readyState"),Qu(e.debug),this.adaptViewer_=new CS(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=kS(),t&&this.setOptions(t),this.eventTarget=new pl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Yu(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:ES(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Yu(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()===qu.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===qu.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 ES(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 ng=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(ng||{}),PS=eg,NS=Qf;Et.forceRegisterEndTiming("load_vivliostyle");var TS=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=`
1850
1872
  <!DOCTYPE html>
1851
1873
  <html data-vivliostyle-paginated="true">
1852
1874
  <head>
@@ -1874,6 +1896,6 @@ span[data-viv-leader] {
1874
1896
  <body onload='parent.printInstance.runInIframe(window)'>
1875
1897
  <div id="vivliostyle-viewer-viewport"></div>
1876
1898
  </body>
1877
- </html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new lf({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1878
- `);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function xx(e,t){new bx(e,t).init()}});var Sx=Sf(cf());var export_printHTML=Sx.printHTML;export{export_printHTML as printHTML};
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 ig({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 IS(e,t){new TS(e,t).init()}});var AS=mg(og());var export_printHTML=AS.printHTML;export{export_printHTML as printHTML};
1879
1901
  //# sourceMappingURL=index.es6.js.map