@vivliostyle/print 2.43.1 → 2.43.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +9 -9
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.es6.js +9 -9
- package/dist/index.es6.js.map +3 -3
- package/eslint.config.js +305 -0
- package/package.json +7 -5
- package/.eslintrc.js +0 -295
package/dist/index.cjs.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var kg=Object.create;var ss=Object.defineProperty;var Eg=Object.getOwnPropertyDescriptor;var Pg=Object.getOwnPropertyNames;var Ng=Object.getPrototypeOf,Tg=Object.prototype.hasOwnProperty;var Ig=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ag=(e,t)=>{for(var i in t)ss(e,i,{get:t[i],enumerable:!0})},bh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Pg(t))!Tg.call(e,r)&&r!==i&&ss(e,r,{get:()=>t[r],enumerable:!(n=Eg(t,r))||n.enumerable});return e};var Fg=(e,t,i)=>(i=e!=null?kg(Ng(e)):{},bh(t||!e||!e.__esModule?ss(i,"default",{value:e,enumerable:!0}):i,e)),Rg=e=>bh(ss({},"__esModule",{value:!0}),e);var wg=Ig((lC,vg)=>{"use strict";var Lg=Object.create,Hr=Object.defineProperty,Og=Object.getOwnPropertyDescriptor,Bg=Object.getOwnPropertyNames,Mg=Object.getPrototypeOf,_g=Object.prototype.hasOwnProperty,ac=e=>{throw TypeError(e)},Dg=(e,t,i)=>t in e?Hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,zg=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Vg=(e,t)=>{for(var i in t)Hr(e,i,{get:t[i],enumerable:!0})},lc=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Bg(t))!_g.call(e,r)&&r!==i&&Hr(e,r,{get:()=>t[r],enumerable:!(n=Og(t,r))||n.enumerable});return e},$g=(e,t,i)=>(i=e!=null?Lg(Mg(e)):{},lc(t||!e||!e.__esModule?Hr(i,"default",{value:e,enumerable:!0}):i,e)),Hg=e=>lc(Hr({},"__esModule",{value:!0}),e),d=(e,t,i)=>Dg(e,typeof t!="symbol"?t+"":t,i),vl=(e,t,i)=>t.has(e)||ac("Cannot "+i),H=(e,t,i)=>(vl(e,t,"read from private field"),i?i.call(e):t.get(e)),ie=(e,t,i)=>t.has(e)?ac("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),de=(e,t,i,n)=>(vl(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),le=(e,t,i)=>(vl(e,t,"access private method"),i),Ug=zg((e,t)=>{var i=-1,n=1,r=0;function s(k,_,E,B,P){if(k===_)return k?[[r,k]]:[];if(E!=null){var N=X(k,_,E);if(N)return N}var O=l(k,_),V=k.substring(0,O);k=k.substring(O),_=_.substring(O),O=c(k,_);var W=k.substring(k.length-O);k=k.substring(0,k.length-O),_=_.substring(0,_.length-O);var K=o(k,_);return V&&K.unshift([r,V]),W&&K.push([r,W]),S(K,P),B&&f(K),K}function o(k,_){var E;if(!k)return[[n,_]];if(!_)return[[i,k]];var B=k.length>_.length?k:_,P=k.length>_.length?_:k,N=B.indexOf(P);if(N!==-1)return E=[[n,B.substring(0,N)],[r,P],[n,B.substring(N+P.length)]],k.length>_.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,_]];var O=p(k,_);if(O){var V=O[0],W=O[1],K=O[2],te=O[3],Q=O[4],pe=s(V,K),se=s(W,te);return pe.concat([[r,Q]],se)}return a(k,_)}function a(k,_){for(var E=k.length,B=_.length,P=Math.ceil((E+B)/2),N=P,O=2*P,V=new Array(O),W=new Array(O),K=0;K<O;K++)V[K]=-1,W[K]=-1;V[N+1]=0,W[N+1]=0;for(var te=E-B,Q=te%2!==0,pe=0,se=0,oe=0,De=0,Ne=0;Ne<P;Ne++){for(var fe=-Ne+pe;fe<=Ne-se;fe+=2){var Ce=N+fe,ge;fe===-Ne||fe!==Ne&&V[Ce-1]<V[Ce+1]?ge=V[Ce+1]:ge=V[Ce-1]+1;for(var Ae=ge-fe;ge<E&&Ae<B&&k.charAt(ge)===_.charAt(Ae);)ge++,Ae++;if(V[Ce]=ge,ge>E)se+=2;else if(Ae>B)pe+=2;else if(Q){var Oe=N+te-fe;if(Oe>=0&&Oe<O&&W[Oe]!==-1){var Fe=E-W[Oe];if(ge>=Fe)return h(k,_,ge,Ae)}}}for(var Ue=-Ne+oe;Ue<=Ne-De;Ue+=2){var Oe=N+Ue,Fe;Ue===-Ne||Ue!==Ne&&W[Oe-1]<W[Oe+1]?Fe=W[Oe+1]:Fe=W[Oe-1]+1;for(var ft=Fe-Ue;Fe<E&&ft<B&&k.charAt(E-Fe-1)===_.charAt(B-ft-1);)Fe++,ft++;if(W[Oe]=Fe,Fe>E)De+=2;else if(ft>B)oe+=2;else if(!Q){var Ce=N+te-Ue;if(Ce>=0&&Ce<O&&V[Ce]!==-1){var ge=V[Ce],Ae=N+ge-Ce;if(Fe=E-Fe,ge>=Fe)return h(k,_,ge,Ae)}}}}return[[i,k],[n,_]]}function h(k,_,E,B){var P=k.substring(0,E),N=_.substring(0,B),O=k.substring(E),V=_.substring(B),W=s(P,N),K=s(O,V);return W.concat(K)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var E=0,B=Math.min(k.length,_.length),P=B,N=0;E<P;)k.substring(N,P)==_.substring(N,P)?(E=P,N=E):B=P,P=Math.floor((B-E)/2+E);return C(k.charCodeAt(P-1))&&P--,P}function u(k,_){var E=k.length,B=_.length;if(E==0||B==0)return 0;E>B?k=k.substring(E-B):E<B&&(_=_.substring(0,E));var P=Math.min(E,B);if(k==_)return P;for(var N=0,O=1;;){var V=k.substring(P-O),W=_.indexOf(V);if(W==-1)return N;O+=W,(W==0||k.substring(P-O)==_.substring(0,O))&&(N=O,O++)}}function c(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var E=0,B=Math.min(k.length,_.length),P=B,N=0;E<P;)k.substring(k.length-P,k.length-N)==_.substring(_.length-P,_.length-N)?(E=P,N=E):B=P,P=Math.floor((B-E)/2+E);return T(k.charCodeAt(k.length-P))&&P--,P}function p(k,_){var E=k.length>_.length?k:_,B=k.length>_.length?_:k;if(E.length<4||B.length*2<E.length)return null;function P(se,oe,De){for(var Ne=se.substring(De,De+Math.floor(se.length/4)),fe=-1,Ce="",ge,Ae,Oe,Fe;(fe=oe.indexOf(Ne,fe+1))!==-1;){var Ue=l(se.substring(De),oe.substring(fe)),ft=c(se.substring(0,De),oe.substring(0,fe));Ce.length<ft+Ue&&(Ce=oe.substring(fe-ft,fe)+oe.substring(fe,fe+Ue),ge=se.substring(0,De-ft),Ae=se.substring(De+Ue),Oe=oe.substring(0,fe-ft),Fe=oe.substring(fe+Ue))}return Ce.length*2>=se.length?[ge,Ae,Oe,Fe,Ce]:null}var N=P(E,B,Math.ceil(E.length/4)),O=P(E,B,Math.ceil(E.length/2)),V;if(!N&&!O)return null;O?N?V=N[4].length>O[4].length?N:O:V=O:V=N;var W,K,te,Q;k.length>_.length?(W=V[0],K=V[1],te=V[2],Q=V[3]):(te=V[0],Q=V[1],W=V[2],K=V[3]);var pe=V[4];return[W,K,te,Q,pe]}function f(k){for(var _=!1,E=[],B=0,P=null,N=0,O=0,V=0,W=0,K=0;N<k.length;)k[N][0]==r?(E[B++]=N,O=W,V=K,W=0,K=0,P=k[N][1]):(k[N][0]==n?W+=k[N][1].length:K+=k[N][1].length,P&&P.length<=Math.max(O,V)&&P.length<=Math.max(W,K)&&(k.splice(E[B-1],0,[i,P]),k[E[B-1]+1][0]=n,B--,B--,N=B>0?E[B-1]:-1,O=0,V=0,W=0,K=0,P=null,_=!0)),N++;for(_&&S(k),w(k),N=1;N<k.length;){if(k[N-1][0]==i&&k[N][0]==n){var te=k[N-1][1],Q=k[N][1],pe=u(te,Q),se=u(Q,te);pe>=se?(pe>=te.length/2||pe>=Q.length/2)&&(k.splice(N,0,[r,Q.substring(0,pe)]),k[N-1][1]=te.substring(0,te.length-pe),k[N+1][1]=Q.substring(pe),N++):(se>=te.length/2||se>=Q.length/2)&&(k.splice(N,0,[r,te.substring(0,se)]),k[N-1][0]=n,k[N-1][1]=Q.substring(0,Q.length-se),k[N+1][0]=i,k[N+1][1]=te.substring(se),N++),N++}N++}}var g=/[^a-zA-Z0-9]/,y=/\s/,b=/[\r\n]/,x=/\n\r?\n$/,m=/^\r?\n\r?\n/;function w(k){function _(se,oe){if(!se||!oe)return 6;var De=se.charAt(se.length-1),Ne=oe.charAt(0),fe=De.match(g),Ce=Ne.match(g),ge=fe&&De.match(y),Ae=Ce&&Ne.match(y),Oe=ge&&De.match(b),Fe=Ae&&Ne.match(b),Ue=Oe&&se.match(x),ft=Fe&&oe.match(m);return Ue||ft?5:Oe||Fe?4:fe&&!ge&&Ae?3:ge||Ae?2:fe||Ce?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var B=k[E-1][1],P=k[E][1],N=k[E+1][1],O=c(B,P);if(O){var V=P.substring(P.length-O);B=B.substring(0,B.length-O),P=V+P.substring(0,P.length-O),N=V+N}for(var W=B,K=P,te=N,Q=_(B,P)+_(P,N);P.charAt(0)===N.charAt(0);){B+=P.charAt(0),P=P.substring(1)+N.charAt(0),N=N.substring(1);var pe=_(B,P)+_(P,N);pe>=Q&&(Q=pe,W=B,K=P,te=N)}k[E-1][1]!=W&&(W?k[E-1][1]=W:(k.splice(E-1,1),E--),k[E][1]=K,te?k[E+1][1]=te:(k.splice(E+1,1),E--))}E++}}function S(k,_){k.push([r,""]);for(var E=0,B=0,P=0,N="",O="",V;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:B++,N+=k[E][1],E++;break;case r:var W=E-P-B-1;if(_){if(W>=0&&F(k[W][1])){var K=k[W][1].slice(-1);if(k[W][1]=k[W][1].slice(0,-1),N=K+N,O=K+O,!k[W][1]){k.splice(W,1),E--;var te=W-1;k[te]&&k[te][0]===n&&(P++,O=k[te][1]+O,te--),k[te]&&k[te][0]===i&&(B++,N=k[te][1]+N,te--),W=te}}if(R(k[E][1])){var K=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),N+=K,O+=K}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(N.length>0||O.length>0){N.length>0&&O.length>0&&(V=l(O,N),V!==0&&(W>=0?k[W][1]+=O.substring(0,V):(k.splice(0,0,[r,O.substring(0,V)]),E++),O=O.substring(V),N=N.substring(V)),V=c(O,N),V!==0&&(k[E][1]=O.substring(O.length-V)+k[E][1],O=O.substring(0,O.length-V),N=N.substring(0,N.length-V)));var Q=P+B;N.length===0&&O.length===0?(k.splice(E-Q,Q),E=E-Q):N.length===0?(k.splice(E-Q,Q,[n,O]),E=E-Q+1):O.length===0?(k.splice(E-Q,Q,[i,N]),E=E-Q+1):(k.splice(E-Q,Q,[i,N],[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,B=0,N="",O="";break}}k[k.length-1][1]===""&&k.pop();var pe=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),pe=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),pe=!0)),E++;pe&&S(k,_)}function C(k){return k>=55296&&k<=56319}function T(k){return k>=56320&&k<=57343}function R(k){return T(k.charCodeAt(0))}function F(k){return C(k.charCodeAt(k.length-1))}function z(k){for(var _=[],E=0;E<k.length;E++)k[E][1].length>0&&_.push(k[E]);return _}function $(k,_,E,B){return F(k)||R(B)?null:z([[r,k],[i,_],[n,E],[r,B]])}function X(k,_,E){var B=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,N=k.length,O=_.length;if(B.length===0&&(P===null||P.length===0)){var V=B.index,W=k.slice(0,V),K=k.slice(V),te=P?P.index:null;e:{var Q=V+O-N;if(te!==null&&te!==Q||Q<0||Q>O)break e;var pe=_.slice(0,Q),se=_.slice(Q);if(se!==K)break e;var oe=Math.min(V,Q),De=W.slice(0,oe),Ne=pe.slice(0,oe);if(De!==Ne)break e;var fe=W.slice(oe),Ce=pe.slice(oe);return $(De,fe,Ce,K)}e:{if(te!==null&&te!==V)break e;var ge=V,pe=_.slice(0,ge),se=_.slice(ge);if(pe!==W)break e;var Ae=Math.min(N-ge,O-ge),Oe=K.slice(K.length-Ae),Fe=se.slice(se.length-Ae);if(Oe!==Fe)break e;var fe=K.slice(0,K.length-Ae),Ce=se.slice(0,se.length-Ae);return $(W,fe,Ce,Oe)}}if(B.length>0&&P&&P.length===0)e:{var De=k.slice(0,B.index),Oe=k.slice(B.index+B.length),oe=De.length,Ae=Oe.length;if(O<oe+Ae)break e;var Ne=_.slice(0,oe),Fe=_.slice(O-Ae);if(De!==Ne||Oe!==Fe)break e;var fe=k.slice(oe,N-Ae),Ce=_.slice(oe,O-Ae);return $(De,fe,Ce,Oe)}return null}function re(k,_,E,B){return s(k,_,E,B,!0)}re.INSERT=n,re.DELETE=i,re.EQUAL=r,t.exports=re}),hc={};Vg(hc,{CoreViewer:()=>mg,HOOKS:()=>No,Navigation:()=>yg,PageProgression:()=>wl,PageSide:()=>dc,PageViewMode:()=>XS,Profiler:()=>mc,ReadyState:()=>pc,UserAgentBaseCss:()=>kd,UserAgentCounterStylesCss:()=>Nd,UserAgentPageCss:()=>Cd,UserAgentTocCss:()=>Ed,UserAgentXml:()=>Sd,ValidationTxt:()=>xd,VivliostylePolyfillCss:()=>Pd,VivliostyleViewportCss:()=>bd,VivliostyleViewportScreenCss:()=>wd,ZoomType:()=>jS,getHooksForName:()=>Gt,isDebug:()=>Tr,pageProgressionOf:()=>cc,plugin:()=>Gg,printHTML:()=>YS,profile:()=>Yg,profiler:()=>Pt,registerHook:()=>Ot,removeHook:()=>gc,setDebug:()=>uc});vg.exports=Hg(hc);var Tr=!1;function uc(e){Tr=e}var wl=(e=>(e.LTR="ltr",e.RTL="rtl",e))(wl||{});function cc(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var dc=(e=>(e.LEFT="left",e.RIGHT="right",e))(dc||{}),pc=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(pc||{}),fc=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(fc||{}),Wg=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=os(arguments);this.consoleDebug(as(t)),this.triggerListeners(1,t)}info(...e){let t=os(arguments);this.consoleInfo(as(t)),this.triggerListeners(2,t)}warn(...e){let t=os(arguments);this.consoleWarn(as(t)),this.triggerListeners(3,t)}error(...e){let t=os(arguments);this.consoleError(as(t)),this.triggerListeners(4,t)}};function os(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function as(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 kg=Object.create;var ss=Object.defineProperty;var Eg=Object.getOwnPropertyDescriptor;var Pg=Object.getOwnPropertyNames;var Ng=Object.getPrototypeOf,Tg=Object.prototype.hasOwnProperty;var Ig=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},Ag=(e,t)=>{for(var i in t)ss(e,i,{get:t[i],enumerable:!0})},bh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Pg(t))!Tg.call(e,r)&&r!==i&&ss(e,r,{get:()=>t[r],enumerable:!(n=Eg(t,r))||n.enumerable});return e};var Fg=(e,t,i)=>(i=e!=null?kg(Ng(e)):{},bh(t||!e||!e.__esModule?ss(i,"default",{value:e,enumerable:!0}):i,e)),Rg=e=>bh(ss({},"__esModule",{value:!0}),e);var wg=Ig((aC,vg)=>{"use strict";var Lg=Object.create,Hr=Object.defineProperty,Og=Object.getOwnPropertyDescriptor,Bg=Object.getOwnPropertyNames,Mg=Object.getPrototypeOf,_g=Object.prototype.hasOwnProperty,ac=e=>{throw TypeError(e)},Dg=(e,t,i)=>t in e?Hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,zg=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},Vg=(e,t)=>{for(var i in t)Hr(e,i,{get:t[i],enumerable:!0})},lc=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Bg(t))!_g.call(e,r)&&r!==i&&Hr(e,r,{get:()=>t[r],enumerable:!(n=Og(t,r))||n.enumerable});return e},$g=(e,t,i)=>(i=e!=null?Lg(Mg(e)):{},lc(t||!e||!e.__esModule?Hr(i,"default",{value:e,enumerable:!0}):i,e)),Hg=e=>lc(Hr({},"__esModule",{value:!0}),e),u=(e,t,i)=>Dg(e,typeof t!="symbol"?t+"":t,i),wl=(e,t,i)=>t.has(e)||ac("Cannot "+i),H=(e,t,i)=>(wl(e,t,"read from private field"),i?i.call(e):t.get(e)),ie=(e,t,i)=>t.has(e)?ac("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),de=(e,t,i,n)=>(wl(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),le=(e,t,i)=>(wl(e,t,"access private method"),i),Ug=zg((e,t)=>{var i=-1,n=1,r=0;function s(k,_,E,B,P){if(k===_)return k?[[r,k]]:[];if(E!=null){var N=X(k,_,E);if(N)return N}var O=l(k,_),V=k.substring(0,O);k=k.substring(O),_=_.substring(O),O=d(k,_);var W=k.substring(k.length-O);k=k.substring(0,k.length-O),_=_.substring(0,_.length-O);var J=o(k,_);return V&&J.unshift([r,V]),W&&J.push([r,W]),S(J,P),B&&f(J),J}function o(k,_){var E;if(!k)return[[n,_]];if(!_)return[[i,k]];var B=k.length>_.length?k:_,P=k.length>_.length?_:k,N=B.indexOf(P);if(N!==-1)return E=[[n,B.substring(0,N)],[r,P],[n,B.substring(N+P.length)]],k.length>_.length&&(E[0][0]=E[2][0]=i),E;if(P.length===1)return[[i,k],[n,_]];var O=p(k,_);if(O){var V=O[0],W=O[1],J=O[2],te=O[3],Q=O[4],pe=s(V,J),se=s(W,te);return pe.concat([[r,Q]],se)}return a(k,_)}function a(k,_){for(var E=k.length,B=_.length,P=Math.ceil((E+B)/2),N=P,O=2*P,V=new Array(O),W=new Array(O),J=0;J<O;J++)V[J]=-1,W[J]=-1;V[N+1]=0,W[N+1]=0;for(var te=E-B,Q=te%2!==0,pe=0,se=0,oe=0,De=0,Ne=0;Ne<P;Ne++){for(var fe=-Ne+pe;fe<=Ne-se;fe+=2){var Ce=N+fe,ge;fe===-Ne||fe!==Ne&&V[Ce-1]<V[Ce+1]?ge=V[Ce+1]:ge=V[Ce-1]+1;for(var Ae=ge-fe;ge<E&&Ae<B&&k.charAt(ge)===_.charAt(Ae);)ge++,Ae++;if(V[Ce]=ge,ge>E)se+=2;else if(Ae>B)pe+=2;else if(Q){var Oe=N+te-fe;if(Oe>=0&&Oe<O&&W[Oe]!==-1){var Fe=E-W[Oe];if(ge>=Fe)return h(k,_,ge,Ae)}}}for(var Ue=-Ne+oe;Ue<=Ne-De;Ue+=2){var Oe=N+Ue,Fe;Ue===-Ne||Ue!==Ne&&W[Oe-1]<W[Oe+1]?Fe=W[Oe+1]:Fe=W[Oe-1]+1;for(var ft=Fe-Ue;Fe<E&&ft<B&&k.charAt(E-Fe-1)===_.charAt(B-ft-1);)Fe++,ft++;if(W[Oe]=Fe,Fe>E)De+=2;else if(ft>B)oe+=2;else if(!Q){var Ce=N+te-Ue;if(Ce>=0&&Ce<O&&V[Ce]!==-1){var ge=V[Ce],Ae=N+ge-Ce;if(Fe=E-Fe,ge>=Fe)return h(k,_,ge,Ae)}}}}return[[i,k],[n,_]]}function h(k,_,E,B){var P=k.substring(0,E),N=_.substring(0,B),O=k.substring(E),V=_.substring(B),W=s(P,N),J=s(O,V);return W.concat(J)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var E=0,B=Math.min(k.length,_.length),P=B,N=0;E<P;)k.substring(N,P)==_.substring(N,P)?(E=P,N=E):B=P,P=Math.floor((B-E)/2+E);return C(k.charCodeAt(P-1))&&P--,P}function c(k,_){var E=k.length,B=_.length;if(E==0||B==0)return 0;E>B?k=k.substring(E-B):E<B&&(_=_.substring(0,E));var P=Math.min(E,B);if(k==_)return P;for(var N=0,O=1;;){var V=k.substring(P-O),W=_.indexOf(V);if(W==-1)return N;O+=W,(W==0||k.substring(P-O)==_.substring(0,O))&&(N=O,O++)}}function d(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var E=0,B=Math.min(k.length,_.length),P=B,N=0;E<P;)k.substring(k.length-P,k.length-N)==_.substring(_.length-P,_.length-N)?(E=P,N=E):B=P,P=Math.floor((B-E)/2+E);return T(k.charCodeAt(k.length-P))&&P--,P}function p(k,_){var E=k.length>_.length?k:_,B=k.length>_.length?_:k;if(E.length<4||B.length*2<E.length)return null;function P(se,oe,De){for(var Ne=se.substring(De,De+Math.floor(se.length/4)),fe=-1,Ce="",ge,Ae,Oe,Fe;(fe=oe.indexOf(Ne,fe+1))!==-1;){var Ue=l(se.substring(De),oe.substring(fe)),ft=d(se.substring(0,De),oe.substring(0,fe));Ce.length<ft+Ue&&(Ce=oe.substring(fe-ft,fe)+oe.substring(fe,fe+Ue),ge=se.substring(0,De-ft),Ae=se.substring(De+Ue),Oe=oe.substring(0,fe-ft),Fe=oe.substring(fe+Ue))}return Ce.length*2>=se.length?[ge,Ae,Oe,Fe,Ce]:null}var N=P(E,B,Math.ceil(E.length/4)),O=P(E,B,Math.ceil(E.length/2)),V;if(!N&&!O)return null;O?N?V=N[4].length>O[4].length?N:O:V=O:V=N;var W,J,te,Q;k.length>_.length?(W=V[0],J=V[1],te=V[2],Q=V[3]):(te=V[0],Q=V[1],W=V[2],J=V[3]);var pe=V[4];return[W,J,te,Q,pe]}function f(k){for(var _=!1,E=[],B=0,P=null,N=0,O=0,V=0,W=0,J=0;N<k.length;)k[N][0]==r?(E[B++]=N,O=W,V=J,W=0,J=0,P=k[N][1]):(k[N][0]==n?W+=k[N][1].length:J+=k[N][1].length,P&&P.length<=Math.max(O,V)&&P.length<=Math.max(W,J)&&(k.splice(E[B-1],0,[i,P]),k[E[B-1]+1][0]=n,B--,B--,N=B>0?E[B-1]:-1,O=0,V=0,W=0,J=0,P=null,_=!0)),N++;for(_&&S(k),w(k),N=1;N<k.length;){if(k[N-1][0]==i&&k[N][0]==n){var te=k[N-1][1],Q=k[N][1],pe=c(te,Q),se=c(Q,te);pe>=se?(pe>=te.length/2||pe>=Q.length/2)&&(k.splice(N,0,[r,Q.substring(0,pe)]),k[N-1][1]=te.substring(0,te.length-pe),k[N+1][1]=Q.substring(pe),N++):(se>=te.length/2||se>=Q.length/2)&&(k.splice(N,0,[r,te.substring(0,se)]),k[N-1][0]=n,k[N-1][1]=Q.substring(0,Q.length-se),k[N+1][0]=i,k[N+1][1]=te.substring(se),N++),N++}N++}}var g=/[^a-zA-Z0-9]/,y=/\s/,b=/[\r\n]/,x=/\n\r?\n$/,m=/^\r?\n\r?\n/;function w(k){function _(se,oe){if(!se||!oe)return 6;var De=se.charAt(se.length-1),Ne=oe.charAt(0),fe=De.match(g),Ce=Ne.match(g),ge=fe&&De.match(y),Ae=Ce&&Ne.match(y),Oe=ge&&De.match(b),Fe=Ae&&Ne.match(b),Ue=Oe&&se.match(x),ft=Fe&&oe.match(m);return Ue||ft?5:Oe||Fe?4:fe&&!ge&&Ae?3:ge||Ae?2:fe||Ce?1:0}for(var E=1;E<k.length-1;){if(k[E-1][0]==r&&k[E+1][0]==r){var B=k[E-1][1],P=k[E][1],N=k[E+1][1],O=d(B,P);if(O){var V=P.substring(P.length-O);B=B.substring(0,B.length-O),P=V+P.substring(0,P.length-O),N=V+N}for(var W=B,J=P,te=N,Q=_(B,P)+_(P,N);P.charAt(0)===N.charAt(0);){B+=P.charAt(0),P=P.substring(1)+N.charAt(0),N=N.substring(1);var pe=_(B,P)+_(P,N);pe>=Q&&(Q=pe,W=B,J=P,te=N)}k[E-1][1]!=W&&(W?k[E-1][1]=W:(k.splice(E-1,1),E--),k[E][1]=J,te?k[E+1][1]=te:(k.splice(E+1,1),E--))}E++}}function S(k,_){k.push([r,""]);for(var E=0,B=0,P=0,N="",O="",V;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:B++,N+=k[E][1],E++;break;case r:var W=E-P-B-1;if(_){if(W>=0&&F(k[W][1])){var J=k[W][1].slice(-1);if(k[W][1]=k[W][1].slice(0,-1),N=J+N,O=J+O,!k[W][1]){k.splice(W,1),E--;var te=W-1;k[te]&&k[te][0]===n&&(P++,O=k[te][1]+O,te--),k[te]&&k[te][0]===i&&(B++,N=k[te][1]+N,te--),W=te}}if(R(k[E][1])){var J=k[E][1].charAt(0);k[E][1]=k[E][1].slice(1),N+=J,O+=J}}if(E<k.length-1&&!k[E][1]){k.splice(E,1);break}if(N.length>0||O.length>0){N.length>0&&O.length>0&&(V=l(O,N),V!==0&&(W>=0?k[W][1]+=O.substring(0,V):(k.splice(0,0,[r,O.substring(0,V)]),E++),O=O.substring(V),N=N.substring(V)),V=d(O,N),V!==0&&(k[E][1]=O.substring(O.length-V)+k[E][1],O=O.substring(0,O.length-V),N=N.substring(0,N.length-V)));var Q=P+B;N.length===0&&O.length===0?(k.splice(E-Q,Q),E=E-Q):N.length===0?(k.splice(E-Q,Q,[n,O]),E=E-Q+1):O.length===0?(k.splice(E-Q,Q,[i,N]),E=E-Q+1):(k.splice(E-Q,Q,[i,N],[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,B=0,N="",O="";break}}k[k.length-1][1]===""&&k.pop();var pe=!1;for(E=1;E<k.length-1;)k[E-1][0]===r&&k[E+1][0]===r&&(k[E][1].substring(k[E][1].length-k[E-1][1].length)===k[E-1][1]?(k[E][1]=k[E-1][1]+k[E][1].substring(0,k[E][1].length-k[E-1][1].length),k[E+1][1]=k[E-1][1]+k[E+1][1],k.splice(E-1,1),pe=!0):k[E][1].substring(0,k[E+1][1].length)==k[E+1][1]&&(k[E-1][1]+=k[E+1][1],k[E][1]=k[E][1].substring(k[E+1][1].length)+k[E+1][1],k.splice(E+1,1),pe=!0)),E++;pe&&S(k,_)}function C(k){return k>=55296&&k<=56319}function T(k){return k>=56320&&k<=57343}function R(k){return T(k.charCodeAt(0))}function F(k){return C(k.charCodeAt(k.length-1))}function z(k){for(var _=[],E=0;E<k.length;E++)k[E][1].length>0&&_.push(k[E]);return _}function $(k,_,E,B){return F(k)||R(B)?null:z([[r,k],[i,_],[n,E],[r,B]])}function X(k,_,E){var B=typeof E=="number"?{index:E,length:0}:E.oldRange,P=typeof E=="number"?null:E.newRange,N=k.length,O=_.length;if(B.length===0&&(P===null||P.length===0)){var V=B.index,W=k.slice(0,V),J=k.slice(V),te=P?P.index:null;e:{var Q=V+O-N;if(te!==null&&te!==Q||Q<0||Q>O)break e;var pe=_.slice(0,Q),se=_.slice(Q);if(se!==J)break e;var oe=Math.min(V,Q),De=W.slice(0,oe),Ne=pe.slice(0,oe);if(De!==Ne)break e;var fe=W.slice(oe),Ce=pe.slice(oe);return $(De,fe,Ce,J)}e:{if(te!==null&&te!==V)break e;var ge=V,pe=_.slice(0,ge),se=_.slice(ge);if(pe!==W)break e;var Ae=Math.min(N-ge,O-ge),Oe=J.slice(J.length-Ae),Fe=se.slice(se.length-Ae);if(Oe!==Fe)break e;var fe=J.slice(0,J.length-Ae),Ce=se.slice(0,se.length-Ae);return $(W,fe,Ce,Oe)}}if(B.length>0&&P&&P.length===0)e:{var De=k.slice(0,B.index),Oe=k.slice(B.index+B.length),oe=De.length,Ae=Oe.length;if(O<oe+Ae)break e;var Ne=_.slice(0,oe),Fe=_.slice(O-Ae);if(De!==Ne||Oe!==Fe)break e;var fe=k.slice(oe,N-Ae),Ce=_.slice(oe,O-Ae);return $(De,fe,Ce,Oe)}return null}function re(k,_,E,B){return s(k,_,E,B,!0)}re.INSERT=n,re.DELETE=i,re.EQUAL=r,t.exports=re}),hc={};Vg(hc,{CoreViewer:()=>mg,HOOKS:()=>No,Navigation:()=>yg,PageProgression:()=>bl,PageSide:()=>dc,PageViewMode:()=>ZS,Profiler:()=>mc,ReadyState:()=>pc,UserAgentBaseCss:()=>kd,UserAgentCounterStylesCss:()=>Nd,UserAgentPageCss:()=>Cd,UserAgentTocCss:()=>Ed,UserAgentXml:()=>Sd,ValidationTxt:()=>xd,VivliostylePolyfillCss:()=>Pd,VivliostyleViewportCss:()=>bd,VivliostyleViewportScreenCss:()=>wd,ZoomType:()=>YS,getHooksForName:()=>Gt,isDebug:()=>Tr,pageProgressionOf:()=>cc,plugin:()=>Gg,printHTML:()=>JS,profile:()=>Yg,profiler:()=>Pt,registerHook:()=>Ot,removeHook:()=>gc,setDebug:()=>uc});vg.exports=Hg(hc);var Tr=!1;function uc(e){Tr=e}var bl=(e=>(e.LTR="ltr",e.RTL="rtl",e))(bl||{});function cc(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var dc=(e=>(e.LEFT="left",e.RIGHT="right",e))(dc||{}),pc=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(pc||{}),fc=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(fc||{}),Wg=class{constructor(e){u(this,"opt_console",e),u(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=os(arguments);this.consoleDebug(as(t)),this.triggerListeners(1,t)}info(...e){let t=os(arguments);this.consoleInfo(as(t)),this.triggerListeners(2,t)}warn(...e){let t=os(arguments);this.consoleWarn(as(t)),this.triggerListeners(3,t)}error(...e){let t=os(arguments);this.consoleError(as(t)),this.triggerListeners(4,t)}};function os(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function as(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 q=new Wg,No=(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))(No||{}),qs={};function Ot(e,t,i){if(!No[e])q.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=qs[e];n||(n=qs[e]=[]),i?n.unshift(t):n.push(t)}}function gc(e,t){if(!No[e])q.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=qs[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Gt(e){return qs[e]||[]}var Gg={registerHook:Ot,removeHook:gc},mc=class{constructor(e){this
|
|
4
|
-
`}}),q.info(t)}disable(){this.registerTiming=ln,this.registerStartTiming=this.registerStartTiming=ln,this.registerEndTiming=this.registerEndTiming=ln}enable(){this.registerTiming=Ko,this.registerStartTiming=this.registerStartTiming=xh,this.registerEndTiming=this.registerEndTiming=jg}isEnabled(){return this.registerStartTiming===xh}};function ln(){}function Ko(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,s=n.length;for(let o=s-1;o>=0&&(r=n[o],!(r&&!r[t]));o--)r=null;r||(r={},n.push(r)),r[t]=i}function xh(e,t){this.registerTiming(e,"start",t)}function jg(e,t){this.registerTiming(e,"end",t)}var Xg={now:Date.now},qg=window&&window.performance,Pt=new mc(qg||Xg);Pt.forceRegisterStartTiming("load_vivliostyle");var Yg={profiler:{registerStartTiming:Pt.registerStartTiming,registerEndTiming:Pt.registerEndTiming,printTimings:Pt.printTimings,disable:Pt.disable,enable:Pt.enable}},bl=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Ys=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Vt="data-adapt-eloff",Zg={};function xl(e){return JSON.parse(e)}function Ht(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function yc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Ji=window.location.href;function Sh(e){Ji=e}var Ni=window.location.href;function Ch(e){Ni=e}function Kg(e){let t=yc(e).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function Ir(e){return e.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ie(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let o=Kg(t);return o?o+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=yc(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,s="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],s=i[2]);n=r.indexOf("/../"),!(n<=0);){let o=r.lastIndexOf("/",n-1);if(o<=0)break;r=r.substr(0,o)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+s}function Zs(e,t){return e.match(/^#/)&&t?Ht(t)+e:Ie(e,t)}function vc(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function An(e){let t;return(e=vc(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 kh(e){return e==null?e:e.toString()}var Jg=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}},wc=["","-webkit-","-moz-"],dn={};function Is(e,t){return CSS.supports(e+t,"unset")}function Qg(e){let t=dn[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return dn[e]=null,null;case"text-combine-upright":if(Is("-webkit-","text-combine")&&!Is("","text-combine-upright"))return dn[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of wc)if(Is(i,e))return t=[i+e],dn[e]=t,t;return q.warn("Property not supported by the browser: ",e),dn[e]=null,null}function A(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=Qg(t);if(r)for(let s of r){switch(s){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(s,i)}}function ki(e,t,i){try{let n=dn[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function wa(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 gi=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 Sl(e){return`\\${e.charCodeAt(0).toString(16)} `}function Ti(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Sl)}function Ur(e){return e.replace(/[\u0000-\u001F"\\]/g,Sl)}function Eh(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Ph(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function em(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function bc(e,t){function i(n){return em(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Ks(e){return bc(e)}function tm(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function im(e,t){t=typeof t=="string"?t:"\\u";function i(r){return tm(r,t)}let n=new RegExp(`${Ks(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function mi(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 xc(e,t){return e-t}function Nh(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function nm(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Jo(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 rm(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Cl=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)}}},ji={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Sc(){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 Cc(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 sm=Sc(),Th={PENDING:{}};function kc(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function om(e){return`"${Ur(`${e}`)}"`}function am(e){return Ti(`${e}`)}function ba(e,t){return e?`${Ti(e)}.${Ti(t)}`:Ti(t)}var Ec=0,Js=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${Ec++}`,this.zero=new tt(this,0),this.one=new tt(this,1),this._true=new tt(this,!0),this._false=new tt(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=kc,i["css-string"]=om,i["css-name"]=am,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 we(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 lm(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Pc(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 hm(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function um(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Yt={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 Nc(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 xa=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=sm}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(Pc(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,s=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return s;case"vh":return o;case"vi":return a?o:s;case"vb":return a?s:o;case"vmin":return s<o?s:o;case"vmax":return s>o?s:o;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Yt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let s=e.builtIns[t];if(s){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new tt(e,s.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,s=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":s=this.pageWidth();break;case"height":s=this.pageHeight();break;case"device-width":s=window.screen.availWidth;break;case"device-height":s=window.screen.availHeight;break;case"color":s=window.screen.pixelDepth;break}if(s!=null&&r!=null)switch(i){case"min":return s>=Number(r);case"max":return s<=Number(r);default:return s==r}else if(s!=null&&t==null)return s!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Xt=class{constructor(e){this.scope=e,d(this,"key"),this.scope=e,this.key=`_${Ec++}`}toString(){let e=new gi;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===Th.PENDING?!1:n;{i[this.key]=Th.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}},Tc=class extends Xt{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)}},To=class extends Xt{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)}},Ic=class extends To{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Wn=class extends To{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Ac=class extends To{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},kl=class extends To{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ii=class extends Tc{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},cm=class extends Ii{constructor(e,t){super(e,t)}getOp(){return"not "}},Sn=class extends Tc{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},El=class extends Ic{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},dm=class extends El{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Pl=class extends Ic{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},pm=class extends Pl{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},fm=class extends Pl{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},gm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},mm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},ym=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Sa=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Nl=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},vm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},Fc=class extends Ac{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Rc=class extends Ac{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Tl=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Lc=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Oc=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Wr=class extends Xt{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(Ti(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Je=class extends Xt{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)}},Ih=class extends Xt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(Ti(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},we=class extends Xt{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 wm(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function bm(e,t,i){let n=t;for(let r=0;r<t.length;r++){let s=t[r].expand(e,i);if(t!==n)n[r]=s;else if(s!==t[r]){n=Array(t.length);for(let o=0;o<r;o++)n[o]=t[o];n[r]=s}}return n}var mr=class Bc extends Xt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),wm(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=bm(t,this.params,i);return n===this.params?this:new Bc(this.scope,this.qualifiedName,n)}},xm=class Mc extends Xt{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),s=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&s===this.ifFalse?this:new Mc(this.scope,n,r,s)}},tt=class extends Xt{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(Ur(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Ah=class _c extends Xt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(Ur(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 _c(this.scope,this.name,n)}},Sm=class extends Xt{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)}},Dc=class extends Xt{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 Ut(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 El(e,t,i)}function ne(e,t,i){return t===e.zero?i:i===e.zero?t:new Fc(e,t,i)}function ye(e,t,i){return t===e.zero?new Sn(e,i):i===e.zero?t:new Rc(e,t,i)}function As(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Tl(e,t,i)}function Ca(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Lc(e,t,i)}var Zt=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}},nn=class extends Zt{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 s=0;s<i;s++)t[s]=e[s];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new _e(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new ai(e.name,t)}visitExpr(e){return e}},st=class{toString(){let e=new gi;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new gi;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}},zc=class Vc extends st{static get instance(){return this.empty||(this.empty=new Vc),this.empty}constructor(){super()}toExpr(t,i){return new tt(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};d(zc,"empty");var Cm=zc,Be=Cm.instance,$c=class Hc extends st{static get instance(){return this.slash||(this.slash=new Hc),this.slash}constructor(){super()}toExpr(t,i){return new tt(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};d($c,"slash");var km=$c,Gn=km.instance,Z=class extends st{constructor(e){super(),this.str=e}toExpr(e,t){return new tt(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(Ur(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},ka=Object.create(null),he=class extends st{constructor(e){if(super(),this.name=e,ka[e])throw new Error("E_INVALID_CALL");ka[e]=this}toExpr(e,t){return new tt(e,this.name)}appendTo(e,t){t?e.append(Ti(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function M(e){let t=ka[e];return t||(t=new he(e)),t}var L=class extends st{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 Tl(e,t,new tt(e,this.num/100)):new Wr(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}},Tt=class extends st{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new tt(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},lt=class extends Tt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Uc=class extends st{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},it=class extends st{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(Ur(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Wc=class extends st{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Il(e,t,i,n){var r,s;let o=t.length;if(o>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(s=t[a])==null||s.appendTo(e,n)}}var J=class extends st{constructor(e){super(),this.values=e}appendTo(e,t){Il(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},_e=class extends st{constructor(e){super(),this.values=e}appendTo(e,t){Il(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ai=class extends st{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(Ti(this.name)),e.append("("),Il(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},j=class extends st{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof tt||this.expr instanceof Wr?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}},pn=class extends st{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 Gc(e,t){return new L(ut(e,t),"px")}var v={absolute:M("absolute"),all:M("all"),always:M("always"),anywhere:M("anywhere"),auto:M("auto"),avoid:M("avoid"),balance:M("balance"),balance_all:M("balance-all"),block:M("block"),block_end:M("block-end"),block_start:M("block-start"),both:M("both"),bottom:M("bottom"),border_box:M("border-box"),break_all:M("break-all"),break_word:M("break-word"),clip:M("clip"),crop:M("crop"),cross:M("cross"),column:M("column"),discard:M("discard"),exclusive:M("exclusive"),_false:M("false"),fixed:M("fixed"),flex:M("flex"),flow_root:M("flow-root"),footnote:M("footnote"),footer:M("footer"),grid:M("grid"),header:M("header"),hidden:M("hidden"),horizontal_tb:M("horizontal-tb"),inherit:M("inherit"),initial:M("initial"),inline:M("inline"),inline_block:M("inline-block"),inline_end:M("inline-end"),inline_start:M("inline-start"),inside:M("inside"),keep:M("keep"),landscape:M("landscape"),left:M("left"),line:M("line"),list_item:M("list-item"),ltr:M("ltr"),manual:M("manual"),max_content:M("max-content"),min_content:M("min-content"),none:M("none"),normal:M("normal"),oeb_page_foot:M("oeb-page-foot"),oeb_page_head:M("oeb-page-head"),outside:M("outside"),padding_box:M("padding-box"),page:M("page"),relative:M("relative"),revert:M("revert"),right:M("right"),same:M("same"),scale:M("scale"),snap_block:M("snap-block"),snap_inline:M("snap-inline"),solid:M("solid"),spread:M("spread"),_static:M("static"),rtl:M("rtl"),table:M("table"),table_caption:M("table-caption"),table_cell:M("table-cell"),table_footer_group:M("table-footer-group"),table_header_group:M("table-header-group"),table_row:M("table-row"),top:M("top"),transparent:M("transparent"),unset:M("unset"),vertical_lr:M("vertical-lr"),vertical_rl:M("vertical-rl"),visible:M("visible"),_true:M("true")},Fh=new L(100,"%"),Gr=new L(100,"pvw"),jr=new L(100,"pvh"),Le=new L(0,"px"),JS=new Wc("U+0-10FFFF"),Rh={"font-size":1,"line-height":2,color:3};function Y(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Lh(e,t){let i=Rh[e]||Number.MAX_VALUE,n=Rh[t]||Number.MAX_VALUE;return i-n}function Xe(e){return e?.length>2&&e.startsWith("--")}var fn,gn,mn,jc=class li{constructor(t,i,n){ie(this,fn),ie(this,gn),ie(this,mn),de(this,fn,Math.round(Math.max(0,Math.min(t,li.MAX)))),de(this,gn,Math.round(Math.max(0,Math.min(i,li.MAX)))),de(this,mn,Math.round(Math.max(0,Math.min(n,li.MAX))))}static fromInt(t,i,n){return new li(t,i,n)}offset(t,i,n){return new li(H(this,fn)+t,H(this,gn)+i,H(this,mn)+n)}toKey(){return JSON.stringify([H(this,fn),H(this,gn),H(this,mn)])}toColorFunc(t){return new ai("color",[new J([M("srgb"),new Tt(H(this,fn)/li.MAX),new Tt(H(this,gn)/li.MAX),new Tt(H(this,mn)/li.MAX),...t!==null?[Gn,new Tt(t)]:[]])])}};fn=new WeakMap,gn=new WeakMap,mn=new WeakMap,d(jc,"MAX",1e4);var ui=jc;function Em(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,s=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(s.c)&&Number.isFinite(s.m)&&Number.isFinite(s.y)&&Number.isFinite(s.k)}):!1}var Vi,$i,Hi,Jt,Xc=class mt{constructor(t,i,n,r){ie(this,Vi),ie(this,$i),ie(this,Hi),ie(this,Jt),de(this,Vi,Math.round(Math.max(0,Math.min(t,mt.MAX)))),de(this,$i,Math.round(Math.max(0,Math.min(i,mt.MAX)))),de(this,Hi,Math.round(Math.max(0,Math.min(n,mt.MAX)))),de(this,Jt,Math.round(Math.max(0,Math.min(r,mt.MAX))))}static fromInt(t,i,n,r){return new mt(t,i,n,r)}static fromNumber(t,i,n,r){return new mt(t*mt.MAX,i*mt.MAX,n*mt.MAX,r*mt.MAX)}toSRGB(){let t=mt.MAX-H(this,Jt);return ui.fromInt(ui.MAX-Math.min(ui.MAX,Math.round(H(this,Vi)*t/mt.MAX)+H(this,Jt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,$i)*t/mt.MAX)+H(this,Jt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,Hi)*t/mt.MAX)+H(this,Jt)))}equals(t){return H(this,Vi)===H(t,Vi)&&H(this,$i)===H(t,$i)&&H(this,Hi)===H(t,Hi)&&H(this,Jt)===H(t,Jt)}toJSON(){return{c:H(this,Vi),m:H(this,$i),y:H(this,Hi),k:H(this,Jt)}}};Vi=new WeakMap,$i=new WeakMap,Hi=new WeakMap,Jt=new WeakMap,d(Xc,"MAX",1e4);var qc=Xc;function hn(e){return e instanceof Tt?Math.max(0,Math.min(1,e.num)):e instanceof L&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function Yc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof J?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=hn(t[0]),n=hn(t[1]),r=hn(t[2]),s=hn(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===Gn){if(t.length!==6)return null;o=hn(t[5])}else{if(t.length!==5)return null;o=hn(t[4])}if(o===null)return null}return{cmyk:qc.fromNumber(i,n,r,s),alpha:o}}function*Pm(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var Ci,Qs,Zc,Oh,Kc=class{constructor(){ie(this,Qs),ie(this,Ci,new Map)}registerDeviceCmyk(e){let t=Yc(e);return t?le(this,Qs,Zc).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ui.fromInt(t.r,t.g,t.b),r=qc.fromInt(i.c,i.m,i.y,i.k);H(this,Ci).set(n.toKey(),r)}}toJSON(){let e={};return H(this,Ci).forEach((t,i)=>{e[i]=t.toJSON()}),e}};Ci=new WeakMap,Qs=new WeakSet,Zc=function(e){let t=e.toSRGB(),i=t.toKey(),n=H(this,Ci).get(i);return n?n.equals(e)?t:le(this,Qs,Oh).call(this,e,t):(H(this,Ci).set(i,e),t)},Oh=function(e,t){for(let i=1;i<=ui.MAX;i++)for(let[n,r,s]of Pm(i)){let o=t.offset(n,r,s),a=o.toKey();if(!H(this,Ci).has(a))return H(this,Ci).set(a,e),o}return q.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Fs,ar,lr,Jc=class extends nn{constructor(e){super(),ie(this,Fs),ie(this,ar,new Map),ie(this,lr,!1),de(this,Fs,e??new Kc)}reset(){de(this,lr,!1)}hadDeviceCmyk(){return H(this,lr)}recordConversion(e,t){H(this,ar).set(e,t)}getConversions(){if(H(this,ar).size===0)return null;let e={};return H(this,ar).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=H(this,Fs).registerDeviceCmyk(e);return t?(de(this,lr,!0),t):super.visitFunc(e)}};Fs=new WeakMap,ar=new WeakMap,lr=new WeakMap;function Qc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Nm(e){return`^${e}`}function Bh(e){return e.replace(/[\[\]\(\),=;^]/g,Nm)}function Tm(e){return e.substr(1)}function Ea(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Tm)}function Im(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Ea(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Mh(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Im(i[2]),e=e.substr(i[0].length)}return t}var _h=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Dh=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,s=Math.floor(this.index/2)-1;if(s<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(s,n-1)],this.index&1){let o=r.nextSibling;!o||o.nodeType==1?e.after=!0:r=o}e.node=r}if(this.id&&(e.after||this.id!=Qc(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:q.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},zh=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let s=i.textContent.length;if(t<=s)break;if(!r){t=s;break}t-=s}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Bh(this.textBefore)),e.append(","),this.textAfter&&e.append(Bh(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Vh=class ed{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,s=[];for(;;){let o;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];o=Mh(i[4]),s.push(new Dh(a,h,kh(o.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Ea(h));let l=i[7];l&&(l=Ea(l)),o=Mh(i[10]),s.push(new zh(a,h,l,kh(o.s)));break}case"!":r++,s.push(new _h);break;case"~":case"@":case"":this.steps=s;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new ed,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let s=[],o=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),s.push(new zh(i,a,h,r)),r=null);o&&!(!o||o.nodeType==9);){let l=n?null:Qc(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;s.push(new Dh(u,l,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new _h),this.steps=s.concat(this.steps)):this.steps=s}toString(){if(!this.steps)return"";let t=new gi;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}},Ei=class{constructor(e,t){this.x=e,this.y=t}},Qo=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},$h=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},pi=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 Am(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Io=class td{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,s=n[r-1];for(let o=0;o<r;o++){let a=n[o],h;s.y<a.y?h=new $h(s,a,1,i):h=new $h(a,s,-1,i),t.push(h),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new Ei(r.x+t,r.y+i));return new td(n)}};function Hh(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new Ei(e+i*Math.sin(o),t+n*Math.cos(o)))}return new Io(r)}function Al(e,t,i,n){return new Io([new Ei(e,t),new Ei(i,t),new Ei(i,n),new Ei(e,n)])}var ls=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Uh(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 Fm(e,t,i,n){let r,s,o,a;t.high.y<i&&q.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Uh(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=Uh(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new ls(r,s,t.shapeId,-1)),e.push(new ls(o,a,t.shapeId,1))):(e.push(new ls(o,a,t.shapeId,-1)),e.push(new ls(r,s,t.shapeId,1)))}function Rm(e,t,i){let n=t+i,r=Array(n),s=Array(n),o;for(o=0;o<=n;o++)r[o]=0,s[o]=0;let a=[],h=!1,l=e.length;for(let u=0;u<l;u++){let c=e[u];r[c.shapeId]+=c.winding,s[c.shapeId]+=c.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(r[o]&&!s[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(r[o]||s[o]){p=!1;break}}h!=p&&(a.push(c.x),h=p)}return a}function Lm(e,t){return t?Math.ceil(e/t)*t:e}function Wh(e,t){return t?Math.floor(e/t)*t:e}function Om(e){return new Ei(e.y,-e.x)}function eo(e){return new Lt(e.y1,-e.x2,e.y2,-e.x1)}function id(e){return new Lt(-e.y2,e.x1,-e.y1,e.x2)}function Gh(e){return new Io(e.points.map(t=>Om(t)))}function Bm(e,t,i,n,r,s){s&&(e=eo(e),t=t.map(m=>Gh(m)),i=i.map(m=>Gh(m)));let o=t.length,a=i?i.length:0,h=[],l=[],u,c,p;for(u=0;u<o;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+o);let f=l.length;l.sort(Am);let g=0;for(;l[g].shapeId>=o;)g++;let y=l[g].low.y;y>e.y1&&h.push(new pi(e.y1,y,e.x2,e.x2));let b=0,x=[];for(;b<f&&(p=l[b]).low.y<y;)p.high.y>y&&x.push(p),b++;for(;b<f||x.length>0;){let m=e.y2,w=Math.min(Lm(Math.ceil(y+n),r),e.y2);for(c=0;c<x.length&&m>w;c++)p=x[c],p.low.x==p.high.x?p.high.y<m&&(m=Math.max(Wh(p.high.y,r),w)):p.low.x!=p.high.x&&(m=w);for(m>e.y2&&(m=e.y2);b<f&&(p=l[b]).low.y<m;){if(p.high.y<y){b++;continue}if(p.low.y<w)p.low.y==p.high.y&&p.low.y==y||(x.push(p),m=w),b++;else{let T=Wh(p.low.y,r);T<m&&(m=T);break}}let S=[];for(c=0;c<x.length;c++)Fm(S,x[c],y,m);S.sort((T,R)=>T.x-R.x||T.lowOrHigh-R.lowOrHigh);let C=Rm(S,o,a);if(C.length==0)h.push(new pi(y,m,e.x2,e.x2));else{let T=0,R=e.x1;for(c=0;c<C.length;c+=2){let F=Math.max(e.x1,C[c]),z=Math.min(e.x2,C[c+1])-F;z>T&&(T=z,R=F)}T==0?h.push(new pi(y,m,e.x2,e.x2)):h.push(new pi(y,m,Math.max(R,e.x1),Math.min(R+T,e.x2)))}if(m==e.y2)break;for(y=m,c=x.length-1;c>=0;c--)x[c].high.y<=m&&x.splice(c,1)}return nd(e,h),h}function nd(e,t){let i=t.length-1,n=new pi(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 rd(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 Mm(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let s=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)s=n.y2;return r===e.length?s=t.y2:s=Math.min(s,t.y2),s<=i?null:new Lt(t.x1,i,t.x2,s)}function _m(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let s=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)s=n.y1;return s=Math.max(s,t.y1),i<=s?null:new Lt(t.x1,s,t.x2,i)}function Dm(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=rd(t,r);for(;;){let h=r+o;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+s<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+s):(i.x1=u-s,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function zm(e,t,i,n,r){for(n||(n=[new pi(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let s,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new pi(o,e.y2,e.x1,e.x2));let a=rd(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(s=t[a],a++,t.splice(a,0,new pi(h.y1,s.y2,s.x1,s.x2)),s.y2=h.y1);a<t.length&&(s=t[a++],s.y2>h.y2&&(t.splice(a,0,new pi(h.y2,s.y2,s.x1,s.x2)),s.y2=h.y2),h.x1!=h.x2&&(r=="left"?s.x1=Math.min(h.x2,e.x2):s.x2=Math.max(h.x1,e.x1)),s.y2!=h.y2););}nd(e,t)}var Vm=class extends Zt{constructor(){super(),d(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function $m(e){if(e){let t=new Vm;try{return e.visit(t),t.propSet}catch(i){q.warn(i,"toSet:")}}return{}}var Hm=class extends Zt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function jh(e,t){if(e){let i=new Hm(t);try{return e.visit(i),i.value}catch(n){q.warn(n,"toInt: ")}}return t}var Um=class extends Zt{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 L(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let s=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),s.push(o.num*h/100)}else s.push(o.num*r.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(s.length%2==0){let o=[];for(let a=0;a<s.length;a+=2)o.push(new Ei(e+s[a],t+s[a+1]));return new Io(o)}break;case"rectangle":if(s.length==4)return Al(e+s[0],t+s[1],e+s[0]+s[2],t+s[1]+s[3]);break;case"ellipse":if(s.length==4)return Hh(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return Hh(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function sd(e,t,i,n,r,s){if(e){let o=new Um;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){q.warn(a,"toShape:")}}return Al(t,i,t+n,i+r)}var Wm=class extends Zt{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 qi(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,s=(n=t?.defaultValue)!=null?n:r?0:1,o=new Wm(r,s);try{e.visit(o)}catch(a){q.warn(a,"toCounters:")}return o.counters}var Gm=class extends nn{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new it(Ir(this.transformer.transformURL(e.url,this.baseUrl)))}};function bi(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function jm(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function Cn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let s=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(s&&s.length>0)return s.map(o=>jm(o.substring(1,o.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Xm=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}},qm=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()}},Ym=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(Ie(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let s=this.counterStore.currentPageCounters[e];return s&&s.length?s[s.length-1]:null},n=new we(this.pageScope,()=>t(i()),`page-counter-${e}`),r=s=>t(s[s.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new we(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],s=r.length?r[r.length-1]:0,o=n?.[e]||[],a=o.length?o[0]:0;return t.length?[s+(t[0]-a),...t.slice(1)]:[s]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?Cn(n,t):Cn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),s=new we(this.pageScope,()=>{let o=this.getTargetCounters(n,r,!0);if(o)if(o[t]){let a=o[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,s,r),s}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new we(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=this.getTargetCounters(n,r,!0),a=o?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,s,h);if(l.length)return i(l);let u=s[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new we(this.pageScope,()=>{if(t==="first-letter"){let s=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(s===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Ys);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){let i=new we(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`);return i.getContentList=()=>this.getRunningContentList(e,t),i}getRunningElementVal(e,t){return new we(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=this.getRunningRawValue(e,t,i);return typeof n.value=="string"?n.value:this.contentListToString(this.resolveDeferredContentList(n.value,n.offset))}getRunningContentList(e,t){let i=this.getRunningRawValue(this.namedStringValues,e,t);return typeof i.value=="string"?null:this.resolveDeferredContentList(i.value,i.offset)}resolveDeferredContentList(e,t){return this.freezePageCounters(e,t)}freezePageCounters(e,t){if(e instanceof j){let i=e.expr;if(i instanceof we){let n=/^page-counters?-(.+)$/.exec(i.str);if(n){if(n[1]==="pages")return e;let r=this.counterStore,s=n[1],o=r.getPageCounterFormat(i)||(h=>h.length?String(h[h.length-1]):""),a=r.getOrCreateNamedStringPageCounterExpr(this.pageScope,t,s,o);return new j(a)}}return e}return e instanceof J?new J(e.values.map(i=>this.freezePageCounters(i,t))):e instanceof _e?new _e(e.values.map(i=>this.freezePageCounters(i,t))):e}contentListToString(e){if(e instanceof Z)return e.stringValue();if(e instanceof j){let t=e.expr;if(t instanceof we){let i=t.fn.call(null);return i==null?"":String(i)}return""}return e instanceof J?e.values.map(t=>this.contentListToString(t)).join(""):e instanceof _e?e.values.map(t=>this.contentListToString(t)).join(""):""}getRunningRawValue(e,t,i){let n=e[t];if(!n)return{value:"",offset:-1};let r=Object.keys(n).map(p=>parseInt(p,10)).sort(xc),s=this.counterStore.currentPage;if(!s)return{value:"",offset:-1};let o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${Vt}]`)).map(p=>parseInt(p.getAttribute(Vt),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,y=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,c=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let b=s.container.querySelector(`[${Vt}="${f}"]`);if(!b)l<0&&(l=f);else{let x=s.container.querySelector(`[${Vt}="${o}"]`);if(x||(x=s.container.querySelector(`[${Vt}="0"]`)),x){for(let m=x;m;m=m.firstElementChild)if(m===b){l=f;break}}}}u=f}else(y>a||y<0)&&(h=l=u=c=f)}return{value:n[{first:h,start:l,last:u,"first-except":c}[i]]||"",offset:{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,typeof t!="string"&&(this.counterStore.hasDeferredNamedStrings=!0)}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},Zm=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,"pageCountersBeforeOverride",Object.create(null)),d(this,"hasDeferredNamedStrings",!1),d(this,"namedStringPageSnapshots",Object.create(null)),d(this,"namedStringPageCounterExprMap",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 qm(this,e)}createCounterResolver(e,t,i){return new Ym(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?bi(this.currentPageDocCounters):null,this.currentPageDocCounters=e?bi(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=bi(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let x=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,C=x[m]||[],T=C.length?C[C.length-1]:0,R=S-T,F=n[m],z=F==="reset"||F==="set";r[m]={delta:R,reset:z,value:S}}}let s=Object.create(null),o,a=!1,h=e["counter-reset"];if(h){let x=h.evaluate(t);x&&(a=x===v.none,a||(o=qi(x,{reset:!0})))}o&&"pages"in o&&delete o.pages;let l,u=e["counter-set"];if(u){let x=u.evaluate(t);x&&(l=qi(x,{defaultValue:0}))}l&&"pages"in l&&delete l.pages;let c=[];if(o)for(let x in o)c.push(x);if(l)for(let x in l)c.push(x);let p,f=e["counter-increment"];if(f){let x=f.evaluate(t);x&&(p=qi(x))}p&&"pages"in p&&delete p.pages,p?!("page"in p)&&!(r.page&&r.page.reset)&&(p.page=1):(p=Object.create(null),r.page&&r.page.reset||(p.page=1));for(let x in p)c.push(x);this.setPageControlledCounterNames(c);let g=bi(this.previousPageCounters);if(a)for(let x in this.pageCountersBeforeOverride)g[x]=Array.from(this.pageCountersBeforeOverride[x]);if(this.currentPageDocCounters)for(let x in this.currentPageDocCounters){if(this.isPageControlledCounter(x)){let m=r[x];if(m){if(m.reset)g[x]=[m.value],s[x]=!0;else if(m.delta!==0){g[x]||(g[x]=[0]);let w=g[x];w[w.length-1]+=m.delta}}else g[x]||(g[x]=Array.from(this.currentPageDocCounters[x]));continue}g[x]=Array.from(this.currentPageDocCounters[x])}this.currentPageCounters=g;let y=Object.create(null),b=x=>{if(!Object.prototype.hasOwnProperty.call(y,x)){let m=g[x];m&&(y[x]=Array.from(m))}};if(o)for(let x in o)b(x),this.definePageCounter(x,o[x]);for(let x in p){if(s[x])continue;this.currentPageCounters[x]||this.definePageCounter(x,0);let m=this.currentPageCounters[x];m[m.length-1]+=p[x]}if(l)for(let x in l)if(b(x),!this.currentPageCounters[x])this.definePageCounter(x,l[x]);else{let m=this.currentPageCounters[x];m[m.length-1]=l[x]}for(let x in y)this.pageCountersBeforeOverride[x]=Array.from(y[x])}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=bi(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let s=this.referencesToSolve[r];if(s.targetId===e){if(s.resolve(),this.referencesToSolve.splice(r,1),t){let o=t.indexOf(s);o>=0&&t.splice(o,1)}i.push(s),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Xm(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=bi(this.currentPageCounters),o=this.currentPageDocCounters?bi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=s,o&&(this.pageDocCountersById[a]=o);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:Cn(u,"content"),before:Cn(u,"before"),after:Cn(u,"after"),marker:Cn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let 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 s;r.isResolved()?(s=this.resolvedReferences[r.targetId],s||(s=this.resolvedReferences[r.targetId]=[])):(s=this.unresolvedReferences[r.targetId],s||(s=this.unresolvedReferences[r.targetId]=[])),s.every(o=>!r.equals(o))&&s.push(r)}this.hasDeferredNamedStrings&&this.currentPage&&this.recordNamedStringPageSnapshot(e),this.currentPage=null}recordNamedStringPageSnapshot(e){let t=this.currentPage,i=t.isBlankPage?t.offset-1:t.offset,n=t.isBlankPage?i:Math.max(i,...Array.from(t.container.querySelectorAll(`[${Vt}]`)).map(r=>parseInt(r.getAttribute(Vt),10)));for(let r of Object.keys(this.namedStringPageSnapshots)){let s=parseInt(r,10);if(s<=i)continue;let o=this.namedStringPageSnapshots[s];s<=n&&i<=o.lastOffset&&delete this.namedStringPageSnapshots[s]}this.namedStringPageSnapshots[i]={lastOffset:n,spineIndex:e,counters:bi(this.currentPageCounters)}}getPageCountersForOffset(e){for(let t of Object.keys(this.namedStringPageSnapshots)){let i=parseInt(t,10);if(i>e)break;let n=this.namedStringPageSnapshots[i];if(e<=n.lastOffset)return n.counters}return null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(s=>s+t))}for(let n of Object.keys(this.namedStringPageSnapshots)){let r=this.namedStringPageSnapshots[parseInt(n,10)];r.spineIndex>e&&r.counters.page&&!i.has(r.counters)&&(i.add(r.counters),r.counters.page=r.counters.page.map(s=>s+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${Qn}]`);for(let n of i){let r=n.getAttribute(Qn),s=this.targetCounterExprs.find(o=>o.expr.key===r);if(s&&s.transformedId){let o=this.pageCountersById[s.transformedId];if(o){let a=o[s.name];a&&(n.textContent=s.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let s=r.container.querySelectorAll(`[${ta}]`);for(let h of s){let l=h.getAttribute(ta),u=this.namedStringPageCounterExprMap[l];if(!u)continue;let c=this.getPageCountersForOffset(u.offset),p=c?.[u.counterName];p&&(h.textContent=u.format(p))}let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let a=r.container.querySelectorAll(`[${Jn}]`);for(let h of a){let l=h.getAttribute(Jn),u=this.pageCounterExprs.find(g=>g.expr.key===l);if(!u)continue;let c=(i=u.expr)==null?void 0:i.str,p=c?.replace(/^page-counters?-/,""),f=o[p];f&&(h.textContent=u.format(f))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let s=this.unresolvedReferences[r];s&&(t=t.concat(s))}),t.sort((r,s)=>r.spineIndex-s.spineIndex||r.pageIndex-s.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}getPageCounterFormat(e){let t=this.pageCounterExprs.find(i=>i.expr===e);return t?t.format:null}getOrCreateNamedStringPageCounterExpr(e,t,i,n){for(let s in this.namedStringPageCounterExprMap){let o=this.namedStringPageCounterExprMap[s];if(o.offset===t&&o.counterName===i)return o.expr}let r=new we(e,()=>{let s=((t>=0?this.getPageCountersForOffset(t):null)||this.currentPageCounters)[i]||[];return n(s)},`named-string-page-counter-${i}`);return this.namedStringPageCounterExprMap[r.key]={expr:r,offset:t,counterName:i,format:n},r}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 we){if(e.str=="viv-leader"){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute("data-viv-leader",e.key),s.setAttribute("data-viv-leader-value",t),s}else if(e.str.startsWith("running-element-")){let s=t&&i.querySelectorAll(`[${Vt}="${t}"]`);if(!s||s.length===0)return null;let o=s[s.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(Qn,e.key),s}else if(e.str.startsWith("target-text-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(ia,e.key),s}else if(e.str.startsWith("named-string-page-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(ta,e.key),s}}let n=this.pagesCounterExprs.findIndex(s=>s.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(s=>s.expr===e)>=0;if(n||r){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(n?ea:Jn,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Jn}]`);for(let r of t){let s=r.getAttribute(Jn),o=this.pageCounterExprs.find(u=>u.expr.key===s),a=(o?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=o.format(l))}let i=e.querySelectorAll(`[${Qn}]`);for(let r of i)r.setAttribute(Xh,!0);let n=e.querySelectorAll(`[${ia}]`);for(let r of n)r.setAttribute(qh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${ea}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(ea),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,o.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${Xh}]`);for(let o of r){let a=o.getAttribute(Qn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(o.textContent=h.format(u[u.length-1]))}}}let s=e.root.querySelectorAll(`[${qh}]`);for(let o of s){let a=o.getAttribute(ia),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(o.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Km(this,e)}},ea="data-vivliostyle-pages-counter",Jn="data-vivliostyle-page-counter",ta="data-vivliostyle-named-string-page-counter",Qn="data-vivliostyle-target-counter",ia="data-vivliostyle-target-text",Xh="data-vivliostyle-target-counter-in-running",qh="data-vivliostyle-target-text-in-running",Km=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}},Jm=new Set(["before","after","first-line","first-letter"]),Yh=new Set(["media","supports","-epubx-when"]),od=new Set([";","}"]),ad=new Set(["{",";","}"]),Qm=new Set([";","{","}"]),ey=":where(:scope)",ty=":where(:not(*))";function iy(e){let{statements:t,changed:i}=Pa(e,0,e.length,null);return i?t.join(`
|
|
5
|
-
`):e}function
|
|
6
|
-
`||e==="\r"||e===" "||e==="\f"}function Gi(e){let t="",i=0,n=!1;for(;i<e.length;){let r=rn(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 s=e[i];if(fd(s)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=s,i++}return t}function by(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 xi(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,by)}var xy=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 Qe(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 ei=[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];ei[NaN]=43;var Sy=[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];ei[NaN]=43;var gd=[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];gd[NaN]=35;var md=[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];md[NaN]=45;var Na=[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];Na[NaN]=37;var Ta=[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];Ta[NaN]=38;var Mi=Qe(35,[61,36]),Cy=Qe(35,[58,77]),ky=Qe(35,[61,36,124,50]),Ey=Qe(35,[38,51]),Py=Qe(35,[42,54]),Ny=Qe(39,[42,55]),Ty=Qe(54,[42,55,47,56]),Iy=Qe(62,[62,82]),Ay=Qe(35,[61,36,33,70]),Fy=Qe(62,[45,71]),Ry=Qe(63,[45,81]),na=Qe(76,[10,72,13,72]),Ly=Qe(39,[39,46,10,72,13,72,92,48]),Oy=Qe(39,[34,46,10,72,13,72,92,49]),By=Qe(39,[39,47,10,74,13,74,92,48]),My=Qe(39,[34,47,10,74,13,74,92,49]),Zh=Qe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),_y=Qe(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]),Dy=Qe(39,[39,68,10,74,13,74,92,75,NaN,67]),zy=Qe(39,[34,68,10,74,13,74,92,75,NaN,67]),Vy=Qe(72,[9,39,10,39,13,39,32,39,41,69]),$y=15,bt=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=$y,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new xy}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,s=this.position,o=this.buffer,a=0,h=0,l="",u=0,c=!1,p=o[e],f=-9;for(;;){let g=r.charCodeAt(s);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,s),a=0):n===Qt&&a===0?(a=54,h=s,l=r.substring(s,s+1),s++):(l=r.substring(h,s),a=54),n=Qt;break;case 1:s++,c=!0;continue;case 2:h=s++,n=Na;continue;case 3:a=1,h=s++,n=ei;continue;case 4:h=s++,a=31,n=Mi;continue;case 33:a=2,h=++s,n=Ly;continue;case 34:a=2,h=++s,n=Oy;continue;case 6:h=++s,a=7,n=ei;continue;case 7:h=s++,a=32,n=Mi;continue;case 8:h=s++,a=21;break;case 9:h=s++,a=32,n=Ey;continue;case 10:h=s++,a=10;break;case 11:h=s++,a=11;break;case 12:h=s++,a=36,n=Mi;continue;case 13:h=s++,a=23;break;case 14:h=s++,a=16;break;case 15:a=24,h=s++,n=gd;continue;case 16:h=s++,n=Sy;continue;case 78:h=s++,a=9,n=ei;continue;case 17:h=s++,a=19,n=Py;continue;case 18:h=s++,a=18,n=Cy;continue;case 77:s++,a=50;break;case 19:h=s++,a=17;break;case 20:h=s++,a=38,n=Ay;continue;case 21:h=s++,a=39,n=Mi;continue;case 22:h=s++,a=37,n=Mi;continue;case 23:h=s++,a=22;break;case 24:h=++s,a=20,n=ei;continue;case 25:h=s++,a=14;break;case 26:h=s++,a=15;break;case 27:h=s++,a=12;break;case 28:h=s++,a=13;break;case 29:h=s++,f=h,a=1,n=na;continue;case 30:h=s++,a=33,n=Mi;continue;case 31:h=s++,a=34,n=ky;continue;case 32:h=s++,a=35,n=Mi;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,s),10);break;case 38:a=4,u=parseFloat(r.substring(h,s));break;case 39:s++;continue;case 40:a=3,u=parseFloat(r.substring(h,s)),h=s++,n=ei;continue;case 41:a=3,u=parseFloat(r.substring(h,s)),l="%",h=s++;break;case 42:s++,n=Ta;continue;case 43:if(l=xi(r.substring(h,s)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(s-1))){a=27,s++;continue}break;case 44:f=s++,n=na;continue;case 45:l=xi(r.substring(h,s));break;case 46:l=r.substring(h,s),s++;break;case 47:l=xi(r.substring(h,s)),s++;break;case 48:f=s,s+=2,n=By;continue;case 49:f=s,s+=2,n=My;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(l=r.substring(h,s),a==1){if(s++,l.toLowerCase()=="url"){n=Zh;continue}a=6}break;case 53:if(l=xi(r.substring(h,s)),a==1){if(s++,l.toLowerCase()=="url"){n=Zh;continue}a=6}break;case 54:n=Ny,s++;continue;case 55:n=Ty,s++;continue;case 56:n=Qt,s++;continue;case 57:n=Iy,s++,r[s]!==">"&&(a=1,n=ei);continue;case 81:a=51,l=r.substring(h,++s),n=Qt;break;case 82:a=52,l=r.substring(h,++s),n=Qt;break;case 58:a=5,n=Na,s++;continue;case 59:a=4,n=Ta,s++;continue;case 60:a=1,n=ei,s++;continue;case 61:a=1,n=na,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:h=s++,n=_y;continue;case 65:h=++s,n=Dy;continue;case 66:h=++s,n=zy;continue;case 67:a=8,l=xi(r.substring(h,s)),s++;break;case 69:s++;break;case 70:n=Fy,s++;continue;case 71:n=Ry,s++;continue;case 79:if(s-f<8&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){s++;continue}case 68:a=8,l=xi(r.substring(h,s)),s++,n=Vy;continue;case 74:if(s++,s-f<9&&r.substring(f+1,s).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Qt;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=ei;continue}l=xi(r.substring(h,s));break;case 75:f=s++;continue;case 76:s++,n=md;continue;default:if(n!==Qt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=s,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,a=0,h=s,l="",u=0,p=o[e&i]}this.position=s,this.tail=e&i}},Ye=null,Ia=null;function Aa(){return Ye}function D(e){if(!Ye)throw new Error("E_TASK_NO_CONTEXT");Ye.name||(Ye.name=e);let t=Ye,i=new Fo(t,t.top,e);return t.top=i,i.state=1,i}function Hy(e){return new Gy(e||new Wy)}function I(e){return new Fa(e)}function Mn(e,t,i){let n=D(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Uy(e,t){return(Ye?Ye.getScheduler():Ia||Hy()).run(e,t)}var Wy=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Gy=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 Jg,Ia||(Ia=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){q.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new jy(this,t||"");i.top=new Fo(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let s of i.callbacks)try{s()}catch(o){q.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=Ye;return Ye=i,this.schedule(i.top.suspend("bootstrap")),Ye=n,i}},yd=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=Ye;return Ye=e,e.top.finish(this.result),Ye=t,!0}return!1}cancel(){this.canceled=!0}},jy=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!==Ye&&this.continuation){this.continuation.cancel();let t=new yd(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&&q.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 q=new Wg,No=(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))(No||{}),qs={};function Ot(e,t,i){if(!No[e])q.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=qs[e];n||(n=qs[e]=[]),i?n.unshift(t):n.push(t)}}function gc(e,t){if(!No[e])q.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=qs[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Gt(e){return qs[e]||[]}var Gg={registerHook:Ot,removeHook:gc},mc=class{constructor(e){u(this,"performanceInstance",e),u(this,"timestamps",{}),u(this,"registerTiming"),u(this,"registerStartTiming"),u(this,"registerEndTiming"),this.registerTiming=ln,this.registerStartTiming=this.registerStartTiming=ln,this.registerEndTiming=this.registerEndTiming=ln}forceRegisterStartTiming(e,t){Jo.call(this,e,"start",t)}forceRegisterEndTiming(e,t){Jo.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let s=0;s<r;s++){let o=n[s];t+=i,r>1&&(t+=`(${s})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
|
|
4
|
+
`}}),q.info(t)}disable(){this.registerTiming=ln,this.registerStartTiming=this.registerStartTiming=ln,this.registerEndTiming=this.registerEndTiming=ln}enable(){this.registerTiming=Jo,this.registerStartTiming=this.registerStartTiming=xh,this.registerEndTiming=this.registerEndTiming=jg}isEnabled(){return this.registerStartTiming===xh}};function ln(){}function Jo(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,s=n.length;for(let o=s-1;o>=0&&(r=n[o],!(r&&!r[t]));o--)r=null;r||(r={},n.push(r)),r[t]=i}function xh(e,t){this.registerTiming(e,"start",t)}function jg(e,t){this.registerTiming(e,"end",t)}var Xg={now:Date.now},qg=window&&window.performance,Pt=new mc(qg||Xg);Pt.forceRegisterStartTiming("load_vivliostyle");var Yg={profiler:{registerStartTiming:Pt.registerStartTiming,registerEndTiming:Pt.registerEndTiming,printTimings:Pt.printTimings,disable:Pt.disable,enable:Pt.enable}},To=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Ys=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Vt="data-adapt-eloff",Zg={};function xl(e){return JSON.parse(e)}function Ht(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function yc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Ji=window.location.href;function Sh(e){Ji=e}var Ni=window.location.href;function Ch(e){Ni=e}function Kg(e){let t=yc(e).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function Ir(e){return e.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ie(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let o=Kg(t);return o?o+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=yc(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,s="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],s=i[2]);n=r.indexOf("/../"),!(n<=0);){let o=r.lastIndexOf("/",n-1);if(o<=0)break;r=r.substr(0,o)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+s}function Zs(e,t){return e.match(/^#/)&&t?Ht(t)+e:Ie(e,t)}function vc(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function An(e){let t;return(e=vc(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 kh(e){return e==null?e:e.toString()}var Jg=class{constructor(){u(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let 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}},wc=["","-webkit-","-moz-"],dn={};function Is(e,t){return CSS.supports(e+t,"unset")}function Qg(e){let t=dn[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return dn[e]=null,null;case"text-combine-upright":if(Is("-webkit-","text-combine")&&!Is("","text-combine-upright"))return dn[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of wc)if(Is(i,e))return t=[i+e],dn[e]=t,t;return q.warn("Property not supported by the browser: ",e),dn[e]=null,null}function A(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=Qg(t);if(r)for(let s of r){switch(s){case"-webkit-text-combine":i==="all"&&(i="horizontal");break;case"text-combine-upright":i==="all"&&n.setProperty("text-indent","0");break}n.setProperty(s,i)}}function ki(e,t,i){try{let n=dn[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function ba(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 gi=class{constructor(){u(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Sl(e){return`\\${e.charCodeAt(0).toString(16)} `}function Ti(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Sl)}function Ur(e){return e.replace(/[\u0000-\u001F"\\]/g,Sl)}function Eh(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Ph(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function em(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function bc(e,t){function i(n){return em(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Ks(e){return bc(e)}function tm(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function im(e,t){t=typeof t=="string"?t:"\\u";function i(r){return tm(r,t)}let n=new RegExp(`${Ks(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function mi(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 xc(e,t){return e-t}function Nh(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function nm(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Qo(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 rm(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Cl=class{constructor(){u(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},ji={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Sc(){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 Cc(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 sm=Sc(),Th={PENDING:{}};function kc(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function om(e){return`"${Ur(`${e}`)}"`}function am(e){return Ti(`${e}`)}function xa(e,t){return e?`${Ti(e)}.${Ti(t)}`:Ti(t)}var Ec=0,Js=class{constructor(e,t){if(u(this,"parent",e),u(this,"resolver",t),u(this,"scopeKey"),u(this,"children",[]),u(this,"zero"),u(this,"one"),u(this,"_true"),u(this,"_false"),u(this,"values",{}),u(this,"funcs",{}),u(this,"builtIns",{}),this.scopeKey=`S${Ec++}`,this.zero=new it(this,0),this.one=new it(this,1),this._true=new it(this,!0),this._false=new it(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=kc,i["css-string"]=om,i["css-name"]=am,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 we(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 lm(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Pc(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 hm(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function um(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Yt={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 Nc(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 Sa=class{constructor(e,t,i,n){u(this,"rootScope",e),u(this,"viewportWidth",t),u(this,"viewportHeight",i),u(this,"actualPageWidth",null),u(this,"pageWidth"),u(this,"actualPageHeight",null),u(this,"pageHeight"),u(this,"initialFontSize"),u(this,"rootFontSize",null),u(this,"isRelativeRootFontSize",null),u(this,"fontSize"),u(this,"rootLineHeight",null),u(this,"pref"),u(this,"scopes",{}),u(this,"pageAreaWidth",null),u(this,"pageAreaHeight",null),u(this,"pageVertical",null),u(this,"pubTitle",null),u(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=sm}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(Pc(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,s=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return s;case"vh":return o;case"vi":return a?o:s;case"vb":return a?s:o;case"vmin":return s<o?s:o;case"vmax":return s>o?s:o;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Yt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let s=e.builtIns[t];if(s){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new it(e,s.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,s=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":s=this.pageWidth();break;case"height":s=this.pageHeight();break;case"device-width":s=window.screen.availWidth;break;case"device-height":s=window.screen.availHeight;break;case"color":s=window.screen.pixelDepth;break}if(s!=null&&r!=null)switch(i){case"min":return s>=Number(r);case"max":return s<=Number(r);default:return s==r}else if(s!=null&&t==null)return s!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Xt=class{constructor(e){u(this,"scope",e),u(this,"key"),this.scope=e,this.key=`_${Ec++}`}toString(){let e=new gi;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===Th.PENDING?!1:n;{i[this.key]=Th.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}},Tc=class extends Xt{constructor(e,t){super(e),u(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)}},Io=class extends Xt{constructor(e,t,i){super(e),u(this,"lhs",t),u(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)}},Ic=class extends Io{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Wn=class extends Io{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Ac=class extends Io{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},kl=class extends Io{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ii=class extends Tc{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},cm=class extends Ii{constructor(e,t){super(e,t)}getOp(){return"not "}},Sn=class extends Tc{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},El=class extends Ic{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},dm=class extends El{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Pl=class extends Ic{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},pm=class extends Pl{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},fm=class extends Pl{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},gm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},mm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},ym=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Ca=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Nl=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},vm=class extends Wn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},Fc=class extends Ac{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Rc=class extends Ac{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Tl=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Lc=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Oc=class extends kl{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Wr=class extends Xt{constructor(e,t,i){var n;super(e),u(this,"num",t),u(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(Ti(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Je=class extends Xt{constructor(e,t){super(e),u(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)}},Ih=class extends Xt{constructor(e,t,i){super(e),u(this,"not",t),u(this,"name",i)}appendTo(e,t){this.not&&e.append("not "),e.append(Ti(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},we=class extends Xt{constructor(e,t,i){super(e),u(this,"fn",t),u(this,"str",i)}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function wm(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function bm(e,t,i){let n=t;for(let r=0;r<t.length;r++){let s=t[r].expand(e,i);if(t!==n)n[r]=s;else if(s!==t[r]){n=Array(t.length);for(let o=0;o<r;o++)n[o]=t[o];n[r]=s}}return n}var mr=class Bc extends Xt{constructor(t,i,n){super(t),u(this,"qualifiedName",i),u(this,"params",n)}appendTo(t,i){t.append(this.qualifiedName),wm(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=bm(t,this.params,i);return n===this.params?this:new Bc(this.scope,this.qualifiedName,n)}},xm=class Mc extends Xt{constructor(t,i,n,r){super(t),u(this,"cond",i),u(this,"ifTrue",n),u(this,"ifFalse",r)}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),s=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&s===this.ifFalse?this:new Mc(this.scope,n,r,s)}},it=class extends Xt{constructor(e,t){super(e),u(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(Ur(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Ah=class _c extends Xt{constructor(t,i,n){super(t),u(this,"name",i),u(this,"value",n)}appendTo(t,i){t.append("("),t.append(Ur(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 _c(this.scope,this.name,n)}},Sm=class extends Xt{constructor(e,t,i,n){super(e),u(this,"name",t),u(this,"value",i),u(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)}},Dc=class extends Xt{constructor(e,t){super(e),u(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 Ut(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 El(e,t,i)}function ne(e,t,i){return t===e.zero?i:i===e.zero?t:new Fc(e,t,i)}function ye(e,t,i){return t===e.zero?new Sn(e,i):i===e.zero?t:new Rc(e,t,i)}function As(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Tl(e,t,i)}function ka(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Lc(e,t,i)}var Zt=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}},nn=class extends Zt{constructor(){super(),u(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let s=0;s<i;s++)t[s]=e[s];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new K(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new _e(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Be:t===e.values?e:new ai(e.name,t)}visitExpr(e){return e}},st=class{toString(){let e=new gi;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new gi;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}},zc=class Vc extends st{static get instance(){return this.empty||(this.empty=new Vc),this.empty}constructor(){super()}toExpr(t,i){return new it(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};u(zc,"empty");var Cm=zc,Be=Cm.instance,$c=class Hc extends st{static get instance(){return this.slash||(this.slash=new Hc),this.slash}constructor(){super()}toExpr(t,i){return new it(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};u($c,"slash");var km=$c,Gn=km.instance,Z=class extends st{constructor(e){super(),u(this,"str",e)}toExpr(e,t){return new it(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(Ur(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Ea=Object.create(null),he=class extends st{constructor(e){if(super(),u(this,"name",e),Ea[e])throw new Error("E_INVALID_CALL");Ea[e]=this}toExpr(e,t){return new it(e,this.name)}appendTo(e,t){t?e.append(Ti(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function M(e){let t=Ea[e];return t||(t=new he(e)),t}var L=class extends st{constructor(e,t){var i;super(),u(this,"num",e),u(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Tl(e,t,new it(e,this.num/100)):new Wr(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}},Tt=class extends st{constructor(e){super(),u(this,"num",e)}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new it(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},lt=class extends Tt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Uc=class extends st{constructor(e){super(),u(this,"hex",e)}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Qe=class extends st{constructor(e){super(),u(this,"url",e)}appendTo(e,t){e.append('url("'),e.append(Ur(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Wc=class extends st{constructor(e){super(),u(this,"urangeText",e)}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Il(e,t,i,n){var r,s;let o=t.length;if(o>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(s=t[a])==null||s.appendTo(e,n)}}var K=class extends st{constructor(e){super(),u(this,"values",e)}appendTo(e,t){Il(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},_e=class extends st{constructor(e){super(),u(this,"values",e)}appendTo(e,t){Il(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ai=class extends st{constructor(e,t){super(),u(this,"name",e),u(this,"values",t)}appendTo(e,t){e.append(Ti(this.name)),e.append("("),Il(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},j=class extends st{constructor(e){super(),u(this,"expr",e)}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof it||this.expr instanceof Wr?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}},pn=class extends st{constructor(e){super(),u(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 Gc(e,t){return new L(ut(e,t),"px")}var v={absolute:M("absolute"),all:M("all"),always:M("always"),anywhere:M("anywhere"),auto:M("auto"),avoid:M("avoid"),balance:M("balance"),balance_all:M("balance-all"),block:M("block"),block_end:M("block-end"),block_start:M("block-start"),both:M("both"),bottom:M("bottom"),border_box:M("border-box"),break_all:M("break-all"),break_word:M("break-word"),clip:M("clip"),crop:M("crop"),cross:M("cross"),column:M("column"),discard:M("discard"),exclusive:M("exclusive"),_false:M("false"),fixed:M("fixed"),flex:M("flex"),flow_root:M("flow-root"),footnote:M("footnote"),footer:M("footer"),grid:M("grid"),header:M("header"),hidden:M("hidden"),horizontal_tb:M("horizontal-tb"),inherit:M("inherit"),initial:M("initial"),inline:M("inline"),inline_block:M("inline-block"),inline_end:M("inline-end"),inline_start:M("inline-start"),inside:M("inside"),keep:M("keep"),landscape:M("landscape"),left:M("left"),line:M("line"),list_item:M("list-item"),ltr:M("ltr"),manual:M("manual"),max_content:M("max-content"),min_content:M("min-content"),none:M("none"),normal:M("normal"),oeb_page_foot:M("oeb-page-foot"),oeb_page_head:M("oeb-page-head"),outside:M("outside"),padding_box:M("padding-box"),page:M("page"),relative:M("relative"),revert:M("revert"),right:M("right"),same:M("same"),scale:M("scale"),snap_block:M("snap-block"),snap_inline:M("snap-inline"),solid:M("solid"),spread:M("spread"),_static:M("static"),rtl:M("rtl"),table:M("table"),table_caption:M("table-caption"),table_cell:M("table-cell"),table_footer_group:M("table-footer-group"),table_header_group:M("table-header-group"),table_row:M("table-row"),top:M("top"),transparent:M("transparent"),unset:M("unset"),vertical_lr:M("vertical-lr"),vertical_rl:M("vertical-rl"),visible:M("visible"),_true:M("true")},Fh=new L(100,"%"),Gr=new L(100,"pvw"),jr=new L(100,"pvh"),Le=new L(0,"px"),tC=new Wc("U+0-10FFFF"),Rh={"font-size":1,"line-height":2,color:3};function Y(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Lh(e,t){let i=Rh[e]||Number.MAX_VALUE,n=Rh[t]||Number.MAX_VALUE;return i-n}function Xe(e){return e?.length>2&&e.startsWith("--")}var fn,gn,mn,jc=class li{constructor(t,i,n){ie(this,fn),ie(this,gn),ie(this,mn),de(this,fn,Math.round(Math.max(0,Math.min(t,li.MAX)))),de(this,gn,Math.round(Math.max(0,Math.min(i,li.MAX)))),de(this,mn,Math.round(Math.max(0,Math.min(n,li.MAX))))}static fromInt(t,i,n){return new li(t,i,n)}offset(t,i,n){return new li(H(this,fn)+t,H(this,gn)+i,H(this,mn)+n)}toKey(){return JSON.stringify([H(this,fn),H(this,gn),H(this,mn)])}toColorFunc(t){return new ai("color",[new K([M("srgb"),new Tt(H(this,fn)/li.MAX),new Tt(H(this,gn)/li.MAX),new Tt(H(this,mn)/li.MAX),...t!==null?[Gn,new Tt(t)]:[]])])}};fn=new WeakMap,gn=new WeakMap,mn=new WeakMap,u(jc,"MAX",1e4);var ui=jc;function Em(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,s=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(s.c)&&Number.isFinite(s.m)&&Number.isFinite(s.y)&&Number.isFinite(s.k)}):!1}var Vi,$i,Hi,Jt,Xc=class mt{constructor(t,i,n,r){ie(this,Vi),ie(this,$i),ie(this,Hi),ie(this,Jt),de(this,Vi,Math.round(Math.max(0,Math.min(t,mt.MAX)))),de(this,$i,Math.round(Math.max(0,Math.min(i,mt.MAX)))),de(this,Hi,Math.round(Math.max(0,Math.min(n,mt.MAX)))),de(this,Jt,Math.round(Math.max(0,Math.min(r,mt.MAX))))}static fromInt(t,i,n,r){return new mt(t,i,n,r)}static fromNumber(t,i,n,r){return new mt(t*mt.MAX,i*mt.MAX,n*mt.MAX,r*mt.MAX)}toSRGB(){let t=mt.MAX-H(this,Jt);return ui.fromInt(ui.MAX-Math.min(ui.MAX,Math.round(H(this,Vi)*t/mt.MAX)+H(this,Jt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,$i)*t/mt.MAX)+H(this,Jt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,Hi)*t/mt.MAX)+H(this,Jt)))}equals(t){return H(this,Vi)===H(t,Vi)&&H(this,$i)===H(t,$i)&&H(this,Hi)===H(t,Hi)&&H(this,Jt)===H(t,Jt)}toJSON(){return{c:H(this,Vi),m:H(this,$i),y:H(this,Hi),k:H(this,Jt)}}};Vi=new WeakMap,$i=new WeakMap,Hi=new WeakMap,Jt=new WeakMap,u(Xc,"MAX",1e4);var qc=Xc;function hn(e){return e instanceof Tt?Math.max(0,Math.min(1,e.num)):e instanceof L&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function Yc(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof K?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=hn(t[0]),n=hn(t[1]),r=hn(t[2]),s=hn(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===Gn){if(t.length!==6)return null;o=hn(t[5])}else{if(t.length!==5)return null;o=hn(t[4])}if(o===null)return null}return{cmyk:qc.fromNumber(i,n,r,s),alpha:o}}function*Pm(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var Ci,Qs,Zc,Oh,Kc=class{constructor(){ie(this,Qs),ie(this,Ci,new Map)}registerDeviceCmyk(e){let t=Yc(e);return t?le(this,Qs,Zc).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=ui.fromInt(t.r,t.g,t.b),r=qc.fromInt(i.c,i.m,i.y,i.k);H(this,Ci).set(n.toKey(),r)}}toJSON(){let e={};return H(this,Ci).forEach((t,i)=>{e[i]=t.toJSON()}),e}};Ci=new WeakMap,Qs=new WeakSet,Zc=function(e){let t=e.toSRGB(),i=t.toKey(),n=H(this,Ci).get(i);return n?n.equals(e)?t:le(this,Qs,Oh).call(this,e,t):(H(this,Ci).set(i,e),t)},Oh=function(e,t){for(let i=1;i<=ui.MAX;i++)for(let[n,r,s]of Pm(i)){let o=t.offset(n,r,s),a=o.toKey();if(!H(this,Ci).has(a))return H(this,Ci).set(a,e),o}return q.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Fs,ar,lr,Jc=class extends nn{constructor(e){super(),ie(this,Fs),ie(this,ar,new Map),ie(this,lr,!1),de(this,Fs,e??new Kc)}reset(){de(this,lr,!1)}hadDeviceCmyk(){return H(this,lr)}recordConversion(e,t){H(this,ar).set(e,t)}getConversions(){if(H(this,ar).size===0)return null;let e={};return H(this,ar).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=H(this,Fs).registerDeviceCmyk(e);return t?(de(this,lr,!0),t):super.visitFunc(e)}};Fs=new WeakMap,ar=new WeakMap,lr=new WeakMap;function Qc(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Nm(e){return`^${e}`}function Bh(e){return e.replace(/[\[\]\(\),=;^]/g,Nm)}function Tm(e){return e.substr(1)}function Pa(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Tm)}function Im(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Pa(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Mh(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Im(i[2]),e=e.substr(i[0].length)}return t}var _h=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Dh=class{constructor(e,t,i){u(this,"index",e),u(this,"id",t),u(this,"sideBias",i)}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,s=Math.floor(this.index/2)-1;if(s<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(s,n-1)],this.index&1){let o=r.nextSibling;!o||o.nodeType==1?e.after=!0:r=o}e.node=r}if(this.id&&(e.after||this.id!=Qc(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:q.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},zh=class{constructor(e,t,i,n){u(this,"offset",e),u(this,"textBefore",t),u(this,"textAfter",i),u(this,"sideBias",n)}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let s=i.textContent.length;if(t<=s)break;if(!r){t=s;break}t-=s}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Bh(this.textBefore)),e.append(","),this.textAfter&&e.append(Bh(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Vh=class ed{constructor(){u(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,s=[];for(;;){let o;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];o=Mh(i[4]),s.push(new Dh(a,h,kh(o.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Pa(h));let l=i[7];l&&(l=Pa(l)),o=Mh(i[10]),s.push(new zh(a,h,l,kh(o.s)));break}case"!":r++,s.push(new _h);break;case"~":case"@":case"":this.steps=s;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new ed,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let s=[],o=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,c=l.length;n?(i+=c,a||(a=l)):(i>c&&(i=c),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),s.push(new zh(i,a,h,r)),r=null);o&&!(!o||o.nodeType==9);){let l=n?null:Qc(t),c=n?1:0;for(;t;)t.nodeType==1&&(c+=2),t=t.previousSibling;s.push(new Dh(c,l,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new _h),this.steps=s.concat(this.steps)):this.steps=s}toString(){if(!this.steps)return"";let t=new gi;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){u(this,"x1",e),u(this,"y1",t),u(this,"x2",i),u(this,"y2",n)}},Ei=class{constructor(e,t){u(this,"x",e),u(this,"y",t)}},ea=class{constructor(e,t,i,n){u(this,"left",e),u(this,"top",t),u(this,"right",i),u(this,"bottom",n)}},$h=class{constructor(e,t,i,n){u(this,"low",e),u(this,"high",t),u(this,"winding",i),u(this,"shapeId",n)}},pi=class{constructor(e,t,i,n){u(this,"y1",e),u(this,"y2",t),u(this,"x1",i),u(this,"x2",n),u(this,"left",null),u(this,"right",null)}};function Am(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Ao=class td{constructor(t){u(this,"points",t)}addSegments(t,i){let n=this.points,r=n.length,s=n[r-1];for(let o=0;o<r;o++){let a=n[o],h;s.y<a.y?h=new $h(s,a,1,i):h=new $h(a,s,-1,i),t.push(h),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new Ei(r.x+t,r.y+i));return new td(n)}};function Hh(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new Ei(e+i*Math.sin(o),t+n*Math.cos(o)))}return new Ao(r)}function Al(e,t,i,n){return new Ao([new Ei(e,t),new Ei(i,t),new Ei(i,n),new Ei(e,n)])}var ls=class{constructor(e,t,i,n){u(this,"x",e),u(this,"winding",t),u(this,"shapeId",i),u(this,"lowOrHigh",n)}};function Uh(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 Fm(e,t,i,n){let r,s,o,a;t.high.y<i&&q.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=Uh(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=Uh(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new ls(r,s,t.shapeId,-1)),e.push(new ls(o,a,t.shapeId,1))):(e.push(new ls(o,a,t.shapeId,-1)),e.push(new ls(r,s,t.shapeId,1)))}function Rm(e,t,i){let n=t+i,r=Array(n),s=Array(n),o;for(o=0;o<=n;o++)r[o]=0,s[o]=0;let a=[],h=!1,l=e.length;for(let c=0;c<l;c++){let d=e[c];r[d.shapeId]+=d.winding,s[d.shapeId]+=d.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(r[o]&&!s[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(r[o]||s[o]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function Lm(e,t){return t?Math.ceil(e/t)*t:e}function Wh(e,t){return t?Math.floor(e/t)*t:e}function Om(e){return new Ei(e.y,-e.x)}function eo(e){return new Lt(e.y1,-e.x2,e.y2,-e.x1)}function id(e){return new Lt(-e.y2,e.x1,-e.y1,e.x2)}function Gh(e){return new Ao(e.points.map(t=>Om(t)))}function Bm(e,t,i,n,r,s){s&&(e=eo(e),t=t.map(m=>Gh(m)),i=i.map(m=>Gh(m)));let o=t.length,a=i?i.length:0,h=[],l=[],c,d,p;for(c=0;c<o;c++)t[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+o);let f=l.length;l.sort(Am);let g=0;for(;l[g].shapeId>=o;)g++;let y=l[g].low.y;y>e.y1&&h.push(new pi(e.y1,y,e.x2,e.x2));let b=0,x=[];for(;b<f&&(p=l[b]).low.y<y;)p.high.y>y&&x.push(p),b++;for(;b<f||x.length>0;){let m=e.y2,w=Math.min(Lm(Math.ceil(y+n),r),e.y2);for(d=0;d<x.length&&m>w;d++)p=x[d],p.low.x==p.high.x?p.high.y<m&&(m=Math.max(Wh(p.high.y,r),w)):p.low.x!=p.high.x&&(m=w);for(m>e.y2&&(m=e.y2);b<f&&(p=l[b]).low.y<m;){if(p.high.y<y){b++;continue}if(p.low.y<w)p.low.y==p.high.y&&p.low.y==y||(x.push(p),m=w),b++;else{let T=Wh(p.low.y,r);T<m&&(m=T);break}}let S=[];for(d=0;d<x.length;d++)Fm(S,x[d],y,m);S.sort((T,R)=>T.x-R.x||T.lowOrHigh-R.lowOrHigh);let C=Rm(S,o,a);if(C.length==0)h.push(new pi(y,m,e.x2,e.x2));else{let T=0,R=e.x1;for(d=0;d<C.length;d+=2){let F=Math.max(e.x1,C[d]),z=Math.min(e.x2,C[d+1])-F;z>T&&(T=z,R=F)}T==0?h.push(new pi(y,m,e.x2,e.x2)):h.push(new pi(y,m,Math.max(R,e.x1),Math.min(R+T,e.x2)))}if(m==e.y2)break;for(y=m,d=x.length-1;d>=0;d--)x[d].high.y<=m&&x.splice(d,1)}return nd(e,h),h}function nd(e,t){let i=t.length-1,n=new pi(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 rd(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 Mm(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let s=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)s=n.y2;return r===e.length?s=t.y2:s=Math.min(s,t.y2),s<=i?null:new Lt(t.x1,i,t.x2,s)}function _m(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let s=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)s=n.y1;return s=Math.max(s,t.y1),i<=s?null:new Lt(t.x1,s,t.x2,i)}function Dm(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=rd(t,r);for(;;){let h=r+o;if(h>e.y2)return!1;let l=e.x1,c=e.x2;for(let d=a;d<t.length&&t[d].y1<h;d++){let p=t[d];p.x1>l&&(l=p.x1),p.x2<c&&(c=p.x2)}if(l+s<=c||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+s):(i.x1=c-s,i.x2=c),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function zm(e,t,i,n,r){for(n||(n=[new pi(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let s,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new pi(o,e.y2,e.x1,e.x2));let a=rd(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(s=t[a],a++,t.splice(a,0,new pi(h.y1,s.y2,s.x1,s.x2)),s.y2=h.y1);a<t.length&&(s=t[a++],s.y2>h.y2&&(t.splice(a,0,new pi(h.y2,s.y2,s.x1,s.x2)),s.y2=h.y2),h.x1!=h.x2&&(r=="left"?s.x1=Math.min(h.x2,e.x2):s.x2=Math.max(h.x1,e.x1)),s.y2!=h.y2););}nd(e,t)}var Vm=class extends Zt{constructor(){super(),u(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function $m(e){if(e){let t=new Vm;try{return e.visit(t),t.propSet}catch(i){q.warn(i,"toSet:")}}return{}}var Hm=class extends Zt{constructor(e){super(),u(this,"value",e)}visitInt(e){return this.value=e.num,e}};function jh(e,t){if(e){let i=new Hm(t);try{return e.visit(i),i.value}catch(n){q.warn(n,"toInt: ")}}return t}var Um=class extends Zt{constructor(){super(),u(this,"collect",!1),u(this,"coords",[]),u(this,"name",null)}visitNumeric(e){return this.collect&&this.coords.push(e),null}visitNum(e){return this.collect&&e.num==0&&this.coords.push(new L(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let s=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),s.push(o.num*h/100)}else s.push(o.num*r.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(s.length%2==0){let o=[];for(let a=0;a<s.length;a+=2)o.push(new Ei(e+s[a],t+s[a+1]));return new Ao(o)}break;case"rectangle":if(s.length==4)return Al(e+s[0],t+s[1],e+s[0]+s[2],t+s[1]+s[3]);break;case"ellipse":if(s.length==4)return Hh(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return Hh(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function sd(e,t,i,n,r,s){if(e){let o=new Um;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){q.warn(a,"toShape:")}}return Al(t,i,t+n,i+r)}var Wm=class extends Zt{constructor(e,t){super(),u(this,"reset",e),u(this,"defaultValue",t),u(this,"counters",Object.create(null)),u(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+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 qi(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,s=(n=t?.defaultValue)!=null?n:r?0:1,o=new Wm(r,s);try{e.visit(o)}catch(a){q.warn(a,"toCounters:")}return o.counters}var Gm=class extends nn{constructor(e,t){super(),u(this,"baseUrl",e),u(this,"transformer",t)}visitURL(e){return new Qe(Ir(this.transformer.transformURL(e.url,this.baseUrl)))}};function bi(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function jm(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function Cn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let s=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(s&&s.length>0)return s.map(o=>jm(o.substring(1,o.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Xm=class{constructor(e,t){u(this,"targetId",e),u(this,"resolved",t),u(this,"pageCounters",null),u(this,"spineIndex",-1),u(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},qm=class{constructor(e,t){u(this,"counterStore",e),u(this,"baseURL",t)}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},Ym=class{constructor(e,t,i,n){u(this,"counterStore",e),u(this,"baseURL",t),u(this,"rootScope",i),u(this,"pageScope",n),u(this,"styler",null),u(this,"namedStringValues",Object.create(null)),u(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ie(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let s=this.counterStore.currentPageCounters[e];return s&&s.length?s[s.length-1]:null},n=new we(this.pageScope,()=>t(i()),`page-counter-${e}`),r=s=>t(s[s.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new we(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],s=r.length?r[r.length-1]:0,o=n?.[e]||[],a=o.length?o[0]:0;return t.length?[s+(t[0]-a),...t.slice(1)]:[s]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?Cn(n,t):Cn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),s=new we(this.pageScope,()=>{let o=this.getTargetCounters(n,r,!0);if(o)if(o[t]){let a=o[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),c=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(c[c.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,s,r),s}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new we(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=this.getTargetCounters(n,r,!0),a=o?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,s,h);if(l.length)return i(l);let c=s[t]||[];return i(c)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new we(this.pageScope,()=>{if(t==="first-letter"){let s=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(s===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Ys);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){let i=new we(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`);return i.getContentList=()=>this.getRunningContentList(e,t),i}getRunningElementVal(e,t){return new we(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=this.getRunningRawValue(e,t,i);return typeof n.value=="string"?n.value:this.contentListToString(this.resolveDeferredContentList(n.value,n.offset))}getRunningContentList(e,t){let i=this.getRunningRawValue(this.namedStringValues,e,t);return typeof i.value=="string"?null:this.resolveDeferredContentList(i.value,i.offset)}resolveDeferredContentList(e,t){return this.freezePageCounters(e,t)}freezePageCounters(e,t){if(e instanceof j){let i=e.expr;if(i instanceof we){let n=/^page-counters?-(.+)$/.exec(i.str);if(n){if(n[1]==="pages")return e;let r=this.counterStore,s=n[1],o=r.getPageCounterFormat(i)||(h=>h.length?String(h[h.length-1]):""),a=r.getOrCreateNamedStringPageCounterExpr(this.pageScope,t,s,o);return new j(a)}}return e}return e instanceof K?new K(e.values.map(i=>this.freezePageCounters(i,t))):e instanceof _e?new _e(e.values.map(i=>this.freezePageCounters(i,t))):e}contentListToString(e){if(e instanceof Z)return e.stringValue();if(e instanceof j){let t=e.expr;if(t instanceof we){let i=t.fn.call(null);return i==null?"":String(i)}return""}return e instanceof K?e.values.map(t=>this.contentListToString(t)).join(""):e instanceof _e?e.values.map(t=>this.contentListToString(t)).join(""):""}getRunningRawValue(e,t,i){let n=e[t];if(!n)return{value:"",offset:-1};let r=Object.keys(n).map(p=>parseInt(p,10)).sort(xc),s=this.counterStore.currentPage;if(!s)return{value:"",offset:-1};let o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${Vt}]`)).map(p=>parseInt(p.getAttribute(Vt),10))),h=-1,l=-1,c=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,y=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,d=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let b=s.container.querySelector(`[${Vt}="${f}"]`);if(!b)l<0&&(l=f);else{let x=s.container.querySelector(`[${Vt}="${o}"]`);if(x||(x=s.container.querySelector(`[${Vt}="0"]`)),x){for(let m=x;m;m=m.firstElementChild)if(m===b){l=f;break}}}}c=f}else(y>a||y<0)&&(h=l=c=d=f)}return{value:n[{first:h,start:l,last:c,"first-except":d}[i]]||"",offset:{first:h,start:l,last:c,"first-except":d}[i]}}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t,typeof t!="string"&&(this.counterStore.hasDeferredNamedStrings=!0)}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},Zm=class{constructor(e){u(this,"documentURLTransformer",e),u(this,"countersById",Object.create(null)),u(this,"pageCountersById",Object.create(null)),u(this,"pageDocCountersById",Object.create(null)),u(this,"pageTextById",Object.create(null)),u(this,"currentPageDocCounters",null),u(this,"previousPageDocCounters",null),u(this,"currentPageDocCounterChanges",Object.create(null)),u(this,"currentPageDocCounterChangeTypes",Object.create(null)),u(this,"currentPageCounters",Object.create(null)),u(this,"previousPageCounters",Object.create(null)),u(this,"pageCountersBeforeOverride",Object.create(null)),u(this,"hasDeferredNamedStrings",!1),u(this,"namedStringPageSnapshots",Object.create(null)),u(this,"namedStringPageCounterExprMap",Object.create(null)),u(this,"currentPageCountersStack",[]),u(this,"pageIndicesById",Object.create(null)),u(this,"currentPage",null),u(this,"newReferencesOfCurrentPage",[]),u(this,"referencesToSolve",[]),u(this,"referencesToSolveStack",[]),u(this,"unresolvedReferences",Object.create(null)),u(this,"resolvedReferences",Object.create(null)),u(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),u(this,"pagesCounterExprs",[]),u(this,"pageCounterExprs",[]),u(this,"targetCounterExprs",[]),u(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new qm(this,e)}createCounterResolver(e,t,i){return new Ym(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?bi(this.currentPageDocCounters):null,this.currentPageDocCounters=e?bi(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=bi(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let x=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,C=x[m]||[],T=C.length?C[C.length-1]:0,R=S-T,F=n[m],z=F==="reset"||F==="set";r[m]={delta:R,reset:z,value:S}}}let s=Object.create(null),o,a=!1,h=e["counter-reset"];if(h){let x=h.evaluate(t);x&&(a=x===v.none,a||(o=qi(x,{reset:!0})))}o&&"pages"in o&&delete o.pages;let l,c=e["counter-set"];if(c){let x=c.evaluate(t);x&&(l=qi(x,{defaultValue:0}))}l&&"pages"in l&&delete l.pages;let d=[];if(o)for(let x in o)d.push(x);if(l)for(let x in l)d.push(x);let p,f=e["counter-increment"];if(f){let x=f.evaluate(t);x&&(p=qi(x))}p&&"pages"in p&&delete p.pages,p?!("page"in p)&&!(r.page&&r.page.reset)&&(p.page=1):(p=Object.create(null),r.page&&r.page.reset||(p.page=1));for(let x in p)d.push(x);this.setPageControlledCounterNames(d);let g=bi(this.previousPageCounters);if(a)for(let x in this.pageCountersBeforeOverride)g[x]=Array.from(this.pageCountersBeforeOverride[x]);if(this.currentPageDocCounters)for(let x in this.currentPageDocCounters){if(this.isPageControlledCounter(x)){let m=r[x];if(m){if(m.reset)g[x]=[m.value],s[x]=!0;else if(m.delta!==0){g[x]||(g[x]=[0]);let w=g[x];w[w.length-1]+=m.delta}}else g[x]||(g[x]=Array.from(this.currentPageDocCounters[x]));continue}g[x]=Array.from(this.currentPageDocCounters[x])}this.currentPageCounters=g;let y=Object.create(null),b=x=>{if(!Object.prototype.hasOwnProperty.call(y,x)){let m=g[x];m&&(y[x]=Array.from(m))}};if(o)for(let x in o)b(x),this.definePageCounter(x,o[x]);for(let x in p){if(s[x])continue;this.currentPageCounters[x]||this.definePageCounter(x,0);let m=this.currentPageCounters[x];m[m.length-1]+=p[x]}if(l)for(let x in l)if(b(x),!this.currentPageCounters[x])this.definePageCounter(x,l[x]);else{let m=this.currentPageCounters[x];m[m.length-1]=l[x]}for(let x in y)this.pageCountersBeforeOverride[x]=Array.from(y[x])}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=bi(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let s=this.referencesToSolve[r];if(s.targetId===e){if(s.resolve(),this.referencesToSolve.splice(r,1),t){let o=t.indexOf(s);o>=0&&t.splice(o,1)}i.push(s),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Xm(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=bi(this.currentPageCounters),o=this.currentPageDocCounters?bi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=s,o&&(this.pageDocCountersById[a]=o);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let c=h[0];this.pageTextById[a]={content:Cn(c,"content"),before:Cn(c,"before"),after:Cn(c,"after"),marker:Cn(c,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let c=this.resolvedReferences[a];if(c){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let p;for(;p=c.shift();)p.unresolve(),d.push(p)}}this.pageIndicesById[a]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let s;r.isResolved()?(s=this.resolvedReferences[r.targetId],s||(s=this.resolvedReferences[r.targetId]=[])):(s=this.unresolvedReferences[r.targetId],s||(s=this.unresolvedReferences[r.targetId]=[])),s.every(o=>!r.equals(o))&&s.push(r)}this.hasDeferredNamedStrings&&this.currentPage&&this.recordNamedStringPageSnapshot(e),this.currentPage=null}recordNamedStringPageSnapshot(e){let t=this.currentPage,i=t.isBlankPage?t.offset-1:t.offset,n=t.isBlankPage?i:Math.max(i,...Array.from(t.container.querySelectorAll(`[${Vt}]`)).map(r=>parseInt(r.getAttribute(Vt),10)));for(let r of Object.keys(this.namedStringPageSnapshots)){let s=parseInt(r,10);if(s<=i)continue;let o=this.namedStringPageSnapshots[s];s<=n&&i<=o.lastOffset&&delete this.namedStringPageSnapshots[s]}this.namedStringPageSnapshots[i]={lastOffset:n,spineIndex:e,counters:bi(this.currentPageCounters)}}getPageCountersForOffset(e){for(let t of Object.keys(this.namedStringPageSnapshots)){let i=parseInt(t,10);if(i>e)break;let n=this.namedStringPageSnapshots[i];if(e<=n.lastOffset)return n.counters}return null}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(s=>s+t))}for(let n of Object.keys(this.namedStringPageSnapshots)){let r=this.namedStringPageSnapshots[parseInt(n,10)];r.spineIndex>e&&r.counters.page&&!i.has(r.counters)&&(i.add(r.counters),r.counters.page=r.counters.page.map(s=>s+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${Qn}]`);for(let n of i){let r=n.getAttribute(Qn),s=this.targetCounterExprs.find(o=>o.expr.key===r);if(s&&s.transformedId){let o=this.pageCountersById[s.transformedId];if(o){let a=o[s.name];a&&(n.textContent=s.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let s=r.container.querySelectorAll(`[${ia}]`);for(let h of s){let l=h.getAttribute(ia),c=this.namedStringPageCounterExprMap[l];if(!c)continue;let d=this.getPageCountersForOffset(c.offset),p=d?.[c.counterName];p&&(h.textContent=c.format(p))}let o=this.getPageCountersForPage(r,t?.[n]);if(!o)continue;let a=r.container.querySelectorAll(`[${Jn}]`);for(let h of a){let l=h.getAttribute(Jn),c=this.pageCounterExprs.find(g=>g.expr.key===l);if(!c)continue;let d=(i=c.expr)==null?void 0:i.str,p=d?.replace(/^page-counters?-/,""),f=o[p];f&&(h.textContent=c.format(f))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let s=this.unresolvedReferences[r];s&&(t=t.concat(s))}),t.sort((r,s)=>r.spineIndex-s.spineIndex||r.pageIndex-s.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}getPageCounterFormat(e){let t=this.pageCounterExprs.find(i=>i.expr===e);return t?t.format:null}getOrCreateNamedStringPageCounterExpr(e,t,i,n){for(let s in this.namedStringPageCounterExprMap){let o=this.namedStringPageCounterExprMap[s];if(o.offset===t&&o.counterName===i)return o.expr}let r=new we(e,()=>{let s=((t>=0?this.getPageCountersForOffset(t):null)||this.currentPageCounters)[i]||[];return n(s)},`named-string-page-counter-${i}`);return this.namedStringPageCounterExprMap[r.key]={expr:r,offset:t,counterName:i,format:n},r}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 we){if(e.str=="viv-leader"){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute("data-viv-leader",e.key),s.setAttribute("data-viv-leader-value",t),s}else if(e.str.startsWith("running-element-")){let s=t&&i.querySelectorAll(`[${Vt}="${t}"]`);if(!s||s.length===0)return null;let o=s[s.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(Qn,e.key),s}else if(e.str.startsWith("target-text-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(na,e.key),s}else if(e.str.startsWith("named-string-page-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(ia,e.key),s}}let n=this.pagesCounterExprs.findIndex(s=>s.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(s=>s.expr===e)>=0;if(n||r){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(n?ta:Jn,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Jn}]`);for(let r of t){let s=r.getAttribute(Jn),o=this.pageCounterExprs.find(c=>c.expr.key===s),a=(o?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=o.format(l))}let i=e.querySelectorAll(`[${Qn}]`);for(let r of i)r.setAttribute(Xh,!0);let n=e.querySelectorAll(`[${na}]`);for(let r of n)r.setAttribute(qh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${ta}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(ta),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,o.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${Xh}]`);for(let o of r){let a=o.getAttribute(Qn),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let c=l[h.name];c&&(o.textContent=h.format(c[c.length-1]))}}}let s=e.root.querySelectorAll(`[${qh}]`);for(let o of s){let a=o.getAttribute(na),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(o.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new Km(this,e)}},ta="data-vivliostyle-pages-counter",Jn="data-vivliostyle-page-counter",ia="data-vivliostyle-named-string-page-counter",Qn="data-vivliostyle-target-counter",na="data-vivliostyle-target-text",Xh="data-vivliostyle-target-counter-in-running",qh="data-vivliostyle-target-text-in-running",Km=class{constructor(e,t){u(this,"counterStore",e),u(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}},Jm=new Set(["before","after","first-line","first-letter"]),Yh=new Set(["media","supports","-epubx-when"]),od=new Set([";","}"]),ad=new Set(["{",";","}"]),Qm=new Set([";","{","}"]),ey=":where(:scope)",ty=":where(:not(*))";function iy(e){let{statements:t,changed:i}=Na(e,0,e.length,null);return i?t.join(`
|
|
5
|
+
`):e}function Na(e,t,i,n){let r=[],s=[],o=!1,a=t,h=()=>{s.length!==0&&(n?r.push(ny(n,s)):r.push(ld(s)),s.length=0)};for(;a<i&&(a=Qi(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let d=yy(e,a,i);if(!d)break;if(n&&!Yh.has(d.name)){s.push(Gi(e.slice(a,d.end))),a=d.end;continue}if(h(),d.hasBlock&&Yh.has(d.name)){let p=Na(e,d.blockStart,d.blockEnd,n);o||(o=p.changed||n!=null),r.push(`${d.header} {${ry(p.statements)}}`)}else r.push(Gi(e.slice(a,d.end)));a=d.end;continue}if(n&&hy(e,a,i)){let d=dy(e,a,i);if(!d)break;s.push(Gi(d.text)),a=d.end;continue}h();let l=py(e,a,i);if(!l){let d=vy(e,a,i);r.push(Gi(d.text)),a=d.end;continue}if(n&&fy(e,a,l)){let d=my(e,a,l.end,i);s.push(Gi(d.text)),a=d.end;continue}let c=n?sy(n,l.prelude):hd(l.prelude);if(c){o||(o=n!=null);let d=Na(e,l.blockStart,l.blockEnd,c);o||(o=d.changed),d.statements.length===0?r.push(`${c} {}`):r.push(...d.statements)}a=l.end}return h(),{statements:r,changed:o}}function ny(e,t){return`${e} { ${ld(t)} }`}function ld(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function ry(e){return e.length===0?"":` ${e.join(" ")} `}function sy(e,t){let i=oy(e);if(!i)return null;let n=cd(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let s=ud(r,i);return s.found?s.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function hd(e){return ud(e.trim(),ey).text}function oy(e){let t=cd(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!ay(i));return t.length===0?null:`:is(${t.join(", ")})`}function ay(e){let t=0;for(;t<e.length;){let i=Fo(e,t);if(i!=null){t=i;continue}let n=rn(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"){if(e[t+1]===":")return!0;let r=t+1,s=Xr(e,r,e.length),o=e.slice(r,s).toLowerCase();if(Jm.has(o))return!0;t=s;continue}t++}return!1}function ud(e,t){let i=0,n=!1,r="",s=[],o=ly(t);for(;i<e.length;){let a=Fo(e,i);if(a!=null){r+=e.slice(i,a),i=a;continue}let h=rn(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 c=i+1,d=Xr(e,c,e.length);if(d>c&&e[d]==="("){s.push(e.slice(c,d).toLowerCase()),r+=e.slice(i,d+1),i=d+1;continue}}if(l==="("){s.push(""),r+=l,i++;continue}if(l===")"){s.pop(),r+=l,i++;continue}if(l==="&"){r+=o&&s.includes("has")?ty:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function ly(e){let t=0;for(;t<e.length;){let i=Fo(e,t);if(i!=null){t=i;continue}let n=rn(e,t,e.length);if(n!=null){t=n;continue}if(e[t]===":"&&e[t+1]!==":"){let r=t+1,s=Xr(e,r,e.length);if(s>r&&e.slice(r,s).toLowerCase()==="has"&&e[s]==="(")return!0;t=s;continue}t++}return!1}function cd(e,t){let i=[],n=0,r=0,s=0,o=0;for(;r<e.length;){let a=Fo(e,r);if(a!=null){r=a;continue}let h=rn(e,r,e.length);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":s++;break;case")":s=Math.max(0,s-1);break;case"[":o++;break;case"]":o=Math.max(0,o-1);break;default:s===0&&o===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function hy(e,t,i){let n=t,r=cy(e,n,i);if(r<=n)return!1;let s=Qi(e,r,i);if(s>=i||e[s]!==":")return!1;let o=qr(e,s+1,i,Qm);return o?.char==="{"?!uy(e,t,r,s,o.index):!0}function uy(e,t,i,n,r){if(Qi(e,i,r)!==n)return!1;let s=Qi(e,n+1,r);if(s!==n+1||s>=r)return!1;let o=e[s];return o===":"||o==="\\"||/[A-Za-z_-]/.test(o)}function cy(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Xr(e,n,i)}function Xr(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 dy(e,t,i){let n=qr(e,t,i,od);if(!n){let s=e.slice(t,i).trim();return s?{text:s,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function py(e,t,i){let n=qr(e,t,i,ad);if(!n||n.char!=="{")return null;let r=dd(e,n.index,i);return r<0?null:{prelude:Gi(e.slice(t,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function fy(e,t,i){if(!gy(e,t,i.blockStart-1))return!0;let n=Qi(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function gy(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 my(e,t,i,n){let r=Qi(e,i,n),s=r<n&&e[r]===";"?r+1:i;return{text:e.slice(t,s),end:s}}function yy(e,t,i){let n=qr(e,t,i,ad);if(!n)return null;let r=Xr(e,t+1,i),s=e.slice(t+1,r).toLowerCase(),o=Gi(e.slice(t,n.index));if(n.char!=="{")return{name:s,header:o,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=dd(e,n.index,i);return a<0?null:{name:s,header:o,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function vy(e,t,i){let n=qr(e,t,i,od);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 qr(e,t,i,n){let r=t,s=0,o=0,a=0;for(;r<i;){let h=rn(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":s++;break;case")":s=Math.max(0,s-1);break;case"[":o++;break;case"]":o=Math.max(0,o-1);break;case"{":if(s===0&&o===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(s===0&&o===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(s===0&&o===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function dd(e,t,i){let n=t+1,r=1;for(;n<i;){let s=rn(e,n,i);if(s!=null){n=s;continue}let o=e[n];if(o==="{")r++;else if(o==="}"&&(r--,r===0))return n;n++}return-1}function Qi(e,t,i){let n=t;for(;n<i;){let r=e[n];if(fd(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=pd(e,n,i);continue}break}return n}function pd(e,t,i){let n=e.indexOf("*/",t+2);return n<0||n+2>i?i:n+2}function rn(e,t,i){let n=e[t];return n==='"'||n==="'"?wy(e,t):n==="/"&&e[t+1]==="*"?pd(e,t,i):null}function Fo(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function wy(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 fd(e){return e===" "||e===`
|
|
6
|
+
`||e==="\r"||e===" "||e==="\f"}function Gi(e){let t="",i=0,n=!1;for(;i<e.length;){let r=rn(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 s=e[i];if(fd(s)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=s,i++}return t}function by(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 xi(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,by)}var xy=class{constructor(){u(this,"type"),u(this,"precededBySpace",!1),u(this,"num",0),u(this,"text",""),u(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function et(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 ei=[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];ei[NaN]=43;var Sy=[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];ei[NaN]=43;var gd=[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];gd[NaN]=35;var md=[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];md[NaN]=45;var Ta=[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];Ta[NaN]=37;var Ia=[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];Ia[NaN]=38;var Mi=et(35,[61,36]),Cy=et(35,[58,77]),ky=et(35,[61,36,124,50]),Ey=et(35,[38,51]),Py=et(35,[42,54]),Ny=et(39,[42,55]),Ty=et(54,[42,55,47,56]),Iy=et(62,[62,82]),Ay=et(35,[61,36,33,70]),Fy=et(62,[45,71]),Ry=et(63,[45,81]),ra=et(76,[10,72,13,72]),Ly=et(39,[39,46,10,72,13,72,92,48]),Oy=et(39,[34,46,10,72,13,72,92,49]),By=et(39,[39,47,10,74,13,74,92,48]),My=et(39,[34,47,10,74,13,74,92,49]),Zh=et(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),_y=et(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]),Dy=et(39,[39,68,10,74,13,74,92,75,NaN,67]),zy=et(39,[34,68,10,74,13,74,92,75,NaN,67]),Vy=et(72,[9,39,10,39,13,39,32,39,41,69]),$y=15,bt=class{constructor(e,t){u(this,"input",e),u(this,"handler",t),u(this,"indexMask"),u(this,"buffer"),u(this,"tail",0),u(this,"curr",0),u(this,"position",0),this.indexMask=$y,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new xy}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,s=this.position,o=this.buffer,a=0,h=0,l="",c=0,d=!1,p=o[e],f=-9;for(;;){let g=r.charCodeAt(s);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,s),a=0):n===Qt&&a===0?(a=54,h=s,l=r.substring(s,s+1),s++):(l=r.substring(h,s),a=54),n=Qt;break;case 1:s++,d=!0;continue;case 2:h=s++,n=Ta;continue;case 3:a=1,h=s++,n=ei;continue;case 4:h=s++,a=31,n=Mi;continue;case 33:a=2,h=++s,n=Ly;continue;case 34:a=2,h=++s,n=Oy;continue;case 6:h=++s,a=7,n=ei;continue;case 7:h=s++,a=32,n=Mi;continue;case 8:h=s++,a=21;break;case 9:h=s++,a=32,n=Ey;continue;case 10:h=s++,a=10;break;case 11:h=s++,a=11;break;case 12:h=s++,a=36,n=Mi;continue;case 13:h=s++,a=23;break;case 14:h=s++,a=16;break;case 15:a=24,h=s++,n=gd;continue;case 16:h=s++,n=Sy;continue;case 78:h=s++,a=9,n=ei;continue;case 17:h=s++,a=19,n=Py;continue;case 18:h=s++,a=18,n=Cy;continue;case 77:s++,a=50;break;case 19:h=s++,a=17;break;case 20:h=s++,a=38,n=Ay;continue;case 21:h=s++,a=39,n=Mi;continue;case 22:h=s++,a=37,n=Mi;continue;case 23:h=s++,a=22;break;case 24:h=++s,a=20,n=ei;continue;case 25:h=s++,a=14;break;case 26:h=s++,a=15;break;case 27:h=s++,a=12;break;case 28:h=s++,a=13;break;case 29:h=s++,f=h,a=1,n=ra;continue;case 30:h=s++,a=33,n=Mi;continue;case 31:h=s++,a=34,n=ky;continue;case 32:h=s++,a=35,n=Mi;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,c=parseInt(r.substring(h,s),10);break;case 38:a=4,c=parseFloat(r.substring(h,s));break;case 39:s++;continue;case 40:a=3,c=parseFloat(r.substring(h,s)),h=s++,n=ei;continue;case 41:a=3,c=parseFloat(r.substring(h,s)),l="%",h=s++;break;case 42:s++,n=Ia;continue;case 43:if(l=xi(r.substring(h,s)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(s-1))){a=27,s++;continue}break;case 44:f=s++,n=ra;continue;case 45:l=xi(r.substring(h,s));break;case 46:l=r.substring(h,s),s++;break;case 47:l=xi(r.substring(h,s)),s++;break;case 48:f=s,s+=2,n=By;continue;case 49:f=s,s+=2,n=My;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(l=r.substring(h,s),a==1){if(s++,l.toLowerCase()=="url"){n=Zh;continue}a=6}break;case 53:if(l=xi(r.substring(h,s)),a==1){if(s++,l.toLowerCase()=="url"){n=Zh;continue}a=6}break;case 54:n=Ny,s++;continue;case 55:n=Ty,s++;continue;case 56:n=Qt,s++;continue;case 57:n=Iy,s++,r[s]!==">"&&(a=1,n=ei);continue;case 81:a=51,l=r.substring(h,++s),n=Qt;break;case 82:a=52,l=r.substring(h,++s),n=Qt;break;case 58:a=5,n=Ta,s++;continue;case 59:a=4,n=Ia,s++;continue;case 60:a=1,n=ei,s++;continue;case 61:a=1,n=ra,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:h=s++,n=_y;continue;case 65:h=++s,n=Dy;continue;case 66:h=++s,n=zy;continue;case 67:a=8,l=xi(r.substring(h,s)),s++;break;case 69:s++;break;case 70:n=Fy,s++;continue;case 71:n=Ry,s++;continue;case 79:if(s-f<8&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){s++;continue}case 68:a=8,l=xi(r.substring(h,s)),s++,n=Vy;continue;case 74:if(s++,s-f<9&&r.substring(f+1,s).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=Qt;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=ei;continue}l=xi(r.substring(h,s));break;case 75:f=s++;continue;case 76:s++,n=md;continue;default:if(n!==Qt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=s,a=0}if(p.type=a,p.precededBySpace=d,p.num=c,p.text=l,p.position=h,e++,e>=t)break;n=Qt,d=!1,a=0,h=s,l="",c=0,p=o[e&i]}this.position=s,this.tail=e&i}},Ye=null,Aa=null;function Fa(){return Ye}function D(e){if(!Ye)throw new Error("E_TASK_NO_CONTEXT");Ye.name||(Ye.name=e);let t=Ye,i=new Ro(t,t.top,e);return t.top=i,i.state=1,i}function Hy(e){return new Gy(e||new Wy)}function I(e){return new Ra(e)}function Mn(e,t,i){let n=D(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Uy(e,t){return(Ye?Ye.getScheduler():Aa||Hy()).run(e,t)}var Wy=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Gy=class{constructor(e){u(this,"timer",e),u(this,"timeout",1),u(this,"slice",25),u(this,"sliceOverTime",0),u(this,"queue"),u(this,"wakeupTime",null),u(this,"timeoutToken",null),u(this,"inTimeSlice",!1),u(this,"order",0),this.queue=new Jg,Aa||(Aa=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){q.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new jy(this,t||"");i.top=new Ro(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let s of i.callbacks)try{s()}catch(o){q.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=Ye;return Ye=i,this.schedule(i.top.suspend("bootstrap")),Ye=n,i}},yd=class{constructor(e){u(this,"task",e),u(this,"scheduledTime",0),u(this,"order",0),u(this,"result",null),u(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Ye;return Ye=e,e.top.finish(this.result),Ye=t,!0}return!1}cancel(){this.canceled=!0}},jy=class{constructor(e,t){u(this,"scheduler",e),u(this,"name",t),u(this,"callbacks",[]),u(this,"exception",null),u(this,"running",!0),u(this,"result",null),u(this,"waitTarget",null),u(this,"top",null),u(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Ye&&this.continuation){this.continuation.cancel();let t=new yd(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&&q.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}}},
|
|
9
|
+
`;e.frameTrace=t}}},Ra=class vd{constructor(t){u(this,"value",t)}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new vd(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Xy=class{constructor(e){u(this,"frame",e)}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Ro(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 Ra(e)):new Ra(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}},Ro=class{constructor(e,t,i){u(this,"task",e),u(this,"parent",t),u(this,"name",i),u(this,"res",null),u(this,"state"),u(this,"callback",null),u(this,"handler",null),this.state=0}checkEnvironment(){if(!Ye)throw new Error("F_TASK_NO_CONTEXT");if(this!==Ye.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Xy(this)}finish(e){this.checkEnvironment(),Ye&&!Ye.exception&&(this.res=e),this.state=2;let t=this.parent;if(Ye&&(Ye.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()?(q.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(s=>{n=s})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Ye;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new qy(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 yd(this.task);return this.task.continuation=t,Ye=null,this.task.waitTarget=e||null,t}},qy=class extends Ro{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Yr=class{constructor(e,t){u(this,"fetch",e),u(this,"name"),u(this,"arrived",!1),u(this,"resource",null),u(this,"task",null),u(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=Fa().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){q.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?I(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},_n=e=>{if(e.length==0)return I(!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 I(!1)}).then(()=>{t.finish(!0)}),t.result()},wd=`
|
|
10
10
|
@media screen {
|
|
11
11
|
[data-vivliostyle-viewer-viewport] {
|
|
12
12
|
background: #aaaaaa;
|
|
@@ -1863,12 +1863,12 @@ span[data-viv-leader] {
|
|
|
1863
1863
|
@counter-style upper-russian {
|
|
1864
1864
|
system: alphabetic;
|
|
1865
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;
|
|
1866
|
-
}`;function Ro(e,t,i){let n=D("fetchFromURL"),r={method:i||"GET",mode:"cors"},s=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=Td([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{o.status>=400?q.warn(`Error fetching ${e} (${o.status}${o.statusText?" "+o.statusText:""})`):q.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function Td(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Yy(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 Zy(e){return URL.createObjectURL(e)}var Fl=class{constructor(e,t){this.parser=e,this.type=t,d(this,"resources",{}),d(this,"fetchers",{})}load(e,t,i){e=Ht(e);let n=this.resources[e];return typeof n<"u"?I(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 s=Ie("user-agent.xml",Ni),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(Sd)}`),Ro(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=s),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ht(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Yr(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ht(e)]}delete(e){delete this.resources[Ht(e)]}};function Ky(e,t){let i=e.responseText;return I(i?xl(i):null)}function Jy(){return new Fl(Ky,"text")}function kt(e,t,i){let n=new Yr(()=>{let r=D("loadElement"),s=r.suspend(e),o=!1,a=null,h=l=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);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 Kh=0,Qy=16777216,Id=33554432,Ad=50331648,Fd=67108864,ev=83886080,tv=100663296,Lo=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 Kh;case"User":return tv;default:return ev}}getBaseSpecificity(){switch(this.flavor){case"UA":return Kh;case"User":return Qy;default:return Id}}},Ra=class extends Lo{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;q.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)}},Jh=class extends Lo{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()}},sn=class extends Jh{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Jh(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())}},He=[],to=[],Se=[],Me=[],_t=[],at=[],$e=[],Ke=[],xe=[],et=[],ct=[],je=[],Ve=[],yn=55,vn=56,hs=57;He[1]=28,He[36]=29,He[7]=29,He[9]=29,He[14]=29,He[18]=29,He[50]=29,He[20]=30,He[13]=27,He[0]=200,to[1]=46,to[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[50]=42,Se[37]=11,Se[23]=12,Se[35]=56,Se[1]=1,Se[36]=3,Se[7]=5,Se[9]=7,Se[14]=9,Se[12]=13,Se[18]=55,Se[50]=58,Se[16]=41,Me[37]=11,Me[23]=12,Me[35]=56,Me[1]=1,Me[36]=3,Me[7]=5,Me[9]=7,Me[14]=9,Me[18]=55,_t[1]=2,_t[36]=4,_t[7]=6,_t[9]=8,_t[18]=14,_t[50]=42,_t[14]=10,_t[12]=13,$e[1]=15,$e[7]=16,$e[4]=17,$e[5]=18,$e[3]=19,$e[2]=20,$e[8]=21,$e[27]=57,$e[16]=22,$e[19]=23,$e[6]=24,$e[11]=25,$e[17]=26,$e[13]=48,$e[31]=47,$e[23]=54,$e[0]=44,Ke[1]=31,Ke[4]=32,Ke[5]=32,Ke[3]=33,Ke[2]=34,Ke[10]=40,Ke[6]=38,Ke[31]=36,Ke[24]=36,Ke[32]=35,xe[1]=45,xe[16]=37,xe[37]=37,xe[38]=37,xe[47]=37,xe[48]=37,xe[39]=37,xe[49]=37,xe[41]=37,xe[26]=37,xe[25]=37,xe[23]=37,xe[24]=37,xe[19]=37,xe[21]=37,xe[36]=37,xe[18]=37,xe[22]=37,xe[11]=39,xe[12]=43,xe[17]=49,et[0]=200,et[12]=50,et[13]=51,et[14]=50,et[15]=51,et[10]=50,et[11]=51,et[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,je[0]=200,je[12]=50,je[13]=51,je[14]=50,je[15]=51,je[10]=50,je[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[yn]=2,Ve[vn]=2;var Zr=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,s;do if(s=i[--n],e===")"&&s instanceof pn){if(s.text===")")r++;else if(s.text==="("){if(r===0)return null;r--}}while(typeof s<"u"&&typeof s!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new J(i.slice(n+1,i.length))),e==",")return null;n++;do s=i[--n];while(typeof s<"u"&&(typeof s!="string"||s==","));if(o=i.length-(n+1),s=="("){if(e!=")"&&t.type!==0)return this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=ct,null;let h=new ai(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof he&&h.values[0].name;Xe(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(o>1)return new _e(this.extractVals(",",n+1));let a=i[0];return a instanceof st?a:a?new pn(a.toString()):Be}exprError(e,t){this.actions=this.propName?ct:et,q.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),s;for(;;){let o=i.pop();if(e==11){let a=[r];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),u=new pm(n.getScope(),h,l);a.unshift(u)}return i.push(new j(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();r=new mr(n.getScope(),ba(l,h),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new Ah(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new Ii(n.getScope(),r);else if(o==-24)r=new Sn(n.getScope(),r);else if(o==-hs)r=new cm(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Ve[e]>Ve[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new El(n.getScope(),s,r);break;case yn:r=new dm(n.getScope(),s,r);break;case vn:r=new fm(n.getScope(),s,r);break;case 25:r=new Pl(n.getScope(),s,r);break;case 38:r=new gm(n.getScope(),s,r);break;case 37:r=new ym(n.getScope(),s,r);break;case 48:r=new mm(n.getScope(),s,r);break;case 47:r=new Sa(n.getScope(),s,r);break;case 39:case 49:r=new Nl(n.getScope(),s,r);break;case 41:r=new vm(n.getScope(),s,r);break;case 23:r=new Fc(n.getScope(),s,r);break;case 24:r=new Rc(n.getScope(),s,r);break;case 36:r=new Tl(n.getScope(),s,r);break;case 19:r=new Lc(n.getScope(),s,r);break;case 21:r=new Oc(n.getScope(),s,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new xm(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new Ah(n.getScope(),s,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(s),i.push(o),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let 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 s=0,o,a=0;for(;s>=0;)switch(i.consume(),o=i.token(),o.type){case 11:s--;break;case 10:case 6:s++;break;case 16:s===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let h=o.position,l=i.input.substring(n,h),u=t&&r==="selector"&&a>0?"":Xe(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,s=t.type===23||r;if(s&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,s)return null}else if(n<0){if(s)return null}else if(n>=0&&!s)return null;this.tokenizer.consume()}else if(s)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Ut(i,t,new Ii(i,new Je(i,"pref-horizontal")));break;case"horizontal":t=Ut(i,t,new Je(i,"pref-horizontal"));break;case"day":t=Ut(i,t,new Ii(i,new Je(i,"pref-night-mode")));break;case"night":t=Ut(i,t,new Je(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new j(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,h=this.valStack,l,u,c,p,f,g,y,b=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&b===null&&(b=l.position-1,a.input[b]==="("&&b++),this.actions===$e&&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 pn(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=ct):(this.actions=at,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=$e,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=ct,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=$e,h.splice(0,h.length);continue;case 29:this.actions=at,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=je,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.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:o.tagSelector(c,l.text),r?this.actions=Me:this.actions=Se,a.consume();break;case 36:o.tagSelector(c,null),r?this.actions=Me:this.actions=Se,a.consume();break;default:this.actions=et,o.error("E_CSS_NAMESPACE",l)}else this.actions=et,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=je,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),r?this.actions=Me:this.actions=Se,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Me:this.actions=Se,a.consume();break;default:this.actions=et,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Me:this.actions=Se,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Me:this.actions=Se;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=Se:this.actions=je;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){y=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(y.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(y=this.readNthPseudoParams(),y)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=at,o.startFuncWithSelector(p,y),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Me:this.actions=Se:this.actions=je;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)y.push(u.text),a.consume();else break e;break}else break;else break e;default:if(y=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){o.pseudoclassSelector(p,y),a.consume(),r?this.actions=Me:this.actions=Se;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=et;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),r?this.actions=Me:this.actions=Se,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(y=this.readNthPseudoParams(),y===null)break}else y=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(p,y),r?this.actions=Me:this.actions=Se,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=et;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:{if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=je,o.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=je,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=je,o.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:o.attributeSelector(c,p,0,null,null),r?this.actions=Me:this.actions=Se,a.consume();continue;default:this.actions=je,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}let x=p,m=null;switch(l.type){case 1:case 2:{let w=l.text;if(a.consume(),l=a.token(),l.type==1){let S=l.text.toLowerCase();(S=="i"||S=="s")&&(m=S,a.consume(),l=a.token())}o.attributeSelector(c,x,f,w,m);break}default:this.actions=je,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=je,o.error("E_CSS_ATTR",l);continue}r?this.actions=Me:this.actions=Se,a.consume();continue}case 11:o.childSelector(),this.actions=_t,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=_t,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=_t,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=He,a.consume();continue;case 41:o.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 Uc(l.text)),a.consume();continue;case 17:h.push(new Tt(l.num)),a.consume();continue;case 18:h.push(new lt(l.num)),a.consume();continue;case 19:h.push(new L(l.num,l.text)),a.consume();continue;case 20:h.push(new Z(l.text)),a.consume();continue;case 21:h.push(new it(Ie(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Wc(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Gn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ke,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 pn("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?to:He;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&&o.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new Je(o.getScope(),ba(l.text,u.text))),this.actions=xe),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Ih(o.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new Ih(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==yn&&h[h.length-1]!==vn&&(u.type===10||u.type===6)){h.push(-hs),a.consume();continue}else h.push(new Je(o.getScope(),l.text));this.actions=xe}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=xe;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new tt(o.getScope(),l.num)),a.consume(),this.actions=xe;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new Wr(o.getScope(),l.num,p)),a.consume(),this.actions=xe;continue;case 34:h.push(new tt(o.getScope(),l.text)),a.consume(),this.actions=xe;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Dc(o.getScope(),l.num)),a.consume(),this.actions=xe);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Ke,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==vn&&h[h.length-2]!==-hs?(this.actions=Ke,this.exprStackReduce(yn,l),h.push(yn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==yn&&h[h.length-2]!==-hs?(this.actions=Ke,this.exprStackReduce(vn,l),h.push(vn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=$e),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=He)),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=He,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=He,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=xe;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=He,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ke,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=et;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=et;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=et;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),o.startRuleBody();continue}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=_t;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),o.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(p),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ke,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ke,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ke,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,m=null,w=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(m=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;)w.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(x,m,w);break;case"-epubx-partition":o.startPartitionRule(x,m,w);break;case"-epubx-partition-group":o.startPartitionGroupRule(x,m,w);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=je;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=et;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=et;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=He;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=He),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){o.nextSelector(),this.actions=at,b=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=He),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===je)switch(l.type){case 16:this.errorBrackets.length==0&&(o.nextSelector(),b=l.position+1,this.actions=at),a.consume();continue;case 11:if(this.errorBrackets.length==0)return o.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)o.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(b,l.position);o.pushSelectorText(x),b=l.position+1}if(l.type===16){o.nextSelector(),this.actions=at,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=Se;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=je;continue}if(this.actions!==et&&this.actions!==je&&this.actions!==ct){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===$e){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new pn(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ke&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=He,a.consume();continue}else{if(l.type===17&&this.actions==Ke)return this.actions=He,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=ct:this.actions=je;continue}a.consume();continue}}return!1}},Rd=class extends Lo{constructor(e){super(null),this.scope=e}error(e,t){q.warn(e,t.toString())}getScope(){return this.scope}};function iv(e,t,i,n,r){let s=Ld(t),o=iy(e.input);return o!==e.input?Qh(new bt(o,s),s,i,n,r):Qh(e,s,i,n,r)}function Qh(e,t,i,n,r){let s=D("parseStylesheet"),o=new Zr(He,e,t,i),a=null;return r&&(a=Bd(new bt(r,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),s.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let l=Ie(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=D("parseStylesheet.import");return Od(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let h=s.timeSlice();if(h.isPending)return h}return I(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function Rl(e,t,i,n,r){let s=Ld(t);return Mn("parseStylesheetFromText",o=>{let a=new bt(e,s);iv(a,s,i,n,r).thenFinish(o)},(o,a)=>{q.warn(a,`Failed to parse stylesheet text: ${e}`),o.finish(!1)})}function Ld(e){if(e instanceof Ra)return e;if(e instanceof sn){if(e.owner)return e.owner;let t=new Ra;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Od(e,t,i,n){return Mn("parseStylesheetFromURL",r=>{Ro(e).then(s=>{s.responseText?Rl(s.responseText,t,e,i,n).then(o=>{o||q.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{q.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function Ri(e,t,i){let n=new Zr($e,t,new Rd(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function nv(e,t,i){new Zr(to,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Bd(e,t,i){let n=new Zr(Ke,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var rv={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function sv(e){return!!rv[e]}function ov(e,t,i){if(t instanceof we&&t.str==="viv-leader")return new j(t);if(i==="content"&&t instanceof we)return new j(t);let n=t.evaluate(e);switch(typeof n){case"number":return sv(i)?n==Math.round(n)?new lt(n):new Tt(n):new L(n,"px");case"string":return n?i==="content"?new Z(n):Ri(t.scope,new bt(n,null),""):Be;case"boolean":return n?v._true:v._false;case"undefined":return Be}throw new Error("E_UNEXPECTED")}var av="data-vivliostyle-flow-root";function lv(e){return e.getAttribute(av)==="true"}function eu(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 Ar(e){return e===v.absolute||e===v.fixed}function yr(e){return e instanceof ai&&e.name==="running"}function Md(e,t,i,n){return e===v.none||(Ar(t)?(i=v.none,e=eu(e)):(i&&i!==v.none&&!Y(i)||n)&&(e=eu(e))),{display:e,position:t,float:i}}function _d(e,t,i,n){return Md(e,t,i,n).display===v.block}function Oo(e){return e instanceof he||e instanceof J||typeof e=="string"}function Dt(e){if(!Oo(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 hr(e){return Oo(e)?e.toString().includes("list-item"):!1}function hv(e){if(!Oo(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 Dd(e){if(!Oo(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 uv(e,t,i,n,r,s,o){return r=r||s||v.horizontal_tb,!!o||!!i&&i!==v.none&&!Y(i)||Ar(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!Y(n)||!!s&&r!==s}function cv(e){return e===v.relative||e===v.absolute||e===v.fixed}var ti=1e5;function Ll(e){let t=e.element.style;t.columnGap=`${ti-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Bo(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function io(e){return e.element.style.columnCount==="1"}function dv(e){e.element.setAttribute("data-vivliostyle-column","true")}function Fr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/ti)}function Ol(e,t){let i=Fr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/ti),s=r*ti,o=i*ti;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=ti),e.right-=s,e.left-=o):e.left<-ti/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=ti),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=ti),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function no(e,t){for(let i=0;i<e.length;i++)Ol(e[i],t)}function $t(e,t,i){let n=e.getElementClientRect(t);if(Ol(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Kr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Bo(r),e.getElementClientRect(t)}return n}function pv(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 La(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function fv(e){if(!e.hasAttribute("data-vivliostyle-column")&&La(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&La(t))return!0;return!1}function Kr(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(La(t))return t;if(i.position==="absolute")break}return null}function gv(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",s=i.previousElementSibling,o=s&&((t=s.style)==null?void 0:t.breakAfter)==="column";if(!r&&!o)return;let a=Kr(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",y=(parseFloat(c)||parseFloat(p)||16)/2,b=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>b.bottom+y:g?x.right<b.left-y:x.left>b.right+y)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${ti}px`)}function us(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?Fr(i,e.vertical):0}function zd(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||us(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&&Kr(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let s=NaN;if(e.style.blockSize=`${r}px`,us(t)){if(e.style.blockSize=`${n}px`,!us(t)){let o=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>o;){let l=(a+h)/2;e.style.blockSize=`${l}px`,us(t)?h=l:a=l}s=a,e.style.blockSize=`${s}px`}}else if(s=parseFloat(i.blockSize),s<r){let o=1/t.clientLayout.layoutUnitPerPixel;s=r+o,e.style.blockSize=`${s}px`}if(isNaN(s)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function mv(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)zd(i,e)}function wn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let s=r.nodeType===1?r:r.parentElement;if(s&&s.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=s.style;if(s.localName==="wbr"||o&&Dt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(s.localName==="br"){let o=s.ownerDocument.createElement("span");s.parentNode.insertBefore(o,s);let a=t.getElementClientRect(o);if(o.remove(),a){let h=[a];no(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,h=s.nextSibling;a.removeChild(s),a.insertBefore(s,h)}let o=$t(t,s,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);no(l,n);let u=l.filter(c=>c.right>c.left&&c.bottom>c.top);if(u.length>0)l=u;else{let c=s?t.getElementComputedStyle(s).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?o=Math.min.apply(null,l.map(c=>c.left)):o=Math.max.apply(null,l.map(c=>c.bottom)),o):NaN}}function Oa(e,t,i){let n=io(t);n&&Bo(t);let r=t.clientLayout.getElementClientRect(e);n&&Ll(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function kn(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Vd(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 Dn="data-adapt-spec";function Bl(e){return!!e.getAttribute(Dn)}function Rt(e){return e?.nodeType!==1?!1:Bl(e)?!0:$d(e)}function $d(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let s=(i=n.style)==null?void 0:i.float;return s==="left"||s==="right"||s==="inline-start"||s==="inline-end"}function tu(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function En(e){let t=e?.viewNode;return t?.nodeType===1&&Bl(t)}function yv(e){return e!=="inline"&&(Dt(e)||Dd(e))}function iu(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 vv(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 Hd(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},s=e[n];Object.keys(s).forEach(o=>{r[o]=s[o].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Ud(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let s=r[i||"ltr"];if(!s)throw new Error(`unknown direction: ${i}`);for(let o of s){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var Wd={"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"}]}},wv=Hd(Wd,!0);function Gd(e,t,i){return Ud(e,t,i||null,wv)}var bv=Hd(Wd,!1);function jd(e,t,i){return Ud(e,t,i||null,bv)}var xv={"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 Sv(e,t){let i=xv[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 Ml(e,t,i){var n;let r=t,s={width:r.style.width,height:r.style.height};function o(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=o("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=o(p);return r.style[p]=s[p],g}let 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 Pn(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 Xd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function qd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function St(e,t){let i=Xd(e);i.includes(t)||(i.push(t),qd(e,i))}function Cv(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function kv(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function ra(e,t){let i=Cv(e);i.includes(t)||(i.push(t),kv(e,i))}function Ev(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var Ba={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ze(e){return!!Ba[e]}var Pv={left:!0,right:!0,recto:!0,verso:!0};function en(e){return!!Pv[e]}function nu(e){return Ze(e)&&e!=="column"&&e!=="region"}var Nv={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ro(e){return!!Nv[e]}function nt(e,t){if(e)if(t){if(en(t))return t;if(en(e))return e;{let i=Ze(e),n=Ze(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:ro(t)?t:ro(e)?e:t}}else return e;else return t}function ru(e){return Ze(e)?e:"auto"}Ot("SIMPLE_PROPERTY",Ev);var vr=$g(Ug());function Tv(e,t){return(0,vr.default)(e,t,0)}function su(e){return e.reduce((t,i)=>i[0]===vr.default.DELETE?t:t+i[1],"")}function Iv(e,t){return Yd(e,t,1)}function Av(e,t){return Yd(e,t,-1)}function Yd(e,t,i){let n=0,r=0;return e.some(s=>{for(let o=0;o<s[1].length;o++){switch(s[0]*i){case vr.default.INSERT:n++;break;case vr.default.DELETE:n--,r++;break;case vr.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Ma;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Ma||(Ma={}));var Fn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(Fn||(Fn={}));var so;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(so||(so={}));var Yi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||Li.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||Li.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Yi||(Yi={}));var Li;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(Li||(Li={}));var yi;(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={}))})(yi||(yi={}));var Fv={transform:!0,"transform-origin":!0},Rv={top:!0,bottom:!0,left:!0,right:!0},_l=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Lv={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 Ov(e,t){let i=Lv[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var _a=class ur extends Cl{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,s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(s){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:s,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(ur.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(ur.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(ur.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(ur.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(s=>{let o=this.elementsById[s];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[s]});let n=this.delayedItems;for(let s=0;s<n.length;s++){let o=n[s];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||A(o.target,o.name,o.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let s=0;s<t.length;s++){let o=t[s],a=this.elementsById[o.ref],h=this.elementsById[o.observer];if(a&&h){let l=Ov(a,o.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(o.event,l,!1)}}}};d(_a,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),d(_a,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Zd=_a,wt=yi.Whitespace;function Kd(e){switch(e){case"normal":case"nowrap":return wt.IGNORE;case"pre-line":return wt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return wt.PRESERVE;default:return null}}function Ee(e,t){return e?e.nodeType==1?!1:Jd(e.textContent,t):!0}function Jd(e,t){switch(t){case wt.PRESERVE:return e.length==0;case wt.NEWLINE:return!!e.match(/^[ \t]*$/);case wt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var Bv=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,d(this,"forcedBreakOffsets",[]),d(this,"formattingContext",null)}},Mv=class{constructor(e,t,i,n,r,s,o,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=s,this.repeated=o,this.last=a,this.breakBefore=h,d(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function _v(e,t){return e.top-t.top}function Dv(e,t){return t.right-e.right}function Qd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===yi.ShadowType.ROOTLESS&&t.shadowType===yi.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Da(e.shadowContext,t.shadowContext)&&Da(e.nodeShadow,t.nodeShadow)&&Qd(e.shadowSibling,t.shadowSibling)}function Oi(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(!Qd(e.steps[i],t.steps[i]))return!1;return!0}function zv(e){return{steps:[{node:e,shadowType:ot.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function oo(e,t){return{steps:[{node:e.sourceNode,shadowType:ot.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ao(e,t){let i=new bn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ao(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var ot=yi.ShadowType,Rs=class{constructor(e,t,i,n,r,s,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=s,this.styler=o,d(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Da(this.parentShadow,e.parentShadow):!1}};function Da(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Vv=class{constructor(e,t){this.outer=e,this.count=t}},bn=class ep{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=ot.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Fn.FloatReference.INLINE,this.whitespace=i?i.whitespace:wt.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=Fn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:wt.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,this.pageType=this.parent?this.parent.pageType:null}cloneItem(){let t=new ep(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.pageType=this.pageType,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,s=[];r.shadowType===yi.ShadowType.ROOTLESS&&(r.floatReference!==Fn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&s.push(r.toNodePositionStep()),r=r.parent;while(r);let o=this.preprocessedTextContent?Av(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:s,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Bi=class tp{constructor(t){this.primary=t,d(this,"floats",null)}clone(){let t=new tp(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(!Oi(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(!Oi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},$v=class ip{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new ip(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Hv=class np{constructor(){d(this,"positions",[]),d(this,"startBreakType",null),d(this,"breakAfter",null)}clone(){let t=new np,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}},Uv=class rp{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 rp;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}},sp=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,A(this.element,"top",`${e}px`),A(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,A(this.element,"left",`${e}px`),A(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):Al(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 sd(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)}},Rr=class extends Zt{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 it)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();if(t instanceof we){let n=t;if(typeof n.getContentList=="function"){let r=n.getContentList();if(r)return r.visit(this),null}}let 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 we&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function It(e){return e!=null&&e!==Be&&e!==v.normal&&e!==v.none&&!Y(e)}var Te=Fn.FloatReference,Wv=20;function Gv(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Ai(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function sa(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=jd(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=Gd(e,r,i),o=Sv(s,r);o==="line-left"?e="left":o==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(q.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var op=class{constructor(e,t,i,n,r,s){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=s,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}},jv=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=>Oi(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=>Oi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let s=r.nodePosition.steps;if(!(s!=null&&s.length)||s.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let o=Math.min(s.length,i.length);for(let a=0;a<o;a++)if(s[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},ap=class{constructor(e,t,i,n,r,s){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=s}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},ou=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Oi(this.nodePosition,e.nodePosition):!1}},xn=class{constructor(e,t,i,n,r,s,o){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=!Y(s)&&s||e&&e.writingMode||v.horizontal_tb,this.direction=!Y(o)&&o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new jv;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let s=r-1;s>=0;s--){let o=this.children[s];if(o.floatReference===t&&o.flowName===i&&Oi(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new zn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],s=r.area&&r.area.element;s&&s.parentNode&&s.parentNode.removeChild(s),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&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)}findPageFloatAnchor(e){var t;for(let i=this.children.length-1;i>=0;i--){let n=this.children[i].findPageFloatAnchor(e);if(n)return n}return(t=this.floatAnchors[e])!=null?t:null}hasCurrentAnchor(e){var t,i;let n=this.findPageFloatAnchor(e);return n?!!((i=(t=this.container)==null?void 0:t.element)!=null&&i.contains(n)):!1}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.findPageFloatAnchor(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 s=r.float,o=s.getOrder();o>t&&(!i||o>i.getOrder())&&(i=s)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}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&&fv(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Wv?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Te.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if(this.floatReference===Te.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===v.line&&this.hasCurrentAnchor(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 jd(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Gd(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],r=!1,s=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?r||(i.slice(o+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),s=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],s=this.toLogicalFloatSides(r.floatSide)[0];(s===i||i==="snap-block"&&s==="block-end"||i==="snap-inline"&&s==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,s=!0){this.container;let o=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(o,h,i,n,r);if(s&&this.parent&&this.parent.container){let c=this.parent.getLimitValue(a,l,i,n,r,s);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 s=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?s.right:s.top;case"block-end":return this.container.vertical?s.left:s.bottom;case"inline-start":return this.container.vertical?this.container.rtl?s.bottom:s.top:this.container.rtl?s.right:s.left;case"inline-end":return this.container.vertical?this.container.rtl?s.top:s.bottom:this.container.rtl?s.left:s.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var s,o,a,h;this.container;let l=this.container.originX,u=this.container.originY,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 y=parseFloat((o=(s=this.container.element)==null?void 0:s.style)==null?void 0:o.width);isFinite(y)&&y>this.container.width&&(p.right+=y-this.container.width)}else{let y=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(y)&&y>this.container.height&&(p.bottom+=y-this.container.height)}function f(y,b,x){return y.unit==="%"?x*y.num/100:e.convertLengthToPx(y,b,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((y,b)=>{if(i&&!i(b,this))return y;let[x,m]=this.toLogicalFloatSides(b.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||r&&m.includes("block")===r.includes("block")&&m!==r))return y;let w=b.area,S=b.continuations[0].float.floatMinWrapBlock,C=w.vertical?w.left+w.getInsetLeft()+w.width+w.getInsetRight():w.top+w.getInsetTop()+w.height+w.getInsetBottom(),T=w.vertical?w.top+w.getInsetTop()+w.height+w.getInsetBottom():w.left+w.getInsetLeft()+w.width+w.getInsetRight(),R=y.top,F=y.left,z=y.bottom,$=y.right,X=y.floatMinWrapBlockStart,re=y.floatMinWrapBlockEnd;switch(x){case"inline-start":w.vertical?R=Math.max(R,T):F=Math.max(F,T);break;case"block-start":w.vertical?(S&&w.left<$&&(X=f(S,w.rootViewNodes[0],c.x2-c.x1)),$=Math.min($,w.left)):(S&&C>R&&(X=f(S,w.rootViewNodes[0],c.y2-c.y1)),R=Math.max(R,C));break;case"inline-end":w.vertical?z=Math.min(z,w.top):$=Math.min($,w.left);break;case"block-end":w.vertical?(S&&C>F&&(re=f(S,w.rootViewNodes[0],c.x2-c.x1)),F=Math.max(F,C)):(S&&w.top<z&&(re=f(S,w.rootViewNodes[0],c.y2-c.y1)),z=Math.min(z,w.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:R,left:F,bottom:z,right:$,floatMinWrapBlockStart:X,floatMinWrapBlockEnd:re}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}setFloatAreaDimensions(e,t,i,n,r,s,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,s,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0].includes("block")&&!o[a[0]])return null;e.clientLayout;let h=a.find(C=>C.includes("inline")&&o[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,y=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 b(C,T){let R=C(e.bands,T);return R?(e.vertical&&(R=id(R)),u=e.vertical?Math.min(u,R.x2):Math.max(u,R.y1),c=e.vertical?Math.max(c,R.x1):Math.min(c,R.y2),!0):s}let x,m,w,S;if(r){let C=e.vertical?eo(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")&&!b(Mm,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!b(_m,C)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?u=Math.min(u,n):u=Math.max(u,n)),w=(c-u)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(w=Math.min(w,this.footnoteMaxBlockSize),e.vertical?u=c+w:u=c-w),x=Math.max(0,w-e.getInsetBefore()-e.getInsetAfter()),S=(f-p)*e.getInlineDir(),m=S-e.getInsetStart()-e.getInsetEnd(),!s&&(x<=0||m<=0)))return null}else{let C=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,C)),w=x+e.getInsetBefore()+e.getInsetAfter();let T=(c-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let F=this.container.getPaddingRect(),z=this.container.getBoxDir()*(n-(this.container.vertical?F.x2:F.y1)),$=this.container.getBoxDir()*((this.container.vertical?F.x1:F.y2)-n-w);z<=$?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!s&&T<w)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?m=Ml(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?m=e.getContentInlineSize():m=e.vertical?e.height:e.width,S=m+e.getInsetStart()+e.getInsetEnd();let R=(f-p)*e.getInlineDir();if(!s&&R<S)return null}return u-=g,c-=g,p-=y,f-=y,a.some(C=>C==="inline-start"||C==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,m):(a.some(C=>C==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-S*e.getInlineDir(),m),a.some(C=>C==="block-start"||C==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,x):(a.some(C=>C==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(c-w*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(s=>s.floatSide.includes("block-start")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x1:o.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let s=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.min(r,s):Math.max(r,s):s)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-end")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x2:o.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let s=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.max(r,s):Math.min(r,s):s)}return r}getPageFloatClearEdge(e,t){let i=u=>{let c=this.toLogicalFloatSides(u),p=c[0];return e==="both"?p==="block-end":e==="inline-start"?c.includes("inline-end")||p==="block-end":e==="inline-end"?c.includes("inline-start")||p==="block-start"||p==="block-end":!1};function n(u){return c=>!i(c.float.floatSide)&&u.isAnchorAlreadyAppeared(c.float.getId())}function r(u,c){return i(u.floatSide)?!1:u.continuations.some(n(c))}let s=t.getPaddingRect(),o=t.vertical?s.x1:s.y2,a=this;for(;a;){if(a.floatsDeferredToNext.some(n(a)))return o;a=a.parent}function h(u){return u.floatFragments.some(c=>r(c,u))||u.children.some(c=>h(c))}if(e==="column"||e==="region"||e==="page"){for(a=this;a;a=a.parent)if(a.floatReference===e){if(h(a))return o;break}}t.clientLayout;let l=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,r);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,r)*t.getBoxDir()<o*t.getBoxDir()?o:l}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],s=this.toLogical(i),o;s==="all"?o=["block-start","block-end","inline-start","inline-end"]:s==="both"?o=["inline-start","inline-end"]:s==="same"?r==="snap-block"?o=["block-start","block-end"]:o=[r]:o=[s];let a=e.getOrder();function 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 o.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 o=n.getLimitValuesInner(t,i);r?e.vertical?(o.right<r.right&&(r.right=o.right,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>r.left&&(r.left=o.left,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>r.top&&(r.top=o.top,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<r.bottom&&(r.bottom=o.bottom,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):r=o,n=n.parent}let s=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=s}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},er=[],zn=class{static register(e){er.push(e)}findByNodeContext(e){for(let t=er.length-1;t>=0;t--){let i=er[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=er.length-1;t>=0;t--){let i=er[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Xv=class{appliesToNodeContext(e){return Ai(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition(),o=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new op(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=o,o){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),I(h)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new ap(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return I(void 0)}forbid(e,t){}};zn.register(new Xv);var lp="data-vivliostyle-footnote-first-ref",hp="data-vivliostyle-footnote-referenced";function lo(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function Et(e){if(e.localName!=="aside")return!1;if(lo(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return lo(t,"footnote")}function Wt(e){if(e.localName!=="a")return!1;if(lo(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return lo(t,"noteref")}function Dl(e,t){if(!Wt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=Zs(i,t);return n==="#"?null:n}function up(e,t,i){let n=Dl(e,t);if(!n)return null;let r=i(n);return r&&Et(r)?r:null}function qv(e,t,i,n,r){if(r.value)return;let s=e.getElementsByTagName("a");for(let o=0;o<s.length;o++){let a=s.item(o),h=Dl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function au(e,t,i,n,r){if(e.localName!=="a"||!Wt(e))return!0;let s=Dl(e,t);if(!s)return!0;qv(e.ownerDocument,t,i,n,r);let o=n.get(s);return o==null||i(e)===o}function zl(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===v.inline?t.createCascadeValue(v.inline,n.priority):null}function Yv(e,t,i,n,r,s,o){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)||!Wt(a))return t;let h=up(a,n,r);if(!h)return t;let l=a.getAttribute(s);l?(e.setAttribute(s,l),h.setAttribute(s,l)):(e.removeAttribute(s),h.removeAttribute(s));let u=o.getStyle(h);if(!u)return t;let c={...t},p=zl(u,o),f=o.getProp(u,"footnote-policy"),g=o.getStyleMap(u,"_pseudos"),y=g?.after;if(p&&(c["footnote-display"]=p),f&&(c["footnote-policy"]=f),y){let b=o.getMutableStyleMap(c,"_pseudos");b.after={...y}}return c}function Zv(e,t,i,n,r){var s;if(!(i?.type===ot.ROOTED&&Et(e)))return t;let o=r.getStyle(e);if(!o)return t;let a={...t},h=zl(o,r),l=r.getProp(o,"footnote-policy"),u=r.getStyleMap(o,"_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&&((s=f?.evaluate)==null?void 0:s.call(f,n,"list-style-position"))===v.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(M("list-item"),0),a["list-style-position"]=r.createCascadeValue(v.outside,0),a["list-style-type"]=r.createCascadeValue(v.none,0),a["list-style-image"]=r.createCascadeValue(v.none,0)}return a}function Kv(e,t,i){var n,r;let s=t?.type===ot.ROOTED&&Et(e)?i.getStyle(e):null;return{sourceStyle:s,footnoteDisplay:((n=zl(s,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(s,"footnote-policy"))==null?void 0:r.value)||null}}function cp(e,t){if(e instanceof j){let i=e.expr.evaluate(t);return typeof i=="string"?new Z(i):typeof i=="number"?new Z(String(i)):e}return e instanceof J?new J(e.values.map(i=>cp(i,t))):e}function Jv(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=cp(n.value,i))}function Qv(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Wt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let s=r.hash.substring(1),o=e.getElementById(s);if(o&&Et(o)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(lp,"true")),o.setAttribute(hp,"true")}}}Ot("PREPROCESS_SINGLE_DOCUMENT",Qv);var ew=ap,tw=.1,ho=class dp extends op{constructor(t,i,n,r,s,o){super(t,i,"block-end",null,n,s),this.footnotePolicy=r,this.policyAnchorNode=o}isAllowedToPrecede(t){return!(t instanceof dp)}};function iw(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}function pp(e){return e?-1:1}function za(e,t){return t?e.right:e.top}function Vl(e,t){return t?e.left:e.bottom}function fp(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function gp(e,t){let i=fp(e.getBoundingClientRect());return Ol(i,t),i.right<i.left||i.bottom<i.top?null:i}function Va(e,t){let i=Array.from(e,fp);return no(i,t),i.filter(n=>n.right>n.left&&n.bottom>n.top)}function mp(e,t){return e.length?t?Math.min(...e.map(i=>i.left)):Math.max(...e.map(i=>i.bottom)):NaN}function nw(e,t){if(!e.length)return NaN;let i=pp(t),n=e.reduce((r,s)=>za(s,t)*i<za(r,t)*i?s:r);return Vl(n,t)}function rw(e,t){if(!e)return NaN;if(e.nodeType===Node.ELEMENT_NODE){let s=gp(e,t);return s?Vl(s,t):NaN}let i=e.textContent||"";if(!i.length)return NaN;let n=e.ownerDocument.createRange();n.setStart(e,0),n.setEnd(e,i.length);let r=Va(n.getClientRects(),t);return mp(r,t)}function sw(e,t){let i=e.viewNode;if(!i)return NaN;if(i.nodeType===Node.ELEMENT_NODE){let a=i;if(e.after||!e.inline){let l=gp(a,t);if(l)return e.after?Vl(l,t):za(l,t)}let h=Va(a.getClientRects(),t);return nw(h,t)}let n=i.textContent||"";if(!n.length)return NaN;let r=e.offsetInNode;e.after&&(r+=n.length),r=Math.max(0,Math.min(r,n.length-1));let s=i.ownerDocument.createRange();s.setStart(i,r),s.setEnd(i,r+1);let o=Va(s.getClientRects(),t);return mp(o,t)}var lu=class extends ew{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof ho?!0:this.getOrder()<e.getOrder()}},ow=class{constructor(e,t,i){this.footnote=e,this.vertical=i,d(this,"anchorEdge"),this.anchorEdge=rw(t,i)}allowLayout(e){if(!isNaN(this.anchorEdge)){let i=sw(e,this.vertical);if(!isNaN(i)){let n=pp(this.vertical);return i*n<this.anchorEdge*n-tw}}let t=e.toNodePosition();return!Oi(t,this.footnote.nodePosition)}},aw=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof ho}createPageFloat(e,t,i){var n;let r=Te.REGION,s=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(s)&&(r=Te.PAGE);let o=!!t.generatingNodePosition;o&&r!==Te.PAGE&&(r=Te.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Wt(l)&&(h=l),h=iw(h);let u=new ho(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(u.insidePageFloatArea=o,o){let c=t.generatingNodePosition;c&&(u.parentPageFloat=t.findPageFloatByNodePosition(c))}return t.addPageFloat(u),I(u)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new lu(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof lu);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 s,o;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((s=i.clientLayout.getElementComputedStyle(n))==null?void 0:s.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)||A(n,c,`${Math.max(0,f-h)}px`)}}A(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){A(n,"max-block-size",""),A(n,e.vertical?"max-width":"max-height","");break}a=(o=a.parent)!=null?o:null}return I(void 0)})}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=t.collectPageFloatAnchors()[i.getId()]||null,r=new ow(i,n,t.getContainer(i.floatReference).vertical);t.addLayoutConstraint(r,i.floatReference);break}}}};zn.register(new aw);var $l=class{calculateOffset(e){return Rn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Rn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Jr=class extends $l{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(ro(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=wn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let s=r.style.borderCollapse==="collapse",o=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!s)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!s&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},tr=class{find(e){let t=Gt("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()}`)}},Nn=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 Jr(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===yi.ShadowType.ROOTLESS&&En(i))return;let s=i.viewNode;((r=s.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(s=s.parentElement.parentElement);let o=s.parentNode;Vd(o,s),n&&o.removeChild(s)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),I(!0)}},Hl=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){}},Ul=new Nn,lw=Ma.isInstanceOfBlockFormattingContext;Ot("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,s)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&_d(i,n,r,s)?new Hl(o?o.formattingContext:null):null});Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Hl?Ul:null);var Wl=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 s=n.accept(r,t);s=n.postLayout(r,this.initialPosition,t,s),s?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},hw=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){}},$a=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 s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ee(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?s=t.afterIgnoredTextNode(i):s=t.startIgnoredTextNode(i):i.nodeContext.after?s=t.afterNonElementNode(i):s=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?s=t.afterInlineElementNode(i):s=t.startInlineElementNode(i):i.nodeContext.after?s=t.afterNonInlineElementNode(i):s=t.startNonInlineElementNode(i):i.nodeContext.after?s=t.afterNonDisplayableNode(i):s=t.startNonDisplayableNode(i);let o=(s&&s.isPending()?s:I(!0)).thenAsync(()=>i.break?I(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},wr=class extends hw{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&&Ze(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:I(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),I(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:I(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakAfter)),I(!0)))}},Ha=[];function uw(){Ha=[]}var cs;function ds(e){if(e==="")return 0;if(cs===void 0){let i=Intl.Segmenter;cs=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(cs===null)return[...e].length;let t=0;for(let i of cs.segment(e))t++;return t}var cw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],dw=new Set(cw);function pw(e){return!(e.toLowerCase()==="none"||dw.has(e))}var fw=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],gw=new Set(fw),mw=["fixed","extends"],yw=new Set(mw),QS=Symbol();function Qr(e){return e instanceof he&&e.name.toLowerCase()!=="none"}function yp(e){return e.name}function vw(e){if(e instanceof he)return gw.has(e.name);if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof he){let n=t.name;return yw.has(n)&&(n==="fixed"&&i instanceof lt||n==="extends"&&Qr(i))}}return!1}function ww(e){let t=dt(e,"system");return t instanceof he&&t.name==="cyclic"}function bw(e){let t=dt(e,"system");if(t instanceof he&&t.name==="fixed")return!0;if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof he&&i.name==="fixed"&&n instanceof lt}return!1}function xw(e){let t=dt(e,"system");return t instanceof he?1:t.values[1].num}function Sw(e){let t=dt(e,"system");return t instanceof he&&t.name==="alphabetic"}function Cw(e){let t=dt(e,"system");return t instanceof he&&t.name==="numeric"}function kw(e){let t=dt(e,"system");return t instanceof he&&t.name==="additive"}function Ew(e){let t=dt(e,"system");if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof he&&i.name==="extends"&&Qr(n)}return!1}function Pw(e){let t=dt(e,"system");return yp(t.values[1])}function jt(e){return e instanceof Z||e instanceof he}function fi(e){return e instanceof Z?e.str:e.name}function vp(e){if(jt(e))return!0;if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];return jt(t)&&jt(i)}return!1}function Nw(e){if(jt(e))return{prefix:fi(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:fi(t),suffix:fi(i)}}}function hu(e){return e instanceof lt||e instanceof he&&e.name==="infinite"}function uo(e,t){return e instanceof lt?e.num:t?-1/0:1/0}var eC=Symbol();function Ua(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(hu(t)&&hu(i)))return!1;let n=uo(t,!0),r=uo(i,!1);return!(n>r)}function Tw(e){return{lower:uo(e.values[0],!0),upper:uo(e.values[1],!1)}}function wp(e){return e instanceof he&&e.name==="auto"||Ua(e)||e instanceof _e&&e.values.length>=1&&e.values.every(t=>Ua(t))}function Iw(e){return e instanceof he?null:(Ua(e)?[e]:e.values).map(t=>Tw(t))}var tC=Symbol();function co(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof lt&&t.num>=0&&jt(i)||jt(t)&&i instanceof lt&&i.num>=0}function po(e){let[t,i]=e.values;return t instanceof lt?[t.num,fi(i)]:[i.num,fi(t)]}function bp(e){return co(e)}function Aw(e){let[t,i]=po(e);return{minLength:t,symbol:i}}function xp(e){return jt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>jt(t))}function Fw(e){return jt(e)?[fi(e)]:e.values.map(t=>fi(t))}var iC=Symbol();function Sp(e){if(co(e))return!0;if(e instanceof _e&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!co(i))return!1;let[n]=po(i);if(n>=t)return!1;t=n}return!0}return!1}function Rw(e){if(co(e)){let[t,i]=po(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=po(t);return{weight:i,symbol:n}})}var Lw=["auto","bullets","numbers","words","spell-out"],Ow=new Set(Lw);function Bw(e){return e instanceof he&&Ow.has(e.name)||Qr(e)}function Mw(e,t){switch(e){case"system":return vw(t);case"negative":return vp(t);case"prefix":case"suffix":return jt(t);case"range":return wp(t);case"pad":return bp(t);case"fallback":return Qr(t);case"symbols":return xp(t);case"additive-symbols":return Sp(t);case"speak-as":return Bw(t);default:return!0}}function dt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function _w(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Vn(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var Ls,Os,Bs,Ms,_s,Ds,zs,Vs,ps,ci,Cp,fs,kp,gs,Ep,ms,Pp,ys,Np,vs,Tp,ws,Ip,vt,oa,Ap,Fp,uu,cu,aa,du,cr,ze=class Ui{constructor(t,i){ie(this,vt),d(this,"_store"),ie(this,Ls),ie(this,Os),ie(this,Bs),ie(this,Ms),ie(this,_s),ie(this,Ds),ie(this,zs),ie(this,Vs),this._store=t;let n=dt(i,"negative");de(this,Ls,n&&vp(n)?Nw(n):null);let r=dt(i,"prefix");de(this,Os,r&&jt(r)?fi(r):null);let s=dt(i,"suffix");de(this,Bs,s&&jt(s)?fi(s):null);let o=dt(i,"range");de(this,Ms,o&&wp(o)?Iw(o):null);let a=dt(i,"pad");de(this,_s,a&&bp(a)?Aw(a):null);let h=dt(i,"fallback");de(this,Ds,h&&Qr(h)?yp(h):null);let l=dt(i,"symbols");de(this,zs,l&&xp(l)?Fw(l):null);let u=dt(i,"additive-symbols");de(this,Vs,u&&Sp(u)?Rw(u):null)}static create(t,i){return ww(i)?new _i(t,i):bw(i)?new Dw(t,i):Sw(i)?new Vw(t,i):Cw(i)?new pu(t,i):kw(i)?new $w(t,i):Ew(i)?new Hw(t,i):new zw(t,i)}static createDecimal(t){var i;return new pu(t,le(i=Ui,ci,Cp).call(i))}static createDisc(t){var i;return new _i(t,le(i=Ui,ci,kp).call(i))}static createSquare(t){var i;return new _i(t,le(i=Ui,ci,Ep).call(i))}static createCircle(t){var i;return new _i(t,le(i=Ui,ci,Pp).call(i))}static createDisclosureOpen(t){var i;return new _i(t,le(i=Ui,ci,Np).call(i))}static createDisclosureClosed(t){return new _i(t,le(this,ci,Tp).call(this))}static createNone(t){var i;return new _i(t,le(i=Ui,ci,Ip).call(i))}static get CHINESE_LONGHAND_NAMES(){return fu.NAMES}static createChineseLonghand(t,i){return new fu(t,i)}static createEthiopicNumeric(t){return new Ww(t)}_getNegative(){return H(this,Ls)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return H(this,Os)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return H(this,Bs)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return H(this,Ms)}static _getRangeFrom(t){return t._getRange()}_getPad(){return H(this,_s)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(H(this,Ds)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return H(this,zs)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return H(this,Vs)}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 le(this,vt,cr).call(this,t,new Set)}formatMarker(t){return le(this,vt,Ap).call(this)+this.format(t)+le(this,vt,Fp).call(this)}};Ls=new WeakMap,Os=new WeakMap,Bs=new WeakMap,Ms=new WeakMap,_s=new WeakMap,Ds=new WeakMap,zs=new WeakMap,Vs=new WeakMap,ps=new WeakMap,ci=new WeakSet,Cp=function(){var e;return(e=H(ze,ps))!=null?e:de(ze,ps,{system:new U(M("numeric"),0),symbols:new U(new J([new Z("0"),new Z("1"),new Z("2"),new Z("3"),new Z("4"),new Z("5"),new Z("6"),new Z("7"),new Z("8"),new Z("9")]),0)})},fs=new WeakMap,kp=function(){var e;return(e=H(ze,fs))!=null?e:de(ze,fs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u2022"),0),suffix:new U(new Z(" "),0)})},gs=new WeakMap,Ep=function(){var e;return(e=H(ze,gs))!=null?e:de(ze,gs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25AA"),0),suffix:new U(new Z(" "),0)})},ms=new WeakMap,Pp=function(){var e;return(e=H(ze,ms))!=null?e:de(ze,ms,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25E6"),0),suffix:new U(new Z(" "),0)})},ys=new WeakMap,Np=function(){var e;return(e=H(ze,ys))!=null?e:de(ze,ys,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25BE"),0),suffix:new U(new Z(" "),0)})},vs=new WeakMap,Tp=function(){var e;return(e=H(ze,vs))!=null?e:de(ze,vs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25B8"),0),suffix:new U(new Z(" "),0)})},ws=new WeakMap,Ip=function(){var e;return(e=H(ze,ws))!=null?e:de(ze,ws,{system:new U(M("cyclic"),0),symbols:new U(new Z(""),0),suffix:new U(new Z(""),0)})},vt=new WeakSet,oa=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Ap=function(){var e;return(e=this._getPrefix())!=null?e:""},Fp=function(){var e;return(e=this._getSuffix())!=null?e:". "},uu=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},cu=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},aa=function(){var e;return(e=this._getFallback())!=null?e:Vn(this._store)},du=function(e,t){let{minLength:i,symbol:n}=le(this,vt,cu).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=le(this,vt,oa).call(this),o=t?ds(r)+(s?ds(s):0):0,a=i-ds(e)-o;if(a<=0)return e;let h=ds(n),l=Math.ceil(a/h);return n.repeat(l)+e},cr=function(e,t){var i,n,r;if(t.has(this))return le(i=Vn(this._store),vt,cr).call(i,e,new Set);if(t.add(this),!_w(e,le(this,vt,uu).call(this))){let l=le(this,vt,aa).call(this);return le(n=l,vt,cr).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let l=le(this,vt,aa).call(this);return le(r=l,vt,cr).call(r,e,t)}let h=le(this,vt,du).call(this,a,s);if(s){let{prefix:l,suffix:u}=le(this,vt,oa).call(this);h=l+h+(u??"")}return h},ie(ze,ci),ie(ze,ps,null),ie(ze,fs,null),ie(ze,gs,null),ie(ze,ms,null),ie(ze,ys,null),ie(ze,vs,null),ie(ze,ws,null);var ce=ze,_i=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},$s,Dw=class extends ce{constructor(e,t){super(e,t),ie(this,$s),de(this,$s,xw(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-H(this,$s);return(t=i[n])!=null?t:null}};$s=new WeakMap;var zw=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Vw=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},pu=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},$w=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(s=>s.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:s,symbol:o}=r;if(s===0||s>n)continue;let a=Math.floor(n/s);if(i+=o.repeat(a),n-=s*a,n===0)return i}return null}},br,Ct,Ft,Rp=class extends ce{constructor(t,i){super(t,i),ie(this,Ct),ie(this,br);let n=Pw(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?de(this,br,r):de(this,br,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(le(this,Ct,Ft).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(le(this,Ct,Ft).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(le(this,Ct,Ft).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(le(this,Ct,Ft).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(le(this,Ct,Ft).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(le(this,Ct,Ft).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(le(this,Ct,Ft).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(le(this,Ct,Ft).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(le(this,Ct,Ft).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(le(this,Ct,Ft).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(le(this,Ct,Ft).call(this),t)}};br=new WeakMap,Ct=new WeakSet,Ft=function(e=new Set){var t;if(e.has(this))return Vn(this._store);e.add(this);let i=this._store.get(H(this,br));return i?i instanceof Rp?le(t=i,Ct,Ft).call(t,e):i:Vn(this._store)};var Hw=Rp,Uw=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"];function ir(e){return{suffix:new U(new Z("\u3001"),0),fallback:new U(M("cjk-decimal"),0),range:new U(new J([new lt(-9999),new lt(9999)]),0),negative:new U(new Z(e),0)}}var la,ha,bs,ua,xs,Wa,Lp,Hs,yt=class Op extends ce{constructor(t,i){var n;let{chars:r,descriptors:s}=le(n=Op,Wa,Lp).call(n).get(i);super(t,s),ie(this,Hs),de(this,Hs,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=H(this,Hs);if(t===0)return i.digits[0];let n=[],r=0,s=t;for(;s>0;)n.unshift({digit:s%10,position:r}),s=Math.floor(s/10),r++;let o=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:c}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),o&&c===1?a+=i.markers[c]:(a+=i.digits[u],c>0&&(a+=i.markers[c])))}return a}};la=new WeakMap,ha=new WeakMap,bs=new WeakMap,ua=new WeakMap,xs=new WeakMap,Wa=new WeakSet,Lp=function(){var e;return(e=H(yt,xs))!=null?e:de(yt,xs,new Map([["simp-chinese-informal",{chars:H(yt,la),descriptors:ir("\u8D1F")}],["simp-chinese-formal",{chars:H(yt,ha),descriptors:ir("\u8D1F")}],["trad-chinese-informal",{chars:H(yt,bs),descriptors:ir("\u8CA0")}],["trad-chinese-formal",{chars:H(yt,ua),descriptors:ir("\u8CA0")}],["cjk-ideographic",{chars:H(yt,bs),descriptors:ir("\u8CA0")}]]))},Hs=new WeakMap,ie(yt,Wa),ie(yt,la,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(yt,ha,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ie(yt,bs,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(yt,ua,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),d(yt,"NAMES",new Set(Uw)),ie(yt,xs,null);var fu=yt,Ss,Ga,Bp,ja,fo,Xa,qa,hi=class Wi extends ce{constructor(t){var i;super(t,le(i=Wi,Ga,Bp).call(i))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return H(Wi,fo)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,s="";for(let o=r-1;o>=0;o--){let a=i[o],h=o%2===1,l=o===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),c=a%10;s+=H(Wi,ja)[u]+H(Wi,fo)[c]}h?a!==0&&(s+=H(Wi,Xa)):o!==0&&(s+=H(Wi,qa))}return s}};Ss=new WeakMap,Ga=new WeakSet,Bp=function(){var e;return(e=H(hi,Ss))!=null?e:de(hi,Ss,{range:new U(new J([new lt(1),M("infinite")]),0),suffix:new U(new Z("/ "),0)})},ja=new WeakMap,fo=new WeakMap,Xa=new WeakMap,qa=new WeakMap,ie(hi,Ga),ie(hi,Ss,null),ie(hi,ja,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ie(hi,fo,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ie(hi,Xa,"\u137B"),ie(hi,qa,"\u137C");var Ww=hi,Re,Gw=class{constructor(){ie(this,Re),de(this,Re,new Map),H(this,Re).set("none",ce.createNone(H(this,Re))),H(this,Re).set("decimal",ce.createDecimal(H(this,Re))),H(this,Re).set("disc",ce.createDisc(H(this,Re))),H(this,Re).set("square",ce.createSquare(H(this,Re))),H(this,Re).set("circle",ce.createCircle(H(this,Re))),H(this,Re).set("disclosure-open",ce.createDisclosureOpen(H(this,Re))),H(this,Re).set("disclosure-closed",ce.createDisclosureClosed(H(this,Re)));for(let e of ce.CHINESE_LONGHAND_NAMES)H(this,Re).set(e,ce.createChineseLonghand(H(this,Re),e));H(this,Re).set("ethiopic-numeric",ce.createEthiopicNumeric(H(this,Re)))}define(e,t){if(!pw(e))return null;let i=ce.create(H(this,Re),t);return H(this,Re).set(e,i),i}getStyle(e){var t;return(t=H(this,Re).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Vn(H(this,Re))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Vn(H(this,Re))).formatMarker(t)}};Re=new WeakMap;var Tn=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)}},Di=class{constructor(e,t){this.where=e,this.success=t,d(this,"what",-1)}},nr=class Mp{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 Mp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Tn(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 Di(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,s=new Tn(gu);n>=0?i?s.markAsStartAlternate(n):s.markAsEndAlternate(n):i?s.markAsStartGroup():s.markAsEndGroup(),this.nodes.push(s),this.connect(t,r);let o=new Di(r,!0),a=new Di(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new Tn(gu);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Di(0,!0),r=new Di(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 Tn(t));let n=new Di(i,!0),r=new Di(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 s=0;s<t.nodes.length;s++)this.nodes.push(t.nodes[s]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let s=0;s<t.connections.length;s++){let o=t.connections[s];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let s=0;s<t.match.length;s++)this.match.push(t.match[s]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let s=0;s<t.nomatch.length;s++)this.match.push(t.nomatch[s]+r);else if(this.emptyHead){for(let s=0;s<t.nomatch.length;s++)this.nomatch.push(t.nomatch[s]+r);this.emptyHead=t.emptyHead}else for(let s=0;s<t.nomatch.length;s++)this.error.push(t.nomatch[s]+r);for(let s=0;s<t.error.length;s++)this.error.push(t.error[s]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},jw=1,go=2,_p=4,Si=8,Zi=16,$n=32,Ln=64,mo=128,ni=256,ri=512,yo=1024,Dp=2048,zp=4096,vo=8192,Gl=class extends Zt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},ue=class Vp extends Gl{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&jw?t:null}visitSlash(t){return this.allowed&Dp?t:null}visitStr(t){return this.allowed&go?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&_p||this.allowed&Ln&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&ri)?t.unit=="%"&&this.allowed&yo?t:null:t.num<0&&!(this.allowed&ni)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&ri?t:null:t.num<=0&&!(this.allowed&ni)?null:this.allowed&Zi?t:null}visitInt(t){return t.num==0?this.allowed&ri?t:null:t.num<=0&&!(this.allowed&ni)?null:this.allowed&($n|Zi)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Ln&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&mo?t:null}visitURange(t){return this.allowed&zp?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(t.name.toLowerCase()==="attr"){let i=Yl(t);if(i&&Kw(i.type,this.allowed,this.units))return t}if(this.allowed&Ln){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Yc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&vo){let i=t.visit(new Jc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Si|Zi|$n|ni|ri|yo)?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 Vp(this.allowed|t.allowed,i,n)}},ee=Object.create(null),Xw=Zi|ni|ri,qw=$n|ni|ri,zi=Si|ni|ri|yo;function es(e){let t=Object.create(null);for(let i of e)t[i]=Be;return t}var Mo=es(["%"]),_o=es(["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"]),$p={..._o,...Mo},jl=es(["deg","grad","rad","turn"]),Xl=es(["s","ms"]),ql=es(["hz","khz"]);function Yw(e){return e.replace(/\s+/g,"").toLowerCase()}function Do(e){return e.toLowerCase()}function Zw(e){if(e instanceof he)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:Do(e.name)}}if(e instanceof ai&&e.name.toLowerCase()==="type"){if(e.values.length!==1)return null;let t=Yw(e.values[0].stringValue());return t?{kind:"syntax",syntax:t}:null}return null}function Yl(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 he)i=r.name;else if(r instanceof J){let s=r.values;if(s.length<1||s.length>2||!(s[0]instanceof he)||(i=s[0].name,s.length===2&&(n=Zw(s[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(t=e.values[1])!=null?t:null}}function Hp(e,t){return!!e[Do(t)]}function un(e,t){return Object.keys(t).some(i=>Hp(e,i))}function Kw(e,t,i){switch(e.kind){case"string":return!!(t&go);case"url":return!!(t&(mo|vo));case"unit":return Hp(i,e.unit);case"syntax":switch(e.syntax){case"<string>":return!!(t&go);case"<url>":return!!(t&(mo|vo));case"<color>":return!!(t&Ln);case"<integer>":return!!(t&($n|Zi|ni|ri));case"<number>":return!!(t&(Zi|$n|ni|ri));case"<length>":return un(i,_o);case"<length-percentage>":return un(i,$p);case"<percentage>":return un(i,Mo);case"<angle>":return un(i,jl);case"<time>":return un(i,Xl);case"<frequency>":return un(i,ql);default:return!1}}return!1}function Ya(e){switch(e.kind){case"string":return null;case"url":return null;case"unit":return new ue(zi,ee,{[Do(e.unit)]:Be});case"syntax":switch(e.syntax){case"<color>":return new ue(Ln,ee,ee);case"<integer>":return new ue(qw,ee,ee);case"<number>":return new ue(Xw,ee,ee);case"<length>":return new ue(zi,ee,_o);case"<length-percentage>":return new ue(zi,ee,$p);case"<percentage>":return new ue(zi,ee,Mo);case"<angle>":return new ue(zi,ee,jl);case"<time>":return new ue(zi,ee,Xl);case"<frequency>":return new ue(zi,ee,ql);default:return null}}return null}function Jw(e){switch(e.kind){case"string":case"url":case"unit":return!0;case"syntax":return e.syntax==="<string>"||e.syntax==="<url>"||!!Ya(e)}return!1}function Qw(e){switch(e.kind){case"url":return new it("about:invalid");case"string":return new Z("");default:return v.unset}}function eb(e,t,i){if(t==null)return null;switch(i.kind){case"string":return new Z(t);case"url":return t?new it(t):new it("about:invalid");case"unit":{let n=Ri(e,new bt(`${t.trim()}${Do(i.unit)}`,null),""),r=Ya(i);return n&&r?n.visit(r):null}case"syntax":{if(i.syntax==="<string>")return new Z(t);if(i.syntax==="<url>")return t?new it(t):new it("about:invalid");let n=Ri(e,new bt(t,null),""),r=Ya(i);return n&&r?n.visit(r):null}}return null}var gu=new ue(0,ee,ee),Zl=class extends Gl{constructor(e){super(),d(this,"successTerminal"),d(this,"failureTerminal"),d(this,"first"),this.successTerminal=new Tn(null),this.failureTerminal=new Tn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,s=i,o=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(s>=e.length){r=r.failure;continue}let h=e[s],l=h;if(r.isSpecial()){let u=!0;r.isStartGroup()?(o?o.push(a):o=[a],a=[]):r.isEndGroup()?o.length>0?a=o.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(s==0&&!t&&r.validator instanceof xr&&this instanceof xr){if(l=new J(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof Kl&&this instanceof xr){if(l=new _e(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<s;u++)n[u]=e[u]}e!==n&&(n[s-i]=l),s++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:s==e.length)?n:null}validateSingle(e){let t=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}},xr=class extends Zl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new J(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Kl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new _e(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Kl=class extends Zl{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new _e(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}},tb=class extends Zl{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ai(e.name,t):null}},mu=class extends Gl{validateSingle(e){return null}visitFunc(e){let t=Yl(e);return t&&Jw(t.type)?e:null}},Up=class{tryParse(e,t,i){return t}success(e,t){}},Wp=class extends Up{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,s=r>1?new J(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},ib=class extends Wp{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}},nb=class extends Up{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Gn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let s=1;s<this.nodes.length&&t<e.length&&(r=this.nodes[s].tryParse(e,t,i),r!=t);s++)t=r;return t}},zo=class extends Zt{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 Wp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},jn=class extends zo{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}},Gp=class extends zo{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 ib(this.validatorSet,this.propList)}},rb=class extends zo{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Gn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let s=[e[n],e[r]];if(this.syntax[i].tryParse(s,0,this)!=2)return this.error=!0,0}return e.length}},sb=class extends jn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let s=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,o=e[r];o||(o=[],e[r]=o),o.push(s)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof _e?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 _e(t[i]);return null}},ob=class extends jn{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 o=this.values["font-weight"],a=o instanceof ai&&o.name==="calc"?e.indexOf(o):-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]===Gn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let s=t==e.length-1?e[t]:new J(e.slice(t,e.length));return s.visit(r["font-family"])?(this.values["font-family"]=s,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new _e(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}},ab=class extends jn{validateList(e){if(e.length===1&&e[0]instanceof he)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[M("no-autospace"),M("space-all")];break}return super.validateList(e)}},lb=class extends zo{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=Ri(this.validatorSet.scope,new bt(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 J(e).toString();return this.validateValueText(t)?e.length:0}visitCommaList(e){return this.validateValueText(e.toString()),null}},yu=["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"],jp=class extends jn{constructor(){super()}refreshPropList(){this.propList=this.validatorSet.getPropertiesForAll()}init(e,t){super.init(e,t)}validateList(e){return this.error=!0,0}},vu={SIMPLE:jn,INSETS:Gp,INSETS_SLASH:rb,COMMA:sb,FONT:ob,TEXT_SPACING:ab,ALL:jp},hb=["initial-letter"],ub=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 Js(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||Xe(r)||yu.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)yu.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},(s,o)=>i.item(o)).filter(s=>!!s);if(!n.length||n.length===1&&n[0]===e.toLowerCase())return null;let r={};for(let s of n)r[s]=i.getPropertyValue(s);return{propList:n,values:r}}getShorthand(e,t){if(Xe(e))return null;let i=this.shorthands[e];if(i)return i instanceof jp&&!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):!wu(t))&&(this.browserShorthandMisses[e]=!0),null;let r=new lb(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 L(t.num,t.text);else if(t.type==7)i=new Uc(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 nr;if(e=="||"){for(let r=0;r<t.length;r++){let s=new nr;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new nr;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 nr;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 nr;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Kl(t);break;case"SPACE":i=new xr(t);break;case"attr":i=new mu;break;default:i=new tb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ue(Ln,ee,ee)),this.namedValidators.ATTR=this.primitive(new mu),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ue(vo,ee,ee)),this.namedValidators.POS_INT=this.primitive(new ue($n,ee,ee)),this.namedValidators.POS_NUM=this.primitive(new ue(Zi,ee,ee)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ue(Si,ee,Mo)),this.namedValidators.NEGATIVE=this.primitive(new ue(ni,ee,ee)),this.namedValidators.ZERO=this.primitive(new ue(ri,ee,ee)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ue(yo,ee,ee)),this.namedValidators.POS_LENGTH=this.primitive(new ue(Si,ee,_o)),this.namedValidators.POS_ANGLE=this.primitive(new ue(Si,ee,jl)),this.namedValidators.POS_TIME=this.primitive(new ue(Si,ee,Xl)),this.namedValidators.FREQUENCY=this.primitive(new ue(Si,ee,ql)),this.namedValidators.RESOLUTION=this.primitive(new ue(Si,ee,{dpi:Be,dpcm:Be,dppx:Be})),this.namedValidators.URI=this.primitive(new ue(mo,ee,ee)),this.namedValidators.URANGE=this.primitive(new ue(zp,ee,ee)),this.namedValidators.IDENT=this.primitive(new ue(_p,ee,ee)),this.namedValidators.STRING=this.primitive(new ue(go,ee,ee)),this.namedValidators.SLASH=this.primitive(new ue(Dp,ee,ee));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="",s,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=u=>{if(o)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,o=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(o||h(" "),this.isBuiltIn(u.text)){let 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 ue(0,c,ee)))}o=!1;break;case 5:{let c={};c[`${u.num}`]=new lt(u.num),i.push(this.primitive(new ue(0,c,ee))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],o=!0;break;case 15:{s=a();let c=n.pop();if(c.b!="[")throw new Error("']' unexpected");i=c.vals,i.push(s),r=c.op,o=!1;break}case 11:{s=a();let c=n.pop();if(c.b!="(")throw new Error("')' unexpected");i=c.vals,i.push(this.newFunc(c.fn,s)),r=c.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let 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 xr(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 Tt(n.num));break;case 5:i.push(new lt(n.num));break;case 3:i.push(new L(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new J(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&vu[i.text]?(n=new vu[i.text],e.consume()):n=new jn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])s.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Gp){let l=this.shorthands[i.text];s.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(s.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:s}),s=[],o=!1;break;case 15:{let l=new nb(s,o),u=a.pop();s=u.syntax,o=u.slash,s.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,h),this.shorthands[t]=n,this.invalidateAllPropertyNames()}}parse(e){let t=new bt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],s=r?r.propList:[n];for(let o of s)i[o]=(t=this.defaultValues[o])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){var r,s;let o=n.ruleType;if(Xe(e)||o==="font-face"){n.simpleProperty(e,t,i);return}if(o==="counter-style"){Mw(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(wu(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?Y(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t)):n.simpleProperty(h,t,i)}else a&&!wc.includes(`-${a}-`)||n.unknownProperty(h,t);return}else if(hb.includes(e)&&!Object.keys(c).some(f=>Is(f?`-${f}-`:"",e))){n.unknownProperty(h,t);return}let p=this.validators[e];if(p){let f=Y(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=(s=this.getShorthand(e,t))==null?void 0:s.clone();if(!f){n.unknownProperty(h,t);return}Y(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t))}}};function Xp(){let e=new ub;return e.initBuiltInValidators(),e.parse(xd),e}var cb=class extends Zt{constructor(){super(...arguments),d(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function wu(e){let t=new cb;return e.visit(t),t.varFound}function qp(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var db=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},pb=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Yp=class Us{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Us.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Us.fragmentIndices={}}matches(){let t=Us.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&qp(t.fragmentIndex,this.a,this.b)}};d(Yp,"fragmentIndices",{});var Vo=Yp,Cs=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Vo(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new pb(e)}static buildAnyMatcher(e){return new db(e)}},Zp={"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},fb=["image-resolution","orphans","widows"];function gb(){return Gt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(fb))}var mb={"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},Za=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],yb=["max-%","min-%","%"],bu=(()=>{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<Za.length;i++)for(let n=0;n<e.length;n++){let r=Za[i].replace("%",e[n]);t[r]=!0}return t})();function Xn(e,t){let i={};for(let n of Za)for(let r in e){let s=n.replace("%",r),o=n.replace("%",e[r]);i[s]=o,i[o]=s}for(let n of yb)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var Kp=Xn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Jp=Xn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),vb=Xn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),wb=Xn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),bb=Xn({inside:"right",outside:"left"},{}),xb=Xn({inside:"left",outside:"right"},{}),U=class Ka{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 Ka(i,this.priority)}increaseSpecificity(t){return t==0?this:new Ka(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Xe(i)?this.value:xo(t,this.value,i,n,r)}isEnabled(t){return!0}},Ja=class Qa extends U{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new U(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Qa(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Qa(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){q.warn(i)}return!1}};function el(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Kt(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 Qp={"region-id":!0,"fragment-selector-id":!0},Sr="data-viv-footnote-counter";function wo(e){let t=e.getAttribute(Sr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,s])=>{if(Array.isArray(s)){let o=s.filter(a=>typeof a=="number"&&isFinite(a));n[r]=o}else typeof s=="number"&&isFinite(s)&&(n[r]=[s])}),n}function ef(e,t,i){let n=wo(e);n[t]=i,e.setAttribute(Sr,JSON.stringify(n))}function Sb(e,t){var i,n;if(!Wt(e)||e.hasAttribute(lp))return null;let r=wo(e)[t];if(r)return r;let s=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!s)return null;let o=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=Zs(s,o);if(a==="#"||a.replace(/#.*$/,"")!==o.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=wo(l)[t];return u?(ef(e,t,u),u):null}function Cb(e){let t=ve(e,"content");return!!t&&It(t.value)}function kb(e){return!!Qp[e]}function Ws(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Xi(e){return e.charAt(0)!=="_"&&!Qp[e]}function In(e){return!!Zp[e]||Xe(e)}function ve(e,t){return e[t]}function Fi(e,t,i){i?e[t]=i:delete e[t]}function pt(e,t){return e[t]}function oi(e,t){let i=e[t];return i||(i={},e[t]=i),i}var tf=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function nf(e,t){return e[t]}function rf(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function bo(e,t,i,n,r,s,o){var a,h;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=oi(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),o){let l=tf(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!Ws(l))if(kb(l)){let u=nf(i,l),c=rf(t,l);Array.prototype.push.apply(c,u)}else{let u=ve(i,l);if(!u.isEnabled(e))continue;let c=u.increaseSpecificity(n);Kt(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 y=new U(Be,c.priority);Kt(t,g,y,e)}}}function Eb(e,t){let i={};for(let n=0;n<t.length;n++)bo(e,i,t[n],0,null,null,null);return i}function Jl(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 Pb=class extends nn{constructor(e,t){super(),this.props=e,this.context=t,d(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ve(this.props,"font-size");if(!e.value.isNumeric())return Yt.em;let t=e.value;if(!lm(t.unit))throw new Error("Unexpected state");return t.num*Yt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?tl(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Ql(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?xo(this.context,e,this.propName).visit(this):e}};function Ql(e,t,i){let n=e.unit,r=e.num;return n==="em"?new L(r*t,"px"):n==="rem"?new L(r*i.fontSize(),"px"):n==="rlh"?new L(r*i.rootLineHeight,"px"):e}function tl(e,t,i){e=Ql(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new L(r/100*t,"px"):new L(r*i.queryUnitSize(n,!1),"px")}var qn=class{apply(e){}mergeWith(e){return new Nb([this,e])}clone(){return this}},ks=class extends qn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Nb=class sf extends qn{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 sf([].concat(this.list))}},eh=class extends qn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){bo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Pe=class extends qn{constructor(){super(),d(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Tb=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}},Ib=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}},xu=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}},Ab=class extends Pe{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},Fb=class extends Pe{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Rb=class extends Pe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function $o(e,t,i,n){var r;if(!e)return!1;let s=((r=e.ownerDocument)==null?void 0:r.contentType)==="text/html",o=s?Lr(i):i;if(t!==null){let a=e.getAttributeNodeNS(t||null,o);return!!a&&n(a)}for(let a of Array.from(e.attributes))if((s?Lr(a.localName):a.localName)===o&&n(a))return!0;return!1}function Lr(e){return e.replace(/[A-Z]/g,t=>t.toLowerCase())}function of(e){return e==="i"}function rr(e,t){return Array.from(e,i=>{let n=Ks(i);if(!of(t))return n;let r=Lr(i),s=r.toUpperCase();return r!==s&&/^[a-z]$/i.test(i)?`[${r}${s}]`:n}).join("")}function sr(e){return new RegExp(e)}function Lb(e,t,i){return of(i)?Lr(e)===Lr(t):e===t}var Su=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){$o(e.currentElement,this.ns,this.name,()=>!0)&&this.chained.apply(e)}},Ob=class extends Pe{constructor(e,t,i,n=null){super(),this.ns=e,this.name=t,this.value=i,this.caseSensitivity=n}apply(e){$o(e.currentElement,this.ns,this.name,t=>Lb(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}},Bb=class extends Pe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){$o(e.currentElement,this.ns,this.name,t=>!!mb[t.value])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},or=class extends Pe{constructor(e,t,i,n=null){super(),this.ns=e,this.name=t,this.regexp=i,this.caseSensitivity=n}apply(e){$o(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)}},Cu=class extends Pe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},_b=class extends Pe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},on=class extends Pe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return qp(e,this.a,this.b)}},Db=class extends on{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},il=class extends on{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}},nl=class extends on{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}},rl=class extends on{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,s=t[n];s||(s=t[n]={}),s[r]=(s[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},zb=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}},Vb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},$b=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Hb=class extends Pe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},rt=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}},af=class lf extends qn{constructor(){super(),d(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new lf;return t.applied=this.applied,t}},th=class extends Pe{constructor(e){super(),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new af;for(let t of e)this.firstActions.push(Jl(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}},Ub=class extends th{positive(){return!1}},Wb=class extends th{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}},hf=class extends on{constructor(e,t,i){super(e,t),d(this,"checkAppliedAction"),d(this,"firstActions",[]),this.checkAppliedAction=new af;for(let n of i)this.firstActions.push(Jl(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,s=t.currentId,o=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let 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=s,t.currentClassNames=o,t.currentSiblingOrder=a,u}getPriority(){return 5}},Gb=class extends hf{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}},Ho=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)}},jb=class uf extends Ho{constructor(t,i,n){super(t,i,n)}fresh(t){return new uf(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}},Xb=class cf extends Ho{constructor(t,i,n){super(t,i,n)}fresh(t){return new cf(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)}},qb=class df extends Ho{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new df(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)}},Yb=class pf extends Ho{constructor(t,i,n){super(t,i,n),d(this,"fired",!1)}fresh(t){return new pf(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}},Zb=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}},Kb=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}},Jb=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}},Qb=class extends nn{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(Y(e))return e;let n=(t=this.validatorSet)==null?void 0:t.validators[this.propName];return n?(i=e.visit(n))!=null?i:v.unset:!this.propName||CSS.supports(this.propName,e.toString())?e:v.unset}visitFunc(e){var t;if(e.name.toLowerCase()!=="attr")return super.visitFunc(e);this.hadAttrFunction=!0;let i=Yl(e);if(!i)return super.visitFunc(e);let n=((t=i.fallback)!=null?t:Qw(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:eb(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function Or(e,t){if(It(e)){if(e instanceof Z)return e.stringValue();if(e instanceof j&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof J)return e.values.map(i=>Or(i,t)).join("")}return""}function ih(e){if(e instanceof j){let t=e.expr;return t instanceof we&&/^page-counters?-/.test(t.str)}return e instanceof J||e instanceof _e?e.values.some(t=>ih(t)):!1}function sl(e,t){return ih(e)?e instanceof J?new J(e.values.map(i=>sl(i,t))):e instanceof _e?new _e(e.values.map(i=>sl(i,t))):e:new Z(Or(e,t))}var Br=class extends nn{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}hasLocalCounterResetOrSet(e){return this.hasLocalCounter(e,"counter-reset",{reset:!0})||this.hasLocalCounter(e,"counter-set",{defaultValue:0})}hasLocalCounterIncrement(e){return this.hasLocalCounter(e,"counter-increment",{})}hasLocalCounter(e,t,i){let n=this.cascade.currentStyle,r=n?.[t];if(!r)return!1;let s=r.evaluate(this.cascade.context);if(!s||Y(s))return!1;let o=qi(s,i);return Object.prototype.hasOwnProperty.call(o,e)}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Or(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 Z("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Z("")}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 gi;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,s=!1,o=!1){var a,h,l,u,c,p,f,g,y;let b=typeof r=="string",x=F=>b?this.formatCounterList(F,r,i):this.formatLastValue(F,i),m=F=>{this.pseudoName==="footnote-call"&&this.element&&ef(this.element,t,F)},w=(F,z)=>F.length===z.length&&F.every(($,X)=>$===z[X]);if(this.pseudoName==="footnote-call"&&this.element){let F=Sb(this.element,t);if(F)return x(F)}if(this.pseudoName==="footnote-marker"&&this.element){let F=wo(this.element)[t];if(F)return x(F)}let S;if(t==="pages")return x([]);if(!this.element){if(s&&n.length)return S=n,m(S),x(S);if((a=e.isPageControlledCounter)!=null&&a.call(e,t)&&o&&n.length){let F=((h=e.currentPageCounters)==null?void 0:h[t])||[];return S=[(F.length?F[F.length-1]:0)+n[n.length-1]],m(S),x(S)}if(!((l=e.isPageControlledCounter)!=null&&l.call(e,t))){let F=((u=e.currentPageCounters)==null?void 0:u[t])||[];if(F.length)return S=F,m(S),x(S)}}let C=((c=e.currentPageDocCounters)==null?void 0:c[t])||[],T=!this.element&&n.length&&!w(n,C),R=this.element||T?n:C.length?C:n;if((p=e.isPageControlledCounter)!=null&&p.call(e,t)){let F=((f=e.currentPageDocCounters)==null?void 0:f[t])||[],z=((g=e.currentPageCounters)==null?void 0:g[t])||[],$=z.length?z[z.length-1]:0,X=F.length?F[0]:0,re=R.length?R[0]:0,k=$+(re-X);return S=R.length?[k,...R.slice(1)]:z.length?z:[0],m(S),x(S)}return R.length?(S=R,m(S),x(S)):(S=((y=e.currentPageCounters)==null?void 0:y[t])||[],m(S),x(S))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),s=!this.element&&this.hasLocalCounterResetOrSet(i),o=!this.element&&this.hasLocalCounterIncrement(i),a=this.getCounterStore();if(a){let l=i==="pages"||((t=a?.isPageControlledCounter)==null?void 0:t.call(a,i)),u=this.getPageScope(),c=new we(u,()=>this.buildCounterText(a,i,n,r,void 0,s,o),l?`page-counter-${i}`:`counter-${i}`);if(l&&a!=null&&a.registerPageCounterExpr){let p=f=>this.formatLastValue(f,n);a.registerPageCounterExpr(i,p,c)}return new j(c)}let h=this.cascade.counters[i];if(h&&h.length){let l=h&&h.length&&h[h.length-1]||0;return new Z(this.format(l,n))}else{let l=new j(this.counterResolver.getPageCounterVal(i,u=>this.format(u||0,n)));return new J([l])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",s=(this.cascade.counters[i]||[]).slice(),o=!this.element&&this.hasLocalCounterResetOrSet(i),a=!this.element&&this.hasLocalCounterIncrement(i),h=this.getCounterStore();if(h){let p=i==="pages"||((t=h?.isPageControlledCounter)==null?void 0:t.call(h,i)),f=this.getPageScope(),g=new we(f,()=>this.buildCounterText(h,i,r,s,n,o,a),p?`page-counters-${i}`:`counters-${i}`);return p&&h!=null&&h.registerPageCounterExpr&&h.registerPageCounterExpr(i,y=>this.formatCounterList(y,n,r),g),new j(g)}let l=this.cascade.counters[i],u=new gi;if(l&&l.length)for(let p=0;p<l.length;p++)p>0&&u.append(n),u.append(this.format(l[p],r));let c=new j(this.counterResolver.getPageCountersVal(i,p=>{let f=[];if(p.length)for(let y=0;y<p.length;y++)f.push(this.format(p[y],r));let g=u.toString();return g.length&&f.push(g),f.length?f.join(n):this.format(0,r)}));return new J([c])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof it?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new j(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new J([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof it?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),s=e.length>3?e[3].stringValue():"decimal",o=new j(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,s));return h.length?h.join(r):this.format(0,s)}));return new J([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof it?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new j(this.counterResolver.getTargetTextVal(i,n));return new J([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new j(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 j(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let 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 y=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=Or(y,this.cascade.context)}}}break;case"first-letter":{let c=pt(this.cascade.currentStyle,"_pseudos"),p=(o=(s=c?.before)==null?void 0:s.content)==null?void 0:o.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(Ys);u=g?g[0]:""}break}return new Z(u)}visitFuncLeader(e){let t="";if(e[0]instanceof he)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Z&&(t=e[0].stringValue());return t.length==0?new Z(""):new j(new we(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 ca(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,s)=>r+(i==="vertical-rl"||i==="vertical-lr"?s.height:s.width),0)}var e0=(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){w==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},u=function(){let P=i.clientLayout.getElementClientRect(y);return m==="vertical-rl"||m==="vertical-lr"?w==="rtl"?P.top-=k:P.bottom+=k:w==="rtl"?P.left-=k:P.right+=k,R.left>P.left||R.right<P.right||R.top>P.top||R.bottom<P.bottom},c=function(){let P,N,O=x.repeat(1e4);if(l(O),u())P=1,N=1e4;else return;for(let V=0;V<16;V++){let W="",K=Math.floor((P+N)/2);for(let te=0;te<K;te++)W+=x;if(l(W),u())N=K;else{if(P==K)return;P=K}}l(x)},p=function(P){let N=0,O=y.parentElement;for(;O&&O!==f.viewNode;)N+=i.getComputedInsets(O)[P],O=O.parentElement;return N};var r=l,s=u,o=c,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,y=g.parentElement,b=y.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:m,direction:w,marginInlineEnd:S}=i.clientLayout.getElementComputedStyle(y);g.style.marginInlineStart="1px",l(x),y.style.display="inline-block",y.style.textIndent="0";let C=Kr(f.viewNode),T=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let R=i.clientLayout.getElementClientRect(f.viewNode),F=i.clientLayout.getElementClientRect(y),z=i.parseComputedLength(S),$=[],X=y.parentElement;for(;X.parentElement&&X.parentElement!==f.viewNode;)X=X.parentElement;let re=X.nextSibling;for(;re;){if(re.nodeType===1){let P=re,{display:N,float:O,position:V}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||V==="absolute"||V==="fixed"){re=re.nextSibling;continue}if(Dt(N))$.push(P);else if(hv(N))break}else if(re.nodeType===3){let P=re;P.length>0&&$.push(P)}re=re.nextSibling}let k=$.reduce((P,N)=>P+ca(N,i.clientLayout,m),0);if(b!=="after"){let P=ca(X,i.clientLayout,m),N=ca(y,i.clientLayout,m);k+=P-N}m==="vertical-rl"||m==="vertical-lr"?(w==="rtl"?R.top+=z:R.bottom-=z,R.top=Math.min(F.top,R.top),R.bottom=Math.max(F.bottom,R.bottom)):(w==="rtl"?R.left+=z:R.right-=z,R.left=Math.min(F.left,R.left),R.right=Math.max(F.right,R.right)),c();let _=i.clientLayout.getElementClientRect(y);w=="rtl"?y.style.float="left":y.style.float="right";let E=i.clientLayout.getElementClientRect(y),B=0;w=="rtl"?m=="vertical-rl"||m=="vertical-lr"?B=_.top-E.top-p("top"):B=_.left-E.left-p("left"):m=="vertical-rl"||m=="vertical-lr"?B=E.bottom-_.bottom-p("bottom"):B=E.right-_.right-p("right"),B-=k,B=Math.max(0,B-.1),y.style.float="",g.style.marginInlineStart=`${B}px`,C&&(T?C.style.columnFill=T:C.style.removeProperty("column-fill"))}};Ot("POST_LAYOUT_BLOCK",e0);var nh=1/1048576;function cn(e,t){for(let i in e)t[i]=e[i].clone()}var t0=class ff{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 ff;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return cn(this.tags,t.tags),cn(this.nstags,t.nstags),cn(this.epubtypes,t.epubtypes),cn(this.classes,t.classes),cn(this.ids,t.ids),cn(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,s,o){return new i0(this,t,i,n,r,s,o)}nextOrder(){return this.order+=nh}},gf=class mf{constructor(t,i,n,r,s,o,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=o,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 Z("\u201C"),new Z("\u201D"),new Z("\u2018"),new Z("\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=Cs.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let s=this.viewConditions[r];return s&&s.length>0?s.length===1?s[0]:Cs.buildAnyMatcher([].concat(s)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Cs.buildAllMatcher(n):Cs.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=da,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,s,o,a,h,l,u,c;let p=new Set,f=Object.create(null),g=v.inline,y=t.display;if(y&&(g=y.evaluate(this.context)),g===v.none){(i=this.currentElement)==null||i.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if((n=this.currentElement)!=null&&n.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let b=v.inline,x=t.float;x&&(b=x.evaluate(this.context));let m=null,w=null,S=null,C=t["counter-reset"];if(C){let F=C.evaluate(this.context);F&&(m=qi(F,{reset:!0}))}let T=t["counter-set"];if(T){let F=T.evaluate(this.context);F&&(S=qi(F,{defaultValue:0}))}let R=t["counter-increment"];if(R){let F=R.evaluate(this.context);F&&(w=qi(F))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((s=(r=this.currentElement)==null?void 0:r.start)!=null?s:1)-1),hr(g)&&(w||(w=Object.create(null)),w["list-item"]=(o=w["list-item"])!=null?o:1,/^\s*[-+]?\d/.test((h=(a=this.currentElement)==null?void 0:a.getAttribute("value"))!=null?h:"")&&(S||(S=Object.create(null)),S["list-item"]=this.currentElement.value)),((u=(l=this.currentElement)==null?void 0:l.parentNode)==null?void 0:u.nodeType)===Node.DOCUMENT_NODE&&(m||(m=Object.create(null)),m.footnote===void 0&&(m.footnote=0)),b===v.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(w||(w=Object.create(null)),w.footnote===void 0)){let F=(c=this.currentStyle["counter-increment"])==null?void 0:c.value;(!F||!(F===v.footnote||F instanceof J&&F.values.includes(v.footnote)))&&(w.footnote=1)}if(m)for(let F in m)p.add(F),f[F]="reset";if(w)for(let F in w)p.add(F),f[F]||(f[F]="increment");if(S)for(let F in S)p.add(F),f[F]="set";if(this.lastCounterChanges=Array.from(p),this.lastCounterChangeTypes=f,m)for(let F in m)this.defineCounter(F,m[F]);if(w)for(let F in w){this.counters[F]||this.defineCounter(F,0);let z=this.counters[F];z[z.length-1]+=w[F]}if(S)for(let F in S)if(!this.counters[F])this.defineCounter(F,S[F]);else{let z=this.counters[F];z[z.length-1]=S[F]}if(hr(g)){let F=this.counters["list-item"],z=F[F.length-1];t["ua-list-item-count"]=new U(new Tt(z),0);let $=oi(t,"_pseudos");$.marker||($.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 Br(this,this.currentElement,this.counterResolver));let n=i.value instanceof _e?i.value.values:[i.value];for(let r of n)if(r instanceof J){let s=r.values[0].stringValue(),o=r.values.slice(1);if(o.some(a=>ih(a)))this.counterResolver.setNamedString(s,sl(new J(o),this.context),this.currentElementOffset);else{let a=o.map(h=>Or(h,this.context)).join("");this.counterResolver.setNamedString(s,a,this.currentElementOffset)}}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof ai&&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 Br(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var s,o,a;let h=this.currentPageType;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let l=this.code.nsPrefix[this.currentNamespace];l?this.currentNSTag=l+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let u=i.getAttribute("class");u?this.currentClassNames=u.split(/\s+/):this.currentClassNames=da;let c=i.getAttributeNS("http://www.idpf.org/2007/ops","type");c?this.currentEpubTypes=c.split(/\s+/):this.currentEpubTypes=da;let p=wa(i);p&&(this.stack[this.stack.length-1].push(new Kb(this.lang)),this.lang=p.toLowerCase());let f=this.isRoot,g=this.siblingOrderStack;this.currentSiblingOrder=++g[g.length-1],g.push(0);let y=this.siblingTypeCountsStack,b=this.currentSiblingTypeCounts=y[y.length-1],x=b[this.currentNamespace];x||(x=b[this.currentNamespace]={}),x[this.currentLocalName]=(x[this.currentLocalName]||0)+1,y.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let w=this.followingSiblingTypeCountsStack,S=this.currentFollowingSiblingTypeCounts=w[w.length-1];S&&S[this.currentNamespace]&&S[this.currentNamespace][this.currentLocalName]--,w.push({}),this.applyActions(),this.currentPageType=h,this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i,t);let C=n.quotes,T=null;if(C){let z=C.evaluate(this.context);z&&(T=new Jb(this.quotes),z===v.none?this.quotes=[new Z(""),new Z("")]:z===v.auto||z===v.initial?this.quotes=[new Z("\u201C"),new Z("\u201D"),new Z("\u2018"),new Z("\u2019")]:z instanceof J&&(this.quotes=z.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(f||R){let z=Object.create(null);Object.keys(this.counters).forEach($=>{z[$]=Array.from(this.counters[$])}),this.counterListener.countersOfId(R,z)}let F=pt(this.currentStyle,"_pseudos");if(F){let z=!0;for(let $ of n0){$||(z=!1);let X=F[$];if(X){let re=(s=ve(this.currentStyle,"float"))==null?void 0:s.value,k=i instanceof Element&&Wt(i),_=i instanceof Element&&Et(i),E=!!ve(this.currentStyle,"--viv-semantic-footnote-content"),B=re===v.footnote,P=($==="before"||$==="after")&&(B||_||E)&&!!X.content,N=Cb(X),O=$==="footnote-call"&&k&&N,V=$==="footnote-marker"&&(_||E)&&N;if(($==="before"||$==="after")&&!(P||It((o=X.content)==null?void 0:o.value)||this.hasNonTrivialViewConditionalPseudoContent(X))||$==="marker"&&!hr((a=ve(this.currentStyle,"display"))==null?void 0:a.value)||($==="footnote-call"||$==="footnote-marker")&&re!==v.footnote&&!O&&!V||($==="footnote-call"||$==="footnote-marker")&&E&&!N)delete F[$];else if(z){if(this.processPseudoelementProps(X,i,$),$==="marker")this.processMarkerPseudoelementProps(X,i,t),delete F[$];else if($==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(X,"list-style-position",t,i)===v.outside){this.processMarkerPseudoelementProps(X,i,t);let W=X.content;W&&(this.currentStyle["_footnote-marker-content"]=W),this.currentStyle.display=new U(M("list-item"),0),this.currentStyle["list-style-position"]=new U(v.outside,0),this.currentStyle["list-style-type"]=new U(v.none,0),this.currentStyle["list-style-image"]=new U(v.none,0),delete F[$]}}else if($==="first-letter"&&X["initial-letter"]){let W=X["initial-letter"].evaluate(this.context);W!==v.normal&&!Y(W)&&(this.currentStyle["--viv-initialLetter"]=new U(W,0)),delete X["initial-letter"]}}else this.stack[this.stack.length-2].push(new Zb(X,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),T&&this.stack[this.stack.length-2].push(T)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return It((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,s,o,a,h;let l=hr((r=this.currentStyle.display)==null?void 0:r.value);if(!It((s=t.content)==null?void 0:s.value)&&l){let c=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof it)t.content=new U(new J([p,new Z(" ")]),0);else if(c instanceof Z)t.content=new U(c,0);else if(c instanceof he&&c!==v.none){let f=(a=(o=this.currentStyle["ua-list-item-count"])==null?void 0:o.value)==null?void 0:a.num;if(f!=null){let g=c.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new U(new Z(this.counterStyleStore.formatMarker(c.name,f)),0))}}}let u=t.content;if(u){let c=u.value;if(It(c)){let p=this.resolveMarkerContentVal(c);this.currentStyle["--viv-marker-content"]=new U(p,0)}}for(let c of mf.markerAllowedProps){let p=t[c];if(p){let f=p.evaluate(this.context,c);f&&!Y(f)&&(this.currentStyle[`--viv-marker-${c}`]=new U(f,0))}}if(!Dt((h=ve(this.currentStyle,"display"))==null?void 0:h.value)){let c=this.getInheritedPropertyValue("list-style-position",n,i);c&&c!==v.outside&&!Y(c)&&(this.currentStyle["list-style-position"]=new U(c,0))}}resolveMarkerContentVal(t){if(t instanceof j){let i=t.expr.evaluate(this.context);return typeof i=="string"?new Z(i):typeof i=="number"?new Z(String(i)):t}if(t instanceof J){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new J(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let o=n;o;o=o.parentElement){let a=(o===this.currentElement?this.currentStyle:i.getStyle(o,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let s=i.validatorSet;return(r=s?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var s;let o=t[i];if(o){let a=o.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(s=h?.defaultValues[i])!=null?s:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i,n){let r=t.scope,s=t.validatorSet;for(let o in n)if(Xi(o)&&!Xe(o)){let a=n[o],h=new Qb(i,r,o,s),l=a.filterValue(h);if(!h.hadAttrFunction){n[o]=l;continue}let u=h.validatePropertyValue(l.value);n[o]=u===l.value?l:new U(u,l.priority)}}applyAttrFilter(t,i){let n=this.currentStyle,r=pt(n,"_pseudos");for(let s in r)this.applyAttrFilterInner(i,t,r[s]);this.applyAttrFilterInner(i,t,n)}applyVarFilter(t,i,n){let r=t[0],s=t.map(c=>({...c})),o=32,a={},h=pt(r,"_pseudos"),l=Object.keys(r).filter(Xi),u=c=>{var p,f,g;let y=ve(r,c),b=y.value,x=Xe(c)?s:t,m=new p0(x,i,n,Xe(c)?c:null);Xe(c)&&m.getFallbackCycleMembers(b,x,n)&&(b=v.initial);for(let w=0;;w++){if(w>=o){b=Xe(c)?v.initial:Be;break}let S=b.visit(m);if(m.error){b=Xe(c)?v.initial:Be,m.error=!1;break}if(S===b)break;b=S}if(b!==y.value){let w=i.validatorSet,S=(p=w?.getShorthand(c,b))==null?void 0:p.clone();if(S)if(Y(b)){for(let C of S.propList){let T=new U(b,y.priority),R=ve(r,C);Fi(a,C,el(this.context,R,T))}delete r[c]}else{let C=Ri(i.scope,new bt(b.toString(),null),"");if(C&&(C.visit(S),!S.error)){for(let T of S.propList){let R=new U((g=(f=S.values[T])!=null?f:w.defaultValues[T])!=null?g:v.initial,y.priority),F=ve(r,T);Fi(a,T,el(this.context,F,R))}delete r[c]}}else r[c]=new U(b,y.priority)}if(a[c]){let w=ve(r,c);w&&w.value!==Be&&Kt(a,c,w,this.context)}};for(let c in r)if(Ws(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)Xe(c)&&u(c);for(let c of l)Xe(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 Ef(i);for(let r in t)if(Ws(r)){let s=pt(t,r);for(let o in s)this.applyCalcFilter(s[o],i)}else if(Xi(r)&&!Xe(r)){let s=ve(t,r),o=s.value.visit(n);o!==s.value&&(t[r]=new U(o,s.priority))}}applyCmykFilter(t,i){let n=new Jc(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(Ws(r)){let s=pt(t,r);for(let o in s)this.applyCmykFilterInternal(s[o],i,`::${o}:`)}else if(Xi(r)&&!Xe(r)){let s=ve(t,r),o=s.value.toString();i.reset();let a=s.value.visit(i);a!==s.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,o),t[r]=new U(a,s.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};d(gf,"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 i0=gf,da=[],n0=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ol=null;function r0(e){ol=e}var Mr=class extends sn{constructor(e,t,i,n,r,s,o){super(e,t,o),this.condition=i,this.regionId=r,this.validatorSet=s,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:ol?ol.clone():new t0,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Jl(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 Ab(e,t.toLowerCase())):t?this.chain.push(new xu(t.toLowerCase())):this.chain.push(new Rb(e)))}invalidSelector(e){q.warn(e),this.chain.push(new rt("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Hn;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new Tb(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Vb);break;case"disabled":this.chain.push(new $b);break;case"checked":this.chain.push(new Hb);break;case"root":case"scope":this.chain.push(new _b);break;case"link":this.chain.push(new xu("a")),this.chain.push(new Su("","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)${Ks(i)}($|\\s)`),r=t[1];this.chain.push(new Fb(n,r,e==="href-role-type"))}else this.chain.push(new rt(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new rt(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Mb(new RegExp(`^${Ks(i.toLowerCase())}($|-)`)))}else this.chain.push(new rt(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=s0[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new rt(""));break}case"first-child":this.chain.push(new Cu);break;case"last-child":this.chain.push(new nl(0,1));break;case"first-of-type":this.chain.push(new il(0,1));break;case"last-of-type":this.chain.push(new rl(0,1));break;case"only-child":this.chain.push(new Cu),this.chain.push(new nl(0,1));break;case"only-of-type":this.chain.push(new il(0,1)),this.chain.push(new rl(0,1));break;case"empty":this.chain.push(new zb);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 rt(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new rt(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new Ib(e)))}attributeSelector(e,t,i,n,r){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,n=n||"";let s;switch(i){case 0:s=new Su(e,t);break;case 39:s=new Ob(e,t,n,r??null);break;case 45:!n||n.match(/\s/)?s=new rt(""):s=new or(e,t,sr(`(^|\\s)${rr(n,r??null)}($|\\s)`),r??null);break;case 44:s=new or(e,t,sr(`^${rr(n,r??null)}($|-)`),r??null);break;case 43:n?s=new or(e,t,sr(`^${rr(n,r??null)}`),r??null):s=new rt("");break;case 42:n?s=new or(e,t,sr(`${rr(n,r??null)}$`),r??null):s=new rt("");break;case 46:n?s=new or(e,t,sr(rr(n,r??null)),r??null):s=new rt("");break;case 50:if(n=="supported")s=new Bb(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Es++}`;this.processChain(new ks(new jb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Es++}`;this.processChain(new ks(new Xb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Es++}`;this.processChain(new ks(new qb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Es++}`;this.processChain(new ks(new Yb(e,this.viewConditionId,null))),this.chain=[new rt(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 eh(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Ja(t,0,this.condition):i=new U(t,0),rf(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Gt("SIMPLE_PROPERTY").forEach(s=>{let o=s({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new Ja(t,n,this.condition):new U(t,n);Kt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Hn(this);break;case"not":i=new o0(this);break;case"where":i=new a0(this);break;case"has":i=new l0(this);break;case"nth-child":t&&t.length>=2&&(i=new vf(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new h0(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},s0={"nth-child":Db,"nth-of-type":il,"nth-last-child":nl,"nth-last-of-type":rl},Es=0,Hn=class yf extends Mr{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 Wb(this.selectorTexts):this.positive()?new th(this.chains):new Ub(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new rt("")),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 yf;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}},o0=class extends Hn{positive(){return!1}forgiving(){return!1}},a0=class extends Hn{increasingSpecificity(){return!1}},l0=class extends Hn{relational(){return!0}},vf=class extends Hn{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 hf(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}forgiving(){return!0}},h0=class extends vf{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Gb(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}},u0=class extends sn{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 Wr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Gs=class extends sn{constructor(e,t,i,n,r,s){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=s,d(this,"order"),this.order=0}property(e,t,i){i?q.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){q.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){q.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=nh;let r=this.condition?new Ja(t,n,this.condition):new U(t,n);Kt(this.elementStyle,e,r)}},c0=class extends Rd{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){q.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){q.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Fd:Ad;n+=this.order,this.order+=nh;let r=new U(t,n);Kt(this.elementStyle,e,r)}};function wf(e,t){let i=tf(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function al(e,t,i){wf(i,n=>{Cr(e,n,t)})}function d0(e,t,i,n){let r=new c0(e,t),s=new bt(n,r);try{nv(s,r,i)}catch(o){q.warn(o,"Style attribute parse error:")}return r.elementStyle}function bf(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function xf(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function ll(e,t,i,n,r){let s={};for(let o in e)Xi(o)&&(s[o]=ve(e,o));return al(s,t,e),Sf(e,i,n,(o,a)=>{Cr(s,a,t),al(s,t,a)}),s}function Sf(e,t,i,n){let r=pt(e,"_regions");if((t||i)&&r){if(i){let s=["footnote"];t?t=t.concat(s):t=s}for(let s of t){let o=r[s];o&&n(s,o)}}}function Cr(e,t,i){for(let n in t)if(Xi(n)){let r=ve(t,n),s=e[n];e[n]=el(i,s,r)}}var Cf=(e,t,i,n,r,s)=>{var o,a;let h=i?n?vb:Kp:n?wb:Jp,l=r?bb:xb;for(let u in e){let c=e[u];if(!c)continue;let p=(o=h[u])!=null?o:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,y;if(g){let b=e[g];if(b&&b.priority>c.priority||p&&f&&p!==f&&(g=f,b=e[g],b&&b.priority>c.priority))continue;y=bu[p]?p:bu[f]?f:u}else y=u,u.startsWith("text-align")&&(c.value===v.inside||c.value===v.outside)&&(c=new U(r===(c.value===v.inside)?v.right:v.left,c.priority));t[y]=s(u,c)}},p0=class kf extends nn{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,s;let o=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===v.initial)return{found:!0,value:null,elementStyles:i.slice(a),element:n};if(!(h===v.inherit||h===v.unset||h===v.revert))return{found:!0,value:h,elementStyles:i.slice(a),element:n}}}n&&(o=n.parentElement)}for(;o;o=o.parentElement){let a=this.styler.getStyle(o,!1),h=(s=a?.[t])==null?void 0:s.value;if(h){if(h===v.initial)return{found:!0,value:null,elementStyles:a?[a]:[],element:o};if(!(h===v.inherit||h===v.unset||h===v.revert))return{found:!0,value:h,elementStyles:a?[a]:[],element:o}}}return{found:!1,value:null,elementStyles:[],element:null}}collectReferencedCustomProperties(t){let i=new Set;class n extends Zt{visitFunc(s){let o=s.values[0]instanceof he&&s.values[0].name;return s.name==="var"&&o&&Xe(o)&&i.add(o),super.visitFunc(s)}}return t.visit(new n),Array.from(i)}findReferencedCycleStart(t,i,n,r=new Set){for(let s of this.collectReferencedCustomProperties(t)){if(this.resolvingCustomProperties.includes(s))return s;if(r.has(s))continue;r.add(s);let o=this.getRawCustomPropertyLookup(s,i,n),a=o.value&&this.findReferencedCycleStart(o.value,o.elementStyles,o.element,r);if(a)return a}return null}getFallbackCycleMembers(t,i,n){let r=null,s=this;class o extends Zt{visitFunc(l){if(l.name==="var")for(let u of l.values.slice(1)){let c=s.findReferencedCycleStart(u,i,n);if(c)return r=c,null}return super.visitFunc(l)}}if(t.visit(new o),!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===v.initial)return{found:!0,value:null,continueLookup:!1};if(i===v.inherit||i===v.unset||i===v.revert)return{found:!0,value:null,continueLookup:!0};let s=this.getFallbackCycleMembers(i,n,r);return s?(s.forEach(o=>this.varResolutionState.cycleMembers.add(o)),{found:!0,value:null,continueLookup:!1}):{found:!0,value:this.resolveReferencedCustomProperty(t,i,n,r),continueLookup:!1}}resolveReferencedCustomProperty(t,i,n,r){let s=this.resolvingCustomProperties.indexOf(t);if(s>=0)return this.resolvingCustomProperties.slice(s).forEach(c=>this.varResolutionState.cycleMembers.add(c)),null;let o=new Set(this.varResolutionState.cycleMembers);this.varResolutionState.cycleMembers=new Set;let a=new kf(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([...o,...u]),this.resolvingCustomProperties.pop(),u.has(t)?null:h}getVarValue(t){var i,n,r,s;let o=(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&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=this.styler.getStyle(o,!1),h=this.resolveCustomProperty(t,(s=a?.[t])==null?void 0:s.value,a?[a]:[],o);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 he&&t.values[0].name;return!i||!Xe(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 _e(t.values.slice(1)))}},Ef=class extends nn{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=Ri(this.context.rootScope,new bt(i,null),"");if(n instanceof j)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 L(r,"px"):/\d[a-z]/i.test(i)||(t=new Tt(r)))}catch(r){q.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Pc(e.unit)||this.context.rootFontSize!=null&&um(e.unit)?new L(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new L(e.num*this.percentRef/100,"px"):e}};function xo(e,t,i,n,r){try{if(t instanceof j)return t.expr instanceof we&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:ov(e,t.expr,i);if(t instanceof L||t instanceof ai||t instanceof J||t instanceof _e)return t.visit(new Ef(e,!0,n,r))}catch(s){return q.warn(s),Be}return t}var ku={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Eu(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.none;if(t===v.none)return ku;let i=t instanceof J?t.values:[t],n=Object.create(ku);for(let r of i)if(r instanceof he)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 Pu(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var f0={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Nu={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Tu={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Iu(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.normal;if(t===v.normal)return Nu;if(t===v.auto)return Tu;let i=t instanceof J?t.values:[t],n=Object.create(Nu);for(let r of i)if(r instanceof he)switch(r.name){case"trim-both":case"trim-auto":return Tu;case"space-all":return f0;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 pa={ideographAlpha:!1,ideographNumeric:!1},g0={ideographAlpha:!0,ideographNumeric:!0};function Au(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.normal;if(t===v.normal||t===v.auto)return g0;if(t===v.none)return pa;let i=t instanceof J?t.values:[t],n=Object.create(pa);for(let r of i)if(r instanceof he)switch(r.name){case"no-autospace":return pa;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Fu(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ru(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 m0=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let s=r.length-1;for(let o=0;o<s;o++)n.parentNode.insertBefore(document.createTextNode(r[o]),n);n.textContent=r[s]}}}processGeneratedContent(e,t,i,n,r,s){r=Ru(r);let o=Au(t),a=Iu(i),h=Eu(n);if(Pu(h)&&Fu(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(s?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),c=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let g=!c,y=!c||/\n$/.test(c.textContent),b=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||y,g,y,b,x,c,p,o,a,h,r,s),c=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,s,o,a,h,l;let u=!e||e.fragmentIndex===1&&f(),c=u||g();function p(m){var w;if(m?.nodeType!==1)return!1;let S=m;if(S.hasAttribute(Dn))return!0;let{position:C,float:T}=(w=S.style)!=null?w:{};return C==="absolute"||C==="fixed"||T&&T!=="none"}function f(){let m=t[0];for(let w=m;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!m.inline)return!0;for(let w=m.viewNode.previousSibling;w;w=w.previousSibling)if(!Ee(w,m.whitespace)&&!p(w))return!1;return!0}function g(){var m,w;let S=t[0],C;for(;S&&S.inline&&(C=(m=S.viewNode)==null?void 0:m.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&S.whitespace!==wt.PRESERVE&&(C=C.previousSibling),C)));)S=S.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let T=(w=C.style)==null?void 0:w.display;if(T&&T!=="inline")return!/^(inline|ruby)\b/.test(T)}else if(C.nodeType===Node.TEXT_NODE){if(S.whitespace===wt.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(S.whitespace===wt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let y=-1;for(let m=0;m<t.length;m++){let w=t[m];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ee(w.viewNode,w.whitespace)){let S=function(P){var N,O,V;if(((N=P.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===wt.PRESERVE){if(/\n$/.test(W.textContent))return!0}else if(P.whitespace===wt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(W.textContent))return!0;if(((V=W.previousElementSibling)==null?void 0:V.localName)==="br")return Ee(W,P.whitespace)}return!1},C=function(P){var N,O,V;if(((N=P.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===wt.PRESERVE){if(/^\n/.test(W.textContent))return!0}else if(P.whitespace===wt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(W.textContent))return!0;if(((V=W.nextElementSibling)==null?void 0:V.localName)==="br")return Ee(W,P.whitespace)}return!1};var b=S,x=C;y<0&&(y=m);let T=Ru((s=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),R=Au(w.inheritedProps["text-autospace"]),F=Iu(w.inheritedProps["text-spacing-trim"]),z=Eu(w.inheritedProps["hanging-punctuation"]);if(Pu(z)&&Fu(R,F)||/\b(flex|grid)\b/.test(w.parent.display))continue;let $=null,X=null,re=m===y,k=m===y&&u,_=m===y&&c,E=!1,B=!1;for(let P=m-1;P>=0;P--){let N=t[P];if(S(N)){_=!0;break}if(!N.display&&N.viewNode.nodeType===Node.TEXT_NODE&&N.viewNode.textContent.length>0){$=N.viewNode;break}if(((o=N.viewNode)==null?void 0:o.nodeType)===Node.ELEMENT_NODE&&ii(N.viewNode)==="footnote-call"){if(N.viewNode.contains(w.viewNode))continue;let O=vv(N.viewNode);if(O){$=O;break}}if(N.display&&!/^(inline|ruby)\b/.test(N.display)||((a=N.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(N.viewNode.localName==="br"||ji[N.viewNode.localName]))break;P===0&&(re=!0,u&&(k=!0,_=!0))}for(let P=m+1;P<t.length;P++){let N=t[P];if(C(N)){E=!0;break}if(N.viewNode!==w.viewNode&&!N.display&&N.viewNode.nodeType===Node.TEXT_NODE&&N.viewNode.textContent.length>0){X=N.viewNode;break}if(N.display&&!/^(inline|ruby)\b/.test(N.display)||((h=N.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(N.viewNode.localName==="br"||ji[N.viewNode.localName])){P===t.length-1&&p(N.viewNode)&&(B=!0);break}if(P===t.length-1){E=!0,B=!0;for(let O=N.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){B=!1;break}}}if(((l=w.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=w.parent.viewNode.firstChild;for(;Ee(P,w.whitespace);)P=P.nextSibling;w.viewNode===P&&(k=!0)}if(!B){let P=w.parent.viewNode.lastChild;for(;Ee(P,w.whitespace);)P=P.previousSibling;w.viewNode===P&&(B=!0)}}if(this.processTextSpacing(w.viewNode,re,k,_,E,B,$,X,R,F,z,T,w.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,h,l,u,c,p){let f=e.textContent,g=e.ownerDocument,y=0,b,x,m;function w(){if(t)return!0;if(!o)return!1;b||(b=g.createRange(),b.selectNode(e));let E=b.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(o));let B=x.getClientRects(),P=B[B.length-1];return P?(y||(y=Fr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function S(){if(!a)return!1;b||(b=g.createRange(),b.selectNode(e));let E=b.getClientRects()[0];if(!E)return!1;y||(y=Fr(E,p)),m||(m=g.createRange(),m.selectNode(a));let B=m.getClientRects()[0];return B?p?E.top+E.height>B.top+E.width||E.left>B.left+B.width-E.width/10||E.left+E.width<B.left+E.width/10:E.left+E.width>B.left+E.height||E.top+E.height<B.top+E.height/10||E.top>B.top+B.height-E.height/10:!1}let C=!1,T=!1,R=!1,F=!1,z;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(z="viv-ts-open",C=!0,T=!0):s&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(z="viv-ts-close",C=!0,R=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(z="viv-ts-close",C=!0,F=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(z="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))&&(z="viv-ts-close",C=!0),C){let E=function(V){let W=parseFloat(g.defaultView.getComputedStyle(V).fontSize)*.7;return(p?V.offsetHeight:V.offsetWidth)>W},B=function(){return p?P.offsetLeft:P.offsetTop};var $=E,X=B;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(z),N=g.createElement("viv-ts-inner");P.appendChild(N),e.parentNode.insertBefore(P,e),N.appendChild(e);let O=E(N);if(O||T||R||F){if(z==="viv-ts-open"){if(T)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)&&w())P.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&E(o.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let V=B();P.className="viv-ts-auto",V===B()&&!w()&&(P.className="viv-ts-trim")}}else if(z==="viv-ts-close"){if(R)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let V=B();F?(P.className=O?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&V===B()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",V===B()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",V===B()&&(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(F){let V=S(),W=V&&u.allowEnd;W||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?W&&l.trimEnd?P.className="viv-ts-auto":!W&&!S()?P.className="":!V&&u.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):(P.className="viv-ts-space",S()||(l.allowEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!V&&!S()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let V=B();P.className="viv-ts-auto",V===B()&&(P.className="")}}}}let re=!1;function k(E){var B;let P=(B=E?.ownerDocument.defaultView)==null?void 0:B.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function _(E,B){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(B))return _(P,B);if(B.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(B);if(parseFloat(O.marginInlineStart)||parseFloat(O.borderInlineStartWidth)||parseFloat(O.paddingInlineStart))return!0}let N=B.parentElement;return N&&!N.contains(E)?_(E,N):!1}return(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&k(o.parentElement))&&!_(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),re=!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),re=!0)),y}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)}},rh=new m0;rh.registerHooks();function y0(e){rh.preprocessForTextSpacing(e)}function v0(e,t,i,n,r,s){rh.processGeneratedContent(e,t,i,n,r,s)}var dr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),w0=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],sh="data-adapt-pseudo";function ii(e){return e.getAttribute(sh)||""}function kr(e,t){e.setAttribute(sh,t)}var fa=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=ii(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 s=1,o;i=="first-letter"?s=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=o[1]-0),r["x-first-pseudo"]=new U(new lt(s),0)}return r}processContent(e,t,i){let n=ii(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;It(r)&&(r.visit(new Rr(e,this.context,r,this.exprContentListener)),y0(e))}}},rC=so.isInstanceOfAfterIfContinuesLayoutConstraint,b0=Vo.registerFragmentIndex,sC=Vo.clearFragmentIndices,x0=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new oh(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let s=i.firstChild;return A(s,"display","block"),I(s)})}createNodePositionForPseudoElement(){let e=dr.createElementNS("http://www.w3.org/1999/xhtml","div");kr(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 Bi(i)}createShadowContext(e){return new Rs(this.sourceNode,e,null,null,null,yi.ShadowType.ROOTED,this.styler)}},S0=class Pf{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,d(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),I(!0))):I(!0)}getRepetitiveElements(){return new C0(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Pf?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},C0=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 Nf(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return I(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=E0(e,t,n);return t.fragmentLayoutConstraints.push(new S0(e,i,r)),I(e)})}function Tf(e,t){return e.thenAsync(i=>Nf(i,t))}function k0(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Nf(n,t);return n=n.parent,r.thenReturn(!0)}else return I(!1)}).then(()=>{i.finish(!0)}),i.result()}function E0(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Oa(i,t,e.vertical);return n.removeChild(i),r}var P0=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},pr=class extends $l{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]}},So=class extends sp{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),dv(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 s=r,o=i[n];if(r=ao(o,s),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return I(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Iv(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,s=r.match(Ys),o=s?s[0].length:0;if(!s&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(Ys);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return I(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=D("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var s;if(e.viewNode&&!En(e)&&((s=e.viewNode.parentElement)==null?void 0:s.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let o=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(o);if(Fr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,En(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)&&(Ai(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 Tf(i,this)}buildDeepElementView(e){if(!e.viewNode)return I(e);let t=[],i=e.sourceNode,n=D("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!En(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(s=>{let o=s;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,r.breakLoop();return}En(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Ai(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),A(r,"height",`${i}px`),A(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),A(r,"width",`${i}px`),A(r,"height",`${n}px`)),A(r,"float",t),A(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),s=this.vertical?-this.getLeftEdge():this.getBottomEdge(),o=null,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,s,f)&&(p.y1=s),this.almostEquals(p.y2,s,f)?p.y2=s:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=bl==="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,y=f-t[p].x1,b=t[p].x2-g,x=0,m=0;y>c?x=1:y<-c&&(x=-1),b>c?m=1:b<-c&&(m=-1);let w=x!==0&&m!==0?x===m?x:0:x||m;if(h>0&&w!==0){let S=w*h;u[p]+S>=0&&(p>=t.length-1||u[p+1]-S>=0)&&(u[p]+=S,p<t.length-1&&(u[p+1]-=S))}}for(let p=0;p<t.length;p++){let f=t[p];f.left=this.createFloat(e,"left",f.x1-i,u[p]),f.right=this.createFloat(e,"right",n-f.x2,u[p]),f.x1<n&&f.x2>i?o=f:o||A(f.right,"float","none")}if(o){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(o!==p&&(p.y2>=s||this.almostEquals(p.y2,s,f))&&(this.footnoteEdge=this.vertical?-o.y2:o.y2,o.x1===i&&o.x2===n))for(let g=t.indexOf(o);g<t.length;g++){let y=t[g];this.element.removeChild(y.left),this.element.removeChild(y.right),y.left=null,y.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(A(this.element,r,`${i}px`),this.vertical){let s=this.left+(t-i);A(this.element,"left",`${s}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&kn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=wn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let s=n-e.boxOffset;for(;;){if(r=wn(e,this.clientLayout,s,this.vertical),!isNaN(r))return r;if(s>0){s--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(s=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new Qo(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 Qo(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 Qo(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=sa(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return A(i,"float","none"),A(i,"display","inline-block"),A(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let s=$t(this.clientLayout,i,this.vertical),o=this.getComputedMargin(i),a=new Lt(s.left-o.left,s.top-o.top,s.right+o.right,s.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let S=u.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),u.viewNode.appendChild(S);let C=$t(this.clientLayout,S,this.vertical);h=Math.max(this.rtl?this.getEndEdge(C):this.getStartEdge(C),h),l=Math.min(this.rtl?this.getStartEdge(C):this.getEndEdge(C),l),u.viewNode.removeChild(S);let T=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+T):h=Math.min(h,l-T),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=eo(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let S=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+S}if(e.clearSide){let S=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?sa(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;S!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),S!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let T=C*f;if(p.y1<T){let R=p.y2-p.y1;p.y1=T,p.y2=p.y1+R}}c.y2+=this.getFloatLayoutUnit(),Dm(c,this.bands,p,n),this.vertical&&(a=id(p));let g=this.getComputedInsets(i);A(i,"width",`${a.x2-a.x1-g.left-g.right}px`),A(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),A(i,"position","absolute"),e.display,A(i,"display",e.display);let y,b=null;if(u&&(u.containingBlockForAbsolute?b=u:b=u.getContainingBlockForAbsolute()),b){let S=b.viewNode.ownerDocument.createElement("div");S.style.position="absolute",b.vertical?S.style.right="0":S.style.left="0",S.style.top="0",b.viewNode.appendChild(S),y=$t(this.clientLayout,S,this.vertical),b.viewNode.removeChild(S)}else y={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(b?b.vertical:this.vertical){let S=Math.max(0,y.right-a.x2);A(i,"right",`${S}px`)}else{let S=Math.max(0,a.x1-y.left);A(i,"left",`${S}px`)}let x=Math.max(0,a.y1-y.top);A(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let m=this.vertical?a.x1:a.y2,w=this.vertical?a.x2:a.y1;!this.isOverflown(m)||this.breakPositions.length==0?(this.killFloats(),c=new Lt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(c=eo(c)),zm(c,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=m:this.rightFloatEdge=m,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(m),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,s){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!o.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!o.hasFloatFragments(),s);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,A(e.element,"width",`${p}px`))}else{let p=parseFloat(c.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,A(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return I(u)})}createPageFloatArea(e,t,i,n,r){let s=this.element.ownerDocument.createElement("div");A(s,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new xn(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=o.getContainer(),l=new I0(t,s,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>I(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,s,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},c=D("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,s,r,l).then(p=>{if(u.floatArea=p,!p){c.finish(u);return}let f=!1,g=0;c.loopWithFrame(y=>{if(g>=e.length){y.breakLoop();return}let b=e[g],x=new Bi(b.nodePosition),m=p.breakPositions?p.breakPositions.length:0;p.layout(x,!0).then(w=>{if(u.newPosition=w,!w||n){if(w&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.length>m&&p.breakPositions.slice(m).some(S=>S instanceof pr))){f=!0,y.breakLoop();return}g++,y.continueLoop()}else f=!0,y.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&u.newPosition){let y=a.getPageFloatLayoutContext(h.floatReference);if(y.footnoteMaxBlockSize==null){if(y.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,s,o).then(b=>{c.finish(b)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let y=a.setFloatAreaDimensions(p,h.floatReference,t,s,!1,n,l);if(!y)f=!0;else{let b=r.createPageFloatFragment(e,y,i,p,!!u.newPosition);a.addPageFloatFragment(b,!0),u.pageFloatFragment=b}}c.finish(u)})}),c.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,s=e.float,o=new Set;for(let u=r;u;u=u.effectiveParent)for(let c of u.floatFragments)c.continuations.some(p=>p.float.insidePageFloatArea)&&o.add(c);r.stashEndFloatFragments(s);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)!o.has(g)&&g.continuations.some(y=>y.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(s.floatReference),r.deferPageFloat(e)}let h=s instanceof ho,l=D("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],s.floatSide,s.clearSide,h||!r.hasFloatFragments(),t,i,n).then(u=>{let c=u.floatArea,p=u.pageFloatFragment,f=u.newPosition;p?this.layoutStashedPageFloats(s.floatReference,[n]).then(g=>{if(g){let y=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,y),r.discardStashedFragments(s.floatReference),f){let b=new ou(s,f.primary);r.deferPageFloat(b)}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=[],s=[],o=!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 zn().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?(s.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(s.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!o)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&ii(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(Dn,"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,s=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<s.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Ml(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new zn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=I(r):n=i.createPageFloat(e,t,this),n.thenAsync(s=>{let o=oo(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(s);let h=i.findPageFloatFragment(s,t),l=new ou(s,o);if(h&&h.hasFloat(s))return t.registerPageFloatAnchor(s,a.viewNode),I(a);if(t.isForbidden(s)||t.hasPrecedingFloatsDeferredToNext(s))return t.deferPageFloat(l),t.registerPageFloatAnchor(s,a.viewNode),I(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return I(null);{let u=p=>{if(!p||p.nodeType!==1)return NaN;let f=$t(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},c=wn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=s;if(p.footnotePolicy===v.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)?I(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?e.floatSide==="footnote"||t.generatingNodePosition?I(a):I(null):(t.registerPageFloatAnchor(s,a.viewNode),I(a)))}})}processLineStyling(e,t,i){let n=D("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let s=0,o=e.firstPseudo;return o?.count===0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(r),l=o.count-s;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{s+=l,this.layoutContext.peelOff(u,0).then(c=>{e=c,o=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&ji[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let s=this.getComputedMargin(r.viewNode),o=this.vertical?-s.left:s.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=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 s=this.suppressOpenAncestorBlockEndInset(n??e),o=this.calculateEdge(n,i,r,i[r].boxOffset);s();let a=!1;if(!n||!kn(n.viewNode)){let l=Rn(n,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*l.minimum),this.isOverflown(o+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(o+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(o);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=I(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){Gt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,s=t[0].boxOffset,o=r,a=t.length-1,h=t[a].boxOffset,l;for(;s<h;){l=s+Math.ceil((h-s)/2),o=r;let u=a;for(;o<u;){let p=o+Math.ceil((u-o)/2);t[p].boxOffset>l?u=p-1:o=p}let c=this.calculateEdge(null,t,o,l);if(this.vertical?c<=n:c>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(c),s=l,r=o}return{nodeContext:t[o],index:s,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,r,s;let o=this.findEndOfLine(t,e,!0),a=o.nodeContext;if(o.checkPointIndex===0&&o.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,o.index,e,o.checkPointIndex,i)}else{let l=iu(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof pr&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(s=a.viewNode)==null?void 0:s.previousSibling;for(;u&&(Ee(u,a.parent.whitespace)||Rt(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Gt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Co.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,s=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;s==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let c=s.nodeType===1?s:null;c?r?r=!1:Bl(c)?l=!a:!c.firstChild||ji[c.localName]||/^r(uby|[bt]c?)$/.test(c.localName)||yv(this.clientLayout.getElementComputedStyle(c).display)?(l=!a,l?(c.localName==="ruby"&&s.firstChild&&(s=s.firstChild),n.setStartBefore(s),a=!0,o=s):/^r(uby|tc?)$/.test(c.localName)||(o=s),s.contains(t)&&(h=!1)):u=s.firstChild:(a||(s.parentNode==null?h=!1:(n.setStartBefore(s),a=!0)),o=s),u||(u=s.nextSibling,u||(r=!0,u=s.parentNode)),s=u}while(l&&h);if(a){n.setEndAfter(o);let u=this.clientLayout.getRangeClientRects(n);no(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?Dv:_v);let n=0,r=0,s=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(o>0){let 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(o==0||u>=.6||u>=.2&&this.getStartEdge(l)>=s-1){s=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),r=o==0?l.left:Math.min(r,l.left)):(n=o==0?l.top:Math.min(n,l.top),r=o==0?l.bottom:Math.max(r,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(r),o=0),a>=i.length)break}return t.sort(xc),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&Pn(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=Rn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,s=r[0];for(;s.parent&&s.inline;)s=s.parent;let o,a;t&&!this.isFootnote?(o=1,a=1):(o=Math.max((s.inheritedProps.widows||2)-0,1),a=Math.max((s.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(s),l=this.findLinePositions(r),u=this.footnoteEdge-h,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=mi(l.length,m=>{let w=l[m];return this.vertical?w<u||w<=f.edge:w>u||w>=f.edge}),y=g<=0;y&&(g=mi(l.length,m=>this.vertical?l[m]<u:l[m]>u));let b=r[r.length-1].viewNode;if(b?.parentElement.localName==="viv-ts-inner"&&(b=b.parentElement.parentElement),(g===l.length&&b.nextSibling||g>=l.length-1&&b.parentElement.querySelector(".MJXc-display"))&&(o=0,a=1),g=Math.min(l.length-o,g),g<a)return null;u=l[g-1];let x;if(y?x=f.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,u,t),x){let m=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(m)&&c*(u-m)>0&&(u=m),this.computedBlockSize=c*(u-this.beforeEdge)+p,l.length>=2){let w=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[w]-l[w-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,wn(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 tr().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Ul.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let s=e.getMinBreakPenalty();s>i&&(n=Math.min(n,s))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return I(e);let r=D("doFinishBreak"),s=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return q.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,s,!0).then(()=>{r.finish(o)})):r.finish(o)}),r.result();e=i,s=!0,this.computedBlockSize=n}return this.finishBreak(e,s,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Rt(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!io(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||Pn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let s=n.getAttribute("data-viv-box-break");St(n,"block-end"),t.push({element:n,original:s})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let o=e;o;o=o.parent)if(Rt(o.viewNode))return!1;if(kn(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=wn(e,this.clientLayout,0,this.vertical);i();let r=Rn(e,this.collectElementsOffset()),s=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let o=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||kn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=e.clearSide==="same"?e.floatSide:e.clearSide,i=/^(page|column|region)$/.test(t),n=this.getComputedMargin(e.viewNode),r=e.viewNode.ownerDocument.createElement("div");this.vertical?(r.style.bottom="0px",r.style.width="1px",r.style.marginRight=`${n.right}px`):(r.style.right="0px",r.style.height="1px",r.style.marginTop=`${n.top}px`);let s=()=>i?this.clientLayout.getElementClientRect(r):$t(this.clientLayout,r,this.vertical);e.viewNode.parentNode.insertBefore(r,e.viewNode);let o=s(),a=this.getBeforeEdge(o),h=this.getBoxDir(),l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(t)?sa(t,e.vertical,e.direction,this.layoutContext.page.side):t,u=l==="left"||l==="right"?e.direction==="rtl"==(l==="left")?"inline-end":"inline-start":l,c=this.pageFloatLayoutContext.getPageFloatClearEdge(u,this),p=c;switch(l){case"left":c=h*Math.max(c*h,this.leftFloatEdge*h);break;case"right":c=h*Math.max(c*h,this.rightFloatEdge*h);break;default:c=h*Math.max(c*h,Math.max(this.rightFloatEdge*h,this.leftFloatEdge*h))}let f=this.getFloatLayoutUnit(),g=this.leftFloatEdge*h>this.beforeEdge*h||this.rightFloatEdge*h>this.beforeEdge*h;if(f>0&&g){let b=c*h>p*h;c=h*(Math.ceil(c*h/f)+(b?1:0))*f}let y=this.getFloatLayoutTolerance(f);if(a*h+y>c*h)return e.viewNode.parentNode.removeChild(r),!1;{let b=Math.max(1,(c-a)*h);this.vertical?r.style.width=`${b}px`:r.style.height=`${b}px`,o=s();let x=this.getAfterEdge(o);if(!e.floatSide)if(this.vertical){let m=x-n.right-c;m>0==n.right>=0&&(m+=n.right),r.style.marginLeft=`${m}px`}else{let m=c-(x+n.top);m>0==n.top>=0&&(m+=n.top),r.style.marginBottom=`${m}px`}return e.clearSpacer=r,!0}}isBFC(e){return!!(lw(e)||Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(tu(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 I(e);let s=D("skipEdges"),o=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],c=[],p=!1;function f(C){var T,R;if(!(!t||o.isNonFirstColumn||i||!nu(h))){for(let F=C;F;F=F.parent)if(F.breakBefore==="column"&&(F.breakBefore=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakBefore)==="column"&&(z.style.breakBefore="")}}}function g(C){var T,R;if(!(!t||!o.isNonFirstColumn||i||h!=="column")){for(let F=C;F;F=F.parent)if(F.breakBefore==="column"&&(F.breakBefore=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakBefore)==="column"&&(z.style.breakBefore="")}h=null}}function y(C){var T,R;if(!(i||!nu(h))){for(let F=C;F;F=F.parent)if(F.breakAfter==="column"&&(F.breakAfter=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakAfter)==="column"&&(z.style.breakAfter="")}}}function b(C){h=nt(h,C)}function x(){return i?!0:Ze(h)?t?o.isNonFirstColumn&&h!=="column"&&h!=="region":!m()&&!w():!1}function m(){var C;if(!l||!e||e.floatSide)return!1;for(let T=l;T!=null&&T.parent;T=T.parent){if(T.parent.viewNode&&Rt(T.parent.viewNode))continue;let R=T.after?T.viewNode:(C=T.viewNode)==null?void 0:C.previousSibling;for(;R&&(Ee(R,T.parent.whitespace)||Rt(R));)R=R.previousSibling;if(R)return!1}return!0}function w(){var C,T;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Rt(e.parent.viewNode))return!1;let R=!1;for(let F=e;F!=null&&F.parent&&!F.after;F=F.parent){if(F!==e&&Rt(F.viewNode))return!1;let z=(T=F.viewNode)==null?void 0:T.previousSibling;for(;z&&(Ee(z,F.parent.whitespace)||Rt(z));)Rt(z)&&(R=!0),z=z.previousSibling;if(z)return!1}return R}let S=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return s.loopWithFrame(C=>{for(var T;e;){e.formattingContext;let R=new tr().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ee(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){b(e.breakBefore),f(e),g(e),x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=ro(h)?h:null),R&&R.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?iu(l):this.breakPositions[this.breakPositions.length-1]instanceof pr||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ee(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),b(e.breakBefore),f(e),g(e),x()?S():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let z=e.viewNode,$=z.style;if(e.after){zd(z,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let X=e.sourceNode;if(X.localName==="svg"||X.localName==="math"||X.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),c.push(l),h=null,b(e.breakAfter),y(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||R&&R.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(tu(e.viewNode))break;if(x()){S(),C.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,$d(e.viewNode)||(l=e.copy(),c.push(l)),b(e.breakAfter),y(e),$&&!Rt(e.viewNode)&&this.hasNonZeroBlockEndInset($)&&(c=l?[l]:[])}else{if(u.push(e.copy()),b(e.breakBefore),f(e),g(e),l&&Ze(h)&&pv(l.viewNode,e.viewNode),(e.pageType!=((T=e.parent)==null?void 0:T.pageType)||!Ze(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let X=e.viewNode.localName;if(ji[X]){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}$&&this.hasNonZeroBlockStartInset($)&&(a=!1,c=[]),p=!0}}while(!1);let F=this.nextInTree(e,a);if(F.isPending()){F.then(z=>{e=z,C.continueLoop()});return}else e=F.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,c,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Ze(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),s.finish(e)}),s.result()}skipTailEdges(e){let t=e.copy(),i=D("skipEdges"),n=null,r=!1;return i.loopWithFrame(s=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ee(e.viewNode,e.whitespace))break;if(!e.after){Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=nt(n,e.breakBefore),Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ze(n)){this.pageBreakType=n,s.breakLoop();return}n=null}r=!1,n=nt(n,e.breakAfter)}else{n=nt(n,e.breakBefore);let h=e.viewNode.localName;if(ji[h]){Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){s.breakLoop();return}}r=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,s.continueLoop()});return}else e=o.get()}t=null,s.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Ai(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=D("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let s=e.formattingContext;new tr().find(s).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new tr().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=Bm(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],A(this.element,"width",`${this.width}px`),A(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 tr().find(e.formattingContext),s=this.calculateClonedPaddingBorder(n),o=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+s);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new pr(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 I(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?I(null):I(e);Ll(this);let n=D("layout");return this.openAllViews(e.primary).then(r=>{let s=null;if(r.viewNode)s=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(s=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new N0(t,i);o.layout(r,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,s,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=I(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(io(this)&&(mv(this),Bo(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(A(this.element,"width",`${this.width}px`),A(this.element,"left",`${this.left}px`)):A(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 Bi(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,s)=>r.getPriorityOfFinishBreak()-s.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):I(!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(s=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())s.breakLoop();else if(this.pageBreakType)s.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),s.breakLoop()}else o?o=!1:s.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),s.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=D("redoLayout"),n=0,r=null,s=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,s).then(h=>{s=!1,h?(r=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Yi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(so.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},oh=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(s){return So.prototype.openAllViews.call(this,s).thenAsync(o=>(r.startNodeContexts.push(o.copy()),I(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Jr(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 Oi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let s=r.data.slice(e.offsetInNode);if(!Jd(s,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let s=r.nextSibling;s;s=s.nextSibling)if(!Ee(s,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Co=class{breakTextNode(e,t,i,n,r,s){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+Lu(n)),r){let s=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=s.slice(0,i+1)+r+s.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let s=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Ph(r)&&Ph(s)?Lu(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};d(Co,"instance");Co.instance=new Co;function Lu(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var N0=class extends Wl{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 T0(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||uw()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Vd(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}},T0=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return k0(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}},I0=class extends So{constructor(e,t,i,n,r,s,o){super(t,i,n,r,s),this.floatSide=e,this.parentContainer=o,d(this,"rootViewNodes",[]),d(this,"floatMargins",[]),d(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),I(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(s,o){s.forEach(a=>{let h=ki(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=o*l/100;A(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(s=>{ki(e,s)==="auto"&&A(e,s,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=ki(t,"height");n!==""&&n!=="auto"&&A(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ki(t,"width");n!==""&&n!=="auto"&&A(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=$t(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(Vt);if(!g||!t||!i)return!1;let y=i.getNodeByOffset(parseInt(g,10));if(!y||y.nodeType!==Node.ELEMENT_NODE)return!1;let b=t.getStyle(y,!1),x=(c=(u=ve(b,"footnote-display"))==null?void 0:u.value)==null?void 0:c.toString(),m=!!((p=ve(b,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!m});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),s=this.vertical?r.height:r.width;n.forEach(h=>{A(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let o=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);A(l,"display","inline-block"),A(l,"position","absolute"),A(l,"visibility","hidden"),A(l,"white-space","nowrap"),A(l,"max-width","none"),A(l,"left","0"),A(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>s+o&&(A(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=$t(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=>ii(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&&Et(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");kr(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,s=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,o=this.rootViewNodes[t+1],a=(n=o?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(o).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),u=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),c=this.getFootnoteBreakOpportunity(r);if(s==="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()})}},tn=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||Ha.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new A0(e,this.rootSourceNode),Ha.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},A0=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=oo(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=oo(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Oa(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Oa(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?I(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?I(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,s=t.viewNode,o=r.createElement("div");s.appendChild(o);let a=new oh(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Bi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=h,I(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Dn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let s=n.indexOf(r);if(s>=0)return i?s===0:!1;for(let o=r;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},If=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}},Af=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},F0=class extends If{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},R0=class extends Af{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new ah(e)),this.processor.doLayout(e,t)}},ah=class Ff{constructor(t){d(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),d(this,"nodeContext");let i=di(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||kn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!Lf(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let s=this.getRepetitiveElements();s&&t&&r.stopAtOverflow&&(i==null||s.isAfterLastContent(i))&&s.preventSkippingFooter()}finishBreak(t,i){let n=di(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return I(!0);let s=this.nodeContext;return _0(n,s,i).thenAsync(()=>D0(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),I(!0))))}getRepetitiveElements(){return di(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Ff?di(this.nodeContext.formattingContext)===di(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},L0=class extends Wl{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new F0(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new R0(this.formattingContext,this.processor))}},O0=class extends wr{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),I(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),I(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return wr.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"?I(!0):wr.prototype.afterNonInlineElementNode.call(this,e)}},B0=class extends Nn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=di(e.formattingContext);return n.getRootViewNode(e)?(i&&Rf(e.parent,t),e.belongsTo(n)?Nn.prototype.layout.call(this,e,t,i):new L0(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=z0(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=di(e.formattingContext),n=D("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=di(e.formattingContext),n=new O0(i,t);return new $a(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=di(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Tf(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return Nn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Nn.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 tn&&!i.belongsTo(n)&&t(n,i)}}function Rf(e,t){e&&M0(e.after?e.parent:e,(i,n)=>{Li.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new ah(n))})}function _0(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let s=r.viewNode.firstChild;return n.appendHeaderToFragment(r,s,i)}}return I(!0)}function D0(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 I(!0)}function Lf(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function z0(e){let t=e.formattingContext;return!t||!(t instanceof tn)?null:t}function di(e){return e instanceof tn,e}var V0=new B0;Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof tn&&!Li.isInstanceOfTableFormattingContext(e)?V0:null);var Of=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))}},$0=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}},H0=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},U0=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,d(this,"pseudoColumn"),d(this,"empty",!1),this.pseudoColumn=new oh(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&A(e,"vertical-align","top"),i&&i!=="normal"&&A(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return A(e,"vertical-align",t),i&&i!=="normal"&&A(e,"align-content",i),n}},W0=class{constructor(e,t){this.viewNode=e,this.side=t}},G0=class extends Jr{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)}},j0=class extends $l{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(s=>!!s.nodeContext)&&n.some((s,o)=>{let a=i[o].pseudoColumn,h=s.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(s=>s.nodeContext&&s.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty));let r=i.some((s,o)=>s.breakPosition instanceof pr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof Jr&&s.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(s.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},On=class extends tn{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 Of(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),s=0;for(;r[s];)s++;for(;e<n;e++){r=this.getRowSlots(e);for(let o=s;o<s+t.colSpan;o++){let a=r[o]=new H0(e,o,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=$t(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let s=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!s||t.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),i),t.push(s)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],s=this.getCellFragmentOfCell(i);!s||r.collected.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),r.elements),r.collected.push(s))})}),[new X0(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Yi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}Li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},X0=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=Rn(e,n);i=Math.max(i,t(r))}),i}};function zt(e){return e instanceof On,e}function q0(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Y0(e){return e==="table"||e==="inline-table"}function Ou(e){return q0(e)||Y0(e)}function Bf(e,t,i){let n=e.nodeContext,r=n.display,s=n.parent?n.parent.display:null,o=!1;if(s==="inline-table"&&!(n.formattingContext instanceof On)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof On){o=a.formattingContext===t;break}}return o||r==="table-row"&&!Ou(s)||r==="table-cell"&&s!=="table-row"&&!Ou(s)||n.formattingContext instanceof On&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,I(!0))):null}function Mf(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Ai(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),I(!0)))}var Z0=class extends wr{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=Bf(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Mf(this.column,e);if(n)return n;let r=e.nodeContext,s=r.display,o=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new W0(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return o.isHeaderRegistered()||(this.inHeaderOrFooter=!0,o.setHeaderNodeContext(r)),I(!0);case"table-footer-group":return o.isFooterRegistered()||(this.inHeaderOrFooter=!0,o.setFooterNodeContext(r)),I(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Of(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),o.firstContentSourceNode||(o.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let s=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(s[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,I(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let s=t.rows[this.rowIndex];s&&i.breakAfter&&(s.breakAfter=nt(s.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let s=i.viewNode;t.addCell(this.rowIndex,new $0(this.rowIndex,this.columnIndex,s)),this.columnIndex++,Vf(s);let o=t.rows[this.rowIndex];o&&(i.breakBefore&&(o.breakBefore=nt(o.breakBefore,i.breakBefore)),i.breakAfter&&(o.breakAfter=nt(o.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!En(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},_f=class Df extends wr{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 Mf(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,s=t.columnIndex,o=t.colSpan,a=i.viewNode;o>1&&(A(a,"box-sizing","border-box"),A(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new U0(this.column,h,i);return this.formattingContext.addCellFragment(r,s,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(Vf(a),I(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let s=n[r];if(s.cell.anchorSlot.columnIndex===t&&s.cellNodePosition.steps[0].node===i)return{position:s,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,s=r.rowIndex;if(s<this.currentRowIndex&&s+r.rowSpan>this.currentRowIndex){let o=i[s];o||(o=i[s]=[]),o.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 I(!0);let s=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=D("layoutRowSpanningCellsFromPreviousFragment"),h=I(!0),l=0,u=[];return n.forEach(c=>{h=h.thenAsync(()=>{let p=ao(c[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=I(!0),g=0;function y(b){for(;g<b;){if(!u.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");A(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return c.forEach(b=>{f=f.thenAsync(()=>{let x=b.cell;y(x.anchorSlot.columnIndex);let m=b.cellNodePosition,w=ao(m.steps[0],p);return w.offsetInNode=m.offsetInNode,w.after=m.after,w.fragmentIndex=m.steps[0].fragmentIndex+1,s.setCurrent(w,!1).thenAsync(()=>{let S=b.breakChunkPosition;for(let C=0;C<x.colSpan;C++)u.push(g+C);return g+=x.colSpan,this.layoutCell(x,w,S).thenAsync(()=>(w.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,I(!0)))})})}),f.thenAsync(()=>(y(i.getColumnCount()),l++,I(!0)))})})}),h.then(()=>{s.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return I(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let s=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(s=nt(s,a.breakAfter))}let o=n.rows[this.currentRowIndex];return o!=null&&o.breakBefore&&(s=nt(s,o.breakBefore)),!t.leadingEdge&&Ze(s)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=s,this.resetColumn(),t.break=!0,I(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),I(!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);b0(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return I(!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,I(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let s=D("startTableCell"),o,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,o=I(h.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=oo(h,0);return I(new Bi(l))});return o.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=Bf(t,zt(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),s=n.display;return s==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,I(!0)):s==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,I(!0)):s==="table-row"?this.startTableRow(t):s==="table-cell"?this.startTableCell(t):I(!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 j0(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return I(!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)):A(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)):A(i.viewNode,"display","table-row-group")),r&&Df.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 s=super.afterNonInlineElementNode(t);return(s&&s.isPending()?s:I(!0)).thenAsync(()=>{if(!t.break){let o=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!o&&h&&!!(a!=null&&a.isFooterRegistered());(o||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return I(!0)})}else return super.afterNonInlineElementNode(t);return I(!0)}};d(_f,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var K0=_f,_r=[];function J0(e){let t=_r.findIndex(n=>n.root===e),i=_r[t];return i?i.tableLayoutOption:null}function Q0(e){let t=_r.findIndex(i=>i.root===e);t>=0&&_r.splice(t,1)}var zf=class{layoutEntireTable(e,t){let i=zt(e.formattingContext),n=new Z0(i,t);return new $a(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=r.createElement("td");s.appendChild(l),o.push(l)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(h=>{let l=$t(n,h,i),u=i?l.height:l.width;return Math.ceil(u)});return e.parentNode.removeChild(s),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let s=r.span;for(r.removeAttribute("span"),n-=s;s-- >1;){let o=r.cloneNode(!0);i.insertBefore(o,r),t.push(o)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let s=e.length;s<i;s++){let o=n.ownerDocument.createElement("col");r.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let s=r.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=s;return}let a=e.colWidths=this.getColumnWidths(r,o,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((u,c)=>{A(u,n?"height":"width",`${a[c]}px`)}),h.forEach(u=>{s.appendChild(u.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=zt(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=J0(e.sourceNode);Q0(e.sourceNode);let r=D("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{var a;let h=o.viewNode,l=i.rows[0];if(l&&Ze(l.breakBefore)&&this.hasInFlowContentBefore(h,t)){(a=h.parentNode)==null||a.removeChild(h),t.pageBreakType=l.breakBefore,r.finish(s);return}let u=$t(t.clientLayout,h,t.vertical),c=t.vertical?u.left:u.bottom;if(c+=(t.vertical?-1:1)*Rn(e,t.collectElementsOffset()).current,!t.isOverflown(c)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new nx(s)),r.finish(o);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&&Ze(i.breakBefore)||t<e.rows.length-1&&Ze(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&&!Rt(n)||n.nodeType===3&&!Ee(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,s)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[s]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),A(t,"table-layout","fixed"),A(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=zt(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new K0(i,t),o=new $a(s,t.layoutContext),a=D("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=zt(e.formattingContext);if(n.getRootViewNode(e)){if(i){let r=n.getRepetitiveElements();r&&e.sourceNode!==n.tableSourceNode&&!e.after&&!r.isFooterRegistered()&&r.preventSkippingHeader(),Rf(e.parent,t)}return new tx(n,this).layout(e,t)}else return t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new G0(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return ga(e),!1}finishBreak(e,t,i,n){let r=zt(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode),o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!o.includes(a.cell)),o.length){let a=D("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let u=o[h++],c=r.getCellFragmentOfCell(u),p=c.findAcceptableBreakPosition().nodeContext,f=c.cellNodeContext,g=f.toNodePosition(),y=new Bi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:y,cell:u});let b=f.viewNode;c.column.layoutContext.processFragmentedBlockEdge(c.cellNodeContext),s<u.rowIndex+u.rowSpan-1&&(b.rowSpan=s-u.rowIndex+1),c.empty?l.continueLoop():c.pseudoColumn.finishBreak(p,!1,!0).then(()=>{ex(c,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),ga(t),r.finishFragment(),a.finish(!0)}),a.result()}}return ga(t),r.finishFragment(),Ul.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Nn.prototype.clearOverflownViewNodes(e,t,i,n)}};function ex(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,s=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=$t(s.clientLayout,a,r),l=s.getComputedPaddingBorder(a);if(r){let u=h.right-s.footnoteEdge-n.calculateOffset(i)-l.right;A(o,"max-width",`${u}px`)}else{let u=s.footnoteEdge-n.calculateOffset(i)-h.top-l.top;A(o,"max-height",`${u}px`)}}function Vf(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 s=n[r].style.position;if(s!=="absolute"&&s!=="fixed")return}A(i,"display","contents")}}function ga(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],s=Array.from(t.children).indexOf(r),o=Array.from(r.children).reduce((c,p)=>{let f=p.rowSpan;return f>1&&s+f<t.childElementCount?Math.max(c,f):c},0),a=o?t.children[s+o-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;A(a,e.vertical?"width":"height",`${u}px`)}var tx=class extends Wl{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new ix(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new sx(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()}},ix=class extends If{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},nx=class extends Jr{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 rx(this.position.sourceNode))}},rx=class $f{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,_r.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return I(!0)}equalsTo(t){return t instanceof $f&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},sx=class extends Af{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new ox(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},ox=class Hf extends ah{constructor(t){super(t),d(this,"flagmentLayoutConstraintType","TableRow"),d(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||kn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!Lf(t,i,r):!0}nextCandidate(t){let i=zt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let s=zt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,s),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,r)})}),!t){let o=s.getRootViewNode(this.nodeContext);new zf().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=zt(this.nodeContext.formattingContext),r=D("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),o=0;return r.loop(()=>{if(o<s.length){let a=s[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return I(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let s=0;s<n;s++)i.cellFragments[s]&&i.cellFragments[s].forEach(o=>{o&&r.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=zt(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Hf?zt(this.nodeContext.formattingContext)===zt(t.nodeContext.formattingContext):!1}},ax=new zf;function lx(e,t,i,n,r,s){if(!t)return null;if(i===v.table){let o=e.parent;return new On(o?o.formattingContext:null,e.sourceNode)}return null}function hx(e){return e instanceof On?ax:null}Ot("RESOLVE_FORMATTING_CONTEXT",lx);Ot("RESOLVE_LAYOUT_PROCESSOR",hx);function Bu(e){return e.reduce((t,i)=>t+i,0)/e.length}function ux(e){let t=Bu(e);return Bu(e.map(i=>{let n=i-t;return n*n}))}var cx=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function Dr(e){return e.vertical?e.width:e.height}function zr(e,t){e.vertical?e.width=t:e.height=t}var Uf=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,d(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Dr(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,s)=>s.penalty<r.penalty?s:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new cx(e,t)}preBalance(e){}postBalance(){zr(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let s=r+n-t;A(i.element,"width",`${t}px`),A(i.element,"left",`${s}px`),i.width=t,i.left=s}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(A(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)}},hl=1;function Wf(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(o=>o.computedBlockSize)),s=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return r>s+hl}function Gf(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+hl))-hl;n<Dr(t)?zr(t,n):zr(t,Dr(t)-1)}var dx=class extends Uf{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);zr(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 Mu(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Wf(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Mu(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Dr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Gf(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Dr(this.layoutContainer)+this.originalContainerBlockSize*.1);zr(this.layoutContainer,t)}}};function Mu(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(s=>s.lastLineStride||0)),r=n>0?n/2:6;return i.every(s=>t>s.computedBlockSize+r)}var px=class extends Uf{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 ux(t)}hasNextCandidate(e){return Wf(e)}updateCondition(e){Gf(e,this.layoutContainer)}};function fx(e,t,i,n,r,s,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=s[s.length-1],l=!!(h&&h.pageBreakType);return a||l?new dx(i,n,r,e):t===v.balance_all?new px(i,n,r):(v.balance,null)}}var ma=class{constructor(e,t,i){d(this,"endStuckFixed"),d(this,"endFixed"),d(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},gx=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 ma(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 ma(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new ma(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=mi(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=mi(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function mx(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var yx=class ul{constructor(t,i,n,r,s,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=s,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,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=s.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let u=new ul(t,l.before,n,!1,s,this.isBlock(),a,!0),c=u.styleValue("content");It(c)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=nt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ze(this.breakBefore)&&(s.breakBefore=nt(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new ul(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");It(o)&&(this.afterBox=s)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=_d(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!yr(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}},vx=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()!==v.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let s=n||r.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new yx(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=Kd(i);n&&!Ee(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!")}},_u=class{constructor(e,t,i,n,r,s,o,a,h,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=s,this.counterListener=o,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,o,a,e.lang,h,l),this.offsetMap=new gx;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new vx(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 U(r,Id))}}}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)In(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&&!Y(n)||r&&!Y(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Du.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Du[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Y(n.value)){let a=n.evaluate(this.context);if(a instanceof L){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*Yt.lh/Yt.em;break;default:{let l=Yt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!Y(o.value)){let a=o.evaluate(this.context);if(a instanceof Tt)this.context.rootLineHeight=a.num*s;else if(a instanceof L){let h=a.num;switch(a.unit){case"em":case"rem":h*=s;break;case"%":h*=s/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=Yt[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 d0(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:mx(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},s=this.counterSnapshots[this.counterSnapshots.length-1];if(s&&s.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=mi(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let s=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=s.page,u=l&&!Y(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let o=ve(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,o,r)}r++}if(r>=this.lastOffset)break;let s=n.firstChild;if(s==null){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n===this.root)return}n=s}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,s=Number.POSITIVE_INFINITY,o=!1,a=!1,h=!1,l=t["flow-options"];if(l){let y=$m(l.evaluate(this.context,"flow-options"));o=!!y.exclusive,a=!!y.static,h=!!y.last}let u=t["flow-linger"];u&&(s=jh(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let c=t["flow-priority"];c&&(r=jh(c.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let y=this.boxStack.lastFlowName();f=this.flows[e]=new Bv(e,y)}let g=new Mv(e,i,n,r,s,o,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ze(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 s=this.last.firstChild;if(s==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=nt(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(s=this.last.nextSibling,s)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=s,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,o,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=nt(l.flowChunk.breakBefore,l.breakBefore));let c=this.boxStack.nearestBlockStartOffset(l);if(c===0||o===this.xmldoc.body){let p=a.page,f=p&&!Y(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()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&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){}},Du=["column-count","column-width","column-fill"],oC=`OTTO${new Date().valueOf()}`;function lh(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function wx(e){let t=new gi;for(let i of lh(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function bx(e,t){let i={};for(let n in e)i[n]=ve(e,n).evaluate(t,n);return i}var jf=class{constructor(e){this.properties=e,d(this,"fontTraitKey"),d(this,"src"),d(this,"blobURLs",[]),d(this,"blobs",[]),d(this,"family"),this.fontTraitKey=wx(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 gi;i.append(`@font-face {
|
|
1866
|
+
}`;function Lo(e,t,i){let n=D("fetchFromURL"),r={method:i||"GET",mode:"cors"},s=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=Td([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{o.status>=400?q.warn(`Error fetching ${e} (${o.status}${o.statusText?" "+o.statusText:""})`):q.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function Td(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Yy(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 Zy(e){return URL.createObjectURL(e)}var Fl=class{constructor(e,t){u(this,"parser",e),u(this,"type",t),u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Ht(e);let n=this.resources[e];return typeof n<"u"?I(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 s=Ie("user-agent.xml",Ni),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(Sd)}`),Lo(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=s),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ht(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Yr(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ht(e)]}delete(e){delete this.resources[Ht(e)]}};function Ky(e,t){let i=e.responseText;return I(i?xl(i):null)}function Jy(){return new Fl(Ky,"text")}function kt(e,t,i){let n=new Yr(()=>{let r=D("loadElement"),s=r.suspend(e),o=!1,a=null,h=l=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);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 Kh=0,Qy=16777216,Id=33554432,Ad=50331648,Fd=67108864,ev=83886080,tv=100663296,Oo=class{constructor(e){u(this,"scope",e),u(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n,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 Kh;case"User":return tv;default:return ev}}getBaseSpecificity(){switch(this.flavor){case"UA":return Kh;case"User":return Qy;default:return Id}}},La=class extends Oo{constructor(){super(null),u(this,"stack",[]),u(this,"tokenizer",null),u(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;q.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)}},Jh=class extends Oo{constructor(e,t,i){super(e),u(this,"owner",t),u(this,"topLevel",i),u(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},sn=class extends Jh{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Jh(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())}},He=[],to=[],Se=[],Me=[],_t=[],at=[],$e=[],Ke=[],xe=[],tt=[],ct=[],je=[],Ve=[],yn=55,vn=56,hs=57;He[1]=28,He[36]=29,He[7]=29,He[9]=29,He[14]=29,He[18]=29,He[50]=29,He[20]=30,He[13]=27,He[0]=200,to[1]=46,to[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[50]=42,Se[37]=11,Se[23]=12,Se[35]=56,Se[1]=1,Se[36]=3,Se[7]=5,Se[9]=7,Se[14]=9,Se[12]=13,Se[18]=55,Se[50]=58,Se[16]=41,Me[37]=11,Me[23]=12,Me[35]=56,Me[1]=1,Me[36]=3,Me[7]=5,Me[9]=7,Me[14]=9,Me[18]=55,_t[1]=2,_t[36]=4,_t[7]=6,_t[9]=8,_t[18]=14,_t[50]=42,_t[14]=10,_t[12]=13,$e[1]=15,$e[7]=16,$e[4]=17,$e[5]=18,$e[3]=19,$e[2]=20,$e[8]=21,$e[27]=57,$e[16]=22,$e[19]=23,$e[6]=24,$e[11]=25,$e[17]=26,$e[13]=48,$e[31]=47,$e[23]=54,$e[0]=44,Ke[1]=31,Ke[4]=32,Ke[5]=32,Ke[3]=33,Ke[2]=34,Ke[10]=40,Ke[6]=38,Ke[31]=36,Ke[24]=36,Ke[32]=35,xe[1]=45,xe[16]=37,xe[37]=37,xe[38]=37,xe[47]=37,xe[48]=37,xe[39]=37,xe[49]=37,xe[41]=37,xe[26]=37,xe[25]=37,xe[23]=37,xe[24]=37,xe[19]=37,xe[21]=37,xe[36]=37,xe[18]=37,xe[22]=37,xe[11]=39,xe[12]=43,xe[17]=49,tt[0]=200,tt[12]=50,tt[13]=51,tt[14]=50,tt[15]=51,tt[10]=50,tt[11]=51,tt[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,je[0]=200,je[12]=50,je[13]=51,je[14]=50,je[15]=51,je[10]=50,je[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[yn]=2,Ve[vn]=2;var Zr=class{constructor(e,t,i,n){u(this,"actions",e),u(this,"tokenizer",t),u(this,"handler",i),u(this,"baseURL",n),u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(Be)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,s;do if(s=i[--n],e===")"&&s instanceof pn){if(s.text===")")r++;else if(s.text==="("){if(r===0)return null;r--}}while(typeof s<"u"&&typeof s!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new K(i.slice(n+1,i.length))),e==",")return null;n++;do s=i[--n];while(typeof s<"u"&&(typeof s!="string"||s==","));if(o=i.length-(n+1),s=="("){if(e!=")"&&t.type!==0)return this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=ct,null;let h=new ai(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof he&&h.values[0].name;Xe(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(o>1)return new _e(this.extractVals(",",n+1));let a=i[0];return a instanceof st?a:a?new pn(a.toString()):Be}exprError(e,t){this.actions=this.propName?ct:tt,q.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),s;for(;;){let o=i.pop();if(e==11){let a=[r];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new pm(n.getScope(),h,l);a.unshift(c)}return i.push(new j(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();r=new mr(n.getScope(),xa(l,h),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new Ah(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new Ii(n.getScope(),r);else if(o==-24)r=new Sn(n.getScope(),r);else if(o==-hs)r=new cm(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Ve[e]>Ve[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new El(n.getScope(),s,r);break;case yn:r=new dm(n.getScope(),s,r);break;case vn:r=new fm(n.getScope(),s,r);break;case 25:r=new Pl(n.getScope(),s,r);break;case 38:r=new gm(n.getScope(),s,r);break;case 37:r=new ym(n.getScope(),s,r);break;case 48:r=new mm(n.getScope(),s,r);break;case 47:r=new Ca(n.getScope(),s,r);break;case 39:case 49:r=new Nl(n.getScope(),s,r);break;case 41:r=new vm(n.getScope(),s,r);break;case 23:r=new Fc(n.getScope(),s,r);break;case 24:r=new Rc(n.getScope(),s,r);break;case 36:r=new Tl(n.getScope(),s,r);break;case 19:r=new Lc(n.getScope(),s,r);break;case 21:r=new Oc(n.getScope(),s,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new xm(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new Ah(n.getScope(),s,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(s),i.push(o),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let d=i.nthToken(1),p=i.nthToken(2);if(d.type===1&&p.type===18)i.consume(),i.consume(),r=d.text,n=p.position+1;else{if(d.type===10||d.type===6||d.type===1&&d.text.toLowerCase()==="not"&&(p.type===10||p.type===6))return null;n=e.position+1}}else return null;let s=0,o,a=0;for(;s>=0;)switch(i.consume(),o=i.token(),o.type){case 11:s--;break;case 10:case 6:s++;break;case 16:s===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let h=o.position,l=i.input.substring(n,h),c=t&&r==="selector"&&a>0?"":Xe(r)?l:l.trim();return new Sm(this.handler.getScope(),r,c,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,s=t.type===23||r;if(s&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,s)return null}else if(n<0){if(s)return null}else if(n>=0&&!s)return null;this.tokenizer.consume()}else if(s)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Ut(i,t,new Ii(i,new Je(i,"pref-horizontal")));break;case"horizontal":t=Ut(i,t,new Je(i,"pref-horizontal"));break;case"day":t=Ut(i,t,new Ii(i,new Je(i,"pref-night-mode")));break;case"night":t=Ut(i,t,new Je(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new j(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":case"footnote":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,h=this.valStack,l,c,d,p,f,g,y,b=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&b===null&&(b=l.position-1,a.input[b]==="("&&b++),this.actions===$e&&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 pn(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=ct):(this.actions=at,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=$e,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=ct,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=$e,h.splice(0,h.length);continue;case 29:this.actions=at,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=je,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(d,l.text),r?this.actions=Me:this.actions=Se,a.consume();break;case 36:o.tagSelector(d,null),r?this.actions=Me:this.actions=Se,a.consume();break;default:this.actions=tt,o.error("E_CSS_NAMESPACE",l)}else this.actions=tt,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=je,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),r?this.actions=Me:this.actions=Se,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Me:this.actions=Se,a.consume();break;default:this.actions=tt,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Me:this.actions=Se,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),r?this.actions=Me:this.actions=Se,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Me:this.actions=Se;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=Se:this.actions=je;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){y=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(y.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(y=this.readNthPseudoParams(),y)if(p==="nth-child"||p==="nth-last-child"){if(c=a.nthToken(0),c.type===1&&c.text==="of"){a.consume(),this.actions=at,o.startFuncWithSelector(p,y),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Me:this.actions=Se:this.actions=je;continue}break}else if(p==="nth"){if(c=a.nthToken(0),c.type===1&&c.text==="of")if(a.consume(),c=a.token(),c.type===1)y.push(c.text),a.consume();else break e;break}else break;else break e;default:if(y=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){o.pseudoclassSelector(p,y),a.consume(),r?this.actions=Me:this.actions=Se;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=tt;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),r?this.actions=Me:this.actions=Se,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(y=this.readNthPseudoParams(),y===null)break}else y=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(p,y),r?this.actions=Me:this.actions=Se,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=tt;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:{if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=je,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=je,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=je,o.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:o.attributeSelector(d,p,0,null,null),r?this.actions=Me:this.actions=Se,a.consume();continue;default:this.actions=je,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}let x=p,m=null;switch(l.type){case 1:case 2:{let w=l.text;if(a.consume(),l=a.token(),l.type==1){let S=l.text.toLowerCase();(S=="i"||S=="s")&&(m=S,a.consume(),l=a.token())}o.attributeSelector(d,x,f,w,m);break}default:this.actions=je,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=je,o.error("E_CSS_ATTR",l);continue}r?this.actions=Me:this.actions=Se,a.consume();continue}case 11:o.childSelector(),this.actions=_t,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=_t,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=_t,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=He,a.consume();continue;case 41:o.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 Uc(l.text)),a.consume();continue;case 17:h.push(new Tt(l.num)),a.consume();continue;case 18:h.push(new lt(l.num)),a.consume();continue;case 19:h.push(new L(l.num,l.text)),a.consume();continue;case 20:h.push(new Z(l.text)),a.consume();continue;case 21:h.push(new Qe(Ie(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Wc(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Gn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ke,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(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new pn("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?to:He;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&&o.property(this.propName,g,this.propImportant),!0);case 31:if(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new Je(o.getScope(),xa(l.text,c.text))),this.actions=xe),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Ih(o.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Ih(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==yn&&h[h.length-1]!==vn&&(c.type===10||c.type===6)){h.push(-hs),a.consume();continue}else h.push(new Je(o.getScope(),l.text));this.actions=xe}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=xe;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new it(o.getScope(),l.num)),a.consume(),this.actions=xe;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new Wr(o.getScope(),l.num,p)),a.consume(),this.actions=xe;continue;case 34:h.push(new it(o.getScope(),l.text)),a.consume(),this.actions=xe;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Dc(o.getScope(),l.num)),a.consume(),this.actions=xe);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Ke,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==vn&&h[h.length-2]!==-hs?(this.actions=Ke,this.exprStackReduce(yn,l),h.push(yn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==yn&&h[h.length-2]!==-hs?(this.actions=Ke,this.exprStackReduce(vn,l),h.push(vn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=$e),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=He)),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=He,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=He,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let x=this.readSupportsTest(l);if(x){h.push(x),this.actions=xe;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=He,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ke,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=tt;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=tt;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=tt;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),o.startRuleBody();continue}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=_t;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),o.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(p),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ke,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ke,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ke,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,m=null,w=[];for(l.type==1&&(x=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(m=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;)w.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(x,m,w);break;case"-epubx-partition":o.startPartitionRule(x,m,w);break;case"-epubx-partition-group":o.startPartitionGroupRule(x,m,w);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=je;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=tt;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=tt;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=He;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=He),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){o.nextSelector(),this.actions=at,b=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=He),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===je)switch(l.type){case 16:this.errorBrackets.length==0&&(o.nextSelector(),b=l.position+1,this.actions=at),a.consume();continue;case 11:if(this.errorBrackets.length==0)return o.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)o.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(b,l.position);o.pushSelectorText(x),b=l.position+1}if(l.type===16){o.nextSelector(),this.actions=at,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=Se;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=je;continue}if(this.actions!==tt&&this.actions!==je&&this.actions!==ct){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===$e){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new pn(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ke&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=He,a.consume();continue}else{if(l.type===17&&this.actions==Ke)return this.actions=He,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=ct:this.actions=je;continue}a.consume();continue}}return!1}},Rd=class extends Oo{constructor(e){super(null),u(this,"scope",e)}error(e,t){q.warn(e,t.toString())}getScope(){return this.scope}};function iv(e,t,i,n,r){let s=Ld(t),o=iy(e.input);return o!==e.input?Qh(new bt(o,s),s,i,n,r):Qh(e,s,i,n,r)}function Qh(e,t,i,n,r){let s=D("parseStylesheet"),o=new Zr(He,e,t,i),a=null;return r&&(a=Bd(new bt(r,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),s.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let l=Ie(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let c=D("parseStylesheet.import");return Od(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,c.finish(!0)}),c.result()}let h=s.timeSlice();if(h.isPending)return h}return I(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function Rl(e,t,i,n,r){let s=Ld(t);return Mn("parseStylesheetFromText",o=>{let a=new bt(e,s);iv(a,s,i,n,r).thenFinish(o)},(o,a)=>{q.warn(a,`Failed to parse stylesheet text: ${e}`),o.finish(!1)})}function Ld(e){if(e instanceof La)return e;if(e instanceof sn){if(e.owner)return e.owner;let t=new La;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Od(e,t,i,n){return Mn("parseStylesheetFromURL",r=>{Lo(e).then(s=>{s.responseText?Rl(s.responseText,t,e,i,n).then(o=>{o||q.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{q.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function Ri(e,t,i){let n=new Zr($e,t,new Rd(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function nv(e,t,i){new Zr(to,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Bd(e,t,i){let n=new Zr(Ke,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var rv={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function sv(e){return!!rv[e]}function ov(e,t,i){if(t instanceof we&&t.str==="viv-leader")return new j(t);if(i==="content"&&t instanceof we)return new j(t);let n=t.evaluate(e);switch(typeof n){case"number":return sv(i)?n==Math.round(n)?new lt(n):new Tt(n):new L(n,"px");case"string":return n?i==="content"?new Z(n):Ri(t.scope,new bt(n,null),""):Be;case"boolean":return n?v._true:v._false;case"undefined":return Be}throw new Error("E_UNEXPECTED")}var av="data-vivliostyle-flow-root";function lv(e){return e.getAttribute(av)==="true"}function eu(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 Ar(e){return e===v.absolute||e===v.fixed}function yr(e){return e instanceof ai&&e.name==="running"}function Md(e,t,i,n){return e===v.none||(Ar(t)?(i=v.none,e=eu(e)):(i&&i!==v.none&&!Y(i)||n)&&(e=eu(e))),{display:e,position:t,float:i}}function _d(e,t,i,n){return Md(e,t,i,n).display===v.block}function Bo(e){return e instanceof he||e instanceof K||typeof e=="string"}function Dt(e){if(!Bo(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 hr(e){return Bo(e)?e.toString().includes("list-item"):!1}function hv(e){if(!Bo(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 Dd(e){if(!Bo(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 uv(e,t,i,n,r,s,o){return r=r||s||v.horizontal_tb,!!o||!!i&&i!==v.none&&!Y(i)||Ar(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!Y(n)||!!s&&r!==s}function cv(e){return e===v.relative||e===v.absolute||e===v.fixed}var ti=1e5;function Ll(e){let t=e.element.style;t.columnGap=`${ti-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Mo(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function io(e){return e.element.style.columnCount==="1"}function dv(e){e.element.setAttribute("data-vivliostyle-column","true")}function Fr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/ti)}function Ol(e,t){let i=Fr(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/ti),s=r*ti,o=i*ti;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=ti),e.right-=s,e.left-=o):e.left<-ti/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=ti),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=ti),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function no(e,t){for(let i=0;i<e.length;i++)Ol(e[i],t)}function $t(e,t,i){let n=e.getElementClientRect(t);if(Ol(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Kr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Mo(r),e.getElementClientRect(t)}return n}function pv(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 Oa(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function fv(e){if(!e.hasAttribute("data-vivliostyle-column")&&Oa(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Oa(t))return!0;return!1}function Kr(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(Oa(t))return t;if(i.position==="absolute")break}return null}function gv(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",s=i.previousElementSibling,o=s&&((t=s.style)==null?void 0:t.breakAfter)==="column";if(!r&&!o)return;let a=Kr(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:c,columnGap:d,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=c==="rtl",y=(parseFloat(d)||parseFloat(p)||16)/2,b=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>b.bottom+y:g?x.right<b.left-y:x.left>b.right+y)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${ti}px`)}function us(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?Fr(i,e.vertical):0}function zd(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||us(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&&Kr(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let s=NaN;if(e.style.blockSize=`${r}px`,us(t)){if(e.style.blockSize=`${n}px`,!us(t)){let o=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>o;){let l=(a+h)/2;e.style.blockSize=`${l}px`,us(t)?h=l:a=l}s=a,e.style.blockSize=`${s}px`}}else if(s=parseFloat(i.blockSize),s<r){let o=1/t.clientLayout.layoutUnitPerPixel;s=r+o,e.style.blockSize=`${s}px`}if(isNaN(s)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function mv(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)zd(i,e)}function wn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let s=r.nodeType===1?r:r.parentElement;if(s&&s.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=s.style;if(s.localName==="wbr"||o&&Dt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(s.localName==="br"){let o=s.ownerDocument.createElement("span");s.parentNode.insertBefore(o,s);let a=t.getElementClientRect(o);if(o.remove(),a){let h=[a];no(h,n);let l=h[0],c=n?l.left:l.bottom;if(!isNaN(c)&&c!==0)return c}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,h=s.nextSibling;a.removeChild(s),a.insertBefore(s,h)}let o=$t(t,s,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);no(l,n);let c=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(c.length>0)l=c;else{let d=s?t.getElementComputedStyle(s).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?o=Math.min.apply(null,l.map(d=>d.left)):o=Math.max.apply(null,l.map(d=>d.bottom)),o):NaN}}function Ba(e,t,i){let n=io(t);n&&Mo(t);let r=t.clientLayout.getElementClientRect(e);n&&Ll(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function kn(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Vd(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 Dn="data-adapt-spec";function Bl(e){return!!e.getAttribute(Dn)}function Rt(e){return e?.nodeType!==1?!1:Bl(e)?!0:$d(e)}function $d(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let s=(i=n.style)==null?void 0:i.float;return s==="left"||s==="right"||s==="inline-start"||s==="inline-end"}function tu(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function En(e){let t=e?.viewNode;return t?.nodeType===1&&Bl(t)}function yv(e){return e!=="inline"&&(Dt(e)||Dd(e))}function iu(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 vv(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 Hd(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},s=e[n];Object.keys(s).forEach(o=>{r[o]=s[o].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Ud(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let s=r[i||"ltr"];if(!s)throw new Error(`unknown direction: ${i}`);for(let o of s){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var Wd={"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"}]}},wv=Hd(Wd,!0);function Gd(e,t,i){return Ud(e,t,i||null,wv)}var bv=Hd(Wd,!1);function jd(e,t,i){return Ud(e,t,i||null,bv)}var xv={"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 Sv(e,t){let i=xv[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 Ml(e,t,i){var n;let r=t,s={width:r.style.width,height:r.style.height};function o(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=o("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function c(p,f){r.style[p]=f;let g=o(p);return r.style[p]=s[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=c(h,"max-content");break;case"min-content inline size":f=c(h,"min-content");break;case"fit-content inline size":f=c(h,"fit-content");break;case"max-content block size":f=c(l,"max-content");break;case"min-content block size":f=c(l,"min-content");break;case"fit-content block size":f=c(l,"fit-content");break;case"max-content width":f=c("width","max-content");break;case"max-content height":f=c("height","max-content");break;case"min-content width":f=c("width","min-content");break;case"min-content height":f=c("height","min-content");break;case"fit-content width":f=c("width","fit-content");break;case"fit-content height":f=c("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function Pn(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 Xd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function qd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function St(e,t){let i=Xd(e);i.includes(t)||(i.push(t),qd(e,i))}function Cv(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function kv(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function sa(e,t){let i=Cv(e);i.includes(t)||(i.push(t),kv(e,i))}function Ev(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var Ma={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ze(e){return!!Ma[e]}var Pv={left:!0,right:!0,recto:!0,verso:!0};function en(e){return!!Pv[e]}function nu(e){return Ze(e)&&e!=="column"&&e!=="region"}var Nv={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ro(e){return!!Nv[e]}function nt(e,t){if(e)if(t){if(en(t))return t;if(en(e))return e;{let i=Ze(e),n=Ze(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:ro(t)?t:ro(e)?e:t}}else return e;else return t}function ru(e){return Ze(e)?e:"auto"}Ot("SIMPLE_PROPERTY",Ev);var vr=$g(Ug());function Tv(e,t){return(0,vr.default)(e,t,0)}function su(e){return e.reduce((t,i)=>i[0]===vr.default.DELETE?t:t+i[1],"")}function Iv(e,t){return Yd(e,t,1)}function Av(e,t){return Yd(e,t,-1)}function Yd(e,t,i){let n=0,r=0;return e.some(s=>{for(let o=0;o<s[1].length;o++){switch(s[0]*i){case vr.default.INSERT:n++;break;case vr.default.DELETE:n--,r++;break;case vr.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var _a;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(_a||(_a={}));var Fn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(Fn||(Fn={}));var so;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(so||(so={}));var Yi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||Li.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||Li.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Yi||(Yi={}));var Li;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(Li||(Li={}));var yi;(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={}))})(yi||(yi={}));var Fv={transform:!0,"transform-origin":!0},Rv={top:!0,bottom:!0,left:!0,right:!0},_l=class{constructor(e,t,i){u(this,"target",e),u(this,"name",t),u(this,"value",i)}},Lv={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 Ov(e,t){let i=Lv[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Da=class ur extends Cl{constructor(t,i){super(),u(this,"container",t),u(this,"bleedBox",i),u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(s){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:s,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(ur.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(ur.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(ur.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(ur.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(s=>{let o=this.elementsById[s];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[s]});let n=this.delayedItems;for(let s=0;s<n.length;s++){let o=n[s];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||A(o.target,o.name,o.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let s=0;s<t.length;s++){let o=t[s],a=this.elementsById[o.ref],h=this.elementsById[o.observer];if(a&&h){let l=Ov(a,o.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(o.event,l,!1)}}}};u(Da,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Da,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Zd=Da,wt=yi.Whitespace;function Kd(e){switch(e){case"normal":case"nowrap":return wt.IGNORE;case"pre-line":return wt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return wt.PRESERVE;default:return null}}function Ee(e,t){return e?e.nodeType==1?!1:Jd(e.textContent,t):!0}function Jd(e,t){switch(t){case wt.PRESERVE:return e.length==0;case wt.NEWLINE:return!!e.match(/^[ \t]*$/);case wt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var Bv=class{constructor(e,t){u(this,"flowName",e),u(this,"parentFlowName",t),u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Mv=class{constructor(e,t,i,n,r,s,o,a,h){u(this,"flowName",e),u(this,"element",t),u(this,"startOffset",i),u(this,"priority",n),u(this,"linger",r),u(this,"exclusive",s),u(this,"repeated",o),u(this,"last",a),u(this,"breakBefore",h),u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function _v(e,t){return e.top-t.top}function Dv(e,t){return t.right-e.right}function Qd(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===yi.ShadowType.ROOTLESS&&t.shadowType===yi.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&za(e.shadowContext,t.shadowContext)&&za(e.nodeShadow,t.nodeShadow)&&Qd(e.shadowSibling,t.shadowSibling)}function Oi(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(!Qd(e.steps[i],t.steps[i]))return!1;return!0}function zv(e){return{steps:[{node:e,shadowType:ot.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function oo(e,t){return{steps:[{node:e.sourceNode,shadowType:ot.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ao(e,t){let i=new bn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ao(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var ot=yi.ShadowType,Rs=class{constructor(e,t,i,n,r,s,o){u(this,"owner",e),u(this,"root",t),u(this,"xmldoc",i),u(this,"parentShadow",n),u(this,"type",s),u(this,"styler",o),u(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&za(this.parentShadow,e.parentShadow):!1}};function za(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Vv=class{constructor(e,t){u(this,"outer",e),u(this,"count",t)}},bn=class ep{constructor(t,i,n){u(this,"sourceNode",t),u(this,"parent",i),u(this,"boxOffset",n),u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=ot.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Fn.FloatReference.INLINE,this.whitespace=i?i.whitespace:wt.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=Fn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:wt.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,this.pageType=this.parent?this.parent.pageType:null}cloneItem(){let t=new ep(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.pageType=this.pageType,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,s=[];r.shadowType===yi.ShadowType.ROOTLESS&&(r.floatReference!==Fn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&s.push(r.toNodePositionStep()),r=r.parent;while(r);let o=this.preprocessedTextContent?Av(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:s,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Bi=class tp{constructor(t){u(this,"primary",t),u(this,"floats",null)}clone(){let t=new tp(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(!Oi(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(!Oi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},$v=class ip{constructor(t,i){u(this,"chunkPosition",t),u(this,"flowChunk",i)}clone(){return new ip(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Hv=class np{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new np,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}},Uv=class rp{constructor(){u(this,"page",0),u(this,"flows",{}),u(this,"flowPositions",{}),u(this,"isBlankPage",!1),u(this,"highestSeenOffset",0),u(this,"highestSeenNode"),u(this,"lookupPositionOffset")}clone(){let t=new rp;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}},sp=class{constructor(e){u(this,"element",e),u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,A(this.element,"top",`${e}px`),A(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,A(this.element,"left",`${e}px`),A(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):Al(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 sd(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)}},Rr=class extends Zt{constructor(e,t,i,n){super(),u(this,"elem",e),u(this,"context",t),u(this,"rootContentValue",i),u(this,"exprContentListener",n)}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof Qe)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr();if(t instanceof we){let n=t;if(typeof n.getContentList=="function"){let r=n.getContentList();if(r)return r.visit(this),null}}let 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 we&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function It(e){return e!=null&&e!==Be&&e!==v.normal&&e!==v.none&&!Y(e)}var Te=Fn.FloatReference,Wv=20;function Gv(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Ai(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function oa(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=jd(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=Gd(e,r,i),o=Sv(s,r);o==="line-left"?e="left":o==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(q.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var op=class{constructor(e,t,i,n,r,s){u(this,"nodePosition",e),u(this,"floatReference",t),u(this,"floatSide",i),u(this,"clearSide",n),u(this,"flowName",r),u(this,"floatMinWrapBlock",s),u(this,"order",null),u(this,"id",null),u(this,"insidePageFloatArea",!1),u(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}},jv=class{constructor(){u(this,"floats",[]),u(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Oi(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=>Oi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let s=r.nodePosition.steps;if(!(s!=null&&s.length)||s.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let o=Math.min(s.length,i.length);for(let a=0;a<o;a++)if(s[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},ap=class{constructor(e,t,i,n,r,s){u(this,"floatReference",e),u(this,"floatSide",t),u(this,"clearSide",i),u(this,"continuations",n),u(this,"area",r),u(this,"continues",s)}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},ou=class{constructor(e,t){u(this,"float",e),u(this,"nodePosition",t)}equals(e){return e?this===e?!0:this.float===e.float&&Oi(this.nodePosition,e.nodePosition):!1}},xn=class{constructor(e,t,i,n,r,s,o){u(this,"parent",e),u(this,"floatReference",t),u(this,"container",i),u(this,"flowName",n),u(this,"generatingNodePosition",r),u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),u(this,"footnoteMaxBlockSize",null),u(this,"ignoreFootnoteAreaMaxHeight",!1),u(this,"footnoteAnchorsSeen",new Set),u(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Y(s)&&s||e&&e.writingMode||v.horizontal_tb,this.direction=!Y(o)&&o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new jv;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let s=r-1;s>=0;s--){let o=this.children[s];if(o.floatReference===t&&o.flowName===i&&Oi(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new zn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],s=r.area&&r.area.element;s&&s.parentNode&&s.parentNode.removeChild(s),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&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)}findPageFloatAnchor(e){var t;for(let i=this.children.length-1;i>=0;i--){let n=this.children[i].findPageFloatAnchor(e);if(n)return n}return(t=this.floatAnchors[e])!=null?t:null}hasCurrentAnchor(e){var t,i;let n=this.findPageFloatAnchor(e);return n?!!((i=(t=this.container)==null?void 0:t.element)!=null&&i.contains(n)):!1}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.findPageFloatAnchor(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 s=r.float,o=s.getOrder();o>t&&(!i||o>i.getOrder())&&(i=s)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}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&&fv(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<Wv?!1:(this.footnoteMaxBlockSize=t,!0)}initFootnoteRetryFromEmptyFragment(e,t){if(!("footnotePolicy"in e&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(e.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(t.vertical?t.width:t.height)+t.getInsetBefore()+t.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i){let n=t.area&&"isFootnote"in t.area&&t.area.isFootnote;if(this.locked)this.invalidate();else{if(n&&this.footnoteAnchorsSeen.has(i.getId())&&this.hasMultiColumnFootnoteContext()){let r=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Te.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if(this.floatReference===Te.PAGE&&"footnotePolicy"in t&&t.footnotePolicy===v.line&&this.hasCurrentAnchor(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 jd(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Gd(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],r=!1,s=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?r||(i.slice(o+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),s=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],s=this.toLogicalFloatSides(r.floatSide)[0];(s===i||i==="snap-block"&&s==="block-end"||i==="snap-inline"&&s==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,s=!0){this.container;let o=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),c=this.getLimitValueInner(o,h,i,n,r);if(s&&this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,l,i,n,r,s);switch(a){case"top":return Math.max(c,d);case"left":return Math.max(c,d);case"bottom":return Math.min(c,d);case"right":return Math.min(c,d);default:}}return c}getLimitValueInner(e,t,i,n,r){this.container;let s=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?s.right:s.top;case"block-end":return this.container.vertical?s.left:s.bottom;case"inline-start":return this.container.vertical?this.container.rtl?s.bottom:s.top:this.container.rtl?s.right:s.left;case"inline-end":return this.container.vertical?this.container.rtl?s.top:s.bottom:this.container.rtl?s.left:s.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){var s,o,a,h;this.container;let l=this.container.originX,c=this.container.originY,d=this.container.getPaddingRect(),p={top:d.y1-c,left:d.x1-l,bottom:d.y2-c,right:d.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let y=parseFloat((o=(s=this.container.element)==null?void 0:s.style)==null?void 0:o.width);isFinite(y)&&y>this.container.width&&(p.right+=y-this.container.width)}else{let y=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(y)&&y>this.container.height&&(p.bottom+=y-this.container.height)}function f(y,b,x){return y.unit==="%"?x*y.num/100:e.convertLengthToPx(y,b,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((y,b)=>{if(i&&!i(b,this))return y;let[x,m]=this.toLogicalFloatSides(b.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||r&&m.includes("block")===r.includes("block")&&m!==r))return y;let w=b.area,S=b.continuations[0].float.floatMinWrapBlock,C=w.vertical?w.left+w.getInsetLeft()+w.width+w.getInsetRight():w.top+w.getInsetTop()+w.height+w.getInsetBottom(),T=w.vertical?w.top+w.getInsetTop()+w.height+w.getInsetBottom():w.left+w.getInsetLeft()+w.width+w.getInsetRight(),R=y.top,F=y.left,z=y.bottom,$=y.right,X=y.floatMinWrapBlockStart,re=y.floatMinWrapBlockEnd;switch(x){case"inline-start":w.vertical?R=Math.max(R,T):F=Math.max(F,T);break;case"block-start":w.vertical?(S&&w.left<$&&(X=f(S,w.rootViewNodes[0],d.x2-d.x1)),$=Math.min($,w.left)):(S&&C>R&&(X=f(S,w.rootViewNodes[0],d.y2-d.y1)),R=Math.max(R,C));break;case"inline-end":w.vertical?z=Math.min(z,w.top):$=Math.min($,w.left);break;case"block-end":w.vertical?(S&&C>F&&(re=f(S,w.rootViewNodes[0],d.x2-d.x1)),F=Math.max(F,C)):(S&&w.top<z&&(re=f(S,w.rootViewNodes[0],d.y2-d.y1)),z=Math.min(z,w.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:R,left:F,bottom:z,right:$,floatMinWrapBlockStart:X,floatMinWrapBlockEnd:re}},p)),p.left+=l,p.right+=l,p.top+=c,p.bottom+=c,p}setFloatAreaDimensions(e,t,i,n,r,s,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,s,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0].includes("block")&&!o[a[0]])return null;e.clientLayout;let h=a.find(C=>C.includes("inline")&&o[C==="inline-start"?"inline-end":"inline-start"]),l=a.find(C=>C.includes("block")),c=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,y=e.vertical?e.originY:e.originX;e.isFootnote||(c=e.vertical?Math.min(c,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(c,e.top+g),d=e.vertical?Math.max(d,e.left+g):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g));function b(C,T){let R=C(e.bands,T);return R?(e.vertical&&(R=id(R)),c=e.vertical?Math.min(c,R.x2):Math.max(c,R.y1),d=e.vertical?Math.max(d,R.x1):Math.min(d,R.y2),!0):s}let x,m,w,S;if(r){let C=e.vertical?eo(new Lt(d,p,c,f)):new Lt(p,c,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!b(Mm,C)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!b(_m,C)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?c=Math.min(c,n):c=Math.max(c,n)),w=(d-c)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(w=Math.min(w,this.footnoteMaxBlockSize),e.vertical?c=d+w:c=d-w),x=Math.max(0,w-e.getInsetBefore()-e.getInsetAfter()),S=(f-p)*e.getInlineDir(),m=S-e.getInsetStart()-e.getInsetEnd(),!s&&(x<=0||m<=0)))return null}else{let C=e.getContentBlockMarginAfter();x=Math.max(0,e.computedBlockSize+Math.min(0,C)),w=x+e.getInsetBefore()+e.getInsetAfter();let T=(d-c)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let F=this.container.getPaddingRect(),z=this.container.getBoxDir()*(n-(this.container.vertical?F.x2:F.y1)),$=this.container.getBoxDir()*((this.container.vertical?F.x1:F.y2)-n-w);z<=$?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!s&&T<w)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?m=Ml(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?m=e.getContentInlineSize():m=e.vertical?e.height:e.width,S=m+e.getInsetStart()+e.getInsetEnd();let R=(f-p)*e.getInlineDir();if(!s&&R<S)return null}return c-=g,d-=g,p-=y,f-=y,a.some(C=>C==="inline-start"||C==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,m):(a.some(C=>C==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-S*e.getInlineDir(),m),a.some(C=>C==="block-start"||C==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(c,x):(a.some(C=>C==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-w*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(s=>s.floatSide.includes("block-start")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x1:o.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let s=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.min(r,s):Math.max(r,s):s)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-end")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x2:o.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let s=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.max(r,s):Math.min(r,s):s)}return r}getPageFloatClearEdge(e,t){let i=c=>{let d=this.toLogicalFloatSides(c),p=d[0];return e==="both"?p==="block-end":e==="inline-start"?d.includes("inline-end")||p==="block-end":e==="inline-end"?d.includes("inline-start")||p==="block-start"||p==="block-end":!1};function n(c){return d=>!i(d.float.floatSide)&&c.isAnchorAlreadyAppeared(d.float.getId())}function r(c,d){return i(c.floatSide)?!1:c.continuations.some(n(d))}let s=t.getPaddingRect(),o=t.vertical?s.x1:s.y2,a=this;for(;a;){if(a.floatsDeferredToNext.some(n(a)))return o;a=a.parent}function h(c){return c.floatFragments.some(d=>r(d,c))||c.children.some(d=>h(d))}if(e==="column"||e==="region"||e==="page"){for(a=this;a;a=a.parent)if(a.floatReference===e){if(h(a))return o;break}}t.clientLayout;let l=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,r);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,r)*t.getBoxDir()<o*t.getBoxDir()?o:l}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],s=this.toLogical(i),o;s==="all"?o=["block-start","block-end","inline-start","inline-end"]:s==="both"?o=["inline-start","inline-end"]:s==="same"?r==="snap-block"?o=["block-start","block-end"]:o=[r]:o=[s];let a=e.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function c(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(h(p))||c(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(h(null))||l(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return o.forEach(d=>{switch(d){case"block-start":n[d]=!l(this,d);break;case"block-end":n[d]=!c(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(h(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);r?e.vertical?(o.right<r.right&&(r.right=o.right,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>r.left&&(r.left=o.left,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>r.top&&(r.top=o.top,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<r.bottom&&(r.bottom=o.bottom,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):r=o,n=n.parent}let s=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=s}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},er=[],zn=class{static register(e){er.push(e)}findByNodeContext(e){for(let t=er.length-1;t>=0;t--){let i=er[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=er.length-1;t>=0;t--){let i=er[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Xv=class{appliesToNodeContext(e){return Ai(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition(),o=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new op(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=o,o){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),I(h)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new ap(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return I(void 0)}forbid(e,t){}};zn.register(new Xv);var lp="data-vivliostyle-footnote-first-ref",hp="data-vivliostyle-footnote-referenced";function lo(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function Et(e){if(e.localName!=="aside")return!1;if(lo(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return lo(t,"footnote")}function Wt(e){if(e.localName!=="a")return!1;if(lo(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return lo(t,"noteref")}function Dl(e,t){if(!Wt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=Zs(i,t);return n==="#"?null:n}function up(e,t,i){let n=Dl(e,t);if(!n)return null;let r=i(n);return r&&Et(r)?r:null}function qv(e,t,i,n,r){if(r.value)return;let s=e.getElementsByTagName("a");for(let o=0;o<s.length;o++){let a=s.item(o),h=Dl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function au(e,t,i,n,r){if(e.localName!=="a"||!Wt(e))return!0;let s=Dl(e,t);if(!s)return!0;qv(e.ownerDocument,t,i,n,r);let o=n.get(s);return o==null||i(e)===o}function zl(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===v.inline?t.createCascadeValue(v.inline,n.priority):null}function Yv(e,t,i,n,r,s,o){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)||!Wt(a))return t;let h=up(a,n,r);if(!h)return t;let l=a.getAttribute(s);l?(e.setAttribute(s,l),h.setAttribute(s,l)):(e.removeAttribute(s),h.removeAttribute(s));let c=o.getStyle(h);if(!c)return t;let d={...t},p=zl(c,o),f=o.getProp(c,"footnote-policy"),g=o.getStyleMap(c,"_pseudos"),y=g?.after;if(p&&(d["footnote-display"]=p),f&&(d["footnote-policy"]=f),y){let b=o.getMutableStyleMap(d,"_pseudos");b.after={...y}}return d}function Zv(e,t,i,n,r){var s;if(!(i?.type===ot.ROOTED&&Et(e)))return t;let o=r.getStyle(e);if(!o)return t;let a={...t},h=zl(o,r),l=r.getProp(o,"footnote-policy"),c=r.getStyleMap(o,"_pseudos"),d=c?.["footnote-marker"],p=r.getProp(d,"content"),f=r.getProp(d,"list-style-position");if(h&&(a["footnote-display"]=h),l&&(a["footnote-policy"]=l),p&&((s=f?.evaluate)==null?void 0:s.call(f,n,"list-style-position"))===v.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(M("list-item"),0),a["list-style-position"]=r.createCascadeValue(v.outside,0),a["list-style-type"]=r.createCascadeValue(v.none,0),a["list-style-image"]=r.createCascadeValue(v.none,0)}return a}function Kv(e,t,i){var n,r;let s=t?.type===ot.ROOTED&&Et(e)?i.getStyle(e):null;return{sourceStyle:s,footnoteDisplay:((n=zl(s,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(s,"footnote-policy"))==null?void 0:r.value)||null}}function cp(e,t){if(e instanceof j){let i=e.expr.evaluate(t);return typeof i=="string"?new Z(i):typeof i=="number"?new Z(String(i)):e}return e instanceof K?new K(e.values.map(i=>cp(i,t))):e}function Jv(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=cp(n.value,i))}function Qv(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Wt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let s=r.hash.substring(1),o=e.getElementById(s);if(o&&Et(o)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(lp,"true")),o.setAttribute(hp,"true")}}}Ot("PREPROCESS_SINGLE_DOCUMENT",Qv);var ew=ap,tw=.1,ho=class dp extends op{constructor(t,i,n,r,s,o){super(t,i,"block-end",null,n,s),u(this,"footnotePolicy",r),u(this,"policyAnchorNode",o)}isAllowedToPrecede(t){return!(t instanceof dp)}};function iw(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}function pp(e){return e?-1:1}function Va(e,t){return t?e.right:e.top}function Vl(e,t){return t?e.left:e.bottom}function fp(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function gp(e,t){let i=fp(e.getBoundingClientRect());return Ol(i,t),i.right<i.left||i.bottom<i.top?null:i}function $a(e,t){let i=Array.from(e,fp);return no(i,t),i.filter(n=>n.right>n.left&&n.bottom>n.top)}function mp(e,t){return e.length?t?Math.min(...e.map(i=>i.left)):Math.max(...e.map(i=>i.bottom)):NaN}function nw(e,t){if(!e.length)return NaN;let i=pp(t),n=e.reduce((r,s)=>Va(s,t)*i<Va(r,t)*i?s:r);return Vl(n,t)}function rw(e,t){if(!e)return NaN;if(e.nodeType===Node.ELEMENT_NODE){let s=gp(e,t);return s?Vl(s,t):NaN}let i=e.textContent||"";if(!i.length)return NaN;let n=e.ownerDocument.createRange();n.setStart(e,0),n.setEnd(e,i.length);let r=$a(n.getClientRects(),t);return mp(r,t)}function sw(e,t){let i=e.viewNode;if(!i)return NaN;if(i.nodeType===Node.ELEMENT_NODE){let a=i;if(e.after||!e.inline){let l=gp(a,t);if(l)return e.after?Vl(l,t):Va(l,t)}let h=$a(a.getClientRects(),t);return nw(h,t)}let n=i.textContent||"";if(!n.length)return NaN;let r=e.offsetInNode;e.after&&(r+=n.length),r=Math.max(0,Math.min(r,n.length-1));let s=i.ownerDocument.createRange();s.setStart(i,r),s.setEnd(i,r+1);let o=$a(s.getClientRects(),t);return mp(o,t)}var lu=class extends ew{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof ho?!0:this.getOrder()<e.getOrder()}},ow=class{constructor(e,t,i){u(this,"footnote",e),u(this,"vertical",i),u(this,"anchorEdge"),this.anchorEdge=rw(t,i)}allowLayout(e){if(!isNaN(this.anchorEdge)){let i=sw(e,this.vertical);if(!isNaN(i)){let n=pp(this.vertical);return i*n<this.anchorEdge*n-tw}}let t=e.toNodePosition();return!Oi(t,this.footnote.nodePosition)}},aw=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof ho}createPageFloat(e,t,i){var n;let r=Te.REGION,s=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(s)&&(r=Te.PAGE);let o=!!t.generatingNodePosition;o&&r!==Te.PAGE&&(r=Te.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Wt(l)&&(h=l),h=iw(h);let c=new ho(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(c.insidePageFloatArea=o,o){let d=t.generatingNodePosition;d&&(c.parentPageFloat=t.findPageFloatByNodePosition(d))}return t.addPageFloat(c),I(c)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new lu(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof lu);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 s,o;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((s=i.clientLayout.getElementComputedStyle(n))==null?void 0:s.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"],c=getComputedStyle(n);for(let d of l){let p=c.getPropertyValue(d);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||A(n,d,`${Math.max(0,f-h)}px`)}}A(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){A(n,"max-block-size",""),A(n,e.vertical?"max-width":"max-height","");break}a=(o=a.parent)!=null?o:null}return I(void 0)})}forbid(e,t){let i=e;if(i.footnotePolicy===v.line){let n=t.collectPageFloatAnchors()[i.getId()]||null,r=new ow(i,n,t.getContainer(i.floatReference).vertical);t.addLayoutConstraint(r,i.floatReference)}}};zn.register(new aw);var $l=class{calculateOffset(e){return Rn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Rn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Jr=class extends $l{constructor(e,t,i,n){super(),u(this,"position",e),u(this,"breakOnEdge",t),u(this,"overflows",i),u(this,"computedBlockSize",n),u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(ro(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=wn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let s=r.style.borderCollapse==="collapse",o=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!s)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!s&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},tr=class{find(e){let t=Gt("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()}`)}},Nn=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 Jr(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===yi.ShadowType.ROOTLESS&&En(i))return;let s=i.viewNode;((r=s.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(s=s.parentElement.parentElement);let o=s.parentNode;Vd(o,s),n&&o.removeChild(s)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),I(!0)}},Hl=class{constructor(e){u(this,"parent",e),u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Ul=new Nn,lw=_a.isInstanceOfBlockFormattingContext;Ot("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,s)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&_d(i,n,r,s)?new Hl(o?o.formattingContext:null):null});Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Hl?Ul:null);var Wl=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=D("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let s=n.accept(r,t);s=n.postLayout(r,this.initialPosition,t,s),s?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},hw=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){}},Ha=class{constructor(e,t){u(this,"strategy",e),u(this,"layoutContext",t)}iterate(e){let t=this.strategy,i=t.initialState(e),n=D("LayoutIterator");return n.loopWithFrame(r=>{let s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ee(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?s=t.afterIgnoredTextNode(i):s=t.startIgnoredTextNode(i):i.nodeContext.after?s=t.afterNonElementNode(i):s=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?s=t.afterInlineElementNode(i):s=t.startInlineElementNode(i):i.nodeContext.after?s=t.afterNonInlineElementNode(i):s=t.startNonInlineElementNode(i):i.nodeContext.after?s=t.afterNonDisplayableNode(i):s=t.startNonDisplayableNode(i);let o=(s&&s.isPending()?s:I(!0)).thenAsync(()=>i.break?I(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},wr=class extends hw{constructor(e){super(),u(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&&Ze(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:I(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),I(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:I(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakAfter)),I(!0)))}},Ua=[];function uw(){Ua=[]}var cs;function ds(e){if(e==="")return 0;if(cs===void 0){let i=Intl.Segmenter;cs=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(cs===null)return[...e].length;let t=0;for(let i of cs.segment(e))t++;return t}var cw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],dw=new Set(cw);function pw(e){return!(e.toLowerCase()==="none"||dw.has(e))}var fw=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],gw=new Set(fw),mw=["fixed","extends"],yw=new Set(mw);function Qr(e){return e instanceof he&&e.name.toLowerCase()!=="none"}function yp(e){return e.name}function vw(e){if(e instanceof he)return gw.has(e.name);if(e instanceof K&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof he){let n=t.name;return yw.has(n)&&(n==="fixed"&&i instanceof lt||n==="extends"&&Qr(i))}}return!1}function ww(e){let t=dt(e,"system");return t instanceof he&&t.name==="cyclic"}function bw(e){let t=dt(e,"system");if(t instanceof he&&t.name==="fixed")return!0;if(t instanceof K&&t.values.length===2){let[i,n]=t.values;return i instanceof he&&i.name==="fixed"&&n instanceof lt}return!1}function xw(e){let t=dt(e,"system");return t instanceof he?1:t.values[1].num}function Sw(e){let t=dt(e,"system");return t instanceof he&&t.name==="alphabetic"}function Cw(e){let t=dt(e,"system");return t instanceof he&&t.name==="numeric"}function kw(e){let t=dt(e,"system");return t instanceof he&&t.name==="additive"}function Ew(e){let t=dt(e,"system");if(t instanceof K&&t.values.length===2){let[i,n]=t.values;return i instanceof he&&i.name==="extends"&&Qr(n)}return!1}function Pw(e){let t=dt(e,"system");return yp(t.values[1])}function jt(e){return e instanceof Z||e instanceof he}function fi(e){return e instanceof Z?e.str:e.name}function vp(e){if(jt(e))return!0;if(e instanceof K&&e.values.length===2){let t=e.values[0],i=e.values[1];return jt(t)&&jt(i)}return!1}function Nw(e){if(jt(e))return{prefix:fi(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:fi(t),suffix:fi(i)}}}function hu(e){return e instanceof lt||e instanceof he&&e.name==="infinite"}function uo(e,t){return e instanceof lt?e.num:t?-1/0:1/0}function Wa(e){if(!(e instanceof K&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(hu(t)&&hu(i)))return!1;let n=uo(t,!0),r=uo(i,!1);return!(n>r)}function Tw(e){return{lower:uo(e.values[0],!0),upper:uo(e.values[1],!1)}}function wp(e){return e instanceof he&&e.name==="auto"||Wa(e)||e instanceof _e&&e.values.length>=1&&e.values.every(t=>Wa(t))}function Iw(e){return e instanceof he?null:(Wa(e)?[e]:e.values).map(t=>Tw(t))}function co(e){if(!(e instanceof K&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof lt&&t.num>=0&&jt(i)||jt(t)&&i instanceof lt&&i.num>=0}function po(e){let[t,i]=e.values;return t instanceof lt?[t.num,fi(i)]:[i.num,fi(t)]}function bp(e){return co(e)}function Aw(e){let[t,i]=po(e);return{minLength:t,symbol:i}}function xp(e){return jt(e)||e instanceof K&&e.values.length>=1&&e.values.every(t=>jt(t))}function Fw(e){return jt(e)?[fi(e)]:e.values.map(t=>fi(t))}function Sp(e){if(co(e))return!0;if(e instanceof _e&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!co(i))return!1;let[n]=po(i);if(n>=t)return!1;t=n}return!0}return!1}function Rw(e){if(co(e)){let[t,i]=po(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=po(t);return{weight:i,symbol:n}})}var Lw=["auto","bullets","numbers","words","spell-out"],Ow=new Set(Lw);function Bw(e){return e instanceof he&&Ow.has(e.name)||Qr(e)}function Mw(e,t){switch(e){case"system":return vw(t);case"negative":return vp(t);case"prefix":case"suffix":return jt(t);case"range":return wp(t);case"pad":return bp(t);case"fallback":return Qr(t);case"symbols":return xp(t);case"additive-symbols":return Sp(t);case"speak-as":return Bw(t);default:return!0}}function dt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function _w(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Vn(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var Ls,Os,Bs,Ms,_s,Ds,zs,Vs,ps,ci,Cp,fs,kp,gs,Ep,ms,Pp,ys,Np,vs,Tp,ws,Ip,vt,aa,Ap,Fp,uu,cu,la,du,cr,ze=class Ui{constructor(t,i){ie(this,vt),u(this,"_store"),ie(this,Ls),ie(this,Os),ie(this,Bs),ie(this,Ms),ie(this,_s),ie(this,Ds),ie(this,zs),ie(this,Vs),this._store=t;let n=dt(i,"negative");de(this,Ls,n&&vp(n)?Nw(n):null);let r=dt(i,"prefix");de(this,Os,r&&jt(r)?fi(r):null);let s=dt(i,"suffix");de(this,Bs,s&&jt(s)?fi(s):null);let o=dt(i,"range");de(this,Ms,o&&wp(o)?Iw(o):null);let a=dt(i,"pad");de(this,_s,a&&bp(a)?Aw(a):null);let h=dt(i,"fallback");de(this,Ds,h&&Qr(h)?yp(h):null);let l=dt(i,"symbols");de(this,zs,l&&xp(l)?Fw(l):null);let c=dt(i,"additive-symbols");de(this,Vs,c&&Sp(c)?Rw(c):null)}static create(t,i){return ww(i)?new _i(t,i):bw(i)?new Dw(t,i):Sw(i)?new Vw(t,i):Cw(i)?new pu(t,i):kw(i)?new $w(t,i):Ew(i)?new Hw(t,i):new zw(t,i)}static createDecimal(t){var i;return new pu(t,le(i=Ui,ci,Cp).call(i))}static createDisc(t){var i;return new _i(t,le(i=Ui,ci,kp).call(i))}static createSquare(t){var i;return new _i(t,le(i=Ui,ci,Ep).call(i))}static createCircle(t){var i;return new _i(t,le(i=Ui,ci,Pp).call(i))}static createDisclosureOpen(t){var i;return new _i(t,le(i=Ui,ci,Np).call(i))}static createDisclosureClosed(t){return new _i(t,le(this,ci,Tp).call(this))}static createNone(t){var i;return new _i(t,le(i=Ui,ci,Ip).call(i))}static get CHINESE_LONGHAND_NAMES(){return fu.NAMES}static createChineseLonghand(t,i){return new fu(t,i)}static createEthiopicNumeric(t){return new Ww(t)}_getNegative(){return H(this,Ls)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return H(this,Os)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return H(this,Bs)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return H(this,Ms)}static _getRangeFrom(t){return t._getRange()}_getPad(){return H(this,_s)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(H(this,Ds)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return H(this,zs)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return H(this,Vs)}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 le(this,vt,cr).call(this,t,new Set)}formatMarker(t){return le(this,vt,Ap).call(this)+this.format(t)+le(this,vt,Fp).call(this)}};Ls=new WeakMap,Os=new WeakMap,Bs=new WeakMap,Ms=new WeakMap,_s=new WeakMap,Ds=new WeakMap,zs=new WeakMap,Vs=new WeakMap,ps=new WeakMap,ci=new WeakSet,Cp=function(){var e;return(e=H(ze,ps))!=null?e:de(ze,ps,{system:new U(M("numeric"),0),symbols:new U(new K([new Z("0"),new Z("1"),new Z("2"),new Z("3"),new Z("4"),new Z("5"),new Z("6"),new Z("7"),new Z("8"),new Z("9")]),0)})},fs=new WeakMap,kp=function(){var e;return(e=H(ze,fs))!=null?e:de(ze,fs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u2022"),0),suffix:new U(new Z(" "),0)})},gs=new WeakMap,Ep=function(){var e;return(e=H(ze,gs))!=null?e:de(ze,gs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25AA"),0),suffix:new U(new Z(" "),0)})},ms=new WeakMap,Pp=function(){var e;return(e=H(ze,ms))!=null?e:de(ze,ms,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25E6"),0),suffix:new U(new Z(" "),0)})},ys=new WeakMap,Np=function(){var e;return(e=H(ze,ys))!=null?e:de(ze,ys,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25BE"),0),suffix:new U(new Z(" "),0)})},vs=new WeakMap,Tp=function(){var e;return(e=H(ze,vs))!=null?e:de(ze,vs,{system:new U(M("cyclic"),0),symbols:new U(new Z("\u25B8"),0),suffix:new U(new Z(" "),0)})},ws=new WeakMap,Ip=function(){var e;return(e=H(ze,ws))!=null?e:de(ze,ws,{system:new U(M("cyclic"),0),symbols:new U(new Z(""),0),suffix:new U(new Z(""),0)})},vt=new WeakSet,aa=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Ap=function(){var e;return(e=this._getPrefix())!=null?e:""},Fp=function(){var e;return(e=this._getSuffix())!=null?e:". "},uu=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},cu=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},la=function(){var e;return(e=this._getFallback())!=null?e:Vn(this._store)},du=function(e,t){let{minLength:i,symbol:n}=le(this,vt,cu).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=le(this,vt,aa).call(this),o=t?ds(r)+(s?ds(s):0):0,a=i-ds(e)-o;if(a<=0)return e;let h=ds(n),l=Math.ceil(a/h);return n.repeat(l)+e},cr=function(e,t){var i,n,r;if(t.has(this))return le(i=Vn(this._store),vt,cr).call(i,e,new Set);if(t.add(this),!_w(e,le(this,vt,uu).call(this))){let l=le(this,vt,la).call(this);return le(n=l,vt,cr).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let l=le(this,vt,la).call(this);return le(r=l,vt,cr).call(r,e,t)}let h=le(this,vt,du).call(this,a,s);if(s){let{prefix:l,suffix:c}=le(this,vt,aa).call(this);h=l+h+(c??"")}return h},ie(ze,ci),ie(ze,ps,null),ie(ze,fs,null),ie(ze,gs,null),ie(ze,ms,null),ie(ze,ys,null),ie(ze,vs,null),ie(ze,ws,null);var ce=ze,_i=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},$s,Dw=class extends ce{constructor(e,t){super(e,t),ie(this,$s),de(this,$s,xw(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-H(this,$s);return(t=i[n])!=null?t:null}};$s=new WeakMap;var zw=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Vw=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},pu=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},$w=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(s=>s.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:s,symbol:o}=r;if(s===0||s>n)continue;let a=Math.floor(n/s);if(i+=o.repeat(a),n-=s*a,n===0)return i}return null}},br,Ct,Ft,Rp=class extends ce{constructor(t,i){super(t,i),ie(this,Ct),ie(this,br);let n=Pw(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?de(this,br,r):de(this,br,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(le(this,Ct,Ft).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(le(this,Ct,Ft).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(le(this,Ct,Ft).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(le(this,Ct,Ft).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(le(this,Ct,Ft).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(le(this,Ct,Ft).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(le(this,Ct,Ft).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(le(this,Ct,Ft).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(le(this,Ct,Ft).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(le(this,Ct,Ft).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(le(this,Ct,Ft).call(this),t)}};br=new WeakMap,Ct=new WeakSet,Ft=function(e=new Set){var t;if(e.has(this))return Vn(this._store);e.add(this);let i=this._store.get(H(this,br));return i?i instanceof Rp?le(t=i,Ct,Ft).call(t,e):i:Vn(this._store)};var Hw=Rp,Uw=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"];function ir(e){return{suffix:new U(new Z("\u3001"),0),fallback:new U(M("cjk-decimal"),0),range:new U(new K([new lt(-9999),new lt(9999)]),0),negative:new U(new Z(e),0)}}var ha,ua,bs,ca,xs,Ga,Lp,Hs,yt=class Op extends ce{constructor(t,i){var n;let{chars:r,descriptors:s}=le(n=Op,Ga,Lp).call(n).get(i);super(t,s),ie(this,Hs),de(this,Hs,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=H(this,Hs);if(t===0)return i.digits[0];let n=[],r=0,s=t;for(;s>0;)n.unshift({digit:s%10,position:r}),s=Math.floor(s/10),r++;let o=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:c,position:d}=n[l],p=l===n.length-1;c===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[c],d>0&&(a+=i.markers[d])))}return a}};ha=new WeakMap,ua=new WeakMap,bs=new WeakMap,ca=new WeakMap,xs=new WeakMap,Ga=new WeakSet,Lp=function(){var e;return(e=H(yt,xs))!=null?e:de(yt,xs,new Map([["simp-chinese-informal",{chars:H(yt,ha),descriptors:ir("\u8D1F")}],["simp-chinese-formal",{chars:H(yt,ua),descriptors:ir("\u8D1F")}],["trad-chinese-informal",{chars:H(yt,bs),descriptors:ir("\u8CA0")}],["trad-chinese-formal",{chars:H(yt,ca),descriptors:ir("\u8CA0")}],["cjk-ideographic",{chars:H(yt,bs),descriptors:ir("\u8CA0")}]]))},Hs=new WeakMap,ie(yt,Ga),ie(yt,ha,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(yt,ua,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ie(yt,bs,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(yt,ca,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),u(yt,"NAMES",new Set(Uw)),ie(yt,xs,null);var fu=yt,Ss,ja,Bp,Xa,fo,qa,Ya,hi=class Wi extends ce{constructor(t){var i;super(t,le(i=Wi,ja,Bp).call(i))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return H(Wi,fo)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,s="";for(let o=r-1;o>=0;o--){let a=i[o],h=o%2===1,l=o===r-1;if(!(a===0||l&&a===1||h&&a===1)){let c=Math.floor(a/10),d=a%10;s+=H(Wi,Xa)[c]+H(Wi,fo)[d]}h?a!==0&&(s+=H(Wi,qa)):o!==0&&(s+=H(Wi,Ya))}return s}};Ss=new WeakMap,ja=new WeakSet,Bp=function(){var e;return(e=H(hi,Ss))!=null?e:de(hi,Ss,{range:new U(new K([new lt(1),M("infinite")]),0),suffix:new U(new Z("/ "),0)})},Xa=new WeakMap,fo=new WeakMap,qa=new WeakMap,Ya=new WeakMap,ie(hi,ja),ie(hi,Ss,null),ie(hi,Xa,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ie(hi,fo,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ie(hi,qa,"\u137B"),ie(hi,Ya,"\u137C");var Ww=hi,Re,Gw=class{constructor(){ie(this,Re),de(this,Re,new Map),H(this,Re).set("none",ce.createNone(H(this,Re))),H(this,Re).set("decimal",ce.createDecimal(H(this,Re))),H(this,Re).set("disc",ce.createDisc(H(this,Re))),H(this,Re).set("square",ce.createSquare(H(this,Re))),H(this,Re).set("circle",ce.createCircle(H(this,Re))),H(this,Re).set("disclosure-open",ce.createDisclosureOpen(H(this,Re))),H(this,Re).set("disclosure-closed",ce.createDisclosureClosed(H(this,Re)));for(let e of ce.CHINESE_LONGHAND_NAMES)H(this,Re).set(e,ce.createChineseLonghand(H(this,Re),e));H(this,Re).set("ethiopic-numeric",ce.createEthiopicNumeric(H(this,Re)))}define(e,t){if(!pw(e))return null;let i=ce.create(H(this,Re),t);return H(this,Re).set(e,i),i}getStyle(e){var t;return(t=H(this,Re).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Vn(H(this,Re))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Vn(H(this,Re))).formatMarker(t)}};Re=new WeakMap;var Tn=class{constructor(e){u(this,"validator",e),u(this,"success",null),u(this,"failure",null),u(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Di=class{constructor(e,t){u(this,"where",e),u(this,"success",t),u(this,"what",-1)}},nr=class Mp{constructor(){u(this,"nodes",[]),u(this,"connections",[]),u(this,"match",[]),u(this,"nomatch",[]),u(this,"error",[]),u(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Mp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Tn(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 Di(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,s=new Tn(gu);n>=0?i?s.markAsStartAlternate(n):s.markAsEndAlternate(n):i?s.markAsStartGroup():s.markAsEndGroup(),this.nodes.push(s),this.connect(t,r);let o=new Di(r,!0),a=new Di(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new Tn(gu);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Di(0,!0),r=new Di(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 Tn(t));let n=new Di(i,!0),r=new Di(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 s=0;s<t.nodes.length;s++)this.nodes.push(t.nodes[s]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let s=0;s<t.connections.length;s++){let o=t.connections[s];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let s=0;s<t.match.length;s++)this.match.push(t.match[s]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let s=0;s<t.nomatch.length;s++)this.match.push(t.nomatch[s]+r);else if(this.emptyHead){for(let s=0;s<t.nomatch.length;s++)this.nomatch.push(t.nomatch[s]+r);this.emptyHead=t.emptyHead}else for(let s=0;s<t.nomatch.length;s++)this.error.push(t.nomatch[s]+r);for(let s=0;s<t.error.length;s++)this.error.push(t.error[s]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},jw=1,go=2,_p=4,Si=8,Zi=16,$n=32,Ln=64,mo=128,ni=256,ri=512,yo=1024,Dp=2048,zp=4096,vo=8192,Gl=class extends Zt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},ue=class Vp extends Gl{constructor(t,i,n){super(),u(this,"allowed",t),u(this,"idents",i),u(this,"units",n)}visitEmpty(t){return this.allowed&jw?t:null}visitSlash(t){return this.allowed&Dp?t:null}visitStr(t){return this.allowed&go?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&_p||this.allowed&Ln&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&ri)?t.unit=="%"&&this.allowed&yo?t:null:t.num<0&&!(this.allowed&ni)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&ri?t:null:t.num<=0&&!(this.allowed&ni)?null:this.allowed&Zi?t:null}visitInt(t){return t.num==0?this.allowed&ri?t:null:t.num<=0&&!(this.allowed&ni)?null:this.allowed&($n|Zi)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Ln&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&mo?t:null}visitURange(t){return this.allowed&zp?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(t.name.toLowerCase()==="attr"){let i=Yl(t);if(i&&Kw(i.type,this.allowed,this.units))return t}if(this.allowed&Ln){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Yc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&vo){let i=t.visit(new Jc);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Si|Zi|$n|ni|ri|yo)?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 Vp(this.allowed|t.allowed,i,n)}},ee=Object.create(null),Xw=Zi|ni|ri,qw=$n|ni|ri,zi=Si|ni|ri|yo;function es(e){let t=Object.create(null);for(let i of e)t[i]=Be;return t}var _o=es(["%"]),Do=es(["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"]),$p={...Do,..._o},jl=es(["deg","grad","rad","turn"]),Xl=es(["s","ms"]),ql=es(["hz","khz"]);function Yw(e){return e.replace(/\s+/g,"").toLowerCase()}function zo(e){return e.toLowerCase()}function Zw(e){if(e instanceof he)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:zo(e.name)}}if(e instanceof ai&&e.name.toLowerCase()==="type"){if(e.values.length!==1)return null;let t=Yw(e.values[0].stringValue());return t?{kind:"syntax",syntax:t}:null}return null}function Yl(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 he)i=r.name;else if(r instanceof K){let s=r.values;if(s.length<1||s.length>2||!(s[0]instanceof he)||(i=s[0].name,s.length===2&&(n=Zw(s[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(t=e.values[1])!=null?t:null}}function Hp(e,t){return!!e[zo(t)]}function un(e,t){return Object.keys(t).some(i=>Hp(e,i))}function Kw(e,t,i){switch(e.kind){case"string":return!!(t&go);case"url":return!!(t&(mo|vo));case"unit":return Hp(i,e.unit);case"syntax":switch(e.syntax){case"<string>":return!!(t&go);case"<url>":return!!(t&(mo|vo));case"<color>":return!!(t&Ln);case"<integer>":return!!(t&($n|Zi|ni|ri));case"<number>":return!!(t&(Zi|$n|ni|ri));case"<length>":return un(i,Do);case"<length-percentage>":return un(i,$p);case"<percentage>":return un(i,_o);case"<angle>":return un(i,jl);case"<time>":return un(i,Xl);case"<frequency>":return un(i,ql);default:return!1}}return!1}function Za(e){switch(e.kind){case"string":return null;case"url":return null;case"unit":return new ue(zi,ee,{[zo(e.unit)]:Be});case"syntax":switch(e.syntax){case"<color>":return new ue(Ln,ee,ee);case"<integer>":return new ue(qw,ee,ee);case"<number>":return new ue(Xw,ee,ee);case"<length>":return new ue(zi,ee,Do);case"<length-percentage>":return new ue(zi,ee,$p);case"<percentage>":return new ue(zi,ee,_o);case"<angle>":return new ue(zi,ee,jl);case"<time>":return new ue(zi,ee,Xl);case"<frequency>":return new ue(zi,ee,ql);default:return null}}return null}function Jw(e){switch(e.kind){case"string":case"url":case"unit":return!0;case"syntax":return e.syntax==="<string>"||e.syntax==="<url>"||!!Za(e)}return!1}function Qw(e){switch(e.kind){case"url":return new Qe("about:invalid");case"string":return new Z("");default:return v.unset}}function eb(e,t,i){if(t==null)return null;switch(i.kind){case"string":return new Z(t);case"url":return t?new Qe(t):new Qe("about:invalid");case"unit":{let n=Ri(e,new bt(`${t.trim()}${zo(i.unit)}`,null),""),r=Za(i);return n&&r?n.visit(r):null}case"syntax":{if(i.syntax==="<string>")return new Z(t);if(i.syntax==="<url>")return t?new Qe(t):new Qe("about:invalid");let n=Ri(e,new bt(t,null),""),r=Za(i);return n&&r?n.visit(r):null}}return null}var gu=new ue(0,ee,ee),Zl=class extends Gl{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new Tn(null),this.failureTerminal=new Tn(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,s=i,o=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(s>=e.length){r=r.failure;continue}let h=e[s],l=h;if(r.isSpecial()){let c=!0;r.isStartGroup()?(o?o.push(a):o=[a],a=[]):r.isEndGroup()?o.length>0?a=o.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":c=a[r.getAlternate()]==null,r=c?r.success:r.failure}else{if(s==0&&!t&&r.validator instanceof xr&&this instanceof xr){if(l=new K(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof Kl&&this instanceof xr){if(l=new _e(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<s;c++)n[c]=e[c]}e!==n&&(n[s-i]=l),s++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:s==e.length)?n:null}validateSingle(e){let t=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}},xr=class extends Zl{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new K(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Kl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new _e(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Kl=class extends Zl{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new _e(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}},tb=class extends Zl{constructor(e,t){super(t),u(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 ai(e.name,t):null}},mu=class extends Gl{validateSingle(e){return null}visitFunc(e){let t=Yl(e);return t&&Jw(t.type)?e:null}},Up=class{tryParse(e,t,i){return t}success(e,t){}},Wp=class extends Up{constructor(e,t){super(),u(this,"name",t),u(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,s=r>1?new K(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},ib=class extends Wp{constructor(e,t){super(e,t[0]),u(this,"names",t)}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},nb=class extends Up{constructor(e,t){super(),u(this,"nodes",e),u(this,"slash",t)}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Gn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let s=1;s<this.nodes.length&&t<e.length&&(r=this.nodes[s].tryParse(e,t,i),r!=t);s++)t=r;return t}},Vo=class extends Zt{constructor(){super(...arguments),u(this,"syntax",null),u(this,"propList",null),u(this,"error",!1),u(this,"values",{}),u(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Wp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},jn=class extends Vo{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}},Gp=class extends Vo{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 ib(this.validatorSet,this.propList)}},rb=class extends Vo{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Gn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let s=[e[n],e[r]];if(this.syntax[i].tryParse(s,0,this)!=2)return this.error=!0,0}return e.length}},sb=class extends jn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let s=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:v.initial,o=e[r];o||(o=[],e[r]=o),o.push(s)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof _e?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 _e(t[i]);return null}},ob=class extends jn{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 o=this.values["font-weight"],a=o instanceof ai&&o.name==="calc"?e.indexOf(o):-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]===Gn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let s=t==e.length-1?e[t]:new K(e.slice(t,e.length));return s.visit(r["font-family"])?(this.values["font-family"]=s,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new _e(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}},ab=class extends jn{validateList(e){if(e.length===1&&e[0]instanceof he)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[M("no-autospace"),M("space-all")];break}return super.validateList(e)}},lb=class extends Vo{constructor(e,t=[]){super(),u(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=Ri(this.validatorSet.scope,new bt(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 K(e).toString();return this.validateValueText(t)?e.length:0}visitCommaList(e){return this.validateValueText(e.toString()),null}},yu=["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"],jp=class extends jn{constructor(){super()}refreshPropList(){this.propList=this.validatorSet.getPropertiesForAll()}init(e,t){super.init(e,t)}validateList(e){return this.error=!0,0}},vu={SIMPLE:jn,INSETS:Gp,INSETS_SLASH:rb,COMMA:sb,FONT:ob,TEXT_SPACING:ab,ALL:jp},hb=["initial-letter"],ub=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(this,"backgroundProps",{}),u(this,"scope",new Js(null)),u(this,"browserShorthandStyle",null),u(this,"browserShorthandMisses",{}),u(this,"browserPropertyNamesForAll",null),u(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||Xe(r)||yu.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)yu.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},(s,o)=>i.item(o)).filter(s=>!!s);if(!n.length||n.length===1&&n[0]===e.toLowerCase())return null;let r={};for(let s of n)r[s]=i.getPropertyValue(s);return{propList:n,values:r}}getShorthand(e,t){if(Xe(e))return null;let i=this.shorthands[e];if(i)return i instanceof jp&&!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):!wu(t))&&(this.browserShorthandMisses[e]=!0),null;let r=new lb(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 L(t.num,t.text);else if(t.type==7)i=new Uc(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 nr;if(e=="||"){for(let r=0;r<t.length;r++){let s=new nr;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new nr;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 nr;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 nr;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Kl(t);break;case"SPACE":i=new xr(t);break;case"attr":i=new mu;break;default:i=new tb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ue(Ln,ee,ee)),this.namedValidators.ATTR=this.primitive(new mu),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ue(vo,ee,ee)),this.namedValidators.POS_INT=this.primitive(new ue($n,ee,ee)),this.namedValidators.POS_NUM=this.primitive(new ue(Zi,ee,ee)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ue(Si,ee,_o)),this.namedValidators.NEGATIVE=this.primitive(new ue(ni,ee,ee)),this.namedValidators.ZERO=this.primitive(new ue(ri,ee,ee)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ue(yo,ee,ee)),this.namedValidators.POS_LENGTH=this.primitive(new ue(Si,ee,Do)),this.namedValidators.POS_ANGLE=this.primitive(new ue(Si,ee,jl)),this.namedValidators.POS_TIME=this.primitive(new ue(Si,ee,Xl)),this.namedValidators.FREQUENCY=this.primitive(new ue(Si,ee,ql)),this.namedValidators.RESOLUTION=this.primitive(new ue(Si,ee,{dpi:Be,dpcm:Be,dppx:Be})),this.namedValidators.URI=this.primitive(new ue(mo,ee,ee)),this.namedValidators.URANGE=this.primitive(new ue(zp,ee,ee)),this.namedValidators.IDENT=this.primitive(new ue(_p,ee,ee)),this.namedValidators.STRING=this.primitive(new ue(go,ee,ee)),this.namedValidators.SLASH=this.primitive(new ue(Dp,ee,ee));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="",s,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=c=>{if(o)throw new Error(`'${c}': unexpected`);if(r&&r!=c)throw new Error(`mixed operators: '${c}' and '${r}'`);r=c,o=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(o||h(" "),this.isBuiltIn(c.text)){let d=this.namedValidators[c.text];if(!d)throw new Error(`'${c.text}' unexpected`);i.push(d.clone())}else{let d={};d[c.text.toLowerCase()]=M(c.text),i.push(this.primitive(new ue(0,d,ee)))}o=!1;break;case 5:{let d={};d[`${c.num}`]=new lt(c.num),i.push(this.primitive(new ue(0,d,ee))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:r,b:"(",fn:c.text}),r="",i=[],o=!0;break;case 15:{s=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(s),r=d.op,o=!1;break}case 11:{s=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,s)),r=d.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");let d=c.num,p=d;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");p=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new xr(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 Tt(n.num));break;case 5:i.push(new lt(n.num));break;case 3:i.push(new L(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new K(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&vu[i.text]?(n=new vu[i.text],e.consume()):n=new jn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])s.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Gp){let l=this.shorthands[i.text];s.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(s.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:s}),s=[],o=!1;break;case 15:{let l=new nb(s,o),c=a.pop();s=c.syntax,o=c.slash,s.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,h),this.shorthands[t]=n,this.invalidateAllPropertyNames()}}parse(e){let t=new bt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],s=r?r.propList:[n];for(let o of s)i[o]=(t=this.defaultValues[o])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){var r,s;let o=n.ruleType;if(Xe(e)||o==="font-face"){n.simpleProperty(e,t,i);return}if(o==="counter-style"){Mw(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 c=a?h:e;if(wu(t)){this.getShorthand(c,t),n.simpleProperty(h,t,i);return}let d=this.prefixes[e];if(!d||!d[a]){if(CSS.supports(h,t.toString())){let f=(r=this.getShorthand(c,t))==null?void 0:r.clone();f?Y(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t)):n.simpleProperty(h,t,i)}else a&&!wc.includes(`-${a}-`)||n.unknownProperty(h,t);return}else if(hb.includes(e)&&!Object.keys(d).some(f=>Is(f?`-${f}-`:"",e))){n.unknownProperty(h,t);return}let p=this.validators[e];if(p){let f=Y(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=(s=this.getShorthand(e,t))==null?void 0:s.clone();if(!f){n.unknownProperty(h,t);return}Y(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t))}}};function Xp(){let e=new ub;return e.initBuiltInValidators(),e.parse(xd),e}var cb=class extends Zt{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function wu(e){let t=new cb;return e.visit(t),t.varFound}function qp(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var db=class{constructor(e){u(this,"matchers",e)}matches(){return this.matchers.some(e=>e.matches())}},pb=class{constructor(e){u(this,"matchers",e)}matches(){return this.matchers.every(e=>e.matches())}},Yp=class Us{constructor(t,i,n){u(this,"elementOffset",t),u(this,"a",i),u(this,"b",n)}static registerFragmentIndex(t,i,n){let r=Us.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Us.fragmentIndices={}}matches(){let t=Us.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&qp(t.fragmentIndex,this.a,this.b)}};u(Yp,"fragmentIndices",{});var $o=Yp,Cs=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new $o(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new pb(e)}static buildAnyMatcher(e){return new db(e)}},Zp={"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},fb=["image-resolution","orphans","widows"];function gb(){return Gt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(fb))}var mb={"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},Ka=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],yb=["max-%","min-%","%"],bu=(()=>{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<Ka.length;i++)for(let n=0;n<e.length;n++){let r=Ka[i].replace("%",e[n]);t[r]=!0}return t})();function Xn(e,t){let i={};for(let n of Ka)for(let r in e){let s=n.replace("%",r),o=n.replace("%",e[r]);i[s]=o,i[o]=s}for(let n of yb)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var Kp=Xn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Jp=Xn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),vb=Xn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),wb=Xn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),bb=Xn({inside:"right",outside:"left"},{}),xb=Xn({inside:"left",outside:"right"},{}),U=class Ja{constructor(t,i){u(this,"value",t),u(this,"priority",i)}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Ja(i,this.priority)}increaseSpecificity(t){return t==0?this:new Ja(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Xe(i)?this.value:xo(t,this.value,i,n,r)}isEnabled(t){return!0}},Qa=class el extends U{constructor(t,i,n){super(t,i),u(this,"condition",n)}getBaseValue(){return new U(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new el(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new el(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){q.warn(i)}return!1}};function tl(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Kt(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 Qp={"region-id":!0,"fragment-selector-id":!0},Sr="data-viv-footnote-counter";function wo(e){let t=e.getAttribute(Sr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,s])=>{if(Array.isArray(s)){let o=s.filter(a=>typeof a=="number"&&isFinite(a));n[r]=o}else typeof s=="number"&&isFinite(s)&&(n[r]=[s])}),n}function ef(e,t,i){let n=wo(e);n[t]=i,e.setAttribute(Sr,JSON.stringify(n))}function Sb(e,t){var i,n;if(!Wt(e)||e.hasAttribute(lp))return null;let r=wo(e)[t];if(r)return r;let s=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!s)return null;let o=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=Zs(s,o);if(a==="#"||a.replace(/#.*$/,"")!==o.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 c=wo(l)[t];return c?(ef(e,t,c),c):null}function Cb(e){let t=ve(e,"content");return!!t&&It(t.value)}function kb(e){return!!Qp[e]}function Ws(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Xi(e){return e.charAt(0)!=="_"&&!Qp[e]}function In(e){return!!Zp[e]||Xe(e)}function ve(e,t){return e[t]}function Fi(e,t,i){i?e[t]=i:delete e[t]}function pt(e,t){return e[t]}function oi(e,t){let i=e[t];return i||(i={},e[t]=i),i}var tf=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function nf(e,t){return e[t]}function rf(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function bo(e,t,i,n,r,s,o){var a,h;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=oi(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),o){let l=tf(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!Ws(l))if(kb(l)){let c=nf(i,l),d=rf(t,l);Array.prototype.push.apply(d,c)}else{let c=ve(i,l);if(!c.isEnabled(e))continue;let d=c.increaseSpecificity(n);Kt(t,l,d,e);let p=(a=e.style)==null?void 0:a.validatorSet,f=(h=p?.getShorthand(l,d.value))==null?void 0:h.propList;if(f)for(let g of f){let y=new U(Be,d.priority);Kt(t,g,y,e)}}}function Eb(e,t){let i={};for(let n=0;n<t.length;n++)bo(e,i,t[n],0,null,null,null);return i}function Jl(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 Pb=class extends nn{constructor(e,t){super(),u(this,"props",e),u(this,"context",t),u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ve(this.props,"font-size");if(!e.value.isNumeric())return Yt.em;let t=e.value;if(!lm(t.unit))throw new Error("Unexpected state");return t.num*Yt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?il(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Ql(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?xo(this.context,e,this.propName).visit(this):e}};function Ql(e,t,i){let n=e.unit,r=e.num;return n==="em"?new L(r*t,"px"):n==="rem"?new L(r*i.fontSize(),"px"):n==="rlh"?new L(r*i.rootLineHeight,"px"):e}function il(e,t,i){e=Ql(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new L(r/100*t,"px"):new L(r*i.queryUnitSize(n,!1),"px")}var qn=class{apply(e){}mergeWith(e){return new Nb([this,e])}clone(){return this}},ks=class extends qn{constructor(e){super(),u(this,"conditionItem",e)}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Nb=class sf extends qn{constructor(t){super(),u(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 sf([].concat(this.list))}},eh=class extends qn{constructor(e,t,i,n,r){super(),u(this,"style",e),u(this,"specificity",t),u(this,"pseudoelement",i),u(this,"regionId",n),u(this,"viewConditionId",r)}apply(e){bo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Pe=class extends qn{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Tb=class extends Pe{constructor(e){super(),u(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}},Ib=class extends Pe{constructor(e){super(),u(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}},xu=class extends Pe{constructor(e){super(),u(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}},Ab=class extends Pe{constructor(e,t){super(),u(this,"ns",e),u(this,"localName",t)}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},Fb=class extends Pe{constructor(e,t,i=!1){super(),u(this,"epubTypePatt",e),u(this,"targetLocalName",t),u(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)}}}},Rb=class extends Pe{constructor(e){super(),u(this,"ns",e)}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Ho(e,t,i,n){var r;if(!e)return!1;let s=((r=e.ownerDocument)==null?void 0:r.contentType)==="text/html",o=s?Lr(i):i;if(t!==null){let a=e.getAttributeNodeNS(t||null,o);return!!a&&n(a)}for(let a of Array.from(e.attributes))if((s?Lr(a.localName):a.localName)===o&&n(a))return!0;return!1}function Lr(e){return e.replace(/[A-Z]/g,t=>t.toLowerCase())}function of(e){return e==="i"}function rr(e,t){return Array.from(e,i=>{let n=Ks(i);if(!of(t))return n;let r=Lr(i),s=r.toUpperCase();return r!==s&&/^[a-z]$/i.test(i)?`[${r}${s}]`:n}).join("")}function sr(e){return new RegExp(e)}function Lb(e,t,i){return of(i)?Lr(e)===Lr(t):e===t}var Su=class extends Pe{constructor(e,t){super(),u(this,"ns",e),u(this,"name",t)}apply(e){Ho(e.currentElement,this.ns,this.name,()=>!0)&&this.chained.apply(e)}},Ob=class extends Pe{constructor(e,t,i,n=null){super(),u(this,"ns",e),u(this,"name",t),u(this,"value",i),u(this,"caseSensitivity",n)}apply(e){Ho(e.currentElement,this.ns,this.name,t=>Lb(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}},Bb=class extends Pe{constructor(e,t){super(),u(this,"ns",e),u(this,"name",t)}apply(e){Ho(e.currentElement,this.ns,this.name,t=>!!mb[t.value])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},or=class extends Pe{constructor(e,t,i,n=null){super(),u(this,"ns",e),u(this,"name",t),u(this,"regexp",i),u(this,"caseSensitivity",n)}apply(e){Ho(e.currentElement,this.ns,this.name,t=>!!t.value.match(this.regexp))&&this.chained.apply(e)}},Mb=class extends Pe{constructor(e){super(),u(this,"langRegExp",e)}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Cu=class extends Pe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},_b=class extends Pe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},on=class extends Pe{constructor(e,t){super(),u(this,"a",e),u(this,"b",t)}matchANPlusB(e){return qp(e,this.a,this.b)}},Db=class extends on{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},nl=class extends on{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}},rl=class extends on{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}},sl=class extends on{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,s=t[n];s||(s=t[n]={}),s[r]=(s[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},zb=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}},Vb=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},$b=class extends Pe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Hb=class extends Pe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},rt=class extends Pe{constructor(e){super(),u(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}},af=class lf extends qn{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new lf;return t.applied=this.applied,t}},th=class extends Pe{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new af;for(let t of e)this.firstActions.push(Jl(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}},Ub=class extends th{positive(){return!1}},Wb=class extends th{constructor(e){super([]),u(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}},hf=class extends on{constructor(e,t,i){super(e,t),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new af;for(let n of i)this.firstActions.push(Jl(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,s=t.currentId,o=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let c=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=s,t.currentClassNames=o,t.currentSiblingOrder=a,c}getPriority(){return 5}},Gb=class extends hf{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}},Uo=class{constructor(e,t,i){u(this,"condition",e),u(this,"viewConditionId",t),u(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)}},jb=class uf extends Uo{constructor(t,i,n){super(t,i,n)}fresh(t){return new uf(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}},Xb=class cf extends Uo{constructor(t,i,n){super(t,i,n)}fresh(t){return new cf(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)}},qb=class df extends Uo{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new df(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)}},Yb=class pf extends Uo{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new pf(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}},Zb=class{constructor(e,t){u(this,"afterprop",e),u(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}},Kb=class{constructor(e){u(this,"lang",e)}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Jb=class{constructor(e){u(this,"oldQuotes",e)}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Qb=class extends nn{constructor(e,t,i,n){super(),u(this,"element",e),u(this,"scope",t),u(this,"propName",i),u(this,"validatorSet",n),u(this,"hadAttrFunction",!1)}validatePropertyValue(e){var t,i;if(Y(e))return e;let n=(t=this.validatorSet)==null?void 0:t.validators[this.propName];return n?(i=e.visit(n))!=null?i:v.unset:!this.propName||CSS.supports(this.propName,e.toString())?e:v.unset}visitFunc(e){var t;if(e.name.toLowerCase()!=="attr")return super.visitFunc(e);this.hadAttrFunction=!0;let i=Yl(e);if(!i)return super.visitFunc(e);let n=((t=i.fallback)!=null?t:Qw(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:eb(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function Or(e,t){if(It(e)){if(e instanceof Z)return e.stringValue();if(e instanceof j&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof K)return e.values.map(i=>Or(i,t)).join("")}return""}function ih(e){if(e instanceof j){let t=e.expr;return t instanceof we&&/^page-counters?-/.test(t.str)}return e instanceof K||e instanceof _e?e.values.some(t=>ih(t)):!1}function ol(e,t){return ih(e)?e instanceof K?new K(e.values.map(i=>ol(i,t))):e instanceof _e?new _e(e.values.map(i=>ol(i,t))):e:new Z(Or(e,t))}var Br=class extends nn{constructor(e,t,i,n){super(),u(this,"cascade",e),u(this,"element",t),u(this,"counterResolver",i),u(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}hasLocalCounterResetOrSet(e){return this.hasLocalCounter(e,"counter-reset",{reset:!0})||this.hasLocalCounter(e,"counter-set",{defaultValue:0})}hasLocalCounterIncrement(e){return this.hasLocalCounter(e,"counter-increment",{})}hasLocalCounter(e,t,i){let n=this.cascade.currentStyle,r=n?.[t];if(!r)return!1;let s=r.evaluate(this.cascade.context);if(!s||Y(s))return!1;let o=qi(s,i);return Object.prototype.hasOwnProperty.call(o,e)}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Or(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 Z("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Z("")}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 gi;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,s=!1,o=!1){var a,h,l,c,d,p,f,g,y;let b=typeof r=="string",x=F=>b?this.formatCounterList(F,r,i):this.formatLastValue(F,i),m=F=>{this.pseudoName==="footnote-call"&&this.element&&ef(this.element,t,F)},w=(F,z)=>F.length===z.length&&F.every(($,X)=>$===z[X]);if(this.pseudoName==="footnote-call"&&this.element){let F=Sb(this.element,t);if(F)return x(F)}if(this.pseudoName==="footnote-marker"&&this.element){let F=wo(this.element)[t];if(F)return x(F)}let S;if(t==="pages")return x([]);if(!this.element){if(s&&n.length)return S=n,m(S),x(S);if((a=e.isPageControlledCounter)!=null&&a.call(e,t)&&o&&n.length){let F=((h=e.currentPageCounters)==null?void 0:h[t])||[];return S=[(F.length?F[F.length-1]:0)+n[n.length-1]],m(S),x(S)}if(!((l=e.isPageControlledCounter)!=null&&l.call(e,t))){let F=((c=e.currentPageCounters)==null?void 0:c[t])||[];if(F.length)return S=F,m(S),x(S)}}let C=((d=e.currentPageDocCounters)==null?void 0:d[t])||[],T=!this.element&&n.length&&!w(n,C),R=this.element||T?n:C.length?C:n;if((p=e.isPageControlledCounter)!=null&&p.call(e,t)){let F=((f=e.currentPageDocCounters)==null?void 0:f[t])||[],z=((g=e.currentPageCounters)==null?void 0:g[t])||[],$=z.length?z[z.length-1]:0,X=F.length?F[0]:0,re=R.length?R[0]:0,k=$+(re-X);return S=R.length?[k,...R.slice(1)]:z.length?z:[0],m(S),x(S)}return R.length?(S=R,m(S),x(S)):(S=((y=e.currentPageCounters)==null?void 0:y[t])||[],m(S),x(S))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),s=!this.element&&this.hasLocalCounterResetOrSet(i),o=!this.element&&this.hasLocalCounterIncrement(i),a=this.getCounterStore();if(a){let l=i==="pages"||((t=a?.isPageControlledCounter)==null?void 0:t.call(a,i)),c=this.getPageScope(),d=new we(c,()=>this.buildCounterText(a,i,n,r,void 0,s,o),l?`page-counter-${i}`:`counter-${i}`);if(l&&a!=null&&a.registerPageCounterExpr){let p=f=>this.formatLastValue(f,n);a.registerPageCounterExpr(i,p,d)}return new j(d)}let h=this.cascade.counters[i];if(h&&h.length){let l=h&&h.length&&h[h.length-1]||0;return new Z(this.format(l,n))}else{let l=new j(this.counterResolver.getPageCounterVal(i,c=>this.format(c||0,n)));return new K([l])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",s=(this.cascade.counters[i]||[]).slice(),o=!this.element&&this.hasLocalCounterResetOrSet(i),a=!this.element&&this.hasLocalCounterIncrement(i),h=this.getCounterStore();if(h){let p=i==="pages"||((t=h?.isPageControlledCounter)==null?void 0:t.call(h,i)),f=this.getPageScope(),g=new we(f,()=>this.buildCounterText(h,i,r,s,n,o,a),p?`page-counters-${i}`:`counters-${i}`);return p&&h!=null&&h.registerPageCounterExpr&&h.registerPageCounterExpr(i,y=>this.formatCounterList(y,n,r),g),new j(g)}let l=this.cascade.counters[i],c=new gi;if(l&&l.length)for(let p=0;p<l.length;p++)p>0&&c.append(n),c.append(this.format(l[p],r));let d=new j(this.counterResolver.getPageCountersVal(i,p=>{let f=[];if(p.length)for(let y=0;y<p.length;y++)f.push(this.format(p[y],r));let g=c.toString();return g.length&&f.push(g),f.length?f.join(n):this.format(0,r)}));return new K([d])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new j(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new K([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),s=e.length>3?e[3].stringValue():"decimal",o=new j(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,s));return h.length?h.join(r):this.format(0,s)}));return new K([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new j(this.counterResolver.getTargetTextVal(i,n));return new K([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new j(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 j(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o,a,h;let l=e.length>0?e[0].stringValue():"text",c="";switch(l){case"text":c=this.element.textContent;break;case"before":case"after":case"marker":{let d=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(d&&this.element)for(let f=0;f<d.length;f++){let g=d[f];if(g.parentElement===this.element){p=g;break}}if(p)c=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)c=this.evaluateAndGetString(g);else if(l==="marker"){let y=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;c=Or(y,this.cascade.context)}}}break;case"first-letter":{let d=pt(this.cascade.currentStyle,"_pseudos"),p=(o=(s=d?.before)==null?void 0:s.content)==null?void 0:o.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(Ys);c=g?g[0]:""}break}return new Z(c)}visitFuncLeader(e){let t="";if(e[0]instanceof he)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Z&&(t=e[0].stringValue());return t.length==0?new Z(""):new j(new we(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 da(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,s)=>r+(i==="vertical-rl"||i==="vertical-lr"?s.height:s.width),0)}var e0=(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){w==="rtl"?g.textContent=(P.startsWith("\u200F")?"":"\u200F")+P+(P.endsWith("\u200F")?"":"\u200F"):g.textContent=P},c=function(){let P=i.clientLayout.getElementClientRect(y);return m==="vertical-rl"||m==="vertical-lr"?w==="rtl"?P.top-=k:P.bottom+=k:w==="rtl"?P.left-=k:P.right+=k,R.left>P.left||R.right<P.right||R.top>P.top||R.bottom<P.bottom},d=function(){let P,N,O=x.repeat(1e4);if(l(O),c())P=1,N=1e4;else return;for(let V=0;V<16;V++){let W="",J=Math.floor((P+N)/2);for(let te=0;te<J;te++)W+=x;if(l(W),c())N=J;else{if(P==J)return;P=J}}l(x)},p=function(P){let N=0,O=y.parentElement;for(;O&&O!==f.viewNode;)N+=i.getComputedInsets(O)[P],O=O.parentElement;return N};var r=l,s=c,o=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,y=g.parentElement,b=y.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:m,direction:w,marginInlineEnd:S}=i.clientLayout.getElementComputedStyle(y);g.style.marginInlineStart="1px",l(x),y.style.display="inline-block",y.style.textIndent="0";let C=Kr(f.viewNode),T=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let R=i.clientLayout.getElementClientRect(f.viewNode),F=i.clientLayout.getElementClientRect(y),z=i.parseComputedLength(S),$=[],X=y.parentElement;for(;X.parentElement&&X.parentElement!==f.viewNode;)X=X.parentElement;let re=X.nextSibling;for(;re;){if(re.nodeType===1){let P=re,{display:N,float:O,position:V}=i.clientLayout.getElementComputedStyle(P);if(O!=="none"||V==="absolute"||V==="fixed"){re=re.nextSibling;continue}if(Dt(N))$.push(P);else if(hv(N))break}else if(re.nodeType===3){let P=re;P.length>0&&$.push(P)}re=re.nextSibling}let k=$.reduce((P,N)=>P+da(N,i.clientLayout,m),0);if(b!=="after"){let P=da(X,i.clientLayout,m),N=da(y,i.clientLayout,m);k+=P-N}m==="vertical-rl"||m==="vertical-lr"?(w==="rtl"?R.top+=z:R.bottom-=z,R.top=Math.min(F.top,R.top),R.bottom=Math.max(F.bottom,R.bottom)):(w==="rtl"?R.left+=z:R.right-=z,R.left=Math.min(F.left,R.left),R.right=Math.max(F.right,R.right)),d();let _=i.clientLayout.getElementClientRect(y);w=="rtl"?y.style.float="left":y.style.float="right";let E=i.clientLayout.getElementClientRect(y),B=0;w=="rtl"?m=="vertical-rl"||m=="vertical-lr"?B=_.top-E.top-p("top"):B=_.left-E.left-p("left"):m=="vertical-rl"||m=="vertical-lr"?B=E.bottom-_.bottom-p("bottom"):B=E.right-_.right-p("right"),B-=k,B=Math.max(0,B-.1),y.style.float="",g.style.marginInlineStart=`${B}px`,C&&(T?C.style.columnFill=T:C.style.removeProperty("column-fill"))}};Ot("POST_LAYOUT_BLOCK",e0);var nh=1/1048576;function cn(e,t){for(let i in e)t[i]=e[i].clone()}var t0=class ff{constructor(){u(this,"nsCount",0),u(this,"nsPrefix",{}),u(this,"tags",{}),u(this,"nstags",{}),u(this,"epubtypes",{}),u(this,"classes",{}),u(this,"ids",{}),u(this,"pagetypes",{}),u(this,"order",0)}clone(){let t=new ff;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return cn(this.tags,t.tags),cn(this.nstags,t.nstags),cn(this.epubtypes,t.epubtypes),cn(this.classes,t.classes),cn(this.ids,t.ids),cn(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,s,o){return new i0(this,t,i,n,r,s,o)}nextOrder(){return this.order+=nh}},gf=class mf{constructor(t,i,n,r,s,o,a){u(this,"context",i),u(this,"counterListener",n),u(this,"counterResolver",r),u(this,"counterStyleStore",o),u(this,"cmykStore",a),u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",Object.create(null)),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"pageTypePageIndices",Object.create(null)),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",Object.create(null)),u(this,"lastCounterChanges",[]),u(this,"lastCounterChangeTypes",Object.create(null)),u(this,"counterScoping",[Object.create(null)]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",Object.create(null)),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=t,this.quotes=[new Z("\u201C"),new Z("\u201D"),new Z("\u2018"),new Z("\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=Cs.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let s=this.viewConditions[r];return s&&s.length>0?s.length===1?s[0]:Cs.buildAnyMatcher([].concat(s)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Cs.buildAllMatcher(n):Cs.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=pa,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,s,o,a,h,l,c,d;let p=new Set,f=Object.create(null),g=v.inline,y=t.display;if(y&&(g=y.evaluate(this.context)),g===v.none){(i=this.currentElement)==null||i.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if((n=this.currentElement)!=null&&n.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let b=v.inline,x=t.float;x&&(b=x.evaluate(this.context));let m=null,w=null,S=null,C=t["counter-reset"];if(C){let F=C.evaluate(this.context);F&&(m=qi(F,{reset:!0}))}let T=t["counter-set"];if(T){let F=T.evaluate(this.context);F&&(S=qi(F,{defaultValue:0}))}let R=t["counter-increment"];if(R){let F=R.evaluate(this.context);F&&(w=qi(F))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((s=(r=this.currentElement)==null?void 0:r.start)!=null?s:1)-1),hr(g)&&(w||(w=Object.create(null)),w["list-item"]=(o=w["list-item"])!=null?o:1,/^\s*[-+]?\d/.test((h=(a=this.currentElement)==null?void 0:a.getAttribute("value"))!=null?h:"")&&(S||(S=Object.create(null)),S["list-item"]=this.currentElement.value)),((c=(l=this.currentElement)==null?void 0:l.parentNode)==null?void 0:c.nodeType)===Node.DOCUMENT_NODE&&(m||(m=Object.create(null)),m.footnote===void 0&&(m.footnote=0)),b===v.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(w||(w=Object.create(null)),w.footnote===void 0)){let F=(d=this.currentStyle["counter-increment"])==null?void 0:d.value;(!F||!(F===v.footnote||F instanceof K&&F.values.includes(v.footnote)))&&(w.footnote=1)}if(m)for(let F in m)p.add(F),f[F]="reset";if(w)for(let F in w)p.add(F),f[F]||(f[F]="increment");if(S)for(let F in S)p.add(F),f[F]="set";if(this.lastCounterChanges=Array.from(p),this.lastCounterChangeTypes=f,m)for(let F in m)this.defineCounter(F,m[F]);if(w)for(let F in w){this.counters[F]||this.defineCounter(F,0);let z=this.counters[F];z[z.length-1]+=w[F]}if(S)for(let F in S)if(!this.counters[F])this.defineCounter(F,S[F]);else{let z=this.counters[F];z[z.length-1]=S[F]}if(hr(g)){let F=this.counters["list-item"],z=F[F.length-1];t["ua-list-item-count"]=new U(new Tt(z),0);let $=oi(t,"_pseudos");$.marker||($.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 Br(this,this.currentElement,this.counterResolver));let n=i.value instanceof _e?i.value.values:[i.value];for(let r of n)if(r instanceof K){let s=r.values[0].stringValue(),o=r.values.slice(1);if(o.some(a=>ih(a)))this.counterResolver.setNamedString(s,ol(new K(o),this.context),this.currentElementOffset);else{let a=o.map(h=>Or(h,this.context)).join("");this.counterResolver.setNamedString(s,a,this.currentElementOffset)}}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof ai&&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 Br(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var s,o,a;let h=this.currentPageType;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let l=this.code.nsPrefix[this.currentNamespace];l?this.currentNSTag=l+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let c=i.getAttribute("class");c?this.currentClassNames=c.split(/\s+/):this.currentClassNames=pa;let d=i.getAttributeNS("http://www.idpf.org/2007/ops","type");d?this.currentEpubTypes=d.split(/\s+/):this.currentEpubTypes=pa;let p=ba(i);p&&(this.stack[this.stack.length-1].push(new Kb(this.lang)),this.lang=p.toLowerCase());let f=this.isRoot,g=this.siblingOrderStack;this.currentSiblingOrder=++g[g.length-1],g.push(0);let y=this.siblingTypeCountsStack,b=this.currentSiblingTypeCounts=y[y.length-1],x=b[this.currentNamespace];x||(x=b[this.currentNamespace]={}),x[this.currentLocalName]=(x[this.currentLocalName]||0)+1,y.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let w=this.followingSiblingTypeCountsStack,S=this.currentFollowingSiblingTypeCounts=w[w.length-1];S&&S[this.currentNamespace]&&S[this.currentNamespace][this.currentLocalName]--,w.push({}),this.applyActions(),this.currentPageType=h,this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i,t);let C=n.quotes,T=null;if(C){let z=C.evaluate(this.context);z&&(T=new Jb(this.quotes),z===v.none?this.quotes=[new Z(""),new Z("")]:z===v.auto||z===v.initial?this.quotes=[new Z("\u201C"),new Z("\u201D"),new Z("\u2018"),new Z("\u2019")]:z instanceof K&&(this.quotes=z.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(f||R){let z=Object.create(null);Object.keys(this.counters).forEach($=>{z[$]=Array.from(this.counters[$])}),this.counterListener.countersOfId(R,z)}let F=pt(this.currentStyle,"_pseudos");if(F){let z=!0;for(let $ of n0){$||(z=!1);let X=F[$];if(X){let re=(s=ve(this.currentStyle,"float"))==null?void 0:s.value,k=i instanceof Element&&Wt(i),_=i instanceof Element&&Et(i),E=!!ve(this.currentStyle,"--viv-semantic-footnote-content"),B=re===v.footnote,P=($==="before"||$==="after")&&(B||_||E)&&!!X.content,N=Cb(X),O=$==="footnote-call"&&k&&N,V=$==="footnote-marker"&&(_||E)&&N;if(($==="before"||$==="after")&&!(P||It((o=X.content)==null?void 0:o.value)||this.hasNonTrivialViewConditionalPseudoContent(X))||$==="marker"&&!hr((a=ve(this.currentStyle,"display"))==null?void 0:a.value)||($==="footnote-call"||$==="footnote-marker")&&re!==v.footnote&&!O&&!V||($==="footnote-call"||$==="footnote-marker")&&E&&!N)delete F[$];else if(z){if(this.processPseudoelementProps(X,i,$),$==="marker")this.processMarkerPseudoelementProps(X,i,t),delete F[$];else if($==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(X,"list-style-position",t,i)===v.outside){this.processMarkerPseudoelementProps(X,i,t);let W=X.content;W&&(this.currentStyle["_footnote-marker-content"]=W),this.currentStyle.display=new U(M("list-item"),0),this.currentStyle["list-style-position"]=new U(v.outside,0),this.currentStyle["list-style-type"]=new U(v.none,0),this.currentStyle["list-style-image"]=new U(v.none,0),delete F[$]}}else if($==="first-letter"&&X["initial-letter"]){let W=X["initial-letter"].evaluate(this.context);W!==v.normal&&!Y(W)&&(this.currentStyle["--viv-initialLetter"]=new U(W,0)),delete X["initial-letter"]}}else this.stack[this.stack.length-2].push(new Zb(X,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),T&&this.stack[this.stack.length-2].push(T)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return It((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,s,o,a,h;let l=hr((r=this.currentStyle.display)==null?void 0:r.value);if(!It((s=t.content)==null?void 0:s.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof Qe)t.content=new U(new K([p,new Z(" ")]),0);else if(d instanceof Z)t.content=new U(d,0);else if(d instanceof he&&d!==v.none){let f=(a=(o=this.currentStyle["ua-list-item-count"])==null?void 0:o.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new U(new Z(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let c=t.content;if(c){let d=c.value;if(It(d)){let p=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new U(p,0)}}for(let d of mf.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!Y(f)&&(this.currentStyle[`--viv-marker-${d}`]=new U(f,0))}}if(!Dt((h=ve(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==v.outside&&!Y(d)&&(this.currentStyle["list-style-position"]=new U(d,0))}}resolveMarkerContentVal(t){if(t instanceof j){let i=t.expr.evaluate(this.context);return typeof i=="string"?new Z(i):typeof i=="number"?new Z(String(i)):t}if(t instanceof K){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new K(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let o=n;o;o=o.parentElement){let a=(o===this.currentElement?this.currentStyle:i.getStyle(o,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let s=i.validatorSet;return(r=s?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var s;let o=t[i];if(o){let a=o.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(s=h?.defaultValues[i])!=null?s:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i,n){let r=t.scope,s=t.validatorSet;for(let o in n)if(Xi(o)&&!Xe(o)){let a=n[o],h=new Qb(i,r,o,s),l=a.filterValue(h);if(!h.hadAttrFunction){n[o]=l;continue}let c=h.validatePropertyValue(l.value);n[o]=c===l.value?l:new U(c,l.priority)}}applyAttrFilter(t,i){let n=this.currentStyle,r=pt(n,"_pseudos");for(let s in r)this.applyAttrFilterInner(i,t,r[s]);this.applyAttrFilterInner(i,t,n)}applyVarFilter(t,i,n){let r=t[0],s=t.map(d=>({...d})),o=32,a={},h=pt(r,"_pseudos"),l=Object.keys(r).filter(Xi),c=d=>{var p,f,g;let y=ve(r,d),b=y.value,x=Xe(d)?s:t,m=new p0(x,i,n,Xe(d)?d:null);Xe(d)&&m.getFallbackCycleMembers(b,x,n)&&(b=v.initial);for(let w=0;;w++){if(w>=o){b=Xe(d)?v.initial:Be;break}let S=b.visit(m);if(m.error){b=Xe(d)?v.initial:Be,m.error=!1;break}if(S===b)break;b=S}if(b!==y.value){let w=i.validatorSet,S=(p=w?.getShorthand(d,b))==null?void 0:p.clone();if(S)if(Y(b)){for(let C of S.propList){let T=new U(b,y.priority),R=ve(r,C);Fi(a,C,tl(this.context,R,T))}delete r[d]}else{let C=Ri(i.scope,new bt(b.toString(),null),"");if(C&&(C.visit(S),!S.error)){for(let T of S.propList){let R=new U((g=(f=S.values[T])!=null?f:w.defaultValues[T])!=null?g:v.initial,y.priority),F=ve(r,T);Fi(a,T,tl(this.context,F,R))}delete r[d]}}else r[d]=new U(b,y.priority)}if(a[d]){let w=ve(r,d);w&&w.value!==Be&&Kt(a,d,w,this.context)}};for(let d in r)if(Ws(d)){if(d==="_pseudos")continue;let p=pt(r,d);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}for(let d of l)Xe(d)&&c(d);for(let d of l)Xe(d)||c(d);if(h)for(let d in h)this.applyVarFilter([h[d],...t],i,n);for(let d in a)r[d]=a[d]}applyCalcFilter(t,i){let n=new Ef(i);for(let r in t)if(Ws(r)){let s=pt(t,r);for(let o in s)this.applyCalcFilter(s[o],i)}else if(Xi(r)&&!Xe(r)){let s=ve(t,r),o=s.value.visit(n);o!==s.value&&(t[r]=new U(o,s.priority))}}applyCmykFilter(t,i){let n=new Jc(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(Ws(r)){let s=pt(t,r);for(let o in s)this.applyCmykFilterInternal(s[o],i,`::${o}:`)}else if(Xi(r)&&!Xe(r)){let s=ve(t,r),o=s.value.toString();i.reset();let a=s.value.visit(i);a!==s.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,o),t[r]=new U(a,s.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};u(gf,"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 i0=gf,pa=[],n0=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],al=null;function r0(e){al=e}var Mr=class extends sn{constructor(e,t,i,n,r,s,o){super(e,t,o),u(this,"condition",i),u(this,"regionId",r),u(this,"validatorSet",s),u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"selectorFunctionContainsPseudoelement",!1),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:al?al.clone():new t0,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Jl(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 Ab(e,t.toLowerCase())):t?this.chain.push(new xu(t.toLowerCase())):this.chain.push(new Rb(e)))}invalidSelector(e){q.warn(e),this.chain.push(new rt("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Hn;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new Tb(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Vb);break;case"disabled":this.chain.push(new $b);break;case"checked":this.chain.push(new Hb);break;case"root":case"scope":this.chain.push(new _b);break;case"link":this.chain.push(new xu("a")),this.chain.push(new Su("","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)${Ks(i)}($|\\s)`),r=t[1];this.chain.push(new Fb(n,r,e==="href-role-type"))}else this.chain.push(new rt(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new rt(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Mb(new RegExp(`^${Ks(i.toLowerCase())}($|-)`)))}else this.chain.push(new rt(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=s0[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new rt(""));break}case"first-child":this.chain.push(new Cu);break;case"last-child":this.chain.push(new rl(0,1));break;case"first-of-type":this.chain.push(new nl(0,1));break;case"last-of-type":this.chain.push(new sl(0,1));break;case"only-child":this.chain.push(new Cu),this.chain.push(new rl(0,1));break;case"only-of-type":this.chain.push(new nl(0,1)),this.chain.push(new sl(0,1));break;case"empty":this.chain.push(new zb);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 rt(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new rt(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new Ib(e)))}attributeSelector(e,t,i,n,r){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,n=n||"";let s;switch(i){case 0:s=new Su(e,t);break;case 39:s=new Ob(e,t,n,r??null);break;case 45:!n||n.match(/\s/)?s=new rt(""):s=new or(e,t,sr(`(^|\\s)${rr(n,r??null)}($|\\s)`),r??null);break;case 44:s=new or(e,t,sr(`^${rr(n,r??null)}($|-)`),r??null);break;case 43:n?s=new or(e,t,sr(`^${rr(n,r??null)}`),r??null):s=new rt("");break;case 42:n?s=new or(e,t,sr(`${rr(n,r??null)}$`),r??null):s=new rt("");break;case 46:n?s=new or(e,t,sr(rr(n,r??null)),r??null):s=new rt("");break;case 50:if(n=="supported")s=new Bb(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Es++}`;this.processChain(new ks(new jb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Es++}`;this.processChain(new ks(new Xb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Es++}`;this.processChain(new ks(new qb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Es++}`;this.processChain(new ks(new Yb(e,this.viewConditionId,null))),this.chain=[new rt(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 eh(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Qa(t,0,this.condition):i=new U(t,0),rf(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new K([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Gt("SIMPLE_PROPERTY").forEach(s=>{let o=s({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new Qa(t,n,this.condition):new U(t,n);Kt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Hn(this);break;case"not":i=new o0(this);break;case"where":i=new a0(this);break;case"has":i=new l0(this);break;case"nth-child":t&&t.length>=2&&(i=new vf(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new h0(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},s0={"nth-child":Db,"nth-of-type":nl,"nth-last-child":rl,"nth-last-of-type":sl},Es=0,Hn=class yf extends Mr{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),u(this,"parent",t),u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(this,"selectorTexts",[]),u(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 Wb(this.selectorTexts):this.positive()?new th(this.chains):new Ub(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(t=this.parent).selectorFunctionContainsPseudoelement||(t.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new rt("")),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 yf;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}},o0=class extends Hn{positive(){return!1}forgiving(){return!1}},a0=class extends Hn{increasingSpecificity(){return!1}},l0=class extends Hn{relational(){return!0}},vf=class extends Hn{constructor(e,t,i){super(e),u(this,"a",t),u(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 hf(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}forgiving(){return!0}},h0=class extends vf{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Gb(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}},u0=class extends sn{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 Wr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Gs=class extends sn{constructor(e,t,i,n,r,s){super(e,t,!1),u(this,"condition",i),u(this,"elementStyle",n),u(this,"validatorSet",r),u(this,"ruleType",s),u(this,"order"),this.order=0}property(e,t,i){i?q.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){q.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){q.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=nh;let r=this.condition?new Qa(t,n,this.condition):new U(t,n);Kt(this.elementStyle,e,r)}},c0=class extends Rd{constructor(e,t){super(e),u(this,"validatorSet",t),u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){q.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){q.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Fd:Ad;n+=this.order,this.order+=nh;let r=new U(t,n);Kt(this.elementStyle,e,r)}};function wf(e,t){let i=tf(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function ll(e,t,i){wf(i,n=>{Cr(e,n,t)})}function d0(e,t,i,n){let r=new c0(e,t),s=new bt(n,r);try{nv(s,r,i)}catch(o){q.warn(o,"Style attribute parse error:")}return r.elementStyle}function bf(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function xf(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function hl(e,t,i,n,r){let s={};for(let o in e)Xi(o)&&(s[o]=ve(e,o));return ll(s,t,e),Sf(e,i,n,(o,a)=>{Cr(s,a,t),ll(s,t,a)}),s}function Sf(e,t,i,n){let r=pt(e,"_regions");if((t||i)&&r){if(i){let s=["footnote"];t?t=t.concat(s):t=s}for(let s of t){let o=r[s];o&&n(s,o)}}}function Cr(e,t,i){for(let n in t)if(Xi(n)){let r=ve(t,n),s=e[n];e[n]=tl(i,s,r)}}var Cf=(e,t,i,n,r,s)=>{var o,a;let h=i?n?vb:Kp:n?wb:Jp,l=r?bb:xb;for(let c in e){let d=e[c];if(!d)continue;let p=(o=h[c])!=null?o:h[l[c]],f=(a=l[c])!=null?a:l[h[c]],g=p??f,y;if(g){let b=e[g];if(b&&b.priority>d.priority||p&&f&&p!==f&&(g=f,b=e[g],b&&b.priority>d.priority))continue;y=bu[p]?p:bu[f]?f:c}else y=c,c.startsWith("text-align")&&(d.value===v.inside||d.value===v.outside)&&(d=new U(r===(d.value===v.inside)?v.right:v.left,d.priority));t[y]=s(c,d)}},p0=class kf extends nn{constructor(t,i,n,r=null){super(),u(this,"elementStyles",t),u(this,"styler",i),u(this,"element",n),u(this,"currentCustomPropertyName",r),u(this,"resolvingCustomProperties",[]),u(this,"varResolutionState",{cycleMembers:new Set}),r&&this.resolvingCustomProperties.push(r)}getRawCustomPropertyLookup(t,i,n){var r,s;let o=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===v.initial)return{found:!0,value:null,elementStyles:i.slice(a),element:n};if(!(h===v.inherit||h===v.unset||h===v.revert))return{found:!0,value:h,elementStyles:i.slice(a),element:n}}}n&&(o=n.parentElement)}for(;o;o=o.parentElement){let a=this.styler.getStyle(o,!1),h=(s=a?.[t])==null?void 0:s.value;if(h){if(h===v.initial)return{found:!0,value:null,elementStyles:a?[a]:[],element:o};if(!(h===v.inherit||h===v.unset||h===v.revert))return{found:!0,value:h,elementStyles:a?[a]:[],element:o}}}return{found:!1,value:null,elementStyles:[],element:null}}collectReferencedCustomProperties(t){let i=new Set;class n extends Zt{visitFunc(s){let o=s.values[0]instanceof he&&s.values[0].name;return s.name==="var"&&o&&Xe(o)&&i.add(o),super.visitFunc(s)}}return t.visit(new n),Array.from(i)}findReferencedCycleStart(t,i,n,r=new Set){for(let s of this.collectReferencedCustomProperties(t)){if(this.resolvingCustomProperties.includes(s))return s;if(r.has(s))continue;r.add(s);let o=this.getRawCustomPropertyLookup(s,i,n),a=o.value&&this.findReferencedCycleStart(o.value,o.elementStyles,o.element,r);if(a)return a}return null}getFallbackCycleMembers(t,i,n){let r=null,s=this;class o extends Zt{visitFunc(l){if(l.name==="var")for(let c of l.values.slice(1)){let d=s.findReferencedCycleStart(c,i,n);if(d)return r=d,null}return super.visitFunc(l)}}if(t.visit(new o),!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===v.initial)return{found:!0,value:null,continueLookup:!1};if(i===v.inherit||i===v.unset||i===v.revert)return{found:!0,value:null,continueLookup:!0};let s=this.getFallbackCycleMembers(i,n,r);return s?(s.forEach(o=>this.varResolutionState.cycleMembers.add(o)),{found:!0,value:null,continueLookup:!1}):{found:!0,value:this.resolveReferencedCustomProperty(t,i,n,r),continueLookup:!1}}resolveReferencedCustomProperty(t,i,n,r){let s=this.resolvingCustomProperties.indexOf(t);if(s>=0)return this.resolvingCustomProperties.slice(s).forEach(d=>this.varResolutionState.cycleMembers.add(d)),null;let o=new Set(this.varResolutionState.cycleMembers);this.varResolutionState.cycleMembers=new Set;let a=new kf(n,this.styler,r,t);a.resolvingCustomProperties=this.resolvingCustomProperties,a.resolvingCustomProperties.push(t),a.varResolutionState=this.varResolutionState;let h=i,l=32;for(let d=0;;d++){if(d>=l){h=null;break}let p=h.visit(a);if(a.error){h=null;break}if(p===h)break;h=p}let c=this.varResolutionState.cycleMembers;return this.varResolutionState.cycleMembers=new Set([...o,...c]),this.resolvingCustomProperties.pop(),c.has(t)?null:h}getVarValue(t){var i,n,r,s;let o=(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&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=this.styler.getStyle(o,!1),h=this.resolveCustomProperty(t,(s=a?.[t])==null?void 0:s.value,a?[a]:[],o);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 he&&t.values[0].name;return!i||!Xe(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 _e(t.values.slice(1)))}},Ef=class extends nn{constructor(e,t,i,n){super(),u(this,"context",e),u(this,"resolveViewportUnit",t),u(this,"percentRef",i),u(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=Ri(this.context.rootScope,new bt(i,null),"");if(n instanceof j)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 L(r,"px"):/\d[a-z]/i.test(i)||(t=new Tt(r)))}catch(r){q.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Pc(e.unit)||this.context.rootFontSize!=null&&um(e.unit)?new L(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new L(e.num*this.percentRef/100,"px"):e}};function xo(e,t,i,n,r){try{if(t instanceof j)return t.expr instanceof we&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:ov(e,t.expr,i);if(t instanceof L||t instanceof ai||t instanceof K||t instanceof _e)return t.visit(new Ef(e,!0,n,r))}catch(s){return q.warn(s),Be}return t}var ku={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Eu(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.none;if(t===v.none)return ku;let i=t instanceof K?t.values:[t],n=Object.create(ku);for(let r of i)if(r instanceof he)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 Pu(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var f0={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Nu={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Tu={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Iu(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.normal;if(t===v.normal)return Nu;if(t===v.auto)return Tu;let i=t instanceof K?t.values:[t],n=Object.create(Nu);for(let r of i)if(r instanceof he)switch(r.name){case"trim-both":case"trim-auto":return Tu;case"space-all":return f0;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 fa={ideographAlpha:!1,ideographNumeric:!1},g0={ideographAlpha:!0,ideographNumeric:!0};function Au(e){let t=e instanceof st?e:typeof e=="string"?M(e):v.normal;if(t===v.normal||t===v.auto)return g0;if(t===v.none)return fa;let i=t instanceof K?t.values:[t],n=Object.create(fa);for(let r of i)if(r instanceof he)switch(r.name){case"no-autospace":return fa;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Fu(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ru(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 m0=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let s=r.length-1;for(let o=0;o<s;o++)n.parentNode.insertBefore(document.createTextNode(r[o]),n);n.textContent=r[s]}}}processGeneratedContent(e,t,i,n,r,s){r=Ru(r);let o=Au(t),a=Iu(i),h=Eu(n);if(Pu(h)&&Fu(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(s?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=c.nextNode();f;f=p){p=c.nextNode();let g=!d,y=!d||/\n$/.test(d.textContent),b=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||y,g,y,b,x,d,p,o,a,h,r,s),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,s,o,a,h,l;let c=!e||e.fragmentIndex===1&&f(),d=c||g();function p(m){var w;if(m?.nodeType!==1)return!1;let S=m;if(S.hasAttribute(Dn))return!0;let{position:C,float:T}=(w=S.style)!=null?w:{};return C==="absolute"||C==="fixed"||T&&T!=="none"}function f(){let m=t[0];for(let w=m;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!m.inline)return!0;for(let w=m.viewNode.previousSibling;w;w=w.previousSibling)if(!Ee(w,m.whitespace)&&!p(w))return!1;return!0}function g(){var m,w;let S=t[0],C;for(;S&&S.inline&&(C=(m=S.viewNode)==null?void 0:m.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&S.whitespace!==wt.PRESERVE&&(C=C.previousSibling),C)));)S=S.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let T=(w=C.style)==null?void 0:w.display;if(T&&T!=="inline")return!/^(inline|ruby)\b/.test(T)}else if(C.nodeType===Node.TEXT_NODE){if(S.whitespace===wt.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(S.whitespace===wt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let y=-1;for(let m=0;m<t.length;m++){let w=t[m];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ee(w.viewNode,w.whitespace)){let S=function(P){var N,O,V;if(((N=P.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===wt.PRESERVE){if(/\n$/.test(W.textContent))return!0}else if(P.whitespace===wt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(W.textContent))return!0;if(((V=W.previousElementSibling)==null?void 0:V.localName)==="br")return Ee(W,P.whitespace)}return!1},C=function(P){var N,O,V;if(((N=P.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return P.viewNode.localName==="br";if(((O=P.viewNode)==null?void 0:O.nodeType)===Node.TEXT_NODE){let W=P.viewNode;if(P.whitespace===wt.PRESERVE){if(/^\n/.test(W.textContent))return!0}else if(P.whitespace===wt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(W.textContent))return!0;if(((V=W.nextElementSibling)==null?void 0:V.localName)==="br")return Ee(W,P.whitespace)}return!1};var b=S,x=C;y<0&&(y=m);let T=Ru((s=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),R=Au(w.inheritedProps["text-autospace"]),F=Iu(w.inheritedProps["text-spacing-trim"]),z=Eu(w.inheritedProps["hanging-punctuation"]);if(Pu(z)&&Fu(R,F)||/\b(flex|grid)\b/.test(w.parent.display))continue;let $=null,X=null,re=m===y,k=m===y&&c,_=m===y&&d,E=!1,B=!1;for(let P=m-1;P>=0;P--){let N=t[P];if(S(N)){_=!0;break}if(!N.display&&N.viewNode.nodeType===Node.TEXT_NODE&&N.viewNode.textContent.length>0){$=N.viewNode;break}if(((o=N.viewNode)==null?void 0:o.nodeType)===Node.ELEMENT_NODE&&ii(N.viewNode)==="footnote-call"){if(N.viewNode.contains(w.viewNode))continue;let O=vv(N.viewNode);if(O){$=O;break}}if(N.display&&!/^(inline|ruby)\b/.test(N.display)||((a=N.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(N.viewNode.localName==="br"||ji[N.viewNode.localName]))break;P===0&&(re=!0,c&&(k=!0,_=!0))}for(let P=m+1;P<t.length;P++){let N=t[P];if(C(N)){E=!0;break}if(N.viewNode!==w.viewNode&&!N.display&&N.viewNode.nodeType===Node.TEXT_NODE&&N.viewNode.textContent.length>0){X=N.viewNode;break}if(N.display&&!/^(inline|ruby)\b/.test(N.display)||((h=N.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(N.viewNode.localName==="br"||ji[N.viewNode.localName])){P===t.length-1&&p(N.viewNode)&&(B=!0);break}if(P===t.length-1){E=!0,B=!0;for(let O=N.viewNode.nextSibling;O;O=O.nextSibling)if(!p(O)){B=!1;break}}}if(((l=w.parent)==null?void 0:l.display)==="inline-block"){if(!k){let P=w.parent.viewNode.firstChild;for(;Ee(P,w.whitespace);)P=P.nextSibling;w.viewNode===P&&(k=!0)}if(!B){let P=w.parent.viewNode.lastChild;for(;Ee(P,w.whitespace);)P=P.previousSibling;w.viewNode===P&&(B=!0)}}if(this.processTextSpacing(w.viewNode,re,k,_,E,B,$,X,R,F,z,T,w.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,h,l,c,d,p){let f=e.textContent,g=e.ownerDocument,y=0,b,x,m;function w(){if(t)return!0;if(!o)return!1;b||(b=g.createRange(),b.selectNode(e));let E=b.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(o));let B=x.getClientRects(),P=B[B.length-1];return P?(y||(y=Fr(P,p)),p?E.top<P.top+P.height-E.width||E.left+E.width<P.left+E.width/10||E.left>P.left+P.width-E.width/10:E.left<P.left+P.width-E.height||E.top>P.top+P.height-E.height/10||E.top+E.height<P.top+E.height/10):!1}function S(){if(!a)return!1;b||(b=g.createRange(),b.selectNode(e));let E=b.getClientRects()[0];if(!E)return!1;y||(y=Fr(E,p)),m||(m=g.createRange(),m.selectNode(a));let B=m.getClientRects()[0];return B?p?E.top+E.height>B.top+E.width||E.left>B.left+B.width-E.width/10||E.left+E.width<B.left+E.width/10:E.left+E.width>B.left+E.height||E.top+E.height<B.top+E.height/10||E.top>B.top+B.height-E.height/10:!1}let C=!1,T=!1,R=!1,F=!1,z;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(z="viv-ts-open",C=!0,T=!0):s&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(z="viv-ts-close",C=!0,R=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(z="viv-ts-close",C=!0,F=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(z="viv-ts-open",C=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(z="viv-ts-close",C=!0),C){let E=function(V){let W=parseFloat(g.defaultView.getComputedStyle(V).fontSize)*.7;return(p?V.offsetHeight:V.offsetWidth)>W},B=function(){return p?P.offsetLeft:P.offsetTop};var $=E,X=B;if(e.parentElement.localName==="viv-ts-inner")return 0;let P=g.createElement(z),N=g.createElement("viv-ts-inner");P.appendChild(N),e.parentNode.insertBefore(P,e),N.appendChild(e);let O=E(N);if(O||T||R||F){if(z==="viv-ts-open"){if(T)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)&&w())P.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&E(o.parentElement)))P.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let V=B();P.className="viv-ts-auto",V===B()&&!w()&&(P.className="viv-ts-trim")}}else if(z==="viv-ts-close"){if(R)P.className=O?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let V=B();F?(P.className=O?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&V===B()&&(l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-hang-end",V===B()&&(P.className="")):P.className="viv-ts-space")):l.trimEnd?P.className="viv-ts-trim":l.allowEnd?(P.className="viv-ts-auto",V===B()&&(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(F){let V=S(),W=V&&c.allowEnd;W||(P.className=O?"viv-hang-end":"viv-hang-end viv-hang-hw"),O?W&&l.trimEnd?P.className="viv-ts-auto":!W&&!S()?P.className="":!V&&c.allowEnd&&(l.trimEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):(P.className="viv-ts-space",S()||(l.allowEnd?(P.className="viv-ts-auto",S()||(P.className="viv-hang-end")):P.className="viv-hang-end"))):!V&&!S()&&(P.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?P.className="viv-ts-space":P.className="viv-ts-auto";else{let V=B();P.className="viv-ts-auto",V===B()&&(P.className="")}}}}let re=!1;function k(E){var B;let P=(B=E?.ownerDocument.defaultView)==null?void 0:B.getComputedStyle(E);return!!P&&(P.textOrientation==="upright"||P.textCombineUpright==="all"||P["-webkit-text-combine"]==="horizontal")}function _(E,B){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(B))return _(P,B);if(B.nodeType===Node.ELEMENT_NODE){let O=g.defaultView.getComputedStyle(B);if(parseFloat(O.marginInlineStart)||parseFloat(O.borderInlineStartWidth)||parseFloat(O.paddingInlineStart))return!0}let N=B.parentElement;return N&&!N.contains(E)?_(E,N):!1}return(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&k(o.parentElement))&&!_(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),re=!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),re=!0)),y}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)}},rh=new m0;rh.registerHooks();function y0(e){rh.preprocessForTextSpacing(e)}function v0(e,t,i,n,r,s){rh.processGeneratedContent(e,t,i,n,r,s)}var dr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),w0=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],sh="data-adapt-pseudo";function ii(e){return e.getAttribute(sh)||""}function kr(e,t){e.setAttribute(sh,t)}var ga=class{constructor(e,t,i,n,r){u(this,"element",e),u(this,"style",t),u(this,"styler",i),u(this,"context",n),u(this,"exprContentListener",r),u(this,"contentProcessed",{})}getStyle(e,t){let i=ii(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 s=1,o;i=="first-letter"?s=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=o[1]-0),r["x-first-pseudo"]=new U(new lt(s),0)}return r}processContent(e,t,i){let n=ii(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;It(r)&&(r.visit(new Rr(e,this.context,r,this.exprContentListener)),y0(e))}}},nC=so.isInstanceOfAfterIfContinuesLayoutConstraint,b0=$o.registerFragmentIndex,rC=$o.clearFragmentIndices,x0=class{constructor(e,t){u(this,"sourceNode",e),u(this,"styler",t)}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new oh(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let s=i.firstChild;return A(s,"display","block"),I(s)})}createNodePositionForPseudoElement(){let e=dr.createElementNS("http://www.w3.org/1999/xhtml","div");kr(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 Bi(i)}createShadowContext(e){return new Rs(this.sourceNode,e,null,null,null,yi.ShadowType.ROOTED,this.styler)}},S0=class Pf{constructor(t,i,n){u(this,"nodeContext",t),u(this,"afterIfContinues",i),u(this,"pseudoElementHeight",n),u(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),I(!0))):I(!0)}getRepetitiveElements(){return new C0(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Pf?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},C0=class{constructor(e,t){u(this,"nodeContext",e),u(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 Nf(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return I(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=E0(e,t,n);return t.fragmentLayoutConstraints.push(new S0(e,i,r)),I(e)})}function Tf(e,t){return e.thenAsync(i=>Nf(i,t))}function k0(e,t){let i=D("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Nf(n,t);return n=n.parent,r.thenReturn(!0)}else return I(!1)}).then(()=>{i.finish(!0)}),i.result()}function E0(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Ba(i,t,e.vertical);return n.removeChild(i),r}var P0=class{constructor(e){u(this,"constraints",e)}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},pr=class extends $l{constructor(e,t){super(),u(this,"checkPoints",e),u(this,"penalty",t),u(this,"alreadyEvaluated",!1),u(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},So=class extends sp{constructor(e,t,i,n,r){super(e),u(this,"layoutContext",t),u(this,"clientLayout",i),u(this,"layoutConstraint",n),u(this,"pageFloatLayoutContext",r),u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isNonFirstColumn",!1),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"lastLineStride",0),u(this,"breakAtTheEdgeBeforeFloat",null),dv(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 s=r,o=i[n];if(r=ao(o,s),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return I(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Iv(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,s=r.match(Ys),o=s?s[0].length:0;if(!s&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(Ys);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return I(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=D("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var s;if(e.viewNode&&!En(e)&&((s=e.viewNode.parentElement)==null?void 0:s.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let o=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(o);if(Fr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,En(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)&&(Ai(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 Tf(i,this)}buildDeepElementView(e){if(!e.viewNode)return I(e);let t=[],i=e.sourceNode,n=D("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!En(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(s=>{let o=s;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,r.breakLoop();return}En(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Ai(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),A(r,"height",`${i}px`),A(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),A(r,"width",`${i}px`),A(r,"height",`${n}px`)),A(r,"float",t),A(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),s=this.vertical?-this.getLeftEdge():this.getBottomEdge(),o=null,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,s,f)&&(p.y1=s),this.almostEquals(p.y2,s,f)?p.y2=s:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=To==="webkit"?Math.floor:Math.round,c=t.map(p=>h>0?(l(p.y2/h)-l(p.y1/h))*h:p.y2-p.y1),d=.01;for(let p=0;p<t.length;p++){let f=p<t.length-1?t[p+1].x1:i,g=p<t.length-1?t[p+1].x2:n,y=f-t[p].x1,b=t[p].x2-g,x=0,m=0;y>d?x=1:y<-d&&(x=-1),b>d?m=1:b<-d&&(m=-1);let w=x!==0&&m!==0?x===m?x:0:x||m;if(h>0&&w!==0){let S=w*h;c[p]+S>=0&&(p>=t.length-1||c[p+1]-S>=0)&&(c[p]+=S,p<t.length-1&&(c[p+1]-=S))}}for(let p=0;p<t.length;p++){let f=t[p];f.left=this.createFloat(e,"left",f.x1-i,c[p]),f.right=this.createFloat(e,"right",n-f.x2,c[p]),f.x1<n&&f.x2>i?o=f:o||A(f.right,"float","none")}if(o){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(o!==p&&(p.y2>=s||this.almostEquals(p.y2,s,f))&&(this.footnoteEdge=this.vertical?-o.y2:o.y2,o.x1===i&&o.x2===n))for(let g=t.indexOf(o);g<t.length;g++){let y=t[g];this.element.removeChild(y.left),this.element.removeChild(y.right),y.left=null,y.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(A(this.element,r,`${i}px`),this.vertical){let s=this.left+(t-i);A(this.element,"left",`${s}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&kn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=wn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let s=n-e.boxOffset;for(;;){if(r=wn(e,this.clientLayout,s,this.vertical),!isNaN(r))return r;if(s>0){s--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(s=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ea(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 ea(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 ea(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=oa(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return A(i,"float","none"),A(i,"display","inline-block"),A(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let s=$t(this.clientLayout,i,this.vertical),o=this.getComputedMargin(i),a=new Lt(s.left-o.left,s.top-o.top,s.right+o.right,s.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let S=c.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),c.viewNode.appendChild(S);let C=$t(this.clientLayout,S,this.vertical);h=Math.max(this.rtl?this.getEndEdge(C):this.getStartEdge(C),h),l=Math.min(this.rtl?this.getStartEdge(C):this.getEndEdge(C),l),c.viewNode.removeChild(S);let T=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+T):h=Math.min(h,l-T),c!==e.parent&&!e.firstPseudo&&(c.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new Lt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=eo(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let S=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+S}if(e.clearSide){let S=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?oa(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;S!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),S!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let T=C*f;if(p.y1<T){let R=p.y2-p.y1;p.y1=T,p.y2=p.y1+R}}d.y2+=this.getFloatLayoutUnit(),Dm(d,this.bands,p,n),this.vertical&&(a=id(p));let g=this.getComputedInsets(i);A(i,"width",`${a.x2-a.x1-g.left-g.right}px`),A(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),A(i,"position","absolute"),e.display,A(i,"display",e.display);let y,b=null;if(c&&(c.containingBlockForAbsolute?b=c:b=c.getContainingBlockForAbsolute()),b){let S=b.viewNode.ownerDocument.createElement("div");S.style.position="absolute",b.vertical?S.style.right="0":S.style.left="0",S.style.top="0",b.viewNode.appendChild(S),y=$t(this.clientLayout,S,this.vertical),b.viewNode.removeChild(S)}else y={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(b?b.vertical:this.vertical){let S=Math.max(0,y.right-a.x2);A(i,"right",`${S}px`)}else{let S=Math.max(0,a.x1-y.left);A(i,"left",`${S}px`)}let x=Math.max(0,a.y1-y.top);A(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let m=this.vertical?a.x1:a.y2,w=this.vertical?a.x2:a.y1;!this.isOverflown(m)||this.breakPositions.length==0?(this.killFloats(),d=new Lt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=eo(d)),zm(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=m:this.rightFloatEdge=m,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(m),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,s){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let c=!!o.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!o.hasFloatFragments(),s);if(c){if(e.isFootnote){let d=getComputedStyle(e.element);if(e.vertical){let p=parseFloat(d.maxWidth);!isNaN(p)&&e.width>p&&(e.width=p,A(e.element,"width",`${p}px`))}else{let p=parseFloat(d.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,A(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return I(c)})}createPageFloatArea(e,t,i,n,r){let s=this.element.ownerDocument.createElement("div");A(s,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new xn(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=o.getContainer(),l=new I0(t,s,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(c=>I(c?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,s,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c={floatArea:null,pageFloatFragment:null,newPosition:null},d=D("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,s,r,l).then(p=>{if(c.floatArea=p,!p){d.finish(c);return}let f=!1,g=0;d.loopWithFrame(y=>{if(g>=e.length){y.breakLoop();return}let b=e[g],x=new Bi(b.nodePosition),m=p.breakPositions?p.breakPositions.length:0;p.layout(x,!0).then(w=>{if(c.newPosition=w,!w||n){if(w&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.length>m&&p.breakPositions.slice(m).some(S=>S instanceof pr))){f=!0,y.breakLoop();return}g++,y.continueLoop()}else f=!0,y.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&c.newPosition){let y=a.getPageFloatLayoutContext(h.floatReference);if(y.footnoteMaxBlockSize==null){if(y.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,s,o).then(b=>{d.finish(b)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let y=a.setFloatAreaDimensions(p,h.floatReference,t,s,!1,n,l);if(!y)f=!0;else{let b=r.createPageFloatFragment(e,y,i,p,!!c.newPosition);a.addPageFloatFragment(b,!0),c.pageFloatFragment=b}}d.finish(c)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,s=e.float,o=new Set;for(let c=r;c;c=c.effectiveParent)for(let d of c.floatFragments)d.continuations.some(p=>p.float.insidePageFloatArea)&&o.add(d);r.stashEndFloatFragments(s);function a(c,d){d?r.removePageFloatFragment(d,!0):c&&c.element.parentNode.removeChild(c.element);let p=[];for(let f=r;f;f=f.effectiveParent)for(let g of f.floatFragments)!o.has(g)&&g.continuations.some(y=>y.float.insidePageFloatArea)&&p.push(g);for(let f of p)r.removePageFloatFragment(f,!0);r.restoreStashedFragments(s.floatReference),r.deferPageFloat(e)}let h=s instanceof ho,l=D("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],s.floatSide,s.clearSide,h||!r.hasFloatFragments(),t,i,n).then(c=>{let d=c.floatArea,p=c.pageFloatFragment,f=c.newPosition;p?this.layoutStashedPageFloats(s.floatReference,[n]).then(g=>{if(g){let y=!!r.generatingNodePosition;if(r.addPageFloatFragment(p,y),r.discardStashedFragments(s.floatReference),f){let b=new ou(s,f.primary);r.deferPageFloat(b)}l.finish(!0)}else a(d,p),l.finish(!1)}):(a(d,p),l.finish(!1))}),l.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],s=[],o=!1,a=D("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let c=n[h];if(t.includes(c)){h++,l.continueLoop();return}let d=new zn().findByFloat(c.continuations[0].float);this.layoutSinglePageFloatFragment(c.continuations,c.floatSide,c.clearSide,!1,d,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(s.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(s.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let c=l.element;c&&c.parentNode&&c.parentNode.removeChild(c)})):n.forEach(l=>{let c=l.area.element;c&&c.parentNode&&c.parentNode.removeChild(c)}),a.finish(!o)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&ii(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(Dn,"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,s=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<s.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Ml(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new zn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=I(r):n=i.createPageFloat(e,t,this),n.thenAsync(s=>{let o=oo(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(s);let h=i.findPageFloatFragment(s,t),l=new ou(s,o);if(h&&h.hasFloat(s))return t.registerPageFloatAnchor(s,a.viewNode),I(a);if(t.isForbidden(s)||t.hasPrecedingFloatsDeferredToNext(s))return t.deferPageFloat(l),t.registerPageFloatAnchor(s,a.viewNode),I(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return I(null);{let c=p=>{if(!p||p.nodeType!==1)return NaN;let f=$t(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},d=wn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=s;if(p.footnotePolicy===v.line||isNaN(d)){let f=a;for(;f;){if((f.shadowContext?f.shadowContext.owner:f.sourceNode)===p.policyAnchorNode){let g=c(f.viewNode);isNaN(g)||(d=g);break}f=f.parent}}}return isNaN(d)&&e.floatSide==="footnote"&&(d=c(a.viewNode)),this.isOverflown(d)?I(a):this.layoutPageFloatInner(l,i,d,h).thenAsync(p=>p?e.floatSide==="footnote"||t.generatingNodePosition?I(a):I(null):(t.registerPageFloatAnchor(s,a.viewNode),I(a)))}})}processLineStyling(e,t,i){let n=D("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let s=0,o=e.firstPseudo;return o?.count===0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(r),l=o.count-s;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(r,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{s+=l,this.layoutContext.peelOff(c,0).then(d=>{e=d,o=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&ji[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let s=this.getComputedMargin(r.viewNode),o=this.vertical?-s.left:s.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=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 s=this.suppressOpenAncestorBlockEndInset(n??e),o=this.calculateEdge(n,i,r,i[r].boxOffset);s();let a=!1;if(!n||!kn(n.viewNode)){let l=Rn(n,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*l.minimum),this.isOverflown(o+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(o+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(o);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=I(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){Gt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,s=t[0].boxOffset,o=r,a=t.length-1,h=t[a].boxOffset,l;for(;s<h;){l=s+Math.ceil((h-s)/2),o=r;let c=a;for(;o<c;){let p=o+Math.ceil((c-o)/2);t[p].boxOffset>l?c=p-1:o=p}let d=this.calculateEdge(null,t,o,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(d),s=l,r=o}return{nodeContext:t[o],index:s,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,r,s;let o=this.findEndOfLine(t,e,!0),a=o.nodeContext;if(o.checkPointIndex===0&&o.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,o.index,e,o.checkPointIndex,i)}else{let l=iu(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof pr&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let c=(s=a.viewNode)==null?void 0:s.previousSibling;for(;c&&(Ee(c,a.parent.whitespace)||Rt(c));)c=c.previousSibling;if(c)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Gt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Co.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,s=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;s==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=s.nodeType===1?s:null;d?r?r=!1:Bl(d)?l=!a:!d.firstChild||ji[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||yv(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&s.firstChild&&(s=s.firstChild),n.setStartBefore(s),a=!0,o=s):/^r(uby|tc?)$/.test(d.localName)||(o=s),s.contains(t)&&(h=!1)):c=s.firstChild:(a||(s.parentNode==null?h=!1:(n.setStartBefore(s),a=!0)),o=s),c||(c=s.nextSibling,c||(r=!0,c=s.parentNode)),s=c}while(l&&h);if(a){n.setEndAfter(o);let c=this.clientLayout.getRangeClientRects(n);no(c,this.vertical);for(let d=0;d<c.length;d++)i.push(c[d]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Dv:_v);let n=0,r=0,s=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(o>0){let d=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?c=h*(this.getAfterEdge(l)-n)/d:h*this.getAfterEdge(l)>h*r?c=h*(r-this.getBeforeEdge(l))/d:c=1}if(o==0||c>=.6||c>=.2&&this.getStartEdge(l)>=s-1){s=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),r=o==0?l.left:Math.min(r,l.left)):(n=o==0?l.top:Math.min(n,l.top),r=o==0?l.bottom:Math.max(r,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(r),o=0),a>=i.length)break}return t.sort(xc),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&Pn(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=Rn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,s=r[0];for(;s.parent&&s.inline;)s=s.parent;let o,a;t&&!this.isFootnote?(o=1,a=1):(o=Math.max((s.inheritedProps.widows||2)-0,1),a=Math.max((s.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(s),l=this.findLinePositions(r),c=this.footnoteEdge-h,d=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);c-=d*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=d*(1/0));let g=mi(l.length,m=>{let w=l[m];return this.vertical?w<c||w<=f.edge:w>c||w>=f.edge}),y=g<=0;y&&(g=mi(l.length,m=>this.vertical?l[m]<c:l[m]>c));let b=r[r.length-1].viewNode;if(b?.parentElement.localName==="viv-ts-inner"&&(b=b.parentElement.parentElement),(g===l.length&&b.nextSibling||g>=l.length-1&&b.parentElement.querySelector(".MJXc-display"))&&(o=0,a=1),g=Math.min(l.length-o,g),g<a)return null;c=l[g-1];let x;if(y?x=f.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,c,t),x){let m=this.getAfterEdgeOfBlockContainer(x);if(!isNaN(m)&&d*(c-m)>0&&(c=m),this.computedBlockSize=d*(c-this.beforeEdge)+p,l.length>=2){let w=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[w]-l[w-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,wn(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 tr().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Ul.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let s=e.getMinBreakPenalty();s>i&&(n=Math.min(n,s))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return I(e);let r=D("doFinishBreak"),s=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return q.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,s,!0).then(()=>{r.finish(o)})):r.finish(o)}),r.result();e=i,s=!0,this.computedBlockSize=n}return this.finishBreak(e,s,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Rt(t.viewNode))return!1;return e.after?!0:e.sourceNode.namespaceURI==="http://www.w3.org/2000/svg"?!1:!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!io(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||Pn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let s=n.getAttribute("data-viv-box-break");St(n,"block-end"),t.push({element:n,original:s})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let o=e;o;o=o.parent)if(Rt(o.viewNode))return!1;if(kn(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=wn(e,this.clientLayout,0,this.vertical);i();let r=Rn(e,this.collectElementsOffset()),s=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let o=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||kn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=e.clearSide==="same"?e.floatSide:e.clearSide,i=/^(page|column|region)$/.test(t),n=this.getComputedMargin(e.viewNode),r=e.viewNode.ownerDocument.createElement("div");this.vertical?(r.style.bottom="0px",r.style.width="1px",r.style.marginRight=`${n.right}px`):(r.style.right="0px",r.style.height="1px",r.style.marginTop=`${n.top}px`);let s=()=>i?this.clientLayout.getElementClientRect(r):$t(this.clientLayout,r,this.vertical);e.viewNode.parentNode.insertBefore(r,e.viewNode);let o=s(),a=this.getBeforeEdge(o),h=this.getBoxDir(),l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(t)?oa(t,e.vertical,e.direction,this.layoutContext.page.side):t,c=l==="left"||l==="right"?e.direction==="rtl"==(l==="left")?"inline-end":"inline-start":l,d=this.pageFloatLayoutContext.getPageFloatClearEdge(c,this),p=d;switch(l){case"left":d=h*Math.max(d*h,this.leftFloatEdge*h);break;case"right":d=h*Math.max(d*h,this.rightFloatEdge*h);break;default:d=h*Math.max(d*h,Math.max(this.rightFloatEdge*h,this.leftFloatEdge*h))}let f=this.getFloatLayoutUnit(),g=this.leftFloatEdge*h>this.beforeEdge*h||this.rightFloatEdge*h>this.beforeEdge*h;if(f>0&&g){let b=d*h>p*h;d=h*(Math.ceil(d*h/f)+(b?1:0))*f}let y=this.getFloatLayoutTolerance(f);if(a*h+y>d*h)return e.viewNode.parentNode.removeChild(r),!1;{let b=Math.max(1,(d-a)*h);this.vertical?r.style.width=`${b}px`:r.style.height=`${b}px`,o=s();let x=this.getAfterEdge(o);if(!e.floatSide)if(this.vertical){let m=x-n.right-d;m>0==n.right>=0&&(m+=n.right),r.style.marginLeft=`${m}px`}else{let m=d-(x+n.top);m>0==n.top>=0&&(m+=n.top),r.style.marginBottom=`${m}px`}return e.clearSpacer=r,!0}}isBFC(e){return!!(lw(e)||Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(tu(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 I(e);let s=D("skipEdges"),o=this,a=!i&&t&&e&&e.after,h=i,l=null,c=[],d=[],p=!1;function f(C){var T,R;if(!(!t||o.isNonFirstColumn||i||!nu(h))){for(let F=C;F;F=F.parent)if(F.breakBefore==="column"&&(F.breakBefore=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakBefore)==="column"&&(z.style.breakBefore="")}}}function g(C){var T,R;if(!(!t||!o.isNonFirstColumn||i||h!=="column")){for(let F=C;F;F=F.parent)if(F.breakBefore==="column"&&(F.breakBefore=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakBefore)==="column"&&(z.style.breakBefore="")}h=null}}function y(C){var T,R;if(!(i||!nu(h))){for(let F=C;F;F=F.parent)if(F.breakAfter==="column"&&(F.breakAfter=null),((T=F.viewNode)==null?void 0:T.nodeType)===1){let z=F.viewNode;((R=z.style)==null?void 0:R.breakAfter)==="column"&&(z.style.breakAfter="")}}}function b(C){h=nt(h,C)}function x(){return i?!0:Ze(h)?t?o.isNonFirstColumn&&h!=="column"&&h!=="region":!m()&&!w():!1}function m(){var C;if(!l||!e||e.floatSide)return!1;for(let T=l;T!=null&&T.parent;T=T.parent){if(T.parent.viewNode&&Rt(T.parent.viewNode))continue;let R=T.after?T.viewNode:(C=T.viewNode)==null?void 0:C.previousSibling;for(;R&&(Ee(R,T.parent.whitespace)||Rt(R));)R=R.previousSibling;if(R)return!1}return!0}function w(){var C,T;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Rt(e.parent.viewNode))return!1;let R=!1;for(let F=e;F!=null&&F.parent&&!F.after;F=F.parent){if(F!==e&&Rt(F.viewNode))return!1;let z=(T=F.viewNode)==null?void 0:T.previousSibling;for(;z&&(Ee(z,F.parent.whitespace)||Rt(z));)Rt(z)&&(R=!0),z=z.previousSibling;if(z)return!1}return R}let S=()=>{e=c[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return s.loopWithFrame(C=>{for(var T;e;){e.formattingContext;let R=new tr().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ee(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){b(e.breakBefore),f(e),g(e),x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&c.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),C.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=ro(h)?h:null),R&&R.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?iu(l):this.breakPositions[this.breakPositions.length-1]instanceof pr||!t&&c.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ee(e.sourceNode.firstChild,e.whitespace)){c.push(e.copy()),b(e.breakBefore),f(e),g(e),x()?S():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let z=e.viewNode,$=z.style;if(e.after){zd(z,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let X=e.sourceNode;if(X.localName==="svg"||X.localName==="math"||X.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),d.push(l),h=null,b(e.breakAfter),y(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||R&&R.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(tu(e.viewNode))break;if(x()){S(),C.breakLoop();return}c=[],t=!1,a=!1,h=null}p=!1,$d(e.viewNode)||(l=e.copy(),d.push(l)),b(e.breakAfter),y(e),$&&!Rt(e.viewNode)&&this.hasNonZeroBlockEndInset($)&&(d=l?[l]:[])}else{if(c.push(e.copy()),b(e.breakBefore),f(e),g(e),l&&Ze(h)&&pv(l.viewNode,e.viewNode),(e.pageType!=((T=e.parent)==null?void 0:T.pageType)||!Ze(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){C.breakLoop();return}let X=e.viewNode.localName;if(ji[X]){x()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}$&&this.hasNonZeroBlockStartInset($)&&(a=!1,d=[]),p=!0}}while(!1);let F=this.nextInTree(e,a);if(F.isPending()){F.then(z=>{e=z,C.continueLoop()});return}else e=F.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,d,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Ze(h)&&(this.pageBreakType=h),C.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),s.finish(e)}),s.result()}skipTailEdges(e){let t=e.copy(),i=D("skipEdges"),n=null,r=!1;return i.loopWithFrame(s=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ee(e.viewNode,e.whitespace))break;if(!e.after){Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=nt(n,e.breakBefore),Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ze(n)){this.pageBreakType=n,s.breakLoop();return}n=null}r=!1,n=nt(n,e.breakAfter)}else{n=nt(n,e.breakBefore);let h=e.viewNode.localName;if(ji[h]){Ze(n)&&(this.pageBreakType=n),s.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){s.breakLoop();return}}r=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,s.continueLoop()});return}else e=o.get()}t=null,s.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Ai(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=D("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let s=e.formattingContext;new tr().find(s).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new tr().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=Bm(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],A(this.element,"width",`${this.width}px`),A(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 tr().find(e.formattingContext),s=this.calculateClonedPaddingBorder(n),o=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+s);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new pr(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 I(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?I(null):I(e);Ll(this);let n=D("layout");return this.openAllViews(e.primary).then(r=>{let s=null;if(r.viewNode)s=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(s=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new N0(t,i);o.layout(r,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,s,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=I(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(io(this)&&(mv(this),Mo(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(A(this.element,"width",`${this.width}px`),A(this.element,"left",`${this.left}px`)):A(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 c=new Bi(h.toNodePosition());n.finish(c)}})})})}),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,s)=>r.getPriorityOfFinishBreak()-s.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):I(!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(s=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())s.breakLoop();else if(this.pageBreakType)s.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),s.breakLoop()}else o?o=!1:s.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),s.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=D("redoLayout"),n=0,r=null,s=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,s).then(h=>{s=!1,h?(r=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Yi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(so.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},oh=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(this,"column"),u(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(s){return So.prototype.openAllViews.call(this,s).thenAsync(o=>(r.startNodeContexts.push(o.copy()),I(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Jr(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 Oi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let s=r.data.slice(e.offsetInNode);if(!Jd(s,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let s=r.nextSibling;s;s=s.nextSibling)if(!Ee(s,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Co=class{breakTextNode(e,t,i,n,r,s){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+Lu(n)),r){let s=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=s.slice(0,i+1)+r+s.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let s=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Ph(r)&&Ph(s)?Lu(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Co,"instance");Co.instance=new Co;function Lu(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var N0=class extends Wl{constructor(e,t){super(),u(this,"leadingEdge",e),u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"initialLastLineStride",0),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new T0(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||uw()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Vd(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}},T0=class{constructor(e,t,i){u(this,"leadingEdge",e),u(this,"breakAfter",t),u(this,"context",i)}doLayout(e,t){let i=D("DefaultLayoutMode.doLayout");return k0(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}},I0=class extends So{constructor(e,t,i,n,r,s,o){super(t,i,n,r,s),u(this,"floatSide",e),u(this,"parentContainer",o),u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),I(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(s,o){s.forEach(a=>{let h=ki(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=o*l/100;A(e,a,`${c}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(s=>{ki(e,s)==="auto"&&A(e,s,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=ki(t,"height");n!==""&&n!=="auto"&&A(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ki(t,"width");n!==""&&n!=="auto"&&A(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=$t(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,c,d,p;let f=(l=h.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(h);if((f?.getPropertyValue("--viv-footnote-display").trim()||"")==="compact")return!(f?.display==="list-item"&&f.getPropertyValue("list-style-position").trim()==="outside");let g=h.getAttribute(Vt);if(!g||!t||!i)return!1;let y=i.getNodeByOffset(parseInt(g,10));if(!y||y.nodeType!==Node.ELEMENT_NODE)return!1;let b=t.getStyle(y,!1),x=(d=(c=ve(b,"footnote-display"))==null?void 0:c.value)==null?void 0:d.toString(),m=!!((p=ve(b,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!m});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),s=this.vertical?r.height:r.width;n.forEach(h=>{A(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let o=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);A(l,"display","inline-block"),A(l,"position","absolute"),A(l,"visibility","hidden"),A(l,"white-space","nowrap"),A(l,"max-width","none"),A(l,"left","0"),A(l,"top","0"),this.element.appendChild(l);let c=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?c.height:c.width};n.forEach(h=>{a(h)>s+o&&(A(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=$t(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=>ii(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&&Et(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");kr(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,s=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,o=this.rootViewNodes[t+1],a=(n=o?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(o).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),c=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(r);if(s==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!d?this.createFootnoteBreakOpportunity(r):p&&d?.remove()}else c&&h.remove(),d?.remove()})}},tn=class{constructor(e,t){u(this,"parent",e),u(this,"rootSourceNode",t),u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||Ua.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new A0(e,this.rootSourceNode),Ua.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},A0=class{constructor(e,t){u(this,"vertical",e),u(this,"ownerSourceNode",t),u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=oo(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=oo(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Ba(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Ba(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?I(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?I(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,s=t.viewNode,o=r.createElement("div");s.appendChild(o);let a=new oh(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Bi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=h,I(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Dn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let s=n.indexOf(r);if(s>=0)return i?s===0:!1;for(let o=r;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},If=class{constructor(e){u(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}},Af=class{constructor(e){u(this,"formattingContext",e)}accept(e,t){return!0}postLayout(e,t,i,n){return n}},F0=class extends If{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},R0=class extends Af{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new ah(e)),this.processor.doLayout(e,t)}},ah=class Ff{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=di(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||kn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!Lf(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let s=this.getRepetitiveElements();s&&t&&r.stopAtOverflow&&(i==null||s.isAfterLastContent(i))&&s.preventSkippingFooter()}finishBreak(t,i){let n=di(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return I(!0);let s=this.nodeContext;return _0(n,s,i).thenAsync(()=>D0(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),I(!0))))}getRepetitiveElements(){return di(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Ff?di(this.nodeContext.formattingContext)===di(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},L0=class extends Wl{constructor(e,t){super(),u(this,"formattingContext",e),u(this,"processor",t)}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new F0(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new R0(this.formattingContext,this.processor))}},O0=class extends wr{constructor(e,t){super(),u(this,"formattingContext",e),u(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),I(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),I(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return wr.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"?I(!0):wr.prototype.afterNonInlineElementNode.call(this,e)}},B0=class extends Nn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=di(e.formattingContext);return n.getRootViewNode(e)?(i&&Rf(e.parent,t),e.belongsTo(n)?Nn.prototype.layout.call(this,e,t,i):new L0(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=z0(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=di(e.formattingContext),n=D("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=di(e.formattingContext),n=new O0(i,t);return new Ha(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=di(e.formattingContext),n=D("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Tf(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return Nn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Nn.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 tn&&!i.belongsTo(n)&&t(n,i)}}function Rf(e,t){e&&M0(e.after?e.parent:e,(i,n)=>{Li.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new ah(n))})}function _0(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let s=r.viewNode.firstChild;return n.appendHeaderToFragment(r,s,i)}}return I(!0)}function D0(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 I(!0)}function Lf(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function z0(e){let t=e.formattingContext;return!t||!(t instanceof tn)?null:t}function di(e){return e instanceof tn,e}var V0=new B0;Ot("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof tn&&!Li.isInstanceOfTableFormattingContext(e)?V0:null);var Of=class{constructor(e,t){u(this,"rowIndex",e),u(this,"sourceNode",t),u(this,"cells",[]),u(this,"breakBefore",null),u(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},$0=class{constructor(e,t,i){u(this,"rowIndex",e),u(this,"columnIndex",t),u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},H0=class{constructor(e,t,i){u(this,"rowIndex",e),u(this,"columnIndex",t),u(this,"cell",i)}},U0=class{constructor(e,t,i){u(this,"column",e),u(this,"cellNodeContext",i),u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new oh(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&A(e,"vertical-align","top"),i&&i!=="normal"&&A(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return A(e,"vertical-align",t),i&&i!=="normal"&&A(e,"align-content",i),n}},W0=class{constructor(e,t){u(this,"viewNode",e),u(this,"side",t)}},G0=class extends Jr{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?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)}},j0=class extends $l{constructor(e,t,i){super(),u(this,"rowIndex",e),u(this,"beforeNodeContext",t),u(this,"formattingContext",i),u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(s=>!!s.nodeContext)&&n.some((s,o)=>{let a=i[o].pseudoColumn,h=s.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(s=>s.nodeContext&&s.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty));let r=i.some((s,o)=>s.breakPosition instanceof pr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof Jr&&s.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(s.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},On=class extends tn{constructor(e,t){super(e,t),u(this,"tableSourceNode",t),u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){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 Of(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),s=0;for(;r[s];)s++;for(;e<n;e++){r=this.getRowSlots(e);for(let o=s;o<s+t.colSpan;o++){let a=r[o]=new H0(e,o,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=$t(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let s=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!s||t.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),i),t.push(s)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],s=this.getCellFragmentOfCell(i);!s||r.collected.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),r.elements),r.collected.push(s))})}),[new X0(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Yi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}Li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},X0=class{constructor(e){u(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=Rn(e,n);i=Math.max(i,t(r))}),i}};function zt(e){return e instanceof On,e}function q0(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Y0(e){return e==="table"||e==="inline-table"}function Ou(e){return q0(e)||Y0(e)}function Bf(e,t,i){let n=e.nodeContext,r=n.display,s=n.parent?n.parent.display:null,o=!1;if(s==="inline-table"&&!(n.formattingContext instanceof On)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof On){o=a.formattingContext===t;break}}return o||r==="table-row"&&!Ou(s)||r==="table-cell"&&s!=="table-row"&&!Ou(s)||n.formattingContext instanceof On&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,I(!0))):null}function Mf(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Ai(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),I(!0)))}var Z0=class extends wr{constructor(e,t){super(),u(this,"formattingContext",e),u(this,"column",t),u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=Bf(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Mf(this.column,e);if(n)return n;let r=e.nodeContext,s=r.display,o=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new W0(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return o.isHeaderRegistered()||(this.inHeaderOrFooter=!0,o.setHeaderNodeContext(r)),I(!0);case"table-footer-group":return o.isFooterRegistered()||(this.inHeaderOrFooter=!0,o.setFooterNodeContext(r)),I(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Of(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),o.firstContentSourceNode||(o.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let s=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(s[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,I(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let s=t.rows[this.rowIndex];s&&i.breakAfter&&(s.breakAfter=nt(s.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let s=i.viewNode;t.addCell(this.rowIndex,new $0(this.rowIndex,this.columnIndex,s)),this.columnIndex++,Vf(s);let o=t.rows[this.rowIndex];o&&(i.breakBefore&&(o.breakBefore=nt(o.breakBefore,i.breakBefore)),i.breakAfter&&(o.breakAfter=nt(o.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!En(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},_f=class Df extends wr{constructor(t,i){super(!0),u(this,"formattingContext",t),u(this,"column",i),u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(this,"inFooter"),u(this,"didExtractRowSpanningCellBreakPositions",!1),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(t){return Mf(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,s=t.columnIndex,o=t.colSpan,a=i.viewNode;o>1&&(A(a,"box-sizing","border-box"),A(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new U0(this.column,h,i);return this.formattingContext.addCellFragment(r,s,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(Vf(a),I(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let s=n[r];if(s.cell.anchorSlot.columnIndex===t&&s.cellNodePosition.steps[0].node===i)return{position:s,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,s=r.rowIndex;if(s<this.currentRowIndex&&s+r.rowSpan>this.currentRowIndex){let o=i[s];o||(o=i[s]=[]),o.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return I(!0);let s=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=D("layoutRowSpanningCellsFromPreviousFragment"),h=I(!0),l=0,c=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=ao(d[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=I(!0),g=0;function y(b){for(;g<b;){if(!c.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");A(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return d.forEach(b=>{f=f.thenAsync(()=>{let x=b.cell;y(x.anchorSlot.columnIndex);let m=b.cellNodePosition,w=ao(m.steps[0],p);return w.offsetInNode=m.offsetInNode,w.after=m.after,w.fragmentIndex=m.steps[0].fragmentIndex+1,s.setCurrent(w,!1).thenAsync(()=>{let S=b.breakChunkPosition;for(let C=0;C<x.colSpan;C++)c.push(g+C);return g+=x.colSpan,this.layoutCell(x,w,S).thenAsync(()=>(w.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,I(!0)))})})}),f.thenAsync(()=>(y(i.getColumnCount()),l++,I(!0)))})})}),h.then(()=>{s.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return I(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let s=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(s=nt(s,a.breakAfter))}let o=n.rows[this.currentRowIndex];return o!=null&&o.breakBefore&&(s=nt(s,o.breakBefore)),!t.leadingEdge&&Ze(s)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=s,this.resetColumn(),t.break=!0,I(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),I(!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);b0(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return I(!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,I(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let s=D("startTableCell"),o,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,o=I(h.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=oo(h,0);return I(new Bi(l))});return o.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=Bf(t,zt(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),s=n.display;return s==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,I(!0)):s==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,I(!0)):s==="table-row"?this.startTableRow(t):s==="table-cell"?this.startTableCell(t):I(!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 j0(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return I(!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)):A(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)):A(i.viewNode,"display","table-row-group")),r&&Df.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 s=super.afterNonInlineElementNode(t);return(s&&s.isPending()?s:I(!0)).thenAsync(()=>{if(!t.break){let o=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!o&&h&&!!(a!=null&&a.isFooterRegistered());(o||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return I(!0)})}else return super.afterNonInlineElementNode(t);return I(!0)}};u(_f,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var K0=_f,_r=[];function J0(e){let t=_r.findIndex(n=>n.root===e),i=_r[t];return i?i.tableLayoutOption:null}function Q0(e){let t=_r.findIndex(i=>i.root===e);t>=0&&_r.splice(t,1)}var zf=class{layoutEntireTable(e,t){let i=zt(e.formattingContext),n=new Z0(i,t);return new Ha(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=r.createElement("td");s.appendChild(l),o.push(l)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(h=>{let l=$t(n,h,i),c=i?l.height:l.width;return Math.ceil(c)});return e.parentNode.removeChild(s),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let s=r.span;for(r.removeAttribute("span"),n-=s;s-- >1;){let o=r.cloneNode(!0);i.insertBefore(o,r),t.push(o)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let s=e.length;s<i;s++){let o=n.ownerDocument.createElement("col");r.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let s=r.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=s;return}let a=e.colWidths=this.getColumnWidths(r,o,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((c,d)=>{A(c,n?"height":"width",`${a[d]}px`)}),h.forEach(c=>{s.appendChild(c.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=zt(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=J0(e.sourceNode);Q0(e.sourceNode);let r=D("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{var a;let h=o.viewNode,l=i.rows[0];if(l&&Ze(l.breakBefore)&&this.hasInFlowContentBefore(h,t)){(a=h.parentNode)==null||a.removeChild(h),t.pageBreakType=l.breakBefore,r.finish(s);return}let c=$t(t.clientLayout,h,t.vertical),d=t.vertical?c.left:c.bottom;if(d+=(t.vertical?-1:1)*Rn(e,t.collectElementsOffset()).current,!t.isOverflown(d)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new nx(s)),r.finish(o);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&&Ze(i.breakBefore)||t<e.rows.length-1&&Ze(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&&!Rt(n)||n.nodeType===3&&!Ee(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(e,t,i){let n=e.captions;n.forEach((r,s)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[s]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),A(t,"table-layout","fixed"),A(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=zt(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new K0(i,t),o=new Ha(s,t.layoutContext),a=D("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=zt(e.formattingContext);if(n.getRootViewNode(e)){if(i){let r=n.getRepetitiveElements();r&&e.sourceNode!==n.tableSourceNode&&!e.after&&!r.isFooterRegistered()&&r.preventSkippingHeader(),Rf(e.parent,t)}return new tx(n,this).layout(e,t)}else return t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new G0(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return ma(e),!1}finishBreak(e,t,i,n){let r=zt(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode),o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!o.includes(a.cell)),o.length){let a=D("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let c=o[h++],d=r.getCellFragmentOfCell(c),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),y=new Bi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:y,cell:c});let b=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),s<c.rowIndex+c.rowSpan-1&&(b.rowSpan=s-c.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{ex(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),ma(t),r.finishFragment(),a.finish(!0)}),a.result()}}return ma(t),r.finishFragment(),Ul.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Nn.prototype.clearOverflownViewNodes(e,t,i,n)}};function ex(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,s=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=$t(s.clientLayout,a,r),l=s.getComputedPaddingBorder(a);if(r){let c=h.right-s.footnoteEdge-n.calculateOffset(i)-l.right;A(o,"max-width",`${c}px`)}else{let c=s.footnoteEdge-n.calculateOffset(i)-h.top-l.top;A(o,"max-height",`${c}px`)}}function Vf(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 s=n[r].style.position;if(s!=="absolute"&&s!=="fixed")return}A(i,"display","contents")}}function ma(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return d+g},0),r=i[i.length-1],s=Array.from(t.children).indexOf(r),o=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&s+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[s+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,c=n+l;A(a,e.vertical?"width":"height",`${c}px`)}var tx=class extends Wl{constructor(e,t){super(),u(this,"tableFormattingContext",e),u(this,"processor",t)}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new ix(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new sx(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()}},ix=class extends If{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},nx=class extends Jr{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 rx(this.position.sourceNode))}},rx=class $f{constructor(t){u(this,"tableRootNode",t),u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,_r.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return I(!0)}equalsTo(t){return t instanceof $f&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},sx=class extends Af{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new ox(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},ox=class Hf extends ah{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||kn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!Lf(t,i,r):!0}nextCandidate(t){let i=zt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let s=zt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,s),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,r)})}),!t){let o=s.getRootViewNode(this.nodeContext);new zf().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=zt(this.nodeContext.formattingContext),r=D("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),o=0;return r.loop(()=>{if(o<s.length){let a=s[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return I(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let s=0;s<n;s++)i.cellFragments[s]&&i.cellFragments[s].forEach(o=>{o&&r.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=zt(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Hf?zt(this.nodeContext.formattingContext)===zt(t.nodeContext.formattingContext):!1}},ax=new zf;function lx(e,t,i,n,r,s){if(!t)return null;if(i===v.table){let o=e.parent;return new On(o?o.formattingContext:null,e.sourceNode)}return null}function hx(e){return e instanceof On?ax:null}Ot("RESOLVE_FORMATTING_CONTEXT",lx);Ot("RESOLVE_LAYOUT_PROCESSOR",hx);function Bu(e){return e.reduce((t,i)=>t+i,0)/e.length}function ux(e){let t=Bu(e);return Bu(e.map(i=>{let n=i-t;return n*n}))}var cx=class{constructor(e,t){u(this,"layoutResult",e),u(this,"penalty",t)}};function Dr(e){return e.vertical?e.width:e.height}function zr(e,t){e.vertical?e.width=t:e.height=t}var Uf=class{constructor(e,t,i){u(this,"layoutContainer",e),u(this,"columnGenerator",t),u(this,"regionPageFloatLayoutContext",i),u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Dr(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,s)=>s.penalty<r.penalty?s:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new cx(e,t)}preBalance(e){}postBalance(){zr(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let s=r+n-t;A(i.element,"width",`${t}px`),A(i.element,"left",`${s}px`),i.width=t,i.left=s}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(A(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)}},ul=1;function Wf(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(o=>o.computedBlockSize)),s=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return r>s+ul}function Gf(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+ul))-ul;n<Dr(t)?zr(t,n):zr(t,Dr(t)-1)}var dx=class extends Uf{constructor(e,t,i,n){super(i,e,t),u(this,"columnCount",n),u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);zr(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 Mu(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Wf(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Mu(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Dr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Gf(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Dr(this.layoutContainer)+this.originalContainerBlockSize*.1);zr(this.layoutContainer,t)}}};function Mu(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(s=>s.lastLineStride||0)),r=n>0?n/2:6;return i.every(s=>t>s.computedBlockSize+r)}var px=class extends Uf{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 ux(t)}hasNextCandidate(e){return Wf(e)}updateCondition(e){Gf(e,this.layoutContainer)}};function fx(e,t,i,n,r,s,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=s[s.length-1],l=!!(h&&h.pageBreakType);return a||l?new dx(i,n,r,e):t===v.balance_all?new px(i,n,r):(v.balance,null)}}var ya=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},gx=class{constructor(){u(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new ya(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 ya(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new ya(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=mi(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=mi(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}};function mx(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var yx=class cl{constructor(t,i,n,r,s,o,a,h){if(u(this,"context",t),u(this,"style",i),u(this,"offset",n),u(this,"isRoot",r),u(this,"flowChunk",s),u(this,"atBlockStart",o),u(this,"atFlowStart",a),u(this,"isParentBoxDisplayed",h),u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=s.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new cl(t,l.before,n,!1,s,this.isBlock(),a,!0),d=c.styleValue("content");It(d)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=nt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ze(this.breakBefore)&&(s.breakBefore=nt(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new cl(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");It(o)&&(this.afterBox=s)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=_d(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!yr(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}},vx=class{constructor(e){u(this,"context",e),u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let s=n||r.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new yx(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=Kd(i);n&&!Ee(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!")}},_u=class{constructor(e,t,i,n,r,s,o,a,h,l){u(this,"xmldoc",e),u(this,"scope",i),u(this,"context",n),u(this,"primaryFlows",r),u(this,"validatorSet",s),u(this,"counterListener",o),u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"counterSnapshots",[]),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang,h,l),this.offsetMap=new gx;let c=e.getElementOffset(this.root);this.lastOffset=c,this.boxStack=new vx(n),this.offsetMap.addStuckRange(c);let d=this.getAttrStyle(this.root);this.cascade.pushElement(this,this.root,d,c),this.recordCounterSnapshot(c,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(d,!1),this.root.namespaceURI==="http://www.w3.org/1999/xhtml"&&(this.bodyReached=!1),this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${c}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new U(r,Id))}}}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)In(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&&!Y(n)||r&&!Y(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Du.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Du[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Y(n.value)){let a=n.evaluate(this.context);if(a instanceof L){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*Yt.lh/Yt.em;break;default:{let l=Yt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!Y(o.value)){let a=o.evaluate(this.context);if(a instanceof Tt)this.context.rootLineHeight=a.num*s;else if(a instanceof L){let h=a.num;switch(a.unit){case"em":case"rem":h*=s;break;case"%":h*=s/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=Yt[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 d0(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:mx(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},s=this.counterSnapshots[this.counterSnapshots.length-1];if(s&&s.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=mi(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let s=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=s.page,c=l&&!Y(l.value)&&l.value.toString();c&&c.toLowerCase()!=="auto"&&(this.cascade.firstPageType=c)}let o=ve(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,o,r)}r++}if(r>=this.lastOffset)break;let s=n.firstChild;if(s==null){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n===this.root)return}n=s}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,s=Number.POSITIVE_INFINITY,o=!1,a=!1,h=!1,l=t["flow-options"];if(l){let y=$m(l.evaluate(this.context,"flow-options"));o=!!y.exclusive,a=!!y.static,h=!!y.last}let c=t["flow-linger"];c&&(s=jh(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=jh(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let y=this.boxStack.lastFlowName();f=this.flows[e]=new Bv(e,y)}let g=new Mv(e,i,n,r,s,o,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ze(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 s=this.last.firstChild;if(s==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=nt(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(s=this.last.nextSibling,s)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=s,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,c=a["flow-into"];if(c){let p=c.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,o,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=nt(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||o===this.xmldoc.body){let p=a.page,f=p&&!Y(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}return Number.POSITIVE_INFINITY}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},Du=["column-count","column-width","column-fill"],sC=`OTTO${new Date().valueOf()}`;function lh(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function wx(e){let t=new gi;for(let i of lh(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function bx(e,t){let i={};for(let n in e)i[n]=ve(e,n).evaluate(t,n);return i}var jf=class{constructor(e){u(this,"properties",e),u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=wx(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 gi;i.append(`@font-face {
|
|
1867
1867
|
font-family: `),i.append(this.family),i.append(`;
|
|
1868
1868
|
`);for(let n of lh(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1869
1869
|
`);if(t){i.append('src: url("');let n=Zy(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
|
|
1870
1870
|
}
|
|
1871
|
-
`),i.toString()}},xx=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 _e){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 _e(i)}else{let t=this.familyMap[e.stringValue()];return t?new _e([M(t),e]):e}}},Sx=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,s={};for(let l of lh(e.properties))s[l]=e.properties[l];let o=this.getViewFontFamily(e,i);s["font-family"]=M(o);let a=new jf(s),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),q.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(s=>{t.registerFamily(e,s),q.debug("Found already-loaded font:",i)}):(r=new Yr(()=>{let s=D("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?Ro(o,"blob").then(h=>{if(!h.responseBlob){s.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(s)})}):this.initFont(e,null,t).thenFinish(s),s.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){q.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return _n(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 I(!0);let i=D("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?I(!0):I(!1))).thenFinish(i),i.result()}},vi=!0;function Cx(e){vi=e}var Ki=[];function zu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Xf(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 hh(e,t,i){if(!vi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Xf(e.ownerDocument).includes(e))return I(!1);let n=e.textContent,r=e.src,s=e.type==="module",o=r&&r.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return I(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(s||r)&&e.async&&!o,h=(s&&!a||r&&e.defer)&&!o,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(qf(t)||(t.onload=null),l)return Ki.some(c=>zu(c,e))||Ki.push(e),I(!0);for(let c of t.document.head.getElementsByTagName("script"))c.hasAttribute("data-vivliostyle-scripting")&&zu(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(q.debug("script:",r),r){let c=kt(u);return t.document.head.appendChild(u),_n([c])}else return t.document.head.appendChild(u),I(!0)}function kx(e,t){var i;let n={},r=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let u of Object.values(l))r(u)},s=o=>{if(o instanceof eh)r(o.style);else if(o instanceof qn||Array.isArray(o))for(let a of Object.values(o))s(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))s(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function Ex(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=kx(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function Px(e,t,i){if(!vi)return I(!1);let n=Xf(e);if(n.length===0)return I(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),s=r?Ex(e,t,i):null,o=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 o.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?I(!0):I(!1)}):I(!1);let u=n.shift();return hh(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Ki.push(u),h=!0),n.length===0&&r&&(q.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),I(!0)))}).then(()=>{s&&s.remove(),l.finish(!0)}),l.result()}function Nx(e){if(!vi)return I(!1);let t=D("loadScripts");return t.loop(()=>Ki.length===0?I(!1):hh(Ki.shift(),e,{atEnd:!0}).thenReturn(Ki.length>0)).then(()=>{q.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),q.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function qf(e){return vi?Ki.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Tx=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Sl),Ix=e=>`"${Tx(e)}"`,ya=(e,t,i)=>Ix(i.transformURL(xi(String(e)),t)),Ax=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${ya(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${ya(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${ya(r,t,i)}`),Fx={},Rx=new Set(["base","body","head","html","link","meta","script","style","title"]);function Lx(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 cl=class fr extends Cl{constructor(t,i,n,r,s,o,a,h,l,u,c,p,f,g,y,b=new Map,x={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=s,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=c,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=y,this.semanticFootnoteFirstRefOffsets=b,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 fr(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)}getExplicitPageType(t){let i=t?.page;if(!i||Y(i.value))return null;let n=i.evaluate(this.context,"page").toString();return!n||n.toLowerCase()==="auto"?null:n}isNormalFlowElement(t){var i,n,r;let s=this.styler.getStyle(t,!1),o=(i=s?.display)==null?void 0:i.evaluate(this.styler.context,"display");if((o&&!Y(o)?o:v.inline)===v.none)return!1;let a=(n=s?.position)==null?void 0:n.evaluate(this.styler.context,"position"),h=a&&!Y(a)?a:v.static;if(yr(h)||Ar(h))return!1;let l=(r=s?.float)==null?void 0:r.evaluate(this.styler.context,"float");return(l&&!Y(l)?l:v.none)===v.none}getFirstInFlowChildElement(t){var i;let n=t.firstChild;for(;n;){if(n.nodeType===Node.TEXT_NODE){if(!Ee(n))return null;n=n.nextSibling;continue}if(n.nodeType!==Node.ELEMENT_NODE){n=n.nextSibling;continue}let r=n;if(this.isNormalFlowElement(r)){let s=this.styler.getStyle(r,!1),o=(i=s?.display)==null?void 0:i.evaluate(this.styler.context,"display"),a=o&&!Y(o)?o:v.inline;return Dt(a)?null:r}n=n.nextSibling}return null}getEffectiveStartPageType(t,i){let n=i,r=t;for(;r;){let s=this.getFirstInFlowChildElement(r);if(!s)return n;let o=this.getExplicitPageType(this.styler.getStyle(s,!1));o&&(n=o),r=s}return n}syncTextNodePageTypeBoundary(t){if(t.sourceNode.nodeType!==Node.TEXT_NODE||Ee(t.sourceNode)||t.fragmentIndex!==1)return;let i=t.pageType;this.styler.cascade.currentPageType!==i&&(en(t.breakBefore)||(t.breakBefore=nt(t.breakBefore,"page")),i!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=i)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!Wt(t)||!au(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(Sr);if(!i)return;let n=up(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(Sr,i)}createPseudoelementShadow(t,i,n,r,s,o,a,h){var l,u;let c=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!c)return h;let p=[],f=dr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,y=Wt(t)&&!!c["footnote-call"]&&It((l=c["footnote-call"].content)==null?void 0:l.value);for(let m of w0){let w;if(m){if(!c[m])continue;let S=Et(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(m=="footnote-call"&&!Wt(t)||m=="footnote-marker"&&!(S||C||i&&this.isFootnote)&&!((u=this.nodeContext)!=null&&u.pluginProps.nestedFootnoteDetached))continue;if(m.match(/^first-/)){let T=r.display;if(!T||T===v.inline)continue;let R=t.firstElementChild;if(R&&Ee(R.previousSibling)){let F=s.getStyle(R,!1);if(F){let z=ve(F,"display");if(z!=null&&z.value&&z.value!==v.inline)continue}}}if(m==="before"||m==="after"||m==="footnote-call"||m==="footnote-marker"){let T=c[m].content,R=(m==="before"||m==="after")&&(r.float===v.footnote||S||C)&&!!T;if(!T||!It(T.value)&&!R)continue}p.push(m),w=dr.createElementNS("http://www.w3.org/1999/xhtml","span"),kr(w,m)}else{if(y)continue;w=dr.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(w),m.match(/^first-/)&&(g=w)}if(!p.length)return h;let b=new fa(t,n,s,o,this.exprContentListener),x=new Rs(t,f,null,a,h,ot.ROOTLESS,b);return h||x}getPseudoMap(t,i,n,r,s){let o=pt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Cr(l,o[h],s),al(l,s,o[h]),Sf(o[h],i,n,(u,c)=>{Cr(l,c,s),wf(c,p=>{Cr(l,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=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);s=new Rs(n,l,h,r,s,i,u)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let h=D("createShadows"),l=null,u=r.template,c;if(u instanceof it||u===v.footnote)if(u!==v.footnote||au(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=u instanceof it?u.url:Ie("user-agent.xml#footnote",Ni);c=this.createRefShadow(p,ot.ROOTLESS,t,a,l)}else c=I(l);else c=I(l);return c.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let y=t.getAttribute("href"),b=null;y?b=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?y=a.owner.getAttribute("href"):y=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),b=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),y&&(y=Zs(y,b.url),f=this.createRefShadow(y,ot.ROOTED,t,a,p))}f==null&&(f=I(p));let g=null;f.then(y=>{if(r.display===v.table_cell){let b=Ie("user-agent.xml#table-cell",Ni);g=this.createRefShadow(b,ot.ROOTLESS,t,a,y)}else g=I(y);g.then(b=>{b=this.createPseudoelementShadow(t,i,n,r,s,o,a,b),h.finish(b)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=ll(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((s=this.nodeContext)!=null&&s.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=bf(a,o,t);let u=!h&&t!==l;i=xf(a,o,i);let c=(x,m)=>{let w;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(w=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(w=o.pageAreaWidth));let S=m.evaluate(o,x,w,t);return x=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},p=!!new Je(o.style.pageScope,"left-page").evaluate(o);if(Cf(a,r,t,i,p,c),u){let x=r[t?"height":"width"];(!x||x===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(yr(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,y=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),b=Md(y,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{b[x]&&(r[x]=b[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,s=[],o=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let b=l?.owner;if(b instanceof Element&&Wt(b)){let x=b.getAttribute("href")||b.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let m=Zs(x,this.xmldoc.url),w=this.xmldoc.getElement(m);w&&Et(w)&&((n=w.parentNode)==null?void 0:n.nodeType)===1&&(r=w.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let b=l&&l.root==r,x=!!b&&l.type==ot.ROOTED&&Et(r);if(!b||l.type==ot.ROOTLESS||x){let m=(l?l.styler:this.styler).getStyle(r,!1);s.push(m),o=o||wa(r)}b&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let c=new Set;if(s.length>0){let b=s[0],x=ll(b,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let m in x){if(!In(m))continue;let w=x[m].evaluate(this.context,m);w&&w!==v.inherit&&w!==v.unset&&w!==v.revert&&w!==Be&&c.add(m)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new U(new L(f,"px"),0)};p&&(g["line-height"]=new U(new Tt(this.context.pref.lineHeight),0));let y=new Pb(g,this.context);for(let b=s.length-1;b>=0;--b){let x=s[b],m=[];for(let C in x)In(C)&&m.push(C);m.sort(Lh);let w,S;for(let C of m){if(b>0&&h&&C.startsWith("--viv-marker-")||b>0&&c.has(C))continue;y.setPropName(C);let T=ve(x,C),R=T;if(T.value===v.initial)delete g[C];else if(!Y(T.value)){if(C==="font-size"&&b===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)R=new U(new L(this.context.rootFontSize,"px"),T.priority);else if(C==="line-height"&&b===s.length-1&&this.context.rootLineHeight&&T.value instanceof L&&(T.value.unit==="lh"||T.value.unit==="rlh"))R=new U(new L(this.context.rootLineHeight,"px"),T.priority);else if(b===0&&T.value instanceof L&&T.value.unit==="lh"){let F=this.getLineHeightUnitSize(C,w,S);F!=null&&(R=new U(new L(T.value.num*F,"px"),T.priority))}else Xe(C)||(R=T.filterValue(y));C==="font-size"?w=R.value:C==="line-height"&&(S=R.value),g[C]=R}}}for(let b in t)In(b)||(g[b]=t[b]);return{lang:o,elementStyle:g}}resolveURL(t){return t=Ie(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=wa(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=gb().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let s=t[r];if(s){if(Y(s))s===v.initial&&(n[r]=void 0);else if(s instanceof lt)n[r]=s.num;else if(s instanceof he)n[r]=s.name;else if(s instanceof L){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*Yt[o.unit];break;default:n[r]=s}}else n[r]=s;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,s,o){let a=Gt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,s,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let s=!0,o=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 T=this.xmldoc.getElementOffset(a);Vo.registerFragmentIndex(T,this.nodeContext.fragmentIndex,0)}let u={},c={getStyle:T=>this.styler.getStyle(T,!1),getProp:(T,R)=>T?ve(T,R):null,getStyleMap:(T,R)=>pt(T,R),getMutableStyleMap:(T,R)=>oi(T,R),createCascadeValue:(T,R)=>new U(T,R),filterFootnoteMarkerContent:(T,R)=>T.filterValue(new Br(this.styler.cascade,R,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let T=this.inheritFromSourceParent(l);l=T.elementStyle,this.nodeContext.lang=T.lang}let p=l.position,f=l.float,g=l["float-reference"],y=f&&!Y(f.value)&&f.value!==v.none&&g&&!Y(g.value)?Gv(g.value.toString()):null,b=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===ot.ROOTED&&Et(a);if(this.nodeContext.parent&&(yr(p?.value)||y&&Ai(y)||b)){let T=this.inheritFromSourceParent(l);l=T.elementStyle,this.nodeContext.lang=T.lang}l=Yv(a,l,this.nodeContext.shadowContext,this.xmldoc.url,T=>this.xmldoc.getElement(T),Sr,c),l=Zv(a,l,this.nodeContext.shadowContext,this.context,c),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),y&&Ai(y)&&u.display===v.block&&(u.display=v.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let x=u["flow-into"];if(x&&x.toString()!=this.flowName)return o.finish(!1),o.result();if(vi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return hh(a,this.viewport.window).thenFinish(o),o.result();let m=u.display;if(Et(a)&&!b&&a.hasAttribute(hp)&&(m=u.display=v.none),Y(m)&&(m===v.initial||m===v.unset?m=v.inline:m===v.inherit?m=((n=this.nodeContext.parent)==null?void 0:n.display)&&M((r=this.nodeContext.parent)==null?void 0:r.display):m=null),m===v.none)return o.finish(!1),o.result();let w=this.nodeContext.parent==null,S=u[this.nodeContext.vertical?"width":"height"],C=(m===v.grid||m===v.inline_grid)&&!!S&&!(S===v.auto||Y(S));return this.nodeContext.flexContainer=m===v.flex||C,this.createShadows(a,w,l,u,h,this.context,this.nodeContext.shadowContext).then(T=>{var R,F;this.nodeContext.nodeShadow=T;let z=u.position,$=u.float,X=u.clear,re=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,k=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:re,_=lv(a),E=u["column-count"],B=u["column-width"],P=E&&E!==v.auto&&!Y(E)||B&&B!==v.auto&&!Y(B);this.nodeContext.establishesBFC=uv(m,z,$,u.overflow,re,k,P||_),this.nodeContext.containingBlockForAbsolute=cv(z),this.nodeContext.isInsideBFC()&&$!==v.footnote&&!(y&&Ai(y))&&($=null,X=null);let N=null,O=!1,V=this.isFootnote&&(!((R=this.nodeContext)!=null&&R.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||b),W=Kv(a,this.nodeContext.shadowContext,c);Jv(W.sourceStyle,u,this.context),N=W.footnoteDisplay;let K=$ instanceof J||$===v.left||$===v.right||$===v.top||$===v.bottom||$===v.inline_start||$===v.inline_end||$===v.block_start||$===v.block_end||$===v.snap_block||$===v.snap_inline||$===v.inside||$===v.outside||$===v.footnote;if($&&(delete u.float,$===v.footnote))if(N=u["footnote-display"]||N,O=!!u["--viv-marker-content"],V){K=!1;let G=N?.toString();G&&(u["--viv-footnote-display"]=M(G)),m=O?M("list-item"):G==="inline"||G==="compact"?v.inline:v.block,u.display=m}else u.display=v.inline;if(V&&Et(a)){O=O||!!u["--viv-marker-content"];let G=N?.toString();G&&(u["--viv-footnote-display"]=M(G)),O&&(m=u.display=M("list-item")),!O&&(G==="inline"||G==="compact")&&(m=u.display=v.inline)}X&&(X===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(X=M(this.nodeContext.parent.clearSide)),(X===v.left||X===v.right||X===v.top||X===v.bottom||X===v.inline_start||X===v.inline_end||X===v.block_start||X===v.block_end||X===v.inside||X===v.outside||X===v.both||X===v.all||X===v.same||X===v.column||X===v.region||X===v.page)&&(delete u.clear,(K||u.display&&u.display!=v.inline)&&(this.nodeContext.clearSide=X.toString())));let te=hr(m)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),Q=u["break-inside"];(K||Q&&!Y(Q)&&Q!==v.auto)&&this.nodeContext.breakPenalty++,m&&m!==v.inline&&Dt(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!K&&!m||Dt(m)||Dd(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=K?$.toString():null,this.nodeContext.floatReference=y||Te.INLINE;let pe=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=pe&&!Y(pe)?pe:null;let se=this.isInsideNonRootMultiColumn(),oe=u["column-span"];if(this.nodeContext.columnSpan=!se&&oe&&!Y(oe)?oe:null,!this.nodeContext.inline){let G=u["break-after"];G&&!Y(G)&&!(se&&G===v.column)&&(this.nodeContext.breakAfter=G.toString(),Ba[this.nodeContext.breakAfter]&&(u["break-after"]=v.column));let Bt=u["break-before"];Bt&&!Y(Bt)&&!(se&&Bt===v.column)&&(this.nodeContext.breakBefore=Bt.toString(),Ba[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let qt=u.page,an=qt&&!Y(qt)?qt.toString():null,Mt=an;!Mt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===v.table_header_group||m===v.table_footer_group)&&(Mt=this.styler.cascade.currentPageType),!Mt||Mt.toLowerCase()==="auto"?Mt=this.nodeContext.pageType:this.nodeContext.pageType=Mt;let Zn=an!=null&&an.toLowerCase()!=="auto",wi=Zn?this.nodeContext.fragmentIndex===1?this.getEffectiveStartPageType(a,Mt):(F=this.styler.cascade.currentPageType)!=null?F:Mt:Mt;this.styler.cascade.currentPageType!==wi&&!(!Zn&&u.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!en(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),wi!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=wi)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let De=u["border-collapse"];if(!De||De===M("separate")){let G=u["border-spacing"],Bt,qt;G&&(G instanceof J?(Bt=G.values[0],qt=G.values[1]):Bt=qt=G,Bt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=ut(Bt,this.context)),qt.isNumeric()&&(this.nodeContext.blockBorderSpacing=ut(qt,this.context)))}let Ne=u["footnote-policy"]||W.footnotePolicy;Ne&&!Y(Ne)&&(u["--viv-footnote-policy"]=Ne),this.nodeContext.footnotePolicy=Ne&&!Y(Ne)?Ne:null;let fe=u["x-first-pseudo"];if(fe){let G=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Vv(G,fe.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Ce=u["white-space"];if(Ce){let G=Kd(Ce.toString());G!==null&&(this.nodeContext.whitespace=G)}let ge=u["hyphenate-character"];ge&&ge instanceof Z&&(this.nodeContext.hyphenateCharacter=ge.str);let Ae=u["word-break"],Oe=u["line-break"],Fe=u["overflow-wrap"];(Ae===v.break_all||Oe===v.anywhere||Fe===v.break_word||Fe===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,m,z,$,w),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,h));let Ue=!1,ft=null,Yn=[],At=a.namespaceURI,me=a.localName,is=me;At=="http://www.w3.org/1999/xhtml"?(Rx.has(me)?me="div":me=="vide_"?me="video":me=="audi_"?me="audio":me=="object"&&(Ue=!!this.customRenderer),a.hasAttribute(sh)&&a.hasAttribute("src")&&u.content instanceof it&&(me="img")):At=="http://www.idpf.org/2007/ops"?(me="span",At="http://www.w3.org/1999/xhtml"):At=="http://www.pyroxy.com/ns/shadow"?(At="http://www.w3.org/1999/xhtml",me=this.nodeContext.inline?"span":"div"):Ue=!!this.customRenderer,te?t?(me="li",u["--viv-marker-content"]&&(u["list-style-type"]=v.none,u["list-style-image"]=v.none)):(m=Dt(m)?v.inline:v.block,u.display=m,me="div"):me=="body"||me=="li"?me="div":me=="q"&&(me="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(Ue=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(Ue=!0);let Go;if(Ue){let G=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;Go=this.customRenderer(a,G,u)}else Go=I(null);Go.then(G=>{var Bt,qt,an,Mt,Zn;if(G)Ue&&(s=G.getAttribute("data-adapt-process-children")=="true");else if(u.display===v.none){o.finish(!1);return}else G=this.createElement(At,me);if(!w&&P&&u["column-fill"]===v.auto){let We=this.nodeContext.vertical?u.width:u.height;(!We||We===v.auto||Y(We))&&(G.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=v.balance)}me!=is&&(G.setAttribute("data-vivliostyle-original-tag",is),(is==="html"||is==="body")&&(G.role="presentation")),me=="a"&&G.addEventListener("click",this.page.hrefHandler,!1),ft&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ft),G.appendChild(ft)),G.localName=="iframe"&&G.namespaceURI=="http://www.w3.org/1999/xhtml"&&Lx(G);let wi=this.nodeContext.inheritedProps["image-resolution"],jo=[],Xo=u.width,qo=u.height,xg=a.getAttribute("width"),Sg=a.getAttribute("height"),Yo=Xo===v.auto||!Xo&&!xg,Zo=qo===v.auto||!qo&&!Sg,yh=a.attributes,Cg=yh.length,Kn=null,vh=null;m===v.table_cell&&((an=(qt=(Bt=this.nodeContext.parent)==null?void 0:Bt.viewNode)==null?void 0:qt.lastElementChild)==null?void 0:an.localName)==="a"&&G.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let We=0;We<Cg;We++){let xt=yh[We],ht=xt.namespaceURI,ae=xt.localName,ke=xt.nodeValue;if(ht){if(ht=="http://www.w3.org/2000/xmlns/")continue;ht=="http://www.w3.org/1999/xlink"&&ae=="href"&&(ke=this.documentURLTransformer.transformURL(this.resolveURL(ke),this.xmldoc.url))}else{if(!vi&&ae.match(/^on/)||ae=="style")continue;if(ae==="media"&&me==="source"&&At==="http://www.w3.org/1999/xhtml"&&((Mt=a.parentElement)==null?void 0:Mt.localName)==="picture")try{let Ge=this.context.rootScope,gt=new Lo(Ge),rs=new bt(ke,gt),wh=Bd(rs,gt,"");if(wh){if(wh.toExpr().evaluate(this.context))continue;ke="not all"}}catch{}if((ae=="id"||ae=="name")&&t){let Ge=this.documentURLTransformer.transformFragment(ke,this.xmldoc.url);G.setAttribute(ae,ke),G.setAttribute("data-vivliostyle-id",Ge);let gt=G.ownerDocument.createElement("a");gt.setAttribute(ae,Ge),gt.setAttribute(Dn,"1"),gt.style.position="absolute",G.appendChild(gt),this.page.registerElementWithId(G,Ge);continue}if(ae=="src"||ae=="href"||ae=="poster")ke=this.resolveURL(ke),ae==="href"?ke=this.documentURLTransformer.transformURL(ke,this.xmldoc.url):ke=Ir(ke),ae==="src"&&(ke=vc(ke));else if(ae=="srcset")ke=ke.split(",").map(Ge=>{let gt=Ge.trim().split(/\s+/),rs=Ir(this.resolveURL(gt[0]));return gt.length>1?`${rs} ${gt.slice(1).join(" ")}`:rs}).join(",");else if(ae==="data"&&Ue&&me==="object"&&G.hasAttribute("data"))continue;if(ae==="poster"&&me==="video"&&At==="http://www.w3.org/1999/xhtml"){let Ge=new Image,gt=kt(Ge,ke);Yo&&Zo?(Yn.push(gt),jo.push({image:Ge,element:G,fetcher:gt})):this.page.fetchers.push(gt)}}if(At=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(ke=Ax(ke,this.xmldoc.url,this.documentURLTransformer)),ht){let Ge=Fx[ht];Ge&&(ae=`${Ge}:${ae}`)}if(ae=="src"&&!ht&&(me=="img"||me=="input")&&At=="http://www.w3.org/1999/xhtml")Kn=ke;else if(ae=="alt"&&!ht&&me=="img"&&At=="http://www.w3.org/1999/xhtml")vh=ke;else if(ae=="href"&&me=="image"&&At=="http://www.w3.org/2000/svg"&&(ht=="http://www.w3.org/1999/xlink"||!ht))ht||G.setAttribute(ae,ke),this.page.fetchers.push(kt(G,ke));else if(ht)G.setAttributeNS(ht,ae,ke);else try{G.setAttribute(ae,ke)}catch(Ge){q.warn(Ge)}}if(Kn){let We=me==="input"?new Image:G,xt=kt(We,Kn,vh);We!==G&&(G.src=Kn);let ht=()=>{var ae,ke;if(u.position===v.fixed)return!0;for(let Ge=(ae=this.nodeContext.parent)==null?void 0:ae.viewNode;Ge&&Ge!==this.viewRoot;Ge=Ge.parentElement)if(((ke=Ge.style)==null?void 0:ke.position)==="fixed")return!0;return!1};!Yo&&!Zo&&!(()=>{let ae=this.nodeContext.vertical?Xo:qo;return ae instanceof L&&ae.unit==="%"})()&&!ht()?this.page.fetchers.push(xt):(Yo&&Zo&&wi&&wi!==1&&jo.push({image:We,element:G,fetcher:xt}),Yn.push(xt))}else!Kn&&me==="img"&&At==="http://www.w3.org/1999/xhtml"&&(G.srcset||((Zn=a.parentElement)==null?void 0:Zn.localName)==="picture")&&this.page.fetchers.push(kt(G));delete u.content;let ns=u["--viv-marker-content"];if(ns){let We=ns instanceof J?ns.values:[ns];for(let xt of We)xt instanceof it&&xt.url&&Yn.push(kt(new Image,xt.url))}if(G.localName==="object"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("data")&&this.page.fetchers.push(kt(G)),G.localName==="embed"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("src")&&this.page.fetchers.push(kt(G)),G.localName==="iframe"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("src")){let We=G;We.loading==="lazy"&&(We.loading="eager"),this.page.fetchers.push(kt(G))}if(this.preprocessElementStyle(u),this.applyComputedStyles(G,u),this.nodeContext.inline)t||(St(G,"inline-start"),Pn(G)&&St(G,"clone"));else if(t){if(!Ar(u.position)){let We=u["margin-break"],xt=this.getBreakTypeAt(this.nodeContext),ht=xt!==null,ae=xt==="auto";(We===v.discard&&ht||We!==v.keep&&ae&&!this.nodeContext.floatSide)&&ra(G,"block-start")}}else{let We=this.nodeContext.vertical?"width":"height";ki(G,We)&&A(G,We,this.nodeContext.display==="table-row"?"0.01px":""),St(G,"block-start"),Pn(G)&&St(G,"clone"),ra(G,"block-start")}te&&u["ua-list-item-count"]&&G.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=G,Yn.length?_n(Yn).then(()=>{wi>0&&this.modifyElemDimensionWithImageResolution(jo,wi,u,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Ee(r,n.parent.whitespace)||Rt(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&&Kr(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Ze(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&&(Ee(f,h.parent.whitespace)||!h.floatSide&&Rt(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(s=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:s.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Ze(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let s=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(s&&s["after-if-continues"]&&s["after-if-continues"].content){let o=new fa(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new x0(t,o)}}isSVGUrlAttribute(t){return fr.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(s=>{if(s.fetcher.get().get()==="load"){let o=s.image,a=o.width/i,h=o.height/i,l=s.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=ut(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=ut(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=ut(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=ut(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||v.none,c=n["max-height"]||v.none;if(u===v.none&&c===v.none)A(l,"max-width",`${a}px`);else if(u!==v.none&&c===v.none)A(l,"width",`${a}px`);else if(u===v.none&&c!==v.none)A(l,"height",`${h}px`);else{u.isNumeric(),c.isNumeric();let p=u,f=c;p.unit!=="%"?A(l,"max-width",`${Math.min(a,ut(p,this.context))}px`):f.unit!=="%"?A(l,"max-height",`${Math.min(h,ut(f,this.context))}px`):r?A(l,"height",`${h}px`):A(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Le,c=n["min-height"]||Le;u.isNumeric(),u.isNumeric();let p=u,f=c;p.num===0&&f.num===0?A(l,"min-width",`${a}px`):p.num!==0&&f.num===0?A(l,"width",`${a}px`):p.num===0&&f.num!==0?A(l,"height",`${h}px`):p.unit!=="%"?A(l,"min-width",`${Math.max(a,ut(p,this.context))}px`):f.unit!=="%"?A(l,"min-height",`${Math.max(h,ut(f,this.context))}px`):r?A(l,"height",`${h}px`):A(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Gt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},s=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",s,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof tn&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new tn(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||Y(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=D("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=su(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return I(!0);let t,i=t=this.sourceNode.textContent,n=D("preprocessTextContent"),r=Gt("PREPROCESS_TEXT_CONTENT"),s=0;return n.loop(()=>s>=r.length?I(!1):r[s++](this.nodeContext,i).thenAsync(o=>(i=o,I(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Tv(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=D("createNodeView"),r,s=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=I(!0)):r=this.createTextNodeView(),r.then(o=>{var a;if(s=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(c,p)=>c?.nodeType===1&&ii(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&&Ee(this.viewNode))&&!u.hasChildNodes()&&Xd(u).includes("block-start")&&St(u,"text-start"),u.appendChild(this.viewNode),gv(this.viewNode))}n.finish(s)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):I(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,s,o,a=n.subShadow||n.parentShadow;n.subShadow?(s=n.subShadow.root,o=n.subShadow.type,o==ot.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=ot.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let l=new bn(s,r,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ot.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==ot.ROOTLESS&&(r=r.firstChild),r){let s=new bn(r,t,i);return s.shadowContext=t.nodeShadow,s.shadowType=t.nodeShadow.type,this.processShadowContent(s)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new bn(n,t,i));if(t.sourceNode.nodeType!=1){let r=su(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let s=r;return ii(s)==="footnote-call"&&s.getAttribute(fr.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?s:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&Et(i)}insertFootnoteCall(t){var i,n;let r=D("insertFootnoteCall"),s=dr.createElementNS("http://www.w3.org/1999/xhtml","span");kr(s,"footnote-call");let o=this.xmldoc.getElementOffset(t.sourceNode);s.setAttribute(fr.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let a=new bn(s,t.parent,t.boxOffset);a.inline=!0;let h=new fa(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Rs(t.sourceNode,s,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,ot.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&s.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return I(n);this.syncTextNodePageTypeBoundary(n);let r=D("nextInTree");return this.setCurrent(n,!0,i).then(s=>{if((!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let o=this.findImmediateFootnoteCallSibling(n);o!=null&&o.parentNode&&o.parentNode.removeChild(o),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){Er(t,this.page)}applyComputedStyles(t,i){var n,r,s;let o=i["background-image"];o&&this.addImageFetchers(o);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===v.relative,y=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),b=Object.keys(i);b.sort(Lh);let x,m;for(let w of b){if(Bx[w])continue;let S=i[w];if(!(!S||S===Be&&!Xe(w))){if(S=S.visit(new Gm(this.xmldoc.url,this.documentURLTransformer)),S instanceof L)if(S.unit==="em"){let C=this.getEmUnitSize(w,x);C!=null&&(S=new L(S.num*C,"px"))}else if(S.unit==="lh"){let C=this.getLineHeightUnitSize(w,x,m);C!=null&&(S=new L(S.num*C,"px"))}else Nc(S.unit)&&(S=Gc(S,this.context));if((w==="font-size"||w==="line-height")&&(w==="font-size"?x=S:m=S,this.viewport.layoutUnitAdj&&S instanceof L&&S.unit!=="%"&&S.unit!=="em"&&S.unit!=="lh"&&(S=new pn(`calc(${S.toString()} - var(--viv-layoutUnitAdj))`))),Fv[w]||g&&Rv[w]){this.page.delayedItems.push(new _l(t,w,S));continue}y&&this.page.pageAreaElement&&In(w)?(A(this.page.pageAreaElement.parentElement.parentElement,w,S.toString()),w!=="writing-mode"&&w!=="direction"&&A(this.viewport.layoutBox,w,S.toString())):A(t,w,S.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,s=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,o=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||s*this.context.pref.lineHeight;return{fontSize:s,lineHeight:o}}getComputedFontMetrics(t,i){var n,r,s;let o=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(o.fontSize))!=null?n:i.fontSize,h=(s=(r=this.parsePlusLayoutUnitAdj(o.lineHeight))!=null?r:i.lineHeight)!=null?s: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,s,o;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 Tt||n instanceof L&&(n.unit==="em"||n.unit==="%"))u=n instanceof L&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof L&&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=(s=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:s.viewNode;c&&c.nodeType===1;c=c.parentNode){let p=(o=c?.style)==null?void 0:o.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(u=parseFloat(p));break}}if(u!=null){if(i&&!(i instanceof L))return null;let c=h.fontSize;if(i instanceof L){let p=tl(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 L){let s=tl(i,r,this.context).num;if(typeof s=="number"&&!isNaN(s))return s}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,s=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),o=pt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let h=a.content;It(h)&&(h.visit(new Rr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=D("peelOff"),r=t.firstPseudo,s=t.offsetInNode,o=t.after;if(i>0){let c=t.viewNode.textContent;t.viewNode.textContent=c.substr(0,i),s+=i}else if(!o&&t.viewNode&&s==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 bn(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:u,u=null;let c=this.setCurrent(t,!1);if(c.isPending())return c}return I(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let s={},o=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=pt(this.cascadedPageStyle,Po);p&&p.area&&(a=p.area)}let h=pt(a,"_pseudos");t=this.computeStyle(t,i,a,s);let l=this.getFootnoteAreaInheritedMetrics();!s["font-size"]&&l.fontSize!=null&&(s["font-size"]=new L(l.fontSize,"px")),delete s.content;let u=this.computedStyleParentFontSizeOverride,c=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,s);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ve(f,"display"),y={},b=this.createElement("http://www.w3.org/1999/xhtml","span");kr(b,"before"),n.appendChild(b),this.computeStyle(t,i,f,y),g||(y.display=v.block);let x=ve(f,"content");if(x){let w=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;y.content=x.filterValue(new Br(this.styler.cascade,w,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let m=y.content;if(It(m)){m.visit(new Rr(b,this.context,m,this.exprContentListener));let w=b.querySelectorAll("img[src]");for(let C=0;C<w.length;C++){let T=w[C],R=T.getAttribute("src");if(!R)continue;let F=kt(T,R);o.push(F),this.page.fetchers.push(F)}let S=b.getAttribute("src");if(S){let C=b.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",S),b.appendChild(C));let T=kt(C,S);o.push(T),this.page.fetchers.push(T)}}delete y.content,this.applyComputedStyles(b,y)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=c}return o.length?_n(o).thenReturn(t):I(t)}processFragmentedBlockEdge(t){var i,n,r;let s=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=ve(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!Dt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=s;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(St(l,"inline-end"),Pn(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;St(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(ki(l,u)&&A(l,u,""),St(l,"block-end"),!a++&&h!==s){let{textAlign:c}=this.viewport.window.getComputedStyle(l);if(c==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?qd(p,["block-start","text-start","block-end","text-end","justify"]):(St(l,"text-end"),St(l,"justify")):St(l,"text-end")}else St(l,"text-end")}Pn(l)&&St(l,"clone"),ra(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),s=-(n+r);isNaN(s)||(t.style.marginInlineEnd=`${s}px`)}createChildAnonymousBlockIfNeeded(t){let i=s=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||ji[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let l=s.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===s.lastChild&&Ee(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(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||s.hasAttribute(Dn)){let l=s.previousElementSibling;return l&&(l.nextSibling===s||l.nextSibling===s.previousSibling&&Ee(l.nextSibling))?i(l):!1}return!(!o||Dt(o))},n=null;for(let s=t.lastElementChild;s;s=s.previousElementSibling){let o=i(s);if(o){n=s;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ee(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let s=n.nextSibling,o=null;s;s=o)o=s.nextSibling,r.appendChild(s);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,s=t.unit;if(hm(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Ql(t,a,this.context).num}else{let o=this.context.queryUnitSize(s,!1);return o?r*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&ii(n)===ii(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let s=i.steps[r];return this.isSameNodePositionStep(n,s)})}isPseudoelement(t){return!!ii(t)}};d(cl,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),d(cl,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var Ox=cl,Bx={"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}},ko=class{constructor(e,t,i,n,r,s){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=s||this.root.clientHeight;return}let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(A(this.root,"--viv-outputPixelRatio",`${i}`),A(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),bl){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&&A(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=s||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=l.width),(!this.height||!s&&u)&&(this.height=l.height)}resetZoom(){A(this.outerZoomBox,"width",""),A(this.outerZoomBox,"height",""),A(this.contentContainer,"width",""),A(this.contentContainer,"height",""),A(this.contentContainer,"transform","")}zoom(e,t,i){A(this.root,"--viv-outputScale",`${i}`),A(this.outerZoomBox,"width",`${e*i}px`),A(this.outerZoomBox,"height",`${t*i}px`),A(this.contentContainer,"width",`${e}px`),A(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function Er(e,t){if(e instanceof _e)for(let i of e.values)Er(i,t);else if(e instanceof it){let i=Ir(e.url);t.fetchers.push(kt(new Image,i))}else if(e instanceof ai)for(let i of e.values)Er(i,t);else if(e instanceof J)for(let i of e.values)Er(i,t)}var _x=1,Uo=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${_x++}`,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})}},Dx=class extends Uo{constructor(e){super(e,null,null,[],null),this.specified.width=new U(Gr,0),this.specified.height=new U(jr,0)}},Vu=class extends Js{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,s){let o=r.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return s?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},Yf=class Zf extends Uo{constructor(t,i,n,r,s,o,a){super(t,i,n,r,s),this.condition=o,this.specificity=a,d(this,"keyMap",{}),t instanceof Vu||(this._scope=new Vu(t,this)),this.pageMaster=this,this.specified.width=new U(Gr,0),this.specified.height=new U(jr,0),this.specified["wrap-flow"]=new U(v.auto,0),this.specified.position=new U(v.relative,0),this.specified.overflow=new U(v.visible,0)}createInstance(t){return new ch(t,this)}clone(t){let i=new Zf(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}},Kf=class Jf extends Uo{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new U(v.auto,0)}createInstance(t){return new Ux(t,this)}clone(t){let i=new Jf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},ts=class Qf extends Uo{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Un(t,this)}clone(t){let i=new Qf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function zx(e,t,i){return!t||Y(t)?new tt(e,i):t.toExpr(e,e.zero)}function be(e,t,i){return!t||t===v.auto||Y(t)?null:t.toExpr(e,i)}function Vx(e,t,i){return!t||t===v.normal||Y(t)?null:t.toExpr(e,i)}function Nt(e,t,i){return!t||t===v.auto||Y(t)?e.zero:t.toExpr(e,i)}function $u(e,t,i){return!t||Y(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function si(e,t,i,n){return!t||i===v.none||Y(t)?e.zero:t.toExpr(e,n)}function eg(e,t,i){return!t||Y(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Wo=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 ne(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?Kp:Jp;n=e;for(let s in r)n=n.replace(s,r[s])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Dc(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ye(i,As(i,new mr(i,"min",[n,r]),ne(i,s,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=eg(e,t.enabled,e._true),n=be(e,t.page,e.zero);if(n){let o=new Je(e,"page-number");i=Ut(e,i,new Nl(e,n,o))}let r=be(e,t["min-page-width"],e.zero);r&&(i=Ut(e,i,new Sa(e,new Je(e,"page-width"),r)));let s=be(e,t["min-page-height"],e.zero);s&&(i=Ut(e,i,new Sa(e,new Je(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new j(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=be(e,t.left,i),r=be(e,t["margin-left"],i),s=si(e,t["border-left-width"],t["border-left-style"],i),o=Nt(e,t["padding-left"],i),a=be(e,t.width,i),h=be(e,t["max-width"],i),l=Nt(e,t["padding-right"],i),u=si(e,t["border-right-width"],t["border-right-style"],i),c=be(e,t["margin-right"],i),p=be(e,t.right,i),f=ne(e,s,o),g=ne(e,s,l);if(n&&p&&a){let x=ye(e,i,ne(e,a,ne(e,ne(e,n,f),g)));r?c?p=ye(e,x,c):c=ye(e,x,ne(e,p,r)):(x=ye(e,x,p),c?r=ye(e,x,c):(r=As(e,x,new tt(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=ye(e,i,ne(e,ne(e,r,f),ne(e,c,g)));this.isAutoWidth&&(h||(h=ye(e,x,n||p)),!this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ye(e,x,ne(e,n,a))):a=ye(e,x,ne(e,n,p)):n=ye(e,x,ne(e,p,a))}let y=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),b=Nt(e,y,i);t.left=new j(n),t["margin-left"]=new j(r),t["border-left-width"]=new j(s),t["padding-left"]=new j(o),t.width=new j(a),t["max-width"]=new j(h||a),t["padding-right"]=new j(l),t["border-right-width"]=new j(u),t["margin-right"]=new j(c),t.right=new j(p),t["snap-width"]=new j(b)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=be(e,t.top,n),s=be(e,t["margin-top"],i),o=si(e,t["border-top-width"],t["border-top-style"],i),a=Nt(e,t["padding-top"],i),h=be(e,t.height,n),l=be(e,t["max-height"],n),u=Nt(e,t["padding-bottom"],i),c=si(e,t["border-bottom-width"],t["border-bottom-style"],i),p=be(e,t["margin-bottom"],i),f=be(e,t.bottom,n),g=ne(e,o,a),y=ne(e,c,u);if(r&&f&&h){let m=ye(e,n,ne(e,h,ne(e,ne(e,r,g),y)));s?p?f=ye(e,m,s):p=ye(e,m,ne(e,f,s)):(m=ye(e,m,f),p?s=ye(e,m,p):(s=As(e,m,new tt(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let m=ye(e,n,ne(e,ne(e,s,g),ne(e,p,y)));this.isAutoHeight&&(l||(l=ye(e,m,r||f)),this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ye(e,m,ne(e,r,h))):h=ye(e,m,ne(e,f,r)):r=ye(e,m,ne(e,f,h))}let b=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=Nt(e,b,i);t.top=new j(r),t["margin-top"]=new j(s),t["border-top-width"]=new j(o),t["padding-top"]=new j(a),t.height=new j(h),t["max-height"]=new j(l||h),t["padding-bottom"]=new j(u),t["border-bottom-width"]=new j(c),t["margin-bottom"]=new j(p),t.bottom=new j(f),t["snap-height"]=new j(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=be(e,t[this.vertical?"height":"width"],null),n=be(e,t["column-width"],i),r=be(e,t["column-count"],null),s=Vx(e,t["column-gap"],null);s||(s=new Wr(e,1,"em")),n&&!r&&(r=new mr(e,"floor",[Ca(e,ne(e,i,s),ne(e,n,s))]),r=new mr(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,Ca(e,ne(e,i,s),r),s),t["column-width"]=new j(n),t["column-count"]=new j(r),t["column-gap"]=new j(s)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=ll(this.cascaded,e,r,!1,null);this.vertical=bf(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=xf(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof gh&&e.currentLayoutPosition&&new Je(i,"left-page").evaluate(e));Cf(s,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new we(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new we(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&&In(t)&&this.pageMasterInstance instanceof Bn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new L(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=xo(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let s=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=xo(e,r,t,s)}return ut(r,e)}getSpecial(e,t){let i=nf(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==Be&&n.push(s)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&Nc(r.unit)&&(r=Gc(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),A(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new _l(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),s=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),A(t.element,"margin-left",`${n}px`),A(t.element,"padding-left",`${r}px`),A(t.element,"border-left-width",`${s}px`),t.marginLeft=n,t.borderLeft=s,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),s=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(A(t.element,"margin-right",`${r}px`),A(t.element,"padding-right",`${s}px`),A(t.element,"border-right-width",`${o}px`),t.marginRight=r,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,s+=t.snapOffsetX)}t.paddingRight=s,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),s=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,s+=t.snapOffsetY)}t.paddingTop=s,A(t.element,"top",`${n}px`),A(t.element,"margin-top",`${r}px`),A(t.element,"padding-top",`${s}px`),A(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),s=this.getPropAsNumber(e,"height")-t.snapOffsetY;A(t.element,"height",`${s}px`),A(t.element,"margin-bottom",`${i}px`),A(t.element,"padding-bottom",`${n}px`),A(t.element,"border-bottom-width",`${r}px`),t.height=s-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){A(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,A(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){A(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");A(t.element,"right",`${n}px`),A(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&A(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&A(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let s=0;s<Hu.length;s++)this.propagateProperty(e,t,Hu[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<Wu.length;r++)this.propagateProperty(e,t,Wu[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;A(r,"text-overflow","inherit"),A(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var s,o;let a=(o=(s=this.cascaded.width)!=null?s:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!Y(a)},r=()=>{var s,o;let a=(o=(s=this.cascaded.height)!=null?s:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!Y(a)};for(let s=0;s<Gu.length;s++){let o=Gu[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;A(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){var a,h,l,u,c,p,f,g,y,b;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let x=(this.vertical||!n)&&this.isAutoHeight,m=(!this.vertical||!n)&&this.isAutoWidth,w=null;if(m||x){m&&A(t.element,"width","auto"),x&&A(t.element,"height","auto");let S=n&&io(n);S&&Bo(n),w=s.getElementClientRect(n?n.element:t.element),S&&Ll(n),m&&(this.calculatedWidth=Math.ceil(w.right-w.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=w.bottom-w.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let S=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),T=this.getProp(e,"column-rule-color");if(S>0&&C&&C!=v.none&&T!=v.transparent){let R=this.getPropAsNumber(e,"column-gap"),F=this.vertical?t.height:t.width,z=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),$=t.getPaddingRect(),X=n,re=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(F+R)*k/r-R/2+t.paddingTop-S/2:(F+R)*k/r-R/2+t.paddingLeft-S/2,E=this.vertical?$.y1+_+S/2:$.x1+_+S/2,B=(c=(u=(l=X.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:c.call(u,E),P=(g=(f=(p=X.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),N=isFinite(B)?this.vertical?B-$.x1:B-$.y1:NaN,O=isFinite(P)?this.vertical?P-$.x1:P-$.y1:NaN,V=parseFloat(this.vertical?(y=n?.element.style.width)!=null?y:"":(b=n?.element.style.height)!=null?b:""),W=V>0?V:this.vertical?n.width:n.height,K=Math.max(z>0?z:0,0),te=K+W,Q=Math.max(K,isFinite(this.vertical?O:N)?Math.max(0,this.vertical?O:N):0),pe=Math.min(te,isFinite(this.vertical?N:O)?Math.max(0,this.vertical?N:O):te),se=Math.max(0,pe-Q),oe=t.element.ownerDocument.createElement("div");A(oe,"position","absolute"),A(oe,this.vertical?"left":"top",`${Q}px`),A(oe,this.vertical?"top":"left",`${_}px`),A(oe,this.vertical?"height":"width","0px"),A(oe,this.vertical?"width":"height",`${se}px`),A(oe,re,`${S}px ${C.toString()}${T?` ${T.toString()}`:""}`),t.element.insertBefore(oe,t.element.firstChild)}}}for(let S=0;S<Uu.length;S++)this.propagateProperty(e,t,Uu[S],o);for(let S of $x){let C=this.getProp(e,S);C&&Er(C,i)}for(let S=0;S<ju.length;S++)this.propagateDelayedProperty(e,t,ju[S],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof Bn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Xi(s)&&Fi(i,s,ve(n,s));if(this.pageBox.pseudoName==uh)for(let s in t)(s.match(/^background-/)||s=="writing-mode")&&(i[s]=t[s]);if(this.pageBox.pseudoName=="layout-host")for(let s in t)!s.match(/^background-/)&&s!="writing-mode"&&(i[s]=t[s]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;if(r){let s=Array.from(e.lastCounterChanges),o={...e.lastCounterChangeTypes};e.counterScoping.push(null),e.pushCounters(i),i.content=r.filterValue(new Br(e,null,e.counterResolver)),e.popCounters(),e.popCounters(),e.lastCounterChanges=s,e.lastCounterChangeTypes=o}this.init(e.context);for(let s of this.pageBox.children)s.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Hu=["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","outline-offset","overflow","visibility"],Uu=["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"],$x=["background-image","border-image-source","filter"],Wu=["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"],Gu=["width","height","image-resolution","object-fit","object-position"],ju=["transform","transform-origin"],uh="background-host",Hx=class extends Wo{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)}},ch=class extends Wo{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Ut(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Ux=class extends Wo{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Un=class extends Wo{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof he&&(n=[t]),t instanceof _e&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof he){let o=ba(n[s].name,"enabled"),a=new Je(r,o);i&&(a=new Ii(r,a)),e=Ut(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=eg(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=zx(t,i["flow-from"],"body"),s=new mr(t,"has-content",[r]);e=Ut(t,e,s)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,s=r?r.toExpr(t,null):t._true;s=Ut(t,s,e),this.pageMasterInstance.style.enabled=new j(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof sg||(A(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},dh=class extends sn{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 U(t,i?Ad:Fd)}},tg=class extends dh{constructor(e,t,i,n){super(e,t,i,n)}},Wx=class ig extends dh{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new U(Fh,0),n.specified.height=new U(Fh,0)}startPartitionRule(t,i,n){let r=new ts(this.scope,t,i,n,this.target),s=new tg(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new Kf(this.scope,t,i,n,this.target),s=new ig(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},Gx=class extends dh{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new ts(this.scope,e,t,i,this.target),r=new tg(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Kf(this.scope,e,t,i,this.target),r=new Wx(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function ng(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var jx={a10:{width:new L(26,"mm"),height:new L(37,"mm")},a9:{width:new L(37,"mm"),height:new L(52,"mm")},a8:{width:new L(52,"mm"),height:new L(74,"mm")},a7:{width:new L(74,"mm"),height:new L(105,"mm")},a6:{width:new L(105,"mm"),height:new L(148,"mm")},a5:{width:new L(148,"mm"),height:new L(210,"mm")},a4:{width:new L(210,"mm"),height:new L(297,"mm")},a3:{width:new L(297,"mm"),height:new L(420,"mm")},a2:{width:new L(420,"mm"),height:new L(594,"mm")},a1:{width:new L(594,"mm"),height:new L(841,"mm")},a0:{width:new L(841,"mm"),height:new L(1189,"mm")},b10:{width:new L(31,"mm"),height:new L(44,"mm")},b9:{width:new L(44,"mm"),height:new L(62,"mm")},b8:{width:new L(62,"mm"),height:new L(88,"mm")},b7:{width:new L(88,"mm"),height:new L(125,"mm")},b6:{width:new L(125,"mm"),height:new L(176,"mm")},b5:{width:new L(176,"mm"),height:new L(250,"mm")},b4:{width:new L(250,"mm"),height:new L(353,"mm")},b3:{width:new L(353,"mm"),height:new L(500,"mm")},b2:{width:new L(500,"mm"),height:new L(707,"mm")},b1:{width:new L(707,"mm"),height:new L(1e3,"mm")},b0:{width:new L(1e3,"mm"),height:new L(1414,"mm")},c10:{width:new L(28,"mm"),height:new L(40,"mm")},c9:{width:new L(40,"mm"),height:new L(57,"mm")},c8:{width:new L(57,"mm"),height:new L(81,"mm")},c7:{width:new L(81,"mm"),height:new L(114,"mm")},c6:{width:new L(114,"mm"),height:new L(162,"mm")},c5:{width:new L(162,"mm"),height:new L(229,"mm")},c4:{width:new L(229,"mm"),height:new L(324,"mm")},c3:{width:new L(324,"mm"),height:new L(458,"mm")},c2:{width:new L(458,"mm"),height:new L(648,"mm")},c1:{width:new L(648,"mm"),height:new L(917,"mm")},c0:{width:new L(917,"mm"),height:new L(1297,"mm")},"jis-b10":{width:new L(32,"mm"),height:new L(45,"mm")},"jis-b9":{width:new L(45,"mm"),height:new L(64,"mm")},"jis-b8":{width:new L(64,"mm"),height:new L(91,"mm")},"jis-b7":{width:new L(91,"mm"),height:new L(128,"mm")},"jis-b6":{width:new L(128,"mm"),height:new L(182,"mm")},"jis-b5":{width:new L(182,"mm"),height:new L(257,"mm")},"jis-b4":{width:new L(257,"mm"),height:new L(364,"mm")},"jis-b3":{width:new L(364,"mm"),height:new L(515,"mm")},"jis-b2":{width:new L(515,"mm"),height:new L(728,"mm")},"jis-b1":{width:new L(728,"mm"),height:new L(1030,"mm")},"jis-b0":{width:new L(1030,"mm"),height:new L(1456,"mm")},letter:{width:new L(8.5,"in"),height:new L(11,"in")},legal:{width:new L(8.5,"in"),height:new L(14,"in")},ledger:{width:new L(11,"in"),height:new L(17,"in")}},Xx=new L(.24,"pt"),aC=new L(3,"mm"),qx=new L(10,"mm"),Yx=new L(13,"mm");function Eo(e){let t={width:Gr,height:jr,bleed:Le,bleedOffset:Le,cropOffset:Le},i=e.size;if(!(!i||i.value===v.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&&jx[u.name.toLowerCase()];p&&(c&&c===v.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,s=n&&!Y(n.value)?n.value:v.none,o=r&&!Y(r.value)?r.value:v.auto;if(o===v.auto){if(s!==v.none){let l=!1;s.isSpaceList()?l=s.values.some(u=>u===v.crop):l=s===v.crop,l&&(t.bleed=new L(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!Y(a.value)?a.value:v.auto;return h===v.auto?s!==v.none&&(t.bleedOffset=Yx):h.isNumeric()&&(t.cropOffset=h),t}function Xu(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),s=n+r,o=e.width;o===Gr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-s*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===jr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-s*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=s,i}function rg(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 Pr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var dl=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(dl||{});function Zx(e,t,i,n,r,s,o){let a=r;a<=s+2*Yt.mm&&(a=s+r/2);let h=Math.max(r,a),l=s+h+i/2,u=rg(e,l,l),c=[[0,s+r],[r,s+r],[r,s+r-a]],p=c.map(y=>[y[1],y[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(y=>[s+h-y[0],y[1]]),p=p.map(y=>[s+h-y[0],y[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(y=>[y[0],s+h-y[1]]),p=p.map(y=>[y[0],s+h-y[1]]));let f=Pr(e,i,n);f.setAttribute("points",c.map(y=>y.join(",")).join(" ")),u.appendChild(f);let g=Pr(e,i,n);return g.setAttribute("points",p.map(y=>y.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(y=>{u.style[y]=`${o}px`}),u}var Vr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Vr||{});function Kx(e,t,i,n,r,s){let o=r*2,a,h;t==="top"||t==="bottom"?(a=o,h=r):(a=r,h=o);let l=rg(e,a,h),u=Pr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let c=Pr(e,i,n);c.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(c);let p=Pr(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(Vr).forEach(g=>{let y=Vr[g];y===t?l.style[y]=`${s}px`:y!==f&&(l.style[y]="0",l.style[`margin-${y}`]="auto")}),l}function Jx(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let y=o.value;y instanceof J?y.values.forEach(b=>{b===v.crop?r=!0:b===v.cross&&(s=!0)}):y===v.crop?r=!0:y===v.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let h=i.container,l=h.ownerDocument,u=ut(Xx,n),c=Math.max(0,t.bleedOffset-ut(qx,n)),p=t.bleedOffset-c,f=e["crop-marks-line-color"],g=f&&!Y(f.value)?f.value:v.auto;r&&Object.keys(dl).forEach(y=>{let b=dl[y],x=Zx(l,b,u,g,p,a,c);h.appendChild(x)}),s&&Object.keys(Vr).forEach(y=>{let b=Vr[y],x=Kx(l,b,u,g,p,c);h.appendChild(x)})}var pl=(()=>{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,"outline-offset":!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})(),ph={"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"}},Qx=(()=>{let e=ph;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),fh="vivliostyle-page-rule-master",$r="_marginBoxes",Po="_footnoteArea",sg=class extends Yf{constructor(e,t,i){super(e,null,fh,[],t,null,0),d(this,"pageMarginBoxes",{});let n=Eo(i),r=new eS(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[$r];t&&Qx.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new iS(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new U(v.relative,0),this.specified.width=new U(t.width,0),this.specified.height=new U(t.height,0);for(let i in e)!pl[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Bn(e,this)}},eS=class extends ts{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new tS(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new U(v.auto,0),this.specified["z-index"]=new U(new lt(0),0),this.specified.position=new U(v.absolute,0),this.specified.overflow=new U(v.visible,0);for(let t in pl)pl.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new rS(e,this)}},tS=class extends ts{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new U(M("body"),0)}createInstance(e){return new og(e,this)}},iS=class extends ts{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[$r][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Zp[i]||r&&r.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Be&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new ag(e,this)}},Bn=class extends ch{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=Le,e["margin-left"]=Le,e["border-left-width"]=Le,e["padding-left"]=Le,e["padding-right"]=Le,e["border-right-width"]=Le,e["margin-right"]=Le,e.right=Le}initVertical(){let e=this.style;e.top=Le,e["margin-top"]=Le,e["border-top-width"]=Le,e["padding-top"]=Le,e["padding-bottom"]=Le,e["border-bottom-width"]=Le,e["margin-bottom"]=Le,e.bottom=Le}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new j(e.borderBoxWidth),t.height=new j(e.borderBoxHeight),t["padding-left"]=new j(e.marginLeft),t["padding-right"]=new j(e.marginRight),t["padding-top"]=new j(e.marginTop),t["padding-bottom"]=new j(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},s={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,s,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let s="start",o="center",a="end",h=this.pageBox.scope,l={},u={},c={};for(let w in e){let S=ph[w];if(S){let C=e[w],T=this.pageMarginBoxInstances[w],R=new js(C,T.style,t,h,r);l[S.positionAlongVariableDimension]=C,u[S.positionAlongVariableDimension]=T,c[S.positionAlongVariableDimension]=R}}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,y={};Object.keys(l).forEach(w=>{let S=w,C=be(h,u[S].style[t?"max-width":"max-height"],i.extent);if(C){let T=C.evaluate(n);if(f[S]>T){let R=c[S]=new qu(l[S],u[S].style,t,h,r,T);y[S]=R.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),g=!1,[s,o,a].forEach(w=>{var S;f[w]=(S=y[w])!=null?S:f[w]}));let b={};Object.keys(l).forEach(w=>{let S=w,C=be(h,u[S].style[t?"min-width":"min-height"],i.extent);if(C){let T=C.evaluate(n);if(f[S]<T){let R=c[S]=new qu(l[S],u[S].style,t,h,r,T);b[S]=R.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(c,p.extent),[s,o,a].forEach(w=>{f[w]=b[w]||f[w]}));let x=p.start+p.extent,m=p.start+(p.start+p.extent);[s,o,a].forEach(w=>{let S=f[w];if(S!=null){let C=l[w],T=0;switch(w){case s:T=t?C.left:C.top;break;case o:T=(m-S)/2;break;case a:T=x-S;break}t?C.setHorizontalPosition(T,S-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(T,S-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],h=new nS(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(o.center=l.xSize);let u=(i=l.xSize)!=null?i:r.getOuterSize(),c=Math.max((t-u)/2,0);n&&(o.start=n.hasAutoSize()?c:n.getOuterSize()),s&&(o.end=s.hasAutoSize()?c:s.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,s,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof js&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof js&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),s=t.getOuterMaxContentSize();if(r>0&&s>0){let o=r+s;if(o<i)n.xSize=i*r/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:s>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},js=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 s=t[i?"width":"height"];if(this.hasAutoSize_=!s||s===v.auto||Y(s),this.minMaxFitContent=s instanceof he&&(s.name==="min-content"||s.name==="max-content"||s.name==="fit-content")?s.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Ml(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()}},nS=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}},qu=class extends js{constructor(e,t,i,n,r,s){super(e,t,i,n,r),d(this,"fixedSize"),this.fixedSize=s}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},rS=class extends Un{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,s=e.end,o=e.extent,a=i[o].toExpr(n,null),h=be(n,t[o],a),l=be(n,t[`margin-${r}`],a),u=be(n,t[`margin-${s}`],a),c=Nt(n,t[`padding-${r}`],a),p=Nt(n,t[`padding-${s}`],a),f=si(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=si(n,t[`border-${s}-width`],t[`border-${s}-style`],a),y=ne(n,ne(n,f,c),ne(n,g,p)),b,x,m;return h?(this.borderBoxSizing?(x=h,m=ye(n,x,y)):(m=h,x=ne(n,m,y)),b=ye(n,a,x),!l&&!u?(l=As(n,b,new tt(n,.5)),u=l):l?u=ye(n,b,l):l=ye(n,b,u)):(l||(l=n.zero),u||(u=n.zero),b=ne(n,l,u),x=ye(n,a,b),m=ye(n,x,y),h=this.borderBoxSizing?x:m),t[r]=new j(l),t[s]=new j(u),t[`margin-${r}`]=Le,t[`margin-${s}`]=Le,t[`border-${r}-width`]=new j(f),t[`border-${s}-width`]=new j(g),t[`padding-${r}`]=new j(c),t[`padding-${s}`]=new j(p),t[o]=new j(h),t[`max-${o}`]=new j(h),{borderBoxExtent:x,contentBoxExtent:m,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)}},og=class extends Un{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 j(this.parentInstance.contentBoxWidth),e["margin-left"]=new j(new Sn(i,t.left.toExpr(i,null))),e["margin-right"]=new j(new Sn(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new j(this.parentInstance.contentBoxHeight),e["margin-top"]=new j(new Sn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new j(new Sn(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},ag=class extends Un{constructor(e,t){super(e,t),d(this,"boxInfo"),d(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ph[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){A(t,"display","flex"),A(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&&A(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof it||r instanceof j&&r.expr instanceof we&&r.expr.str.startsWith("running-element-")){let s="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?s=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(s=this.vertical||this.rtl?"end":"start")),A(t,"align-items",s)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=be(n,i[o],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new j(u);else if(l){let c=Nt(n,i[`margin-${r}`],h),p=Nt(n,i[`margin-${s}`],h),f=Nt(n,i[`padding-${r}`],h),g=Nt(n,i[`padding-${s}`],h),y=si(n,i[`border-${r}-width`],i[`border-${r}-style`],h),b=si(n,i[`border-${s}-width`],i[`border-${s}-style`],h),x=ne(n,l,ne(n,this.borderBoxSizing?n.zero:ne(n,ne(n,f,g),ne(n,y,b)),ne(n,c,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new j(ne(n,u,Ca(n,ye(n,h,x),new tt(n,2))));break;case"end":i[r]=new j(ye(n,ne(n,u,h),x));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=$u(n,i[`margin-${s}`],h),u=$u(n,i[`margin-${o}`],h),c=Nt(n,i[`padding-${s}`],h),p=Nt(n,i[`padding-${o}`],h),f=si(n,i[`border-${s}-width`],i[`border-${s}-style`],h),g=si(n,i[`border-${o}-width`],i[`border-${o}-style`],h),y=be(n,i[a],h),b=null;function x(m){if(b)return b;b={extent:y?y.evaluate(m):null,marginInside:l?l.evaluate(m):null,marginOutside:u?u.evaluate(m):null};let w=h.evaluate(m),S=0;return r||[f,c,p,g].forEach(C=>{C&&(S+=C.evaluate(m))}),(b.marginInside===null||b.marginOutside===null)&&S+b.extent+b.marginInside+b.marginOutside>w&&(b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)),b.extent!==null&&b.marginInside!==null&&b.marginOutside!==null&&(b.marginOutside=null),b.extent===null?(b.extent=w-S-b.marginInside-b.marginOutside,b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)):typeof b.extent=="number"&&(b.marginInside===null&&typeof b.marginOutside=="number"?b.marginInside=w-S-b.extent-b.marginOutside:typeof b.marginInside=="number"&&b.marginOutside===null?b.marginOutside=w-S-b.extent-b.marginInside:b.marginInside=b.marginOutside=(w-S-b.extent)/2),b}i[a]=new j(new we(n,function(){let m=x(this).extent;return m===null?"auto":m},a)),i[`margin-${s}`]=new j(new we(n,function(){let m=x(this).marginInside;return m===null?"auto":m},`margin-${s}`)),i[`margin-${o}`]=new j(new we(n,function(){let m=x(this).marginOutside;return m===null?"auto":m},`margin-${o}`)),s==="left"?i.left=new j(ne(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new j(ne(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,s,o){super.finishContainer(e,t,i,n,r,s,o);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let u=this.parentInstance.pageAreaDimension,c=this.getProp(e,"width"),p=c instanceof he&&(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&&A(t.element,"width",p),f&&A(t.element,"min-width",`${f}px`),g&&A(t.element,"max-width",`${g}px`);let w=this.getProp(e,"margin-left"),S=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);A(t.element,"right",`${C}px`),(w===v.auto||S!==v.auto)&&A(t.element,"margin-left","auto"),S===v.auto&&A(t.element,"margin-right","auto")}else l.isInRightColumn&&(A(t.element,"right","0"),(S===v.auto||w!==v.auto)&&A(t.element,"margin-right","auto"),w===v.auto&&A(t.element,"margin-left","auto"))}let y=this.getProp(e,"height"),b=y instanceof he&&(y.name==="min-content"||y.name==="max-content"||y.name==="fit-content")?y.name:null,x=this.getPropAsNumber(e,"min-height"),m=this.getPropAsNumber(e,"max-height");if(b||x||m){b&&A(t.element,"height",b),x&&A(t.element,"min-height",`${x}px`),m&&A(t.element,"max-height",`${m}px`);let w=this.getProp(e,"margin-top"),S=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);A(t.element,"bottom",`${C}px`),(w===v.auto||S!==v.auto)&&A(t.element,"margin-top","auto"),S===v.auto&&A(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(A(t.element,"bottom","0"),(S===v.auto||w!==v.auto)&&A(t.element,"margin-bottom","auto"),w===v.auto&&A(t.element,"margin-top","auto"))}}},sS=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 Je(e,"page-number"),r=new Nl(e,new Oc(e,n,new tt(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ii(e,r)),e.defineName("verso-page",r),(t.pageProgression||ng(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new Ii(e,r))):(e.defineName("left-page",new Ii(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===uh?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 U?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new sg(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:fh}),n=i.specified,r=e.size;if(r&&!Y(r.value)){let o=Eo(e),a=r.priority;Kt(n,"width",new U(o.width,a),this.context),Kt(n,"height",new U(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let s=i.createInstance(this.rootPageBoxInstance);return s.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),s.resolveAutoSizing(this.context),s}},oS=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}},aS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},lS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},hS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},uS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},cS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},dS=class extends Pe{constructor(e){super(),this.scope=e}apply(e){new Je(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},pS=class extends on{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}},fS=class extends on{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}},gS=class extends eh{constructor(e,t){super(e,t,null,null,null)}apply(e){mS(e.context,e.currentStyle,this.style,this.specificity,e)}};function mS(e,t,i,n,r){bo(e,t,i,n,null,null,null);let s=i[$r];if(s){let a=oi(t,$r);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),bo(e,l,s[h],n,null,null,null)}}let o=i[Po];if(o){let a=oi(t,Po);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=o[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof U&&Kt(l,p,f)}let c=pt(u,"_pseudos");if(c){let p=oi(l,"_pseudos");for(let f in c)if(c.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let y=c[f];for(let b in y)if(y.hasOwnProperty(b)){let x=y[b];x instanceof U&&Kt(g,b,x)}}}}}}var yS=class extends Mr{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 oS(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 fS(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new pS(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 aS(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new lS(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new hS(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new uS(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new cS(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new dS(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(s=>s.selectors===null))return;super.simpleProperty(e,t,i);let n=ve(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{Fi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new U(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=r[h];l?Kt(l,e,a):(l=r[h]={},Fi(l,e,a),s&&["bleed","marks"].forEach(u=>{s[u]&&Fi(l,u,s[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new gS(this.elementStyle,e)}startFootnoteRule(e){let t=oi(this.elementStyle,Po),i=t.area;if(i||(i={},t.area=i),e){let r=oi(i,"_pseudos"),s=r[e];s||(s={},r[e]=s),i=s}let n=new lg(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=oi(this.elementStyle,$r),i=t[e];i||(i={},t[e]=i);let n=new vS(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},vS=class extends sn{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 U(t,n);Fi(this.boxStyle,e,r)}},lg=class extends sn{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 U(t,n);Fi(this.areaStyle,e,r)}},hg=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 s=this.root.firstChild;s;s=s.nextSibling){if(s.nodeType!=1)continue;let o=s;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":r=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Vt,"0")}doc(){return new cg([this.document])}getElementOffset(e){let t=e.getAttribute(Vt);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(Vt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,s=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,s=r.previousSibling,!s)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=s}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,s=r.previousSibling,!s){r=r.parentNode;break}r=s}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=mi(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,s=r.firstChild||r.nextSibling,o=null;for(;;){if(s){if(s.nodeType==1||(r=s,o=r,n+=s.textContent.length,n>e&&!/^\s*$/.test(s.textContent)))break}else if(r=r.parentNode,!r)break;s=r.nextSibling}return s&&o&&/^\s*$/.test(o.textContent)&&(o=s),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},fl=(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))(fl||{});function Ps(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let s=r.documentElement,o="parsererror";if(s.localName===o)return null;for(let a=s.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return r}function wS(e){let t=e.contentType;if(t){let n=Object.keys(fl);for(let r=0;r<n.length;r++)if(fl[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 ug(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s!=null){let o=wS(e);if(i=Ps(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Ps(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Ps(s,"image/svg+xml",r))}i||(i=Ps(s,"text/html",r))}}let n=i?new hg(t,e.url,i):null;return I(n)}function bS(){return new Fl(ug,"document")}var xS=class gl{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new gl(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new gl(n=>{if(!this.check(n))return!1;let r=new cg([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Yu=new xS(e=>!0),cg=class ml{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 ml(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 ml(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)}},SS=new Yr(()=>{let e=D("uaStylesheetBase"),t=Xp(),i=Ie("user-agent-base.css",Ni),n=new Mr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),r0(n.cascade),Rl(kd,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function CS(){return SS.get()}var kS=class extends Gs{constructor(e,t,i,n,r,s){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=s}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||q.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},ES=class{constructor(e,t,i,n,r,s,o,a,h,l,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=s,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,this.counterStyleStore=u,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 we(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new we(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new xa(this.rootScope,e,t,i),s=Eb(r,this.viewportProps),o=s.width,a=s.height,h=s["text-zoom"],l=1;if(o&&a||h){let u=Yt.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=u/i,i=u,e*=l,t*=l),o&&a){let c=ut(o.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 s of r.positions){let o=s.chunkPosition.primary;for(let a of o.steps)i(a);if(s.chunkPosition.floats)for(let a of s.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function Ku(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var gh=class extends xa{constructor(e,t,i,n,r,s,o,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=s,this.customRenderer=o,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 xx(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new xn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let y=e.flowProps[g],b=ve(y,"flow-consume");b&&(b.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=D("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new _u(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=ng(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Hx(r);let s=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(s,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new sS(s,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=bx(h.properties,this),u=new jf(l);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Px(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=Xu(Eo(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 xa(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),s=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new _u(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,s,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new Hv,i.flowPositions[e.flowName]=n);let r=zv(e.element),s=new Bi(r),o=new $v(s,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;if(Xe(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 s=new r,o=Ri(this.style.rootScope,new bt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}evalSupportsSelector(e){class t extends dg{errorMsg(...o){}}let i=new t(null),n=hd(e),r=new bt(n+"{}",i);return new Zr(He,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,s=n.offsetInNode,o=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,o=!1,s=0;let h=this.xmldoc.getNodeOffset(r,s,o);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let s=0;s<r.positions.length;s++){let o=r.positions[s].chunkPosition.primary,a=this.getNodePositionOffset(o);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){var t;let i=this.getPageStartOffset(e);if(!isFinite(i))return{counterOffset:i,changeOffset:i};let n=this.xmldoc.body||this.xmldoc.root,r=n?this.getFirstInFlowElementAtOrAfter(n,i):null,s=n?this.xmldoc.getElementOffset(n):i,o=i<=s,a=r===n&&o&&(t=this.getFirstInFlowChildElement(n))!=null?t:r;if(!a)return o?{counterOffset:s,changeOffset:s}:{counterOffset:i,changeOffset:i};let h=this.xmldoc.getElementOffset(a),l=i;return o&&h!==i&&(l=h),h===i&&(this.isInlineLevelElement(a)?l=Math.max(0,i-1):l=this.getDeepestFirstInFlowChildOffset(a)),{counterOffset:l,changeOffset:h}}getPageStartElement(e,t=this.getPageStartOffset(e)){var i;if(!isFinite(t))return null;let n=this.xmldoc.body||this.xmldoc.root;if(!n)return null;let r=this.getFirstInFlowElementAtOrAfter(n,t),s=this.xmldoc.getElementOffset(n),o=t<=s;if(r===n&&o)return(i=this.getFirstInFlowChildElement(n))!=null?i:r;if((r?this.xmldoc.getElementOffset(r):Number.POSITIVE_INFINITY)>t){let a=this.xmldoc.getNodeByOffset(t);if(!Ee(a)){let h=a.nodeType===Node.ELEMENT_NODE?a:a.parentElement;for(;h;){if(this.xmldoc.getElementOffset(h)<=t&&this.isPageBoundaryCandidateElement(h))return h;h=h.parentElement}}}return r}isForcedPageBreakValue(e){return Ze(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ve(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ve(e,"page");if(!t||Y(t.value))return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){if(this.isInlineLevelElement(e))return null;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.getPageGroupPageType(i);if(n)return n;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.isPageBoundaryCandidateElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){var e;let t=this.xmldoc.body||this.xmldoc.root;if(!t)return null;let i=this.xmldoc.getElementOffset(t),n=this.getFirstInFlowElementAtOrAfter(t,i);return n===t&&(e=this.getFirstInFlowChildElement(t))!=null?e:n}getEffectiveFirstPageType(e){let t=e,i=t?this.getPageGroupPageType(t):null;for(;t;){let n=this.getFirstInFlowChildElement(t);if(!n)return i;let r=this.getPageGroupPageType(n);r&&(i=r),t=n}return i}getEffectivePageGroupStartElement(e){let t=e,i=e;for(;i;){let n=this.getFirstInFlowChildElement(i);if(!n)return t;this.getPageGroupPageType(n)&&(t=n),i=n}return t}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return this.getEffectiveFirstPageType(e)}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),s=this.xmldoc.body||this.xmldoc.root,o=this.xmldoc.getElementOffset(s);if(i<=o&&e===s||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e?.startSideOfFlow("body")||null,n=e?.flowPositions.body,r=!!(n&&n.positions.length),s=!!i&&en(i)&&!this.matchPageSide(i)&&!r,o=!(this.blankPageAtStart&&(!e||e.page===1))&&!(e!=null&&e.isBlankPage)&&!s,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=this.getEffectivePageGroupStartElement(h),u=l===h?a:this.xmldoc.getElementOffset(l),c=l.ownerDocument,p=this.currentPageGroupDocument!==c&&o;p&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=c);let f=l;for(;f;){let g=this.getPageGroupPageType(f);if(g){let y=this.pageGroupPageCounts[g]||(this.pageGroupPageCounts[g]=new Map),b=y.get(f)||0;(b>0||o&&(p||this.shouldStartPageGroup(f,g,u)))&&(b+=1,y.set(f,b),(t.pageTypePageIndices[g]||(t.pageTypePageIndices[g]=[])).push(b))}if(f===this.xmldoc.root)break;f=f.parentElement}}preparePageGroupPageIndicesForRerender(e,t){this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=null;for(let i=0;i<t;i++){let n=e[i]||null;this.updatePageGroupPageIndices(n)}}getFirstInFlowElementAtOrAfter(e,t){if(this.isPageBoundaryCandidateElement(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.isInlineLevelElement(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(!Ee(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 this.isInlineLevelElement(i)?null:i;t=t.nextSibling}return null}isPageBoundaryCandidateElement(e){return this.isNormalFlowElement(e)&&!this.isInlineLevelElement(e)}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),s=r&&!Y(r)?r:v.static;if(yr(s)||Ar(s))return!1;let o=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(o&&!Y(o)?o:v.none)===v.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&&!Y(n)?n:v.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let s=this.getConsumedOffset(r);s<i&&(i=s)}}return i}dumpLocation(e){q.debug("Location - page",this.currentLayoutPosition.page),q.debug(" current:",e),q.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)q.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Je(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,s=i.startBreakType;i.startBreakType=ru(nt(s,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let s=0;s<n.length;s++){if(r=n[s],r.pageBox.pseudoName===fh)continue;let o=1;r.pageBox.pseudoName===uh&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*l/(h*h)),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===v._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let s=mi(r.length,l=>r[l]>n)-1,o=r[s],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Hl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new xn(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Te.PAGE)return!1;let 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},s=D("layoutDeferredPageFloats"),o=!1,a=0;return s.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let c=new zn().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&&(o=!0,t.validate());h.continueLoop()})}).then(()=>{o&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Bi(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)):I(!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=[],s=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-s.length>0;){let h=0;for(;s.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(s.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,c=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){s.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-s.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=ru(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)||!s.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=y=>y!==""&&y!=="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 P0([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,h,l,u,c,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,y=r.element,b=new xn(a,Te.COLUMN,null,o,null,null,null),x=this.currentLayoutPosition.clone(),m=D("createAndLayoutColumn"),w;return m.loopWithFrame(S=>{let C=this.createLayoutConstraint(b);if(h>1){let T=this.viewport.document.createElement("div");if(A(T,"position","absolute"),y.appendChild(T),w=new So(T,p,this.clientLayout,C,b),w.isNonFirstColumn=s>0,w.forceNonfitting=f,w.vertical=r.vertical,w.rtl=r.rtl,w.snapHeight=r.snapHeight,w.snapWidth=r.snapWidth,r.vertical){let R=(r.rtl?h-s-1:s)*(u+l)+r.paddingTop,F=parseFloat(y.style.width);w.setHorizontalPosition(r.paddingLeft+F-r.width,r.width),w.setVerticalPosition(R,u)}else{let R=(r.rtl?h-s-1:s)*(u+l)+r.paddingLeft;w.setVerticalPosition(r.paddingTop,r.height),w.setHorizontalPosition(R,u)}w.originX=t,w.originY=i}else w=new So(y,p,this.clientLayout,C,b),w.isNonFirstColumn=!1,w.copyFrom(r);w.exclusions=g?[]:n.concat(),w.innerShape=c,b.setContainer(w),(w.vertical?w.height:w.width)>=0?this.layoutColumn(w,o).then(()=>{b.isInvalidated()||b.finish(),w.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(w.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),w.element!==y&&y.removeChild(w.element),S.continueLoop()):S.breakLoop()}):(b.finish(),S.breakLoop())}).then(()=>{m.finish(w)}),m.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof og||t instanceof ch&&!(t instanceof Bn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Un;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new xn(e,Te.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(s,t,o,a),c=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,s,u,o,a,h,c).thenAsync(f=>I(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return I(null);if(h<=1)return I(f.columns);let g=t.getProp(this,"column-fill")||v.balance,y=this.currentLayoutPosition.flowPositions[a],b=fx(h,g,p,u,o,f.columns,y);return b?(c=!1,s.lock(),u.lock(),b.balanceColumns(f).thenAsync(x=>(s.unlock(),s.validate(),u.unlock(),this.currentLayoutPosition=x.position,I(x.columns)))):I(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,h,l,u){let c=D("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=Zu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),y=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,b=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),m=sd(x,0,0,a.width,a.height,this),w=new Ox(h,this,this.viewport,this.styler,b,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),S=0,C=null,T=[];return c.loopWithFrame(R=>{this.createAndLayoutColumn(t,i,n,r,a,S++,h,o,l,g,y,m,w,u).then(F=>{if(s.isInvalidated()){T=null,R.breakLoop();return}if((F.pageBreakType&&F.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=p.clone(),Ku(f),o.validate(),o.isLocked()?(T=null,R.breakLoop()):R.continueLoop();return}C=F,T[S-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(S=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?R.continueLoop():R.breakLoop()})}).then(()=>{c.finish(T)}),c.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return I(!0);let h=D("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,u=t.getProp(this,"flow-from"),c=this.viewport.document.createElement("div");c.role=t instanceof ag?"complementary":"presentation";let p=t.getProp(this,"position");A(c,"position",p?p.name:"absolute");let f=t instanceof Bn;t instanceof Un?i.appendChild(c):i.insertBefore(c,i.firstChild);let g=new sp(c);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=s,t.prepareContainer(this,g,e,this.faces,this.clientLayout),(g.width<=0||g.height<=0)&&(t instanceof Bn||u&&u.isIdent())&&(this.invalidPageAreaOnCurrentPage=!0,q.warn("Negative or zero page area size")),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let y,b=!1;if(!u||!u.isIdent()){let x=[],m=t.getProp(this,"content");if(m instanceof j&&m.expr instanceof we&&m.expr.str.startsWith("running-element-"))m.visit(new Rr(c,this,m,this.counterStore.getExprContentListener()));else if(It(m)){let w="span";m instanceof it&&(w="img");let S=this.viewport.document.createElement(w);m.visit(new Rr(S,this,m,this.counterStore.getExprContentListener())),c.appendChild(S),w=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces);let C=S.querySelectorAll("img[src]");for(let R=0;R<C.length;R++){let F=C[R],z=F.getAttribute("src");if(!z)continue;let $=kt(F,z);x.push($),e.fetchers.push($)}let T=S.getAttribute("src");if(T){let R=S.querySelector("img");R||(R=S);let F=kt(R,T);x.push(F),e.fetchers.push(F)}w=="span"&&v0(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(c),b=!0);b||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),y=x.length?_n(x).thenReturn(!0):I(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),y=I(!0);else{let x=D("layoutContainer.inner"),m=u.toString(),w=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,g,m,w).then(S=>{if(!o.isInvalidated()){let C=S[0];C.element===c&&(g=C),g.computedBlockSize=Math.max.apply(null,S.map(R=>R.computedBlockSize)),t.finishContainer(this,g,e,C,w,this.clientLayout,this.faces);let T=this.currentLayoutPosition.flowPositions[m];T&&T.breakAfter==="region"&&(T.breakAfter=null)}x.finish(!0)}),y=x.result()}return y.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!b&&!l){let m=t.getProp(this,"shape-outside"),w=g.getOuterShape(m,this);s.push(w)}}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 m=t.children[f?x++:x--],w=this.layoutContainer(e,m,c,n,r,s,o);if(w.isPending())return w.thenAsync(()=>I(!o.isInvalidated()));if(o.isInvalidated())break}return I(!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;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Uv,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),this.invalidPageAreaOnCurrentPage=!1,t=this.currentLayoutPosition;let o=t.startSideOfFlow("body");t.isBlankPage=en(o)&&this.matchPageSide(o),e.isBlankPage=t.isBlankPage,t.page++;let a=this.getPageStartPageTypeOverride(t);if(a===""?e.pageType="":a&&(e.pageType=a),e.pageType==null){let b=t.page===1?this.resolveFirstPageType():null,x=e.isBlankPage?this.styler.cascade.previousPageType:b??this.styler.cascade.currentPageType;if(e.pageType=x,!e.pageType){let m=this.getPageStartPageType(t);m&&(e.pageType=m)}e.pageType=(i=e.pageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType}this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let h=Zu(t),l=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=l,this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!s){let b=new Je(this.style.pageScope,"left-page");e.side=b.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let u=this.selectPageMaster(l);if(!u)return I(null);let c=0;if(!s){e.setAutoPageWidth(u.pageBox.specified.width.value===Gr),e.setAutoPageHeight(u.pageBox.specified.height.value===jr);let{counterOffset:b,changeOffset:x}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(b)||(b=this.lookupOffset,x=this.lookupOffset),isFinite(b)&&this.styler.styleUntil(b,0);let m=this.styler.getCounterSnapshotAtOffset(b),w=x===b?m:this.styler.getCounterSnapshotAtOffset(x);m||(m=this.styler.getLastCounterSnapshot()),w||(w=m);let S=w&&w.offset===x?w:null;this.counterStore.setCurrentPageDocCounters((n=m?.counters)!=null?n:null,(r=S?.changes)!=null?r:null,S?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let C=Xu(Eo(l),this);this.setPageSizeAndBleed(C,e),Jx(l,C,e,this),c=C.bleedOffset+C.bleed}let p=!s&&u.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=p!=v.horizontal_tb;let f=u.getProp(this,"direction")||v.ltr,g=new xn(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,p,f),y=D("layoutNextPage");return y.loopWithFrame(b=>{this.layoutContainer(e,u,e.bleedBox,c,c,[],g).then(()=>{if(g.isInvalidated()||g.finish(),g.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Ku(h),g.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);b.continueLoop()}else b.breakLoop()})}).then(()=>{u.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,this.checkRepeatedInvalidPageArea(t),Object.keys(t.flowPositions).forEach(x=>{let m=t.flowPositions[x],w=m.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(m.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let b=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(b,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),y.finish(t)}),y.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`}},PS=class yl extends Mr{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 Yf(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Gx(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Ut(this.scope,this.condition,i)),this.masterHandler.pushHandler(new yl(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new u0(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Gs(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new kS(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 Gs(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Gs(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=oi(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new lg(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new yS(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Mr.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 yl(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},dg=class extends Ra{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 Gw),d(this,"footnoteProps",{}),d(this,"flowProps",{}),d(this,"viewportProps",[]),d(this,"pageProps",{}),this.rootScope=new Js(null),this.pageScope=new Js(this.rootScope),this.rootBox=new Dx(this.rootScope),this.cascadeParserHandler=new PS(this,null,null,null),this.slave=this.cascadeParserHandler}};function NS(e,t){return t.parseOPSResource(e)}var TS=class extends Fl{constructor(e){super(NS,"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=Xp(),CS().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ie(An(t),Ji)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ie(An(t),Ji)),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 ug(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Gt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){q.warn("Error during single document preprocessing:",g)}}let o=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),y=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),b=f.getAttribute("action"),x=f.getAttribute("ref");g&&y&&b&&x&&o.push({observer:g,event:y,action:b,ref:x})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ie("user-agent-page.css",Ni),text:Cd,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-counter-styles.css",Ni),text:Nd,flavor:"UA",classes:null,media:null}),n)h.push({url:Ie("user-agent-toc.css",Ni),text:Ed,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,y=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(y=="style"){let b=f.getAttribute("class"),x=f.getAttribute("media"),m=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:m?b:null,media:x})}else if(y=="link"){let b=f.getAttribute("href"),x=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),m=f.getAttribute("class"),w=f.getAttribute("media");if(b&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||m)){let S=Ie(b,i),C=f.getAttribute("title");h.push({url:S,text:null,classes:C?m:null,media:w,flavor:"Author"})}}else y=="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 Yr(()=>{let p=D("fetchStylesheet"),f=0,g=new dg(this.validatorSet);return p.loop(()=>{if(f<h.length){let y=h[f++];return g.startStylesheet(y.flavor),y.text!==null?Rl(y.text,g,y.url,y.classes,y.media).thenReturn(!0):Od(y.url,g,y.classes,y.media)}return I(!1)}).then(()=>{let y=g.cascadeParserHandler.finish();u=new ES(this,g.rootScope,g.pageScope,y,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""}},Nr="\u25B8",Ju="\u25BE",IS="\u25B9";function mh(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(s=>s.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function AS(e){let t=mh(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var FS=class{constructor(e,t,i,n,r,s,o,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,d(this,"pref"),d(this,"page",null),d(this,"instance",null),this.pref=Cc(s),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;ki(n,"height","auto")!="auto"&&(A(n,"height","auto"),this.setAutoHeight(n,t)),ki(n,"position","static")=="absolute"&&(A(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let s=r.behavior;if(s)switch(s.toString()){case"toc-node-anchor":r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Le,r.padding=Le,r["padding-inline-start"]=new L(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new L(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Le;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&Ee(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=Nr&&(l.textContent=Nr,A(l,"cursor","pointer"),l.addEventListener("click",RS,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),s.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=IS,A(l,"margin","0.2em 0 0 -1em"),A(l,"margin-inline-start","-1em"),A(l,"margin-inline-end","0"),A(l,"display","inline-block"),A(l,"width","1em"),A(l,"text-align","center"),A(l,"vertical-align","top"),A(l,"cursor","default"),A(l,"font-family","Menlo,sans-serif"),h.appendChild(l),A(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){A(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 I(h)}}showTOC(e,t,i,n,r){if(this.page)return I(this.page);let s=D("showTOC"),o=new Zd(e,e);this.page=o;let a=Ht(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of mh(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new ko(t.window,u.fontSize,0,e,u.width,u.height);let c=this.makeCustomRenderer(h),p=new gh(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(o,null).then(()=>{this.setAutoHeight(e,2),s.finish(o)})})}),s.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,s]=r.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:s,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function RS(e){let t=e.target,i=t.textContent==Nr;t.textContent=i?Ju:Nr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let s=r,o=s.getAttribute("data-adapt-class");if(o==="toc-container"){if(s.setAttribute("aria-hidden",i?"false":"true"),s.firstChild){r=s.firstChild;continue}}else if(o==="toc-node"&&(s.style.height=i?"auto":"0px",s.children.length>=2&&(s.children[1].tabIndex=i?0:-1),s.children.length>=3&&(s.children[0].tabIndex=i?0:-1,!i))){let a=s.children[0];if(a.textContent==Ju){a.textContent=Nr,a.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),r=s.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Ns(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function LS(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function OS(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Ht(e))}var Qu=class extends TS{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=bS(),this.jsonStore=Jy()}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 Xs(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):OS(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):Ro(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}q.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 s of r)if(s){this.loadOPF(e,s).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return I(n);let r=D("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new Xs(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(s,o).then(()=>{r.finish(n)})}):n.initWithXMLDoc(s,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=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 Xs(this,e),s=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(s){let o=s.getAttribute("href");if(/^#/.test(o)){let a=xl(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ie(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&mh(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=D("EPUBDocStore.load"),n=Ht(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(Ji)||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:")?q.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Ji.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?q.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?q.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):q.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Ht(e),i=this.documents[t];if(i)return i.isPending()?i:I(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,s=i.height-0;if(r&&s){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${s}px;}`+(o?`@page{size:${r}px ${s}px;margin:0;}`:"@page{margin:0;}")}return""}},ec=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=Zg}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ie(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=nm(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 BS(e){return e.id}function MS(e){return t=>{let i=D("deobfuscator");return _S("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);Yy(r).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Td([a,s]))})}),i.result()}}function _S(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 Pi={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},gr="http://idpf.org/epub/vocab/package/meta/#",qe={language:`${Pi.dcterms}language`,title:`${Pi.dcterms}title`,creator:`${Pi.dcterms}creator`,layout:`${Pi.rendition}layout`,titleType:`${gr}title-type`,displaySeq:`${gr}display-seq`,alternateScript:`${gr}alternate-script`,role:`${gr}role`};function DS(e,t){let i={};return(n,r)=>{var s,o,a,h,l,u;let c,p,f=n.r||i,g=r.r||i;if(e==qe.title&&(c=((s=f[qe.titleType])==null?void 0:s[0].v)=="main",p=((o=g[qe.titleType])==null?void 0:o[0].v)=="main",c!=p))return c?-1:1;let y=parseInt((a=f[qe.displaySeq])==null?void 0:a[0].v,10);isNaN(y)&&(y=Number.MAX_VALUE);let b=parseInt((h=g[qe.displaySeq])==null?void 0:h[0].v,10);return isNaN(b)&&(b=Number.MAX_VALUE),y!=b?y-b:e!=qe.language&&t&&(c=((l=f[qe.language]||f[qe.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[qe.language]||g[qe.alternateScript])==null?void 0:u[0].v)==t,c!=p)?c?-1:1:n.o-r.o}}function zS(e,t){let i;if(!t)i=Pi;else{i={};for(let p in Pi)i[p]=Pi[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]]:gr;if(f)return f+p[3]}}return null},r=1,s=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:Pi.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}),o=Jo(s,c=>c.refines),a=c=>rm(c,(p,f)=>p.map(g=>{let y={v:g.value,o:g.order};g.scheme&&(y.s=g.scheme);let b=o[`#${g.id}`]||[];if(b.length||g.lang||g.role){g.lang&&b.push({name:qe.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&b.push({name:qe.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=Jo(b,m=>m.name);y.r=a(x)}return y})),h=a(Jo(s,c=>c.refines?null:c.name)),l=null;h[qe.language]&&(l=h[qe.language][0].v);let u=c=>{for(let p in c){let f=c[p];f.sort(DS(p,l));for(let g=0;g<f.length;g++){let y=f[g].r;y&&u(y)}}};return u(h),h}function VS(){let e=window.MathJax;return e?e.Hub:null}var tc={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},va="viv-id-",Xs=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 s=r+(n?`#${n}`:"");return va+bc(s,":")}transformURL(n,r){let s=n.match(/^([^#]*)#?(.*)$/);if(s){let o=s[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(s[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(va)===0&&(n=n.substring(va.length));let r=im(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ie("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new ec,u=h;l.initWithElement(u,e.url);let c=u.getAttribute("fallback");return c&&!tc[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=Nh(this.items,BS),this.itemMapByPath=Nh(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(tc[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 s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=cc(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Yu.withChild("EncryptionMethod",Yu.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=zS(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[qe.language]&&(this.lang=this.metadata[qe.language][0].v),this.metadata[qe.layout]&&(this.prePaginated=this.metadata[qe.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=MS(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),I(!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(),I(!0);let t=0,i=0,n=D("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let s=this.spine[i++];s.epage=t,this.store.load(s.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),s.epageCount=Math.ceil(o.getTotalOffset()/a),t+=s.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new hg(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new ec;r.initWithParam(n),r.id;let s=i.document.createElement("itemref");s.setAttribute("idref",r.id),i.root.appendChild(s),r.itemRefElement=s,this.itemMap[r.id]=r;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):I(null)}initWithWebPubManifest(e,t,i){var n,r,s,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[qe.title]=(Array.isArray(a)?a:[a]).map(x=>{var m;return{v:(m=x.value)!=null?m:x}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((s=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?s:[]).map(x=>x.content);h&&h.length!==0&&(this.metadata[qe.creator]=(Array.isArray(h)?h:[h]).map(x=>{var m;return{v:(m=x.name)!=null?m:x}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[qe.language]=(Array.isArray(l)?l:[l]).map(x=>({v:x})));let u=Ht(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 x of AS(t)){let m=x.getAttribute("href");if(/^(https?:)?\/\//.test(m)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(m))continue;let w=Ht(Ie(m,this.pubURL)),S=this.getPathFromURL(w),C=S!==null?encodeURI(S):w;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,y=-1;[e.readingOrder,e.resources].forEach(x=>{x instanceof Array&&x.forEach(m=>{let w=x===e.readingOrder,S=typeof m=="string"?m:m.url||m.href,C=typeof m=="string"?"":m.encodingFormat||m.href&&m.type||"";if(w||C==="text/html"||C==="application/xhtml+xml"||!C&&m.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(S)){let T=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,R={url:Ie(An(S),T),index:g++,startPage:null,skipPagesBefore:null};m.rel==="contents"&&y===-1&&(y=R.index),f.push(R)}})});let b=D("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var x,m;y!==-1&&(this.toc=this.items[y]),this.toc||(this.toc=i?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[c]);let w=(m=e.readingOrder)==null?void 0:m.length;w&&w<this.items.length&&this.items.splice(w),b.finish(!0)}),b.result()}getCFI(e,t){let i=this.spine[e],n=D("getCFI");return this.store.load(i.src).then(r=>{let s=r.getNodeByOffset(t),o=null;if(s){let a=r.getNodeOffset(s,0,!1),h=t-a,l=new Vh;l.prependPathFromNode(s,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return Mn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Vh;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let s=r.node,o=s.getAttribute("idref");if(s.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let s=i.navigate(r.document),o=r.getNodeOffset(s.node,s.offset,s.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{q.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Mn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let s=this.spine[r];(!s||s.epageCount==0)&&(s=this.spine[--r]);let o=Math.floor(e-s.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:o});return}let i=mi(this.spine.length,r=>{let s=this.spine[r];return s.epage+s.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let s=0;if(e>0){let o=r.getTotalOffset();s=Math.round(o*e/n.epageCount),s==o&&s--}t.finish({spineIndex:i,offsetInItem:s,pageIndex:-1})})},(t,i)=>{q.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 I(n)}if(e.offsetInItem<=0)return I(t.epage);let i=D("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),s=Math.min(r,e.offsetInItem);i.finish(t.epage+s*t.epageCount/r)}),i.result()}},Ts=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),$S=class{constructor(e,t,i,n,r,s){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=Cc(n),this.clientLayout=new Mx(t),this.counterStore=new Zm(e.documentURLTransformer),this.cmykStore=new Kc,s!=null&&s.length&&this.cmykStore.registerCmykReserveMap(s)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return I(!0);let i=D("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let s=0;s<e;s++){let o=this.spineItems[s];if(!o||!o.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,s)=>r+s.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let s=e.item.spineIndex+1;s<this.spineItems.length;s++){let o=this.spineItems[s];if(o&&o.pages[0]){r=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let s=i[r];if(!s)continue;let o=(e=n[r])!=null?e:0;t+=Math.min(s,o)}return t}reportPaginationProgress(e,t){let i=Gt("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),s=r;t&&(s=e.instance.getPosition(t,!0)),s<0&&(s=0),s>r&&(s=r);let o=this.paginationProgress.renderedOffsetsBySpine[n];o!=null&&s<o&&(s=o),this.paginationProgress.renderedOffsetsBySpine[n]=s;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let c={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(c)}catch(f){q.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,s,o){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=s?.pageType===n.pageType,u=n.offset!==t.offset,c=o&&!u&&i>0;if(a=n.pageType!=null&&(c||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,o){let p=e.instance.getPageStartPageTypeOverride(t.position);p===""?t.pageType="":p&&(t.pageType=p)}if(!o&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!o&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(s)&&r.pageType!==s.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let s=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||s)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Ns(n));let r=Ns(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return I(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let s=e.pages[t.page],o=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||o,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,s,a,o,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):I(!0)):I(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=D("resolveUnresolvedReferencesForPage"),s=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),o=0,a=t;return r.loopWithFrame(h=>{if(o++,o>s.length){h.breakLoop();return}let l=s[o-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let c=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:c.currentPageType,previousPageType:c.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},y=LS(u.instance.pageGroupPageCounts),b=u.instance.currentPageGroupDocument,x=u.instance.scopes;u.instance.scopes={};let m=l.pageIndex<u.pages.length-1,w=!!u.pages[l.pageIndex],S=w&&m,C=S?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let T=u.layoutPositions[l.pageIndex];w&&u.instance.preparePageGroupPageIndicesForRerender(u.layoutPositions,l.pageIndex),this.renderSinglePage(u,T).then(R=>{S&&u.instance.endIsolatedRootPageFloatLayoutContext(C);let F=c.currentPageType;c.currentPageType=f.currentPageType,c.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=y,u.instance.currentPageGroupDocument=b,u.instance.scopes=x;let z=Ns(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),R.pageAndPosition.position.spineIndex===a.spineIndex&&R.pageAndPosition.position.pageIndex===i&&(a=R.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&F!==R.pageAndPosition.page.pageType&&(c.currentPageType=a.pageType);let $=u!==e,X=u.pages.length,re=u.layoutPositions[X],k=u.instance.hasActiveRootPageFloatLayoutContext();if(re&&!k){let _=$?Ns(this.counterStore.currentPageCounters):null;$&&(this.counterStore.currentPageCounters=z);let E=X;this.renderSinglePage(u,re).then(()=>{$&&this.markSpineItemCompleteIfReady(u);let B=u.pages.length-E;if($&&B>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,B),this.counterStore.updateTargetCounterNodesInPages(u.pages);let P=u.item.spineIndex;for(let N=P+1;N<this.spineItems.length;N++){let O=this.spineItems[N];if(O){O.item.epage+=B;for(let V of O.pageCounterStarts)V!=null&&V.page&&(V.page=V.page.map(W=>W+B));this.counterStore.updatePageCounterNodesInPages(O.pages,O.pageCounterStarts)}}if(_){let N=_.page;N&&(_.page=N.map(O=>O+B))}}_&&(this.counterStore.currentPageCounters=_),h.continueLoop()});return}$&&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(),s=this.preparePageCountersForRender(e,n),o=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,s,o,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,s,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(c=>{i.finish({pageAndPosition:Ts(c,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=mi(t.layoutPositions.length,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=D("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,s;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);s=a.pageIndex,r=n.pages[s],r?o.breakLoop():n.complete?(s=n.pages.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):s<n.layoutPositions.length&&!n.pages[s]?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Ts(r,s))})})}),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,s=n.offsetInItem,o=i.pages[r];if(o){t.finish(Ts(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(s>=0&&i.instance.getPosition(h)>s){o=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(Ts(o,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(s=>!s.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,s=0;t&&(s=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++s>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=D("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=s.pages[s.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return I(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 I({left:null,right:null});let n=D("getSpread"),r=i.side==="left",s;return this.isRectoPage(i,e)?s=this.previousPage(e,t):s=this.nextPage(e,t),s.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return I(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(s=>{if(s){if(s.page.side===i.side)return r;let o=this.nextPage(s.position,t);return o.thenAsync(a=>a?o:r)}else return I(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return I(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),s=i.container.previousElementSibling;return n?r.thenAsync(o=>o?o.page.side===i.side||o.page.container!==s?r:this.previousPage(o.position,t):I(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(!Et(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ie(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let s=0;s<r.length;s++){let o=r.item(s);if(!Wt(o))continue;let a=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ie(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(o)}return null}navigateTo(e,t,i){q.debug("Navigate to",e);let n=this.opf.getPathFromURL(Ht(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return I(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return I(null)}let s=D("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(o=>{if(!o){s.finish(null);return}let a=o.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(o,a),l=h??(a?o.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(s)})}),s.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Tr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let s=new Zd(n,r);if(s.spineIndex=e.item.spineIndex,s.position=t,s.offset=e.instance.getPosition(t),s.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",o),s.registerElementWithId(r,o)}if(i!==this.viewport){let o=kc(this.viewport.width,this.viewport.height,i.width,i.height),a=Ri(null,new bt(o,null),"");s.delayedItems.push(new _l(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Ie(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let h=Eh(r),l=Eh(o),u=new gi;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 y=g.getAttribute("name"),b=g.getAttribute("value");y&&b&&(u.append("&"),u.append(encodeURIComponent(y)),u.append("="),u.append(encodeURIComponent(b)))}}s.setAttribute("src",u.toString());let c=t.getAttribute("width");c&&s.setAttribute("width",c);let p=t.getAttribute("height");p&&s.setAttribute("height",p)}}}return s||(s=this.viewport.document.createElement("object"),r&&s.setAttribute("data",Ir(r)),s.setAttribute("data-adapt-process-children","true")),I(s)}makeMathJaxView(e,t,i,n){let r=VS();if(r){let s=i.ownerDocument,o=s.createElement("span");i.appendChild(o);let a=s.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=r.queue;h.Push(["Typeset",r,o]);let l=D("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(o)}),l.result()}return I(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ie(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):I(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return I(null);let t=this.spineItems[e];if(t)return I(t);let i=D("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],s=this.opf.store;return s.load(r.src).then(o=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=o.document.title;let l=s.getStyleForDoc(o),u=this.makeCustomRenderer(o),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 ko(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],y,b;if(r.startPage!==null)y=r.startPage-1,b=y;else{if(e>0&&(!g||!g.complete))y=r.epage||e,!this.opf.prePaginated&&y%2==(f?1:0)&&y++,b=y;else{y=g?g.instance.pageNumberOffset+g.pages.length:0;let w=g&&g.pageCounterStarts[g.pages.length-1],S=w&&w.page;if(S&&S.length)b=S[S.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;b=!C||!C.length?y:C[C.length-1]}}r.skipPagesBefore!==null&&(y+=r.skipPagesBefore,b+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(b);let x=new gh(l,o,this.opf.lang,c,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,y,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);x.pref=this.pref;let m=this.opf.metadata&&this.opf.metadata[qe.title];x.pubTitle=m&&m[0]&&m[0].v||"",x.docTitle=r.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),t={item:r,xmldoc:o,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(w=>{w.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 I(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"),I(this.tocView.page);let n=D("showTOC");this.tocView||(this.tocView=new FS(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,s=Math.min(344,Math.round(.67*r.width)-16),o=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),Tr||(a.style.visibility="hidden"),a.style.width=`${s+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,s,o,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},ic="data-vivliostyle-viewer-status",HS="data-vivliostyle-spread-view",pg=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(pg||{}),US=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,s=(o,a)=>{let h=r.getElementById(o);return h||(h=r.createElement("style"),h.id=o,a&&(h.textContent=a),r.head.appendChild(h)),h};s("vivliostyle-viewport-screen-css",wd),s("vivliostyle-viewport-css",bd),s("vivliostyle-polyfill-css",Pd),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Tr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ic,"loading"),this.fontMapper=new Sx(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=s("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Sc(),this.pageSizes=[],this.pixelRatioLimit=bl==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=fc;q.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),q.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),q.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),q.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(ic,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){Pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=D("loadPublication");return this.configure(e).then(()=>{let o=new Qu;o.init(n,r).then(()=>{let a=Ie(An(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(o).then(()=>{this.render(i).then(()=>{s.finish(!0)})})):s.finish(!1)})})}),s.result()}loadXML(e){Pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=D("loadXML");return this.configure(e).then(()=>{let a=new Qu;a.init(r,s).then(()=>{let h=t.map((l,u)=>({url:Ie(An(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Xs(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,I(!0))):t=I(!0),t.thenAsync(()=>(Pt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let s=Yt[r];if(s)return t*s}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Sh(e.userAgentRootURL.replace(/resources\/?$/,"")),Ch(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Sh(e.rootURL),Ch(`${Ji}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!==vi&&(Cx(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),I(!0)}configurePlugins(e){Gt("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=>{A(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),A(e.container,"visibility","visible"),A(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?_n(i.fetchers):I(!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 ko(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new ko(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(HS,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let o=function(g){let y=g*.75;return Math.ceil(y)};var s=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),u=o(h),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,I(!0);let t=Ie(An(this.cmykReserveMapUrl),Ji),i=D("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Em(n)?this.cmykReserveMap=n:(q.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 $S(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?I(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,I(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,I(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,I(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 nc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return I(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Aa().getScheduler().run(()=>Mn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,Pt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.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():I(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),Pt.registerEndTiming("render (resize)"),vi&&qf(this.window)?Nx(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 nc)Pt.registerEndTiming("render (resize)"),q.debug(i.message);else throw i}));return I(!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 I(!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 I(!0);if(!this.opfView)return I(!0);let n=D("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=D("moveTo.showCurrent");s=o.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else s=I(!0);s.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return I(!0)}else if(i=="hide")return I(!0);if(n&&i!="show")return this.opfView.hideTOC(),I(!0);{let s=D("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(r&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}s.finish(!0)}),s.result()}}runCommand(e){let t=e.a||"";return Mn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(q.error("No such action:",t),i.finish(!0))},(i,n)=>{q.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=rc(e),i=null,n=this;Uy(()=>{let r=D("commandLoop"),s=Aa().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};s.run(()=>(n.callback(l),I(!0)))}},r.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=D("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=rc(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},fg=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(fg||{}),nc=class gg extends Error{constructor(){super(),d(this,"name","RenderingCanceledError"),d(this,"message","Page rendering has been canceled"),d(this,"stack"),Object.setPrototypeOf(this,gg.prototype),this.stack=new Error().stack}};function rc(e){return typeof e=="string"?xl(e):e}var sc=wl;function WS(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function oc(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 mg=class{constructor(e,t){this.settings=e,d(this,"initialized",!1),d(this,"adaptViewer_"),d(this,"options"),d(this,"eventTarget"),d(this,"readyState"),uc(e.debug),this.adaptViewer_=new US(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=WS(),t&&this.setOptions(t),this.eventTarget=new Cl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},oc(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function s(l){if(l)return l.map(u=>({url:u.url||null,text:u.text||null}))}let o=s(r.authorStyleSheet),a=s(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:GS(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},oc(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()===sc.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===sc.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 GS(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 yg=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(yg||{}),jS=fg,XS=pg;Pt.forceRegisterEndTiming("load_vivliostyle");var qS=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:s=!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=s}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1871
|
+
`),i.toString()}},xx=class{constructor(e){u(this,"deobfuscator",e),u(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 _e){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 _e(i)}else{let t=this.familyMap[e.stringValue()];return t?new _e([M(t),e]):e}}},Sx=class{constructor(e,t,i){u(this,"head",e),u(this,"body",t),u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=D("initFont"),r=e.src,s={};for(let l of lh(e.properties))s[l]=e.properties[l];let o=this.getViewFontFamily(e,i);s["font-family"]=M(o);let a=new jf(s),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),q.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(s=>{t.registerFamily(e,s),q.debug("Found already-loaded font:",i)}):(r=new Yr(()=>{let s=D("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?Lo(o,"blob").then(h=>{if(!h.responseBlob){s.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(s)})}):this.initFont(e,null,t).thenFinish(s),s.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){q.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return _n(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 I(!0);let i=D("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?I(!0):I(!1))).thenFinish(i),i.result()}},vi=!0;function Cx(e){vi=e}var Ki=[];function zu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Xf(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 hh(e,t,i){if(!vi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Xf(e.ownerDocument).includes(e))return I(!1);let n=e.textContent,r=e.src,s=e.type==="module",o=r&&r.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return I(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(s||r)&&e.async&&!o,h=(s&&!a||r&&e.defer)&&!o,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(qf(t)||(t.onload=null),l)return Ki.some(d=>zu(d,e))||Ki.push(e),I(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&zu(d,e)&&t.document.head.removeChild(d);let c=t.document.createElement("script");c.textContent=n,r&&(c.src=r),c.async=a,c.defer=h,c.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||c.setAttribute(d.name,d.value);if(q.debug("script:",r),r){let d=kt(c);return t.document.head.appendChild(c),_n([d])}else return t.document.head.appendChild(c),I(!0)}function kx(e,t){var i;let n={},r=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let c of Object.values(l))r(c)},s=o=>{if(o instanceof eh)r(o.style);else if(o instanceof qn||Array.isArray(o))for(let a of Object.values(o))s(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))s(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function Ex(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=kx(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function Px(e,t,i){if(!vi)return I(!1);let n=Xf(e);if(n.length===0)return I(!1);let r=n.some(c=>!(c.async||c.defer||c.type==="module")),s=r?Ex(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=D("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?I(!0):I(!1)}):I(!1);let c=n.shift();return hh(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Ki.push(c),h=!0),n.length===0&&r&&(q.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),I(!0)))}).then(()=>{s&&s.remove(),l.finish(!0)}),l.result()}function Nx(e){if(!vi)return I(!1);let t=D("loadScripts");return t.loop(()=>Ki.length===0?I(!1):hh(Ki.shift(),e,{atEnd:!0}).thenReturn(Ki.length>0)).then(()=>{q.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),q.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function qf(e){return vi?Ki.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Tx=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Sl),Ix=e=>`"${Tx(e)}"`,va=(e,t,i)=>Ix(i.transformURL(xi(String(e)),t)),Ax=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${va(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${va(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${va(r,t,i)}`),Fx={},Rx=new Set(["base","body","head","html","link","meta","script","style","title"]);function Lx(e){if(e instanceof Z)return e;if(e instanceof K){let t=[];for(let i of e.values)if(i instanceof Z)t.push(i.str);else return null;if(t.length>0)return new Z(t.join(""))}return null}function Ox(e){return e instanceof Qe?e:e instanceof K&&e.values[0]instanceof Qe&&e.values.slice(1).every(t=>t instanceof Z&&t.str.trim()==="")?e.values[0]:null}function Bx(e){if(To!=="webkit")return!1;let t=e["--viv-marker-content"];if(!t)return!1;let i=Ox(t);if(i)return e["list-style-type"]=v.none,e["list-style-image"]=i,delete e["--viv-marker-content"],!0;let n=Lx(t);return n?(e["list-style-type"]=n,e["list-style-image"]=v.none,!0):!1}function Mx(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){return t==="mouse-events"}}},!1)}var dl=class fr extends Cl{constructor(t,i,n,r,s,o,a,h,l,c,d,p,f,g,y,b=new Map,x={value:!1}){super(),u(this,"flowName",t),u(this,"context",i),u(this,"viewport",n),u(this,"styler",r),u(this,"regionIds",s),u(this,"xmldoc",o),u(this,"docFaces",a),u(this,"footnoteStyle",h),u(this,"stylerProducer",l),u(this,"page",c),u(this,"customRenderer",d),u(this,"fallbackMap",p),u(this,"documentURLTransformer",f),u(this,"pageProps",g),u(this,"cascadedPageStyle",y),u(this,"semanticFootnoteFirstRefOffsets",b),u(this,"semanticFootnoteFirstRefOffsetsInitialized",x),u(this,"document"),u(this,"exprContentListener"),u(this,"computedStyleParentFontSizeOverride",null),u(this,"computedStyleParentLineHeightOverride",null),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new fr(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)}getExplicitPageType(t){let i=t?.page;if(!i||Y(i.value))return null;let n=i.evaluate(this.context,"page").toString();return!n||n.toLowerCase()==="auto"?null:n}isNormalFlowElement(t){var i,n,r;let s=this.styler.getStyle(t,!1),o=(i=s?.display)==null?void 0:i.evaluate(this.styler.context,"display");if((o&&!Y(o)?o:v.inline)===v.none)return!1;let a=(n=s?.position)==null?void 0:n.evaluate(this.styler.context,"position"),h=a&&!Y(a)?a:v.static;if(yr(h)||Ar(h))return!1;let l=(r=s?.float)==null?void 0:r.evaluate(this.styler.context,"float");return(l&&!Y(l)?l:v.none)===v.none}getFirstInFlowChildElement(t){var i;let n=t.firstChild;for(;n;){if(n.nodeType===Node.TEXT_NODE){if(!Ee(n))return null;n=n.nextSibling;continue}if(n.nodeType!==Node.ELEMENT_NODE){n=n.nextSibling;continue}let r=n;if(this.isNormalFlowElement(r)){let s=this.styler.getStyle(r,!1),o=(i=s?.display)==null?void 0:i.evaluate(this.styler.context,"display"),a=o&&!Y(o)?o:v.inline;return Dt(a)?null:r}n=n.nextSibling}return null}getEffectiveStartPageType(t,i){let n=i,r=t;for(;r;){let s=this.getFirstInFlowChildElement(r);if(!s)return n;let o=this.getExplicitPageType(this.styler.getStyle(s,!1));o&&(n=o),r=s}return n}syncTextNodePageTypeBoundary(t){if(t.sourceNode.nodeType!==Node.TEXT_NODE||Ee(t.sourceNode)||t.fragmentIndex!==1)return;let i=t.pageType;this.styler.cascade.currentPageType!==i&&(en(t.breakBefore)||(t.breakBefore=nt(t.breakBefore,"page")),i!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=i)}syncSemanticFootnoteCounterToTarget(t){if(t.localName!=="a"||!Wt(t)||!au(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(Sr);if(!i)return;let n=up(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(Sr,i)}createPseudoelementShadow(t,i,n,r,s,o,a,h){var l,c;let d=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!d)return h;let p=[],f=dr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,y=Wt(t)&&!!d["footnote-call"]&&It((l=d["footnote-call"].content)==null?void 0:l.value);for(let m of w0){let w;if(m){if(!d[m])continue;let S=Et(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(m=="footnote-call"&&!Wt(t)||m=="footnote-marker"&&!(S||C||i&&this.isFootnote)&&!((c=this.nodeContext)!=null&&c.pluginProps.nestedFootnoteDetached))continue;if(m.match(/^first-/)){let T=r.display;if(!T||T===v.inline)continue;let R=t.firstElementChild;if(R&&Ee(R.previousSibling)){let F=s.getStyle(R,!1);if(F){let z=ve(F,"display");if(z!=null&&z.value&&z.value!==v.inline)continue}}}if(m==="before"||m==="after"||m==="footnote-call"||m==="footnote-marker"){let T=d[m].content,R=(m==="before"||m==="after")&&(r.float===v.footnote||S||C)&&!!T;if(!T||!It(T.value)&&!R)continue}p.push(m),w=dr.createElementNS("http://www.w3.org/1999/xhtml","span"),kr(w,m)}else{if(y)continue;w=dr.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(w),m.match(/^first-/)&&(g=w)}if(!p.length)return h;let b=new ga(t,n,s,o,this.exprContentListener),x=new Rs(t,f,null,a,h,ot.ROOTLESS,b);return h||x}getPseudoMap(t,i,n,r,s){let o=pt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Cr(l,o[h],s),ll(l,s,o[h]),Sf(o[h],i,n,(c,d)=>{Cr(l,d,s),wf(d,p=>{Cr(l,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=D("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);s=new Rs(n,l,h,r,s,i,c)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let h=D("createShadows"),l=null,c=r.template,d;if(c instanceof Qe||c===v.footnote)if(c!==v.footnote||au(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=c instanceof Qe?c.url:Ie("user-agent.xml#footnote",Ni);d=this.createRefShadow(p,ot.ROOTLESS,t,a,l)}else d=I(l);else d=I(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let y=t.getAttribute("href"),b=null;y?b=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?y=a.owner.getAttribute("href"):y=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),b=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),y&&(y=Zs(y,b.url),f=this.createRefShadow(y,ot.ROOTED,t,a,p))}f==null&&(f=I(p));let g=null;f.then(y=>{if(r.display===v.table_cell){let b=Ie("user-agent.xml#table-cell",Ni);g=this.createRefShadow(b,ot.ROOTLESS,t,a,y)}else g=I(y);g.then(b=>{b=this.createPseudoelementShadow(t,i,n,r,s,o,a,b),h.finish(b)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=hl(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((s=this.nodeContext)!=null&&s.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=bf(a,o,t);let c=!h&&t!==l;i=xf(a,o,i);let d=(x,m)=>{let w;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(w=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(w=o.pageAreaWidth));let S=m.evaluate(o,x,w,t);return x=="font-family"&&(S=this.docFaces.filterFontFamily(S)),S},p=!!new Je(o.style.pageScope,"left-page").evaluate(o);if(Cf(a,r,t,i,p,d),c){let x=r[t?"height":"width"];(!x||x===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(yr(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,y=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),b=Md(y,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{b[x]&&(r[x]=b[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,s=[],o=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let b=l?.owner;if(b instanceof Element&&Wt(b)){let x=b.getAttribute("href")||b.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let m=Zs(x,this.xmldoc.url),w=this.xmldoc.getElement(m);w&&Et(w)&&((n=w.parentNode)==null?void 0:n.nodeType)===1&&(r=w.parentNode,l=null)}}}let c=-1;for(;r&&r.nodeType==1;){let b=l&&l.root==r,x=!!b&&l.type==ot.ROOTED&&Et(r);if(!b||l.type==ot.ROOTLESS||x){let m=(l?l.styler:this.styler).getStyle(r,!1);s.push(m),o=o||ba(r)}b&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,c++)}let d=new Set;if(s.length>0){let b=s[0],x=hl(b,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let m in x){if(!In(m))continue;let w=x[m].evaluate(this.context,m);w&&w!==v.inherit&&w!==v.unset&&w!==v.revert&&w!==Be&&d.add(m)}}let p=c===0,f=this.context.queryUnitSize("em",p),g={"font-size":new U(new L(f,"px"),0)};p&&(g["line-height"]=new U(new Tt(this.context.pref.lineHeight),0));let y=new Pb(g,this.context);for(let b=s.length-1;b>=0;--b){let x=s[b],m=[];for(let C in x)In(C)&&m.push(C);m.sort(Lh);let w,S;for(let C of m){if(b>0&&h&&C.startsWith("--viv-marker-")||b>0&&d.has(C))continue;y.setPropName(C);let T=ve(x,C),R=T;if(T.value===v.initial)delete g[C];else if(!Y(T.value)){if(C==="font-size"&&b===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)R=new U(new L(this.context.rootFontSize,"px"),T.priority);else if(C==="line-height"&&b===s.length-1&&this.context.rootLineHeight&&T.value instanceof L&&(T.value.unit==="lh"||T.value.unit==="rlh"))R=new U(new L(this.context.rootLineHeight,"px"),T.priority);else if(b===0&&T.value instanceof L&&T.value.unit==="lh"){let F=this.getLineHeightUnitSize(C,w,S);F!=null&&(R=new U(new L(T.value.num*F,"px"),T.priority))}else Xe(C)||(R=T.filterValue(y));C==="font-size"?w=R.value:C==="line-height"&&(S=R.value),g[C]=R}}}for(let b in t)In(b)||(g[b]=t[b]);return{lang:o,elementStyle:g}}resolveURL(t){return t=Ie(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=ba(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=gb().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let s=t[r];if(s){if(Y(s))s===v.initial&&(n[r]=void 0);else if(s instanceof lt)n[r]=s.num;else if(s instanceof he)n[r]=s.name;else if(s instanceof L){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*Yt[o.unit];break;default:n[r]=s}}else n[r]=s;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,s,o){let a=Gt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,s,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let s=!0,o=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 T=this.xmldoc.getElementOffset(a);$o.registerFragmentIndex(T,this.nodeContext.fragmentIndex,0)}let c={},d={getStyle:T=>this.styler.getStyle(T,!1),getProp:(T,R)=>T?ve(T,R):null,getStyleMap:(T,R)=>pt(T,R),getMutableStyleMap:(T,R)=>oi(T,R),createCascadeValue:(T,R)=>new U(T,R),filterFootnoteMarkerContent:(T,R)=>T.filterValue(new Br(this.styler.cascade,R,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let T=this.inheritFromSourceParent(l);l=T.elementStyle,this.nodeContext.lang=T.lang}let p=l.position,f=l.float,g=l["float-reference"],y=f&&!Y(f.value)&&f.value!==v.none&&g&&!Y(g.value)?Gv(g.value.toString()):null,b=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===ot.ROOTED&&Et(a);if(this.nodeContext.parent&&(yr(p?.value)||y&&Ai(y)||b)){let T=this.inheritFromSourceParent(l);l=T.elementStyle,this.nodeContext.lang=T.lang}l=Yv(a,l,this.nodeContext.shadowContext,this.xmldoc.url,T=>this.xmldoc.getElement(T),Sr,d),l=Zv(a,l,this.nodeContext.shadowContext,this.context,d),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),y&&Ai(y)&&c.display===v.block&&(c.display=v.flow_root),h.processContent(a,c,this.nodeContext),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let x=c["flow-into"];if(x&&x.toString()!=this.flowName)return o.finish(!1),o.result();if(vi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return hh(a,this.viewport.window).thenFinish(o),o.result();let m=c.display;if(Et(a)&&!b&&a.hasAttribute(hp)&&(m=c.display=v.none),Y(m)&&(m===v.initial||m===v.unset?m=v.inline:m===v.inherit?m=((n=this.nodeContext.parent)==null?void 0:n.display)&&M((r=this.nodeContext.parent)==null?void 0:r.display):m=null),m===v.none)return o.finish(!1),o.result();let w=this.nodeContext.parent==null,S=c[this.nodeContext.vertical?"width":"height"],C=(m===v.grid||m===v.inline_grid)&&!!S&&!(S===v.auto||Y(S));return this.nodeContext.flexContainer=m===v.flex||C,this.createShadows(a,w,l,c,h,this.context,this.nodeContext.shadowContext).then(T=>{var R,F;this.nodeContext.nodeShadow=T;let z=c.position,$=c.float,X=c.clear,re=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,k=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:re,_=lv(a),E=c["column-count"],B=c["column-width"],P=E&&E!==v.auto&&!Y(E)||B&&B!==v.auto&&!Y(B);this.nodeContext.establishesBFC=uv(m,z,$,c.overflow,re,k,P||_),this.nodeContext.containingBlockForAbsolute=cv(z),this.nodeContext.isInsideBFC()&&$!==v.footnote&&!(y&&Ai(y))&&($=null,X=null);let N=null,O=!1,V=this.isFootnote&&(!((R=this.nodeContext)!=null&&R.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||b),W=Kv(a,this.nodeContext.shadowContext,d);Jv(W.sourceStyle,c,this.context),N=W.footnoteDisplay;let J=$ instanceof K||$===v.left||$===v.right||$===v.top||$===v.bottom||$===v.inline_start||$===v.inline_end||$===v.block_start||$===v.block_end||$===v.snap_block||$===v.snap_inline||$===v.inside||$===v.outside||$===v.footnote;if($&&(delete c.float,$===v.footnote))if(N=c["footnote-display"]||N,O=!!c["--viv-marker-content"],V){J=!1;let G=N?.toString();G&&(c["--viv-footnote-display"]=M(G)),m=O?M("list-item"):G==="inline"||G==="compact"?v.inline:v.block,c.display=m}else c.display=v.inline;if(V&&Et(a)){O=O||!!c["--viv-marker-content"];let G=N?.toString();G&&(c["--viv-footnote-display"]=M(G)),O&&(m=c.display=M("list-item")),!O&&(G==="inline"||G==="compact")&&(m=c.display=v.inline)}X&&(X===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(X=M(this.nodeContext.parent.clearSide)),(X===v.left||X===v.right||X===v.top||X===v.bottom||X===v.inline_start||X===v.inline_end||X===v.block_start||X===v.block_end||X===v.inside||X===v.outside||X===v.both||X===v.all||X===v.same||X===v.column||X===v.region||X===v.page)&&(delete c.clear,(J||c.display&&c.display!=v.inline)&&(this.nodeContext.clearSide=X.toString())));let te=hr(m)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),Q=c["break-inside"];(J||Q&&!Y(Q)&&Q!==v.auto)&&this.nodeContext.breakPenalty++,m&&m!==v.inline&&Dt(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!J&&!m||Dt(m)||Dd(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=J?$.toString():null,this.nodeContext.floatReference=y||Te.INLINE;let pe=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=pe&&!Y(pe)?pe:null;let se=this.isInsideNonRootMultiColumn(),oe=c["column-span"];if(this.nodeContext.columnSpan=!se&&oe&&!Y(oe)?oe:null,!this.nodeContext.inline){let G=c["break-after"];G&&!Y(G)&&!(se&&G===v.column)&&(this.nodeContext.breakAfter=G.toString(),Ma[this.nodeContext.breakAfter]&&(c["break-after"]=v.column));let Bt=c["break-before"];Bt&&!Y(Bt)&&!(se&&Bt===v.column)&&(this.nodeContext.breakBefore=Bt.toString(),Ma[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let qt=c.page,an=qt&&!Y(qt)?qt.toString():null,Mt=an;!Mt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===v.table_header_group||m===v.table_footer_group)&&(Mt=this.styler.cascade.currentPageType),!Mt||Mt.toLowerCase()==="auto"?Mt=this.nodeContext.pageType:this.nodeContext.pageType=Mt;let Zn=an!=null&&an.toLowerCase()!=="auto",wi=Zn?this.nodeContext.fragmentIndex===1?this.getEffectiveStartPageType(a,Mt):(F=this.styler.cascade.currentPageType)!=null?F:Mt:Mt;this.styler.cascade.currentPageType!==wi&&!(!Zn&&c.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!en(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),wi!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=wi)}this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let De=c["border-collapse"];if(!De||De===M("separate")){let G=c["border-spacing"],Bt,qt;G&&(G instanceof K?(Bt=G.values[0],qt=G.values[1]):Bt=qt=G,Bt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=ut(Bt,this.context)),qt.isNumeric()&&(this.nodeContext.blockBorderSpacing=ut(qt,this.context)))}let Ne=c["footnote-policy"]||W.footnotePolicy;Ne&&!Y(Ne)&&(c["--viv-footnote-policy"]=Ne),this.nodeContext.footnotePolicy=Ne&&!Y(Ne)?Ne:null;let fe=c["x-first-pseudo"];if(fe){let G=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Vv(G,fe.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Ce=c["white-space"];if(Ce){let G=Kd(Ce.toString());G!==null&&(this.nodeContext.whitespace=G)}let ge=c["hyphenate-character"];ge&&ge instanceof Z&&(this.nodeContext.hyphenateCharacter=ge.str);let Ae=c["word-break"],Oe=c["line-break"],Fe=c["overflow-wrap"];(Ae===v.break_all||Oe===v.anywhere||Fe===v.break_word||Fe===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,m,z,$,w),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(a,h));let Ue=!1,ft=null,Yn=[],At=a.namespaceURI,me=a.localName,is=me;At=="http://www.w3.org/1999/xhtml"?(Rx.has(me)?me="div":me=="vide_"?me="video":me=="audi_"?me="audio":me=="object"&&(Ue=!!this.customRenderer),a.hasAttribute(sh)&&a.hasAttribute("src")&&c.content instanceof Qe&&(me="img")):At=="http://www.idpf.org/2007/ops"?(me="span",At="http://www.w3.org/1999/xhtml"):At=="http://www.pyroxy.com/ns/shadow"?(At="http://www.w3.org/1999/xhtml",me=this.nodeContext.inline?"span":"div"):Ue=!!this.customRenderer,te?t?(me="li",c["--viv-marker-content"]&&(Bx(c)||(c["list-style-type"]=v.none,c["list-style-image"]=v.none))):(m=Dt(m)?v.inline:v.block,c.display=m,me="div"):me=="body"||me=="li"?me="div":me=="q"&&(me="span"),c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(Ue=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(Ue=!0);let jo;if(Ue){let G=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;jo=this.customRenderer(a,G,c)}else jo=I(null);jo.then(G=>{var Bt,qt,an,Mt,Zn;if(G)Ue&&(s=G.getAttribute("data-adapt-process-children")=="true");else if(c.display===v.none){o.finish(!1);return}else G=this.createElement(At,me);if(!w&&P&&c["column-fill"]===v.auto){let We=this.nodeContext.vertical?c.width:c.height;(!We||We===v.auto||Y(We))&&(G.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=v.balance)}me!=is&&(G.setAttribute("data-vivliostyle-original-tag",is),(is==="html"||is==="body")&&(G.role="presentation")),me=="a"&&G.addEventListener("click",this.page.hrefHandler,!1),ft&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ft),G.appendChild(ft)),G.localName=="iframe"&&G.namespaceURI=="http://www.w3.org/1999/xhtml"&&Mx(G);let wi=this.nodeContext.inheritedProps["image-resolution"],Xo=[],qo=c.width,Yo=c.height,xg=a.getAttribute("width"),Sg=a.getAttribute("height"),Zo=qo===v.auto||!qo&&!xg,Ko=Yo===v.auto||!Yo&&!Sg,yh=a.attributes,Cg=yh.length,Kn=null,vh=null;m===v.table_cell&&((an=(qt=(Bt=this.nodeContext.parent)==null?void 0:Bt.viewNode)==null?void 0:qt.lastElementChild)==null?void 0:an.localName)==="a"&&G.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let We=0;We<Cg;We++){let xt=yh[We],ht=xt.namespaceURI,ae=xt.localName,ke=xt.nodeValue;if(ht){if(ht=="http://www.w3.org/2000/xmlns/")continue;ht=="http://www.w3.org/1999/xlink"&&ae=="href"&&(ke=this.documentURLTransformer.transformURL(this.resolveURL(ke),this.xmldoc.url))}else{if(!vi&&ae.match(/^on/)||ae=="style")continue;if(ae==="media"&&me==="source"&&At==="http://www.w3.org/1999/xhtml"&&((Mt=a.parentElement)==null?void 0:Mt.localName)==="picture")try{let Ge=this.context.rootScope,gt=new Oo(Ge),rs=new bt(ke,gt),wh=Bd(rs,gt,"");if(wh){if(wh.toExpr().evaluate(this.context))continue;ke="not all"}}catch{}if((ae=="id"||ae=="name")&&t){let Ge=this.documentURLTransformer.transformFragment(ke,this.xmldoc.url);G.setAttribute(ae,ke),G.setAttribute("data-vivliostyle-id",Ge);let gt=G.ownerDocument.createElement("a");gt.setAttribute(ae,Ge),gt.setAttribute(Dn,"1"),gt.style.position="absolute",G.appendChild(gt),this.page.registerElementWithId(G,Ge);continue}if(ae=="src"||ae=="href"||ae=="poster")ke=this.resolveURL(ke),ae==="href"?ke=this.documentURLTransformer.transformURL(ke,this.xmldoc.url):ke=Ir(ke),ae==="src"&&(ke=vc(ke));else if(ae=="srcset")ke=ke.split(",").map(Ge=>{let gt=Ge.trim().split(/\s+/),rs=Ir(this.resolveURL(gt[0]));return gt.length>1?`${rs} ${gt.slice(1).join(" ")}`:rs}).join(",");else if(ae==="data"&&Ue&&me==="object"&&G.hasAttribute("data"))continue;if(ae==="poster"&&me==="video"&&At==="http://www.w3.org/1999/xhtml"){let Ge=new Image,gt=kt(Ge,ke);Zo&&Ko?(Yn.push(gt),Xo.push({image:Ge,element:G,fetcher:gt})):this.page.fetchers.push(gt)}}if(At=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(ke=Ax(ke,this.xmldoc.url,this.documentURLTransformer)),ht){let Ge=Fx[ht];Ge&&(ae=`${Ge}:${ae}`)}if(ae=="src"&&!ht&&(me=="img"||me=="input")&&At=="http://www.w3.org/1999/xhtml")Kn=ke;else if(ae=="alt"&&!ht&&me=="img"&&At=="http://www.w3.org/1999/xhtml")vh=ke;else if(ae=="href"&&me=="image"&&At=="http://www.w3.org/2000/svg"&&(ht=="http://www.w3.org/1999/xlink"||!ht))ht||G.setAttribute(ae,ke),this.page.fetchers.push(kt(G,ke));else if(ht)G.setAttributeNS(ht,ae,ke);else try{G.setAttribute(ae,ke)}catch(Ge){q.warn(Ge)}}if(Kn){let We=me==="input"?new Image:G,xt=kt(We,Kn,vh);We!==G&&(G.src=Kn);let ht=()=>{var ae,ke;if(c.position===v.fixed)return!0;for(let Ge=(ae=this.nodeContext.parent)==null?void 0:ae.viewNode;Ge&&Ge!==this.viewRoot;Ge=Ge.parentElement)if(((ke=Ge.style)==null?void 0:ke.position)==="fixed")return!0;return!1};!Zo&&!Ko&&!(()=>{let ae=this.nodeContext.vertical?qo:Yo;return ae instanceof L&&ae.unit==="%"})()&&!ht()?this.page.fetchers.push(xt):(Zo&&Ko&&wi&&wi!==1&&Xo.push({image:We,element:G,fetcher:xt}),Yn.push(xt))}else!Kn&&me==="img"&&At==="http://www.w3.org/1999/xhtml"&&(G.srcset||((Zn=a.parentElement)==null?void 0:Zn.localName)==="picture")&&this.page.fetchers.push(kt(G));delete c.content;let ns=c["--viv-marker-content"];if(ns){let We=ns instanceof K?ns.values:[ns];for(let xt of We)xt instanceof Qe&&xt.url&&Yn.push(kt(new Image,xt.url))}if(G.localName==="object"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("data")&&this.page.fetchers.push(kt(G)),G.localName==="embed"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("src")&&this.page.fetchers.push(kt(G)),G.localName==="iframe"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("src")){let We=G;We.loading==="lazy"&&(We.loading="eager"),this.page.fetchers.push(kt(G))}if(this.preprocessElementStyle(c),this.applyComputedStyles(G,c),this.nodeContext.inline)t||(St(G,"inline-start"),Pn(G)&&St(G,"clone"));else if(t){if(!Ar(c.position)){let We=c["margin-break"],xt=this.getBreakTypeAt(this.nodeContext),ht=xt!==null,ae=xt==="auto";(We===v.discard&&ht||We!==v.keep&&ae&&!this.nodeContext.floatSide)&&sa(G,"block-start")}}else{let We=this.nodeContext.vertical?"width":"height";ki(G,We)&&A(G,We,this.nodeContext.display==="table-row"?"0.01px":""),St(G,"block-start"),Pn(G)&&St(G,"clone"),sa(G,"block-start")}te&&c["ua-list-item-count"]&&G.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=G,Yn.length?_n(Yn).then(()=>{wi>0&&this.modifyElemDimensionWithImageResolution(Xo,wi,c,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Ee(r,n.parent.whitespace)||Rt(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&&Kr(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Ze(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),d=parseFloat(c.paddingBlockStart),p=parseFloat(c.borderBlockStartWidth);if(d||p)return null;let f=l?.firstChild;for(;f&&(Ee(f,h.parent.whitespace)||!h.floatSide&&Rt(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(s=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:s.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Ze(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let s=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(s&&s["after-if-continues"]&&s["after-if-continues"].content){let o=new ga(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new x0(t,o)}}isSVGUrlAttribute(t){return fr.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(s=>{if(s.fetcher.get().get()==="load"){let o=s.image,a=o.width/i,h=o.height/i,l=s.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=ut(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=ut(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=ut(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=ut(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||v.none,d=n["max-height"]||v.none;if(c===v.none&&d===v.none)A(l,"max-width",`${a}px`);else if(c!==v.none&&d===v.none)A(l,"width",`${a}px`);else if(c===v.none&&d!==v.none)A(l,"height",`${h}px`);else{c.isNumeric(),d.isNumeric();let p=c,f=d;p.unit!=="%"?A(l,"max-width",`${Math.min(a,ut(p,this.context))}px`):f.unit!=="%"?A(l,"max-height",`${Math.min(h,ut(f,this.context))}px`):r?A(l,"height",`${h}px`):A(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||Le,d=n["min-height"]||Le;c.isNumeric(),c.isNumeric();let p=c,f=d;p.num===0&&f.num===0?A(l,"min-width",`${a}px`):p.num!==0&&f.num===0?A(l,"width",`${a}px`):p.num===0&&f.num!==0?A(l,"height",`${h}px`):p.unit!=="%"?A(l,"min-width",`${Math.max(a,ut(p,this.context))}px`):f.unit!=="%"?A(l,"min-height",`${Math.max(h,ut(f,this.context))}px`):r?A(l,"height",`${h}px`):A(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Gt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},s=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",s,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof tn&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new tn(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||Y(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=D("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=su(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return I(!0);let t,i=t=this.sourceNode.textContent,n=D("preprocessTextContent"),r=Gt("PREPROCESS_TEXT_CONTENT"),s=0;return n.loop(()=>s>=r.length?I(!1):r[s++](this.nodeContext,i).thenAsync(o=>(i=o,I(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Tv(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=D("createNodeView"),r,s=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=I(!0)):r=this.createTextNodeView(),r.then(o=>{var a;if(s=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(d,p)=>d?.nodeType===1&&ii(d)===p,l=this.nodeContext.parent,c=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(c=this.viewRoot),c&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Ee(this.viewNode))&&!c.hasChildNodes()&&Xd(c).includes("block-start")&&St(c,"text-start"),c.appendChild(this.viewNode),gv(this.viewNode))}n.finish(s)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):I(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,s,o,a=n.subShadow||n.parentShadow;n.subShadow?(s=n.subShadow.root,o=n.subShadow.type,o==ot.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=ot.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let l=new bn(s,r,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ot.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==ot.ROOTLESS&&(r=r.firstChild),r){let s=new bn(r,t,i);return s.shadowContext=t.nodeShadow,s.shadowType=t.nodeShadow.type,this.processShadowContent(s)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new bn(n,t,i));if(t.sourceNode.nodeType!=1){let r=su(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let s=r;return ii(s)==="footnote-call"&&s.getAttribute(fr.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?s:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&Et(i)}insertFootnoteCall(t){var i,n;let r=D("insertFootnoteCall"),s=dr.createElementNS("http://www.w3.org/1999/xhtml","span");kr(s,"footnote-call");let o=this.xmldoc.getElementOffset(t.sourceNode);s.setAttribute(fr.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let a=new bn(s,t.parent,t.boxOffset);a.inline=!0;let h=new ga(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Rs(t.sourceNode,s,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,ot.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&s.hasChildNodes())r.finish(a);else{let c=a.modify();c.after=!0,a.viewNode||(c.inline=!0),r.finish(c)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return I(n);this.syncTextNodePageTypeBoundary(n);let r=D("nextInTree");return this.setCurrent(n,!0,i).then(s=>{if((!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let o=this.findImmediateFootnoteCallSibling(n);o!=null&&o.parentNode&&o.parentNode.removeChild(o),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){Er(t,this.page)}applyComputedStyles(t,i){var n,r,s;let o=i["background-image"];o&&this.addImageFetchers(o);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 c=i["clip-path"];c&&this.addImageFetchers(c);let d=i.filter;d&&this.addImageFetchers(d);let p=i["shape-outside"];p&&this.addImageFetchers(p);let f=i["--viv-marker-content"];f&&this.addImageFetchers(f);let g=i.position===v.relative,y=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),b=Object.keys(i);b.sort(Lh);let x,m;for(let w of b){if(Dx[w])continue;let S=i[w];if(!(!S||S===Be&&!Xe(w))){if(S=S.visit(new Gm(this.xmldoc.url,this.documentURLTransformer)),S instanceof L)if(S.unit==="em"){let C=this.getEmUnitSize(w,x);C!=null&&(S=new L(S.num*C,"px"))}else if(S.unit==="lh"){let C=this.getLineHeightUnitSize(w,x,m);C!=null&&(S=new L(S.num*C,"px"))}else Nc(S.unit)&&(S=Gc(S,this.context));if((w==="font-size"||w==="line-height")&&(w==="font-size"?x=S:m=S,this.viewport.layoutUnitAdj&&S instanceof L&&S.unit!=="%"&&S.unit!=="em"&&S.unit!=="lh"&&(S=new pn(`calc(${S.toString()} - var(--viv-layoutUnitAdj))`))),Fv[w]||g&&Rv[w]){this.page.delayedItems.push(new _l(t,w,S));continue}y&&this.page.pageAreaElement&&In(w)?(A(this.page.pageAreaElement.parentElement.parentElement,w,S.toString()),w!=="writing-mode"&&w!=="direction"&&A(this.viewport.layoutBox,w,S.toString())):A(t,w,S.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,s=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,o=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||s*this.context.pref.lineHeight;return{fontSize:s,lineHeight:o}}getComputedFontMetrics(t,i){var n,r,s;let o=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(o.fontSize))!=null?n:i.fontSize,h=(s=(r=this.parsePlusLayoutUnitAdj(o.lineHeight))!=null?r:i.lineHeight)!=null?s: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,s,o;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let c=null;if(n)if(n instanceof Tt||n instanceof L&&(n.unit==="em"||n.unit==="%"))c=n instanceof L&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof L&&n.unit!=="lh"){let d=this.context.queryUnitSize(n.unit,!1);if(d!=null)return n.num*d}return null}if(c==null)for(let d=(s=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:s.viewNode;d&&d.nodeType===1;d=d.parentNode){let p=(o=d?.style)==null?void 0:o.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(c=parseFloat(p));break}}if(c!=null){if(i&&!(i instanceof L))return null;let d=h.fontSize;if(i instanceof L){let p=il(i,d,this.context).num;return typeof p!="number"||isNaN(p)?null:c*p}else return d==null?null:c*d}return l}getEmUnitSize(t,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(t==="font-size"||i==null)return r;if(i instanceof L){let s=il(i,r,this.context).num;if(typeof s=="number"&&!isNaN(s))return s}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,s=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),o=pt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let h=a.content;It(h)&&(h.visit(new Rr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=D("peelOff"),r=t.firstPseudo,s=t.offsetInNode,o=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),s+=i}else if(!o&&t.viewNode&&s==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t&&t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new bn(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return I(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let s={},o=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=pt(this.cascadedPageStyle,Po);p&&p.area&&(a=p.area)}let h=pt(a,"_pseudos");t=this.computeStyle(t,i,a,s);let l=this.getFootnoteAreaInheritedMetrics();!s["font-size"]&&l.fontSize!=null&&(s["font-size"]=new L(l.fontSize,"px")),delete s.content;let c=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,s);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ve(f,"display"),y={},b=this.createElement("http://www.w3.org/1999/xhtml","span");kr(b,"before"),n.appendChild(b),this.computeStyle(t,i,f,y),g||(y.display=v.block);let x=ve(f,"content");if(x){let w=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;y.content=x.filterValue(new Br(this.styler.cascade,w,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let m=y.content;if(It(m)){m.visit(new Rr(b,this.context,m,this.exprContentListener));let w=b.querySelectorAll("img[src]");for(let C=0;C<w.length;C++){let T=w[C],R=T.getAttribute("src");if(!R)continue;let F=kt(T,R);o.push(F),this.page.fetchers.push(F)}let S=b.getAttribute("src");if(S){let C=b.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",S),b.appendChild(C));let T=kt(C,S);o.push(T),this.page.fetchers.push(T)}}delete y.content,this.applyComputedStyles(b,y)}}finally{this.computedStyleParentFontSizeOverride=c,this.computedStyleParentLineHeightOverride=d}return o.length?_n(o).thenReturn(t):I(t)}processFragmentedBlockEdge(t){var i,n,r;let s=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=ve(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!Dt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=s;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(St(l,"inline-end"),Pn(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;St(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(ki(l,c)&&A(l,c,""),St(l,"block-end"),!a++&&h!==s){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?qd(p,["block-start","text-start","block-end","text-end","justify"]):(St(l,"text-end"),St(l,"justify")):St(l,"text-end")}else St(l,"text-end")}Pn(l)&&St(l,"clone"),sa(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),s=-(n+r);isNaN(s)||(t.style.marginInlineEnd=`${s}px`)}createChildAnonymousBlockIfNeeded(t){let i=s=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||ji[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let l=s.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===s.lastChild&&Ee(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let d=i(c);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||s.hasAttribute(Dn)){let l=s.previousElementSibling;return l&&(l.nextSibling===s||l.nextSibling===s.previousSibling&&Ee(l.nextSibling))?i(l):!1}return!(!o||Dt(o))},n=null;for(let s=t.lastElementChild;s;s=s.previousElementSibling){let o=i(s);if(o){n=s;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ee(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let s=n.nextSibling,o=null;s;s=o)o=s.nextSibling,r.appendChild(s);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,s=t.unit;if(hm(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Ql(t,a,this.context).num}else{let o=this.context.queryUnitSize(s,!1);return o?r*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&ii(n)===ii(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let s=i.steps[r];return this.isSameNodePositionStep(n,s)})}isPseudoelement(t){return!!ii(t)}};u(dl,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),u(dl,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var _x=dl,Dx={"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},zx=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"pixelRatio"),u(this,"scaleRatio"),u(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}},ko=class{constructor(e,t,i,n,r,s){if(u(this,"window",e),u(this,"fontSize",t),u(this,"pixelRatio",i),u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),u(this,"layoutUnitPerPixel",64),u(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=s||this.root.clientHeight;return}let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(A(this.root,"--viv-outputPixelRatio",`${i}`),A(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),To){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;default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&A(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=s||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&c)&&(this.width=l.width),(!this.height||!s&&c)&&(this.height=l.height)}resetZoom(){A(this.outerZoomBox,"width",""),A(this.outerZoomBox,"height",""),A(this.contentContainer,"width",""),A(this.contentContainer,"height",""),A(this.contentContainer,"transform","")}zoom(e,t,i){A(this.root,"--viv-outputScale",`${i}`),A(this.outerZoomBox,"width",`${e*i}px`),A(this.outerZoomBox,"height",`${t*i}px`),A(this.contentContainer,"width",`${e}px`),A(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function Er(e,t){if(e instanceof _e)for(let i of e.values)Er(i,t);else if(e instanceof Qe){let i=Ir(e.url);t.fetchers.push(kt(new Image,i))}else if(e instanceof ai)for(let i of e.values)Er(i,t);else if(e instanceof K)for(let i of e.values)Er(i,t)}var Vx=1,Wo=class{constructor(e,t,i,n,r){u(this,"name",t),u(this,"pseudoName",i),u(this,"classes",n),u(this,"parent",r),u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${Vx++}`,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})}},$x=class extends Wo{constructor(e){super(e,null,null,[],null),this.specified.width=new U(Gr,0),this.specified.height=new U(jr,0)}},Vu=class extends Js{constructor(e,t){super(e,n),u(this,"pageMaster",t);let i=this;function n(r,s){let o=r.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return s?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},Yf=class Zf extends Wo{constructor(t,i,n,r,s,o,a){super(t,i,n,r,s),u(this,"condition",o),u(this,"specificity",a),u(this,"keyMap",{}),t instanceof Vu||(this._scope=new Vu(t,this)),this.pageMaster=this,this.specified.width=new U(Gr,0),this.specified.height=new U(jr,0),this.specified["wrap-flow"]=new U(v.auto,0),this.specified.position=new U(v.relative,0),this.specified.overflow=new U(v.visible,0)}createInstance(t){return new ch(t,this)}clone(t){let i=new Zf(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}},Kf=class Jf extends Wo{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new U(v.auto,0)}createInstance(t){return new jx(t,this)}clone(t){let i=new Jf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},ts=class Qf extends Wo{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Un(t,this)}clone(t){let i=new Qf(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Hx(e,t,i){return!t||Y(t)?new it(e,i):t.toExpr(e,e.zero)}function be(e,t,i){return!t||t===v.auto||Y(t)?null:t.toExpr(e,i)}function Ux(e,t,i){return!t||t===v.normal||Y(t)?null:t.toExpr(e,i)}function Nt(e,t,i){return!t||t===v.auto||Y(t)?e.zero:t.toExpr(e,i)}function $u(e,t,i){return!t||Y(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function si(e,t,i,n){return!t||i===v.none||Y(t)?e.zero:t.toExpr(e,n)}function eg(e,t,i){return!t||Y(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Go=class{constructor(e,t){u(this,"parentInstance",e),u(this,"pageBox",t),u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),u(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return ne(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?Kp:Jp;n=e;for(let s in r)n=n.replace(s,r[s])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;if(e==="columns"){let i=this.pageBox.scope,n=new Dc(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ye(i,As(i,new mr(i,"min",[n,r]),ne(i,s,o)),o)}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=eg(e,t.enabled,e._true),n=be(e,t.page,e.zero);if(n){let o=new Je(e,"page-number");i=Ut(e,i,new Nl(e,n,o))}let r=be(e,t["min-page-width"],e.zero);r&&(i=Ut(e,i,new Ca(e,new Je(e,"page-width"),r)));let s=be(e,t["min-page-height"],e.zero);s&&(i=Ut(e,i,new Ca(e,new Je(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new j(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=be(e,t.left,i),r=be(e,t["margin-left"],i),s=si(e,t["border-left-width"],t["border-left-style"],i),o=Nt(e,t["padding-left"],i),a=be(e,t.width,i),h=be(e,t["max-width"],i),l=Nt(e,t["padding-right"],i),c=si(e,t["border-right-width"],t["border-right-style"],i),d=be(e,t["margin-right"],i),p=be(e,t.right,i),f=ne(e,s,o),g=ne(e,s,l);if(n&&p&&a){let x=ye(e,i,ne(e,a,ne(e,ne(e,n,f),g)));r?d?p=ye(e,x,d):d=ye(e,x,ne(e,p,r)):(x=ye(e,x,p),d?r=ye(e,x,d):(r=As(e,x,new it(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let x=ye(e,i,ne(e,ne(e,r,f),ne(e,d,g)));this.isAutoWidth&&(h||(h=ye(e,x,n||p)),!this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ye(e,x,ne(e,n,a))):a=ye(e,x,ne(e,n,p)):n=ye(e,x,ne(e,p,a))}let y=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),b=Nt(e,y,i);t.left=new j(n),t["margin-left"]=new j(r),t["border-left-width"]=new j(s),t["padding-left"]=new j(o),t.width=new j(a),t["max-width"]=new j(h||a),t["padding-right"]=new j(l),t["border-right-width"]=new j(c),t["margin-right"]=new j(d),t.right=new j(p),t["snap-width"]=new j(b)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=be(e,t.top,n),s=be(e,t["margin-top"],i),o=si(e,t["border-top-width"],t["border-top-style"],i),a=Nt(e,t["padding-top"],i),h=be(e,t.height,n),l=be(e,t["max-height"],n),c=Nt(e,t["padding-bottom"],i),d=si(e,t["border-bottom-width"],t["border-bottom-style"],i),p=be(e,t["margin-bottom"],i),f=be(e,t.bottom,n),g=ne(e,o,a),y=ne(e,d,c);if(r&&f&&h){let m=ye(e,n,ne(e,h,ne(e,ne(e,r,g),y)));s?p?f=ye(e,m,s):p=ye(e,m,ne(e,f,s)):(m=ye(e,m,f),p?s=ye(e,m,p):(s=As(e,m,new it(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let m=ye(e,n,ne(e,ne(e,s,g),ne(e,p,y)));this.isAutoHeight&&(l||(l=ye(e,m,r||f)),this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ye(e,m,ne(e,r,h))):h=ye(e,m,ne(e,f,r)):r=ye(e,m,ne(e,f,h))}let b=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=Nt(e,b,i);t.top=new j(r),t["margin-top"]=new j(s),t["border-top-width"]=new j(o),t["padding-top"]=new j(a),t.height=new j(h),t["max-height"]=new j(l||h),t["padding-bottom"]=new j(c),t["border-bottom-width"]=new j(d),t["margin-bottom"]=new j(p),t.bottom=new j(f),t["snap-height"]=new j(x)}initColumns(){let e=this.pageBox.scope,t=this.style,i=be(e,t[this.vertical?"height":"width"],null),n=be(e,t["column-width"],i),r=be(e,t["column-count"],null),s=Ux(e,t["column-gap"],null);s||(s=new Wr(e,1,"em")),n&&!r&&(r=new mr(e,"floor",[ka(e,ne(e,i,s),ne(e,n,s))]),r=new mr(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,ka(e,ne(e,i,s),r),s),t["column-width"]=new j(n),t["column-count"]=new j(r),t["column-gap"]=new j(s)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=hl(this.cascaded,e,r,!1,null);this.vertical=bf(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=xf(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof gh&&e.currentLayoutPosition&&new Je(i,"left-page").evaluate(e));Cf(s,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new we(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new we(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&&In(t)&&this.pageMasterInstance instanceof Bn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new L(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=xo(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let s=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=xo(e,r,t,s)}return ut(r,e)}getSpecial(e,t){let i=nf(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==Be&&n.push(s)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&Nc(r.unit)&&(r=Gc(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),A(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new _l(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),s=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),A(t.element,"margin-left",`${n}px`),A(t.element,"padding-left",`${r}px`),A(t.element,"border-left-width",`${s}px`),t.marginLeft=n,t.borderLeft=s,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),s=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(A(t.element,"margin-right",`${r}px`),A(t.element,"padding-right",`${s}px`),A(t.element,"border-right-width",`${o}px`),t.marginRight=r,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,s+=t.snapOffsetX)}t.paddingRight=s,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),s=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,s+=t.snapOffsetY)}t.paddingTop=s,A(t.element,"top",`${n}px`),A(t.element,"margin-top",`${r}px`),A(t.element,"padding-top",`${s}px`),A(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),s=this.getPropAsNumber(e,"height")-t.snapOffsetY;A(t.element,"height",`${s}px`),A(t.element,"margin-bottom",`${i}px`),A(t.element,"padding-bottom",`${n}px`),A(t.element,"border-bottom-width",`${r}px`),t.height=s-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){A(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,A(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){A(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");A(t.element,"right",`${n}px`),A(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&A(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&A(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let s=0;s<Hu.length;s++)this.propagateProperty(e,t,Hu[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<Wu.length;r++)this.propagateProperty(e,t,Wu[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;A(r,"text-overflow","inherit"),A(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var s,o;let a=(o=(s=this.cascaded.width)!=null?s:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!Y(a)},r=()=>{var s,o;let a=(o=(s=this.cascaded.height)!=null?s:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!Y(a)};for(let s=0;s<Gu.length;s++){let o=Gu[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;A(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){var a,h,l,c,d,p,f,g,y,b;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let x=(this.vertical||!n)&&this.isAutoHeight,m=(!this.vertical||!n)&&this.isAutoWidth,w=null;if(m||x){m&&A(t.element,"width","auto"),x&&A(t.element,"height","auto");let S=n&&io(n);S&&Mo(n),w=s.getElementClientRect(n?n.element:t.element),S&&Ll(n),m&&(this.calculatedWidth=Math.ceil(w.right-w.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=w.bottom-w.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let S=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),T=this.getProp(e,"column-rule-color");if(S>0&&C&&C!=v.none&&T!=v.transparent){let R=this.getPropAsNumber(e,"column-gap"),F=this.vertical?t.height:t.width,z=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),$=t.getPaddingRect(),X=n,re=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(F+R)*k/r-R/2+t.paddingTop-S/2:(F+R)*k/r-R/2+t.paddingLeft-S/2,E=this.vertical?$.y1+_+S/2:$.x1+_+S/2,B=(d=(c=(l=X.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:c.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(c,E),P=(g=(f=(p=X.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,E),N=isFinite(B)?this.vertical?B-$.x1:B-$.y1:NaN,O=isFinite(P)?this.vertical?P-$.x1:P-$.y1:NaN,V=parseFloat(this.vertical?(y=n?.element.style.width)!=null?y:"":(b=n?.element.style.height)!=null?b:""),W=V>0?V:this.vertical?n.width:n.height,J=Math.max(z>0?z:0,0),te=J+W,Q=Math.max(J,isFinite(this.vertical?O:N)?Math.max(0,this.vertical?O:N):0),pe=Math.min(te,isFinite(this.vertical?N:O)?Math.max(0,this.vertical?N:O):te),se=Math.max(0,pe-Q),oe=t.element.ownerDocument.createElement("div");A(oe,"position","absolute"),A(oe,this.vertical?"left":"top",`${Q}px`),A(oe,this.vertical?"top":"left",`${_}px`),A(oe,this.vertical?"height":"width","0px"),A(oe,this.vertical?"width":"height",`${se}px`),A(oe,re,`${S}px ${C.toString()}${T?` ${T.toString()}`:""}`),t.element.insertBefore(oe,t.element.firstChild)}}}for(let S=0;S<Uu.length;S++)this.propagateProperty(e,t,Uu[S],o);for(let S of Wx){let C=this.getProp(e,S);C&&Er(C,i)}for(let S=0;S<ju.length;S++)this.propagateDelayedProperty(e,t,ju[S],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof Bn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Xi(s)&&Fi(i,s,ve(n,s));if(this.pageBox.pseudoName==uh)for(let s in t)(s.match(/^background-/)||s=="writing-mode")&&(i[s]=t[s]);if(this.pageBox.pseudoName=="layout-host")for(let s in t)!s.match(/^background-/)&&s!="writing-mode"&&(i[s]=t[s]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;if(r){let s=Array.from(e.lastCounterChanges),o={...e.lastCounterChangeTypes};e.counterScoping.push(null),e.pushCounters(i),i.content=r.filterValue(new Br(e,null,e.counterResolver)),e.popCounters(),e.popCounters(),e.lastCounterChanges=s,e.lastCounterChangeTypes=o}this.init(e.context);for(let s of this.pageBox.children)s.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Hu=["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","outline-offset","overflow","visibility"],Uu=["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"],Wx=["background-image","border-image-source","filter"],Wu=["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"],Gu=["width","height","image-resolution","object-fit","object-position"],ju=["transform","transform-origin"],uh="background-host",Gx=class extends Go{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)}},ch=class extends Go{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Ut(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},jx=class extends Go{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Un=class extends Go{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof he&&(n=[t]),t instanceof _e&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof he){let o=xa(n[s].name,"enabled"),a=new Je(r,o);i&&(a=new Ii(r,a)),e=Ut(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=eg(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Hx(t,i["flow-from"],"body"),s=new mr(t,"has-content",[r]);e=Ut(t,e,s)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,s=r?r.toExpr(t,null):t._true;s=Ut(t,s,e),this.pageMasterInstance.style.enabled=new j(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof sg||(A(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},dh=class extends sn{constructor(e,t,i,n){super(e,t,!1),u(this,"target",i),u(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 U(t,i?Ad:Fd)}},tg=class extends dh{constructor(e,t,i,n){super(e,t,i,n)}},Xx=class ig extends dh{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new U(Fh,0),n.specified.height=new U(Fh,0)}startPartitionRule(t,i,n){let r=new ts(this.scope,t,i,n,this.target),s=new tg(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new Kf(this.scope,t,i,n,this.target),s=new ig(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},qx=class extends dh{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new ts(this.scope,e,t,i,this.target),r=new tg(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Kf(this.scope,e,t,i,this.target),r=new Xx(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function ng(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var Yx={a10:{width:new L(26,"mm"),height:new L(37,"mm")},a9:{width:new L(37,"mm"),height:new L(52,"mm")},a8:{width:new L(52,"mm"),height:new L(74,"mm")},a7:{width:new L(74,"mm"),height:new L(105,"mm")},a6:{width:new L(105,"mm"),height:new L(148,"mm")},a5:{width:new L(148,"mm"),height:new L(210,"mm")},a4:{width:new L(210,"mm"),height:new L(297,"mm")},a3:{width:new L(297,"mm"),height:new L(420,"mm")},a2:{width:new L(420,"mm"),height:new L(594,"mm")},a1:{width:new L(594,"mm"),height:new L(841,"mm")},a0:{width:new L(841,"mm"),height:new L(1189,"mm")},b10:{width:new L(31,"mm"),height:new L(44,"mm")},b9:{width:new L(44,"mm"),height:new L(62,"mm")},b8:{width:new L(62,"mm"),height:new L(88,"mm")},b7:{width:new L(88,"mm"),height:new L(125,"mm")},b6:{width:new L(125,"mm"),height:new L(176,"mm")},b5:{width:new L(176,"mm"),height:new L(250,"mm")},b4:{width:new L(250,"mm"),height:new L(353,"mm")},b3:{width:new L(353,"mm"),height:new L(500,"mm")},b2:{width:new L(500,"mm"),height:new L(707,"mm")},b1:{width:new L(707,"mm"),height:new L(1e3,"mm")},b0:{width:new L(1e3,"mm"),height:new L(1414,"mm")},c10:{width:new L(28,"mm"),height:new L(40,"mm")},c9:{width:new L(40,"mm"),height:new L(57,"mm")},c8:{width:new L(57,"mm"),height:new L(81,"mm")},c7:{width:new L(81,"mm"),height:new L(114,"mm")},c6:{width:new L(114,"mm"),height:new L(162,"mm")},c5:{width:new L(162,"mm"),height:new L(229,"mm")},c4:{width:new L(229,"mm"),height:new L(324,"mm")},c3:{width:new L(324,"mm"),height:new L(458,"mm")},c2:{width:new L(458,"mm"),height:new L(648,"mm")},c1:{width:new L(648,"mm"),height:new L(917,"mm")},c0:{width:new L(917,"mm"),height:new L(1297,"mm")},"jis-b10":{width:new L(32,"mm"),height:new L(45,"mm")},"jis-b9":{width:new L(45,"mm"),height:new L(64,"mm")},"jis-b8":{width:new L(64,"mm"),height:new L(91,"mm")},"jis-b7":{width:new L(91,"mm"),height:new L(128,"mm")},"jis-b6":{width:new L(128,"mm"),height:new L(182,"mm")},"jis-b5":{width:new L(182,"mm"),height:new L(257,"mm")},"jis-b4":{width:new L(257,"mm"),height:new L(364,"mm")},"jis-b3":{width:new L(364,"mm"),height:new L(515,"mm")},"jis-b2":{width:new L(515,"mm"),height:new L(728,"mm")},"jis-b1":{width:new L(728,"mm"),height:new L(1030,"mm")},"jis-b0":{width:new L(1030,"mm"),height:new L(1456,"mm")},letter:{width:new L(8.5,"in"),height:new L(11,"in")},legal:{width:new L(8.5,"in"),height:new L(14,"in")},ledger:{width:new L(11,"in"),height:new L(17,"in")}},Zx=new L(.24,"pt"),oC=new L(3,"mm"),Kx=new L(10,"mm"),Jx=new L(13,"mm");function Eo(e){let t={width:Gr,height:jr,bleed:Le,bleedOffset:Le,cropOffset:Le},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,c,d;if(l.isSpaceList()?(c=l.values[0],d=l.values[1]):(c=l,d=null),c.isNumeric())t.width=c,t.height=d||c;else{let p=c.name&&Yx[c.name.toLowerCase()];p&&(d&&d===v.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,s=n&&!Y(n.value)?n.value:v.none,o=r&&!Y(r.value)?r.value:v.auto;if(o===v.auto){if(s!==v.none){let l=!1;s.isSpaceList()?l=s.values.some(c=>c===v.crop):l=s===v.crop,l&&(t.bleed=new L(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!Y(a.value)?a.value:v.auto;return h===v.auto?s!==v.none&&(t.bleedOffset=Jx):h.isNumeric()&&(t.cropOffset=h),t}function Xu(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),s=n+r,o=e.width;o===Gr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-s*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===jr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-s*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=s,i}function rg(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 Pr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var pl=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(pl||{});function Qx(e,t,i,n,r,s,o){let a=r;a<=s+2*Yt.mm&&(a=s+r/2);let h=Math.max(r,a),l=s+h+i/2,c=rg(e,l,l),d=[[0,s+r],[r,s+r],[r,s+r-a]],p=d.map(y=>[y[1],y[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(y=>[s+h-y[0],y[1]]),p=p.map(y=>[s+h-y[0],y[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(y=>[y[0],s+h-y[1]]),p=p.map(y=>[y[0],s+h-y[1]]));let f=Pr(e,i,n);f.setAttribute("points",d.map(y=>y.join(",")).join(" ")),c.appendChild(f);let g=Pr(e,i,n);return g.setAttribute("points",p.map(y=>y.join(",")).join(" ")),c.appendChild(g),t.split(" ").forEach(y=>{c.style[y]=`${o}px`}),c}var Vr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Vr||{});function eS(e,t,i,n,r,s){let o=r*2,a,h;t==="top"||t==="bottom"?(a=o,h=r):(a=r,h=o);let l=rg(e,a,h),c=Pr(e,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let d=Pr(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=Pr(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(Vr).forEach(g=>{let y=Vr[g];y===t?l.style[y]=`${s}px`:y!==f&&(l.style[y]="0",l.style[`margin-${y}`]="auto")}),l}function tS(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let y=o.value;y instanceof K?y.values.forEach(b=>{b===v.crop?r=!0:b===v.cross&&(s=!0)}):y===v.crop?r=!0:y===v.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let h=i.container,l=h.ownerDocument,c=ut(Zx,n),d=Math.max(0,t.bleedOffset-ut(Kx,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!Y(f.value)?f.value:v.auto;r&&Object.keys(pl).forEach(y=>{let b=pl[y],x=Qx(l,b,c,g,p,a,d);h.appendChild(x)}),s&&Object.keys(Vr).forEach(y=>{let b=Vr[y],x=eS(l,b,c,g,p,d);h.appendChild(x)})}var fl=(()=>{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,"outline-offset":!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})(),ph={"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"}},iS=(()=>{let e=ph;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),fh="vivliostyle-page-rule-master",$r="_marginBoxes",Po="_footnoteArea",sg=class extends Yf{constructor(e,t,i){super(e,null,fh,[],t,null,0),u(this,"pageMarginBoxes",{});let n=Eo(i),r=new nS(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[$r];t&&iS.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new sS(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new U(v.relative,0),this.specified.width=new U(t.width,0),this.specified.height=new U(t.height,0);for(let i in e)!fl[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Bn(e,this)}},nS=class extends ts{constructor(e,t,i,n){super(e,null,null,[],t),u(this,"pageSize",n);let r=new rS(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new U(v.auto,0),this.specified["z-index"]=new U(new lt(0),0),this.specified.position=new U(v.absolute,0),this.specified.overflow=new U(v.visible,0);for(let t in fl)fl.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new aS(e,this)}},rS=class extends ts{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new U(M("body"),0)}createInstance(e){return new og(e,this)}},sS=class extends ts{constructor(e,t,i,n){super(e,null,null,[],t),u(this,"marginBoxName",i),this.applySpecified(n)}applySpecified(e){let t=e[$r][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Zp[i]||r&&r.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Be&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new ag(e,this)}},Bn=class extends ch{constructor(e,t){super(e,t),u(this,"pageAreaDimension",null),u(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=Le,e["margin-left"]=Le,e["border-left-width"]=Le,e["padding-left"]=Le,e["padding-right"]=Le,e["border-right-width"]=Le,e["margin-right"]=Le,e.right=Le}initVertical(){let e=this.style;e.top=Le,e["margin-top"]=Le,e["border-top-width"]=Le,e["padding-top"]=Le,e["padding-bottom"]=Le,e["border-bottom-width"]=Le,e["margin-bottom"]=Le,e.bottom=Le}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new j(e.borderBoxWidth),t.height=new j(e.borderBoxHeight),t["padding-left"]=new j(e.marginLeft),t["padding-right"]=new j(e.marginRight),t["padding-top"]=new j(e.marginTop),t["padding-bottom"]=new j(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},s={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,s,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let s="start",o="center",a="end",h=this.pageBox.scope,l={},c={},d={};for(let w in e){let S=ph[w];if(S){let C=e[w],T=this.pageMarginBoxInstances[w],R=new js(C,T.style,t,h,r);l[S.positionAlongVariableDimension]=C,c[S.positionAlongVariableDimension]=T,d[S.positionAlongVariableDimension]=R}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,y={};Object.keys(l).forEach(w=>{let S=w,C=be(h,c[S].style[t?"max-width":"max-height"],i.extent);if(C){let T=C.evaluate(n);if(f[S]>T){let R=d[S]=new qu(l[S],c[S].style,t,h,r,T);y[S]=R.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[s,o,a].forEach(w=>{var S;f[w]=(S=y[w])!=null?S:f[w]}));let b={};Object.keys(l).forEach(w=>{let S=w,C=be(h,c[S].style[t?"min-width":"min-height"],i.extent);if(C){let T=C.evaluate(n);if(f[S]<T){let R=d[S]=new qu(l[S],c[S].style,t,h,r,T);b[S]=R.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[s,o,a].forEach(w=>{f[w]=b[w]||f[w]}));let x=p.start+p.extent,m=p.start+(p.start+p.extent);[s,o,a].forEach(w=>{let S=f[w];if(S!=null){let C=l[w],T=0;switch(w){case s:T=t?C.left:C.top;break;case o:T=(m-S)/2;break;case a:T=x-S;break}t?C.setHorizontalPosition(T,S-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(T,S-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],h=new oS(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(o.center=l.xSize);let c=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-c)/2,0);n&&(o.start=n.hasAutoSize()?d:n.getOuterSize()),s&&(o.end=s.hasAutoSize()?d:s.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,s,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof js&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof js&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),s=t.getOuterMaxContentSize();if(r>0&&s>0){let o=r+s;if(o<i)n.xSize=i*r/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:s>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},js=class{constructor(e,t,i,n,r){u(this,"container",e),u(this,"isHorizontal",i),u(this,"clientLayout",r),u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let s=t[i?"width":"height"];if(this.hasAutoSize_=!s||s===v.auto||Y(s),this.minMaxFitContent=s instanceof he&&(s.name==="min-content"||s.name==="max-content"||s.name==="fit-content")?s.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Ml(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()}},oS=class{constructor(e){u(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}},qu=class extends js{constructor(e,t,i,n,r,s){super(e,t,i,n,r),u(this,"fixedSize"),this.fixedSize=s}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},aS=class extends Un{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"contentBoxWidth",null),u(this,"contentBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=i[o].toExpr(n,null),h=be(n,t[o],a),l=be(n,t[`margin-${r}`],a),c=be(n,t[`margin-${s}`],a),d=Nt(n,t[`padding-${r}`],a),p=Nt(n,t[`padding-${s}`],a),f=si(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=si(n,t[`border-${s}-width`],t[`border-${s}-style`],a),y=ne(n,ne(n,f,d),ne(n,g,p)),b,x,m;return h?(this.borderBoxSizing?(x=h,m=ye(n,x,y)):(m=h,x=ne(n,m,y)),b=ye(n,a,x),!l&&!c?(l=As(n,b,new it(n,.5)),c=l):l?c=ye(n,b,l):l=ye(n,b,c)):(l||(l=n.zero),c||(c=n.zero),b=ne(n,l,c),x=ye(n,a,b),m=ye(n,x,y),h=this.borderBoxSizing?x:m),t[r]=new j(l),t[s]=new j(c),t[`margin-${r}`]=Le,t[`margin-${s}`]=Le,t[`border-${r}-width`]=new j(f),t[`border-${s}-width`]=new j(g),t[`padding-${r}`]=new j(d),t[`padding-${s}`]=new j(p),t[o]=new j(h),t[`max-${o}`]=new j(h),{borderBoxExtent:x,contentBoxExtent:m,marginStart:l,marginEnd:c}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},og=class extends Un{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 j(this.parentInstance.contentBoxWidth),e["margin-left"]=new j(new Sn(i,t.left.toExpr(i,null))),e["margin-right"]=new j(new Sn(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new j(this.parentInstance.contentBoxHeight),e["margin-top"]=new j(new Sn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new j(new Sn(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},ag=class extends Un{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ph[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){A(t,"display","flex"),A(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&&A(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof Qe||r instanceof j&&r.expr instanceof we&&r.expr.str.startsWith("running-element-")){let s="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?s=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(s=this.vertical||this.rtl?"end":"start")),A(t,"align-items",s)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=be(n,i[o],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new j(c);else if(l){let d=Nt(n,i[`margin-${r}`],h),p=Nt(n,i[`margin-${s}`],h),f=Nt(n,i[`padding-${r}`],h),g=Nt(n,i[`padding-${s}`],h),y=si(n,i[`border-${r}-width`],i[`border-${r}-style`],h),b=si(n,i[`border-${s}-width`],i[`border-${s}-style`],h),x=ne(n,l,ne(n,this.borderBoxSizing?n.zero:ne(n,ne(n,f,g),ne(n,y,b)),ne(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new j(ne(n,c,ka(n,ye(n,h,x),new it(n,2))));break;case"end":i[r]=new j(ye(n,ne(n,c,h),x));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=$u(n,i[`margin-${s}`],h),c=$u(n,i[`margin-${o}`],h),d=Nt(n,i[`padding-${s}`],h),p=Nt(n,i[`padding-${o}`],h),f=si(n,i[`border-${s}-width`],i[`border-${s}-style`],h),g=si(n,i[`border-${o}-width`],i[`border-${o}-style`],h),y=be(n,i[a],h),b=null;function x(m){if(b)return b;b={extent:y?y.evaluate(m):null,marginInside:l?l.evaluate(m):null,marginOutside:c?c.evaluate(m):null};let w=h.evaluate(m),S=0;return r||[f,d,p,g].forEach(C=>{C&&(S+=C.evaluate(m))}),(b.marginInside===null||b.marginOutside===null)&&S+b.extent+b.marginInside+b.marginOutside>w&&(b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)),b.extent!==null&&b.marginInside!==null&&b.marginOutside!==null&&(b.marginOutside=null),b.extent===null?(b.extent=w-S-b.marginInside-b.marginOutside,b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)):typeof b.extent=="number"&&(b.marginInside===null&&typeof b.marginOutside=="number"?b.marginInside=w-S-b.extent-b.marginOutside:typeof b.marginInside=="number"&&b.marginOutside===null?b.marginOutside=w-S-b.extent-b.marginInside:b.marginInside=b.marginOutside=(w-S-b.extent)/2),b}i[a]=new j(new we(n,function(){let m=x(this).extent;return m===null?"auto":m},a)),i[`margin-${s}`]=new j(new we(n,function(){let m=x(this).marginInside;return m===null?"auto":m},`margin-${s}`)),i[`margin-${o}`]=new j(new we(n,function(){let m=x(this).marginOutside;return m===null?"auto":m},`margin-${o}`)),s==="left"?i.left=new j(ne(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new j(ne(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,s,o){super.finishContainer(e,t,i,n,r,s,o);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let c=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof he&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&A(t.element,"width",p),f&&A(t.element,"min-width",`${f}px`),g&&A(t.element,"max-width",`${g}px`);let w=this.getProp(e,"margin-left"),S=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=c.borderBoxWidth.evaluate(e)+c.marginRight.evaluate(e);A(t.element,"right",`${C}px`),(w===v.auto||S!==v.auto)&&A(t.element,"margin-left","auto"),S===v.auto&&A(t.element,"margin-right","auto")}else l.isInRightColumn&&(A(t.element,"right","0"),(S===v.auto||w!==v.auto)&&A(t.element,"margin-right","auto"),w===v.auto&&A(t.element,"margin-left","auto"))}let y=this.getProp(e,"height"),b=y instanceof he&&(y.name==="min-content"||y.name==="max-content"||y.name==="fit-content")?y.name:null,x=this.getPropAsNumber(e,"min-height"),m=this.getPropAsNumber(e,"max-height");if(b||x||m){b&&A(t.element,"height",b),x&&A(t.element,"min-height",`${x}px`),m&&A(t.element,"max-height",`${m}px`);let w=this.getProp(e,"margin-top"),S=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=c.borderBoxHeight.evaluate(e)+c.marginBottom.evaluate(e);A(t.element,"bottom",`${C}px`),(w===v.auto||S!==v.auto)&&A(t.element,"margin-top","auto"),S===v.auto&&A(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(A(t.element,"bottom","0"),(S===v.auto||w!==v.auto)&&A(t.element,"margin-bottom","auto"),w===v.auto&&A(t.element,"margin-top","auto"))}}},lS=class{constructor(e,t,i,n,r){u(this,"pageScope",t),u(this,"rootPageBoxInstance",i),u(this,"context",n),u(this,"docElementStyle",r),u(this,"pageMasterCache",{}),u(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new Je(e,"page-number"),r=new Nl(e,new Oc(e,n,new it(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ii(e,r)),e.defineName("verso-page",r),(t.pageProgression||ng(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new Ii(e,r))):(e.defineName("left-page",new Ii(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===uh?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 U?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new sg(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:fh}),n=i.specified,r=e.size;if(r&&!Y(r.value)){let o=Eo(e),a=r.priority;Kt(n,"width",new U(o.width,a),this.context),Kt(n,"height",new U(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let s=i.createInstance(this.rootPageBoxInstance);return s.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),s.resolveAutoSizing(this.context),s}},hS=class extends Pe{constructor(e){super(),u(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}},uS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},cS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},dS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},pS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},fS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},gS=class extends Pe{constructor(e){super(),u(this,"scope",e)}apply(e){new Je(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},mS=class extends on{constructor(e,t,i){super(t,i),u(this,"scope",e),u(this,"a",t),u(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}},yS=class extends on{constructor(e,t,i,n){super(t,i),u(this,"scope",e),u(this,"a",t),u(this,"b",i),u(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}},vS=class extends eh{constructor(e,t){super(e,t,null,null,null)}apply(e){wS(e.context,e.currentStyle,this.style,this.specificity,e)}};function wS(e,t,i,n,r){bo(e,t,i,n,null,null,null);let s=i[$r];if(s){let a=oi(t,$r);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),bo(e,l,s[h],n,null,null,null)}}let o=i[Po];if(o){let a=oi(t,Po);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let c=o[h];for(let p in c)if(c.hasOwnProperty(p)&&p!=="_pseudos"){let f=c[p];f instanceof U&&Kt(l,p,f)}let d=pt(c,"_pseudos");if(d){let p=oi(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let y=d[f];for(let b in y)if(y.hasOwnProperty(b)){let x=y[b];x instanceof U&&Kt(g,b,x)}}}}}}var bS=class extends Mr{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),u(this,"pageProps",r),u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new hS(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 yS(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new mS(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 uS(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new cS(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new dS(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new pS(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new fS(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new gS(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(s=>s.selectors===null))return;super.simpleProperty(e,t,i);let n=ve(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{Fi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new U(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=r[h];l?Kt(l,e,a):(l=r[h]={},Fi(l,e,a),s&&["bleed","marks"].forEach(c=>{s[c]&&Fi(l,c,s[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new vS(this.elementStyle,e)}startFootnoteRule(e){let t=oi(this.elementStyle,Po),i=t.area;if(i||(i={},t.area=i),e){let r=oi(i,"_pseudos"),s=r[e];s||(s={},r[e]=s),i=s}let n=new lg(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=oi(this.elementStyle,$r),i=t[e];i||(i={},t[e]=i);let n=new xS(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},xS=class extends sn{constructor(e,t,i,n){super(e,t,!1),u(this,"validatorSet",i),u(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 U(t,n);Fi(this.boxStyle,e,r)}},lg=class extends sn{constructor(e,t,i,n){super(e,t,!1),u(this,"validatorSet",i),u(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 U(t,n);Fi(this.areaStyle,e,r)}},hg=class{constructor(e,t,i){u(this,"store",e),u(this,"url",t),u(this,"document",i),u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let s=this.root.firstChild;s;s=s.nextSibling){if(s.nodeType!=1)continue;let o=s;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":r=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Vt,"0")}doc(){return new cg([this.document])}getElementOffset(e){let t=e.getAttribute(Vt);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(Vt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,s=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,s=r.previousSibling,!s)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=s}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,s=r.previousSibling,!s){r=r.parentNode;break}r=s}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=mi(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,r=i,s=r.firstChild||r.nextSibling,o=null;for(;;){if(s){if(s.nodeType==1||(r=s,o=r,n+=s.textContent.length,n>e&&!/^\s*$/.test(s.textContent)))break}else if(r=r.parentNode,!r)break;s=r.nextSibling}return s&&o&&/^\s*$/.test(o.textContent)&&(o=s),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},gl=(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))(gl||{});function Ps(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let s=r.documentElement,o="parsererror";if(s.localName===o)return null;for(let a=s.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return r}function SS(e){let t=e.contentType;if(t){let n=Object.keys(gl);for(let r=0;r<n.length;r++)if(gl[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 ug(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s!=null){let o=SS(e);if(i=Ps(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Ps(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Ps(s,"image/svg+xml",r))}i||(i=Ps(s,"text/html",r))}}let n=i?new hg(t,e.url,i):null;return I(n)}function CS(){return new Fl(ug,"document")}var kS=class ml{constructor(t){u(this,"fn",t)}check(t){return this.fn(t)}withAttribute(t,i){return new ml(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new ml(n=>{if(!this.check(n))return!1;let r=new cg([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Yu=new kS(e=>!0),cg=class yl{constructor(t){u(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 yl(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 yl(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)}},ES=new Yr(()=>{let e=D("uaStylesheetBase"),t=Xp(),i=Ie("user-agent-base.css",Ni),n=new Mr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),r0(n.cascade),Rl(kd,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function PS(){return ES.get()}var NS=class extends Gs{constructor(e,t,i,n,r,s){super(e,t,null,i,n,"counter-style"),u(this,"counterStyleName",r),u(this,"counterStyles",s)}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||q.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},TS=class{constructor(e,t,i,n,r,s,o,a,h,l,c){u(this,"store",e),u(this,"rootScope",t),u(this,"pageScope",i),u(this,"cascade",n),u(this,"rootBox",r),u(this,"fontFaces",s),u(this,"footnoteProps",o),u(this,"flowProps",a),u(this,"viewportProps",h),u(this,"pageProps",l),u(this,"counterStyleStore",c),u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,g=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new we(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.getCurrentPageNumberForPageScope()},"page-number")),this.pageScope.defineName("blank-page",new we(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Sa(this.rootScope,e,t,i),s=Eb(r,this.viewportProps),o=s.width,a=s.height,h=s["text-zoom"],l=1;if(o&&a||h){let c=Yt.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=c/i,i=c,e*=l,t*=l),o&&a){let d=ut(o.evaluate(r,"width"),r),p=ut(a.evaluate(r,"height"),r);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}};function 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 s of r.positions){let o=s.chunkPosition.primary;for(let a of o.steps)i(a);if(s.chunkPosition.floats)for(let a of s.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function Ku(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var gh=class extends Sa{constructor(e,t,i,n,r,s,o,a,h,l,c,d,p,f){super(e.rootScope,n.width,n.height,n.fontSize),u(this,"style",e),u(this,"xmldoc",t),u(this,"viewport",n),u(this,"clientLayout",r),u(this,"fontMapper",s),u(this,"customRenderer",o),u(this,"fallbackMap",a),u(this,"pageNumberOffset",h),u(this,"documentURLTransformer",l),u(this,"counterStore",c),u(this,"cmykStore",d),u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"currentCascadedPageStyle",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"pageNumberContextStack",[]),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),u(this,"invalidPageAreaOnCurrentPage",!1),u(this,"repeatedInvalidPageAreaLayoutPosition",null),u(this,"semanticFootnoteFirstRefOffsets",new Map),u(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),u(this,"pageGroupPageCounts",Object.create(null)),u(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new xx(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new xn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let y=e.flowProps[g],b=ve(y,"flow-consume");b&&(b.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=D("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new _u(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=ng(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Gx(r);let s=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(s,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new lS(s,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=bx(h.properties,this),c=new jf(l);o.push(c)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Px(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 c=Xu(Eo(l),this);this.pageSheetSize[h]={width:c.pageWidth+c.cropOffset*2,height:c.pageHeight+c.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Sa(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),s=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new _u(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,s,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new Hv,i.flowPositions[e.flowName]=n);let r=zv(e.element),s=new Bi(r),o=new $v(s,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;if(Xe(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,c){}}let s=new r,o=Ri(this.style.rootScope,new bt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}getCurrentPageNumberForPageScope(){var e;return this.currentLayoutPosition?this.currentLayoutPosition.page:(e=this.pageNumberContextStack[this.pageNumberContextStack.length-1])!=null?e:0}getPageNumberContextDepth(){return this.pageNumberContextStack.length}pushPageNumberContext(e){this.pageNumberContextStack.push(e)}restorePageNumberContextDepth(e){this.pageNumberContextStack.length=e}evalSupportsSelector(e){class t extends dg{errorMsg(...o){}}let i=new t(null),n=hd(e),r=new bt(n+"{}",i);return new Zr(He,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,s=n.offsetInNode,o=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,o=!1,s=0;let h=this.xmldoc.getNodeOffset(r,s,o);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let s=0;s<r.positions.length;s++){let o=r.positions[s].chunkPosition.primary,a=this.getNodePositionOffset(o);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){var t;let i=this.getPageStartOffset(e);if(!isFinite(i))return{counterOffset:i,changeOffset:i};let n=this.xmldoc.body||this.xmldoc.root,r=n?this.getFirstInFlowElementAtOrAfter(n,i):null,s=n?this.xmldoc.getElementOffset(n):i,o=i<=s,a=r===n&&o&&(t=this.getFirstInFlowChildElement(n))!=null?t:r;if(!a)return o?{counterOffset:s,changeOffset:s}:{counterOffset:i,changeOffset:i};let h=this.xmldoc.getElementOffset(a),l=i;return o&&h!==i&&(l=h),h===i&&(this.isInlineLevelElement(a)?l=Math.max(0,i-1):l=this.getDeepestFirstInFlowChildOffset(a)),{counterOffset:l,changeOffset:h}}getPageStartElement(e,t=this.getPageStartOffset(e)){var i;if(!isFinite(t))return null;let n=this.xmldoc.body||this.xmldoc.root;if(!n)return null;let r=this.getFirstInFlowElementAtOrAfter(n,t),s=this.xmldoc.getElementOffset(n),o=t<=s;if(r===n&&o)return(i=this.getFirstInFlowChildElement(n))!=null?i:r;if((r?this.xmldoc.getElementOffset(r):Number.POSITIVE_INFINITY)>t){let a=this.xmldoc.getNodeByOffset(t);if(!Ee(a)){let h=a.nodeType===Node.ELEMENT_NODE?a:a.parentElement;for(;h;){if(this.xmldoc.getElementOffset(h)<=t&&this.isPageBoundaryCandidateElement(h))return h;h=h.parentElement}}}return r}isForcedPageBreakValue(e){return Ze(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ve(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ve(e,"page");if(!t||Y(t.value))return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){if(this.isInlineLevelElement(e))return null;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.getPageGroupPageType(i);if(n)return n;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);if(i&&this.xmldoc.getElementOffset(i)<t)return"";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.isPageBoundaryCandidateElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){var e;let t=this.xmldoc.body||this.xmldoc.root;if(!t)return null;let i=this.xmldoc.getElementOffset(t),n=this.getFirstInFlowElementAtOrAfter(t,i);return n===t&&(e=this.getFirstInFlowChildElement(t))!=null?e:n}getEffectiveFirstPageType(e){let t=e,i=t?this.getPageGroupPageType(t):null;for(;t;){let n=this.getFirstInFlowChildElement(t);if(!n)return i;let r=this.getPageGroupPageType(n);r&&(i=r),t=n}return i}getEffectivePageGroupStartElement(e){let t=e,i=e;for(;i;){let n=this.getFirstInFlowChildElement(i);if(!n)return t;this.getPageGroupPageType(n)&&(t=n),i=n}return t}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return this.getEffectiveFirstPageType(e)}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),s=this.xmldoc.body||this.xmldoc.root,o=this.xmldoc.getElementOffset(s);if(i<=o&&e===s||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e?.startSideOfFlow("body")||null,n=e?.flowPositions.body,r=!!(n&&n.positions.length),s=!!i&&en(i)&&!this.matchPageSide(i)&&!r,o=!(this.blankPageAtStart&&(!e||e.page===1))&&!(e!=null&&e.isBlankPage)&&!s,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=this.getEffectivePageGroupStartElement(h),c=l===h?a:this.xmldoc.getElementOffset(l),d=l.ownerDocument,p=this.currentPageGroupDocument!==d&&o;p&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=d);let f=l;for(;f;){let g=this.getPageGroupPageType(f);if(g){let y=this.pageGroupPageCounts[g]||(this.pageGroupPageCounts[g]=new Map),b=y.get(f)||0;(b>0||o&&(p||this.shouldStartPageGroup(f,g,c)))&&(b+=1,y.set(f,b),(t.pageTypePageIndices[g]||(t.pageTypePageIndices[g]=[])).push(b))}if(f===this.xmldoc.root)break;f=f.parentElement}}preparePageGroupPageIndicesForRerender(e,t){this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=null;for(let i=0;i<t;i++){let n=e[i]||null;this.updatePageGroupPageIndices(n)}}getFirstInFlowElementAtOrAfter(e,t){if(this.isPageBoundaryCandidateElement(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.isInlineLevelElement(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(!Ee(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 this.isInlineLevelElement(i)?null:i;t=t.nextSibling}return null}isPageBoundaryCandidateElement(e){return this.isNormalFlowElement(e)&&!this.isInlineLevelElement(e)}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),s=r&&!Y(r)?r:v.static;if(yr(s)||Ar(s))return!1;let o=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(o&&!Y(o)?o:v.none)===v.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&&!Y(n)?n:v.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let s=this.getConsumedOffset(r);s<i&&(i=s)}}return i}dumpLocation(e){q.debug("Location - page",this.currentLayoutPosition.page),q.debug(" current:",e),q.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)q.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Je(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,s=i.startBreakType;i.startBreakType=ru(nt(s,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let s=0;s<n.length;s++){if(r=n[s],r.pageBox.pseudoName===fh)continue;let o=1;r.pageBox.pseudoName===uh&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(o*l/(h*h)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===v._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let s=mi(r.length,l=>r[l]>n)-1,o=r[s],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Hl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new xn(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,c;if(!n||h.floatReference!==Te.PAGE)return!1;let d=((c=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:c.body)||null,p=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},s=D("layoutDeferredPageFloats"),o=!1,a=0;return s.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],c=l.float;if(r(c)){h.breakLoop();return}let d=new zn().findByFloat(c),p=d.findPageFloatFragment(c,t);if(p&&p.hasFloat(c)){h.continueLoop();return}else if(t.isForbidden(c)||t.hasPrecedingFloatsDeferredToNext(c)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,d,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(o=!0,t.validate());h.continueLoop()})}).then(()=>{o&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Bi(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)):I(!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=[],s=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-s.length>0;){let h=0;for(;s.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(s.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let c=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(p===null||c.exclusive)&&r.push(h),c.exclusive){s.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-s.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=ru(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{var a;if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,c)=>r.includes(c)||!s.includes(c)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let h=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(h),e.computedBlockSize===0){let l=e.pageFloatLayoutContext,c=l;for(;c;){let d=c.floatFragments.filter(p=>"isFootnote"in p.area&&p.area.isFootnote);if(d.length>0&&!c.ignoreFootnoteAreaMaxHeight&&d.some(p=>{let f=getComputedStyle(p.area.element),g=y=>y!==""&&y!=="none";return g(f.getPropertyValue("max-block-size"))||g(p.area.vertical?f.maxWidth:f.maxHeight)})){c.ignoreFootnoteAreaMaxHeight=!0;for(let p of d){l.removePageFloatFragment(p,!0);let f=(a=p.continuations[0])==null?void 0:a.float;f&&c.removeFloatDeferredToNext(f)}l.invalidate();break}c=c.parent}}}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new P0([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,h,l,c,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,y=r.element,b=new xn(a,Te.COLUMN,null,o,null,null,null),x=this.currentLayoutPosition.clone(),m=D("createAndLayoutColumn"),w;return m.loopWithFrame(S=>{let C=this.createLayoutConstraint(b);if(h>1){let T=this.viewport.document.createElement("div");if(A(T,"position","absolute"),y.appendChild(T),w=new So(T,p,this.clientLayout,C,b),w.isNonFirstColumn=s>0,w.forceNonfitting=f,w.vertical=r.vertical,w.rtl=r.rtl,w.snapHeight=r.snapHeight,w.snapWidth=r.snapWidth,r.vertical){let R=(r.rtl?h-s-1:s)*(c+l)+r.paddingTop,F=parseFloat(y.style.width);w.setHorizontalPosition(r.paddingLeft+F-r.width,r.width),w.setVerticalPosition(R,c)}else{let R=(r.rtl?h-s-1:s)*(c+l)+r.paddingLeft;w.setVerticalPosition(r.paddingTop,r.height),w.setHorizontalPosition(R,c)}w.originX=t,w.originY=i}else w=new So(y,p,this.clientLayout,C,b),w.isNonFirstColumn=!1,w.copyFrom(r);w.exclusions=g?[]:n.concat(),w.innerShape=d,b.setContainer(w),(w.vertical?w.height:w.width)>=0?this.layoutColumn(w,o).then(()=>{b.isInvalidated()||b.finish(),w.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(w.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),w.element!==y&&y.removeChild(w.element),S.continueLoop()):S.breakLoop()}):(b.finish(),S.breakLoop())}).then(()=>{m.finish(w)}),m.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof og||t instanceof ch&&!(t instanceof Bn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Un;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new xn(e,Te.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(s,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,s,c,o,a,h,d).thenAsync(f=>I(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return I(null);if(h<=1)return I(f.columns);let g=t.getProp(this,"column-fill")||v.balance,y=this.currentLayoutPosition.flowPositions[a],b=fx(h,g,p,c,o,f.columns,y);return b?(d=!1,s.lock(),c.lock(),b.balanceColumns(f).thenAsync(x=>(s.unlock(),s.validate(),c.unlock(),this.currentLayoutPosition=x.position,I(x.columns)))):I(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,h,l,c){let d=D("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=Zu(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),y=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,b=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),m=sd(x,0,0,a.width,a.height,this),w=new _x(h,this,this.viewport,this.styler,b,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),S=0,C=null,T=[];return d.loopWithFrame(R=>{this.createAndLayoutColumn(t,i,n,r,a,S++,h,o,l,g,y,m,w,c).then(F=>{if(s.isInvalidated()){T=null,R.breakLoop();return}if((F.pageBreakType&&F.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=p.clone(),Ku(f),o.validate(),o.isLocked()?(T=null,R.breakLoop()):R.continueLoop();return}C=F,T[S-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(S=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?R.continueLoop():R.breakLoop()})}).then(()=>{d.finish(T)}),d.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return I(!0);let h=D("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,c=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof ag?"complementary":"presentation";let p=t.getProp(this,"position");A(d,"position",p?p.name:"absolute");let f=t instanceof Bn;t instanceof Un?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new sp(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=s,t.prepareContainer(this,g,e,this.faces,this.clientLayout),(g.width<=0||g.height<=0)&&(t instanceof Bn||c&&c.isIdent())&&(this.invalidPageAreaOnCurrentPage=!0,q.warn("Negative or zero page area size")),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let y,b=!1;if(!c||!c.isIdent()){let x=[],m=t.getProp(this,"content");if(m instanceof j&&m.expr instanceof we&&m.expr.str.startsWith("running-element-"))m.visit(new Rr(d,this,m,this.counterStore.getExprContentListener()));else if(It(m)){let w="span";m instanceof Qe&&(w="img");let S=this.viewport.document.createElement(w);m.visit(new Rr(S,this,m,this.counterStore.getExprContentListener())),d.appendChild(S),w=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces);let C=S.querySelectorAll("img[src]");for(let R=0;R<C.length;R++){let F=C[R],z=F.getAttribute("src");if(!z)continue;let $=kt(F,z);x.push($),e.fetchers.push($)}let T=S.getAttribute("src");if(T){let R=S.querySelector("img");R||(R=S);let F=kt(R,T);x.push(F),e.fetchers.push(F)}w=="span"&&v0(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(d),b=!0);b||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),y=x.length?_n(x).thenReturn(!0):I(!0)}else if(this.pageBreaks[c.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),y=I(!0);else{let x=D("layoutContainer.inner"),m=c.toString(),w=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,g,m,w).then(S=>{if(!o.isInvalidated()){let C=S[0];C.element===d&&(g=C),g.computedBlockSize=Math.max.apply(null,S.map(R=>R.computedBlockSize)),t.finishContainer(this,g,e,C,w,this.clientLayout,this.faces);let T=this.currentLayoutPosition.flowPositions[m];T&&T.breakAfter==="region"&&(T.breakAfter=null)}x.finish(!0)}),y=x.result()}return y.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!b&&!l){let m=t.getProp(this,"shape-outside"),w=g.getOuterShape(m,this);s.push(w)}}else if(t.children.length==0){i.removeChild(d),h.finish(!0);return}let x=f?0:t.children.length-1;h.loop(()=>{for(;x>=0&&x<t.children.length;){let m=t.children[f?x++:x--],w=this.layoutContainer(e,m,d,n,r,s,o);if(w.isPending())return w.thenAsync(()=>I(!o.isInvalidated()));if(o.isInvalidated())break}return I(!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;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Uv,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),this.invalidPageAreaOnCurrentPage=!1,t=this.currentLayoutPosition;let o=t.startSideOfFlow("body");t.isBlankPage=en(o)&&this.matchPageSide(o),e.isBlankPage=t.isBlankPage,t.page++;let a=this.getPageStartPageTypeOverride(t);if(a===""?e.pageType="":a&&(e.pageType=a),e.pageType==null){let b=t.page===1?this.resolveFirstPageType():null,x=e.isBlankPage?this.styler.cascade.previousPageType:b??this.styler.cascade.currentPageType;if(e.pageType=x,!e.pageType){let m=this.getPageStartPageType(t);m&&(e.pageType=m)}e.pageType=(i=e.pageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType}this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let h=Zu(t),l=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=l,this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!s){let b=new Je(this.style.pageScope,"left-page");e.side=b.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(l);if(!c)return I(null);let d=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===Gr),e.setAutoPageHeight(c.pageBox.specified.height.value===jr);let{counterOffset:b,changeOffset:x}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(b)||(b=this.lookupOffset,x=this.lookupOffset),isFinite(b)&&this.styler.styleUntil(b,0);let m=this.styler.getCounterSnapshotAtOffset(b),w=x===b?m:this.styler.getCounterSnapshotAtOffset(x);m||(m=this.styler.getLastCounterSnapshot()),w||(w=m);let S=w&&w.offset===x?w:null;this.counterStore.setCurrentPageDocCounters((n=m?.counters)!=null?n:null,(r=S?.changes)!=null?r:null,S?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let C=Xu(Eo(l),this);this.setPageSizeAndBleed(C,e),tS(l,C,e,this),d=C.bleedOffset+C.bleed}let p=!s&&c.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=p!=v.horizontal_tb;let f=c.getProp(this,"direction")||v.ltr,g=new xn(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,p,f),y=D("layoutNextPage");return y.loopWithFrame(b=>{this.layoutContainer(e,c,e.bleedBox,d,d,[],g).then(()=>{if(g.isInvalidated()||g.finish(),g.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Ku(h),g.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);b.continueLoop()}else b.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,this.checkRepeatedInvalidPageArea(t),Object.keys(t.flowPositions).forEach(x=>{let m=t.flowPositions[x],w=m.breakAfter;w&&(w==="page"||!this.matchPageSide(w))&&(m.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let b=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(b,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),y.finish(t)}),y.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`}},IS=class vl extends Mr{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),u(this,"masterHandler",t),u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Yf(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new qx(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Ut(this.scope,this.condition,i)),this.masterHandler.pushHandler(new vl(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new u0(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Gs(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new NS(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 Gs(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Gs(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=oi(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new lg(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new bS(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Mr.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 vl(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},dg=class extends La{constructor(e){super(),u(this,"validatorSet",e),u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"counterStyles",new Gw),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new Js(null),this.pageScope=new Js(this.rootScope),this.rootBox=new $x(this.rootScope),this.cascadeParserHandler=new IS(this,null,null,null),this.slave=this.cascadeParserHandler}};function AS(e,t){return t.parseOPSResource(e)}var FS=class extends Fl{constructor(e){super(AS,"document"),u(this,"fontDeobfuscator",e),u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=D("OPSDocStore.init");return this.validatorSet=Xp(),PS().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ie(An(t),Ji)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ie(An(t),Ji)),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 ug(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Gt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){q.warn("Error during single document preprocessing:",g)}}let o=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),y=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),b=f.getAttribute("action"),x=f.getAttribute("ref");g&&y&&b&&x&&o.push({observer:g,event:y,action:b,ref:x})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ie("user-agent-page.css",Ni),text:Cd,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-counter-styles.css",Ni),text:Nd,flavor:"UA",classes:null,media:null}),n)h.push({url:Ie("user-agent-toc.css",Ni),text:Ed,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,y=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(y=="style"){let b=f.getAttribute("class"),x=f.getAttribute("media"),m=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:m?b:null,media:x})}else if(y=="link"){let b=f.getAttribute("href"),x=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),m=f.getAttribute("class"),w=f.getAttribute("media");if(b&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||m)){let S=Ie(b,i),C=f.getAttribute("title");h.push({url:S,text:null,classes:C?m:null,media:w,flavor:"Author"})}}else y=="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 c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new Yr(()=>{let p=D("fetchStylesheet"),f=0,g=new dg(this.validatorSet);return p.loop(()=>{if(f<h.length){let y=h[f++];return g.startStylesheet(y.flavor),y.text!==null?Rl(y.text,g,y.url,y.classes,y.media).thenReturn(!0):Od(y.url,g,y.classes,y.media)}return I(!1)}).then(()=>{let y=g.cascadeParserHandler.finish();c=new TS(this,g.rootScope,g.pageScope,y,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],p.finish(c)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},Nr="\u25B8",Ju="\u25BE",RS="\u25B9";function mh(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(s=>s.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function LS(e){let t=mh(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var OS=class{constructor(e,t,i,n,r,s,o,a,h,l,c){u(this,"store",e),u(this,"url",t),u(this,"lang",i),u(this,"clientLayout",n),u(this,"fontMapper",r),u(this,"rendererFactory",o),u(this,"fallbackMap",a),u(this,"documentURLTransformer",h),u(this,"counterStore",l),u(this,"cmykStore",c),u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=Cc(s),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;ki(n,"height","auto")!="auto"&&(A(n,"height","auto"),this.setAutoHeight(n,t)),ki(n,"position","static")=="absolute"&&(A(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let s=r.behavior;if(s)switch(s.toString()){case"toc-node-anchor":r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Le,r.padding=Le,r["padding-inline-start"]=new L(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new L(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Le;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&Ee(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=Nr&&(l.textContent=Nr,A(l,"cursor","pointer"),l.addEventListener("click",BS,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),s.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=RS,A(l,"margin","0.2em 0 0 -1em"),A(l,"margin-inline-start","-1em"),A(l,"margin-inline-end","0"),A(l,"display","inline-block"),A(l,"width","1em"),A(l,"text-align","center"),A(l,"vertical-align","top"),A(l,"cursor","default"),A(l,"font-family","Menlo,sans-serif"),h.appendChild(l),A(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){A(h,"height","0px");let c=i.firstElementChild;c&&c.localName==="a"&&(c.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return I(h)}}showTOC(e,t,i,n,r){if(this.page)return I(this.page);let s=D("showTOC"),o=new Zd(e,e);this.page=o;let a=Ht(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of mh(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,r);t=new ko(t.window,c.fontSize,0,e,c.width,c.height);let d=this.makeCustomRenderer(h),p=new gh(l,h,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),s.finish(o)})})}),s.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,s]=r.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:s,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function BS(e){let t=e.target,i=t.textContent==Nr;t.textContent=i?Ju:Nr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let s=r,o=s.getAttribute("data-adapt-class");if(o==="toc-container"){if(s.setAttribute("aria-hidden",i?"false":"true"),s.firstChild){r=s.firstChild;continue}}else if(o==="toc-node"&&(s.style.height=i?"auto":"0px",s.children.length>=2&&(s.children[1].tabIndex=i?0:-1),s.children.length>=3&&(s.children[0].tabIndex=i?0:-1,!i))){let a=s.children[0];if(a.textContent==Ju){a.textContent=Nr,a.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),r=s.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Ns(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function MS(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function _S(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(Ht(e))}var Qu=class extends FS{constructor(){super(null),u(this,"plainXMLStore"),u(this,"jsonStore"),u(this,"opfByURL",{}),u(this,"primaryOPFByEPubURL",{}),u(this,"deobfuscators",{}),u(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=CS(),this.jsonStore=Jy()}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 Xs(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):_S(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):Lo(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}q.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 s of r)if(s){this.loadOPF(e,s).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return I(n);let r=D("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new Xs(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(s,o).then(()=>{r.finish(n)})}):n.initWithXMLDoc(s,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=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 Xs(this,e),s=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(s){let o=s.getAttribute("href");if(/^#/.test(o)){let a=xl(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ie(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&mh(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=D("EPUBDocStore.load"),n=Ht(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(Ji)||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:")?q.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Ji.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?q.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?q.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):q.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Ht(e),i=this.documents[t];if(i)return i.isPending()?i:I(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,s=i.height-0;if(r&&s){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${s}px;}`+(o?`@page{size:${r}px ${s}px;margin:0;}`:"@page{margin:0;}")}return""}},ec=class{constructor(){u(this,"id",null),u(this,"src",""),u(this,"mediaType",null),u(this,"title",null),u(this,"itemRefElement",null),u(this,"spineIndex",-1),u(this,"compressedSize",0),u(this,"compressed",null),u(this,"epage",0),u(this,"epageCount",0),u(this,"startPage",null),u(this,"skipPagesBefore",null),u(this,"itemProperties"),this.itemProperties=Zg}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ie(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=nm(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 DS(e){return e.id}function zS(e){return t=>{let i=D("deobfuscator");return VS("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);Yy(r).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Td([a,s]))})}),i.result()}}function VS(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 Pi={dcterms:"http://purl.org/dc/terms/",marc:"http://id.loc.gov/vocabulary/",media:"http://www.idpf.org/epub/vocab/overlays/#",rendition:"http://www.idpf.org/vocab/rendition/#",onix:"http://www.editeur.org/ONIX/book/codelists/current.html#",xsd:"http://www.w3.org/2001/XMLSchema#",opf:"http://www.idpf.org/2007/opf"},gr="http://idpf.org/epub/vocab/package/meta/#",qe={language:`${Pi.dcterms}language`,title:`${Pi.dcterms}title`,creator:`${Pi.dcterms}creator`,layout:`${Pi.rendition}layout`,titleType:`${gr}title-type`,displaySeq:`${gr}display-seq`,alternateScript:`${gr}alternate-script`,role:`${gr}role`};function $S(e,t){let i={};return(n,r)=>{var s,o,a,h,l,c;let d,p,f=n.r||i,g=r.r||i;if(e==qe.title&&(d=((s=f[qe.titleType])==null?void 0:s[0].v)=="main",p=((o=g[qe.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let y=parseInt((a=f[qe.displaySeq])==null?void 0:a[0].v,10);isNaN(y)&&(y=Number.MAX_VALUE);let b=parseInt((h=g[qe.displaySeq])==null?void 0:h[0].v,10);return isNaN(b)&&(b=Number.MAX_VALUE),y!=b?y-b:e!=qe.language&&t&&(d=((l=f[qe.language]||f[qe.alternateScript])==null?void 0:l[0].v)==t,p=((c=g[qe.language]||g[qe.alternateScript])==null?void 0:c[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function HS(e,t){let i;if(!t)i=Pi;else{i={};for(let p in Pi)i[p]=Pi[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:gr;if(f)return f+p[3]}}return null},r=1,s=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Pi.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=Qo(s,d=>d.refines),a=d=>rm(d,(p,f)=>p.map(g=>{let y={v:g.value,o:g.order};g.scheme&&(y.s=g.scheme);let b=o[`#${g.id}`]||[];if(b.length||g.lang||g.role){g.lang&&b.push({name:qe.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&b.push({name:qe.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=Qo(b,m=>m.name);y.r=a(x)}return y})),h=a(Qo(s,d=>d.refines?null:d.name)),l=null;h[qe.language]&&(l=h[qe.language][0].v);let c=d=>{for(let p in d){let f=d[p];f.sort($S(p,l));for(let g=0;g<f.length;g++){let y=f[g].r;y&&c(y)}}};return c(h),h}function US(){let e=window.MathJax;return e?e.Hub:null}var tc={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},wa="viv-id-",Xs=class{constructor(e,t){u(this,"store",e),u(this,"pubURL",t),u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let s=r+(n?`#${n}`:"");return wa+bc(s,":")}transformURL(n,r){let s=n.match(/^([^#]*)#?(.*)$/);if(s){let o=s[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(s[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(wa)===0&&(n=n.substring(wa.length));let r=im(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ie("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new ec,c=h;l.initWithElement(c,e.url);let d=c.getAttribute("fallback");return d&&!tc[l.mediaType]&&(r[l.src]=d),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Nh(this.items,DS),this.itemMapByPath=Nh(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let c=this.itemMap[r[l]];if(!c)break;if(tc[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,d=c.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=c,p.spineIndex=l),p});let s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=cc(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Yu.withChild("EncryptionMethod",Yu.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),c=a[h].getAttribute("media-type");c&&l&&this.itemMap[l]&&(this.bindings[c]=this.itemMap[l].src)}if(this.metadata=HS(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[qe.language]&&(this.lang=this.metadata[qe.language][0].v),this.metadata[qe.layout]&&(this.prePaginated=this.metadata[qe.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=zS(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),I(!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(),I(!0);let t=0,i=0,n=D("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let s=this.spine[i++];s.epage=t,this.store.load(s.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),s.epageCount=Math.ceil(o.getTotalOffset()/a),t+=s.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new hg(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new ec;r.initWithParam(n),r.id;let s=i.document.createElement("itemref");s.setAttribute("idref",r.id),i.root.appendChild(s),r.itemRefElement=s,this.itemMap[r.id]=r;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):I(null)}initWithWebPubManifest(e,t,i){var n,r,s,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[qe.title]=(Array.isArray(a)?a:[a]).map(x=>{var m;return{v:(m=x.value)!=null?m:x}}));let h=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((s=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?s:[]).map(x=>x.content);h&&h.length!==0&&(this.metadata[qe.creator]=(Array.isArray(h)?h:[h]).map(x=>{var m;return{v:(m=x.name)!=null?m:x}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[qe.language]=(Array.isArray(l)?l:[l]).map(x=>({v:x})));let c=Ht(this.pubURL),d=this.getPathFromURL(c),p=d!==null?encodeURI(d):/^(?:about:|blob:)/i.test(c)?c:null;if(!e.readingOrder&&t&&p!==null){e.readingOrder=[p];for(let x of LS(t)){let m=x.getAttribute("href");if(/^(https?:)?\/\//.test(m)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(m))continue;let w=Ht(Ie(m,this.pubURL)),S=this.getPathFromURL(w),C=S!==null?encodeURI(S):w;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,y=-1;[e.readingOrder,e.resources].forEach(x=>{x instanceof Array&&x.forEach(m=>{let w=x===e.readingOrder,S=typeof m=="string"?m:m.url||m.href,C=typeof m=="string"?"":m.encodingFormat||m.href&&m.type||"";if(w||C==="text/html"||C==="application/xhtml+xml"||!C&&m.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(S)){let T=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,R={url:Ie(An(S),T),index:g++,startPage:null,skipPagesBefore:null};m.rel==="contents"&&y===-1&&(y=R.index),f.push(R)}})});let b=D("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var x,m;y!==-1&&(this.toc=this.items[y]),this.toc||(this.toc=i?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[d]);let w=(m=e.readingOrder)==null?void 0:m.length;w&&w<this.items.length&&this.items.splice(w),b.finish(!0)}),b.result()}getCFI(e,t){let i=this.spine[e],n=D("getCFI");return this.store.load(i.src).then(r=>{let s=r.getNodeByOffset(t),o=null;if(s){let a=r.getNodeOffset(s,0,!1),h=t-a,l=new Vh;l.prependPathFromNode(s,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return Mn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Vh;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let s=r.node,o=s.getAttribute("idref");if(s.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let s=i.navigate(r.document),o=r.getNodeOffset(s.node,s.offset,s.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{q.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return Mn("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let s=this.spine[r];(!s||s.epageCount==0)&&(s=this.spine[--r]);let o=Math.floor(e-s.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:o});return}let i=mi(this.spine.length,r=>{let s=this.spine[r];return s.epage+s.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let s=0;if(e>0){let o=r.getTotalOffset();s=Math.round(o*e/n.epageCount),s==o&&s--}t.finish({spineIndex:i,offsetInItem:s,pageIndex:-1})})},(t,i)=>{q.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 I(n)}if(e.offsetInItem<=0)return I(t.epage);let i=D("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),s=Math.min(r,e.offsetInItem);i.finish(t.epage+s*t.epageCount/r)}),i.result()}},Ts=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),WS=class{constructor(e,t,i,n,r,s){u(this,"opf",e),u(this,"viewport",t),u(this,"fontMapper",i),u(this,"pageSheetSizeReporter",r),u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"cmykStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),u(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=Cc(n),this.clientLayout=new zx(t),this.counterStore=new Zm(e.documentURLTransformer),this.cmykStore=new Kc,s!=null&&s.length&&this.cmykStore.registerCmykReserveMap(s)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return I(!0);let i=D("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let s=0;s<e;s++){let o=this.spineItems[s];if(!o||!o.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,s)=>r+s.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let s=e.item.spineIndex+1;s<this.spineItems.length;s++){let o=this.spineItems[s];if(o&&o.pages[0]){r=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let s=i[r];if(!s)continue;let o=(e=n[r])!=null?e:0;t+=Math.min(s,o)}return t}reportPaginationProgress(e,t){let i=Gt("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),s=r;t&&(s=e.instance.getPosition(t,!0)),s<0&&(s=0),s>r&&(s=r);let o=this.paginationProgress.renderedOffsetsBySpine[n];o!=null&&s<o&&(s=o),this.paginationProgress.renderedOffsetsBySpine[n]=s;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),c=h>0?l/h:0;c<this.paginationProgress.lastReportedFraction?c=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=c,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let d={fraction:c,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(d)}catch(f){q.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,s,o){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=s?.pageType===n.pageType,c=n.offset!==t.offset,d=o&&!c&&i>0;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,o){let p=e.instance.getPageStartPageTypeOverride(t.position);p===""?t.pageType="":p&&(t.pageType=p)}if(!o&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!o&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(s)&&r.pageType!==s.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let s=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||s)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Ns(n));let r=Ns(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return I(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let s=e.pages[t.page],o=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||o,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,s,a,o,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):I(!0)):I(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=D("resolveUnresolvedReferencesForPage"),s=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),o=0,a=t;return r.loopWithFrame(h=>{if(o++,o>s.length){h.breakLoop();return}let l=s[o-1];if(l.refs=l.refs.filter(c=>!c.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(c=>{if(!c){h.continueLoop();return}let d=c.instance.styler.cascade,p=c.instance.pageManager.pageCascadeInstance,f={currentPageType:d.currentPageType,previousPageType:d.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},y=MS(c.instance.pageGroupPageCounts),b=c.instance.currentPageGroupDocument,x=c.instance.scopes;c.instance.scopes={};let m=l.pageIndex<c.pages.length-1,w=!!c.pages[l.pageIndex],S=w&&m,C=S?c.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let T=c.layoutPositions[l.pageIndex];w&&c.instance.preparePageGroupPageIndicesForRerender(c.layoutPositions,l.pageIndex),this.renderSinglePage(c,T).then(R=>{S&&c.instance.endIsolatedRootPageFloatLayoutContext(C);let F=d.currentPageType;d.currentPageType=f.currentPageType,d.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,c.instance.pageGroupPageCounts=y,c.instance.currentPageGroupDocument=b,c.instance.scopes=x;let z=Ns(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),R.pageAndPosition.position.spineIndex===a.spineIndex&&R.pageAndPosition.position.pageIndex===i&&(a=R.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&F!==R.pageAndPosition.page.pageType&&(d.currentPageType=a.pageType);let $=c!==e,X=c.pages.length,re=c.layoutPositions[X],k=c.instance.hasActiveRootPageFloatLayoutContext();if(re&&!k){let _=$?Ns(this.counterStore.currentPageCounters):null;$&&(this.counterStore.currentPageCounters=z);let E=X;this.renderSinglePage(c,re).then(()=>{$&&this.markSpineItemCompleteIfReady(c);let B=c.pages.length-E;if($&&B>0){this.counterStore.adjustPageCountersOfLaterSpines(c.item.spineIndex,B),this.counterStore.updateTargetCounterNodesInPages(c.pages);let P=c.item.spineIndex;for(let N=P+1;N<this.spineItems.length;N++){let O=this.spineItems[N];if(O){O.item.epage+=B;for(let V of O.pageCounterStarts)V!=null&&V.page&&(V.page=V.page.map(W=>W+B));this.counterStore.updatePageCounterNodesInPages(O.pages,O.pageCounterStarts)}}if(_){let N=_.page;N&&(_.page=N.map(O=>O+B))}}_&&(this.counterStore.currentPageCounters=_),h.continueLoop()});return}$&&this.markSpineItemCompleteIfReady(c),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=e.instance.getPageNumberContextDepth();e.instance.pushPageNumberContext(n+1);let s=()=>{e.instance.restorePageNumberContextDepth(r)};i.handler=(d,p)=>{s(),d.task.raise(p,d.parent)};let o=this.isInCounterResolveScope(),a=this.preparePageCountersForRender(e,n),h=n>0?e.pages[n-1]:null,l=e.pages[n+1],c=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,c,n,a,h,l,o),e.instance.layoutNextPage(c,t).then(d=>{t=d;let p=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,c,p),this.counterStore.finishPage(c.spineIndex,p),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,a,c).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,c,p,t)).then(f=>{s(),i.finish({pageAndPosition:Ts(f,p),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=mi(t.layoutPositions.length,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=D("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,s;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);s=a.pageIndex,r=n.pages[s],r?o.breakLoop():n.complete?(s=n.pages.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):s<n.layoutPositions.length&&!n.pages[s]?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Ts(r,s))})})}),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,s=n.offsetInItem,o=i.pages[r];if(o){t.finish(Ts(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(s>=0&&i.instance.getPosition(h)>s){o=c,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=c,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(Ts(o,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(s=>!s.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,s=0;t&&(s=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++s>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=D("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=s.pages[s.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return I(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 I({left:null,right:null});let n=D("getSpread"),r=i.side==="left",s;return this.isRectoPage(i,e)?s=this.previousPage(e,t):s=this.nextPage(e,t),s.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return I(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(s=>{if(s){if(s.page.side===i.side)return r;let o=this.nextPage(s.position,t);return o.thenAsync(a=>a?o:r)}else return I(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return I(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),s=i.container.previousElementSibling;return n?r.thenAsync(o=>o?o.page.side===i.side||o.page.container!==s?r:this.previousPage(o.position,t):I(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(!Et(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ie(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let s=0;s<r.length;s++){let o=r.item(s);if(!Wt(o))continue;let a=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ie(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(o)}return null}navigateTo(e,t,i){q.debug("Navigate to",e);let n=this.opf.getPathFromURL(Ht(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return I(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return I(null)}let s=D("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(o=>{if(!o){s.finish(null);return}let a=o.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(o,a),l=h??(a?o.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(s)})}),s.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Tr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let s=new Zd(n,r);if(s.spineIndex=e.item.spineIndex,s.position=t,s.offset=e.instance.getPosition(t),s.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",o),s.registerElementWithId(r,o)}if(i!==this.viewport){let o=kc(this.viewport.width,this.viewport.height,i.width,i.height),a=Ri(null,new bt(o,null),"");s.delayedItems.push(new _l(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Ie(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let h=Eh(r),l=Eh(o),c=new gi;c.append(a),c.append("?src="),c.append(h),c.append("&type="),c.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let y=g.getAttribute("name"),b=g.getAttribute("value");y&&b&&(c.append("&"),c.append(encodeURIComponent(y)),c.append("="),c.append(encodeURIComponent(b)))}}s.setAttribute("src",c.toString());let d=t.getAttribute("width");d&&s.setAttribute("width",d);let p=t.getAttribute("height");p&&s.setAttribute("height",p)}}}return s||(s=this.viewport.document.createElement("object"),r&&s.setAttribute("data",Ir(r)),s.setAttribute("data-adapt-process-children","true")),I(s)}makeMathJaxView(e,t,i,n){let r=US();if(r){let s=i.ownerDocument,o=s.createElement("span");i.appendChild(o);let a=s.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=r.queue;h.Push(["Typeset",r,o]);let l=D("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(o)}),l.result()}return I(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ie(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):I(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return I(null);let t=this.spineItems[e];if(t)return I(t);let i=D("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],s=this.opf.store;return s.load(r.src).then(o=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=o.document.title;let l=s.getStyleForDoc(o),c=this.makeCustomRenderer(o),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new ko(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],y,b;if(r.startPage!==null)y=r.startPage-1,b=y;else{if(e>0&&(!g||!g.complete))y=r.epage||e,!this.opf.prePaginated&&y%2==(f?1:0)&&y++,b=y;else{y=g?g.instance.pageNumberOffset+g.pages.length:0;let w=g&&g.pageCounterStarts[g.pages.length-1],S=w&&w.page;if(S&&S.length)b=S[S.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;b=!C||!C.length?y:C[C.length-1]}}r.skipPagesBefore!==null&&(y+=r.skipPagesBefore,b+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(b);let x=new gh(l,o,this.opf.lang,d,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,y,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);x.pref=this.pref;let m=this.opf.metadata&&this.opf.metadata[qe.title];x.pubTitle=m&&m[0]&&m[0].v||"",x.docTitle=r.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),t={item:r,xmldoc:o,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(w=>{w.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 I(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"),I(this.tocView.page);let n=D("showTOC");this.tocView||(this.tocView=new OS(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,s=Math.min(344,Math.round(.67*r.width)-16),o=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),Tr||(a.style.visibility="hidden"),a.style.width=`${s+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,s,o,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},ic="data-vivliostyle-viewer-status",GS="data-vivliostyle-spread-view",pg=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(pg||{}),jS=class{constructor(e,t,i,n){u(this,"window",e),u(this,"viewportElement",t),u(this,"instanceId",i),u(this,"callbackFn",n),u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView"),u(this,"cmykReserveMap"),u(this,"cmykReserveMapUrl");let r=t.ownerDocument,s=(o,a)=>{let h=r.getElementById(o);return h||(h=r.createElement("style"),h.id=o,a&&(h.textContent=a),r.head.appendChild(h)),h};s("vivliostyle-viewport-screen-css",wd),s("vivliostyle-viewport-css",bd),s("vivliostyle-polyfill-css",Pd),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Tr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ic,"loading"),this.fontMapper=new Sx(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=s("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Sc(),this.pageSizes=[],this.pixelRatioLimit=To==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=fc;q.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),q.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),q.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),q.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(ic,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){Pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=D("loadPublication");return this.configure(e).then(()=>{let o=new Qu;o.init(n,r).then(()=>{let a=Ie(An(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(o).then(()=>{this.render(i).then(()=>{s.finish(!0)})})):s.finish(!1)})})}),s.result()}loadXML(e){Pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=D("loadXML");return this.configure(e).then(()=>{let a=new Qu;a.init(r,s).then(()=>{let h=t.map((l,c)=>({url:Ie(An(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Xs(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,I(!0))):t=I(!0),t.thenAsync(()=>(Pt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let s=Yt[r];if(s)return t*s}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Sh(e.userAgentRootURL.replace(/resources\/?$/,"")),Ch(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Sh(e.rootURL),Ch(`${Ji}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!==vi&&(Cx(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),I(!0)}configurePlugins(e){Gt("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=>{A(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),A(e.container,"visibility","visible"),A(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?_n(i.fetchers):I(!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 ko(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new ko(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;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(GS,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let o=function(g){let y=g*.75;return Math.ceil(y)};var s=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),c=o(h),d=l*((this.pixelRatio||1)-1)+2,p=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,I(!0);let t=Ie(An(this.cmykReserveMapUrl),Ji),i=D("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Em(n)?this.cmykReserveMap=n:(q.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 WS(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?I(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,I(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,I(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,I(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.");if(e==="fit inside viewport"){let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}else 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 nc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return I(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Fa().getScheduler().run(()=>Mn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,Pt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.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():I(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),Pt.registerEndTiming("render (resize)"),vi&&qf(this.window)?Nx(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 nc)Pt.registerEndTiming("render (resize)"),q.debug(i.message);else throw i}));return I(!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 I(!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 I(!0);if(!this.opfView)return I(!0);let n=D("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=D("moveTo.showCurrent");s=o.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else s=I(!0);s.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return I(!0)}else if(i=="hide")return I(!0);if(n&&i!="show")return this.opfView.hideTOC(),I(!0);{let s=D("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(r&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}s.finish(!0)}),s.result()}}runCommand(e){let t=e.a||"";return Mn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(q.error("No such action:",t),i.finish(!0))},(i,n)=>{q.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=rc(e),i=null,n=this;Uy(()=>{let r=D("commandLoop"),s=Fa().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};s.run(()=>(n.callback(l),I(!0)))}},r.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=D("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=rc(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},fg=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(fg||{}),nc=class gg extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,gg.prototype),this.stack=new Error().stack}};function rc(e){return typeof e=="string"?xl(e):e}var sc=bl;function XS(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function oc(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 mg=class{constructor(e,t){u(this,"settings",e),u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),uc(e.debug),this.adaptViewer_=new jS(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=XS(),t&&this.setOptions(t),this.eventTarget=new Cl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},oc(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function s(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let o=s(r.authorStyleSheet),a=s(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:qS(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},oc(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()===sc.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===sc.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 qS(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 yg=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(yg||{}),YS=fg,ZS=pg;Pt.forceRegisterEndTiming("load_vivliostyle");var KS=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:s=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=s}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1872
1872
|
<!DOCTYPE html>
|
|
1873
1873
|
<html data-vivliostyle-paginated="true">
|
|
1874
1874
|
<head>
|
|
@@ -1897,5 +1897,5 @@ span[data-viv-leader] {
|
|
|
1897
1897
|
<div id="vivliostyle-viewer-viewport"></div>
|
|
1898
1898
|
</body>
|
|
1899
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 mg({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var s,o;let a=(o=(s=r.content.error)==null?void 0:s.toString())!=null?o:r.content.messages.join(`
|
|
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
|
|
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 JS(e,t){new KS(e,t).init()}});var QS={};Ag(QS,{printHTML:()=>bg.printHTML});module.exports=Rg(QS);var bg=Fg(wg());
|
|
1901
1901
|
//# sourceMappingURL=index.cjs.js.map
|