@vivliostyle/print 2.44.1 → 2.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,12 +1,12 @@
1
- var Tg=Object.create;var lo=Object.defineProperty;var Ag=Object.getOwnPropertyDescriptor;var Ig=Object.getOwnPropertyNames;var Fg=Object.getPrototypeOf,Rg=Object.prototype.hasOwnProperty;var Lg=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},Og=(e,t)=>{for(var i in t)lo(e,i,{get:t[i],enumerable:!0})},Eh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ig(t))!Rg.call(e,r)&&r!==i&&lo(e,r,{get:()=>t[r],enumerable:!(n=Ag(t,r))||n.enumerable});return e};var Bg=(e,t,i)=>(i=e!=null?Tg(Fg(e)):{},Eh(t||!e||!e.__esModule?lo(i,"default",{value:e,enumerable:!0}):i,e)),Mg=e=>Eh(lo({},"__esModule",{value:!0}),e);var Cg=Lg((gC,Sg)=>{"use strict";var _g=Object.create,Wr=Object.defineProperty,Dg=Object.getOwnPropertyDescriptor,zg=Object.getOwnPropertyNames,Vg=Object.getPrototypeOf,Ug=Object.prototype.hasOwnProperty,dc=e=>{throw TypeError(e)},$g=(e,t,i)=>t in e?Wr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Hg=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(i){throw t=0,i}},Wg=(e,t)=>{for(var i in t)Wr(e,i,{get:t[i],enumerable:!0})},pc=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of zg(t))!Ug.call(e,r)&&r!==i&&Wr(e,r,{get:()=>t[r],enumerable:!(n=Dg(t,r))||n.enumerable});return e},Gg=(e,t,i)=>(i=e!=null?_g(Vg(e)):{},pc(t||!e||!e.__esModule?Wr(i,"default",{value:e,enumerable:!0}):i,e)),jg=e=>pc(Wr({},"__esModule",{value:!0}),e),u=(e,t,i)=>$g(e,typeof t!="symbol"?t+"":t,i),Sl=(e,t,i)=>t.has(e)||dc("Cannot "+i),H=(e,t,i)=>(Sl(e,t,"read from private field"),i?i.call(e):t.get(e)),ie=(e,t,i)=>t.has(e)?dc("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),de=(e,t,i,n)=>(Sl(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),le=(e,t,i)=>(Sl(e,t,"access private method"),i),Xg=Hg((e,t)=>{var i=-1,n=1,r=0;function o(k,_,F,D,E){if(k===_)return k?[[r,k]]:[];if(F!=null){var N=X(k,_,F);if(N)return N}var R=l(k,_),$=k.substring(0,R);k=k.substring(R),_=_.substring(R),R=d(k,_);var V=k.substring(k.length-R);k=k.substring(0,k.length-R),_=_.substring(0,_.length-R);var q=s(k,_);return $&&q.unshift([r,$]),V&&q.push([r,V]),b(q,E),D&&f(q),q}function s(k,_){var F;if(!k)return[[n,_]];if(!_)return[[i,k]];var D=k.length>_.length?k:_,E=k.length>_.length?_:k,N=D.indexOf(E);if(N!==-1)return F=[[n,D.substring(0,N)],[r,E],[n,D.substring(N+E.length)]],k.length>_.length&&(F[0][0]=F[2][0]=i),F;if(E.length===1)return[[i,k],[n,_]];var R=p(k,_);if(R){var $=R[0],V=R[1],q=R[2],Q=R[3],ee=R[4],pe=o($,q),oe=o(V,Q);return pe.concat([[r,ee]],oe)}return a(k,_)}function a(k,_){for(var F=k.length,D=_.length,E=Math.ceil((F+D)/2),N=E,R=2*E,$=new Array(R),V=new Array(R),q=0;q<R;q++)$[q]=-1,V[q]=-1;$[N+1]=0,V[N+1]=0;for(var Q=F-D,ee=Q%2!==0,pe=0,oe=0,se=0,De=0,Te=0;Te<E;Te++){for(var fe=-Te+pe;fe<=Te-oe;fe+=2){var Ce=N+fe,ge;fe===-Te||fe!==Te&&$[Ce-1]<$[Ce+1]?ge=$[Ce+1]:ge=$[Ce-1]+1;for(var Ie=ge-fe;ge<F&&Ie<D&&k.charAt(ge)===_.charAt(Ie);)ge++,Ie++;if($[Ce]=ge,ge>F)oe+=2;else if(Ie>D)pe+=2;else if(ee){var Be=N+Q-fe;if(Be>=0&&Be<R&&V[Be]!==-1){var Fe=F-V[Be];if(ge>=Fe)return h(k,_,ge,Ie)}}}for(var He=-Te+se;He<=Te-De;He+=2){var Be=N+He,Fe;He===-Te||He!==Te&&V[Be-1]<V[Be+1]?Fe=V[Be+1]:Fe=V[Be-1]+1;for(var gt=Fe-He;Fe<F&&gt<D&&k.charAt(F-Fe-1)===_.charAt(D-gt-1);)Fe++,gt++;if(V[Be]=Fe,Fe>F)De+=2;else if(gt>D)se+=2;else if(!ee){var Ce=N+Q-He;if(Ce>=0&&Ce<R&&$[Ce]!==-1){var ge=$[Ce],Ie=N+ge-Ce;if(Fe=F-Fe,ge>=Fe)return h(k,_,ge,Ie)}}}}return[[i,k],[n,_]]}function h(k,_,F,D){var E=k.substring(0,F),N=_.substring(0,D),R=k.substring(F),$=_.substring(D),V=o(E,N),q=o(R,$);return V.concat(q)}function l(k,_){if(!k||!_||k.charAt(0)!==_.charAt(0))return 0;for(var F=0,D=Math.min(k.length,_.length),E=D,N=0;F<E;)k.substring(N,E)==_.substring(N,E)?(F=E,N=F):D=E,E=Math.floor((D-F)/2+F);return C(k.charCodeAt(E-1))&&E--,E}function c(k,_){var F=k.length,D=_.length;if(F==0||D==0)return 0;F>D?k=k.substring(F-D):F<D&&(_=_.substring(0,F));var E=Math.min(F,D);if(k==_)return E;for(var N=0,R=1;;){var $=k.substring(E-R),V=_.indexOf($);if(V==-1)return N;R+=V,(V==0||k.substring(E-R)==_.substring(0,R))&&(N=R,R++)}}function d(k,_){if(!k||!_||k.slice(-1)!==_.slice(-1))return 0;for(var F=0,D=Math.min(k.length,_.length),E=D,N=0;F<E;)k.substring(k.length-E,k.length-N)==_.substring(_.length-E,_.length-N)?(F=E,N=F):D=E,E=Math.floor((D-F)/2+F);return P(k.charCodeAt(k.length-E))&&E--,E}function p(k,_){var F=k.length>_.length?k:_,D=k.length>_.length?_:k;if(F.length<4||D.length*2<F.length)return null;function E(oe,se,De){for(var Te=oe.substring(De,De+Math.floor(oe.length/4)),fe=-1,Ce="",ge,Ie,Be,Fe;(fe=se.indexOf(Te,fe+1))!==-1;){var He=l(oe.substring(De),se.substring(fe)),gt=d(oe.substring(0,De),se.substring(0,fe));Ce.length<gt+He&&(Ce=se.substring(fe-gt,fe)+se.substring(fe,fe+He),ge=oe.substring(0,De-gt),Ie=oe.substring(De+He),Be=se.substring(0,fe-gt),Fe=se.substring(fe+He))}return Ce.length*2>=oe.length?[ge,Ie,Be,Fe,Ce]:null}var N=E(F,D,Math.ceil(F.length/4)),R=E(F,D,Math.ceil(F.length/2)),$;if(!N&&!R)return null;R?N?$=N[4].length>R[4].length?N:R:$=R:$=N;var V,q,Q,ee;k.length>_.length?(V=$[0],q=$[1],Q=$[2],ee=$[3]):(Q=$[0],ee=$[1],V=$[2],q=$[3]);var pe=$[4];return[V,q,Q,ee,pe]}function f(k){for(var _=!1,F=[],D=0,E=null,N=0,R=0,$=0,V=0,q=0;N<k.length;)k[N][0]==r?(F[D++]=N,R=V,$=q,V=0,q=0,E=k[N][1]):(k[N][0]==n?V+=k[N][1].length:q+=k[N][1].length,E&&E.length<=Math.max(R,$)&&E.length<=Math.max(V,q)&&(k.splice(F[D-1],0,[i,E]),k[F[D-1]+1][0]=n,D--,D--,N=D>0?F[D-1]:-1,R=0,$=0,V=0,q=0,E=null,_=!0)),N++;for(_&&b(k),S(k),N=1;N<k.length;){if(k[N-1][0]==i&&k[N][0]==n){var Q=k[N-1][1],ee=k[N][1],pe=c(Q,ee),oe=c(ee,Q);pe>=oe?(pe>=Q.length/2||pe>=ee.length/2)&&(k.splice(N,0,[r,ee.substring(0,pe)]),k[N-1][1]=Q.substring(0,Q.length-pe),k[N+1][1]=ee.substring(pe),N++):(oe>=Q.length/2||oe>=ee.length/2)&&(k.splice(N,0,[r,Q.substring(0,oe)]),k[N-1][0]=n,k[N-1][1]=ee.substring(0,ee.length-oe),k[N+1][0]=i,k[N+1][1]=Q.substring(oe),N++),N++}N++}}var g=/[^a-zA-Z0-9]/,v=/\s/,w=/[\r\n]/,x=/\n\r?\n$/,m=/^\r?\n\r?\n/;function S(k){function _(oe,se){if(!oe||!se)return 6;var De=oe.charAt(oe.length-1),Te=se.charAt(0),fe=De.match(g),Ce=Te.match(g),ge=fe&&De.match(v),Ie=Ce&&Te.match(v),Be=ge&&De.match(w),Fe=Ie&&Te.match(w),He=Be&&oe.match(x),gt=Fe&&se.match(m);return He||gt?5:Be||Fe?4:fe&&!ge&&Ie?3:ge||Ie?2:fe||Ce?1:0}for(var F=1;F<k.length-1;){if(k[F-1][0]==r&&k[F+1][0]==r){var D=k[F-1][1],E=k[F][1],N=k[F+1][1],R=d(D,E);if(R){var $=E.substring(E.length-R);D=D.substring(0,D.length-R),E=$+E.substring(0,E.length-R),N=$+N}for(var V=D,q=E,Q=N,ee=_(D,E)+_(E,N);E.charAt(0)===N.charAt(0);){D+=E.charAt(0),E=E.substring(1)+N.charAt(0),N=N.substring(1);var pe=_(D,E)+_(E,N);pe>=ee&&(ee=pe,V=D,q=E,Q=N)}k[F-1][1]!=V&&(V?k[F-1][1]=V:(k.splice(F-1,1),F--),k[F][1]=q,Q?k[F+1][1]=Q:(k.splice(F+1,1),F--))}F++}}function b(k,_){k.push([r,""]);for(var F=0,D=0,E=0,N="",R="",$;F<k.length;){if(F<k.length-1&&!k[F][1]){k.splice(F,1);continue}switch(k[F][0]){case n:E++,R+=k[F][1],F++;break;case i:D++,N+=k[F][1],F++;break;case r:var V=F-E-D-1;if(_){if(V>=0&&A(k[V][1])){var q=k[V][1].slice(-1);if(k[V][1]=k[V][1].slice(0,-1),N=q+N,R=q+R,!k[V][1]){k.splice(V,1),F--;var Q=V-1;k[Q]&&k[Q][0]===n&&(E++,R=k[Q][1]+R,Q--),k[Q]&&k[Q][0]===i&&(D++,N=k[Q][1]+N,Q--),V=Q}}if(L(k[F][1])){var q=k[F][1].charAt(0);k[F][1]=k[F][1].slice(1),N+=q,R+=q}}if(F<k.length-1&&!k[F][1]){k.splice(F,1);break}if(N.length>0||R.length>0){N.length>0&&R.length>0&&($=l(R,N),$!==0&&(V>=0?k[V][1]+=R.substring(0,$):(k.splice(0,0,[r,R.substring(0,$)]),F++),R=R.substring($),N=N.substring($)),$=d(R,N),$!==0&&(k[F][1]=R.substring(R.length-$)+k[F][1],R=R.substring(0,R.length-$),N=N.substring(0,N.length-$)));var ee=E+D;N.length===0&&R.length===0?(k.splice(F-ee,ee),F=F-ee):N.length===0?(k.splice(F-ee,ee,[n,R]),F=F-ee+1):R.length===0?(k.splice(F-ee,ee,[i,N]),F=F-ee+1):(k.splice(F-ee,ee,[i,N],[n,R]),F=F-ee+2)}F!==0&&k[F-1][0]===r?(k[F-1][1]+=k[F][1],k.splice(F,1)):F++,E=0,D=0,N="",R="";break}}k[k.length-1][1]===""&&k.pop();var pe=!1;for(F=1;F<k.length-1;)k[F-1][0]===r&&k[F+1][0]===r&&(k[F][1].substring(k[F][1].length-k[F-1][1].length)===k[F-1][1]?(k[F][1]=k[F-1][1]+k[F][1].substring(0,k[F][1].length-k[F-1][1].length),k[F+1][1]=k[F-1][1]+k[F+1][1],k.splice(F-1,1),pe=!0):k[F][1].substring(0,k[F+1][1].length)==k[F+1][1]&&(k[F-1][1]+=k[F+1][1],k[F][1]=k[F][1].substring(k[F+1][1].length)+k[F+1][1],k.splice(F+1,1),pe=!0)),F++;pe&&b(k,_)}function C(k){return k>=55296&&k<=56319}function P(k){return k>=56320&&k<=57343}function L(k){return P(k.charCodeAt(0))}function A(k){return C(k.charCodeAt(k.length-1))}function z(k){for(var _=[],F=0;F<k.length;F++)k[F][1].length>0&&_.push(k[F]);return _}function U(k,_,F,D){return A(k)||L(D)?null:z([[r,k],[i,_],[n,F],[r,D]])}function X(k,_,F){var D=typeof F=="number"?{index:F,length:0}:F.oldRange,E=typeof F=="number"?null:F.newRange,N=k.length,R=_.length;if(D.length===0&&(E===null||E.length===0)){var $=D.index,V=k.slice(0,$),q=k.slice($),Q=E?E.index:null;e:{var ee=$+R-N;if(Q!==null&&Q!==ee||ee<0||ee>R)break e;var pe=_.slice(0,ee),oe=_.slice(ee);if(oe!==q)break e;var se=Math.min($,ee),De=V.slice(0,se),Te=pe.slice(0,se);if(De!==Te)break e;var fe=V.slice(se),Ce=pe.slice(se);return U(De,fe,Ce,q)}e:{if(Q!==null&&Q!==$)break e;var ge=$,pe=_.slice(0,ge),oe=_.slice(ge);if(pe!==V)break e;var Ie=Math.min(N-ge,R-ge),Be=q.slice(q.length-Ie),Fe=oe.slice(oe.length-Ie);if(Be!==Fe)break e;var fe=q.slice(0,q.length-Ie),Ce=oe.slice(0,oe.length-Ie);return U(V,fe,Ce,Be)}}if(D.length>0&&E&&E.length===0)e:{var De=k.slice(0,D.index),Be=k.slice(D.index+D.length),se=De.length,Ie=Be.length;if(R<se+Ie)break e;var Te=_.slice(0,se),Fe=_.slice(R-Ie);if(De!==Te||Be!==Fe)break e;var fe=k.slice(se,N-Ie),Ce=_.slice(se,R-Ie);return U(De,fe,Ce,Be)}return null}function re(k,_,F,D){return o(k,_,F,D,!0)}re.INSERT=n,re.DELETE=i,re.EQUAL=r,t.exports=re}),fc={};Wg(fc,{CoreViewer:()=>bg,HOOKS:()=>As,Navigation:()=>xg,PageProgression:()=>Cl,PageSide:()=>yc,PageViewMode:()=>rC,Profiler:()=>bc,ReadyState:()=>vc,UserAgentBaseCss:()=>Td,UserAgentCounterStylesCss:()=>Fd,UserAgentPageCss:()=>Nd,UserAgentTocCss:()=>Ad,UserAgentXml:()=>Pd,ValidationTxt:()=>Ed,VivliostylePolyfillCss:()=>Id,VivliostyleViewportCss:()=>kd,VivliostyleViewportScreenCss:()=>Cd,ZoomType:()=>nC,getHooksForName:()=>_t,isDebug:()=>Ar,pageProgressionOf:()=>mc,plugin:()=>Yg,printHTML:()=>sC,profile:()=>Qg,profiler:()=>Nt,registerHook:()=>Ft,removeHook:()=>kl,setDebug:()=>gc});Sg.exports=jg(fc);var Ar=!1;function gc(e){Ar=e}var Cl=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Cl||{});function mc(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var yc=(e=>(e.LEFT="left",e.RIGHT="right",e))(yc||{}),vc=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(vc||{}),wc=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(wc||{}),qg=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=ho(arguments);this.consoleDebug(uo(t)),this.triggerListeners(1,t)}info(...e){let t=ho(arguments);this.consoleInfo(uo(t)),this.triggerListeners(2,t)}warn(...e){let t=ho(arguments);this.consoleWarn(uo(t)),this.triggerListeners(3,t)}error(...e){let t=ho(arguments);this.consoleError(uo(t)),this.triggerListeners(4,t)}};function ho(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function uo(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
2
- `])),n=n.concat([t.toString()]),i&&(n=n.concat([`
3
- `]).concat(i))),n}var Y=new qg,As=(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))(As||{}),Jo={};function Ft(e,t,i){if(!As[e])Y.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Jo[e];n||(n=Jo[e]=[]),i?n.unshift(t):n.push(t)}}function kl(e,t){if(!As[e])Y.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Jo[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function _t(e){return Jo[e]||[]}var Yg={registerHook:Ft,removeHook:kl},bc=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){ea.call(this,e,"start",t)}forceRegisterEndTiming(e,t){ea.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];t+=i,r>1&&(t+=`(${o})`),t+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
- `}}),Y.info(t)}disable(){this.registerTiming=ln,this.registerStartTiming=this.registerStartTiming=ln,this.registerEndTiming=this.registerEndTiming=ln}enable(){this.registerTiming=ea,this.registerStartTiming=this.registerStartTiming=Ph,this.registerEndTiming=this.registerEndTiming=Zg}isEnabled(){return this.registerStartTiming===Ph}};function ln(){}function ea(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[t]));s--)r=null;r||(r={},n.push(r)),r[t]=i}function Ph(e,t){this.registerTiming(e,"start",t)}function Zg(e,t){this.registerTiming(e,"end",t)}var Kg={now:Date.now},Jg=window&&window.performance,Nt=new bc(Jg||Kg);Nt.forceRegisterStartTiming("load_vivliostyle");var Qg={profiler:{registerStartTiming:Nt.registerStartTiming,registerEndTiming:Nt.registerEndTiming,printTimings:Nt.printTimings,disable:Nt.disable,enable:Nt.enable}},Gr=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Qo=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Ht="data-adapt-eloff",em={};function El(e){return JSON.parse(e)}function pt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function xc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Pl="?viv-toc-box";function Is(e){return e.endsWith(Pl)}function dn(e){return Is(e)?e.slice(0,-Pl.length):e}function Sa(e){return Is(e)?e:pt(e)+Pl}var Ji=window.location.href;function Nh(e){Ji=e}var Ni=window.location.href;function Th(e){Ni=e}function tm(e){let t=xc(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 Ae(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//)){let s=tm(t);return s?s+e:(i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e)}if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=xc(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function es(e,t){return e.match(/^#/)&&t?pt(t)+e:Ae(e,t)}function Sc(e){return/^about:blank($|[?#])/i.test(e)?"data:text/html,":e}function Fn(e){let t;return(e=Sc(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 Ah(e){return e==null?e:e.toString()}var im=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}},Cc=["","-webkit-","-moz-"],pn={};function Lo(e,t){return CSS.supports(e+t,"unset")}function nm(e){let t=pn[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return pn[e]=null,null;case"text-combine-upright":if(Lo("-webkit-","text-combine")&&!Lo("","text-combine-upright"))return pn[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Cc)if(Lo(i,e))return t=[i+e],pn[e]=t,t;return Y.warn("Property not supported by the browser: ",e),pn[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=nm(t);if(r)for(let o of r){switch(o){case"-webkit-text-combine":i==="all"&&(i="horizontal");break;case"text-combine-upright":i==="all"&&n.setProperty("text-indent","0");break}n.setProperty(o,i)}}function ki(e,t,i){try{let n=pn[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function Ca(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var 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 Nl(e){return`\\${e.charCodeAt(0).toString(16)} `}function Ti(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Nl)}function jr(e){return e.replace(/[\u0000-\u001F"\\]/g,Nl)}function Ih(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Fh(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function rm(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function kc(e,t){function i(n){return rm(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function ts(e){return kc(e)}function om(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function sm(e,t){t=typeof t=="string"?t:"\\u";function i(r){return om(r,t)}let n=new RegExp(`${ts(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 Ec(e,t){return e-t}function Rh(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function am(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function ta(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 lm(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Tl=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 Pc(){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 Nc(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 hm=Pc(),Lh={PENDING:{}};function Tc(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function um(e){return`"${jr(`${e}`)}"`}function cm(e){return Ti(`${e}`)}function ka(e,t){return e?`${Ti(e)}.${Ti(t)}`:Ti(t)}var Ac=0,is=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${Ac++}`,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=Tc,i["css-string"]=um,i["css-name"]=cm,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 dm(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Ic(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 pm(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function fm(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Zt={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function Fc(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 Ea=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=hm}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(Ic(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Zt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let o=e.builtIns[t];if(o){if(n)return e.zero;let s=Array(i.length);for(let a=0;a<i.length;a++)s[a]=i[a].evaluate(this);return new it(e,o.apply(this,s))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,o=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&t==null)return o!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Xt=class{constructor(e){u(this,"scope",e),u(this,"key"),this.scope=e,this.key=`_${Ac++}`}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===Lh.PENDING?!1:n;{i[this.key]=Lh.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}},Rc=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)}},Fs=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)}},Lc=class extends Fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Gn=class extends Fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Oc=class extends Fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Al=class extends Fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ai=class extends Rc{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},gm=class extends Ai{constructor(e,t){super(e,t)}getOp(){return"not "}},Cn=class extends Rc{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Il=class extends Lc{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},mm=class extends Il{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Fl=class extends Lc{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},ym=class extends Fl{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},vm=class extends Fl{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},wm=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},bm=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},xm=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Pa=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Rl=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Sm=class extends Gn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},Bc=class extends Oc{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Mc=class extends Oc{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Ll=class extends Al{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},_c=class extends Al{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Dc=class extends Al{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Xr=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)}},Oh=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 Cm(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function km(e,t,i){let n=t;for(let r=0;r<t.length;r++){let o=t[r].expand(e,i);if(t!==n)n[r]=o;else if(o!==t[r]){n=Array(t.length);for(let s=0;s<r;s++)n[s]=t[s];n[r]=o}}return n}var yr=class zc extends Xt{constructor(t,i,n){super(t),u(this,"qualifiedName",i),u(this,"params",n)}appendTo(t,i){t.append(this.qualifiedName),Cm(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=km(t,this.params,i);return n===this.params?this:new zc(this.scope,this.qualifiedName,n)}},Em=class Vc 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),o=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new Vc(this.scope,n,r,o)}},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(jr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Bh=class Uc extends Xt{constructor(t,i,n){super(t),u(this,"name",i),u(this,"value",n)}appendTo(t,i){t.append("("),t.append(jr(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 Uc(this.scope,this.name,n)}},Pm=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)}},$c=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 Wt(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 Il(e,t,i)}function ne(e,t,i){return t===e.zero?i:i===e.zero?t:new Bc(e,t,i)}function ye(e,t,i){return t===e.zero?new Cn(e,i):i===e.zero?t:new Mc(e,t,i)}function Oo(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Ll(e,t,i)}function Na(e,t,i){return t===e.zero?e.zero:i===e.one?t:new _c(e,t,i)}var Kt=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},nn=class extends Kt{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 o=0;o<i;o++)t[o]=e[o];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?Me:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Me:t===e.values?e:new Oe(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Me:t===e.values?e:new ai(e.name,t)}visitExpr(e){return e}},ot=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}},Hc=class Wc extends ot{static get instance(){return this.empty||(this.empty=new Wc),this.empty}constructor(){super()}toExpr(t,i){return new it(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};u(Hc,"empty");var Nm=Hc,Me=Nm.instance,Gc=class jc extends ot{static get instance(){return this.slash||(this.slash=new jc),this.slash}constructor(){super()}toExpr(t,i){return new it(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};u(Gc,"slash");var Tm=Gc,jn=Tm.instance,K=class extends ot{constructor(e){super(),u(this,"str",e)}toExpr(e,t){return new it(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(jr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Ta=Object.create(null),he=class extends ot{constructor(e){if(super(),u(this,"name",e),Ta[e])throw new Error("E_INVALID_CALL");Ta[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 B(e){let t=Ta[e];return t||(t=new he(e)),t}var O=class extends ot{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 Ll(e,t,new it(e,this.num/100)):new Xr(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}},At=class extends ot{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 At{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Xc=class extends ot{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 ot{constructor(e){super(),u(this,"url",e)}appendTo(e,t){e.append('url("'),e.append(jr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},qc=class extends ot{constructor(e){super(),u(this,"urangeText",e)}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Ol(e,t,i,n){var r,o;let s=t.length;if(s>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<s;a++)e.append(i),(o=t[a])==null||o.appendTo(e,n)}}var J=class extends ot{constructor(e){super(),u(this,"values",e)}appendTo(e,t){Ol(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Oe=class extends ot{constructor(e){super(),u(this,"values",e)}appendTo(e,t){Ol(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ai=class extends ot{constructor(e,t){super(),u(this,"name",e),u(this,"values",t)}appendTo(e,t){e.append(Ti(this.name)),e.append("("),Ol(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},j=class extends ot{constructor(e){super(),u(this,"expr",e)}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof it||this.expr instanceof Xr?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}},fn=class extends ot{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 Yc(e,t){return new O(ut(e,t),"px")}var y={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),inside:B("inside"),keep:B("keep"),landscape:B("landscape"),left:B("left"),line:B("line"),list_item:B("list-item"),ltr:B("ltr"),manual:B("manual"),max_content:B("max-content"),min_content:B("min-content"),none:B("none"),normal:B("normal"),oeb_page_foot:B("oeb-page-foot"),oeb_page_head:B("oeb-page-head"),outside:B("outside"),padding_box:B("padding-box"),page:B("page"),relative:B("relative"),revert:B("revert"),right:B("right"),same:B("same"),scale:B("scale"),snap_block:B("snap-block"),snap_inline:B("snap-inline"),solid:B("solid"),spread:B("spread"),_static:B("static"),rtl:B("rtl"),table:B("table"),table_caption:B("table-caption"),table_cell:B("table-cell"),table_footer_group:B("table-footer-group"),table_header_group:B("table-header-group"),table_row:B("table-row"),top:B("top"),transparent:B("transparent"),unset:B("unset"),vertical_lr:B("vertical-lr"),vertical_rl:B("vertical-rl"),visible:B("visible"),_true:B("true")},Mh=new O(100,"%"),qr=new O(100,"pvw"),Yr=new O(100,"pvh"),Le=new O(0,"px"),hC=new qc("U+0-10FFFF"),_h={"font-size":1,"line-height":2,color:3};function Z(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function Dh(e,t){let i=_h[e]||Number.MAX_VALUE,n=_h[t]||Number.MAX_VALUE;return i-n}function Xe(e){return e?.length>2&&e.startsWith("--")}var gn,mn,yn,Zc=class li{constructor(t,i,n){ie(this,gn),ie(this,mn),ie(this,yn),de(this,gn,Math.round(Math.max(0,Math.min(t,li.MAX)))),de(this,mn,Math.round(Math.max(0,Math.min(i,li.MAX)))),de(this,yn,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,gn)+t,H(this,mn)+i,H(this,yn)+n)}toKey(){return JSON.stringify([H(this,gn),H(this,mn),H(this,yn)])}toColorFunc(t){return new ai("color",[new J([B("srgb"),new At(H(this,gn)/li.MAX),new At(H(this,mn)/li.MAX),new At(H(this,yn)/li.MAX),...t!==null?[jn,new At(t)]:[]])])}};gn=new WeakMap,mn=new WeakMap,yn=new WeakMap,u(Zc,"MAX",1e4);var ui=Zc;function Am(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Vi,Ui,$i,Qt,Kc=class yt{constructor(t,i,n,r){ie(this,Vi),ie(this,Ui),ie(this,$i),ie(this,Qt),de(this,Vi,Math.round(Math.max(0,Math.min(t,yt.MAX)))),de(this,Ui,Math.round(Math.max(0,Math.min(i,yt.MAX)))),de(this,$i,Math.round(Math.max(0,Math.min(n,yt.MAX)))),de(this,Qt,Math.round(Math.max(0,Math.min(r,yt.MAX))))}static fromInt(t,i,n,r){return new yt(t,i,n,r)}static fromNumber(t,i,n,r){return new yt(t*yt.MAX,i*yt.MAX,n*yt.MAX,r*yt.MAX)}toSRGB(){let t=yt.MAX-H(this,Qt);return ui.fromInt(ui.MAX-Math.min(ui.MAX,Math.round(H(this,Vi)*t/yt.MAX)+H(this,Qt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,Ui)*t/yt.MAX)+H(this,Qt)),ui.MAX-Math.min(ui.MAX,Math.round(H(this,$i)*t/yt.MAX)+H(this,Qt)))}equals(t){return H(this,Vi)===H(t,Vi)&&H(this,Ui)===H(t,Ui)&&H(this,$i)===H(t,$i)&&H(this,Qt)===H(t,Qt)}toJSON(){return{c:H(this,Vi),m:H(this,Ui),y:H(this,$i),k:H(this,Qt)}}};Vi=new WeakMap,Ui=new WeakMap,$i=new WeakMap,Qt=new WeakMap,u(Kc,"MAX",1e4);var Jc=Kc;function hn(e){return e instanceof At?Math.max(0,Math.min(1,e.num)):e instanceof O&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function Qc(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]),o=hn(t[3]);if(i===null||n===null||r===null||o===null)return null;let s=null;if(t.length>=5){if(t[4]===jn){if(t.length!==6)return null;s=hn(t[5])}else{if(t.length!==5)return null;s=hn(t[4])}if(s===null)return null}return{cmyk:Jc.fromNumber(i,n,r,o),alpha:s}}function*Im(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,ns,ed,zh,td=class{constructor(){ie(this,ns),ie(this,Ci,new Map)}registerDeviceCmyk(e){let t=Qc(e);return t?le(this,ns,ed).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=Jc.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,ns=new WeakSet,ed=function(e){let t=e.toSRGB(),i=t.toKey(),n=H(this,Ci).get(i);return n?n.equals(e)?t:le(this,ns,zh).call(this,e,t):(H(this,Ci).set(i,e),t)},zh=function(e,t){for(let i=1;i<=ui.MAX;i++)for(let[n,r,o]of Im(i)){let s=t.offset(n,r,o),a=s.toKey();if(!H(this,Ci).has(a))return H(this,Ci).set(a,e),s}return Y.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Bo,lr,hr,id=class extends nn{constructor(e){super(),ie(this,Bo),ie(this,lr,new Map),ie(this,hr,!1),de(this,Bo,e??new td)}reset(){de(this,hr,!1)}hadDeviceCmyk(){return H(this,hr)}recordConversion(e,t){H(this,lr).set(e,t)}getConversions(){if(H(this,lr).size===0)return null;let e={};return H(this,lr).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=H(this,Bo).registerDeviceCmyk(e);return t?(de(this,hr,!0),t):super.visitFunc(e)}};Bo=new WeakMap,lr=new WeakMap,hr=new WeakMap;function nd(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Fm(e){return`^${e}`}function Vh(e){return e.replace(/[\[\]\(\),=;^]/g,Fm)}function Rm(e){return e.substr(1)}function Aa(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Rm)}function Lm(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Aa(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Uh(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Lm(i[2]),e=e.substr(i[0].length)}return t}var $h=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Hh=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,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?e.after=!0:r=s}e.node=r}if(this.id&&(e.after||this.id!=nd(e.node))){let s=t.ownerDocument.getElementById(this.id);s?e.node=s:Y.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Wh=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 o=i.textContent.length;if(t<=o)break;if(!r){t=o;break}t-=o}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Vh(this.textBefore)),e.append(","),this.textAfter&&e.append(Vh(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Gh=class rd{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,o=[];for(;;){let s;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[3];s=Uh(i[4]),o.push(new Hh(a,h,Ah(s.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Aa(h));let l=i[7];l&&(l=Aa(l)),s=Uh(i[10]),o.push(new Wh(a,h,l,Ah(s.s)));break}case"!":r++,o.push(new $h);break;case"~":case"@":case"":this.steps=o;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new rd,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let o=[],s=t.parentNode,a="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,c=l.length;n?(i+=c,a||(a=l)):(i>c&&(i=c),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new Wh(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:nd(t),c=n?1:0;for(;t;)t.nodeType==1&&(c+=2),t=t.previousSibling;o.push(new Hh(c,l,r)),r=null,t=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new $h),this.steps=o.concat(this.steps)):this.steps=o}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")}},Mt=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)}},ia=class{constructor(e,t,i,n){u(this,"left",e),u(this,"top",t),u(this,"right",i),u(this,"bottom",n)}},jh=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 Om(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Rs=class od{constructor(t){u(this,"points",t)}addSegments(t,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new jh(o,a,1,i):h=new jh(a,o,-1,i),t.push(h),o=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new Ei(r.x+t,r.y+i));return new od(n)}};function Xh(e,t,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new Ei(e+i*Math.sin(s),t+n*Math.cos(s)))}return new Rs(r)}function Bl(e,t,i,n){return new Rs([new Ei(e,t),new Ei(i,t),new Ei(i,n),new Ei(e,n)])}var co=class{constructor(e,t,i,n){u(this,"x",e),u(this,"winding",t),u(this,"shapeId",i),u(this,"lowOrHigh",n)}};function qh(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 Bm(e,t,i,n){let r,o,s,a;t.high.y<i&&Y.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=qh(t,i),o=t.winding):(r=t.low.x,o=0),t.high.y>=n?(s=qh(t,n),a=t.winding):(s=t.high.x,a=0),r<s?(e.push(new co(r,o,t.shapeId,-1)),e.push(new co(s,a,t.shapeId,1))):(e.push(new co(s,a,t.shapeId,-1)),e.push(new co(r,o,t.shapeId,1)))}function Mm(e,t,i){let n=t+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=e.length;for(let c=0;c<l;c++){let d=e[c];r[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let p=!1;for(s=0;s<t;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=t;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function _m(e,t){return t?Math.ceil(e/t)*t:e}function Yh(e,t){return t?Math.floor(e/t)*t:e}function Dm(e){return new Ei(e.y,-e.x)}function rs(e){return new Mt(e.y1,-e.x2,e.y2,-e.x1)}function sd(e){return new Mt(-e.y2,e.x1,-e.y1,e.x2)}function Zh(e){return new Rs(e.points.map(t=>Dm(t)))}function zm(e,t,i,n,r,o){o&&(e=rs(e),t=t.map(m=>Zh(m)),i=i.map(m=>Zh(m)));let s=t.length,a=i?i.length:0,h=[],l=[],c,d,p;for(c=0;c<s;c++)t[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+s);let f=l.length;l.sort(Om);let g=0;for(;l[g].shapeId>=s;)g++;let v=l[g].low.y;v>e.y1&&h.push(new pi(e.y1,v,e.x2,e.x2));let w=0,x=[];for(;w<f&&(p=l[w]).low.y<v;)p.high.y>v&&x.push(p),w++;for(;w<f||x.length>0;){let m=e.y2,S=Math.min(_m(Math.ceil(v+n),r),e.y2);for(d=0;d<x.length&&m>S;d++)p=x[d],p.low.x==p.high.x?p.high.y<m&&(m=Math.max(Yh(p.high.y,r),S)):p.low.x!=p.high.x&&(m=S);for(m>e.y2&&(m=e.y2);w<f&&(p=l[w]).low.y<m;){if(p.high.y<v){w++;continue}if(p.low.y<S)p.low.y==p.high.y&&p.low.y==v||(x.push(p),m=S),w++;else{let P=Yh(p.low.y,r);P<m&&(m=P);break}}let b=[];for(d=0;d<x.length;d++)Bm(b,x[d],v,m);b.sort((P,L)=>P.x-L.x||P.lowOrHigh-L.lowOrHigh);let C=Mm(b,s,a);if(C.length==0)h.push(new pi(v,m,e.x2,e.x2));else{let P=0,L=e.x1;for(d=0;d<C.length;d+=2){let A=Math.max(e.x1,C[d]),z=Math.min(e.x2,C[d+1])-A;z>P&&(P=z,L=A)}P==0?h.push(new pi(v,m,e.x2,e.x2)):h.push(new pi(v,m,Math.max(L,e.x1),Math.min(L+P,e.x2)))}if(m==e.y2)break;for(v=m,d=x.length-1;d>=0;d--)x[d].high.y<=m&&x.splice(d,1)}return ad(e,h),h}function ad(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 ld(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 Vm(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)o=n.y2;return r===e.length?o=t.y2:o=Math.min(o,t.y2),o<=i?null:new Mt(t.x1,i,t.x2,o)}function Um(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)o=n.y1;return o=Math.max(o,t.y1),i<=o?null:new Mt(t.x1,o,t.x2,i)}function $m(e,t,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=ld(t,r);for(;;){let h=r+s;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+o<=c||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=c-o,i.x2=c),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Hm(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 o,s=t.length==0?e.y1:t[t.length-1].y2;s<e.y2&&t.push(new pi(s,e.y2,e.x1,e.x2));let a=ld(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(o=t[a],a++,t.splice(a,0,new pi(h.y1,o.y2,o.x1,o.x2)),o.y2=h.y1);a<t.length&&(o=t[a++],o.y2>h.y2&&(t.splice(a,0,new pi(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,e.x2):o.x2=Math.max(h.x1,e.x1)),o.y2!=h.y2););}ad(e,t)}var Wm=class extends Kt{constructor(){super(),u(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Gm(e){if(e){let t=new Wm;try{return e.visit(t),t.propSet}catch(i){Y.warn(i,"toSet:")}}return{}}var jm=class extends Kt{constructor(e){super(),u(this,"value",e)}visitInt(e){return this.value=e.num,e}};function Kh(e,t){if(e){let i=new jm(t);try{return e.visit(i),i.value}catch(n){Y.warn(n,"toInt: ")}}return t}var Xm=class extends Kt{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 O(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new Ei(e+o[a],t+o[a+1]));return new Rs(s)}break;case"rectangle":if(o.length==4)return Bl(e+o[0],t+o[1],e+o[0]+o[2],t+o[1]+o[3]);break;case"ellipse":if(o.length==4)return Xh(e+o[0],t+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return Xh(e+o[0],t+o[1],o[2],o[2]);break}}return null}};function hd(e,t,i,n,r,o){if(e){let s=new Xm;try{return e.visit(s),s.getShape(t,i,n,r,o)}catch(a){Y.warn(a,"toShape:")}}return Bl(t,i,t+n,i+r)}var qm=class extends Kt{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,o=(n=t?.defaultValue)!=null?n:r?0:1,s=new qm(r,o);try{e.visit(s)}catch(a){Y.warn(a,"toCounters:")}return s.counters}var Ym=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 Zm(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function kn(e,t){var i;if(t==="content"){let n=e.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(t==="marker"){let n=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=e.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let o=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(s=>Zm(s.substring(1,s.length-1))).join("")}return""}else{let n=e.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var Km=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}},Jm=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()}},Qm=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(Ae(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let o=this.counterStore.currentPageCounters[e];return o&&o.length?o[o.length-1]:null},n=new we(this.pageScope,()=>t(i()),`page-counter-${e}`),r=o=>t(o[o.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new 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]||[],o=r.length?r[r.length-1]:0,s=n?.[e]||[],a=s.length?s[0]:0;return t.length?[o+(t[0]-a),...t.slice(1)]:[o]}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?kn(n,t):kn(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),o=new we(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[t]){let a=s[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),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,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new we(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,o,h);if(l.length)return i(l);let c=o[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 o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(Qo);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,o=n[1],s=r.getPageCounterFormat(i)||(h=>h.length?String(h[h.length-1]):""),a=r.getOrCreateNamedStringPageCounterExpr(this.pageScope,t,o,s);return new j(a)}}return e}return e instanceof J?new J(e.values.map(i=>this.freezePageCounters(i,t))):e instanceof Oe?new Oe(e.values.map(i=>this.freezePageCounters(i,t))):e}contentListToString(e){if(e instanceof K)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 Oe?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(Ec),o=this.counterStore.currentPage;if(!o)return{value:"",offset:-1};let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${Ht}]`)).map(p=>parseInt(p.getAttribute(Ht),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,v=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,d=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let w=o.container.querySelector(`[${Ht}="${f}"]`);if(!w)l<0&&(l=f);else{let x=o.container.querySelector(`[${Ht}="${s}"]`);if(x||(x=o.container.querySelector(`[${Ht}="0"]`)),x){for(let m=x;m;m=m.firstElementChild)if(m===w){l=f;break}}}}c=f}else(v>a||v<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)}},ey=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 Jm(this,e)}createCounterResolver(e,t,i){return new Qm(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 S=this.currentPageDocCounters[m],b=S.length?S[S.length-1]:0,C=x[m]||[],P=C.length?C[C.length-1]:0,L=b-P,A=n[m],z=A==="reset"||A==="set";r[m]={delta:L,reset:z,value:b}}}let o=Object.create(null),s,a=!1,h=e["counter-reset"];if(h){let x=h.evaluate(t);x&&(a=x===y.none,a||(s=qi(x,{reset:!0})))}s&&"pages"in s&&delete s.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(s)for(let x in s)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],o[x]=!0;else if(m.delta!==0){g[x]||(g[x]=[0]);let S=g[x];S[S.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 v=Object.create(null),w=x=>{if(!Object.prototype.hasOwnProperty.call(v,x)){let m=g[x];m&&(v[x]=Array.from(m))}};if(s)for(let x in s)w(x),this.definePageCounter(x,s[x]);for(let x in p){if(o[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(w(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 v)this.pageCountersBeforeOverride[x]=Array.from(v[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 o=this.referencesToSolve[r];if(o.targetId===e){if(o.resolve(),this.referencesToSolve.splice(r,1),t){let s=t.indexOf(o);s>=0&&t.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Km(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=bi(this.currentPageCounters),s=this.currentPageDocCounters?bi(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let c=h[0];this.pageTextById[a]={content:kn(c,"content"),before:kn(c,"before"),after:kn(c,"after"),marker:kn(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 o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.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(`[${Ht}]`)).map(r=>parseInt(r.getAttribute(Ht),10)));for(let r of Object.keys(this.namedStringPageSnapshots)){let o=parseInt(r,10);if(o<=i)continue;let s=this.namedStringPageSnapshots[o];o<=n&&i<=s.lastOffset&&delete this.namedStringPageSnapshots[o]}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(o=>o+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(o=>o+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${er}]`);for(let n of i){let r=n.getAttribute(er),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let o=r.container.querySelectorAll(`[${ra}]`);for(let h of o){let l=h.getAttribute(ra),c=this.namedStringPageCounterExprMap[l];if(!c)continue;let d=this.getPageCountersForOffset(c.offset),p=d?.[c.counterName];p&&(h.textContent=c.format(p))}let s=this.getPageCountersForPage(r,t?.[n]);if(!s)continue;let a=r.container.querySelectorAll(`[${Qn}]`);for(let h of a){let l=h.getAttribute(Qn),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=s[p];f&&(h.textContent=c.format(f))}}}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(t=t.concat(o))}),t.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}getPageCounterFormat(e){let t=this.pageCounterExprs.find(i=>i.expr===e);return t?t.format:null}getOrCreateNamedStringPageCounterExpr(e,t,i,n){for(let o in this.namedStringPageCounterExprMap){let s=this.namedStringPageCounterExprMap[o];if(s.offset===t&&s.counterName===i)return s.expr}let r=new we(e,()=>{let o=((t>=0?this.getPageCountersForOffset(t):null)||this.currentPageCounters)[i]||[];return n(o)},`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 o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute("data-viv-leader",e.key),o.setAttribute("data-viv-leader-value",t),o}else if(e.str.startsWith("running-element-")){let o=t&&i.querySelectorAll(`[${Ht}="${t}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(e.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(er,e.key),o}else if(e.str.startsWith("target-text-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(oa,e.key),o}else if(e.str.startsWith("named-string-page-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(ra,e.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===e)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=t,o.setAttribute(n?na:Qn,e.key),o}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Qn}]`);for(let r of t){let o=r.getAttribute(Qn),s=this.pageCounterExprs.find(c=>c.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=e.querySelectorAll(`[${er}]`);for(let r of i)r.setAttribute(Jh,!0);let n=e.querySelectorAll(`[${oa}]`);for(let r of n)r.setAttribute(Qh,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${na}]`),n=e.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(na),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${Jh}]`);for(let s of r){let a=s.getAttribute(er),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&&(s.textContent=h.format(c[c.length-1]))}}}let o=e.root.querySelectorAll(`[${Qh}]`);for(let s of o){let a=s.getAttribute(oa),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new ty(this,e)}},na="data-vivliostyle-pages-counter",Qn="data-vivliostyle-page-counter",ra="data-vivliostyle-named-string-page-counter",er="data-vivliostyle-target-counter",oa="data-vivliostyle-target-text",Jh="data-vivliostyle-target-counter-in-running",Qh="data-vivliostyle-target-text-in-running",ty=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}},iy=new Set(["before","after","first-line","first-letter"]),eu=new Set(["media","supports","-epubx-when"]),ud=new Set([";","}"]),cd=new Set(["{",";","}"]),ny=new Set([";","{","}"]),ry=":where(:scope)",oy=":where(:not(*))";function sy(e){let{statements:t,changed:i}=Ia(e,0,e.length,null);return i?t.join(`
5
- `):e}function Ia(e,t,i,n){let r=[],o=[],s=!1,a=t,h=()=>{o.length!==0&&(n?r.push(ay(n,o)):r.push(dd(o)),o.length=0)};for(;a<i&&(a=Qi(e,a,i),!(a>=i||e[a]==="}"));){if(e[a]==="@"){let d=xy(e,a,i);if(!d)break;if(n&&!eu.has(d.name)){o.push(Gi(e.slice(a,d.end))),a=d.end;continue}if(h(),d.hasBlock&&eu.has(d.name)){let p=Ia(e,d.blockStart,d.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${d.header} {${ly(p.statements)}}`)}else r.push(Gi(e.slice(a,d.end)));a=d.end;continue}if(n&&py(e,a,i)){let d=my(e,a,i);if(!d)break;o.push(Gi(d.text)),a=d.end;continue}h();let l=yy(e,a,i);if(!l){let d=Sy(e,a,i);r.push(Gi(d.text)),a=d.end;continue}if(n&&vy(e,a,l)){let d=by(e,a,l.end,i);o.push(Gi(d.text)),a=d.end;continue}let c=n?hy(n,l.prelude):pd(l.prelude);if(c){s||(s=n!=null);let d=Ia(e,l.blockStart,l.blockEnd,c);s||(s=d.changed),d.statements.length===0?r.push(`${c} {}`):r.push(...d.statements)}a=l.end}return h(),{statements:r,changed:s}}function ay(e,t){return`${e} { ${dd(t)} }`}function dd(e){return e.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function ly(e){return e.length===0?"":` ${e.join(" ")} `}function hy(e,t){let i=uy(e);if(!i)return null;let n=gd(t,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=fd(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function pd(e){return fd(e.trim(),ry).text}function uy(e){let t=gd(e,",").map(i=>i.trim()).filter(Boolean).filter(i=>!cy(i));return t.length===0?null:`:is(${t.join(", ")})`}function cy(e){let t=0;for(;t<e.length;){let i=Ls(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,o=Zr(e,r,e.length),s=e.slice(r,o).toLowerCase();if(iy.has(s))return!0;t=o;continue}t++}return!1}function fd(e,t){let i=0,n=!1,r="",o=[],s=dy(t);for(;i<e.length;){let a=Ls(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=Zr(e,c,e.length);if(d>c&&e[d]==="("){o.push(e.slice(c,d).toLowerCase()),r+=e.slice(i,d+1),i=d+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?oy:t,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function dy(e){let t=0;for(;t<e.length;){let i=Ls(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,o=Zr(e,r,e.length);if(o>r&&e.slice(r,o).toLowerCase()==="has"&&e[o]==="(")return!0;t=o;continue}t++}return!1}function gd(e,t){let i=[],n=0,r=0,o=0,s=0;for(;r<e.length;){let a=Ls(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"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===t&&(i.push(e.slice(n,r)),n=r+1);break}r++}return i.push(e.slice(n)),i}function py(e,t,i){let n=t,r=gy(e,n,i);if(r<=n)return!1;let o=Qi(e,r,i);if(o>=i||e[o]!==":")return!1;let s=Kr(e,o+1,i,ny);return s?.char==="{"?!fy(e,t,r,o,s.index):!0}function fy(e,t,i,n,r){if(Qi(e,i,r)!==n)return!1;let o=Qi(e,n+1,r);if(o!==n+1||o>=r)return!1;let s=e[o];return s===":"||s==="\\"||/[A-Za-z_-]/.test(s)}function gy(e,t,i){let n=t;return e[n]==="-"&&(n++,n<i&&e[n]==="-"&&n++),Zr(e,n,i)}function Zr(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 my(e,t,i){let n=Kr(e,t,i,ud);if(!n){let o=e.slice(t,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r).trim(),end:r}}function yy(e,t,i){let n=Kr(e,t,i,cd);if(!n||n.char!=="{")return null;let r=md(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 vy(e,t,i){if(!wy(e,t,i.blockStart-1))return!0;let n=Qi(e,i.blockStart,i.blockEnd);return n<i.blockEnd&&e[n]===";"}function wy(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 by(e,t,i,n){let r=Qi(e,i,n),o=r<n&&e[r]===";"?r+1:i;return{text:e.slice(t,o),end:o}}function xy(e,t,i){let n=Kr(e,t,i,cd);if(!n)return null;let r=Zr(e,t+1,i),o=e.slice(t+1,r).toLowerCase(),s=Gi(e.slice(t,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=md(e,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function Sy(e,t,i){let n=Kr(e,t,i,ud);if(!n)return{text:e.slice(t,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:e.slice(t,r),end:r}}function Kr(e,t,i,n){let r=t,o=0,s=0,a=0;for(;r<i;){let h=rn(e,r,i);if(h!=null){r=h;continue}let l=e[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function md(e,t,i){let n=t+1,r=1;for(;n<i;){let o=rn(e,n,i);if(o!=null){n=o;continue}let s=e[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function Qi(e,t,i){let n=t;for(;n<i;){let r=e[n];if(vd(r)){n++;continue}if(r==="/"&&e[n+1]==="*"){n=yd(e,n,i);continue}break}return n}function yd(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==="'"?Cy(e,t):n==="/"&&e[t+1]==="*"?yd(e,t,i):null}function Ls(e,t){return e[t]!=="\\"?null:t+1>=e.length?e.length:t+2}function Cy(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 vd(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 o=e[i];if(vd(o)){n=t.length>0,i++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,i++}return t}function ky(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,ky)}var Ey=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 ei=[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];ei[NaN]=80;var ti=[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];ti[NaN]=43;var Py=[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];ti[NaN]=43;var wd=[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];wd[NaN]=35;var bd=[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];bd[NaN]=45;var Fa=[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];Fa[NaN]=37;var Ra=[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];Ra[NaN]=38;var Mi=et(35,[61,36]),Ny=et(35,[58,77]),Ty=et(35,[61,36,124,50]),Ay=et(35,[38,51]),Iy=et(35,[42,54]),Fy=et(39,[42,55]),Ry=et(54,[42,55,47,56]),Ly=et(62,[62,82]),Oy=et(35,[61,36,33,70]),By=et(62,[45,71]),My=et(63,[45,81]),sa=et(76,[10,72,13,72]),_y=et(39,[39,46,10,72,13,72,92,48]),Dy=et(39,[34,46,10,72,13,72,92,49]),zy=et(39,[39,47,10,74,13,74,92,48]),Vy=et(39,[34,47,10,74,13,74,92,49]),tu=et(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Uy=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]),$y=et(39,[39,68,10,74,13,74,92,75,NaN,67]),Hy=et(39,[34,68,10,74,13,74,92,75,NaN,67]),Wy=et(72,[9,39,10,39,13,39,32,39,41,69]),Gy=15,xt=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=Gy,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Ey}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=ei,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",c=0,d=!1,p=s[e],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,o),a=0):n===ei&&a===0?(a=54,h=o,l=r.substring(o,o+1),o++):(l=r.substring(h,o),a=54),n=ei;break;case 1:o++,d=!0;continue;case 2:h=o++,n=Fa;continue;case 3:a=1,h=o++,n=ti;continue;case 4:h=o++,a=31,n=Mi;continue;case 33:a=2,h=++o,n=_y;continue;case 34:a=2,h=++o,n=Dy;continue;case 6:h=++o,a=7,n=ti;continue;case 7:h=o++,a=32,n=Mi;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=Ay;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Mi;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=wd;continue;case 16:h=o++,n=Py;continue;case 78:h=o++,a=9,n=ti;continue;case 17:h=o++,a=19,n=Iy;continue;case 18:h=o++,a=18,n=Ny;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=Oy;continue;case 21:h=o++,a=39,n=Mi;continue;case 22:h=o++,a=37,n=Mi;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=ti;continue;case 25:h=o++,a=14;break;case 26:h=o++,a=15;break;case 27:h=o++,a=12;break;case 28:h=o++,a=13;break;case 29:h=o++,f=h,a=1,n=sa;continue;case 30:h=o++,a=33,n=Mi;continue;case 31:h=o++,a=34,n=Ty;continue;case 32:h=o++,a=35,n=Mi;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,c=parseInt(r.substring(h,o),10);break;case 38:a=4,c=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,c=parseFloat(r.substring(h,o)),h=o++,n=ti;continue;case 41:a=3,c=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=Ra;continue;case 43:if(l=xi(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=sa;continue;case 45:l=xi(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=xi(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=zy;continue;case 49:f=o,o+=2,n=Vy;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=tu;continue}a=6}break;case 53:if(l=xi(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=tu;continue}a=6}break;case 54:n=Fy,o++;continue;case 55:n=Ry,o++;continue;case 56:n=ei,o++;continue;case 57:n=Ly,o++,r[o]!==">"&&(a=1,n=ti);continue;case 81:a=51,l=r.substring(h,++o),n=ei;break;case 82:a=52,l=r.substring(h,++o),n=ei;break;case 58:a=5,n=Fa,o++;continue;case 59:a=4,n=Ra,o++;continue;case 60:a=1,n=ti,o++;continue;case 61:a=1,n=sa,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=Uy;continue;case 65:h=++o,n=$y;continue;case 66:h=++o,n=Hy;continue;case 67:a=8,l=xi(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=By,o++;continue;case 71:n=My,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=xi(r.substring(h,o)),o++,n=Wy;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=ei;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=ti;continue}l=xi(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=bd;continue;default:if(n!==ei){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=d,p.num=c,p.text=l,p.position=h,e++,e>=t)break;n=ei,d=!1,a=0,h=o,l="",c=0,p=s[e&i]}this.position=o,this.tail=e&i}},Ye=null,La=null;function Oa(){return Ye}function M(e){if(!Ye)throw new Error("E_TASK_NO_CONTEXT");Ye.name||(Ye.name=e);let t=Ye,i=new Os(t,t.top,e);return t.top=i,i.state=1,i}function jy(e){return new Yy(e||new qy)}function T(e){return new Ba(e)}function _n(e,t,i){let n=M(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Xy(e,t){return(Ye?Ye.getScheduler():La||jy()).run(e,t)}var qy=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Yy=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 im,La||(La=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){Y.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Zy(this,t||"");i.top=new Os(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){Y.error(s)}};try{e().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=Ye;return Ye=i,this.schedule(i.top.suspend("bootstrap")),Ye=n,i}},xd=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}},Zy=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 xd(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=M("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&&Y.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}
1
+ var bm=Object.create;var So=Object.defineProperty;var xm=Object.getOwnPropertyDescriptor;var Sm=Object.getOwnPropertyNames;var Cm=Object.getPrototypeOf,km=Object.prototype.hasOwnProperty;var Pm=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(i){throw e=0,i}},Em=(t,e)=>{for(var i in e)So(t,i,{get:e[i],enumerable:!0})},Jh=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Sm(e))!km.call(t,r)&&r!==i&&So(t,r,{get:()=>e[r],enumerable:!(n=xm(e,r))||n.enumerable});return t};var Nm=(t,e,i)=>(i=t!=null?bm(Cm(t)):{},Jh(e||!t||!t.__esModule?So(i,"default",{value:t,enumerable:!0}):i,t)),Tm=t=>Jh(So({},"__esModule",{value:!0}),t);var gm=Pm((Mk,fm)=>{"use strict";var Im=Object.create,io=Object.defineProperty,Am=Object.getOwnPropertyDescriptor,Fm=Object.getOwnPropertyNames,Rm=Object.getPrototypeOf,Lm=Object.prototype.hasOwnProperty,Yc=t=>{throw TypeError(t)},Om=(t,e,i)=>e in t?io(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,Bm=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(i){throw e=0,i}},Mm=(t,e)=>{for(var i in e)io(t,i,{get:e[i],enumerable:!0})},Zc=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Fm(e))!Lm.call(t,r)&&r!==i&&io(t,r,{get:()=>e[r],enumerable:!(n=Am(e,r))||n.enumerable});return t},_m=(t,e,i)=>(i=t!=null?Im(Rm(t)):{},Zc(e||!t||!t.__esModule?io(i,"default",{value:t,enumerable:!0}):i,t)),Dm=t=>Zc(io({},"__esModule",{value:!0}),t),u=(t,e,i)=>Om(t,typeof e!="symbol"?e+"":e,i),jl=(t,e,i)=>e.has(t)||Yc("Cannot "+i),U=(t,e,i)=>(jl(t,e,"read from private field"),i?i.call(t):e.get(t)),ne=(t,e,i)=>e.has(t)?Yc("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),pe=(t,e,i,n)=>(jl(t,e,"write to private field"),n?n.call(t,i):e.set(t,i),i),le=(t,e,i)=>(jl(t,e,"access private method"),i),zm=Bm((t,e)=>{var i=-1,n=1,r=0;function o(P,M,A,H,z){if(P===M)return P?[[r,P]]:[];if(A!=null){var E=J(P,M,A);if(E)return E}var O=l(P,M),T=P.substring(0,O);P=P.substring(O),M=M.substring(O),O=d(P,M);var $=P.substring(P.length-O);P=P.substring(0,P.length-O),M=M.substring(0,M.length-O);var G=s(P,M);return T&&G.unshift([r,T]),$&&G.push([r,$]),y(G,z),H&&f(G),G}function s(P,M){var A;if(!P)return[[n,M]];if(!M)return[[i,P]];var H=P.length>M.length?P:M,z=P.length>M.length?M:P,E=H.indexOf(z);if(E!==-1)return A=[[n,H.substring(0,E)],[r,z],[n,H.substring(E+z.length)]],P.length>M.length&&(A[0][0]=A[2][0]=i),A;if(z.length===1)return[[i,P],[n,M]];var O=p(P,M);if(O){var T=O[0],$=O[1],G=O[2],q=O[3],Q=O[4],oe=o(T,G),se=o($,q);return oe.concat([[r,Q]],se)}return a(P,M)}function a(P,M){for(var A=P.length,H=M.length,z=Math.ceil((A+H)/2),E=z,O=2*z,T=new Array(O),$=new Array(O),G=0;G<O;G++)T[G]=-1,$[G]=-1;T[E+1]=0,$[E+1]=0;for(var q=A-H,Q=q%2!==0,oe=0,se=0,me=0,Me=0,ue=0;ue<z;ue++){for(var fe=-ue+oe;fe<=ue-se;fe+=2){var ke=E+fe,ye;fe===-ue||fe!==ue&&T[ke-1]<T[ke+1]?ye=T[ke+1]:ye=T[ke-1]+1;for(var Fe=ye-fe;ye<A&&Fe<H&&P.charAt(ye)===M.charAt(Fe);)ye++,Fe++;if(T[ke]=ye,ye>A)se+=2;else if(Fe>H)oe+=2;else if(Q){var _e=E+q-fe;if(_e>=0&&_e<O&&$[_e]!==-1){var Re=A-$[_e];if(ye>=Re)return h(P,M,ye,Fe)}}}for(var We=-ue+me;We<=ue-Me;We+=2){var _e=E+We,Re;We===-ue||We!==ue&&$[_e-1]<$[_e+1]?Re=$[_e+1]:Re=$[_e-1]+1;for(var gt=Re-We;Re<A&&gt<H&&P.charAt(A-Re-1)===M.charAt(H-gt-1);)Re++,gt++;if($[_e]=Re,Re>A)Me+=2;else if(gt>H)me+=2;else if(!Q){var ke=E+q-We;if(ke>=0&&ke<O&&T[ke]!==-1){var ye=T[ke],Fe=E+ye-ke;if(Re=A-Re,ye>=Re)return h(P,M,ye,Fe)}}}}return[[i,P],[n,M]]}function h(P,M,A,H){var z=P.substring(0,A),E=M.substring(0,H),O=P.substring(A),T=M.substring(H),$=o(z,E),G=o(O,T);return $.concat(G)}function l(P,M){if(!P||!M||P.charAt(0)!==M.charAt(0))return 0;for(var A=0,H=Math.min(P.length,M.length),z=H,E=0;A<z;)P.substring(E,z)==M.substring(E,z)?(A=z,E=A):H=z,z=Math.floor((H-A)/2+A);return k(P.charCodeAt(z-1))&&z--,z}function c(P,M){var A=P.length,H=M.length;if(A==0||H==0)return 0;A>H?P=P.substring(A-H):A<H&&(M=M.substring(0,A));var z=Math.min(A,H);if(P==M)return z;for(var E=0,O=1;;){var T=P.substring(z-O),$=M.indexOf(T);if($==-1)return E;O+=$,($==0||P.substring(z-O)==M.substring(0,O))&&(E=O,O++)}}function d(P,M){if(!P||!M||P.slice(-1)!==M.slice(-1))return 0;for(var A=0,H=Math.min(P.length,M.length),z=H,E=0;A<z;)P.substring(P.length-z,P.length-E)==M.substring(M.length-z,M.length-E)?(A=z,E=A):H=z,z=Math.floor((H-A)/2+A);return S(P.charCodeAt(P.length-z))&&z--,z}function p(P,M){var A=P.length>M.length?P:M,H=P.length>M.length?M:P;if(A.length<4||H.length*2<A.length)return null;function z(se,me,Me){for(var ue=se.substring(Me,Me+Math.floor(se.length/4)),fe=-1,ke="",ye,Fe,_e,Re;(fe=me.indexOf(ue,fe+1))!==-1;){var We=l(se.substring(Me),me.substring(fe)),gt=d(se.substring(0,Me),me.substring(0,fe));ke.length<gt+We&&(ke=me.substring(fe-gt,fe)+me.substring(fe,fe+We),ye=se.substring(0,Me-gt),Fe=se.substring(Me+We),_e=me.substring(0,fe-gt),Re=me.substring(fe+We))}return ke.length*2>=se.length?[ye,Fe,_e,Re,ke]:null}var E=z(A,H,Math.ceil(A.length/4)),O=z(A,H,Math.ceil(A.length/2)),T;if(!E&&!O)return null;O?E?T=E[4].length>O[4].length?E:O:T=O:T=E;var $,G,q,Q;P.length>M.length?($=T[0],G=T[1],q=T[2],Q=T[3]):(q=T[0],Q=T[1],$=T[2],G=T[3]);var oe=T[4];return[$,G,q,Q,oe]}function f(P){for(var M=!1,A=[],H=0,z=null,E=0,O=0,T=0,$=0,G=0;E<P.length;)P[E][0]==r?(A[H++]=E,O=$,T=G,$=0,G=0,z=P[E][1]):(P[E][0]==n?$+=P[E][1].length:G+=P[E][1].length,z&&z.length<=Math.max(O,T)&&z.length<=Math.max($,G)&&(P.splice(A[H-1],0,[i,z]),P[A[H-1]+1][0]=n,H--,H--,E=H>0?A[H-1]:-1,O=0,T=0,$=0,G=0,z=null,M=!0)),E++;for(M&&y(P),C(P),E=1;E<P.length;){if(P[E-1][0]==i&&P[E][0]==n){var q=P[E-1][1],Q=P[E][1],oe=c(q,Q),se=c(Q,q);oe>=se?(oe>=q.length/2||oe>=Q.length/2)&&(P.splice(E,0,[r,Q.substring(0,oe)]),P[E-1][1]=q.substring(0,q.length-oe),P[E+1][1]=Q.substring(oe),E++):(se>=q.length/2||se>=Q.length/2)&&(P.splice(E,0,[r,q.substring(0,se)]),P[E-1][0]=n,P[E-1][1]=Q.substring(0,Q.length-se),P[E+1][0]=i,P[E+1][1]=q.substring(se),E++),E++}E++}}var g=/[^a-zA-Z0-9]/,m=/\s/,v=/[\r\n]/,b=/\n\r?\n$/,x=/^\r?\n\r?\n/;function C(P){function M(se,me){if(!se||!me)return 6;var Me=se.charAt(se.length-1),ue=me.charAt(0),fe=Me.match(g),ke=ue.match(g),ye=fe&&Me.match(m),Fe=ke&&ue.match(m),_e=ye&&Me.match(v),Re=Fe&&ue.match(v),We=_e&&se.match(b),gt=Re&&me.match(x);return We||gt?5:_e||Re?4:fe&&!ye&&Fe?3:ye||Fe?2:fe||ke?1:0}for(var A=1;A<P.length-1;){if(P[A-1][0]==r&&P[A+1][0]==r){var H=P[A-1][1],z=P[A][1],E=P[A+1][1],O=d(H,z);if(O){var T=z.substring(z.length-O);H=H.substring(0,H.length-O),z=T+z.substring(0,z.length-O),E=T+E}for(var $=H,G=z,q=E,Q=M(H,z)+M(z,E);z.charAt(0)===E.charAt(0);){H+=z.charAt(0),z=z.substring(1)+E.charAt(0),E=E.substring(1);var oe=M(H,z)+M(z,E);oe>=Q&&(Q=oe,$=H,G=z,q=E)}P[A-1][1]!=$&&($?P[A-1][1]=$:(P.splice(A-1,1),A--),P[A][1]=G,q?P[A+1][1]=q:(P.splice(A+1,1),A--))}A++}}function y(P,M){P.push([r,""]);for(var A=0,H=0,z=0,E="",O="",T;A<P.length;){if(A<P.length-1&&!P[A][1]){P.splice(A,1);continue}switch(P[A][0]){case n:z++,O+=P[A][1],A++;break;case i:H++,E+=P[A][1],A++;break;case r:var $=A-z-H-1;if(M){if($>=0&&L(P[$][1])){var G=P[$][1].slice(-1);if(P[$][1]=P[$][1].slice(0,-1),E=G+E,O=G+O,!P[$][1]){P.splice($,1),A--;var q=$-1;P[q]&&P[q][0]===n&&(z++,O=P[q][1]+O,q--),P[q]&&P[q][0]===i&&(H++,E=P[q][1]+E,q--),$=q}}if(N(P[A][1])){var G=P[A][1].charAt(0);P[A][1]=P[A][1].slice(1),E+=G,O+=G}}if(A<P.length-1&&!P[A][1]){P.splice(A,1);break}if(E.length>0||O.length>0){E.length>0&&O.length>0&&(T=l(O,E),T!==0&&($>=0?P[$][1]+=O.substring(0,T):(P.splice(0,0,[r,O.substring(0,T)]),A++),O=O.substring(T),E=E.substring(T)),T=d(O,E),T!==0&&(P[A][1]=O.substring(O.length-T)+P[A][1],O=O.substring(0,O.length-T),E=E.substring(0,E.length-T)));var Q=z+H;E.length===0&&O.length===0?(P.splice(A-Q,Q),A=A-Q):E.length===0?(P.splice(A-Q,Q,[n,O]),A=A-Q+1):O.length===0?(P.splice(A-Q,Q,[i,E]),A=A-Q+1):(P.splice(A-Q,Q,[i,E],[n,O]),A=A-Q+2)}A!==0&&P[A-1][0]===r?(P[A-1][1]+=P[A][1],P.splice(A,1)):A++,z=0,H=0,E="",O="";break}}P[P.length-1][1]===""&&P.pop();var oe=!1;for(A=1;A<P.length-1;)P[A-1][0]===r&&P[A+1][0]===r&&(P[A][1].substring(P[A][1].length-P[A-1][1].length)===P[A-1][1]?(P[A][1]=P[A-1][1]+P[A][1].substring(0,P[A][1].length-P[A-1][1].length),P[A+1][1]=P[A-1][1]+P[A+1][1],P.splice(A-1,1),oe=!0):P[A][1].substring(0,P[A+1][1].length)==P[A+1][1]&&(P[A-1][1]+=P[A+1][1],P[A][1]=P[A][1].substring(P[A+1][1].length)+P[A+1][1],P.splice(A+1,1),oe=!0)),A++;oe&&y(P,M)}function k(P){return P>=55296&&P<=56319}function S(P){return P>=56320&&P<=57343}function N(P){return S(P.charCodeAt(0))}function L(P){return k(P.charCodeAt(P.length-1))}function I(P){for(var M=[],A=0;A<P.length;A++)P[A][1].length>0&&M.push(P[A]);return M}function D(P,M,A,H){return L(P)||N(H)?null:I([[r,P],[i,M],[n,A],[r,H]])}function J(P,M,A){var H=typeof A=="number"?{index:A,length:0}:A.oldRange,z=typeof A=="number"?null:A.newRange,E=P.length,O=M.length;if(H.length===0&&(z===null||z.length===0)){var T=H.index,$=P.slice(0,T),G=P.slice(T),q=z?z.index:null;e:{var Q=T+O-E;if(q!==null&&q!==Q||Q<0||Q>O)break e;var oe=M.slice(0,Q),se=M.slice(Q);if(se!==G)break e;var me=Math.min(T,Q),Me=$.slice(0,me),ue=oe.slice(0,me);if(Me!==ue)break e;var fe=$.slice(me),ke=oe.slice(me);return D(Me,fe,ke,G)}e:{if(q!==null&&q!==T)break e;var ye=T,oe=M.slice(0,ye),se=M.slice(ye);if(oe!==$)break e;var Fe=Math.min(E-ye,O-ye),_e=G.slice(G.length-Fe),Re=se.slice(se.length-Fe);if(_e!==Re)break e;var fe=G.slice(0,G.length-Fe),ke=se.slice(0,se.length-Fe);return D($,fe,ke,_e)}}if(H.length>0&&z&&z.length===0)e:{var Me=P.slice(0,H.index),_e=P.slice(H.index+H.length),me=Me.length,Fe=_e.length;if(O<me+Fe)break e;var ue=M.slice(0,me),Re=M.slice(O-Fe);if(Me!==ue||_e!==Re)break e;var fe=P.slice(me,E-Fe),ke=M.slice(me,O-Fe);return D(Me,fe,ke,_e)}return null}function te(P,M,A,H){return o(P,M,A,H,!0)}te.INSERT=n,te.DELETE=i,te.EQUAL=r,e.exports=te}),Kc={};Mm(Kc,{CoreViewer:()=>dm,HOOKS:()=>qs,Navigation:()=>pm,PageProgression:()=>Xl,PageSide:()=>ed,PageViewMode:()=>Pk,Profiler:()=>nd,ReadyState:()=>td,UserAgentBaseCss:()=>dp,UserAgentCounterStylesCss:()=>gp,UserAgentPageCss:()=>cp,UserAgentTocCss:()=>pp,UserAgentXml:()=>up,ValidationTxt:()=>hp,VivliostylePolyfillCss:()=>fp,VivliostyleViewportCss:()=>lp,VivliostyleViewportScreenCss:()=>ap,ZoomType:()=>kk,getHooksForName:()=>zt,isDebug:()=>Vr,pageProgressionOf:()=>Qc,plugin:()=>$m,printHTML:()=>Nk,profile:()=>Gm,profiler:()=>Nt,registerHook:()=>Ft,removeHook:()=>ql,setDebug:()=>Jc});fm.exports=Dm(Kc);var Vr=!1;function Jc(t){Vr=t}var Xl=(t=>(t.LTR="ltr",t.RTL="rtl",t))(Xl||{});function Qc(t){switch(t){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${t}`)}}var ed=(t=>(t.LEFT="left",t.RIGHT="right",t))(ed||{}),td=(t=>(t.LOADING="loading",t.INTERACTIVE="interactive",t.COMPLETE="complete",t))(td||{}),id=(t=>(t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t))(id||{}),Vm=class{constructor(t){u(this,"opt_console",t),u(this,"listeners",{})}consoleDebug(t){this.opt_console?this.opt_console.debug?this.opt_console.debug(...t):this.opt_console.log(...t):console.debug(...t)}consoleInfo(t){this.opt_console?this.opt_console.info?this.opt_console.info(...t):this.opt_console.log(...t):console.info(...t)}consoleWarn(t){this.opt_console?this.opt_console.warn?this.opt_console.warn(...t):this.opt_console.log(...t):console.warn(...t)}consoleError(t){this.opt_console?this.opt_console.error?this.opt_console.error(...t):this.opt_console.log(...t):console.error(...t)}triggerListeners(t,e){let i=this.listeners[t];i&&i(e)}addListener(t,e){this.listeners[t]=e}debug(...t){let e=Co(arguments);this.consoleDebug(ko(e)),this.triggerListeners(1,e)}info(...t){let e=Co(arguments);this.consoleInfo(ko(e)),this.triggerListeners(2,e)}warn(...t){let e=Co(arguments);this.consoleWarn(ko(e)),this.triggerListeners(3,e)}error(...t){let e=Co(arguments);this.consoleError(ko(e)),this.triggerListeners(4,e)}};function Co(t){let e=Array.from(t),i=null;return e[0]instanceof Error&&(i=e.shift()),{error:i,messages:e}}function ko(t){let e=t.error,i=e&&(e.frameTrace||e.stack),n=[].concat(t.messages);return e&&(n.length>0&&(n=n.concat([`
2
+ `])),n=n.concat([e.toString()]),i&&(n=n.concat([`
3
+ `]).concat(i))),n}var Y=new Vm,qs=(t=>(t.SIMPLE_PROPERTY="SIMPLE_PROPERTY",t.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",t.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",t.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",t.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",t.CONFIGURATION="CONFIGURATION",t.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",t.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",t.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",t.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",t.PAGINATION_PROGRESS="PAGINATION_PROGRESS",t))(qs||{}),ds={};function Ft(t,e,i){if(!qs[t])Y.warn(new Error(`Skipping unknown plugin hook '${t}'.`));else{let n=ds[t];n||(n=ds[t]=[]),i?n.unshift(e):n.push(e)}}function ql(t,e){if(!qs[t])Y.warn(new Error(`Ignoring unknown plugin hook '${t}'.`));else{let i=ds[t];if(i){let n=i.indexOf(e);n>=0&&i.splice(n,1)}}}function zt(t){return ds[t]||[]}var $m={registerHook:Ft,removeHook:ql},nd=class{constructor(t){u(this,"performanceInstance",t),u(this,"timestamps",{}),u(this,"registerTiming"),u(this,"registerStartTiming"),u(this,"registerEndTiming"),this.registerTiming=mn,this.registerStartTiming=this.registerStartTiming=mn,this.registerEndTiming=this.registerEndTiming=mn}forceRegisterStartTiming(t,e){ba.call(this,t,"start",e)}forceRegisterEndTiming(t,e){ba.call(this,t,"end",e)}printTimings(){let t=this.timestamps,e="";Object.keys(t).forEach(i=>{let n=t[i],r=n.length;for(let o=0;o<r;o++){let s=n[o];e+=i,r>1&&(e+=`(${o})`),e+=` => start: ${s.start}, end: ${s.end}, duration: ${s.end-s.start}
4
+ `}}),Y.info(e)}disable(){this.registerTiming=mn,this.registerStartTiming=this.registerStartTiming=mn,this.registerEndTiming=this.registerEndTiming=mn}enable(){this.registerTiming=ba,this.registerStartTiming=this.registerStartTiming=Qh,this.registerEndTiming=this.registerEndTiming=Hm}isEnabled(){return this.registerStartTiming===Qh}};function mn(){}function ba(t,e,i){i||(i=this.performanceInstance.now());let n=this.timestamps[t];n||(n=this.timestamps[t]=[]);let r,o=n.length;for(let s=o-1;s>=0&&(r=n[s],!(r&&!r[e]));s--)r=null;r||(r={},n.push(r)),r[e]=i}function Qh(t,e){this.registerTiming(t,"start",e)}function Hm(t,e){this.registerTiming(t,"end",e)}var Um={now:Date.now},Wm=window&&window.performance,Nt=new nd(Wm||Um);Nt.forceRegisterStartTiming("load_vivliostyle");var Gm={profiler:{registerStartTiming:Nt.registerStartTiming,registerEndTiming:Nt.registerEndTiming,printTimings:Nt.printTimings,disable:Nt.disable,enable:Nt.enable}},no=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",ps=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,jt="data-adapt-eloff",jm={};function Yl(t){return JSON.parse(t)}function ft(t){let e=t.match(/^([^#]*)/);return e?e[1]:t}function rd(t){let e=t.match(/^([^#?]*)/);return e?e[1]:t}var Zl="?viv-toc-box";function Ys(t){return t.endsWith(Zl)}function bn(t){return Ys(t)?t.slice(0,-Zl.length):t}function Ua(t){return Ys(t)?t:ft(t)+Zl}var an=window.location.href;function eu(t){an=t}var Ei=window.location.href;function tu(t){Ei=t}function Xm(t){let e=rd(t).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return e?e[1]:null}function $r(t){return t.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function Ie(t,e){if(/^data:/i.test(e))return t||e;if(!e||t.match(/^\w{2,}:/))return t.toLowerCase().match("^javascript:")?"#":(t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`),t);e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`);let i;if(t.match(/^\/\//))return i=e.match(/^(\w{2,}:)\/\//),i?i[1]+t:t;if(t.match(/^\//)){let s=Xm(e);return s?s+t:(i=e.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+t:t)}if(t.match(/^\.(\/|$)/)&&(t=t.substr(2)),e=rd(e),t.match(/^#/))return e+t;let n=e.lastIndexOf("/");if(n<0)return t;let r=e.substr(0,n+1)+t,o="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],o=i[2]);n=r.indexOf("/../"),!(n<=0);){let s=r.lastIndexOf("/",n-1);if(s<=0)break;r=r.substr(0,s)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function fs(t,e){return t.match(/^#/)&&e?ft(e)+t:Ie(t,e)}function od(t){return/^about:blank($|[?#])/i.test(t)?"data:text/html,":t}function _n(t){let e;return(t=od(t))!==t||((e=/^(https?:)\/\/github\.com\/web-platform-tests\/wpt\/(blob\/|tree\/|raw\/)?(.*)$/.exec(t))?t=`${e[1]}//raw.githack.com/web-platform-tests/wpt/${e[2]?"":"master/"}${e[3]}`:(e=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(t))?t=`${e[1]}//raw.githubusercontent.com/${e[2]}/${e[3]?"":"master/"}${e[4]}`:(e=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(t))?/\.sub\.[^/]+(?:[?#].*)?$/.test(e[2])||(t=`${e[1]}//raw.githack.com/web-platform-tests/wpt/master/${e[2]}`):(e=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(t))?t=`${e[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${e[2]}`:(e=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(t))?t=`${e[1]}//gist.githubusercontent.com/${e[2]}/raw/${e[6]}`:(e=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(t))?t=`${e[1]}//gist.githubusercontent.com/${e[2]}/raw/${e[3]}.${e[4]}`:(e=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(t))&&(t=`${e[1]}//output.jsbin.com/${e[2]}${e[3]}/`)),t}function iu(t){return t==null?t:t.toString()}var qm=class{constructor(){u(this,"queue",[null])}length(){return this.queue.length-1}add(t){let e=this.queue.length;for(;e>1;){let i=Math.floor(e/2),n=this.queue[i];if(n.compare(t)>0){this.queue[e]=t;return}this.queue[e]=n,e=i}this.queue[1]=t}peek(){return this.queue[1]}remove(){let t=this.queue[1],e=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(e)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(e)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=e}return t}},sd=["","-webkit-","-moz-"],xn={};function Xo(t,e){return CSS.supports(t+e,"unset")}function Ym(t){let e=xn[t];if(e||e===null)return e;switch(t){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return xn[t]=null,null;case"text-combine-upright":if(Xo("-webkit-","text-combine")&&!Xo("","text-combine-upright"))return xn[t]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of sd)if(Xo(i,t))return e=[i+t],xn[t]=e,e;return Y.warn("Property not supported by the browser: ",t),xn[t]=null,null}function R(t,e,i){let n=t?.style;if(!n)return;if(e.startsWith("--")){n.setProperty(e,i||" ");return}let r=Ym(e);if(r)for(let o of r){switch(o){case"-webkit-text-combine":i==="all"&&(i="horizontal");break;case"text-combine-upright":i==="all"&&n.setProperty("text-indent","0");break}n.setProperty(o,i)}}function Ni(t,e,i){try{let n=xn[e];return t.style.getPropertyValue(n?n[0]:e)}catch{}return i||""}function Zm(t){return t.documentElement}function Wa(t){return t.nextElementSibling}function nu(t){return t.previousElementSibling}var Km=class Ga{constructor(e,i){u(this,"root",e),u(this,"node",i)}static atRoot(e){return new Ga(e,e)}moveTo(e){return e===null?null:new Ga(this.root,e)}get firstChild(){return this.moveTo(this.node.firstChild)}get nextSibling(){return this.moveTo(this.node.nextSibling)}get parent(){if(this.node===this.root)return null;let e=this.node.parentNode;return e===this.root||e===this.root.parentNode?null:this.moveTo(e)}};function ja(t){let e=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!e&&t.namespaceURI=="http://www.w3.org/1999/xhtml"&&(e=t.getAttribute("lang")),e}var mi=class{constructor(){u(this,"list",[])}append(t){return this.list.push(t),this}clear(){this.list=[]}toString(){let t=this.list.join("");return this.list=[t],t}};function Kl(t){return`\\${t.charCodeAt(0).toString(16)} `}function Fi(t){return t.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Kl)}function ro(t){return t.replace(/[\u0000-\u001F"\\]/g,Kl)}function ru(t){return t.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function ou(t){return!!t.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Jm(t,e){return e=typeof e=="string"?e:"\\u",e+(65536|t.charCodeAt(0)).toString(16).substr(1)}function ad(t,e){function i(n){return Jm(n,e)}return t.replace(/[^-a-zA-Z0-9_]/g,i)}function gs(t){return ad(t)}function Qm(t,e){return e=typeof e=="string"?e:"\\u",t.indexOf(e)===0?String.fromCharCode(parseInt(t.substring(e.length),16)):t}function ey(t,e){e=typeof e=="string"?e:"\\u";function i(r){return Qm(r,e)}let n=new RegExp(`${gs(e)}[0-9a-fA-F]{4}`,"g");return t.replace(n,i)}function yi(t,e){let i=0,n=t;for(;;){if(i<=n,i==0||e(i-1),n==t||e(n),i==n)return i;let r=i+n>>1;e(r)?n=r:i=r+1}}function ld(t,e){return t-e}function su(t,e){let i={};for(let n of t){let r=e(n);r&&!i[r]&&(i[r]=n)}return i}function ty(t){let e={};for(let i=0;i<t.length;i++)e[t[i]]=!0;return e}function xa(t,e){let i={};for(let n of t){let r=e(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function iy(t,e){let i={};for(let n in t)i[n]=e(t[n],n);return i}var Jl=class{constructor(){u(this,"listeners",{})}dispatchEvent(t){let e=this.listeners[t.type];if(e){t.target=this,t.currentTarget=this;for(let i=0;i<e.length;i++)e[i](t)}}addEventListener(t,e,i){if(i)return;let n=this.listeners[t];n?n.includes(e)||n.push(e):this.listeners[t]=[e]}removeEventListener(t,e,i){if(i)return;let n=this.listeners[t];if(n){let r=n.indexOf(e);r>=0&&n.splice(r,1)}}},tn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function hd(){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 ud(t){return{fontFamily:t.fontFamily,lineHeight:t.lineHeight,margin:t.margin,hyphenate:t.hyphenate,columnWidth:t.columnWidth,horizontal:t.horizontal,nightMode:t.nightMode,spreadView:t.spreadView,pageBorder:t.pageBorder,enabledMediaTypes:Object.assign({},t.enabledMediaTypes),defaultPaperSize:t.defaultPaperSize?Object.assign({},t.defaultPaperSize):void 0}}var Ql=hd(),au={PENDING:{}};function cd(t,e,i,n){let r=Math.min((t-0)/i,(e-0)/n);return`matrix(${r},0,0,${r},0,0)`}function ny(t){return`"${ro(`${t}`)}"`}function ry(t){return Fi(`${t}`)}function Xa(t,e){return t?`${Fi(t)}.${Fi(e)}`:Fi(e)}var dd=0,qa=class{constructor(t,e){if(u(this,"parent",t),u(this,"resolver",e),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${dd++}`,this.zero=new it(this,0),this.one=new it(this,1),this._true=new it(this,!0),this._false=new it(this,!1),t&&t.children.push(this),!t){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=cd,i["css-string"]=ny,i["css-name"]=ry,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(t,e){this.values[t]=new be(this,e,t)}defineName(t,e){this.values[t]=e}defineFunc(t,e){this.funcs[t]=e}defineBuiltIn(t,e){this.builtIns[t]=e}};function oy(t){switch(t?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function pd(t){switch(t?.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 sy(t){switch(t?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function ay(t){switch(t?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var vi={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 fd(t){switch(t){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 Ya=class{constructor(t,e,i,n,r){u(this,"rootScope",t),u(this,"viewportWidth",e),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"),u(this,"isRootLineHeightFromRelativeCalc",!1),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(e/2)-this.pref.pageBorder:e},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.rootLineHeight=r,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=Ql}getScopeContext(t){let e=this.scopes[t.scopeKey];return e||(e={},this.scopes[t.scopeKey]=e),e}clearScope(t){this.scopes[t.scopeKey]={};for(let e=0;e<t.children.length;e++)this.clearScope(t.children[e])}queryUnitSize(t,e,i){if(pd(t)){let n=this.pageWidth()/100,r=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,s=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(t){case"vw":return o;case"vh":return s;case"vi":return a?s:o;case"vb":return a?o:s;case"vmin":return o<s?o:s;case"vmax":return o>s?o:s;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return t=="em"||t=="rem"?e?this.initialFontSize:this.fontSize():t=="lh"||t=="rlh"?this.rootLineHeight:vi[t]}evalName(t,e){let i=t;for(;i;){let n=i.values[e];if(n||i.resolver&&(n=i.resolver.call(this,e,!1),n))return n;i=i.parent}throw new Error(`Name '${e}' is undefined`)}evalCall(t,e,i,n){let r=t;for(;r;){let o=r.funcs[e];if(o||r.resolver&&(o=r.resolver.call(this,e,!0),o))return o;let s=r.builtIns[e];if(s){if(n)return r.zero;let a=Array(i.length);for(let h=0;h<i.length;h++)a[h]=i[h].evaluate(this);return new it(r,s.apply(this,a))}r=r.parent}throw new Error(`Function '${e}' is undefined`)}evalMediaName(t,e){let i=t==="all"||!!this.pref.enabledMediaTypes[t];return e?!i:i}evalMediaTest(t,e){let i="",n=t.match(/^(min|max)-(.*)$/);n&&(i=n[1],t=n[2]);let r=null,o=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(r=e.evaluate(this));break}switch(t){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&r!=null)switch(i){case"min":return o>=Number(r);case"max":return o<=Number(r);default:return o==r}else if(o!=null&&e==null)return o!==0;return!1}evalSupportsTest(t,e,i){return!1}queryVal(t,e){let i=this.scopes[t.scopeKey];return i?i[e]:void 0}storeVal(t,e,i){this.getScopeContext(t)[e]=i}},Kt=class{constructor(t){u(this,"scope",t),u(this,"key"),this.key=`_${dd++}`}toString(){let t=new mi;return this.appendTo(t,0),t.toString()}expand(t,e){return this}dependCore(t,e,i){return t===this}dependOuter(t,e,i){let n=i[this.key];if(n!=null)return n===au.PENDING?!1:n;{i[this.key]=au.PENDING;let r=this.dependCore(t,e,i);return i[this.key]=r,r}}depend(t,e){return this.dependOuter(t,e,{})}evaluate(t){let e=t.queryVal(this.scope,this.key);return typeof e<"u"||(e=this.evaluateCore(t),t.storeVal(this.scope,this.key,e)),e}isMediaName(){return!1}},gd=class extends Kt{constructor(t,e){super(t),u(this,"val",e)}evaluateCore(t){let e=this.val.evaluate(t);return this.evalPrefix(e)}dependCore(t,e,i){return t===this||this.val.dependOuter(t,e,i)}appendTo(t,e){10<e&&t.append("("),t.append(this.getOp()),this.val.appendTo(t,10),10<e&&t.append(")")}expand(t,e){let i=this.val.expand(t,e);return i===this.val?this:new this.constructor(this.scope,i)}},md=class extends Kt{constructor(t,e,i){super(t),u(this,"lhs",e),u(this,"rhs",i)}dependCore(t,e,i){return t===this||this.lhs.dependOuter(t,e,i)||this.rhs.dependOuter(t,e,i)}appendTo(t,e){let i=this.getPriority();i<=e&&t.append("("),this.lhs.appendTo(t,i),t.append(this.getOp()),this.rhs.appendTo(t,i),i<=e&&t.append(")")}expand(t,e){let i=this.lhs.expand(t,e),n=this.rhs.expand(t,e);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},eh=class extends md{evaluateCore(t){let e=this.lhs.evaluate(t),i=this.rhs.evaluate(t);return this.evalInfix(e,i)}},yd=class extends md{constructor(t,e,i){super(t,e,i)}getPriority(){return 1}},Zn=class extends eh{constructor(t,e,i){super(t,e,i)}getPriority(){return 2}},vd=class extends eh{constructor(t,e,i){super(t,e,i)}getPriority(){return 3}},th=class extends eh{constructor(t,e,i){super(t,e,i)}getPriority(){return 4}},Ri=class extends gd{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},ly=class extends Ri{constructor(t,e){super(t,e)}getOp(){return"not "}},In=class extends gd{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},ih=class extends yd{constructor(t,e,i){super(t,e,i)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},hy=class extends ih{constructor(t,e,i){super(t,e,i)}getOp(){return" and "}},nh=class extends yd{constructor(t,e,i){super(t,e,i)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},uy=class extends nh{constructor(t,e,i){super(t,e,i)}getOp(){return", "}},cy=class extends nh{constructor(t,e,i){super(t,e,i)}getOp(){return" or "}},dy=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return"<"}evalInfix(t,e){return t<e}},py=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return"<="}evalInfix(t,e){return t<=e}},fy=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return">"}evalInfix(t,e){return t>e}},Za=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return">="}evalInfix(t,e){return t>=e}},rh=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return"=="}evalInfix(t,e){return t==e}},gy=class extends Zn{constructor(t,e,i){super(t,e,i)}getOp(){return"!="}evalInfix(t,e){return t!=e}},wd=class extends vd{constructor(t,e,i){super(t,e,i)}getOp(){return"+"}evalInfix(t,e){return t+e}},bd=class extends vd{constructor(t,e,i){super(t,e,i)}getOp(){return" - "}evalInfix(t,e){return t-e}},oh=class extends th{constructor(t,e,i){super(t,e,i)}getOp(){return"*"}evalInfix(t,e){return t*e}},xd=class extends th{constructor(t,e,i){super(t,e,i)}getOp(){return"/"}evalInfix(t,e){return t/e}},Sd=class extends th{constructor(t,e,i){super(t,e,i)}getOp(){return"%"}evalInfix(t,e){return t%e}},oo=class extends Kt{constructor(t,e,i){var n;super(t),u(this,"num",e),u(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(t,e){t.append(this.num.toString()),t.append(Fi(this.unit))}evaluateCore(t){return this.num*t.queryUnitSize(this.unit,!1)}},Qe=class extends Kt{constructor(t,e){super(t),u(this,"qualifiedName",e)}appendTo(t,e){t.append(this.qualifiedName)}evaluateCore(t){return t.evalName(this.scope,this.qualifiedName).evaluate(t)}dependCore(t,e,i){return t===this||e.evalName(this.scope,this.qualifiedName).dependOuter(t,e,i)}},lu=class extends Kt{constructor(t,e,i){super(t),u(this,"not",e),u(this,"name",i)}appendTo(t,e){this.not&&t.append("not "),t.append(Fi(this.name))}evaluateCore(t){return t.evalMediaName(this.name,this.not)}isMediaName(){return!0}},be=class extends Kt{constructor(t,e,i){super(t),u(this,"fn",e),u(this,"str",i)}appendTo(t,e){t.append(this.str)}evaluateCore(t){return this.fn.call(t)}};function my(t,e){t.append("(");for(let i=0;i<e.length;i++)i&&t.append(","),e[i].appendTo(t,0);t.append(")")}function yy(t,e,i){let n=e;for(let r=0;r<e.length;r++){let o=e[r].expand(t,i);if(e!==n)n[r]=o;else if(o!==e[r]){n=Array(e.length);for(let s=0;s<r;s++)n[s]=e[s];n[r]=o}}return n}var Er=class Cd extends Kt{constructor(e,i,n){super(e),u(this,"qualifiedName",i),u(this,"params",n)}appendTo(e,i){e.append(this.qualifiedName),my(e,this.params)}evaluateCore(e){return e.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(e,this.params).evaluate(e)}dependCore(e,i,n){if(e===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(e,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(e,i,n)}expand(e,i){let n=yy(e,this.params,i);return n===this.params?this:new Cd(this.scope,this.qualifiedName,n)}},vy=class kd extends Kt{constructor(e,i,n,r){super(e),u(this,"cond",i),u(this,"ifTrue",n),u(this,"ifFalse",r)}appendTo(e,i){i>0&&e.append("("),this.cond.appendTo(e,0),e.append("?"),this.ifTrue.appendTo(e,0),e.append(":"),this.ifFalse.appendTo(e,0),i>0&&e.append(")")}evaluateCore(e){return this.cond.evaluate(e)?this.ifTrue.evaluate(e):this.ifFalse.evaluate(e)}dependCore(e,i,n){return e===this||this.cond.dependOuter(e,i,n)||this.ifTrue.dependOuter(e,i,n)||this.ifFalse.dependOuter(e,i,n)}expand(e,i){let n=this.cond.expand(e,i),r=this.ifTrue.expand(e,i),o=this.ifFalse.expand(e,i);return n===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new kd(this.scope,n,r,o)}},it=class extends Kt{constructor(t,e){super(t),u(this,"val",e)}appendTo(t,e){switch(typeof this.val){case"number":case"boolean":t.append(this.val.toString());break;case"string":t.append('"'),t.append(ro(this.val)),t.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(t){return this.val}},hu=class Pd extends Kt{constructor(e,i,n){super(e),u(this,"name",i),u(this,"value",n)}appendTo(e,i){e.append("("),e.append(ro(this.name.name)),e.append(":"),this.value.appendTo(e,0),e.append(")")}evaluateCore(e){return e.evalMediaTest(this.name.name,this.value)}dependCore(e,i,n){return e===this||this.value.dependOuter(e,i,n)}expand(e,i){let n=this.value.expand(e,i);return n===this.value?this:new Pd(this.scope,this.name,n)}},wy=class extends Kt{constructor(t,e,i,n){super(t),u(this,"name",e),u(this,"value",i),u(this,"isFunc",n)}appendTo(t,e){this.isFunc&&t.append(this.name),t.append("("),!this.isFunc&&this.name&&(t.append(this.name),t.append(":")),t.append(this.value),t.append(")")}evaluateCore(t){return t.evalSupportsTest(this.name,this.value,this.isFunc)}},Ed=class extends Kt{constructor(t,e){super(t),u(this,"index",e)}appendTo(t,e){t.append("$"),t.append(this.index.toString())}evaluateCore(t){throw new Error(`Parameter not expanded: ${this.index}`)}expand(t,e){let i=e[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function Xt(t,e,i){return e===t._false||e===t.zero||i==t._false||i==t.zero?t._false:e===t._true||e===t.one?i:i===t._true||i===t.one?e:new ih(t,e,i)}function re(t,e,i){return e===t.zero?i:i===t.zero?e:new wd(t,e,i)}function we(t,e,i){return e===t.zero?new In(t,i):i===t.zero?e:new bd(t,e,i)}function qo(t,e,i){return e===t.zero||i===t.zero?t.zero:e===t.one?i:i===t.one?e:new oh(t,e,i)}function Ka(t,e,i){return e===t.zero?t.zero:i===t.one?e:new xd(t,e,i)}var Zt=class{visitValues(t){for(let e=0;e<t.length;e++)t[e].visit(this);return null}visitEmpty(t){return null}visitSlash(t){return null}visitStr(t){return null}visitIdent(t){return null}visitNumeric(t){return null}visitNum(t){return null}visitInt(t){return this.visitNum(t)}visitHexColor(t){return null}visitURL(t){return null}visitURange(t){return null}visitSpaceList(t){return this.visitValues(t.values),null}visitCommaList(t){return this.visitValues(t.values),null}visitFunc(t){return this.visitValues(t.values),null}visitExpr(t){return null}},dn=class extends Zt{constructor(){super(),u(this,"error",!1)}visitValues(t){let e=null;for(let i=0;i<t.length;i++){let n=t[i],r=n.visit(this);if(this.error)return[];if(e)e[i]=r;else if(n!==r){e=new Array(t.length);for(let o=0;o<i;o++)e[o]=t[o];e[i]=r}}return e||t}visitEmpty(t){return t}visitStr(t){return t}visitIdent(t){return t}visitSlash(t){return t}visitNumeric(t){return t}visitNum(t){return t}visitInt(t){return t}visitHexColor(t){return t}visitURL(t){return t}visitURange(t){return t}visitSpaceList(t){let e=this.visitValues(t.values);return this.error?Ae:e===t.values?t:new ee(e)}visitCommaList(t){let e=this.visitValues(t.values);return this.error?Ae:e===t.values?t:new Be(e)}visitFunc(t){let e=this.visitValues(t.values);return this.error?Ae:e===t.values?t:new Vt(t.name,e)}visitExpr(t){return t}},ot=class{toString(){let t=new mi;return this.appendTo(t,!0),t.toString()}stringValue(){let t=new mi;return this.appendTo(t,!1),t.toString()}toExpr(t,e){return null}appendTo(t,e){t.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(t){return this}},Nd=class Td extends ot{static get instance(){return this.empty||(this.empty=new Td),this.empty}constructor(){super()}toExpr(e,i){return new it(e,"")}appendTo(e,i){}visit(e){return e.visitEmpty(this)}};u(Nd,"empty");var by=Nd,Ae=by.instance,Id=class Ad extends ot{static get instance(){return this.slash||(this.slash=new Ad),this.slash}constructor(){super()}toExpr(e,i){return new it(e,"/")}appendTo(e,i){e.append("/")}visit(e){return e.visitSlash(this)}};u(Id,"slash");var xy=Id,Kn=xy.instance,K=class extends ot{constructor(t){super(),u(this,"str",t)}toExpr(t,e){return new it(t,this.str)}appendTo(t,e){e?(t.append('"'),t.append(ro(this.str)),t.append('"')):t.append(this.str)}visit(t){return t.visitStr(this)}},Ja=Object.create(null),he=class extends ot{constructor(t){if(super(),u(this,"name",t),Ja[t])throw new Error("E_INVALID_CALL");Ja[t]=this}toExpr(t,e){return new it(t,this.name)}appendTo(t,e){e?t.append(Fi(this.name)):t.append(this.name)}visit(t){return t.visitIdent(this)}isIdent(){return!0}};function _(t){let e=Ja[t];return e||(e=new he(t)),e}var B=class extends ot{constructor(t,e){var i;super(),u(this,"num",t),u(this,"unit"),this.unit=(i=e?.toLowerCase())!=null?i:""}toExpr(t,e){return this.num==0?t.zero:e&&this.unit=="%"?this.num==100?e:new oh(t,e,new it(t,this.num/100)):new oo(t,this.num,this.unit)}appendTo(t,e){t.append(this.num.toString()),t.append(this.unit)}visit(t){return t.visitNumeric(this)}isNumeric(){return!0}},It=class extends ot{constructor(t){super(),u(this,"num",t)}toExpr(t,e){return this.num==0?t.zero:this.num==1?t.one:new it(t,this.num)}appendTo(t,e){t.append(this.num.toString())}visit(t){return t.visitNum(this)}isNum(){return!0}},ht=class extends It{constructor(t){super(t)}visit(t){return t.visitInt(this)}},Fd=class extends ot{constructor(t){super(),u(this,"hex",t)}appendTo(t,e){t.append("#"),t.append(this.hex)}visit(t){return t.visitHexColor(this)}},et=class extends ot{constructor(t){super(),u(this,"url",t)}appendTo(t,e){t.append('url("'),t.append(ro(this.url)),t.append('")')}visit(t){return t.visitURL(this)}},Rd=class extends ot{constructor(t){super(),u(this,"urangeText",t)}appendTo(t,e){t.append(this.urangeText)}visit(t){return t.visitURange(this)}};function sh(t,e,i,n){var r,o;let s=e.length;if(s>0){(r=e[0])==null||r.appendTo(t,n);for(let a=1;a<s;a++)t.append(i),(o=e[a])==null||o.appendTo(t,n)}}var ee=class extends ot{constructor(t){super(),u(this,"values",t)}appendTo(t,e){sh(t,this.values," ",e)}visit(t){return t.visitSpaceList(this)}isSpaceList(){return!0}},Be=class extends ot{constructor(t){super(),u(this,"values",t)}appendTo(t,e){sh(t,this.values,",",e)}visit(t){return t.visitCommaList(this)}},Vt=class extends ot{constructor(t,e){super(),u(this,"name",t),u(this,"values",e)}appendTo(t,e){t.append(Fi(this.name)),t.append("("),sh(t,this.values,",",e),t.append(")")}visit(t){return t.visitFunc(this)}},j=class extends ot{constructor(t){super(),u(this,"expr",t)}toExpr(){return this.expr}appendTo(t,e){this.expr instanceof it||this.expr instanceof oo?this.expr.appendTo(t,0):(t.append("-epubx-expr("),this.expr.appendTo(t,0),t.append(")"))}visit(t){return t.visitExpr(this)}isExpr(){return!0}},Sn=class extends ot{constructor(t){super(),u(this,"text",t)}appendTo(t,e){t.append(this.text||" ")}};function ct(t,e){if(t){if(t.isNumeric()){let i=t;return e.queryUnitSize(i.unit,!1)*i.num}if(t.isNum())return t.num}return 0}function Ld(t,e){return new B(ct(t,e),"px")}var w={absolute:_("absolute"),all:_("all"),always:_("always"),anywhere:_("anywhere"),auto:_("auto"),avoid:_("avoid"),balance:_("balance"),balance_all:_("balance-all"),block:_("block"),block_end:_("block-end"),block_start:_("block-start"),both:_("both"),bottom:_("bottom"),border_box:_("border-box"),break_all:_("break-all"),break_word:_("break-word"),clip:_("clip"),crop:_("crop"),cross:_("cross"),column:_("column"),discard:_("discard"),exclusive:_("exclusive"),_false:_("false"),fixed:_("fixed"),flex:_("flex"),flow_root:_("flow-root"),footnote:_("footnote"),footer:_("footer"),grid:_("grid"),header:_("header"),hidden:_("hidden"),horizontal_tb:_("horizontal-tb"),inherit:_("inherit"),initial:_("initial"),inline:_("inline"),inline_block:_("inline-block"),inline_end:_("inline-end"),inline_start:_("inline-start"),inside:_("inside"),keep:_("keep"),landscape:_("landscape"),left:_("left"),line:_("line"),list_item:_("list-item"),ltr:_("ltr"),manual:_("manual"),max_content:_("max-content"),min_content:_("min-content"),none:_("none"),normal:_("normal"),oeb_page_foot:_("oeb-page-foot"),oeb_page_head:_("oeb-page-head"),outside:_("outside"),padding_box:_("padding-box"),page:_("page"),relative:_("relative"),revert:_("revert"),revert_layer:_("revert-layer"),revert_rule:_("revert-rule"),right:_("right"),same:_("same"),scale:_("scale"),snap_block:_("snap-block"),snap_inline:_("snap-inline"),solid:_("solid"),spread:_("spread"),_static:_("static"),rtl:_("rtl"),table:_("table"),table_caption:_("table-caption"),table_cell:_("table-cell"),table_footer_group:_("table-footer-group"),table_header_group:_("table-header-group"),table_row:_("table-row"),top:_("top"),transparent:_("transparent"),unset:_("unset"),vertical_lr:_("vertical-lr"),vertical_rl:_("vertical-rl"),visible:_("visible"),_true:_("true")},uu=new B(100,"%"),so=new B(100,"pvw"),ao=new B(100,"pvh"),Oe=new B(0,"px"),Ak=new Rd("U+0-10FFFF"),cu={"font-size":1,"line-height":2,color:3};function Z(t){return t===w.inherit||t===w.initial||t===w.unset||Rt(t)}function Rt(t){return t===w.revert||t===w.revert_layer||t===w.revert_rule}var Sy=class extends Zt{constructor(){super(...arguments),u(this,"found",!1)}visitIdent(t){return Rt(t)&&(this.found=!0),null}};function Cy(t){let e=new Sy;return t.visit(e),e.found}function du(t,e){let i=cu[t]||Number.MAX_VALUE,n=cu[e]||Number.MAX_VALUE;return i-n}function ze(t){return t!=null&&t.length>2&&t.startsWith("--")}var Cn,kn,Pn,Od=class hi{constructor(e,i,n){ne(this,Cn),ne(this,kn),ne(this,Pn),pe(this,Cn,Math.round(Math.max(0,Math.min(e,hi.MAX)))),pe(this,kn,Math.round(Math.max(0,Math.min(i,hi.MAX)))),pe(this,Pn,Math.round(Math.max(0,Math.min(n,hi.MAX))))}static fromInt(e,i,n){return new hi(e,i,n)}offset(e,i,n){return new hi(U(this,Cn)+e,U(this,kn)+i,U(this,Pn)+n)}toKey(){return JSON.stringify([U(this,Cn),U(this,kn),U(this,Pn)])}toColorFunc(e){return new Vt("color",[new ee([_("srgb"),new It(U(this,Cn)/hi.MAX),new It(U(this,kn)/hi.MAX),new It(U(this,Pn)/hi.MAX),...e!==null?[Kn,new It(e)]:[]])])}};Cn=new WeakMap,kn=new WeakMap,Pn=new WeakMap,u(Od,"MAX",1e4);var ci=Od;function ky(t){return Array.isArray(t)?t.every(e=>{if(!Array.isArray(e)||e.length!==2)return!1;let[i,n]=e;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,o=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var ji,Xi,qi,ti,Bd=class yt{constructor(e,i,n,r){ne(this,ji),ne(this,Xi),ne(this,qi),ne(this,ti),pe(this,ji,Math.round(Math.max(0,Math.min(e,yt.MAX)))),pe(this,Xi,Math.round(Math.max(0,Math.min(i,yt.MAX)))),pe(this,qi,Math.round(Math.max(0,Math.min(n,yt.MAX)))),pe(this,ti,Math.round(Math.max(0,Math.min(r,yt.MAX))))}static fromInt(e,i,n,r){return new yt(e,i,n,r)}static fromNumber(e,i,n,r){return new yt(e*yt.MAX,i*yt.MAX,n*yt.MAX,r*yt.MAX)}toSRGB(){let e=yt.MAX-U(this,ti);return ci.fromInt(ci.MAX-Math.min(ci.MAX,Math.round(U(this,ji)*e/yt.MAX)+U(this,ti)),ci.MAX-Math.min(ci.MAX,Math.round(U(this,Xi)*e/yt.MAX)+U(this,ti)),ci.MAX-Math.min(ci.MAX,Math.round(U(this,qi)*e/yt.MAX)+U(this,ti)))}equals(e){return U(this,ji)===U(e,ji)&&U(this,Xi)===U(e,Xi)&&U(this,qi)===U(e,qi)&&U(this,ti)===U(e,ti)}toJSON(){return{c:U(this,ji),m:U(this,Xi),y:U(this,qi),k:U(this,ti)}}};ji=new WeakMap,Xi=new WeakMap,qi=new WeakMap,ti=new WeakMap,u(Bd,"MAX",1e4);var Md=Bd;function yn(t){return t instanceof It?Math.max(0,Math.min(1,t.num)):t instanceof B&&t.unit==="%"?Math.max(0,Math.min(1,t.num/100)):null}function _d(t){if(t.name!=="device-cmyk"&&t.name!=="cmyk")return null;let e=t.values.length===1?t.values[0]:null,i=e instanceof ee?e.values:t.values;if(i.length<4||i.length>6)return null;let n=yn(i[0]),r=yn(i[1]),o=yn(i[2]),s=yn(i[3]);if(n===null||r===null||o===null||s===null)return null;let a=null;if(i.length>=5){if(i[4]===Kn){if(i.length!==6)return null;a=yn(i[5])}else{if(i.length!==5)return null;a=yn(i[4])}if(a===null)return null}return{cmyk:Md.fromNumber(n,r,o,s),alpha:a}}function*Py(t){for(let e=-t;e<=t;e++)for(let i=-t;i<=t;i++)for(let n=-t;n<=t;n++)Math.abs(e)+Math.abs(i)+Math.abs(n)===t&&(yield[e,i,n])}var Pi,ms,Dd,pu,zd=class{constructor(){ne(this,ms),ne(this,Pi,new Map)}registerDeviceCmyk(t){let e=_d(t);return e?le(this,ms,Dd).call(this,e.cmyk).toColorFunc(e.alpha):null}registerCmykReserveMap(t){for(let[e,i]of t){let n=ci.fromInt(e.r,e.g,e.b),r=Md.fromInt(i.c,i.m,i.y,i.k);U(this,Pi).set(n.toKey(),r)}}toJSON(){let t={};return U(this,Pi).forEach((e,i)=>{t[i]=e.toJSON()}),t}};Pi=new WeakMap,ms=new WeakSet,Dd=function(t){let e=t.toSRGB(),i=e.toKey(),n=U(this,Pi).get(i);return n?n.equals(t)?e:le(this,ms,pu).call(this,t,e):(U(this,Pi).set(i,t),e)},pu=function(t,e){for(let i=1;i<=ci.MAX;i++)for(let[n,r,o]of Py(i)){let s=e.offset(n,r,o),a=s.toKey();if(!U(this,Pi).has(a))return U(this,Pi).set(a,t),s}return Y.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(t.toJSON())}`),e};var Yo,fr,gr,Vd=class extends dn{constructor(t){super(),ne(this,Yo),ne(this,fr,new Map),ne(this,gr,!1),pe(this,Yo,t??new zd)}reset(){pe(this,gr,!1)}hadDeviceCmyk(){return U(this,gr)}recordConversion(t,e){U(this,fr).set(t,e)}getConversions(){if(U(this,fr).size===0)return null;let t={};return U(this,fr).forEach((e,i)=>{t[i]=e}),t}visitFunc(t){let e=U(this,Yo).registerDeviceCmyk(t);return e?(pe(this,gr,!0),e):super.visitFunc(t)}};Yo=new WeakMap,fr=new WeakMap,gr=new WeakMap;function $d(t){if(t.nodeType==1){let e=t.getAttribute("id");if(e)return e}return null}function Ey(t){return`^${t}`}function fu(t){return t.replace(/[\[\]\(\),=;^]/g,Ey)}function Ny(t){return t.substr(1)}function Qa(t){return t&&t.replace(/\^[\[\]\(\),=;^]/g,Ny)}function Ty(t){let e=[];do{let i=t.match(/^(\^,|[^,])*/),n=Qa(i[0]);if(t=t.substr(i[0].length+1),!t&&!e.length)return n;e.push(n)}while(t);return e}function gu(t){let e={};for(;t;){let i=t.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return e;e[i[1]]=Ty(i[2]),t=t.substr(i[0].length)}return e}var mu=class{appendTo(t){t.append("!")}applyTo(t){return!1}},yu=class{constructor(t,e,i){u(this,"index",t),u(this,"id",e),u(this,"sideBias",i)}appendTo(t){t.append("/"),t.append(this.index.toString()),(this.id||this.sideBias)&&(t.append("["),this.id&&t.append(this.id),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}applyTo(t){if(t.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let e=t.node,i=e.children,n=i.length,r,o=Math.floor(this.index/2)-1;if(o<0||n==0)r=e.firstChild,t.node=r||e;else{if(r=i[Math.min(o,n-1)],this.index&1){let s=r.nextSibling;!s||s.nodeType==1?t.after=!0:r=s}t.node=r}if(this.id&&(t.after||this.id!=$d(t.node))){let s=e.ownerDocument.getElementById(this.id);s?t.node=s:Y.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},vu=class{constructor(t,e,i,n){u(this,"offset",t),u(this,"textBefore",e),u(this,"textAfter",i),u(this,"sideBias",n)}applyTo(t){if(this.offset>0&&!t.after){let e=this.offset,i=t.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let o=i.textContent.length;if(e<=o)break;if(!r){e=o;break}e-=o}if(!r){e=0;break}i=r}t.node=i,t.offset=e}return t.sideBias=this.sideBias,!0}appendTo(t){t.append(":"),t.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(t.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&t.append(fu(this.textBefore)),t.append(","),this.textAfter&&t.append(fu(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},wu=class Hd{constructor(){u(this,"steps",null)}fromString(e){var i,n,r;let o=e.match(/^#?epubcfi\((.*)\)$/);if(!o)throw new Error("E_CFI_NOT_CFI");let s=decodeURIComponent(o[1]),a=0,h=[];for(;;){let l;switch(s.charAt(a)){case"/":{if(a++,o=s.substr(a).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!o)throw new Error("E_CFI_NUMBER_EXPECTED");a+=o[0].length;let c=parseInt(o[1],10),d=(i=o[3])!=null?i:null;l=gu(o[4]),h.push(new yu(c,d,iu(l.s)));break}case":":{if(a++,o=s.substr(a).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!o)throw new Error("E_CFI_NUMBER_EXPECTED");a+=o[0].length;let c=parseInt(o[1],10),d=(n=o[4])!=null?n:null;d&&(d=Qa(d));let p=(r=o[7])!=null?r:null;p&&(p=Qa(p)),l=gu(o[10]),h.push(new vu(c,d,p,iu(l.s)));break}case"!":a++,h.push(new mu);break;case"~":case"@":case"":this.steps=h;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(e){let i={node:e.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 Hd,i.ref.steps=this.steps.slice(n+1);break}return i}trim(e,i){return e.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(e,i,n,r){let o=[],s=e.parentNode,a="",h="";for(;e;){switch(e.nodeType){case 3:case 4:case 5:{let l=e.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)),e=e.previousSibling;continue}case 8:e=e.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),o.push(new vu(i,a,h,r)),r=null);s&&!(!s||s.nodeType==9);){let l=n?null:$d(e),c=n?1:0;for(;e;)e.nodeType==1&&(c+=2),e=e.previousSibling;o.push(new yu(c,l,r)),r=null,e=s,s=s.parentNode,n=!1}o.reverse(),this.steps?(o.push(new mu),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let e=new mi;e.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(e);return e.append(")"),e.toString().replace(/%/g,"%25")}},Dt=class{constructor(t,e,i,n){u(this,"x1",t),u(this,"y1",e),u(this,"x2",i),u(this,"y2",n)}},Ti=class{constructor(t,e){u(this,"x",t),u(this,"y",e)}},Sa=class{constructor(t,e,i,n){u(this,"left",t),u(this,"top",e),u(this,"right",i),u(this,"bottom",n)}},bu=class{constructor(t,e,i,n){u(this,"low",t),u(this,"high",e),u(this,"winding",i),u(this,"shapeId",n)}},fi=class{constructor(t,e,i,n){u(this,"y1",t),u(this,"y2",e),u(this,"x1",i),u(this,"x2",n),u(this,"left",null),u(this,"right",null)}};function Iy(t,e){return t.low.y-e.low.y||t.low.x-e.low.x}var Zs=class Ud{constructor(e){u(this,"points",e)}addSegments(e,i){let n=this.points,r=n.length,o=n[r-1];for(let s=0;s<r;s++){let a=n[s],h;o.y<a.y?h=new bu(o,a,1,i):h=new bu(a,o,-1,i),e.push(h),o=a}}withOffset(e,i){let n=[];for(let r of this.points)n.push(new Ti(r.x+e,r.y+i));return new Ud(n)}};function xu(t,e,i,n){let r=[];for(let o=0;o<20;o++){let s=o*2*Math.PI/20;r.push(new Ti(t+i*Math.sin(s),e+n*Math.cos(s)))}return new Zs(r)}function ah(t,e,i,n){return new Zs([new Ti(t,e),new Ti(i,e),new Ti(i,n),new Ti(t,n)])}var Po=class{constructor(t,e,i,n){u(this,"x",t),u(this,"winding",e),u(this,"shapeId",i),u(this,"lowOrHigh",n)}};function Su(t,e){let i=t.low.x+(t.high.x-t.low.x)*(e-t.low.y)/(t.high.y-t.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function Ay(t,e,i,n){let r,o,s,a;e.high.y<i&&Y.warn("Error: inconsistent segment (1)"),e.low.y<=i?(r=Su(e,i),o=e.winding):(r=e.low.x,o=0),e.high.y>=n?(s=Su(e,n),a=e.winding):(s=e.high.x,a=0),r<s?(t.push(new Po(r,o,e.shapeId,-1)),t.push(new Po(s,a,e.shapeId,1))):(t.push(new Po(s,a,e.shapeId,-1)),t.push(new Po(r,o,e.shapeId,1)))}function Fy(t,e,i){let n=e+i,r=Array(n),o=Array(n),s;for(s=0;s<=n;s++)r[s]=0,o[s]=0;let a=[],h=!1,l=t.length;for(let c=0;c<l;c++){let d=t[c];r[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let p=!1;for(s=0;s<e;s++)if(r[s]&&!o[s]){p=!0;break}if(p){for(s=e;s<=n;s++)if(r[s]||o[s]){p=!1;break}}h!=p&&(a.push(d.x),h=p)}return a}function Ry(t,e){return e?Math.ceil(t/e)*e:t}function Cu(t,e){return e?Math.floor(t/e)*e:t}function Ly(t){return new Ti(t.y,-t.x)}function ys(t){return new Dt(t.y1,-t.x2,t.y2,-t.x1)}function Wd(t){return new Dt(-t.y2,t.x1,-t.y1,t.x2)}function ku(t){return new Zs(t.points.map(e=>Ly(e)))}function Oy(t,e,i,n,r,o){o&&(t=ys(t),e=e.map(x=>ku(x)),i=i.map(x=>ku(x)));let s=e.length,a=i?i.length:0,h=[],l=[],c,d,p;for(c=0;c<s;c++)e[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+s);let f=l.length;l.sort(Iy);let g=0;for(;l[g].shapeId>=s;)g++;let m=l[g].low.y;m>t.y1&&h.push(new fi(t.y1,m,t.x2,t.x2));let v=0,b=[];for(;v<f&&(p=l[v]).low.y<m;)p.high.y>m&&b.push(p),v++;for(;v<f||b.length>0;){let x=t.y2,C=Math.min(Ry(Math.ceil(m+n),r),t.y2);for(d=0;d<b.length&&x>C;d++)p=b[d],p.low.x==p.high.x?p.high.y<x&&(x=Math.max(Cu(p.high.y,r),C)):p.low.x!=p.high.x&&(x=C);for(x>t.y2&&(x=t.y2);v<f&&(p=l[v]).low.y<x;){if(p.high.y<m){v++;continue}if(p.low.y<C)p.low.y==p.high.y&&p.low.y==m||(b.push(p),x=C),v++;else{let S=Cu(p.low.y,r);S<x&&(x=S);break}}let y=[];for(d=0;d<b.length;d++)Ay(y,b[d],m,x);y.sort((S,N)=>S.x-N.x||S.lowOrHigh-N.lowOrHigh);let k=Fy(y,s,a);if(k.length==0)h.push(new fi(m,x,t.x2,t.x2));else{let S=0,N=t.x1;for(d=0;d<k.length;d+=2){let L=Math.max(t.x1,k[d]),I=Math.min(t.x2,k[d+1])-L;I>S&&(S=I,N=L)}S==0?h.push(new fi(m,x,t.x2,t.x2)):h.push(new fi(m,x,Math.max(N,t.x1),Math.min(N+S,t.x2)))}if(x==t.y2)break;for(m=x,d=b.length-1;d>=0;d--)b[d].high.y<=x&&b.splice(d,1)}return Gd(t,h),h}function Gd(t,e){let i=e.length-1,n=new fi(t.y2,t.y2,t.x1,t.x2);for(;i>=0;){let r=n;n=e[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,e.splice(i,1),n=r),i--}}function jd(t,e){let i=0,n=t.length;for(;i<n;){let r=Math.floor((i+n)/2);e>=t[r].y2?i=r+1:n=r}return i}function By(t,e){if(!t.length)return e;let i=e.y1,n,r;for(r=0;r<t.length&&(n=t[r],!(n.y2>e.y1&&n.x1-.1<=e.x1&&n.x2+.1>=e.x2));r++)i=Math.max(i,n.y2);let o=i;for(;r<t.length&&(n=t[r],!(n.y1>=e.y2||n.x1-.1>e.x1||n.x2+.1<e.x2));r++)o=n.y2;return r===t.length?o=e.y2:o=Math.min(o,e.y2),o<=i?null:new Dt(e.x1,i,e.x2,o)}function My(t,e){if(!t.length)return e;let i=e.y2,n,r;for(r=t.length-1;r>=0&&(n=t[r],!(r===t.length-1&&n.y2<e.y2))&&!(n.y1<e.y2&&n.x1-.1<=e.x1&&n.x2+.1>=e.x2);r--)i=Math.min(i,n.y1);let o=Math.min(i,n.y2);for(;r>=0&&(n=t[r],!(n.y2<=e.y1||n.x1-.1>e.x1||n.x2+.1<e.x2));r--)o=n.y1;return o=Math.max(o,e.y1),i<=o?null:new Dt(e.x1,o,e.x2,i)}function _y(t,e,i,n){let r=i.y1,o=i.x2-i.x1,s=i.y2-i.y1,a=jd(e,r);for(;;){let h=r+s;if(h>t.y2)return!1;let l=t.x1,c=t.x2;for(let d=a;d<e.length&&e[d].y1<h;d++){let p=e[d];p.x1>l&&(l=p.x1),p.x2<c&&(c=p.x2)}if(l+o<=c||a>=e.length)return n=="left"?(i.x1=l,i.x2=l+o):(i.x1=c-o,i.x2=c),i.y2+=r-i.y1,i.y1=r,!0;r=e[a].y2,a++}}function Dy(t,e,i,n,r){for(n||(n=[new fi(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=t.y1;)n.shift();if(n.length==0)return;n[0].y1<t.y1&&(n[0].y1=t.y1);let o,s=e.length==0?t.y1:e[e.length-1].y2;s<t.y2&&e.push(new fi(s,t.y2,t.x1,t.x2));let a=jd(e,n[0].y1);for(let h of n){if(a==e.length)break;for(e[a].y1<h.y1&&(o=e[a],a++,e.splice(a,0,new fi(h.y1,o.y2,o.x1,o.x2)),o.y2=h.y1);a<e.length&&(o=e[a++],o.y2>h.y2&&(e.splice(a,0,new fi(h.y2,o.y2,o.x1,o.x2)),o.y2=h.y2),h.x1!=h.x2&&(r=="left"?o.x1=Math.min(h.x2,t.x2):o.x2=Math.max(h.x1,t.x1)),o.y2!=h.y2););}Gd(t,e)}var zy=class extends Zt{constructor(){super(),u(this,"propSet",{})}visitIdent(t){return this.propSet[t.name]=!0,t}visitSpaceList(t){return this.visitValues(t.values),t}};function Vy(t){if(t){let e=new zy;try{return t.visit(e),e.propSet}catch(i){Y.warn(i,"toSet:")}}return{}}var $y=class extends Zt{constructor(t){super(),u(this,"value",t)}visitInt(t){return this.value=t.num,t}};function Pu(t,e){if(t){let i=new $y(e);try{return t.visit(i),i.value}catch(n){Y.warn(n,"toInt: ")}}return e}var Hy=class extends Zt{constructor(){super(),u(this,"collect",!1),u(this,"coords",[]),u(this,"name",null)}visitNumeric(t){return this.collect&&this.coords.push(t),null}visitNum(t){return this.collect&&t.num==0&&this.coords.push(new B(0,"px")),null}visitSpaceList(t){return this.visitValues(t.values),null}visitFunc(t){return this.collect||(this.collect=!0,this.visitValues(t.values),this.collect=!1,this.name=t.name.toLowerCase()),null}getShape(t,e,i,n,r){if(this.coords.length>0){let o=[];switch(this.coords.forEach((s,a)=>{if(s.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),o.push(s.num*h/100)}else o.push(s.num*r.queryUnitSize(s.unit,!1))}),this.name){case"polygon":if(o.length%2==0){let s=[];for(let a=0;a<o.length;a+=2)s.push(new Ti(t+o[a],e+o[a+1]));return new Zs(s)}break;case"rectangle":if(o.length==4)return ah(t+o[0],e+o[1],t+o[0]+o[2],e+o[1]+o[3]);break;case"ellipse":if(o.length==4)return xu(t+o[0],e+o[1],o[2],o[3]);break;case"circle":if(o.length==3)return xu(t+o[0],e+o[1],o[2],o[2]);break}}return null}};function Xd(t,e,i,n,r,o){if(t){let s=new Hy;try{return t.visit(s),s.getShape(e,i,n,r,o)}catch(a){Y.warn(a,"toShape:")}}return ah(e,i,e+n,i+r)}var Uy=class extends Zt{constructor(t,e){super(),u(this,"reset",t),u(this,"defaultValue",e),u(this,"counters",Object.create(null)),u(this,"name",null)}visitIdent(t){return this.name=t.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+this.defaultValue,t}visitInt(t){return this.name&&(this.counters[this.name]+=t.num-(this.reset?0:this.defaultValue)),t}visitSpaceList(t){return this.visitValues(t.values),t}};function nn(t,e){var i,n;let r=(i=e?.reset)!=null?i:!1,o=(n=e?.defaultValue)!=null?n:r?0:1,s=new Uy(r,o);try{t.visit(s)}catch(a){Y.warn(a,"toCounters:")}return s.counters}var Wy=class extends dn{constructor(t,e){super(),u(this,"baseUrl",t),u(this,"transformer",e)}visitURL(t){return new et($r(this.transformer.transformURL(t.url,this.baseUrl)))}};function Si(t){let e=Object.create(null);return Object.keys(t).forEach(i=>{e[i]=Array.from(t[i])}),e}function Gy(t){return t.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(e,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function An(t,e){var i;if(e==="content"){let n=t.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),n.textContent||""}else if(e==="marker"){let n=t.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let r=(i=t.style)==null?void 0:i.getPropertyValue("--viv-marker-content");if(r){let o=r.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(s=>Gy(s.substring(1,s.length-1))).join("")}return""}else{let n=t.querySelector(`[data-adapt-pseudo="${e}"]`);return n&&n.textContent||""}}var jy=class{constructor(t,e){u(this,"targetId",t),u(this,"resolved",e),u(this,"pageCounters",null),u(this,"spineIndex",-1),u(this,"pageIndex",-1)}equals(t){return this===t?!0:t?this.targetId===t.targetId&&this.resolved===t.resolved&&this.spineIndex===t.spineIndex&&this.pageIndex===t.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Xy=class{constructor(t,e){u(this,"counterStore",t),u(this,"baseURL",e)}countersOfId(t,e){t=this.counterStore.documentURLTransformer.transformFragment(t,this.baseURL),this.counterStore.countersById[t]=e}getExprContentListener(){return this.counterStore.getExprContentListener()}},qy=class{constructor(t,e,i,n){u(this,"counterStore",t),u(this,"baseURL",e),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(t){this.styler=t}getFragment(t){let e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null}getTransformedId(t){let e=this.counterStore.documentURLTransformer.transformURL(Ie(t,this.baseURL),this.baseURL);return e.charAt(0)==="#"&&(e=e.substring(1)),e}getPageCounterVal(t,e){let i=()=>{let o=this.counterStore.currentPageCounters[t];return o&&o.length?o[o.length-1]:null},n=new be(this.pageScope,()=>e(i()),`page-counter-${t}`),r=o=>e(o[o.length-1]);return this.counterStore.registerPageCounterExpr(t,r,n),n}getPageCountersVal(t,e){let i=()=>this.counterStore.currentPageCounters[t]||[],n=new be(this.pageScope,()=>e(i()),`page-counters-${t}`);return this.counterStore.registerPageCounterExpr(t,e,n),n}getTargetCounters(t,e,i){let n=this.counterStore.countersById[e];return!n&&i&&t&&(this.styler.styleUntilIdIsReached(t),n=this.counterStore.countersById[e]),n||null}getTargetPageCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[t]||null}getTargetPageDocCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[t]||null}adjustCountersForCrossScope(t,e,i,n){if(!this.counterStore.isPageControlledCounter(t)||!i)return e;let r=i[t]||[],o=r.length?r[r.length-1]:0,s=n?.[t]||[],a=s.length?s[0]:0;return e.length?[o+(e[0]-a),...e.slice(1)]:[o]}getTargetPageText(t,e){if(this.counterStore.currentPage.elementsById[t]){let i=this.counterStore.currentPage.elementsById[t];if(i&&i.length>0){let n=i[0];return e==="before"||e==="after"||e==="marker"?An(n,e):An(n,"content")}return""}else{if(t in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[t];return i[e]!==void 0?i[e]:i.content||""}return null}}getTargetCounterVal(t,e,i){let n=this.getFragment(t),r=this.getTransformedId(t),o=new be(this.pageScope,()=>{let s=this.getTargetCounters(n,r,!0);if(s)if(s[e]){let a=s[e],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),c=this.adjustCountersForCrossScope(e,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[e]){let h=a[e];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-${e}-of-${t}`);return this.counterStore.registerTargetCounterExpr(e,i,o,r),o}getTargetCountersVal(t,e,i){let n=this.getFragment(t),r=this.getTransformedId(t);return new be(this.pageScope,()=>{let o=this.getTargetPageCounters(r);if(o){this.counterStore.resolveReference(r);let s=this.getTargetCounters(n,r,!0),a=s?.[e]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(e,a,o,h);if(l.length)return i(l);let c=o[e]||[];return i(c)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${e}-of-${t}`)}getTargetTextVal(t,e){let i=this.getTransformedId(t),n=new be(this.pageScope,()=>{if(e==="first-letter"){let o=this.getTargetPageText(i,"before"),s=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(o===null&&s===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let h=(o??"")+(s??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(ps);return l?l[0]:""}let r=this.getTargetPageText(i,e);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${e}-of-${t}`);return this.counterStore.registerTargetTextExpr(e,n,i),n}getNamedStringVal(t,e){let i=new be(this.pageScope,()=>this.getRunningValue(this.namedStringValues,t,e),`named-string-${e}-${t}`);return i.getContentList=()=>this.getRunningContentList(t,e),i}getRunningElementVal(t,e){return new be(this.pageScope,()=>this.getRunningValue(this.runningElements,t,e),`running-element-${e}-${t}`)}getRunningValue(t,e,i){let n=this.getRunningRawValue(t,e,i);return typeof n.value=="string"?n.value:this.contentListToString(this.resolveDeferredContentList(n.value,n.offset))}getRunningContentList(t,e){let i=this.getRunningRawValue(this.namedStringValues,t,e);return typeof i.value=="string"?null:this.resolveDeferredContentList(i.value,i.offset)}resolveDeferredContentList(t,e){return this.freezePageCounters(t,e)}freezePageCounters(t,e){if(t instanceof j){let i=t.expr;if(i instanceof be){let n=/^page-counters?-(.+)$/.exec(i.str);if(n){if(n[1]==="pages")return t;let r=this.counterStore,o=n[1],s=r.getPageCounterFormat(i)||(h=>h.length?String(h[h.length-1]):""),a=r.getOrCreateNamedStringPageCounterExpr(this.pageScope,e,o,s);return new j(a)}}return t}return t instanceof ee?new ee(t.values.map(i=>this.freezePageCounters(i,e))):t instanceof Be?new Be(t.values.map(i=>this.freezePageCounters(i,e))):t}contentListToString(t){if(t instanceof K)return t.stringValue();if(t instanceof j){let e=t.expr;if(e instanceof be){let i=e.fn.call(null);return i==null?"":String(i)}return""}return t instanceof ee?t.values.map(e=>this.contentListToString(e)).join(""):t instanceof Be?t.values.map(e=>this.contentListToString(e)).join(""):""}getRunningRawValue(t,e,i){let n=t[e];if(!n)return{value:"",offset:-1};let r=Object.keys(n).map(p=>parseInt(p,10)).sort(ld),o=this.counterStore.currentPage;if(!o)return{value:"",offset:-1};let s=o.isBlankPage?o.offset-1:o.offset,a=o.isBlankPage?s:Math.max(s,...Array.from(o.container.querySelectorAll(`[${jt}]`)).map(p=>parseInt(p.getAttribute(jt),10))),h=-1,l=-1,c=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=s){if(h<0&&(h=f,d=-1),l<0)if(f===s)l=f;else{g<h&&(l=g);let v=o.container.querySelector(`[${jt}="${f}"]`);if(!v)l<0&&(l=f);else{let b=o.container.querySelector(`[${jt}="${s}"]`);if(b||(b=o.container.querySelector(`[${jt}="0"]`)),b){for(let x=b;x;x=x.firstElementChild)if(x===v){l=f;break}}}}c=f}else(m>a||m<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(t,e,i){let n=this.namedStringValues[t]||(this.namedStringValues[t]=Object.create(null));n[i]=e,typeof e!="string"&&(this.counterStore.hasDeferredNamedStrings=!0)}setRunningElement(t,e){let i=this.runningElements[t]||(this.runningElements[t]=Object.create(null));i[e]=String(e)}},Yy=class{constructor(t){u(this,"documentURLTransformer",t),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(t){return new Xy(this,t)}createCounterResolver(t,e,i){return new qy(this,t,e,i)}setCurrentPage(t){this.currentPage=t}setCurrentPageDocCounters(t,e,i){this.previousPageDocCounters=this.currentPageDocCounters?Si(this.currentPageDocCounters):null,this.currentPageDocCounters=t?Si(t):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),e&&e.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(t){let e=Object.assign(Object.create(null),{page:!0});t.forEach(i=>{e[i]=!0}),this.pageControlledCounterNames=e}isPageControlledCounter(t){return!!this.pageControlledCounterNames[t]}definePageCounter(t,e){this.currentPageCounters[t]?this.currentPageCounters[t].push(e):this.currentPageCounters[t]=[e]}forceSetPageCounter(t){let e=this.currentPageCounters.page;!e||!e.length?this.currentPageCounters.page=[t]:e[e.length-1]=t}updatePageCounters(t,e){this.previousPageCounters=Si(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let b=this.previousPageDocCounters||{};for(let x in this.currentPageDocCounters){if(!i[x])continue;let C=this.currentPageDocCounters[x],y=C.length?C[C.length-1]:0,k=b[x]||[],S=k.length?k[k.length-1]:0,N=y-S,L=n[x],I=L==="reset"||L==="set";r[x]={delta:N,reset:I,value:y}}}let o=Object.create(null),s,a=!1,h=t["counter-reset"];if(h){let b=h.evaluate(e);b&&(a=b===w.none,a||(s=nn(b,{reset:!0})))}s&&"pages"in s&&delete s.pages;let l,c=t["counter-set"];if(c){let b=c.evaluate(e);b&&(l=nn(b,{defaultValue:0}))}l&&"pages"in l&&delete l.pages;let d=[];if(s)for(let b in s)d.push(b);if(l)for(let b in l)d.push(b);let p,f=t["counter-increment"];if(f){let b=f.evaluate(e);b&&(p=nn(b))}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 b in p)d.push(b);this.setPageControlledCounterNames(d);let g=Si(this.previousPageCounters);if(a)for(let b in this.pageCountersBeforeOverride)g[b]=Array.from(this.pageCountersBeforeOverride[b]);if(this.currentPageDocCounters)for(let b in this.currentPageDocCounters){if(this.isPageControlledCounter(b)){let x=r[b];if(x){if(x.reset)g[b]=[x.value],o[b]=!0;else if(x.delta!==0){g[b]||(g[b]=[0]);let C=g[b];C[C.length-1]+=x.delta}}else g[b]||(g[b]=Array.from(this.currentPageDocCounters[b]));continue}g[b]=Array.from(this.currentPageDocCounters[b])}this.currentPageCounters=g;let m=Object.create(null),v=b=>{if(!Object.prototype.hasOwnProperty.call(m,b)){let x=g[b];x&&(m[b]=Array.from(x))}};if(s)for(let b in s)v(b),this.definePageCounter(b,s[b]);for(let b in p){if(o[b])continue;this.currentPageCounters[b]||this.definePageCounter(b,0);let x=this.currentPageCounters[b];x[x.length-1]+=p[b]}if(l)for(let b in l)if(v(b),!this.currentPageCounters[b])this.definePageCounter(b,l[b]);else{let x=this.currentPageCounters[b];x[x.length-1]=l[b]}for(let b in m)this.pageCountersBeforeOverride[b]=Array.from(m[b])}pushPageCounters(t){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Si(t)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(t){let e=this.unresolvedReferences[t],i=this.resolvedReferences[t];i||(i=this.resolvedReferences[t]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let o=this.referencesToSolve[r];if(o.targetId===t){if(o.resolve(),this.referencesToSolve.splice(r,1),e){let s=e.indexOf(o);s>=0&&e.splice(s,1)}i.push(o),n=!0}else r++}n||this.saveReferenceOfCurrentPage(t,!0)}saveReferenceOfCurrentPage(t,e){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===t)){let i=new jy(t,e);this.newReferencesOfCurrentPage.push(i)}}finishPage(t,e){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let o=Si(this.currentPageCounters),s=this.currentPageDocCounters?Si(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=o,s&&(this.pageDocCountersById[a]=s);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let c=h[0];this.pageTextById[a]={content:An(c,"content"),before:An(c,"before"),after:An(c,"after"),marker:An(c,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<e){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:t,pageIndex:e}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=t,r.pageIndex=e;let o;r.isResolved()?(o=this.resolvedReferences[r.targetId],o||(o=this.resolvedReferences[r.targetId]=[])):(o=this.unresolvedReferences[r.targetId],o||(o=this.unresolvedReferences[r.targetId]=[])),o.every(s=>!r.equals(s))&&o.push(r)}this.hasDeferredNamedStrings&&this.currentPage&&this.recordNamedStringPageSnapshot(t),this.currentPage=null}recordNamedStringPageSnapshot(t){let e=this.currentPage,i=e.isBlankPage?e.offset-1:e.offset,n=e.isBlankPage?i:Math.max(i,...Array.from(e.container.querySelectorAll(`[${jt}]`)).map(r=>parseInt(r.getAttribute(jt),10)));for(let r of Object.keys(this.namedStringPageSnapshots)){let o=parseInt(r,10);if(o<=i)continue;let s=this.namedStringPageSnapshots[o];o<=n&&i<=s.lastOffset&&delete this.namedStringPageSnapshots[o]}this.namedStringPageSnapshots[i]={lastOffset:n,spineIndex:t,counters:Si(this.currentPageCounters)}}getPageCountersForOffset(t){for(let e of Object.keys(this.namedStringPageSnapshots)){let i=parseInt(e,10);if(i>t)break;let n=this.namedStringPageSnapshots[i];if(t<=n.lastOffset)return n.counters}return null}adjustPageCountersOfLaterSpines(t,e){if(e<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>t){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(o=>o+e))}for(let n of Object.keys(this.namedStringPageSnapshots)){let r=this.namedStringPageSnapshots[parseInt(n,10)];r.spineIndex>t&&r.counters.page&&!i.has(r.counters)&&(i.add(r.counters),r.counters.page=r.counters.page.map(o=>o+e))}}updateTargetCounterNodesInPages(t){for(let e of t){if(!e||!e.container)continue;let i=e.container.querySelectorAll(`[${or}]`);for(let n of i){let r=n.getAttribute(or),o=this.targetCounterExprs.find(s=>s.expr.key===r);if(o&&o.transformedId){let s=this.pageCountersById[o.transformedId];if(s){let a=s[o.name];a&&(n.textContent=o.format(a[a.length-1]))}}}}}getPageCountersForPage(t,e){let i=Object.keys(t.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return e||null}updatePageCounterNodesInPages(t,e){var i;for(let n=0;n<t.length;n++){let r=t[n];if(!(r!=null&&r.container))continue;let o=r.container.querySelectorAll(`[${ka}]`);for(let h of o){let l=h.getAttribute(ka),c=this.namedStringPageCounterExprMap[l];if(!c)continue;let d=this.getPageCountersForOffset(c.offset),p=d?.[c.counterName];p&&(h.textContent=c.format(p))}let s=this.getPageCountersForPage(r,e?.[n]);if(!s)continue;let a=r.container.querySelectorAll(`[${rr}]`);for(let h of a){let l=h.getAttribute(rr),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=s[p];f&&(h.textContent=c.format(f))}}}getUnresolvedRefsToPage(t){let e=[];Object.keys(t.elementsById).forEach(r=>{let o=this.unresolvedReferences[r];o&&(e=e.concat(o))}),e.sort((r,o)=>r.spineIndex-o.spineIndex||r.pageIndex-o.pageIndex);let i=[],n=null;return e.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(t){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=t}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(t,e,i){t==="pages"?this.pagesCounterExprs.push({expr:i,format:e}):this.pageCounterExprs.push({expr:i,format:e})}getPageCounterFormat(t){let e=this.pageCounterExprs.find(i=>i.expr===t);return e?e.format:null}getOrCreateNamedStringPageCounterExpr(t,e,i,n){for(let o in this.namedStringPageCounterExprMap){let s=this.namedStringPageCounterExprMap[o];if(s.offset===e&&s.counterName===i)return s.expr}let r=new be(t,()=>{let o=((e>=0?this.getPageCountersForOffset(e):null)||this.currentPageCounters)[i]||[];return n(o)},`named-string-page-counter-${i}`);return this.namedStringPageCounterExprMap[r.key]={expr:r,offset:e,counterName:i,format:n},r}registerTargetCounterExpr(t,e,i,n){this.targetCounterExprs.push({name:t,expr:i,format:e,transformedId:n})}registerTargetTextExpr(t,e,i){this.targetTextExprs.push({pseudoElement:t,expr:e,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(t,e,i){if(t instanceof be){if(t.str=="viv-leader"){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute("data-viv-leader",t.key),o.setAttribute("data-viv-leader-value",e),o}else if(t.str.startsWith("running-element-")){let o=e&&i.querySelectorAll(`[${jt}="${e}"]`);if(!o||o.length===0)return null;let s=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(s),s.style.position="",s.style.visibility="",s}else if(t.str.startsWith("target-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(or,t.key),o}else if(t.str.startsWith("target-text-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(Pa,t.key),o}else if(t.str.startsWith("named-string-page-counter-")){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(ka,t.key),o}}let n=this.pagesCounterExprs.findIndex(o=>o.expr===t)>=0,r=!n&&this.pageCounterExprs.findIndex(o=>o.expr===t)>=0;if(n||r){let o=i.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(n?Ca:rr,t.key),o}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${rr}]`);for(let r of e){let o=r.getAttribute(rr),s=this.pageCounterExprs.find(c=>c.expr.key===o),a=(s?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=s.format(l))}let i=t.querySelectorAll(`[${or}]`);for(let r of i)r.setAttribute(Eu,!0);let n=t.querySelectorAll(`[${Pa}]`);for(let r of n)r.setAttribute(Nu,!0)}finishLastPage(t){var e;let i=t.root.querySelectorAll(`[${Ca}]`),n=t.contentContainer.childElementCount;for(let s of i){let a=s.getAttribute(Ca),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,s.textContent=this.pagesCounterExprs[h].format([n])}let r=t.root.querySelectorAll(`[${Eu}]`);for(let s of r){let a=s.getAttribute(or),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&&(s.textContent=h.format(c[c.length-1]))}}}let o=t.root.querySelectorAll(`[${Nu}]`);for(let s of o){let a=s.getAttribute(Pa),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(s.textContent=(e=l[h.pseudoElement])!=null?e:"")}}}createLayoutConstraint(t){return new Zy(this,t)}},Ca="data-vivliostyle-pages-counter",rr="data-vivliostyle-page-counter",ka="data-vivliostyle-named-string-page-counter",or="data-vivliostyle-target-counter",Pa="data-vivliostyle-target-text",Eu="data-vivliostyle-target-counter-in-running",Nu="data-vivliostyle-target-text-in-running",Zy=class{constructor(t,e){u(this,"counterStore",t),u(this,"pageIndex",e)}allowLayout(t){if(!t||t.after)return!0;let e=t.viewNode;if(!e||e.nodeType!==1)return!0;let i=e.getAttribute("data-vivliostyle-id")||e.getAttribute("id")||e.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}},Ky=new Set(["before","after","first-line","first-letter"]),Tu=new Set(["media","supports","layer","-epubx-when"]),qd=new Set([";","}"]),Yd=new Set(["{",";","}"]),Jy=new Set([";","{","}"]),Qy=":where(:scope)",ev=":where(:not(*))";function tv(t){let{statements:e,changed:i}=el(t,0,t.length,null);return i?e.join(`
5
+ `):t}function el(t,e,i,n){let r=[],o=[],s=!1,a=e,h=()=>{o.length!==0&&(n?r.push(iv(n,o)):r.push(Zd(o)),o.length=0)};for(;a<i&&(a=ln(t,a,i),!(a>=i||t[a]==="}"));){if(t[a]==="@"){let d=mv(t,a,i);if(!d)break;if(n&&!Tu.has(d.name)){o.push(Qi(t.slice(a,d.end))),a=d.end;continue}if(h(),d.hasBlock&&Tu.has(d.name)){let p=el(t,d.blockStart,d.blockEnd,n);s||(s=p.changed||n!=null),r.push(`${d.header} {${nv(p.statements)}}`)}else r.push(Qi(t.slice(a,d.end)));a=d.end;continue}if(n&&lv(t,a,i)){let d=cv(t,a,i);if(!d)break;o.push(Qi(d.text)),a=d.end;continue}h();let l=dv(t,a,i);if(!l){let d=yv(t,a,i);r.push(Qi(d.text)),a=d.end;continue}if(n&&pv(t,a,l)){let d=gv(t,a,l.end,i);o.push(Qi(d.text)),a=d.end;continue}let c=n?rv(n,l.prelude):Kd(l.prelude);if(c){s||(s=n!=null);let d=el(t,l.blockStart,l.blockEnd,c);s||(s=d.changed),d.statements.length===0?r.push(`${c} {}`):r.push(...d.statements)}a=l.end}return h(),{statements:r,changed:s}}function iv(t,e){return`${t} { ${Zd(e)} }`}function Zd(t){return t.map(e=>e.endsWith(";")?e:`${e};`).join(" ")}function nv(t){return t.length===0?"":` ${t.join(" ")} `}function rv(t,e){let i=ov(t);if(!i)return null;let n=Qd(e,",").map(r=>r.trim()).filter(Boolean).map(r=>{let o=Jd(r,i);return o.found?o.text:`${i} ${r}`}).filter(Boolean);return n.length===0?null:n.join(", ")}function Kd(t){return Jd(t.trim(),Qy).text}function ov(t){let e=Qd(t,",").map(i=>i.trim()).filter(Boolean).filter(i=>!sv(i));return e.length===0?null:`:is(${e.join(", ")})`}function sv(t){let e=0;for(;e<t.length;){let i=Ks(t,e);if(i!=null){e=i;continue}let n=pn(t,e,t.length);if(n!=null){e=n;continue}if(t[e]===":"){if(t[e+1]===":")return!0;let r=e+1,o=lo(t,r,t.length),s=t.slice(r,o).toLowerCase();if(Ky.has(s))return!0;e=o;continue}e++}return!1}function Jd(t,e){let i=0,n=!1,r="",o=[],s=av(e);for(;i<t.length;){let a=Ks(t,i);if(a!=null){r+=t.slice(i,a),i=a;continue}let h=pn(t,i,t.length);if(h!=null){r+=t.slice(i,h),i=h;continue}let l=t[i];if(l===":"&&t[i+1]!==":"){let c=i+1,d=lo(t,c,t.length);if(d>c&&t[d]==="("){o.push(t.slice(c,d).toLowerCase()),r+=t.slice(i,d+1),i=d+1;continue}}if(l==="("){o.push(""),r+=l,i++;continue}if(l===")"){o.pop(),r+=l,i++;continue}if(l==="&"){r+=s&&o.includes("has")?ev:e,n=!0,i++;continue}r+=l,i++}return{text:r,found:n}}function av(t){let e=0;for(;e<t.length;){let i=Ks(t,e);if(i!=null){e=i;continue}let n=pn(t,e,t.length);if(n!=null){e=n;continue}if(t[e]===":"&&t[e+1]!==":"){let r=e+1,o=lo(t,r,t.length);if(o>r&&t.slice(r,o).toLowerCase()==="has"&&t[o]==="(")return!0;e=o;continue}e++}return!1}function Qd(t,e){let i=[],n=0,r=0,o=0,s=0;for(;r<t.length;){let a=Ks(t,r);if(a!=null){r=a;continue}let h=pn(t,r,t.length);if(h!=null){r=h;continue}let l=t[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;default:o===0&&s===0&&l===e&&(i.push(t.slice(n,r)),n=r+1);break}r++}return i.push(t.slice(n)),i}function lv(t,e,i){let n=e,r=uv(t,n,i);if(r<=n)return!1;let o=ln(t,r,i);if(o>=i||t[o]!==":")return!1;let s=ho(t,o+1,i,Jy);return s?.char==="{"?!hv(t,e,r,o,s.index):!0}function hv(t,e,i,n,r){if(ln(t,i,r)!==n)return!1;let o=ln(t,n+1,r);if(o!==n+1||o>=r)return!1;let s=t[o];return s===":"||s==="\\"||/[A-Za-z_-]/.test(s)}function uv(t,e,i){let n=e;return t[n]==="-"&&(n++,n<i&&t[n]==="-"&&n++),lo(t,n,i)}function lo(t,e,i){let n=e;for(;n<i;){let r=t[n];if(r==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(r))break;n++}return n}function cv(t,e,i){let n=ho(t,e,i,qd);if(!n){let o=t.slice(e,i).trim();return o?{text:o,end:i}:null}let r=n.char===";"?n.index+1:n.index;return{text:t.slice(e,r).trim(),end:r}}function dv(t,e,i){let n=ho(t,e,i,Yd);if(!n||n.char!=="{")return null;let r=ep(t,n.index,i);return r<0?null:{prelude:Qi(t.slice(e,n.index)),blockStart:n.index+1,blockEnd:r,end:r+1}}function pv(t,e,i){if(!fv(t,e,i.blockStart-1))return!0;let n=ln(t,i.blockStart,i.blockEnd);return n<i.blockEnd&&t[n]===";"}function fv(t,e,i){let n=ln(t,e,i);if(n>=i)return!1;let r=t[n];return r==="&"||r==="."||r==="#"||r===":"||r==="["||r==="|"||r==="*"||r===">"||r==="+"||r==="~"||r==="\\"||/[A-Za-z_-]/.test(r)}function gv(t,e,i,n){let r=ln(t,i,n),o=r<n&&t[r]===";"?r+1:i;return{text:t.slice(e,o),end:o}}function mv(t,e,i){let n=ho(t,e,i,Yd);if(!n)return null;let r=lo(t,e+1,i),o=t.slice(e+1,r).toLowerCase(),s=Qi(t.slice(e,n.index));if(n.char!=="{")return{name:o,header:s,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=ep(t,n.index,i);return a<0?null:{name:o,header:s,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function yv(t,e,i){let n=ho(t,e,i,qd);if(!n)return{text:t.slice(e,i),end:i};let r=n.char===";"?n.index+1:n.index;return{text:t.slice(e,r),end:r}}function ho(t,e,i,n){let r=e,o=0,s=0,a=0;for(;r<i;){let h=pn(t,r,i);if(h!=null){r=h;continue}let l=t[r];switch(l){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":s++;break;case"]":s=Math.max(0,s-1);break;case"{":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a++;break;case"}":if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};a=Math.max(0,a-1);break;default:if(o===0&&s===0&&a===0&&n.has(l))return{index:r,char:l};break}r++}return null}function ep(t,e,i){let n=e+1,r=1;for(;n<i;){let o=pn(t,n,i);if(o!=null){n=o;continue}let s=t[n];if(s==="{")r++;else if(s==="}"&&(r--,r===0))return n;n++}return-1}function ln(t,e,i){let n=e;for(;n<i;){let r=t[n];if(ip(r)){n++;continue}if(r==="/"&&t[n+1]==="*"){n=tp(t,n,i);continue}break}return n}function tp(t,e,i){let n=t.indexOf("*/",e+2);return n<0||n+2>i?i:n+2}function pn(t,e,i){let n=t[e];return n==='"'||n==="'"?vv(t,e):n==="/"&&t[e+1]==="*"?tp(t,e,i):null}function Ks(t,e){return t[e]!=="\\"?null:e+1>=t.length?t.length:e+2}function vv(t,e){let i=t[e],n=e+1;for(;n<t.length;){let r=t[n];if(r==="\\"){n+=2;continue}if(r===i)return n+1;n++}return t.length}function ip(t){return t===" "||t===`
6
+ `||t==="\r"||t===" "||t==="\f"}function Qi(t){let e="",i=0,n=!1;for(;i<t.length;){let r=pn(t,i,t.length);if(r!=null&&t[i]!=="/"){n&&e.length>0&&(e+=" ",n=!1),e+=t.slice(i,r),i=r;continue}if(r!=null){n=e.length>0,i=r;continue}let o=t[i];if(ip(o)){n=e.length>0,i++;continue}n&&e.length>0&&(e+=" ",n=!1),e+=o,i++}return e}function wv(t){if(t=t.substr(1),t.match(/^[^0-9a-fA-F\n\r]$/))return t;let e=parseInt(t,16);return isNaN(e)?"":e===0||e>=55296&&e<=57343||e>1114111?"\uFFFD":String.fromCodePoint(e)}function Ci(t){return t.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,wv)}var bv=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 tt(t,e){let i=Array(128),n;for(n=0;n<128;n++)i[n]=t;for(i[NaN]=t==35?35:72,n=0;n<e.length;n+=2)i[e[n]]=e[n+1];return i}var ii=[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];ii[NaN]=80;var ni=[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];ni[NaN]=43;var xv=[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];ni[NaN]=43;var np=[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];np[NaN]=35;var rp=[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];rp[NaN]=45;var tl=[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];tl[NaN]=37;var il=[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];il[NaN]=38;var Hi=tt(35,[61,36]),Sv=tt(35,[58,77]),Cv=tt(35,[61,36,124,50]),kv=tt(35,[38,51]),Pv=tt(35,[42,54]),Ev=tt(39,[42,55]),Nv=tt(54,[42,55,47,56]),Tv=tt(62,[62,82]),Iv=tt(35,[61,36,33,70]),Av=tt(62,[45,71]),Fv=tt(63,[45,81]),Ea=tt(76,[10,72,13,72]),Rv=tt(39,[39,46,10,72,13,72,92,48]),Lv=tt(39,[34,46,10,72,13,72,92,49]),Ov=tt(39,[39,47,10,74,13,74,92,48]),Bv=tt(39,[34,47,10,74,13,74,92,49]),Iu=tt(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Mv=tt(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]),_v=tt(39,[39,68,10,74,13,74,92,75,NaN,67]),Dv=tt(39,[34,68,10,74,13,74,92,75,NaN,67]),zv=tt(72,[9,39,10,39,13,39,32,39,41,69]),Vv=15,xt=class{constructor(t,e){u(this,"input",t),u(this,"handler",e),u(this,"indexMask"),u(this,"buffer"),u(this,"tail",0),u(this,"curr",0),u(this,"position",0),this.indexMask=Vv,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new bv}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(t){return(this.tail-this.curr&this.indexMask)<=t&&this.fillBuffer(),this.buffer[this.curr+t&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let t=this.tail,e=this.curr,i=this.indexMask;if(t>=e?e+=i:e--,e==t)throw new Error("F_CSSTOK_INTERNAL");let n=ii,r=this.input,o=this.position,s=this.buffer,a=0,h=0,l="",c=0,d=!1,p=s[t],f=-9;for(;;){let g=r.charCodeAt(o);switch(n[g]||n[65]){case 72:isNaN(g)?(l=r.substring(h,o),a=0):n===ii&&a===0?(a=54,h=o,l=r.substring(o,o+1),o++):(l=r.substring(h,o),a=54),n=ii;break;case 1:o++,d=!0;continue;case 2:h=o++,n=tl;continue;case 3:a=1,h=o++,n=ni;continue;case 4:h=o++,a=31,n=Hi;continue;case 33:a=2,h=++o,n=Rv;continue;case 34:a=2,h=++o,n=Lv;continue;case 6:h=++o,a=7,n=ni;continue;case 7:h=o++,a=32,n=Hi;continue;case 8:h=o++,a=21;break;case 9:h=o++,a=32,n=kv;continue;case 10:h=o++,a=10;break;case 11:h=o++,a=11;break;case 12:h=o++,a=36,n=Hi;continue;case 13:h=o++,a=23;break;case 14:h=o++,a=16;break;case 15:a=24,h=o++,n=np;continue;case 16:h=o++,n=xv;continue;case 78:h=o++,a=9,n=ni;continue;case 17:h=o++,a=19,n=Pv;continue;case 18:h=o++,a=18,n=Sv;continue;case 77:o++,a=50;break;case 19:h=o++,a=17;break;case 20:h=o++,a=38,n=Iv;continue;case 21:h=o++,a=39,n=Hi;continue;case 22:h=o++,a=37,n=Hi;continue;case 23:h=o++,a=22;break;case 24:h=++o,a=20,n=ni;continue;case 25:h=o++,a=14;break;case 26:h=o++,a=15;break;case 27:h=o++,a=12;break;case 28:h=o++,a=13;break;case 29:h=o++,f=h,a=1,n=Ea;continue;case 30:h=o++,a=33,n=Hi;continue;case 31:h=o++,a=34,n=Cv;continue;case 32:h=o++,a=35,n=Hi;continue;case 35:break;case 36:o++,a=a+41-31;break;case 37:a=5,c=parseInt(r.substring(h,o),10);break;case 38:a=4,c=parseFloat(r.substring(h,o));break;case 39:o++;continue;case 40:a=3,c=parseFloat(r.substring(h,o)),h=o++,n=ni;continue;case 41:a=3,c=parseFloat(r.substring(h,o)),l="%",h=o++;break;case 42:o++,n=il;continue;case 43:if(l=Ci(r.substring(h,o)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(o-1))){a=27,o++;continue}break;case 44:f=o++,n=Ea;continue;case 45:l=Ci(r.substring(h,o));break;case 46:l=r.substring(h,o),o++;break;case 47:l=Ci(r.substring(h,o)),o++;break;case 48:f=o,o+=2,n=Ov;continue;case 49:f=o,o+=2,n=Bv;continue;case 50:o++,a=25;break;case 51:o++,a=26;break;case 52:if(l=r.substring(h,o),a==1){if(o++,l.toLowerCase()=="url"){n=Iu;continue}a=6}break;case 53:if(l=Ci(r.substring(h,o)),a==1){if(o++,l.toLowerCase()=="url"){n=Iu;continue}a=6}break;case 54:n=Ev,o++;continue;case 55:n=Nv,o++;continue;case 56:n=ii,o++;continue;case 57:n=Tv,o++,r[o]!==">"&&(a=1,n=ni);continue;case 81:a=51,l=r.substring(h,++o),n=ii;break;case 82:a=52,l=r.substring(h,++o),n=ii;break;case 58:a=5,n=tl,o++;continue;case 59:a=4,n=il,o++;continue;case 60:a=1,n=ni,o++;continue;case 61:a=1,n=Ea,f=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:h=o++,n=Mv;continue;case 65:h=++o,n=_v;continue;case 66:h=++o,n=Dv;continue;case 67:a=8,l=Ci(r.substring(h,o)),o++;break;case 69:o++;break;case 70:n=Av,o++;continue;case 71:n=Fv,o++;continue;case 79:if(o-f<8&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:a=8,l=Ci(r.substring(h,o)),o++,n=zv;continue;case 74:if(o++,o-f<9&&r.substring(f+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=ii;break;case 73:if(o-f<9&&r.substring(f+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,n=ni;continue}l=Ci(r.substring(h,o));break;case 75:f=o++;continue;case 76:o++,n=rp;continue;default:if(n!==ii){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=o,a=0}if(p.type=a,p.precededBySpace=d,p.num=c,p.text=l,p.position=h,t++,t>=e)break;n=ii,d=!1,a=0,h=o,l="",c=0,p=s[t&i]}this.position=o,this.tail=t&i}},qe=null,nl=null;function Hr(){return qe}function V(t){if(!qe)throw new Error("E_TASK_NO_CONTEXT");qe.name||(qe.name=t);let e=qe,i=new Js(e,e.top,t);return e.top=i,i.state=1,i}function $v(t){return new Wv(t||new Uv)}function F(t){return new rl(t)}function hn(t,e,i){let n=V(t);n.handler=i;try{e(n)}catch(r){n.task.raise(r,n)}return n.result()}function Hv(t,e){return(qe?qe.getScheduler():nl||$v()).run(t,e)}var Uv=class{currentTime(){return new Date().valueOf()}setTimeout(t,e){return setTimeout(t,e)}clearTimeout(t){clearTimeout(t)}},Wv=class{constructor(t){u(this,"timer",t),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 qm,nl||(nl=this)}setSlice(t){this.slice=t}setTimeout(t){this.timeout=t}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let t=this.queue.peek().scheduledTime,e=this.timer.currentTime();if(this.timeoutToken!=null){if(e+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=t-e;i<=this.timeout&&(i=this.timeout),this.wakeupTime=e+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(t,e){let i=this.timer.currentTime();t.order=this.order++,t.scheduledTime=i+(e||0),this.queue.add(t),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let t=this.timer.currentTime();for(this.sliceOverTime=t+this.slice;this.queue.length();){let e=this.queue.peek();if(e.scheduledTime>t||(this.queue.remove(),e.canceled||e.resumeInternal(),t=this.timer.currentTime(),t>=this.sliceOverTime))break}}catch(t){Y.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let i=new Gv(this,e||"");i.top=new Js(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let o of i.callbacks)try{o()}catch(s){Y.error(s)}};try{t().then(o=>{i.result=o,r()})}catch(o){i.raise(o),r()}});let n=qe;return qe=i,this.schedule(i.top.suspend("bootstrap")),qe=n,i}},op=class{constructor(t){u(this,"task",t),u(this,"scheduledTime",0),u(this,"order",0),u(this,"result",null),u(this,"canceled",!1)}compare(t){let e=t;return e.scheduledTime-this.scheduledTime||e.order-this.order}getTask(){return this.task}schedule(t,e){this.result=t;let i=this.task;i&&i.scheduler.schedule(this,e)}resumeInternal(){let t=this.task;if(this.task=null,t&&t.continuation==this){t.continuation=null;let e=qe;return qe=t,t.top.finish(this.result),qe=e,!0}return!1}cancel(){this.canceled=!0}},Gv=class{constructor(t,e){u(this,"scheduler",t),u(this,"name",e),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(t){if(this.raise(t||new Error("E_TASK_INTERRUPT")),this!==qe&&this.continuation){this.continuation.cancel();let e=new op(this);this.waitTarget="interrupt",this.continuation=e,this.scheduler.schedule(e)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(t){this.callbacks.push(t)}join(){let t=V("Task.join");if(!this.running)t.finish(this.result);else{let e=t.suspend(this);this.whenDone(()=>{e.schedule(this.result)})}return t.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let t=this.exception;this.exception=null,this.top.handler(this.top,t)}else this.exception&&Y.error(this.exception,"Unhandled exception in task",this.name)}raise(t,e){if(this.fillStack(t),e){let i=this.top;for(;i&&i!=e;)i=i.parent;i==e&&(this.top=i)}this.exception=t,this.unwind()}fillStack(t){let e=t.frameTrace;if(!e){e=t.stack?`${t.stack}
7
7
  ---- async ---
8
- `:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
9
- `;e.frameTrace=t}}},Ba=class Sd{constructor(t){u(this,"value",t)}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Sd(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Ky=class{constructor(e){u(this,"frame",e)}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new Os(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 Ba(e)):new Ba(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}},Os=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 Ky(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=M("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(Y.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=M("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=M("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Ye;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Jy(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 xd(this.task);return this.task.continuation=t,Ye=null,this.task.waitTarget=e||null,t}},Jy=class extends Os{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Jr=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=Oa().getScheduler().run(()=>{let e=M("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){Y.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},Dn=e=>{if(e.length==0)return T(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=M("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()},Cd=`
8
+ `:"";for(let i=this.top;i;i=i.parent)e+=" ",e+=i.getName(),e+=`
9
+ `;t.frameTrace=e}}},rl=class sp{constructor(e){u(this,"value",e)}then(e){e(this.value)}thenAsync(e){return e(this.value)}thenReturn(e){return new sp(e)}thenFinish(e){e.finish(this.value)}isPending(){return!1}get(){return this.value}},jv=class{constructor(t){u(this,"frame",t)}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new Js(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return e.state=1,this.frame.parent=e,this.frame.then(i=>{t(i).then(n=>{e.finish(n)})}),e.result()}else return t(this.frame.res)}thenReturn(t){return this.isPending()?this.thenAsync(()=>new rl(t)):new rl(t)}thenFinish(t){this.isPending()?this.then(e=>{t.finish(e)}):t.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Js=class{constructor(t,e,i){u(this,"task",t),u(this,"parent",e),u(this,"name",i),u(this,"res",null),u(this,"state"),u(this,"callback",null),u(this,"handler",null),this.state=0}checkEnvironment(){if(!qe)throw new Error("F_TASK_NO_CONTEXT");if(this!==qe.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new jv(this)}finish(t){this.checkEnvironment(),qe&&!qe.exception&&(this.res=t),this.state=2;let e=this.parent;if(qe&&(qe.top=e),this.callback){try{this.callback(t)}catch(i){this.task.raise(i,e)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(t){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=t;break;case 2:{let e=this.task,i=this.parent;try{t(this.res),this.state=3}catch(n){this.state=3,e.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 t=V("Frame.timeSlice");return t.getScheduler().isTimeSliceOver()?(Y.debug("-- time slice --"),t.suspend().schedule(!0)):t.finish(!0),t.result()}sleep(t){let e=V("Frame.sleep");return e.suspend().schedule(!0,t),e.result()}loop(t){let e=V("Frame.loop"),i=n=>{try{for(;n;){let r=t();if(r.isPending()){r.then(i);return}else r.then(o=>{n=o})}e.finish(!0)}catch(r){e.task.raise(r,e)}};return i(!0),e.result()}loopWithFrame(t){let e=qe;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Xv(e,e.top);e.top=n,n.state=1,t(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(t){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let e=new op(this.task);return this.task.continuation=e,qe=null,this.task.waitTarget=t||null,e}},Xv=class extends Js{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},Qs=class{constructor(t,e){u(this,"fetch",t),u(this,"name"),u(this,"arrived",!1),u(this,"resource",null),u(this,"task",null),u(this,"piggybacks",[]),this.name=e}start(){this.task||(this.task=Hr().getScheduler().run(()=>{let t=V("Fetcher.run");return this.fetch().then(e=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=e,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](e)}catch(r){Y.error(r,"Error:")}t.finish(e)}),t.result()},this.name))}piggyback(t){this.arrived?t(this.resource):this.piggybacks.push(t)}get(){return this.arrived?F(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},Hn=t=>{if(t.length==0)return F(!0);if(t.length==1)return t[0].get().thenReturn(!0);let e=V("waitForFetches"),i=0;return e.loop(()=>{for(;i<t.length;){let n=t[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return F(!1)}).then(()=>{e.finish(!0)}),e.result()},ap=`
10
10
  @media screen {
11
11
  [data-vivliostyle-viewer-viewport] {
12
12
  background: #aaaaaa;
@@ -75,7 +75,7 @@ var Tg=Object.create;var lo=Object.defineProperty;var Ag=Object.getOwnPropertyDe
75
75
  transform-origin: center top;
76
76
  }
77
77
  }
78
- `,kd=`
78
+ `,lp=`
79
79
  [data-vivliostyle-layout-box] {
80
80
  position: absolute;
81
81
  left: 0;
@@ -198,7 +198,7 @@ var Tg=Object.create;var lo=Object.defineProperty;var Ag=Object.getOwnPropertyDe
198
198
  break-after: page;
199
199
  }
200
200
  }
201
- `,Ed=`
201
+ `,hp=`
202
202
  /*
203
203
  * Copyright 2013 Google, Inc.
204
204
  * Copyright 2015 Daishinsha Inc.
@@ -829,7 +829,7 @@ word-wrap = overflow-wrap;
829
829
  [adapt,webkit]start = inline-start;
830
830
  [adapt,webkit]end = inline-end;
831
831
 
832
- `,Pd=`
832
+ `,up=`
833
833
  <!DOCTYPE html>
834
834
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
835
835
  <head>
@@ -853,7 +853,7 @@ word-wrap = overflow-wrap;
853
853
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
854
854
 
855
855
  </body>
856
- </html>`,Nd=`
856
+ </html>`,cp=`
857
857
  @namespace "http://www.w3.org/1999/xhtml";
858
858
 
859
859
  :root {
@@ -976,7 +976,7 @@ word-wrap = overflow-wrap;
976
976
  margin: 10%;
977
977
  }
978
978
  }
979
- `,Td=String.raw`
979
+ `,dp=String.raw`
980
980
  @namespace "http://www.w3.org/1999/xhtml";
981
981
  @namespace m "http://www.w3.org/1998/Math/MathML";
982
982
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1407,7 +1407,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1407
1407
  epub|case[required-namespace::supported] ~ epub|default {
1408
1408
  display: none;
1409
1409
  }
1410
- `,Ad=`
1410
+ `,pp=`
1411
1411
  @namespace "http://www.w3.org/1999/xhtml";
1412
1412
 
1413
1413
  *:not([data-vivliostyle-role=doc-toc],
@@ -1417,6 +1417,10 @@ epub|case[required-namespace::supported] ~ epub|default {
1417
1417
  display: none;
1418
1418
  }
1419
1419
 
1420
+ /* An entry hidden from the printed table of contents is still listed in the
1421
+ viewer's TOC menu (see PR #1269). Nothing in Vivliostyle's own cascade is
1422
+ left to roll back to here, so the keyword reaches the browser, which reverts
1423
+ to the display of the element itself. */
1420
1424
  [hidden] {
1421
1425
  display: revert;
1422
1426
  }
@@ -1437,7 +1441,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1437
1441
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1438
1442
  -adapt-behavior: toc-container;
1439
1443
  }
1440
- `,Id=`
1444
+ `,fp=`
1441
1445
  [data-viv-margin-discard~="block-start"] {
1442
1446
  margin-block-start: 0 !important;
1443
1447
  }
@@ -1503,7 +1507,7 @@ span.viv-anonymous-block {
1503
1507
  /* see #2034 */
1504
1508
  @font-face {
1505
1509
  font-family: "-viv-ts-sp";
1506
- src: url("data:font/woff2;base64,d09GMgABAAAAAADcAAoAAAAAAhwAAACWAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAABmAANAoUNgE2AiQDDAsIAAQgBQYHLhuDAfivCuyG888wVNS8F/ZFrDP4HM9/f7Fz/327szNpE39MLJMEEwhM4rqEpw5WA/yHf662vHz4yq43QNDB8YgOIBcKMTAeaQjBDrH14HBRR74Oowl4tbBt3gYLxV0Fd2NjjGDXnS4ACk4ExYDAJc3tIYAgPOf4u3qBDwf8K4JaIACDfyIAgMIABFUBC6LutJhuZR3vCA==") format("woff2");
1510
+ src: url("data:font/woff2;base64,d09GMgABAAAAAADsAAoAAAAAAhwAAACkAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAABmAANAoUNgE2AiQDDAsIAAQgBQYHLhuDATAvDuxmH09wwcdQfVXDjoN4/uuenbvv/WombeKVxJoJmsgSDAIMQBNI2364+oJVIbt1VpdteYNucBxRTKkHHAAtsOCiG02Dh+ybQCFXG3XLx6aFAW6lt2nu/R/sYAIAJhgonJTgpE20Fsy1eGx9BUCBHYJCAxpAKsezAIKwvzuuv0MdwOvy2w0RlAHC9crGWiIAgIIGCEoJGCTsDC4sx/ZMAAA=") format("woff2");
1507
1511
  }
1508
1512
  viv-ts-open.viv-ts-auto > viv-ts-inner,
1509
1513
  viv-ts-open.viv-ts-trim > viv-ts-inner {
@@ -1646,7 +1650,7 @@ span[data-viv-leader] {
1646
1650
  -webkit-initial-letter: var(--viv-initialLetter);
1647
1651
  initial-letter: var(--viv-initialLetter);
1648
1652
  }
1649
- `,Fd=String.raw`
1653
+ `,gp=String.raw`
1650
1654
  @counter-style decimal-leading-zero {
1651
1655
  system: extends decimal;
1652
1656
  pad: 2 '0';
@@ -1870,12 +1874,12 @@ span[data-viv-leader] {
1870
1874
  @counter-style upper-russian {
1871
1875
  system: alphabetic;
1872
1876
  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;
1873
- }`;function Bs(e,t,i){let n=M("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var h;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(s.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(s.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?s.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=Rd([a]):t==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?Y.warn(`Error fetching ${e} (${s.status}${s.statusText?" "+s.statusText:""})`):Y.warn(a,`Error fetching ${e}`),o.schedule(s)}),n.result()}function Rd(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Qy(e){let t=M("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function ev(e){return URL.createObjectURL(e)}var Ml=class{constructor(e,t){u(this,"parser",e),u(this,"type",t),u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=pt(e);let n=this.resources[e];return typeof n<"u"?T(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=M("fetch"),r=Is(e);r&&(e=dn(e));let o=Ae("user-agent.xml",Ni),s=!r&&e===o;return s&&(e=`data:application/xml,${encodeURIComponent(Pd)}`),Bs(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e=Sa(e),a.url=Sa(a.url)):s&&(a.url=e=o),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=pt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Jr(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[pt(e)]}delete(e){delete this.resources[pt(e)]}};function tv(e,t){let i=e.responseText;return T(i?El(i):null)}function iv(){return new Ml(tv,"text")}function Et(e,t,i){let n=new Jr(()=>{let r=M("loadElement"),o=r.suspend(e),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);else(e.localName==="img"||e.localName==="embed"||e.localName==="object"||e.localName==="iframe")&&(e.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4));return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var iu=0,nv=16777216,Ld=33554432,Od=50331648,Bd=67108864,rv=83886080,ov=100663296,Ms=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 iu;case"User":return ov;default:return rv}}getBaseSpecificity(){switch(this.flavor){case"UA":return iu;case"User":return nv;default:return Ld}}},Ma=class extends Ms{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;Y.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)}},nu=class extends Ms{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()}},on=class extends nu{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new nu(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},$e=[],os=[],Se=[],_e=[],Vt=[],at=[],Ue=[],Ke=[],xe=[],tt=[],ct=[],je=[],Ve=[],vn=55,wn=56,po=57;$e[1]=28,$e[36]=29,$e[7]=29,$e[9]=29,$e[14]=29,$e[18]=29,$e[50]=29,$e[20]=30,$e[13]=27,$e[0]=200,os[1]=46,os[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,_e[37]=11,_e[23]=12,_e[35]=56,_e[1]=1,_e[36]=3,_e[7]=5,_e[9]=7,_e[14]=9,_e[18]=55,Vt[1]=2,Vt[36]=4,Vt[7]=6,Vt[9]=8,Vt[18]=14,Vt[50]=42,Vt[14]=10,Vt[12]=13,Ue[1]=15,Ue[7]=16,Ue[4]=17,Ue[5]=18,Ue[3]=19,Ue[2]=20,Ue[8]=21,Ue[27]=57,Ue[16]=22,Ue[19]=23,Ue[6]=24,Ue[11]=25,Ue[17]=26,Ue[13]=48,Ue[31]=47,Ue[23]=54,Ue[0]=44,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[vn]=2,Ve[wn]=2;var Qr=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(Me)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],e===")"&&o instanceof fn){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new J(i.slice(n+1,i.length))),e==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){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,s+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(s>1)return new Oe(this.extractVals(",",n+1));let a=i[0];return a instanceof ot?a:a?new fn(a.toString()):Me}exprError(e,t){this.actions=this.propName?ct:tt,Y.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(e==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new ym(n.getScope(),h,l);a.unshift(c)}return i.push(new j(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new yr(n.getScope(),ka(l,h),a),e=0;continue}}if(s==10){r.isMediaName()&&(r=new Bh(n.getScope(),r,null)),e=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new Ai(n.getScope(),r);else if(s==-24)r=new Cn(n.getScope(),r);else if(s==-po)r=new gm(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Ve[e]>Ve[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new Il(n.getScope(),o,r);break;case vn:r=new mm(n.getScope(),o,r);break;case wn:r=new vm(n.getScope(),o,r);break;case 25:r=new Fl(n.getScope(),o,r);break;case 38:r=new wm(n.getScope(),o,r);break;case 37:r=new xm(n.getScope(),o,r);break;case 48:r=new bm(n.getScope(),o,r);break;case 47:r=new Pa(n.getScope(),o,r);break;case 39:case 49:r=new Rl(n.getScope(),o,r);break;case 41:r=new Sm(n.getScope(),o,r);break;case 23:r=new Bc(n.getScope(),o,r);break;case 24:r=new Mc(n.getScope(),o,r);break;case 36:r=new Ll(n.getScope(),o,r);break;case 19:r=new _c(n.getScope(),o,r);break;case 21:r=new Dc(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new Em(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new Bh(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let 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 o=0,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=i.input.substring(n,h),c=t&&r==="selector"&&a>0?"":Xe(r)?l:l.trim();return new Pm(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,o=t.type===23||r;if(o&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Wt(i,t,new Ai(i,new Je(i,"pref-horizontal")));break;case"horizontal":t=Wt(i,t,new Je(i,"pref-horizontal"));break;case"day":t=Wt(i,t,new Ai(i,new Je(i,"pref-night-mode")));break;case"night":t=Wt(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,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,c,d,p,f,g,v,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===Ue&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new fn(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=ct):(this.actions=at,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ue,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=ct,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ue,h.splice(0,h.length);continue;case 29:this.actions=at,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=je,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(d,l.text),r?this.actions=_e:this.actions=Se,a.consume();break;case 36:s.tagSelector(d,null),r?this.actions=_e:this.actions=Se,a.consume();break;default:this.actions=tt,s.error("E_CSS_NAMESPACE",l)}else this.actions=tt,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=_e:this.actions=Se,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=je,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=_e:this.actions=Se,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=_e:this.actions=Se,a.consume();break;default:this.actions=tt,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=_e:this.actions=Se,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=_e:this.actions=Se,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=_e:this.actions=Se,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=_e:this.actions=Se;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=Se:this.actions=je;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){v=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(v.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(v=this.readNthPseudoParams(),v)if(p==="nth-child"||p==="nth-last-child"){if(c=a.nthToken(0),c.type===1&&c.text==="of"){a.consume(),this.actions=at,s.startFuncWithSelector(p,v),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=_e: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)v.push(c.text),a.consume();else break e;break}else break;else break e;default:if(v=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,v),a.consume(),r?this.actions=_e:this.actions=Se;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=tt;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=_e:this.actions=Se,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(v=this.readNthPseudoParams(),v===null)break}else v=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,v),r?this.actions=_e:this.actions=Se,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=tt;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:{if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=je,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=je,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=je,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(d,p,0,null,null),r?this.actions=_e:this.actions=Se,a.consume();continue;default:this.actions=je,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}let x=p,m=null;switch(l.type){case 1:case 2:{let S=l.text;if(a.consume(),l=a.token(),l.type==1){let b=l.text.toLowerCase();(b=="i"||b=="s")&&(m=b,a.consume(),l=a.token())}s.attributeSelector(d,x,f,S,m);break}default:this.actions=je,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=je,s.error("E_CSS_ATTR",l);continue}r?this.actions=_e:this.actions=Se,a.consume();continue}case 11:s.childSelector(),this.actions=Vt,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=Vt,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=Vt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=$e,a.consume();continue;case 41:s.nextSelector(),this.actions=at,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Xc(l.text)),a.consume();continue;case 17:h.push(new At(l.num)),a.consume();continue;case 18:h.push(new lt(l.num)),a.consume();continue;case 19:h.push(new O(l.num,l.text)),a.consume();continue;case 20:h.push(new K(l.text)),a.consume();continue;case 21:h.push(new Qe(Ae(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new qc(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(jn),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 fn("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?os:$e;continue;case 44:for(a.consume();h.length>0;){let x=h.length;if(g=this.valStackReduce(";",l),!g||h.length===x)break}return t?(this.result=g,!0):(this.propName&&g&&s.property(this.propName,g,this.propImportant),!0);case 31:if(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(s.getScope(),ka(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 Oh(s.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Oh(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==vn&&h[h.length-1]!==wn&&(c.type===10||c.type===6)){h.push(-po),a.consume();continue}else h.push(new Je(s.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(s.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 Xr(s.getScope(),l.num,p)),a.consume(),this.actions=xe;continue;case 34:h.push(new it(s.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 $c(s.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]!==wn&&h[h.length-2]!==-po?(this.actions=Ke,this.exprStackReduce(vn,l),h.push(vn),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==vn&&h[h.length-2]!==-po?(this.actions=Ke,this.exprStackReduce(wn,l),h.push(wn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Ue),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=$e)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=$e,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=$e,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let 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=$e,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ke,h.push("{");continue}s.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}s.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"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.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":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=Vt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let x=l.text;a.consume(),a.consume(),s.startFootnoteRule(x),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=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){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let x=null,m=null,S=[];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;)S.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(x,m,S);break;case"-epubx-partition":s.startPartitionRule(x,m,S);break;case"-epubx-partition-group":s.startPartitionGroupRule(x,m,S);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=je;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=tt;continue}s.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=$e;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=$e),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=at,w=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=$e),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){if(this.actions===je)switch(l.type){case 16:this.errorBrackets.length==0&&(s.nextSelector(),w=l.position+1,this.actions=at),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===at)s.error("E_CSS_SYNTAX",l);else{let x=a.input.substring(w,l.position);s.pushSelectorText(x),w=l.position+1}if(l.type===16){s.nextSelector(),this.actions=at,a.consume();continue}else return s.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=Se;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=je;continue}if(this.actions!==tt&&this.actions!==je&&this.actions!==ct){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===Ue){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new fn(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Ke&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=$e,a.consume();continue}else{if(l.type===17&&this.actions==Ke)return this.actions=$e,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=ct:this.actions=je;continue}a.consume();continue}}return!1}},Md=class extends Ms{constructor(e){super(null),u(this,"scope",e)}error(e,t){Y.warn(e,t.toString())}getScope(){return this.scope}};function sv(e,t,i,n,r){let o=_d(t),s=sy(e.input);return s!==e.input?ru(new xt(s,o),o,i,n,r):ru(e,o,i,n,r)}function ru(e,t,i,n,r){let o=M("parseStylesheet"),s=new Qr($e,e,t,i),a=null;return r&&(a=zd(new xt(r,t),t,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ae(s.importURL,i);s.importCondition&&(t.startMediaRule(s.importCondition),t.startRuleBody());let c=M("parseStylesheet.import");return Dd(l,t,null,null).then(()=>{s.importCondition&&t.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,c.finish(!0)}),c.result()}let h=o.timeSlice();if(h.isPending)return h}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function _l(e,t,i,n,r){let o=_d(t);return _n("parseStylesheetFromText",s=>{let a=new xt(e,o);sv(a,o,i,n,r).thenFinish(s)},(s,a)=>{Y.warn(a,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function _d(e){if(e instanceof Ma)return e;if(e instanceof on){if(e.owner)return e.owner;let t=new Ma;return t.flavor=e.flavor,t.slave=e,e.owner=t,t}return e}function Dd(e,t,i,n){return _n("parseStylesheetFromURL",r=>{Bs(e).then(o=>{o.responseText?_l(o.responseText,t,e,i,n).then(s=>{s||Y.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{Y.warn(o,"Exception while fetching and parsing:",e),r.finish(!0)})}function Ri(e,t,i){let n=new Qr(Ue,t,new Md(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function av(e,t,i){new Qr(os,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function zd(e,t,i){let n=new Qr(Ke,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var lv={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function hv(e){return!!lv[e]}function uv(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 hv(i)?n==Math.round(n)?new lt(n):new At(n):new O(n,"px");case"string":return n?i==="content"?new K(n):Ri(t.scope,new xt(n,null),""):Me;case"boolean":return n?y._true:y._false;case"undefined":return Me}throw new Error("E_UNEXPECTED")}var cv="data-vivliostyle-flow-root";function dv(e){return e.getAttribute(cv)==="true"}function ou(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function Fr(e){return e===y.absolute||e===y.fixed}function vr(e){return e instanceof ai&&e.name==="running"}function Vd(e,t,i,n){return e===y.none||(Fr(t)?(i=y.none,e=ou(e)):(i&&i!==y.none&&!Z(i)||n)&&(e=ou(e))),{display:e,position:t,float:i}}function Ud(e,t,i,n){return Vd(e,t,i,n).display===y.block}function _s(e){return e instanceof he||e instanceof J||typeof e=="string"}function Ut(e){if(!_s(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 ur(e){return _s(e)?e.toString().includes("list-item"):!1}function pv(e){if(!_s(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 $d(e){if(!_s(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 fv(e,t,i,n,r,o,s){return r=r||o||y.horizontal_tb,!!s||!!i&&i!==y.none&&!Z(i)||Fr(t)||e===y.inline_block||e===y.table_cell||e===y.table_caption||e==y.flex||e==y.grid||e==y.flow_root||(e===y.block||e===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!Z(n)||!!o&&r!==o}function gv(e){return e===y.relative||e===y.absolute||e===y.fixed}var ii=1e5;function Dl(e){let t=e.element.style;t.columnGap=`${ii-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ds(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function ss(e){return e.element.style.columnCount==="1"}function mv(e){e.element.setAttribute("data-vivliostyle-column","true")}function Rr(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/ii)}function zl(e,t){let i=Rr(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/ii),o=r*ii,s=i*ii;return t?(e.top-=o,e.bottom-=s,e.bottom<e.top&&(e.bottom+=ii),e.right-=o,e.left-=s):e.left<-ii/2?(e.right+=o,e.left+=s,e.left>e.right&&(e.left-=ii),e.top+=o,e.bottom+=s):(e.left-=o,e.right-=s,e.right<e.left&&(e.right+=ii),e.top+=o,e.bottom+=s),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function as(e,t){for(let i=0;i<e.length;i++)zl(e[i],t)}function Bt(e,t,i){let n=e.getElementClientRect(t);if(zl(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!eo(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Ds(r),e.getElementClientRect(t)}return n}function yv(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 _a(e){let t=e.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function vv(e){if(!e.hasAttribute("data-vivliostyle-column")&&_a(e))return!0;for(let t of e.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&_a(t))return!0;return!1}function eo(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(_a(t))return t;if(i.position==="absolute")break}return null}function wv(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((t=o.style)==null?void 0:t.breakAfter)==="column";if(!r&&!s)return;let a=eo(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",v=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),x=i.getBoundingClientRect();(f?x.top>w.bottom+v:g?x.right<w.left-v:x.left>w.right+v)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${ii}px`)}function fo(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?Rr(i,e.vertical):0}function Hd(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||fo(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&&eo(e.parentElement)){e.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(e.style.blockSize=`${r}px`,fo(t)){if(e.style.blockSize=`${n}px`,!fo(t)){let s=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;e.style.blockSize=`${l}px`,fo(t)?h=l:a=l}o=a,e.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/t.clientLayout.layoutUnitPerPixel;o=r+s,e.style.blockSize=`${o}px`}if(isNaN(o)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function bv(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)Hd(i,e)}function bn(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Ut(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.parentNode.insertBefore(s,o);let a=t.getElementClientRect(s);if(s.remove(),a){let h=[a];as(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&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=Bt(t,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return e.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);as(l,n);let c=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(c.length>0)l=c;else{let d=o?t.getElementComputedStyle(o).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(d=>d.left)):s=Math.max.apply(null,l.map(d=>d.bottom)),s):NaN}}function Da(e,t,i){let n=ss(t);n&&Ds(t);let r=t.clientLayout.getElementClientRect(e);n&&Dl(t);let o=t.getComputedMargin(e);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function En(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Wd(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 zn="data-adapt-spec";function Vl(e){return!!e.getAttribute(zn)}function Ot(e){return e?.nodeType!==1?!1:Vl(e)?!0:Gd(e)}function Gd(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function su(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function Pn(e){let t=e?.viewNode;return t?.nodeType===1&&Vl(t)}function xv(e){return e!=="inline"&&(Ut(e)||$d(e))}function au(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))&&Ut(i.display))return i;return null}function Sv(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 jd(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},o=e[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Xd(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=e.replace(s.regexp,s.to);if(a!==e)return a}return e}var qd={"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"}]}},Cv=jd(qd,!0);function Yd(e,t,i){return Xd(e,t,i||null,Cv)}var kv=jd(qd,!1);function Zd(e,t,i){return Xd(e,t,i||null,kv)}var Ev={"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 Pv(e,t){let i=Ev[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 Ul(e,t,i){var n;let r=t,o={width:r.style.width,height:r.style.height};function s(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function c(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=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 Nn(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 Kd(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Jd(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function Ct(e,t){let i=Kd(e);i.includes(t)||(i.push(t),Jd(e,i))}function Nv(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Tv(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function aa(e,t){let i=Nv(e);i.includes(t)||(i.push(t),Tv(e,i))}function Av(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===y.always?y.page:i,important:e.important};default:return e}}var za={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ze(e){return!!za[e]}var Iv={left:!0,right:!0,recto:!0,verso:!0};function en(e){return!!Iv[e]}function lu(e){return Ze(e)&&e!=="column"&&e!=="region"}var Fv={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ls(e){return!!Fv[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:ls(t)?t:ls(e)?e:t}}else return e;else return t}function hu(e){return Ze(e)?e:"auto"}Ft("SIMPLE_PROPERTY",Av);var wr=Gg(Xg());function Rv(e,t){return(0,wr.default)(e,t,0)}function uu(e){return e.reduce((t,i)=>i[0]===wr.default.DELETE?t:t+i[1],"")}function Lv(e,t){return Qd(e,t,1)}function Ov(e,t){return Qd(e,t,-1)}function Qd(e,t,i){let n=0,r=0;return e.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case wr.default.INSERT:n++;break;case wr.default.DELETE:n--,r++;break;case wr.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Va;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Va||(Va={}));var Rn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(Rn||(Rn={}));var hs;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(hs||(hs={}));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 Bv={transform:!0,"transform-origin":!0},Mv={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)}},_v={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 Dv(e,t){let i=_v[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Ua=class cr extends Tl{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,"pageFloatLayoutContext",null),u(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(cr.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(cr.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(cr.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(cr.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||I(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<t.length;o++){let s=t[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=Dv(a,s.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(s.event,l,!1)}}}};u(Ua,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Ua,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var ep=Ua,bt=yi.Whitespace;function tp(e){switch(e){case"normal":case"nowrap":return bt.IGNORE;case"pre-line":return bt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return bt.PRESERVE;default:return null}}function Ee(e,t){return e?e.nodeType==1?!1:ip(e.textContent,t):!0}function ip(e,t){switch(t){case bt.PRESERVE:return e.length==0;case bt.NEWLINE:return!!e.match(/^[ \t]*$/);case bt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var zv=class{constructor(e,t){u(this,"flowName",e),u(this,"parentFlowName",t),u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Vv=class{constructor(e,t,i,n,r,o,s,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",o),u(this,"repeated",s),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 Uv(e,t){return e.top-t.top}function $v(e,t){return t.right-e.right}function np(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&&$a(e.shadowContext,t.shadowContext)&&$a(e.nodeShadow,t.nodeShadow)&&np(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(!np(e.steps[i],t.steps[i]))return!1;return!0}function Hv(e){return{steps:[{node:e,shadowType:st.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function us(e,t){return{steps:[{node:e.sourceNode,shadowType:st.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function cs(e,t){let i=new xn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?cs(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var st=yi.ShadowType,Mo=class{constructor(e,t,i,n,r,o,s){u(this,"owner",e),u(this,"root",t),u(this,"xmldoc",i),u(this,"parentShadow",n),u(this,"type",o),u(this,"styler",s),u(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&$a(this.parentShadow,e.parentShadow):!1}};function $a(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Wv=class{constructor(e,t){u(this,"outer",e),u(this,"count",t)}},xn=class rp{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=st.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Rn.FloatReference.INLINE,this.whitespace=i?i.whitespace:bt.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=Rn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:bt.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 rp(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,o=[];r.shadowType===yi.ShadowType.ROOTLESS&&(r.floatReference!==Rn.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&o.push(r.toNodePositionStep()),r=r.parent;while(r);let s=this.preprocessedTextContent?Ov(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:o,offsetInNode:s,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Bi=class op{constructor(t){u(this,"primary",t),u(this,"floats",null)}clone(){let t=new op(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}},Gv=class sp{constructor(t,i){u(this,"chunkPosition",t),u(this,"flowChunk",i)}clone(){return new sp(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},jv=class ap{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new ap,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}},Xv=class lp{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 lp;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}},hp=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,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):Bl(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new Mt(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 Mt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return hd(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 Mt(e,t,e+i,t+n)}},Lr=class extends Kt{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!==Me&&e!==y.normal&&e!==y.none&&!Z(e)}var Pe=Rn.FloatReference,qv=20;function Yv(e){switch(e){case"inline":return Pe.INLINE;case"column":return Pe.COLUMN;case"region":return Pe.REGION;case"page":return Pe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Ii(e){switch(e){case Pe.INLINE:return!1;case Pe.COLUMN:case Pe.REGION:case Pe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function la(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Zd(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let o=Yd(e,r,i),s=Pv(o,r);s==="line-left"?e="left":s==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(Y.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var up=class{constructor(e,t,i,n,r,o){u(this,"nodePosition",e),u(this,"floatReference",t),u(this,"floatSide",i),u(this,"clearSide",n),u(this,"flowName",r),u(this,"floatMinWrapBlock",o),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}},Zv=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 o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},cp=class{constructor(e,t,i,n,r,o){u(this,"floatReference",e),u(this,"floatSide",t),u(this,"clearSide",i),u(this,"continuations",n),u(this,"area",r),u(this,"continues",o)}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},cu=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}},Sn=class{constructor(e,t,i,n,r,o,s){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,"lineFootnoteInvalidationMaxBlockSize",new Map),u(this,"lineFootnoteFinishInvalidatedOnce",new Set),u(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!Z(o)&&o||e&&e.writingMode||y.horizontal_tb,this.direction=!Z(s)&&s||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new Zv;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}addPageFloatLayoutContextAsPreviousSibling(e){this.children.push(e)}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let o=r-1;o>=0;o--){let s=this.children[o];if(s.floatReference===t&&s.flowName===i&&Oi(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,t,i,n),s))return s}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Vn().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e&&t.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var t;if(!("footnotePolicy"in e))return;let i=this;for(;i;)i.footnoteAnchorsSeen.add(e.getId()),i=(t=i.parent)!=null?t:i.outerContext}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t,this.markPageFloatAnchorSeen(e)}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}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}hasInvalidatedForLineFootnote(e){return e.floatReference===this.floatReference?this.lineFootnoteInvalidationMaxBlockSize.get(e.getId())===this.footnoteMaxBlockSize:this.getParent(e.floatReference).hasInvalidatedForLineFootnote(e)}markInvalidatedForLineFootnote(e){e.floatReference===this.floatReference?this.lineFootnoteInvalidationMaxBlockSize.set(e.getId(),this.footnoteMaxBlockSize):this.getParent(e.floatReference).markInvalidatedForLineFootnote(e)}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 o=r.float,s=o.getOrder();s>t&&(!i||s>i.getOrder())&&(i=o)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}hasRootMultiColumnFootnoteContext(){return this.children.some(e=>{let t=0;for(let i of e.children)if(!i.generatingNodePosition&&(t+=1,t>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(e=>e.children.some(t=>{var i;let n=(i=t.getContainer())==null?void 0:i.element;return n!=null&&vv(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(e){let t=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return t<qv?!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{let r=n&&"footnotePolicy"in i&&i.footnotePolicy===y.line;if(n&&this.footnoteAnchorsSeen.has(i.getId())&&(r||this.hasMultiColumnFootnoteContext())){let o=t.area.computedBlockSize+t.area.getInsetBefore()+t.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(o))return this.removePageFloatFragment(t),this.removeEndFloatFragments(t.floatSide),!0}this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)}return!0}}return this.floatReference===Pe.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e];if(t.continuations.some(i=>{let n=i.float;return"footnotePolicy"in n&&n.footnotePolicy===y.line&&!this.hasCurrentAnchor(n.getId())&&!this.floatsDeferredFromPrevious.some(r=>r.float===n)})){if(this.locked){this.invalidate();return}this.removePageFloatFragment(t);return}}if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--){let t=this.floatsDeferredToNext[e].float,i=this.findPageFloatFragment(t);if("footnotePolicy"in t&&t.footnotePolicy===y.line&&this.hasCurrentAnchor(t.getId())&&!i&&!this.lineFootnoteFinishInvalidatedOnce.has(t.getId())){if(this.locked){this.invalidate();return}this.lineFootnoteFinishInvalidatedOnce.add(t.getId()),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 Zd(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Yd(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let s of t){let a=this.toLogical(s);i.includes(a)||i.push(a)}let n=[],r=!1,o=!1;for(let s=0;s<i.length;s++){let a=i[s];a.includes("block")?r||(i.slice(s+1).some(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(o||(i.slice(s+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),o=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}isFragmentInCurrentContainer(e){var t;if(this.floatReference!==Pe.REGION)return!0;let i=e.area;return!i.parentElement||!((t=this.container)!=null&&t.element)||i.parentElement===this.container.element}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];this.isFragmentInCurrentContainer(r)&&(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r,o=!0,s){this.container;let a=this.toLogical(e),h=this.toPhysical(e),l=t&&this.toLogical(t),c=t&&this.toPhysical(t),d=this.getLimitValueInner(a,l,i,n,r,s);if(o&&this.parent&&this.parent.container){let p=this.parent.getLimitValue(h,c,i,n,r,o,s);switch(h){case"top":return Math.max(d,p);case"left":return Math.max(d,p);case"bottom":return Math.min(d,p);case"right":return Math.min(d,p);default:}}return d}getLimitValueInner(e,t,i,n,r,o){this.container;let s=this.getLimitValuesInner(i,n,r,e,t,o);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,o){var s,a,h,l;this.container;let c=this.container.originX,d=this.container.originY,p=this.container.getPaddingRect(),f={top:p.y1-d,left:p.x1-c,bottom:p.y2-d,right:p.x2-c,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let w=parseFloat((a=(s=this.container.element)==null?void 0:s.style)==null?void 0:a.width);isFinite(w)&&w>this.container.width&&(f.right+=w-this.container.width)}else{let w=parseFloat((l=(h=this.container.element)==null?void 0:h.style)==null?void 0:l.height);isFinite(w)&&w>this.container.height&&(f.bottom+=w-this.container.height)}function g(w,x,m){return w.unit==="%"?m*w.num/100:e.convertLengthToPx(w,x,t)}let v=this.floatFragments;return v.length>0&&(f=v.reduce((w,x)=>{if(x.area===o||!this.isFragmentInCurrentContainer(x)||i&&!i(x,this))return w;let[m,S]=this.toLogicalFloatSides(x.floatSide);if(S&&(n&&S.includes("block")===n.includes("block")&&S!==n||r&&S.includes("block")===r.includes("block")&&S!==r))return w;let b=x.area,C=x.continuations[0].float.floatMinWrapBlock,P=b.vertical?b.left+b.getInsetLeft()+b.width+b.getInsetRight():b.top+b.getInsetTop()+b.height+b.getInsetBottom(),L=b.vertical?b.top+b.getInsetTop()+b.height+b.getInsetBottom():b.left+b.getInsetLeft()+b.width+b.getInsetRight(),A=w.top,z=w.left,U=w.bottom,X=w.right,re=w.floatMinWrapBlockStart,k=w.floatMinWrapBlockEnd;switch(m){case"inline-start":b.vertical?A=Math.max(A,L):z=Math.max(z,L);break;case"block-start":b.vertical?(C&&b.left<X&&(re=g(C,b.rootViewNodes[0],p.x2-p.x1)),X=Math.min(X,b.left)):(C&&P>A&&(re=g(C,b.rootViewNodes[0],p.y2-p.y1)),A=Math.max(A,P));break;case"inline-end":b.vertical?U=Math.min(U,b.top):X=Math.min(X,b.left);break;case"block-end":b.vertical?(C&&P>z&&(k=g(C,b.rootViewNodes[0],p.x2-p.x1)),z=Math.max(z,P)):(C&&b.top<U&&(k=g(C,b.rootViewNodes[0],p.y2-p.y1)),U=Math.min(U,b.top));break;default:throw new Error(`Unknown logical float side: ${m}`)}return{top:A,left:z,bottom:U,right:X,floatMinWrapBlockStart:re,floatMinWrapBlockEnd:k}},f)),f.left+=c,f.right+=c,f.top+=d,f.bottom+=d,f}setFloatAreaDimensions(e,t,i,n,r,o,s){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;e.clientLayout;let h=a.find(P=>P.includes("inline")&&s[P==="inline-start"?"inline-end":"inline-start"]),l=a.find(P=>P.includes("block")),c=!0,d=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout,void 0,c,e),p=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout,void 0,c,e),f=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout,void 0,c,e),g=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout,void 0,c,e),v=e.vertical?e.originX:e.originY,w=e.vertical?e.originY:e.originX;e.isFootnote||(d=e.vertical?Math.min(d,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+v):Math.max(d,e.top+v),p=e.vertical?Math.max(p,e.left+v):Math.min(p,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+v));function x(P,L){let A=P(e.bands,L);return A?(e.vertical&&(A=sd(A)),d=e.vertical?Math.min(d,A.x2):Math.max(d,A.y1),p=e.vertical?Math.max(p,A.x1):Math.min(p,A.y2),!0):o}let m,S,b,C;if(r){let P=e.vertical?rs(new Mt(p,f,d,g)):new Mt(f,d,g,p);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!x(Vm,P)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!x(Um,P)||(e.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(e.vertical?d=Math.min(d,n):d=Math.max(d,n)),b=(p-d)*e.getBoxDir(),e.isFootnote&&this.footnoteMaxBlockSize!=null&&(b=Math.min(b,this.footnoteMaxBlockSize),e.vertical?d=p+b:d=p-b),m=Math.max(0,b-e.getInsetBefore()-e.getInsetAfter()),C=(g-f)*e.getInlineDir(),S=C-e.getInsetStart()-e.getInsetEnd(),!o&&(m<=0||S<=0)))return null}else{let P=e.getContentBlockMarginAfter();m=Math.max(0,e.computedBlockSize+Math.min(0,P)),b=m+e.getInsetBefore()+e.getInsetAfter();let L=(p-d)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let z=this.container.getPaddingRect(),U=this.container.getBoxDir()*(n-(this.container.vertical?z.x2:z.y1)),X=this.container.getBoxDir()*((this.container.vertical?z.x1:z.y2)-n-b);U<=X?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&L<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?S=Ul(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?S=e.getContentInlineSize():S=e.vertical?e.height:e.width,C=S+e.getInsetStart()+e.getInsetEnd();let A=(g-f)*e.getInlineDir();if(!o&&A<C)return null}if(d-=v,p-=v,f-=w,g-=w,a.some(P=>P==="inline-start"||P==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(f,S):(a.some(P=>P==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(g-C*e.getInlineDir(),S),a.some(P=>P==="block-start"||P==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline"))e.setBlockPosition(d,m);else if(a.some(P=>P==="block-end")||a.length===1&&a[0]==="inline-end"){let P=p-b*e.getBoxDir();e.setBlockPosition(P,m)}return a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-start")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x1:s.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let o=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.min(r,o):Math.max(r,o):o)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(o=>o.floatSide.includes("block-end")).filter(o=>{if(!isFinite(e))return!0;let s=o.getOuterRect();return n?s.y1<=e&&e<=s.y2:s.x1<=e&&e<=s.x2}).forEach(o=>{let s=o.getOuterRect(),a=n?s.x2:s.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let o=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(o)&&(r=isFinite(r)?n?Math.max(r,o):Math.min(r,o):o)}return r}getPageFloatClearEdge(e,t){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 o=t.getPaddingRect(),s=t.vertical?o.x1:o.y2,a=this;for(;a;){if(a.floatsDeferredToNext.some(n(a)))return s;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 s;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()<s*t.getBoxDir()?s:l}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=e.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function 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 s.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 s=n.getLimitValuesInner(t,i);r?e.vertical?(s.right<r.right&&(r.right=s.right,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>r.left&&(r.left=s.left,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>r.top&&(r.top=s.top,r.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<r.bottom&&(r.bottom=s.bottom,r.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):r=s,n=n.parent}let o=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=o}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},tr=[],Vn=class{static register(e){tr.push(e)}findByNodeContext(e){for(let t=tr.length-1;t>=0;t--){let i=tr[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=tr.length-1;t>=0;t--){let i=tr[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Kv=class{appliesToNodeContext(e){return Ii(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,o=e.toNodePosition(),s=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new up(o,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),T(h)})}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new cp(o.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return T(void 0)}forbid(e,t){}};Vn.register(new Kv);var dp="data-vivliostyle-footnote-first-ref",pp="data-vivliostyle-footnote-referenced";function ds(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function Pt(e){if(e.localName!=="aside")return!1;if(ds(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return ds(t,"footnote")}function Gt(e){if(e.localName!=="a")return!1;if(ds(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return ds(t,"noteref")}function Hl(e,t){if(!Gt(e))return null;let i=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=es(i,t);return n==="#"?null:n}function fp(e,t,i){let n=Hl(e,t);if(!n)return null;let r=i(n);return r&&Pt(r)?r:null}function Jv(e,t,i,n,r){if(r.value)return;let o=e.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=Hl(a,t);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function du(e,t,i,n,r){if(e.localName!=="a"||!Gt(e))return!0;let o=Hl(e,t);if(!o)return!0;Jv(e.ownerDocument,t,i,n,r);let s=n.get(o);return s==null||i(e)===s}function Wl(e,t){let i=t.getProp(e,"footnote-display");if(i)return i;let n=t.getProp(e,"display");return n?.value===y.inline?t.createCascadeValue(y.inline,n.priority):null}function Qv(e,t,i,n,r,o,s){if(e.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||e.localName!=="include"||!e.classList.contains("-vivliostyle-footnote-content"))return t;let a=i?.owner;if(!(a instanceof Element)||!Gt(a))return t;let h=fp(a,n,r);if(!h)return t;let l=a.getAttribute(o);l?(e.setAttribute(o,l),h.setAttribute(o,l)):(e.removeAttribute(o),h.removeAttribute(o));let c=s.getStyle(h);if(!c)return t;let d={...t},p=Wl(c,s),f=s.getProp(c,"footnote-policy"),g=s.getStyleMap(c,"_pseudos"),v=g?.after;if(p&&(d["footnote-display"]=p),f&&(d["footnote-policy"]=f),v){let w=s.getMutableStyleMap(d,"_pseudos");w.after={...v}}return d}function ew(e,t,i,n,r){var o;if(!(i?.type===st.ROOTED&&Pt(e)))return t;let s=r.getStyle(e);if(!s)return t;let a={...t},h=Wl(s,r),l=r.getProp(s,"footnote-policy"),c=r.getStyleMap(s,"_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&&((o=f?.evaluate)==null?void 0:o.call(f,n,"list-style-position"))===y.outside){let g=r.filterFootnoteMarkerContent(p,e);a["--viv-marker-content"]=r.createCascadeValue(g,0),a.display=r.createCascadeValue(B("list-item"),0),a["list-style-position"]=r.createCascadeValue(y.outside,0),a["list-style-type"]=r.createCascadeValue(y.none,0),a["list-style-image"]=r.createCascadeValue(y.none,0)}return a}function tw(e,t,i){var n,r;let o=t?.type===st.ROOTED&&Pt(e)?i.getStyle(e):null;return{sourceStyle:o,footnoteDisplay:((n=Wl(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function gp(e,t){if(e instanceof j){let i=e.expr.evaluate(t);return typeof i=="string"?new K(i):typeof i=="number"?new K(String(i)):e}return e instanceof J?new J(e.values.map(i=>gp(i,t))):e}function iw(e,t,i){let n=e?.["_footnote-marker-content"];n&&(t["--viv-marker-content"]=gp(n.value,i))}function nw(e){let t=e.getElementsByTagName("a"),i=new Set;for(let n=0;n<t.length;n++){let r=t.item(n);if(!Gt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=e.getElementById(o);if(s&&Pt(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(dp,"true")),s.setAttribute(pp,"true")}}}Ft("PREPROCESS_SINGLE_DOCUMENT",nw);var rw=cp,ow=.1,Or=class mp extends up{constructor(t,i,n,r,o,s){super(t,i,"block-end",null,n,o),u(this,"footnotePolicy",r),u(this,"policyAnchorNode",s)}isAllowedToPrecede(t){return!(t instanceof mp)}};function sw(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 yp(e){return e?-1:1}function Ha(e,t){return t?e.right:e.top}function Gl(e,t){return t?e.left:e.bottom}function vp(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom,width:e.width,height:e.height}}function wp(e,t){let i=vp(e.getBoundingClientRect());return zl(i,t),i.right<i.left||i.bottom<i.top?null:i}function Wa(e,t){let i=Array.from(e,vp);return as(i,t),i.filter(n=>n.right>n.left&&n.bottom>n.top)}function bp(e,t){return e.length?t?Math.min(...e.map(i=>i.left)):Math.max(...e.map(i=>i.bottom)):NaN}function aw(e,t){if(!e.length)return NaN;let i=yp(t),n=e.reduce((r,o)=>Ha(o,t)*i<Ha(r,t)*i?o:r);return Gl(n,t)}function lw(e,t){if(!e)return NaN;if(e.nodeType===Node.ELEMENT_NODE){let o=wp(e,t);return o?Gl(o,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=Wa(n.getClientRects(),t);return bp(r,t)}function hw(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=wp(a,t);if(l)return e.after?Gl(l,t):Ha(l,t)}let h=Wa(a.getClientRects(),t);return aw(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 o=i.ownerDocument.createRange();o.setStart(i,r),o.setEnd(i,r+1);let s=Wa(o.getClientRects(),t);return bp(s,t)}var pu=class extends rw{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Or?!0:this.getOrder()<e.getOrder()}},uw=class{constructor(e,t,i){u(this,"footnote",e),u(this,"vertical",i),u(this,"anchorEdge"),this.anchorEdge=lw(t,i)}allowLayout(e){if(!isNaN(this.anchorEdge)){let i=hw(e,this.vertical);if(!isNaN(i)){let n=yp(this.vertical);return i*n<this.anchorEdge*n-ow}}let t=e.toNodePosition();return!Oi(t,this.footnote.nodePosition)}},cw=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Or}createPageFloat(e,t,i){var n;let r=Pe.REGION,o=t.getPageFloatLayoutContext(r);t.getPageFloatLayoutContext(Pe.PAGE).hasSameContainerAs(o)&&(r=Pe.PAGE);let s=!!t.generatingNodePosition;s&&r!==Pe.PAGE&&(r=Pe.PAGE);let a=e.toNodePosition();t.flowName;let h=e.sourceNode,l=(n=e.shadowContext)==null?void 0:n.owner;l instanceof Element&&Gt(l)&&(h=l),h=sw(h);let c=new Or(a,r,t.flowName,e.footnotePolicy,e.floatMinWrapBlock,h);if(c.insidePageFloatArea=s,s){let d=t.generatingNodePosition;d&&(c.parentPageFloat=t.findPageFloatByNodePosition(d))}return t.addPageFloat(c),T(c)}createPageFloatFragment(e,t,i,n,r){let o=e[0].float;return new pu(o.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference),n=i.getContainer(e.floatReference).element,r=i.floatFragments.filter(o=>o instanceof pu&&(e.floatReference!==Pe.REGION||!o.area.parentElement||o.area.parentElement===n));return r.find(o=>o.hasFloat(e))||r[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=e.vertical?e.paddingLeft+e.paddingRight+e.borderLeft+e.borderRight:e.paddingTop+e.paddingBottom+e.borderTop+e.borderBottom,l=e.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],c=getComputedStyle(n);for(let d of l){let p=c.getPropertyValue(d);if(p&&p!=="none"){let f=parseFloat(p);isNaN(f)||I(n,d,`${Math.max(0,f-h)}px`)}}I(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){I(n,"max-block-size",""),I(n,e.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return T(void 0)})}forbid(e,t){let i=e;if(i.footnotePolicy===y.line){let n=t.collectPageFloatAnchors()[i.getId()]||null,r=new uw(i,n,t.getContainer(i.floatReference).vertical);t.addLayoutConstraint(r,i.floatReference)}}};Vn.register(new cw);var jl=class{calculateOffset(e){return Ln(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Ln(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var to=class extends jl{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(ls(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=bn(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(e.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},ir=class{find(e){let t=_t("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()}`)}},Tn=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 to(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&&Pn(i))return;let o=i.viewNode;((r=o.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let s=o.parentNode;Wd(s,o),n&&s.removeChild(o)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),T(!0)}},Xl=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){}},ql=new Tn,dw=Va.isInstanceOfBlockFormattingContext;Ft("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,o)=>{let s=e.parent;return!s&&e.formattingContext||s&&e.formattingContext!==s.formattingContext?null:e.establishesBFC||!e.formattingContext&&Ud(i,n,r,o)?new Xl(s?s.formattingContext:null):null});Ft("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Xl?ql:null);var Yl=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=M("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let o=n.accept(r,t);o=n.postLayout(r,this.initialPosition,t,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},pw=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){}},Ga=class{constructor(e,t){u(this,"strategy",e),u(this,"layoutContext",t)}iterate(e){let t=this.strategy,i=t.initialState(e),n=M("LayoutIterator");return n.loopWithFrame(r=>{let o;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ee(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?o=t.afterIgnoredTextNode(i):o=t.startIgnoredTextNode(i):i.nodeContext.after?o=t.afterNonElementNode(i):o=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?o=t.afterInlineElementNode(i):o=t.startInlineElementNode(i):i.nodeContext.after?o=t.afterNonInlineElementNode(i):o=t.startNonInlineElementNode(i):i.nodeContext.after?o=t.afterNonDisplayableNode(i):o=t.startNonDisplayableNode(i);let s=(o&&o.isPending()?o:T(!0)).thenAsync(()=>i.break?T(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},br=class extends pw{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:T(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:T(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}},ja=[];function fw(){ja=[]}var go;function mo(e){if(e==="")return 0;if(go===void 0){let i=Intl.Segmenter;go=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(go===null)return[...e].length;let t=0;for(let i of go.segment(e))t++;return t}var gw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],mw=new Set(gw);function yw(e){return!(e.toLowerCase()==="none"||mw.has(e))}var vw=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],ww=new Set(vw),bw=["fixed","extends"],xw=new Set(bw);function io(e){return e instanceof he&&e.name.toLowerCase()!=="none"}function xp(e){return e.name}function Sw(e){if(e instanceof he)return ww.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 xw.has(n)&&(n==="fixed"&&i instanceof lt||n==="extends"&&io(i))}}return!1}function Cw(e){let t=dt(e,"system");return t instanceof he&&t.name==="cyclic"}function kw(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 Ew(e){let t=dt(e,"system");return t instanceof he?1:t.values[1].num}function Pw(e){let t=dt(e,"system");return t instanceof he&&t.name==="alphabetic"}function Nw(e){let t=dt(e,"system");return t instanceof he&&t.name==="numeric"}function Tw(e){let t=dt(e,"system");return t instanceof he&&t.name==="additive"}function Aw(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"&&io(n)}return!1}function Iw(e){let t=dt(e,"system");return xp(t.values[1])}function jt(e){return e instanceof K||e instanceof he}function fi(e){return e instanceof K?e.str:e.name}function Sp(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 Fw(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 fu(e){return e instanceof lt||e instanceof he&&e.name==="infinite"}function ps(e,t){return e instanceof lt?e.num:t?-1/0:1/0}function Xa(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(fu(t)&&fu(i)))return!1;let n=ps(t,!0),r=ps(i,!1);return!(n>r)}function Rw(e){return{lower:ps(e.values[0],!0),upper:ps(e.values[1],!1)}}function Cp(e){return e instanceof he&&e.name==="auto"||Xa(e)||e instanceof Oe&&e.values.length>=1&&e.values.every(t=>Xa(t))}function Lw(e){return e instanceof he?null:(Xa(e)?[e]:e.values).map(t=>Rw(t))}function fs(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 gs(e){let[t,i]=e.values;return t instanceof lt?[t.num,fi(i)]:[i.num,fi(t)]}function kp(e){return fs(e)}function Ow(e){let[t,i]=gs(e);return{minLength:t,symbol:i}}function Ep(e){return jt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>jt(t))}function Bw(e){return jt(e)?[fi(e)]:e.values.map(t=>fi(t))}function Pp(e){if(fs(e))return!0;if(e instanceof Oe&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!fs(i))return!1;let[n]=gs(i);if(n>=t)return!1;t=n}return!0}return!1}function Mw(e){if(fs(e)){let[t,i]=gs(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=gs(t);return{weight:i,symbol:n}})}var _w=["auto","bullets","numbers","words","spell-out"],Dw=new Set(_w);function zw(e){return e instanceof he&&Dw.has(e.name)||io(e)}function Vw(e,t){switch(e){case"system":return Sw(t);case"negative":return Sp(t);case"prefix":case"suffix":return jt(t);case"range":return Cp(t);case"pad":return kp(t);case"fallback":return io(t);case"symbols":return Ep(t);case"additive-symbols":return Pp(t);case"speak-as":return zw(t);default:return!0}}function dt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function Uw(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Un(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var _o,Do,zo,Vo,Uo,$o,Ho,Wo,yo,ci,Np,vo,Tp,wo,Ap,bo,Ip,xo,Fp,So,Rp,Co,Lp,wt,ha,Op,Bp,gu,mu,ua,yu,dr,ze=class Hi{constructor(t,i){ie(this,wt),u(this,"_store"),ie(this,_o),ie(this,Do),ie(this,zo),ie(this,Vo),ie(this,Uo),ie(this,$o),ie(this,Ho),ie(this,Wo),this._store=t;let n=dt(i,"negative");de(this,_o,n&&Sp(n)?Fw(n):null);let r=dt(i,"prefix");de(this,Do,r&&jt(r)?fi(r):null);let o=dt(i,"suffix");de(this,zo,o&&jt(o)?fi(o):null);let s=dt(i,"range");de(this,Vo,s&&Cp(s)?Lw(s):null);let a=dt(i,"pad");de(this,Uo,a&&kp(a)?Ow(a):null);let h=dt(i,"fallback");de(this,$o,h&&io(h)?xp(h):null);let l=dt(i,"symbols");de(this,Ho,l&&Ep(l)?Bw(l):null);let c=dt(i,"additive-symbols");de(this,Wo,c&&Pp(c)?Mw(c):null)}static create(t,i){return Cw(i)?new _i(t,i):kw(i)?new $w(t,i):Pw(i)?new Ww(t,i):Nw(i)?new vu(t,i):Tw(i)?new Gw(t,i):Aw(i)?new jw(t,i):new Hw(t,i)}static createDecimal(t){var i;return new vu(t,le(i=Hi,ci,Np).call(i))}static createDisc(t){var i;return new _i(t,le(i=Hi,ci,Tp).call(i))}static createSquare(t){var i;return new _i(t,le(i=Hi,ci,Ap).call(i))}static createCircle(t){var i;return new _i(t,le(i=Hi,ci,Ip).call(i))}static createDisclosureOpen(t){var i;return new _i(t,le(i=Hi,ci,Fp).call(i))}static createDisclosureClosed(t){return new _i(t,le(this,ci,Rp).call(this))}static createNone(t){var i;return new _i(t,le(i=Hi,ci,Lp).call(i))}static get CHINESE_LONGHAND_NAMES(){return wu.NAMES}static createChineseLonghand(t,i){return new wu(t,i)}static createEthiopicNumeric(t){return new qw(t)}_getNegative(){return H(this,_o)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return H(this,Do)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return H(this,zo)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return H(this,Vo)}static _getRangeFrom(t){return t._getRange()}_getPad(){return H(this,Uo)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(H(this,$o)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return H(this,Ho)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return H(this,Wo)}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,wt,dr).call(this,t,new Set)}formatMarker(t){return le(this,wt,Op).call(this)+this.format(t)+le(this,wt,Bp).call(this)}};_o=new WeakMap,Do=new WeakMap,zo=new WeakMap,Vo=new WeakMap,Uo=new WeakMap,$o=new WeakMap,Ho=new WeakMap,Wo=new WeakMap,yo=new WeakMap,ci=new WeakSet,Np=function(){var e;return(e=H(ze,yo))!=null?e:de(ze,yo,{system:new W(B("numeric"),0),symbols:new W(new J([new K("0"),new K("1"),new K("2"),new K("3"),new K("4"),new K("5"),new K("6"),new K("7"),new K("8"),new K("9")]),0)})},vo=new WeakMap,Tp=function(){var e;return(e=H(ze,vo))!=null?e:de(ze,vo,{system:new W(B("cyclic"),0),symbols:new W(new K("\u2022"),0),suffix:new W(new K(" "),0)})},wo=new WeakMap,Ap=function(){var e;return(e=H(ze,wo))!=null?e:de(ze,wo,{system:new W(B("cyclic"),0),symbols:new W(new K("\u25AA"),0),suffix:new W(new K(" "),0)})},bo=new WeakMap,Ip=function(){var e;return(e=H(ze,bo))!=null?e:de(ze,bo,{system:new W(B("cyclic"),0),symbols:new W(new K("\u25E6"),0),suffix:new W(new K(" "),0)})},xo=new WeakMap,Fp=function(){var e;return(e=H(ze,xo))!=null?e:de(ze,xo,{system:new W(B("cyclic"),0),symbols:new W(new K("\u25BE"),0),suffix:new W(new K(" "),0)})},So=new WeakMap,Rp=function(){var e;return(e=H(ze,So))!=null?e:de(ze,So,{system:new W(B("cyclic"),0),symbols:new W(new K("\u25B8"),0),suffix:new W(new K(" "),0)})},Co=new WeakMap,Lp=function(){var e;return(e=H(ze,Co))!=null?e:de(ze,Co,{system:new W(B("cyclic"),0),symbols:new W(new K(""),0),suffix:new W(new K(""),0)})},wt=new WeakSet,ha=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Op=function(){var e;return(e=this._getPrefix())!=null?e:""},Bp=function(){var e;return(e=this._getSuffix())!=null?e:". "},gu=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},mu=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},ua=function(){var e;return(e=this._getFallback())!=null?e:Un(this._store)},yu=function(e,t){let{minLength:i,symbol:n}=le(this,wt,mu).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:o}=le(this,wt,ha).call(this),s=t?mo(r)+(o?mo(o):0):0,a=i-mo(e)-s;if(a<=0)return e;let h=mo(n),l=Math.ceil(a/h);return n.repeat(l)+e},dr=function(e,t){var i,n,r;if(t.has(this))return le(i=Un(this._store),wt,dr).call(i,e,new Set);if(t.add(this),!Uw(e,le(this,wt,gu).call(this))){let l=le(this,wt,ua).call(this);return le(n=l,wt,dr).call(n,e,t)}let o=this._usesNegativeSign(e),s=o?Math.abs(e):e,a=this._generateInitialRepresentation(s);if(a===null){let l=le(this,wt,ua).call(this);return le(r=l,wt,dr).call(r,e,t)}let h=le(this,wt,yu).call(this,a,o);if(o){let{prefix:l,suffix:c}=le(this,wt,ha).call(this);h=l+h+(c??"")}return h},ie(ze,ci),ie(ze,yo,null),ie(ze,vo,null),ie(ze,wo,null),ie(ze,bo,null),ie(ze,xo,null),ie(ze,So,null),ie(ze,Co,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]}},Go,$w=class extends ce{constructor(e,t){super(e,t),ie(this,Go),de(this,Go,Ew(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,Go);return(t=i[n])!=null?t:null}};Go=new WeakMap;var Hw=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)}},Ww=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}},vu=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}},Gw=class extends ce{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(o=>o.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},xr,kt,Lt,Mp=class extends ce{constructor(t,i){super(t,i),ie(this,kt),ie(this,xr);let n=Iw(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?de(this,xr,r):de(this,xr,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(le(this,kt,Lt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(le(this,kt,Lt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(le(this,kt,Lt).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(le(this,kt,Lt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(le(this,kt,Lt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(le(this,kt,Lt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(le(this,kt,Lt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(le(this,kt,Lt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(le(this,kt,Lt).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(le(this,kt,Lt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(le(this,kt,Lt).call(this),t)}};xr=new WeakMap,kt=new WeakSet,Lt=function(e=new Set){var t;if(e.has(this))return Un(this._store);e.add(this);let i=this._store.get(H(this,xr));return i?i instanceof Mp?le(t=i,kt,Lt).call(t,e):i:Un(this._store)};var jw=Mp,Xw=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"];function nr(e){return{suffix:new W(new K("\u3001"),0),fallback:new W(B("cjk-decimal"),0),range:new W(new J([new lt(-9999),new lt(9999)]),0),negative:new W(new K(e),0)}}var ca,da,ko,pa,Eo,qa,_p,jo,vt=class Dp extends ce{constructor(t,i){var n;let{chars:r,descriptors:o}=le(n=Dp,qa,_p).call(n).get(i);super(t,o),ie(this,jo),de(this,jo,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=H(this,jo);if(t===0)return i.digits[0];let n=[],r=0,o=t;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&t>=10&&t<=19,a="",h=!1;for(let l=0;l<n.length;l++){let{digit:c,position:d}=n[l],p=l===n.length-1;c===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),s&&d===1?a+=i.markers[d]:(a+=i.digits[c],d>0&&(a+=i.markers[d])))}return a}};ca=new WeakMap,da=new WeakMap,ko=new WeakMap,pa=new WeakMap,Eo=new WeakMap,qa=new WeakSet,_p=function(){var e;return(e=H(vt,Eo))!=null?e:de(vt,Eo,new Map([["simp-chinese-informal",{chars:H(vt,ca),descriptors:nr("\u8D1F")}],["simp-chinese-formal",{chars:H(vt,da),descriptors:nr("\u8D1F")}],["trad-chinese-informal",{chars:H(vt,ko),descriptors:nr("\u8CA0")}],["trad-chinese-formal",{chars:H(vt,pa),descriptors:nr("\u8CA0")}],["cjk-ideographic",{chars:H(vt,ko),descriptors:nr("\u8CA0")}]]))},jo=new WeakMap,ie(vt,qa),ie(vt,ca,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(vt,da,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ie(vt,ko,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ie(vt,pa,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),u(vt,"NAMES",new Set(Xw)),ie(vt,Eo,null);var wu=vt,Po,Ya,zp,Za,ms,Ka,Ja,hi=class Wi extends ce{constructor(t){var i;super(t,le(i=Wi,Ya,zp).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,ms)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let c=Math.floor(a/10),d=a%10;o+=H(Wi,Za)[c]+H(Wi,ms)[d]}h?a!==0&&(o+=H(Wi,Ka)):s!==0&&(o+=H(Wi,Ja))}return o}};Po=new WeakMap,Ya=new WeakSet,zp=function(){var e;return(e=H(hi,Po))!=null?e:de(hi,Po,{range:new W(new J([new lt(1),B("infinite")]),0),suffix:new W(new K("/ "),0)})},Za=new WeakMap,ms=new WeakMap,Ka=new WeakMap,Ja=new WeakMap,ie(hi,Ya),ie(hi,Po,null),ie(hi,Za,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ie(hi,ms,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ie(hi,Ka,"\u137B"),ie(hi,Ja,"\u137C");var qw=hi,Re,Yw=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(!yw(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:Un(H(this,Re))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Un(H(this,Re))).formatMarker(t)}};Re=new WeakMap;var An=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)}},rr=class Vp{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 Vp;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new An(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,o=new An(bu);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,r);let s=new 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(s)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new An(bu);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 An(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 o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<t.connections.length;o++){let s=t.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+r);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+r);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Zw=1,ys=2,Up=4,Si=8,Zi=16,$n=32,On=64,vs=128,ni=256,ri=512,ws=1024,$p=2048,Hp=4096,bs=8192,Zl=class extends Kt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},ue=class Wp extends Zl{constructor(t,i,n){super(),u(this,"allowed",t),u(this,"idents",i),u(this,"units",n)}visitEmpty(t){return this.allowed&Zw?t:null}visitSlash(t){return this.allowed&$p?t:null}visitStr(t){return this.allowed&ys?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Up||this.allowed&On&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&ri)?t.unit=="%"&&this.allowed&ws?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&On&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&vs?t:null}visitURange(t){return this.allowed&Hp?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(t.name.toLowerCase()==="attr"){let i=eh(t);if(i&&tb(i.type,this.allowed,this.units))return t}if(this.allowed&On){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Qc(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&bs){let i=t.visit(new id);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Si|Zi|$n|ni|ri|ws)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Wp(this.allowed|t.allowed,i,n)}},te=Object.create(null),Kw=Zi|ni|ri,Jw=$n|ni|ri,zi=Si|ni|ri|ws;function no(e){let t=Object.create(null);for(let i of e)t[i]=Me;return t}var zs=no(["%"]),Vs=no(["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"]),Gp={...Vs,...zs},Kl=no(["deg","grad","rad","turn"]),Jl=no(["s","ms"]),Ql=no(["hz","khz"]);function Qw(e){return e.replace(/\s+/g,"").toLowerCase()}function Us(e){return e.toLowerCase()}function eb(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:Us(e.name)}}if(e instanceof ai&&e.name.toLowerCase()==="type"){if(e.values.length!==1)return null;let t=Qw(e.values[0].stringValue());return t?{kind:"syntax",syntax:t}:null}return null}function eh(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 o=r.values;if(o.length<1||o.length>2||!(o[0]instanceof he)||(i=o[0].name,o.length===2&&(n=eb(o[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(t=e.values[1])!=null?t:null}}function jp(e,t){return!!e[Us(t)]}function un(e,t){return Object.keys(t).some(i=>jp(e,i))}function tb(e,t,i){switch(e.kind){case"string":return!!(t&ys);case"url":return!!(t&(vs|bs));case"unit":return jp(i,e.unit);case"syntax":switch(e.syntax){case"<string>":return!!(t&ys);case"<url>":return!!(t&(vs|bs));case"<color>":return!!(t&On);case"<integer>":return!!(t&($n|Zi|ni|ri));case"<number>":return!!(t&(Zi|$n|ni|ri));case"<length>":return un(i,Vs);case"<length-percentage>":return un(i,Gp);case"<percentage>":return un(i,zs);case"<angle>":return un(i,Kl);case"<time>":return un(i,Jl);case"<frequency>":return un(i,Ql);default:return!1}}return!1}function Qa(e){switch(e.kind){case"string":return null;case"url":return null;case"unit":return new ue(zi,te,{[Us(e.unit)]:Me});case"syntax":switch(e.syntax){case"<color>":return new ue(On,te,te);case"<integer>":return new ue(Jw,te,te);case"<number>":return new ue(Kw,te,te);case"<length>":return new ue(zi,te,Vs);case"<length-percentage>":return new ue(zi,te,Gp);case"<percentage>":return new ue(zi,te,zs);case"<angle>":return new ue(zi,te,Kl);case"<time>":return new ue(zi,te,Jl);case"<frequency>":return new ue(zi,te,Ql);default:return null}}return null}function ib(e){switch(e.kind){case"string":case"url":case"unit":return!0;case"syntax":return e.syntax==="<string>"||e.syntax==="<url>"||!!Qa(e)}return!1}function nb(e){switch(e.kind){case"url":return new Qe("about:invalid");case"string":return new K("");default:return y.unset}}function rb(e,t,i){if(t==null)return null;switch(i.kind){case"string":return new K(t);case"url":return t?new Qe(t):new Qe("about:invalid");case"unit":{let n=Ri(e,new xt(`${t.trim()}${Us(i.unit)}`,null),""),r=Qa(i);return n&&r?n.visit(r):null}case"syntax":{if(i.syntax==="<string>")return new K(t);if(i.syntax==="<url>")return t?new Qe(t):new Qe("about:invalid");let n=Ri(e,new xt(t,null),""),r=Qa(i);return n&&r?n.visit(r):null}}return null}var bu=new ue(0,te,te),th=class extends Zl{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new An(null),this.failureTerminal=new An(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=e.length){r=r.failure;continue}let h=e[o],l=h;if(r.isSpecial()){let c=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":c=a[r.getAlternate()]==null,r=c?r.success:r.failure}else{if(o==0&&!t&&r.validator instanceof Sr&&this instanceof Sr){if(l=new J(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else if(o==0&&!t&&r.validator instanceof ih&&this instanceof Sr){if(l=new Oe(e).visit(r.validator),l){o=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<o;c++)n[c]=e[c]}e!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:o==e.length)?n:null}validateSingle(e){let t=this.validateList([e],!1,0);return t?t[0]:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Sr=class extends th{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 ih){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new Oe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},ih=class extends th{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 Oe(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}},ob=class extends th{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}},xu=class extends Zl{validateSingle(e){return null}visitFunc(e){let t=eh(e);return t&&ib(t.type)?e:null}},Xp=class{tryParse(e,t,i){return t}success(e,t){}},qp=class extends Xp{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,o=r>1?new J(n):n[0];return this.success(o,i),t+r}return t}success(e,t){t.values[this.name]=e}},sb=class extends qp{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}},ab=class extends Xp{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]==jn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let o=1;o<this.nodes.length&&t<e.length&&(r=this.nodes[o].tryParse(e,t,i),r!=t);o++)t=r;return t}},$s=class extends Kt{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 qp(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Xn=class extends $s{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}},Yp=class extends $s{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new sb(this.validatorSet,this.propList)}},lb=class extends $s{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===jn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let o=[e[n],e[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return e.length}},hb=class extends Xn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let o=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:y.initial,s=e[r];s||(s=[],e[r]=s),s.push(o)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof Oe?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 Oe(t[i]);return null}},ub=class extends Xn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"])){let s=this.values["font-weight"],a=s instanceof ai&&s.name==="calc"?e.indexOf(s):-1;if(a>=0&&e[a].visit(r["font-size"]))delete this.values["font-weight"],t=a;else return this.error=!0,t}if(this.values["font-size"]=e[t++],e[t]===jn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let o=t==e.length-1?e[t]:new J(e.slice(t,e.length));return o.visit(r["font-family"])?(this.values["font-family"]=o,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new Oe(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}},cb=class extends Xn{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=[y.auto,y.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},db=class extends $s{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 xt(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}},Su=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","inset-block-start","inset-block-end","inset-inline-start","inset-inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Zp=class extends Xn{constructor(){super()}refreshPropList(){this.propList=this.validatorSet.getPropertiesForAll()}init(e,t){super.init(e,t)}validateList(e){return this.error=!0,0}},Cu={SIMPLE:Xn,INSETS:Yp,INSETS_SLASH:lb,COMMA:hb,FONT:ub,TEXT_SPACING:cb,ALL:Zp},pb=["initial-letter"],fb=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 is(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)||Su.includes(r)||i.push(r)}return this.browserPropertyNamesForAll=i,this.browserPropertyNamesForAll}getPropertiesForAll(){if(this.allPropertyNames)return this.allPropertyNames;let e=new Set;for(let n in this.validators)Su.includes(n)||e.add(n);let t=this.getBrowserPropertyNamesForAll();if(t)for(let n of t)this.shorthands[n]||e.add(n);let i=Array.from(e);return t&&(this.allPropertyNames=i),i}getBrowserShorthandStyle(){return this.browserShorthandStyle!==null?this.browserShorthandStyle:typeof document>"u"?null:(this.browserShorthandStyle=document.createElement("div").style,this.browserShorthandStyle)}expandBrowserShorthand(e,t){let i=this.getBrowserShorthandStyle();if(!i)return null;i.cssText="",i.setProperty(e,t);let n=Array.from({length:i.length},(o,s)=>i.item(s)).filter(o=>!!o);if(!n.length||n.length===1&&n[0]===e.toLowerCase())return null;let r={};for(let o of n)r[o]=i.getPropertyValue(o);return{propList:n,values:r}}getShorthand(e,t){if(Xe(e))return null;let i=this.shorthands[e];if(i)return i instanceof Zp&&!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):!ku(t))&&(this.browserShorthandMisses[e]=!0),null;let r=new db(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 O(t.num,t.text);else if(t.type==7)i=new Xc(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new rr;if(e=="||"){for(let r=0;r<t.length;r++){let o=new rr;o.startClause(r),o.addGroup(t[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new rr;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 rr;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 rr;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new ih(t);break;case"SPACE":i=new Sr(t);break;case"attr":i=new xu;break;default:i=new ob(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ue(On,te,te)),this.namedValidators.ATTR=this.primitive(new xu),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ue(bs,te,te)),this.namedValidators.POS_INT=this.primitive(new ue($n,te,te)),this.namedValidators.POS_NUM=this.primitive(new ue(Zi,te,te)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ue(Si,te,zs)),this.namedValidators.NEGATIVE=this.primitive(new ue(ni,te,te)),this.namedValidators.ZERO=this.primitive(new ue(ri,te,te)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ue(ws,te,te)),this.namedValidators.POS_LENGTH=this.primitive(new ue(Si,te,Vs)),this.namedValidators.POS_ANGLE=this.primitive(new ue(Si,te,Kl)),this.namedValidators.POS_TIME=this.primitive(new ue(Si,te,Jl)),this.namedValidators.FREQUENCY=this.primitive(new ue(Si,te,Ql)),this.namedValidators.RESOLUTION=this.primitive(new ue(Si,te,{dpi:Me,dpcm:Me,dppx:Me})),this.namedValidators.URI=this.primitive(new ue(vs,te,te)),this.namedValidators.URANGE=this.primitive(new ue(Hp,te,te)),this.namedValidators.IDENT=this.primitive(new ue(Up,te,te)),this.namedValidators.STRING=this.primitive(new ue(ys,te,te)),this.namedValidators.SLASH=this.primitive(new ue($p,te,te));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=c=>{if(s)throw new Error(`'${c}': unexpected`);if(r&&r!=c)throw new Error(`mixed operators: '${c}' and '${r}'`);r=c,s=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(s||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()]=B(c.text),i.push(this.primitive(new ue(0,d,te)))}s=!1;break;case 5:{let d={};d[`${c.num}`]=new lt(c.num),i.push(this.primitive(new ue(0,d,te))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:c.text}),r="",i=[],s=!0;break;case 15:{o=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(o),r=d.op,s=!1;break}case 11:{o=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,o)),r=d.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),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 Sr(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(B(n.text));break;case 4:i.push(new At(n.num));break;case 5:i.push(new lt(n.num));break;case 3:i.push(new O(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&&Cu[i.text]?(n=new Cu[i.text],e.consume()):n=new Xn,n.setOwner(this);let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])o.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Yp){let l=this.shorthands[i.text];o.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let l=new ab(o,s),c=a.pop();o=c.syntax,s=c.slash,o.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(o,h),this.shorthands[t]=n,this.invalidateAllPropertyNames()}}parse(e){let t=new xt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(t=this.defaultValues[s])!=null?t:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){var r,o;let s=n.ruleType;if(Xe(e)||s==="font-face"){n.simpleProperty(e,t,i);return}if(s==="counter-style"){Vw(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(ku(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?Z(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t)):n.simpleProperty(h,t,i)}else a&&!Cc.includes(`-${a}-`)||n.unknownProperty(h,t);return}else if(pb.includes(e)&&!Object.keys(d).some(f=>Lo(f?`-${f}-`:"",e))){n.unknownProperty(h,t);return}let p=this.validators[e];if(p){let f=Z(t)||t.isExpr()?t:t.visit(p);f?n.simpleProperty(e,f,i):!a&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(h,t)}else{let f=(o=this.getShorthand(e,t))==null?void 0:o.clone();if(!f){n.unknownProperty(h,t);return}Z(t)?f.propagateDefaultingValue(t,i,n):(t.visit(f),f.finish(i,n)||n.invalidPropertyValue(h,t))}}};function Kp(){let e=new fb;return e.initBuiltInValidators(),e.parse(Ed),e}var gb=class extends Kt{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function ku(e){let t=new gb;return e.visit(t),t.varFound}function Jp(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var mb=class{constructor(e){u(this,"matchers",e)}matches(){return this.matchers.some(e=>e.matches())}},yb=class{constructor(e){u(this,"matchers",e)}matches(){return this.matchers.every(e=>e.matches())}},Qp=class Xo{constructor(t,i,n){u(this,"elementOffset",t),u(this,"a",i),u(this,"b",n)}static registerFragmentIndex(t,i,n){let r=Xo.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Xo.fragmentIndices={}}matches(){let t=Xo.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Jp(t.fragmentIndex,this.a,this.b)}};u(Qp,"fragmentIndices",{});var Hs=Qp,No=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new Hs(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new yb(e)}static buildAnyMatcher(e){return new mb(e)}},ef={"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},vb=["image-resolution","orphans","widows"];function wb(){return _t("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(vb))}var bb={"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},el=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],xb=["max-%","min-%","%"],Eu=(()=>{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<el.length;i++)for(let n=0;n<e.length;n++){let r=el[i].replace("%",e[n]);t[r]=!0}return t})();function qn(e,t){let i={};for(let n of el)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}for(let n of xb)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}return i}var tf=qn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),nf=qn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Sb=qn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Cb=qn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),kb=qn({inside:"right",outside:"left"},{}),Eb=qn({inside:"left",outside:"right"},{}),W=class tl{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 tl(i,this.priority)}increaseSpecificity(t){return t==0?this:new tl(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&Xe(i)?this.value:Cs(t,this.value,i,n,r)}isEnabled(t){return!0}},il=class nl extends W{constructor(t,i,n){super(t,i),u(this,"condition",n)}getBaseValue(){return new W(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new nl(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new nl(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){Y.warn(i)}return!1}};function rl(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Jt(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 rf={"region-id":!0,"fragment-selector-id":!0},Cr="data-viv-footnote-counter";function xs(e){let t=e.getAttribute(Cr);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function of(e,t,i){let n=xs(e);n[t]=i,e.setAttribute(Cr,JSON.stringify(n))}function Pb(e,t){var i,n;if(!Gt(e)||e.hasAttribute(dp))return null;let r=xs(e)[t];if(r)return r;let o=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=e.baseURI||((i=e.ownerDocument)==null?void 0:i.baseURI)||"",a=es(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=e.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let c=xs(l)[t];return c?(of(e,t,c),c):null}function Nb(e){let t=ve(e,"content");return!!t&&It(t.value)}function Tb(e){return!!rf[e]}function qo(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Xi(e){return e.charAt(0)!=="_"&&!rf[e]}function In(e){return!!ef[e]||Xe(e)}function ve(e,t){return e[t]}function Fi(e,t,i){i?e[t]=i:delete e[t]}function ft(e,t){return e[t]}function si(e,t){let i=e[t];return i||(i={},e[t]=i),i}var sf=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function af(e,t){return e[t]}function lf(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Ss(e,t,i,n,r,o,s){var a,h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=si(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),s){let l=sf(t);t={},l.push({styles:t,matcher:s})}for(let l in i)if(!qo(l))if(Tb(l)){let c=af(i,l),d=lf(t,l);Array.prototype.push.apply(d,c)}else{let c=ve(i,l);if(!c.isEnabled(e))continue;let d=c.increaseSpecificity(n);Jt(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 v=new W(Me,d.priority);Jt(t,g,v,e)}}}function Ab(e,t){let i={};for(let n=0;n<t.length;n++)Ss(e,i,t[n],0,null,null,null);return i}function nh(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 Ib=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 Zt.em;let t=e.value;if(!dm(t.unit))throw new Error("Unexpected state");return t.num*Zt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?ol(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?rh(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Cs(this.context,e,this.propName).visit(this):e}};function rh(e,t,i){let n=e.unit,r=e.num;return n==="em"?new O(r*t,"px"):n==="rem"?new O(r*i.fontSize(),"px"):n==="rlh"?new O(r*i.rootLineHeight,"px"):e}function ol(e,t,i){e=rh(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new O(r/100*t,"px"):new O(r*i.queryUnitSize(n,!1),"px")}var Yn=class{apply(e){}mergeWith(e){return new Fb([this,e])}clone(){return this}},To=class extends Yn{constructor(e){super(),u(this,"conditionItem",e)}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Fb=class hf extends Yn{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 hf([].concat(this.list))}},oh=class extends Yn{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){Ss(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Ne=class extends Yn{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Rb=class extends Ne{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}},Lb=class extends Ne{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}},Pu=class extends Ne{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}},Ob=class extends Ne{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}},Bb=class extends Ne{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)}}}},Mb=class extends Ne{constructor(e){super(),u(this,"ns",e)}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Ws(e,t,i,n){var r;if(!e)return!1;let o=((r=e.ownerDocument)==null?void 0:r.contentType)==="text/html",s=o?Br(i):i;if(t!==null){let a=e.getAttributeNodeNS(t||null,s);return!!a&&n(a)}for(let a of Array.from(e.attributes))if((o?Br(a.localName):a.localName)===s&&n(a))return!0;return!1}function Br(e){return e.replace(/[A-Z]/g,t=>t.toLowerCase())}function uf(e){return e==="i"}function or(e,t){return Array.from(e,i=>{let n=ts(i);if(!uf(t))return n;let r=Br(i),o=r.toUpperCase();return r!==o&&/^[a-z]$/i.test(i)?`[${r}${o}]`:n}).join("")}function sr(e){return new RegExp(e)}function _b(e,t,i){return uf(i)?Br(e)===Br(t):e===t}var Nu=class extends Ne{constructor(e,t){super(),u(this,"ns",e),u(this,"name",t)}apply(e){Ws(e.currentElement,this.ns,this.name,()=>!0)&&this.chained.apply(e)}},Db=class extends Ne{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){Ws(e.currentElement,this.ns,this.name,t=>_b(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}},zb=class extends Ne{constructor(e,t){super(),u(this,"ns",e),u(this,"name",t)}apply(e){Ws(e.currentElement,this.ns,this.name,t=>!!bb[t.value])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},ar=class extends Ne{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){Ws(e.currentElement,this.ns,this.name,t=>!!t.value.match(this.regexp))&&this.chained.apply(e)}},Vb=class extends Ne{constructor(e){super(),u(this,"langRegExp",e)}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Tu=class extends Ne{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Ub=class extends Ne{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},sn=class extends Ne{constructor(e,t){super(),u(this,"a",e),u(this,"b",t)}matchANPlusB(e){return Jp(e,this.a,this.b)}},$b=class extends sn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},sl=class extends sn{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}},al=class extends sn{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}},ll=class extends sn{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,o=t[n];o||(o=t[n]={}),o[r]=(o[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},Hb=class extends Ne{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}},Wb=class extends Ne{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Gb=class extends Ne{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},jb=class extends Ne{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},rt=class extends Ne{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}},cf=class df extends Yn{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new df;return t.applied=this.applied,t}},sh=class extends Ne{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new cf;for(let t of e)this.firstActions.push(nh(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 Ne?e.getPriority():0))}positive(){return!0}relational(){return!1}},Xb=class extends sh{positive(){return!1}},qb=class extends sh{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}},pf=class extends sn{constructor(e,t,i){super(e,t),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new cf;for(let n of i)this.firstActions.push(nh(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,o=t.currentId,s=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let c=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=o,t.currentClassNames=s,t.currentSiblingOrder=a,c}getPriority(){return 5}},Yb=class extends pf{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}},Gs=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)}},Zb=class ff extends Gs{constructor(t,i,n){super(t,i,n)}fresh(t){return new ff(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}},Kb=class gf extends Gs{constructor(t,i,n){super(t,i,n)}fresh(t){return new gf(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)}},Jb=class mf extends Gs{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new mf(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)}},Qb=class yf extends Gs{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new yf(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}},e0=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}},t0=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}},i0=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}},n0=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(Z(e))return e;let n=(t=this.validatorSet)==null?void 0:t.validators[this.propName];return n?(i=e.visit(n))!=null?i:y.unset:!this.propName||CSS.supports(this.propName,e.toString())?e:y.unset}visitFunc(e){var t;if(e.name.toLowerCase()!=="attr")return super.visitFunc(e);this.hadAttrFunction=!0;let i=eh(e);if(!i)return super.visitFunc(e);let n=((t=i.fallback)!=null?t:nb(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:rb(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function Mr(e,t){if(It(e)){if(e instanceof K)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=>Mr(i,t)).join("")}return""}function ah(e){if(e instanceof j){let t=e.expr;return t instanceof we&&/^page-counters?-/.test(t.str)}return e instanceof J||e instanceof Oe?e.values.some(t=>ah(t)):!1}function hl(e,t){return ah(e)?e instanceof J?new J(e.values.map(i=>hl(i,t))):e instanceof Oe?new Oe(e.values.map(i=>hl(i,t))):e:new K(Mr(e,t))}var _r=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 o=r.evaluate(this.cascade.context);if(!o||Z(o))return!1;let s=qi(o,i);return Object.prototype.hasOwnProperty.call(s,e)}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=Mr(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 K("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new K("")}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,o=!1,s=!1){var a,h,l,c,d,p,f,g,v;let w=typeof r=="string",x=A=>w?this.formatCounterList(A,r,i):this.formatLastValue(A,i),m=A=>{this.pseudoName==="footnote-call"&&this.element&&of(this.element,t,A)},S=(A,z)=>A.length===z.length&&A.every((U,X)=>U===z[X]);if(this.pseudoName==="footnote-call"&&this.element){let A=Pb(this.element,t);if(A)return x(A)}if(this.pseudoName==="footnote-marker"&&this.element){let A=xs(this.element)[t];if(A)return x(A)}let b;if(t==="pages")return x([]);if(!this.element){if(o&&n.length)return b=n,m(b),x(b);if((a=e.isPageControlledCounter)!=null&&a.call(e,t)&&s&&n.length){let A=((h=e.currentPageCounters)==null?void 0:h[t])||[];return b=[(A.length?A[A.length-1]:0)+n[n.length-1]],m(b),x(b)}if(!((l=e.isPageControlledCounter)!=null&&l.call(e,t))){let A=((c=e.currentPageCounters)==null?void 0:c[t])||[];if(A.length)return b=A,m(b),x(b)}}let C=((d=e.currentPageDocCounters)==null?void 0:d[t])||[],P=!this.element&&n.length&&!S(n,C),L=this.element||P?n:C.length?C:n;if((p=e.isPageControlledCounter)!=null&&p.call(e,t)){let A=((f=e.currentPageDocCounters)==null?void 0:f[t])||[],z=((g=e.currentPageCounters)==null?void 0:g[t])||[],U=z.length?z[z.length-1]:0,X=A.length?A[0]:0,re=L.length?L[0]:0,k=U+(re-X);return b=L.length?[k,...L.slice(1)]:z.length?z:[0],m(b),x(b)}return L.length?(b=L,m(b),x(b)):(b=((v=e.currentPageCounters)==null?void 0:v[t])||[],m(b),x(b))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=!this.element&&this.hasLocalCounterResetOrSet(i),s=!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,o,s),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 K(this.format(l,n))}else{let l=new j(this.counterResolver.getPageCounterVal(i,c=>this.format(c||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",o=(this.cascade.counters[i]||[]).slice(),s=!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,o,n,s,a),p?`page-counters-${i}`:`counters-${i}`);return p&&h!=null&&h.registerPageCounterExpr&&h.registerPageCounterExpr(i,v=>this.formatCounterList(v,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 v=0;v<p.length;v++)f.push(this.format(p[v],r));let g=c.toString();return g.length&&f.push(g),f.length?f.join(n):this.format(0,r)}));return new J([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",o=new j(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new J([o])}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(),o=e.length>3?e[3].stringValue():"decimal",s=new j(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new J([s])}visitFuncTargetText(e){let t=e[0],i;t instanceof 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 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,o,s,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=ft(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 v=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;c=Mr(v,this.cascade.context)}}}break;case"first-letter":{let d=ft(this.cascade.currentStyle,"_pseudos"),p=(s=(o=d?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(Qo);c=g?g[0]:""}break}return new K(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 K&&(t=e[0].stringValue());return t.length==0?new K(""):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 fa(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}var r0=(e,t,i)=>{let n=t.filter(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(E){S==="rtl"?g.textContent=(E.startsWith("\u200F")?"":"\u200F")+E+(E.endsWith("\u200F")?"":"\u200F"):g.textContent=E},c=function(){let E=i.clientLayout.getElementClientRect(v);return m==="vertical-rl"||m==="vertical-lr"?S==="rtl"?E.top-=k:E.bottom+=k:S==="rtl"?E.left-=k:E.right+=k,L.left>E.left||L.right<E.right||L.top>E.top||L.bottom<E.bottom},d=function(){let E,N,R=x.repeat(1e4);if(l(R),c())E=1,N=1e4;else return;for(let $=0;$<16;$++){let V="",q=Math.floor((E+N)/2);for(let Q=0;Q<q;Q++)V+=x;if(l(V),c())N=q;else{if(E==q)return;E=q}}l(x)},p=function(E){let N=0,R=v.parentElement;for(;R&&R!==f.viewNode;)N+=i.getComputedInsets(R)[E],R=R.parentElement;return N};var r=l,o=c,s=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,v=g.parentElement,w=v.getAttribute("data-adapt-pseudo"),x=g.getAttribute("data-viv-leader-value"),{writingMode:m,direction:S,marginInlineEnd:b}=i.clientLayout.getElementComputedStyle(v);g.style.marginInlineStart="1px",l(x),v.style.display="inline-block",v.style.textIndent="0";let C=eo(f.viewNode),P=C?.style.columnFill||null;C&&(C.style.columnFill="auto");let L=i.clientLayout.getElementClientRect(f.viewNode),A=i.clientLayout.getElementClientRect(v),z=i.parseComputedLength(b),U=[],X=v.parentElement;for(;X.parentElement&&X.parentElement!==f.viewNode;)X=X.parentElement;let re=X.nextSibling;for(;re;){if(re.nodeType===1){let E=re,{display:N,float:R,position:$}=i.clientLayout.getElementComputedStyle(E);if(R!=="none"||$==="absolute"||$==="fixed"){re=re.nextSibling;continue}if(Ut(N))U.push(E);else if(pv(N))break}else if(re.nodeType===3){let E=re;E.length>0&&U.push(E)}re=re.nextSibling}let k=U.reduce((E,N)=>E+fa(N,i.clientLayout,m),0);if(w!=="after"){let E=fa(X,i.clientLayout,m),N=fa(v,i.clientLayout,m);k+=E-N}m==="vertical-rl"||m==="vertical-lr"?(S==="rtl"?L.top+=z:L.bottom-=z,L.top=Math.min(A.top,L.top),L.bottom=Math.max(A.bottom,L.bottom)):(S==="rtl"?L.left+=z:L.right-=z,L.left=Math.min(A.left,L.left),L.right=Math.max(A.right,L.right)),d();let _=i.clientLayout.getElementClientRect(v);S=="rtl"?v.style.float="left":v.style.float="right";let F=i.clientLayout.getElementClientRect(v),D=0;S=="rtl"?m=="vertical-rl"||m=="vertical-lr"?D=_.top-F.top-p("top"):D=_.left-F.left-p("left"):m=="vertical-rl"||m=="vertical-lr"?D=F.bottom-_.bottom-p("bottom"):D=F.right-_.right-p("right"),D-=k,D=Math.max(0,D-.1),v.style.float="",g.style.marginInlineStart=`${D}px`,C&&(P?C.style.columnFill=P:C.style.removeProperty("column-fill"))}};Ft("POST_LAYOUT_BLOCK",r0);var lh=1/1048576;function cn(e,t){for(let i in e)t[i]=e[i].clone()}var o0=class vf{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 vf;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,o,s){return new s0(this,t,i,n,r,o,s)}nextOrder(){return this.order+=lh}},wf=class bf{constructor(t,i,n,r,o,s,a){u(this,"context",i),u(this,"counterListener",n),u(this,"counterResolver",r),u(this,"counterStyleStore",s),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 K("\u201C"),new K("\u201D"),new K("\u2018"),new K("\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=No.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:No.buildAnyMatcher([].concat(o)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:No.buildAllMatcher(n):No.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=ga,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,o,s,a,h,l,c,d;let p=new Set,f=Object.create(null),g=y.inline,v=t.display;if(v&&(g=v.evaluate(this.context)),g===y.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 w=y.inline,x=t.float;x&&(w=x.evaluate(this.context));let m=null,S=null,b=null,C=t["counter-reset"];if(C){let A=C.evaluate(this.context);A&&(m=qi(A,{reset:!0}))}let P=t["counter-set"];if(P){let A=P.evaluate(this.context);A&&(b=qi(A,{defaultValue:0}))}let L=t["counter-increment"];if(L){let A=L.evaluate(this.context);A&&(S=qi(A))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((o=(r=this.currentElement)==null?void 0:r.start)!=null?o:1)-1),ur(g)&&(S||(S=Object.create(null)),S["list-item"]=(s=S["list-item"])!=null?s:1,/^\s*[-+]?\d/.test((h=(a=this.currentElement)==null?void 0:a.getAttribute("value"))!=null?h:"")&&(b||(b=Object.create(null)),b["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)),w===y.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(S||(S=Object.create(null)),S.footnote===void 0)){let A=(d=this.currentStyle["counter-increment"])==null?void 0:d.value;(!A||!(A===y.footnote||A instanceof J&&A.values.includes(y.footnote)))&&(S.footnote=1)}if(m)for(let A in m)p.add(A),f[A]="reset";if(S)for(let A in S)p.add(A),f[A]||(f[A]="increment");if(b)for(let A in b)p.add(A),f[A]="set";if(this.lastCounterChanges=Array.from(p),this.lastCounterChangeTypes=f,m)for(let A in m)this.defineCounter(A,m[A]);if(S)for(let A in S){this.counters[A]||this.defineCounter(A,0);let z=this.counters[A];z[z.length-1]+=S[A]}if(b)for(let A in b)if(!this.counters[A])this.defineCounter(A,b[A]);else{let z=this.counters[A];z[z.length-1]=b[A]}if(ur(g)){let A=this.counters["list-item"],z=A[A.length-1];t["ua-list-item-count"]=new W(new At(z),0);let U=si(t,"_pseudos");U.marker||(U.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 _r(this,this.currentElement,this.counterResolver));let n=i.value instanceof Oe?i.value.values:[i.value];for(let r of n)if(r instanceof J){let o=r.values[0].stringValue(),s=r.values.slice(1);if(s.some(a=>ah(a)))this.counterResolver.setNamedString(o,hl(new J(s),this.context),this.currentElementOffset);else{let a=s.map(h=>Mr(h,this.context)).join("");this.counterResolver.setNamedString(o,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 _r(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var o,s,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=ga;let d=i.getAttributeNS("http://www.idpf.org/2007/ops","type");d?this.currentEpubTypes=d.split(/\s+/):this.currentEpubTypes=ga;let p=Ca(i);p&&(this.stack[this.stack.length-1].push(new t0(this.lang)),this.lang=p.toLowerCase());let f=this.isRoot,g=this.siblingOrderStack;this.currentSiblingOrder=++g[g.length-1],g.push(0);let v=this.siblingTypeCountsStack,w=this.currentSiblingTypeCounts=v[v.length-1],x=w[this.currentNamespace];x||(x=w[this.currentNamespace]={}),x[this.currentLocalName]=(x[this.currentLocalName]||0)+1,v.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let S=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=S[S.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,S.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,P=null;if(C){let z=C.evaluate(this.context);z&&(P=new i0(this.quotes),z===y.none?this.quotes=[new K(""),new K("")]:z===y.auto||z===y.initial?this.quotes=[new K("\u201C"),new K("\u201D"),new K("\u2018"),new K("\u2019")]:z instanceof J&&(this.quotes=z.values))}this.pushCounters(this.currentStyle);let L=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(f||L){let z=Object.create(null);Object.keys(this.counters).forEach(U=>{z[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(L,z)}let A=ft(this.currentStyle,"_pseudos");if(A){let z=!0;for(let U of a0){U||(z=!1);let X=A[U];if(X){let re=(o=ve(this.currentStyle,"float"))==null?void 0:o.value,k=i instanceof Element&&Gt(i),_=i instanceof Element&&Pt(i),F=!!ve(this.currentStyle,"--viv-semantic-footnote-content"),D=re===y.footnote,E=(U==="before"||U==="after")&&(D||_||F)&&!!X.content,N=Nb(X),R=U==="footnote-call"&&k&&N,$=U==="footnote-marker"&&(_||F)&&N;if((U==="before"||U==="after")&&!(E||It((s=X.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(X))||U==="marker"&&!ur((a=ve(this.currentStyle,"display"))==null?void 0:a.value)||(U==="footnote-call"||U==="footnote-marker")&&re!==y.footnote&&!R&&!$||(U==="footnote-call"||U==="footnote-marker")&&F&&!N)delete A[U];else if(z){if(this.processPseudoelementProps(X,i,U),U==="marker")this.processMarkerPseudoelementProps(X,i,t),delete A[U];else if(U==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(X,"list-style-position",t,i)===y.outside){this.processMarkerPseudoelementProps(X,i,t);let V=X.content;V&&(this.currentStyle["_footnote-marker-content"]=V),this.currentStyle.display=new W(B("list-item"),0),this.currentStyle["list-style-position"]=new W(y.outside,0),this.currentStyle["list-style-type"]=new W(y.none,0),this.currentStyle["list-style-image"]=new W(y.none,0),delete A[U]}}else if(U==="first-letter"&&X["initial-letter"]){let V=X["initial-letter"].evaluate(this.context);V!==y.normal&&!Z(V)&&(this.currentStyle["--viv-initialLetter"]=new W(V,0)),delete X["initial-letter"]}}else this.stack[this.stack.length-2].push(new e0(X,i))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),P&&this.stack[this.stack.length-2].push(P)}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,o,s,a,h;let l=ur((r=this.currentStyle.display)==null?void 0:r.value);if(!It((o=t.content)==null?void 0:o.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof Qe)t.content=new W(new J([p,new K(" ")]),0);else if(d instanceof K)t.content=new W(d,0);else if(d instanceof he&&d!==y.none){let f=(a=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new W(new K(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 W(p,0)}}for(let d of bf.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!Z(f)&&(this.currentStyle[`--viv-marker-${d}`]=new W(f,0))}}if(!Ut((h=ve(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==y.outside&&!Z(d)&&(this.currentStyle["list-style-position"]=new W(d,0))}}resolveMarkerContentVal(t){if(t instanceof j){let i=t.expr.evaluate(this.context);return typeof i=="string"?new K(i):typeof i=="number"?new K(String(i)):t}if(t instanceof J){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new J(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let s=n;s;s=s.parentElement){let a=(s===this.currentElement?this.currentStyle:i.getStyle(s,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===y.inherit||h===y.unset||h===y.revert)continue;if(h===y.initial)break;return h}}let o=i.validatorSet;return(r=o?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var o;let s=t[i];if(s){let a=s.evaluate(this.context,i);if(a!==y.inherit&&a!==y.unset&&a!==y.revert){if(a===y.initial){let h=n.validatorSet;return(o=h?.defaultValues[i])!=null?o:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i,n){let r=t.scope,o=t.validatorSet;for(let s in n)if(Xi(s)&&!Xe(s)){let a=n[s],h=new n0(i,r,s,o),l=a.filterValue(h);if(!h.hadAttrFunction){n[s]=l;continue}let c=h.validatePropertyValue(l.value);n[s]=c===l.value?l:new W(c,l.priority)}}applyAttrFilter(t,i){let n=this.currentStyle,r=ft(n,"_pseudos");for(let o in r)this.applyAttrFilterInner(i,t,r[o]);this.applyAttrFilterInner(i,t,n)}applyVarFilter(t,i,n){let r=t[0],o=t.map(d=>({...d})),s=32,a={},h=ft(r,"_pseudos"),l=Object.keys(r).filter(Xi),c=d=>{var p,f,g;let v=ve(r,d),w=v.value,x=Xe(d)?o:t,m=new y0(x,i,n,Xe(d)?d:null);Xe(d)&&m.getFallbackCycleMembers(w,x,n)&&(w=y.initial);for(let S=0;;S++){if(S>=s){w=Xe(d)?y.initial:y.unset;break}let b=w.visit(m);if(m.error){w=Xe(d)?y.initial:y.unset,m.error=!1;break}if(b===w)break;w=b}if(w!==v.value){let S=i.validatorSet,b=(p=S?.getShorthand(d,w))==null?void 0:p.clone();if(b)if(Z(w)){for(let C of b.propList){let P=new W(w,v.priority),L=ve(r,C);Fi(a,C,rl(this.context,L,P))}delete r[d]}else{let C=Ri(i.scope,new xt(w.toString(),null),"");if(C&&(C.visit(b),!b.error)){for(let P of b.propList){let L=new W((g=(f=b.values[P])!=null?f:S.defaultValues[P])!=null?g:y.initial,v.priority),A=ve(r,P);Fi(a,P,rl(this.context,A,L))}delete r[d]}}else r[d]=new W(w,v.priority)}if(a[d]){let S=ve(r,d);S&&S.value!==Me&&Jt(a,d,S,this.context)}};for(let d in r)if(qo(d)){if(d==="_pseudos")continue;let p=ft(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 Af(i);for(let r in t)if(qo(r)){let o=ft(t,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Xi(r)&&!Xe(r)){let o=ve(t,r),s=o.value.visit(n);s!==o.value&&(t[r]=new W(s,o.priority))}}applyCmykFilter(t,i){let n=new id(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(qo(r)){let o=ft(t,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Xi(r)&&!Xe(r)){let o=ve(t,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),t[r]=new W(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};u(wf,"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 s0=wf,ga=[],a0=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],ul=null;function l0(e){ul=e}var Dr=class extends on{constructor(e,t,i,n,r,o,s){super(e,t,s),u(this,"condition",i),u(this,"regionId",r),u(this,"validatorSet",o),u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"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:ul?ul.clone():new o0,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=nh(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 Ob(e,t.toLowerCase())):t?this.chain.push(new Pu(t.toLowerCase())):this.chain.push(new Mb(e)))}invalidSelector(e){Y.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 Rb(e)))}pseudoclassSelector(e,t){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Wb);break;case"disabled":this.chain.push(new Gb);break;case"checked":this.chain.push(new jb);break;case"root":case"scope":this.chain.push(new Ub);break;case"link":this.chain.push(new Pu("a")),this.chain.push(new Nu("","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)${ts(i)}($|\\s)`),r=t[1];this.chain.push(new Bb(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 Vb(new RegExp(`^${ts(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=h0[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 Tu);break;case"last-child":this.chain.push(new al(0,1));break;case"first-of-type":this.chain.push(new sl(0,1));break;case"last-of-type":this.chain.push(new ll(0,1));break;case"only-child":this.chain.push(new Tu),this.chain.push(new al(0,1));break;case"only-of-type":this.chain.push(new sl(0,1)),this.chain.push(new ll(0,1));break;case"empty":this.chain.push(new Hb);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 Lb(e)))}attributeSelector(e,t,i,n,r){if(this.invalidContinuationAfterPseudoelement(`[${t}]`))return;this.specificity+=256,n=n||"";let o;switch(i){case 0:o=new Nu(e,t);break;case 39:o=new Db(e,t,n,r??null);break;case 45:!n||n.match(/\s/)?o=new rt(""):o=new ar(e,t,sr(`(^|\\s)${or(n,r??null)}($|\\s)`),r??null);break;case 44:o=new ar(e,t,sr(`^${or(n,r??null)}($|-)`),r??null);break;case 43:n?o=new ar(e,t,sr(`^${or(n,r??null)}`),r??null):o=new rt("");break;case 42:n?o=new ar(e,t,sr(`${or(n,r??null)}$`),r??null):o=new rt("");break;case 46:n?o=new ar(e,t,sr(or(n,r??null)),r??null):o=new rt("");break;case 50:if(n=="supported")o=new zb(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(o)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Ao++}`;this.processChain(new To(new Zb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Ao++}`;this.processChain(new To(new Kb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Ao++}`;this.processChain(new To(new Jb(e,this.viewConditionId,null))),this.chain=[new rt(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Ao++}`;this.processChain(new To(new Qb(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 oh(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new il(t,0,this.condition):i=new W(t,0),lf(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===y.oeb_page_head||t===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),_t("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:e,value:t,important:i});e=s.name,t=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new il(t,n,this.condition):new W(t,n);Jt(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 u0(this);break;case"where":i=new c0(this);break;case"has":i=new d0(this);break;case"nth-child":t&&t.length>=2&&(i=new Sf(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new p0(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},h0={"nth-child":$b,"nth-of-type":sl,"nth-last-child":al,"nth-last-of-type":ll},Ao=0,Hn=class xf extends Dr{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 qb(this.selectorTexts):this.positive()?new sh(this.chains):new Xb(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 xf;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}},u0=class extends Hn{positive(){return!1}forgiving(){return!1}},c0=class extends Hn{increasingSpecificity(){return!1}},d0=class extends Hn{relational(){return!0}},Sf=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 pf(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}forgiving(){return!0}},p0=class extends Sf{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Yb(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.owner.popHandler()}},f0=class extends on{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 Xr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},Yo=class extends on{constructor(e,t,i,n,r,o){super(e,t,!1),u(this,"condition",i),u(this,"elementStyle",n),u(this,"validatorSet",r),u(this,"ruleType",o),u(this,"order"),this.order=0}property(e,t,i){i?Y.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){Y.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){Y.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=lh;let r=this.condition?new il(t,n,this.condition):new W(t,n);Jt(this.elementStyle,e,r)}},g0=class extends Md{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){Y.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){Y.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Bd:Od;n+=this.order,this.order+=lh;let r=new W(t,n);Jt(this.elementStyle,e,r)}};function Cf(e,t){let i=sf(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function cl(e,t,i){Cf(i,n=>{kr(e,n,t)})}function m0(e,t,i,n){let r=new g0(e,t),o=new xt(n,r);try{av(o,r,i)}catch(s){Y.warn(s,"Style attribute parse error:")}return r.elementStyle}function kf(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.vertical_rl}return i}function Ef(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==y.inherit&&r!==y.revert&&r!==y.unset)return r===y.rtl}return i}function dl(e,t,i,n,r){let o={};for(let s in e)Xi(s)&&(o[s]=ve(e,s));return cl(o,t,e),Pf(e,i,n,(s,a)=>{kr(o,a,t),cl(o,t,a)}),o}function Pf(e,t,i,n){let r=ft(e,"_regions");if((t||i)&&r){if(i){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let s=r[o];s&&n(o,s)}}}function kr(e,t,i){for(let n in t)if(Xi(n)){let r=ve(t,n),o=e[n];e[n]=rl(i,o,r)}}var Nf=(e,t,i,n,r,o)=>{var s,a;let h=i?n?Sb:tf:n?Cb:nf,l=r?kb:Eb;for(let c in e){let d=e[c];if(!d)continue;let p=(s=h[c])!=null?s:h[l[c]],f=(a=l[c])!=null?a:l[h[c]],g=p??f,v;if(g){let w=e[g];if(w&&w.priority>d.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>d.priority))continue;v=Eu[p]?p:Eu[f]?f:c}else v=c,c.startsWith("text-align")&&(d.value===y.inside||d.value===y.outside)&&(d=new W(r===(d.value===y.inside)?y.right:y.left,d.priority));t[v]=o(c,d)}},y0=class Tf 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,o;let s=n??this.styler.root;if(i!=null&&i.length){for(let a=0;a<i.length;a++){let h=(r=i[a][t])==null?void 0:r.value;if(h){if(h===y.initial)return{found:!0,value:null,elementStyles:i.slice(a),element:n};if(!(h===y.inherit||h===y.unset||h===y.revert))return{found:!0,value:h,elementStyles:i.slice(a),element:n}}}n&&(s=n.parentElement)}for(;s;s=s.parentElement){let a=this.styler.getStyle(s,!1),h=(o=a?.[t])==null?void 0:o.value;if(h){if(h===y.initial)return{found:!0,value:null,elementStyles:a?[a]:[],element:s};if(!(h===y.inherit||h===y.unset||h===y.revert))return{found:!0,value:h,elementStyles:a?[a]:[],element:s}}}return{found:!1,value:null,elementStyles:[],element:null}}collectReferencedCustomProperties(t){let i=new Set;class n extends Kt{visitFunc(o){let s=o.values[0]instanceof he&&o.values[0].name;return o.name==="var"&&s&&Xe(s)&&i.add(s),super.visitFunc(o)}}return t.visit(new n),Array.from(i)}findReferencedCycleStart(t,i,n,r=new Set){for(let o of this.collectReferencedCustomProperties(t)){if(this.resolvingCustomProperties.includes(o))return o;if(r.has(o))continue;r.add(o);let s=this.getRawCustomPropertyLookup(o,i,n),a=s.value&&this.findReferencedCycleStart(s.value,s.elementStyles,s.element,r);if(a)return a}return null}getFallbackCycleMembers(t,i,n){let r=null,o=this;class s extends Kt{visitFunc(l){if(l.name==="var")for(let c of l.values.slice(1)){let d=o.findReferencedCycleStart(c,i,n);if(d)return r=d,null}return super.visitFunc(l)}}if(t.visit(new s),!r)return null;let a=this.resolvingCustomProperties.indexOf(r);return new Set(this.resolvingCustomProperties.slice(a))}resolveCustomProperty(t,i,n,r){if(!i)return{found:!1,value:null,continueLookup:!1};if(i===y.initial)return{found:!0,value:null,continueLookup:!1};if(i===y.inherit||i===y.unset||i===y.revert)return{found:!0,value:null,continueLookup:!0};let o=this.getFallbackCycleMembers(i,n,r);return o?(o.forEach(s=>this.varResolutionState.cycleMembers.add(s)),{found:!0,value:null,continueLookup:!1}):{found:!0,value:this.resolveReferencedCustomProperty(t,i,n,r),continueLookup:!1}}resolveReferencedCustomProperty(t,i,n,r){let o=this.resolvingCustomProperties.indexOf(t);if(o>=0)return this.resolvingCustomProperties.slice(o).forEach(d=>this.varResolutionState.cycleMembers.add(d)),null;let s=new Set(this.varResolutionState.cycleMembers);this.varResolutionState.cycleMembers=new Set;let a=new Tf(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([...s,...c]),this.resolvingCustomProperties.pop(),c.has(t)?null:h}getVarValue(t){var i,n,r,o;let s=(i=this.element)!=null?i:this.styler.root;if((n=this.elementStyles)!=null&&n.length){for(let a=0;a<this.elementStyles.length;a++){let h=this.elementStyles[a],l=this.resolveCustomProperty(t,(r=h[t])==null?void 0:r.value,this.elementStyles.slice(a),this.element);if(l.found){if(l.value)return l.value;if(!l.continueLookup)return null}}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=this.styler.getStyle(s,!1),h=this.resolveCustomProperty(t,(o=a?.[t])==null?void 0:o.value,a?[a]:[],s);if(h.found){if(h.value)return h.value;if(!h.continueLookup)return null}}return null}visitFunc(t){if(t.name!=="var")return super.visitFunc(t);let i=t.values[0]instanceof he&&t.values[0].name;return!i||!Xe(i)?(this.error=!0,Me):this.getVarValue(i)||(this.currentCustomPropertyName&&this.varResolutionState.cycleMembers.has(this.currentCustomPropertyName)?(this.error=!0,Me):t.values.length<2?(this.error=!0,Me):t.values.length===2?t.values[1]:new Oe(t.values.slice(1)))}visitSpaceList(t){let i=this.visitValues(t.values);if(this.error)return Me;if(i===t.values)return t;let n=[];for(let r of i)r instanceof J?n.push(...r.values):n.push(r);return new J(n)}visitCommaList(t){let i=this.visitValues(t.values);if(this.error)return Me;if(i===t.values)return t;let n=[];for(let r of i)r instanceof Oe?n.push(...r.values):n.push(r);return new Oe(n)}},Af=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 xt(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 O(r,"px"):/\d[a-z]/i.test(i)||(t=new At(r)))}catch(r){Y.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&Ic(e.unit)||this.context.rootFontSize!=null&&fm(e.unit)?new O(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new O(e.num*this.percentRef/100,"px"):e}};function Cs(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:uv(e,t.expr,i);if(t instanceof O||t instanceof ai||t instanceof J||t instanceof Oe)return t.visit(new Af(e,!0,n,r))}catch(o){return Y.warn(o),Me}return t}var Au={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Iu(e){let t=e instanceof ot?e:typeof e=="string"?B(e):y.none;if(t===y.none)return Au;let i=t instanceof J?t.values:[t],n=Object.create(Au);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 Fu(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var v0={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Ru={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Lu={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Ou(e){let t=e instanceof ot?e:typeof e=="string"?B(e):y.normal;if(t===y.normal)return Ru;if(t===y.auto)return Lu;let i=t instanceof J?t.values:[t],n=Object.create(Ru);for(let r of i)if(r instanceof he)switch(r.name){case"trim-both":case"trim-auto":return Lu;case"space-all":return v0;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 ma={ideographAlpha:!1,ideographNumeric:!1},w0={ideographAlpha:!0,ideographNumeric:!0};function Bu(e){let t=e instanceof ot?e:typeof e=="string"?B(e):y.normal;if(t===y.normal||t===y.auto)return w0;if(t===y.none)return ma;let i=t instanceof J?t.values:[t],n=Object.create(ma);for(let r of i)if(r instanceof he)switch(r.name){case"no-autospace":return ma;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Mu(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function _u(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 b0=/^[‘’“”〰﹙﹚﹛﹜﹝﹞〚〛]\p{M}*$/u,x0=/^[‘“﹙﹛﹝〚]\p{M}*$/u;function S0(e,t){return Gr==="chromium"&&t&&b0.test(e)}function C0(e){return x0.test(e)?"viv-ts-open":"viv-ts-close"}var k0=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\u3030]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000\u3030])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(r.length>1){let o=r.length-1;for(let s=0;s<o;s++)n.parentNode.insertBefore(document.createTextNode(r[s]),n);n.textContent=r[o]}}}processGeneratedContent(e,t,i,n,r,o){r=_u(r);let s=Bu(t),a=Ou(i),h=Iu(n);if(Fu(h)&&Mu(s,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(o?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=c.nextNode();f;f=p){p=c.nextNode();let g=!d,v=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),x=!p;this.processTextSpacing(f,g||v,g,v,w,x,d,p,s,a,h,r,o),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,o,s,a,h,l;let c=!e||e.fragmentIndex===1&&f(),d=c||g();function p(m){var S;if(m?.nodeType!==1)return!1;let b=m;if(b.hasAttribute(zn))return!0;let{position:C,float:P}=(S=b.style)!=null?S:{};return C==="absolute"||C==="fixed"||P&&P!=="none"}function f(){let m=t[0];for(let S=m;;S=S.parent)if(!S||!S.inline){if(S?.fragmentIndex!==1)return!1;break}if(!m.inline)return!0;for(let S=m.viewNode.previousSibling;S;S=S.previousSibling)if(!Ee(S,m.whitespace)&&!p(S))return!1;return!0}function g(){var m,S;let b=t[0],C;for(;b&&b.inline&&(C=(m=b.viewNode)==null?void 0:m.previousSibling,!(C&&(C.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(C.textContent)&&b.whitespace!==bt.PRESERVE&&(C=C.previousSibling),C)));)b=b.parent;for(;C;){if(C.nodeType===Node.ELEMENT_NODE){if(C.localName==="br")return!0;let P=(S=C.style)==null?void 0:S.display;if(P&&P!=="inline")return!/^(inline|ruby)\b/.test(P)}else if(C.nodeType===Node.TEXT_NODE){if(b.whitespace===bt.PRESERVE){if(/\n$/.test(C.textContent))return!0}else if(b.whitespace===bt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(C.textContent))return!0}C=C.lastChild}return!1}let v=-1;for(let m=0;m<t.length;m++){let S=t[m];if(!S.after&&S.inline&&!S.display&&S.parent&&S.viewNode.parentNode&&S.viewNode.nodeType===Node.TEXT_NODE&&!Ee(S.viewNode,S.whitespace)){let b=function(E){var N,R,$;if(((N=E.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((R=E.viewNode)==null?void 0:R.nodeType)===Node.TEXT_NODE){let V=E.viewNode;if(E.whitespace===bt.PRESERVE){if(/\n$/.test(V.textContent))return!0}else if(E.whitespace===bt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(V.textContent))return!0;if((($=V.previousElementSibling)==null?void 0:$.localName)==="br")return Ee(V,E.whitespace)}return!1},C=function(E){var N,R,$;if(((N=E.viewNode)==null?void 0:N.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((R=E.viewNode)==null?void 0:R.nodeType)===Node.TEXT_NODE){let V=E.viewNode;if(E.whitespace===bt.PRESERVE){if(/^\n/.test(V.textContent))return!0}else if(E.whitespace===bt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(V.textContent))return!0;if((($=V.nextElementSibling)==null?void 0:$.localName)==="br")return Ee(V,E.whitespace)}return!1};var w=b,x=C;v<0&&(v=m);let P=_u((o=(n=(i=S.lang)!=null?i:S.parent.lang)!=null?n:e?.lang)!=null?o:(r=e?.parent)==null?void 0:r.lang),L=Bu(S.inheritedProps["text-autospace"]),A=Ou(S.inheritedProps["text-spacing-trim"]),z=Iu(S.inheritedProps["hanging-punctuation"]);if(Fu(z)&&Mu(L,A)||/\b(flex|grid)\b/.test(S.parent.display))continue;let U=null,X=null,re=m===v,k=m===v&&c,_=m===v&&d,F=!1,D=!1;for(let E=m-1;E>=0;E--){let N=t[E];if(b(N)){_=!0;break}if(!N.display&&N.viewNode.nodeType===Node.TEXT_NODE&&N.viewNode.textContent.length>0){U=N.viewNode;break}if(((s=N.viewNode)==null?void 0:s.nodeType)===Node.ELEMENT_NODE&&Yt(N.viewNode)==="footnote-call"){if(N.viewNode.contains(S.viewNode))continue;let R=Sv(N.viewNode);if(R){U=R;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;E===0&&(re=!0,c&&(k=!0,_=!0))}for(let E=m+1;E<t.length;E++){let N=t[E];if(C(N)){F=!0;break}if(N.viewNode!==S.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])){E===t.length-1&&p(N.viewNode)&&(D=!0);break}if(E===t.length-1){F=!0,D=!0;for(let R=N.viewNode.nextSibling;R;R=R.nextSibling)if(!p(R)){D=!1;break}}}if(((l=S.parent)==null?void 0:l.display)==="inline-block"){if(!k){let E=S.parent.viewNode.firstChild;for(;Ee(E,S.whitespace);)E=E.nextSibling;S.viewNode===E&&(k=!0)}if(!D){let E=S.parent.viewNode.lastChild;for(;Ee(E,S.whitespace);)E=E.previousSibling;S.viewNode===E&&(D=!0)}}if(this.processTextSpacing(S.viewNode,re,k,_,F,D,U,X,L,A,z,P,S.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,o,s,a,h,l,c,d,p){let f=e.textContent,g=e.ownerDocument,v=0,w,x,m;function S(){if(t)return!0;if(!s)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;x||(x=g.createRange(),x.selectNode(s));let N=x.getClientRects(),R=N[N.length-1];return R?(v||(v=Rr(R,p)),p?E.top<R.top+R.height-E.width||E.left+E.width<R.left+E.width/10||E.left>R.left+R.width-E.width/10:E.left<R.left+R.width-E.height||E.top>R.top+R.height-E.height/10||E.top+E.height<R.top+E.height/10):!1}function b(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let E=w.getClientRects()[0];if(!E)return!1;v||(v=Rr(E,p)),m||(m=g.createRange(),m.selectNode(a));let N=m.getClientRects()[0];return N?p?E.top+E.height>N.top+E.width||E.left>N.left+N.width-E.width/10||E.left+E.width<N.left+E.width/10:E.left+E.width>N.left+E.height||E.top+E.height<N.top+E.height/10||E.top>N.top+N.height-E.height/10:!1}let C=!1,P=!1,L=!1,A=!1,z=!1,U,X=S0(f,p);if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0,L=!0):o&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,A=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(U="viv-ts-close",C=!0,z=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(U="viv-ts-open",C=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))?(U="viv-ts-close",C=!0):X&&(U=C0(f),C=!0,P=!0),C){let E=function(q){let Q=parseFloat(g.defaultView.getComputedStyle(q).fontSize)*.7;return(p?q.offsetHeight:q.offsetWidth)>Q},N=function(){return p?R.offsetLeft:R.offsetTop};var re=E,k=N;if(e.parentElement.localName==="viv-ts-inner")return 0;let R=g.createElement(U),$=g.createElement("viv-ts-inner");if(R.appendChild($),e.parentNode.insertBefore(R,e),$.appendChild(e),X&&g.defaultView.getComputedStyle($.parentElement).textOrientation==="mixed"&&($.style.textOrientation="sideways"),P)return 0;let V=E($);if(V||L||A||z){if(U==="viv-ts-open"){if(L)R.className="viv-hang-first";else if(i||n)l.trimStart?R.className="viv-ts-trim":R.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&S())R.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||s.parentElement.localName==="viv-ts-inner"&&E(s.parentElement)))R.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&S()){let q=N();R.className="viv-ts-auto",q===N()&&!S()&&(R.className="viv-ts-trim")}}else if(U==="viv-ts-close"){if(A)R.className=V?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let q=N();z?(R.className=V?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&q===N()&&(l.trimEnd?R.className="viv-ts-trim":l.allowEnd?(R.className="viv-hang-end",q===N()&&(R.className="")):R.className="viv-ts-space")):l.trimEnd?R.className="viv-ts-trim":l.allowEnd?(R.className="viv-ts-auto",q===N()&&(R.className="")):R.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))V&&l.trimAdjacent&&(R.className="viv-ts-trim");else if(z){let q=b(),Q=q&&c.allowEnd;Q||(R.className=V?"viv-hang-end":"viv-hang-end viv-hang-hw"),V?Q&&l.trimEnd?R.className="viv-ts-auto":!Q&&!b()?R.className="":!q&&c.allowEnd&&(l.trimEnd?(R.className="viv-ts-auto",b()||(R.className="viv-hang-end")):(R.className="viv-ts-space",b()||(l.allowEnd?(R.className="viv-ts-auto",b()||(R.className="viv-hang-end")):R.className="viv-hang-end"))):!q&&!b()&&(R.className="")}else if(l.trimEnd||l.allowEnd)if(b())l.allowEnd?R.className="viv-ts-space":R.className="viv-ts-auto";else{let q=N();R.className="viv-ts-auto",q===N()&&(R.className="")}}}}let _=!1;function F(E){var N;let R=(N=E?.ownerDocument.defaultView)==null?void 0:N.getComputedStyle(E);return!!R&&(R.textOrientation==="upright"||R.textCombineUpright==="all"||R["-webkit-text-combine"]==="horizontal")}function D(E,N){if(E.nodeType===Node.ELEMENT_NODE){let V=g.defaultView.getComputedStyle(E);if(parseFloat(V.marginInlineEnd)||parseFloat(V.borderInlineEndWidth)||parseFloat(V.paddingInlineEnd))return!0}let R=E.parentElement;if(R&&!R.contains(N))return D(R,N);if(N.nodeType===Node.ELEMENT_NODE){let V=g.defaultView.getComputedStyle(N);if(parseFloat(V.marginInlineStart)||parseFloat(V.borderInlineStartWidth)||parseFloat(V.paddingInlineStart))return!0}let $=N.parentElement;return $&&!$.contains(E)?D(E,$):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&F(s.parentElement))&&!D(s,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),_=!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&&F(a.parentElement))&&!D(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),_=!0)),v}registerHooks(){Ft("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Ft("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Ft("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},hh=new k0;hh.registerHooks();function E0(e){hh.preprocessForTextSpacing(e)}function P0(e,t,i,n,r,o){hh.processGeneratedContent(e,t,i,n,r,o)}var pr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),N0=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],uh="data-adapt-pseudo";function Yt(e){return e.getAttribute(uh)||""}function Er(e,t){e.setAttribute(uh,t)}var ya=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=Yt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=ft(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new W(new lt(o),0)}return r}processContent(e,t,i){let n=Yt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;It(r)&&(r.visit(new Lr(e,this.context,r,this.exprContentListener)),E0(e))}}},cC=hs.isInstanceOfAfterIfContinuesLayoutConstraint,T0=Hs.registerFragmentIndex,dC=Hs.clearFragmentIndices,A0=class{constructor(e,t){u(this,"sourceNode",e),u(this,"styler",t)}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new ch(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return I(o,"display","block"),T(o)})}createNodePositionForPseudoElement(){let e=pr.createElementNS("http://www.w3.org/1999/xhtml","div");Er(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 Mo(this.sourceNode,e,null,null,null,yi.ShadowType.ROOTED,this.styler)}},I0=class If{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),T(!0))):T(!0)}getRepetitiveElements(){return new F0(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof If?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},F0=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 Ff(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return T(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=L0(e,t,n);return t.fragmentLayoutConstraints.push(new I0(e,i,r)),T(e)})}function Rf(e,t){return e.thenAsync(i=>Ff(i,t))}function R0(e,t){let i=M("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Ff(n,t);return n=n.parent,r.thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result()}function L0(e,t,i){let n=e.viewNode;n.appendChild(i);let r=Da(i,t,e.vertical);return n.removeChild(i),r}var O0=class{constructor(e){u(this,"constraints",e)}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},fr=class extends jl{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]}},ks=class extends hp{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),u(this,"lineFootnoteOverflowEdge",null),mv(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=M("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let o=r,s=i[n];if(r=cs(s,o),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return T(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Lv(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,o=r.match(Qo),s=o?o[0].length:0;if(!o&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(Qo);if(h){let l=h[0];s=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(s)}}return this.layoutContext.peelOff(e,s)}return T(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=M("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;if(e.viewNode&&!Pn(e)&&((o=e.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let s=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(s);if(Rr(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(s=>{let a=s;a!==e&&(e=a,Pn(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(Ii(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}if(e.pluginProps.lineFootnoteOverflow){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 Rf(i,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let t=[],i=e.sourceNode,n=M("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!Pn(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(o=>{let s=o;if(s!==e){let a=s;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=s,r.breakLoop();return}Pn(s)||t.push(s.copy())}this.nextInTree(s).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Ii(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null,a=1.5/(this.clientLayout.pixelRatio||1);for(let p of t){let f=Math.abs(p.x1-i)<a&&Math.abs(p.x2-n)<a?a:void 0;this.almostEquals(p.x1,i,f)?p.x1=i:this.almostEquals(p.x1,n,f)&&(p.x1=n),this.almostEquals(p.x2,n,f)?p.x2=n:this.almostEquals(p.x2,i,f)&&(p.x2=i),this.almostEquals(p.y1,r,f)?p.y1=r:this.almostEquals(p.y1,o,f)&&(p.y1=o),this.almostEquals(p.y2,o,f)?p.y2=o:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=Gr==="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,v=f-t[p].x1,w=t[p].x2-g,x=0,m=0;v>d?x=1:v<-d&&(x=-1),w>d?m=1:w<-d&&(m=-1);let S=x!==0&&m!==0?x===m?x:0:x||m;if(h>0&&S!==0){let b=S*h;c[p]+b>=0&&(p>=t.length-1||c[p+1]-b>=0)&&(c[p]+=b,p<t.length-1&&(c[p+1]-=b))}}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?s=f:s||I(f.right,"float","none")}if(s){let p=t[t.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(s!==p&&(p.y2>=o||this.almostEquals(p.y2,o,f))&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let g=t.indexOf(s);g<t.length;g++){let v=t[g];this.element.removeChild(v.left),this.element.removeChild(v.right),v.left=null,v.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),n=1.5/(this.clientLayout.pixelRatio||1);if(i>0&&i<t&&!this.almostEquals(i,t,n)){let r=this.vertical?"width":"height";if(I(this.element,r,`${i}px`),this.vertical){let o=this.left+(t-i);I(this.element,"left",`${o}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&En(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=bn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let o=n-e.boxOffset;for(;;){if(r=bn(e,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(o=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new ia(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 ia(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 ia(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=M("layoutFloat"),i=e.viewNode,n=la(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let o=Bt(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new Mt(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let b=c.viewNode.ownerDocument.createElement("div");b.style.left="0px",b.style.top="0px",this.vertical?(b.style.bottom="0px",b.style.width="1px"):(b.style.right="0px",b.style.height="1px"),c.viewNode.appendChild(b);let C=Bt(this.clientLayout,b,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(b);let P=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+P):h=Math.min(h,l-P),c!==e.parent&&!e.firstPseudo&&(c.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new Mt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=rs(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let b=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+b}if(e.clearSide){let b=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?la(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,C=this.beforeEdge;b!=="right"&&(C=f*Math.max(C*f,this.leftFloatEdge*f)),b!=="left"&&(C=f*Math.max(C*f,this.rightFloatEdge*f));let P=C*f;if(p.y1<P){let L=p.y2-p.y1;p.y1=P,p.y2=p.y1+L}}d.y2+=this.getFloatLayoutUnit(),$m(d,this.bands,p,n),this.vertical&&(a=sd(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let v,w=null;if(c&&(c.containingBlockForAbsolute?w=c:w=c.getContainingBlockForAbsolute()),w){let b=w.viewNode.ownerDocument.createElement("div");b.style.position="absolute",w.vertical?b.style.right="0":b.style.left="0",b.style.top="0",w.viewNode.appendChild(b),v=Bt(this.clientLayout,b,this.vertical),w.viewNode.removeChild(b)}else v={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(w?w.vertical:this.vertical){let b=Math.max(0,v.right-a.x2);I(i,"right",`${b}px`)}else{let b=Math.max(0,a.x1-v.left);I(i,"left",`${b}px`)}let x=Math.max(0,a.y1-v.top);I(i,"top",`${x}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let m=this.vertical?a.x1:a.y2,S=this.vertical?a.x2:a.y1;!this.isOverflown(m)||this.breakPositions.length==0?(this.killFloats(),d=new Mt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=rs(d)),Hm(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=m:this.rightFloatEdge=m,this.bottommostFloatTop=S,this.updateMaxReachedAfterEdge(m),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!s.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let c=!!s.setFloatAreaDimensions(e,t,i,n,!0,e.isFootnote||!s.hasFloatFragments(),o);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,I(e.element,"width",`${p}px`))}else{let p=parseFloat(d.maxHeight);!isNaN(p)&&e.height>p&&(e.height=p,I(e.element,"height",`${p}px`))}}e.killFloats(),e.init()}else a.element.parentNode.removeChild(h);return T(c)})}createPageFloatArea(e,t,i,n,r){let o=this.element.ownerDocument.createElement("div");I(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new Sn(null,Pe.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=s.getContainer(),l=new _0(t,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(c=>T(c?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,o,s){let a=this.pageFloatLayoutContext;e=(s?s.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c={floatArea:null,pageFloatFragment:null,newPosition:null},d=M("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,o,r,l).then(p=>{if(c.floatArea=p,!p){d.finish(c);return}let f=!1,g=0;d.loopWithFrame(v=>{if(g>=e.length){v.breakLoop();return}let w=e[g],x=new Bi(w.nodePosition),m=p.getRootViewNodeCount();p.layout(x,!0).then(S=>{if(c.newPosition=S,!S||n){if(S&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.some(b=>b instanceof fr)&&p.hasNonPseudoTextContentAfter(m))){f=!0,v.breakLoop();return}g++,v.continueLoop()}else f=!0,v.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&c.newPosition){let v=a.getPageFloatLayoutContext(h.floatReference);if(v.footnoteMaxBlockSize==null){if(v.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(e,t,i,n,r,o,s).then(w=>{d.finish(w)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let v=a.setFloatAreaDimensions(p,h.floatReference,t,o,!1,n,l);if(!v)f=!0;else{let w=r.createPageFloatFragment(e,v,i,p,!!c.newPosition);a.addPageFloatFragment(w,!0),c.pageFloatFragment=w}}d.finish(c)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,o=e.float,s=o instanceof Or,a=s&&o.footnotePolicy===y.line&&!!n&&!n.hasFloat(o),h=new Set;for(let d=r;d;d=d.effectiveParent)for(let p of d.floatFragments)p.continuations.some(f=>f.float.insidePageFloatArea)&&h.add(p);a||r.stashEndFloatFragments(o);function l(d,p){p?r.removePageFloatFragment(p,!0):d&&d.element.parentNode.removeChild(d.element);let f=[];for(let g=r;g;g=g.effectiveParent)for(let v of g.floatFragments)!h.has(v)&&v.continuations.some(w=>w.float.insidePageFloatArea)&&f.push(v);for(let g of f)r.removePageFloatFragment(g,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(e)}let c=M("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],o.floatSide,o.clearSide,s||!r.hasFloatFragments(),t,i,a?null:n).then(d=>{let p=d.floatArea,f=d.pageFloatFragment,g=d.newPosition;f?this.layoutStashedPageFloats(o.floatReference,[n]).then(v=>{if(v){let w=f;if(a&&n){let b=n.area,C=b.getRootViewNodeCount();if(b.appendContentFrom(f.area),r.removePageFloatFragment(f,!0),!r.setFloatAreaDimensions(b,o.floatReference,n.floatSide,i,!1,!0,r.getPageFloatPlacementCondition(o,o.floatSide,o.clearSide))){b.removeContentAfter(C),l(p,f),c.finish(!1);return}n.addContinuations(f.continuations),w=n}let x=!!r.generatingNodePosition,m=!x&&o instanceof Or&&o.footnotePolicy===y.line,S=m&&r.hasInvalidatedForLineFootnote(o);if(r.addPageFloatFragment(w,x||S),m&&!S&&r.markInvalidatedForLineFootnote(o),r.discardStashedFragments(o.floatReference),g){let b=new cu(o,g.primary);r.deferPageFloat(b)}c.finish(!0)}else l(p,f),c.finish(!1)}):(l(p,f),c.finish(!1))}),c.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],o=[],s=!1,a=M("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 Vn().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?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.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(!s)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Yt(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(zn,"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=M("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Pe.REGION);return r.getContainer().width<o.getContainer().width&&e===Pe.COLUMN?t===y.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=Ul(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Pe.REGION):n.finish(e)}):t===y.all?n.finish(Pe.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Vn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=T(r):n=i.createPageFloat(e,t,this),n.thenAsync(o=>{let s=us(e,0),a=this.setFloatAnchorViewNode(e);t.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,t),l=new cu(o,s);if(h&&h.hasFloat(o))return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(t.isForbidden(o)||t.hasPrecedingFloatsDeferredToNext(o))return t.deferPageFloat(l),t.registerPageFloatAnchor(o,a.viewNode),T(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let c=p=>{if(!p||p.nodeType!==1)return NaN;let f=Bt(this.clientLayout,p,this.vertical);return f.right>=f.left&&f.bottom>=f.top?this.vertical?f.left:f.bottom:NaN},d=bn(a,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let p=o;if(p.footnotePolicy===y.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)),!(e.floatSide==="footnote"&&o.footnotePolicy===y.line)&&this.isOverflown(d)?T(a):(e.floatSide==="footnote"&&t.registerPageFloatAnchor(o,a.viewNode),this.layoutPageFloatInner(l,i,d,h).thenAsync(p=>{if(!p)return t.registerPageFloatAnchor(o,a.viewNode),T(a);if(e.floatSide==="footnote"){if(o.footnotePolicy===y.line&&t.hasInvalidatedForLineFootnote(o)){if(t.isInvalidated())return T(null);let f=i.findPageFloatFragment(o,t);if(f!=null&&f.hasFloat(o)&&f.continues)return this.registerLineFootnoteOverflowEdge(d),T(a)}return T(a)}return t.generatingNodePosition?T(a):T(null)}))}})}processLineStyling(e,t,i){let n=M("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=e.firstPseudo;return s?.count===0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(r,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(c,0).then(d=>{e=d,s=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}registerLineFootnoteOverflowEdge(e){if(!isFinite(e))return;let t=this.getBoxDir();(this.lineFootnoteOverflowEdge==null||t*e<t*this.lineFootnoteOverflowEdge)&&(this.lineFootnoteOverflowEdge=e)}findLineFootnoteOverflowBreak(e){if(this.lineFootnoteOverflowEdge==null||e.length===0)return null;let t=this.findLinePositions(e),i=this.getBoxDir(),n=1.5/(this.clientLayout.pixelRatio||1),r=t.find(o=>i*(o-this.lineFootnoteOverflowEdge)>=-n);return r==null?null:this.findAcceptableBreakInside(e,r,!0)}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 o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?t=Math.max(t,s):i=Math.min(i,s)}return t+i}layoutBreakableBlock(e){let t=M("layoutBreakableBlock"),i=[];return this.lineFootnoteOverflowEdge=null,this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??e),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!En(n.viewNode)){let l=Ln(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=T(n),h.then(l=>{let c=this.findLineFootnoteOverflowBreak(i);if(c){let d=c.modify();d.overflow=!0,d.pluginProps.lineFootnoteOverflow=1,this.breakPositions=[],this.saveEdgeBreakPosition(d,null,!0),this.lineFootnoteOverflowEdge=null,t.finish(d);return}this.lineFootnoteOverflowEdge=null,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){_t("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,o=t[0].boxOffset,s=r,a=t.length-1,h=t[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let c=a;for(;s<c;){let p=s+Math.ceil((c-s)/2);t[p].boxOffset>l?c=p-1:s=p}let d=this.calculateEdge(null,t,s,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(d),o=l,r=s}return{nodeContext:t[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(e,t,i){var n,r,o;let s=this.findEndOfLine(t,e,!0),a=s.nodeContext;if(s.checkPointIndex===0&&s.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,s.index,e,s.checkPointIndex,i)}else{let l=au(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof fr&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let c=(o=a.viewNode)==null?void 0:o.previousSibling;for(;c&&(Ee(c,a.parent.whitespace)||Ot(c));)c=c.previousSibling;if(c)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return _t("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Es.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,o=e,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;o==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=o.nodeType===1?o:null;d?r?r=!1:Vl(d)?l=!a:!d.firstChild||ji[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||xv(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(d.localName)||(s=o),o.contains(t)&&(h=!1)):c=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),c||(c=o.nextSibling,c||(r=!0,c=o.parentNode)),o=c}while(l&&h);if(a){n.setEndAfter(s);let c=this.clientLayout.getRangeClientRects(n);as(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?$v:Uv);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(s>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(s==0||c>=.6||c>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(t.push(r),s=0),a>=i.length)break}return t.sort(Ec),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&Nn(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=Ln(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let s,a;t&&!this.isFootnote?(s=1,a=1):(s=Math.max((o.inheritedProps.widows||2)-0,1),a=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),l=this.findLinePositions(r),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 S=l[m];return this.vertical?S<c||S<=f.edge:S>c||S>=f.edge}),v=g<=0;v&&(g=mi(l.length,m=>this.vertical?l[m]<c:l[m]>c));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(s=0,a=1),g=Math.min(l.length-s,g),g<a)return null;c=l[g-1];let x;if(v?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 S=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[S]-l[S-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,bn(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 ir().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=ql.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let o=e.getMinBreakPenalty();o>i&&(n=Math.min(n,o))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return T(e);let r=M("doFinishBreak"),o=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return Y.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();e=i,o=!0,this.computedBlockSize=n}return this.finishBreak(e,o,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Ot(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(!ss(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||Nn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");Ct(n,"block-end"),t.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let s=e;s;s=s.parent)if(Ot(s.viewNode))return!1;if(En(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=bn(e,this.clientLayout,0,this.vertical);i();let r=Ln(e,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let s=n+this.getTrailingMarginEdgeAdjustment(t),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||En(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Pe.INLINE||e.floatSide)return!1;let t=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 o=()=>i?this.clientLayout.getElementClientRect(r):Bt(this.clientLayout,r,this.vertical);e.viewNode.parentNode.insertBefore(r,e.viewNode);let s=o(),a=this.getBeforeEdge(s),h=this.getBoxDir(),l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(t)?la(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 w=d*h>p*h;d=h*(Math.ceil(d*h/f)+(w?1:0))*f}let v=this.getFloatLayoutTolerance(f);if(a*h+v>d*h)return e.viewNode.parentNode.removeChild(r),!1;{let w=Math.max(1,(d-a)*h);this.vertical?r.style.width=`${w}px`:r.style.height=`${w}px`,s=o();let x=this.getAfterEdge(s);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!!(dw(e)||Yi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(su(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return T(e);let o=M("skipEdges"),s=this,a=!i&&t&&e&&e.after,h=i,l=null,c=[],d=[],p=!1;function f(C){var P,L;if(!(!t||s.isNonFirstColumn||i||!lu(h))){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((P=A.viewNode)==null?void 0:P.nodeType)===1){let z=A.viewNode;((L=z.style)==null?void 0:L.breakBefore)==="column"&&(z.style.breakBefore="")}}}function g(C){var P,L;if(!(!t||!s.isNonFirstColumn||i||h!=="column")){for(let A=C;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((P=A.viewNode)==null?void 0:P.nodeType)===1){let z=A.viewNode;((L=z.style)==null?void 0:L.breakBefore)==="column"&&(z.style.breakBefore="")}h=null}}function v(C){var P,L;if(!(i||!lu(h))){for(let A=C;A;A=A.parent)if(A.breakAfter==="column"&&(A.breakAfter=null),((P=A.viewNode)==null?void 0:P.nodeType)===1){let z=A.viewNode;((L=z.style)==null?void 0:L.breakAfter)==="column"&&(z.style.breakAfter="")}}}function w(C){h=nt(h,C)}function x(){return i?!0:Ze(h)?t?s.isNonFirstColumn&&h!=="column"&&h!=="region":!m()&&!S():!1}function m(){var C;if(!l||!e||e.floatSide)return!1;for(let P=l;P!=null&&P.parent;P=P.parent){if(P.parent.viewNode&&Ot(P.parent.viewNode))continue;let L=P.after?P.viewNode:(C=P.viewNode)==null?void 0:C.previousSibling;for(;L&&(Ee(L,P.parent.whitespace)||Ot(L));)L=L.previousSibling;if(L)return!1}return!0}function S(){var C,P;if(l||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((C=e.parent)!=null&&C.viewNode)||Ot(e.parent.viewNode))return!1;let L=!1;for(let A=e;A!=null&&A.parent&&!A.after;A=A.parent){if(A!==e&&Ot(A.viewNode))return!1;let z=(P=A.viewNode)==null?void 0:P.previousSibling;for(;z&&(Ee(z,A.parent.whitespace)||Ot(z));)Ot(z)&&(L=!0),z=z.previousSibling;if(z)return!1}return L}let b=()=>{e=c[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return o.loopWithFrame(C=>{for(var P;e;){e.formattingContext;let L=new ir().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){w(e.breakBefore),f(e),g(e),x()?b():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=ls(h)?h:null),L&&L.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?au(l):this.breakPositions[this.breakPositions.length-1]instanceof fr||!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()),w(e.breakBefore),f(e),g(e),x()?b():(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,U=z.style;if(e.after){Hd(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,w(e.breakAfter),v(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||L&&L.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(su(e.viewNode))break;if(x()){b(),C.breakLoop();return}c=[],t=!1,a=!1,h=null}p=!1,Gd(e.viewNode)||(l=e.copy(),d.push(l)),w(e.breakAfter),v(e),U&&!Ot(e.viewNode)&&this.hasNonZeroBlockEndInset(U)&&(d=l?[l]:[])}else{if(c.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Ze(h)&&yv(l.viewNode,e.viewNode),(e.pageType!=((P=e.parent)==null?void 0:P.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()?b():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),C.breakLoop();return}U&&this.hasNonZeroBlockStartInset(U)&&(a=!1,d=[]),p=!0}}while(!1);let A=this.nextInTree(e,a);if(A.isPending()){A.then(z=>{e=z,C.continueLoop()});return}else e=A.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()),o.finish(e)}),o.result()}skipTailEdges(e){let t=e.copy(),i=M("skipEdges"),n=null,r=!1;return i.loopWithFrame(o=>{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),o.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=nt(n,e.breakBefore),Ze(n)&&(this.pageBreakType=n),o.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ze(n)){this.pageBreakType=n,o.breakLoop();return}n=null}r=!1,n=nt(n,e.breakAfter)}else{n=nt(n,e.breakBefore);let h=e.viewNode.localName;if(ji[h]){Ze(n)&&(this.pageBreakType=n),o.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){o.breakLoop();return}}r=!0}while(!1);let s=this.layoutContext.nextInTree(e);if(s.isPending()){s.then(a=>{e=a,o.continueLoop()});return}else e=s.get()}t=null,o.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(Ii(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Pe.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=M("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let o=e.formattingContext;new ir().find(o).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new ir().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 Mt(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=zm(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new ir().find(e.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new fr(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);Dl(this);let n=M("layout");return this.openAllViews(e.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new B0(t,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=T(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(ss(this)&&(bv(this),Ds(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let 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=M("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=M("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;e;){let s=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let s=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=s}this.killFloats(),this.init();let i=M("redoLayout"),n=0,r=null,o=!0;return i.loopWithFrame(s=>{if(n<e.length){let a=e[n++];this.layout(a,o).then(h=>{o=!1,h?(r=h,s.breakLoop()):s.continueLoop()});return}s.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Yi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(hs.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},ch=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(o){return ks.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),T(s)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new to(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 o=r.data.slice(e.offsetInNode);if(!ip(o,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Ee(o,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Es=class{breakTextNode(e,t,i,n,r,o){if(t.after)t.offsetInNode=e.length;else{let s=i-t.boxOffset,a=e.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(e,a,s,t):s=this.breakAfterOtherCharacter(e,a,s,t),s>0&&(t=this.updateNodeContext(t,s,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+Du(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let o=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Fh(r)&&Fh(o)?Du(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Es,"instance");Es.instance=new Es;function Du(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var B0=class extends Yl{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 M0(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||fw()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Wd(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}},M0=class{constructor(e,t,i){u(this,"leadingEdge",e),u(this,"breakAfter",t),u(this,"context",i)}doLayout(e,t){let i=M("DefaultLayoutMode.doLayout");return R0(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},_0=class extends ks{constructor(e,t,i,n,r,o,s){super(t,i,n,r,o),u(this,"floatSide",e),u(this,"parentContainer",s),u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0),u(this,"parentElement"),this.parentElement=s.element}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),T(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(o,s){o.forEach(a=>{let h=ki(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=s*l/100;I(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(o=>{ki(e,o)==="auto"&&I(e,o,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=ki(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ki(t,"width");n!==""&&n!=="auto"&&I(t,"margin-left","auto")}}}getRootViewNodeCount(){return this.rootViewNodes.length}hasNonPseudoTextContentAfter(e){let t=i=>{var n;return i.nodeType===Node.TEXT_NODE?!!((n=i.textContent)!=null&&n.trim()):i.nodeType!==Node.ELEMENT_NODE||Yt(i)?!1:Array.from(i.childNodes).some(t)};return this.rootViewNodes.slice(e).some(t)}appendContentFrom(e){e.rootViewNodes.forEach(t=>{this.element.appendChild(t)}),this.rootViewNodes.push(...e.rootViewNodes),this.floatMargins.push(...e.floatMargins),e.rootViewNodes.splice(0),e.floatMargins.splice(0),e.element.parentNode&&e.element.parentNode.removeChild(e.element),this.applyCompactFootnoteDisplay(),this.updateComputedBlockSizeForFootnoteArea(!0)}removeContentAfter(e){let t=this.rootViewNodes.splice(e);this.floatMargins.splice(e),t.forEach(i=>{i.parentNode&&i.parentNode.removeChild(i)}),this.applyCompactFootnoteDisplay(),this.updateComputedBlockSizeForFootnoteArea(!0)}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Bt(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(Ht);if(!g||!t||!i)return!1;let v=i.getNodeByOffset(parseInt(g,10));if(!v||v.nodeType!==Node.ELEMENT_NODE)return!1;let w=t.getStyle(v,!1),x=(d=(c=ve(w,"footnote-display"))==null?void 0:c.value)==null?void 0:d.toString(),m=!!((p=ve(w,"--viv-marker-content"))!=null&&p.value);return x==="compact"&&!m});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea(!0);return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let c=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?c.height:c.width};n.forEach(h=>{a(h)>o+s&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea(!0)}updateComputedBlockSizeForFootnoteArea(e=!1){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let t=this.getBoxDir(),i=this.beforeEdge;if(e){let n=Bt(this.clientLayout,this.element,this.vertical),r=this.vertical?this.borderRight+this.paddingRight:this.borderTop+this.paddingTop;i=this.getBeforeEdge(n)+t*r}this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(n=>{let r=Bt(this.clientLayout,n,this.vertical),o=this.getComputedMargin(n),s=this.vertical?o.left:o.bottom;return t*(this.getAfterEdge(r)-i)+Math.max(0,s)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(t=>Yt(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&&Pt(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let t=e.ownerDocument.createElement("span");Er(t,"after"),t.setAttribute("data-vivliostyle-default-footnote-separator","1"),t.style.whiteSpace="normal",t.textContent=" ",e.appendChild(t)}getFootnoteBreakOpportunity(e){let t=e.nextElementSibling;return t!=null&&t.hasAttribute("data-vivliostyle-footnote-break")?t:null}createFootnoteBreakOpportunity(e){let t=e.ownerDocument.createElement("wbr");t.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",t)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[t+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),c=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!d?this.createFootnoteBreakOpportunity(r):p&&d?.remove()}else 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||ja.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new D0(e,this.rootSourceNode),ja.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},D0=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=us(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=us(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Da(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Da(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,o=t.viewNode,s=r.createElement("div");o.appendChild(s);let a=new ch(n,s,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Bi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(s),this.moveChildren(s,o,i),a.getColumn().pageBreakType=h,T(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(zn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Lf=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}},Of=class{constructor(e){u(this,"formattingContext",e)}accept(e,t){return!0}postLayout(e,t,i,n){return n}},z0=class extends Lf{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},V0=class extends Of{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new dh(e)),this.processor.doLayout(e,t)}},dh=class Bf{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||En(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!_f(t,i,r):!0}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let o=this.getRepetitiveElements();o&&t&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(t,i){let n=di(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return T(!0);let o=this.nodeContext;return G0(n,o,i).thenAsync(()=>j0(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return di(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Bf?di(this.nodeContext.formattingContext)===di(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},U0=class extends Yl{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 z0(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new V0(this.formattingContext,this.processor))}},$0=class extends br{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),T(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),T(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return br.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?T(!0):br.prototype.afterNonInlineElementNode.call(this,e)}},H0=class extends Tn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=di(e.formattingContext);return n.getRootViewNode(e)?(i&&Mf(e.parent,t),e.belongsTo(n)?Tn.prototype.layout.call(this,e,t,i):new U0(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=X0(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=M("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=di(e.formattingContext),n=new $0(i,t);return new Ga(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=di(e.formattingContext),n=M("doLayout"),r=t.layoutContext.nextInTree(e,!1);return Rf(r,t).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(t.layoutNext(s,!1).then(l=>{s=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||s&&t.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(e,t,i,n){return Tn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Tn.prototype.clearOverflownViewNodes(e,t,i,n)}};function W0(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 Mf(e,t){e&&W0(e.after?e.parent:e,(i,n)=>{Li.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new dh(n))})}function G0(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let o=r.viewNode.firstChild;return n.appendHeaderToFragment(r,o,i)}}return T(!0)}function j0(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return T(!0)}function _f(e,t,i){let n=i.ownerSourceNode,r=e||t;return!r||n.contains(r.sourceNode)}function X0(e){let t=e.formattingContext;return!t||!(t instanceof tn)?null:t}function di(e){return e instanceof tn,e}var q0=new H0;Ft("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof tn&&!Li.isInstanceOfTableFormattingContext(e)?q0:null);var Df=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))}},Y0=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}},Z0=class{constructor(e,t,i){u(this,"rowIndex",e),u(this,"columnIndex",t),u(this,"cell",i)}},K0=class{constructor(e,t,i){u(this,"column",e),u(this,"cellNodeContext",i),u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new ch(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},J0=class{constructor(e,t){u(this,"viewNode",e),u(this,"side",t)}},Q0=class extends to{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)}},ex=class extends jl{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(o=>!!o.nodeContext)&&n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext&&o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof fr&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof to&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Bn=class extends 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 Df(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),o=0;for(;r[o];)o++;for(;e<n;e++){r=this.getRowSlots(e);for(let s=o;s<o+t.colSpan;s++){let a=r[s]=new Z0(e,s,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}isPreviousFragmentRowSpanningCellBreakPosition(e,t){let i=e.cell;return t>=0&&i.rowIndex<t&&i.rowIndex+i.rowSpan>t}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Bt(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let o=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!o||t.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),t.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new tx(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)}},tx=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=Ln(e,n);i=Math.max(i,t(r))}),i}};function $t(e){return e instanceof Bn,e}function ix(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function nx(e){return e==="table"||e==="inline-table"}function zu(e){return ix(e)||nx(e)}function zf(e,t,i){let n=e.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof Bn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof Bn){s=a.formattingContext===t;break}}return s||r==="table-row"&&!zu(o)||r==="table-cell"&&o!=="table-row"&&!zu(o)||n.formattingContext instanceof Bn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,T(!0))):null}function Vf(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(Ii(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var rx=class extends br{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=zf(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Vf(this.column,e);if(n)return n;let r=e.nodeContext,o=r.display,s=t.getRepetitiveElements();switch(o){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new J0(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Df(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let o=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(o[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let o=t.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=nt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;t.addCell(this.rowIndex,new Y0(this.rowIndex,this.columnIndex,o)),this.columnIndex++,Wf(o);let s=t.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=nt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=nt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!Pn(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Uf=class $f extends br{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 Vf(this.column,t)||super.startNonInlineElementNode(t)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,o=t.columnIndex,s=t.colSpan,a=i.viewNode;s>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new K0(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(Wf(a),T(!0)))}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorSlot.columnIndex===t&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[];return t.forEach(n=>{let r=n.cell,o=r.rowIndex;if(o<this.currentRowIndex&&o+r.rowSpan>this.currentRowIndex){let s=i[o];s||(s=i[o]=[]),s.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return T(!0);let o=this.column.layoutContext,s=t.nodeContext;s.viewNode.parentNode.removeChild(s.viewNode);let a=M("layoutRowSpanningCellsFromPreviousFragment"),h=T(!0),l=0,c=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=cs(d[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let f=T(!0),g=0;function v(w){for(;g<w;){if(!c.includes(g)){let x=p.viewNode.ownerDocument.createElement("td");I(x,"padding","0"),p.viewNode.appendChild(x)}g++}}return d.forEach(w=>{f=f.thenAsync(()=>{let x=w.cell;v(x.anchorSlot.columnIndex);let m=w.cellNodePosition,S=cs(m.steps[0],p);return S.offsetInNode=m.offsetInNode,S.after=m.after,S.fragmentIndex=m.steps[0].fragmentIndex+1,o.setCurrent(S,!1).thenAsync(()=>{let b=w.breakChunkPosition;for(let C=0;C<x.colSpan;C++)c.push(g+C);return g+=x.colSpan,this.layoutCell(x,S,b).thenAsync(()=>(S.viewNode.rowSpan=x.rowIndex+x.rowSpan-this.currentRowIndex+r-l,T(!0)))})})}),f.thenAsync(()=>(v(i.getColumnCount()),l++,T(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=nt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=nt(o,s.breakBefore)),!t.leadingEdge&&Ze(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),t.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),T(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);T0(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return T(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,T(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let o=M("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=T(h.breakChunkPosition)}else s=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=us(h,0);return T(new Bi(l))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(t){let i=zf(t,$t(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(t):o==="table-cell"?this.startTableCell(t):T(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new ex(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):I(i.viewNode,"display","table-row-group")),r&&$f.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else if(r==="table-row"&&!this.inHeader&&!this.inFooter){let o=super.afterNonInlineElementNode(t);return(o&&o.isPending()?o:T(!0)).thenAsync(()=>{if(!t.break){let s=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!s&&h&&!!(a!=null&&a.isFooterRegistered());(s||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0)}return T(!0)})}else return super.afterNonInlineElementNode(t);return T(!0)}};u(Uf,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var ox=Uf,zr=[];function sx(e){let t=zr.findIndex(n=>n.root===e),i=zr[t];return i?i.tableLayoutOption:null}function ax(e){let t=zr.findIndex(i=>i.root===e);t>=0&&zr.splice(t,1)}var Hf=class{layoutEntireTable(e,t){let i=$t(e.formattingContext),n=new rx(i,t);return new Ga(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<t;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}e.parentNode.insertBefore(o,e.nextSibling);let a=s.map(h=>{let l=Bt(n,h,i),c=i?l.height:l.width;return Math.ceil(c)});return e.parentNode.removeChild(o),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),t.push(s)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let o=e.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),e.push(s)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=e.getColumnCount();if(!(s>0)){e.colGroups=o;return}let a=e.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,t),l.forEach((c,d)=>{I(c,n?"height":"width",`${a[d]}px`)}),h.forEach(c=>{o.appendChild(c.cloneNode(!0))}),e.colGroups=o}doInitialLayout(e,t){let i=$t(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=sx(e.sourceNode);ax(e.sourceNode);let r=M("TableLayoutProcessor.doInitialLayout"),o=e.copy();return this.layoutEntireTable(e,t).then(s=>{var a;let h=s.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(o);return}let c=Bt(t.clientLayout,h,t.vertical),d=t.vertical?c.left:c.bottom;if(d+=(t.vertical?-1:1)*Ln(e,t.collectElementsOffset()).current,!t.isOverflown(d)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new cx(o)),r.finish(s);return}this.normalizeColGroups(i,h,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&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&&!Ot(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,o)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),I(t,"table-layout","fixed"),I(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=$t(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new ox(i,t),s=new Ga(o,t.layoutContext),a=M("TableFormattingContext.doLayout");return s.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=$t(e.formattingContext);if(n.getRootViewNode(e)){if(i){let r=n.getRepetitiveElements();r&&e.sourceNode!==n.tableSourceNode&&!e.after&&!r.isFooterRegistered()&&r.preventSkippingHeader(),Mf(e.parent,t)}return new hx(n,this).layout(e,t)}else return t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Q0(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return va(e),!1}finishBreak(e,t,i,n){let r=$t(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let o=r.findRowIndexBySourceNode(t.sourceNode),s;if(t.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=M("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let c=s[h++],d=r.getCellFragmentOfCell(c),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),v=new Bi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:v,cell:c});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),o<c.rowIndex+c.rowSpan-1&&(w.rowSpan=o-c.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{lx(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),va(t),r.finishFragment(),a.finish(!0)}),a.result()}}return va(t),r.finishFragment(),ql.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Tn.prototype.clearOverflownViewNodes(e,t,i,n)}};function lx(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,o=e.column,s=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=Bt(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let c=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;I(s,"max-width",`${c}px`)}else{let c=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(s,"max-height",`${c}px`)}}function Wf(e){let t=e.matches("td, th")?e:e.closest("td, th");if(!t||t.style.verticalAlign!=="baseline")return;let i=t.querySelector(".-vivliostyle-table-cell-container");if(!i)return;let n=i.children;if(n.length!==0){for(let r=0;r<n.length;r++){let o=n[r].style.position;if(o!=="absolute"&&o!=="fixed")return}I(i,"display","contents")}}function va(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),g=e.vertical?f.width:f.height;return d+g},0),r=i[i.length-1],o=Array.from(t.children).indexOf(r),s=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(d,f):d},0),a=s?t.children[o+s-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,c=n+l;I(a,e.vertical?"width":"height",`${c}px`)}var hx=class extends Yl{constructor(e,t){super(),u(this,"tableFormattingContext",e),u(this,"processor",t)}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new ux(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new px(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()}},ux=class extends Lf{constructor(e,t){super(e),u(this,"processor",t)}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},cx=class extends to{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 dx(this.position.sourceNode))}},dx=class Gf{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,zr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return T(!0)}equalsTo(t){return t instanceof Gf&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},px=class extends Of{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 fx(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},fx=class jf extends dh{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||En(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!t||t&&t.overflow?!_f(t,i,r):!0}nextCandidate(t){let i=$t(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let o=$t(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(t,s.breakPosition,n,r)})}),!t){let s=o.getRootViewNode(this.nodeContext);new Hf().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=$t(this.nodeContext.formattingContext),r=M("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return T(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=$t(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof jf?$t(this.nodeContext.formattingContext)===$t(t.nodeContext.formattingContext):!1}},gx=new Hf;function mx(e,t,i,n,r,o){if(!t)return null;if(i===y.table){let s=e.parent;return new Bn(s?s.formattingContext:null,e.sourceNode)}return null}function yx(e){return e instanceof Bn?gx:null}Ft("RESOLVE_FORMATTING_CONTEXT",mx);Ft("RESOLVE_LAYOUT_PROCESSOR",yx);function Vu(e){return e.reduce((t,i)=>t+i,0)/e.length}function vx(e){let t=Vu(e);return Vu(e.map(i=>{let n=i-t;return n*n}))}var wx=class{constructor(e,t){u(this,"layoutResult",e),u(this,"penalty",t)}};function Vr(e){return e.vertical?e.width:e.height}function Ur(e,t){e.vertical?e.width=t:e.height=t}var Xf=class{constructor(e,t,i){u(this,"layoutContainer",e),u(this,"columnGenerator",t),u(this,"regionPageFloatLayoutContext",i),u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Vr(e)}balanceColumns(e){let t=M("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new wx(e,t)}preBalance(e){}postBalance(){Ur(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let o=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${o}px`),i.width=t,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},pl=1;function qf(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+pl}function Yf(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+pl))-pl;n<Vr(t)?Ur(t,n):Ur(t,Vr(t)-1)}var bx=class extends Xf{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);Ur(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 Uu(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return qf(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Uu(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Vr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Yf(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Vr(this.layoutContainer)+this.originalContainerBlockSize*.1);Ur(this.layoutContainer,t)}}};function Uu(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>t>o.computedBlockSize+r)}var xx=class extends Xf{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 vx(t)}hasNextCandidate(e){return qf(e)}updateCondition(e){Yf(e,this.layoutContainer)}};function Sx(e,t,i,n,r,o,s){if(t===y.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new bx(i,n,r,e):t===y.balance_all?new xx(i,n,r):(y.balance,null)}}var wa=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Cx=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 wa(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 wa(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new wa(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 kx(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Ex=class fl{constructor(t,i,n,r,o,s,a,h){if(u(this,"context",t),u(this,"style",i),u(this,"offset",n),u(this,"isRoot",r),u(this,"flowChunk",o),u(this,"atBlockStart",s),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=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new fl(t,l.before,n,!1,o,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)&&(o.breakBefore=nt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new fl(this.context,r.after,t,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");It(s)&&(this.afterBox=o)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Ud(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!vr(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}},Px=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()!==y.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new Ex(this.context,e,t,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",y.normal).toString(),n=tp(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,o,s,a,h,l){u(this,"xmldoc",e),u(this,"scope",i),u(this,"context",n),u(this,"primaryFlows",r),u(this,"validatorSet",o),u(this,"counterListener",s),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,s,a,e.lang,h,l),this.offsetMap=new Cx;let c=e.getElementOffset(this.root);this.lastOffset=c,this.boxStack=new Px(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 W(r,Ld))}}}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&&!Z(n)||r&&!Z(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<Hu.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Hu[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!Z(n.value)){let a=n.evaluate(this.context);if(a instanceof O){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*Zt.lh/Zt.em;break;default:{let l=Zt[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let o=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,s=e["line-height"];if(s&&!Z(s.value)){let a=s.evaluate(this.context);if(a instanceof At)this.context.rootLineHeight=a.num*o;else if(a instanceof O){let h=a.num;switch(a.unit){case"em":case"rem":h*=o;break;case"%":h*=o/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=Zt[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return m0(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:kx(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=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 o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,c=l&&!Z(l.value)&&l.value.toString();c&&c.toLowerCase()!=="auto"&&(this.cascade.firstPageType=c)}let s=ve(o,"flow-into"),a=s?s.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=t["flow-options"];if(l){let v=Gm(l.evaluate(this.context,"flow-options"));s=!!v.exclusive,a=!!v.static,h=!!v.last}let c=t["flow-linger"];c&&(o=Kh(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=Kh(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let v=this.boxStack.lastFlowName();f=this.flows[e]=new zv(e,v)}let g=new Vv(e,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(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 o=this.last.firstChild;if(o==null)for(;this.last;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let s=this.boxStack.pop(this.lastOffset),a=null;if(s.afterBox){let h=s.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,s.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(s):s.afterBox.offset,s.flowName),a=s.afterBox.getBreakValue("after")}a=nt(a,s.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,s.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,!this.last||this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let s=this.last,a=this.getAttrStyle(s);this.primaryStack.push(this.primary),this.cascade.pushElement(this,s,a,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=s.getAttribute("id")||s.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&s.localName=="body"&&s.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,c=a["flow-into"];if(c){let p=c.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,s,this.lastOffset);this.primary=!!this.primaryFlows[p],l=this.boxStack.push(a,this.lastOffset,s===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,s===this.root),s===this.xmldoc.body&&(l.breakBefore=nt(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||s===this.xmldoc.body){let p=a.page,f=p&&!Z(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===y.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&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){}},Hu=["column-count","column-width","column-fill"],pC=`OTTO${new Date().valueOf()}`;function ph(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Nx(e){let t=new gi;for(let i of ph(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Tx(e,t){let i={};for(let n in e)i[n]=ve(e,n).evaluate(t,n);return i}var Zf=class{constructor(e){u(this,"properties",e),u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=Nx(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 {
1877
+ }`;function ea(t,e,i){let n=V("fetchFromURL"),r={method:i||"GET",mode:"cors"},o=n.suspend(),s={status:0,statusText:"",url:t,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(t,r).then(a=>{var h,l;if(s.status=a.status,s.url=a.url,s.statusText=a.statusText,s.contentType=(l=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase())!=null?l:null,!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return e==="blob"?a.blob():e==="arraybuffer"?a.arrayBuffer():e==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(t)?(s.contentType="text/html",a.arrayBuffer().then(c=>new TextDecoder("Shift_JIS").decode(c))):(/^data:,(<|%3c)/i.test(t)&&(s.contentType="text/html"),a.text())}).then(a=>{e==="blob"&&a instanceof Blob?s.responseBlob=a:e==="arraybuffer"&&a instanceof ArrayBuffer?s.responseBlob=mp([a]):e==="json"?s.responseText=JSON.stringify(a):typeof a=="string"&&(s.responseText=a),o.schedule(s)}).catch(a=>{s.status>=400?Y.warn(`Error fetching ${t} (${s.status}${s.statusText?" "+s.statusText:""})`):Y.warn(a,`Error fetching ${t}`),o.schedule(s)}),n.result()}function mp(t,e){let i=e||"application/octet-stream";return new Blob(t,{type:i})}function qv(t){let e=V("readBlob"),i=new FileReader,n=e.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(t),e.result()}function Yv(t){return URL.createObjectURL(t)}var lh=class{constructor(t,e){u(this,"parser",t),u(this,"type",e),u(this,"resources",{}),u(this,"fetchers",{})}load(t,e,i){t=ft(t);let n=this.resources[t];return typeof n<"u"?F(n):this.fetch(t,e,i).get()}fetchInner(t,e,i){let n=V("fetch"),r=Ys(t);r&&(t=bn(t));let o=Ie("user-agent.xml",Ei),s=!r&&t===o;return s&&(t=`data:application/xml,${encodeURIComponent(up)}`),ea(t,this.type).then(a=>{if(a.status>=400&&e)throw new Error((i||`Failed to fetch required resource: ${t}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(t=Ua(t),a.url=Ua(a.url)):s&&(a.url=t=o),this.parser(a,this).then(h=>{delete this.fetchers[t],this.resources[t]=h,n.finish(h)})}),n.result()}fetch(t,e,i){if(t=ft(t),this.resources[t])return null;let n=this.fetchers[t];return n||(n=new Qs(()=>this.fetchInner(t,e,i),`Fetch ${t}`),this.fetchers[t]=n,n.start()),n}get(t){return this.resources[ft(t)]}delete(t){delete this.resources[ft(t)]}};function Zv(t,e){let i=t.responseText;return F(i?Yl(i):null)}function Kv(){return new lh(Zv,"text")}function Pt(t,e,i){let n=new Qs(()=>{let r=V("loadElement"),o=r.suspend(t),s=!1,a=null,h=l=>{s||(s=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(l?l.type:"timeout"))};if(t.addEventListener("load",h,!1),t.addEventListener("error",h,!1),t.addEventListener("abort",h,!1),t.namespaceURI=="http://www.w3.org/2000/svg")e&&t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),a=setTimeout(h,300);else if(t.localName==="script")a=setTimeout(h,3e3);else if(e)if(t.localName==="img"){let l=t;l.loading==="lazy"&&(l.loading="eager"),l.src=e,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else t.src=e,i&&(t.alt=i);else(t.localName==="img"||t.localName==="embed"||t.localName==="object"||t.localName==="iframe")&&(t.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4));return r.result()},`loadElement ${e||t.localName}`);return n.start(),n}var Au=0,Jv=16777216,yp=33554432,vp=50331648,wp=67108864,Qv=83886080,ew=100663296,ta=class{constructor(t){u(this,"scope",t),u(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(t,e){}startStylesheet(t){this.flavor=t}tagSelector(t,e){}classSelector(t){}pseudoclassSelector(t,e){}pseudoelementSelector(t,e){}idSelector(t){}attributeSelector(t,e,i,n,r){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(t){}startFootnoteRule(t){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(t){}startWhenRule(t){}startMediaRule(t){this.startWhenRule(t)}startLayerRule(t){}layerStatementRule(t){}startFlowRule(t){}startPageTemplateRule(){}startPageMasterRule(t,e,i){}startPartitionRule(t,e,i){}startPartitionGroupRule(t,e,i){}startRuleBody(){}property(t,e,i){}endRule(){}startFuncWithSelector(t,e){}endFuncWithSelector(){}pushSelectorText(t){}getImportantSpecificity(){switch(this.flavor){case"UA":return Au;case"User":return ew;default:return Qv}}getBaseSpecificity(){switch(this.flavor){case"UA":return Au;case"User":return Jv;default:return yp}}},tw=class{constructor(t){u(this,"outer",t)}},iw=class extends ta{constructor(t,e){super(t),u(this,"tokenizer",null),u(this,"initialSlave"),u(this,"slave"),this.initialSlave=this.slave=e(this)}delegateTo(t){let e=t(new tw(this.slave));return this.slave=e,e}takeBack(t){this.slave=t.outer}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(t,e){this.slave.error(t,e)}errorMsg(t,e){var i;Y.warn(t,(i=e?.toString())!=null?i:"")}startStylesheet(t){super.startStylesheet(t),this.slave=this.initialSlave,this.slave.startStylesheet(t)}tagSelector(t,e){this.slave.tagSelector(t,e)}classSelector(t){this.slave.classSelector(t)}pseudoclassSelector(t,e){this.slave.pseudoclassSelector(t,e)}pseudoelementSelector(t,e){this.slave.pseudoelementSelector(t,e)}idSelector(t){this.slave.idSelector(t)}attributeSelector(t,e,i,n,r){this.slave.attributeSelector(t,e,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(t){this.slave.startCounterStyleRule(t)}startFootnoteRule(t){this.slave.startFootnoteRule(t)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(t){this.slave.startPageMarginBoxRule(t)}startWhenRule(t){this.slave.startWhenRule(t)}startLayerRule(t){this.slave.startLayerRule(t)}layerStatementRule(t){this.slave.layerStatementRule(t)}startFlowRule(t){this.slave.startFlowRule(t)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(t,e,i){this.slave.startPageMasterRule(t,e,i)}startPartitionRule(t,e,i){this.slave.startPartitionRule(t,e,i)}startPartitionGroupRule(t,e,i){this.slave.startPartitionGroupRule(t,e,i)}startRuleBody(){this.slave.startRuleBody()}property(t,e,i){this.slave.property(t,e,i)}endRule(){this.slave.endRule()}startFuncWithSelector(t,e){this.slave.startFuncWithSelector(t,e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(t){this.slave.pushSelectorText(t)}},Fu=class extends ta{constructor(t,e,i){super(t),u(this,"owner",e),u(this,"delegation",i),u(this,"depth",0),this.flavor=e.flavor}getCurrentToken(){return this.owner.getCurrentToken()}error(t,e){this.owner.errorMsg(t,e)}startRuleBody(){this.depth++}endDelegation(){this.delegation&&this.owner.takeBack(this.delegation)}endRule(){--this.depth==0&&this.endDelegation()}},Jn=class extends Fu{constructor(t,e,i){super(t,e,i)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.delegateTo(e=>new Fu(this.scope,this.owner,e))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(t){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(t){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startLayerRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_LAYER")}layerStatementRule(t){this.report("E_CSS_UNEXPECTED_LAYER")}startFlowRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(t,e,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(t,e,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(t,e,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(t,e){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(t,e,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ue=[],vs=[],Ce=[],De=[],Ut=[],at=[],He=[],Je=[],Se=[],Ke=[],dt=[],je=[],$e=[],En=55,Nn=56,Eo=57;Ue[1]=28,Ue[36]=29,Ue[7]=29,Ue[9]=29,Ue[14]=29,Ue[18]=29,Ue[50]=29,Ue[20]=30,Ue[13]=27,Ue[0]=200,vs[1]=46,vs[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[50]=42,Ce[37]=11,Ce[23]=12,Ce[35]=56,Ce[1]=1,Ce[36]=3,Ce[7]=5,Ce[9]=7,Ce[14]=9,Ce[12]=13,Ce[18]=55,Ce[50]=58,Ce[16]=41,De[37]=11,De[23]=12,De[35]=56,De[1]=1,De[36]=3,De[7]=5,De[9]=7,De[14]=9,De[18]=55,Ut[1]=2,Ut[36]=4,Ut[7]=6,Ut[9]=8,Ut[18]=14,Ut[50]=42,Ut[14]=10,Ut[12]=13,He[1]=15,He[7]=16,He[4]=17,He[5]=18,He[3]=19,He[2]=20,He[8]=21,He[27]=57,He[16]=22,He[19]=23,He[6]=24,He[11]=25,He[17]=26,He[13]=48,He[31]=47,He[23]=54,He[0]=44,Je[1]=31,Je[4]=32,Je[5]=32,Je[3]=33,Je[2]=34,Je[10]=40,Je[6]=38,Je[31]=36,Je[24]=36,Je[32]=35,Se[1]=45,Se[16]=37,Se[37]=37,Se[38]=37,Se[47]=37,Se[48]=37,Se[39]=37,Se[49]=37,Se[41]=37,Se[26]=37,Se[25]=37,Se[23]=37,Se[24]=37,Se[19]=37,Se[21]=37,Se[36]=37,Se[18]=37,Se[22]=37,Se[11]=39,Se[12]=43,Se[17]=49,Ke[0]=200,Ke[12]=50,Ke[13]=51,Ke[14]=50,Ke[15]=51,Ke[10]=50,Ke[11]=51,Ke[17]=53,dt[0]=200,dt[12]=50,dt[13]=52,dt[14]=50,dt[15]=51,dt[10]=50,dt[11]=51,dt[17]=53,je[0]=200,je[12]=50,je[13]=51,je[14]=50,je[15]=51,je[10]=50,je[11]=51,$e[11]=0,$e[16]=0,$e[22]=1,$e[18]=1,$e[26]=2,$e[25]=2,$e[38]=3,$e[37]=3,$e[48]=3,$e[47]=3,$e[39]=3,$e[49]=3,$e[41]=3,$e[23]=4,$e[24]=4,$e[36]=5,$e[19]=5,$e[21]=5,$e[0]=6,$e[En]=2,$e[Nn]=2;var uo=class{constructor(t,e,i,n){u(this,"actions",t),u(this,"tokenizer",e),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,"importHasLayer",!1),u(this,"importLayerNames",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(t,e){let i=[],n=this.valStack;for(;e<n.length&&(i.push(n[e++]),e!==n.length);){if(n[e++]!==t)throw new Error("Unexpected state");e===n.length&&i.push(Ae)}return i}valStackReduce(t,e){let i=this.valStack,n=i.length,r=0,o;do if(o=i[--n],t===")"&&o instanceof Sn){if(o.text===")")r++;else if(o.text==="("){if(r===0)return null;r--}}while(typeof o<"u"&&typeof o!="string");let s=i.length-(n+1);if(s>1&&i.splice(n+1,s,new ee(i.slice(n+1,i.length))),t==",")return null;n++;do o=i[--n];while(typeof o<"u"&&(typeof o!="string"||o==","));if(s=i.length-(n+1),o=="("){if(t!=")"&&e.type!==0)return this.handler.error("E_CSS_MISMATCHED_C_PAR",e),this.actions=dt,null;let h=new Vt(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,s+2,h),h.name==="var"){let l=h.values[0]instanceof he&&h.values[0].name;ze(l||void 0)||(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,e),this.actions=dt)}return h}if(t!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=dt,null;if(s>1)return new Be(this.extractVals(",",n+1));let a=i[0];return a instanceof ot?a:a?new Sn(a.toString()):Ae}exprError(t,e){this.actions=this.propName?dt:Ke,Y.warn(t,e.toString())}exprStackReduce(t,e){let i=this.valStack,n=this.handler,r=i.pop(),o;for(;;){let s=i.pop();if(t==11){let a=[r];for(;s==16;)a.unshift(i.pop()),s=i.pop();if(typeof s=="string"){if(s=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new uy(n.getScope(),h,l);a.unshift(c)}return i.push(new j(a[0])),!0}else if(s=="("){let h=i.pop(),l=i.pop();r=new Er(n.getScope(),Xa(l,h),a),t=0;continue}}if(s==10){r.isMediaName()&&(r=new hu(n.getScope(),r,null)),t=0;continue}}else if(typeof s=="string"){i.push(s);break}if(s<0)if(s==-31)r=new Ri(n.getScope(),r);else if(s==-24)r=new In(n.getScope(),r);else if(s==-Eo)r=new ly(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if($e[t]>$e[s]){i.push(s);break}switch(o=i.pop(),s){case 26:r=new ih(n.getScope(),o,r);break;case En:r=new hy(n.getScope(),o,r);break;case Nn:r=new cy(n.getScope(),o,r);break;case 25:r=new nh(n.getScope(),o,r);break;case 38:r=new dy(n.getScope(),o,r);break;case 37:r=new fy(n.getScope(),o,r);break;case 48:r=new py(n.getScope(),o,r);break;case 47:r=new Za(n.getScope(),o,r);break;case 39:case 49:r=new rh(n.getScope(),o,r);break;case 41:r=new gy(n.getScope(),o,r);break;case 23:r=new wd(n.getScope(),o,r);break;case 24:r=new bd(n.getScope(),o,r);break;case 36:r=new oh(n.getScope(),o,r);break;case 19:r=new xd(n.getScope(),o,r);break;case 21:r=new Sd(n.getScope(),o,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new vy(n.getScope(),i.pop(),o,r);break;case 10:if(o.isMediaName())r=new hu(n.getScope(),o,r);else return this.exprError("E_CSS_MEDIA_TEST",e),!1;break}else return this.exprError("E_CSS_EXPR_COND",e),!1;break;case 22:if(t!=18)return this.exprError("E_CSS_EXPR_COND",e),!1;case 10:return i.push(o),i.push(s),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",e),!1}}}return i.push(r),!1}readLayerName(){let t=this.tokenizer,e=t.token();if(e.type!==1)return null;let i=[e.text];for(t.consume();;){if(e=t.token(),e.type!==9||e.precededBySpace)return i;i.push(e.text),t.consume()}}readSupportsTest(t){let e=t.type===6,i=this.tokenizer,n,r="";if(e)r=t.text,n=t.position+r.length+1;else if(t.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=t.position+1}}else return null;let o=0,s,a=0;for(;o>=0;)switch(i.consume(),s=i.token(),s.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",s),null}i.consume();let h=s.position,l=i.input.substring(n,h),c=e&&r==="selector"&&a>0?"":ze(r)?l:l.trim();return new wy(this.handler.getScope(),r,c,e)}readPseudoParams(){let t=[];for(;;){let e=this.tokenizer.token();switch(e.type){case 1:t.push(e.text);break;case 23:t.push("+");break;case 4:case 5:t.push(e.num);break;default:return t}this.tokenizer.consume()}}skipPseudoFunctionContents(){let t=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(t===0)return!0;t--;break;case 10:case 6:t++;break}this.tokenizer.consume()}}readNthPseudoParams(){let t=!1,e=this.tokenizer.token();if(e.type===23)t=!0,this.tokenizer.consume(),e=this.tokenizer.token();else if(e.type===1&&(e.text==="even"||e.text==="odd"))return this.tokenizer.consume(),[2,e.text==="odd"?1:0];switch(e.type){case 3:if(t&&e.num<0)return null;case 1:if(t&&e.text.charAt(0)==="-")return null;if(e.text==="n"||e.text==="-n"){if(t&&e.precededBySpace)return null;let i=e.text==="-n"?-1:1;e.type===3&&(i=e.num);let n=0;this.tokenizer.consume(),e=this.tokenizer.token();let r=e.type===24,o=e.type===23||r;if(o&&(this.tokenizer.consume(),e=this.tokenizer.token()),e.type===5){if(n=e.num,1/n===-1/0){if(n=0,o)return null}else if(n<0){if(o)return null}else if(n>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[i,r&&n>0?-n:n]}else if(e.text==="n-"||e.text==="-n-"){if(t&&e.precededBySpace)return null;let i=e.text==="-n-"?-1:1;if(e.type===3&&(i=e.num),this.tokenizer.consume(),e=this.tokenizer.token(),e.type===5)return e.num<0||1/e.num===-1/0?null:(this.tokenizer.consume(),[i,e.num])}else{let i=e.text.match(/^n(-[0-9]+)$/);if(i)return t&&e.precededBySpace?null:(this.tokenizer.consume(),[e.type===3?e.num:1,parseInt(i[1],10)]);if(i=e.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return t&&(e.precededBySpace||e.num<0)?null:(this.tokenizer.consume(),[0,e.num])}return null}makeCondition(t,e){let i=this.handler.getScope();if(e=e||i._true,t){let n=t.split(/\s+/);for(let r of n)switch(r){case"vertical":e=Xt(i,e,new Ri(i,new Qe(i,"pref-horizontal")));break;case"horizontal":e=Xt(i,e,new Qe(i,"pref-horizontal"));break;case"day":e=Xt(i,e,new Ri(i,new Qe(i,"pref-night-mode")));break;case"night":e=Xt(i,e,new Qe(i,"pref-night-mode"));break;default:e=i._false}}return e===i._true?null:new j(e)}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(t,e,i,n,r,o){let s=this.handler,a=this.tokenizer,h=this.valStack,l,c,d,p,f,g=null,m,v=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));t>0;--t){if(l=a.token(),r&&v===null&&(v=l.position-1,a.input[v]==="("&&v++),this.actions===He&&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 Sn(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(s.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=dt):(this.actions=at,s.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=He,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=dt,s.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=He,h.splice(0,h.length);continue;case 29:this.actions=at,s.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=je,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:s.tagSelector(d,l.text),r?this.actions=De:this.actions=Ce,a.consume();break;case 36:s.tagSelector(d,null),r?this.actions=De:this.actions=Ce,a.consume();break;default:this.actions=Ke,s.error("E_CSS_NAMESPACE",l)}else this.actions=Ke,s.error("E_CSS_UNDECLARED_PREFIX",l);else s.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=De:this.actions=Ce,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=je,s.error("E_CSS_SPACE_EXPECTED",l);continue}s.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:s.tagSelector(null,l.text),r?this.actions=De:this.actions=Ce,a.consume();break;case 36:s.tagSelector(null,null),r?this.actions=De:this.actions=Ce,a.consume();break;default:this.actions=Ke,s.error("E_CSS_NAMESPACE",l)}else s.tagSelector(this.defaultNamespaceURI,null),r?this.actions=De:this.actions=Ce,a.consume();continue;case 5:l.precededBySpace&&s.descendantSelector();case 6:if(!l.text){s.error("E_CSS_SYNTAX",l),a.consume();continue}s.idSelector(l.text),r?this.actions=De:this.actions=Ce,a.consume();continue;case 7:l.precededBySpace&&s.descendantSelector();case 8:s.classSelector(l.text),r?this.actions=De:this.actions=Ce,a.consume();continue;case 55:l.precededBySpace&&s.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:s.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=De:this.actions=Ce;continue;case 6:switch(p=l.text.toLowerCase(),a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,s.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=Ce:this.actions=je;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(c=a.nthToken(0),c.type===1&&c.text==="of"){a.consume(),this.actions=at,s.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=De:this.actions=Ce: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)m.push(c.text),a.consume();else break e;break}else break;else break e;case"dir":if(l=a.token(),l.type===1&&a.nthToken(1).type===11){m=[l.text],a.consume();break}default:if(m=[],!this.skipPseudoFunctionContents())break e}if(l=a.token(),l.type==11){s.pseudoclassSelector(p,m),a.consume(),r?this.actions=De:this.actions=Ce;continue}break}s.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Ke;continue;case 58:l.precededBySpace&&s.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:s.pseudoelementSelector(l.text,null),r?this.actions=De:this.actions=Ce,a.consume();continue;case 6:if(p=l.text.toLowerCase(),a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){s.pseudoelementSelector(p,m),r?this.actions=De:this.actions=Ce,a.consume();continue}break}s.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Ke;continue;case 9:l.precededBySpace&&s.descendantSelector();case 10:{if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=je,s.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=je,s.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=je,s.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:s.attributeSelector(d,p,0,null,null),r?this.actions=De:this.actions=Ce,a.consume();continue;default:this.actions=je,s.error("E_CSS_ATTR_OP_EXPECTED",l);continue}let b=p,x=null;switch(l.type){case 1:case 2:{let C=l.text;if(a.consume(),l=a.token(),l.type==1){let y=l.text.toLowerCase();(y=="i"||y=="s")&&(x=y,a.consume(),l=a.token())}s.attributeSelector(d,b,f,C,x);break}default:this.actions=je,s.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=je,s.error("E_CSS_ATTR",l);continue}r?this.actions=De:this.actions=Ce,a.consume();continue}case 11:s.childSelector(),this.actions=Ut,a.consume();continue;case 12:s.adjacentSiblingSelector(),this.actions=Ut,a.consume();continue;case 56:s.followingSiblingSelector(),this.actions=Ut,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),s.startRuleBody(),this.actions=Ue,a.consume();continue;case 41:s.nextSelector(),this.actions=at,a.consume();continue;case 15:h.push(_(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Fd(l.text)),a.consume();continue;case 17:h.push(new It(l.num)),a.consume();continue;case 18:h.push(new ht(l.num)),a.consume();continue;case 19:h.push(new B(l.num,l.text)),a.consume();continue;case 20:h.push(new K(l.text)),a.consume();continue;case 21:h.push(new et(Ie(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Rd(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Kn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Je,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),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 Sn("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&s.property(this.propName,g,this.propImportant),this.actions=i?vs:Ue;continue;case 44:for(a.consume();h.length>0;){let b=h.length;if(g=this.valStackReduce(";",l),!g||h.length===b)break}return e?(this.result=g,!0):(this.propName&&g&&s.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 Qe(s.getScope(),Xa(l.text,c.text))),this.actions=Se),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new lu(s.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new lu(s.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==En&&h[h.length-1]!==Nn&&(c.type===10||c.type===6)){h.push(-Eo),a.consume();continue}else h.push(new Qe(s.getScope(),l.text));this.actions=Se}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=Se;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new it(s.getScope(),l.num)),a.consume(),this.actions=Se;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new oo(s.getScope(),l.num,p)),a.consume(),this.actions=Se;continue;case 34:h.push(new it(s.getScope(),l.text)),a.consume(),this.actions=Se;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Ed(s.getScope(),l.num)),a.consume(),this.actions=Se);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Je,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==Nn&&h[h.length-2]!==-Eo?(this.actions=Je,this.exprStackReduce(En,l),h.push(En),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==En&&h[h.length-2]!==-Eo?(this.actions=Je,this.exprStackReduce(Nn,l),h.push(Nn),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=He),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?s.startWhenRule(h.pop()):s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=Ue)),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=Ue,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Ue,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=Se;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Ue,a.consume(),s.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==1&&l.text.toLowerCase()=="layer")this.importHasLayer=!0,this.importLayerNames=null,a.consume(),l=a.token();else if(l.type==6&&l.text.toLowerCase()=="layer"){a.consume();let b=this.readLayerName();if(l=a.token(),!b||l.type!=11){s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Ke;continue}this.importHasLayer=!0,this.importLayerNames=b,a.consume(),l=a.token()}if(l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Je,h.push("{");continue}s.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Ke;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}s.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Ke;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&s.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}s.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Ke;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":s.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":s.startPageTemplateRule();break;case"-epubx-define":s.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":s.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),s.startRuleBody();continue}break;case"-epubx-region":a.consume(),s.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),s.startPageRule(),this.pageRule=!0,this.actions=Ut;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),s.startFootnoteRule(null),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let b=l.text;a.consume(),a.consume(),s.startFootnoteRule(b),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startPageMarginBoxRule(p),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Je,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Je,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Je,h.push("{");continue;case"layer":{if(a.consume(),l=a.token(),l.type==12){a.consume(),s.startLayerRule(null),this.ruleStack.push(p),s.startRuleBody();continue}let b=[];for(;;){let x=this.readLayerName();if(!x){b.length=0;break}if(b.push(x),a.token().type!=16)break;a.consume()}if(b.length>0){if(l=a.token(),l.type==17){a.consume(),s.layerStatementRule(b);continue}if(l.type==12&&b.length==1){a.consume(),s.startLayerRule(b[0]),this.ruleStack.push(p),s.startRuleBody();continue}}break}case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){s.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),l=a.token();let b=null,x=null,C=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(x=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)C.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":s.startPageMasterRule(b,x,C);break;case"-epubx-partition":s.startPartitionRule(b,x,C);break;case"-epubx-partition-group":s.startPartitionGroupRule(b,x,C);break}this.ruleStack.push(p),s.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":s.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=je;continue;default:s.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=Ke;continue}s.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=Ke;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ue;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),s.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=Ue),a.consume();continue;case 53:if(r&&this.errorBrackets.length==0&&l.type==16){s.nextSelector(),this.actions=at,v=l.position+1,a.consume();continue}this.errorBrackets.length==0&&(this.actions=Ue),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&&(s.nextSelector(),v=l.position+1,this.actions=at),a.consume();continue;case 11:if(this.errorBrackets.length==0)return s.endFuncWithSelector(),a.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(l.type+1),a.consume();continue;case 6:this.errorBrackets.push(11),a.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),a.consume();continue;default:a.consume();continue}switch(l.type){case 16:case 11:if(this.actions===at)s.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(v,l.position);s.pushSelectorText(b),v=l.position+1}if(l.type===16){s.nextSelector(),this.actions=at,a.consume();continue}else return s.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(o){this.actions=Ce;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}s.error("E_CSS_SYNTAX",l),a.consume(),this.actions=je;continue}if(this.actions!==Ke&&this.actions!==je&&this.actions!==dt){if(l.type==54)s.error("E_CSS_SYNTAX",l);else if(this.actions===He){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Sn(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Je&&h.length>0){s.startMediaRule(h.pop()),this.ruleStack.push("media"),s.startRuleBody(),this.actions=Ue,a.consume();continue}else{if(l.type===17&&this.actions==Je)return this.actions=Ue,a.consume(),!1;s.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=dt:this.actions=je;continue}a.consume();continue}}return!1}},bp=class extends ta{constructor(t){super(t)}error(t,e){Y.warn(t,e.toString())}};function nw(t,e,i,n,r){let o=i??"",s=tv(t.input);return s!==t.input?Ru(new xt(s,e),e,o,n,r):Ru(t,e,o,n,r)}function Ru(t,e,i,n,r){let o=V("parseStylesheet"),s=new uo(Ue,t,e,i),a=null;return r&&(a=Cp(new xt(r,e),e,i)),a=s.makeCondition(n,a&&a.toExpr()),a&&(e.startMediaRule(a),e.startRuleBody()),o.loop(()=>{for(;!s.runParser(100,!1,!1,!1,!1);){if(s.importReady){let l=Ie(s.importURL,i);s.importHasLayer&&(e.startLayerRule(s.importLayerNames),e.startRuleBody()),s.importCondition&&(e.startMediaRule(s.importCondition),e.startRuleBody());let c=V("parseStylesheet.import");return Sp(l,e,null,null).then(()=>{s.importCondition&&e.endRule(),s.importHasLayer&&e.endRule(),s.importReady=!1,s.importURL=null,s.importCondition=null,s.importHasLayer=!1,s.importLayerNames=null,c.finish(!0)}),c.result()}let h=o.timeSlice();if(h.isPending)return h}return F(!1)}).then(()=>{a&&e.endRule(),o.finish(!0)}),o.result()}function xp(t,e,i,n,r){return hn("parseStylesheetFromText",o=>{let s=new xt(t,e);nw(s,e,i,n,r).thenFinish(o)},(o,s)=>{Y.warn(s,`Failed to parse stylesheet text: ${t}`),o.finish(!1)})}function Sp(t,e,i,n){return hn("parseStylesheetFromURL",r=>{ea(t).then(o=>{o.responseText?xp(o.responseText,e,t,i,n).then(s=>{s||Y.warn(`Failed to parse stylesheet from ${t}`),r.finish(!0)}):r.finish(!0)})},(r,o)=>{Y.warn(o,"Exception while fetching and parsing:",t),r.finish(!0)})}function Mi(t,e,i){let n=new uo(He,e,new bp(t),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function rw(t,e,i){new uo(vs,t,e,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Cp(t,e,i){let n=new uo(Je,t,e,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var ow={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function sw(t){return!!(t&&ow[t])}function aw(t,e,i){if(e instanceof be&&e.str==="viv-leader")return new j(e);if(i==="content"&&e instanceof be)return new j(e);let n=e.evaluate(t);switch(typeof n){case"number":return sw(i)?n==Math.round(n)?new ht(n):new It(n):new B(n,"px");case"string":return n?i==="content"?new K(n):Mi(e.scope,new xt(n,null),""):Ae;case"boolean":return n?w._true:w._false;case"undefined":return Ae}throw new Error("E_UNEXPECTED")}var lw="data-vivliostyle-flow-root";function hw(t){return t.getAttribute(lw)==="true"}function Lu(t){let e=t?.toString()||"block",i;switch(e){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=e}return _(i)}function Ur(t){return t===w.absolute||t===w.fixed}function Nr(t){return t instanceof Vt&&t.name==="running"}function kp(t,e,i,n){return t===w.none||(Ur(e)?(i=w.none,t=Lu(t)):(i&&i!==w.none&&!Z(i)||n)&&(t=Lu(t))),{display:t,position:e,float:i}}function uw(t,e,i,n){return kp(t,e,i,n).display===w.block}function ia(t){return t instanceof he||t instanceof ee||typeof t=="string"}function Wt(t){if(!ia(t))return!1;let e=t.toString();switch(e){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return e.includes("inline")}}function mr(t){return ia(t)?t.toString().includes("list-item"):!1}function cw(t){if(!ia(t))return!1;switch(t.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Pp(t){if(!ia(t))return!1;switch(t.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function dw(t,e,i,n,r,o,s){return r=r||o||w.horizontal_tb,!!s||!!i&&i!==w.none&&!Z(i)||Ur(e)||t===w.inline_block||t===w.table_cell||t===w.table_caption||t==w.flex||t==w.grid||t==w.flow_root||(t===w.block||t===w.list_item)&&!!n&&n!==w.visible&&n!==w.clip&&!Z(n)||!!o&&r!==o}function pw(t){return t===w.relative||t===w.absolute||t===w.fixed}function Fn(t){var e,i;return((e=t?.style)==null?void 0:e["box-decoration-break"])==="clone"||((i=t?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function Ep(t){let e=t.getAttribute("data-viv-box-break");return e?e.split(" "):[]}function Np(t,e){t.setAttribute("data-viv-box-break",e.join(" "))}function Ct(t,e){let i=Ep(t);i.includes(e)||(i.push(e),Np(t,i))}function fw(t){let e=t.getAttribute("data-viv-margin-discard");return e?e.split(" "):[]}function gw(t,e){t.setAttribute("data-viv-margin-discard",e.join(" "))}function Na(t,e){let i=fw(t);i.includes(e)||(i.push(e),gw(t,i))}function mw(t){let e=t.name,i=t.value;switch(e){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:e.replace(/^page-/,""),value:i===w.always?w.page:i,important:t.important};default:return t}}var ol={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ye(t){return t!=null&&!!ol[t]}var yw={left:!0,right:!0,recto:!0,verso:!0};function un(t){return t!=null&&!!yw[t]}function Ou(t){return Ye(t)&&t!=="column"&&t!=="region"}var vw={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function ws(t){return t!=null&&!!vw[t]}function nt(t,e){if(t)if(e){if(un(e))return e;if(un(t))return t;{let i=Ye(t),n=Ye(e);if(i&&n)switch(e){case"column":return t;case"region":return t==="column"?e:t;default:return e}else return n?e:i?t:ws(e)?e:ws(t)?t:e}}else return t;else return e}function Bu(t){return t!=null&&Ye(t)?t:"auto"}Ft("SIMPLE_PROPERTY",mw);var Tr=_m(zm());function ww(t,e){return(0,Tr.default)(t,e,0)}function Mu(t){return t.reduce((e,i)=>i[0]===Tr.default.DELETE?e:e+i[1],"")}function bw(t,e){return Tp(t,e,1)}function xw(t,e){return Tp(t,e,-1)}function Tp(t,e,i){let n=0,r=0;return t.some(o=>{for(let s=0;s<o[1].length;s++){switch(o[0]*i){case Tr.default.INSERT:n++;break;case Tr.default.DELETE:n--,r++;break;case Tr.default.EQUAL:r++;break}if(r>e)return!0}return!1}),Math.max(Math.min(e,r-1)+n,0)}var sl;(t=>{function e(i){return i.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=e})(sl||(sl={}));var Dn;(t=>{let e;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(e=t.FloatReference||(t.FloatReference={}))})(Dn||(Dn={}));var bs;(t=>{function e(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=e})(bs||(bs={}));var rn;(t=>{function e(n){return n.formattingContextType==="RepetitiveElementsOwner"||_i.isInstanceOfTableFormattingContext(n)}t.isInstanceOfRepetitiveElementsOwnerFormattingContext=e;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||_i.isInstanceOfTableRowLayoutConstraint(n):!1}t.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(rn||(rn={}));var _i;(t=>{function e(n){return n.formattingContextType==="Table"}t.isInstanceOfTableFormattingContext=e;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}t.isInstanceOfTableRowLayoutConstraint=i})(_i||(_i={}));var wi;(t=>{let e;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(e=t.Whitespace||(t.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=t.ShadowType||(t.ShadowType={}))})(wi||(wi={}));var Sw={transform:!0,"transform-origin":!0},Cw={top:!0,bottom:!0,left:!0,right:!0},hh=class{constructor(t,e,i){u(this,"target",t),u(this,"name",e),u(this,"value",i)}},kw={show:function(t){t.style.visibility="visible"},hide:function(t){t.style.visibility="hidden"},play:function(t){t.currentTime=0,t.play()},pause:function(t){t.pause()},resume:function(t){t.play()},mute:function(t){t.muted=!0},unmute:function(t){t.muted=!1}};function Pw(t,e){let i=kw[e];return i?()=>{for(let n=0;n<t.length;n++)try{i(t[n])}catch{}}:null}var al=class yr extends Jl{constructor(e,i){super(),u(this,"container",e),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,"pageFloatLayoutContext",null),u(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,o=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let s={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:o,preventDefault(){n.preventDefault()}};this.dispatchEvent(s)}}}setAutoPageWidth(e){this.isAutoPageWidth=e,e?this.container.setAttribute(yr.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(yr.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(yr.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(yr.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(e,i){let n=this.elementsById[i];n?n.push(e):this.elementsById[i]=[e]}finish(e,i){Object.keys(this.elementsById).forEach(o=>{let s=this.elementsById[o];for(let a=0;a<s.length;)this.container.contains(s[a])?a++:s.splice(a,1);s.length===0&&delete this.elementsById[o]});let n=this.delayedItems;for(let o=0;o<n.length;o++){let s=n[o];s.target===this.container&&s.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||R(s.target,s.name,s.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let o=0;o<e.length;o++){let s=e[o],a=this.elementsById[s.ref],h=this.elementsById[s.observer];if(a&&h){let l=Pw(a,s.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(s.event,l,!1)}}}};u(al,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(al,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Ip=al,bt=wi.Whitespace;function Ap(t){switch(t){case"normal":case"nowrap":return bt.IGNORE;case"pre-line":return bt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return bt.PRESERVE;default:return null}}function Ee(t,e){return t?t.nodeType==1?!1:Fp(t.textContent,e):!0}function Fp(t,e){switch(e){case bt.PRESERVE:return t.length==0;case bt.NEWLINE:return!!t.match(/^[ \t]*$/);case bt.IGNORE:default:return!!t.match(/^[ \t\r\n\f]*$/)}}var Ew=class{constructor(t,e,i){u(this,"flowName",t),u(this,"parentFlowName",e),u(this,"formattingContext",i),u(this,"forcedBreakOffsets",[])}},Nw=class{constructor(t,e,i,n,r,o,s,a,h){u(this,"flowName",t),u(this,"element",e),u(this,"startOffset",i),u(this,"priority",n),u(this,"linger",r),u(this,"exclusive",o),u(this,"repeated",s),u(this,"last",a),u(this,"breakBefore",h),u(this,"startPage",-1)}isBetter(t){return this.exclusive?!t.exclusive||this.priority>t.priority?!0:this.last:!1}};function Tw(t,e){return t.top-e.top}function Iw(t,e){return e.right-t.right}function Rp(t,e){var i,n;return t===e?!0:!t||!e?!1:(t.node===e.node||!!t.shadowContext&&!!e.shadowContext&&t.shadowType===wi.ShadowType.ROOTLESS&&e.shadowType===wi.ShadowType.ROOTLESS&&((i=t.node)==null?void 0:i.outerHTML)===((n=e.node)==null?void 0:n.outerHTML))&&t.shadowType===e.shadowType&&ll(t.shadowContext,e.shadowContext)&&ll(t.nodeShadow,e.nodeShadow)&&Rp(t.shadowSibling,e.shadowSibling)}function Di(t,e){if(t===e)return!0;if(!t||!e||t.offsetInNode!==e.offsetInNode||t.after!==e.after||t.steps.length!==e.steps.length)return!1;for(let i=0;i<t.steps.length;i++)if(!Rp(t.steps[i],e.steps[i]))return!1;return!0}function Aw(t){return{steps:[{node:t,shadowType:st.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function xs(t,e){return{steps:[{node:t.sourceNode,shadowType:st.NONE,shadowContext:t.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:t.formattingContext,fragmentIndex:e??t.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:t.preprocessedTextContent}}function Ss(t,e){var i;let n=e,r=new en(t.node,n,0,(i=t.formattingContext)!=null?i:n.formattingContext);return r.blockContainer=Cs(n),Lp(r,t),r.shadowSibling=t.shadowSibling?Ss(t.shadowSibling,e.copy()):null,r}function Fw(t,e){var i;let n=new en(t.node,null,0,(i=t.formattingContext)!=null?i:e);return Lp(n,t),n.shadowSibling=t.shadowSibling,n}function Lp(t,e){t.shadowType=e.shadowType,t.shadowContext=e.shadowContext,t.nodeShadow=e.nodeShadow,t.fragmentIndex=e.fragmentIndex+1}function Rw(t){return t.steps[t.steps.length-1]}var st=wi.ShadowType,Zo=class{constructor(t,e,i,n,r,o,s){u(this,"owner",t),u(this,"root",e),u(this,"xmldoc",i),u(this,"parentShadow",n),u(this,"type",o),u(this,"styler",s),u(this,"subShadow",null),r&&(r.subShadow=this)}equals(t){return t?this.owner===t.owner&&this.xmldoc===t.xmldoc&&this.type===t.type&&ll(this.parentShadow,t.parentShadow):!1}};function ll(t,e){return t===e||!!t&&!!e&&t.equals(e)}var Lw=class{constructor(t,e){u(this,"outer",t),u(this,"count",e)}},en=class Ko{constructor(e,i,n,r){u(this,"sourceNode",e),u(this,"parent",i),u(this,"boxOffset",n),u(this,"formattingContext",r),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,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),u(this,"blockContainer",null),this.shadowType=st.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Dn.FloatReference.INLINE,this.whitespace=i?i.whitespace:bt.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.pageType=i?i.pageType:null}static childOf(e,i,n){let r=new Ko(e,i,n,i.formattingContext);return r.blockContainer=Cs(i),r}static siblingOf(e,i,n){let r=i.parent,o=new Ko(e,r,n,(r??i).formattingContext);return o.blockContainer=i.blockContainer,o}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=Dn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:bt.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.parent&&(this.formattingContext=this.parent.formattingContext),this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null,this.pageType=this.parent?this.parent.pageType:null}cloneItem(){let e=new Ko(this.sourceNode,this.parent,this.boxOffset,this.formattingContext);return e.offsetInNode=this.offsetInNode,e.after=this.after,e.nodeShadow=this.nodeShadow,e.shadowType=this.shadowType,e.shadowContext=this.shadowContext,e.shadowSibling=this.shadowSibling,e.inline=this.inline,e.breakPenalty=this.breakPenalty,e.display=this.display,e.floatReference=this.floatReference,e.floatSide=this.floatSide,e.clearSide=this.clearSide,e.floatMinWrapBlock=this.floatMinWrapBlock,e.columnSpan=this.columnSpan,e.captionSide=this.captionSide,e.inlineBorderSpacing=this.inlineBorderSpacing,e.blockBorderSpacing=this.blockBorderSpacing,e.establishesBFC=this.establishesBFC,e.containingBlockForAbsolute=this.containingBlockForAbsolute,e.flexContainer=this.flexContainer,e.whitespace=this.whitespace,e.hyphenateCharacter=this.hyphenateCharacter,e.breakWord=this.breakWord,e.breakBefore=this.breakBefore,e.breakAfter=this.breakAfter,e.viewNode=this.viewNode,e.clearSpacer=this.clearSpacer,e.firstPseudo=this.firstPseudo,e.vertical=this.vertical,e.overflow=this.overflow,e.preprocessedTextContent=this.preprocessedTextContent,e.repeatOnBreak=this.repeatOnBreak,e.pluginProps=Object.create(this.pluginProps),e.fragmentIndex=this.fragmentIndex,e.afterIfContinues=this.afterIfContinues,e.footnotePolicy=this.footnotePolicy,e.pageType=this.pageType,e.blockContainer=this.blockContainer,e}modify(){return this.shared?this.cloneItem():this}copy(){let e=this;do{if(e.shared)break;e.shared=!0,e=e.parent}while(e);return this}clone(){let e=this.cloneItem(),i=[e],n=e,r;for(;(r=n.parent)!=null;)r=r.cloneItem(),n.parent=r,n=r,i.push(r);for(let o=i.length-2;o>=0;o--)i[o].blockContainer=Cs(i[o+1]);return e}toNodePositionStep(){var e;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((e=this.viewNode)==null?void 0:e.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var e,i,n;let r=this.shadowType===wi.ShadowType.ROOTLESS&&(this.floatReference!==Dn.FloatReference.INLINE||this.floatSide==="footnote")&&(n=(i=(e=this.shadowContext)==null?void 0:e.styler)==null?void 0:i.style)!=null&&n._pseudos?this:null,o=[],s=_u(r?r.parent:this);for(;Ow(s);)(!s.firstPseudo||s.parent.firstPseudo===s.firstPseudo)&&o.push(s.toNodePositionStep()),s=_u(s.parent);let a=this.preprocessedTextContent?xw(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:[...o,Bw(s)],offsetInNode:a,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let e=this.parent;for(;e;){if(e.establishesBFC)return!0;e=e.parent}return!1}getContainingBlockForAbsolute(){let e=this.parent;for(;e;){if(e.containingBlockForAbsolute)return Lt(e);e=e.parent}return null}belongsTo(e){return this.formattingContext===e&&!!this.parent&&this.parent.formattingContext===e}};function Op(t){return t.parent!==null?t:null}function _u(t){return t.parent,t}function Ow(t){return t.parent!==null}function Bw(t){return{...t.toNodePositionStep(),shadowSibling:t.shadowSibling}}function uh(t){var e;return t.parent!==null&&((e=t.viewNode)==null?void 0:e.nodeType)===3?t:null}function Lt(t){return t.viewNode!==null&&t.viewNode.nodeType===1?t:null}function Mw(t){var e;return t.floatSide!==null&&((e=t.viewNode)==null?void 0:e.nodeType)===1?t:null}function _w(t){var e;return t.clearSide!==null&&((e=t.viewNode)==null?void 0:e.nodeType)===1?t:null}function Dw(t){var e;return t.afterIfContinues!==null&&((e=t.viewNode)==null?void 0:e.nodeType)===1?t:null}function Yi(t){var e;return(e=Lt(t))!=null?e:uh(t)}function Cs(t){let e=Lt(t);return e&&!(t.inline&&t.blockContainer)?e:t.blockContainer}var zi=class Bp{constructor(e){u(this,"primary",e),u(this,"floats",null)}clone(){let e=new Bp(this.primary);if(this.floats){e.floats=[];for(let i=0;i<this.floats.length;++i)e.floats[i]=this.floats[i]}return e}isSamePosition(e){if(!e)return!1;if(this===e)return!0;if(!Di(this.primary,e.primary))return!1;if(this.floats){if(!e.floats||this.floats.length!==e.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!Di(this.floats[i],e.floats[i]))return!1}else if(e.floats)return!1;return!0}},zw=class Mp{constructor(e,i){u(this,"chunkPosition",e),u(this,"flowChunk",i)}clone(){return new Mp(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(e){return!!e&&(this===e||this.chunkPosition.isSamePosition(e.chunkPosition))}},Vw=class _p{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let e=new _p,i=this.positions,n=e.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return e.startBreakType=this.startBreakType,e.breakAfter=this.breakAfter,e}isSamePosition(e){if(this===e)return!0;if(!e||this.positions.length!==e.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(e.positions[i]))return!1;return!0}hasContent(e){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=e}},$w=class Dp{constructor(){u(this,"page",0),u(this,"flows",{}),u(this,"flowPositions",{}),u(this,"isBlankPage",!1),u(this,"highestSeenOffset",0),u(this,"highestSeenNode",null),u(this,"lookupPositionOffset",null)}clone(){let e=new Dp;e.page=this.page,e.isBlankPage=this.isBlankPage,e.highestSeenNode=this.highestSeenNode,e.highestSeenOffset=this.highestSeenOffset,e.lookupPositionOffset=this.lookupPositionOffset,e.flows=this.flows;for(let i in this.flowPositions)e.flowPositions[i]=this.flowPositions[i].clone();return e}isSamePosition(e){if(this===e)return!0;if(!e||this.page!==e.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(e.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(e.flowPositions[r]))return!1;return!0}hasContent(e,i){let n=this.flowPositions[e];return n?n.hasContent(i):!1}startSideOfFlow(e){var i;let n=(i=this.flowPositions[e])==null?void 0:i.startBreakType;return n&&un(n)?n:"any"}firstFlowChunkOfFlow(e){let i=this.flowPositions[e];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}};function zp(t,e){e.left=t.left,e.top=t.top,e.marginLeft=t.marginLeft,e.marginRight=t.marginRight,e.marginTop=t.marginTop,e.marginBottom=t.marginBottom,e.borderLeft=t.borderLeft,e.borderRight=t.borderRight,e.borderTop=t.borderTop,e.borderBottom=t.borderBottom,e.paddingLeft=t.paddingLeft,e.paddingRight=t.paddingRight,e.paddingTop=t.paddingTop,e.paddingBottom=t.paddingBottom,e.width=t.width,e.height=t.height,e.originX=t.originX,e.originY=t.originY,e.snapWidth=t.snapWidth,e.snapHeight=t.snapHeight,e.vertical=t.vertical,e.rtl=t.rtl,e.borderBoxSizing=t.borderBoxSizing}var Vp=class{constructor(t){u(this,"element",t),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(t){return this.vertical?t.right:t.top}getAfterEdge(t){return this.vertical?t.left:t.bottom}getStartEdge(t){return this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left}getEndEdge(t){return this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right}getInlineSize(t){return this.vertical?t.bottom-t.top:t.right-t.left}getBoxSize(t){return this.vertical?t.right-t.left:t.bottom-t.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(t){this.element=t.element,zp(t,this),this.innerShape=t.innerShape,this.exclusions=t.exclusions,this.computedBlockSize=t.computedBlockSize}setVerticalPosition(t,e){this.top=t,this.height=e,R(this.element,"top",`${t}px`),R(this.element,"height",`${e}px`)}setHorizontalPosition(t,e){this.left=t,this.width=e,R(this.element,"left",`${t}px`),R(this.element,"width",`${e}px`)}setBlockPosition(t,e){if(this.vertical){let i=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+i*this.getBoxDir(),e)}else this.setVerticalPosition(t,e)}setInlinePosition(t,e){if(this.vertical)if(this.rtl){let i=e+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(t+i*this.getInlineDir(),e)}else this.setVerticalPosition(t,e);else if(this.rtl){let i=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+i*this.getInlineDir(),e)}else this.setHorizontalPosition(t,e)}clear(){let t=this.element,e;for(;e=t.lastChild;)t.removeChild(e)}getInnerShape(){let t=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(t.x1,t.y1):ah(t.x1,t.y1,t.x2,t.y2)}getInnerRect(){let t=this.originX+this.left+this.getInsetLeft(),e=this.originY+this.top+this.getInsetTop();return new Dt(t,e,t+this.width,e+this.height)}getPaddingRect(){let t=this.originX+this.left+this.marginLeft+this.borderLeft,e=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new Dt(t,e,t+i,e+n)}getOuterShape(t,e){let i=this.getOuterRect();return Xd(t,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,e)}getOuterRect(){let t=this.originX+this.left,e=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new Dt(t,e,t+i,e+n)}},Wr=class extends Zt{constructor(t,e,i,n){super(),u(this,"elem",t),u(this,"context",e),u(this,"rootContentValue",i),u(this,"exprContentListener",n)}visitStrInner(t,e){var i;if(!e){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=t;return}e=this.elem.ownerDocument.createTextNode(t)}this.elem.appendChild(e)}visitStr(t){return this.visitStrInner(t.str),null}visitURL(t){if(this.rootContentValue instanceof et)this.elem.setAttribute("src",t.url);else{let e=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");e.setAttribute("src",t.url),this.elem.appendChild(e)}return null}visitSpaceList(t){return this.visitValues(t.values),null}visitExpr(t){let e=t.toExpr();if(e instanceof be){let n=e;if(typeof n.getContentList=="function"){let r=n.getContentList();if(r)return r.visit(this),null}}let i=e.evaluate(this.context);if(typeof i=="string"){this.elem.ownerDocument;let n=this.exprContentListener(e,i,this.elem.ownerDocument);!n&&i&&e instanceof be&&e.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function At(t){return t!=null&&t!==Ae&&t!==w.normal&&t!==w.none&&!Z(t)}var ri=1e5;function ch(t){let e=t.element.style;e.columnGap=`${ri-(t.vertical?t.height:t.width)}px`,e.columnFill="auto",e.columnCount="1",e.columnWidth="0"}function na(t){let e=("element"in t?t.element:t).style;e.columnWidth="",e.columnCount="",e.columnGap="",e.columnFill=""}function ks(t){return t.element.style.columnCount==="1"}function Hw(t){t.element.setAttribute("data-vivliostyle-column","true")}function Gr(t,e){let i=e?t.bottom:Math.max(Math.abs(t.left),Math.abs(t.right));return Math.round(i/ri)}function dh(t,e){let i=Gr(t,e);if(i===0)return 0;let n=e?t.top:Math.min(Math.abs(t.left),Math.abs(t.right)),r=Math.round(n/ri),o=r*ri,s=i*ri;return e?(t.top-=o,t.bottom-=s,t.bottom<t.top&&(t.bottom+=ri),t.right-=o,t.left-=s):t.left<-ri/2?(t.right+=o,t.left+=s,t.left>t.right&&(t.left-=ri),t.top+=o,t.bottom+=s):(t.left-=o,t.right-=s,t.right<t.left&&(t.right+=ri),t.top+=o,t.bottom+=s),t.width=t.right-t.left,t.height=t.bottom-t.top,r}function Ps(t,e){for(let i=0;i<t.length;i++)dh(t[i],e)}function _t(t,e,i){let n=t.getElementClientRect(e);if(dh(n,i)>0&&t.getElementComputedStyle(e).display.startsWith("table")&&!co(e)){let r=e.closest("[data-vivliostyle-column]");if(r)return na(r),t.getElementClientRect(e)}return n}function Uw(t,e){var i,n;if(t.nodeType===1){let r=t;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(e.nodeType===1){let r=e;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function hl(t){let e=t.style;return e?!isNaN(parseFloat(e.columnCount))||!isNaN(parseFloat(e.columnWidth)):!1}function Ww(t){if(!t.hasAttribute("data-vivliostyle-column")&&hl(t))return!0;for(let e of t.querySelectorAll("*"))if(!e.hasAttribute("data-vivliostyle-column")&&hl(e))return!0;return!1}function co(t){for(let e=t.nodeType===1?t:t.parentElement;e;e=e.parentElement){let i=e.style;if(!i||e.hasAttribute("data-vivliostyle-column"))break;if(hl(e))return e;if(i.position==="absolute")break}return null}function Gw(t){var e;if(t.nodeType!==1)return;let i=t,n=i.style,r=n?.breakBefore==="column",o=i.previousElementSibling,s=o&&((e=o.style)==null?void 0:e.breakAfter)==="column";if(!r&&!s)return;let a=co(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",m=(parseFloat(d)||parseFloat(p)||16)/2,v=a.getBoundingClientRect(),b=i.getBoundingClientRect();(f?b.top>v.bottom+m:g?b.right<v.left-m:b.left>v.right+m)&&(r&&(n.breakBefore=""),s&&o&&(o.style.breakAfter=""),n.marginBlockStart=`${ri}px`)}function No(t){let e=t.element.lastElementChild,i=e&&t.clientLayout.getElementClientRect(e);return i?Gr(i,t.vertical):0}function $p(t,e){if(t.getAttribute("data-viv-saved-column-fill")!=="auto"||No(e))return;let i=e.clientLayout.getElementComputedStyle(t),n=parseFloat(i.blockSize);t.style.columnFill="auto";let r=parseFloat(i.blockSize);if(r<=0||t.parentElement&&co(t.parentElement)){t.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(t.style.blockSize=`${r}px`,No(e)){if(t.style.blockSize=`${n}px`,!No(e)){let s=1/(e.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>s;){let l=(a+h)/2;t.style.blockSize=`${l}px`,No(e)?h=l:a=l}o=a,t.style.blockSize=`${o}px`}}else if(o=parseFloat(i.blockSize),o<r){let s=1/e.clientLayout.layoutUnitPerPixel;o=r+s,t.style.blockSize=`${o}px`}if(isNaN(o)){t.style.blockSize="",t.style.columnFill="balance";return}t.removeAttribute("data-viv-saved-column-fill")}function jw(t){let e=t.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of e)$p(i,t)}function Tn(t,e,i,n){let r=t.viewNode;if(!r)return NaN;let o=r.nodeType===1?r:r.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let s=o.style;if(o.localName==="wbr"||s&&Wt(s.display)&&/^([\d\.]|super|(text-)?top)/.test(s.verticalAlign))return NaN}if(r===o){if(o.localName==="br"){let s=o.ownerDocument.createElement("span");o.before(s);let a=e.getElementClientRect(s);if(s.remove(),a){let h=[a];Ps(h,n);let l=h[0],c=n?l.left:l.bottom;if(!isNaN(c)&&c!==0)return c}return NaN}if(t.after||!t.inline){if(t.after&&!t.inline&&o.querySelector("ruby")){let a=o.parentNode,h=o.nextSibling;a.removeChild(o),a.insertBefore(o,h)}let s=_t(e,o,n);if(s.left===0&&s.top===0&&s.right===0&&s.bottom===0)return NaN;if(s.right>=s.left&&s.bottom>=s.top)return t.after?n?s.left:s.bottom:n?s.right:s.top}return NaN}else{let s=NaN,a=r.ownerDocument.createRange(),h=r.textContent.length;if(!h)return NaN;t.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=e.getRangeClientRects(a);Ps(l,n);let c=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(c.length>0)l=c;else{let d=o?e.getElementComputedStyle(o).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?s=Math.min.apply(null,l.map(d=>d.left)):s=Math.max.apply(null,l.map(d=>d.bottom)),s):NaN}}function ul(t,e,i){let n=ks(e);n&&na(e);let r=e.clientLayout.getElementClientRect(t);n&&ch(e);let o=e.getComputedMargin(t);return i?r.width+o.left+o.right:r.height+o.top+o.bottom}function Rn(t){for(;t;){if(t.parentNode===t.ownerDocument)return!1;t=t.parentNode}return!0}function Hp(t,e){var i;if(t)for(let n=t.lastChild,r=n;n!==e;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=e.style)==null?void 0:i.display)==="inline")&&t.removeChild(n)}var Un="data-adapt-spec";function ph(t){return!!t.getAttribute(Un)}function Mt(t){return t?.nodeType!==1?!1:ph(t)?!0:Up(t)}function Up(t){var e,i;if(t?.nodeType!==1)return!1;let n=t,r=(e=n.style)==null?void 0:e.position;if(r==="absolute"||r==="fixed")return!0;let o=(i=n.style)==null?void 0:i.float;return o==="left"||o==="right"||o==="inline-start"||o==="inline-end"}function Du(t){var e;return t?.nodeType!==1?!1:((e=t.style)==null?void 0:e.position)==="fixed"}function Ln(t){let e=t?.viewNode;return e?.nodeType===1&&ph(e)}function Xw(t){return t!=="inline"&&(Wt(t)||Pp(t))}function zu(t){var e;for(let i=t.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((e=i.parent)==null?void 0:e.vertical))&&Wt(i.display))return Lt(i);return null}function Wp(t){let e=t.parentElement;return e?.localName==="viv-ts-inner"?e.parentElement:null}function qw(t){let e=t;for(;e;){if(e.nodeType===Node.TEXT_NODE&&e.textContent.length>0)return e;if(e.lastChild)e=e.lastChild;else{for(;e&&!e.previousSibling;)if(e=e.parentNode,e===t||!e)return null;e=e?.previousSibling||null}}return null}function Gp(t,e){let i={};return Object.keys(t).forEach(n=>{let r=i[n]={},o=t[n];Object.keys(o).forEach(s=>{r[s]=o[s].map(a=>{let h=e?a.logical:a.physical,l=e?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function jp(t,e,i,n){let r=n[e];if(!r)throw new Error(`unknown writing-mode: ${e}`);let o=r[i||"ltr"];if(!o)throw new Error(`unknown direction: ${i}`);for(let s of o){let a=t.replace(s.regexp,s.to);if(a!==t)return a}return t}var Xp={"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"}]}},Yw=Gp(Xp,!0);function qp(t,e,i){return jp(t,e,i||null,Yw)}var Zw=Gp(Xp,!1);function Yp(t,e,i){return jp(t,e,i||null,Zw)}var Kw={"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 Jw(t,e){let i=Kw[e];if(!i)throw new Error(`unknown writing-mode: ${e}`);for(let n=0;n<i.length;n++)if(i[n].physical===t)return i[n].logical;return t}function fh(t,e,i){var n;let r=e,o={width:r.style.width,height:r.style.height};function s(p){return t.getElementComputedStyle(e).getPropertyValue(p)}let a=s("writing-mode")!=="horizontal-tb",h=a?"height":"width",l=a?"width":"height";function c(p,f){r.style[p]=f;let g=s(p);return r.style[p]=o[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=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"&&e.childNodes.length===1&&((n=e.firstElementChild)==null?void 0:n.localName)==="img"&&!e.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}var Ne=Dn.FloatReference,Qw=20;function eb(t){switch(t){case"inline":return Ne.INLINE;case"column":return Ne.COLUMN;case"region":return Ne.REGION;case"page":return Ne.PAGE;default:throw new Error(`Unknown float-reference: ${t}`)}}function Li(t){switch(t){case Ne.INLINE:return!1;case Ne.COLUMN:case Ne.REGION:case Ne.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${t}`)}}function Ta(t,e,i,n){let r=e?"vertical-rl":"horizontal-tb";if((t==="top"||t==="bottom")&&(t=Yp(t,r,i)),t==="block-start"&&(t="inline-start"),t==="block-end"&&(t="inline-end"),t==="inline-start"||t==="inline-end"){let o=qp(t,r,i),s=Jw(o,r);s==="line-left"?t="left":s==="line-right"&&(t="right")}else t==="inside"?t=n==="left"?"right":"left":t==="outside"&&(t=n==="left"?"left":"right");return t!=="left"&&t!=="right"&&(Y.warn(`Invalid float value: ${t}. Fallback to left.`),t="left"),t}var Zp=class{constructor(t,e,i,n,r,o){u(this,"nodePosition",t),u(this,"floatReference",e),u(this,"floatSide",i),u(this,"clearSide",n),u(this,"flowName",r),u(this,"floatMinWrapBlock",o),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(t){return t.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!t.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(t){return!1}},tb=class{constructor(){u(this,"floats",[]),u(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(t){return`pf${t}`}addPageFloat(t){if(this.floats.findIndex(e=>Di(e.nodePosition,t.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let e=t.order=this.nextOrder();t.id=this.createPageFloatId(e),this.floats.push(t)}}findPageFloatByNodePosition(t){let e=this.floats.findIndex(n=>Di(n.nodePosition,t));if(e>=0)return this.floats[e];let i=t?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let o=r.nodePosition.steps;if(!(o!=null&&o.length)||o.length===i.length||r.nodePosition.offsetInNode!==t.offsetInNode||r.nodePosition.after!==t.after)return!1;let s=Math.min(o.length,i.length);for(let a=0;a<s;a++)if(o[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(t){let e=this.floats.findIndex(i=>i.id===t);return e>=0?this.floats[e]:null}},Kp=class{constructor(t,e,i,n,r,o){u(this,"floatReference",t),u(this,"floatSide",e),u(this,"clearSide",i),u(this,"continuations",n),u(this,"area",r),u(this,"continues",o)}hasFloat(t){return this.continuations.some(e=>e.float===t)}findNotAllowedFloat(t){for(let e=this.continuations.length-1;e>=0;e--){let i=this.continuations[e].float;if(!i.isAllowedOnContext(t))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let t=this.continuations.map(e=>e.float);return Math.min.apply(null,t.map(e=>e.getOrder()))}shouldBeStashedBefore(t){return this.getOrder()<t.getOrder()}addContinuations(t){t.forEach(e=>{this.continuations.push(e)})}getFlowName(){let t=this.continuations[0].float.flowName;return this.continuations.every(e=>e.float.flowName===t),t}},Vu=class{constructor(t,e){u(this,"float",t),u(this,"nodePosition",e)}equals(t){return t?this===t?!0:this.float===t.float&&Di(this.nodePosition,t.nodePosition):!1}};function Jp(t,e){if(t==="inside"||t==="outside"){let i=e.pageSide==="left";t=t==="inside"?i?"right":"left":i?"left":"right"}return Yp(t,e.writingMode.toString(),e.direction.toString())}function ib(t,e){return qp(t,e.writingMode.toString(),e.direction.toString())}function nb(t,e){let i=t.split(" "),n=[];for(let a of i){let h=Jp(a,e);n.includes(h)||n.push(h)}let r=[],o=!1,s=!1;for(let a=0;a<n.length;a++){let h=n[a];h.includes("block")?o||(n.slice(a+1).some(l=>l.includes("block"))?(r.push("snap-block"),o=!0):r.push(h)):h.includes("inline")&&(s||(n.slice(a+1).some(l=>l.includes("inline"))?(r.push("snap-inline"),s=!0):r.push(h)))}return r}var Oi=class Jo{constructor(e,i){u(this,"parent"),u(this,"floatReference"),u(this,"flowName"),u(this,"generatingNodePosition"),u(this,"writingMode"),u(this,"direction"),u(this,"pageSide"),u(this,"outerContext"),u(this,"floatStore"),u(this,"state"),this.parent=e.parent,this.floatReference=e.floatReference,this.flowName=e.flowName,this.generatingNodePosition=e.generatingNodePosition,this.writingMode=e.writingMode,this.direction=e.direction,this.pageSide=e.pageSide,this.outerContext=e.outerContext,this.floatStore=e.floatStore,this.state=i??this.newState()}static buildIdentity(e,i,n,r,o,s,a,h){var l,c,d;return{parent:e,floatReference:i,flowName:n,generatingNodePosition:r,writingMode:!Z(o)&&o||e?.writingMode||w.horizontal_tb,direction:!Z(s)&&s||e?.direction||w.ltr,pageSide:(c=(l=h??e?.pageSide)!=null?l:a?.pageSide)!=null?c:null,outerContext:a,floatStore:e?e.floatStore:(d=a?.floatStore)!=null?d:new tb}}newState(){let e=this.getPreviousSibling();return{children:[],floatAnchors:{},invalidated:!1,locked:!1,forbiddenFloats:[],floatFragments:[],stashedFloatFragments:[],floatsDeferredToNext:[],floatsDeferredFromPrevious:e?[...e.state.floatsDeferredToNext]:[],layoutConstraints:[],footnoteMaxBlockSize:null,ignoreFootnoteAreaMaxHeight:!1,footnoteAnchorsSeen:new Set,lineFootnoteInvalidationMaxBlockSize:new Map,lineFootnoteFinishInvalidatedOnce:new Set}}static createDetached(e,i,n,r){return new $u(Jo.buildIdentity(null,i,n,r,null,null,e,null))}static create(e,i,n,r,o,s,a=null,h=null){let l=Jo.buildIdentity(e,i,n,r,o,s,a,h);return new $u(l)}static createWithContainer(e,i,n,r,o,s,a,h=null,l=null){let c=Jo.buildIdentity(i,n,r,o,s,a,h,l);return new tf(c,e)}static register(e,i){if(!e)return;let n=e.state.children.findIndex(r=>r.state===i.state);n>=0?e.state.children[n]=i:e.state.children.push(i)}identity(){return{parent:this.parent,floatReference:this.floatReference,flowName:this.flowName,generatingNodePosition:this.generatingNodePosition,writingMode:this.writingMode,direction:this.direction,pageSide:this.pageSide,outerContext:this.outerContext,floatStore:this.floatStore}}get floatFragments(){return this.state.floatFragments}get footnoteMaxBlockSize(){return this.state.footnoteMaxBlockSize}set footnoteMaxBlockSize(e){this.state.footnoteMaxBlockSize=e}get ignoreFootnoteAreaMaxHeight(){return this.state.ignoreFootnoteAreaMaxHeight}set ignoreFootnoteAreaMaxHeight(e){this.state.ignoreFootnoteAreaMaxHeight=e}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}`)}getPreviousSibling(){let e=this,i=this.parent,n;for(;i;){if(n=i.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),n)return n;e=i,i=i.parent}return null}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)}isForbidden(e){let i=e.getId(),n=e.floatReference;return n===this.floatReference?this.state.forbiddenFloats.includes(i):this.getParent(n).isForbidden(e)}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let i=this.floatFragments.findIndex(n=>n.hasFloat(e));return i>=0?this.floatFragments[i]: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(i=>i.continues&&i.getFlowName()===e&&i.floatSide!=="block-end")}markPageFloatAnchorSeen(e){var i;if(!("footnotePolicy"in e))return;let n=this;for(;n;)n.state.footnoteAnchorsSeen.add(e.getId()),n=(i=n.parent)!=null?i:n.outerContext}registerPageFloatAnchor(e,i){this.state.floatAnchors[e.getId()]=i,this.markPageFloatAnchorSeen(e)}hasInvalidatedForLineFootnote(e){return e.floatReference===this.floatReference?this.state.lineFootnoteInvalidationMaxBlockSize.get(e.getId())===this.footnoteMaxBlockSize:this.getParent(e.floatReference).hasInvalidatedForLineFootnote(e)}markInvalidatedForLineFootnote(e){e.floatReference===this.floatReference?this.state.lineFootnoteInvalidationMaxBlockSize.set(e.getId(),this.footnoteMaxBlockSize):this.getParent(e.floatReference).markInvalidatedForLineFootnote(e)}deferPageFloat(e){let i=e.float;if(i.floatReference===this.floatReference){let n=this.state.floatsDeferredToNext.findIndex(r=>r.float===i);n>=0?this.state.floatsDeferredToNext.splice(n,1,e):this.state.floatsDeferredToNext.push(e)}else this.getParent(i.floatReference).deferPageFloat(e)}removeFloatDeferredToNext(e){let i=this.state.floatsDeferredToNext.findIndex(n=>n.float===e);i>=0&&this.state.floatsDeferredToNext.splice(i,1)}hasPrecedingFloatsDeferredToNext(e,i){if(!i&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let n=e.getOrder();return this.state.floatsDeferredToNext.some(r=>r.float.getOrder()<n&&!e.isAllowedToPrecede(r.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let i=e.getOrder(),n=null;if(this.floatFragments.forEach(r=>{r.continuations.forEach(o=>{let s=o.float,a=s.getOrder();a>i&&(!n||a>n.getOrder())&&(n=s)})}),this.parent){let r=this.parent.getLastFollowingFloatInFragments(e);r&&(!n||r.getOrder()>n.getOrder())&&(n=r)}return n}getDeferredPageFloatContinuations(e){e=e||this.flowName;let i=this.state.floatsDeferredFromPrevious.filter(n=>!e||n.float.flowName===e);return this.parent&&(i=this.parent.getDeferredPageFloatContinuations(e).concat(i)),i.sort((n,r)=>n.float.getOrder()-r.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let i=this.state.floatsDeferredToNext.filter(n=>!e||n.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(i):i}trySetFootnoteRetryMaxBlockSize(e){let i=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:e/2;return i<Qw?!1:(this.footnoteMaxBlockSize=i,!0)}isInvalidated(){return this.state.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.state.invalidated=!1}toLogical(e){return Jp(e,this)}toPhysical(e){return ib(e,this)}toLogicalFloatSides(e){return nb(e,this)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.state.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.state.stashedFloatFragments.concat().sort((i,n)=>n.getOrder()-i.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getFloatFragmentExclusions(){let e=this.floatFragments.map(i=>i.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.state.layoutConstraints)}addLayoutConstraint(e,i){i===this.floatReference?this.state.layoutConstraints.push(e):this.getParent(i).addLayoutConstraint(e,i)}lock(){this.state.locked=!0}unlock(){this.state.locked=!1}isLocked(){return this.state.locked}},$u=class extends Oi{withContainer(t){return new tf(this.identity(),t,this.state)}},Qp=class extends Oi{get children(){return this.state.children}attachChildren(t){t.forEach(e=>{this.state.children.push(e),e.reattachFloatFragments()})}detachChildren(){let t=this.state.children.splice(0);return t.forEach(e=>{e.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),t}collectPageFloatAnchors(){let t=Object.assign({},this.state.floatAnchors);return this.state.children.reduce((e,i)=>Object.assign(e,i.collectPageFloatAnchors()),t)}getFloatsDeferredToNextInChildContexts(){let t=[],e=[];for(let i=this.state.children.length-1;i>=0;i--){let n=this.state.children[i];e.includes(n.flowName)||(e.push(n.flowName),t=t.concat(n.state.floatsDeferredToNext.map(r=>r.float)),t=t.concat(n.getFloatsDeferredToNextInChildContexts()))}return t}findPageFloatAnchor(t){var e;for(let i=this.state.children.length-1;i>=0;i--){let n=this.state.children[i].findPageFloatAnchor(t);if(n)return n}return(e=this.state.floatAnchors[t])!=null?e:null}hasRootMultiColumnFootnoteContext(){return this.state.children.some(t=>{let e=0;for(let i of t.state.children)if(!i.generatingNodePosition&&(e+=1,e>1))return!0;return!1})}getPreviousSiblingOf(t,e,i,n){let r=this.state.children.indexOf(t);r<0&&(r=this.state.children.length);for(let o=r-1;o>=0;o--){let s=this.state.children[o];if(s.floatReference===e&&s.flowName===i&&Di(s.generatingNodePosition,n)||(s=s.getPreviousSiblingOf(null,e,i,n),s))return s}return null}},Hu=class ef extends Qp{asAttached(){return null}addPageFloatLayoutContextAsPreviousSibling(e){this.state.children.push(e)}static createRoot(){return new ef(Oi.buildIdentity(null,null,null,null,null,null,null,null))}},tf=class extends Qp{constructor(t,e,i){var n,r;super(t,i),u(this,"container",e),u(this,"attachedParent"),u(this,"attachedOuter"),this.attachedParent=(r=(n=t.parent)==null?void 0:n.asAttached())!=null?r:null,this.attachedOuter=t.outerContext,this.reattachFloatFragments(),Oi.register(this.parent,this)}asAttached(){return this}getParent(t){var e;let i=(e=this.attachedParent)!=null?e:this.attachedOuter;if(i)return i;throw new Error(`No PageFloatLayoutContext for ${t}`)}getPageFloatLayoutContext(t){return t===this.floatReference?this:this.getParent(t).getPageFloatLayoutContext(t)}forbid(t){let e=t.getId(),i=t.floatReference;i===this.floatReference?this.state.forbiddenFloats.includes(e)||(this.state.forbiddenFloats.push(e),new Wn().findByFloat(t).forbid(t,this)):this.getParent(i).forbid(t)}addPageFloatFragment(t,e){let i=t.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(t,e):this.floatFragments.includes(t)||(this.floatFragments.push(t),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),e||this.invalidate()}removePageFloatFragment(t,e){let i=t.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(t,e);else{let n=this.floatFragments.indexOf(t);if(n>=0){let r=this.floatFragments.splice(n,1)[0],o=r.area&&r.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),e||this.invalidate()}}}hasCurrentAnchor(t){let e=this.findPageFloatAnchor(t);return e?this.container.element.contains(e):!1}isAnchorAlreadyAppeared(t){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===t))return!0;let e=this.findPageFloatAnchor(t);return e?this.container.element.contains(e):!1}hasNonRootMultiColumnFootnoteContext(){return this.state.children.some(t=>t.state.children.some(e=>Ww(e.container.element)))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}initFootnoteRetryFromEmptyFragment(t,e){if(!("footnotePolicy"in t&&this.footnoteMaxBlockSize==null&&this.state.footnoteAnchorsSeen.has(t.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let i=(e.vertical?e.width:e.height)+e.getInsetBefore()+e.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(i)}checkAndForbidNotAllowedFloat(){var t;if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let i=this.floatFragments[e],n=i.findNotAllowedFloat(this);if(n){let r=i.area&&"isFootnote"in i.area&&i.area.isFootnote;if(this.state.locked)this.invalidate();else{let o=r&&"footnotePolicy"in n&&n.footnotePolicy===w.line;if(r&&this.state.footnoteAnchorsSeen.has(n.getId())&&(o||this.hasMultiColumnFootnoteContext())){let s=i.area.computedBlockSize+i.area.getInsetBefore()+i.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(s))return this.removePageFloatFragment(i),this.removeEndFloatFragments(i.floatSide),!0}this.removePageFloatFragment(i),this.forbid(n),this.removeEndFloatFragments(i.floatSide)}return!0}}return this.floatReference===Ne.REGION&&(t=this.attachedParent)!=null&&t.isLocked()?this.attachedParent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let t=this.getFloatsDeferredToNextInChildContexts(),e=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);e.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of e){let n=i.getOrder();if(t.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.state.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){for(let t=this.floatFragments.length-1;t>=0;t--){let e=this.floatFragments[t];if(e.continuations.some(i=>{let n=i.float;return"footnotePolicy"in n&&n.footnotePolicy===w.line&&!this.hasCurrentAnchor(n.getId())&&!this.state.floatsDeferredFromPrevious.some(r=>r.float===n)})){if(this.state.locked){this.invalidate();return}this.removePageFloatFragment(e);return}}if(!this.checkAndForbidNotAllowedFloat()){for(let t=this.state.floatsDeferredToNext.length-1;t>=0;t--){let e=this.state.floatsDeferredToNext[t].float,i=this.findPageFloatFragment(e);if("footnotePolicy"in e&&e.footnotePolicy===w.line&&this.hasCurrentAnchor(e.getId())&&!i&&!this.state.lineFootnoteFinishInvalidatedOnce.has(e.getId())){if(this.state.locked){this.invalidate();return}this.state.lineFootnoteFinishInvalidatedOnce.add(e.getId()),this.removeFloatDeferredToNext(e),this.forbid(e),this.invalidate();return}}for(let t=this.state.floatsDeferredToNext.length-1;t>=0;t--)if(!this.state.floatsDeferredToNext[t].float.isAllowedOnContext(this)){if(this.state.locked){this.invalidate();return}this.state.floatsDeferredToNext.splice(t,1)}this.state.floatsDeferredFromPrevious.forEach(t=>{this.state.floatsDeferredToNext.findIndex(e=>t.equals(e))>=0||this.floatFragments.some(e=>e.hasFloat(t.float))||this.state.floatsDeferredToNext.push(t)})}}restoreStashedFragments(t){if(t!==this.floatReference){this.getParent(t).restoreStashedFragments(t);return}this.state.stashedFloatFragments.forEach(e=>{this.addPageFloatFragment(e,!0)}),this.state.stashedFloatFragments.splice(0)}hasSameContainerAs(t){return this.container.element===t.container.element}invalidate(){this.state.invalidated=!0,!this.state.locked&&(this.state.children.forEach(t=>{this.hasSameContainerAs(t)&&t.floatFragments.forEach(e=>{let i=e.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear(),this.state.children.forEach(t=>{t.state.layoutConstraints.splice(0)}),this.state.children.splice(0),Object.keys(this.state.floatAnchors).forEach(t=>{delete this.state.floatAnchors[t]}))}removeEndFloatFragments(t){let e=this.toLogicalFloatSides(t)[0];if(e==="block-end"||e==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===e?this.removePageFloatFragment(n):i++}}}isFragmentInCurrentContainer(t){if(this.floatReference!==Ne.REGION)return!0;let e=t.area;return!e.parentElement||e.parentElement===this.container.element}stashEndFloatFragments(t){let e=t.floatReference;if(e!==this.floatReference){this.getParent(e).stashEndFloatFragments(t);return}let i=this.toLogicalFloatSides(t.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],o=this.toLogicalFloatSides(r.floatSide)[0];this.isFragmentInCurrentContainer(r)&&(o===i||i==="snap-block"&&o==="block-end"||i==="snap-inline"&&o==="inline-end")&&r.shouldBeStashedBefore(t)?(this.state.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}getLimitValue(t,e,i,n,r,o=!0,s){let a=this.toLogical(t),h=this.toPhysical(t),l=e&&this.toLogical(e),c=e&&this.toPhysical(e),d=this.getLimitValueInner(a,l,i,n,r,s),p=this.attachedParent;if(o&&p){let f=p.getLimitValue(h,c,i,n,r,o,s);switch(h){case"top":return Math.max(d,f);case"left":return Math.max(d,f);case"bottom":return Math.min(d,f);case"right":return Math.min(d,f);default:}}return d}getLimitValueInner(t,e,i,n,r,o){let s=this.getLimitValuesInner(i,n,r,t,e,o);switch(t){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: ${t}`)}}getLimitValuesInner(t,e,i,n,r,o){var s,a,h,l;let c=this.container.originX,d=this.container.originY,p=this.container.getPaddingRect(),f={top:p.y1-d,left:p.x1-c,bottom:p.y2-d,right:p.x2-c,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let v=parseFloat((a=(s=this.container.element)==null?void 0:s.style)==null?void 0:a.width);isFinite(v)&&v>this.container.width&&(f.right+=v-this.container.width)}else{let v=parseFloat((l=(h=this.container.element)==null?void 0:h.style)==null?void 0:l.height);isFinite(v)&&v>this.container.height&&(f.bottom+=v-this.container.height)}function g(v,b,x){return v.unit==="%"?x*v.num/100:t.convertLengthToPx(v,b,e)}let m=this.floatFragments;return m.length>0&&(f=m.reduce((v,b)=>{if(b.area===o||!this.isFragmentInCurrentContainer(b)||i&&!i(b,this))return v;let[x,C]=this.toLogicalFloatSides(b.floatSide);if(C&&(n&&C.includes("block")===n.includes("block")&&C!==n||r&&C.includes("block")===r.includes("block")&&C!==r))return v;let y=b.area,k=b.continuations[0].float.floatMinWrapBlock,S=y.vertical?y.left+y.getInsetLeft()+y.width+y.getInsetRight():y.top+y.getInsetTop()+y.height+y.getInsetBottom(),N=y.vertical?y.top+y.getInsetTop()+y.height+y.getInsetBottom():y.left+y.getInsetLeft()+y.width+y.getInsetRight(),L=v.top,I=v.left,D=v.bottom,J=v.right,te=v.floatMinWrapBlockStart,P=v.floatMinWrapBlockEnd;switch(x){case"inline-start":y.vertical?L=Math.max(L,N):I=Math.max(I,N);break;case"block-start":y.vertical?(k&&y.left<J&&(te=g(k,y.rootViewNodes[0],p.x2-p.x1)),J=Math.min(J,y.left)):(k&&S>L&&(te=g(k,y.rootViewNodes[0],p.y2-p.y1)),L=Math.max(L,S));break;case"inline-end":y.vertical?D=Math.min(D,y.top):J=Math.min(J,y.left);break;case"block-end":y.vertical?(k&&S>I&&(P=g(k,y.rootViewNodes[0],p.x2-p.x1)),I=Math.max(I,S)):(k&&y.top<D&&(P=g(k,y.rootViewNodes[0],p.y2-p.y1)),D=Math.min(D,y.top));break;default:throw new Error(`Unknown logical float side: ${x}`)}return{top:L,left:I,bottom:D,right:J,floatMinWrapBlockStart:te,floatMinWrapBlockEnd:P}},f)),f.left+=c,f.right+=c,f.top+=d,f.bottom+=d,f}setFloatAreaDimensions(t,e,i,n,r,o,s){if(e!==this.floatReference)return this.getParent(e).setFloatAreaDimensions(t,e,i,n,r,o,s);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!s["block-start"]&&!s["block-end"])return null}else if(a[0].includes("block")&&!s[a[0]])return null;let h=a.find(S=>S.includes("inline")&&s[S==="inline-start"?"inline-end":"inline-start"]),l=a.find(S=>S.includes("block")),c=!0,d=this.getLimitValue("block-start",h,t.layoutContext,t.clientLayout,void 0,c,t),p=this.getLimitValue("block-end",h,t.layoutContext,t.clientLayout,void 0,c,t),f=this.getLimitValue("inline-start",l,t.layoutContext,t.clientLayout,void 0,c,t),g=this.getLimitValue("inline-end",l,t.layoutContext,t.clientLayout,void 0,c,t),m=t.vertical?t.originX:t.originY,v=t.vertical?t.originY:t.originX;t.isFootnote||(d=t.vertical?Math.min(d,t.left+t.getInsetLeft()+t.width+t.getInsetRight()+m):Math.max(d,t.top+m),p=t.vertical?Math.max(p,t.left+m):Math.min(p,t.top+t.getInsetTop()+t.height+t.getInsetBottom()+m));function b(S,N){let L=S(t.bands,N);return L?(t.vertical&&(L=Wd(L)),d=t.vertical?Math.min(d,L.x2):Math.max(d,L.y1),p=t.vertical?Math.max(p,L.x1):Math.min(p,L.y2),!0):o}let x,C,y,k;if(r){let S=t.vertical?ys(new Dt(p,f,d,g)):new Dt(f,d,g,p);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!b(By,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!b(My,S)||(t.isFootnote&&n!==null&&isFinite(n)&&a[0]==="block-end"&&(t.vertical?d=Math.min(d,n):d=Math.max(d,n)),y=(p-d)*t.getBoxDir(),t.isFootnote&&this.footnoteMaxBlockSize!=null&&(y=Math.min(y,this.footnoteMaxBlockSize),t.vertical?d=p+y:d=p-y),x=Math.max(0,y-t.getInsetBefore()-t.getInsetAfter()),k=(g-f)*t.getInlineDir(),C=k-t.getInsetStart()-t.getInsetEnd(),!o&&(x<=0||C<=0)))return null}else{let S=t.getContentBlockMarginAfter();x=Math.max(0,t.computedBlockSize+Math.min(0,S)),y=x+t.getInsetBefore()+t.getInsetAfter();let N=(p-d)*t.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let I=this.container.getPaddingRect(),D=this.container.getBoxDir()*(n-(this.container.vertical?I.x2:I.y1)),J=this.container.getBoxDir()*((this.container.vertical?I.x1:I.y2)-n-y);D<=J?a[0]="block-start":a[0]="block-end"}if(!s[a[0]])if(s["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(s["inline-start"])a[0]="inline-start";else if(s["inline-end"])a[0]="inline-end";else return null;if(!o&&N<y)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?C=fh(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?C=t.getContentInlineSize():C=t.vertical?t.height:t.width,k=C+t.getInsetStart()+t.getInsetEnd();let L=(g-f)*t.getInlineDir();if(!o&&L<k)return null}if(d-=m,p-=m,f-=v,g-=v,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?t.setInlinePosition(f,C):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&t.setInlinePosition(g-k*t.getInlineDir(),C),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline"))t.setBlockPosition(d,x);else if(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end"){let S=p-y*t.getBoxDir();t.setBlockPosition(S,x)}return a.join(" ")}reattachFloatFragments(){let t=this.container.element&&this.container.element.parentNode;t&&this.floatFragments.forEach(e=>{t.appendChild(e.area.element)})}getMaxReachedAfterEdge(){let t=this.container.vertical;return this.floatFragments.reduce((e,i)=>{let n=i.getOuterRect();return t?Math.min(e,n.x1):Math.max(e,n.y2)},t?1/0:0)}getBlockEndEdgeOfBlockStartFloats(t){let e=this.container.vertical,i=NaN;this.floatFragments.filter(r=>r.floatSide.includes("block-start")).filter(r=>{if(t===void 0||!isFinite(t))return!0;let o=r.getOuterRect();return e?o.y1<=t&&t<=o.y2:o.x1<=t&&t<=o.x2}).forEach(r=>{let o=r.getOuterRect(),s=e?o.x1:o.y2;i=isFinite(i)?e?Math.min(i,s):Math.max(i,s):s});let n=this.attachedParent;if(n){let r=n.getBlockEndEdgeOfBlockStartFloats(t);isFinite(r)&&(i=isFinite(i)?e?Math.min(i,r):Math.max(i,r):r)}return i}getBlockStartEdgeOfBlockEndFloats(t){let e=this.container.vertical,i=NaN;this.floatFragments.filter(r=>r.floatSide.includes("block-end")).filter(r=>{if(t===void 0||!isFinite(t))return!0;let o=r.getOuterRect();return e?o.y1<=t&&t<=o.y2:o.x1<=t&&t<=o.x2}).forEach(r=>{let o=r.getOuterRect(),s=e?o.x2:o.y1;i=isFinite(i)?e?Math.max(i,s):Math.min(i,s):s});let n=this.attachedParent;if(n){let r=n.getBlockStartEdgeOfBlockEndFloats(t);isFinite(r)&&(i=isFinite(i)?e?Math.max(i,r):Math.min(i,r):r)}return i}getPageFloatClearEdge(t,e){let i=c=>{let d=this.toLogicalFloatSides(c),p=d[0];return t==="both"?p==="block-end":t==="inline-start"?d.includes("inline-end")||p==="block-end":t==="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 o=e.getPaddingRect(),s=e.vertical?o.x1:o.y2,a=this;for(;a;){if(a.state.floatsDeferredToNext.some(n(a)))return s;a=a.attachedParent}function h(c){return c.floatFragments.some(d=>r(d,c))||c.state.children.some(d=>h(d))}if(t==="column"||t==="region"||t==="page"){for(a=this;a;a=a.attachedParent)if(a.floatReference===t){if(h(a))return s;break}}let l=this.getLimitValue("block-start",null,e.layoutContext,e.clientLayout,r);return this.getLimitValue("block-end",null,e.layoutContext,e.clientLayout,r)*e.getBoxDir()<s*e.getBoxDir()?s:l}getPageFloatPlacementCondition(t,e,i){if(t.floatReference!==this.floatReference)return this.getParent(t.floatReference).getPageFloatPlacementCondition(t,e,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(e)[0],o=this.toLogical(i),s;o==="all"?s=["block-start","block-end","inline-start","inline-end"]:o==="both"?s=["inline-start","inline-end"]:o==="same"?r==="snap-block"?s=["block-start","block-end"]:s=[r]:s=[o];let a=t.getOrder();function h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.state.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.attachedParent)if(d.floatReference===i){(d.floatFragments.some(h(null))||l(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return s.forEach(d=>{switch(d){case"block-start":n[d]=!l(this,d);break;case"block-end":n[d]=!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}isColumnFullWithPageFloats(t){let e=t.layoutContext,i=t.clientLayout,n=this.getLimitValuesInner(e,i);for(let o=this.attachedParent;o;o=o.attachedParent){let s=o.getLimitValuesInner(e,i);t.vertical?(s.right<n.right&&(n.right=s.right,n.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.left>n.left&&(n.left=s.left,n.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd)):(s.top>n.top&&(n.top=s.top,n.floatMinWrapBlockStart=s.floatMinWrapBlockStart),s.bottom<n.bottom&&(n.bottom=s.bottom,n.floatMinWrapBlockEnd=s.floatMinWrapBlockEnd))}let r=Math.max(n.floatMinWrapBlockStart,n.floatMinWrapBlockEnd);return(t.vertical?n.right-n.left:n.bottom-n.top)<=r}getMaxBlockSizeOfPageFloats(){let t=this.container.vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(e=>{let i=e.area;return t?i.width:i.height})):0}},sr=[],Wn=class{static register(t){sr.push(t)}findByNodeContext(t){for(let e=sr.length-1;e>=0;e--){let i=sr[e];if(i.appliesToNodeContext(t))return i}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=sr.length-1;e>=0;e--){let i=sr[e];if(i.appliesToFloat(t))return i}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},rb=class{appliesToNodeContext(t){return Li(t.floatReference)}appliesToFloat(t){return!0}createPageFloat(t,e,i){let n=t.floatReference,r=t.floatSide,o=t.toNodePosition(),s=!!e.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,t.columnSpan,t).thenAsync(a=>{n=a,e.flowName;let h=new Zp(o,n,r,t.clearSide,e.flowName,t.floatMinWrapBlock);if(h.insidePageFloatArea=s,s){let l=e.generatingNodePosition;l&&(h.parentPageFloat=e.findPageFloatByNodePosition(l))}return e.addPageFloat(h),F(h)})}createPageFloatFragment(t,e,i,n,r){let o=t[0].float;return new Kp(o.floatReference,e,i,t,n,r)}findPageFloatFragment(t,e){return e.findPageFloatFragment(t)}adjustPageFloatArea(t,e,i){return F(void 0)}forbid(t,e){}};Wn.register(new rb);var nf="data-vivliostyle-footnote-first-ref",rf="data-vivliostyle-footnote-referenced";function Es(t,e){return!!(t&&t.match(new RegExp(`(^|\\s)${e}($|\\s)`)))}function Et(t){if(t.localName!=="aside")return!1;if(Es(t.getAttribute("role"),"doc-footnote"))return!0;let e=t.getAttributeNS("http://www.idpf.org/2007/ops","type")||t.getAttribute("epub:type");return Es(e,"footnote")}function qt(t){if(t.localName!=="a")return!1;if(Es(t.getAttribute("role"),"doc-noteref"))return!0;let e=t.getAttributeNS("http://www.idpf.org/2007/ops","type")||t.getAttribute("epub:type");return Es(e,"noteref")}function gh(t,e){if(!qt(t))return null;let i=t.getAttribute("href")||t.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return null;let n=fs(i,e);return n==="#"?null:n}function of(t,e,i){let n=gh(t,e);if(!n)return null;let r=i(n);return r&&Et(r)?r:null}function ob(t,e,i,n,r){if(r.value)return;let o=t.getElementsByTagName("a");for(let s=0;s<o.length;s++){let a=o.item(s),h=gh(a,e);!h||n.has(h)||n.set(h,i(a))}r.value=!0}function Uu(t,e,i,n,r){if(t.localName!=="a"||!qt(t))return!0;let o=gh(t,e);if(!o)return!0;ob(t.ownerDocument,e,i,n,r);let s=n.get(o);return s==null||i(t)===s}function mh(t,e){let i=e.getProp(t,"footnote-display");if(i)return i;let n=e.getProp(t,"display");return n?.value===w.inline?e.createCascadeValue(w.inline,n.priority):null}function sb(t,e,i,n,r,o,s){if(t.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||t.localName!=="include"||!t.classList.contains("-vivliostyle-footnote-content"))return e;let a=i?.owner;if(!(a instanceof Element)||!qt(a))return e;let h=of(a,n,r);if(!h)return e;let l=a.getAttribute(o);l?(t.setAttribute(o,l),h.setAttribute(o,l)):(t.removeAttribute(o),h.removeAttribute(o));let c=s.getStyle(h);if(!c)return e;let d={...e},p=mh(c,s),f=s.getProp(c,"footnote-policy"),g=s.getStyleMap(c,"_pseudos"),m=g?.after;if(p&&(d["footnote-display"]=p),f&&(d["footnote-policy"]=f),m){let v=s.getMutableStyleMap(d,"_pseudos");v.after={...m}}return d}function ab(t,e,i,n,r){if(!(i?.type===st.ROOTED&&Et(t)))return e;let o=r.getStyle(t);if(!o)return e;let s={...e},a=mh(o,r),h=r.getProp(o,"footnote-policy"),l=r.getStyleMap(o,"_pseudos"),c=l?.["footnote-marker"],d=r.getProp(c,"content"),p=r.getProp(c,"list-style-position");if(a&&(s["footnote-display"]=a),h&&(s["footnote-policy"]=h),d&&p?.evaluate(n,"list-style-position")===w.outside){let f=r.filterFootnoteMarkerContent(d,t);s["--viv-marker-content"]=r.createCascadeValue(f,0),s.display=r.createCascadeValue(_("list-item"),0),s["list-style-position"]=r.createCascadeValue(w.outside,0),s["list-style-type"]=r.createCascadeValue(w.none,0),s["list-style-image"]=r.createCascadeValue(w.none,0)}return s}function lb(t,e,i){var n,r;let o=e?.type===st.ROOTED&&Et(t)?i.getStyle(t):null;return{sourceStyle:o,footnoteDisplay:((n=mh(o,i))==null?void 0:n.value)||null,footnotePolicy:((r=i.getProp(o,"footnote-policy"))==null?void 0:r.value)||null}}function sf(t,e){if(t instanceof j){let i=t.expr.evaluate(e);return typeof i=="string"?new K(i):typeof i=="number"?new K(String(i)):t}return t instanceof ee?new ee(t.values.map(i=>sf(i,e))):t}function hb(t,e,i){let n=t?.["_footnote-marker-content"];n&&(e["--viv-marker-content"]=sf(n.value,i))}function ub(t){let e=t.getElementsByTagName("a"),i=new Set;for(let n=0;n<e.length;n++){let r=e.item(n);if(!qt(r)||!(r instanceof HTMLAnchorElement)||!r.hash||r.href!==r.baseURI.replace(/#.*$/,"")+r.hash)continue;let o=r.hash.substring(1),s=t.getElementById(o);if(s&&Et(s)){let a=r.baseURI.replace(/#.*$/,"")+r.hash;i.has(a)||(i.add(a),r.setAttribute(nf,"true")),s.setAttribute(rf,"true")}}}Ft("PREPROCESS_SINGLE_DOCUMENT",ub);var cb=Kp,db=.1,jr=class af extends Zp{constructor(e,i,n,r,o,s){super(e,i,"block-end",null,n,o),u(this,"footnotePolicy",r),u(this,"policyAnchorNode",s)}isAllowedToPrecede(e){return!(e instanceof af)}};function pb(t){let e=t.nodeType===Node.ELEMENT_NODE?t:t.parentElement;for(;e;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(e.localName)&&!e.querySelector("br"))return e;e=e.parentElement}return t}function lf(t){return t?-1:1}function cl(t,e){return e?t.right:t.top}function yh(t,e){return e?t.left:t.bottom}function hf(t){return{left:t.left,top:t.top,right:t.right,bottom:t.bottom,width:t.width,height:t.height}}function uf(t,e){let i=hf(t.getBoundingClientRect());return dh(i,e),i.right<i.left||i.bottom<i.top?null:i}function dl(t,e){let i=Array.from(t,hf);return Ps(i,e),i.filter(n=>n.right>n.left&&n.bottom>n.top)}function cf(t,e){return t.length?e?Math.min(...t.map(i=>i.left)):Math.max(...t.map(i=>i.bottom)):NaN}function fb(t,e){if(!t.length)return NaN;let i=lf(e),n=t.reduce((r,o)=>cl(o,e)*i<cl(r,e)*i?o:r);return yh(n,e)}function gb(t,e){if(!t)return NaN;if(t.nodeType===Node.ELEMENT_NODE){let o=uf(t,e);return o?yh(o,e):NaN}let i=t.textContent||"";if(!i.length)return NaN;let n=t.ownerDocument.createRange();n.setStart(t,0),n.setEnd(t,i.length);let r=dl(n.getClientRects(),e);return cf(r,e)}function mb(t,e){let i=t.viewNode;if(!i)return NaN;if(i.nodeType===Node.ELEMENT_NODE){let a=i;if(t.after||!t.inline){let l=uf(a,e);if(l)return t.after?yh(l,e):cl(l,e)}let h=dl(a.getClientRects(),e);return fb(h,e)}let n=i.textContent||"";if(!n.length)return NaN;let r=t.offsetInNode;t.after&&(r+=n.length),r=Math.max(0,Math.min(r,n.length-1));let o=i.ownerDocument.createRange();o.setStart(i,r),o.setEnd(i,r+1);let s=dl(o.getClientRects(),e);return cf(s,e)}var Wu=class extends cb{constructor(t,e,i,n){super(t,"block-end",null,e,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof jr?!0:this.getOrder()<t.getOrder()}},yb=class{constructor(t,e,i){u(this,"footnote",t),u(this,"vertical",i),u(this,"anchorEdge"),this.anchorEdge=gb(e,i)}allowLayout(t){if(!isNaN(this.anchorEdge)){let i=mb(t,this.vertical);if(!isNaN(i)){let n=lf(this.vertical);return i*n<this.anchorEdge*n-db}}let e=t.toNodePosition();return!Di(e,this.footnote.nodePosition)}},vb=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof jr}createPageFloat(t,e,i){var n;let r=Ne.REGION,o=e.getPageFloatLayoutContext(r);e.getPageFloatLayoutContext(Ne.PAGE).hasSameContainerAs(o)&&(r=Ne.PAGE);let s=!!e.generatingNodePosition;s&&r!==Ne.PAGE&&(r=Ne.PAGE);let a=t.toNodePosition();e.flowName;let h=t.sourceNode,l=(n=t.shadowContext)==null?void 0:n.owner;l instanceof Element&&qt(l)&&(h=l),h=pb(h);let c=new jr(a,r,e.flowName,t.footnotePolicy,t.floatMinWrapBlock,h);if(c.insidePageFloatArea=s,s){let d=e.generatingNodePosition;d&&(c.parentPageFloat=e.findPageFloatByNodePosition(d))}return e.addPageFloat(c),F(c)}createPageFloatFragment(t,e,i,n,r){let o=t[0].float;return new Wu(o.floatReference,t,n,r)}findPageFloatFragment(t,e){let i=e.getPageFloatLayoutContext(t.floatReference),n=i.container.element,r=i.floatFragments.filter(o=>o instanceof Wu&&(t.floatReference!==Ne.REGION||!o.area.parentElement||o.area.parentElement===n));return r.find(o=>o.hasFloat(t))||r[0]||null}adjustPageFloatArea(t,e,i){t.isFootnote=!0,t.adjustContentRelativeSize=!1;let n=t.element;return i.layoutContext.applyFootnoteStyle(e.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>{var o,s;if(t.vertical=r,t.convertPercentageSizesToPx(n),i.setComputedInsets(n,t),i.setComputedWidthAndHeight(n,t),((o=i.clientLayout.getElementComputedStyle(n))==null?void 0:o.boxSizing)==="border-box"){let h=t.vertical?t.paddingLeft+t.paddingRight+t.borderLeft+t.borderRight:t.paddingTop+t.paddingBottom+t.borderTop+t.borderBottom,l=t.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)||R(n,d,`${Math.max(0,f-h)}px`)}}R(n,"box-sizing","content-box")}let a=i.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){R(n,"max-block-size",""),R(n,t.vertical?"max-width":"max-height","");break}a=(s=a.parent)!=null?s:null}return F(void 0)})}forbid(t,e){let i=t;if(i.footnotePolicy===w.line){let n=e.collectPageFloatAnchors()[i.getId()]||null,r=new yb(i,n,e.getPageFloatLayoutContext(i.floatReference).container.vertical);e.addLayoutConstraint(r,i.floatReference)}}};Wn.register(new vb);var vh=class{calculateOffset(t){return zn(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function zn(t,e){return{current:e.reduce((i,n)=>i+n.calculateOffset(t),0),minimum:e.reduce((i,n)=>i+n.calculateMinimumOffset(t),0)}}var po=class extends vh{constructor(t,e,i,n){super(),u(this,"position",t),u(this,"breakOnEdge",e),u(this,"overflows",i),u(this,"computedBlockSize",n),u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(t,e){return this.updateOverflows(t),e<this.getMinBreakPenalty()?null:t.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let t=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(ws(this.breakOnEdge)?1:0)+(this.overflows&&!t?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(t){var e;let i=t.calculateClonedPaddingBorder(this.position);if(this.edge=Tn(this.position,t.clientLayout,0,t.vertical)+i,!this.position.after&&!this.position.inline){let n=t.parseComputedLength(t.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(t.vertical?-1:1)*n}else if(this.position.after&&((e=this.position.shadowContext)==null?void 0:e.root.id)==="table-cell"){let n=t.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let o=r.style.borderCollapse==="collapse",s=0,a=0;for(let h=n;h;h=h.parentElement){let l=t.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!o)&&(s+=t.parseComputedLength(l.paddingBlockEnd)),h===r&&!o&&(s+=t.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),o?a=Math.max(a,t.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=t.parseComputedLength(l.borderBlockEndWidth)),h===r)break}this.edge+=(t.vertical?-1:1)*(s+a)}}this.isEdgeUpdated=!0}updateOverflows(t){this.isEdgeUpdated||this.updateEdge(t);let e=this.edge,i=this.calculateOffset(t);this.overflowIfRepetitiveElementsDropped=t.isOverflown(e+(t.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=t.isOverflown(e+(t.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let t=this.getNodeContext();if(!t||!t.parent)return!1;let{formattingContext:e}=t.parent;if(!rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))return!1;let i=e.getRepetitiveElements();return i?i.isFirstContentNode(t):!1}},ar=class{find(t){let e=zt("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<e.length;i++){let n=e[i](t);if(n)return n}throw new Error(`No processor found for a formatting context: ${t.getName()}`)}},On=class{layout(t,e,i){let n=e.asFloatNodeContext(t);return n?e.layoutFloatOrFootnote(n):e.isBreakable(t)?e.layoutBreakableBlock(t):e.layoutUnbreakable(t)}createEdgeBreakPosition(t,e,i,n){return new po(t.copy(),e,i,n)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return!1}clearOverflownViewNodes(t,e,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===wi.ShadowType.ROOTLESS&&Ln(i))return;let o=i.viewNode;o=(r=Wp(o))!=null?r:o;let s=o.parentNode;Hp(s,o),n&&o.remove()}finishBreak(t,e,i,n){let r=i||e.viewNode!=null&&e.viewNode.nodeType==1&&!e.after;return t.clearOverflownViewNodes(e,r),n&&t.layoutContext.processFragmentedBlockEdge(e),F(!0)}},ra=class{constructor(t){u(this,"parent",t),u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}saveState(){}restoreState(t){}},wh=new On,wb=sl.isInstanceOfBlockFormattingContext;Ft("RESOLVE_FORMATTING_CONTEXT",t=>{let e=t.parent;return!e||t.formattingContext!==e.formattingContext?null:t.establishesBFC?new ra(e.formattingContext):null});Ft("RESOLVE_LAYOUT_PROCESSOR",t=>t instanceof ra?wh:null);var bh=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition",null),u(this,"initialFragmentLayoutConstraints",null)}layout(t,e){return this.prepareLayout(t,e),this.tryLayout(t,e)}tryLayout(t,e){let i=V("AbstractLayoutRetryer.tryLayout");this.saveState(t,e);let n=this.resolveLayoutMode(t);return n.doLayout(t,e).then(r=>{let o=n.accept(r,e);o=n.postLayout(r,this.initialPosition,e,o),o?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(t,e),this.tryLayout(this.initialPosition,e).thenFinish(i))}),i.result()}prepareLayout(t,e){}clearNodes(t){var e,i;let n=(i=t.viewNode)!=null?i:(e=t.parent)==null?void 0:e.viewNode;if(!n)return;let r;for(;r=n.lastChild;)n.removeChild(r);let o;for(;o=n.nextSibling;)o.remove()}saveState(t,e){this.initialPosition=t.copy(),this.initialBreakPositions=[].concat(e.breakPositions),this.initialFragmentLayoutConstraints=[].concat(e.fragmentLayoutConstraints),this.initialStateOfFormattingContext=t.formattingContext.saveState()}restoreState(t,e){e.breakPositions=this.initialBreakPositions,e.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,t.formattingContext.restoreState(this.initialStateOfFormattingContext)}};function bb(t){return t.nodeContext!==null?t:null}function xb(t){return Yi(t.nodeContext)!==null?t:null}var Sb=class{initialState(t){return{nodeContext:t,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(t){}afterNonDisplayableNode(t){}startIgnoredTextNode(t){}afterIgnoredTextNode(t){}startNonElementNode(t){}afterNonElementNode(t){}startInlineElementNode(t){}afterInlineElementNode(t){}startNonInlineElementNode(t){}afterNonInlineElementNode(t){}finish(t){}},pl=class{constructor(t,e){u(this,"strategy",t),u(this,"layoutContext",e)}iterate(t){let e=this.strategy,i=e.initialState(t),n=V("LayoutIterator");return n.loopWithFrame(r=>{for(;;){let o=bb(i);if(!o)break;let s=this.step(o);if(s.isPending()){s.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=s.get()}e.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}step(t){let e=this.strategy,i,n=xb(t);return n?n.nodeContext.viewNode.nodeType!==1?Ee(n.nodeContext.viewNode,n.nodeContext.whitespace)?n.nodeContext.after?i=e.afterIgnoredTextNode(n):i=e.startIgnoredTextNode(n):n.nodeContext.after?i=e.afterNonElementNode(n):i=e.startNonElementNode(n):n.nodeContext.inline?n.nodeContext.after?i=e.afterInlineElementNode(n):i=e.startInlineElementNode(n):n.nodeContext.after?i=e.afterNonInlineElementNode(n):i=e.startNonInlineElementNode(n):t.nodeContext.after?i=e.afterNonDisplayableNode(t):i=e.startNonDisplayableNode(t),(i&&i.isPending()?i:F(!0)).thenAsync(()=>t.break?F(null):this.layoutContext.nextInTree(t.nodeContext,t.atUnforcedBreak))}},Ir=class extends Sb{constructor(t){super(),u(this,"leadingEdge",t)}startNonInlineBox(t){}endEmptyNonInlineBox(t){}endNonInlineBox(t){}initialState(t){return{nodeContext:t,atUnforcedBreak:!!this.leadingEdge&&t.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(t,e){let i=!t.leadingEdge&&Ye(t.breakAtTheEdge);return i&&((t.nodeContext=t.leadingEdgeContexts[0]||t.nodeContext).viewNode.remove(),e.pageBreakType=t.breakAtTheEdge),i}saveEdgeAndProcessOverflow(t,e){let i=e.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge);return i&&(t.nodeContext=(t.lastAfterNodeContext||t.nodeContext).modify(),t.nodeContext.overflow=!0),i}processLayoutConstraint(t,e,i){let n=t.nodeContext,r=!e.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!1,t.breakAtTheEdge),n=t.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(t){t.onStartEdges=!1}startNonInlineElementNode(t){return t.leadingEdgeContexts.push(t.nodeContext.copy()),t.breakAtTheEdge=nt(t.breakAtTheEdge,t.nodeContext.breakBefore),t.onStartEdges=!0,this.startNonInlineBox(t)}afterNonInlineElementNode(t){let e,i;return t.onStartEdges?(e=this.endEmptyNonInlineBox(t),i=e&&e.isPending()?e:F(!0),i=i.thenAsync(()=>(t.break||(t.leadingEdgeContexts=[],t.leadingEdge=!1,t.atUnforcedBreak=!1,t.breakAtTheEdge=null),F(!0)))):(e=this.endNonInlineBox(t),i=e&&e.isPending()?e:F(!0)),i.thenAsync(()=>(t.break||(t.onStartEdges=!1,t.lastAfterNodeContext=t.nodeContext.copy(),t.breakAtTheEdge=nt(t.breakAtTheEdge,t.nodeContext.breakAfter)),F(!0)))}},fl=[];function Cb(){fl=[]}var To;function Io(t){if(t==="")return 0;if(To===void 0){let i=Intl.Segmenter;To=typeof i=="function"?new i(void 0,{granularity:"grapheme"}):null}if(To===null)return[...t].length;let e=0;for(let i of To.segment(t))e++;return e}var kb=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Pb=new Set(kb);function Eb(t){return!(t.toLowerCase()==="none"||Pb.has(t))}var Nb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Tb=new Set(Nb),Ib=["fixed","extends"],Ab=new Set(Ib);function fo(t){return t instanceof he&&t.name.toLowerCase()!=="none"}function df(t){return t.name}function Fb(t){if(t instanceof he)return Tb.has(t.name);if(t instanceof ee&&t.values.length===2){let e=t.values[0],i=t.values[1];if(e instanceof he){let n=e.name;return Ab.has(n)&&(n==="fixed"&&i instanceof ht||n==="extends"&&fo(i))}}return!1}function Rb(t){let e=pt(t,"system");return e instanceof he&&e.name==="cyclic"}function Lb(t){let e=pt(t,"system");if(e instanceof he&&e.name==="fixed")return!0;if(e instanceof ee&&e.values.length===2){let[i,n]=e.values;return i instanceof he&&i.name==="fixed"&&n instanceof ht}return!1}function Ob(t){let e=pt(t,"system");return e instanceof he?1:e.values[1].num}function Bb(t){let e=pt(t,"system");return e instanceof he&&e.name==="alphabetic"}function Mb(t){let e=pt(t,"system");return e instanceof he&&e.name==="numeric"}function _b(t){let e=pt(t,"system");return e instanceof he&&e.name==="additive"}function Db(t){let e=pt(t,"system");if(e instanceof ee&&e.values.length===2){let[i,n]=e.values;return i instanceof he&&i.name==="extends"&&fo(n)}return!1}function zb(t){let e=pt(t,"system");return df(e.values[1])}function Yt(t){return t instanceof K||t instanceof he}function gi(t){return t instanceof K?t.str:t.name}function pf(t){if(Yt(t))return!0;if(t instanceof ee&&t.values.length===2){let e=t.values[0],i=t.values[1];return Yt(e)&&Yt(i)}return!1}function Vb(t){if(Yt(t))return{prefix:gi(t),suffix:null};{let e=t.values[0],i=t.values[1];return{prefix:gi(e),suffix:gi(i)}}}function Gu(t){return t instanceof ht||t instanceof he&&t.name==="infinite"}function Ns(t,e){return t instanceof ht?t.num:e?-1/0:1/0}function gl(t){if(!(t instanceof ee&&t.values.length===2))return!1;let e=t.values[0],i=t.values[1];if(!(Gu(e)&&Gu(i)))return!1;let n=Ns(e,!0),r=Ns(i,!1);return!(n>r)}function $b(t){return{lower:Ns(t.values[0],!0),upper:Ns(t.values[1],!1)}}function ff(t){return t instanceof he&&t.name==="auto"||gl(t)||t instanceof Be&&t.values.length>=1&&t.values.every(e=>gl(e))}function Hb(t){return t instanceof he?null:(gl(t)?[t]:t.values).map(e=>$b(e))}function Ts(t){if(!(t instanceof ee&&t.values.length===2))return!1;let e=t.values[0],i=t.values[1];return e instanceof ht&&e.num>=0&&Yt(i)||Yt(e)&&i instanceof ht&&i.num>=0}function Is(t){let[e,i]=t.values;return e instanceof ht?[e.num,gi(i)]:[i.num,gi(e)]}function gf(t){return Ts(t)}function Ub(t){let[e,i]=Is(t);return{minLength:e,symbol:i}}function mf(t){return Yt(t)||t instanceof ee&&t.values.length>=1&&t.values.every(e=>Yt(e))}function Wb(t){return Yt(t)?[gi(t)]:t.values.map(e=>gi(e))}function yf(t){if(Ts(t))return!0;if(t instanceof Be&&t.values.length>=1){let e=1/0;for(let i of t.values){if(!Ts(i))return!1;let[n]=Is(i);if(n>=e)return!1;e=n}return!0}return!1}function Gb(t){if(Ts(t)){let[e,i]=Is(t);return[{weight:e,symbol:i}]}else return t.values.map(e=>{let[i,n]=Is(e);return{weight:i,symbol:n}})}var jb=["auto","bullets","numbers","words","spell-out"],Xb=new Set(jb);function qb(t){return t instanceof he&&Xb.has(t.name)||fo(t)}function Yb(t,e){switch(t){case"system":return Fb(e);case"negative":return pf(e);case"prefix":case"suffix":return Yt(e);case"range":return ff(e);case"pad":return gf(e);case"fallback":return fo(e);case"symbols":return mf(e);case"additive-symbols":return yf(e);case"speak-as":return qb(e);default:return!0}}function pt(t,e){var i;let n=(i=t[e])==null?void 0:i.value;return n??null}function Zb(t,e){return e.some(({lower:i,upper:n})=>t>=i&&t<=n)}function Gn(t){let e=t.get("decimal");return e||(e=de.createDecimal(t),t.set("decimal",e)),e}var Qo,es,ts,is,ns,vr,rs,os,Ao,di,vf,Fo,wf,Ro,bf,Lo,xf,Oo,Sf,Bo,Cf,Mo,kf,wt,Ia,Pf,Ef,ju,Xu,Aa,qu,wr,Ve=class Zi{constructor(e,i){ne(this,wt),u(this,"_store"),ne(this,Qo),ne(this,es),ne(this,ts),ne(this,is),ne(this,ns),ne(this,vr),ne(this,rs),ne(this,os),this._store=e;let n=pt(i,"negative");pe(this,Qo,n&&pf(n)?Vb(n):null);let r=pt(i,"prefix");pe(this,es,r&&Yt(r)?gi(r):null);let o=pt(i,"suffix");pe(this,ts,o&&Yt(o)?gi(o):null);let s=pt(i,"range");pe(this,is,s&&ff(s)?Hb(s):null);let a=pt(i,"pad");pe(this,ns,a&&gf(a)?Ub(a):null);let h=pt(i,"fallback");pe(this,vr,h&&fo(h)?df(h):null);let l=pt(i,"symbols");pe(this,rs,l&&mf(l)?Wb(l):null);let c=pt(i,"additive-symbols");pe(this,os,c&&yf(c)?Gb(c):null)}static create(e,i){return Rb(i)?new Ui(e,i):Lb(i)?new Kb(e,i):Bb(i)?new Qb(e,i):Mb(i)?new Yu(e,i):_b(i)?new e0(e,i):Db(i)?new t0(e,i):new Jb(e,i)}static createDecimal(e){var i;return new Yu(e,le(i=Zi,di,vf).call(i))}static createDisc(e){var i;return new Ui(e,le(i=Zi,di,wf).call(i))}static createSquare(e){var i;return new Ui(e,le(i=Zi,di,bf).call(i))}static createCircle(e){var i;return new Ui(e,le(i=Zi,di,xf).call(i))}static createDisclosureOpen(e){var i;return new Ui(e,le(i=Zi,di,Sf).call(i))}static createDisclosureClosed(e){return new Ui(e,le(this,di,Cf).call(this))}static createNone(e){var i;return new Ui(e,le(i=Zi,di,kf).call(i))}static get CHINESE_LONGHAND_NAMES(){return Zu.NAMES}static createChineseLonghand(e,i){return new Zu(e,i)}static createEthiopicNumeric(e){return new n0(e)}_getNegative(){return U(this,Qo)}static _getNegativeFrom(e){return e._getNegative()}_getPrefix(){return U(this,es)}static _getPrefixFrom(e){return e._getPrefix()}_getSuffix(){return U(this,ts)}static _getSuffixFrom(e){return e._getSuffix()}static _getAutoRangeFrom(e){return e._getAutoRange()}_getRange(){return U(this,is)}static _getRangeFrom(e){return e._getRange()}_getPad(){return U(this,ns)}static _getPadFrom(e){return e._getPad()}_getFallback(){var e;return U(this,vr)!=null&&(e=this._store.get(U(this,vr)))!=null?e:null}static _getFallbackFrom(e){return e._getFallback()}_getSymbols(){return U(this,rs)}static _getSymbolsFrom(e){return e._getSymbols()}_getAdditiveSymbols(){return U(this,os)}static _getAdditiveSymbolsFrom(e){return e._getAdditiveSymbols()}static _useNegativeSignFrom(e,i){return e._usesNegativeSign(i)}static _generateInitialRepresentationFrom(e,i){return e._generateInitialRepresentation(i)}format(e){return le(this,wt,wr).call(this,e,new Set)}formatMarker(e){return le(this,wt,Pf).call(this)+this.format(e)+le(this,wt,Ef).call(this)}};Qo=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap,ns=new WeakMap,vr=new WeakMap,rs=new WeakMap,os=new WeakMap,Ao=new WeakMap,di=new WeakSet,vf=function(){var t;return(t=U(Ve,Ao))!=null?t:pe(Ve,Ao,{system:new X(_("numeric"),0),symbols:new X(new ee([new K("0"),new K("1"),new K("2"),new K("3"),new K("4"),new K("5"),new K("6"),new K("7"),new K("8"),new K("9")]),0)})},Fo=new WeakMap,wf=function(){var t;return(t=U(Ve,Fo))!=null?t:pe(Ve,Fo,{system:new X(_("cyclic"),0),symbols:new X(new K("\u2022"),0),suffix:new X(new K(" "),0)})},Ro=new WeakMap,bf=function(){var t;return(t=U(Ve,Ro))!=null?t:pe(Ve,Ro,{system:new X(_("cyclic"),0),symbols:new X(new K("\u25AA"),0),suffix:new X(new K(" "),0)})},Lo=new WeakMap,xf=function(){var t;return(t=U(Ve,Lo))!=null?t:pe(Ve,Lo,{system:new X(_("cyclic"),0),symbols:new X(new K("\u25E6"),0),suffix:new X(new K(" "),0)})},Oo=new WeakMap,Sf=function(){var t;return(t=U(Ve,Oo))!=null?t:pe(Ve,Oo,{system:new X(_("cyclic"),0),symbols:new X(new K("\u25BE"),0),suffix:new X(new K(" "),0)})},Bo=new WeakMap,Cf=function(){var t;return(t=U(Ve,Bo))!=null?t:pe(Ve,Bo,{system:new X(_("cyclic"),0),symbols:new X(new K("\u25B8"),0),suffix:new X(new K(" "),0)})},Mo=new WeakMap,kf=function(){var t;return(t=U(Ve,Mo))!=null?t:pe(Ve,Mo,{system:new X(_("cyclic"),0),symbols:new X(new K(""),0),suffix:new X(new K(""),0)})},wt=new WeakSet,Ia=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},Pf=function(){var t;return(t=this._getPrefix())!=null?t:""},Ef=function(){var t;return(t=this._getSuffix())!=null?t:". "},ju=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},Xu=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},Aa=function(){var t;return(t=this._getFallback())!=null?t:Gn(this._store)},qu=function(t,e){let{minLength:i,symbol:n}=le(this,wt,Xu).call(this);if(i===0||n==="")return t;let{prefix:r,suffix:o}=le(this,wt,Ia).call(this),s=e?Io(r)+(o?Io(o):0):0,a=i-Io(t)-s;if(a<=0)return t;let h=Io(n),l=Math.ceil(a/h);return n.repeat(l)+t},wr=function(t,e){var i,n,r;if(e.has(this))return le(i=Gn(this._store),wt,wr).call(i,t,new Set);if(e.add(this),!Zb(t,le(this,wt,ju).call(this))){let l=le(this,wt,Aa).call(this);return le(n=l,wt,wr).call(n,t,e)}let o=this._usesNegativeSign(t),s=o?Math.abs(t):t,a=this._generateInitialRepresentation(s);if(a===null){let l=le(this,wt,Aa).call(this);return le(r=l,wt,wr).call(r,t,e)}let h=le(this,wt,qu).call(this,a,o);if(o){let{prefix:l,suffix:c}=le(this,wt,Ia).call(this);h=l+h+(c??"")}return h},ne(Ve,di),ne(Ve,Ao,null),ne(Ve,Fo,null),ne(Ve,Ro,null),ne(Ve,Lo,null),ne(Ve,Oo,null),ne(Ve,Bo,null),ne(Ve,Mo,null);var de=Ve,Ui=class extends de{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0)return null;let i=e.length,n=((t-1)%i+i)%i;return e[n]}},ss,Kb=class extends de{constructor(t,e){super(t,e),ne(this,ss),pe(this,ss,Ob(e))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){var e;let i=this._getSymbols();if(!i||i.length===0)return null;let n=t-U(this,ss);return(e=i[n])!=null?e:null}};ss=new WeakMap;var Jb=class extends de{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0||t<1)return null;let i=e.length,n=e[(t-1)%i],r=Math.ceil(t/i);return n.repeat(r)}},Qb=class extends de{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2||t<1)return null;let i=e.length,n="",r=t;for(;r!==0;)r=r-1,n=e[r%i]+n,r=Math.floor(r/i);return n}},Yu=class extends de{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2)return null;let i=e.length;if(t===0)return e[0];let n="",r=t;for(;r!==0;)n=e[r%i]+n,r=Math.floor(r/i);return n}},e0=class extends de{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getAdditiveSymbols();if(!e||e.length===0)return null;let i="";if(t===0){let r=e.find(o=>o.weight===0);return r?r.symbol:null}let n=t;for(let r of e){let{weight:o,symbol:s}=r;if(o===0||o>n)continue;let a=Math.floor(n/o);if(i+=s.repeat(a),n-=o*a,n===0)return i}return null}},Ar,kt,Bt,Nf=class extends de{constructor(e,i){super(e,i),ne(this,kt),ne(this,Ar);let n=zb(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?pe(this,Ar,r):pe(this,Ar,n)}_getNegative(){var e;return(e=super._getNegative())!=null?e:de._getNegativeFrom(le(this,kt,Bt).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:de._getPrefixFrom(le(this,kt,Bt).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:de._getSuffixFrom(le(this,kt,Bt).call(this))}_getAutoRange(){return de._getAutoRangeFrom(le(this,kt,Bt).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:de._getRangeFrom(le(this,kt,Bt).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:de._getPadFrom(le(this,kt,Bt).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:de._getFallbackFrom(le(this,kt,Bt).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:de._getSymbolsFrom(le(this,kt,Bt).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:de._getAdditiveSymbolsFrom(le(this,kt,Bt).call(this))}_usesNegativeSign(e){return de._useNegativeSignFrom(le(this,kt,Bt).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:de._generateInitialRepresentationFrom(le(this,kt,Bt).call(this),e)}};Ar=new WeakMap,kt=new WeakSet,Bt=function(t=new Set){var e;if(t.has(this))return Gn(this._store);t.add(this);let i=this._store.get(U(this,Ar));return i?i instanceof Nf?le(e=i,kt,Bt).call(e,t):i:Gn(this._store)};var t0=Nf,i0=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"];function lr(t){return{suffix:new X(new K("\u3001"),0),fallback:new X(_("cjk-decimal"),0),range:new X(new ee([new ht(-9999),new ht(9999)]),0),negative:new X(new K(t),0)}}var Fa,Ra,_o,La,Do,ml,Tf,as,vt=class If extends de{constructor(e,i){var n;let{chars:r,descriptors:o}=le(n=If,ml,Tf).call(n).get(i);super(e,o),ne(this,as),pe(this,as,r)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let i=U(this,as);if(e===0)return i.digits[0];let n=[],r=0,o=e;for(;o>0;)n.unshift({digit:o%10,position:r}),o=Math.floor(o/10),r++;let s=i.informal&&e>=10&&e<=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),s&&d===1?a+=i.markers[d]:(a+=i.digits[c],d>0&&(a+=i.markers[d])))}return a}};Fa=new WeakMap,Ra=new WeakMap,_o=new WeakMap,La=new WeakMap,Do=new WeakMap,ml=new WeakSet,Tf=function(){var t;return(t=U(vt,Do))!=null?t:pe(vt,Do,new Map([["simp-chinese-informal",{chars:U(vt,Fa),descriptors:lr("\u8D1F")}],["simp-chinese-formal",{chars:U(vt,Ra),descriptors:lr("\u8D1F")}],["trad-chinese-informal",{chars:U(vt,_o),descriptors:lr("\u8CA0")}],["trad-chinese-formal",{chars:U(vt,La),descriptors:lr("\u8CA0")}],["cjk-ideographic",{chars:U(vt,_o),descriptors:lr("\u8CA0")}]]))},as=new WeakMap,ne(vt,ml),ne(vt,Fa,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ne(vt,Ra,{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),ne(vt,_o,{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0}),ne(vt,La,{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1}),u(vt,"NAMES",new Set(i0)),ne(vt,Do,null);var Zu=vt,zo,yl,Af,vl,As,wl,bl,ui=class Ki extends de{constructor(e){var i;super(e,le(i=Ki,yl,Af).call(i))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){if(e<1)return null;if(e===1)return U(Ki,As)[1];let i=[],n=e;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,o="";for(let s=r-1;s>=0;s--){let a=i[s],h=s%2===1,l=s===r-1;if(!(a===0||l&&a===1||h&&a===1)){let c=Math.floor(a/10),d=a%10;o+=U(Ki,vl)[c]+U(Ki,As)[d]}h?a!==0&&(o+=U(Ki,wl)):s!==0&&(o+=U(Ki,bl))}return o}};zo=new WeakMap,yl=new WeakSet,Af=function(){var t;return(t=U(ui,zo))!=null?t:pe(ui,zo,{range:new X(new ee([new ht(1),_("infinite")]),0),suffix:new X(new K("/ "),0)})},vl=new WeakMap,As=new WeakMap,wl=new WeakMap,bl=new WeakMap,ne(ui,yl),ne(ui,zo,null),ne(ui,vl,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ne(ui,As,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ne(ui,wl,"\u137B"),ne(ui,bl,"\u137C");var n0=ui,Le,br,r0=class{constructor(){ne(this,Le),ne(this,br,new Map),pe(this,Le,new Map),U(this,Le).set("none",de.createNone(U(this,Le))),U(this,Le).set("decimal",de.createDecimal(U(this,Le))),U(this,Le).set("disc",de.createDisc(U(this,Le))),U(this,Le).set("square",de.createSquare(U(this,Le))),U(this,Le).set("circle",de.createCircle(U(this,Le))),U(this,Le).set("disclosure-open",de.createDisclosureOpen(U(this,Le))),U(this,Le).set("disclosure-closed",de.createDisclosureClosed(U(this,Le)));for(let t of de.CHINESE_LONGHAND_NAMES)U(this,Le).set(t,de.createChineseLonghand(U(this,Le),t));U(this,Le).set("ethiopic-numeric",de.createEthiopicNumeric(U(this,Le)))}define(t,e,i){if(!Eb(t))return null;let n=de.create(U(this,Le),e),r=i&&U(this,br).get(t);return r&&Vi(i,r)<0||(i?U(this,br).set(t,i):U(this,br).delete(t),U(this,Le).set(t,n)),n}getStyle(t){var e;return(e=U(this,Le).get(t))!=null?e:null}format(t,e){var i;return((i=this.getStyle(t))!=null?i:Gn(U(this,Le))).format(e)}formatMarker(t,e){var i;return((i=this.getStyle(t))!=null?i:Gn(U(this,Le))).formatMarker(e)}};Le=new WeakMap,br=new WeakMap;var Bn=class{constructor(t){u(this,"validator",t),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(t){this.code=2*t+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(t){this.code=2*t+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Wi=class{constructor(t,e){u(this,"where",t),u(this,"success",e),u(this,"what",-1)}},hr=class Ff{constructor(){u(this,"nodes",[]),u(this,"connections",[]),u(this,"match",[]),u(this,"nomatch",[]),u(this,"error",[]),u(this,"emptyHead",!0)}connect(e,i){for(let n=0;n<e.length;n++)this.connections[e[n]].what=i;e.splice(0,e.length)}clone(){let e=new Ff;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Bn(n.validator);r.code=n.code,e.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new Wi(n.where,n.success);r.what=n.what,e.connections.push(r)}return e.match.push(...this.match),e.nomatch.push(...this.nomatch),e.error.push(...this.error),e}addSpecialToArr(e,i,n){let r=this.nodes.length,o=new Bn(Ku);n>=0?i?o.markAsStartAlternate(n):o.markAsEndAlternate(n):i?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(e,r);let s=new Wi(r,!0),a=new Wi(r,!1);e.push(this.connections.length),this.connections.push(a),e.push(this.connections.length),this.connections.push(s)}endSpecialGroup(){let e=[this.match,this.nomatch,this.error];for(let i=0;i<e.length;i++)this.addSpecialToArr(e[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(e){this.addSpecialToArr(this.match,!1,e)}startClause(e){if(this.nodes.length)throw new Error("invalid call");let i=new Bn(Ku);i.markAsStartAlternate(e),this.nodes.push(i);let n=new Wi(0,!0),r=new Wi(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(e){let i=this.nodes.length;this.nodes.push(new Bn(e));let n=new Wi(i,!0),r=new Wi(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 ce}addGroup(e,i){if(e.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&e.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(e.nodes[0].validator);return}for(let o=0;o<e.nodes.length;o++)this.nodes.push(e.nodes[o]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let o=0;o<e.connections.length;o++){let s=e.connections[o];s.where+=n,s.what>=0&&(s.what+=n),this.connections.push(s)}for(let o=0;o<e.match.length;o++)this.match.push(e.match[o]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let o=0;o<e.nomatch.length;o++)this.match.push(e.nomatch[o]+r);else if(this.emptyHead){for(let o=0;o<e.nomatch.length;o++)this.nomatch.push(e.nomatch[o]+r);this.emptyHead=e.emptyHead}else for(let o=0;o<e.nomatch.length;o++)this.error.push(e.nomatch[o]+r);for(let o=0;o<e.error.length;o++)this.error.push(e.error[o]+r);e.nodes=null,e.connections=null}finish(e,i){let n=this.nodes.length;this.nodes.push(e),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]}},o0=1,Fs=2,Rf=4,ki=8,on=16,jn=32,Vn=64,Rs=128,oi=256,si=512,Ls=1024,Lf=2048,Of=4096,Os=8192,xh=class extends Zt{constructor(){super()}validateForShorthand(t,e){let i=t[e].visit(this);return i?[i]:null}},ce=class Bf extends xh{constructor(e,i,n){super(),u(this,"allowed",e),u(this,"idents",i),u(this,"units",n)}visitEmpty(e){return this.allowed&o0?e:null}visitSlash(e){return this.allowed&Lf?e:null}visitStr(e){return this.allowed&Fs?e:null}visitIdent(e){return this.idents[e.name.toLowerCase()]||(this.allowed&Rf||this.allowed&Vn&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&si)?e.unit=="%"&&this.allowed&Ls?e:null:e.num<0&&!(this.allowed&oi)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&si?e:null:e.num<=0&&!(this.allowed&oi)?null:this.allowed&on?e:null}visitInt(e){return e.num==0?this.allowed&si?e:null:e.num<=0&&!(this.allowed&oi)?null:this.allowed&(jn|on)?e:this.idents[`${e.num}`]||null}visitHexColor(e){return this.allowed&Vn&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&Rs?e:null}visitURange(e){return this.allowed&Of?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){if(e.name.toLowerCase()==="attr"){let i=Ph(e);if(i&&u0(i.type,this.allowed,this.units))return e}if(this.allowed&Vn){if(e.name==="device-cmyk"||e.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&_d(e)!==null?e:null;if(CSS.supports("color",e.toString()))return e}if(this.allowed&Os){let i=e.visit(new Vd);if(CSS.supports("background-image",i.toString()))return e}return e.name==="calc"&&this.allowed&(ki|on|jn|oi|si|Ls)?e:null}visitExpr(e){return this.allowed&2046?e:null}combine(e){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in e.idents)i[r]=e.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in e.units)n[r]=e.units[r];return new Bf(this.allowed|e.allowed,i,n)}},ie=Object.create(null),s0=on|oi|si,a0=jn|oi|si,Gi=ki|oi|si|Ls;function go(t){let e=Object.create(null);for(let i of t)e[i]=Ae;return e}var oa=go(["%"]),sa=go(["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"]),Mf={...sa,...oa},Sh=go(["deg","grad","rad","turn"]),Ch=go(["s","ms"]),kh=go(["hz","khz"]);function l0(t){return t.replace(/\s+/g,"").toLowerCase()}function aa(t){return t.toLowerCase()}function h0(t){if(t instanceof he)switch(t.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:`<${t.name.toLowerCase()}>`};default:return{kind:"unit",unit:aa(t.name)}}if(t instanceof Vt&&t.name.toLowerCase()==="type"){if(t.values.length!==1)return null;let e=l0(t.values[0].stringValue());return e?{kind:"syntax",syntax:e}:null}return null}function Ph(t){var e;if(t.name.toLowerCase()!=="attr"||t.values.length<1||t.values.length>2)return null;let i,n={kind:"string"},r=t.values[0];if(r instanceof he)i=r.name;else if(r instanceof ee){let o=r.values;if(o.length<1||o.length>2||!(o[0]instanceof he)||(i=o[0].name,o.length===2&&(n=h0(o[1]),!n)))return null}else return null;return{attributeName:i,type:n,fallback:(e=t.values[1])!=null?e:null}}function _f(t,e){return!!t[aa(e)]}function vn(t,e){return Object.keys(e).some(i=>_f(t,i))}function u0(t,e,i){switch(t.kind){case"string":return!!(e&Fs);case"url":return!!(e&(Rs|Os));case"unit":return _f(i,t.unit);case"syntax":switch(t.syntax){case"<string>":return!!(e&Fs);case"<url>":return!!(e&(Rs|Os));case"<color>":return!!(e&Vn);case"<integer>":return!!(e&(jn|on|oi|si));case"<number>":return!!(e&(on|jn|oi|si));case"<length>":return vn(i,sa);case"<length-percentage>":return vn(i,Mf);case"<percentage>":return vn(i,oa);case"<angle>":return vn(i,Sh);case"<time>":return vn(i,Ch);case"<frequency>":return vn(i,kh);default:return!1}}return!1}function xl(t){switch(t.kind){case"string":return null;case"url":return null;case"unit":return new ce(Gi,ie,{[aa(t.unit)]:Ae});case"syntax":switch(t.syntax){case"<color>":return new ce(Vn,ie,ie);case"<integer>":return new ce(a0,ie,ie);case"<number>":return new ce(s0,ie,ie);case"<length>":return new ce(Gi,ie,sa);case"<length-percentage>":return new ce(Gi,ie,Mf);case"<percentage>":return new ce(Gi,ie,oa);case"<angle>":return new ce(Gi,ie,Sh);case"<time>":return new ce(Gi,ie,Ch);case"<frequency>":return new ce(Gi,ie,kh);default:return null}}return null}function c0(t){switch(t.kind){case"string":case"url":case"unit":return!0;case"syntax":return t.syntax==="<string>"||t.syntax==="<url>"||!!xl(t)}return!1}function d0(t){switch(t.kind){case"url":return new et("about:invalid");case"string":return new K("");default:return w.unset}}function p0(t,e,i){if(e==null)return null;switch(i.kind){case"string":return new K(e);case"url":return e?new et(e):new et("about:invalid");case"unit":{let n=Mi(t,new xt(`${e.trim()}${aa(i.unit)}`,null),""),r=xl(i);return n&&r?n.visit(r):null}case"syntax":{if(i.syntax==="<string>")return new K(e);if(i.syntax==="<url>")return e?new et(e):new et("about:invalid");let n=Mi(t,new xt(e,null),""),r=xl(i);return n&&r?n.visit(r):null}}return null}var Ku=new ce(0,ie,ie),Eh=class extends xh{constructor(t){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new Bn(null),this.failureTerminal=new Bn(null),this.first=t.finish(this.successTerminal,this.failureTerminal)}validateList(t,e,i){let n=e?[]:t,r=this.first,o=i,s=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(o>=t.length){r=r.failure;continue}let h=t[o],l=h;if(r.isSpecial()){let c=!0;r.isStartGroup()?(s?s.push(a):s=[a],a=[]):r.isEndGroup()?s.length>0?a=s.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":c=a[r.getAlternate()]==null,r=c?r.success:r.failure}else{if(o==0&&!e&&r.validator instanceof Fr&&this instanceof Fr){if(l=new ee(t).visit(r.validator),l){o=t.length,r=r.success;continue}}else if(o==0&&!e&&r.validator instanceof Nh&&this instanceof Fr){if(l=new Be(t).visit(r.validator),l){o=t.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&t===n){n=[];for(let c=0;c<o;c++)n[c]=t[c]}t!==n&&(n[o-i]=l),o++,r=r.success}}return r===this.successTerminal&&(e?n.length>0:o==t.length)?n:null}validateSingle(t){let e=this.validateList([t],!1,0);return e?e[0]:null}visitEmpty(t){return this.validateSingle(t)}visitSlash(t){return this.validateSingle(t)}visitStr(t){return this.validateSingle(t)}visitIdent(t){return this.validateSingle(t)}visitNumeric(t){return this.validateSingle(t)}visitNum(t){return this.validateSingle(t)}visitInt(t){return this.validateSingle(t)}visitHexColor(t){return this.validateSingle(t)}visitURL(t){return this.validateSingle(t)}visitURange(t){return this.validateSingle(t)}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.validateSingle(t)}visitExpr(t){return null}},Fr=class extends Eh{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new ee(e):null}visitCommaList(t){let e=this.first,i=!1;for(;e;){if(e.validator instanceof Nh){i=!0;break}e=e.failure}if(i){let n=this.validateList(t.values,!1,0);return n===t.values?t:n?new Be(n):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},Nh=class extends Eh{constructor(t){super(t)}visitSpaceList(t){return this.validateSingle(t)}visitCommaList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new Be(e):null}validateForShorthand(t,e){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(t,e),n)return n;i=i.failure}return null}},f0=class extends Eh{constructor(t,e){super(e),u(this,"name",t)}validateSingle(t){return null}visitFunc(t){if(t.name.toLowerCase()!=this.name)return null;let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new Vt(t.name,e):null}},Ju=class extends xh{validateSingle(t){return null}visitFunc(t){let e=Ph(t);return e&&c0(e.type)?t:null}},Df=class{tryParse(t,e,i){return e}success(t,e){}},zf=class extends Df{constructor(t,e){super(),u(this,"name",e),u(this,"validator"),this.validator=t.validators[this.name]}tryParse(t,e,i){if(i.values[this.name])return e;let n=this.validator.validateForShorthand(t,e);if(n){let r=n.length,o=r>1?new ee(n):n[0];return this.success(o,i),e+r}return e}success(t,e){e.values[this.name]=t}},g0=class extends zf{constructor(t,e){super(t,e[0]),u(this,"names",e)}success(t,e){for(let i=0;i<this.names.length;i++)e.values[this.names[i]]=t}},m0=class extends Df{constructor(t,e){super(),u(this,"nodes",t),u(this,"slash",e)}tryParse(t,e,i){let n=e;if(this.slash)if(t[e]==Kn){if(++e==t.length)return n}else return n;let r=this.nodes[0].tryParse(t,e,i);if(r==e)return n;e=r;for(let o=1;o<this.nodes.length&&e<t.length&&(r=this.nodes[o].tryParse(t,e,i),r!=e);o++)e=r;return e}},la=class extends Zt{constructor(t,e,i){super(),u(this,"validatorSet",t),u(this,"syntax",e),u(this,"propList",i),u(this,"error",!1),u(this,"values",{})}static create(t,e,i){return new this(t,e,i)}clone(t){return new this.constructor(this.validatorSet,this.syntax,this.propList)}finish(t,e){var i,n;if(!this.error){for(let r of this.propList)e.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:w.initial,t);return!0}return!1}propagateDefaultingValue(t,e,i){for(let n of this.propList)i.simpleProperty(n,t,e)}validateList(t){return this.error=!0,0}validateSingle(t){return this.validateList([t]),null}visitEmpty(t){return this.validateSingle(t)}visitStr(t){return this.validateSingle(t)}visitIdent(t){return this.validateSingle(t)}visitNumeric(t){return this.validateSingle(t)}visitNum(t){return this.validateSingle(t)}visitInt(t){return this.validateSingle(t)}visitHexColor(t){return this.validateSingle(t)}visitURL(t){return this.validateSingle(t)}visitSpaceList(t){return this.validateList(t.values),null}visitCommaList(t){return this.error=!0,null}visitFunc(t){return this.validateSingle(t)}visitExpr(t){return this.validateSingle(t)}},Qn=class extends la{validateList(t){let e=0,i=0;for(;e<t.length;){let n=this.syntax[i].tryParse(t,e,this);if(n>e){e=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return e}},Vf=class extends la{validateList(t){if(t.length>this.syntax.length||t.length==0)return this.error=!0,0;for(let e=0;e<this.syntax.length;e++){let i=e;for(;i>=t.length;)i=i==1?0:i-2;if(this.syntax[e].tryParse(t,i,this)!=i+1)return this.error=!0,0}return t.length}createSyntaxNode(){return new g0(this.validatorSet,this.propList)}},y0=class extends la{validateList(t){let e=t.length;for(let i=0;i<t.length;i++)if(t[i]===Kn){e=i;break}if(e>this.syntax.length||t.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=e;)n=n==1?0:n-2;let r;if(e+1<t.length)for(r=e+i+1;r>=t.length;)r=r-(r==e+2?1:2);else r=n;let o=[t[n],t[r]];if(this.syntax[i].tryParse(o,0,this)!=2)return this.error=!0,0}return t.length}},v0=class extends Qn{mergeIn(t,e){var i,n;for(let r of this.propList){let o=(n=(i=e[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:w.initial,s=t[r];s||(s=[],t[r]=s),s.push(o)}}visitCommaList(t){let e={};for(let i=0;i<t.values.length;i++)if(this.values={},t.values[i]instanceof Be?this.error=!0:(t.values[i].visit(this),this.mergeIn(e,this.values),this.values["background-color"]&&i!=t.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in e)i=="background-color"?this.values[i]=e[i].pop():this.values[i]=new Be(e[i]);return null}},w0=class $f extends Qn{static create(e,i,n){return new $f(e,i,[...n,"font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian"])}validateList(e){let i=super.validateList(e),n=this.values["font-variant_css2"];n&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=n);let r=this.values["font-stretch_css3"];if(r&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=r),i+2>e.length)return this.error=!0,i;this.error=!1;let o=this.validatorSet.validators;if(!e[i].visit(o["font-size"])){let a=this.values["font-weight"],h=a instanceof Vt&&a.name==="calc"?e.indexOf(a):-1;if(h>=0&&e[h].visit(o["font-size"]))delete this.values["font-weight"],i=h;else return this.error=!0,i}if(this.values["font-size"]=e[i++],e[i]===Kn){if(i++,i+2>e.length)return this.error=!0,i;if(!e[i].visit(o["line-height"]))return this.error=!0,i;this.values["line-height"]=e[i++]}let s=i==e.length-1?e[i]:new ee(e.slice(i,e.length));return s.visit(o["font-family"])?(this.values["font-family"]=s,e.length):(this.error=!0,i)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let i=[this.values["font-family"]];for(let r=1;r<e.values.length;r++)i.push(e.values[r]);let n=new Be(i);return n.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=n:this.error=!0,null}visitIdent(e){let i=this.validatorSet.systemFonts[e.name];if(i)for(let n in i)this.values[n]=i[n];else this.error=!0;return null}},b0=class extends Qn{validateList(t){if(t.length===1&&t[0]instanceof he)switch(t[0].name.toLowerCase()){case"normal":t=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":t=[w.auto,w.auto];break;case"none":t=[_("no-autospace"),_("space-all")];break}return super.validateList(t)}},Hf=class extends la{constructor(t,e,i=[]){super(t,[],i),u(this,"name",e)}clone(t){return new x0(this.validatorSet,this.name,[...this.propList],t)}},x0=class extends Hf{constructor(t,e,i,n){super(t,e,i),u(this,"scope",n)}validateValueText(t){let e=this.validatorSet.expandBrowserShorthand(this.name,t);if(!e)return this.error=!0,!1;this.propList=e.propList,this.values={};for(let i of e.propList){let n=e.values[i];if(!n)continue;let r=Mi(this.scope,new xt(n,null),"");if(!r)return this.error=!0,!1;this.values[i]=r}return this.error=!1,!0}validateList(t){let e=t.length===1?t[0].toString():new ee(t).toString();return this.validateValueText(e)?t.length:0}visitCommaList(t){return this.validateValueText(t.toString()),null}},Qu=["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"],Uf=class extends Qn{refreshPropList(){this.propList=this.validatorSet.getPropertiesForAll()}validateList(t){return this.error=!0,0}},ec={SIMPLE:Qn,INSETS:Vf,INSETS_SLASH:y0,COMMA:v0,FONT:w0,TEXT_SPACING:b0,ALL:Uf},S0=["initial-letter"],C0=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,"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 t=document.documentElement;if(!t)return null;let e=getComputedStyle(t),i=[];for(let n=0;n<e.length;n++){let r=e.item(n);!r||ze(r)||Qu.includes(r)||i.push(r)}return this.browserPropertyNamesForAll=i,this.browserPropertyNamesForAll}getPropertiesForAll(){if(this.allPropertyNames)return this.allPropertyNames;let t=new Set;for(let n in this.validators)Qu.includes(n)||t.add(n);let e=this.getBrowserPropertyNamesForAll();if(e)for(let n of e)this.shorthands[n]||t.add(n);let i=Array.from(t);return e&&(this.allPropertyNames=i),i}getBrowserShorthandStyle(){return this.browserShorthandStyle!==null?this.browserShorthandStyle:typeof document>"u"?null:(this.browserShorthandStyle=document.createElement("div").style,this.browserShorthandStyle)}expandBrowserShorthand(t,e){let i=this.getBrowserShorthandStyle();if(!i)return null;i.cssText="",i.setProperty(t,e);let n=Array.from({length:i.length},(o,s)=>i.item(s)).filter(o=>!!o);if(!n.length||n.length===1&&n[0]===t.toLowerCase())return null;let r={};for(let o of n)r[o]=i.getPropertyValue(o);return{propList:n,values:r}}getShorthand(t,e){if(ze(t))return null;t=t.toLowerCase();let i=this.shorthands[t];if(i)return i instanceof Uf&&!this.allPropertyNames&&i.refreshPropList(),i;if(this.validators[t]||this.browserShorthandMisses[t]||e==null)return null;let n=this.expandBrowserShorthand(t,typeof e=="string"?e:e.toString());if(!n)return(typeof e=="string"?!/\bvar\(/i.test(e):!Sl(e))&&(this.browserShorthandMisses[t]=!0),null;let r=new Hf(this,t,n.propList);return this.shorthands[t]=r,this.invalidateAllPropertyNames(),r}addReplacement(t,e){let i;if(e.type==3)i=new B(e.num,e.text);else if(e.type==7)i=new Fd(e.text);else if(e.type==1)i=_(e.text);else throw new Error("unexpected replacement");if(t.isPrimitive()){let n=t.nodes[0].validator.idents;for(let r in n)n[r]=i;return t}throw new Error("unexpected replacement")}newGroup(t,e){let i=new hr;if(t=="||"){for(let r=0;r<e.length;r++){let o=new hr;o.startClause(r),o.addGroup(e[r],1),o.endClause(r),i.addGroup(o,r==0?1:4)}let n=new hr;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(t){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<e.length;r++)i.addGroup(e[r],r==0?1:n);return i}}addCounts(t,e,i){let n=new hr;for(let r=0;r<e;r++)n.addGroup(t.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(t,3);else for(let r=e;r<i;r++)n.addGroup(t.clone(),2);return n}primitive(t){let e=new hr;return e.addPrimitive(t),e}newFunc(t,e){let i;switch(t){case"COMMA":i=new Nh(e);break;case"SPACE":i=new Fr(e);break;case"attr":i=new Ju;break;default:i=new f0(t.toLowerCase(),e);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ce(Vn,ie,ie)),this.namedValidators.ATTR=this.primitive(new Ju),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ce(Os,ie,ie)),this.namedValidators.POS_INT=this.primitive(new ce(jn,ie,ie)),this.namedValidators.POS_NUM=this.primitive(new ce(on,ie,ie)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ce(ki,ie,oa)),this.namedValidators.NEGATIVE=this.primitive(new ce(oi,ie,ie)),this.namedValidators.ZERO=this.primitive(new ce(si,ie,ie)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ce(Ls,ie,ie)),this.namedValidators.POS_LENGTH=this.primitive(new ce(ki,ie,sa)),this.namedValidators.POS_ANGLE=this.primitive(new ce(ki,ie,Sh)),this.namedValidators.POS_TIME=this.primitive(new ce(ki,ie,Ch)),this.namedValidators.FREQUENCY=this.primitive(new ce(ki,ie,kh)),this.namedValidators.RESOLUTION=this.primitive(new ce(ki,ie,{dpi:Ae,dpcm:Ae,dppx:Ae})),this.namedValidators.URI=this.primitive(new ce(Rs,ie,ie)),this.namedValidators.URANGE=this.primitive(new ce(Of,ie,ie)),this.namedValidators.IDENT=this.primitive(new ce(Rf,ie,ie)),this.namedValidators.STRING=this.primitive(new ce(Fs,ie,ie)),this.namedValidators.SLASH=this.primitive(new ce(Lf,ie,ie));let t={"font-family":_("sans-serif")};this.systemFonts.caption=t,this.systemFonts.icon=t,this.systemFonts.menu=t,this.systemFonts["message-box"]=t,this.systemFonts["small-caption"]=t,this.systemFonts["status-bar"]=t}isBuiltIn(t){return!!t.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(t,e){let i=t.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(t.consume(),i=t.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,t.consume(),i=t.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");t.consume(),i=t.token()}if(i.type!=1)throw new Error("Property name expected");if(e==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return t.consume(),null;let r=i.text;if(t.consume(),e!=2){if(t.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(t.token().type!=18)throw new Error("':' expected");return r}parseValidators(t){for(;;){let e=this.readNameAndPrefixes(t,1);if(!e)return;let i=[],n=[],r="",o,s=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},h=c=>{if(s)throw new Error(`'${c}': unexpected`);if(r&&r!=c)throw new Error(`mixed operators: '${c}' and '${r}'`);r=c,s=!0},l=null;for(;!l;){t.consume();let c=t.token();switch(c.type){case 1:if(s||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()]=_(c.text),i.push(this.primitive(new ce(0,d,ie)))}s=!1;break;case 5:{let d={};d[`${c.num}`]=new ht(c.num),i.push(this.primitive(new ce(0,d,ie))),s=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:s||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],s=!0;break;case 6:s||h(" "),n.push({vals:i,op:r,b:"(",fn:c.text}),r="",i=[],s=!0;break;case 15:{o=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(o),r=d.op,s=!1;break}case 11:{o=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,o)),r=d.op,s=!1;break}case 18:if(s)throw new Error("':' unexpected");t.consume(),i.push(this.addReplacement(i.pop(),t.token()));break;case 22:if(s)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(s)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(s)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(t.consume(),c=t.token(),c.type!=5)throw new Error("<int> expected");let d=c.num,p=d;if(t.consume(),c=t.token(),c.type==16){if(t.consume(),c=t.token(),c.type!=5)throw new Error("<int> expected");p=c.num,t.consume(),c=t.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")}}t.consume(),this.isBuiltIn(e)?this.namedValidators[e]=l:l.isSimple()?this.validators[e]=l.nodes[0].validator:this.validators[e]=new Fr(l)}}parseDefaults(t){for(;;){let e=this.readNameAndPrefixes(t,2);if(!e)return;let i=[];for(;;){t.consume();let n=t.token();if(n.type==17){t.consume();break}switch(n.type){case 1:i.push(_(n.text));break;case 4:i.push(new It(n.num));break;case 5:i.push(new ht(n.num));break;case 3:i.push(new B(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[e]=i.length>1?new ee(i):i[0]}}parseShorthands(t){for(;;){let e=this.readNameAndPrefixes(t,3);if(!e)return;let i=t.nthToken(1),n;i.type==1&&ec[i.text]?(n=ec[i.text],t.consume()):n=Qn;let r=!1,o=[],s=!1,a=[],h=[];for(;!r;)switch(t.consume(),i=t.token(),i.type){case 1:if(this.validators[i.text])o.push(new zf(this,i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Vf){let c=this.shorthands[i.text];o.push(c.createSyntaxNode()),h.push(...c.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||s)throw new Error("unexpected slash");s=!0;break;case 14:a.push({slash:s,syntax:o}),o=[],s=!1;break;case 15:{let c=new m0(o,s),d=a.pop();o=d.syntax,s=d.slash,o.push(c);break}case 17:r=!0,t.consume();break;default:throw new Error("unexpected token")}let l=n.create(this,o,h);this.shorthands[e]=l,this.invalidateAllPropertyNames()}}parse(t){let e=new xt(t,null);this.parseValidators(e),this.parseDefaults(e),this.parseShorthands(e),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(t){var e;let i={};for(let n of t){let r=this.shorthands[n],o=r?r.propList:[n];for(let s of o)i[s]=(e=this.defaultValues[s])!=null?e:w.initial}return i}validatePropertyAndHandleShorthand(t,e,i,n,r){var o,s;let a=r.ruleType;if(ze(t)||a==="font-face"){r.simpleProperty(t,e,i);return}if(a==="counter-style"){Yb(t,e)?r.simpleProperty(t,e,i):r.invalidPropertyValue(t,e);return}let h="",l=t;t=t.toLowerCase();let c=t.match(/^-([a-z]+)-([-a-z0-9]+)$/);c&&(h=c[1],t=c[2]);let d=h?l:t;if(Sl(e)){this.getShorthand(d,e),r.simpleProperty(d,e,i);return}let p=this.prefixes[t],f=Rt(e)?"unset":e.toString();if(!p||!p[h]){if(CSS.supports(l,f)){let m=(o=this.getShorthand(d,f))==null?void 0:o.clone(n);m?Z(e)?m.propagateDefaultingValue(e,i,r):(e.visit(m),m.finish(i,r)||r.invalidPropertyValue(l,e)):r.simpleProperty(l,e,i)}else h&&!sd.includes(`-${h}-`)||r.unknownProperty(l,e);return}else if(S0.includes(t)&&!Object.keys(p).some(m=>Xo(m?`-${m}-`:"",t))){r.unknownProperty(l,e);return}let g=this.validators[t];if(g){let m=Z(e)||e.isExpr()?e:e.visit(g);m?r.simpleProperty(t,m,i):!h&&CSS.supports(t,e.toString())?r.simpleProperty(t,e,i):r.invalidPropertyValue(l,e)}else{let m=(s=this.getShorthand(t,e))==null?void 0:s.clone(n);if(!m){r.unknownProperty(l,e);return}Z(e)?m.propagateDefaultingValue(e,i,r):(e.visit(m),m.finish(i,r)||r.invalidPropertyValue(l,e))}}};function k0(){let t=new C0;return t.initBuiltInValidators(),t.parse(hp),t}var P0=class extends Zt{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(t){return t.name==="var"?this.varFound=!0:this.varFound||this.visitValues(t.values),null}};function Sl(t){let e=new P0;return t.visit(e),e.varFound}function Wf(t,e,i){return t-=i,e===0?t===0:t%e===0&&t/e>=0}var E0=class{constructor(t){u(this,"matchers",t)}matches(){return this.matchers.some(t=>t.matches())}},N0=class{constructor(t){u(this,"matchers",t)}matches(){return this.matchers.every(t=>t.matches())}},Gf=class ls{constructor(e,i,n){u(this,"elementOffset",e),u(this,"a",i),u(this,"b",n)}static registerFragmentIndex(e,i,n){let r=ls.fragmentIndices;(!r[e]||r[e].priority<=n)&&(r[e]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){ls.fragmentIndices={}}matches(){let e=ls.fragmentIndices[this.elementOffset];return e!=null&&e.fragmentIndex!=null&&Wf(e.fragmentIndex,this.a,this.b)}};u(Gf,"fragmentIndices",{});var ha=Gf,Vo=class{static buildViewConditionMatcher(t,e){let i=e.split("_");return i[0]=="NFS"?new ha(t,parseInt(i[1],10),parseInt(i[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new N0(t)}static buildAnyMatcher(t){return new E0(t)}},jf={"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},T0=["image-resolution","orphans","widows"];function I0(){return zt("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(T0))}var A0={"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},Cl=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],F0=["max-%","min-%","%"],tc=(()=>{let t=["left","right","top","bottom"],e={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<Cl.length;i++)for(let n=0;n<t.length;n++){let r=Cl[i].replace("%",t[n]);e[r]=!0}return e})();function er(t,e){let i={};for(let n of Cl)for(let r in t){let o=n.replace("%",r),s=n.replace("%",t[r]);i[o]=s,i[s]=o}for(let n of F0)for(let r in e){let o=n.replace("%",r),s=n.replace("%",e[r]);i[o]=s,i[s]=o}return i}var Xf=er({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),qf=er({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),R0=er({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),L0=er({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),O0=er({inside:"right",outside:"left"},{}),B0=er({inside:"left",outside:"right"},{}),Oa=class{constructor(t,e){u(this,"name",t),u(this,"parent",e),u(this,"order",0),u(this,"children",[])}},M0=class{constructor(){u(this,"root",new Oa(null,null))}register(t,e){let i=t??this.root;if(e)for(let n of e){let r=i.children.find(o=>o.name===n);r||(r=new Oa(n,i),i.children.push(r)),i=r}else{let n=new Oa(null,i);i.children.push(n),i=n}return this.renumber(),i}renumber(){let t=0,e=i=>{for(let n of i.children)e(n);i.order=t++};for(let i of this.root.children)e(i)}},Bs=16777216,_0=4,D0=0;function mo(){return++D0}function ic(t){switch(Math.floor(t.priority/Bs)){case 0:return 0;case 1:case 6:return 1;default:return 2}}function nc(t){switch(Math.floor(t.priority/Bs)){case 0:return 0;case 1:case 6:return 1;case 3:case 4:return 3;default:return 2}}function Ms(t){return t.layer?t.layer.order:1/0}function Vi(t,e){let i=Math.floor(t.priority/Bs),n=Math.floor(e.priority/Bs);if(i!==n)return i-n;if(t.layer!==e.layer){let r=Ms(t),o=Ms(e);if(r!==o){let s=r>o?1:-1;return i>=_0?-s:s}}return t.priority-e.priority}var X=class kl{constructor(e,i,n=null,r=0){u(this,"value",e),u(this,"priority",i),u(this,"layer",n),u(this,"ruleId",r)}getBaseValue(){return this}withValue(e){return e===this.value?this:new kl(e,this.priority,this.layer,this.ruleId)}filterValue(e){return this.withValue(this.value.visit(e))}increaseSpecificity(e){return e==0?this:new kl(this.value,this.priority+e,this.layer,this.ruleId)}evaluate(e,i,n,r){return i&&ze(i)?this.value:Hs(e,this.value,i,n,r)}isEnabled(e){return!0}},Pl=class El extends X{constructor(e,i,n,r=null,o=0){super(e,i,r,o),u(this,"condition",n)}getBaseValue(){return new X(this.value,this.priority,this.layer,this.ruleId)}withValue(e){return e===this.value?this:new El(e,this.priority,this.condition,this.layer,this.ruleId)}increaseSpecificity(e){return e==0?this:new El(this.value,this.priority+e,this.condition,this.layer,this.ruleId)}isEnabled(e){try{return!!this.condition.evaluate(e)}catch(i){Y.warn(i)}return!1}};function Nl(t,e,i){return(!e||Vi(i,e)>=0)&&i.isEnabled(t)?i.getBaseValue():e}function ei(t,e,i,n){if(!t)return;if(!i){delete t[e];return}if(n&&!i.isEnabled(n))return;z0(t,e,i);let r=t[e];(!r||Vi(i,r)>=0)&&(t[e]=n?i.getBaseValue():i)}var Rr=new Set;function yo(t,e,i){var n;if(Rt(e)){Rr.add(t);return}if(!Cy(e))return;Rr.add(t);let r=(n=i?.getShorthand(t,e))==null?void 0:n.propList;if(r)for(let o of r)Rr.add(o)}var _s=new WeakMap;function z0(t,e,i){if(!Rr.has(e)||i.value===Ae)return;let n=_s.get(t);n||(n={},_s.set(t,n));let r=n[e];if(!r){r=n[e]=[];let o=t[e];o&&o.value!==Ae&&r.push(o)}r.push(i)}function V0(t,e){switch(e.value){case w.revert_rule:return t.ruleId===e.ruleId;case w.revert_layer:return nc(t)===nc(e)&&Ms(t)>=Ms(e);default:return ic(t)>=ic(e)}}function $0(t,e,i){let n=i;for(;Rt(e.value);){n=n.filter(o=>!V0(o,e));let r=null;for(let o of n)(!r||Vi(o,r)>=0)&&(r=o);if(!r)return ze(t)?w.initial:e.value;e=r}return e.value}function Xn(t,e=!1){var i;if(!Rr.size)return!1;let n=_s.get(t),r=!1;for(let o in t)if(Or(o)){let s=lt(t,o);for(let a in s)Xn(s[a],e)&&(r=!0)}else if(o==="_viewConditionalStyles")for(let s of Th(t))Xn(s.styles,e)&&(r=!0);else if(Ii(o)){let s=ge(t,o);if(!s||!Rt(s.value))continue;if(e&&ze(o)){t[o]=s.withValue(w.initial);continue}let a=$0(o,s,(i=n?.[o])!=null?i:[]);t[o]=s.withValue(a),Sl(a)&&(r=!0)}return e&&_s.delete(t),r}var Yf={"region-id":!0,"fragment-selector-id":!0},Lr="data-viv-footnote-counter";function Ds(t){let e=t.getAttribute(Lr);if(!e)return Object.create(null);let i;try{i=JSON.parse(e)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,o])=>{if(Array.isArray(o)){let s=o.filter(a=>typeof a=="number"&&isFinite(a));n[r]=s}else typeof o=="number"&&isFinite(o)&&(n[r]=[o])}),n}function Zf(t,e,i){let n=Ds(t);n[e]=i,t.setAttribute(Lr,JSON.stringify(n))}function H0(t,e){var i,n;if(!qt(t)||t.hasAttribute(nf))return null;let r=Ds(t)[e];if(r)return r;let o=t.getAttribute("href")||t.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!o)return null;let s=t.baseURI||((i=t.ownerDocument)==null?void 0:i.baseURI)||"",a=fs(o,s);if(a==="#"||a.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let h=a.indexOf("#");if(h<0||h===a.length-1)return null;let l=(n=t.ownerDocument)==null?void 0:n.getElementById(a.substring(h+1));if(!(l instanceof Element))return null;let c=Ds(l)[e];return c?(Zf(t,e,c),c):null}function U0(t){let e=ge(t,"content");return!!e&&At(e.value)}function W0(t){return!!Yf[t]}function Or(t){return t.charAt(0)==="_"&&t!=="_viewConditionalStyles"}function Ii(t){return t.charAt(0)!=="_"&&!Yf[t]}function Mn(t){return!!jf[t]||ze(t)}function ge(t,e){return t[e]}function Bi(t,e,i){i?t[e]=i:delete t[e]}function lt(t,e){return t[e]}function li(t,e){let i=t[e];return i||(i={},t[e]=i),i}var Th=t=>{let e=t._viewConditionalStyles;return e||(e=[],t._viewConditionalStyles=e),e};function Kf(t,e){return t[e]}function Jf(t,e){let i=t[e];return i||(i=[],t[e]=i),i}function zs(t,e,i,n,r,o,s,a){var h;if([{id:r,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=li(e,l.styleKey);e=c[l.id],e||(e={},c[l.id]=e)}}),s){let l=Th(e);e={},l.push({styles:e,matcher:s})}for(let l in i)if(!Or(l))if(W0(l)){let c=Kf(i,l),d=Jf(e,l);Array.prototype.push.apply(d,c)}else{let c=ge(i,l);if(!c.isEnabled(t))continue;let d=c.increaseSpecificity(n);ei(e,l,d,t);let p=(h=a?.getShorthand(l,d.value))==null?void 0:h.propList;if(p)for(let f of p){let g=d.withValue(Ae);ei(e,f,g,t)}}}function G0(t,e){let i={};for(let n=0;n<e.length;n++)zs(t,i,e[n],0,null,null,null,null);return i}function Ih(t,e){if(t.length>0){t.sort((i,n)=>n.getPriority()-i.getPriority());for(let i=t.length-1;i>=0;i--)e=t[i].wire(e)}return e}var j0=class extends dn{constructor(t,e){super(),u(this,"props",t),u(this,"context",e),u(this,"propName","")}setPropName(t){this.propName=t}getFontSize(){let t=ge(this.props,"font-size");if(!t.value.isNumeric())return vi.em;let e=t.value;if(!oy(e.unit))throw new Error("Unexpected state");return e.num*vi[e.unit]}visitNumeric(t){return this.propName==="font-size"?Tl(t,this.getFontSize(),this.context):t.unit==="em"||t.unit==="rem"||t.unit==="lh"||t.unit==="rlh"?Ah(t,this.getFontSize(),this.context):t}visitExpr(t){return this.propName=="font-size"?Hs(this.context,t,this.propName).visit(this):t}};function Ah(t,e,i){let n=t.unit,r=t.num;return n==="em"?new B(r*e,"px"):n==="rem"?new B(r*i.fontSize(),"px"):n==="rlh"?new B(r*i.rootLineHeight,"px"):t}function Tl(t,e,i){t=Ah(t,e??0,i);let n=t.unit,r=t.num;return n==="px"?t:n==="%"?new B(r/100*(e??0),"px"):new B(r*i.queryUnitSize(n,!1),"px")}var Qf=class{constructor(t,e,i,n){u(this,"instance",t),u(this,"currentStyle",e),u(this,"currentClassNames",i),u(this,"currentEpubTypes",n)}},eg=class extends Qf{constructor(t,e,i,n,r){super(t,e,i,n),u(this,"currentElement",r)}},tr=class{apply(t){}mergeWith(t){return new X0([this,t])}clone(){return this}},$o=class extends tr{constructor(t){super(),u(this,"conditionItem",t)}apply(t){t.instance.pushConditionItem(this.conditionItem.fresh(t.instance))}},X0=class tg extends tr{constructor(e){super(),u(this,"list",e)}apply(e){for(let i=0;i<this.list.length;i++)this.list[i].apply(e)}mergeWith(e){return this.list.push(e),this}clone(){return new tg([].concat(this.list))}},Fh=class extends tr{constructor(t,e,i,n,r){super(),u(this,"style",t),u(this,"specificity",e),u(this,"pseudoelement",i),u(this,"regionId",n),u(this,"viewConditionId",r)}apply(t){zs(t.instance.context,t.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,t.instance.buildViewConditionMatcher(this.viewConditionId),t.instance.mergeValidatorSet)}},Te=class{getPriority(){return 0}primarySlot(t){return null}wire(t){return new q0(this,t)}},Rh=class extends tr{constructor(t,e){super(),u(this,"condition",t),u(this,"chained",e)}makePrimary(t){let e=this.condition.primarySlot(t);return e?(t.insertInTable(e.table,e.key,this.chained),!0):!1}},q0=class extends Rh{apply(t){this.condition.matches(t)&&this.chained.apply(t)}},Y0=class extends Rh{apply(t){if(this.condition.matches(t)){t.instance.dependentConditions.push(this.condition.condition);try{this.chained.apply(t)}finally{t.instance.dependentConditions.pop()}}}},Z0=class extends Te{constructor(t){super(),u(this,"className",t)}matches(t){return t.currentClassNames.includes(this.className)}getPriority(){return 10}primarySlot(t){return{table:t.classes,key:this.className}}},K0=class extends Te{constructor(t){super(),u(this,"id",t)}matches(t){return t.instance.currentId==this.id||t.instance.currentXmlId==this.id}getPriority(){return 11}primarySlot(t){return{table:t.ids,key:this.id}}},rc=class extends Te{constructor(t){super(),u(this,"localName",t)}matches(t){return t.instance.currentLocalName==this.localName}getPriority(){return 8}primarySlot(t){return{table:t.tags,key:this.localName}}},J0=class extends Te{constructor(t,e){super(),u(this,"ns",t),u(this,"localName",e)}matches(t){return t.instance.currentLocalName==this.localName&&t.instance.currentNamespace==this.ns}getPriority(){return 8}primarySlot(t){let e=t.nsPrefix[this.ns];return e||(e=`ns${t.nsCount++}:`,t.nsPrefix[this.ns]=e),{table:t.nstags,key:e+this.localName}}},Q0=class extends Te{constructor(t,e,i=!1){super(),u(this,"epubTypePatt",t),u(this,"targetLocalName",e),u(this,"useRoleAttr",i)}matches(t){let e=t.currentElement;if(e instanceof HTMLAnchorElement&&e.hash&&e.href==e.baseURI.replace(/#.*$/,"")+e.hash){let i=e.hash.substring(1),n=e.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");if(r&&r.match(this.epubTypePatt))return!0}}return!1}},ex=class extends Te{constructor(t){super(),u(this,"ns",t)}matches(t){return t.instance.currentNamespace==this.ns}};function ua(t,e,i,n){var r;if(!t)return!1;let o=((r=t.ownerDocument)==null?void 0:r.contentType)==="text/html",s=o?Xr(i):i;if(e!==null){let a=t.getAttributeNodeNS(e||null,s);return!!a&&n(a)}for(let a of Array.from(t.attributes))if((o?Xr(a.localName):a.localName)===s&&n(a))return!0;return!1}function Xr(t){return t.replace(/[A-Z]/g,e=>e.toLowerCase())}function ig(t){return t==="i"}function ur(t,e){return Array.from(t,i=>{let n=gs(i);if(!ig(e))return n;let r=Xr(i),o=r.toUpperCase();return r!==o&&/^[a-z]$/i.test(i)?`[${r}${o}]`:n}).join("")}function cr(t){return new RegExp(t)}function tx(t,e,i){return ig(i)?Xr(t)===Xr(e):t===e}var oc=class extends Te{constructor(t,e){super(),u(this,"ns",t),u(this,"name",e)}matches(t){return ua(t.currentElement,this.ns,this.name,()=>!0)}},ix=class extends Te{constructor(t,e,i,n=null){super(),u(this,"ns",t),u(this,"name",e),u(this,"value",i),u(this,"caseSensitivity",n)}matches(t){return ua(t.currentElement,this.ns,this.name,e=>tx(e.value,this.value,this.caseSensitivity))}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}primarySlot(t){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?{table:t.epubtypes,key:this.value}:null}},nx=class extends Te{constructor(t,e){super(),u(this,"ns",t),u(this,"name",e)}matches(t){return ua(t.currentElement,this.ns,this.name,e=>!!A0[e.value])}getPriority(){return 0}primarySlot(t){return null}},dr=class extends Te{constructor(t,e,i,n=null){super(),u(this,"ns",t),u(this,"name",e),u(this,"regexp",i),u(this,"caseSensitivity",n)}matches(t){return ua(t.currentElement,this.ns,this.name,e=>!!e.value.match(this.regexp))}},rx=class extends Te{constructor(t){super(),u(this,"langRegExp",t)}matches(t){return!!t.instance.lang.match(this.langRegExp)}},sc=class extends Te{constructor(){super()}matches(t){return t.instance.isFirst}getPriority(){return 6}},ox=class extends Te{constructor(){super()}matches(t){return t.instance.isRoot}getPriority(){return 12}},fn=class extends Te{constructor(t,e){super(),u(this,"a",t),u(this,"b",e)}matchANPlusB(t){return Wf(t,this.a,this.b)}},sx=class extends fn{constructor(t,e){super(t,e)}matches(t){return this.matchANPlusB(t.instance.currentSiblingOrder)}getPriority(){return 5}};function Ho(){return{byNamespace:{},noNamespace:null}}function Vs(t,e){let i=e!==null?t.byNamespace[e]:t.noNamespace;return i||(i={},e!==null?t.byNamespace[e]=i:t.noNamespace=i),i}var Il=class extends fn{constructor(t,e){super(t,e)}matches(t){let e=Vs(t.instance.currentSiblingTypeCounts,t.instance.currentNamespace)[t.instance.currentLocalName];return this.matchANPlusB(e)}getPriority(){return 5}},Al=class extends fn{constructor(t,e){super(t,e)}matches(t){let e=t.instance.currentFollowingSiblingOrder;return e===null&&(e=t.instance.currentFollowingSiblingOrder=t.currentElement.parentNode.childElementCount-t.instance.currentSiblingOrder+1),this.matchANPlusB(e)}getPriority(){return 4}},Fl=class extends fn{constructor(t,e){super(t,e)}matches(t){let e=t.instance.currentFollowingSiblingTypeCounts,i=t.instance.currentNamespace!==null?e.byNamespace[t.instance.currentNamespace]:e.noNamespace;if(!i){let n=t.currentElement;do{let r=n.namespaceURI,o=n.localName,s=Vs(e,r);s[o]=(s[o]||0)+1}while(n=Wa(n));i=Vs(e,t.instance.currentNamespace)}return this.matchANPlusB(i[t.instance.currentLocalName])}getPriority(){return 4}},ax=class extends Te{constructor(){super()}matches(t){let e=t.currentElement.firstChild;for(;e;){switch(e.nodeType){case Node.ELEMENT_NODE:return!1;case Node.TEXT_NODE:if(e.length>0)return!1}e=e.nextSibling}return!0}getPriority(){return 4}},lx=class extends Te{constructor(){super()}matches(t){return t.currentElement.disabled===!1}getPriority(){return 5}},hx=class extends Te{constructor(){super()}matches(t){return t.currentElement.disabled===!0}getPriority(){return 5}},ux=class extends Te{constructor(){super()}matches(t){let e=t.currentElement;return e.selected===!0||e.checked===!0}getPriority(){return 5}},cx=class extends Te{constructor(t){super(),u(this,"selector",t)}matches(t){let e=t.currentElement;try{return!!e&&e.matches(this.selector)}catch{return!1}}},rt=class extends Te{constructor(t){super(),u(this,"condition",t)}matches(t){return!!t.instance.conditions[this.condition]}wire(t){return new Y0(this,t)}getPriority(){return 5}},ng=class rg extends tr{constructor(){super(),u(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new rg;return e.applied=this.applied,e}},Lh=class extends Te{constructor(t){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),u(this,"priority"),this.checkAppliedAction=new ng,this.priority=Math.max(...t.map(e=>e.length>0?Math.max(...e.map(i=>i.getPriority())):0));for(let e of t)this.firstActions.push(Ih(e,this.checkAppliedAction))}matches(t){for(let i of this.firstActions)if(i.apply(t),this.checkAppliedAction.applied)break;let e=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,e===this.positive()}getPriority(){return this.priority}positive(){return!0}relational(){return!1}},dx=class extends Lh{positive(){return!1}},px=class extends Lh{constructor(t){super([]),u(this,"selectorTexts",t)}matches(t){for(let i of this.selectorTexts){let n,r;/^\s*[+~]/.test(i)?(r=t.currentElement.parentNode,n=`:scope > :nth-child(${Array.from(r.children).indexOf(t.currentElement)+1}) ${i}`):(r=t.currentElement,n=`:scope ${i}`);try{if(r.querySelector(n)){this.checkAppliedAction.apply(t);break}}catch{}}let e=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,e}relational(){return!0}},og=class extends fn{constructor(t,e,i){super(t,e),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new ng;for(let n of i)this.firstActions.push(Ih(n,this.checkAppliedAction))}matches(t){for(let r of this.firstActions)if(r.apply(t),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return!1;this.checkAppliedAction.applied=!1;let e=t.currentElement,i=1,n=nu(e);for(;n;)this.matchesSelector(n,t)&&i++,n=nu(n);return this.matchANPlusB(i)}matchesSelector(t,e){let i=e.instance,n=i.currentNamespace,r=i.currentLocalName,o=i.currentId,s=i.currentSiblingOrder;i.currentNamespace=t.namespaceURI,i.currentLocalName=t.localName,i.currentId=t.getAttribute("id");let a=1,h=t.previousElementSibling;for(;h;)a++,h=h.previousElementSibling;i.currentSiblingOrder=a;let l=new eg(i,e.currentStyle,t.classList?Array.from(t.classList):[],e.currentEpubTypes,t);for(let d of this.firstActions)if(d.apply(l),this.checkAppliedAction.applied)break;let c=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,i.currentNamespace=n,i.currentLocalName=r,i.currentId=o,i.currentSiblingOrder=s,c}getPriority(){return 5}},fx=class extends og{constructor(t,e,i){super(t,e,i)}matches(t){for(let r of this.firstActions)if(r.apply(t),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return!1;this.checkAppliedAction.applied=!1;let e=t.currentElement,i=1,n=Wa(e);for(;n;)this.matchesSelector(n,t)&&i++,n=Wa(n);return this.matchANPlusB(i)}getPriority(){return 4}},ca=class{constructor(t,e,i){u(this,"condition",t),u(this,"viewConditionId",e),u(this,"viewCondition",i)}increment(t){t.increment(this.condition,this.viewCondition)}decrement(t){t.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(t){return t.buildViewConditionMatcher(this.viewConditionId)}},gx=class sg extends ca{constructor(e,i,n){super(e,i,n)}fresh(e){return new sg(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,i){return i==0&&this.increment(e),!1}pop(e,i){return i==0?(this.decrement(e),!0):!1}},mx=class ag extends ca{constructor(e,i,n){super(e,i,n)}fresh(e){return new ag(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,i){return i==0?this.increment(e):i==1&&this.decrement(e),!1}pop(e,i){return i==0?(this.decrement(e),!0):(i==1&&this.increment(e),!1)}},yx=class lg extends ca{constructor(e,i,n){super(e,i,n),u(this,"fired",!1)}fresh(e){return new lg(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,i){return this.fired?(this.decrement(e),!0):!1}pop(e,i){return this.fired?(this.decrement(e),!0):(i==0&&(this.fired=!0,this.increment(e)),!1)}},vx=class hg extends ca{constructor(e,i,n){super(e,i,n),u(this,"fired",!1)}fresh(e){return new hg(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,i){return this.fired&&(i==-1?this.increment(e):i==0&&this.decrement(e)),!1}pop(e,i){if(this.fired){if(i==-1)return this.decrement(e),!0;i==0&&this.increment(e)}else i==0&&(this.fired=!0,this.increment(e));return!1}},wx=class{constructor(t,e,i){u(this,"afterprop",t),u(this,"element",e),u(this,"elementStyle",i)}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.processPseudoelementProps(this.afterprop,this.element,this.elementStyle),!0):!1}},bx=class{constructor(t){u(this,"lang",t)}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.lang=this.lang,!0):!1}},xx=class{constructor(t){u(this,"oldQuotes",t)}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.quotes=this.oldQuotes,!0):!1}},Sx=class extends dn{constructor(t,e,i,n){super(),u(this,"element",t),u(this,"scope",e),u(this,"propName",i),u(this,"validatorSet",n),u(this,"hadAttrFunction",!1)}validatePropertyValue(t){var e;if(Z(t))return t;let i=this.validatorSet.validators[this.propName];return i?(e=t.visit(i))!=null?e:w.unset:!this.propName||CSS.supports(this.propName,t.toString())?t:w.unset}visitFunc(t){var e;if(t.name.toLowerCase()!=="attr")return super.visitFunc(t);this.hadAttrFunction=!0;let i=Ph(t);if(!i)return super.visitFunc(t);let n=((e=i.fallback)!=null?e:d0(i.type)).visit(this);return!this.element||!this.element.hasAttribute(i.attributeName)?n:p0(this.scope,this.element.getAttribute(i.attributeName),i.type)||n}};function qr(t,e){if(At(t)){if(t instanceof K)return t.stringValue();if(t instanceof j&&e){let i=t.expr.evaluate(e);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(t instanceof ee)return t.values.map(i=>qr(i,e)).join("")}return""}function Oh(t){if(t instanceof j){let e=t.expr;return e instanceof be&&/^page-counters?-/.test(e.str)}return t instanceof ee||t instanceof Be?t.values.some(e=>Oh(e)):!1}function Rl(t,e){return Oh(t)?t instanceof ee?new ee(t.values.map(i=>Rl(i,e))):t instanceof Be?new Be(t.values.map(i=>Rl(i,e))):t:new K(qr(t,e))}var Yr=class extends dn{constructor(t,e,i,n,r){super(),u(this,"cascade",t),u(this,"element",e),u(this,"counterResolver",i),u(this,"elementStyle",n),u(this,"pseudoName",r)}getCounterStore(){var t,e;return(e=(t=this.cascade.context)==null?void 0:t.counterStore)!=null?e:null}hasLocalCounterResetOrSet(t){return this.hasLocalCounter(t,"counter-reset",{reset:!0})||this.hasLocalCounter(t,"counter-set",{defaultValue:0})}hasLocalCounterIncrement(t){return this.hasLocalCounter(t,"counter-increment",{})}hasLocalCounter(t,e,i){let n=this.elementStyle[e];if(!n)return!1;let r=n.evaluate(this.cascade.context);if(!r||Z(r))return!1;let o=nn(r,i);return Object.prototype.hasOwnProperty.call(o,t)}evaluateAndGetString(t){if(!t)return"";let e=this.cascade.quoteDepth,i=t.visit(this),n=qr(i,this.cascade.context);return this.cascade.quoteDepth=e,n}visitIdent(t){let e=this.cascade,i=e.quotes,n=Math.floor(i.length/2)-1;switch(t.name){case"open-quote":{let r=i[2*Math.min(n,e.quoteDepth)];return e.quoteDepth++,r}case"close-quote":return e.quoteDepth>0&&e.quoteDepth--,i[2*Math.min(n,e.quoteDepth)+1];case"no-open-quote":return e.quoteDepth++,new K("");case"no-close-quote":return e.quoteDepth>0&&e.quoteDepth--,new K("")}return t}format(t,e){return this.cascade.counterStyleStore.format(e,t)}formatCounterList(t,e,i){if(!t.length)return this.format(0,i);let n=new mi;for(let r=0;r<t.length;r++)r>0&&n.append(e),n.append(this.format(t[r],i));return n.toString()}formatLastValue(t,e){let i=t.length?t[t.length-1]:0;return this.format(i,e)}buildCounterText(t,e,i,n,r,o=!1,s=!1){var a,h,l,c,d,p,f,g,m;let v=typeof r=="string",b=L=>v?this.formatCounterList(L,r,i):this.formatLastValue(L,i),x=L=>{this.pseudoName==="footnote-call"&&this.element&&Zf(this.element,e,L)},C=(L,I)=>L.length===I.length&&L.every((D,J)=>D===I[J]);if(this.pseudoName==="footnote-call"&&this.element){let L=H0(this.element,e);if(L)return b(L)}if(this.pseudoName==="footnote-marker"&&this.element){let L=Ds(this.element)[e];if(L)return b(L)}let y;if(e==="pages")return b([]);if(!this.element){if(o&&n.length)return y=n,x(y),b(y);if((a=t.isPageControlledCounter)!=null&&a.call(t,e)&&s&&n.length){let L=((h=t.currentPageCounters)==null?void 0:h[e])||[];return y=[(L.length?L[L.length-1]:0)+n[n.length-1]],x(y),b(y)}if(!((l=t.isPageControlledCounter)!=null&&l.call(t,e))){let L=((c=t.currentPageCounters)==null?void 0:c[e])||[];if(L.length)return y=L,x(y),b(y)}}let k=((d=t.currentPageDocCounters)==null?void 0:d[e])||[],S=!this.element&&n.length&&!C(n,k),N=this.element||S?n:k.length?k:n;if((p=t.isPageControlledCounter)!=null&&p.call(t,e)){let L=((f=t.currentPageDocCounters)==null?void 0:f[e])||[],I=((g=t.currentPageCounters)==null?void 0:g[e])||[],D=I.length?I[I.length-1]:0,J=L.length?L[0]:0,te=N.length?N[0]:0,P=D+(te-J);return y=N.length?[P,...N.slice(1)]:I.length?I:[0],x(y),b(y)}return N.length?(y=N,x(y),b(y)):(y=((m=t.currentPageCounters)==null?void 0:m[e])||[],x(y),b(y))}visitFuncCounter(t){var e;let i=t[0].toString(),n=t.length>1?t[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),o=!this.element&&this.hasLocalCounterResetOrSet(i),s=!this.element&&this.hasLocalCounterIncrement(i),a=this.getCounterStore();if(a){let l=i==="pages"||((e=a?.isPageControlledCounter)==null?void 0:e.call(a,i)),c=this.counterResolver.pageScope,d=new be(c,()=>this.buildCounterText(a,i,n,r,void 0,o,s),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 K(this.format(l,n))}else{let l=new j(this.counterResolver.getPageCounterVal(i,c=>this.format(c||0,n)));return new ee([l])}}visitFuncCounters(t){var e;let i=t[0].toString(),n=t[1].stringValue(),r=t.length>2?t[2].stringValue():"decimal",o=(this.cascade.counters[i]||[]).slice(),s=!this.element&&this.hasLocalCounterResetOrSet(i),a=!this.element&&this.hasLocalCounterIncrement(i),h=this.getCounterStore();if(h){let p=i==="pages"||((e=h?.isPageControlledCounter)==null?void 0:e.call(h,i)),f=this.counterResolver.pageScope,g=new be(f,()=>this.buildCounterText(h,i,r,o,n,s,a),p?`page-counters-${i}`:`counters-${i}`);return p&&h!=null&&h.registerPageCounterExpr&&h.registerPageCounterExpr(i,m=>this.formatCounterList(m,n,r),g),new j(g)}let l=this.cascade.counters[i],c=new mi;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 m=0;m<p.length;m++)f.push(this.format(p[m],r));let g=c.toString();return g.length&&f.push(g),f.length?f.join(n):this.format(0,r)}));return new ee([d])}visitFuncTargetCounter(t){let e=t[0],i;e instanceof et?i=e.url:i=e.stringValue();let n=t[1].toString(),r=t.length>2?t[2].stringValue():"decimal",o=new j(this.counterResolver.getTargetCounterVal(i,n,s=>this.format(s||0,r)));return new ee([o])}visitFuncTargetCounters(t){let e=t[0],i;e instanceof et?i=e.url:i=e.stringValue();let n=t[1].toString(),r=t[2].stringValue(),o=t.length>3?t[3].stringValue():"decimal",s=new j(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,o));return h.length?h.join(r):this.format(0,o)}));return new ee([s])}visitFuncTargetText(t){let e=t[0],i;e instanceof et?i=e.url:i=e.stringValue();let n=t.length>1?t[1].stringValue():"content",r=new j(this.counterResolver.getTargetTextVal(i,n));return new ee([r])}visitFuncString(t){let e=t.length>0?t[0].stringValue():"",i=t.length>1?t[1].stringValue():"first";return new j(this.counterResolver.getNamedStringVal(e,i))}visitFuncElement(t){let e=t.length>0?t[0].stringValue():"",i=t.length>1?t[1].stringValue():"first";return new j(this.counterResolver.getRunningElementVal(e,i))}visitFuncContent(t){var e,i,n,r,o,s,a,h;let l=t.length>0?t[0].stringValue():"text",c="";switch(l){case"text":c=this.element.textContent;break;case"before":case"after":case"marker":{let d=(e=this.element)==null?void 0:e.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=lt(this.elementStyle,"_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 m=(r=this.elementStyle["--viv-marker-content"])==null?void 0:r.value;c=qr(m,this.cascade.context)}}}break;case"first-letter":{let d=lt(this.elementStyle,"_pseudos"),p=(s=(o=d?.before)==null?void 0:o.content)==null?void 0:s.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(ps);c=g?g[0]:""}break}return new K(c)}visitFuncLeader(t){let e="";if(t[0]instanceof he)switch(t[0].stringValue()){case"dotted":e=".";break;case"solid":e="_";break;case"space":e=" ";break}else t[0]instanceof K&&(e=t[0].stringValue());return e.length==0?new K(""):new j(new be(this.counterResolver.rootScope,()=>e,"viv-leader"))}visitFunc(t){switch(t.name){case"counter":if(t.values.length<=2)return this.visitFuncCounter(t.values);break;case"counters":if(t.values.length<=3)return this.visitFuncCounters(t.values);break;case"target-counter":if(t.values.length<=3)return this.visitFuncTargetCounter(t.values);break;case"target-counters":if(t.values.length<=4)return this.visitFuncTargetCounters(t.values);break;case"target-text":if(t.values.length>=1&&t.values.length<=2)return this.visitFuncTargetText(t.values);break;case"string":if(t.values.length<=2)return this.visitFuncString(t.values);break;case"element":if(t.values.length<=2)return this.visitFuncElement(t.values);break;case"content":if(t.values.length<=1)return this.visitFuncContent(t.values);break;case"leader":if(t.values.length<=1)return this.visitFuncLeader(t.values);break}return t}};function Ba(t,e,i){let n;if(t.nodeType===1)n=Array.from(t.getClientRects());else{let r=t.ownerDocument.createRange();r.selectNodeContents(t),n=e.getRangeClientRects(r)}return n.reduce((r,o)=>r+(i==="vertical-rl"||i==="vertical-lr"?o.height:o.width),0)}function Cx(t){let e=Lt(t);return e!==null&&e.after&&e.viewNode.hasAttribute("data-viv-leader")&&e.blockContainer!==null?e:null}var kx=(t,e,i)=>{let n=e.flatMap(h=>{let l=Cx(h),c=l?.viewNode.parentElement,d=c?.parentElement;return l&&c&&d?[{leaderContext:l,pseudoElem:c,pseudoParent:d}]:[]});for(let{leaderContext:h,pseudoElem:l,pseudoParent:c}of n){let d=function(E){y==="rtl"?v.textContent=(E.startsWith("\u200F")?"":"\u200F")+E+(E.endsWith("\u200F")?"":"\u200F"):v.textContent=E},p=function(){let E=i.clientLayout.getElementClientRect(l);return C==="vertical-rl"||C==="vertical-lr"?y==="rtl"?E.top-=M:E.bottom+=M:y==="rtl"?E.left-=M:E.right+=M,L.left>E.left||L.right<E.right||L.top>E.top||L.bottom<E.bottom},f=function(){let E,O,T=x.repeat(1e4);if(d(T),p())E=1,O=1e4;else return;for(let $=0;$<16;$++){let G="",q=Math.floor((E+O)/2);for(let Q=0;Q<q;Q++)G+=x;if(d(G),p())O=q;else{if(E==q)return;E=q}}d(x)},g=function(E){let O=0,T=l.parentElement;for(;T&&T!==m.viewNode;)O+=i.getComputedInsets(T)[E],T=T.parentElement;return O};var r=d,o=p,s=f,a=g;let m=h.blockContainer,v=h.viewNode,b=l.getAttribute("data-adapt-pseudo"),x=v.getAttribute("data-viv-leader-value"),{writingMode:C,direction:y,marginInlineEnd:k}=i.clientLayout.getElementComputedStyle(l);v.style.marginInlineStart="1px",d(x),l.style.display="inline-block",l.style.textIndent="0";let S=co(m.viewNode),N=S?.style.columnFill||null;S&&(S.style.columnFill="auto");let L=i.clientLayout.getElementClientRect(m.viewNode),I=i.clientLayout.getElementClientRect(l),D=i.parseComputedLength(k),J=[],te=c;for(;te.parentElement&&te.parentElement!==m.viewNode;)te=te.parentElement;let P=te.nextSibling;for(;P;){if(P.nodeType===1){let E=P,{display:O,float:T,position:$}=i.clientLayout.getElementComputedStyle(E);if(T!=="none"||$==="absolute"||$==="fixed"){P=P.nextSibling;continue}if(Wt(O))J.push(E);else if(cw(O))break}else if(P.nodeType===3){let E=P;E.length>0&&J.push(E)}P=P.nextSibling}let M=J.reduce((E,O)=>E+Ba(O,i.clientLayout,C),0);if(b!=="after"){let E=Ba(te,i.clientLayout,C),O=Ba(l,i.clientLayout,C);M+=E-O}C==="vertical-rl"||C==="vertical-lr"?(y==="rtl"?L.top+=D:L.bottom-=D,L.top=Math.min(I.top,L.top),L.bottom=Math.max(I.bottom,L.bottom)):(y==="rtl"?L.left+=D:L.right-=D,L.left=Math.min(I.left,L.left),L.right=Math.max(I.right,L.right)),f();let A=i.clientLayout.getElementClientRect(l);y=="rtl"?l.style.float="left":l.style.float="right";let H=i.clientLayout.getElementClientRect(l),z=0;y=="rtl"?C=="vertical-rl"||C=="vertical-lr"?z=A.top-H.top-g("top"):z=A.left-H.left-g("left"):C=="vertical-rl"||C=="vertical-lr"?z=H.bottom-A.bottom-g("bottom"):z=H.right-A.right-g("right"),z-=M,z=Math.max(0,z-.1),l.style.float="",v.style.marginInlineStart=`${z}px`,S&&(N?S.style.columnFill=N:S.style.removeProperty("column-fill"))}};Ft("POST_LAYOUT_BLOCK",kx);var Bh=1/1048576;function wn(t,e){for(let i in t)e[i]=t[i].clone()}var Px=class ug{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),u(this,"layerTrees",{})}clone(){let e=new ug;e.nsCount=this.nsCount;for(let i in this.nsPrefix)e.nsPrefix[i]=this.nsPrefix[i];wn(this.tags,e.tags),wn(this.nstags,e.nstags),wn(this.epubtypes,e.epubtypes),wn(this.classes,e.classes),wn(this.ids,e.ids),wn(this.pagetypes,e.pagetypes),e.order=this.order;for(let i in this.layerTrees)e.layerTrees[i]=this.layerTrees[i];return e}registerLayer(e,i,n){var r,o;return((o=(r=this.layerTrees)[e])!=null?o:r[e]=new M0).register(i,n)}insertInTable(e,i,n){let r=e[i];r&&(n=r.mergeWith(n)),e[i]=n}createInstance(e,i,n,r,o,s,a,h,l,c,d){return new Ex(this,e,i,n,r,o,s,a,h,l,c,d)}nextOrder(){return this.order+=Bh}},cg=class dg{constructor(e,i,n,r,o,s,a,h,l,c,d,p){u(this,"context",i),u(this,"counterListener",n),u(this,"counterResolver",r),u(this,"counterStyleStore",s),u(this,"cmykStore",a),u(this,"root",h),u(this,"scope",l),u(this,"validatorSet",c),u(this,"styles",d),u(this,"mergeValidatorSet",p),u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",Object.create(null)),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentLocalName",""),u(this,"currentNamespace",null),u(this,"currentId",null),u(this,"currentXmlId",null),u(this,"currentNSTag",""),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",[Ho()]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[Ho()]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",Object.create(null)),u(this,"dependentConditions",[]),u(this,"elementStack",[]),this.code=e,this.quotes=[new K("\u201C"),new K("\u201D"),new K("\u2018"),new K("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(e){this.stack[this.stack.length-1].push(e)}increment(e,i){this.conditions[e]=(this.conditions[e]||0)+1,i&&(this.viewConditions[e]?this.viewConditions[e].push(i):this.viewConditions[e]=[i])}decrement(e,i){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(n=>n!==i),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let i=null;e&&(this.currentElementOffset,i=Vo.buildViewConditionMatcher(this.currentElementOffset,e));let n=this.dependentConditions.map(r=>{let o=this.viewConditions[r];return o&&o.length>0?o.length===1?o[0]:Vo.buildAnyMatcher([].concat(o)):null}).filter(r=>r!==null);return n.length<=0?i:i===null?n.length===1?n[0]:Vo.buildAllMatcher(n):Vo.buildAllMatcher([i].concat(n))}applyAction(e,i,n){let r=i[n];r&&r.apply(e)}pushRule(e,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentNamespace=null,this.currentLocalName="",this.currentId=null,this.currentXmlId=null,this.currentNSTag="",this.currentPageType=i,this.applyActions(new Qf(this,n,e,Ma))}defineCounter(e,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[e]?(n[e]&&this.counters[e].pop(),this.counters[e].push(i)):this.counters[e]=[i],n[e]=!0}pushCounters(e,i){var n,r,o,s,a,h,l,c,d,p;let f=new Set,g=Object.create(null),m=w.inline,v=e.display;if(v&&(m=v.evaluate(this.context)),m===w.none){(n=this.currentElement)==null||n.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if((r=this.currentElement)!=null&&r.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let b=w.inline,x=e.float;x&&(b=x.evaluate(this.context));let C=null,y=null,k=null,S=e["counter-reset"];if(S){let I=S.evaluate(this.context);I&&(C=nn(I,{reset:!0}))}let N=e["counter-set"];if(N){let I=N.evaluate(this.context);I&&(k=nn(I,{defaultValue:0}))}let L=e["counter-increment"];if(L){let I=L.evaluate(this.context);I&&(y=nn(I))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(C||(C=Object.create(null)),C["list-item"]=((s=(o=this.currentElement)==null?void 0:o.start)!=null?s:1)-1),mr(m)&&(y||(y=Object.create(null)),y["list-item"]=(a=y["list-item"])!=null?a:1,/^\s*[-+]?\d/.test((l=(h=this.currentElement)==null?void 0:h.getAttribute("value"))!=null?l:"")&&(k||(k=Object.create(null)),k["list-item"]=this.currentElement.value)),((d=(c=this.currentElement)==null?void 0:c.parentNode)==null?void 0:d.nodeType)===Node.DOCUMENT_NODE&&(C||(C=Object.create(null)),C.footnote===void 0&&(C.footnote=0)),b===w.footnote&&!i["--viv-semantic-footnote-content"]&&(y||(y=Object.create(null)),y.footnote===void 0)){let I=(p=i["counter-increment"])==null?void 0:p.value;(!I||!(I===w.footnote||I instanceof ee&&I.values.includes(w.footnote)))&&(y.footnote=1)}if(C)for(let I in C)f.add(I),g[I]="reset";if(y)for(let I in y)f.add(I),g[I]||(g[I]="increment");if(k)for(let I in k)f.add(I),g[I]="set";if(this.lastCounterChanges=Array.from(f),this.lastCounterChangeTypes=g,C)for(let I in C)this.defineCounter(I,C[I]);if(y)for(let I in y){this.counters[I]||this.defineCounter(I,0);let D=this.counters[I];D[D.length-1]+=y[I]}if(k)for(let I in k)if(!this.counters[I])this.defineCounter(I,k[I]);else{let D=this.counters[I];D[D.length-1]=k[I]}if(mr(m)){let I=this.counters["list-item"],D=I[I.length-1];e["ua-list-item-count"]=new X(new It(D),0);let J=li(e,"_pseudos");J.marker||(J.marker={})}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let i in e){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(e,i,n){let r=e["string-set"];if(!r)return;r=r.filterValue(new Yr(this,i,this.counterResolver,e));let o=r.value instanceof Be?r.value.values:[r.value];for(let s of o)if(s instanceof ee){let a=s.values[0].stringValue(),h=s.values.slice(1);if(h.some(l=>Oh(l)))this.counterResolver.setNamedString(a,Rl(new ee(h),this.context),n);else{let l=h.map(c=>qr(c,this.context)).join("");this.counterResolver.setNamedString(a,l,n)}}delete e["string-set"]}setRunningElement(e,i){let n=e.position;if(n?.value instanceof Vt&&n.value.name==="running"){let r=n.value.values[0].stringValue();this.counterResolver.setRunningElement(r,i)}}processPseudoelementProps(e,i,n,r){this.pushCounters(e,n);let o=e.content;o&&(e.content=o.filterValue(new Yr(this,i,this.counterResolver,n,r))),this.popCounters()}pushElement(e,i,n){var r,o,s;let a=this.currentPageType;this.currentPageType=null,this.currentElement=e,this.currentElementOffset=n,this.currentNamespace=e.namespaceURI,this.currentLocalName=e.localName;let h=this.currentNamespace!==null?this.code.nsPrefix[this.currentNamespace]:void 0;h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=e.getAttribute("id"),this.currentXmlId=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=e.getAttribute("class"),c=l?l.split(/\s+/):Ma,d=e.getAttributeNS("http://www.idpf.org/2007/ops","type"),p=d?d.split(/\s+/):Ma,f=ja(e);f&&(this.stack[this.stack.length-1].push(new bx(this.lang)),this.lang=f.toLowerCase());let g=this.isRoot,m=this.siblingOrderStack;this.currentSiblingOrder=++m[m.length-1],m.push(0);let v=this.siblingTypeCountsStack,b=this.currentSiblingTypeCounts=v[v.length-1],x=Vs(b,this.currentNamespace);x[this.currentLocalName]=(x[this.currentLocalName]||0)+1,v.push(Ho());let C=this.followingSiblingOrderStack,y=C[C.length-1];y!==null?this.currentFollowingSiblingOrder=C[C.length-1]=y-1:this.currentFollowingSiblingOrder=null,C.push(null);let k=this.followingSiblingTypeCountsStack,S=this.currentFollowingSiblingTypeCounts=k[k.length-1],N=S&&(this.currentNamespace!==null?S.byNamespace[this.currentNamespace]:S.noNamespace);N&&N[this.currentLocalName]--,k.push(Ho());let L=new eg(this,i,c,p,e);this.applyActions(L),this.currentPageType=a,this.applyVarFilter([i],e),Xn(i,!0)&&this.applyVarFilter([i],e),this.applyCalcFilter(i,this.context),this.applyCmykFilter(i,e),this.applyAttrFilter(e,i);let I=i.quotes,D=null;if(I){let P=I.evaluate(this.context);P&&(D=new xx(this.quotes),P===w.none?this.quotes=[new K(""),new K("")]:P===w.auto||P===w.initial?this.quotes=[new K("\u201C"),new K("\u201D"),new K("\u2018"),new K("\u2019")]:P instanceof ee&&(this.quotes=P.values))}this.pushCounters(i,i);let J=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(g||J){let P=Object.create(null);Object.keys(this.counters).forEach(M=>{P[M]=Array.from(this.counters[M])}),this.counterListener.countersOfId(J,P)}let te=lt(i,"_pseudos");if(te){let P=!0;for(let M of Nx){M||(P=!1);let A=te[M];if(A){let H=(r=ge(i,"float"))==null?void 0:r.value,z=e instanceof Element&&qt(e),E=e instanceof Element&&Et(e),O=!!ge(i,"--viv-semantic-footnote-content"),T=H===w.footnote,$=(M==="before"||M==="after")&&(T||E||O)&&!!A.content,G=U0(A),q=M==="footnote-call"&&z&&G,Q=M==="footnote-marker"&&(E||O)&&G;if((M==="before"||M==="after")&&!($||At((o=A.content)==null?void 0:o.value)||this.hasNonTrivialViewConditionalPseudoContent(A))||M==="marker"&&!mr((s=ge(i,"display"))==null?void 0:s.value)||(M==="footnote-call"||M==="footnote-marker")&&H!==w.footnote&&!q&&!Q||(M==="footnote-call"||M==="footnote-marker")&&O&&!G)delete te[M];else if(P){if(this.processPseudoelementProps(A,e,i,M),M==="marker")this.processMarkerPseudoelementProps(A,e,i),delete te[M];else if(M==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(A,"list-style-position",e,i)===w.outside){this.processMarkerPseudoelementProps(A,e,i);let oe=A.content;oe&&(i["_footnote-marker-content"]=oe),i.display=new X(_("list-item"),0),i["list-style-position"]=new X(w.outside,0),i["list-style-type"]=new X(w.none,0),i["list-style-image"]=new X(w.none,0),delete te[M]}}else if(M==="first-letter"&&A["initial-letter"]){let oe=A["initial-letter"].evaluate(this.context);oe!==w.normal&&!Z(oe)&&(i["--viv-initialLetter"]=new X(oe,0)),delete A["initial-letter"]}}else this.stack[this.stack.length-2].push(new wx(A,e,i))}}}return this.setNamedStrings(i,e,n),this.setRunningElement(i,n),D&&this.stack[this.stack.length-2].push(D),L}hasNonTrivialViewConditionalPseudoContent(e){let i=e._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return At((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(e,i,n){var r,o,s,a,h;let l=mr((r=n.display)==null?void 0:r.value);if(!At((o=e.content)==null?void 0:o.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",i,n),p=this.getInheritedPropertyValue("list-style-image",i,n);if(p instanceof et)e.content=new X(new ee([p,new K(" ")]),0);else if(d instanceof K)e.content=new X(d,0);else if(d instanceof he&&d!==w.none){let f=(a=(s=n["ua-list-item-count"])==null?void 0:s.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(e.content=new X(new K(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let c=e.content;if(c){let d=c.value;if(At(d)){let p=this.resolveMarkerContentVal(d);n["--viv-marker-content"]=new X(p,0)}}for(let d of dg.markerAllowedProps){let p=e[d];if(p){let f=p.evaluate(this.context,d);f&&!Z(f)&&(n[`--viv-marker-${d}`]=new X(f,0))}}if(!Wt((h=ge(n,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",i,n);d&&d!==w.outside&&!Z(d)&&(n["list-style-position"]=new X(d,0))}}resolveMarkerContentVal(e){if(e instanceof j){let i=e.expr.evaluate(this.context);return typeof i=="string"?new K(i):typeof i=="number"?new K(String(i)):e}if(e instanceof ee){let i=e.values.map(n=>this.resolveMarkerContentVal(n));return new ee(i)}return e}getInheritedPropertyValue(e,i,n){var r;for(let o=i;o;o=o.parentElement){let s=(o===i?n:this.styles.styleOf(o))[e];if(s){let a=s.evaluate(this.context,e);if(a===w.inherit||a===w.unset||Rt(a))continue;if(a===w.initial)break;return a}}return(r=this.validatorSet.defaultValues[e])!=null?r:null}resolvePseudoelementInheritedPropertyValue(e,i,n,r){var o;let s=e[i];if(s){let a=s.evaluate(this.context,i);if(a!==w.inherit&&a!==w.unset&&!Rt(a))return a===w.initial?(o=this.validatorSet.defaultValues[i])!=null?o:null:a}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(e,i){for(let n in i)if(Ii(n)&&!ze(n)){let r=i[n],o=new Sx(e,this.scope,n,this.validatorSet),s=r.filterValue(o);if(!o.hadAttrFunction){i[n]=s;continue}let a=o.validatePropertyValue(s.value);i[n]=s.withValue(a)}}applyAttrFilter(e,i){let n=lt(i,"_pseudos");for(let r in n)this.applyAttrFilterInner(e,n[r]);this.applyAttrFilterInner(e,i)}applyVarFilter(e,i){let n=e[0],r=e.map(c=>({...c})),o=32,s={},a=lt(n,"_pseudos"),h=Object.keys(n).filter(Ii),l=c=>{var d,p,f;let g=ge(n,c),m=g.value,v=ze(c)?r:e,b=new Mx(v,this.styles,this.root,i,ze(c)?c:null);ze(c)&&b.getFallbackCycleMembers(m,v,i)&&(m=w.initial);for(let x=0;;x++){if(x>=o){m=ze(c)?w.initial:w.unset;break}let C=m.visit(b);if(b.error){m=ze(c)?w.initial:w.unset,b.error=!1;break}if(C===m)break;m=C}if(m!==g.value){let x=(d=this.validatorSet.getShorthand(c,m))==null?void 0:d.clone(this.scope);if(x)if(Z(m)){for(let C of x.propList){let y=g.withValue(m),k=ge(n,C);Bi(s,C,Nl(this.context,k,y))}delete n[c]}else{let C=Mi(this.scope,new xt(m.toString(),null),"");if(C&&(C.visit(x),!x.error)){for(let y of x.propList){let k=g.withValue((f=(p=x.values[y])!=null?p:this.validatorSet.defaultValues[y])!=null?f:w.initial),S=ge(n,y);Bi(s,y,Nl(this.context,S,k))}delete n[c]}}else n[c]=g.withValue(m)}if(s[c]){let x=ge(n,c);x&&x.value!==Ae&&ei(s,c,x,this.context)}};for(let c in n)if(Or(c)){if(c==="_pseudos")continue;let d=lt(n,c);for(let p in d)this.applyVarFilter([d[p],...e],i)}for(let c of h)ze(c)&&l(c);for(let c of h)ze(c)||l(c);if(a)for(let c in a)this.applyVarFilter([a[c],...e],i);for(let c in s)n[c]=s[c]}applyCalcFilter(e,i){let n=new Mh(i);for(let r in e)if(Or(r)){let o=lt(e,r);for(let s in o)this.applyCalcFilter(o[s],i)}else if(Ii(r)&&!ze(r)){let o=ge(e,r);e[r]=o.withValue(o.value.visit(n))}}applyCmykFilter(e,i){let n=new Vd(this.cmykStore);if(this.applyCmykFilterInternal(e,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(e,i,n){for(let r in e)if(Or(r)){let o=lt(e,r);for(let s in o)this.applyCmykFilterInternal(o[s],i,`::${s}:`)}else if(Ii(r)&&!ze(r)){let o=ge(e,r),s=o.value.toString();i.reset();let a=o.value.visit(i);a!==o.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,s),e[r]=o.withValue(a))}}applyActions(e){let i,n=e.currentClassNames;for(i=0;i<n.length;i++)this.applyAction(e,this.code.classes,n[i]);let r=e.currentEpubTypes;for(i=0;i<r.length;i++)this.applyAction(e,this.code.epubtypes,r[i]);this.currentId!==null&&this.applyAction(e,this.code.ids,this.currentId),this.applyAction(e,this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(e,this.code.tags,"*"),this.applyAction(e,this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(e,this.code.pagetypes,this.currentPageType),this.applyAction(e,this.code.pagetypes,"*")),this.stack.push([]);for(let o=1;o>=-1;--o){let s=this.stack[this.stack.length-o-2];for(i=0;i<s.length;)s[i].push(this,o)?s.splice(i,1):i++}this.isFirst=!0,this.isRoot=!1,Xn(e.currentStyle)}pop(){for(let e=1;e>=-1;--e){let i=this.stack[this.stack.length-e-2],n=0;for(;n<i.length;)i[n].pop(this,e)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};u(cg,"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 Ex=cg,Ma=[],Nx=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],Ll=class pg{constructor(){u(this,"actions",[])}push(e){this.actions.push(e)}restartWith(e){let i=new pg;return i.push(e),i}emit(e,i){i.insertChained(Ih(this.actions,e))}contributeTo(e){e.takeAlternative(this.actions)}recordTextIn(e,i){e.push(i)}finishIn(e){e.applyRuleForSelector()}},ac=class{push(){}restartWith(){return this}emit(){}contributeTo(){}recordTextIn(){}finishIn(){}},$s=class extends Jn{constructor(t,e,i,n,r,o,s){super(t,e,s),u(this,"condition",i),u(this,"regionId",r),u(this,"validatorSet",o),u(this,"chain",new ac),u(this,"selectorListVoided",!1),u(this,"pendingChained",[]),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"ruleId",0),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"layer"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:new Px,this.layer=n?n.layer:null,this.state=0}layerStatementRule(t){for(let e of t)this.cascade.registerLayer(this.flavor,this.layer,e)}insertNonPrimary(t){this.cascade.insertInTable(this.cascade.tags,"*",t)}processChain(t){this.chain.emit(t,this)}insertChained(t){this.pendingChained.push(t)}takePendingChained(){for(let t of this.pendingChained)t instanceof Rh&&t.makePrimary(this.cascade)||this.insertNonPrimary(t);this.pendingChained.splice(0)}invalidContinuationAfterPseudoelement(t){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${t}`),!0):!1}isInsideSelectorRule(t){return this.state!=0?(this.reportAndSkip(t),!0):!1}tagSelector(t,e){!e&&!t||this.invalidContinuationAfterPseudoelement(e||"*")||(e&&(this.specificity+=1),e&&t?this.chain.push(new J0(t,e.toLowerCase())):e?this.chain.push(new rc(e.toLowerCase())):this.chain.push(new ex(t)))}invalidSelector(t){Y.warn(t),this.setInvalid(),this.voidSelectorList()}setInvalid(){this.invalid=!0;for(let t=this;t instanceof qn;t=t.parent)t.parent.invalid=!0}classSelector(t){this.invalidContinuationAfterPseudoelement(`.${t}`)||(this.specificity+=256,this.chain.push(new Z0(t)))}pseudoclassSelector(t,e){if(!this.invalidContinuationAfterPseudoelement(`:${t}`)){if(e?!lc.has(t.toLowerCase()):lc.has(t.toLowerCase())){this.invalidSelector(`Unsupported pseudo-class :${t}`);return}switch(t.toLowerCase()){case"enabled":this.chain.push(new lx);break;case"disabled":this.chain.push(new hx);break;case"checked":this.chain.push(new ux);break;case"root":case"scope":this.chain.push(new ox);break;case"link":case"any-link":this.chain.push(new rc("a")),this.chain.push(new oc("","href"));break;case"href-epub-type":case"href-role-type":if(e&&e.length>=1&&typeof e[0]=="string"){let i=e[0],n=new RegExp(`(^|\\s)${gs(i)}($|\\s)`),r=e[1];this.chain.push(new Q0(n,r,t==="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(e&&e.length==1&&typeof e[0]=="string"){let i=e[0];this.chain.push(new rx(new RegExp(`^${gs(i.toLowerCase())}($|-)`)))}else this.chain.push(new rt(""));break;case"dir":if(e&&e.length==1&&typeof e[0]=="string"){/^(ltr|rtl)$/i.test(e[0])?this.chain.push(new cx(`:dir(${e[0].toLowerCase()})`)):this.chain.push(new rt(""));break}this.invalidSelector(`Invalid pseudo-class :${t}`);return;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Tx[t.toLowerCase()];e&&e.length==2?this.chain.push(new i(e[0],e[1])):this.chain.push(new rt(""));break}case"first-child":this.chain.push(new sc);break;case"last-child":this.chain.push(new Al(0,1));break;case"first-of-type":this.chain.push(new Il(0,1));break;case"last-of-type":this.chain.push(new Fl(0,1));break;case"only-child":this.chain.push(new sc),this.chain.push(new Al(0,1));break;case"only-of-type":this.chain.push(new Il(0,1)),this.chain.push(new Fl(0,1));break;case"empty":this.chain.push(new ax);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(t,e);return;default:this.invalidSelector(`Unknown pseudo-class :${t}`);return}this.specificity+=256}}pseudoelementSelector(t,e){if(t=t.toLowerCase(),!this.invalidContinuationAfterPseudoelement(`::${t}`)){switch(t){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=t;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${t}`);return}break;case"first-n-lines":if(e&&e.length==1&&typeof e[0]=="number"){let i=Math.round(e[0]);if(i>0&&i==e[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${t}`);return}break}}this.chain.push(new rt(""));break;case"nth-fragment":e&&e.length==2?this.viewConditionId=`NFS_${e[0]}_${e[1]}`:this.chain.push(new rt(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${t}`);return}this.specificity+=1}}idSelector(t){this.invalidContinuationAfterPseudoelement(`#${t}`)||(this.specificity+=65536,this.chain.push(new K0(t)))}attributeSelector(t,e,i,n,r){if(this.invalidContinuationAfterPseudoelement(`[${e}]`))return;this.specificity+=256,n=n||"";let o;switch(i){case 0:o=new oc(t,e);break;case 39:o=new ix(t,e,n,r??null);break;case 45:!n||n.match(/\s/)?o=new rt(""):o=new dr(t,e,cr(`(^|\\s)${ur(n,r??null)}($|\\s)`),r??null);break;case 44:o=new dr(t,e,cr(`^${ur(n,r??null)}($|-)`),r??null);break;case 43:n?o=new dr(t,e,cr(`^${ur(n,r??null)}`),r??null):o=new rt("");break;case 42:n?o=new dr(t,e,cr(`${ur(n,r??null)}$`),r??null):o=new rt("");break;case 46:n?o=new dr(t,e,cr(ur(n,r??null)),r??null):o=new rt("");break;case 50:if(n=="supported")o=new nx(t,e);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(o)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let t=`d${Uo++}`;this.processChain(new $o(new gx(t,this.viewConditionId,null))),this.chain=this.chain.restartWith(new rt(t)),this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let t=`c${Uo++}`;this.processChain(new $o(new mx(t,this.viewConditionId,null))),this.chain=this.chain.restartWith(new rt(t)),this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let t=`a${Uo++}`;this.processChain(new $o(new yx(t,this.viewConditionId,null))),this.chain=this.chain.restartWith(new rt(t)),this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let t=`f${Uo++}`;this.processChain(new $o(new vx(t,this.viewConditionId,null))),this.chain=this.chain.restartWith(new rt(t)),this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.selectorListVoided||(this.chain=new Ll)}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.ruleId=mo(),this.pseudoelement=null,this.viewConditionId=null,this.specificity=0,this.footnoteContent=!1,this.selectorListVoided=!1,this.pendingChained.splice(0),this.chain=new Ll,this.invalid=!1)}error(t,e){super.error(t,e),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(t){super.startStylesheet(t),this.state=0}startRuleBody(){this.finishChain(),this.selectorListVoided?this.pendingChained.splice(0):this.takePendingChained(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain.finishIn(this)}voidSelector(){this.chain=new ac,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}voidSelectorList(){this.voidSelector(),this.selectorListVoided=!0}applyRuleForSelector(){this.processChain(this.makeApplyRuleAction(this.specificity)),this.voidSelector()}makeApplyRuleAction(t){let e=this.regionId;return this.footnoteContent&&(e?e="xxx-bogus-xxx":e="footnote"),new Fh(this.elementStyle,t,this.pseudoelement,e,this.viewConditionId)}special(t,e){let i;this.condition?i=new Pl(e,0,this.condition):i=new X(e,0),Jf(this.elementStyle,t).push(i)}property(t,e,i){this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}invalidPropertyValue(t,e){this.report(`E_INVALID_PROPERTY_VALUE ${t}: ${e.toString()}`)}unknownProperty(t,e){this.report(`E_INVALID_PROPERTY ${t}: ${e.toString()}`)}simpleProperty(t,e,i){t=="display"&&(e===w.oeb_page_head||e===w.oeb_page_foot)&&(this.simpleProperty("flow-options",new ee([w.exclusive,w._static]),i),this.simpleProperty("flow-into",e,i),e=w.block),zt("SIMPLE_PROPERTY").forEach(o=>{let s=o({name:t,value:e,important:i});t=s.name,e=s.value,i=s.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder();yo(t,e,this.validatorSet);let r=this.condition?new Pl(e,n,this.condition,this.layer,this.ruleId):new X(e,n,this.layer,this.ruleId);ei(this.elementStyle,t,r)}finish(){return this.cascade}startFuncWithSelector(t,e){let i;switch(t){case"is":i=n=>new qn(this,n);break;case"not":i=n=>new Ix(this,n);break;case"where":i=n=>new Ax(this,n);break;case"has":i=n=>new Fx(this,n);break;case"nth-child":e&&e.length>=2&&(i=n=>new fg(this,n,e[0],e[1]));break;case"nth-last-child":e&&e.length>=2&&(i=n=>new Rx(this,n,e[0],e[1]));break}i&&this.owner.delegateTo(n=>{let r=i(n);return r.startSelectorRule(),r})}},Tx={"nth-child":sx,"nth-of-type":Il,"nth-last-child":Al,"nth-last-of-type":Fl},lc=new Set(["dir","href-epub-type","href-role-type","lang","nth-child","nth-last-child","nth-last-of-type","nth-of-type"]),Uo=0,qn=class Ol extends $s{constructor(e,i){super(e.scope,e.owner,e.condition,e,e.regionId,e.validatorSet,i),u(this,"parent",e),u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(this,"selectorTexts",[]),this.parentChain=e.chain}insertChained(e){this.parent.insertChained(e)}takeAlternative(e){this.chains.push(e),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity)}nextSelector(){this.chain.contributeTo(this),this.chain=new Ll,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain.contributeTo(this),this.chains.length>0?(this.parentChain.push(this.relational()?new px(this.selectorTexts):this.positive()?new Lh(this.chains):new dx(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new rt("")),this.endDelegation()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(e,i){super.error(e,i),this.voidAlternative()}pseudoelementSelector(e,i){this.invalidSelector(`Pseudo-element ::${e} in a selector list`)}invalidSelector(e){Y.warn(e),this.setInvalid(),this.voidAlternative()}voidAlternative(){this.voidSelector();let e=this;for(;e instanceof Ol&&!e.forgiving();)e=e.parent,e.voidSelector();e instanceof Ol||(e.voidSelectorList(),this.endDelegation())}pushSelectorText(e){this.relational()&&this.chain.recordTextIn(this.selectorTexts,e)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Ix=class extends qn{positive(){return!1}forgiving(){return!1}},Ax=class extends qn{increasingSpecificity(){return!1}},Fx=class extends qn{relational(){return!0}forgiving(){return!1}},fg=class extends qn{constructor(t,e,i,n){super(t,e),u(this,"a",i),u(this,"b",n)}endFuncWithSelector(){this.chain.contributeTo(this),this.chains.length>0?(this.parentChain.push(new og(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.endDelegation()}forgiving(){return!1}},Rx=class extends fg{endFuncWithSelector(){this.chain.contributeTo(this),this.chains.length>0?(this.parentChain.push(new fx(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new rt("")),this.endDelegation()}},Lx=class extends Jn{constructor(t,e,i){super(t,e,i)}property(t,e,i){if(this.scope.values[t])this.error(`E_CSS_NAME_REDEFINED ${t}`,this.getCurrentToken());else{let n=t.match(/height|^(top|bottom)$/)?"vh":"vw",r=new oo(this.scope,100,n);this.scope.defineName(t,e.toExpr(this.scope,r))}}},hs=class extends Jn{constructor(t,e,i,n,r,o,s,a=null){super(t,e,o),u(this,"condition",i),u(this,"elementStyle",n),u(this,"validatorSet",r),u(this,"ruleType",s),u(this,"layer",a),u(this,"order"),u(this,"ruleId",mo()),this.order=0}property(t,e,i){i?Y.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}invalidPropertyValue(t,e){Y.warn("E_INVALID_PROPERTY_VALUE",`${t}:`,e.toString())}unknownProperty(t,e){Y.warn("E_INVALID_PROPERTY",`${t}:`,e.toString())}simpleProperty(t,e,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Bh,yo(t,e,this.validatorSet);let r=this.condition?new Pl(e,n,this.condition,this.layer,this.ruleId):new X(e,n,this.layer,this.ruleId);ei(this.elementStyle,t,r)}},Ox=class extends bp{constructor(t,e){super(t),u(this,"validatorSet",e),u(this,"elementStyle",{}),u(this,"order",0),u(this,"ruleId",mo())}property(t,e,i){this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}invalidPropertyValue(t,e){Y.warn("E_INVALID_PROPERTY_VALUE",`${t}:`,e.toString())}unknownProperty(t,e){Y.warn("E_INVALID_PROPERTY",`${t}:`,e.toString())}simpleProperty(t,e,i){let n=i?wp:vp;n+=this.order,this.order+=Bh,yo(t,e,this.validatorSet);let r=new X(e,n,null,this.ruleId);ei(this.elementStyle,t,r)}};function gg(t,e){let i=Th(t);i&&i.forEach(n=>{n.matcher.matches()&&e(n.styles)})}function Bl(t,e,i){gg(i,n=>{Br(t,n,e)})}function Bx(t,e,i,n){let r=new Ox(t,e),o=new xt(n,r);try{rw(o,r,i)}catch(s){Y.warn(s,"Style attribute parse error:")}return r.elementStyle}function Ml(t,e,i){let n=t["writing-mode"];if(n){let r=n.evaluate(e,"writing-mode");if(r&&r!==w.inherit&&r!==w.unset&&!Rt(r))return r===w.vertical_rl}return i}function mg(t,e,i){let n=t.direction;if(n){let r=n.evaluate(e,"direction");if(r&&r!==w.inherit&&r!==w.unset&&!Rt(r))return r===w.rtl}return i}function _l(t,e,i,n){let r={};for(let o in t)Ii(o)&&(r[o]=ge(t,o));return Bl(r,e,t),yg(t,i,n,(o,s)=>{Br(r,s,e),Bl(r,e,s)}),r}function yg(t,e,i,n){let r=lt(t,"_regions");if((e||i)&&r){if(i){let o=["footnote"];e?e=e.concat(o):e=o}for(let o of e){let s=r[o];s&&n(o,s)}}}function Br(t,e,i){for(let n in e)if(Ii(n)){let r=ge(e,n),o=t[n];t[n]=Nl(i,o,r)}}var vg=(t,e,i,n,r,o)=>{var s,a;let h=i?n?R0:Xf:n?L0:qf,l=r?O0:B0;for(let c in t){let d=t[c];if(!d)continue;let p=(s=h[c])!=null?s:h[l[c]],f=(a=l[c])!=null?a:l[h[c]],g=p??f,m;if(g){let v=t[g];if(v&&Vi(v,d)>0||p&&f&&p!==f&&(g=f,v=t[g],v&&Vi(v,d)>0))continue;m=tc[p]?p:tc[f]?f:c}else m=c,c.startsWith("text-align")&&(d.value===w.inside||d.value===w.outside)&&(d=d.withValue(r===(d.value===w.inside)?w.right:w.left));e[m]=o(c,d)}},Mx=class wg extends dn{constructor(e,i,n,r,o=null){super(),u(this,"elementStyles",e),u(this,"styles",i),u(this,"root",n),u(this,"element",r),u(this,"currentCustomPropertyName",o),u(this,"resolvingCustomProperties",[]),u(this,"varResolutionState",{cycleMembers:new Set}),o&&this.resolvingCustomProperties.push(o)}getRawCustomPropertyLookup(e,i,n){var r,o;let s=n??this.root;if(i!=null&&i.length){for(let a=0;a<i.length;a++){let h=(r=i[a][e])==null?void 0:r.value;if(h){if(h===w.initial)return{found:!0,value:null,elementStyles:i.slice(a),element:n};if(!(h===w.inherit||h===w.unset||Rt(h)))return{found:!0,value:h,elementStyles:i.slice(a),element:n}}}n&&(s=n.parentElement)}for(;s;s=s.parentElement){let a=this.styles.styleOf(s),h=(o=a?.[e])==null?void 0:o.value;if(h){if(h===w.initial)return{found:!0,value:null,elementStyles:a?[a]:[],element:s};if(!(h===w.inherit||h===w.unset||Rt(h)))return{found:!0,value:h,elementStyles:a?[a]:[],element:s}}}return{found:!1,value:null,elementStyles:[],element:null}}collectReferencedCustomProperties(e){let i=new Set;class n extends Zt{visitFunc(o){let s=o.values[0]instanceof he&&o.values[0].name;return o.name==="var"&&s&&ze(s)&&i.add(s),super.visitFunc(o)}}return e.visit(new n),Array.from(i)}findReferencedCycleStart(e,i,n,r=new Set){for(let o of this.collectReferencedCustomProperties(e)){if(this.resolvingCustomProperties.includes(o))return o;if(r.has(o))continue;r.add(o);let s=this.getRawCustomPropertyLookup(o,i,n),a=s.value&&this.findReferencedCycleStart(s.value,s.elementStyles,s.element,r);if(a)return a}return null}getFallbackCycleMembers(e,i,n){let r=null,o=this;class s extends Zt{visitFunc(l){if(l.name==="var")for(let c of l.values.slice(1)){let d=o.findReferencedCycleStart(c,i,n);if(d)return r=d,l}return super.visitFunc(l)}}if(e.visit(new s),!r)return null;let a=this.resolvingCustomProperties.indexOf(r);return new Set(this.resolvingCustomProperties.slice(a))}resolveCustomProperty(e,i,n,r){if(!i)return{found:!1,value:null,continueLookup:!1};if(i===w.initial)return{found:!0,value:null,continueLookup:!1};if(i===w.inherit||i===w.unset||Rt(i))return{found:!0,value:null,continueLookup:!0};let o=this.getFallbackCycleMembers(i,n,r);return o?(o.forEach(s=>this.varResolutionState.cycleMembers.add(s)),{found:!0,value:null,continueLookup:!1}):{found:!0,value:this.resolveReferencedCustomProperty(e,i,n,r),continueLookup:!1}}resolveReferencedCustomProperty(e,i,n,r){let o=this.resolvingCustomProperties.indexOf(e);if(o>=0)return this.resolvingCustomProperties.slice(o).forEach(d=>this.varResolutionState.cycleMembers.add(d)),null;let s=new Set(this.varResolutionState.cycleMembers);this.varResolutionState.cycleMembers=new Set;let a=new wg(n,this.styles,this.root,r,e);a.resolvingCustomProperties=this.resolvingCustomProperties,a.resolvingCustomProperties.push(e),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([...s,...c]),this.resolvingCustomProperties.pop(),c.has(e)?null:h}getVarValue(e){var i,n,r,o;let s=(i=this.element)!=null?i:this.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(e,(r=h[e])==null?void 0:r.value,this.elementStyles.slice(a),this.element);if(l.found){if(l.value)return l.value;if(!l.continueLookup)return null}}this.element&&(s=this.element.parentElement)}for(;s;s=s.parentElement){let a=this.styles.styleOf(s),h=this.resolveCustomProperty(e,(o=a?.[e])==null?void 0:o.value,a?[a]:[],s);if(h.found){if(h.value)return h.value;if(!h.continueLookup)return null}}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let i=e.values[0]instanceof he&&e.values[0].name;return!i||!ze(i)?(this.error=!0,Ae):this.getVarValue(i)||(this.currentCustomPropertyName&&this.varResolutionState.cycleMembers.has(this.currentCustomPropertyName)?(this.error=!0,Ae):e.values.length<2?(this.error=!0,Ae):e.values.length===2?e.values[1]:new Be(e.values.slice(1)))}visitSpaceList(e){let i=this.visitValues(e.values);if(this.error)return Ae;if(i===e.values)return e;let n=[];for(let r of i)r instanceof ee?n.push(...r.values):n.push(r);return new ee(n)}visitCommaList(e){let i=this.visitValues(e.values);if(this.error)return Ae;if(i===e.values)return e;let n=[];for(let r of i)r instanceof Be?n.push(...r.values):n.push(r);return new Be(n)}},Mh=class extends dn{constructor(t,e,i,n){super(),u(this,"context",t),u(this,"resolveViewportUnit",e),u(this,"percentRef",i),u(this,"vertical",n)}visitFunc(t){let e=super.visitFunc(t);if(t.name!=="calc")return e;let i=e.toString().replace(/^calc\b/,"-epubx-expr");if(this.hasUnresolvableUnit(i))return e;let n=Mi(this.context.rootScope,new xt(i,null),"");if(n instanceof j)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(this.isLengthExpr(i)?e=new B(r,"px"):/\d[a-z]/i.test(i)||(e=new It(r)))}catch(r){Y.warn(r)}return e}hasUnresolvableUnit(t){return/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(t)}isLengthExpr(t){return/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(t)}visitNumeric(t){return this.resolveViewportUnit&&pd(t.unit)||this.context.rootFontSize!=null&&ay(t.unit)?new B(t.num*this.context.queryUnitSize(t.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&t.unit==="%"?new B(t.num*this.percentRef/100,"px"):t}},_x=class extends Mh{hasUnresolvableUnit(t){return/\d(%|em|ex|cap|ch|ic|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(t)}isLengthExpr(t){return/\d(px|in|pt|pc|cm|mm|q|rem|r?lh)\W/i.test(t)}};function Hs(t,e,i,n,r){try{if(e instanceof j)return e.expr instanceof be&&(e.expr.str.startsWith("named-string-")||e.expr.str.startsWith("running-element-"))?e:aw(t,e.expr,i);if(e instanceof B||e instanceof Vt||e instanceof ee||e instanceof Be)return e.visit(new Mh(t,!0,n,r))}catch(o){return Y.warn(o),Ae}return e}var hc={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function uc(t){let e=t instanceof ot?t:typeof t=="string"?_(t):w.none;if(e===w.none)return hc;let i=e instanceof ee?e.values:[e],n=Object.create(hc);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 cc(t){return!t.first&&!t.last&&!t.forceEnd&&!t.allowEnd}var Dx={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},dc={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},pc={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function fc(t){let e=t instanceof ot?t:typeof t=="string"?_(t):w.normal;if(e===w.normal)return dc;if(e===w.auto)return pc;let i=e instanceof ee?e.values:[e],n=Object.create(dc);for(let r of i)if(r instanceof he)switch(r.name){case"trim-both":case"trim-auto":return pc;case"space-all":return Dx;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 _a={ideographAlpha:!1,ideographNumeric:!1},zx={ideographAlpha:!0,ideographNumeric:!0};function gc(t){let e=t instanceof ot?t:typeof t=="string"?_(t):w.normal;if(e===w.normal||e===w.auto)return zx;if(e===w.none)return _a;let i=e instanceof ee?e.values:[e],n=Object.create(_a);for(let r of i)if(r instanceof he)switch(r.name){case"no-autospace":return _a;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function mc(t,e){return!t.ideographAlpha&&!t.ideographNumeric&&!e.trimStart&&!e.spaceFirst&&!e.trimEnd&&!e.allowEnd&&!e.trimAdjacent}function yc(t){return t?(t=t.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(t)?"zh-hant":/^zh\b/.test(t)?"zh-hans":/^ja\b/.test(t)?"ja":/^ko\b/.test(t)?"ko":t):null}var Vx=/^[‘’“”〰﹙﹚﹛﹜﹝﹞〚〛]\p{M}*$/u,$x=/^[‘“﹙﹛﹝〚]\p{M}*$/u;function Hx(t,e){return no==="chromium"&&e&&Vx.test(t)}function Ux(t){return $x.test(t)?"viv-ts-open":"viv-ts-close"}var Wx=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(t){t.body&&this.preprocessForTextSpacing(t.body)}preprocessForTextSpacing(t){var e;let i=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){let r=n.parentElement;if(!r||r.namespaceURI!=="http://www.w3.org/1999/xhtml"||((e=r.dataset)==null?void 0:e.mathTypeset)==="true")continue;let o=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000\u3030]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000\u3030])|(?!\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(o.length>1){let s=o.length-1;for(let a=0;a<s;a++)n.before(document.createTextNode(o[a]));n.textContent=o[s]}}}processGeneratedContent(t,e,i,n,r,o){r=yc(r);let s=gc(e),a=fc(i),h=uc(n);if(cc(h)&&mc(s,a))return;this.preprocessForTextSpacing(t);let l=t.style.whiteSpace;(o?t.offsetHeight:t.offsetWidth)===0&&(t.style.whiteSpace="pre");let c=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=c.nextNode();f;f=p){p=c.nextNode();let g=!d,m=!d||/\n$/.test(d.textContent),v=!p||/^\n/.test(p.textContent),b=!p;this.processTextSpacing(f,g||m,g,m,v,b,d,p,s,a,h,r,o),d=f}t.style.whiteSpace=l}postLayoutBlock(t,e){var i,n,r,o,s,a,h,l;let c=!t||t.fragmentIndex===1&&f(),d=c||m();function p(C){var y;if(C?.nodeType!==1)return!1;let k=C;if(k.hasAttribute(Un))return!0;let{position:S,float:N}=(y=k.style)!=null?y:{};return S==="absolute"||S==="fixed"||!!(N&&N!=="none")}function f(){let C=e[0];for(let y=C;;y=y.parent)if(!y||!y.inline){if(y?.fragmentIndex!==1)return!1;break}if(!C.inline)return!0;for(let y=C.viewNode.previousSibling;y;y=y.previousSibling)if(!Ee(y,C.whitespace)&&!p(y))return!1;return!0}function g(){var C;for(let y=e[0];y&&y.inline;y=y.parent){let k=(C=y.viewNode)==null?void 0:C.previousSibling,S=k&&k.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(k.textContent)&&y.whitespace!==bt.PRESERVE?k.previousSibling:k;if(S)return{nodeContext:y,prevNode:S}}return null}function m(){var C;let y=g();if(!y)return!1;let k=y.nodeContext;for(let S=y.prevNode;S;S=S.lastChild)if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let N=(C=S.style)==null?void 0:C.display;if(N&&N!=="inline")return!/^(inline|ruby)\b/.test(N)}else if(S.nodeType===Node.TEXT_NODE){if(k.whitespace===bt.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(k.whitespace===bt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}return!1}let v=-1;for(let C=0;C<e.length;C++){let y=e[C],k=!y.after&&y.inline&&!y.display?uh(y):null;if(k&&k.viewNode.parentNode&&!Ee(k.viewNode,k.whitespace)){let S=function(O){var T,$,G;if(((T=O.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return O.viewNode.localName==="br";if((($=O.viewNode)==null?void 0:$.nodeType)===Node.TEXT_NODE){let q=O.viewNode;if(O.whitespace===bt.PRESERVE){if(/\n$/.test(q.textContent))return!0}else if(O.whitespace===bt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(q.textContent))return!0;if(((G=q.previousElementSibling)==null?void 0:G.localName)==="br")return Ee(q,O.whitespace)}return!1},N=function(O){var T,$,G;if(((T=O.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return O.viewNode.localName==="br";if((($=O.viewNode)==null?void 0:$.nodeType)===Node.TEXT_NODE){let q=O.viewNode;if(O.whitespace===bt.PRESERVE){if(/^\n/.test(q.textContent))return!0}else if(O.whitespace===bt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(q.textContent))return!0;if(((G=q.nextElementSibling)==null?void 0:G.localName)==="br")return Ee(q,O.whitespace)}return!1};var b=S,x=N;v<0&&(v=C);let L=yc((o=(n=(i=k.lang)!=null?i:k.parent.lang)!=null?n:t?.lang)!=null?o:(r=t?.parent)==null?void 0:r.lang),I=gc(k.inheritedProps["text-autospace"]),D=fc(k.inheritedProps["text-spacing-trim"]),J=uc(k.inheritedProps["hanging-punctuation"]);if(cc(J)&&mc(I,D)||/\b(flex|grid)\b/.test((s=k.parent.display)!=null?s:""))continue;let te=null,P=null,M=C===v,A=C===v&&c,H=C===v&&d,z=!1,E=!1;for(let O=C-1;O>=0;O--){let T=e[O];if(S(T)){H=!0;break}if(!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){te=T.viewNode;break}if(((a=T.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&Qt(T.viewNode)==="footnote-call"){if(T.viewNode.contains(k.viewNode))continue;let $=qw(T.viewNode);if($){te=$;break}}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((h=T.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||tn[T.viewNode.localName]))break;O===0&&(M=!0,c&&(A=!0,H=!0))}for(let O=C+1;O<e.length;O++){let T=e[O];if(N(T)){z=!0;break}if(T.viewNode!==k.viewNode&&!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){P=T.viewNode;break}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((l=T.viewNode)==null?void 0:l.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||tn[T.viewNode.localName])){O===e.length-1&&p(T.viewNode)&&(E=!0);break}if(O===e.length-1){z=!0,E=!0;for(let $=T.viewNode.nextSibling;$;$=$.nextSibling)if(!p($)){E=!1;break}}}if(k.parent.display==="inline-block"){let O=Lt(k.parent);if(!A){let T=O.viewNode.firstChild;for(;Ee(T,k.whitespace);)T=T.nextSibling;k.viewNode===T&&(A=!0)}if(!E){let T=O.viewNode.lastChild;for(;Ee(T,k.whitespace);)T=T.previousSibling;k.viewNode===T&&(E=!0)}}if(this.processTextSpacing(k.viewNode,M,A,H,z,E,te,P,I,D,J,L,k.vertical)>0)break}}}processTextSpacing(t,e,i,n,r,o,s,a,h,l,c,d,p){var f,g;let m=t.textContent,v=t.ownerDocument,b=0,x,C,y;function k(){if(e)return!0;if(!s)return!1;x||(x=v.createRange(),x.selectNode(t));let E=x.getClientRects()[0];if(!E)return!1;C||(C=v.createRange(),C.selectNode(s));let O=C.getClientRects(),T=O[O.length-1];return T?(b||(b=Gr(T,p)),p?E.top<T.top+T.height-E.width||E.left+E.width<T.left+E.width/10||E.left>T.left+T.width-E.width/10:E.left<T.left+T.width-E.height||E.top>T.top+T.height-E.height/10||E.top+E.height<T.top+E.height/10):!1}function S(){if(!a)return!1;x||(x=v.createRange(),x.selectNode(t));let E=x.getClientRects()[0];if(!E)return!1;b||(b=Gr(E,p)),y||(y=v.createRange(),y.selectNode(a));let O=y.getClientRects()[0];return O?p?E.top+E.height>O.top+E.width||E.left>O.left+O.width-E.width/10||E.left+E.width<O.left+E.width/10:E.left+E.width>O.left+E.height||E.top+E.height<O.top+E.height/10||E.top>O.top+O.height-E.height/10:!1}let N=!1,L=!1,I=!1,D=!1,J,te=Hx(m,p);if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(m)?(J="viv-ts-open",L=!0):o&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(m)?(J="viv-ts-close",I=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(m)?(J="viv-ts-close",D=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(m)?J="viv-ts-open":(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(m)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(m)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(m))?J="viv-ts-close":te&&(J=Ux(m),N=!0),J!==void 0){let E=function(q){let Q=parseFloat(v.defaultView.getComputedStyle(q).fontSize)*.7;return(p?q.offsetHeight:q.offsetWidth)>Q},O=function(){return p?T.offsetLeft:T.offsetTop};var P=E,M=O;if(((f=t.parentElement)==null?void 0:f.localName)==="viv-ts-inner")return 0;let T=v.createElement(J),$=v.createElement("viv-ts-inner");if(T.appendChild($),t.before(T),$.appendChild(t),te&&v.defaultView.getComputedStyle(T).textOrientation==="mixed"&&($.style.textOrientation="sideways"),N)return 0;let G=E($);if(G||L||I||D){if(J==="viv-ts-open"){if(L)T.className="viv-hang-first";else if(i||n)l.trimStart?T.className="viv-ts-trim":T.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&k())T.className="viv-ts-space";else if(l.trimAdjacent&&s&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(s.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(s.textContent)||((g=s.parentElement)==null?void 0:g.localName)==="viv-ts-inner"&&E(s.parentElement)))T.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&k()){let q=O();T.className="viv-ts-auto",q===O()&&!k()&&(T.className="viv-ts-trim")}}else if(J==="viv-ts-close"){if(I)T.className=G?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||r){let q=O();D?(T.className=G?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&q===O()&&(l.trimEnd?T.className="viv-ts-trim":l.allowEnd?(T.className="viv-hang-end",q===O()&&(T.className="")):T.className="viv-ts-space")):l.trimEnd?T.className="viv-ts-trim":l.allowEnd?(T.className="viv-ts-auto",q===O()&&(T.className="")):T.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))G&&l.trimAdjacent&&(T.className="viv-ts-trim");else if(D){let q=S(),Q=q&&c.allowEnd;Q||(T.className=G?"viv-hang-end":"viv-hang-end viv-hang-hw"),G?Q&&l.trimEnd?T.className="viv-ts-auto":!Q&&!S()?T.className="":!q&&c.allowEnd&&(l.trimEnd?(T.className="viv-ts-auto",S()||(T.className="viv-hang-end")):(T.className="viv-ts-space",S()||(l.allowEnd?(T.className="viv-ts-auto",S()||(T.className="viv-hang-end")):T.className="viv-hang-end"))):!q&&!S()&&(T.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?T.className="viv-ts-space":T.className="viv-ts-auto";else{let q=O();T.className="viv-ts-auto",q===O()&&(T.className="")}}}}let A=!1;function H(E){var O;let T=(O=E?.ownerDocument.defaultView)==null?void 0:O.getComputedStyle(E);return!!T&&(T.textOrientation==="upright"||T.textCombineUpright==="all"||T["-webkit-text-combine"]==="horizontal")}function z(E,O){if(E.nodeType===Node.ELEMENT_NODE){let G=v.defaultView.getComputedStyle(E);if(parseFloat(G.marginInlineEnd)||parseFloat(G.borderInlineEndWidth)||parseFloat(G.paddingInlineEnd))return!0}let T=E.parentElement;if(T&&!T.contains(O))return z(T,O);if(O.nodeType===Node.ELEMENT_NODE){let G=v.defaultView.getComputedStyle(O);if(parseFloat(G.marginInlineStart)||parseFloat(G.borderInlineStartWidth)||parseFloat(G.paddingInlineStart))return!0}let $=O.parentElement;return $&&!$.contains(E)?z(E,$):!1}return(h.ideographAlpha||h.ideographNumeric)&&(s&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(m)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(s.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(s.textContent))&&!(p&&s.parentElement!==null&&H(s.parentElement))&&!z(s,t)&&(t.before(v.createElement("viv-ts-thin-sp")),A=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(m)&&(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&&a.parentElement!==null&&H(a.parentElement))&&!z(t,a)&&(t.after(v.createElement("viv-ts-thin-sp")),A=!0)),b}registerHooks(){Ft("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Ft("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Ft("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},_h=new Wx;_h.registerHooks();function Gx(t){_h.preprocessForTextSpacing(t)}function jx(t,e,i,n,r,o){_h.processGeneratedContent(t,e,i,n,r,o)}var xr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Xx=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],Dh="data-adapt-pseudo";function Qt(t){return t.getAttribute(Dh)||""}function Mr(t,e){t.setAttribute(Dh,e)}var Da=class{constructor(t,e,i,n,r){u(this,"element",t),u(this,"style",e),u(this,"styler",i),u(this,"context",n),u(this,"exprContentListener",r),u(this,"contentProcessed",{}),u(this,"afterStyleTaken",!1)}getStyle(t,e){let i=Qt(t);!this.afterStyleTaken&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.afterStyleTaken=!0);let n=lt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let o=1,s;i=="first-letter"?o=0:(s=i.match(/^first-([0-9]+)-lines$/))!=null&&(o=s[1]-0),r["x-first-pseudo"]=new X(new ht(o),0)}return r}processContent(t,e,i){let n=Qt(t);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=e.content;At(r)&&(r.visit(new Wr(t,this.context,r,this.exprContentListener)),Gx(t))}}},Rk=bs.isInstanceOfAfterIfContinuesLayoutConstraint,qx=ha.registerFragmentIndex,Lk=ha.clearFragmentIndices,Yx=class{constructor(t,e){u(this,"sourceNode",t),u(this,"styler",e)}createElement(t,e){let i=e.viewNode.ownerDocument.createElement("div"),n=new zh(t,i,e),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let o=i.firstChild;return R(o,"display","block"),F(o)})}createNodePositionForPseudoElement(){let t=xr.createElementNS("http://www.w3.org/1999/xhtml","div");Mr(t,"after-if-continues");let e=this.createShadowContext(t),i={steps:[{node:t,shadowType:e.type,shadowContext:e,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new zi(i)}createShadowContext(t){return new Zo(this.sourceNode,t,null,null,null,wi.ShadowType.ROOTED,this.styler)}},Zx=class bg{constructor(e,i,n){u(this,"nodeContext",e),u(this,"afterIfContinues",i),u(this,"pseudoElementHeight",n),u(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(e,i,n){return!(i&&!e||e&&e.overflow)}nextCandidate(e){return!1}postLayout(e,i,n,r){}finishBreak(e,i){return this.getRepetitiveElements().affectTo(e)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),F(!0))):F(!0)}getRepetitiveElements(){return new Kx(this.nodeContext,this.pseudoElementHeight)}equalsTo(e){return e instanceof bg?this.afterIfContinues==e.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},Kx=class{constructor(t,e){u(this,"nodeContext",t),u(this,"pseudoElementHeight",e)}calculateOffset(t){return this.affectTo(t)?this.pseudoElementHeight:0}calculateMinimumOffset(t){return this.calculateOffset(t)}affectTo(t){if(!t)return!1;let e=t.shadowContext?t.shadowContext.owner:t.sourceNode;if(e===this.nodeContext.sourceNode)return!!t.after;for(let i=e.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function xg(t,e){let i=t&&Dw(t);if(!i||i.after||e.asFloatNodeContext(i))return F(t);let n=i.afterIfContinues,r=i;return n.createElement(e,r).thenAsync(o=>{let s=Qx(r,e,o);return e.fragmentLayoutConstraints.push(new Zx(r,n,s)),F(t)})}function Sg(t,e){return t.thenAsync(i=>xg(i,e))}function Jx(t,e){let i=V("processAfterIfContinuesOfAncestors"),n=t;return i.loop(()=>{if(n!==null){let r=xg(n,e);return n=n.parent,r.thenReturn(!0)}else return F(!1)}).then(()=>{i.finish(!0)}),i.result()}function Qx(t,e,i){let n=t.viewNode;n.appendChild(i);let r=ul(i,e,t.vertical);return n.removeChild(i),r}var eS=class{constructor(t){u(this,"constraints",t)}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},Sr=class extends vh{constructor(t,e){super(),u(this,"checkPoints",t),u(this,"penalty",e),u(this,"alreadyEvaluated",!1),u(this,"breakNodeContext",null)}findAcceptableBreak(t,e){return e<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=t.findBoxBreakPosition(this,e>0),this.alreadyEvaluated=!!this.breakNodeContext||e>0||!!t.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Us=class extends Vp{constructor(t,e,i,n,r,o,s,a,h){super(t),u(this,"layoutContext",e),u(this,"clientLayout",i),u(this,"layoutConstraint",n),u(this,"flowRootFormattingContext",h),u(this,"last"),u(this,"viewDocument"),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,"chunkPositions",[]),u(this,"bands"),u(this,"overflown",!1),u(this,"breakPositions",[]),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),u(this,"lineFootnoteOverflowEdge",null),u(this,"pageFloatLayoutContext"),Hw(this),this.last=t.lastChild,this.viewDocument=t.ownerDocument,this.pageFloatLayoutContext=r.withContainer(this),zp(o,this),this.innerShape=s,this.exclusions=a,this.bands=this.measure(),this.createFloats()}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}asFloatNodeContext(t){let e=Lt(t);return e&&e.floatSide&&(!this.isFloat||e.parent)?e:null}stopByOverflow(t){return this.stopAtOverflow&&!!t&&t.overflow}almostEquals(t,e,i=this.clientLayout.pixelRatio===0?.5:1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(t-e)<i}getFloatLayoutUnit(){return this.clientLayout.pixelRatio===0?0:1/(this.clientLayout.pixelRatio||1)}getFloatLayoutTolerance(t){return t||1}isOverflown(t){let e=1.5/(this.clientLayout.pixelRatio||1);return this.almostEquals(t,this.footnoteEdge,e)?!1:this.vertical?t<this.footnoteEdge:t>this.footnoteEdge}getExclusions(){let t=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(t)}openAllViews(t){let e=V("openAllViews"),i=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return e.loop(()=>{for(;n>=0;){let o=r;if(r=o?Ss(i[n],o):Fw(Rw(t),this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),r.after=t.after,r.preprocessedTextContent=t.preprocessedTextContent,r.after))break;let s=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,s.isPending())return s}return F(!1)}).then(()=>{e.finish(r)}),e.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?bw(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,e){var i,n,r;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0){let o=uh(t);if(o){let s=o.viewNode,a=s.textContent,h=a.match(ps),l=h?h[0].length:0;if(!h&&((i=t.sourceNode)==null?void 0:i.nodeType)===3&&((n=t.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&a===t.sourceNode.textContent){let c=a+t.sourceNode.nextSibling.textContent,d=c.match(ps);if(d){let p=d[0];l=p.length,t.sourceNode.textContent=p,s.textContent=p,t.sourceNode.nextSibling.textContent=c.substr(l)}}if(l>0){let c=(r=s.textContent)!=null?r:"";s.textContent=c.substr(0,l)}return this.layoutContext.peelOff(o,l)}}return F(t)}buildViewToNextBlockEdge(t,e){let i=!1,n=V("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var o;let s=Yi(t);if(s&&!Ln(s)&&((o=s.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(e.push(s.copy()),e.length>1e3)){let a=s.viewNode.nodeType===1?s.viewNode:s.viewNode.parentElement,h=this.clientLayout.getElementClientRect(a);if(Gr(h,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let h=a;if(h!==t){t=h;let l=Yi(h);l&&!Ln(l)&&e.push(l.copy())}this.nextInTree(t).then(l=>{if(t=l,!t){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(t))&&(i=!0,t=t.modify(),t.overflow=!0);let c=this.asFloatNodeContext(t);c&&(Li(c.floatReference)||c.floatSide==="footnote")?this.layoutFloatOrFootnote(c).then(d=>{if(t=d,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){r.breakLoop();return}if(t.pluginProps.lineFootnoteOverflow){r.breakLoop();return}r.continueLoop()}):t.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(t)}),n.result()}nextInTree(t,e){let i=this.layoutContext.nextInTree(t,e);return Sg(i,this)}buildDeepElementView(t){if(!t.viewNode)return F(t);let e=[],i=t.sourceNode,n=V("buildDeepElementView");return n.loopWithFrame(r=>{let o=Yi(t);o&&o.inline&&!Ln(o)?e.push(o.copy()):(e.length>0&&this.postLayoutBlock(t,e),e=[]),this.maybePeelOff(t,0).then(s=>{let a=s;if(a!==t){let h=a;for(;h&&h.sourceNode!=i;)h=h.parent;if(h==null){t=a,r.breakLoop();return}let l=Yi(a);l&&!Ln(l)&&e.push(l.copy())}this.nextInTree(a).then(h=>{if(t=h,!t||t.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(t)&&(t=t.modify(),t.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}let l=this.asFloatNodeContext(t);if(l&&(Li(l.floatReference)||l.floatSide==="footnote")){this.layoutFloatOrFootnote(l).then(c=>{if(t=c,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{e.length>0&&this.postLayoutBlock(t,e),n.finish(t)}),n.result()}createFloat(t,e,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),R(r,"height",`${i}px`),R(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),R(r,"width",`${i}px`),R(r,"height",`${n}px`)),R(r,"float",e),R(r,"clear",e),this.element.insertBefore(r,t),r}killFloats(){let t=this.element.firstChild;for(;t;){let e=t.nextSibling;if(t.nodeType==1){let i=t,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}t=e}}createFloats(){let t=this.element.firstChild,e=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),o=this.vertical?-this.getLeftEdge():this.getBottomEdge(),s=null,a=1.5/(this.clientLayout.pixelRatio||1);for(let p of e){let f=Math.abs(p.x1-i)<a&&Math.abs(p.x2-n)<a?a:void 0;this.almostEquals(p.x1,i,f)?p.x1=i:this.almostEquals(p.x1,n,f)&&(p.x1=n),this.almostEquals(p.x2,n,f)?p.x2=n:this.almostEquals(p.x2,i,f)&&(p.x2=i),this.almostEquals(p.y1,r,f)?p.y1=r:this.almostEquals(p.y1,o,f)&&(p.y1=o),this.almostEquals(p.y2,o,f)?p.y2=o:this.almostEquals(p.y2,r,f)&&(p.y2=r)}let h=this.getFloatLayoutUnit(),l=no==="webkit"?Math.floor:Math.round,c=e.map(p=>h>0?(l(p.y2/h)-l(p.y1/h))*h:p.y2-p.y1),d=.01;for(let p=0;p<e.length;p++){let f=p<e.length-1?e[p+1].x1:i,g=p<e.length-1?e[p+1].x2:n,m=f-e[p].x1,v=e[p].x2-g,b=0,x=0;m>d?b=1:m<-d&&(b=-1),v>d?x=1:v<-d&&(x=-1);let C=b!==0&&x!==0?b===x?b:0:b||x;if(h>0&&C!==0){let y=C*h;c[p]+y>=0&&(p>=e.length-1||c[p+1]-y>=0)&&(c[p]+=y,p<e.length-1&&(c[p+1]-=y))}}for(let p=0;p<e.length;p++){let f=e[p];f.left=this.createFloat(t,"left",f.x1-i,c[p]),f.right=this.createFloat(t,"right",n-f.x2,c[p]),f.x1<n&&f.x2>i?s=f:s||R(f.right,"float","none")}if(s){let p=e[e.length-1],f=1.5/(this.clientLayout.pixelRatio||1);if(s!==p&&(p.y2>=o||this.almostEquals(p.y2,o,f))&&(this.footnoteEdge=this.vertical?-s.y2:s.y2,s.x1===i&&s.x2===n))for(let g=e.indexOf(s);g<e.length;g++){let m=e[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var t;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(t=this.element.parentElement)!=null&&t.hasAttribute("data-vivliostyle-in-column-balancing"))return;let e=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),n=1.5/(this.clientLayout.pixelRatio||1);if(i>0&&i<e&&!this.almostEquals(i,e,n)){let r=this.vertical?"width":"height";if(R(this.element,r,`${i}px`),this.vertical){let o=this.left+(e-i);R(this.element,"left",`${o}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(t,e,i,n){let r;if(t&&Rn(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(r=Tn(t,this.clientLayout,0,this.vertical),!isNaN(r)))return r;t=e[i];let o=n-t.boxOffset;for(;;){if(r=Tn(t,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(i--,i<0)return this.beforeEdge;let s=e[i];t=s,s.viewNode.nodeType!=1&&(o=s.viewNode.textContent.length)}}parseComputedLength(t){let e=t.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return e?this.clientLayout.adjustLengthValue(parseFloat(e[0])):0}getComputedMargin(t){let e=this.clientLayout.getElementComputedStyle(t),i=new Sa(0,0,0,0);return e&&(i.left=this.parseComputedLength(e.marginLeft),i.top=this.parseComputedLength(e.marginTop),i.right=this.parseComputedLength(e.marginRight),i.bottom=this.parseComputedLength(e.marginBottom)),i}getComputedPaddingBorder(t){let e=this.clientLayout.getElementComputedStyle(t),i=new Sa(0,0,0,0);return e&&(i.left=this.parseComputedLength(e.borderLeftWidth)+this.parseComputedLength(e.paddingLeft),i.top=this.parseComputedLength(e.borderTopWidth)+this.parseComputedLength(e.paddingTop),i.right=this.parseComputedLength(e.borderRightWidth)+this.parseComputedLength(e.paddingRight),i.bottom=this.parseComputedLength(e.borderBottomWidth)+this.parseComputedLength(e.paddingBottom)),i}getComputedInsets(t){let e=this.clientLayout.getElementComputedStyle(t),i=new Sa(0,0,0,0);if(e){if(e.boxSizing=="border-box")return this.getComputedMargin(t);i.left=this.parseComputedLength(e.marginLeft)+this.parseComputedLength(e.borderLeftWidth)+this.parseComputedLength(e.paddingLeft),i.top=this.parseComputedLength(e.marginTop)+this.parseComputedLength(e.borderTopWidth)+this.parseComputedLength(e.paddingTop),i.right=this.parseComputedLength(e.marginRight)+this.parseComputedLength(e.borderRightWidth)+this.parseComputedLength(e.paddingRight),i.bottom=this.parseComputedLength(e.marginBottom)+this.parseComputedLength(e.borderBottomWidth)+this.parseComputedLength(e.paddingBottom)}return i}setComputedInsets(t,e){let i=this.clientLayout.getElementComputedStyle(t);i&&(e.marginLeft=this.parseComputedLength(i.marginLeft),e.borderLeft=this.parseComputedLength(i.borderLeftWidth),e.paddingLeft=this.parseComputedLength(i.paddingLeft),e.marginTop=this.parseComputedLength(i.marginTop),e.borderTop=this.parseComputedLength(i.borderTopWidth),e.paddingTop=this.parseComputedLength(i.paddingTop),e.marginRight=this.parseComputedLength(i.marginRight),e.borderRight=this.parseComputedLength(i.borderRightWidth),e.paddingRight=this.parseComputedLength(i.paddingRight),e.marginBottom=this.parseComputedLength(i.marginBottom),e.borderBottom=this.parseComputedLength(i.borderBottomWidth),e.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(t,e){let i=this.clientLayout.getElementComputedStyle(t);i&&(e.width=this.parseComputedLength(i.width),e.height=this.parseComputedLength(i.height))}layoutUnbreakable(t){return this.buildDeepElementView(t)}layoutFloat(t){let e=V("layoutFloat"),i=t.viewNode,n=Ta(t.floatSide,t.vertical,t.direction,this.layoutContext.page.side);return R(i,"float","none"),R(i,"display","inline-block"),R(i,"vertical-align","top"),this.buildDeepElementView(t).then(r=>{let o=_t(this.clientLayout,i,this.vertical),s=this.getComputedMargin(i),a=new Dt(o.left-s.left,o.top-s.top,o.right+s.right,o.bottom+s.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=t.parent;for(;c&&c.inline;)c=c.parent;let d=c&&Yi(c);if(d){let k=d.viewNode,S=k.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"),k.appendChild(S);let N=_t(this.clientLayout,S,this.vertical);h=Math.max(this.rtl?this.getEndEdge(N):this.getStartEdge(N),h),l=Math.min(this.rtl?this.getStartEdge(N):this.getEndEdge(N),l),k.removeChild(S);let L=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+L):h=Math.min(h,l-L),c!==t.parent&&!t.firstPseudo&&(k.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new Dt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),f=a;this.vertical&&(f=ys(a));let g=this.getBoxDir();if(f.y1<this.bottommostFloatTop*g){let k=f.y2-f.y1;f.y1=this.bottommostFloatTop*g,f.y2=f.y1+k}if(t.clearSide){let k=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(t.clearSide)?Ta(t.clearSide,t.vertical,t.direction,this.layoutContext.page.side):t.clearSide==="same"?n:t.clearSide,S=this.beforeEdge;k!=="right"&&(S=g*Math.max(S*g,this.leftFloatEdge*g)),k!=="left"&&(S=g*Math.max(S*g,this.rightFloatEdge*g));let N=S*g;if(f.y1<N){let L=f.y2-f.y1;f.y1=N,f.y2=f.y1+L}}p.y2+=this.getFloatLayoutUnit(),_y(p,this.bands,f,n),this.vertical&&(a=Wd(f));let m=this.getComputedInsets(i);R(i,"width",`${a.x2-a.x1-m.left-m.right}px`),R(i,"height",`${a.y2-a.y1-m.top-m.bottom}px`),R(i,"position","absolute"),t.display,R(i,"display",t.display);let v,b=c?c.containingBlockForAbsolute?Lt(c):c.getContainingBlockForAbsolute():null;if(b){let k=b.viewNode,S=k.ownerDocument.createElement("div");S.style.position="absolute",b.vertical?S.style.right="0":S.style.left="0",S.style.top="0",k.appendChild(S),v=_t(this.clientLayout,S,this.vertical),k.removeChild(S)}else v={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(b?b.vertical:this.vertical){let k=Math.max(0,v.right-a.x2);R(i,"right",`${k}px`)}else{let k=Math.max(0,a.x1-v.left);R(i,"left",`${k}px`)}let x=Math.max(0,a.y1-v.top);R(i,"top",`${x}px`),t.clearSpacer&&(t.clearSpacer.remove(),t.clearSpacer=null);let C=this.vertical?a.x1:a.y2,y=this.vertical?a.x2:a.y1;!this.isOverflown(C)||this.breakPositions.length==0?(this.killFloats(),p=new Dt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=ys(p)),Dy(p,this.bands,f,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=C:this.rightFloatEdge=C,this.bottommostFloatTop=y,this.updateMaxReachedAfterEdge(C),e.finish(r)):(t=t.modify(),t.overflow=!0,e.finish(t))}),e.result()}setupFloatArea(t,e,i,n,r,o){let s=this.pageFloatLayoutContext,a=s.getPageFloatLayoutContext(e).container,h=t.element;return r.adjustPageFloatArea(t,a,this).thenAsync(()=>{t.killFloats(),t.remeasure();let l=!!s.setFloatAreaDimensions(t,e,i,n,!0,t.isFootnote||!s.hasFloatFragments(),o);if(l){if(t.isFootnote){let c=getComputedStyle(t.element);if(t.vertical){let d=parseFloat(c.maxWidth);!isNaN(d)&&t.width>d&&(t.width=d,R(t.element,"width",`${d}px`))}else{let d=parseFloat(c.maxHeight);!isNaN(d)&&t.height>d&&(t.height=d,R(t.element,"height",`${d}px`))}}t.killFloats(),t.remeasure()}else h.remove();return F(l)})}createPageFloatArea(t,e,i,n,r){let o=this.element.ownerDocument.createElement("div");R(o,"position","absolute");let s=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),a=Oi.createDetached(this.pageFloatLayoutContext,Ne.COLUMN,this.pageFloatLayoutContext.flowName,t.nodePosition),h=s.container,l=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference).container;l.element.parentNode.appendChild(o);let c=l.getPaddingRect(),d=c.x1-l.originX,p=c.y1-l.originY;R(o,"left",`${d}px`),R(o,"top",`${p}px`);let f=new nS(e,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h,{vertical:l.vertical,rtl:l.rtl,snapWidth:0,snapHeight:0,originX:l.originX,originY:l.originY,left:d,top:p,width:c.x2-c.x1,height:c.y2-c.y1,marginLeft:0,marginRight:0,marginTop:0,marginBottom:0,borderLeft:0,borderRight:0,borderTop:0,borderBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,paddingBottom:0,borderBoxSizing:!1},null,(l.exclusions||[]).concat(),this.flowRootFormattingContext);return f.isFloat=!0,f.forceNonfitting=!this.pageFloatLayoutContext.hasFloatFragments(),this.setupFloatArea(f,t.floatReference,e,i,n,r).thenAsync(g=>F(g?f:null))}layoutSinglePageFloatFragment(t,e,i,n,r,o,s){let a=this.pageFloatLayoutContext;t=(s?s.continuations:[]).concat(t);let h=t[0].float,l=a.getPageFloatPlacementCondition(h,e,i),c={floatArea:null,pageFloatFragment:null,newPosition:null},d=V("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,e,o,r,l).then(p=>{if(c.floatArea=p,!p){d.finish(c);return}let f=!1,g=0;d.loopWithFrame(m=>{if(g>=t.length){m.breakLoop();return}let v=t[g],b=new zi(v.nodePosition),x=p.getRootViewNodeCount();p.layout(b,!0).then(C=>{if(c.newPosition=C,!C||n){if(C&&p.isFootnote&&p.breakPositions&&!(p.breakPositions.some(y=>y instanceof Sr)&&p.hasNonPseudoTextContentAfter(x))){f=!0,m.breakLoop();return}g++,m.continueLoop()}else f=!0,m.breakLoop()})}).then(()=>{if(!f&&p.isFootnote&&p.computedBlockSize<=0&&c.newPosition){let m=a.getPageFloatLayoutContext(h.floatReference);if(m.footnoteMaxBlockSize==null){if(m.initFootnoteRetryFromEmptyFragment(h,p)){p.element.parentNode&&p.element.parentNode.removeChild(p.element),this.layoutSinglePageFloatFragment(t,e,i,n,r,o,s).then(v=>{d.finish(v)});return}f=!0}}if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,e,o,!1,n,l);if(!m)f=!0;else{let v=r.createPageFloatFragment(t,m,i,p,!!c.newPosition);a.addPageFloatFragment(v,!0),c.pageFloatFragment=v}}d.finish(c)})}),d.result()}layoutPageFloatInner(t,e,i,n){let r=this.pageFloatLayoutContext,o=t.float,s=o instanceof jr,a=s&&o.footnotePolicy===w.line&&!!n&&!n.hasFloat(o),h=new Set;for(let d=r;d;d=d.effectiveParent)for(let p of d.floatFragments)p.continuations.some(f=>f.float.insidePageFloatArea)&&h.add(p);a||r.stashEndFloatFragments(o);function l(d,p){p?r.removePageFloatFragment(p,!0):d&&d.element.parentNode.removeChild(d.element);let f=[];for(let g=r;g;g=g.effectiveParent)for(let m of g.floatFragments)!h.has(m)&&m.continuations.some(v=>v.float.insidePageFloatArea)&&f.push(m);for(let g of f)r.removePageFloatFragment(g,!0);r.restoreStashedFragments(o.floatReference),r.deferPageFloat(t)}let c=V("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],o.floatSide,o.clearSide,s||!r.hasFloatFragments(),e,i,a?null:n).then(d=>{let p=d.floatArea,f=d.pageFloatFragment,g=d.newPosition;f?this.layoutStashedPageFloats(o.floatReference,[n]).then(m=>{if(m){let v=f;if(a&&n){let y=n.area,k=y.getRootViewNodeCount();if(y.appendContentFrom(f.area),r.removePageFloatFragment(f,!0),!r.setFloatAreaDimensions(y,o.floatReference,n.floatSide,i,!1,!0,r.getPageFloatPlacementCondition(o,o.floatSide,o.clearSide))){y.removeContentAfter(k),l(p,f),c.finish(!1);return}n.addContinuations(f.continuations),v=n}let b=!!r.generatingNodePosition,x=!b&&o instanceof jr&&o.footnotePolicy===w.line,C=x&&r.hasInvalidatedForLineFootnote(o);if(r.addPageFloatFragment(v,b||C),x&&!C&&r.markInvalidatedForLineFootnote(o),r.discardStashedFragments(o.floatReference),g){let y=new Vu(o,g.primary);r.deferPageFloat(y)}c.finish(!0)}else l(p,f),c.finish(!1)}):(l(p,f),c.finish(!1))}),c.result()}layoutStashedPageFloats(t,e){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(t),r=[],o=[],s=!1,a=V("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let c=n[h];if(e.includes(c)){h++,l.continueLoop();return}let d=new Wn().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?(o.push(g),h++,l.continueLoop()):(s=!0,l.breakLoop())})}).then(()=>{s?(o.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(!s)}),a.result()}findFootnoteCallElement(t){let e=t.previousSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE&&Qt(e)==="footnote-call")return e;e=e.previousSibling}return null}setFloatAnchorViewNode(t){let e=t.viewNode.ownerDocument.createElement("span");if(e.setAttribute(Un,"1"),t.floatSide==="footnote"){let n=this.findFootnoteCallElement(t.viewNode);n?e=n:t.viewNode.before(e)}else t.viewNode.parentNode.appendChild(e);t.viewNode.remove();let i=t.modify();return i.after=!0,i.viewNode=e,t.floatSide==="footnote"&&(i.display="inline"),i}resolveFloatReferenceFromColumnSpan(t,e,i){let n=V("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Ne.REGION);return r.container.width<o.container.width&&t===Ne.COLUMN?e===w.auto?this.buildDeepElementView(i.copy()).then(s=>{let a=s.viewNode,h=fh(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(Ne.REGION):n.finish(t)}):e===w.all?n.finish(Ne.REGION):n.finish(t):n.finish(t),n.result()}layoutPageFloat(t){let e=this.pageFloatLayoutContext,i=new Wn().findByNodeContext(t),n,r=e.findPageFloatByNodePosition(t.toNodePosition());return r?n=F(r):n=i.createPageFloat(t,e,this),n.thenAsync(o=>{let s=xs(t,0),a=this.setFloatAnchorViewNode(t);e.markPageFloatAnchorSeen(o);let h=i.findPageFloatFragment(o,e),l=new Vu(o,s);if(h&&h.hasFloat(o))return e.registerPageFloatAnchor(o,a.viewNode),F(a);if(e.isForbidden(o)||e.hasPrecedingFloatsDeferredToNext(o))return e.deferPageFloat(l),e.registerPageFloatAnchor(o,a.viewNode),F(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return F(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=Tn(a,this.clientLayout,0,this.vertical);if(t.floatSide==="footnote"){let p=o;if(p.footnotePolicy===w.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)&&t.floatSide==="footnote"&&(d=c(a.viewNode)),!(t.floatSide==="footnote"&&o.footnotePolicy===w.line)&&this.isOverflown(d)?F(a):(t.floatSide==="footnote"&&e.registerPageFloatAnchor(o,a.viewNode),this.layoutPageFloatInner(l,i,d,h).thenAsync(p=>{if(!p)return e.registerPageFloatAnchor(o,a.viewNode),F(a);if(t.floatSide==="footnote"){if(o.footnotePolicy===w.line&&e.hasInvalidatedForLineFootnote(o)){if(e.isInvalidated())return F(null);let f=i.findPageFloatFragment(o,e);if(f!=null&&f.hasFloat(o)&&f.continues)return this.registerLineFootnoteOverflowEdge(d),F(a)}return F(a)}return e.generatingNodePosition?F(a):F(null)}))}})}processLineStyling(t,e,i){let n=V("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let o=0,s=t.firstPseudo;return s?.count===0&&(s=s.outer),n.loopWithFrame(a=>{if(!s){a.breakLoop();return}let h=this.findLinePositions(r),l=s.count-o;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(r,h[l-1],!0),d=c&&Op(c);if(!d){a.breakLoop();return}this.finishBreak(d,!1,!1).then(()=>{o+=l,this.layoutContext.peelOff(d,0).then(p=>{t=p,s=t.firstPseudo,r=[],this.buildViewToNextBlockEdge(t,r).then(f=>{e=f,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(e)}),n.result()}registerLineFootnoteOverflowEdge(t){if(!isFinite(t))return;let e=this.getBoxDir();(this.lineFootnoteOverflowEdge==null||e*t<e*this.lineFootnoteOverflowEdge)&&(this.lineFootnoteOverflowEdge=t)}findLineFootnoteOverflowBreak(t){if(this.lineFootnoteOverflowEdge==null||t.length===0)return null;let e=this.findLinePositions(t),i=this.getBoxDir(),n=1.5/(this.clientLayout.pixelRatio||1),r=e.find(o=>i*(o-this.lineFootnoteOverflowEdge)>=-n);return r==null?null:this.findAcceptableBreakInside(t,r,!0)}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&tn[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let e=0,i=0;for(let n=t.length-1;n>=0;n--){let r=t[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),s=this.vertical?-o.left:o.bottom;s>0?e=Math.max(e,s):i=Math.min(i,s)}return e+i}layoutBreakableBlock(t){let e=V("layoutBreakableBlock"),i=[];return this.lineFootnoteOverflowEdge=null,this.buildViewToNextBlockEdge(t,i).then(n=>{let r=i.length-1;if(r<0){e.finish(n);return}this.postLayoutBlock(n,i);let o=this.suppressOpenAncestorBlockEndInset(n??t),s=this.calculateEdge(n,i,r,i[r].boxOffset);o();let a=!1;if(!n||!Rn(n.viewNode)){let l=zn(n,this.collectElementsOffset());a=this.isOverflown(s+(this.vertical?-1:1)*l.minimum),this.isOverflown(s+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(s+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(s);let h;t.firstPseudo?h=this.processLineStyling(t,n,i):h=F(n),h.then(l=>{let c=this.findLineFootnoteOverflowBreak(i);if(c){let d=c.modify();d.overflow=!0,d.pluginProps.lineFootnoteOverflow=1,this.breakPositions=[],this.saveEdgeBreakPosition(d,null,!0),this.lineFootnoteOverflowEdge=null,e.finish(d);return}this.lineFootnoteOverflowEdge=null,i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),e.finish(l)})}),e.result()}postLayoutBlock(t,e){zt("POST_LAYOUT_BLOCK").forEach(i=>{i(t,e,this)})}findEndOfLine(t,e,i){let n=this.vertical?t-1:t+1,r=0,o=e[0].boxOffset,s=r,a=e.length-1,h=e[a].boxOffset,l;for(;o<h;){l=o+Math.ceil((h-o)/2),s=r;let c=a;for(;s<c;){let p=s+Math.ceil((c-s)/2);e[p].boxOffset>l?c=p-1:s=p}let d=this.calculateEdge(null,e,s,l);if(this.vertical?d<=n:d>=n){for(h=l-1;e[s].boxOffset==l;)s--;a=s}else i&&this.updateMaxReachedAfterEdge(d),o=l,r=s}return{nodeContext:e[s],index:o,checkPointIndex:s}}findAcceptableBreakInside(t,e,i){var n,r,o;let s=this.findEndOfLine(e,t,!0),a=s.nodeContext,h=a;if(s.checkPointIndex===0&&s.index===h.boxOffset)return null;let l=a.viewNode;if(l.nodeType!=1&&((n=l.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let c=l;h=this.resolveTextNodeBreaker(h).breakTextNode(c,a,s.index,t,s.checkPointIndex,i)}else{let c=zu(h);if(c){if(((r=this.breakPositions)==null?void 0:r[0])instanceof Sr&&c.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(h=c;!h.after&&h.inline&&h.parent;){let d=(o=h.viewNode)==null?void 0:o.previousSibling;for(;d&&(Ee(d,h.parent.whitespace)||Mt(d));)d=d.previousSibling;if(d)break;h=h.parent}}}return this.clearOverflownViewNodes(h,!1),h}resolveTextNodeBreaker(t){return zt("RESOLVE_TEXT_NODE_BREAKER").reduce((e,i)=>i(t)||e,Ws.instance)}getRangeBoxes(t,e){let i=[],n=t.ownerDocument.createRange(),r=!1,o=t,s=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;o==e&&(e.nodeType===1?h=!(!e.firstChild||r):h=!1);let d=o.nodeType===1?o:null;d?r?r=!1:ph(d)?l=!a:!d.firstChild||tn[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||Xw(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&o.firstChild&&(o=o.firstChild),n.setStartBefore(o),a=!0,s=o):/^r(uby|tc?)$/.test(d.localName)||(s=o),o.contains(e)&&(h=!1)):c=o.firstChild:(a||(o.parentNode==null?h=!1:(n.setStartBefore(o),a=!0)),s=o),c||(c=o.nextSibling,c||(r=!0,c=o.parentNode)),o=c}while(l&&h);if(a){n.setEndAfter(s);let c=this.clientLayout.getRangeClientRects(n);Ps(c,this.vertical);for(let d=0;d<c.length;d++)i.push(c[d]);a=!1}}return i}findLinePositions(t){let e=[],i=this.getRangeBoxes(t[0].viewNode,t[t.length-1].viewNode);i.sort(this.vertical?Iw:Tw);let n=0,r=0,o=0,s=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(s>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(s==0||c>=.6||c>=.2&&this.getStartEdge(l)>=o-1){o=this.getEndEdge(l),this.vertical?(n=s==0?l.right:Math.max(n,l.right),r=s==0?l.left:Math.min(r,l.left)):(n=s==0?l.top:Math.min(n,l.top),r=s==0?l.bottom:Math.max(r,l.bottom)),s++,a++;continue}}if(s>0&&(e.push(r),s=0),a>=i.length)break}return e.sort(ld),this.vertical&&e.reverse(),e}calculateClonedPaddingBorder(t){let e=0;for(let i=t;i;i=i.parent)if(!i.inline&&Fn(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);e+=i.vertical?-n.left:n.bottom,i.display==="table"&&(e+=(i.vertical?-1:1)*i.blockBorderSpacing)}return e}getOffsetByRepetitiveElements(t){let e;return t?e=t.calculateOffset(this):e=zn(null,this.collectElementsOffset()),e.current}findBoxBreakPosition(t,e){var i,n;let r=this.element.parentNode,o=this.element.nextSibling;r.removeChild(this.element),r.insertBefore(this.element,o);let s=t.checkPoints,a=s[0];for(;a.parent&&a.inline;)a=a.parent;let h,l;e&&!this.isFootnote?(h=1,l=1):(h=Math.max((a.inheritedProps.widows||2)-0,1),l=Math.max((a.inheritedProps.orphans||2)-0,1));let c=this.calculateClonedPaddingBorder(a),d=this.findLinePositions(s),p=this.footnoteEdge-c,f=this.getBoxDir(),g=this.getOffsetByRepetitiveElements(t);p-=f*g;let m=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(m.edge)&&(m.edge=f*(1/0));let v=yi(d.length,y=>{let k=d[y];return this.vertical?k<p||k<=m.edge:k>p||k>=m.edge}),b=v<=0;b&&(v=yi(d.length,y=>this.vertical?d[y]<p:d[y]>p));let x=s[s.length-1].viewNode;if(x=(i=Wp(x))!=null?i:x,(v===d.length&&x.nextSibling||v>=d.length-1&&(n=x.parentElement)!=null&&n.querySelector(".MJXc-display"))&&(h=0,l=1),v=Math.min(d.length-h,v),v<l)return null;p=d[v-1];let C;if(b?C=m.checkPoint:C=this.findAcceptableBreakInside(t.checkPoints,p,e),C){let y=this.getAfterEdgeOfBlockContainer(C);if(!isNaN(y)&&f*(p-y)>0&&(p=y),this.computedBlockSize=f*(p-this.beforeEdge)+g,d.length>=2){let k=Math.max(1,Math.min(v-1,d.length-1));this.lastLineStride=Math.abs(d[k]-d[k-1])}}return C}getAfterEdgeOfBlockContainer(t){let e=t;do e=e.parent;while(e&&e.inline);return e?(e=e.copy().modify(),e.after=!0,Tn(e,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let e=t.findIndex(n=>n.overflow);if(e<0)return{edge:NaN,checkPoint:null};let i=t[e];return{edge:this.calculateEdge(null,t,e,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(t){return this.computedBlockSize=t.computedBlockSize+this.getOffsetByRepetitiveElements(t),t.position}finishBreak(t,e,i){let n=new ar().find(t.formattingContext).finishBreak(this,t,e,i);return n||(n=wh.finishBreak(this,t,e,i)),n}findAcceptableBreakPosition(){let t=null,e=0,i=0;do{e=i,i=Number.MAX_VALUE;for(let n=this.breakPositions.length-1;n>=0&&!t;--n){let r=this.breakPositions[n],o=r.findAcceptableBreak(this,e);o&&(t={breakPosition:r,nodeContext:o});let s=r.getMinBreakPenalty();s>e&&(i=Math.min(i,s))}}while(i>e&&!t&&this.forceNonfitting);return t}doFinishBreak(t,e,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!e)return F(t);let r=V("doFinishBreak"),o=!1;if(!t){if(this.forceNonfitting&&!this.isFootnote)return Y.warn("Could not find any page breaks?!!"),this.skipTailEdges(e).then(s=>{s?(s=s.modify(),s.overflow=!1,this.finishBreak(s,o,!0).then(()=>{r.finish(s)})):r.finish(s)}),r.result();t=i,o=!0,this.computedBlockSize=n}return this.finishBreak(t,o,!0).then(()=>{r.finish(t)}),r.result()}isBreakable(t){for(let e=t;e;e=e.parent)if(Mt(e.viewNode))return!1;return t.after?!0:t.sourceNode.namespaceURI==="http://www.w3.org/2000/svg"?!1:!t.flexContainer}isZeroLength(t){let e=t.trim();return e===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(e)}hasNonZeroBlockStartInset(t){return this.vertical?!(this.isZeroLength(t.paddingRight)&&this.isZeroLength(t.borderRightWidth)):!(this.isZeroLength(t.paddingTop)&&this.isZeroLength(t.borderTopWidth))}hasNonZeroBlockEndInset(t){return this.vertical?!(this.isZeroLength(t.paddingLeft)&&this.isZeroLength(t.borderLeftWidth)):!(this.isZeroLength(t.paddingBottom)&&this.isZeroLength(t.borderBottomWidth))}suppressOpenAncestorBlockEndInset(t){if(!ks(this))return()=>{};let e=[];for(let i=t?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||Fn(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let o=n.getAttribute("data-viv-box-break");Ct(n,"block-end"),e.push({element:n,original:o})}return()=>{for(let{element:i,original:n}of e)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(t,e){if(!t)return!1;for(let s=t;s;s=s.parent)if(Mt(s.viewNode))return!1;if(Rn(t.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(t),n=Tn(t,this.clientLayout,0,this.vertical);i();let r=zn(t,this.collectElementsOffset()),o=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=t;else if(e){let s=n+this.getTrailingMarginEdgeAdjustment(e),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(s,a)):Math.max(n,Math.min(s,a))}return this.updateMaxReachedAfterEdge(n),o}checkOverflowAndSaveEdgeAndBreakPosition(t,e,i,n){if(!t||Rn(t.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(t,e);return(i||!r)&&this.saveEdgeBreakPosition(t,n,r),r}applyClearance(t){var e;if(!t.viewNode.parentNode||t.floatReference!==Ne.INLINE||t.floatSide)return!1;let i=(e=t.clearSide==="same"?t.floatSide:t.clearSide)!=null?e:"",n=/^(page|column|region)$/.test(i),r=this.getComputedMargin(t.viewNode),o=t.viewNode.ownerDocument.createElement("div");this.vertical?(o.style.bottom="0px",o.style.width="1px",o.style.marginRight=`${r.right}px`):(o.style.right="0px",o.style.height="1px",o.style.marginTop=`${r.top}px`);let s=()=>n?this.clientLayout.getElementClientRect(o):_t(this.clientLayout,o,this.vertical);t.viewNode.parentNode.insertBefore(o,t.viewNode);let a=s(),h=this.getBeforeEdge(a),l=this.getBoxDir(),c=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(i)?Ta(i,t.vertical,t.direction,this.layoutContext.page.side):i,d=c==="left"||c==="right"?t.direction==="rtl"==(c==="left")?"inline-end":"inline-start":c,p=this.pageFloatLayoutContext.getPageFloatClearEdge(d,this),f=p;switch(c){case"left":p=l*Math.max(p*l,this.leftFloatEdge*l);break;case"right":p=l*Math.max(p*l,this.rightFloatEdge*l);break;default:p=l*Math.max(p*l,Math.max(this.rightFloatEdge*l,this.leftFloatEdge*l))}let g=this.getFloatLayoutUnit(),m=this.leftFloatEdge*l>this.beforeEdge*l||this.rightFloatEdge*l>this.beforeEdge*l;if(g>0&&m){let b=p*l>f*l;p=l*(Math.ceil(p*l/g)+(b?1:0))*g}let v=this.getFloatLayoutTolerance(g);if(h*l+v>p*l)return t.viewNode.parentNode.removeChild(o),!1;{let b=Math.max(1,(p-h)*l);this.vertical?o.style.width=`${b}px`:o.style.height=`${b}px`,a=s();let x=this.getAfterEdge(a);if(!t.floatSide)if(this.vertical){let C=x-r.right-p;C>0==r.right>=0&&(C+=r.right),o.style.marginLeft=`${C}px`}else{let C=p-(x+r.top);C>0==r.top>=0&&(C+=r.top),o.style.marginBottom=`${C}px`}return t.clearSpacer=o,!0}}isBFC(t){return!!(wb(t)||rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}hasFixedPositionAncestor(t){for(let e=t;e;e=e.parent)if(Du(e.viewNode))return!0;return!1}skipEdges(t,e,i){var n;let r=t,o=r.after?(n=r.parent)==null?void 0:n.formattingContext:r.formattingContext;if(o&&!this.isBFC(o))return F(r);let s=V("skipEdges"),a=this,h=!i&&e&&r&&r.after,l=i,c=null,d=[],p=[],f=!1;function g(S){var N,L;if(!(!e||a.isNonFirstColumn||i||!Ou(l))){for(let I=S;I;I=I.parent)if(I.breakBefore==="column"&&(I.breakBefore=null),((N=I.viewNode)==null?void 0:N.nodeType)===1){let D=I.viewNode;((L=D.style)==null?void 0:L.breakBefore)==="column"&&(D.style.breakBefore="")}}}function m(S){var N,L;if(!(!e||!a.isNonFirstColumn||i||l!=="column")){for(let I=S;I;I=I.parent)if(I.breakBefore==="column"&&(I.breakBefore=null),((N=I.viewNode)==null?void 0:N.nodeType)===1){let D=I.viewNode;((L=D.style)==null?void 0:L.breakBefore)==="column"&&(D.style.breakBefore="")}l=null}}function v(S){var N,L;if(!(i||!Ou(l))){for(let I=S;I;I=I.parent)if(I.breakAfter==="column"&&(I.breakAfter=null),((N=I.viewNode)==null?void 0:N.nodeType)===1){let D=I.viewNode;((L=D.style)==null?void 0:L.breakAfter)==="column"&&(D.style.breakAfter="")}}}function b(S){l=nt(l,S)}function x(){return i?!0:Ye(l)?e?a.isNonFirstColumn&&l!=="column"&&l!=="region":!C()&&!y():!1}function C(){var S;if(!c||!r||r.floatSide)return!1;for(let N=c;N!=null&&N.parent;N=N.parent){if(N.parent.viewNode&&Mt(N.parent.viewNode))continue;let L=N.after?N.viewNode:(S=N.viewNode)==null?void 0:S.previousSibling;for(;L&&(Ee(L,N.parent.whitespace)||Mt(L));)L=L.previousSibling;if(L)return!1}return!0}function y(){var S,N;if(c||!(r!=null&&r.viewNode)||r.shadowContext||r.after||r.floatSide||!((S=r.parent)!=null&&S.viewNode)||Mt(r.parent.viewNode))return!1;let L=!1;for(let I=r;I!=null&&I.parent&&!I.after;I=I.parent){if(I!==r&&Mt(I.viewNode))return!1;let D=(N=I.viewNode)==null?void 0:N.previousSibling;for(;D&&(Ee(D,I.parent.whitespace)||Mt(D));)Mt(D)&&(L=!0),D=D.previousSibling;if(D)return!1}return L}let k=S=>{let N=d[0]||S;r=N,N.viewNode.remove(),this.pageBreakType=l};return s.loopWithFrame(S=>{for(var N;r;){let L=new ar().find(r.formattingContext);do{let D=Yi(r);if(!D)break;if(r.inline&&D.viewNode.nodeType!=1){if(Ee(D.viewNode,r.whitespace)||this.hasFixedPositionAncestor(r))break;if(!r.after){b(r.breakBefore),g(r),m(r),x()?k(D):this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)?(r=(this.stopAtOverflow&&c||r).modify(),r.overflow=!0):(!c&&!e&&d.length===0&&this.saveEdgeBreakPosition(r,l,!1),r=r.modify(),r.breakBefore=l),S.breakLoop();return}}if(!r.after){if(r.floatSide&&(this.breakAtTheEdgeBeforeFloat=ws(l)?l:null),L&&L.startNonInlineElementNode(r))break;let M=_w(r);if(M&&this.applyClearance(M)&&e&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(r.copy(),l,!1),!r.inline&&!r.repeatOnBreak&&(c?zu(c):this.breakPositions[this.breakPositions.length-1]instanceof Sr||!e&&d.length===0)&&this.saveEdgeBreakPosition(r.copy(),l,!1),!this.isBFC(r.formattingContext)||rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(r.formattingContext)||this.asFloatNodeContext(r)!==null||r.flexContainer||!r.nodeShadow&&!r.sourceNode.firstElementChild&&Ee(r.sourceNode.firstChild,r.whitespace)){d.push(D.copy()),b(r.breakBefore),g(r),m(r),x()?k(D):(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)||!this.layoutConstraint.allowLayout(r))&&(r=(this.stopAtOverflow&&c||r).modify(),r.overflow=!0),S.breakLoop();return}}let J=Lt(D);if(!J)break;let te=J.viewNode,P=te.style;if(r.after){$p(te,this),r.floatSide&&(l=l??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let M=r.sourceNode;if(M.localName==="svg"||M.localName==="math"||M.getAttribute("data-math-typeset")==="true"){f=!1,c=J.copy(),p.push(c),l=null,b(r.breakAfter),v(r),this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l);break}if(r.inline||L&&L.afterNonInlineElementNode(r,this.stopAtOverflow))break;if(f){if(Du(r.viewNode))break;if(x()){k(J),S.breakLoop();return}d=[],e=!1,h=!1,l=null}f=!1,Up(J.viewNode)||(c=J.copy(),p.push(c)),b(r.breakAfter),v(r),P&&!Mt(r.viewNode)&&this.hasNonZeroBlockEndInset(P)&&(p=c?[c]:[])}else{if(d.push(J.copy()),b(r.breakBefore),g(r),m(r),c&&Ye(l)&&Uw(c.viewNode,J.viewNode),(r.pageType!=((N=r.parent)==null?void 0:N.pageType)||!Ye(l))&&!this.layoutConstraint.allowLayout(r)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l),r=r.modify(),r.overflow=!0,this.stopAtOverflow)){S.breakLoop();return}let M=te.localName;if(tn[M]){x()?k(J):this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)&&(r=(this.stopAtOverflow&&c||r).modify(),r.overflow=!0),S.breakLoop();return}P&&this.hasNonZeroBlockStartInset(P)&&(h=!1,p=[]),f=!0}}while(!1);let I=this.nextInTree(r,h);if(I.isPending()){I.then(D=>{r=D,S.continueLoop()});return}else r=I.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(c,p,!this.stopAtOverflow,l)?c&&this.stopAtOverflow&&(r=c.modify(),r.overflow=!0):Ye(l)&&(this.pageBreakType=l),S.breakLoop()}).then(()=>{c&&(this.lastAfterPosition=c.toNodePosition()),s.finish(r)}),s.result()}skipTailEdges(t){let e=t,i=e.copy(),n=V("skipEdges"),r=null,o=!1;return n.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){Ye(r)&&(this.pageBreakType=r),s.breakLoop();return}}if(!e.after&&(this.asFloatNodeContext(e)!==null||e.flexContainer)){r=nt(r,e.breakBefore),Ye(r)&&(this.pageBreakType=r),s.breakLoop();return}if(e.viewNode.nodeType!=1)break;let h=e.viewNode,l=h.style;if(e.after){if(o){if(Ye(r)){this.pageBreakType=r,s.breakLoop();return}r=null}o=!1,r=nt(r,e.breakAfter)}else{r=nt(r,e.breakBefore);let c=h.localName;if(tn[c]){Ye(r)&&(this.pageBreakType=r),s.breakLoop();return}if(l&&this.hasNonZeroBlockStartInset(l)){s.breakLoop();return}}o=!0}while(!1);let a=this.layoutContext.nextInTree(e);if(a.isPending()){a.then(h=>{e=h,s.continueLoop()});return}else e=a.get()}i=null,s.breakLoop()}).then(()=>{n.finish(i)}),n.result()}layoutFloatOrFootnote(t){if(Li(t.floatReference)||t.floatSide==="footnote"){let e=this.pageFloatLayoutContext.generatingNodePosition;if(e&&t.sourceNode===e.steps[0].node){let i=t.modify();return i.floatSide=null,i.floatReference=Ne.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(t)}else return this.layoutFloat(t)}layoutNext(t,e,i){let n=V("layoutNext");return this.skipEdges(t,e,i||null).then(r=>{if(t=r,!t||this.pageBreakType||this.stopByOverflow(t))n.finish(t);else{let o=t.formattingContext;new ar().find(o).layout(t,this,e).thenFinish(n)}}),n.result()}clearOverflownViewNodes(t,e){if(t)for(let i=t.parent;t;t=i,i=i?i.parent:null){let n=(i||t).formattingContext;new ar().find(n).clearOverflownViewNodes(this,i,t,e),e=!1}}measure(){R(this.element,"width",`${this.width}px`),R(this.element,"height",`${this.height}px`);let t=this.element.ownerDocument.createElement("div");t.style.position="absolute",t.style.top=`${this.paddingTop}px`,t.style.right=`${this.paddingRight}px`,t.style.bottom=`${this.paddingBottom}px`,t.style.left=`${this.paddingLeft}px`,this.element.appendChild(t);let e=this.clientLayout.getElementClientRect(t);this.element.removeChild(t);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop(),r=new Dt(i,n,i+this.width,n+this.height);return this.startEdge=e?this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left:0,this.endEdge=e?this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right:0,this.beforeEdge=e?this.vertical?e.right:e.top:0,this.afterEdge=e?this.vertical?e.left:e.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,Oy(r,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical)}remeasure(){this.chunkPositions=[],this.bands=this.measure(),this.createFloats(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(t,e,i){let n=t.copy(),r=new ar().find(t.formattingContext),o=this.calculateClonedPaddingBorder(n),s=r.createEdgeBreakPosition(n,e,i,this.computedBlockSize+o);this.breakPositions.push(s)}saveBoxBreakPosition(t){let e=t[0].breakPenalty;if(e){let n=t[0];for(;n.parent&&n.inline;)n=n.parent;e=n.breakPenalty}let i=new Sr(t,e);this.breakPositions.push(i)}updateMaxReachedAfterEdge(t){if(!isNaN(t)){let e=this.getBoxDir()*(t-this.beforeEdge);this.computedBlockSize=Math.max(e,this.computedBlockSize)}}layout(t,e,i){if(this.chunkPositions.push(t),t.primary.after&&(this.lastAfterPosition=t.primary),this.stopAtOverflow&&this.overflown)return F(t);if(this.isFullWithPageFloats())return t.primary.after&&t.primary.steps.length===1?F(null):F(t);ch(this);let n=V("layout");return this.openAllViews(t.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let s=new tS(e,i);s.layout(r,this).then(a=>{this.doFinishBreak(a,s.context.overflownNodeContext,o,s.initialComputedBlockSize).then(h=>{let l;this.pseudoParent?l=F(!0):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(ks(this)&&(jw(this),na(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(R(this.element,"width",`${this.width}px`),R(this.element,"left",`${this.left}px`)):R(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 zi(h.toNodePosition());n.finish(c)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let e=V("doFinishBreakOfFragmentLayoutConstraints"),i=this.fragmentLayoutConstraints.slice();i.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let n=0;return e.loop(()=>n<i.length?i[n++].finishBreak(t,this).thenReturn(!0):F(!1)).then(()=>{e.finish(!0)}),e.result()}doLayout(t,e,i){let n=V("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(o=>{for(;t;){let s=!0;if(this.layoutNext(t,e,i||null).then(a=>{if(e=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,t=this.nodeContextOverflowingDueToRepetitiveElements,t.overflow=!0):t=a,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(t&&this.stopByOverflow(t)){r=t;let h=this.findAcceptableBreakPosition();t=h&&h.nodeContext,h&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else s?s=!1:o.continueLoop()}),s){s=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{n.finish({nodeContext:t,overflownNodeContext:r})}),n.result()}saveDistanceToBlockEndFloats(){let t=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();t>0&&isFinite(t)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(t-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let t=[];for(let e=this;e;e=e.pseudoParent)e.fragmentLayoutConstraints.forEach(i=>{if(rn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}if(bs.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}_i.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{t.push(n)})});return t}},zh=class{constructor(t,e,i){u(this,"startNodeContexts",[]),u(this,"column"),u(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,this.column=Object.create(t),this.column.element=e,this.column.layoutContext=t.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=t;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(o){return Us.prototype.openAllViews.call(this,o).thenAsync(s=>(r.startNodeContexts.push(s.copy()),F(s)))}}layout(t,e){return this.column.layout(t,e)}findAcceptableBreakPosition(){let t=this.column.findAcceptableBreakPosition(),e=this.startNodeContexts[0].copy(),i=new po(e,null,e.overflow,0);return i.findAcceptableBreak(this.column,0),t??{breakPosition:i,nodeContext:e}}finishBreak(t,e,i){return this.column.finishBreak(t,e,i)}doFinishBreakOfFragmentLayoutConstraints(t){this.column.doFinishBreakOfFragmentLayoutConstraints(t)}isStartNodeContext(t){let e=this.startNodeContexts[0];return e.viewNode===t.viewNode&&e.after===t.after&&e.offsetInNode===t.offsetInNode}isLastAfterNodeContext(t){return Di(t.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(t)}isEffectivelyLastAfterNodeContext(t){var e;let i=this.flowRootSourceNode,n=t.sourceNode;if(!i||!n||!t.after||i!==n&&!((e=i.contains)!=null&&e.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(t.offsetInNode<r.length){let o=r.data.slice(t.offsetInNode);if(!Fp(o,t.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let o=r.nextSibling;o;o=o.nextSibling)if(!Ee(o,t.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Ws=class{breakTextNode(t,e,i,n,r,o){if(e.after)e.offsetInNode=t.length;else{let s=i-e.boxOffset,a=t.data;a.charCodeAt(s)==173?s=this.breakAfterSoftHyphen(t,a,s,e):s=this.breakAfterOtherCharacter(t,a,s,e),s>0&&(e=this.updateNodeContext(e,s,t))}return e}breakAfterSoftHyphen(t,e,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(e.slice(0,i))?"\u200D":"";if(t.replaceData(i,e.length-i,n.breakWord?"":r+vc(n)),r){let o=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=o.slice(0,i+1)+r+o.slice(i+1)}return i+1}breakAfterOtherCharacter(t,e,i,n){let r=e.charAt(i);i++;let o=e.charAt(i);return t.replaceData(i,e.length-i,!n.breakWord&&ou(r)&&ou(o)?vc(n):""),i}updateNodeContext(t,e,i){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};u(Ws,"instance");Ws.instance=new Ws;function vc(t){return t.hyphenateCharacter||t.parent&&t.parent.hyphenateCharacter||"-"}var tS=class extends bh{constructor(t,e){super(),u(this,"leadingEdge",t),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=e||null}resolveLayoutMode(t){return new iS(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(t,e){e.fragmentLayoutConstraints=[],e.pseudoParent||Cb()}clearNodes(t){super.clearNodes(t);let e=t;for(;e;){let i=e.viewNode;i&&Hp(i.parentNode,i),e=e.parent}}saveState(t,e){super.saveState(t,e),this.initialPageBreakType=e.pageBreakType,this.initialComputedBlockSize=e.computedBlockSize,this.initialOverflown=e.overflown,this.initialLastLineStride=e.lastLineStride}restoreState(t,e){super.restoreState(t,e),e.pageBreakType=this.initialPageBreakType,e.computedBlockSize=this.initialComputedBlockSize,e.overflown=this.initialOverflown,e.lastLineStride=this.initialLastLineStride}},iS=class{constructor(t,e,i){u(this,"leadingEdge",t),u(this,"breakAfter",e),u(this,"context",i)}doLayout(t,e){let i=V("DefaultLayoutMode.doLayout");return Jx(t,e).then(()=>{e.doLayout(t,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(t,e){return e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||e.fragmentLayoutConstraints.length<=0?!0:e.fragmentLayoutConstraints.every(i=>i.allowLayout(t,this.context.overflownNodeContext,e))}postLayout(t,e,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(t))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,t,e,i)}),n}},nS=class extends Us{constructor(t,e,i,n,r,o,s,a,h,l,c){super(e,i,n,r,o,a,h,l,c),u(this,"floatSide",t),u(this,"parentContainer",s),u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0),u(this,"parentElement"),this.parentElement=s.element}openAllViews(t){return super.openAllViews(t).thenAsync(e=>(e&&this.fixFloatSizeAndPosition(e),F(e)))}convertPercentageSizesToPx(t){let e=this.parentContainer.getPaddingRect(),i=e.x2-e.x1,n=e.y2-e.y1;function r(o,s){o.forEach(a=>{let h=Ni(t,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=s*l/100;R(t,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(o=>{Ni(t,o)==="auto"&&R(t,o,"0")})}fixFloatSizeAndPosition(t){for(;t.parent;)t=t.parent;t.viewNode.nodeType;let e=t.viewNode;if(this.rootViewNodes.push(e),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(e),this.floatMargins.push(this.getComputedMargin(e)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=Ni(e,"height");n!==""&&n!=="auto"&&R(e,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=Ni(e,"width");n!==""&&n!=="auto"&&R(e,"margin-left","auto")}}}getRootViewNodeCount(){return this.rootViewNodes.length}hasNonPseudoTextContentAfter(t){let e=i=>{var n;return i.nodeType===Node.TEXT_NODE?!!((n=i.textContent)!=null&&n.trim()):i.nodeType!==Node.ELEMENT_NODE||Qt(i)?!1:Array.from(i.childNodes).some(e)};return this.rootViewNodes.slice(t).some(e)}appendContentFrom(t){t.rootViewNodes.forEach(e=>{this.element.appendChild(e)}),this.rootViewNodes.push(...t.rootViewNodes),this.floatMargins.push(...t.floatMargins),t.rootViewNodes.splice(0),t.floatMargins.splice(0),t.element.parentNode&&t.element.parentNode.removeChild(t.element),this.applyCompactFootnoteDisplay(),this.updateComputedBlockSizeForFootnoteArea(!0)}removeContentAfter(t){let e=this.rootViewNodes.splice(t);this.floatMargins.splice(t),e.forEach(i=>{i.parentNode&&i.parentNode.removeChild(i)}),this.applyCompactFootnoteDisplay(),this.updateComputedBlockSizeForFootnoteArea(!0)}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((t,e)=>{let i=_t(this.clientLayout,t,this.vertical),n=this.floatMargins[e];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((t,e)=>{let i=this.floatMargins[e];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let t=this.layoutContext,e=t?.styler,i=t?.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(jt);if(!g||!e||!i)return!1;let m=i.getNodeByOffset(parseInt(g,10));if(!m||m.nodeType!==Node.ELEMENT_NODE)return!1;let v=e.getStyle(m,!1),b=(d=(c=ge(v,"footnote-display"))==null?void 0:c.value)==null?void 0:d.toString(),x=!!((p=ge(v,"--viv-marker-content"))!=null&&p.value);return b==="compact"&&!x});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea(!0);return}let r=this.element.getBoundingClientRect(),o=this.vertical?r.height:r.width;n.forEach(h=>{R(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let s=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);R(l,"display","inline-block"),R(l,"position","absolute"),R(l,"visibility","hidden"),R(l,"white-space","nowrap"),R(l,"max-width","none"),R(l,"left","0"),R(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)>o+s&&(R(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea(!0)}updateComputedBlockSizeForFootnoteArea(t=!1){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir(),i=this.beforeEdge;if(t){let n=_t(this.clientLayout,this.element,this.vertical),r=this.vertical?this.borderRight+this.paddingRight:this.borderTop+this.paddingTop;i=this.getBeforeEdge(n)+e*r}this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(n=>{let r=_t(this.clientLayout,n,this.vertical),o=this.getComputedMargin(n),s=this.vertical?o.left:o.bottom;return e*(this.getAfterEdge(r)-i)+Math.max(0,s)}))}getFootnoteAfterPseudo(t){return Array.from(t.children).find(e=>Qt(e)==="after")}hasAuthorFootnoteAfterPseudo(t){let e=this.getFootnoteAfterPseudo(t);if(e&&!e.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let i=Array.from(t.children).find(r=>r instanceof Element&&Et(r)),n=i?this.getFootnoteAfterPseudo(i):null;return!!n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(t){let e=t.ownerDocument.createElement("span");Mr(e,"after"),e.setAttribute("data-vivliostyle-default-footnote-separator","1"),e.style.whiteSpace="normal",e.textContent=" ",t.appendChild(e)}getFootnoteBreakOpportunity(t){let e=t.nextElementSibling;return e!=null&&e.hasAttribute("data-vivliostyle-footnote-break")?e:null}createFootnoteBreakOpportunity(t){let e=t.ownerDocument.createElement("wbr");e.setAttribute("data-vivliostyle-footnote-break","1"),t.insertAdjacentElement("afterend",e)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((t,e)=>{var i,n;let r=t,o=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,s=this.rootViewNodes[e+1],a=(n=s?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(s).display,h=this.getFootnoteAfterPseudo(r),l=this.hasAuthorFootnoteAfterPseudo(r),c=!!(h!=null&&h.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(r);if(o==="inline"&&a==="inline"){let p=!h&&!l;p&&this.createDefaultFootnoteAfterPseudo(r),!p&&!d?this.createFootnoteBreakOpportunity(r):p&&d?.remove()}else c&&h.remove(),d?.remove()})}},cn=class{constructor(t,e){u(this,"parent",t),u(this,"rootSourceNode",e),u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(t){let e=this.getRootNodeContext(t);return e?e.viewNode:null}getRootNodeContext(t){let e=t;do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(t){this.repetitiveElements||fl.some(e=>e.root===this.rootSourceNode?(this.repetitiveElements=e.elements,!0):!1)||(this.repetitiveElements=new rS(t,this.rootSourceNode),fl.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},rS=class{constructor(t,e){u(this,"vertical",t),u(this,"ownerSourceNode",e),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",!1)}setHeaderNodeContext(t){this.headerNodePosition||(this.headerNodePosition=xs(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=xs(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=ul(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=ul(this.footerViewNode,t,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(t,e,i){return!this.headerNodePosition||this.isSkipHeader?F(!0):this.appendElementToFragment(this.headerNodePosition,t,e,i)}appendFooterToFragment(t,e,i){return!this.footerNodePosition||this.isSkipFooter?F(!0):this.appendElementToFragment(this.footerNodePosition,t,e,i)}appendElementToFragment(t,e,i,n){let r=e.viewNode,o=r.ownerDocument.createElement("div");r.appendChild(o);let s=new zh(n,o,e),a=s.getColumn().pageBreakType;return s.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,s.layout(new zi(t),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),s.getColumn().pageBreakType=a,F(!0)))}moveChildren(t,e,i){if(e)for(;t.firstChild;){let n=t.firstChild;t.removeChild(n),n.setAttribute(Un,"1"),i?e.insertBefore(n,i):e.appendChild(n)}}calculateOffset(t){let e=0;return t&&!this.affectTo(t)||((!this.isSkipFooter||t&&this.isAfterLastContent(t))&&(e+=this.footerHeight),this.isSkipHeader||(e+=this.headerHeight)),e}calculateMinimumOffset(t){let e=0;return t&&!this.affectTo(t)||(!this.enableSkippingFooter&&t&&this.isAfterLastContent(t)&&(e+=this.footerHeight),this.enableSkippingHeader||(e+=this.headerHeight)),e}isAfterLastContent(t){return this.findResultFromCache(t,this.afterLastContentNodeCache,e=>this.isAfterNodeContextOf(this.lastContentSourceNode,t,!1))}affectTo(t){return this.findResultFromCache(t,this.affectedNodeCache,e=>this.isAfterNodeContextOf(this.ownerSourceNode,t,!0))}findResultFromCache(t,e,i){let n=e.filter(r=>r.nodeContext.sourceNode===t.sourceNode&&r.nodeContext.after===t.after);if(n.length>0)return n[0].result;{let r=i(t);return e.push({nodeContext:t,result:r}),r}}isAfterNodeContextOf(t,e,i){let n=[];for(let r=t;r;r=r.parentNode){if(e.sourceNode===r)return e.after;n.push(r)}for(let r=e.sourceNode;r;r=r.parentNode){let o=n.indexOf(r);if(o>=0)return i?o===0:!1;for(let s=r;s;s=s.previousElementSibling)if(n.includes(s))return!0}return e.after}isFirstContentNode(t){return t&&this.firstContentSourceNode===t.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(t){return this.headerSourceNode===t}isFooterSourceNode(t){return this.footerSourceNode===t}},Cg=class{constructor(t){u(this,"formattingContext",t)}accept(t,e){return!!t}postLayout(t,e,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},kg=class{constructor(t){u(this,"formattingContext",t)}accept(t,e){return!0}postLayout(t,e,i,n){return n}},oS=class extends Cg{constructor(t,e){super(t),u(this,"processor",e)}doLayout(t,e){return this.processor.doInitialLayout(t,e)}accept(t,e){return!1}},sS=class extends kg{constructor(t,e){super(t),u(this,"processor",e)}doLayout(t,e){return!t.belongsTo(this.formattingContext)&&!t.after&&e.fragmentLayoutConstraints.unshift(new Vh(t)),this.processor.doLayout(t,e)}},Vh=class Pg{constructor(e){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=pi(e.formattingContext);this.nodeContext=i.getRootNodeContext(e)}allowLayout(e,i,n){let r=this.getRepetitiveElements();return!r||Rn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!e||e&&e.overflow?!Ng(e,i,r):!0}nextCandidate(e){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(e,i,n,r){let o=this.getRepetitiveElements();o&&e&&r.stopAtOverflow&&(i==null||o.isAfterLastContent(i))&&o.preventSkippingFooter()}finishBreak(e,i){let n=pi(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return F(!0);let o=this.nodeContext;return cS(n,o,i).thenAsync(()=>dS(n,o,i).thenAsync(()=>(r.prepareLayoutFragment(),F(!0))))}getRepetitiveElements(){return pi(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(e){return e instanceof Pg?pi(this.nodeContext.formattingContext)===pi(e.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},aS=class extends bh{constructor(t,e){super(),u(this,"formattingContext",t),u(this,"processor",e)}resolveLayoutMode(t){let e=this.formattingContext.getRepetitiveElements();return!t.belongsTo(this.formattingContext)&&!e.doneInitialLayout?new oS(this.formattingContext,this.processor):(!t.belongsTo(this.formattingContext)&&!t.after&&e&&e.preventSkippingHeader(),new sS(this.formattingContext,this.processor))}},lS=class extends Ir{constructor(t,e){super(),u(this,"formattingContext",t),u(this,"column",e)}startNonInlineElementNode(t){let e=this.formattingContext,i=t.nodeContext,n=e.getRepetitiveElements();if(i.parent&&e.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),F(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),F(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return Ir.prototype.startNonInlineElementNode.call(this,t)}afterNonInlineElementNode(t){let e=this.formattingContext,i=t.nodeContext;return i.sourceNode===e.rootSourceNode&&(e.getRepetitiveElements().lastContentSourceNode=t.lastAfterNodeContext&&t.lastAfterNodeContext.sourceNode,t.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?F(!0):Ir.prototype.afterNonInlineElementNode.call(this,t)}},hS=class extends On{layout(t,e,i){let n=e.asFloatNodeContext(t);if(n)return e.layoutFloatOrFootnote(n);let r=pi(t.formattingContext);return r.getRootViewNode(t)?(i&&Eg(t.parent,e),t.belongsTo(r)?On.prototype.layout.call(this,t,e,i):new aS(r,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let e=pS(t).getRepetitiveElements();return e&&!e.allowInsertRepeatitiveElements&&(e.isHeaderSourceNode(t.sourceNode)||e.isFooterSourceNode(t.sourceNode))&&Lt(t).viewNode.remove(),!1}doInitialLayout(t,e){let i=pi(t.formattingContext),n=V("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(n),n.result()}layoutEntireBlock(t,e){let i=pi(t.formattingContext),n=new lS(i,e);return new pl(n,e.layoutContext).iterate(t)}doLayout(t,e){let i=pi(t.formattingContext),n=V("doLayout"),r=e.layoutContext.nextInTree(t,!1);return Sg(r,e).then(o=>{let s=o;n.loopWithFrame(a=>{for(;s;){let h=!0;if(e.layoutNext(s,!1).then(l=>{s=l,e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||s&&e.stopByOverflow(s)||s&&s.after&&s.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(s)})}),n.result()}finishBreak(t,e,i,n){return On.prototype.finishBreak.call(this,t,e,i,n)}clearOverflownViewNodes(t,e,i,n){On.prototype.clearOverflownViewNodes(t,e,i,n)}};function uS(t,e){for(let i=t;i;i=i.parent){let n=i.formattingContext;n instanceof cn&&!i.belongsTo(n)&&e(n,i)}}function Eg(t,e){t&&uS(t.after?t.parent:t,(i,n)=>{_i.isInstanceOfTableFormattingContext(i)||e.fragmentLayoutConstraints.push(new Vh(n))})}function cS(t,e,i){let n=t.getRepetitiveElements();if(n){let r=t.getRootNodeContext(e),o=r&&Lt(r);if(o){let s=o.viewNode.firstChild;return n.appendHeaderToFragment(o,s,i)}}return F(!0)}function dS(t,e,i){let n=t.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=t.getRootNodeContext(e),o=r&&Lt(r);if(o)return n.appendFooterToFragment(o,null,i)}return F(!0)}function Ng(t,e,i){let n=i.ownerSourceNode,r=t||e;return!r||n.contains(r.sourceNode)}function pS(t){let e=t.formattingContext;return e instanceof cn?e:null}function pi(t){return t instanceof cn,t}var fS=new hS;Ft("RESOLVE_LAYOUT_PROCESSOR",t=>t instanceof cn&&!_i.isInstanceOfTableFormattingContext(t)?fS:null);var Tg=class{constructor(t,e){u(this,"rowIndex",t),u(this,"sourceNode",e),u(this,"cells",[]),u(this,"breakBefore",null),u(this,"breakAfter",null)}addCell(t){this.cells.push(t)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(t=>t.height))}},gS=class{constructor(t,e,i,n){u(this,"rowIndex",t),u(this,"columnIndex",e),u(this,"anchorColumnIndex",i),u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),this.viewElement=n,this.colSpan=n.colSpan||1,this.rowSpan=n.rowSpan||1}setHeight(t){this.height=t}},mS=class{constructor(t,e,i){u(this,"rowIndex",t),u(this,"columnIndex",e),u(this,"cell",i)}},yS=class{constructor(t,e,i){u(this,"column",t),u(this,"cellNodeContext",i),u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new zh(t,e,i)}findAcceptableBreakPosition(){let t=this.cellNodeContext.viewNode,{verticalAlign:e,alignContent:i}=t.style;e!=="top"&&e!=="baseline"&&R(t,"vertical-align","top"),i&&i!=="normal"&&R(t,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition();return R(t,"vertical-align",e),i&&i!=="normal"&&R(t,"align-content",i),n}},vS=class{constructor(t,e){u(this,"viewNode",t),u(this,"side",e)}},wS=class extends po{constructor(t,e,i,n){super(t,e,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(this,"rowIndex",null),this.formattingContext=t.formattingContext}findAcceptableBreak(t,e){let i=super.findAcceptableBreak(t,e);return e<this.getMinBreakPenalty()||this.hasUnfinishedCells()?null:i}hasUnfinishedCells(){let t=this.getRowIndex(),e=this.formattingContext.getCellsFallingOnRow(t);for(let i of e){if(i.rowIndex+i.rowSpan-1>t)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}getMinBreakPenalty(){let t=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{t+=i.breakPosition.getMinBreakPenalty()});let e=this.getCellFragments();return t+=Math.max(0,...e.map(i=>i.cellNodeContext.breakPenalty)),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let t=this.formattingContext,e=this.getCellFragments();this.acceptableCellBreakPositions=e.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)}},bS=class extends vh{constructor(t,e,i){super(),u(this,"rowIndex",t),u(this,"beforeNodeContext",e),u(this,"formattingContext",i),u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(t,e){if(this!==t.breakPositions[0]&&e<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.some((o,s)=>{let a=i[s].pseudoColumn,h=o.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(o=>o.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let t=this.formattingContext.getRowByIndex(this.rowIndex),e=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();e+=Math.max(0,...n.map(o=>o.cellNodeContext.breakPenalty));let r=i.some((o,s)=>o.breakPosition instanceof Sr&&n[s].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((o,s)=>{let a=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof po&&o.breakPosition.overflows&&a>=3&&(n[s].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(a-=3)),e+=a}),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(e=>e.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},$n=class extends cn{constructor(t,e){super(t,e),u(this,"tableSourceNode",e),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(t,e){var i;if(!e)return e;switch(t.display){case"table-row":{let n=this.findRowIndexBySourceNode(t.sourceNode);return this.cellBreakPositions.every(r=>this.isPreviousFragmentRowSpanningCellBreakPosition(r,n))&&t.fragmentIndex<=1}case"table-cell":return t.fragmentIndex>1||((i=t.parent)==null?void 0:i.display)==="table-row"&&t.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.cellNodePosition.steps[0].node===t.sourceNode);default:return e}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(t,e){this.rows[t]=e}getRowSlots(t){let e=this.slots[t];return e||(e=this.slots[t]=[]),e}addCell(t,e,i){let n=this.rows[t];n||(this.addRow(t,new Tg(t,null)),n=this.rows[t]);let r=this.getRowSlots(t),o=0;for(;r[o];)o++;let s=new gS(t,e,o,i);n.addCell(s);let a=t+s.rowSpan,h=o+s.colSpan;for(let l=t;l<a;l++){let c=this.getRowSlots(l);for(let d=o;d<h;d++)c[d]=new mS(l,d,s)}}getRowByIndex(t){return this.rows[t]}findRowIndexBySourceNode(t){return this.rows.findIndex(e=>t===e.sourceNode)}isPreviousFragmentRowSpanningCellBreakPosition(t,e){let i=t.cell;return e>=0&&i.rowIndex<e&&i.rowIndex+i.rowSpan>e}addCellFragment(t,e,i){let n=this.cellFragments[t];n||(n=this.cellFragments[t]=[]),n[e]=i}getCellsFallingOnRow(t){return this.getRowSlots(t).reduce((e,i)=>i.cell!==e[e.length-1]?e.concat(i.cell):e,[])}getRowSpanningCellsOverflowingTheRow(t){return this.getCellsFallingOnRow(t).filter(e=>e.rowIndex+e.rowSpan-1>t)}getCellFragmentOfCell(t){return this.cellFragments[t.rowIndex]&&this.cellFragments[t.rowIndex][t.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(t=>t.cells.reduce((e,i)=>e+i.colSpan,0)))),this.columnCount}updateCellSizes(t){this.rows.forEach(e=>{e.cells.forEach(i=>{let n=_t(t,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(t){if(!t)return null;let e=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]&&t===this.cellFragments[i][n].pseudoColumn.getColumn()){e=this.rows[i].cells[n];break e}}if(!e)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===e)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(t){let e=[];return this.slots.reduce((i,n,r)=>{if(r>=t.rowIndex)return i;let o=n[t.columnIndex]&&this.getCellFragmentOfCell(n[t.columnIndex].cell);return!o||e.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),i),e.push(o)),i},[])}collectElementsOffsetOfHighestColumn(){let t=[];return this.rows.forEach(e=>{e.cells.forEach((i,n)=>{t[n]||(t[n]={collected:[],elements:[]});let r=t[n],o=this.getCellFragmentOfCell(i);!o||r.collected.includes(o)||(this.collectElementsOffsetFromColumn(o.pseudoColumn.getColumn(),r.elements),r.collected.push(o))})}),[new xS(t.map(e=>e.elements))]}collectElementsOffsetFromColumn(t,e){t.fragmentLayoutConstraints.forEach(i=>{if(rn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}_i.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{e.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(t){this.cellBreakPositions=[].concat(t)}},xS=class{constructor(t){u(this,"repeatitiveElementsInColumns",t)}calculateOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.current)}calculateMinimumOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.minimum)}calculateMaxOffsetOfColumn(t,e){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=zn(t,n);i=Math.max(i,e(r))}),i}};function Gt(t){return t instanceof $n,t}function SS(t){return t==="table-row-group"||t==="table-header-group"||t==="table-footer-group"}function CS(t){return t==="table"||t==="inline-table"}function wc(t){return SS(t)||CS(t)}function Ig(t,e,i){let n=t.nodeContext,r=n.display,o=n.parent?n.parent.display:null,s=!1;if(o==="inline-table"&&!(n.formattingContext instanceof $n)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof $n){s=a.formattingContext===e;break}}return s||r==="table-row"&&!wc(o)||r==="table-cell"&&o!=="table-row"&&!wc(o)||n.formattingContext instanceof $n&&n.formattingContext!==e?i.buildDeepElementView(n).thenAsync(a=>(t.nodeContext=a,F(!0))):null}function Ag(t,e){let i=Mw(e.nodeContext);return!i||!(Li(i.floatReference)||i.floatSide==="footnote")?null:t.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(e.nodeContext=n),F(!0)))}var kS=class extends Ir{constructor(t,e){super(),u(this,"formattingContext",t),u(this,"column",e),u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(t){let e=this.formattingContext,i=Ig(t,e,this.column);if(i)return i;this.postLayoutBlockContents(t);let n=Ag(this.column,t);if(n)return n;let r=t.nodeContext,o=r.display,s=e.getRepetitiveElements();switch(o){case"table":e.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new vS(r.viewNode,r.captionSide);e.captions.push(a);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(r)),F(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(r)),F(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,this.columnIndex=0,e.addRow(this.rowIndex,new Tg(this.rowIndex,r.sourceNode)),r.breakBefore&&(e.rows[this.rowIndex].breakBefore=r.breakBefore),s.firstContentSourceNode||(s.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(t)}afterNonInlineElementNode(t){let e=this.formattingContext,i=t.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(t),i.sourceNode===e.tableSourceNode){let o=r.getElementComputedStyle(e.getRootViewNode(i));e.tableWidth=parseFloat(o[e.vertical?"height":"width"]),e.getRepetitiveElements().lastContentSourceNode=t.lastAfterNodeContext&&t.lastAfterNodeContext.sourceNode,t.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,F(!0);break;case"table-row":if(!this.inHeaderOrFooter){e.lastRowViewNode=i.viewNode,this.inRow=!1;let o=e.rows[this.rowIndex];o&&i.breakAfter&&(o.breakAfter=nt(o.breakAfter,i.breakAfter))}break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let o=i.viewNode;e.addCell(this.rowIndex,this.columnIndex,o),this.columnIndex++,Og(o);let s=e.rows[this.rowIndex];s&&(i.breakBefore&&(s.breakBefore=nt(s.breakBefore,i.breakBefore)),i.breakAfter&&(s.breakAfter=nt(s.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(t)}startNonElementNode(t){this.registerCheckPoint(t)}afterNonElementNode(t){this.registerCheckPoint(t)}startInlineElementNode(t){this.registerCheckPoint(t)}afterInlineElementNode(t){this.registerCheckPoint(t)}registerCheckPoint(t){let e=t.nodeContext;Ln(e)||this.checkPoints.push(e.clone())}postLayoutBlockContents(t){this.checkPoints.length>0&&this.column.postLayoutBlock(t.nodeContext,this.checkPoints),this.checkPoints=[]}},Fg=class Rg extends Ir{constructor(e,i){super(!0),u(this,"formattingContext",e),u(this,"column",i),u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader",!1),u(this,"inFooter",!1),u(this,"didExtractRowSpanningCellBreakPositions",!1),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}startNonInlineElementNode(e){return Ag(this.column,e)||super.startNonInlineElementNode(e)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(e){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<e.colSpan;r++)n+=i[e.anchorColumnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(e.colSpan-1),n}layoutCell(e,i,n){let r=e.rowIndex,o=e.columnIndex,s=e.colSpan,a=i.viewNode;s>1&&(R(a,"box-sizing","border-box"),R(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(e)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new yS(this.column,h,i);return this.formattingContext.addCellFragment(r,o,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenAsync(()=>(Og(a),F(!0)))}findBrokenCellAtSlot(e,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let o=n[r];if(o.cell.anchorColumnIndex===e&&o.cellNodePosition.steps[0].node===i)return{position:o,index:r}}return null}extractRowSpanningCellBreakPositions(){if(this.didExtractRowSpanningCellBreakPositions)return[];let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let i=[];return e.forEach(n=>{let r=n.cell,o=r.rowIndex;if(o<this.currentRowIndex&&o+r.rowSpan>this.currentRowIndex){let s=i[o];s||(s=i[o]=[]),s.push(n)}}),this.didExtractRowSpanningCellBreakPositions=i.length>0,i}layoutRowSpanningCellsFromPreviousFragment(e){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return F(!0);let o=this.column.layoutContext,s=e.nodeContext;s.viewNode.remove();let a=V("layoutRowSpanningCellsFromPreviousFragment"),h=F(!0),l=0,c=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=Ss(d[0].cellNodePosition.steps[1],s.parent);return o.setCurrent(p,!1).thenAsync(()=>{let g=Lt(p).viewNode,m=F(!0),v=0;function b(x){for(;v<x;){if(!c.includes(v)){let C=g.ownerDocument.createElement("td");R(C,"padding","0"),g.appendChild(C)}v++}}return d.forEach(x=>{m=m.thenAsync(()=>{let C=x.cell;b(C.anchorColumnIndex);let y=x.cellNodePosition,k=Ss(y.steps[0],p);return k.offsetInNode=y.offsetInNode,k.after=y.after,k.fragmentIndex=y.steps[0].fragmentIndex+1,o.setCurrent(k,!1).thenAsync(()=>{let S=x.breakChunkPosition;for(let N=0;N<C.colSpan;N++)c.push(v+N);return v+=C.colSpan,this.layoutCell(C,k,S).thenAsync(()=>(k.viewNode.rowSpan=C.rowIndex+C.rowSpan-this.currentRowIndex+r-l,F(!0)))})})}),m.thenAsync(()=>(b(i.getColumnCount()),l++,F(!0)))})})}),h.then(()=>{o.setCurrent(s,!0,e.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(e){if(this.inHeader||this.inFooter)return F(!0);let i=e.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(e).thenAsync(()=>{var r;this.registerCellFragmentIndex();let o=e.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(o=nt(o,a.breakAfter))}let s=n.rows[this.currentRowIndex];return s!=null&&s.breakBefore&&(o=nt(o,s.breakBefore)),!e.leadingEdge&&Ye(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o),(r=i.viewNode)==null||r.remove(),e.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(e.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),e.break=!0,F(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,e.break=!0),F(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(e=>{let i=this.formattingContext.cellBreakPositions.find(n=>n.cell===e);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);qx(r,n.fragmentIndex+1,1)}})}startTableCell(e){if(this.inHeader||this.inFooter)return F(!0);let i=e.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 e.break=!0,F(!0);let r=i.copy().modify();r.after=!0,e.nodeContext=r;let o=V("startTableCell"),s,a=this.findBrokenCellAtSlot(n.anchorColumnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,s=F(h.breakChunkPosition)}else s=this.column.nextInTree(i,e.atUnforcedBreak).thenAsync(h=>{let l=h.viewNode;l&&i.viewNode.removeChild(l);let c=xs(h,0);return F(new zi(c))});return s.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(e),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(e){let i=Ig(e,Gt(this.formattingContext),this.column);if(i)return i;let n=e.nodeContext,r=this.formattingContext.getRepetitiveElements(),o=n.display;return o==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,F(!0)):o==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,F(!0)):o==="table-row"?this.startTableRow(e):o==="table-cell"?this.startTableCell(e):F(!0)}endNonInlineBox(e){let i=e.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new bS(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return F(!0)}afterNonInlineElementNode(e){let i=e.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.remove()):R(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.remove()):R(i.viewNode,"display","table-row-group")),r&&Rg.ignoreList[r])i.viewNode.remove();else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),e.break=!0;else if(r==="table-row"&&!this.inHeader&&!this.inFooter){let o=super.afterNonInlineElementNode(e);return(o&&o.isPending()?o:F(!0)).thenAsync(()=>{if(!e.break){let s=this.column.checkOverflowAndSaveEdge(i,null),a=this.formattingContext.getRepetitiveElements(),h=this.column.nodeContextOverflowingDueToRepetitiveElements===i,l=!s&&h&&!!(a!=null&&a.isFooterRegistered());(s||h)&&!l&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),i.overflow=!0,e.break=!0)}return F(!0)})}else return super.afterNonInlineElementNode(e);return F(!0)}};u(Fg,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var PS=Fg,Zr=[];function ES(t){let e=Zr.findIndex(n=>n.root===t),i=Zr[e];return i?i.tableLayoutOption:null}function NS(t){let e=Zr.findIndex(i=>i.root===t);e>=0&&Zr.splice(e,1)}var Lg=class{layoutEntireTable(t,e){let i=Gt(t.formattingContext),n=new kS(i,e);return new pl(n,e.layoutContext).iterate(t)}getColumnWidths(t,e,i,n){let r=t.ownerDocument,o=r.createElement("tr"),s=[];for(let h=0;h<e;h++){let l=r.createElement("td");o.appendChild(l),s.push(l)}t.after(o);let a=s.map(h=>{let l=_t(n,h,i),c=i?l.height:l.width;return Math.ceil(c)});return o.remove(),a}getColGroupElements(t){let e=[],i=t.firstElementChild;for(;i;)i.localName==="colgroup"&&e.push(i),i=i.nextElementSibling;return e}normalizeAndGetColElements(t){let e=[];return t.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let o=r.span;for(r.removeAttribute("span"),n-=o;o-- >1;){let s=r.cloneNode(!0);i.insertBefore(s,r),e.push(s)}e.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),e.push(r)}),e}addMissingColElements(t,e,i,n){if(t.length<i){let r=n.ownerDocument.createElement("colgroup");e.push(r);for(let o=t.length;o<i;o++){let s=n.ownerDocument.createElement("col");r.appendChild(s),t.push(s)}}}normalizeColGroups(t,e,i){let n=t.vertical,r=t.lastRowViewNode;if(!r)return;t.lastRowViewNode=null;let o=r.ownerDocument.createDocumentFragment(),s=t.getColumnCount();if(!(s>0)){t.colGroups=o;return}let a=t.colWidths=this.getColumnWidths(r,s,n,i.clientLayout),h=this.getColGroupElements(e),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,s,e),l.forEach((c,d)=>{R(c,n?"height":"width",`${a[d]}px`)}),h.forEach(c=>{o.appendChild(c.cloneNode(!0))}),t.colGroups=o}doInitialLayout(t,e){let i=Gt(t.formattingContext);i.vertical=t.vertical,i.initializeRepetitiveElements(t.vertical);let n=ES(t.sourceNode);NS(t.sourceNode);let r=V("TableLayoutProcessor.doInitialLayout"),o=t.copy();return this.layoutEntireTable(t,e).then(s=>{var a;let h=s.viewNode,l=i.rows[0];if(l&&Ye(l.breakBefore)&&this.hasInFlowContentBefore(h,e)){(a=h.parentNode)==null||a.removeChild(h),e.pageBreakType=l.breakBefore,r.finish(o);return}let c=_t(e.clientLayout,h,e.vertical),d=e.vertical?c.left:c.bottom;if(d+=(e.vertical?-1:1)*zn(t,e.collectElementsOffset()).current,!e.isOverflown(d)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){e.breakPositions.push(new FS(o)),r.finish(s);return}this.normalizeColGroups(i,h,e),i.updateCellSizes(e.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(t){for(let e=0;e<t.rows.length;e++){let i=t.rows[e];if(i&&(e>0&&Ye(i.breakBefore)||e<t.rows.length-1&&Ye(i.breakAfter)))return!0}return!1}hasInFlowContentBefore(t,e){let i=t;for(;i&&i!==e.element;){let n=i.previousSibling;for(;n;){if(n.nodeType===1&&!Mt(n)||n.nodeType===3&&!Ee(n))return!0;n=n.previousSibling}i=i.parentNode}return!1}addCaptions(t,e,i){let n=t.captions;n.forEach((r,o)=>{r&&(e.insertBefore(r.viewNode,i),r.side==="top"&&(n[o]=null))})}addColGroups(t,e,i){t.colGroups&&this.getColGroupElements(e).length===0&&(e.insertBefore(t.colGroups.cloneNode(!0),i),R(e,"table-layout","fixed"),R(e,t.vertical?"height":"width",`${t.tableWidth}px`))}removeColGroups(t,e){if(t.colGroups&&e){let i=this.getColGroupElements(e);i&&i.forEach(n=>{e.removeChild(n)})}}doLayout(t,e){let i=Gt(t.formattingContext),n=i.getRootViewNode(t),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let o=new PS(i,e),s=new pl(o,e.layoutContext),a=V("TableFormattingContext.doLayout");return s.iterate(t).thenFinish(a),a.result()}layout(t,e,i){let n=Gt(t.formattingContext);if(n.getRootViewNode(t)){if(i){let r=n.getRepetitiveElements();r&&t.sourceNode!==n.tableSourceNode&&!t.after&&!r.isFooterRegistered()&&r.preventSkippingHeader(),Eg(t.parent,e)}return new IS(n,this).layout(t,e)}else return e.buildDeepElementView(t)}createEdgeBreakPosition(t,e,i,n){return new wS(t,e,i,n)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return za(t),!1}finishBreak(t,e,i,n){let r=Gt(e.formattingContext);if(e.display==="table-row"){let o=r.findRowIndexBySourceNode(e.sourceNode),s;if(e.after?s=r.getRowSpanningCellsOverflowingTheRow(o):s=r.getCellsFallingOnRow(o),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!s.includes(a.cell)),s.length){let a=V("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===s.length){l.breakLoop();return}let c=s[h++],d=r.getCellFragmentOfCell(c),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),m=new zi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:c});let v=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),o<c.rowIndex+c.rowSpan-1&&(v.rowSpan=o-c.rowIndex+1),d.empty?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{TS(d,r,p),l.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),za(e),r.finishFragment(),a.finish(!0)}),a.result()}}return za(e),r.finishFragment(),wh.finishBreak(t,e,i,n)}clearOverflownViewNodes(t,e,i,n){On.prototype.clearOverflownViewNodes(t,e,i,n)}};function TS(t,e,i){let n=e.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=e.vertical,o=t.column,s=t.pseudoColumn.getColumnElement(),a=t.cellNodeContext.viewNode,h=_t(o.clientLayout,a,r),l=o.getComputedPaddingBorder(a);if(r){let c=h.right-o.footnoteEdge-n.calculateOffset(i)-l.right;R(s,"max-width",`${c}px`)}else{let c=o.footnoteEdge-n.calculateOffset(i)-h.top-l.top;R(s,"max-height",`${c}px`)}}function Og(t){let e=t.matches("td, th")?t:t.closest("td, th");if(!e||e.style.verticalAlign!=="baseline")return;let i=e.querySelector(".-vivliostyle-table-cell-container");if(!i)return;let n=i.children;if(n.length!==0){for(let r=0;r<n.length;r++){let o=n[r].style.position;if(o!=="absolute"&&o!=="fixed")return}R(i,"display","contents")}}function za(t){let e=t.display;if(e!=="table-row"&&e!=="table")return;let i=Lt(t),n=e==="table-row"?i.viewNode.parentElement:i.viewNode.querySelector("tbody");if(!n)return;let r;try{r=n.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(r.length===0)return;let o=Array.from(r).reduce((f,g)=>{let m=g.getBoundingClientRect(),v=t.vertical?m.width:m.height;return f+v},0),s=r[r.length-1],a=Array.from(n.children).indexOf(s),h=Array.from(s.children).reduce((f,g)=>{let m=g.rowSpan;return m>1&&a+m<n.childElementCount?Math.max(f,m):f},0),l=h?n.children[a+h-1]:n.lastElementChild;if(l!=n.lastElementChild&&l.querySelector(":scope>*>div>div")){for(let f=l;f&&f!==n.lastElementChild;f=f.nextElementSibling)if(f.querySelector(":scope>[rowspan]:not([rowspan='1'])")){l=f;break}}let c=l.getBoundingClientRect(),d=t.vertical?c.width:c.height,p=o+d;R(l,t.vertical?"width":"height",`${p}px`)}var IS=class extends bh{constructor(t,e){super(),u(this,"tableFormattingContext",t),u(this,"processor",e)}resolveLayoutMode(t){let e=this.tableFormattingContext.getRepetitiveElements();return!e||!e.doneInitialLayout?new AS(this.tableFormattingContext,this.processor):(t.sourceNode===this.tableFormattingContext.tableSourceNode&&!t.after&&e&&e.preventSkippingHeader(),new LS(this.tableFormattingContext,this.processor))}clearNodes(t){super.clearNodes(t);let e=this.tableFormattingContext.getRootViewNode(t);this.processor.removeColGroups(this.tableFormattingContext,e)}restoreState(t,e){super.restoreState(t,e),this.tableFormattingContext.finishFragment()}},AS=class extends Cg{constructor(t,e){super(t),u(this,"processor",e)}doLayout(t,e){return this.processor.doInitialLayout(t,e)}},FS=class extends po{constructor(t){super(t,null,t.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(t){t.fragmentLayoutConstraints.push(new RS(this.position.sourceNode))}},RS=class Bg{constructor(e){u(this,"tableRootNode",e),u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(e,i,n){return e.overflow,!1}nextCandidate(e){return!0}postLayout(e,i,n,r){Zr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(e,i){return F(!0)}equalsTo(e){return e instanceof Bg&&e.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},LS=class extends kg{constructor(t,e){super(t),u(this,"processor",e)}doLayout(t,e){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(t)){let n=new OS(t);e.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||e.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(t,e)}},OS=class Mg extends Vh{constructor(e){super(e),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||Rn(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:i&&!e||e&&e.overflow?!Ng(e,i,r):!0}nextCandidate(e){let i=Gt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(e,i).some(n=>n.constraints.some(r=>r.nextCandidate(e)))?!0:super.nextCandidate(e)}postLayout(e,i,n,r){let o=Gt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,o),this.cellFragmentLayoutConstraints.forEach(s=>{s.constraints.forEach(a=>{a.postLayout(e,s.breakPosition,n,r)})}),!e){let s=o.getRootViewNode(this.nodeContext);new Lg().removeColGroups(o,s),this.removeDummyRowNodes(n)}super.postLayout(e,i,n,r)}finishBreak(e,i){let n=Gt(this.nodeContext.formattingContext),r=V("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),s=0;return r.loop(()=>{if(s<o.length){let a=o[s++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return F(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(e,i))}removeDummyRowNodes(e){if(!(!e||e.display!=="table-row"||!e.viewNode))for(;e.viewNode.previousElementSibling;){let i=e.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(e,i){return this.getCellFragemnts(e,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(e,i){let n=Number.MAX_VALUE;e&&e.display==="table-row"&&(n=i.findRowIndexBySourceNode(e.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let o=0;o<n;o++)i.cellFragments[o]&&i.cellFragments[o].forEach(s=>{s&&r.push({fragment:s,breakPosition:s.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(e){let i=Gt(this.nodeContext.formattingContext),n=i.findCellFromColumn(e);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof Mg?Gt(this.nodeContext.formattingContext)===Gt(e.nodeContext.formattingContext):!1}},BS=new Lg;function MS(t,e,i,n,r,o){if(!e)return null;if(i===w.table){let s=t.parent;return new $n(s?s.formattingContext:null,t.sourceNode)}return null}function _S(t){return t instanceof $n?BS:null}Ft("RESOLVE_FORMATTING_CONTEXT",MS);Ft("RESOLVE_LAYOUT_PROCESSOR",_S);function bc(t){return t.reduce((e,i)=>e+i,0)/t.length}function DS(t){let e=bc(t);return bc(t.map(i=>{let n=i-e;return n*n}))}var zS=class{constructor(t,e){u(this,"layoutResult",t),u(this,"penalty",e)}};function Kr(t){return t.vertical?t.width:t.height}function Jr(t,e){t.vertical?t.width=e:t.height=e}var _g=class{constructor(t,e,i){u(this,"layoutContainer",t),u(this,"columnGenerator",e),u(this,"regionPageFloatLayoutContext",i),u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Kr(t)}balanceColumns(t){let e=V("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),this.preBalance(t),this.savePageFloatLayoutContexts(t),this.layoutContainer.clear();let i=[this.createTrialResult(t)];return e.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,o)=>o.penalty<r.penalty?o:r,i[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),e.finish(n.layoutResult)}),e.result()}createTrialResult(t){let e=this.calculatePenalty(t);return new zS(t,e)}preBalance(t){}postBalance(){Jr(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(t){if(t.length<=1)return;let e=Math.max.apply(null,t.map(i=>i.computedBlockSize));if(!(e<=0))for(let i of t)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>e){let o=r+n-e;R(i.element,"width",`${e}px`),R(i.element,"left",`${o}px`),i.width=e,i.left=o}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>e&&(R(i.element,"height",`${e}px`),i.height=e)}}savePageFloatLayoutContexts(t){let e=this.regionPageFloatLayoutContext.detachChildren();t&&(t.columnPageFloatLayoutContexts=e)}restoreContents(t){let e=this.layoutContainer.element;t.columns.forEach(i=>{e.appendChild(i.element)}),t.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(t.columnPageFloatLayoutContexts)}},Dl=1;function Dg(t){let e=t[t.length-1];if(e.penalty===0)return!1;let i=t[t.length-2];if(i&&e.penalty>=i.penalty)return!1;let n=e.layoutResult.columns,r=Math.max.apply(null,n.map(s=>s.computedBlockSize)),o=Math.max.apply(null,n.map(s=>s.getMaxBlockSizeOfPageFloats()));return r>o+Dl}function zg(t,e){let i=t[t.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+Dl))-Dl;n<Kr(e)?Jr(e,n):Jr(e,Kr(e)-1)}var VS=class extends _g{constructor(t,e,i,n){super(i,t,e),u(this,"columnCount",n),u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(t){let e=t.columns.reduce((i,n)=>i+n.computedBlockSize,0);Jr(this.layoutContainer,e/this.columnCount),this.originalPosition=t.position}checkPosition(t){return this.originalPosition?this.originalPosition.isSamePosition(t):t===null}calculatePenalty(t){if(!this.checkPosition(t.position))return 1/0;let e=t.columns;return xc(e)?1/0:Math.max.apply(null,e.map(i=>i.computedBlockSize))}hasNextCandidate(t){if(t.length===1)return!0;if(this.foundUpperBound)return Dg(t);{let e=t[t.length-1];return this.checkPosition(e.layoutResult.position)&&!xc(e.layoutResult.columns)?(this.foundUpperBound=!0,!0):Kr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(t){if(this.foundUpperBound)zg(t,this.layoutContainer);else{let e=Math.min(this.originalContainerBlockSize,Kr(this.layoutContainer)+this.originalContainerBlockSize*.1);Jr(this.layoutContainer,e)}}};function xc(t){if(t.length<=1)return!1;let e=t[t.length-1].computedBlockSize,i=t.slice(0,t.length-1),n=Math.max(...t.map(o=>o.lastLineStride||0)),r=n>0?n/2:6;return i.every(o=>e>o.computedBlockSize+r)}var $S=class extends _g{constructor(t,e,i){super(i,t,e)}calculatePenalty(t){if(t.columns.every(i=>i.computedBlockSize===0))return 1/0;let e=t.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return DS(e)}hasNextCandidate(t){return Dg(t)}updateCondition(t){zg(t,this.layoutContainer)}};function HS(t,e,i,n,r,o,s){if(e===w.auto)return null;{let a=s.positions.length===0,h=o[o.length-1],l=!!(h&&h.pageBreakType);return a||l?new VS(i,n,r,t):e===w.balance_all?new $S(i,n,r):(w.balance,null)}}var Va=class{constructor(t,e,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=t,this.endFixed=e,this.endSlipped=i}},US=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(t){if(this.map.length==0)this.map.push(new Va(t,t,t));else{let e=this.map[this.map.length-1],i=e.endSlipped+t-e.endFixed;e.endFixed==e.endStuckFixed?(e.endFixed=t,e.endStuckFixed=t,e.endSlipped=i):this.map.push(new Va(t,t,i))}}addSlippedRange(t){this.map.length==0?this.map.push(new Va(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=yi(this.map.length,n=>t<=this.map[n].endFixed),i=this.map[e];return i.endSlipped-Math.max(0,i.endStuckFixed-t)}fixedBySlipped(t){let e=yi(this.map.length,n=>t<=this.map[n].endSlipped),i=this.map[e];return i.endStuckFixed-(i.endSlipped-t)}};function WS(t){let e={};return Object.keys(t).forEach(i=>{e[i]=Array.from(t[i])}),e}var GS=class zl{constructor(e,i,n,r,o,s,a,h){if(u(this,"context",e),u(this,"style",i),u(this,"offset",n),u(this,"isRoot",r),u(this,"flowChunk",o),u(this,"atBlockStart",s),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=o.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new zl(e,l.before,n,!1,o,this.isBlock(),a,!0),d=c.styleValue("content");At(d)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=nt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ye(this.breakBefore)&&(o.breakBefore=nt(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(e,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let o=new zl(this.context,r.after,e,!1,this.flowChunk,i,n,!0),s=o.styleValue("content");At(s)&&(this.afterBox=o)}}}styleValue(e,i){if(!(e in this.styleValues)){let n=this.style[e];this.styleValues[e]=n?n.evaluate(this.context,e):i||null}return this.styleValues[e]}displayValue(){return this.styleValue("display",w.inline)}isBlock(){if(this.isBlockValue===null){let e=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=uw(e,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==w.none&&!Nr(this.styleValue("position"))),this.hasBoxValue}getBreakValue(e){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${e}`);n&&(i=n.toString())}return i}},jS=class{constructor(t){u(this,"context",t),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 t=this.lastBox();return t?t.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(t=>t.displayValue()!==w.none)}push(t,e,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=n||r.flowChunk,s=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new GS(this.context,t,e,i,o,s||this.atBlockStart,s,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&s:this.atFlowStart,h}encounteredTextNode(t){let e=this.lastBox();if((t.nodeType===Node.TEXT_NODE||t.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&e.hasBox()){let i=e.styleValue("white-space",w.normal).toString(),n=Ap(i);n&&!Ee(t,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(t){let e=this.stack.pop();if(e.buildAfterPseudoElementBox(t,this.atBlockStart,this.atFlowStart),this.atFlowStart&&e.afterBox){let n=e.afterBox.getBreakValue("before");e.flowChunk.breakBefore=nt(e.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===e.flowName)e.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return e}nearestBlockStartOffset(t){if(!t.atBlockStart)return t.offset;let e=this.stack.length-1,i=this.stack[e];for(i===t&&(e--,i=this.stack[e]);e>=0;){if(i.flowName!==t.flowName)return t.offset;if(!i.atBlockStart||i.isRoot)return i.offset;t=i,i=this.stack[--e]}throw new Error("No block start offset found!")}},XS=class{constructor(t){u(this,"xmldoc",t),u(this,"map",{})}setAt(t,e){this.map[`e${t}`]=e}styleOf(t){return this.map[`e${this.xmldoc.getElementOffset(t)}`]}},Sc=class{constructor(t,e,i,n,r,o,s,a,h,l,c){u(this,"xmldoc",t),u(this,"scope",i),u(this,"context",n),u(this,"primaryFlows",r),u(this,"validatorSet",o),u(this,"counterListener",s),u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"bodyPropagatedStyle",{}),u(this,"styles"),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,"elementWindow"),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=t.root,this.cascadeHolder=e,this.styles=new XS(t),this.last=Km.atRoot(this.root),this.cascade=e.createInstance(n,s,a,t.lang,h,l,this.root,i,o,this.styles,c),this.offsetMap=new US;let d=t.getElementOffset(this.root);this.lastOffset=d,this.boxStack=new jS(n),this.offsetMap.addStuckRange(d);let p=this.getAttrStyle(this.root);this.elementWindow=this.cascade.pushElement(this.root,p,d),this.recordCounterSnapshot(d,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),this.postprocessTopStyle(p,!1),this.determineRootSizes(p),this.root.namespaceURI==="http://www.w3.org/1999/xhtml"&&(this.bodyReached=!1),this.primaryStack.push(!0),this.styles.setAt(d,p),this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(t,e,i){let n=t[i];return n&&n.evaluate(this.context)!==e[i]}transferPropsToRoot(t,e){for(let i in e){let n=t[i];if(n)this.rootStyle[i]=n,delete t[i];else{let r=e[i];r&&(this.rootStyle[i]=new X(r,yp))}}}postprocessTopStyle(t,e){if(e)for(let i of["writing-mode","direction"])t[i]&&!this.rootStyle[i]&&(this.rootStyle[i]=t[i],this.bodyPropagatedStyle[i]=t[i]);else for(let i in t)Mn(i)&&(this.rootStyle[i]=t[i]);if(!this.rootBackgroundAssigned){let i=this.hasProp(t,this.validatorSet.backgroundProps,"background-color")?t["background-color"].evaluate(this.context):null,n=this.hasProp(t,this.validatorSet.backgroundProps,"background-image")?t["background-image"].evaluate(this.context):null;if(i&&!Z(i)||n&&!Z(n)){this.transferPropsToRoot(t,this.validatorSet.backgroundProps);for(let r of["background-position-x","background-position-y"]){let o=t[r];o&&(this.rootStyle[r]=o,delete t[r])}this.rootBackgroundAssigned=!0}}if(!this.rootLayoutAssigned){for(let i=0;i<Cc.length;i++)if(this.hasProp(t,this.validatorSet.layoutProps,Cc[i])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}}determineRootSizes(t){var e;let i=t["font-size"],n=!0;if(i&&!Z(i.value)){let h=i.evaluate(this.context),l=this.resolveRootSizingCalc(h),c=h instanceof Vt&&l instanceof B;if(l instanceof B){let d=l.num;switch(l.unit){case"em":case"rem":d*=this.context.initialFontSize;break;case"%":d*=this.context.initialFontSize/100;break;case"lh":case"rlh":d*=this.context.rootLineHeight;break;default:{let p=vi[l.unit];p&&(d*=p),n=c}}this.context.rootFontSize=d,this.context.isRelativeRootFontSize=n}}let r=(e=this.context.rootFontSize)!=null?e:this.context.initialFontSize,o=t["line-height"],s=null,a=!1;if(o&&!Z(o.value)){let h=o.evaluate(this.context),l=this.resolveRootSizingCalc(h);if(a=h instanceof Vt&&l instanceof B,l instanceof It)s=l.num*r;else if(l instanceof B){let c=l.num;switch(l.unit){case"em":case"rem":c*=r;break;case"%":c*=r/100;break;case"lh":case"rlh":c*=this.context.rootLineHeight;break;default:{let d=vi[l.unit];d&&(c*=d)}}s=c}}this.context.rootLineHeight=s??this.context.fontSize()*this.context.pref.lineHeight,this.context.isRootLineHeightFromRelativeCalc=a}resolveRootSizingCalc(t){return t instanceof Vt?t.visit(new _x(this.context)):t}getTopContainerStyle(){let t=0;for(;!this.bodyReached&&(t+=5e3,this.styleUntil(t,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(t){if(t.style instanceof CSSStyleDeclaration){let e=t.getAttribute("style");if(e)return Bx(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}recordCounterSnapshot(t,e,i=[],n){let r={offset:t,counters:WS(e),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},o=this.counterSnapshots[this.counterSnapshots.length-1];if(o&&o.offset===t){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(t){if(!this.counterSnapshots.length)return null;let e=yi(this.counterSnapshots.length,n=>t<this.counterSnapshots[n].offset),i=e===0?0:e-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(t){if(t>=this.lastOffset)return;let e=this.context,i=this.xmldoc.getElementOffset(this.root);if(t<i){let o=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let l=o.page,c=l&&!Z(l.value)&&l.value.toString();c&&c.toLowerCase()!=="auto"&&(this.cascade.firstPageType=c)}let s=ge(o,"flow-into"),a=s?s.evaluate(e,"flow-into").toString():"body",h=this.encounteredFlowElement(a,o,this.root,i);this.boxStack.empty()&&this.boxStack.push(o,i,!0,h)}let n=this.xmldoc.getNodeByOffset(t),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let s=n,a=this.getStyle(s,!1),h=a["flow-into"];if(h){let l=h.evaluate(e,"flow-into").toString();this.encounteredFlowElement(l,a,s,r)}r++}if(r>=this.lastOffset)break;let o=n.firstChild;if(o==null){for(;o=n.nextSibling,!o;)if(n=n.parentNode,n===this.root)return}n=o}}resetFlowChunkStream(t){this.flowListener=t;for(let e=0;e<this.flowChunks.length;e++)this.flowListener.encounteredFlowChunk(this.flowChunks[e],this.flows[this.flowChunks[e].flowName])}styleUntilFlowIsReached(t){this.flowToReach=t;let e=0;for(;!(this.flowToReach==null||(e+=5e3,this.styleUntil(e,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(t){if(!t)return;this.idToReach=t;let e=0;for(;!(!this.idToReach||(e+=5e3,this.styleUntil(e,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(t,e,i,n){let r=0,o=Number.POSITIVE_INFINITY,s=!1,a=!1,h=!1,l=e["flow-options"];if(l){let m=Vy(l.evaluate(this.context,"flow-options"));s=!!m.exclusive,a=!!m.static,h=!!m.last}let c=e["flow-linger"];c&&(o=Pu(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=e["flow-priority"];d&&(r=Pu(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[t];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[t]=new Ew(t,m,new ra(null))}let g=new Nw(t,i,n,r,o,s,a,h,p);return this.flowChunks.push(g),this.flowToReach==t&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(t,e,i){if(Ye(t)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<e)&&r.push(e)}let n=this.breakBeforeValues[e];this.breakBeforeValues[e]=nt(n,t)}styleUntil(t,e){let i=-1,n;if(t<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(t),i=n+e,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;this.last;){let o=this.last.firstChild;if(o==null)for(;this.last;){if(this.last.node.nodeType==1){this.cascade.popElement(this.last.node),this.primary=this.primaryStack.pop();let a=this.boxStack.pop(this.lastOffset),h=null;if(a.afterBox){let l=a.afterBox.getBreakValue("before");this.registerForcedBreakOffset(l,a.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(a):a.afterBox.offset,a.flowName),h=a.afterBox.getBreakValue("after")}h=nt(h,a.getBreakValue("after")),this.registerForcedBreakOffset(h,this.lastOffset,a.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parent,!this.last)return t<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(t),i=n+e),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}let s=o;if(this.last=s,s.node.nodeType!=1)this.lastOffset+=s.node.textContent.length,this.boxStack.encounteredTextNode(s.node),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let a=s.node,h=this.getAttrStyle(a);this.primaryStack.push(this.primary),this.elementWindow=this.cascade.pushElement(a,h,this.lastOffset),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let l=a.getAttribute("id")||a.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");l&&l===this.idToReach&&(this.idToReach=null),!this.bodyReached&&a.localName=="body"&&a.parentNode==this.root&&(this.postprocessTopStyle(h,!0),this.bodyReached=!0);let c,d=h["flow-into"];if(d){let f=d.evaluate(r,"flow-into").toString(),g=this.encounteredFlowElement(f,h,a,this.lastOffset);this.primary=!!this.primaryFlows[f],c=this.boxStack.push(h,this.lastOffset,a===this.root,g)}else c=this.boxStack.push(h,this.lastOffset,a===this.root),a===this.xmldoc.body&&(c.breakBefore=nt(c.flowChunk.breakBefore,c.breakBefore));let p=this.boxStack.nearestBlockStartOffset(c);if(p===0||a===this.xmldoc.body){let f=h.page,g=f&&!Z(f.value)&&f.value.toString();!this.cascade.firstPageType&&g&&g.toLowerCase()!=="auto"&&(this.cascade.firstPageType=g)}if(this.registerForcedBreakOffset(c.breakBefore,p,c.flowName),c.beforeBox){let f=c.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(f,c.beforeBox.atBlockStart?p:c.offset,c.flowName)}if(this.primary&&c.displayValue()===w.none&&(this.primary=!1),this.styles.setAt(this.lastOffset,h),this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&p===0)continue;if(t<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(t),i=n+e),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}return Number.POSITIVE_INFINITY}getStyle(t,e){let i=this.xmldoc.getElementOffset(t);return e&&(i=this.xmldoc.getNodeOffset(t,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styles.styleOf(t)}processContent(t,e,i){}},Cc=["column-count","column-width","column-fill"],Ok=`OTTO${new Date().valueOf()}`;function $h(t){return Object.keys(t).filter(e=>!["src","font-family","font-display"].includes(e)).sort()}function qS(t){let e=new mi;for(let i of $h(t))e.append(`${i}:${t[i].toString()};`);return e.toString()}function YS(t,e){let i={};for(let n in t)i[n]=ge(t,n).evaluate(e,n);return i}var Vg=class{constructor(t){u(this,"properties",t),u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),u(this,"styleElement",null),this.fontTraitKey=qS(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let e=this.properties["font-family"];this.family=e?e.stringValue():null}traitsEqual(t){return this.fontTraitKey==t.fontTraitKey}makeAtRule(t,e){let i=new mi;i.append(`@font-face {
1874
1878
  font-family: `),i.append(this.family),i.append(`;
1875
- `);for(let n of ph(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1876
- `);if(t){i.append('src: url("');let n=ev(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1879
+ `);for(let n of $h(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1880
+ `);if(e){i.append('src: url("');let n=Yv(e);i.append(n),this.blobURLs.push(n),this.blobs.push(e),i.append('")')}else i.append("src: "),i.append(t);return i.append(`;
1877
1881
  }
1878
- `),i.toString()}},Ax=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 Oe){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(B(r)),i.push(n)}return new Oe(i)}else{let t=this.familyMap[e.stringValue()];return t?new Oe([B(t),e]):e}}},Ix=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=M("initFont"),r=e.src,o={};for(let l of ph(e.properties))o[l]=e.properties[l];let s=this.getViewFontFamily(e,i);o["font-family"]=B(s);let a=new Zf(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),Y.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{t.registerFamily(e,o),Y.debug("Found already-loaded font:",i)}):(r=new Jr(()=>{let o=M("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(s):null;return a?Bs(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(o)})}):this.initFont(e,null,t).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){Y.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return Dn(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return T(!0);let i=M("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?T(!0):T(!1))).thenFinish(i),i.result()}},vi=!0;function Fx(e){vi=e}var Ki=[];function Wu(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Kf(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 fh(e,t,i){if(!vi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Kf(e.ownerDocument).includes(e))return T(!1);let n=e.textContent,r=e.src,o=e.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&e.async&&!s,h=(o&&!a||r&&e.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Jf(t)||(t.onload=null),l)return Ki.some(d=>Wu(d,e))||Ki.push(e),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Wu(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(Y.debug("script:",r),r){let d=Et(c);return t.document.head.appendChild(c),Dn([d])}else return t.document.head.appendChild(c),T(!0)}function Rx(e,t){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let c of Object.values(l))r(c)},o=s=>{if(s instanceof oh)r(s.style);else if(s instanceof Yn||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(t.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of e.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function Lx(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=Rx(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function Ox(e,t,i){if(!vi)return T(!1);let n=Kf(e);if(n.length===0)return T(!1);let r=n.some(c=>!(c.async||c.defer||c.type==="module")),o=r?Lx(e,t,i):null,s=t.document.fonts,a=t.$,h=!1,l=M("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return s.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let c=n.shift();return fh(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Ki.push(c),h=!0),n.length===0&&r&&(Y.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function Bx(e){if(!vi)return T(!1);let t=M("loadScripts");return t.loop(()=>Ki.length===0?T(!1):fh(Ki.shift(),e,{atEnd:!0}).thenReturn(Ki.length>0)).then(()=>{Y.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),Y.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Jf(e){return vi?Ki.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Mx=e=>String(e).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Nl),_x=e=>`"${Mx(e)}"`,ba=(e,t,i)=>_x(i.transformURL(xi(String(e)),t)),Dx=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${ba(r,t,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${ba(r,t,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${ba(r,t,i)}`),zx={},Vx=new Set(["base","body","head","html","link","meta","script","style","title"]);function Ux(e){if(e instanceof K)return e;if(e instanceof J){let t=[];for(let i of e.values)if(i instanceof K)t.push(i.str);else return null;if(t.length>0)return new K(t.join(""))}return null}function $x(e){return e instanceof Qe?e:e instanceof J&&e.values[0]instanceof Qe&&e.values.slice(1).every(t=>t instanceof K&&t.str.trim()==="")?e.values[0]:null}function Hx(e){if(Gr!=="webkit")return!1;let t=e["--viv-marker-content"];if(!t)return!1;let i=$x(t);if(i)return e["list-style-type"]=y.none,e["list-style-image"]=i,delete e["--viv-marker-content"],!0;let n=Ux(t);return n?(e["list-style-type"]=n,e["list-style-image"]=y.none,!0):!1}function Wx(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 gl=class gr extends Tl{constructor(t,i,n,r,o,s,a,h,l,c,d,p,f,g,v,w=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",o),u(this,"xmldoc",s),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",v),u(this,"semanticFootnoteFirstRefOffsets",w),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 gr(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||Z(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 o=this.styler.getStyle(t,!1),s=(i=o?.display)==null?void 0:i.evaluate(this.styler.context,"display");if((s&&!Z(s)?s:y.inline)===y.none)return!1;let a=(n=o?.position)==null?void 0:n.evaluate(this.styler.context,"position"),h=a&&!Z(a)?a:y.static;if(vr(h)||Fr(h))return!1;let l=(r=o?.float)==null?void 0:r.evaluate(this.styler.context,"float");return(l&&!Z(l)?l:y.none)===y.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 o=this.styler.getStyle(r,!1),s=(i=o?.display)==null?void 0:i.evaluate(this.styler.context,"display"),a=s&&!Z(s)?s:y.inline;return Ut(a)?null:r}n=n.nextSibling}return null}getEffectiveStartPageType(t,i){let n=i,r=t;for(;r;){let o=this.getFirstInFlowChildElement(r);if(!o)return n;let s=this.getExplicitPageType(this.styler.getStyle(o,!1));s&&(n=s),r=o}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"||!Gt(t)||!du(t,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=t.getAttribute(Cr);if(!i)return;let n=fp(t,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(Cr,i)}createPseudoelementShadow(t,i,n,r,o,s,a,h){var l,c;let d=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,s);if(!d)return h;let p=[],f=pr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),g=f,v=Gt(t)&&!!d["footnote-call"]&&It((l=d["footnote-call"].content)==null?void 0:l.value);for(let m of N0){let S;if(m){if(!d[m])continue;let b=Pt(t),C=t.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&t.localName==="include"&&t.classList.contains("-vivliostyle-footnote-content");if(m=="footnote-call"&&!Gt(t)||m=="footnote-marker"&&!(b||C||i&&this.isFootnote)&&!((c=this.nodeContext)!=null&&c.pluginProps.nestedFootnoteDetached))continue;if(m.match(/^first-/)){let P=r.display;if(!P||P===y.inline)continue;let L=t.firstElementChild;if(L&&Ee(L.previousSibling)){let A=o.getStyle(L,!1);if(A){let z=ve(A,"display");if(z!=null&&z.value&&z.value!==y.inline)continue}}}if(m==="before"||m==="after"||m==="footnote-call"||m==="footnote-marker"){let P=d[m].content,L=(m==="before"||m==="after")&&(r.float===y.footnote||b||C)&&!!P;if(!P||!It(P.value)&&!L)continue}p.push(m),S=pr.createElementNS("http://www.w3.org/1999/xhtml","span"),Er(S,m)}else{if(v)continue;S=pr.createElementNS("http://www.pyroxy.com/ns/shadow","content")}g.appendChild(S),m.match(/^first-/)&&(g=S)}if(!p.length)return h;let w=new ya(t,n,o,s,this.exprContentListener),x=new Mo(t,f,null,a,h,st.ROOTLESS,w);return h||x}getPseudoMap(t,i,n,r,o){let s=ft(t,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};kr(l,s[h],o),cl(l,o,s[h]),Pf(s[h],i,n,(c,d)=>{kr(l,d,o),Cf(d,p=>{kr(l,p,o)})})}return a}createRefShadow(t,i,n,r,o){let s=M("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);o=new Mo(n,l,h,r,o,i,c)}}s.finish(o)}),s.result()}createShadows(t,i,n,r,o,s,a){let h=M("createShadows"),l=null,c=r.template,d;if(c instanceof Qe||c===y.footnote)if(c!==y.footnote||du(t,this.xmldoc.url,p=>this.xmldoc.getElementOffset(p),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let p=c instanceof Qe?c.url:Ae("user-agent.xml#footnote",Ni);d=this.createRefShadow(p,st.ROOTLESS,t,a,l)}else d=T(l);else d=T(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let v=t.getAttribute("href"),w=null;v?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?v=a.owner.getAttribute("href"):v=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),v&&(v=es(v,w.url),f=this.createRefShadow(v,st.ROOTED,t,a,p))}f==null&&(f=T(p));let g=null;f.then(v=>{if(r.display===y.table_cell){let w=Ae("user-agent.xml#table-cell",Ni);g=this.createRefShadow(w,st.ROOTLESS,t,a,v)}else g=T(v);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,o,s,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var o;let s=this.context,a=dl(n,s,this.regionIds,this.isFootnote,this.nodeContext),h=!((o=this.nodeContext)!=null&&o.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=kf(a,s,t);let c=!h&&t!==l;i=Ef(a,s,i);let d=(x,m)=>{let S;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(x)&&(S=s.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(x)&&(S=s.pageAreaWidth));let b=m.evaluate(s,x,S,t);return x=="font-family"&&(b=this.docFaces.filterFontFamily(b)),b},p=!!new Je(s.style.pageScope,"left-page").evaluate(s);if(Nf(a,r,t,i,p,d),c){let x=r[t?"height":"width"];(!x||x===y.auto)&&(r[t?"height":"width"]=y.max_content)}if(vr(r.position))return r.position=y.fixed,r.visibility=y.hidden,t;let f=r.position,g=r.float,v=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),w=Vd(v,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{w[x]&&(r[x]=w[x])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&Gt(w)){let x=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(x){let m=es(x,this.xmldoc.url),S=this.xmldoc.getElement(m);S&&Pt(S)&&((n=S.parentNode)==null?void 0:n.nodeType)===1&&(r=S.parentNode,l=null)}}}let c=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,x=!!w&&l.type==st.ROOTED&&Pt(r);if(!w||l.type==st.ROOTLESS||x){let m=(l?l.styler:this.styler).getStyle(r,!1);o.push(m),s=s||Ca(r)}w&&!x?(r=l.owner,l=l.parentShadow):(r=r.parentNode,c++)}let d=new Set;if(o.length>0){let w=o[0],x=dl(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let m in x){if(!In(m))continue;let S=x[m].evaluate(this.context,m);S&&S!==y.inherit&&S!==y.unset&&S!==y.revert&&S!==Me&&d.add(m)}}let p=c===0,f=this.context.queryUnitSize("em",p),g={"font-size":new W(new O(f,"px"),0)};p&&(g["line-height"]=new W(new At(this.context.pref.lineHeight),0));let v=new Ib(g,this.context);for(let w=o.length-1;w>=0;--w){let x=o[w],m=[];for(let C in x)In(C)&&m.push(C);m.sort(Dh);let S,b;for(let C of m){if(w>0&&h&&C.startsWith("--viv-marker-")||w>0&&d.has(C))continue;v.setPropName(C);let P=ve(x,C),L=P;if(P.value===y.initial)delete g[C];else if(!Z(P.value)){if(C==="font-size"&&w===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)L=new W(new O(this.context.rootFontSize,"px"),P.priority);else if(C==="line-height"&&w===o.length-1&&this.context.rootLineHeight&&P.value instanceof O&&(P.value.unit==="lh"||P.value.unit==="rlh"))L=new W(new O(this.context.rootLineHeight,"px"),P.priority);else if(w===0&&P.value instanceof O&&P.value.unit==="lh"){let A=this.getLineHeightUnitSize(C,S,b);A!=null&&(L=new W(new O(P.value.num*A,"px"),P.priority))}else Xe(C)||(L=P.filterValue(v));C==="font-size"?S=L.value:C==="line-height"&&(b=L.value),g[C]=L}}}for(let w in t)In(w)||(g[w]=t[w]);return{lang:s,elementStyle:g}}resolveURL(t){return t=Ae(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Ca(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=wb().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let o=t[r];if(o){if(Z(o))o===y.initial&&(n[r]=void 0);else if(o instanceof lt)n[r]=o.num;else if(o instanceof he)n[r]=o.name;else if(o instanceof O){let s=o;switch(s.unit){case"dpi":case"dpcm":case"dppx":n[r]=s.num*Zt[s.unit];break;default:n[r]=o}}else n[r]=o;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,o,s){let a=_t("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,o,s);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let o=!0,s=M("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 P=this.xmldoc.getElementOffset(a);Hs.registerFragmentIndex(P,this.nodeContext.fragmentIndex,0)}let c={},d={getStyle:P=>this.styler.getStyle(P,!1),getProp:(P,L)=>P?ve(P,L):null,getStyleMap:(P,L)=>ft(P,L),getMutableStyleMap:(P,L)=>si(P,L),createCascadeValue:(P,L)=>new W(P,L),filterFootnoteMarkerContent:(P,L)=>P.filterValue(new _r(this.styler.cascade,L,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let P=this.inheritFromSourceParent(l);l=P.elementStyle,this.nodeContext.lang=P.lang}let p=l.position,f=l.float,g=l["float-reference"],v=f&&!Z(f.value)&&f.value!==y.none&&g&&!Z(g.value)?Yv(g.value.toString()):null,w=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===st.ROOTED&&Pt(a);if(this.nodeContext.parent&&(vr(p?.value)||v&&Ii(v)||w)){let P=this.inheritFromSourceParent(l);l=P.elementStyle,this.nodeContext.lang=P.lang}l=Qv(a,l,this.nodeContext.shadowContext,this.xmldoc.url,P=>this.xmldoc.getElement(P),Cr,d),l=ew(a,l,this.nodeContext.shadowContext,this.context,d),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),v&&Ii(v)&&c.display===y.block&&(c.display=y.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 s.finish(!1),s.result();if(vi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return fh(a,this.viewport.window).thenFinish(s),s.result();let m=c.display;if(Pt(a)&&!w&&a.hasAttribute(pp)&&(m=c.display=y.none),Z(m)&&(m===y.initial||m===y.unset?m=y.inline:m===y.inherit?m=((n=this.nodeContext.parent)==null?void 0:n.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):m=null),m===y.none)return s.finish(!1),s.result();let S=this.nodeContext.parent==null,b=c[this.nodeContext.vertical?"width":"height"],C=(m===y.grid||m===y.inline_grid)&&!!b&&!(b===y.auto||Z(b));return this.nodeContext.flexContainer=m===y.flex||C,this.createShadows(a,S,l,c,h,this.context,this.nodeContext.shadowContext).then(P=>{var L,A;this.nodeContext.nodeShadow=P;let z=c.position,U=c.float,X=c.clear,re=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,k=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:re,_=dv(a),F=c["column-count"],D=c["column-width"],E=F&&F!==y.auto&&!Z(F)||D&&D!==y.auto&&!Z(D);this.nodeContext.establishesBFC=fv(m,z,U,c.overflow,re,k,E||_),this.nodeContext.containingBlockForAbsolute=gv(z),this.nodeContext.isInsideBFC()&&U!==y.footnote&&!(v&&Ii(v))&&(U=null,X=null);let N=null,R=!1,$=this.isFootnote&&(!((L=this.nodeContext)!=null&&L.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||w),V=tw(a,this.nodeContext.shadowContext,d);iw(V.sourceStyle,c,this.context),N=V.footnoteDisplay;let q=U instanceof J||U===y.left||U===y.right||U===y.top||U===y.bottom||U===y.inline_start||U===y.inline_end||U===y.block_start||U===y.block_end||U===y.snap_block||U===y.snap_inline||U===y.inside||U===y.outside||U===y.footnote;if(U&&(delete c.float,U===y.footnote))if(N=c["footnote-display"]||N,R=!!c["--viv-marker-content"],$){q=!1;let G=N?.toString();G&&(c["--viv-footnote-display"]=B(G)),m=R?B("list-item"):G==="inline"||G==="compact"?y.inline:y.block,c.display=m}else c.display=y.inline;if($&&Pt(a)){R=R||!!c["--viv-marker-content"];let G=N?.toString();G&&(c["--viv-footnote-display"]=B(G)),R&&(m=c.display=B("list-item")),!R&&(G==="inline"||G==="compact")&&(m=c.display=y.inline)}X&&(X===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(X=B(this.nodeContext.parent.clearSide)),(X===y.left||X===y.right||X===y.top||X===y.bottom||X===y.inline_start||X===y.inline_end||X===y.block_start||X===y.block_end||X===y.inside||X===y.outside||X===y.both||X===y.all||X===y.same||X===y.column||X===y.region||X===y.page)&&(delete c.clear,(q||c.display&&c.display!=y.inline)&&(this.nodeContext.clearSide=X.toString())));let Q=ur(m)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),ee=c["break-inside"];(q||ee&&!Z(ee)&&ee!==y.auto)&&this.nodeContext.breakPenalty++,m&&m!==y.inline&&Ut(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!q&&!m||Ut(m)||$d(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=q?U.toString():null,this.nodeContext.floatReference=v||Pe.INLINE;let pe=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=pe&&!Z(pe)?pe:null;let oe=this.isInsideNonRootMultiColumn(),se=c["column-span"];if(this.nodeContext.columnSpan=!oe&&se&&!Z(se)?se:null,!this.nodeContext.inline){let G=c["break-after"];G&&!Z(G)&&!(oe&&G===y.column)&&(this.nodeContext.breakAfter=G.toString(),za[this.nodeContext.breakAfter]&&(c["break-after"]=y.column));let Dt=c["break-before"];Dt&&!Z(Dt)&&!(oe&&Dt===y.column)&&(this.nodeContext.breakBefore=Dt.toString(),za[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let qt=c.page,an=qt&&!Z(qt)?qt.toString():null,zt=an;!zt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===y.table_header_group||m===y.table_footer_group)&&(zt=this.styler.cascade.currentPageType),!zt||zt.toLowerCase()==="auto"?zt=this.nodeContext.pageType:this.nodeContext.pageType=zt;let Kn=an!=null&&an.toLowerCase()!=="auto",wi=Kn?this.nodeContext.fragmentIndex===1?this.getEffectiveStartPageType(a,zt):(A=this.styler.cascade.currentPageType)!=null?A:zt:zt;this.styler.cascade.currentPageType!==wi&&!(!Kn&&c.position===y.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===B("separate")){let G=c["border-spacing"],Dt,qt;G&&(G instanceof J?(Dt=G.values[0],qt=G.values[1]):Dt=qt=G,Dt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=ut(Dt,this.context)),qt.isNumeric()&&(this.nodeContext.blockBorderSpacing=ut(qt,this.context)))}let Te=c["footnote-policy"]||V.footnotePolicy;Te&&!Z(Te)&&(c["--viv-footnote-policy"]=Te),this.nodeContext.footnotePolicy=Te&&!Z(Te)?Te:null;let fe=c["x-first-pseudo"];if(fe){let G=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Wv(G,fe.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let Ce=c["white-space"];if(Ce){let G=tp(Ce.toString());G!==null&&(this.nodeContext.whitespace=G)}let ge=c["hyphenate-character"];ge&&ge instanceof K&&(this.nodeContext.hyphenateCharacter=ge.str);let Ie=c["word-break"],Be=c["line-break"],Fe=c["overflow-wrap"];(Ie===y.break_all||Be===y.anywhere||Fe===y.break_word||Fe===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,m,z,U,S),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 He=!1,gt=null,Zn=[],Rt=a.namespaceURI,me=a.localName,oo=me;Rt=="http://www.w3.org/1999/xhtml"?(Vx.has(me)?me="div":me=="vide_"?me="video":me=="audi_"?me="audio":me=="object"&&(He=!!this.customRenderer),a.hasAttribute(uh)&&a.hasAttribute("src")&&c.content instanceof Qe&&(me="img")):Rt=="http://www.idpf.org/2007/ops"?(me="span",Rt="http://www.w3.org/1999/xhtml"):Rt=="http://www.pyroxy.com/ns/shadow"?(Rt="http://www.w3.org/1999/xhtml",me=this.nodeContext.inline?"span":"div"):He=!!this.customRenderer,Q?t?(me="li",c["--viv-marker-content"]&&(Hx(c)||(c["list-style-type"]=y.none,c["list-style-image"]=y.none))):(m=Ut(m)?y.inline:y.block,c.display=m,me="div"):me=="body"||me=="li"?me="div":me=="q"&&(me="span"),c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(He=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(He=!0);let qs;if(He){let G=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;qs=this.customRenderer(a,G,c)}else qs=T(null);qs.then(G=>{var Dt,qt,an,zt,Kn;if(G)He&&(o=G.getAttribute("data-adapt-process-children")=="true");else if(c.display===y.none){s.finish(!1);return}else G=this.createElement(Rt,me);if(!S&&E&&c["column-fill"]===y.auto){let We=this.nodeContext.vertical?c.width:c.height;(!We||We===y.auto||Z(We))&&(G.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=y.balance)}me!=oo&&(G.setAttribute("data-vivliostyle-original-tag",oo),(oo==="html"||oo==="body")&&(G.role="presentation")),me=="a"&&G.addEventListener("click",this.page.hrefHandler,!1),gt&&(this.applyPseudoelementStyle(this.nodeContext,"inner",gt),G.appendChild(gt)),G.localName=="iframe"&&G.namespaceURI=="http://www.w3.org/1999/xhtml"&&Wx(G);let wi=this.nodeContext.inheritedProps["image-resolution"],Ys=[],Zs=c.width,Ks=c.height,Eg=a.getAttribute("width"),Pg=a.getAttribute("height"),Js=Zs===y.auto||!Zs&&!Eg,Qs=Ks===y.auto||!Ks&&!Pg,Sh=a.attributes,Ng=Sh.length,Jn=null,Ch=null;m===y.table_cell&&((an=(qt=(Dt=this.nodeContext.parent)==null?void 0:Dt.viewNode)==null?void 0:qt.lastElementChild)==null?void 0:an.localName)==="a"&&G.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let We=0;We<Ng;We++){let St=Sh[We],ht=St.namespaceURI,ae=St.localName,ke=St.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"&&Rt==="http://www.w3.org/1999/xhtml"&&((zt=a.parentElement)==null?void 0:zt.localName)==="picture")try{let Ge=this.context.rootScope,mt=new Ms(Ge),ao=new xt(ke,mt),kh=zd(ao,mt,"");if(kh){if(kh.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 mt=G.ownerDocument.createElement("a");mt.setAttribute(ae,Ge),mt.setAttribute(zn,"1"),mt.style.position="absolute",G.appendChild(mt),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=Sc(ke));else if(ae=="srcset")ke=ke.split(",").map(Ge=>{let mt=Ge.trim().split(/\s+/),ao=Ir(this.resolveURL(mt[0]));return mt.length>1?`${ao} ${mt.slice(1).join(" ")}`:ao}).join(",");else if(ae==="data"&&He&&me==="object"&&G.hasAttribute("data"))continue;if(ae==="poster"&&me==="video"&&Rt==="http://www.w3.org/1999/xhtml"){let Ge=new Image,mt=Et(Ge,ke);Js&&Qs?(Zn.push(mt),Ys.push({image:Ge,element:G,fetcher:mt})):this.page.fetchers.push(mt)}}if(Rt=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(ke=Dx(ke,this.xmldoc.url,this.documentURLTransformer)),ht){let Ge=zx[ht];Ge&&(ae=`${Ge}:${ae}`)}if(ae=="src"&&!ht&&(me=="img"||me=="input")&&Rt=="http://www.w3.org/1999/xhtml")Jn=ke;else if(ae=="alt"&&!ht&&me=="img"&&Rt=="http://www.w3.org/1999/xhtml")Ch=ke;else if(ae=="href"&&me=="image"&&Rt=="http://www.w3.org/2000/svg"&&(ht=="http://www.w3.org/1999/xlink"||!ht))ht||G.setAttribute(ae,ke),this.page.fetchers.push(Et(G,ke));else if(ht)G.setAttributeNS(ht,ae,ke);else try{G.setAttribute(ae,ke)}catch(Ge){Y.warn(Ge)}}if(Jn){let We=me==="input"?new Image:G,St=Et(We,Jn,Ch);We!==G&&(G.src=Jn);let ht=()=>{var ae,ke;if(c.position===y.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};!Js&&!Qs&&!(()=>{let ae=this.nodeContext.vertical?Zs:Ks;return ae instanceof O&&ae.unit==="%"})()&&!ht()?this.page.fetchers.push(St):(Js&&Qs&&wi&&wi!==1&&Ys.push({image:We,element:G,fetcher:St}),Zn.push(St))}else!Jn&&me==="img"&&Rt==="http://www.w3.org/1999/xhtml"&&(G.srcset||((Kn=a.parentElement)==null?void 0:Kn.localName)==="picture")&&this.page.fetchers.push(Et(G));delete c.content;let so=c["--viv-marker-content"];if(so){let We=so instanceof J?so.values:[so];for(let St of We)St instanceof Qe&&St.url&&Zn.push(Et(new Image,St.url))}if(G.localName==="object"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("data")&&this.page.fetchers.push(Et(G)),G.localName==="embed"&&G.namespaceURI==="http://www.w3.org/1999/xhtml"&&G.hasAttribute("src")&&this.page.fetchers.push(Et(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(Et(G))}if(this.preprocessElementStyle(c),this.applyComputedStyles(G,c),this.nodeContext.inline)t||(Ct(G,"inline-start"),Nn(G)&&Ct(G,"clone"));else if(t){if(!Fr(c.position)){let We=c["margin-break"],St=this.getBreakTypeAt(this.nodeContext),ht=St!==null,ae=St==="auto";(We===y.discard&&ht||We!==y.keep&&ae&&!this.nodeContext.floatSide)&&aa(G,"block-start")}}else{let We=this.nodeContext.vertical?"width":"height";ki(G,We)&&I(G,We,this.nodeContext.display==="table-row"?"0.01px":""),Ct(G,"block-start"),Nn(G)&&Ct(G,"clone"),aa(G,"block-start")}Q&&c["ua-list-item-count"]&&G.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=G,Zn.length?Dn(Zn).then(()=>{wi>0&&this.modifyElemDimensionWithImageResolution(Ys,wi,c,this.nodeContext.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Ee(r,n.parent.whitespace)||Ot(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&&eo(i))}getBreakTypeAt(t){var i,n,r,o,s;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(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&&Ot(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(s=(o=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:o.flowPositions[this.flowName])==null?void 0:s.startBreakType;return 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 o=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let s=new ya(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new A0(t,s)}}isSVGUrlAttribute(t){return gr.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=ut(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=ut(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(h+=ut(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(h+=ut(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||y.none,d=n["max-height"]||y.none;if(c===y.none&&d===y.none)I(l,"max-width",`${a}px`);else if(c!==y.none&&d===y.none)I(l,"width",`${a}px`);else if(c===y.none&&d!==y.none)I(l,"height",`${h}px`);else{c.isNumeric(),d.isNumeric();let p=c,f=d;p.unit!=="%"?I(l,"max-width",`${Math.min(a,ut(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,ut(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let 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?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,ut(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,ut(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){_t("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},o=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof tn&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let s=this.nodeContext.parent,a=s&&s.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!==y.none&&((i===y.auto||Z(i))&&(t.display===y.table_header_group?i=y.header:t.display===y.table_footer_group?i=y.footer:i=y.none),i&&i!==y.none)?i.toString():null}createTextNodeView(){let t=M("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=uu(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let t,i=t=this.sourceNode.textContent,n=M("preprocessTextContent"),r=_t("PREPROCESS_TEXT_CONTENT"),o=0;return n.loop(()=>o>=r.length?T(!1):r[o++](this.nodeContext,i).thenAsync(s=>(i=s,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Rv(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=M("createNodeView"),r,o=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=T(!0)):r=this.createTextNodeView(),r.then(s=>{var a;if(o=s,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(d,p)=>d?.nodeType===1&&Yt(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()&&Kd(c).includes("block-start")&&Ct(c,"text-start"),c.appendChild(this.viewNode),wv(this.viewNode))}n.finish(o)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):T(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,o,s,a=n.subShadow||n.parentShadow;n.subShadow?(o=n.subShadow.root,s=n.subShadow.type,s==st.ROOTLESS&&(o=o.firstChild)):(o=n.owner.firstChild,s=st.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:o?t=null:(t=t.parent.modify(),t.after=!0),o){let l=new xn(o,r,i);return l.shadowContext=a,l.shadowType=s,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=st.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let r=t.nodeShadow.root;if(t.nodeShadow.type==st.ROOTLESS&&(r=r.firstChild),r){let o=new xn(r,t,i);return o.shadowContext=t.nodeShadow,o.shadowType=t.nodeShadow.type,this.processShadowContent(o)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new xn(n,t,i));if(t.sourceNode.nodeType!=1){let r=uu(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let o=r;return Yt(o)==="footnote-call"&&o.getAttribute(gr.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?o:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&Pt(i)}insertFootnoteCall(t){var i,n;let r=M("insertFootnoteCall"),o=pr.createElementNS("http://www.w3.org/1999/xhtml","span");Er(o,"footnote-call");let s=this.xmldoc.getElementOffset(t.sourceNode);o.setAttribute(gr.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=new xn(o,t.parent,t.boxOffset);a.inline=!0;let h=new ya(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Mo(t.sourceNode,o,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,st.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let 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 T(n);this.syncTextNodePageTypeBoundary(n);let r=M("nextInTree");return this.setCurrent(n,!0,i).then(o=>{if((!n.viewNode||!o)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let s=this.findImmediateFootnoteCallSibling(n);s!=null&&s.parentNode&&s.parentNode.removeChild(s),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){Pr(t,this.page)}applyComputedStyles(t,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i["border-image-source"];a&&this.addImageFetchers(a);let h=i["list-style-image"];h&&this.addImageFetchers(h);let l=i["mask-image"];l&&this.addImageFetchers(l);let 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===y.relative,v=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),w=Object.keys(i);w.sort(Dh);let x,m;for(let S of w){if(jx[S])continue;let b=i[S];if(!(!b||b===Me&&!Xe(S))){if(b=b.visit(new Ym(this.xmldoc.url,this.documentURLTransformer)),b instanceof O)if(b.unit==="em"){let C=this.getEmUnitSize(S,x);C!=null&&(b=new O(b.num*C,"px"))}else if(b.unit==="lh"){let C=this.getLineHeightUnitSize(S,x,m);C!=null&&(b=new O(b.num*C,"px"))}else Fc(b.unit)&&(b=Yc(b,this.context));if((S==="font-size"||S==="line-height")&&(S==="font-size"?x=b:m=b,this.viewport.layoutUnitAdj&&b instanceof O&&b.unit!=="%"&&b.unit!=="em"&&b.unit!=="lh"&&(b=new fn(`calc(${b.toString()} - var(--viv-layoutUnitAdj))`))),Bv[S]||g&&Mv[S]){this.page.delayedItems.push(new $l(t,S,b));continue}v&&this.page.pageAreaElement&&In(S)?(I(this.page.pageAreaElement.parentElement.parentElement,S,b.toString()),S!=="writing-mode"&&S!=="direction"&&I(this.viewport.layoutBox,S,b.toString())):I(t,S,b.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var t,i;let n=(i=(t=this.page.pageAreaElement)==null?void 0:t.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(t,i){var n,r,o;let s=this.viewport.window.getComputedStyle(t),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var t,i,n;return((n=(i=(t=this.nodeContext)==null?void 0:t.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(t){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:t?this.parsePlusLayoutUnitAdj(t.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:t?this.parsePlusLayoutUnitAdj(t.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(t,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(t==="line-height"||t==="font-size")return l;let c=null;if(n)if(n instanceof At||n instanceof O&&(n.unit==="em"||n.unit==="%"))c=n instanceof O&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof O&&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=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;d&&d.nodeType===1;d=d.parentNode){let p=(s=d?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(c=parseFloat(p));break}}if(c!=null){if(i&&!(i instanceof O))return null;let d=h.fontSize;if(i instanceof O){let p=ol(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 O){let o=ol(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,o=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),s=ft(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",o,a);let h=a.content;It(h)&&(h.visit(new Lr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=M("peelOff"),r=t.firstPseudo,o=t.offsetInNode,s=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),o+=i}else if(!s&&t.viewNode&&o==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t&&t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new xn(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=o,t.after=s),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return T(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=ft(this.cascadedPageStyle,Ts);p&&p.area&&(a=p.area)}let h=ft(a,"_pseudos");t=this.computeStyle(t,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new O(l.fontSize,"px")),delete o.content;let c=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ve(f,"display"),v={},w=this.createElement("http://www.w3.org/1999/xhtml","span");Er(w,"before"),n.appendChild(w),this.computeStyle(t,i,f,v),g||(v.display=y.block);let x=ve(f,"content");if(x){let S=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;v.content=x.filterValue(new _r(this.styler.cascade,S,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let m=v.content;if(It(m)){m.visit(new Lr(w,this.context,m,this.exprContentListener));let S=w.querySelectorAll("img[src]");for(let C=0;C<S.length;C++){let P=S[C],L=P.getAttribute("src");if(!L)continue;let A=Et(P,L);s.push(A),this.page.fetchers.push(A)}let b=w.getAttribute("src");if(b){let C=w.querySelector("img");C||(C=this.document.createElement("img"),C.setAttribute("src",b),w.appendChild(C));let P=Et(C,b);s.push(P),this.page.fetchers.push(P)}}delete v.content,this.applyComputedStyles(w,v)}}finally{this.computedStyleParentFontSizeOverride=c,this.computedStyleParentLineHeightOverride=d}return s.length?Dn(s).thenReturn(t):T(t)}processFragmentedBlockEdge(t){var i,n,r;let o=!t.inline&&t.after?t.parent:t,s=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=ve(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Ut(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(Ct(l,"inline-end"),Nn(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;Ct(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(ki(l,c)&&I(l,c,""),Ct(l,"block-end"),!a++&&h!==o){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?Jd(p,["block-start","text-start","block-end","text-end","justify"]):(Ct(l,"text-end"),Ct(l,"justify")):Ct(l,"text-end")}else Ct(l,"text-end")}Nn(l)&&Ct(l,"clone"),aa(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(t.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(t){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||ji[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&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(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(zn)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Ee(l.nextSibling))?i(l):!1}return!(!s||Ut(s))},n=null;for(let o=t.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ee(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,o=t.unit;if(pm(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return this.context,rh(t,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Yt(n)===Yt(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(t){return!!Yt(t)}};u(gl,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),u(gl,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var Gx=gl,jx={"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},Xx=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}},Ps=class{constructor(e,t,i,n,r,o){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=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Gr){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&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=o||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},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||!o&&c)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}};function Pr(e,t){if(e instanceof Oe)for(let i of e.values)Pr(i,t);else if(e instanceof Qe){let i=Ir(e.url);t.fetchers.push(Et(new Image,i))}else if(e instanceof ai)for(let i of e.values)Pr(i,t);else if(e instanceof J)for(let i of e.values)Pr(i,t)}var qx=1,js=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${qx++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Yx=class extends js{constructor(e){super(e,null,null,[],null),this.specified.width=new W(qr,0),this.specified.height=new W(Yr,0)}},Gu=class extends is{constructor(e,t){super(e,n),u(this,"pageMaster",t);let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Qf=class eg extends js{constructor(t,i,n,r,o,s,a){super(t,i,n,r,o),u(this,"condition",s),u(this,"specificity",a),u(this,"keyMap",{}),t instanceof Gu||(this._scope=new Gu(t,this)),this.pageMaster=this,this.specified.width=new W(qr,0),this.specified.height=new W(Yr,0),this.specified["wrap-flow"]=new W(y.auto,0),this.specified.position=new W(y.relative,0),this.specified.overflow=new W(y.visible,0)}createInstance(t){return new mh(t,this)}clone(t){let i=new eg(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}},tg=class ig extends js{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new W(y.auto,0)}createInstance(t){return new eS(t,this)}clone(t){let i=new ig(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},ro=class ng extends js{constructor(t,i,n,r,o){super(t,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Wn(t,this)}clone(t){let i=new ng(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||Z(t)?new it(e,i):t.toExpr(e,e.zero)}function be(e,t,i){return!t||t===y.auto||Z(t)?null:t.toExpr(e,i)}function Kx(e,t,i){return!t||t===y.normal||Z(t)?null:t.toExpr(e,i)}function Tt(e,t,i){return!t||t===y.auto||Z(t)?e.zero:t.toExpr(e,i)}function ju(e,t,i){return!t||Z(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function oi(e,t,i,n){return!t||i===y.none||Z(t)?e.zero:t.toExpr(e,n)}function rg(e,t,i){return!t||Z(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var Xs=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?tf:nf;n=e;for(let o in r)n=n.replace(o,r[o])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;if(e==="columns"){let i=this.pageBox.scope,n=new $c(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");t=ye(i,Oo(i,new yr(i,"min",[n,r]),ne(i,o,s)),s)}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=rg(e,t.enabled,e._true),n=be(e,t.page,e.zero);if(n){let s=new Je(e,"page-number");i=Wt(e,i,new Rl(e,n,s))}let r=be(e,t["min-page-width"],e.zero);r&&(i=Wt(e,i,new Pa(e,new Je(e,"page-width"),r)));let o=be(e,t["min-page-height"],e.zero);o&&(i=Wt(e,i,new Pa(e,new Je(e,"page-height"),o))),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),o=oi(e,t["border-left-width"],t["border-left-style"],i),s=Tt(e,t["padding-left"],i),a=be(e,t.width,i),h=be(e,t["max-width"],i),l=Tt(e,t["padding-right"],i),c=oi(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,o,s),g=ne(e,o,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=Oo(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 v=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=Tt(e,v,i);t.left=new j(n),t["margin-left"]=new j(r),t["border-left-width"]=new j(o),t["padding-left"]=new j(s),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(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=be(e,t.top,n),o=be(e,t["margin-top"],i),s=oi(e,t["border-top-width"],t["border-top-style"],i),a=Tt(e,t["padding-top"],i),h=be(e,t.height,n),l=be(e,t["max-height"],n),c=Tt(e,t["padding-bottom"],i),d=oi(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,s,a),v=ne(e,d,c);if(r&&f&&h){let m=ye(e,n,ne(e,h,ne(e,ne(e,r,g),v)));o?p?f=ye(e,m,o):p=ye(e,m,ne(e,f,o)):(m=ye(e,m,f),p?o=ye(e,m,p):(o=Oo(e,m,new it(e,.5)),p=o))}else{o||(o=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let m=ye(e,n,ne(e,ne(e,o,g),ne(e,p,v)));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 w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),x=Tt(e,w,i);t.top=new j(r),t["margin-top"]=new j(o),t["border-top-width"]=new j(s),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),o=Kx(e,t["column-gap"],null);o||(o=new Xr(e,1,"em")),n&&!r&&(r=new yr(e,"floor",[Na(e,ne(e,i,o),ne(e,n,o))]),r=new yr(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,Na(e,ne(e,i,o),r),o),t["column-width"]=new j(n),t["column-count"]=new j(r),t["column-gap"]=new j(o)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,o=dl(this.cascaded,e,r,!1,null);this.vertical=kf(o,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Ef(o,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=o["box-sizing"])==null?void 0:t.value)===y.border_box;let s=!!(e instanceof bh&&e.currentLayoutPosition&&new Je(i,"left-page").evaluate(e));Nf(o,n,this.vertical,this.rtl,s,(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 Mn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new O(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=Cs(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let o=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=Cs(e,r,t,o)}return ut(r,e)}getSpecial(e,t){let i=af(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(e,"");o&&o!==Me&&n.push(o)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&Fc(r.unit)&&(r=Yc(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new $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"),o=this.getPropAsNumber(e,"border-left-width"),s=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,s),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(t.element,"border-left-width",`${o}px`),t.marginLeft=n,t.borderLeft=o,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),o=this.getPropAsNumber(e,"padding-right"),s=this.getPropAsNumber(e,"border-right-width");if(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${o}px`),I(t.element,"border-right-width",`${s}px`),t.marginRight=r,t.borderRight=s,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,o+=t.snapOffsetX)}t.paddingRight=o,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),o=this.getPropAsNumber(e,"padding-top"),s=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=s,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,o+=t.snapOffsetY)}t.paddingTop=o,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${o}px`),I(t.element,"border-top-width",`${s}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),o=this.getPropAsNumber(e,"height")-t.snapOffsetY;I(t.element,"height",`${o}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(t.element,"border-bottom-width",`${r}px`),t.height=o-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){I(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let o=0;o<Xu.length;o++)this.propagateProperty(e,t,Xu[o],n)}transferContentProps(e,t,i,n){for(let r=0;r<Yu.length;r++)this.propagateProperty(e,t,Yu[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!Z(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==y.auto&&!Z(a)};for(let o=0;o<Zu.length;o++){let s=Zu[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;I(t,s,"100%");continue}this.propagatePropertyToElement(e,t,s,i)}}finishContainer(e,t,i,n,r,o,s){var a,h,l,c,d,p,f,g,v,w;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,S=null;if(m||x){m&&I(t.element,"width","auto"),x&&I(t.element,"height","auto");let b=n&&ss(n);b&&Ds(n),S=o.getElementClientRect(n?n.element:t.element),b&&Dl(n),m&&(this.calculatedWidth=Math.ceil(S.right-S.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),x&&(this.calculatedHeight=S.bottom-S.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 b=this.getPropAsNumber(e,"column-rule-width"),C=this.getProp(e,"column-rule-style"),P=this.getProp(e,"column-rule-color");if(b>0&&C&&C!=y.none&&P!=y.transparent){let L=this.getPropAsNumber(e,"column-gap"),A=this.vertical?t.height:t.width,z=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),U=t.getPaddingRect(),X=n,re=this.vertical?"border-top":"border-left";for(let k=1;k<r;k++){let _=this.vertical?(A+L)*k/r-L/2+t.paddingTop-b/2:(A+L)*k/r-L/2+t.paddingLeft-b/2,F=this.vertical?U.y1+_+b/2:U.x1+_+b/2,D=(d=(c=(l=X.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:c.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(c,F),E=(g=(f=(p=X.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,F),N=isFinite(D)?this.vertical?D-U.x1:D-U.y1:NaN,R=isFinite(E)?this.vertical?E-U.x1:E-U.y1:NaN,$=parseFloat(this.vertical?(v=n?.element.style.width)!=null?v:"":(w=n?.element.style.height)!=null?w:""),V=$>0?$:this.vertical?n.width:n.height,q=Math.max(z>0?z:0,0),Q=q+V,ee=Math.max(q,isFinite(this.vertical?R:N)?Math.max(0,this.vertical?R:N):0),pe=Math.min(Q,isFinite(this.vertical?N:R)?Math.max(0,this.vertical?N:R):Q),oe=Math.max(0,pe-ee),se=t.element.ownerDocument.createElement("div");I(se,"position","absolute"),I(se,this.vertical?"left":"top",`${ee}px`),I(se,this.vertical?"top":"left",`${_}px`),I(se,this.vertical?"height":"width","0px"),I(se,this.vertical?"width":"height",`${oe}px`),I(se,re,`${b}px ${C.toString()}${P?` ${P.toString()}`:""}`),t.element.insertBefore(se,t.element.firstChild)}}}for(let b=0;b<qu.length;b++)this.propagateProperty(e,t,qu[b],s);for(let b of Jx){let C=this.getProp(e,b);C&&Pr(C,i)}for(let b=0;b<Ku.length;b++)this.propagateDelayedProperty(e,t,Ku[b],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let o in n)this instanceof Mn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Xi(o)&&Fi(i,o,ve(n,o));if(this.pageBox.pseudoName==gh)for(let o in t)(o.match(/^background-/)||o=="writing-mode")&&(i[o]=t[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in t)!o.match(/^background-/)&&o!="writing-mode"&&(i[o]=t[o]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;if(r){let o=Array.from(e.lastCounterChanges),s={...e.lastCounterChangeTypes};e.counterScoping.push(null),e.pushCounters(i),i.content=r.filterValue(new _r(e,null,e.counterResolver)),e.popCounters(),e.popCounters(),e.lastCounterChanges=o,e.lastCounterChangeTypes=s}this.init(e.context);for(let o of this.pageBox.children)o.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Xu=["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"],qu=["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"],Jx=["background-image","border-image-source","filter"],Yu=["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"],Zu=["width","height","image-resolution","object-fit","object-position"],Ku=["transform","transform-origin"],gh="background-host",Qx=class extends Xs{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)}},mh=class extends Xs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Wt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},eS=class extends Xs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Wn=class extends Xs{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 Oe&&(n=t.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof he){let s=ka(n[o].name,"enabled"),a=new Je(r,s);i&&(a=new Ai(r,a)),e=Wt(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=rg(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Zx(t,i["flow-from"],"body"),o=new yr(t,"has-content",[r]);e=Wt(t,e,o)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(t,null):t._true;o=Wt(t,o,e),this.pageMasterInstance.style.enabled=new j(o)}return e}prepareContainer(e,t,i,n,r){var o;this.pageBox.pageMaster instanceof hg||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(e,t,i,n,r)}},yh=class extends on{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 W(t,i?Od:Bd)}},og=class extends yh{constructor(e,t,i,n){super(e,t,i,n)}},tS=class sg extends yh{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new W(Mh,0),n.specified.height=new W(Mh,0)}startPartitionRule(t,i,n){let r=new ro(this.scope,t,i,n,this.target),o=new og(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,i,n){let r=new tg(this.scope,t,i,n,this.target),o=new sg(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(o)}},iS=class extends yh{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new ro(this.scope,e,t,i,this.target),r=new og(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new tg(this.scope,e,t,i,this.target),r=new tS(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function ag(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===y.vertical_lr||n!==y.vertical_rl&&r!==y.rtl?"ltr":"rtl"}var nS={a10:{width:new O(26,"mm"),height:new O(37,"mm")},a9:{width:new O(37,"mm"),height:new O(52,"mm")},a8:{width:new O(52,"mm"),height:new O(74,"mm")},a7:{width:new O(74,"mm"),height:new O(105,"mm")},a6:{width:new O(105,"mm"),height:new O(148,"mm")},a5:{width:new O(148,"mm"),height:new O(210,"mm")},a4:{width:new O(210,"mm"),height:new O(297,"mm")},a3:{width:new O(297,"mm"),height:new O(420,"mm")},a2:{width:new O(420,"mm"),height:new O(594,"mm")},a1:{width:new O(594,"mm"),height:new O(841,"mm")},a0:{width:new O(841,"mm"),height:new O(1189,"mm")},b10:{width:new O(31,"mm"),height:new O(44,"mm")},b9:{width:new O(44,"mm"),height:new O(62,"mm")},b8:{width:new O(62,"mm"),height:new O(88,"mm")},b7:{width:new O(88,"mm"),height:new O(125,"mm")},b6:{width:new O(125,"mm"),height:new O(176,"mm")},b5:{width:new O(176,"mm"),height:new O(250,"mm")},b4:{width:new O(250,"mm"),height:new O(353,"mm")},b3:{width:new O(353,"mm"),height:new O(500,"mm")},b2:{width:new O(500,"mm"),height:new O(707,"mm")},b1:{width:new O(707,"mm"),height:new O(1e3,"mm")},b0:{width:new O(1e3,"mm"),height:new O(1414,"mm")},c10:{width:new O(28,"mm"),height:new O(40,"mm")},c9:{width:new O(40,"mm"),height:new O(57,"mm")},c8:{width:new O(57,"mm"),height:new O(81,"mm")},c7:{width:new O(81,"mm"),height:new O(114,"mm")},c6:{width:new O(114,"mm"),height:new O(162,"mm")},c5:{width:new O(162,"mm"),height:new O(229,"mm")},c4:{width:new O(229,"mm"),height:new O(324,"mm")},c3:{width:new O(324,"mm"),height:new O(458,"mm")},c2:{width:new O(458,"mm"),height:new O(648,"mm")},c1:{width:new O(648,"mm"),height:new O(917,"mm")},c0:{width:new O(917,"mm"),height:new O(1297,"mm")},"jis-b10":{width:new O(32,"mm"),height:new O(45,"mm")},"jis-b9":{width:new O(45,"mm"),height:new O(64,"mm")},"jis-b8":{width:new O(64,"mm"),height:new O(91,"mm")},"jis-b7":{width:new O(91,"mm"),height:new O(128,"mm")},"jis-b6":{width:new O(128,"mm"),height:new O(182,"mm")},"jis-b5":{width:new O(182,"mm"),height:new O(257,"mm")},"jis-b4":{width:new O(257,"mm"),height:new O(364,"mm")},"jis-b3":{width:new O(364,"mm"),height:new O(515,"mm")},"jis-b2":{width:new O(515,"mm"),height:new O(728,"mm")},"jis-b1":{width:new O(728,"mm"),height:new O(1030,"mm")},"jis-b0":{width:new O(1030,"mm"),height:new O(1456,"mm")},letter:{width:new O(8.5,"in"),height:new O(11,"in")},legal:{width:new O(8.5,"in"),height:new O(14,"in")},ledger:{width:new O(11,"in"),height:new O(17,"in")}},rS=new O(.24,"pt"),fC=new O(3,"mm"),oS=new O(10,"mm"),sS=new O(13,"mm");function Ns(e){let t={width:qr,height:Yr,bleed:Le,bleedOffset:Le,cropOffset:Le},i=e.size;if(!(!i||i.value===y.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&&nS[c.name.toLowerCase()];p&&(d&&d===y.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,o=n&&!Z(n.value)?n.value:y.none,s=r&&!Z(r.value)?r.value:y.auto;if(s===y.auto){if(o!==y.none){let l=!1;o.isSpaceList()?l=o.values.some(c=>c===y.crop):l=o===y.crop,l&&(t.bleed=new O(6,"pt"))}}else s.isNumeric()&&(t.bleed=s);let a=e["crop-offset"],h=a&&!Z(a.value)?a.value:y.auto;return h===y.auto?o!==y.none&&(t.bleedOffset=sS):h.isNumeric()&&(t.cropOffset=h),t}function Ju(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),o=n+r,s=e.width;s===qr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-o*2:i.pageWidth=s.num*t.queryUnitSize(s.unit,!1);let a=e.height;return a===Yr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-o*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function lg(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 Nr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===y.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var ml=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(ml||{});function aS(e,t,i,n,r,o,s){let a=r;a<=o+2*Zt.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,c=lg(e,l,l),d=[[0,o+r],[r,o+r],[r,o+r-a]],p=d.map(v=>[v[1],v[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(v=>[o+h-v[0],v[1]]),p=p.map(v=>[o+h-v[0],v[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(v=>[v[0],o+h-v[1]]),p=p.map(v=>[v[0],o+h-v[1]]));let f=Nr(e,i,n);f.setAttribute("points",d.map(v=>v.join(",")).join(" ")),c.appendChild(f);let g=Nr(e,i,n);return g.setAttribute("points",p.map(v=>v.join(",")).join(" ")),c.appendChild(g),t.split(" ").forEach(v=>{c.style[v]=`${s}px`}),c}var $r=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))($r||{});function lS(e,t,i,n,r,o){let s=r*2,a,h;t==="top"||t==="bottom"?(a=s,h=r):(a=r,h=s);let l=lg(e,a,h),c=Nr(e,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let d=Nr(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=Nr(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($r).forEach(g=>{let v=$r[g];v===t?l.style[v]=`${o}px`:v!==f&&(l.style[v]="0",l.style[`margin-${v}`]="auto")}),l}function hS(e,t,i,n){let r=!1,o=!1,s=e.marks;if(s){let v=s.value;v instanceof J?v.values.forEach(w=>{w===y.crop?r=!0:w===y.cross&&(o=!0)}):v===y.crop?r=!0:v===y.cross&&(o=!0)}let a=t.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,c=ut(rS,n),d=Math.max(0,t.bleedOffset-ut(oS,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:y.auto;r&&Object.keys(ml).forEach(v=>{let w=ml[v],x=aS(l,w,c,g,p,a,d);h.appendChild(x)}),o&&Object.keys($r).forEach(v=>{let w=$r[v],x=lS(l,w,c,g,p,d);h.appendChild(x)})}var yl=(()=>{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})(),vh={"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"}},uS=(()=>{let e=vh;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),wh="vivliostyle-page-rule-master",Hr="_marginBoxes",Ts="_footnoteArea",hg=class extends Qf{constructor(e,t,i){super(e,null,wh,[],t,null,0),u(this,"pageMarginBoxes",{});let n=Ns(i),r=new cS(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[Hr];t&&uS.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new pS(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new W(y.relative,0),this.specified.width=new W(t.width,0),this.specified.height=new W(t.height,0);for(let i in e)!yl[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Mn(e,this)}},cS=class extends ro{constructor(e,t,i,n){super(e,null,null,[],t),u(this,"pageSize",n);let r=new dS(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new W(y.auto,0),this.specified["z-index"]=new W(new lt(0),0),this.specified.position=new W(y.absolute,0),this.specified.overflow=new W(y.visible,0);for(let t in yl)yl.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new gS(e,this)}},dS=class extends ro{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new W(B("body"),0)}createInstance(e){return new ug(e,this)}},pS=class extends ro{constructor(e,t,i,n){super(e,null,null,[],t),u(this,"marginBoxName",i),this.applySpecified(n)}applySpecified(e){let t=e[Hr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(ef[i]||r&&r.value===y.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Me&&n.value!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new cg(e,this)}},Mn=class extends mh{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},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},c={},d={};for(let S in e){let b=vh[S];if(b){let C=e[S],P=this.pageMarginBoxInstances[S],L=new Zo(C,P.style,t,h,r);l[b.positionAlongVariableDimension]=C,c[b.positionAlongVariableDimension]=P,d[b.positionAlongVariableDimension]=L}}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,v={};Object.keys(l).forEach(S=>{let b=S,C=be(h,c[b].style[t?"max-width":"max-height"],i.extent);if(C){let P=C.evaluate(n);if(f[b]>P){let L=d[b]=new Qu(l[b],c[b].style,t,h,r,P);v[b]=L.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[o,s,a].forEach(S=>{var b;f[S]=(b=v[S])!=null?b:f[S]}));let w={};Object.keys(l).forEach(S=>{let b=S,C=be(h,c[b].style[t?"min-width":"min-height"],i.extent);if(C){let P=C.evaluate(n);if(f[b]<P){let L=d[b]=new Qu(l[b],c[b].style,t,h,r,P);w[b]=L.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[o,s,a].forEach(S=>{f[S]=w[S]||f[S]}));let x=p.start+p.extent,m=p.start+(p.start+p.extent);[o,s,a].forEach(S=>{let b=f[S];if(b!=null){let C=l[S],P=0;switch(S){case o:P=t?C.left:C.top;break;case s:P=(m-b)/2;break;case a:P=x-b;break}t?C.setHorizontalPosition(P,b-C.getInsetLeft()-C.getInsetRight()):C.setVerticalPosition(P,b-C.getInsetTop()-C.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,o=e.end,s={};if(r){let a=[n,o],h=new fS(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(s.center=l.xSize);let c=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-c)/2,0);n&&(s.start=n.hasAutoSize()?d:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?d:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,o,t);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Zo&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Zo&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),o=t.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},Zo=class{constructor(e,t,i,n,r){u(this,"container",e),u(this,"isHorizontal",i),u(this,"clientLayout",r),u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let o=t[i?"width":"height"];if(this.hasAutoSize_=!o||o===y.auto||Z(o),this.minMaxFitContent=o instanceof he&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=s[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Ul(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()}},fS=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 Zo{constructor(e,t,i,n,r,o){super(e,t,i,n,r),u(this,"fixedSize"),this.fixedSize=o}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},gS=class extends Wn{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,o=e.end,s=e.extent,a=i[s].toExpr(n,null),h=be(n,t[s],a),l=be(n,t[`margin-${r}`],a),c=be(n,t[`margin-${o}`],a),d=Tt(n,t[`padding-${r}`],a),p=Tt(n,t[`padding-${o}`],a),f=oi(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=oi(n,t[`border-${o}-width`],t[`border-${o}-style`],a),v=ne(n,ne(n,f,d),ne(n,g,p)),w,x,m;return h?(this.borderBoxSizing?(x=h,m=ye(n,x,v)):(m=h,x=ne(n,m,v)),w=ye(n,a,x),!l&&!c?(l=Oo(n,w,new it(n,.5)),c=l):l?c=ye(n,w,l):l=ye(n,w,c)):(l||(l=n.zero),c||(c=n.zero),w=ne(n,l,c),x=ye(n,a,w),m=ye(n,x,v),h=this.borderBoxSizing?x:m),t[r]=new j(l),t[o]=new j(c),t[`margin-${r}`]=Le,t[`margin-${o}`]=Le,t[`border-${r}-width`]=new j(f),t[`border-${o}-width`]=new j(g),t[`padding-${r}`]=new j(d),t[`padding-${o}`]=new j(p),t[s]=new j(h),t[`max-${s}`]=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)}},ug=class extends Wn{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 Cn(i,t.left.toExpr(i,null))),e["margin-right"]=new j(new Cn(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=y.solid,e["border-right-style"]=y.solid,e["border-left-color"]=y.transparent,e["border-right-color"]=y.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new j(this.parentInstance.contentBoxHeight),e["margin-top"]=new j(new Cn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new j(new Cn(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=y.solid,e["border-bottom-style"]=y.solid,e["border-top-color"]=y.transparent,e["border-bottom-color"]=y.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},cg=class extends Wn{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=vh[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){I(t,"display","flex"),I(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&I(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 o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),I(t,"align-items",o)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,o=e.end,s=e.extent,a=r==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=be(n,i[s],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new j(c);else if(l){let d=Tt(n,i[`margin-${r}`],h),p=Tt(n,i[`margin-${o}`],h),f=Tt(n,i[`padding-${r}`],h),g=Tt(n,i[`padding-${o}`],h),v=oi(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=oi(n,i[`border-${o}-width`],i[`border-${o}-style`],h),x=ne(n,l,ne(n,this.borderBoxSizing?n.zero:ne(n,ne(n,f,g),ne(n,v,w)),ne(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new j(ne(n,c,Na(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,o=e.inside,s=e.outside,a=e.extent,h=t[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=ju(n,i[`margin-${o}`],h),c=ju(n,i[`margin-${s}`],h),d=Tt(n,i[`padding-${o}`],h),p=Tt(n,i[`padding-${s}`],h),f=oi(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=oi(n,i[`border-${s}-width`],i[`border-${s}-style`],h),v=be(n,i[a],h),w=null;function x(m){if(w)return w;w={extent:v?v.evaluate(m):null,marginInside:l?l.evaluate(m):null,marginOutside:c?c.evaluate(m):null};let S=h.evaluate(m),b=0;return r||[f,d,p,g].forEach(C=>{C&&(b+=C.evaluate(m))}),(w.marginInside===null||w.marginOutside===null)&&b+w.extent+w.marginInside+w.marginOutside>S&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=S-b-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=S-b-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=S-b-w.extent-w.marginInside:w.marginInside=w.marginOutside=(S-b-w.extent)/2),w}i[a]=new j(new we(n,function(){let m=x(this).extent;return m===null?"auto":m},a)),i[`margin-${o}`]=new j(new we(n,function(){let m=x(this).marginInside;return m===null?"auto":m},`margin-${o}`)),i[`margin-${s}`]=new j(new we(n,function(){let m=x(this).marginOutside;return m===null?"auto":m},`margin-${s}`)),o==="left"?i.left=new j(ne(n,t.marginLeft,t.borderBoxWidth)):o==="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,o,s){super.finishContainer(e,t,i,n,r,o,s);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let 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&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let S=this.getProp(e,"margin-left"),b=this.getProp(e,"margin-right");if(l.isInLeftColumn){let C=c.borderBoxWidth.evaluate(e)+c.marginRight.evaluate(e);I(t.element,"right",`${C}px`),(S===y.auto||b!==y.auto)&&I(t.element,"margin-left","auto"),b===y.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(b===y.auto||S!==y.auto)&&I(t.element,"margin-right","auto"),S===y.auto&&I(t.element,"margin-left","auto"))}let v=this.getProp(e,"height"),w=v instanceof he&&(v.name==="min-content"||v.name==="max-content"||v.name==="fit-content")?v.name:null,x=this.getPropAsNumber(e,"min-height"),m=this.getPropAsNumber(e,"max-height");if(w||x||m){w&&I(t.element,"height",w),x&&I(t.element,"min-height",`${x}px`),m&&I(t.element,"max-height",`${m}px`);let S=this.getProp(e,"margin-top"),b=this.getProp(e,"margin-bottom");if(l.isInTopRow){let C=c.borderBoxHeight.evaluate(e)+c.marginBottom.evaluate(e);I(t.element,"bottom",`${C}px`),(S===y.auto||b!==y.auto)&&I(t.element,"margin-top","auto"),b===y.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(b===y.auto||S!==y.auto)&&I(t.element,"margin-bottom","auto"),S===y.auto&&I(t.element,"margin-top","auto"))}}},mS=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 Rl(e,new Dc(e,n,new it(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ai(e,r)),e.defineName("verso-page",r),(t.pageProgression||ag(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new Ai(e,r))):(e.defineName("left-page",new Ai(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===gh?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 W?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new hg(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:wh}),n=i.specified,r=e.size;if(r&&!Z(r.value)){let s=Ns(e),a=r.priority;Jt(n,"width",new W(s.width,a),this.context),Jt(n,"height",new W(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(e[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},yS=class extends Ne{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}},vS=class extends Ne{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}},wS=class extends Ne{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}},bS=class extends Ne{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}},xS=class extends Ne{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}},SS=class extends Ne{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}},CS=class extends Ne{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}},kS=class extends sn{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}},ES=class extends sn{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}},PS=class extends oh{constructor(e,t){super(e,t,null,null,null)}apply(e){NS(e.context,e.currentStyle,this.style,this.specificity,e)}};function NS(e,t,i,n,r){Ss(e,t,i,n,null,null,null);let o=i[Hr];if(o){let a=si(t,Hr);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),Ss(e,l,o[h],n,null,null,null)}}let s=i[Ts];if(s){let a=si(t,Ts);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let c=s[h];for(let p in c)if(c.hasOwnProperty(p)&&p!=="_pseudos"){let f=c[p];f instanceof W&&Jt(l,p,f)}let d=ft(c,"_pseudos");if(d){let p=si(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let v=d[f];for(let w in v)if(v.hasOwnProperty(w)){let x=v[w];x instanceof W&&Jt(g,w,x)}}}}}}var TS=class extends Dr{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 yS(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 ES(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new kS(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 vS(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new wS(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new bS(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new xS(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new SS(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new CS(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(o=>o.selectors===null))return;super.simpleProperty(e,t,i);let n=ve(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{Fi(r[o],e,n)});else if(e==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=new W(n.value,n.priority+s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?Jt(l,e,a):(l=r[h]={},Fi(l,e,a),o&&["bleed","marks"].forEach(c=>{o[c]&&Fi(l,c,o[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new PS(this.elementStyle,e)}startFootnoteRule(e){let t=si(this.elementStyle,Ts),i=t.area;if(i||(i={},t.area=i),e){let r=si(i,"_pseudos"),o=r[e];o||(o={},r[e]=o),i=o}let n=new dg(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=si(this.elementStyle,Hr),i=t[e];i||(i={},t[e]=i);let n=new AS(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},AS=class extends on{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 W(t,n);Fi(this.boxStyle,e,r)}},dg=class extends on{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 W(t,n);Fi(this.areaStyle,e,r)}},pg=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 o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Ht,"0")}doc(){return new gg([this.document])}getElementOffset(e){let t=e.getAttribute(Ht);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(Ht,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=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,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>e&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){var t;let i=e.match(/([^#]*)#(.+)$/);if(!i||i[1]&&i[1]!=this.url&&((t=this.store)==null?void 0:t.get(i[1]))!==this)return null;let n=i[2],r=this.document.getElementById(n);return!r&&this.document.getElementsByName&&(r=this.document.getElementsByName(n)[0]),r||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),r=this.idMap[n]),r}},vl=(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))(vl||{});function Io(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let o=r.documentElement,s="parsererror";if(o.localName===s)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===s)return null}else return null;return r}function IS(e){let t=e.contentType;if(t){let n=Object.keys(vl);for(let r=0;r<n.length;r++)if(vl[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 fg(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,o=e.responseText;if(o!=null){let s=IS(e);if(i=Io(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Io(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Io(o,"image/svg+xml",r))}i||(i=Io(o,"text/html",r))}}let n=i?new pg(t,e.url,i):null;return T(n)}function FS(){return new Ml(fg,"document")}var RS=class wl{constructor(t){u(this,"fn",t)}check(t){return this.fn(t)}withAttribute(t,i){return new wl(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new wl(n=>{if(!this.check(n))return!1;let r=new gg([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},ec=new RS(e=>!0),gg=class bl{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 bl(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 bl(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)}},LS=new Jr(()=>{let e=M("uaStylesheetBase"),t=Kp(),i=Ae("user-agent-base.css",Ni),n=new Dr(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),l0(n.cascade),_l(Td,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function OS(){return LS.get()}var BS=class extends Yo{constructor(e,t,i,n,r,o){super(e,t,null,i,n,"counter-style"),u(this,"counterStyleName",r),u(this,"counterStyles",o)}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||Y.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},MS=class{constructor(e,t,i,n,r,o,s,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",o),u(this,"footnoteProps",s),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 Ea(this.rootScope,e,t,i),o=Ab(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let c=Zt.em;if((h?h.evaluate(r,"text-zoom"):null)===y.scale&&(l=c/i,i=c,e*=l,t*=l),s&&a){let d=ut(s.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 tc(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function ic(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var bh=class extends Ea{constructor(e,t,i,n,r,o,s,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",o),u(this,"customRenderer",s),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 Ax(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Sn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let v=e.flowProps[g],w=ve(v,"flow-consume");w&&(w.evaluate(this,"flow-consume")==y.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=M("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=ag(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Qx(r);let o=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(o,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new mS(o,this.style.pageScope,this.rootPageBoxInstance,this,n);let s=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Tx(h.properties,this),c=new Zf(l);s.push(c)}this.fontMapper.findOrLoadFonts(s,this.faces).then(()=>{Ox(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=Ju(Ns(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 Ea(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),o=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new $u(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,o,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new jv,i.flowPositions[e.flowName]=n);let r=Hv(e.element),o=new Bi(r),s=new Gv(o,e);n.positions.push(s)}}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 o=new r,s=Ri(this.style.rootScope,new xt(t,null),"");return s?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,s,!1,o),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 mg{errorMsg(...s){}}let i=new t(null),n=pd(e),r=new xt(n+"{}",i);return new Qr($e,r,i,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!i.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,r=n.steps[0].node,o=n.offsetInNode,s=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,s=!1,o=0;let h=this.xmldoc.getNodeOffset(r,o,s);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r)for(let o=0;o<r.positions.length;o++){let s=r.positions[o].chunkPosition.primary,a=this.getNodePositionOffset(s);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){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,o=n?this.xmldoc.getElementOffset(n):i,s=i<=o,a=r===n&&s&&(t=this.getFirstInFlowChildElement(n))!=null?t:r;if(!a)return s?{counterOffset:o,changeOffset:o}:{counterOffset:i,changeOffset:i};let h=this.xmldoc.getElementOffset(a),l=i;return s&&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),o=this.xmldoc.getElementOffset(n),s=t<=o;if(r===n&&s)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||Z(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),o=this.xmldoc.body||this.xmldoc.root,s=this.xmldoc.getElementOffset(o);if(i<=s&&e===o||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e?.startSideOfFlow("body")||null,n=e?.flowPositions.body,r=!!(n&&n.positions.length),o=!!i&&en(i)&&!this.matchPageSide(i)&&!r,s=!(this.blankPageAtStart&&(!e||e.page===1))&&!(e!=null&&e.isBlankPage)&&!o,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&&s;p&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=d);let f=l;for(;f;){let g=this.getPageGroupPageType(f);if(g){let v=this.pageGroupPageCounts[g]||(this.pageGroupPageCounts[g]=new Map),w=v.get(f)||0;(w>0||s&&(p||this.shouldStartPageGroup(f,g,c)))&&(w+=1,v.set(f,w),(t.pageTypePageIndices[g]||(t.pageTypePageIndices[g]=[])).push(w))}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)===y.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),o=r&&!Z(r)?r:y.static;if(vr(o)||Fr(o))return!1;let s=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(s&&!Z(s)?s:y.none)===y.none}isInlineLevelElement(e){return Ut(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!Z(n)?n:y.inline}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let o=this.getConsumedOffset(r);o<i&&(i=o)}}return i}dumpLocation(e){Y.debug("Location - page",this.currentLayoutPosition.page),Y.debug(" current:",e),Y.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)Y.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,o=i.startBreakType;i.startBreakType=hu(nt(o,r))}}}}selectPageMaster(e){var t;let i=this.currentLayoutPosition,n=this.getPosition(i);if(n==Number.POSITIVE_INFINITY&&this.hasActiveRootPageFloatLayoutContext()&&(n=(t=i.highestSeenOffset)!=null?t:this.styler.getReachedOffset()),n==Number.POSITIVE_INFINITY)return null;let r=this.rootPageBoxInstance.children,o;for(let s=0;s<r.length;s++){if(o=r[s],o.pageBox.pseudoName===wh)continue;let a=1;o.pageBox.pseudoName===gh&&!(this.actualPageWidth&&this.actualPageHeight)&&(a=1/0);let h=o.getProp(this,"utilization");h&&h.isNum()&&(a=h.num);let l=this.queryUnitSize("em",!1),c=this.pageWidth()*this.pageHeight(),d=Math.ceil(a*c/(l*l)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(n,d),this.styler.cascade.currentPageType=p,this.updateStartSide(i),this.layoutPositionAtPageStart=i.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let f=o.getProp(this,"enabled");if(!f||f===y._true){if(i.page===1&&this.blankPageAtStart){o.style={};let g=e.size;e={},g&&(e.size=g)}return this.pageManager.getPageRulePageMaster(o,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let o=mi(r.length,l=>r[l]>n)-1,s=r[o],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return s<h?!1:h<s?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Xl(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(e){let t=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new Sn(null,null,null,null,null,null,null),e&&this.rootPageFloatLayoutContext.addPageFloatLayoutContextAsPreviousSibling(e),t}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}hasOnlyDeferredPageFloats(e){return this.noMorePrimaryFlows(e)&&this.hasActiveRootPageFloatLayoutContext()}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,c;if(!n||h.floatReference!==Pe.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},o=M("layoutDeferredPageFloats"),s=!1,a=0;return o.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 Vn().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&&(s=!0,t.validate());h.continueLoop()})}).then(()=>{s&&t.invalidate(),o.finish(!0)}),o.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new 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)):T(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=M("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],o=[],s=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-o.length>0;){let h=0;for(;o.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+1;p<i.positions.length;p++){if(o.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=p)}let c=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,s,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(s=!1,l.flowChunk.repeated&&(p===null||c.exclusive)&&r.push(h),c.exclusive){o.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(!p&&e.pageBreakType&&i.positions.length-o.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(o.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=hu(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)||!o.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=v=>v!==""&&v!=="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 O0([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,o,s,a,h,l,c,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,v=r.element,w=new Sn(a,Pe.COLUMN,null,s,null,null,null),x=this.currentLayoutPosition.clone(),m=M("createAndLayoutColumn"),S;return m.loopWithFrame(b=>{let C=this.createLayoutConstraint(w);if(h>1){let P=this.viewport.document.createElement("div");if(I(P,"position","absolute"),v.appendChild(P),S=new ks(P,p,this.clientLayout,C,w),S.isNonFirstColumn=o>0,S.forceNonfitting=f,S.vertical=r.vertical,S.rtl=r.rtl,S.snapHeight=r.snapHeight,S.snapWidth=r.snapWidth,r.vertical){let L=(r.rtl?h-o-1:o)*(c+l)+r.paddingTop,A=parseFloat(v.style.width);S.setHorizontalPosition(r.paddingLeft+A-r.width,r.width),S.setVerticalPosition(L,c)}else{let L=(r.rtl?h-o-1:o)*(c+l)+r.paddingLeft;S.setVerticalPosition(r.paddingTop,r.height),S.setHorizontalPosition(L,c)}S.originX=t,S.originY=i}else S=new ks(v,p,this.clientLayout,C,w),S.isNonFirstColumn=!1,S.copyFrom(r);S.exclusions=g?[]:n.concat(),S.innerShape=d,w.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,s).then(()=>{w.isInvalidated()||w.finish(),S.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),S.element!==v&&v.removeChild(S.element),b.continueLoop()):b.breakLoop()}):(w.finish(),b.breakLoop())}).then(()=>{m.finish(S)}),m.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof ug||t instanceof mh&&!(t instanceof Mn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Wn;let r=t.getProp(this,"writing-mode")||null,o=t.getProp(this,"direction")||null;return new Sn(e,Pe.REGION,i,n,null,r,o)}layoutFlowColumnsWithBalancing(e,t,i,n,r,o,s,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(o,t,s,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,o,c,s,a,h,d).thenAsync(f=>T(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return T(null);if(h<=1)return T(f.columns);let g=t.getProp(this,"column-fill")||y.balance,v=this.currentLayoutPosition.flowPositions[a],w=Sx(h,g,p,c,s,f.columns,v);return w?(d=!1,o.lock(),c.lock(),w.balanceColumns(f).thenAsync(x=>(o.unlock(),o.validate(),c.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(f.columns)})}layoutFlowColumns(e,t,i,n,r,o,s,a,h,l,c){let d=M("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=tc(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),v=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),x=t.getProp(this,"shape-inside"),m=hd(x,0,0,a.width,a.height,this),S=new Gx(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),b=0,C=null,P=[];return d.loopWithFrame(L=>{this.createAndLayoutColumn(t,i,n,r,a,b++,h,s,l,g,v,m,S,c).then(A=>{if(o.isInvalidated()){P=null,L.breakLoop();return}if((A.pageBreakType&&A.pageBreakType!=="column"||b===l)&&!s.isInvalidated()&&s.finish(),s.isInvalidated()){b=0,this.currentLayoutPosition=p.clone(),ic(f),s.validate(),s.isLocked()?(P=null,L.breakLoop()):L.continueLoop();return}C=A,P[b-1]=C,C.pageBreakType&&C.pageBreakType!="column"&&(b=l,C.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),b<l?L.continueLoop():L.breakLoop()})}).then(()=>{d.finish(P)}),d.result()}layoutContainer(e,t,i,n,r,o,s){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return T(!0);let h=M("layoutContainer"),l=t.getProp(this,"wrap-flow")===y.auto,c=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof cg?"complementary":"presentation";let p=t.getProp(this,"position");I(d,"position",p?p.name:"absolute");let f=t instanceof Mn;t instanceof Wn?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new hp(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=o,t.prepareContainer(this,g,e,this.faces,this.clientLayout),(g.width<=0||g.height<=0)&&(t instanceof Mn||c&&c.isIdent())&&(this.invalidPageAreaOnCurrentPage=!0,Y.warn("Negative or zero page area size")),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(s,t,g);let v,w=!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 Lr(d,this,m,this.counterStore.getExprContentListener()));else if(It(m)){let S="span";m instanceof Qe&&(S="img");let b=this.viewport.document.createElement(S);m.visit(new Lr(b,this,m,this.counterStore.getExprContentListener())),d.appendChild(b),S=="img"&&t.transferSingleUriContentProps(this,b,this.faces),t.transferContentProps(this,g,e,this.faces);let C=b.querySelectorAll("img[src]");for(let L=0;L<C.length;L++){let A=C[L],z=A.getAttribute("src");if(!z)continue;let U=Et(A,z);x.push(U),e.fetchers.push(U)}let P=b.getAttribute("src");if(P){let L=b.querySelector("img");L||(L=b);let A=Et(L,P);x.push(A),e.fetchers.push(A)}S=="span"&&P0(b,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(d),w=!0);w||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),v=x.length?Dn(x).thenReturn(!0):T(!0)}else if(this.pageBreaks[c.toString()])s.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),v=T(!0);else{let x=M("layoutContainer.inner"),m=c.toString(),S=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,o,s,g,m,S).then(b=>{if(!s.isInvalidated()){let C=b[0];C.element===d&&(g=C),g.computedBlockSize=Math.max.apply(null,b.map(L=>L.computedBlockSize)),t.finishContainer(this,g,e,C,S,this.clientLayout,this.faces);let P=this.currentLayoutPosition.flowPositions[m];P&&P.breakAfter==="region"&&(P.breakAfter=null)}x.finish(!0)}),v=x.result()}return v.then(()=>{if(s.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let m=t.getProp(this,"shape-outside"),S=g.getOuterShape(m,this);o.push(S)}}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--],S=this.layoutContainer(e,m,d,n,r,o,s);if(S.isPending())return S.thenAsync(()=>T(!s.isInvalidated()));if(s.isInvalidated())break}return T(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}hasSameFlowPositions(e,t){if(e===t)return!0;if(!e||!t)return!1;let i=Object.keys(e.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!e.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}checkRepeatedInvalidPageArea(e){let t=this.invalidPageAreaOnCurrentPage;if(this.invalidPageAreaOnCurrentPage=!1,!t){this.repeatedInvalidPageAreaLayoutPosition=null;return}if(e.isBlankPage||this.noMorePrimaryFlows(e))return;if(!this.hasSameFlowPositions(this.layoutPositionAtPageStart,e)){this.repeatedInvalidPageAreaLayoutPosition=null;return}let i=!!this.repeatedInvalidPageAreaLayoutPosition&&this.hasSameFlowPositions(this.repeatedInvalidPageAreaLayoutPosition,this.layoutPositionAtPageStart);if(this.repeatedInvalidPageAreaLayoutPosition=this.layoutPositionAtPageStart.clone(),i)throw new Error("Negative or zero page area size")}layoutNextPage(e,t){var i,n,r,o;let s=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Xv,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),this.invalidPageAreaOnCurrentPage=!1,t=this.currentLayoutPosition;let a=t.startSideOfFlow("body");t.isBlankPage=en(a)&&this.matchPageSide(a),e.isBlankPage=t.isBlankPage,t.page++;let h=this.hasOnlyDeferredPageFloats(t),l=h?void 0:this.getPageStartPageTypeOverride(t);if(l===""?e.pageType="":l&&(e.pageType=l),e.pageType==null){let m=t.page===1?this.resolveFirstPageType():null,S=(i=this.styler.cascade.currentPageType)!=null?i:this.styler.cascade.previousPageType,b=e.isBlankPage?this.styler.cascade.previousPageType:h?S:m??this.styler.cascade.currentPageType;if(e.pageType=b,!e.pageType){let C=this.getPageStartPageType(t);C&&(e.pageType=C)}e.pageType=(n=e.pageType)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType}this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let c=tc(t),d=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=d,this.styler.cascade.applyVarFilter([d],this.styler,null),this.styler.cascade.applyCalcFilter(d,this.styler.context),this.styler.cascade.applyCmykFilter(d),!s){let m=new Je(this.style.pageScope,"left-page");e.side=m.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let p=this.selectPageMaster(d);if(!p)return T(null);let f=0;if(!s){e.setAutoPageWidth(p.pageBox.specified.width.value===qr),e.setAutoPageHeight(p.pageBox.specified.height.value===Yr);let{counterOffset:m,changeOffset:S}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(m)||(m=this.lookupOffset,S=this.lookupOffset),isFinite(m)&&this.styler.styleUntil(m,0);let b=this.styler.getCounterSnapshotAtOffset(m),C=S===m?b:this.styler.getCounterSnapshotAtOffset(S);b||(b=this.styler.getLastCounterSnapshot()),C||(C=b);let P=C&&C.offset===S?C:null;this.counterStore.setCurrentPageDocCounters((r=b?.counters)!=null?r:null,(o=P?.changes)!=null?o:null,P?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(d,this);let L=Ju(Ns(d),this);this.setPageSizeAndBleed(L,e),hS(d,L,e,this),f=L.bleedOffset+L.bleed}let g=!s&&p.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=g!=y.horizontal_tb;let v=p.getProp(this,"direction")||y.ltr,w=new Sn(this.rootPageFloatLayoutContext,Pe.PAGE,null,null,null,g,v),x=M("layoutNextPage");return x.loopWithFrame(m=>{this.layoutContainer(e,p,e.bleedBox,f,f,[],w).then(()=>{if(w.isInvalidated()||w.finish(),w.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),ic(c),w.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);m.continueLoop()}else m.breakLoop()})}).then(()=>{e.pageFloatLayoutContext=w,p.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),t=this.currentLayoutPosition,this.checkRepeatedInvalidPageArea(t),Object.keys(t.flowPositions).forEach(S=>{let b=t.flowPositions[S],C=b.breakAfter;C&&(C==="page"||!this.matchPageSide(C))&&(b.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let m=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(m,this.clientLayout),this.noMorePrimaryFlows(t)&&!this.hasActiveRootPageFloatLayoutContext()&&(t=null),x.finish(t)}),x.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`}},_S=class xl extends Dr{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 Qf(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new iS(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Wt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new xl(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new f0(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Yo(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new BS(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 Yo(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Yo(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=si(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new dg(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new TS(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Dr.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new xl(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},mg=class extends Ma{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 Yw),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new is(null),this.pageScope=new is(this.rootScope),this.rootBox=new Yx(this.rootScope),this.cascadeParserHandler=new _S(this,null,null,null),this.slave=this.cascadeParserHandler}};function DS(e,t){return t.parseOPSResource(e)}var zS=class extends Ml{constructor(e){super(DS,"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=M("OPSDocStore.init");return this.validatorSet=Kp(),OS().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Ae(Fn(t),Ji)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ae(Fn(t),Ji)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=M("OPSDocStore.load"),i=e.url,n=Is(i);return fg(e,this).then(r=>{var o;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=_t("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){Y.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),v=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),x=f.getAttribute("ref");g&&v&&w&&x&&s.push({observer:g,event:v,action:w,ref:x})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ae("user-agent-page.css",Ni),text:Nd,flavor:"UA",classes:null,media:null}),h.push({url:Ae("user-agent-counter-styles.css",Ni),text:Fd,flavor:"UA",classes:null,media:null}),n)h.push({url:Ae("user-agent-toc.css",Ni),text:Ad,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,v=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(v=="style"){let w=f.getAttribute("class"),x=f.getAttribute("media"),m=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:m?w:null,media:x})}else if(v=="link"){let w=f.getAttribute("href"),x=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),m=f.getAttribute("class"),S=f.getAttribute("media");if(w&&x!=null&&x.includes("stylesheet")&&(!x.includes("alternate")||m)){let b=Ae(w,i),C=f.getAttribute("title");h.push({url:b,text:null,classes:C?m:null,media:S,flavor:"Author"})}}else v=="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 Jr(()=>{let p=M("fetchStylesheet"),f=0,g=new mg(this.validatorSet);return p.loop(()=>{if(f<h.length){let v=h[f++];return g.startStylesheet(v.flavor),v.text!==null?_l(v.text,g,v.url,v.classes,v.media).thenReturn(!0):Dd(v.url,g,v.classes,v.media)}return T(!1)}).then(()=>{let v=g.cascadeParserHandler.finish();c=new MS(this,g.rootScope,g.pageScope,v,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""}},Tr="\u25B8",nc="\u25BE",VS="\u25B9";function xh(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function US(e){let t=xh(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var $S=class{constructor(e,t,i,n,r,o,s,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",s),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=Nc(o),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;ki(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),ki(n,"position","static")=="absolute"&&(I(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-node":r.display=y.block,r.margin=Le,r.padding=Le,r["padding-inline-start"]=new O(1.25,"em");break;case"toc-node-first-child":r.display=y.inline_block,r.margin=new O(.2,"em"),r["vertical-align"]=y.top,r.color=y.inherit,r["text-decoration"]=y.none;break;case"toc-container":r.padding=Le;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return t(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Ee(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=Tr&&(l.textContent=Tr,I(l,"cursor","pointer"),l.addEventListener("click",HS,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),o.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=VS,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let 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 T(h)}}showTOC(e,t,i,n,r){if(this.page)return T(this.page);let o=M("showTOC"),s=new ep(e,e);this.page=s;let a=Sa(this.url);return this.store.load(a).then(h=>{for(let f of xh(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,r);t=new Ps(t.window,c.fontSize,0,e,c.width,c.height);let d=this.makeCustomRenderer(h),p=new bh(l,h,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(e,2),o.finish(s)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function HS(e){let t=e.target,i=t.textContent==Tr;t.textContent=i?nc:Tr;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==nc){a.textContent=Tr,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}function Fo(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function WS(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}function GS(e){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(e)||/^(?:about:|data:|blob:)/i.test(pt(e))}var rc=class extends zS{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=FS(),this.jsonStore=iv()}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 Ko(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=M("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):GS(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):Bs(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}Y.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=M("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let o of r)if(o){this.loadOPF(e,o).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return T(n);let r=M("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(o=>{o?(n=new Ko(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(s=>{n.initWithXMLDoc(o,s).then(()=>{r.finish(n)})}):n.initWithXMLDoc(o,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=M("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 Ko(this,e),o=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=El(n.getElementById(s.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ae(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&xh(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=M("EPUBDocStore.load"),n=pt(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:")?Y.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Ji.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?Y.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?Y.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):Y.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=pt(e),i=this.documents[t];if(i)return i.isPending()?i:T(i.get());{let n=M("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let r=i.width-0,o=i.height-0;if(r&&o){let s=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${o}px;}`+(s?`@page{size:${r}px ${o}px;margin:0;}`:"@page{margin:0;}")}return""}},oc=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=em}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ae(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=am(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 jS(e){return e.id}function XS(e){return t=>{let i=M("deobfuscator");return qS("SHA-1",e).then(n=>{let r=t.slice(0,1040),o=t.slice(1040,t.size);Qy(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Rd([a,o]))})}),i.result()}}function qS(e,t){let i=M("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"},mr="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:`${mr}title-type`,displaySeq:`${mr}display-seq`,alternateScript:`${mr}alternate-script`,role:`${mr}role`};function YS(e,t){let i={};return(n,r)=>{var o,s,a,h,l,c;let d,p,f=n.r||i,g=r.r||i;if(e==qe.title&&(d=((o=f[qe.titleType])==null?void 0:o[0].v)=="main",p=((s=g[qe.titleType])==null?void 0:s[0].v)=="main",d!=p))return d?-1:1;let v=parseInt((a=f[qe.displaySeq])==null?void 0:a[0].v,10);isNaN(v)&&(v=Number.MAX_VALUE);let w=parseInt((h=g[qe.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),v!=w?v-w: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 ZS(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]]:mr;if(f)return f+p[3]}}return null},r=1,o=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name: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}),s=ta(o,d=>d.refines),a=d=>lm(d,(p,f)=>p.map(g=>{let v={v:g.value,o:g.order};g.scheme&&(v.s=g.scheme);let w=s[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:qe.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:qe.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=ta(w,m=>m.name);v.r=a(x)}return v})),h=a(ta(o,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(YS(p,l));for(let g=0;g<f.length;g++){let v=f[g].r;v&&c(v)}}};return c(h),h}function KS(){let e=window.MathJax;return e?e.Hub:null}var sc={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},xa="viv-id-",Ko=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{constructor(){u(this,"canonicalDocumentURLCache",new Map)}getCanonicalDocumentURL(n){var r,o;let s=pt(dn(n)),a=this.canonicalDocumentURLCache.get(s);if(a)return a;for(let h of e.spine){let l=pt(dn(h.src));if(l===s)return this.canonicalDocumentURLCache.set(s,l),l;let c=(o=(r=e.store)==null?void 0:r.get(l))==null?void 0:o.url;if(c&&pt(dn(c))===s)return this.canonicalDocumentURLCache.set(s,l),l}return this.canonicalDocumentURLCache.set(s,s),s}transformFragment(n,r){let o=this.getCanonicalDocumentURL(r)+(n?`#${n}`:"");return xa+kc(o,":")}transformURL(n,r){let o=n.match(/^([^#]*)#?(.*)$/);if(o){let s=this.getCanonicalDocumentURL(o[1]||dn(r)),a=decodeURIComponent(o[2]);if(s&&e.spine.some(h=>pt(dn(h.src))===s))return`#${this.transformFragment(a,s)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(xa)===0&&(n=n.substring(xa.length));let r=sm(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Ae("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new oc,c=h;l.initWithElement(c,e.url);let d=c.getAttribute("fallback");return d&&!sc[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=Rh(this.items,jS),this.itemMapByPath=Rh(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(sc[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 o=i.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=mc(o));let s=t?t.doc().child("encryption").child("EncryptedData").predicate(ec.withChild("EncryptionMethod",ec.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=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"),s.length>0&&this.uid){let h=XS(this.uid);for(let l=0;l<s.length;l++)this.store.deobfuscators[this.pubURL+s[l]]=h}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let t=0,i=0,n=M("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let o=this.spine[i++];o.epage=t,this.store.load(o.src).then(s=>{if(!s){r.continueLoop();return}let a=1800,h=s.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),o.epageCount=Math.ceil(s.getTotalOffset()/a),t+=o.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new pg(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new oc;r.initWithParam(n),r.id;let o=i.document.createElement("itemref");o.setAttribute("idref",r.id),i.root.appendChild(o),r.itemRefElement=o,this.itemMap[r.id]=r;let s=this.getPathFromURL(n.url);s==null&&(s=n.url),this.itemMapByPath[s]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):T(null)}initWithWebPubManifest(e,t,i){var n,r,o,s;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[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((o=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?o:[]).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||((s=e.metadata)==null?void 0:s.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=pt(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 US(t)){let m=x.getAttribute("href");if(/^(https?:)?\/\//.test(m)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(m))continue;let S=pt(Ae(m,this.pubURL)),b=this.getPathFromURL(S),C=b!==null?encodeURI(b):S;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let f=[],g=0,v=-1;[e.readingOrder,e.resources].forEach(x=>{x instanceof Array&&x.forEach(m=>{let S=x===e.readingOrder,b=typeof m=="string"?m:m.url||m.href,C=typeof m=="string"?"":m.encodingFormat||m.href&&m.type||"";if(S||C==="text/html"||C==="application/xhtml+xml"||!C&&m.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let P=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,L={url:Ae(Fn(b),P),index:g++,startPage:null,skipPagesBefore:null};m.rel==="contents"&&v===-1&&(v=L.index),f.push(L)}})});let w=M("initWithWebPubManifest");return this.initWithChapters(f).then(()=>{var x,m;v!==-1&&(this.toc=this.items[v]),this.toc||(this.toc=i?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[d]);let S=(m=e.readingOrder)==null?void 0:m.length;S&&S<this.items.length&&this.items.splice(S),w.finish(!0)}),w.result()}getCFI(e,t){let i=this.spine[e],n=M("getCFI");return this.store.load(i.src).then(r=>{let o=r.getNodeByOffset(t),s=null;if(o){let a=r.getNodeOffset(o,0,!1),h=t-a,l=new Gh;l.prependPathFromNode(o,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),s=l.toString()}n.finish(s)}),n.result()}resolveFragment(e){return _n("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Gh;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let o=r.node,s=o.getAttribute("idref");if(o.localName!="itemref"||!s||!this.itemMap[s]){t.finish(null);return}n=this.itemMap[s],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let o=i.navigate(r.document),s=r.getNodeOffset(o.node,o.offset,o.after);t.finish({spineIndex:n.spineIndex,offsetInItem:s,pageIndex:-1})})},(t,i)=>{Y.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return _n("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let o=this.spine[r];(!o||o.epageCount==0)&&(o=this.spine[--r]);let s=Math.floor(e-o.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:s});return}let i=mi(this.spine.length,r=>{let o=this.spine[r];return o.epage+o.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let o=0;if(e>0){let s=r.getTotalOffset();o=Math.round(s*e/n.epageCount),o==s&&o--}t.finish({spineIndex:i,offsetInItem:o,pageIndex:-1})})},(t,i)=>{Y.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return T(n)}if(e.offsetInItem<=0)return T(t.epage);let i=M("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),o=Math.min(r,e.offsetInItem);i.finish(t.epage+o*t.epageCount/r)}),i.result()}},Ro=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),JS=class{constructor(e,t,i,n,r,o){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:[],totalOffsetsReady:!1,lastReportedPages:0,lastReportedFraction:0,lastReportedSpineIndex:-1,lastReportedHref:""}),this.pref=Nc(n),this.clientLayout=new Xx(t),this.counterStore=new ey(e.documentURLTransformer),this.cmykStore=new td,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return T(!0);let i=M("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<e;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let o=e.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}collectTotalOffsets(){if(this.paginationProgress.totalOffsetsReady)return T(!0);let e=this.paginationProgress.totalOffsetsBySpine,t=0,i=M("collectTotalOffsets");return i.loopWithFrame(n=>{if(t===this.opf.spine.length){n.breakLoop();return}let r=t++;if(e[r]!=null){n.continueLoop();return}let o=this.opf.spine[r];this.opf.store.load(o.src).then(s=>{s&&(e[r]=s.getTotalOffset()),n.continueLoop()})}).then(()=>{this.paginationProgress.totalOffsetsReady=!0,i.finish(!0)}),i.result()}getTotalOffsetAll(){let e=0;for(let t of this.paginationProgress.totalOffsetsBySpine)t&&(e+=t);return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(e=n[r])!=null?e:0;t+=Math.min(o,s)}return t}reportPaginationProgress(e,t){var i,n;let r=_t("PAGINATION_PROGRESS");if(!r.length)return;let o=e.item.spineIndex,s=this.getTotalOffsetForViewItem(e),a=s;t&&(a=e.instance.getPosition(t,!0)),a<0&&(a=0),a>s&&(a=s);let h=this.paginationProgress.renderedOffsetsBySpine[o];h!=null&&a<h&&(a=h),this.paginationProgress.renderedOffsetsBySpine[o]=a;let l=this.getRenderedPageCount(),c=this.getTotalOffsetAll(),d=this.getRenderedOffsetAll(),p=c>0?d/c:0;p<this.paginationProgress.lastReportedFraction?p=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=p,l>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=l);let f=e.item.src;o>=((i=this.paginationProgress.lastReportedSpineIndex)!=null?i:-1)?(this.paginationProgress.lastReportedSpineIndex=o,this.paginationProgress.lastReportedHref=f):f=(n=this.paginationProgress.lastReportedHref)!=null?n:f;let g={fraction:p,pages:this.paginationProgress.lastReportedPages,href:f};for(let v of r)try{v(g)}catch(w){Y.warn(w)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,c=n.offset!==t.offset,d=s&&!c&&i>0;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,s){let p=e.instance.getPageStartPageTypeOverride(t.position);p===""?t.pageType="":p&&(t.pageType=p)}if(!s&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||o)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Fo(n));let r=Fo(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return T(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let o=e.pages[t.page],s=!!i&&n.offset!==i.offset,a=e.instance.hasActiveRootPageFloatLayoutContext(),h=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||s||a,l=this.isInCounterResolveScope(),c=this.evaluateNextPageRelayout(i,o,h,s,l);return c.needsRelayout?(e.complete=!1,c.shouldCascade?this.renderSinglePage(e,t):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=M("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),s=0,a=t;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(c=>!c.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(c=>{var d;if(!c){h.continueLoop();return}let p=c.instance.styler.cascade,f=c.instance.pageManager.pageCascadeInstance,g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},v={currentPageType:f.currentPageType,previousPageType:f.previousPageType},w=WS(c.instance.pageGroupPageCounts),x=c.instance.currentPageGroupDocument,m=c.instance.scopes;c.instance.scopes={};let S=l.pageIndex<c.pages.length-1,b=!!c.pages[l.pageIndex],C=b&&S,P=C&&l.pageIndex>0?(d=c.pages[l.pageIndex-1])==null?void 0:d.pageFloatLayoutContext:null,L=C?c.instance.beginIsolatedRootPageFloatLayoutContext(P):null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let A=c.layoutPositions[l.pageIndex];b&&c.instance.preparePageGroupPageIndicesForRerender(c.layoutPositions,l.pageIndex),this.renderSinglePage(c,A).then(z=>{C&&c.instance.endIsolatedRootPageFloatLayoutContext(L);let U=p.currentPageType;p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,f.currentPageType=v.currentPageType,f.previousPageType=v.previousPageType,c.instance.pageGroupPageCounts=w,c.instance.currentPageGroupDocument=x,c.instance.scopes=m;let X=Fo(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),z.pageAndPosition.position.spineIndex===a.spineIndex&&z.pageAndPosition.position.pageIndex===i&&(a=z.pageAndPosition.page),a.pageType&&a.pageType!==g.currentPageType&&U!==z.pageAndPosition.page.pageType&&(p.currentPageType=a.pageType);let re=c!==e,k=c.pages.length,_=c.layoutPositions[k],F=c.instance.hasActiveRootPageFloatLayoutContext();if(_&&!F){let D=re?Fo(this.counterStore.currentPageCounters):null;re&&(this.counterStore.currentPageCounters=X);let E=k;this.renderSinglePage(c,_).then(()=>{re&&this.markSpineItemCompleteIfReady(c);let N=c.pages.length-E;if(re&&N>0){this.counterStore.adjustPageCountersOfLaterSpines(c.item.spineIndex,N),this.counterStore.updateTargetCounterNodesInPages(c.pages);let R=c.item.spineIndex;for(let $=R+1;$<this.spineItems.length;$++){let V=this.spineItems[$];if(V){V.item.epage+=N;for(let q of V.pageCounterStarts)q!=null&&q.page&&(q.page=q.page.map(Q=>Q+N));this.counterStore.updatePageCounterNodesInPages(V.pages,V.pageCounterStarts)}}if(D){let $=D.page;$&&(D.page=$.map(V=>V+N))}}D&&(this.counterStore.currentPageCounters=D),h.continueLoop()});return}re&&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=M("renderSinglePage"),n=t?Math.max(t.page,0):0,r=e.instance.getPageNumberContextDepth();e.instance.pushPageNumberContext(n+1);let o=()=>{e.instance.restorePageNumberContextDepth(r)};i.handler=(d,p)=>{o(),d.task.raise(p,d.parent)};let s=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,s),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),(_t("PAGINATION_PROGRESS").length?this.collectTotalOffsets():T(!0)).then(()=>{this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,a,c).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,c,p,t)).then(f=>{o(),i.finish({pageAndPosition:Ro(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,o=>t.instance.getPosition(t.layoutPositions[o],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=M("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(e,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(Ro(r,o))})})}),i.result()}renderPage(e){let t=M("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){t.finish(Ro(s,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(o>=0&&i.instance.getPosition(h)>o){s=c,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=c,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){t.finish(Ro(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=M("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(o=>!o.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=M("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,o=0;t&&(o=n);let s;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=M("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return T(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return T({left:null,right:null});let n=M("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,e)?o=this.previousPage(e,t):o=this.nextPage(e,t),o.then(s=>{let a=this.getPage(e),h=s&&s.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,t);return s.thenAsync(a=>a?s:r)}else return T(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return T(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,t):T(null)):r}navigateToEPage(e,t,i){let n=M("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=M("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!Pt(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ae(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!Gt(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ae(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(s)}return null}navigateTo(e,t,i){Y.debug("Navigate to",e);let n=this.opf.getPathFromURL(pt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let s=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],e=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return T(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=e.indexOf("#");if(s>=0)return this.navigateToFragment(e.substr(s+1),t,i)}return T(null)}let o=M("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(e),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Ar||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new ep(n,r);if(o.spineIndex=e.item.spineIndex,o.position=t,o.offset=e.instance.getPosition(t),o.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=Tc(this.viewport.width,this.viewport.height,i.width,i.height),a=Ri(null,new xt(s,null),"");o.delayedItems.push(new $l(n,"transform",a))}return o}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),o=null;if(r){r=Ae(r,e.url);let s=t.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=Ih(r),l=Ih(s),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 v=g.getAttribute("name"),w=g.getAttribute("value");v&&w&&(c.append("&"),c.append(encodeURIComponent(v)),c.append("="),c.append(encodeURIComponent(w)))}}o.setAttribute("src",c.toString());let d=t.getAttribute("width");d&&o.setAttribute("width",d);let p=t.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",Ir(r)),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(e,t,i,n){let r=KS();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(t,!0);this.resolveURLsInMathML(a,e),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=M("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(s)}),l.result()}return T(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ae(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):T(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return T(null);let t=this.spineItems[e];if(t)return T(t);let i=M("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),c=this.makeCustomRenderer(s),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new Ps(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],v,w;if(r.startPage!==null)v=r.startPage-1,w=v;else{if(e>0&&(!g||!g.complete))v=r.epage||e,!this.opf.prePaginated&&v%2==(f?1:0)&&v++,w=v;else{v=g?g.instance.pageNumberOffset+g.pages.length:0;let S=g&&g.pageCounterStarts[g.pages.length-1],b=S&&S.page;if(b&&b.length)w=b[b.length-1]+1;else{let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?v:C[C.length-1]}}r.skipPagesBefore!==null&&(v+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let x=new bh(l,s,this.opf.lang,d,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,v,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:s,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(S=>{S.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let n=M("showTOC");this.tocView||(this.tocView=new $S(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),Ar||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},ac="data-vivliostyle-viewer-status",QS="data-vivliostyle-spread-view",yg=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(yg||{}),eC=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"),u(this,"paginationProgressHook",null);let r=t.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",Cd),o("vivliostyle-viewport-css",kd),o("vivliostyle-polyfill-css",Id),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Ar&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ac,"loading"),this.fontMapper=new Ix(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=s=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Pc(),this.pageSizes=[],this.pixelRatioLimit=Gr==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=wc;Y.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),Y.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),Y.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),Y.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}ensurePaginationProgressListener(){if(this.paginationProgressHook)return;let e=t=>{this.callback({t:"paginationprogress",...t})};this.paginationProgressHook=e,Ft("PAGINATION_PROGRESS",e)}removePaginationProgressListener(){this.paginationProgressHook&&(kl("PAGINATION_PROGRESS",this.paginationProgressHook),this.paginationProgressHook=null)}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(ac,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){Nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=M("loadPublication");return this.configure(e).then(()=>{let s=new rc;s.init(n,r).then(()=>{let a=Ae(Fn(t),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(e){Nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,o=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=M("loadXML");return this.configure(e).then(()=>{let a=new rc;a.init(r,o).then(()=>{let h=t.map((l,c)=>({url:Ae(Fn(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Ko(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,T(!0))):t=T(!0),t.thenAsync(()=>(Nt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let o=Zt[r];if(o)return t*o}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Nh(e.userAgentRootURL.replace(/resources\/?$/,"")),Th(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Nh(e.rootURL),Th(`${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&&(Fx(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),T(!0)}configurePlugins(e){_t("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=M("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?Dn(i.fetchers):T(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new Ps(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Ps(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(QS,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let v=g*.75;return Math.ceil(v)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),c=s(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,T(!0);let t=Ae(Fn(this.cmykReserveMapUrl),Ji),i=M("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{Am(n)?this.cmykReserveMap=n:(Y.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 JS(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?T(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,T(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,T(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");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 lc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Oa().getScheduler().run(()=>_n("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,Nt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),Nt.registerEndTiming("render (resize)"),vi&&Jf(this.window)?Bx(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 lc)Nt.registerEndTiming("render (resize)"),Y.debug(i.message);else throw i}));return T(!0)}sendLocationNotification(e,t){let i=M("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return T(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=M("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=M("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=T(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return T(!0)}else if(i=="hide")return T(!0);if(n&&i!="show")return this.opfView.hideTOC(),T(!0);{let o=M("showTOC");return this.opfView.showTOC(t).then(s=>{if(s){if(r&&(s.listeners={}),t){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(e){let t=e.a||"";return _n("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(Y.error("No such action:",t),i.finish(!0))},(i,n)=>{Y.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=hc(e),i=null,n=this;Xy(()=>{let r=M("commandLoop"),o=Oa().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),T(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=M("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=hc(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},vg=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(vg||{}),lc=class wg extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,wg.prototype),this.stack=new Error().stack}};function hc(e){return typeof e=="string"?El(e):e}var uc=Cl;function tC(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function cc(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 bg=class{constructor(e,t){u(this,"settings",e),u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),gc(e.debug),this.adaptViewer_=new eC(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=tC(),t&&this.setOptions(t),this.eventTarget=new Tl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},cc(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){e==="paginationprogress"&&this.adaptViewer_.ensurePaginationProgressListener(),this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){var i;this.eventTarget.removeEventListener(e,t,!1),e==="paginationprogress"&&!((i=this.eventTarget.listeners[e])!=null&&i.length)&&this.adaptViewer_.removePaginationProgressListener()}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function o(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:iC(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},cc(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()===uc.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===uc.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 iC(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 xg=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(xg||{}),nC=vg,rC=yg;Nt.forceRegisterEndTiming("load_vivliostyle");var oC=class{constructor(e,{title:t="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1882
+ `),i.toString()}},ZS=class{constructor(t){u(this,"deobfuscator",t),u(this,"familyMap",{})}registerFamily(t,e){let i=t.family,n=this.familyMap[i],r=e.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[i]=r}filterFontFamily(t){if(t instanceof Be){let e=t.values,i=[];for(let n of e){let r=this.familyMap[n.stringValue()];r&&i.push(_(r)),i.push(n)}return new Be(i)}else{let e=this.familyMap[t.stringValue()];return e?new Be([_(e),t]):t}}},KS=class{constructor(t,e,i){u(this,"head",t),u(this,"body",e),u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(t,e){let i=t.family,n=e.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,e.familyMap[i]=n,n)}initFont(t,e,i){let n=V("initFont"),r=t.src,o={};for(let l of $h(t.properties))o[l]=t.properties[l];let s=this.getViewFontFamily(t,i);o["font-family"]=_(s);let a=new Vg(o),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,e),this.head.appendChild(h),a.styleElement=h,Y.debug("Load font:",r),n.finish(a),n.result()}loadFont(t,e){let i=t.src,n=t.family+";"+i+";"+t.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(o=>{e.registerFamily(t,o),Y.debug("Found already-loaded font:",i)}):(r=new Qs(()=>{let o=V("loadFont"),s=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=e.deobfuscator?e.deobfuscator(s):null;return a?ea(s,"blob").then(h=>{if(!h.responseBlob){o.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(t,l,e).thenFinish(o)})}):this.initFont(t,null,e).thenFinish(o),o.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(t,e){let i=[];for(let n of t){if(!n.src||!n.family){Y.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,e))}return Hn(i).thenAsync(()=>(this.reorderFontFaceRules(i),this.waitFontLoading()))}reorderFontFaceRules(t){var e;for(let i of t){let n=(e=i.resource)==null?void 0:e.styleElement;n?.parentNode===this.head&&this.head.appendChild(n)}}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(n=>{n.status==="unloaded"&&(e++,n.load().catch(r=>{}))}),e===0)return F(!0);let i=V("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>t.status==="loading"?F(!0):F(!1))).thenFinish(i),i.result()}},bi=!0;function JS(t){bi=t}var sn=[];function kc(t,e){return t===e||(t.src||e.src?t.src===e.src:t.textContent===e.textContent)}function $g(t){let e=Array.from(t.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(t.querySelectorAll("head > script, body > script")).filter(i=>!e.includes(i))}function Hh(t,e,i){if(!bi||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&$g(t.ownerDocument).includes(t))return F(!1);let n=t.textContent,r=t.src,o=t.type==="module",s=r&&r.includes("/MathJax.js");if(s){if(e.document.head.querySelector("script[src*='/MathJax.js']"))return F(!0);e.MathJax||(e.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){e.MathJax.Hub.processSectionDelay=0}})}let a=(o||r)&&t.async&&!s,h=(o&&!a||r&&t.defer)&&!s,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(Hg(e)||(e.onload=null),l)return sn.some(d=>kc(d,t))||sn.push(t),F(!0);for(let d of e.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&kc(d,t)&&e.document.head.removeChild(d);let c=e.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 t.attributes)["src","async","defer"].includes(d.name)||c.setAttribute(d.name,d.value);if(Y.debug("script:",r),r){let d=Pt(c);return e.document.head.appendChild(c),Hn([d])}else return e.document.head.appendChild(c),F(!0)}function QS(t,e){var i;let n={},r=s=>{var a;let h=(a=s["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=s._marginBoxes;if(l)for(let c of Object.values(l))r(c)},o=s=>{if(s instanceof Fh)r(s.style);else if(s instanceof tr||Array.isArray(s))for(let a of Object.values(s))o(a)};for(let s of Object.values(e.cascade.code))for(let a of Object.values(s??{}))o(a);for(let s of t.querySelectorAll("[style]"))(i=s.style)!=null&&i.fontFamily&&(n[s.style.fontFamily]=!0);return Object.keys(n).join(",")}function eC(t,e,i){var n;let r=(n=e.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:e.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=QS(t,i),r.textContent=t.documentElement.textContent,e.document.body.appendChild(r),r}function tC(t,e,i){if(!bi)return F(!1);let n=$g(t);if(n.length===0)return F(!1);let r=n.some(c=>!(c.async||c.defer||c.type==="module")),o=r?eC(t,e,i):null,s=e.document.fonts,a=e.$,h=!1,l=V("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.sleep(20).thenAsync(()=>{var d,p;return s.status==="loading"||e.document.documentElement.classList.contains("wf-loading")||(d=e.FontJSON)!=null&&d.Font&&(p=e.ret)!=null&&p.readyState&&e.ret.readyState<4?F(!0):F(!1)}):F(!1);let c=n.shift();return Hh(c,e,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&e.$!==a&&(sn.push(c),h=!0),n.length===0&&r&&(Y.debug("dispatchEvent: DOMContentLoaded (document)"),e.document.dispatchEvent(new Event("DOMContentLoaded"))),F(!0)))}).then(()=>{o&&o.remove(),l.finish(!0)}),l.result()}function iC(t){if(!bi)return F(!1);let e=V("loadScripts");return e.loop(()=>sn.length===0?F(!1):Hh(sn.shift(),t,{atEnd:!0}).thenReturn(sn.length>0)).then(()=>{Y.debug("dispatchEvent: DOMContentLoaded (window)"),t.dispatchEvent(new Event("DOMContentLoaded")),Y.debug("dispatchEvent: load (window)"),t.dispatchEvent(new Event("load")),e.finish(!0)}),e.result()}function Hg(t){return bi?sn.length>0||!!t.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var nC=t=>String(t).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Kl),rC=t=>`"${nC(t)}"`,$a=(t,e,i)=>rC(i.transformURL(Ci(String(t)),e)),oC=(t,e,i)=>t.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url(${$a(r,e,i)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url(${$a(r,e,i)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${$a(r,e,i)}`),sC={},aC=new Set(["base","body","head","html","link","meta","script","style","title"]);function lC(t){if(t instanceof K)return t;if(t instanceof ee){let e=[];for(let i of t.values)if(i instanceof K)e.push(i.str);else return null;if(e.length>0)return new K(e.join(""))}return null}function hC(t){return t instanceof et?t:t instanceof ee&&t.values[0]instanceof et&&t.values.slice(1).every(e=>e instanceof K&&e.str.trim()==="")?t.values[0]:null}function uC(t){if(no!=="webkit")return!1;let e=t["--viv-marker-content"];if(!e)return!1;let i=hC(e);if(i)return t["list-style-type"]=w.none,t["list-style-image"]=i,delete t["--viv-marker-content"],!0;let n=lC(e);return n?(t["list-style-type"]=n,t["list-style-image"]=w.none,!0):!1}function cC(t){t.addEventListener("load",()=>{t.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(e,i){return e==="mouse-events"}}},!1)}var Vl=class Cr extends Jl{constructor(e,i,n,r,o,s,a,h,l,c,d,p,f,g,m,v=new Map,b={value:!1}){super(),u(this,"flowName",e),u(this,"context",i),u(this,"viewport",n),u(this,"styler",r),u(this,"regionIds",o),u(this,"xmldoc",s),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",m),u(this,"semanticFootnoteFirstRefOffsets",v),u(this,"semanticFootnoteFirstRefOffsetsInitialized",b),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 Cr(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(e){let i=e?.page;if(!i||Z(i.value))return null;let n=i.evaluate(this.context,"page").toString();return!n||n.toLowerCase()==="auto"?null:n}isNormalFlowElement(e){var i,n,r;let o=this.styler.getStyle(e,!1),s=(i=o?.display)==null?void 0:i.evaluate(this.styler.context,"display");if((s&&!Z(s)?s:w.inline)===w.none)return!1;let a=(n=o?.position)==null?void 0:n.evaluate(this.styler.context,"position"),h=a&&!Z(a)?a:w.static;if(Nr(h)||Ur(h))return!1;let l=(r=o?.float)==null?void 0:r.evaluate(this.styler.context,"float");return(l&&!Z(l)?l:w.none)===w.none}getFirstInFlowChildElement(e){var i;let n=e.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 o=this.styler.getStyle(r,!1),s=(i=o?.display)==null?void 0:i.evaluate(this.styler.context,"display"),a=s&&!Z(s)?s:w.inline;return Wt(a)?null:r}n=n.nextSibling}return null}getEffectiveStartPageType(e,i){let n=i,r=e;for(;r;){let o=this.getFirstInFlowChildElement(r);if(!o)return n;let s=this.getExplicitPageType(this.styler.getStyle(o,!1));s&&(n=s),r=o}return n}syncTextNodePageTypeBoundary(e){if(e.sourceNode.nodeType!==Node.TEXT_NODE||Ee(e.sourceNode)||e.fragmentIndex!==1)return;let i=e.pageType;this.styler.cascade.currentPageType!==i&&(un(e.breakBefore)||(e.breakBefore=nt(e.breakBefore,"page")),i!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=i)}syncSemanticFootnoteCounterToTarget(e){if(e.localName!=="a"||!qt(e)||!Uu(e,this.xmldoc.url,r=>this.xmldoc.getElementOffset(r),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let i=e.getAttribute(Lr);if(!i)return;let n=of(e,this.xmldoc.url,r=>this.xmldoc.getElement(r));n&&n.setAttribute(Lr,i)}createPseudoelementShadow(e,i,n,r,o,s,a,h,l){var c,d;let p=this.getPseudoMap(r,this.regionIds,this.isFootnote,e,a);if(!p)return l;let f=[],g=xr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),m=g,v=qt(i)&&!!p["footnote-call"]&&At((c=p["footnote-call"].content)==null?void 0:c.value);for(let C of Xx){let y;if(C){if(!p[C])continue;let k=Et(i),S=i.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&i.localName==="include"&&i.classList.contains("-vivliostyle-footnote-content");if(C=="footnote-call"&&!qt(i)||C=="footnote-marker"&&!(k||S||n&&this.isFootnote)&&!((d=this.nodeContext)!=null&&d.pluginProps.nestedFootnoteDetached))continue;if(C.match(/^first-/)){let N=o.display;if(!N||N===w.inline)continue;let L=i.firstElementChild;if(L&&Ee(L.previousSibling)){let I=s.getStyle(L,!1);if(I){let D=ge(I,"display");if(D!=null&&D.value&&D.value!==w.inline)continue}}}if(C==="before"||C==="after"||C==="footnote-call"||C==="footnote-marker"){let N=p[C].content,L=(C==="before"||C==="after")&&(o.float===w.footnote||k||S)&&!!N;if(!N||!At(N.value)&&!L)continue}f.push(C),y=xr.createElementNS("http://www.w3.org/1999/xhtml","span"),Mr(y,C)}else{if(v)continue;y=xr.createElementNS("http://www.pyroxy.com/ns/shadow","content")}m.appendChild(y),C.match(/^first-/)&&(m=y)}if(!f.length)return l;let b=new Da(i,r,s,a,this.exprContentListener),x=new Zo(i,g,null,h,l,st.ROOTLESS,b);return l||x}getPseudoMap(e,i,n,r,o){let s=lt(e,"_pseudos");if(!s)return null;let a={};for(let h in s){let l=a[h]={};Br(l,s[h],o),Bl(l,o,s[h]),yg(s[h],i,n,(c,d)=>{Br(l,d,o),gg(d,p=>{Br(l,p,o)})})}return a}createRefShadow(e,i,n,r,o){let s=V("createRefShadow");return this.xmldoc.store.load(e).then(a=>{let h=a;if(h){let l=h.getElement(e);if(l){let c=this.stylerProducer.getStylerForDoc(h);o=new Zo(n,l,h,r,o,i,c)}}s.finish(o)}),s.result()}createShadows(e,i,n,r,o,s,a,h){let l=V("createShadows"),c=null,d=o.template,p;if(d instanceof et||d===w.footnote)if(d!==w.footnote||Uu(i,this.xmldoc.url,f=>this.xmldoc.getElementOffset(f),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let f=d instanceof et?d.url:Ie("user-agent.xml#footnote",Ei);p=this.createRefShadow(f,st.ROOTLESS,i,h,c)}else p=F(c);else p=F(c);return p.then(f=>{var g,m,v;let b=null;if(i.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&i.localName=="include"){let C=i.getAttribute("href"),y=this.xmldoc;C?y=(g=h?.xmldoc)!=null?g:this.xmldoc:h&&(h.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?C=h.owner.getAttribute("href"):C=h.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),y=(v=(m=h.parentShadow)==null?void 0:m.xmldoc)!=null?v:this.xmldoc),C&&(C=fs(C,y.url),b=this.createRefShadow(C,st.ROOTED,i,h,f))}b==null&&(b=F(f));let x=null;b.then(C=>{if(o.display===w.table_cell){let y=Ie("user-agent.xml#table-cell",Ei);x=this.createRefShadow(y,st.ROOTLESS,i,h,C)}else x=F(C);x.then(y=>{y=this.createPseudoelementShadow(e,i,n,r,o,s,a,h,y),l.finish(y)})})}),l.result()}setViewRoot(e,i){this.viewRoot=e,this.isFootnote=i}computeStyle(e,i,n,r){var o;let s=this.context,a=_l(n,s,this.regionIds,this.isFootnote),h=!((o=this.nodeContext)!=null&&o.parent);if(h){let x=this.styler.rootStyle["writing-mode"];!a["writing-mode"]&&x&&this.styler.bodyPropagatedStyle["writing-mode"]!==x&&(a["writing-mode"]=x);let C=this.styler.rootStyle.direction;!a.direction&&C&&this.styler.bodyPropagatedStyle.direction!==C&&(a.direction=C)}let l=e;e=Ml(a,s,e);let c=e;if(h&&!e){let x=this.styler.rootStyle["writing-mode"];x&&this.styler.bodyPropagatedStyle["writing-mode"]===x&&(c=Ml({"writing-mode":x},s,e))}let d=!h&&e!==l;i=mg(a,s,i);let p=(x,C)=>{var y,k;let S;d&&(e?/^(min-|max-)?(height|inline-size)$/.test(x)&&(S=(y=s.pageAreaHeight)!=null?y:void 0):/^(min-|max-)?(width|inline-size)$/.test(x)&&(S=(k=s.pageAreaWidth)!=null?k:void 0));let N=C.evaluate(s,x,S,e);return(x=="font-family"||x=="--viv-marker-font-family")&&(N=this.docFaces.filterFontFamily(N)),N},f=!!new Qe(s.style.pageScope,"left-page").evaluate(s);if(vg(a,r,e,i,f,p),d){let x=r[e?"height":"width"];(!x||x===w.auto)&&(r[e?"height":"width"]=w.max_content)}if(Nr(r.position))return r.position=w.fixed,r.visibility=w.hidden,c;let g=r.position,m=r.float,v=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?w.inline:void 0),b=kp(v,g,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(x=>{b[x]&&(r[x]=b[x])}),c}inheritFromSourceParent(e,i){var n;let r=e.sourceNode,o=[],s=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!e.parent||a),l=e.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let v=l?.owner;if(v instanceof Element&&qt(v)){let b=v.getAttribute("href")||v.getAttributeNS("http://www.w3.org/1999/xlink","href");if(b){let x=fs(b,this.xmldoc.url),C=this.xmldoc.getElement(x);C&&Et(C)&&((n=C.parentNode)==null?void 0:n.nodeType)===1&&(r=C.parentNode,l=null)}}}let c=-1;for(;r&&r.nodeType==1;){let v=l,b=v!==null&&v.root==r,x=b&&v.type==st.ROOTED&&Et(r);if(!b||v.type==st.ROOTLESS||x){let C=(v?v.styler:this.styler).getStyle(r,!1);o.push(C),s=s||ja(r)}b&&!x?(r=v.owner,l=v.parentShadow):(r=r.parentNode,c++)}let d=new Set;if(o.length>0){let v=o[0],b=_l(v,this.context,this.regionIds,this.isFootnote);for(let x in b){if(!Mn(x))continue;let C=b[x].evaluate(this.context,x);C&&C!==w.inherit&&C!==w.unset&&C!==Ae&&!Rt(C)&&d.add(x)}}let p=c===0,f=this.context.queryUnitSize("em",p),g={"font-size":new X(new B(f,"px"),0)};p&&(g["line-height"]=new X(new It(this.context.pref.lineHeight),0));let m=new j0(g,this.context);for(let v=o.length-1;v>=0;--v){let b=o[v],x=[];for(let k in b)Mn(k)&&x.push(k);x.sort(du);let C,y;for(let k of x){if(v>0&&h&&k.startsWith("--viv-marker-")||v>0&&d.has(k))continue;m.setPropName(k);let S=ge(b,k),N=S;if(S.value===w.initial)delete g[k];else if(!Z(S.value)){if(k==="font-size"&&v===o.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)N=new X(new B(this.context.rootFontSize,"px"),S.priority);else if(k==="line-height"&&v===o.length-1&&(S.value instanceof B&&(S.value.unit==="lh"||S.value.unit==="rlh")||this.context.isRootLineHeightFromRelativeCalc))N=new X(new B(this.context.rootLineHeight,"px"),S.priority);else if(v===0&&S.value instanceof B&&S.value.unit==="lh"){let L=this.getLineHeightUnitSize(k,C,y);L!=null&&(N=new X(new B(S.value.num*L,"px"),S.priority))}else ze(k)||(N=S.filterValue(m));k==="font-size"?C=N.value:k==="line-height"&&(y=N.value),g[k]=N}}}for(let v in i)Mn(v)||(g[v]=i[v]);return{lang:s,elementStyle:g}}resolveURL(e){return e=Ie(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(e){e.lang=ja(e.sourceNode)||e.parent&&e.parent.lang||e.lang}transferPolyfilledInheritedProps(e,i){let n=I0().filter(r=>i[r]);if(n.length){let r=e.inheritedProps;if(e.parent){r=e.inheritedProps={};for(let o in e.parent.inheritedProps)r[o]=e.parent.inheritedProps[o]}n.forEach(o=>{let s=i[o];if(s){if(Z(s))s===w.initial&&(r[o]=void 0);else if(s instanceof ht)r[o]=s.num;else if(s instanceof he)r[o]=s.name;else if(s instanceof B){let a=s;switch(a.unit){case"dpi":case"dpcm":case"dppx":r[o]=a.num*vi[a.unit];break;default:r[o]=s}}else r[o]=s;["widows","orphans"].includes(o)||delete i[o]}})}}resolveFormattingContext(e,i,n,r,o,s){let a=zt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](e,i,n,r,o,s);if(l){e.formattingContext=l;return}}}createElementView(e,i,n){var r;let o=!0,s=V("createElementView"),a=this.sourceNode,h=e.shadowContext?e.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(this.syncSemanticFootnoteCounterToTarget(a),!e.shadowContext){let S=this.xmldoc.getElementOffset(a);ha.registerFragmentIndex(S,e.fragmentIndex,0)}let c={},d={getStyle:S=>this.styler.getStyle(S,!1),getProp:(S,N)=>S?ge(S,N):null,getStyleMap:(S,N)=>lt(S,N),getMutableStyleMap:(S,N)=>li(S,N),createCascadeValue:(S,N)=>new X(S,N),filterFootnoteMarkerContent:(S,N)=>S.filterValue(new Yr(this.styler.cascade,N,this.styler.cascade.counterResolver,this.styler.elementWindow.currentStyle,"footnote-marker")).value};if(!e.parent){let S=this.inheritFromSourceParent(e,l);l=S.elementStyle,e.lang=S.lang}let p=l.position,f=l.float,g=l["float-reference"],m=f&&!Z(f.value)&&f.value!==w.none&&g&&!Z(g.value)?eb(g.value.toString()):null,v=!!e.shadowContext&&e.shadowContext.type===st.ROOTED&&Et(a);if(e.parent&&(Nr(p?.value)||m&&Li(m)||v)){let S=this.inheritFromSourceParent(e,l);l=S.elementStyle,e.lang=S.lang}l=sb(a,l,e.shadowContext,this.xmldoc.url,S=>this.xmldoc.getElement(S),Lr,d),l=ab(a,l,e.shadowContext,this.context,d),e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",l,c),m&&Li(m)&&c.display===w.block&&(c.display=w.flow_root),h.processContent(a,c,e),this.transferPolyfilledInheritedProps(e,c),this.inheritLangAttribute(e),c.direction&&(e.direction=c.direction.toString());let b=c["flow-into"];if(b&&b.toString()!=this.flowName)return s.finish(!1),s.result();if(bi&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Hh(a,this.viewport.window).thenFinish(s),s.result();let x=c.display;if(Et(a)&&!v&&a.hasAttribute(rf)&&(x=c.display=w.none),Z(x)&&(x===w.initial||x===w.unset?x=w.inline:x===w.inherit?x=(r=e.parent)!=null&&r.display?_(e.parent.display):null:x=null),x===w.none)return s.finish(!1),s.result();let C=e.parent==null,y=c[e.vertical?"width":"height"],k=(x===w.grid||x===w.inline_grid)&&!!y&&!(y===w.auto||Z(y));return e.flexContainer=x===w.flex||k,this.createShadows(e,a,C,l,c,h,this.context,e.shadowContext).then(S=>{var N;e.nodeShadow=S;let L=c.position,I=c.float,D=c.clear,J=e.vertical?w.vertical_rl:w.horizontal_tb,te=e.parent?e.parent.vertical?w.vertical_rl:w.horizontal_tb:J,P=hw(a),M=c["column-count"],A=c["column-width"],H=M&&M!==w.auto&&!Z(M)||A&&A!==w.auto&&!Z(A);e.establishesBFC=dw(x,L,I,c.overflow,J,te,H||P),e.containingBlockForAbsolute=pw(L),e.isInsideBFC()&&I!==w.footnote&&!(m&&Li(m))&&(I=null,D=null);let z=null,E=!1,O=this.isFootnote&&(!e.parent||e.pluginProps.nestedFootnoteDetached||v),T=lb(a,e.shadowContext,d);hb(T.sourceStyle,c,this.context),z=T.footnoteDisplay;let $=I instanceof ee||I===w.left||I===w.right||I===w.top||I===w.bottom||I===w.inline_start||I===w.inline_end||I===w.block_start||I===w.block_end||I===w.snap_block||I===w.snap_inline||I===w.inside||I===w.outside||I===w.footnote?I.toString():null,G=$!==null;if(I&&(delete c.float,I===w.footnote))if(z=c["footnote-display"]||z,E=!!c["--viv-marker-content"],O){G=!1;let W=z?.toString();W&&(c["--viv-footnote-display"]=_(W)),x=E?_("list-item"):W==="inline"||W==="compact"?w.inline:w.block,c.display=x}else c.display=w.inline;if(O&&Et(a)){E=E||!!c["--viv-marker-content"];let W=z?.toString();W&&(c["--viv-footnote-display"]=_(W)),E&&(x=c.display=_("list-item")),!E&&(W==="inline"||W==="compact")&&(x=c.display=w.inline)}D&&(D===w.inherit&&e.parent&&e.parent.clearSide&&(D=_(e.parent.clearSide)),(D===w.left||D===w.right||D===w.top||D===w.bottom||D===w.inline_start||D===w.inline_end||D===w.block_start||D===w.block_end||D===w.inside||D===w.outside||D===w.both||D===w.all||D===w.same||D===w.column||D===w.region||D===w.page)&&(delete c.clear,(G||c.display&&c.display!=w.inline)&&(e.clearSide=D.toString())));let q=mr(x)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),Q=c["break-inside"];(G||Q&&!Z(Q)&&Q!==w.auto)&&e.breakPenalty++,x&&x!==w.inline&&Wt(x)&&e.breakPenalty++,e.inline=!G&&!x||Wt(x)||Pp(x),e.display=x?x.toString():"inline",e.floatSide=G?$:null,e.floatReference=m||Ne.INLINE;let oe=c["float-min-wrap-block"];e.floatMinWrapBlock=oe&&!Z(oe)?oe:null;let se=this.isInsideNonRootMultiColumn(e),me=c["column-span"];if(e.columnSpan=!se&&me&&!Z(me)?me:null,!e.inline){let W=c["break-after"];W&&!Z(W)&&!(se&&W===w.column)&&(e.breakAfter=W.toString(),ol[e.breakAfter]&&(c["break-after"]=w.column));let $t=c["break-before"];$t&&!Z($t)&&!(se&&$t===w.column)&&(e.breakBefore=$t.toString(),ol[e.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=w.column),e.fragmentIndex!==1&&(e.breakBefore=null));let Jt=c.page,gn=Jt&&!Z(Jt)?Jt.toString():null,Ht=gn;!Ht&&!e.parent&&(e.shadowContext||x===w.table_header_group||x===w.table_footer_group)&&(Ht=this.styler.cascade.currentPageType),!Ht||Ht.toLowerCase()==="auto"?Ht=e.pageType:e.pageType=Ht;let xi=gn!=null&&gn.toLowerCase()!=="auto",$i=xi?e.fragmentIndex===1?this.getEffectiveStartPageType(a,Ht):(N=this.styler.cascade.currentPageType)!=null?N:Ht:Ht;this.styler.cascade.currentPageType!==$i&&!(!xi&&c.position===w.fixed)&&(e.fragmentIndex===1&&!un(e.breakBefore)&&(e.breakBefore="page"),$i!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=$i)}e.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let Me=c["border-collapse"];if(!Me||Me===_("separate")){let W=c["border-spacing"],$t,Jt;W&&(W instanceof ee?($t=W.values[0],Jt=W.values[1]):$t=Jt=W,$t.isNumeric()&&(e.inlineBorderSpacing=ct($t,this.context)),Jt.isNumeric()&&(e.blockBorderSpacing=ct(Jt,this.context)))}let ue=c["footnote-policy"]||T.footnotePolicy;ue&&!Z(ue)&&(c["--viv-footnote-policy"]=ue),e.footnotePolicy=ue&&!Z(ue)?ue:null;let fe=c["x-first-pseudo"];if(fe){let W=e.parent?e.parent.firstPseudo:null;e.firstPseudo=new Lw(W,fe.num)}e.inline||this.processAfterIfcontinues(e,a,l,h,this.context);let ke=c["white-space"];if(ke){let W=Ap(ke.toString());W!==null&&(e.whitespace=W)}let ye=c["hyphenate-character"];ye&&ye instanceof K&&(e.hyphenateCharacter=ye.str);let Fe=c["word-break"],_e=c["line-break"],Re=c["overflow-wrap"];(Fe===w.break_all||_e===w.anywhere||Re===w.break_word||Re===w.anywhere)&&(e.breakWord=!0),this.resolveFormattingContext(e,i,x,L,I,C),e.parent&&(i=e.parent.formattingContext.isFirstTime(e,i)),e.inline||(e.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(e,a,h));let We=!1,gt=null,ir=[],Ot=a.namespaceURI,ve=a.localName,wo=ve;Ot=="http://www.w3.org/1999/xhtml"?(aC.has(ve)?ve="div":ve=="vide_"?ve="video":ve=="audi_"?ve="audio":ve=="object"&&(We=!0),a.hasAttribute(Dh)&&a.hasAttribute("src")&&c.content instanceof et&&(ve="img")):Ot=="http://www.idpf.org/2007/ops"?(ve="span",Ot="http://www.w3.org/1999/xhtml"):Ot=="http://www.pyroxy.com/ns/shadow"?(Ot="http://www.w3.org/1999/xhtml",ve=e.inline?"span":"div"):We=!0,q?i?(ve="li",c["--viv-marker-content"]&&(uC(c)||(c["list-style-type"]=w.none,c["list-style-image"]=w.none))):(x=Wt(x)?w.inline:w.block,c.display=x,ve="div"):ve=="body"||ve=="li"?ve="div":ve=="q"&&(ve="span"),c.behavior&&c.behavior.toString()!="none"&&(We=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(We=!0);let fa;if(We){let W=e.parent?e.parent.viewNode:null;fa=this.customRenderer(a,W,c)}else fa=F(null);fa.then(W=>{var $t,Jt,gn,Ht;if(W)We&&(o=W.getAttribute("data-adapt-process-children")=="true");else if(c.display===w.none){s.finish(!1);return}else W=this.createElement(Ot,ve);if(!C&&H&&c["column-fill"]===w.auto){let Ge=e.vertical?c.width:c.height;(!Ge||Ge===w.auto||Z(Ge))&&(W.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=w.balance)}ve!=wo&&(W.setAttribute("data-vivliostyle-original-tag",wo),(wo==="html"||wo==="body")&&(W.role="presentation")),ve=="a"&&W.addEventListener("click",this.page.hrefHandler,!1),gt&&(this.applyPseudoelementStyle(e,"inner",gt),W.appendChild(gt)),W.localName=="iframe"&&W.namespaceURI=="http://www.w3.org/1999/xhtml"&&cC(W);let xi=e.inheritedProps["image-resolution"],$i=[],ga=c.width,ma=c.height,ym=a.getAttribute("width"),vm=a.getAttribute("height"),ya=ga===w.auto||!ga&&!ym,va=ma===w.auto||!ma&&!vm,Yh=a.attributes,wm=Yh.length,nr=null,Zh=null,wa=(Jt=($t=e.parent)==null?void 0:$t.viewNode)==null?void 0:Jt.lastElementChild;x===w.table_cell&&wa?.localName==="a"&&W.appendChild(wa);for(let Ge=0;Ge<wm;Ge++){let St=Yh[Ge],ut=St.namespaceURI,ae=St.localName,Pe=St.value;if(ut){if(ut=="http://www.w3.org/2000/xmlns/")continue;ut=="http://www.w3.org/1999/xlink"&&ae=="href"&&(Pe=this.documentURLTransformer.transformURL(this.resolveURL(Pe),this.xmldoc.url))}else{if(!bi&&ae.match(/^on/)||ae=="style")continue;if(ae==="media"&&ve==="source"&&Ot==="http://www.w3.org/1999/xhtml"&&((gn=a.parentElement)==null?void 0:gn.localName)==="picture")try{let Ze=this.context.rootScope,mt=new ta(Ze),xo=new xt(Pe,mt),Kh=Cp(xo,mt,"");if(Kh){if(Kh.toExpr().evaluate(this.context))continue;Pe="not all"}}catch{}if((ae=="id"||ae=="name")&&i){let Ze=this.documentURLTransformer.transformFragment(Pe,this.xmldoc.url);W.setAttribute(ae,Pe),W.setAttribute("data-vivliostyle-id",Ze);let mt=W.ownerDocument.createElement("a");mt.setAttribute(ae,Ze),mt.setAttribute(Un,"1"),mt.style.position="absolute",W.appendChild(mt),this.page.registerElementWithId(W,Ze);continue}if(ae=="src"||ae=="href"||ae=="poster")Pe=this.resolveURL(Pe),ae==="href"?Pe=this.documentURLTransformer.transformURL(Pe,this.xmldoc.url):Pe=$r(Pe),ae==="src"&&(Pe=od(Pe));else if(ae=="srcset")Pe=Pe.split(",").map(Ze=>{let mt=Ze.trim().split(/\s+/),xo=$r(this.resolveURL(mt[0]));return mt.length>1?`${xo} ${mt.slice(1).join(" ")}`:xo}).join(",");else if(ae==="data"&&We&&ve==="object"&&W.hasAttribute("data"))continue;if(ae==="poster"&&ve==="video"&&Ot==="http://www.w3.org/1999/xhtml"){let Ze=new Image,mt=Pt(Ze,Pe);ya&&va?(ir.push(mt),$i.push({image:Ze,element:W,fetcher:mt})):this.page.fetchers.push(mt)}}if(Ot=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(Pe=oC(Pe,this.xmldoc.url,this.documentURLTransformer)),ut){let Ze=sC[ut];Ze&&(ae=`${Ze}:${ae}`)}if(ae=="src"&&!ut&&(ve=="img"||ve=="input")&&Ot=="http://www.w3.org/1999/xhtml")nr=Pe;else if(ae=="alt"&&!ut&&ve=="img"&&Ot=="http://www.w3.org/1999/xhtml")Zh=Pe;else if(ae=="href"&&ve=="image"&&Ot=="http://www.w3.org/2000/svg"&&(ut=="http://www.w3.org/1999/xlink"||!ut))ut||W.setAttribute(ae,Pe),this.page.fetchers.push(Pt(W,Pe));else if(ut)W.setAttributeNS(ut,ae,Pe);else try{W.setAttribute(ae,Pe)}catch(Ze){Y.warn(Ze)}}if(nr){let Ge=ve==="input"?new Image:W,St=Pt(Ge,nr,Zh);Ge!==W&&(W.src=nr);let ut=()=>{var ae,Pe;if(c.position===w.fixed)return!0;for(let Ze=(ae=e.parent)==null?void 0:ae.viewNode;Ze&&Ze!==this.viewRoot;Ze=Ze.parentElement)if(((Pe=Ze.style)==null?void 0:Pe.position)==="fixed")return!0;return!1};!ya&&!va&&!(()=>{let ae=e.vertical?ga:ma;return ae instanceof B&&ae.unit==="%"})()&&!ut()?this.page.fetchers.push(St):(ya&&va&&xi&&xi!==1&&$i.push({image:Ge,element:W,fetcher:St}),ir.push(St))}else!nr&&ve==="img"&&Ot==="http://www.w3.org/1999/xhtml"&&(W.srcset||((Ht=a.parentElement)==null?void 0:Ht.localName)==="picture")&&this.page.fetchers.push(Pt(W));delete c.content;let bo=c["--viv-marker-content"];if(bo){let Ge=bo instanceof ee?bo.values:[bo];for(let St of Ge)St instanceof et&&St.url&&ir.push(Pt(new Image,St.url))}if(W.localName==="object"&&W.namespaceURI==="http://www.w3.org/1999/xhtml"&&W.hasAttribute("data")&&this.page.fetchers.push(Pt(W)),W.localName==="embed"&&W.namespaceURI==="http://www.w3.org/1999/xhtml"&&W.hasAttribute("src")&&this.page.fetchers.push(Pt(W)),W.localName==="iframe"&&W.namespaceURI==="http://www.w3.org/1999/xhtml"&&W.hasAttribute("src")){let Ge=W;Ge.loading==="lazy"&&(Ge.loading="eager"),this.page.fetchers.push(Pt(W))}if(this.preprocessElementStyle(e,c),this.applyComputedStyles(W,c),e.inline)i||(Ct(W,"inline-start"),Fn(W)&&Ct(W,"clone"));else if(i){if(!Ur(c.position)){let Ge=c["margin-break"],St=this.getBreakTypeAt(e),ut=St!==null,ae=St==="auto";(Ge===w.discard&&ut||Ge!==w.keep&&ae&&!e.floatSide)&&Na(W,"block-start")}}else{let Ge=e.vertical?"width":"height";Ni(W,Ge)&&R(W,Ge,e.display==="table-row"?"0.01px":""),Ct(W,"block-start"),Fn(W)&&Ct(W,"clone"),Na(W,"block-start")}q&&c["ua-list-item-count"]&&W.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=W,ir.length?Hn(ir).then(()=>{xi!==void 0&&xi>0&&this.modifyElemDimensionWithImageResolution($i,xi,c,e.vertical),s.finish(o)}):s.timeSlice().then(()=>{s.finish(o)})})}),s.result()}isAtStartOfPage(){var e,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(e=n.parent.viewNode)==null?void 0:e.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&(Ee(r,n.parent.whitespace)||Mt(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(e){var i;let n=(i=e.parent)==null?void 0:i.viewNode;return!!(n&&co(n))}getBreakTypeAt(e){var i,n,r,o,s;if(this.isInsideTable(e))return null;for(let h=e;h&&!h.after;h=h.parent){if(Ye(h.breakBefore))return h.breakBefore;let l=h.parent;if(h.fragmentIndex===1&&!l)return h.sourceNode===((i=h.sourceNode.ownerDocument)==null?void 0:i.documentElement)?"page":null;if(!l)continue;if(l.floatSide)return null;let c=l.viewNode;if(c){let d=this.viewport.window.getComputedStyle(c),p=parseFloat(d.paddingBlockStart),f=parseFloat(d.borderBlockStartWidth);if(p||f)return null;let g=c?.firstChild;for(;g&&(Ee(g,l.whitespace)||!h.floatSide&&Mt(g));)g=g.nextSibling;if(g&&g!==h.viewNode)return null}}let a=(s=(o=(r=(n=this.context)==null?void 0:n.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType)!=null?s:null;return Ye(a)?a:"auto"}isInsideTable(e){for(let i=e;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(e,i,n,r,o){let s=this.getPseudoMap(n,this.regionIds,this.isFootnote,e,o);if(s&&s["after-if-continues"]&&s["after-if-continues"].content){let a=new Da(i,n,r,o,this.exprContentListener);e.afterIfContinues=new Yx(i,a)}}isSVGUrlAttribute(e){return Cr.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,i,n,r){e.forEach(o=>{if(o.fetcher.get().get()==="load"){let s=o.image,a=s.width/i,h=s.height/i,l=o.element;if(a>0&&h>0){if(n["box-sizing"]===w.border_box&&(n["border-left-style"]!==w.none&&(a+=ct(n["border-left-width"],this.context)),n["border-right-style"]!==w.none&&(a+=ct(n["border-right-width"],this.context)),n["border-top-style"]!==w.none&&(h+=ct(n["border-top-width"],this.context)),n["border-bottom-style"]!==w.none&&(h+=ct(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||w.none,d=n["max-height"]||w.none;if(c===w.none&&d===w.none)R(l,"max-width",`${a}px`);else if(c!==w.none&&d===w.none)R(l,"width",`${a}px`);else if(c===w.none&&d!==w.none)R(l,"height",`${h}px`);else{c.isNumeric(),d.isNumeric();let p=c,f=d;p.unit!=="%"?R(l,"max-width",`${Math.min(a,ct(p,this.context))}px`):f.unit!=="%"?R(l,"max-height",`${Math.min(h,ct(f,this.context))}px`):r?R(l,"height",`${h}px`):R(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||Oe,d=n["min-height"]||Oe;c.isNumeric();let p=c,f=d;p.num===0&&f.num===0?R(l,"min-width",`${a}px`):p.num!==0&&f.num===0?R(l,"width",`${a}px`):p.num===0&&f.num!==0?R(l,"height",`${h}px`):p.unit!=="%"?R(l,"min-width",`${Math.max(a,ct(p,this.context))}px`):f.unit!=="%"?R(l,"min-height",`${Math.max(h,ct(f,this.context))}px`):r?R(l,"height",`${h}px`):R(l,"width",`${a}px`)}}}})}preprocessElementStyle(e,i){zt("PREPROCESS_ELEMENT_STYLE").forEach(n=>{n(e,i)})}findAndProcessRepeatingElements(e,i,n){for(let r=i.firstChild;r;r=r.nextSibling){if(r.nodeType!==1)continue;let o={},s=n.getStyle(r,!1);if(this.computeStyle(e.vertical,e.direction==="rtl",s,o),!this.processRepeatOnBreak(o))continue;if(e.formattingContext instanceof cn&&!e.belongsTo(e.formattingContext))return;let a=e.parent,h=a?a.formattingContext:null;e.formattingContext=new cn(h,e.sourceNode),e.formattingContext.initializeRepetitiveElements(e.vertical);return}}processRepeatOnBreak(e){let i=e["repeat-on-break"];return i!==w.none&&((i===w.auto||Z(i))&&(e.display===w.table_header_group?i=w.header:e.display===w.table_footer_group?i=w.footer:i=w.none),i&&i!==w.none)?i.toString():null}createTextNodeView(e){let i=V("createTextNodeView");return this.preprocessTextContent(e).then(n=>{let r=this.offsetInNode||0,o=Mu(n).substr(r);this.viewNode=document.createTextNode(o),i.finish(!0)}),i.result()}preprocessTextContent(e){var i;if(e.preprocessedTextContent!=null)return F(e.preprocessedTextContent);let n,r=n=(i=e.sourceNode.textContent)!=null?i:"",o=V("preprocessTextContent"),s=zt("PREPROCESS_TEXT_CONTENT"),a=0;return o.loop(()=>a>=s.length?F(!1):s[a++](e,r).thenAsync(h=>(r=h,F(!0)))).then(()=>{let h=ww(n,r);e.preprocessedTextContent=h,o.finish(h)}),o.result()}createNodeView(e,i,n){let r=V("createNodeView"),o,s=!0;return e.sourceNode.nodeType==1?o=this.createElementView(e,i,n):e.sourceNode.nodeType==8?(this.viewNode=null,o=F(!0)):o=this.createTextNodeView(e),o.then(a=>{var h;if(s=a,e.viewNode=this.viewNode,this.viewNode){let l=(f,g)=>f?.nodeType===1&&Qt(f)===g,c=e.parent,d=c&&l(this.viewNode,"after")&&l(c.viewNode,"first-letter")?c:null,p=c?(h=d?.viewNode)!=null&&h.hasChildNodes()?d.parent.viewNode:c.viewNode:this.viewRoot;e.pluginProps.nestedFootnoteDetached&&(p=this.viewRoot),p&&(e.inline&&!(this.viewNode.nodeType===3&&Ee(this.viewNode))&&!p.hasChildNodes()&&Ep(p).includes("block-start")&&Ct(p,"text-start"),p.appendChild(this.viewNode),Gw(this.viewNode))}r.finish(s)}),r.result()}setCurrent(e,i,n){return this.nodeContext=e,this.sourceNode=e.sourceNode,this.offsetInNode=e.offsetInNode,this.viewNode=null,this.createNodeView(e,i,!!n)}processShadowContent(e){if(e.shadowContext==null||e.sourceNode.localName!="content"||e.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return e;let i=e.boxOffset,n=e.shadowContext,r,o,s=n.subShadow||n.parentShadow;n.subShadow?(r=n.subShadow.root,o=n.subShadow.type,o==st.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=st.ROOTLESS);let a=e.sourceNode.nextSibling,h;if(a?(e.sourceNode=a,e.resetView(),h=e):e.shadowSibling?h=e.shadowSibling:h=null,r){let l=en.childOf(r,e.parent,i);return l.shadowContext=s,l.shadowType=o,l.shadowSibling=h,this.processShadowContent(l)}return h===null&&(h=e.parent.modify(),h.after=!0),h.boxOffset=i,h}nextPositionInTree(e,i){let n=e.boxOffset+1;if(e.after){let r=Op(e);if(!r)return null;if(r.shadowType!=st.ROOTED){let s=r.sourceNode.nextSibling;if(s)return r=r.modify(),r.boxOffset=n,r.sourceNode=s,r.resetView(),this.processShadowContent(r)}if(r.shadowSibling){let s=r.shadowSibling.modify();return s.boxOffset=n,s}let o=r.parent.modify();return o.boxOffset=n,o.after=!0,o}else{if(e.nodeShadow){let o=e.nodeShadow.root;if(e.nodeShadow.type==st.ROOTLESS&&(o=o.firstChild),o){let s=en.childOf(o,e,n);return s.shadowContext=e.nodeShadow,s.shadowType=e.nodeShadow.type,this.processShadowContent(s)}}let r=e.sourceNode.firstChild;if(r)return this.processShadowContent(en.childOf(r,e,n));if(i){let o=Mu(i);n+=o.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}findImmediateFootnoteCallSibling(e){var i;let n=this.xmldoc.getElementOffset(e.sourceNode),r=e.viewNode;if(!r)return null;let o=r.previousSibling;for(;o;){if(o.nodeType===Node.TEXT_NODE){if(((i=o.textContent)!=null?i:"").trim().length===0){o=o.previousSibling;continue}return null}if(o.nodeType===Node.ELEMENT_NODE){let s=o;return Qt(s)==="footnote-call"&&s.getAttribute(Cr.FOOTNOTE_CALL_OWNER_ATTR)===n.toString()?s:null}return null}return null}isSemanticFootnoteElement(e){let i=e.sourceNode;return i instanceof Element&&Et(i)}insertFootnoteCall(e){var i,n;let r=V("insertFootnoteCall"),o=xr.createElementNS("http://www.w3.org/1999/xhtml","span");Mr(o,"footnote-call");let s=this.xmldoc.getElementOffset(e.sourceNode);o.setAttribute(Cr.FOOTNOTE_CALL_OWNER_ATTR,s.toString());let a=en.siblingOf(o,e,e.boxOffset);a.inline=!0;let h=new Da(e.sourceNode,this.styler.getStyle(e.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new Zo(e.sourceNode,o,null,((i=e.parent)==null?void 0:i.shadowContext)||null,null,st.ROOTLESS,h),a.shadowSibling=e,e.boxOffset++,(n=e.viewNode)!=null&&n.parentNode&&e.viewNode.parentNode.removeChild(e.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&o.hasChildNodes())r.finish(a);else{let c=a.modify();c.after=!0,a.viewNode||(c.inline=!0),r.finish(c)}}),r.result()}nextInTree(e,i){return(!e.after&&e.sourceNode.nodeType!=1?this.preprocessTextContent(e):F(null)).thenAsync(n=>this.nextInTreeWithPreprocessedText(e,n,i))}nextInTreeWithPreprocessedText(e,i,n){let r=this.nextPositionInTree(e,i);if(!r||r.after)return F(r);this.syncTextNodePageTypeBoundary(r);let o=r,s=V("nextInTree");return this.setCurrent(o,!0,n).then(a=>{if((!o.viewNode||!a)&&(o=o.modify(),o.after=!0,o.viewNode||(o.inline=!0)),o.floatSide==="footnote"&&!(this.isFootnote&&!o.parent)&&!o.after&&!o.pluginProps.footnoteCallProcessed&&!o.shadowContext&&!this.isSemanticFootnoteElement(o)){let h=this.findImmediateFootnoteCallSibling(o);h!=null&&h.parentNode&&h.parentNode.removeChild(h),this.isFootnote&&o.parent&&(o.pluginProps.nestedFootnoteDetached=1),o.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(o).then(l=>{this.dispatchEvent({type:"nextInTree",nodeContext:l}),s.finish(l)});return}this.dispatchEvent({type:"nextInTree",nodeContext:o}),s.finish(o)}),s.result()}addImageFetchers(e){_r(e,this.page)}applyComputedStyles(e,i){var n,r,o;let s=i["background-image"];s&&this.addImageFetchers(s);let a=i["border-image-source"];a&&this.addImageFetchers(a);let h=i["list-style-image"];h&&this.addImageFetchers(h);let l=i["mask-image"];l&&this.addImageFetchers(l);let 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===w.relative,m=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((o=this.viewRoot)!=null&&o.parentElement),v=Object.keys(i);v.sort(du);let b,x;for(let C of v){if(pC[C])continue;let y=i[C];if(!(!y||y===Ae&&!ze(C))){if(y=y.visit(new Wy(this.xmldoc.url,this.documentURLTransformer)),y instanceof B)if(y.unit==="em"){let k=this.getEmUnitSize(C,b);k!=null&&(y=new B(y.num*k,"px"))}else if(y.unit==="lh"){let k=this.getLineHeightUnitSize(C,b,x);k!=null&&(y=new B(y.num*k,"px"))}else fd(y.unit)&&(y=Ld(y,this.context));if((C==="font-size"||C==="line-height")&&(C==="font-size"?b=y:x=y,this.viewport.layoutUnitAdj&&y instanceof B&&y.unit!=="%"&&y.unit!=="em"&&y.unit!=="lh"&&(y=new Sn(`calc(${y.toString()} - var(--viv-layoutUnitAdj))`))),Sw[C]||g&&Cw[C]){this.page.delayedItems.push(new hh(e,C,y));continue}m&&this.page.pageAreaElement&&Mn(C)?(R(this.page.pageAreaElement.parentElement.parentElement,C,y.toString()),C!=="writing-mode"&&C!=="direction"&&R(this.viewport.layoutBox,C,y.toString())):R(e,C,y.toString())}}}parsePlusLayoutUnitAdj(e){if(e.endsWith("px")){let i=parseFloat(e);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getFootnoteAreaInheritedMetrics(){var e,i;let n=(i=(e=this.page.pageAreaElement)==null?void 0:e.parentElement)==null?void 0:i.parentElement,r=n?this.viewport.window.getComputedStyle(n):null,o=r&&this.parsePlusLayoutUnitAdj(r.fontSize)||this.context.rootFontSize||this.context.initialFontSize,s=r&&this.parsePlusLayoutUnitAdj(r.lineHeight)||this.context.rootLineHeight||o*this.context.pref.lineHeight;return{fontSize:o,lineHeight:s}}getComputedFontMetrics(e,i){var n,r,o;let s=this.viewport.window.getComputedStyle(e),a=(n=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?n:i.fontSize,h=(o=(r=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?r:i.lineHeight)!=null?o:a!=null?a*this.context.pref.lineHeight:null;return{fontSize:a,lineHeight:h}}getParentViewStyle(){var e,i,n;return((n=(i=(e=this.nodeContext)==null?void 0:e.parent)==null?void 0:i.viewNode)==null?void 0:n.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(e){var i,n;return{fontSize:(i=this.computedStyleParentFontSizeOverride)!=null?i:e?this.parsePlusLayoutUnitAdj(e.fontSize):this.context.rootFontSize,lineHeight:(n=this.computedStyleParentLineHeightOverride)!=null?n:e?this.parsePlusLayoutUnitAdj(e.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(e,i,n){var r,o,s;let a=this.getParentViewStyle(),h=this.getParentComputedMetrics(a),l=h.lineHeight;if(e==="line-height"||e==="font-size")return l;let c=null;if(n)if(n instanceof It||n instanceof B&&(n.unit==="em"||n.unit==="%"))c=n instanceof B&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof B&&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=(o=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:o.viewNode;d&&d.nodeType===1;d=d.parentNode){let p=(s=d?.style)==null?void 0:s.lineHeight;if(p){/^[0-9.]+$/.test(p)&&(c=parseFloat(p));break}}if(c!=null){if(i&&!(i instanceof B))return null;let d=h.fontSize;if(i instanceof B){let p=Tl(i,d,this.context).num;return typeof p!="number"||isNaN(p)?null:c*p}else return d==null?null:c*d}return l}getEmUnitSize(e,i){let n=this.getParentViewStyle(),r=this.getParentComputedMetrics(n).fontSize;if(e==="font-size"||i==null)return r;if(i instanceof B){let o=Tl(i,r,this.context).num;if(typeof o=="number"&&!isNaN(o))return o}return null}applyPseudoelementStyle(e,i,n){if(e.after)return;let r=this.sourceNode,o=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(r,!1),s=lt(o,"_pseudos");if(!s||(o=s[i],!o))return;let a={};e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",o,a);let h=a.content;At(h)&&(h.visit(new Wr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(e,i){let n=V("peelOff"),r=e.firstPseudo,o=e.offsetInNode,s=e.after;if(i>0)o+=i;else if(!s&&e.viewNode&&o==0){let f=e.viewNode.parentNode;f&&f.removeChild(e.viewNode)}let a=e.boxOffset+i,h=[],l=e;for(let f=e.parent;f&&f.firstPseudo===r;f=l.parent)h.push(l),l=f;let c=l.shadowSibling,d=h.length-1,p=null;return n.loop(()=>{for(;d>=0;){let f=h[d],g=p??l.parent,m=new en(f.sourceNode,g,a,(g??l).formattingContext);m.blockContainer=g&&Cs(g),d==0&&(m.offsetInNode=o,m.after=s),m.shadowType=f.shadowType,m.shadowContext=f.shadowContext,m.nodeShadow=f.nodeShadow,m.shadowSibling=f.shadowSibling?f.shadowSibling:c,c=null,p=m,d--;let v=this.setCurrent(m,!1);if(v.isPending())return v}return F(!1)}).then(()=>{n.finish(p??e.parent)}),n.result()}createElement(e,i){return e=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(e,i)}applyFootnoteStyle(e,i,n){var r;let o={},s=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let p=lt(this.cascadedPageStyle,Xs);p&&p.area&&(a=p.area)}let h=lt(a,"_pseudos");e=this.computeStyle(e,i,a,o);let l=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&l.fontSize!=null&&(o["font-size"]=new B(l.fontSize,"px")),delete o.content;let c=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=l.fontSize,this.computedStyleParentLineHeightOverride=l.lineHeight;try{this.applyComputedStyles(n,o);let p=this.getComputedFontMetrics(n,l);if(this.computedStyleParentFontSizeOverride=p.fontSize,this.computedStyleParentLineHeightOverride=p.lineHeight,h&&h.before){let f=h.before,g=!!ge(f,"display"),m={},v=this.createElement("http://www.w3.org/1999/xhtml","span");Mr(v,"before"),n.appendChild(v),this.computeStyle(e,i,f,m),g||(m.display=w.block);let b=ge(f,"content");if(b){let C=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;m.content=b.filterValue(new Yr(this.styler.cascade,C,this.styler.cascade.counterResolver,this.styler.elementWindow.currentStyle,"before")).evaluate(this.context,"content")}let x=m.content;if(At(x)){x.visit(new Wr(v,this.context,x,this.exprContentListener));let C=v.querySelectorAll("img[src]");for(let k=0;k<C.length;k++){let S=C[k],N=S.getAttribute("src");if(!N)continue;let L=Pt(S,N);s.push(L),this.page.fetchers.push(L)}let y=v.getAttribute("src");if(y){let k=v.querySelector("img");k||(k=this.document.createElement("img"),k.setAttribute("src",y),v.appendChild(k));let S=Pt(k,y);s.push(S),this.page.fetchers.push(S)}}delete m.content,this.applyComputedStyles(v,m)}}finally{this.computedStyleParentFontSizeOverride=c,this.computedStyleParentLineHeightOverride=d}return s.length?Hn(s).thenReturn(e):F(e)}processFragmentedBlockEdge(e){var i,n,r;let o=!e.inline&&e.after?e.parent:e,s=!1;if(e.inline&&e.after&&!e.shadowContext&&((i=e.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=e.sourceNode.nextSibling,l=(n=ge(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();s=l&&!Wt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=o;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(Ct(l,"inline-end"),Fn(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;Ct(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=e.vertical?"width":"height";if(Ni(l,c)&&R(l,c,""),Ct(l,"block-end"),!a++&&h!==o){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!s){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?Np(p,["block-start","text-start","block-end","text-end","justify"]):(Ct(l,"text-end"),Ct(l,"justify")):Ct(l,"text-end")}else Ct(l,"text-end")}Fn(l)&&Ct(l,"clone"),Na(l,"block-end")}}}fixClonedBoxDecorationOverflow(e){let i=this.viewport.window.getComputedStyle(e),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),o=-(n+r);isNaN(o)||(e.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(e){let i=o=>{let{display:s,position:a,float:h}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||tn[o.localName])return!1;if(o.localName==="br")return!0;if((s==="inline"||s==="contents")&&o.hasChildNodes()){let l=o.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===o.lastChild&&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(s==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||o.hasAttribute(Un)){let l=o.previousElementSibling;return l&&(l.nextSibling===o||l.nextSibling===o.previousSibling&&Ee(l.nextSibling))?i(l):!1}return!(!s||Wt(s))},n=null;for(let o=e.lastElementChild;o;o=o.previousElementSibling){let s=i(o);if(s){n=o;break}if(s===null)return null}if(!n)return e;if(n===e.lastElementChild&&(!n.nextSibling||n.nextSibling===e.lastChild&&Ee(n.nextSibling)))return null;let r=e.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let o=n.nextSibling,s=null;o;o=s)s=o.nextSibling,r.appendChild(o);return e.appendChild(r),r}convertLengthToPx(e,i,n){let r=e.num,o=e.unit;if(sy(o)){let s=i;for(;s&&s.nodeType!==1;)s=s.parentNode;let a=parseFloat(n.getElementComputedStyle(s)["font-size"]);return Ah(e,a,this.context).num}else{let s=this.context.queryUnitSize(o,!1);return s?r*s:e}}isSameNodePositionStep(e,i){if(e.shadowContext){if(!i.shadowContext)return!1;let n=e.node.nodeType===1?e.node:e.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return e.shadowContext.owner===i.shadowContext.owner&&Qt(n)===Qt(r)}else return e.node===i.node}isSameNodePosition(e,i){return e.offsetInNode===i.offsetInNode&&e.after==i.after&&e.steps.length===i.steps.length&&e.steps.every((n,r)=>{let o=i.steps[r];return this.isSameNodePositionStep(n,o)})}isPseudoelement(e){return!!Qt(e)}};u(Vl,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),u(Vl,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var dC=Vl,pC={"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},fC=class{constructor(t){u(this,"layoutBox"),u(this,"window"),u(this,"pixelRatio"),u(this,"scaleRatio"),u(this,"layoutUnitPerPixel"),this.layoutBox=t.layoutBox,this.window=t.window,this.pixelRatio=t.pixelRatio,this.scaleRatio=t.scaleRatio,this.layoutUnitPerPixel=t.layoutUnitPerPixel}subtractOffsets(t,e){let i=e.left,n=e.top;return{left:t.left-i,top:t.top-n,right:t.right-i,bottom:t.bottom-n,width:t.width,height:t.height}}getRangeClientRects(t){let e=t.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(e).map(n=>this.subtractOffsets(n,i))}getElementClientRect(t){let e=t.getBoundingClientRect();if(e.left===0&&e.top===0&&e.right===0&&e.bottom===0)return e;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(e,i)}getElementComputedStyle(t){return this.window.getComputedStyle(t,null)}adjustLengthValue(t){return this.layoutUnitPerPixel?Math.floor(t*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:t}},Gs=class{constructor(t,e,i,n,r,o){if(u(this,"window",t),u(this,"fontSize",e),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=t.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=o||this.root.clientHeight;return}let s=this.root.firstElementChild;s||(s=this.document.createElement("div"),s.setAttribute("data-vivliostyle-outer-zoom-box","true"),s.role="presentation",this.root.appendChild(s));let a=s.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",s.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(R(this.root,"--viv-outputPixelRatio",`${i}`),R(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=i/t.devicePixelRatio),no){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||t.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&&R(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=s.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=s,this.contentContainer=a,this.layoutBox=h,this.width=r||parseFloat(t.getComputedStyle(this.root).width)||this.root.offsetWidth||t.innerWidth,this.height=o||parseFloat(t.getComputedStyle(this.root).height)||this.root.offsetHeight||t.innerHeight;let l={width:794,height:1056},c=!t.outerWidth&&!t.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&t.innerWidth===800&&t.innerHeight===600;(!this.width||!r&&c)&&(this.width=l.width),(!this.height||!o&&c)&&(this.height=l.height)}resetZoom(){R(this.outerZoomBox,"width",""),R(this.outerZoomBox,"height",""),R(this.contentContainer,"width",""),R(this.contentContainer,"height",""),R(this.contentContainer,"transform","")}zoom(t,e,i){R(this.root,"--viv-outputScale",`${i}`),R(this.outerZoomBox,"width",`${t*i}px`),R(this.outerZoomBox,"height",`${e*i}px`),R(this.contentContainer,"width",`${t}px`),R(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};function _r(t,e){if(t instanceof Be)for(let i of t.values)_r(i,e);else if(t instanceof et){let i=$r(t.url);e.fetchers.push(Pt(new Image,i))}else if(t instanceof Vt)for(let i of t.values)_r(i,e);else if(t instanceof ee)for(let i of t.values)_r(i,e)}var gC=1,da=class{constructor(t,e,i,n,r){u(this,"name",e),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=t,this.key=`p${gC++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(t,e,i){throw new Error("E_UNEXPECTED_CALL")}clone(t){throw new Error("E_UNEXPECTED_CALL")}copySpecified(t){let e=this.specified,i=t.specified;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n])}cloneChildren(t){for(let e=0;e<this.children.length;e++)this.children[e].clone({parent:t})}},mC=class extends da{constructor(t){super(t,null,null,[],null),this.specified.width=new X(so,0),this.specified.height=new X(ao,0)}},Pc=class extends qa{constructor(t,e){super(t,n),u(this,"pageMaster",e);let i=this;function n(r,o){let s=r.match(/^([^.]+)\.([^.]+)$/);if(s){let a=i.pageMaster.keyMap[s[1]];if(a){let h=this.lookupInstance(a);if(h)return o?h.resolveFunc(s[2]):h.resolveName(s[2])}}return null}}},Ug=class Wg extends da{constructor(e,i,n,r,o,s,a,h=null){super(e,i,n,r,o),u(this,"condition",s),u(this,"specificity",a),u(this,"layer",h),u(this,"keyMap",{}),e instanceof Pc||(this._scope=new Pc(e,this)),this.pageMaster=this,this.specified.width=new X(so,0),this.specified.height=new X(ao,0),this.specified["wrap-flow"]=new X(w.auto,0),this.specified.position=new X(w.relative,0),this.specified.overflow=new X(w.visible,0)}createInstance(e,i,n){return new Yg(e,this)}clone(e){let i=new Wg(this.scope,this.name,e.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity,this.layer);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},Gg=class jg extends da{constructor(e,i,n,r,o){super(e,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new X(w.auto,0)}createInstance(e,i,n){return new xC(e,this)}clone(e){let i=new jg(e.parent.scope,this.name,this.pseudoName,this.classes,e.parent);return this.copySpecified(i),this.cloneChildren(i),i}},vo=class Xg extends da{constructor(e,i,n,r,o){super(e,i,n,r,o),this.pageMaster=o.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(e,i,n){return new Yn(e,this)}clone(e){let i=new Xg(e.parent.scope,this.name,this.pseudoName,this.classes,e.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function yC(t,e,i){return!e||Z(e)?new it(t,i):e.toExpr(t,t.zero)}function xe(t,e,i){return!e||e===w.auto||Z(e)?null:e.toExpr(t,i)}function vC(t,e,i){return!e||e===w.normal||Z(e)?null:e.toExpr(t,i)}function Tt(t,e,i){return!e||e===w.auto||Z(e)?t.zero:e.toExpr(t,i)}function Ec(t,e,i){return!e||Z(e)?t.zero:e===w.auto?null:e.toExpr(t,i)}function ai(t,e,i,n){return!e||i===w.none||Z(e)?t.zero:e.toExpr(t,n)}function qg(t,e,i){return!e||Z(e)?i:e===w._true?t._true:e===w._false?t._false:e.toExpr(t,t.zero)}var pa=class{constructor(t,e){u(this,"parentInstance",t),u(this,"pageBox",e),u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth"),u(this,"autoHeight"),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),t&&t.children.push(this);let i=this.pageBox.scope;this.autoWidth=new be(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new be(i,()=>this.calculatedHeight,"autoHeight")}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(t,e){let i=this.resolveName(t),n=this.resolveName(e);if(!i||!n)throw new Error("E_INTERNAL");return re(this.pageBox.scope,i,n)}resolveName(t){let e=this.namedValues[t];if(e)return e;let i=this.style[t];switch(i&&(e=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),t){case"margin-left-edge":e=this.resolveName("left");break;case"margin-top-edge":e=this.resolveName("top");break;case"margin-right-edge":e=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":e=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":e=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":e=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":e=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":e=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":e=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":e=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":e=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":e=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":e=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":e=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":e=this.addNamedValues("left-edge","width");break;case"bottom-edge":e=this.addNamedValues("top-edge","height");break}if(!e){let n;if(t=="extent")n=this.vertical?"width":"height";else if(t=="measure")n=this.vertical?"height":"width";else{let r=this.vertical?Xf:qf;n=t;for(let o in r)n=n.replace(o,r[o])}n!=t&&(e=this.resolveName(n))}return e&&(this.namedValues[t]=e),e}resolveFunc(t){let e=this.namedFuncs[t];if(e)return e;if(t==="columns"){let i=this.pageBox.scope,n=new Ed(i,0),r=this.resolveName("column-count"),o=this.resolveName("column-width"),s=this.resolveName("column-gap");e=we(i,qo(i,new Er(i,"min",[n,r]),re(i,o,s)),s)}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,i=qg(t,e.enabled,t._true),n=xe(t,e.page,t.zero);if(n){let s=new Qe(t,"page-number");i=Xt(t,i,new rh(t,n,s))}let r=xe(t,e["min-page-width"],t.zero);r&&(i=Xt(t,i,new Za(t,new Qe(t,"page-width"),r)));let o=xe(t,e["min-page-height"],t.zero);o&&(i=Xt(t,i,new Za(t,new Qe(t,"page-height"),o))),i=this.boxSpecificEnabled(i),e.enabled=new j(i)}boxSpecificEnabled(t){return t}initHorizontal(){let t=this.pageBox.scope,e=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,n=xe(t,e.left,i),r=xe(t,e["margin-left"],i),o=ai(t,e["border-left-width"],e["border-left-style"],i),s=Tt(t,e["padding-left"],i),a=xe(t,e.width,i),h=xe(t,e["max-width"],i),l=Tt(t,e["padding-right"],i),c=ai(t,e["border-right-width"],e["border-right-style"],i),d=xe(t,e["margin-right"],i),p=xe(t,e.right,i),f=re(t,o,s),g=re(t,o,l);if(n&&p&&a){let b=we(t,i,re(t,a,re(t,re(t,n,f),g)));r?d?p=we(t,b,d):d=we(t,b,re(t,p,r)):(b=we(t,b,p),d?r=we(t,b,d):(r=qo(t,b,new it(t,.5)),d=r))}else{r||(r=t.zero),d||(d=t.zero),!n&&!p&&!a&&(n=t.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=t.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let b=we(t,i,re(t,re(t,r,f),re(t,d,g)));this.isAutoWidth&&(h||(h=we(t,b,n||p)),!this.vertical&&(xe(t,e["column-width"],null)||xe(t,e["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=we(t,b,re(t,n,a))):a=we(t,b,re(t,n,p)):n=we(t,b,re(t,p,a))}let m=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),v=Tt(t,m,i);e.left=new j(n),e["margin-left"]=new j(r),e["border-left-width"]=new j(o),e["padding-left"]=new j(s),e.width=new j(a),e["max-width"]=new j(h||a),e["padding-right"]=new j(l),e["border-right-width"]=new j(c),e["margin-right"]=new j(d),e.right=new j(p),e["snap-width"]=new j(v)}initVertical(){let t=this.pageBox.scope,e=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(t,null):null,r=xe(t,e.top,n),o=xe(t,e["margin-top"],i),s=ai(t,e["border-top-width"],e["border-top-style"],i),a=Tt(t,e["padding-top"],i),h=xe(t,e.height,n),l=xe(t,e["max-height"],n),c=Tt(t,e["padding-bottom"],i),d=ai(t,e["border-bottom-width"],e["border-bottom-style"],i),p=xe(t,e["margin-bottom"],i),f=xe(t,e.bottom,n),g=re(t,s,a),m=re(t,d,c);if(r&&f&&h){let x=we(t,n,re(t,h,re(t,re(t,r,g),m)));o?p?f=we(t,x,o):p=we(t,x,re(t,f,o)):(x=we(t,x,f),p?o=we(t,x,p):(o=qo(t,x,new it(t,.5)),p=o))}else{o||(o=t.zero),p||(p=t.zero),!r&&!f&&!h&&(r=t.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=t.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let x=we(t,n,re(t,re(t,o,g),re(t,p,m)));this.isAutoHeight&&(l||(l=we(t,x,r||f)),this.vertical&&(xe(t,e["column-width"],null)||xe(t,e["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=we(t,x,re(t,r,h))):h=we(t,x,re(t,f,r)):r=we(t,x,re(t,f,h))}let v=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=Tt(t,v,i);e.top=new j(r),e["margin-top"]=new j(o),e["border-top-width"]=new j(s),e["padding-top"]=new j(a),e.height=new j(h),e["max-height"]=new j(l||h),e["padding-bottom"]=new j(c),e["border-bottom-width"]=new j(d),e["margin-bottom"]=new j(p),e.bottom=new j(f),e["snap-height"]=new j(b)}initColumns(){let t=this.pageBox.scope,e=this.style,i=xe(t,e[this.vertical?"height":"width"],null),n=xe(t,e["column-width"],i),r=xe(t,e["column-count"],null),o=vC(t,e["column-gap"],null);o||(o=new oo(t,1,"em")),n&&!r&&(r=new Er(t,"floor",[Ka(t,re(t,i,o),re(t,n,o))]),r=new Er(t,"max",[t.one,r])),r||(r=t.one),n=we(t,Ka(t,re(t,i,o),r),o),e["column-width"]=new j(n),e["column-count"]=new j(r),e["column-gap"]=new j(o)}depends(t,e,i){return this.style[t].toExpr(this.pageBox.scope,null).depend(e,i)}resolveStyle(t){var e;let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(t):null,o=_l(this.cascaded,t,r,!1);this.vertical=Ml(o,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=mg(o,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((e=o["box-sizing"])==null?void 0:e.value)===w.border_box;let s=!!(t instanceof Xh&&t.currentLayoutPosition&&new Qe(i,"left-page").evaluate(t));vg(o,n,this.vertical,this.rtl,s,(a,h)=>h.value)}init(t){this.resolveStyle(t),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}register(t){t.registerInstance(this.pageBox.key,this)}getProp(t,e){var i,n;let r=this.style[e];return!r&&Mn(e)&&this.pageMasterInstance instanceof to&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?r=new B(t.rootFontSize,"px"):r=(n=((i=t.styler)==null?void 0:i.rootStyle)[e])==null?void 0:n.value),r&&(r=Hs(t,r,e)),r}getPropAsNumber(t,e){var i,n;let r=this.style[e];if(r){let o=/\b(height|top|bottom)\b/.test(e)?(i=t.pageAreaHeight)!=null?i:t.pageHeight():(n=t.pageAreaWidth)!=null?n:t.pageWidth();r=Hs(t,r,e,o)}return ct(r,t)}getSpecial(t,e){let i=Kf(this.cascaded,e);if(i){let n=[];for(let r=0;r<i.length;r++){let o=i[r].evaluate(t,"");o&&o!==Ae&&n.push(o)}if(n.length)return n}return null}getActiveRegions(t){let e=this.getSpecial(t,"region-id");if(e){let i=[];for(let n=0;n<e.length;n++)i[n]=e[n].toString();return i}return null}propagateProperty(t,e,i,n){this.propagatePropertyToElement(t,e.element,i,n)}propagatePropertyToElement(t,e,i,n){let r=this.getProp(t,i);if(r){r.isNumeric()&&fd(r.unit)&&(r=Ld(r,t)),i==="font-family"&&(r=n.filterFontFamily(r));let o=e.parentElement;(i.startsWith("background")||i==="z-index")&&o!=null&&o.hasAttribute("data-vivliostyle-bleed-box")&&(e=o),R(e,i,r.toString())}}propagateDelayedProperty(t,e,i,n){let r=this.getProp(t,i);r&&n.push(new hh(e.element,i,r))}assignLeftPosition(t,e){let i=this.getPropAsNumber(t,"left"),n=this.getPropAsNumber(t,"margin-left"),r=this.getPropAsNumber(t,"padding-left"),o=this.getPropAsNumber(t,"border-left-width"),s=this.getPropAsNumber(t,"width");e.setHorizontalPosition(i,s),R(e.element,"margin-left",`${n}px`),R(e.element,"padding-left",`${r}px`),R(e.element,"border-left-width",`${o}px`),e.marginLeft=n,e.borderLeft=o,e.paddingLeft=r}assignRightPosition(t,e){let i=this.getPropAsNumber(t,"right"),n=this.getPropAsNumber(t,"snap-height"),r=this.getPropAsNumber(t,"margin-right"),o=this.getPropAsNumber(t,"padding-right"),s=this.getPropAsNumber(t,"border-right-width");if(R(e.element,"margin-right",`${r}px`),R(e.element,"padding-right",`${o}px`),R(e.element,"border-right-width",`${s}px`),e.marginRight=r,e.borderRight=s,this.vertical&&n>0){let a=i+e.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(e.snapOffsetX=n-h,o+=e.snapOffsetX)}e.paddingRight=o,e.snapWidth=n}assignTopPosition(t,e){let i=this.getPropAsNumber(t,"snap-height"),n=this.getPropAsNumber(t,"top"),r=this.getPropAsNumber(t,"margin-top"),o=this.getPropAsNumber(t,"padding-top"),s=this.getPropAsNumber(t,"border-top-width");if(e.top=n,e.marginTop=r,e.borderTop=s,e.snapHeight=i,!this.vertical&&i>0){let a=n+e.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(e.snapOffsetY=i-h,o+=e.snapOffsetY)}e.paddingTop=o,R(e.element,"top",`${n}px`),R(e.element,"margin-top",`${r}px`),R(e.element,"padding-top",`${o}px`),R(e.element,"border-top-width",`${s}px`)}assignBottomPosition(t,e){let i=this.getPropAsNumber(t,"margin-bottom"),n=this.getPropAsNumber(t,"padding-bottom"),r=this.getPropAsNumber(t,"border-bottom-width"),o=this.getPropAsNumber(t,"height")-e.snapOffsetY;R(e.element,"height",`${o}px`),R(e.element,"margin-bottom",`${i}px`),R(e.element,"padding-bottom",`${n}px`),R(e.element,"border-bottom-width",`${r}px`),e.height=o-e.snapOffsetY,e.marginBottom=i,e.borderBottom=r,e.paddingBottom=n}assignBeforePosition(t,e){this.vertical?this.assignRightPosition(t,e):this.assignTopPosition(t,e)}assignAfterPosition(t,e){this.vertical?this.assignLeftPosition(t,e):this.assignBottomPosition(t,e)}assignStartEndPosition(t,e){this.vertical?(this.assignTopPosition(t,e),this.assignBottomPosition(t,e)):(this.assignRightPosition(t,e),this.assignLeftPosition(t,e))}sizeWithMaxHeight(t,e){R(e.element,"border-top-width","0px");let i=this.getPropAsNumber(t,"max-height");this.isTopDependentOnAutoHeight?e.setVerticalPosition(0,i):(this.assignTopPosition(t,e),i-=e.snapOffsetY,e.height=i,R(e.element,"height",`${i}px`))}sizeWithMaxWidth(t,e){R(e.element,"border-left-width","0px");let i=this.getPropAsNumber(t,"max-width");if(this.isRightDependentOnAutoWidth)e.setHorizontalPosition(0,i);else{this.assignRightPosition(t,e),i-=e.snapOffsetX,e.width=i;let n=this.getPropAsNumber(t,"right");R(e.element,"right",`${n}px`),R(e.element,"width",`${i}px`)}}prepareContainer(t,e,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&R(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&R(e.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(t,e):this.sizeWithMaxHeight(t,e):(this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(t,e):this.sizeWithMaxWidth(t,e):this.assignStartEndPosition(t,e);for(let o=0;o<Nc.length;o++)this.propagateProperty(t,e,Nc[o],n)}transferContentProps(t,e,i,n){for(let r=0;r<Ic.length;r++)this.propagateProperty(t,e,Ic[r],n);if(this.style["text-overflow"]){let r=e.element.firstElementChild;R(r,"text-overflow","inherit"),R(r,"overflow","inherit")}}transferSingleUriContentProps(t,e,i){let n=()=>{var o,s;let a=(s=(o=this.cascaded.width)!=null?o:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:s.value;return!!a&&a!==w.auto&&!Z(a)},r=()=>{var o,s;let a=(s=(o=this.cascaded.height)!=null?o:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:s.value;return!!a&&a!==w.auto&&!Z(a)};for(let o=0;o<Ac.length;o++){let s=Ac[o];if(s==="width"||s==="height"){if(s==="width"&&!n()||s==="height"&&!r())continue;R(e,s,"100%");continue}this.propagatePropertyToElement(t,e,s,i)}}finishContainer(t,e,i,n,r,o,s){var a,h,l,c,d,p,f,g,m,v,b,x;this.vertical?this.calculatedWidth=e.computedBlockSize+e.snapOffsetX:this.calculatedHeight=e.computedBlockSize+e.snapOffsetY;let C=(this.vertical||!n)&&this.isAutoHeight,y=(!this.vertical||!n)&&this.isAutoWidth,k=null;if(y||C){y&&R(e.element,"width","auto"),C&&R(e.element,"height","auto");let S=n&&ks(n);S&&na(n),k=o.getElementClientRect(n?n.element:e.element),S&&ch(n),y&&(this.calculatedWidth=Math.ceil(k.right-k.left-e.paddingLeft-e.borderLeft-e.paddingRight-e.borderRight),this.vertical&&(this.calculatedWidth+=e.snapOffsetX)),C&&(this.calculatedHeight=k.bottom-k.top-e.paddingTop-e.borderTop-e.paddingBottom-e.borderBottom,this.vertical||(this.calculatedHeight+=e.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(t,e),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),r>1){let S=this.getPropAsNumber(t,"column-rule-width"),N=this.getProp(t,"column-rule-style"),L=this.getProp(t,"column-rule-color");if(S>0&&N&&N!=w.none&&L!=w.transparent){let I=this.getPropAsNumber(t,"column-gap"),D=this.vertical?e.height:e.width,J=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),te=e.getPaddingRect(),P=n,M=this.vertical?"border-top":"border-left";for(let A=1;A<r;A++){let H=this.vertical?(D+I)*A/r-I/2+e.paddingTop-S/2:(D+I)*A/r-I/2+e.paddingLeft-S/2,z=this.vertical?te.y1+H+S/2:te.x1+H+S/2,E=(p=(d=(c=(l=P.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:c.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(c,z))!=null?p:NaN,O=(v=(m=(g=(f=P.pageFloatLayoutContext)==null?void 0:f.parent)==null?void 0:g.getBlockStartEdgeOfBlockEndFloats)==null?void 0:m.call(g,z))!=null?v:NaN,T=isFinite(E)?this.vertical?E-te.x1:E-te.y1:NaN,$=isFinite(O)?this.vertical?O-te.x1:O-te.y1:NaN,G=parseFloat(this.vertical?(b=n?.element.style.width)!=null?b:"":(x=n?.element.style.height)!=null?x:""),q=G>0?G:this.vertical?n.width:n.height,Q=Math.max(J>0?J:0,0),oe=Q+q,se=Math.max(Q,isFinite(this.vertical?$:T)?Math.max(0,this.vertical?$:T):0),me=Math.min(oe,isFinite(this.vertical?T:$)?Math.max(0,this.vertical?T:$):oe),Me=Math.max(0,me-se),ue=e.element.ownerDocument.createElement("div");R(ue,"position","absolute"),R(ue,this.vertical?"left":"top",`${se}px`),R(ue,this.vertical?"top":"left",`${H}px`),R(ue,this.vertical?"height":"width","0px"),R(ue,this.vertical?"width":"height",`${Me}px`),R(ue,M,`${S}px ${N.toString()}${L?` ${L.toString()}`:""}`),e.element.insertBefore(ue,e.element.firstChild)}}}for(let S=0;S<Tc.length;S++)this.propagateProperty(t,e,Tc[S],s);for(let S of wC){let N=this.getProp(t,S);N&&_r(N,i)}for(let S=0;S<Fc.length;S++)this.propagateDelayedProperty(t,e,Fc[S],i.delayedItems)}buildCascadedStyle(t){let e=this.cascaded,i=this.pageBox.specified;for(let n in i)this instanceof to&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(n==="writing-mode"||n==="direction")||Ii(n)&&Bi(e,n,ge(i,n));if(this.pageBox.pseudoName==Uh)for(let n in t)(n.match(/^background-/)||n=="writing-mode")&&(e[n]=t[n]);if(this.pageBox.pseudoName=="layout-host")for(let n in t)!n.match(/^background-/)&&n!="writing-mode"&&(e[n]=t[n])}resolveContent(t){let e=this.cascaded,i=e.content;if(i){let n=Array.from(t.lastCounterChanges),r={...t.lastCounterChangeTypes};t.counterScoping.push(null),t.pushCounters(e,e),e.content=i.filterValue(new Yr(t,null,t.counterResolver,e)),t.popCounters(),t.popCounters(),t.lastCounterChanges=n,t.lastCounterChangeTypes=r}}applyCascadeAndInit(t,e){this.buildCascadedStyle(e),t.pushRule(this.pageBox.classes,null,this.cascaded),this.resolveContent(t),this.init(t.context),this.register(t.context);for(let i of this.pageBox.children)i.createInstance(this,t.context,e).applyCascadeAndInit(t,e);t.popRule()}resolveAutoSizing(t){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,t)||this.depends("margin-right",this.autoWidth,t)||this.depends("border-right-width",this.autoWidth,t)||this.depends("padding-right",this.autoWidth,t)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,t)||this.depends("margin-top",this.autoHeight,t)||this.depends("border-top-width",this.autoHeight,t)||this.depends("padding-top",this.autoHeight,t));for(let e of this.children)e.resolveAutoSizing(t)}},Nc=["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"],Tc=["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-position-x","background-position-y","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],wC=["background-image","border-image-source","filter"],Ic=["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"],Ac=["width","height","image-resolution","object-fit","object-position"],Fc=["transform","transform-origin"],Uh="background-host";function Rc(t){var e;let i=t;return{priority:i.specificity,layer:(e=i.layer)!=null?e:null}}var bC=class extends pa{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((i,n)=>Vi(Rc(n.pageBox),Rc(i.pageBox))||i.pageBox.index-n.pageBox.index)}},Yg=class extends pa{constructor(t,e){super(t,e),this.pageMasterInstance=this}get pageAreaEstablishingChild(){return null}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=Xt(e.scope,t,e.condition)),t}adjustPageLayout(t,e,i){}},xC=class extends pa{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},Yn=class extends pa{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,i){let n=null;if(e instanceof he&&(n=[e]),e instanceof Be&&(n=e.values),n){let r=this.pageBox.scope;for(let o=0;o<n.length;o++)if(n[o]instanceof he){let s=Xa(n[o].name,"enabled"),a=new Qe(r,s);i&&(a=new Ri(r,a)),t=Xt(r,t,a)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,i=this.style,n=qg(e,i.required,e._false)!==e._false;if(n||this.isAutoHeight){let r=yC(e,i["flow-from"],"body"),o=new Er(e,"has-content",[r]);t=Xt(e,t,o)}if(t=this.processPartitionList(t,i["required-partitions"],!1),t=this.processPartitionList(t,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,o=r?r.toExpr(e,null):e._true;o=Xt(e,o,t),this.pageMasterInstance.style.enabled=new j(o)}return t}prepareContainer(t,e,i,n,r){var o;this.pageBox.pageMaster instanceof em||(R(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(t,e,i,n,r)}},Wh=class extends Jn{constructor(t,e,i,n,r){super(t,e,r),u(this,"target",i),u(this,"validatorSet",n)}property(t,e,i){this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}unknownProperty(t,e){this.report(`E_INVALID_PROPERTY ${t}: ${e.toString()}`)}invalidPropertyValue(t,e){this.report(`E_INVALID_PROPERTY_VALUE ${t}: ${e.toString()}`)}simpleProperty(t,e,i){this.target.specified[t]=new X(e,i?vp:wp)}},Zg=class extends Wh{constructor(t,e,i,n,r){super(t,e,i,n,r)}},SC=class Kg extends Wh{constructor(e,i,n,r,o){super(e,i,n,r,o),n.specified.width=new X(uu,0),n.specified.height=new X(uu,0)}startPartitionRule(e,i,n){let r=new vo(this.scope,e,i,n,this.target);this.owner.delegateTo(o=>new Zg(this.scope,this.owner,r,this.validatorSet,o))}startPartitionGroupRule(e,i,n){let r=new Gg(this.scope,e,i,n,this.target);this.owner.delegateTo(o=>new Kg(this.scope,this.owner,r,this.validatorSet,o))}},CC=class extends Wh{constructor(t,e,i,n,r){super(t,e,i,n,r)}startPartitionRule(t,e,i){let n=new vo(this.scope,t,e,i,this.target);this.owner.delegateTo(r=>new Zg(this.scope,this.owner,n,this.validatorSet,r))}startPartitionGroupRule(t,e,i){let n=new Gg(this.scope,t,e,i,this.target);this.owner.delegateTo(r=>new SC(this.scope,this.owner,n,this.validatorSet,r))}};function Jg(t){var e,i;let n=(e=t["writing-mode"])==null?void 0:e.value,r=(i=t.direction)==null?void 0:i.value;return n===w.vertical_lr||n!==w.vertical_rl&&r!==w.rtl?"ltr":"rtl"}var kC={a10:{width:new B(26,"mm"),height:new B(37,"mm")},a9:{width:new B(37,"mm"),height:new B(52,"mm")},a8:{width:new B(52,"mm"),height:new B(74,"mm")},a7:{width:new B(74,"mm"),height:new B(105,"mm")},a6:{width:new B(105,"mm"),height:new B(148,"mm")},a5:{width:new B(148,"mm"),height:new B(210,"mm")},a4:{width:new B(210,"mm"),height:new B(297,"mm")},a3:{width:new B(297,"mm"),height:new B(420,"mm")},a2:{width:new B(420,"mm"),height:new B(594,"mm")},a1:{width:new B(594,"mm"),height:new B(841,"mm")},a0:{width:new B(841,"mm"),height:new B(1189,"mm")},b10:{width:new B(31,"mm"),height:new B(44,"mm")},b9:{width:new B(44,"mm"),height:new B(62,"mm")},b8:{width:new B(62,"mm"),height:new B(88,"mm")},b7:{width:new B(88,"mm"),height:new B(125,"mm")},b6:{width:new B(125,"mm"),height:new B(176,"mm")},b5:{width:new B(176,"mm"),height:new B(250,"mm")},b4:{width:new B(250,"mm"),height:new B(353,"mm")},b3:{width:new B(353,"mm"),height:new B(500,"mm")},b2:{width:new B(500,"mm"),height:new B(707,"mm")},b1:{width:new B(707,"mm"),height:new B(1e3,"mm")},b0:{width:new B(1e3,"mm"),height:new B(1414,"mm")},c10:{width:new B(28,"mm"),height:new B(40,"mm")},c9:{width:new B(40,"mm"),height:new B(57,"mm")},c8:{width:new B(57,"mm"),height:new B(81,"mm")},c7:{width:new B(81,"mm"),height:new B(114,"mm")},c6:{width:new B(114,"mm"),height:new B(162,"mm")},c5:{width:new B(162,"mm"),height:new B(229,"mm")},c4:{width:new B(229,"mm"),height:new B(324,"mm")},c3:{width:new B(324,"mm"),height:new B(458,"mm")},c2:{width:new B(458,"mm"),height:new B(648,"mm")},c1:{width:new B(648,"mm"),height:new B(917,"mm")},c0:{width:new B(917,"mm"),height:new B(1297,"mm")},"jis-b10":{width:new B(32,"mm"),height:new B(45,"mm")},"jis-b9":{width:new B(45,"mm"),height:new B(64,"mm")},"jis-b8":{width:new B(64,"mm"),height:new B(91,"mm")},"jis-b7":{width:new B(91,"mm"),height:new B(128,"mm")},"jis-b6":{width:new B(128,"mm"),height:new B(182,"mm")},"jis-b5":{width:new B(182,"mm"),height:new B(257,"mm")},"jis-b4":{width:new B(257,"mm"),height:new B(364,"mm")},"jis-b3":{width:new B(364,"mm"),height:new B(515,"mm")},"jis-b2":{width:new B(515,"mm"),height:new B(728,"mm")},"jis-b1":{width:new B(728,"mm"),height:new B(1030,"mm")},"jis-b0":{width:new B(1030,"mm"),height:new B(1456,"mm")},letter:{width:new B(8.5,"in"),height:new B(11,"in")},legal:{width:new B(8.5,"in"),height:new B(14,"in")},ledger:{width:new B(11,"in"),height:new B(17,"in")}},PC=new B(.24,"pt"),Bk=new B(3,"mm"),EC=new B(10,"mm"),NC=new B(13,"mm");function js(t){let e={width:so,height:ao,bleed:Oe,bleedOffset:Oe,cropOffset:Oe},i=t.size;if(!(!i||i.value===w.auto)){let l=i.value,c,d;if(l.isSpaceList()?(c=l.values[0],d=l.values[1]):(c=l,d=null),c.isNumeric())e.width=c,e.height=d||c;else{let p=c.name&&kC[c.name.toLowerCase()];p&&(d&&d===w.landscape?(e.width=p.height,e.height=p.width):(e.width=p.width,e.height=p.height))}}let n=t.marks,r=t.bleed,o=n&&!Z(n.value)?n.value:w.none,s=r&&!Z(r.value)?r.value:w.auto;if(s===w.auto){if(o!==w.none){let l=!1;o.isSpaceList()?l=o.values.some(c=>c===w.crop):l=o===w.crop,l&&(e.bleed=new B(6,"pt"))}}else s.isNumeric()&&(e.bleed=s);let a=t["crop-offset"],h=a&&!Z(a.value)?a.value:w.auto;return h===w.auto?o!==w.none&&(e.bleedOffset=NC):h.isNumeric()&&(e.cropOffset=h),e}function Lc(t,e){let i={},n=Math.max(0,t.bleed.num)*e.queryUnitSize(t.bleed.unit,!1),r=!t.cropOffset.num&&t.bleedOffset.num?t.bleedOffset.num*e.queryUnitSize(t.bleedOffset.unit,!1):Math.max(0,t.cropOffset.num*e.queryUnitSize(t.cropOffset.unit,!1)-n),o=n+r,s=t.width;s===so?e.pref.defaultPaperSize?i.pageWidth=e.pref.defaultPaperSize.width*e.queryUnitSize("px",!1):i.pageWidth=(e.pref.spreadView?Math.floor(e.viewportWidth/2)-e.pref.pageBorder:e.viewportWidth)-o*2:i.pageWidth=s.num*e.queryUnitSize(s.unit,!1);let a=t.height;return a===ao?e.pref.defaultPaperSize?i.pageHeight=e.pref.defaultPaperSize.height*e.queryUnitSize("px",!1):i.pageHeight=e.viewportHeight-o*2:i.pageHeight=a.num*e.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=o,i}function Qg(t,e,i){let n=t.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",e),n.setAttribute("height",i),n.style.position="absolute",n}function Dr(t,e,i,n){n=n||"polyline";let r=t.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===w.auto?"#010101":i.toString()),r.setAttribute("stroke-width",e),r.setAttribute("fill","none"),r}var $l=(t=>(t.TOP_LEFT="top left",t.TOP_RIGHT="top right",t.BOTTOM_LEFT="bottom left",t.BOTTOM_RIGHT="bottom right",t))($l||{});function TC(t,e,i,n,r,o,s){let a=r;a<=o+2*vi.mm&&(a=o+r/2);let h=Math.max(r,a),l=o+h+i/2,c=Qg(t,l,l),d=[[0,o+r],[r,o+r],[r,o+r-a]],p=d.map(m=>[m[1],m[0]]);(e==="top right"||e==="bottom right")&&(d=d.map(m=>[o+h-m[0],m[1]]),p=p.map(m=>[o+h-m[0],m[1]])),(e==="bottom left"||e==="bottom right")&&(d=d.map(m=>[m[0],o+h-m[1]]),p=p.map(m=>[m[0],o+h-m[1]]));let f=Dr(t,i,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),c.appendChild(f);let g=Dr(t,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),c.appendChild(g),e.split(" ").forEach(m=>{c.style[m]=`${s}px`}),c}var Qr=(t=>(t.TOP="top",t.BOTTOM="bottom",t.LEFT="left",t.RIGHT="right",t))(Qr||{});function IC(t,e,i,n,r,o){let s=r*2,a,h;e==="top"||e==="bottom"?(a=s,h=r):(a=r,h=s);let l=Qg(t,a,h),c=Dr(t,i,n);c.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(c);let d=Dr(t,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=Dr(t,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.appendChild(p);let f;switch(e){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Qr).forEach(g=>{let m=Qr[g];m===e?l.style[m]=`${o}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function AC(t,e,i,n){let r=!1,o=!1,s=t.marks;if(s){let m=s.value;m instanceof ee?m.values.forEach(v=>{v===w.crop?r=!0:v===w.cross&&(o=!0)}):m===w.crop?r=!0:m===w.cross&&(o=!0)}let a=e.bleed;if(!r&&!o)return;let h=i.container,l=h.ownerDocument,c=ct(PC,n),d=Math.max(0,e.bleedOffset-ct(EC,n)),p=e.bleedOffset-d,f=t["crop-marks-line-color"],g=f&&!Z(f.value)?f.value:w.auto;r&&Object.keys($l).forEach(m=>{let v=$l[m],b=TC(l,v,c,g,p,a,d);h.appendChild(b)}),o&&Object.keys(Qr).forEach(m=>{let v=Qr[m],b=IC(l,v,c,g,p,d);h.appendChild(b)})}var Hl=(()=>{let t=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],e={width:!0,height:!0,"block-size":!0,"inline-size":!0,"writing-mode":!0,direction:!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 t.forEach(i=>{e[`margin-${i}`]=!0,e[`padding-${i}`]=!0,e[`border-${i}-width`]=!0,e[`border-${i}-style`]=!0,e[`border-${i}-color`]=!0}),e})(),Gh={"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"}},FC=(()=>{let t=Gh;return Object.keys(t).sort((e,i)=>t[e].order-t[i].order)})(),jh="vivliostyle-page-rule-master",eo="_marginBoxes",Xs="_footnoteArea",em=class extends Ug{constructor(t,e,i){super(t,null,jh,[],e,null,0),u(this,"pageMarginBoxes",{}),u(this,"pageRulePartition");let n=js(i);this.pageRulePartition=new RC(this.scope,this,i,n),this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(t){let e=t[eo];e&&FC.forEach(i=>{e[i]&&(this.pageMarginBoxes[i]=new OC(this.scope,this,i,t))})}applySpecified(t,e){this.specified.position=new X(w.relative,0),this.specified.width=new X(e.width,0),this.specified.height=new X(e.height,0);for(let i in t)!Hl[i]&&i!=="background-clip"&&(this.specified[i]=t[i])}createInstance(t,e,i){return new to(t,this,e,i)}},RC=class extends vo{constructor(t,e,i,n){super(t,null,null,[],e),u(this,"pageSize",n),u(this,"pageAreaPartition"),this.pageAreaPartition=new LC(this.scope,this),this.applySpecified(i)}applySpecified(t){this.specified["wrap-flow"]=new X(w.auto,0),this.specified["z-index"]=new X(new ht(0),0),this.specified.position=new X(w.absolute,0),this.specified.overflow=new X(w.visible,0);for(let e in Hl)Hl.hasOwnProperty(e)&&(this.specified[e]=t[e])}createInstance(t,e,i){return new MC(t,this,e,i)}},LC=class extends vo{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new X(_("body"),0)}},OC=class extends vo{constructor(t,e,i,n){super(t,null,null,[],e),u(this,"marginBoxName",i),this.applySpecified(n)}applySpecified(t){let e=t[eo][this.marginBoxName];for(let i in t){let n=t[i],r=e[i];(jf[i]||r&&r.value===w.inherit)&&(this.specified[i]=n)}for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i];n&&n.value!==Ae&&n.value!==w.inherit&&n.value!==w.unset&&n.value!==w.revert&&(this.specified[i]=n)}}createInstance(t,e,i){return new tm(t,this)}},to=class extends Yg{constructor(t,e,i,n){var r;super(t,e),u(this,"pageAreaDimension"),u(this,"pageAreaPartitionInstance"),u(this,"pageMarginBoxInstances",{});let o=(r=i.styler)==null?void 0:r.bodyPropagatedStyle;for(let h in n)if(Object.prototype.hasOwnProperty.call(n,h))switch(h){case"writing-mode":case"direction":if(o?.[h]===n[h])break;this.cascaded[h]=n[h]}this.buildCascadedStyle(n),this.init(i),this.pageAreaPartitionInstance=this.pageBox.pageRulePartition.createInstance(this,i,n);let s=this.pageAreaPartitionInstance.pageAreaDimension;this.pageAreaDimension=s;let a=this.style;a.width=new j(s.borderBoxWidth),a.height=new j(s.borderBoxHeight),a["padding-left"]=new j(s.marginLeft),a["padding-right"]=new j(s.marginRight),a["padding-top"]=new j(s.marginTop),a["padding-bottom"]=new j(s.marginBottom),this.register(i)}get pageAreaEstablishingChild(){return this.pageAreaPartitionInstance}applyCascadeAndInit(t,e){t.pushRule(this.pageBox.classes,null,this.cascaded),this.resolveContent(t);let i=this.cascaded.content;i&&(this.style.content=i.value);for(let n of this.pageBox.children)(n===this.pageBox.pageRulePartition?this.pageAreaPartitionInstance:n.createInstance(this,t.context,e)).applyCascadeAndInit(t,e);t.popRule()}initHorizontal(){let t=this.style;t.left=Oe,t["margin-left"]=Oe,t["border-left-width"]=Oe,t["padding-left"]=Oe,t["padding-right"]=Oe,t["border-right-width"]=Oe,t["margin-right"]=Oe,t.right=Oe}initVertical(){let t=this.style;t.top=Oe,t["margin-top"]=Oe,t["border-top-width"]=Oe,t["padding-top"]=Oe,t["padding-bottom"]=Oe,t["border-bottom-width"]=Oe,t["margin-bottom"]=Oe,t.bottom=Oe}adjustPageLayout(t,e,i){let n=e.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},o={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,t,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,t,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,o,t,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,o,t,i)}sizeMarginBoxesAlongVariableDimension(t,e,i,n,r){let o="start",s="center",a="end",h=this.pageBox.scope,l={},c={},d={};for(let C in t){let y=Gh[C];if(y){let k=t[C],S=this.pageMarginBoxInstances[C],N=new us(k,S.style,e,h,r);l[y.positionAlongVariableDimension]=k,c[y.positionAlongVariableDimension]=S,d[y.positionAlongVariableDimension]=N}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,m={};Object.keys(l).forEach(C=>{let y=C,k=xe(h,c[y].style[e?"max-width":"max-height"],i.extent);if(k){let S=k.evaluate(n),N=f[y];if(N!=null&&N>S){let L=d[y]=new Oc(l[y],c[y].style,e,h,r,S);m[y]=L.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[o,s,a].forEach(C=>{var y;f[C]=(y=m[C])!=null?y:f[C]}));let v={};Object.keys(l).forEach(C=>{let y=C,k=xe(h,c[y].style[e?"min-width":"min-height"],i.extent);if(k){let S=k.evaluate(n),N=f[y];if(N!=null&&N<S){let L=d[y]=new Oc(l[y],c[y].style,e,h,r,S);v[y]=L.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[o,s,a].forEach(C=>{f[C]=v[C]||f[C]}));let b=p.start+p.extent,x=p.start+(p.start+p.extent);[o,s,a].forEach(C=>{let y=f[C];if(y!=null){let k=l[C],S=0;switch(C){case o:S=e?k.left:k.top;break;case s:S=(x-y)/2;break;case a:S=b-y;break}e?k.setHorizontalPosition(S,y-k.getInsetLeft()-k.getInsetRight()):k.setVerticalPosition(S,y-k.getInsetTop()-k.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(t,e){var i;let n=t.start,r=t.center,o=t.end,s={};if(r){let a=[n,o],h=new BC(a),l=this.distributeAutoMarginBoxSizes(r,h,e);l.xSize!=null&&(s.center=l.xSize);let c=(i=l.xSize)!=null?i:r.getOuterSize(),d=Math.max((e-c)/2,0);n&&(s.start=n.hasAutoSize()?d:n.getOuterSize()),o&&(s.end=o.hasAutoSize()?d:o.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n??null,o??null,e);a.xSize!=null&&(s.start=a.xSize),a.ySize!=null&&(s.end=a.ySize)}return s}distributeAutoMarginBoxSizes(t,e,i){let n={xSize:null,ySize:null};if(t instanceof us&&t.minMaxFitContent&&(n.xSize=t.getOuterSize()),e instanceof us&&e.minMaxFitContent&&(n.ySize=e.getOuterSize()),t&&e)if(t.hasAutoSize()&&e.hasAutoSize()){let r=t.getOuterMaxContentSize(),o=e.getOuterMaxContentSize();if(r>0&&o>0){let s=r+o;if(s<i)n.xSize=i*r/s;else{let a=t.getOuterMinContentSize(),h=e.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(s-l):l>0&&(n.xSize=i*a/l)}n.xSize!=null&&n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:o>0&&(n.ySize=i)}else t.hasAutoSize()?n.xSize=Math.max(i-e.getOuterSize(),0):e.hasAutoSize()&&(n.ySize=Math.max(i-t.getOuterSize(),0));else t?t.hasAutoSize()&&(n.xSize=i):e&&e.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(t,e,i,n,r){e.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(t,e,i,n,r)}},us=class{constructor(t,e,i,n,r){u(this,"container",t),u(this,"isHorizontal",i),u(this,"clientLayout",r),u(this,"hasAutoSize_"),u(this,"size",null),u(this,"minMaxFitContent",null);let o=e[i?"width":"height"];if(this.hasAutoSize_=!o||o===w.auto||Z(o),this.minMaxFitContent=o instanceof he&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let s=this.getSize();if(this.isHorizontal){let a=s[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=s[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let t=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=fh(this.clientLayout,this.container.element,t)}return this.size}getOuterMaxContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["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()}},BC=class{constructor(t){u(this,"params",t)}hasAutoSize(){return this.params.some(t=>{var e;return(e=t?.hasAutoSize())!=null?e:!1})}getOuterMaxContentSize(){let t=this.params.map(e=>{var i;return(i=e?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,t)*t.length}getOuterMinContentSize(){let t=this.params.map(e=>{var i;return(i=e?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,t)*t.length}getOuterSize(){let t=this.params.map(e=>{var i;return(i=e?.getOuterSize())!=null?i:0});return Math.max.apply(null,t)*t.length}},Oc=class extends us{constructor(t,e,i,n,r,o){super(t,e,i,n,r),u(this,"fixedSize"),this.fixedSize=o}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},MC=class extends Yn{constructor(t,e,i,n){super(t,e),u(this,"contentBoxWidth"),u(this,"contentBoxHeight"),u(this,"pageAreaDimension"),u(this,"pageAreaEstablishingChild");for(let s in n)s.match(/^background-/)&&(this.cascaded[s]=n[s]);this.buildCascadedStyle(n),this.resolveStyle(i);let r=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"}),o=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.contentBoxWidth=new j(r.contentBoxExtent),this.contentBoxHeight=new j(o.contentBoxExtent),this.pageAreaDimension={borderBoxWidth:r.borderBoxExtent,borderBoxHeight:o.borderBoxExtent,marginLeft:r.marginStart,marginRight:r.marginEnd,marginTop:o.marginStart,marginBottom:o.marginEnd},this.initColumns(),this.initEnabled(),this.register(i),this.pageAreaEstablishingChild=new _C(this,e.pageAreaPartition)}applyCascadeAndInit(t,e){t.pushRule(this.pageBox.classes,null,this.cascaded),this.pageAreaEstablishingChild.applyCascadeAndInit(t,e),t.popRule()}resolvePageBoxDimensions(t){let e=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=t.start,o=t.end,s=t.extent,a=i[s].toExpr(n,null),h=xe(n,e[s],a),l=xe(n,e[`margin-${r}`],a),c=xe(n,e[`margin-${o}`],a),d=Tt(n,e[`padding-${r}`],a),p=Tt(n,e[`padding-${o}`],a),f=ai(n,e[`border-${r}-width`],e[`border-${r}-style`],a),g=ai(n,e[`border-${o}-width`],e[`border-${o}-style`],a),m=re(n,re(n,f,d),re(n,g,p)),v,b,x;return h?(this.borderBoxSizing?(b=h,x=we(n,b,m)):(x=h,b=re(n,x,m)),v=we(n,a,b),!l&&!c?(l=qo(n,v,new it(n,.5)),c=l):l?c=we(n,v,l):l=we(n,v,c)):(l||(l=n.zero),c||(c=n.zero),v=re(n,l,c),b=we(n,a,v),x=we(n,b,m),h=this.borderBoxSizing?b:x),e[r]=new j(l),e[o]=new j(c),e[`margin-${r}`]=Oe,e[`margin-${o}`]=Oe,e[`border-${r}-width`]=new j(f),e[`border-${o}-width`]=new j(g),e[`padding-${r}`]=new j(d),e[`padding-${o}`]=new j(p),e[s]=new j(h),e[`max-${s}`]=new j(h),{borderBoxExtent:b,contentBoxExtent:x,marginStart:l,marginEnd:c}}prepareContainer(t,e,i,n,r){e.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(t,e,i,n,r)}},_C=class extends Yn{constructor(t,e){super(t,e),u(this,"pageAreaEstablishingChild",null),u(this,"pageRulePartitionInstance"),this.pageRulePartitionInstance=t}applyCascadeAndInit(t,e){var i,n;for(let r in e)r.match(/^column.*$/)&&(this.cascaded[r]=e[r]);this.cascaded["writing-mode"]=(i=e["writing-mode"])!=null?i:new X(w.horizontal_tb,0),this.cascaded.direction=(n=e.direction)!=null?n:new X(w.ltr,0),super.applyCascadeAndInit(t,{})}initHorizontal(){let t=this.style,e=this.pageRulePartitionInstance,i=e.style,n=this.pageBox.scope;t.left=i["padding-left"],t.width=e.contentBoxWidth,t["margin-left"]=new j(new In(n,i.left.toExpr(n,null))),t["margin-right"]=new j(new In(n,i.right.toExpr(n,null))),t["border-left-width"]=i.left,t["border-right-width"]=i.right,t["border-left-style"]=w.solid,t["border-right-style"]=w.solid,t["border-left-color"]=w.transparent,t["border-right-color"]=w.transparent}initVertical(){let t=this.style,e=this.pageRulePartitionInstance,i=e.style,n=this.pageBox.scope;t.top=i["padding-top"],t.height=e.contentBoxHeight,t["margin-top"]=new j(new In(n,i.top.toExpr(n,null))),t["margin-bottom"]=new j(new In(n,i.bottom.toExpr(n,null))),t["border-top-width"]=i.top,t["border-bottom-width"]=i.bottom,t["border-top-style"]=w.solid,t["border-bottom-style"]=w.solid,t["border-top-color"]=w.transparent,t["border-bottom-color"]=w.transparent}prepareContainer(t,e,i,n,r){e.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=e.element,super.prepareContainer(t,e,i,n,r),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},tm=class extends Yn{constructor(t,e){super(t,e),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=e.marginBoxName;this.boxInfo=Gh[i];let n=t;n.pageMarginBoxInstances[i]=this}prepareContainer(t,e,i,n,r){e.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(t,e.element),super.prepareContainer(t,e,i,n,r)}applyVerticalAlign(t,e){R(e,"display","flex"),R(e,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(t,"vertical-align"),n=null;i===_("middle")?n="center":i===_("top")?n="flex-start":i===_("bottom")&&(n="flex-end"),n&&R(e,"justify-content",n);let r=this.getProp(t,"content");if(this.vertical||r instanceof et||r instanceof j&&r.expr instanceof be&&r.expr.str.startsWith("running-element-")){let o="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?o=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(o=this.vertical||this.rtl?"end":"start")),R(e,"align-items",o)}}positionAlongVariableDimension(t,e){let i=this.style,n=this.pageBox.scope,r=t.start,o=t.end,s=t.extent,a=r==="left",h=a?e.borderBoxWidth:e.borderBoxHeight,l=xe(n,i[s],h),c=a?e.marginLeft:e.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new j(c);else if(l){let d=Tt(n,i[`margin-${r}`],h),p=Tt(n,i[`margin-${o}`],h),f=Tt(n,i[`padding-${r}`],h),g=Tt(n,i[`padding-${o}`],h),m=ai(n,i[`border-${r}-width`],i[`border-${r}-style`],h),v=ai(n,i[`border-${o}-width`],i[`border-${o}-style`],h),b=re(n,l,re(n,this.borderBoxSizing?n.zero:re(n,re(n,f,g),re(n,m,v)),re(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new j(re(n,c,Ka(n,we(n,h,b),new it(n,2))));break;case"end":i[r]=new j(we(n,re(n,c,h),b));break}}}positionAndSizeAlongFixedDimension(t,e){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,o=t.inside,s=t.outside,a=t.extent,h=e[`margin${s.charAt(0).toUpperCase()}${s.substring(1)}`],l=Ec(n,i[`margin-${o}`],h),c=Ec(n,i[`margin-${s}`],h),d=Tt(n,i[`padding-${o}`],h),p=Tt(n,i[`padding-${s}`],h),f=ai(n,i[`border-${o}-width`],i[`border-${o}-style`],h),g=ai(n,i[`border-${s}-width`],i[`border-${s}-style`],h),m=xe(n,i[a],h),v=null;function b(x){if(v)return v;v={extent:m?m.evaluate(x):null,marginInside:l?l.evaluate(x):null,marginOutside:c?c.evaluate(x):null};let C=h.evaluate(x),y=0;return r||[f,d,p,g].forEach(k=>{k&&(y+=k.evaluate(x))}),(v.marginInside===null||v.marginOutside===null)&&y+v.extent+v.marginInside+v.marginOutside>C&&(v.marginInside===null&&(v.marginInside=0),v.marginOutside===null&&(v.marginOutside=0)),v.extent!==null&&v.marginInside!==null&&v.marginOutside!==null&&(v.marginOutside=null),v.extent===null?(v.extent=C-y-v.marginInside-v.marginOutside,v.marginInside===null&&(v.marginInside=0),v.marginOutside===null&&(v.marginOutside=0)):typeof v.extent=="number"&&(v.marginInside===null&&typeof v.marginOutside=="number"?v.marginInside=C-y-v.extent-v.marginOutside:typeof v.marginInside=="number"&&v.marginOutside===null?v.marginOutside=C-y-v.extent-v.marginInside:v.marginInside=v.marginOutside=(C-y-v.extent)/2),v}i[a]=new j(new be(n,function(){let x=b(this).extent;return x===null?"auto":x},a)),i[`margin-${o}`]=new j(new be(n,function(){let x=b(this).marginInside;return x===null?"auto":x},`margin-${o}`)),i[`margin-${s}`]=new j(new be(n,function(){let x=b(this).marginOutside;return x===null?"auto":x},`margin-${s}`)),o==="left"?i.left=new j(re(n,e.marginLeft,e.borderBoxWidth)):o==="top"&&(i.top=new j(re(n,e.marginTop,e.borderBoxHeight)))}initHorizontal(){let t=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},t):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},t):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},t)}initVertical(){let t=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},t):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},t):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},t)}finishContainer(t,e,i,n,r,o,s){super.finishContainer(t,e,i,n,r,o,s);let a=i.marginBoxes,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=e:l.isInBottomRow&&(a.bottom[h]=e):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=e:l.isInRightColumn&&(a.right[h]=e));let c=this.parentInstance.pageAreaDimension,d=this.getProp(t,"width"),p=d instanceof he&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(t,"min-width"),g=this.getPropAsNumber(t,"max-width");if(p||f||g){p&&R(e.element,"width",p),f&&R(e.element,"min-width",`${f}px`),g&&R(e.element,"max-width",`${g}px`);let C=this.getProp(t,"margin-left"),y=this.getProp(t,"margin-right");if(l.isInLeftColumn){let k=c.borderBoxWidth.evaluate(t)+c.marginRight.evaluate(t);R(e.element,"right",`${k}px`),(C===w.auto||y!==w.auto)&&R(e.element,"margin-left","auto"),y===w.auto&&R(e.element,"margin-right","auto")}else l.isInRightColumn&&(R(e.element,"right","0"),(y===w.auto||C!==w.auto)&&R(e.element,"margin-right","auto"),C===w.auto&&R(e.element,"margin-left","auto"))}let m=this.getProp(t,"height"),v=m instanceof he&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,b=this.getPropAsNumber(t,"min-height"),x=this.getPropAsNumber(t,"max-height");if(v||b||x){v&&R(e.element,"height",v),b&&R(e.element,"min-height",`${b}px`),x&&R(e.element,"max-height",`${x}px`);let C=this.getProp(t,"margin-top"),y=this.getProp(t,"margin-bottom");if(l.isInTopRow){let k=c.borderBoxHeight.evaluate(t)+c.marginBottom.evaluate(t);R(e.element,"bottom",`${k}px`),(C===w.auto||y!==w.auto)&&R(e.element,"margin-top","auto"),y===w.auto&&R(e.element,"margin-bottom","auto")}else l.isInBottomRow&&(R(e.element,"bottom","0"),(y===w.auto||C!==w.auto)&&R(e.element,"margin-bottom","auto"),C===w.auto&&R(e.element,"margin-top","auto"))}}},DC=class{constructor(t,e,i,n,r){u(this,"pageScope",e),u(this,"rootPageBoxInstance",i),u(this,"context",n),u(this,"docElementStyle",r),u(this,"pageMasterCache",{}),u(this,"pageCascadeInstance"),this.pageCascadeInstance=t,this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,i=e.isVersoFirstPage,n=new Qe(t,"page-number"),r=new rh(t,new Sd(t,n,new it(t,2)),i?t.one:t.zero);t.defineName("recto-page",new Ri(t,r)),t.defineName("verso-page",r),(e.pageProgression||Jg(this.docElementStyle))==="ltr"?(t.defineName("left-page",r),t.defineName("right-page",new Ri(t,r))):(t.defineName("left-page",new Ri(t,r)),t.defineName("right-page",r))}getCascadedPageStyle(t){let e={};return this.pageCascadeInstance.pushRule([],t,e),this.pageCascadeInstance.popRule(),e}getPageRulePageMaster(t,e){let i=t.pageBox;if(Object.keys(e).length===0)return i.resetScope(),t;let n=this.makeCacheKey(e,i),r=this.pageMasterCache[n];return r||(i.pseudoName===Uh?r=this.generatePageRuleMaster(e):r=this.generateCascadedPageMaster(e,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(t,e){var i;let n=this.makeCascadeValueObjectKey(t),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${e.key}^${n}^${r}`}makeCascadeValueObjectKey(t){let e=[];for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i],r;n instanceof X?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),e.push(i+r+(n.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let e=new em(this.pageScope,this.rootPageBoxInstance.pageBox,t).createInstance(this.rootPageBoxInstance,this.context,this.docElementStyle);return e.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),e.resolveAutoSizing(this.context),e}generateCascadedPageMaster(t,e){let i=e.clone({pseudoName:jh}),n=i.specified,r=t.size;if(r&&!Z(r.value)){let s=js(t),a=r.priority;ei(n,"width",new X(s.width,a),this.context),ei(n,"height",new X(s.height,a),this.context)}["counter-reset","counter-increment"].forEach(s=>{n[s]&&(t[s]=n[s])});let o=i.createInstance(this.rootPageBoxInstance,this.context,this.docElementStyle);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},zC=class extends Te{constructor(t){super(),u(this,"pageType",t)}matches(t){return t.instance.currentPageType===this.pageType}getPriority(){return 3}primarySlot(t){return{table:t.pagetypes,key:this.pageType}}},VC=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return new Qe(this.scope,"page-number").evaluate(t.instance.context)===1}getPriority(){return 2}},$C=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return!!new Qe(this.scope,"blank-page").evaluate(t.instance.context)}getPriority(){return 2}},HC=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return!!new Qe(this.scope,"left-page").evaluate(t.instance.context)}getPriority(){return 1}},UC=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return!!new Qe(this.scope,"right-page").evaluate(t.instance.context)}getPriority(){return 1}},WC=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return!!new Qe(this.scope,"recto-page").evaluate(t.instance.context)}getPriority(){return 1}},GC=class extends Te{constructor(t){super(),u(this,"scope",t)}matches(t){return!!new Qe(this.scope,"verso-page").evaluate(t.instance.context)}getPriority(){return 1}},jC=class extends fn{constructor(t,e,i){super(e,i),u(this,"scope",t),u(this,"a",e),u(this,"b",i)}matches(t){let e=t.instance.context,i=e.layoutPositionAtPageStart.page;return e.blankPageAtStart&&i--,!!i&&this.matchANPlusB(i)}getPriority(){return 2}},XC=class extends fn{constructor(t,e,i,n){super(e,i),u(this,"scope",t),u(this,"a",e),u(this,"b",i),u(this,"pageType",n)}matches(t){let e=t.instance.pageTypePageIndices[this.pageType];if(!e)return!1;for(let i of e)if(this.matchANPlusB(i))return!0;return!1}getPriority(){return 3}},qC=class extends Fh{constructor(t,e){super(t,e,null,null,null)}apply(t){YC(t.instance.context,t.currentStyle,this.style,this.specificity,t)}};function YC(t,e,i,n,r){zs(t,e,i,n,null,null,null,r.instance.mergeValidatorSet);let o=i[eo];if(o){let a=li(e,eo);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),zs(t,l,o[h],n,null,null,null,r.instance.mergeValidatorSet)}}let s=i[Xs];if(s){let a=li(e,Xs);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let c=s[h];for(let p in c)if(c.hasOwnProperty(p)&&p!=="_pseudos"){let f=c[p];f instanceof X&&ei(l,p,f)}let d=lt(c,"_pseudos");if(d){let p=li(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=d[f];for(let v in m)if(m.hasOwnProperty(v)){let b=m[v];b instanceof X&&ei(g,v,b)}}}}}}var ZC=class extends $s{constructor(t,e,i,n,r,o){super(t,e,i?.condition,i,null,n,o),u(this,"pageProps",r),u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(t,e){this.currentNamedPageSelector=e,e&&(this.chain.push(new zC(e)),this.specificity+=65536)}pseudoclassSelector(t,e){if(t=t.toLowerCase(),e)switch(t){case"nth":{let i=e[0],n=e[1];if(e.length===3&&typeof e[2]=="string"){let r=e[2];this.currentPseudoPageClassSelectors.push(`:${t}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new XC(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${t}(${i}n${n<0?n:"+"+n})`),this.chain.push(new jC(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${t}(${e.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${t}`),t){case"first":this.chain.push(new VC(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new $C(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new HC(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new UC(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new WC(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new GC(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${t}`);break}}finishSelector(){let t;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?t=null:t=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:t,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(t,e,i){if((t==="bleed"||t==="marks")&&!this.currentPageSelectors.some(o=>o.selectors===null))return;super.simpleProperty(t,e,i);let n=ge(this.elementStyle,t),r=this.pageProps;if(t==="bleed"||t==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(o=>{Bi(r[o],t,n)});else if(t==="size"){let o=r[""];this.currentPageSelectors.forEach(s=>{let a=n.increaseSpecificity(s.specificity),h=s.selectors?s.selectors.join(""):"",l=r[h];l?ei(l,t,a):(l=r[h]={},Bi(l,t,a),o&&["bleed","marks"].forEach(c=>{o[c]&&Bi(l,c,o[c])}))})}}insertNonPrimary(t){this.cascade.insertInTable(this.cascade.pagetypes,"*",t)}makeApplyRuleAction(t){return new qC(this.elementStyle,t)}startFootnoteRule(t){let e=li(this.elementStyle,Xs),i=e.area;if(i||(i={},e.area=i),t){let n=li(i,"_pseudos"),r=n[t];r||(r={},n[t]=r),i=r}this.owner.delegateTo(n=>new im(this.scope,this.owner,this.validatorSet,i,n,this.layer))}startPageMarginBoxRule(t){let e=li(this.elementStyle,eo),i=e[t];i||(i={},e[t]=i),this.owner.delegateTo(n=>new KC(this.scope,this.owner,this.validatorSet,i,n,this.layer))}},KC=class extends Jn{constructor(t,e,i,n,r,o=null){super(t,e,r),u(this,"validatorSet",i),u(this,"boxStyle",n),u(this,"layer",o),u(this,"ruleId",mo())}property(t,e,i){this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}invalidPropertyValue(t,e){this.report(`E_INVALID_PROPERTY_VALUE ${t}: ${e.toString()}`)}unknownProperty(t,e){this.report(`E_INVALID_PROPERTY ${t}: ${e.toString()}`)}simpleProperty(t,e,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();yo(t,e,this.validatorSet);let r=new X(e,n,this.layer,this.ruleId);Bi(this.boxStyle,t,r)}},im=class extends Jn{constructor(t,e,i,n,r,o=null){super(t,e,r),u(this,"validatorSet",i),u(this,"areaStyle",n),u(this,"layer",o),u(this,"ruleId",mo())}property(t,e,i){this.validatorSet.validatePropertyAndHandleShorthand(t,e,i,this.scope,this)}invalidPropertyValue(t,e){this.report(`E_INVALID_PROPERTY_VALUE ${t}: ${e.toString()}`)}unknownProperty(t,e){this.report(`E_INVALID_PROPERTY ${t}: ${e.toString()}`)}simpleProperty(t,e,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();yo(t,e,this.validatorSet);let r=new X(e,n,this.layer,this.ruleId);Bi(this.areaStyle,t,r)}},nm=class{constructor(t,e,i){u(this,"store",t),u(this,"url",e),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",null),this.root=Zm(i);let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let s=o;if(s.namespaceURI=="http://www.w3.org/1999/xhtml")switch(s.localName){case"head":r=s;break;case"body":n=s;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(jt,"0")}doc(){return new om([this.document])}getElementOffset(t){let e=t.getAttribute(jt);if(e)return parseInt(e,10);let i=this.lastOffset,n=this.last;for(;n!=t;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(jt,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=t,i-1}getNodeOffset(t,e,i){let n=0,r=t,o=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=e,o=r.previousSibling,!o)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=o}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,o=r.previousSibling,!o){r=r.parentNode;break}r=o}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(t){let e,i=this.root;for(;;){if(e=this.getElementOffset(i),e>=t)return i;let a=i.children;if(!a)break;let h=yi(a.length,l=>{let c=a[l];return this.getElementOffset(c)>t});if(h==0)break;i=a[h-1]}let n=e+1,r=i,o=r.firstChild||r.nextSibling,s=null;for(;;){if(o){if(o.nodeType==1||(r=o,s=r,n+=o.textContent.length,n>t&&!/^\s*$/.test(o.textContent)))break}else if(r=r.parentNode,!r)break;o=r.nextSibling}return o&&s&&/^\s*$/.test(s.textContent)&&(s=o),s||i}buildIdMap(t){let e=t.getAttribute("id");e&&!this.idMap[e]&&(this.idMap[e]=t);let i=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=t);for(let n=t.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(t){var e;let i=t.match(/([^#]*)#(.+)$/);if(!i||i[1]&&i[1]!=this.url&&((e=this.store)==null?void 0:e.get(i[1]))!==this)return null;let n=i[2],r=this.document.getElementById(n);return!r&&this.document.getElementsByName&&(r=this.document.getElementsByName(n)[0]),r||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),r=this.idMap[n]),r}},Ul=(t=>(t.TEXT_HTML="text/html",t.TEXT_XML="text/xml",t.APPLICATION_XML="application/xml",t.APPLICATION_XHTML_XML="application/xhtml+xml",t.IMAGE_SVG_XML="image/svg+xml",t))(Ul||{});function Wo(t,e,i){let n=i||new DOMParser,r;try{r=n.parseFromString(t,e)}catch{}return!r||e!=="text/html"&&r.querySelector("parsererror")?null:r}function JC(t){let e=t.contentType;if(e){let n=Object.keys(Ul);for(let r=0;r<n.length;r++)if(Ul[n[r]]===e)return e;if(e.match(/\+xml$/))return"application/xml"}let i=t.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 rm(t,e){let i=t.responseXML;if(!i){let r=new DOMParser,o=t.responseText;if(o!=null){let s=JC(t);if(i=Wo(o,s||"application/xml",r),i&&!s){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Wo(o,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Wo(o,"image/svg+xml",r))}i||(i=Wo(o,"text/html",r))}}let n=i?new nm(e,t.url,i):null;return F(n)}function QC(){return new lh(rm,"document")}var ek=class Wl{constructor(e){u(this,"fn",e)}check(e){return this.fn(e)}withAttribute(e,i){return new Wl(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(e)==i)}withChild(e,i){return new Wl(n=>{if(!this.check(n))return!1;let r=new om([n]);return r=r.child(e),i&&(r=r.predicate(i)),r.size()>0})}},Bc=new ek(t=>!0),om=class Gl{constructor(e){u(this,"nodes",e)}asArray(){return this.nodes}size(){return this.nodes.length}predicate(e){let i=[];for(let n of this.nodes)e.check(n)&&i.push(n);return new Gl(i)}forEachNode(e){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)e(this.nodes[r],n);return new Gl(i)}forEach(e){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(e(this.nodes[n]));return i}forEachNonNull(e){let i=[];for(let n=0;n<this.nodes.length;n++){let r=e(this.nodes[n]);r!=null&&i.push(r)}return i}child(e){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==e&&n(r)})}childElements(){return this.forEachNode((e,i)=>{for(let n=e.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(e){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(e):null)}textContent(){return this.forEach(e=>e.textContent)}};function tk(t){return[...t].sort(Vi)}var ik=class extends hs{constructor(t,e,i,n,r,o,s,a){super(t,e,null,i,n,s,"counter-style",a),u(this,"counterStyleName",r),u(this,"counterStyles",o)}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle,{priority:this.getBaseSpecificity(),layer:this.layer})||Y.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},nk=class{constructor(t,e,i,n,r,o,s,a,h,l,c){u(this,"store",t),u(this,"rootScope",e),u(this,"pageScope",i),u(this,"cascade",n),u(this,"rootBox",r),u(this,"fontFaces",o),u(this,"footnoteProps",s),u(this,"flowProps",a),u(this,"viewportProps",h),u(this,"pageProps",l),u(this,"counterStyleStore",c),u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=t.fontDeobfuscator,this.validatorSet=t.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 be(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.getCurrentPageNumberForPageScope()},"page-number")),this.pageScope.defineName("blank-page",new be(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(t,e,i,n){if(this.viewportProps.length){let r=new Ya(this.rootScope,t,e,i,i*Ql.lineHeight),o=G0(r,this.viewportProps),s=o.width,a=o.height,h=o["text-zoom"],l=1;if(s&&a||h){let c=vi.em;if((h?h.evaluate(r,"text-zoom"):null)===w.scale&&(l=c/i,i=c,t*=l,e*=l),s&&a){let d=ct(s.evaluate(r,"width"),r),p=ct(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:t,height:e,fontSize:i}}};function Mc(t){let e=new Map,i=n=>{n.formattingContext&&!e.has(n.formattingContext)&&e.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in t.flowPositions){let r=t.flowPositions[n];for(let o of r.positions){let s=o.chunkPosition.primary;for(let a of s.steps)i(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let h of a.steps)i(h)}}return e}function _c(t){for(let[e,i]of t)i!==void 0&&e.restoreState(i)}var Xh=class sm extends Ya{constructor(e,i,n,r,o,s,a,h,l,c,d,p,f,g,m,v,b){super(e.rootScope,r.width,r.height,r.fontSize,r.fontSize*f.lineHeight),u(this,"style",e),u(this,"xmldoc",i),u(this,"viewport",r),u(this,"clientLayout",o),u(this,"fontMapper",s),u(this,"customRenderer",a),u(this,"fallbackMap",h),u(this,"pageNumberOffset",l),u(this,"documentURLTransformer",c),u(this,"counterStore",d),u(this,"cmykStore",p),u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance"),u(this,"styler"),u(this,"stylerMap"),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"),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=i.lang||n,this.faces=new ZS(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=Hu.createRoot(),this.pageProgression=v||null,this.isVersoFirstPage=!!b;for(let L in e.flowProps){let I=e.flowProps[L],D=ge(I,"flow-consume");D&&(D.evaluate(this,"flow-consume")==w.all?this.primaryFlows[L]=!0:delete this.primaryFlows[L])}this.pref=f,this.pubTitle=g,this.docTitle=m;let x=this.counterStore.createCounterListener(this.xmldoc.url),C=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Sc(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,x,C,this.style.counterStyleStore,this.cmykStore,this.style.validatorSet),C.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let y=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=Jg(y)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let k=this.style.rootBox;this.rootPageBoxInstance=new bC(k);let S=this.style.cascade.createInstance(this,x,C,this.lang,this.style.counterStyleStore,this.cmykStore,this.xmldoc.root,this.style.rootScope,this.style.validatorSet,this.styler.styles,this.style.validatorSet);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(S,y),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new DC(S,this.style.pageScope,this.rootPageBoxInstance,this,y);let N=this.style.pageProps;N[""]||(N[""]={}),Object.keys(N).forEach(L=>{let I=N[L];this.styler.cascade.applyVarFilter([I],null),Xn(I,!0)&&this.styler.cascade.applyVarFilter([I],null),this.styler.cascade.applyCalcFilter(I,this.styler.context),this.styler.cascade.applyCmykFilter(I);let D=Lc(js(I),this);this.pageSheetSize[L]={width:D.pageWidth+D.cropOffset*2,height:D.pageHeight+D.cropOffset*2}})}static create(e,i,n,r,o,s,a,h,l,c,d,p,f,g,m,v,b){let x=new sm(e,i,n,r,o,s,a,h,l,c,d,p,f,g,m,v,b),C=V("StyleInstance.create");return x.loadFontsAndScripts().then(()=>{C.finish(x)}),C.result()}loadFontsAndScripts(){let e=V("StyleInstance.loadFontsAndScripts"),i=[];for(let n of this.style.fontFaces){if(n.condition&&!n.condition.evaluate(this))continue;let r=YS(n.properties,this),o=new Vg(r);i.push(o)}return this.fontMapper.findOrLoadFonts(i,this.faces).then(()=>{tC(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)}),e.result()}matchStartPageSide(e){let i=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),n=this.pageProgression=="ltr";switch(e){case"left":return i!==n;case"right":return i===n;case"recto":return i;case"verso":return!i;default:return!0}}getStylerForDoc(e){let i=this.stylerMap[e.url];if(!i){let n=this.style.store.getStyleForDoc(e),r=new Ya(n.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize,this.initialFontSize*Ql.lineHeight),o=this.counterStore.createCounterListener(e.url),s=this.counterStore.createCounterResolver(e.url,n.rootScope,n.pageScope);i=new Sc(e,n.cascade,n.rootScope,r,this.primaryFlows,n.validatorSet,o,s,n.counterStyleStore,this.cmykStore,null),this.stylerMap[e.url]=i}return i}registerInstance(e,i){this.pageBoxInstances[e]=i}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,i){let n=this.currentLayoutPosition;if(n){n.flows[e.flowName]?i=n.flows[e.flowName]:n.flows[e.flowName]=i;let r=n.flowPositions[e.flowName];r||(r=new Vw,n.flowPositions[e.flowName]=r);let o=Aw(e.element),s=new zi(o),a=new zw(s,e);r.positions.push(a)}}evalSupportsTest(e,i,n){if(n)return e==="selector"?this.evalSupportsSelector(i):!1;if(!e)return!1;if(ze(e))return typeof CSS<"u"&&CSS.supports(`(${e}:${i})`);let r=!0;class o{unknownProperty(l,c){r=!1}invalidPropertyValue(l,c){r=!1}simpleProperty(l,c,d){}}let s=new o,a=Mi(this.style.rootScope,new xt(i,null),"");return a?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,a,!1,this.style.rootScope,s),r):!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 i extends am{errorMsg(...a){}}let n=new i(null),r=Kd(e),o=new xt(r+"{}",n);return new uo(Ue,o,n,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!n.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let i=Number.POSITIVE_INFINITY;for(let n=0;n<e.positions.length;n++){let r=e.positions[n].chunkPosition.primary,o=r.steps[0].node,s=r.offsetInNode,a=r.after,h=0;for(;o.ownerDocument!=this.xmldoc.document;)h++,o=r.steps[h].node,a=!1,s=0;let l=this.xmldoc.getNodeOffset(o,s,a);l<i&&(i=l)}return i}getNodePositionOffset(e){let i=e.steps[0].node,n=e.offsetInNode,r=e.after,o=0;for(;i.ownerDocument!=this.xmldoc.document;)o++,i=e.steps[o].node,r=!1,n=0;return this.xmldoc.getNodeOffset(i,n,r)}getPageStartOffset(e,i){if(!e)return 0;let n=Number.POSITIVE_INFINITY;for(let r in this.primaryFlows){let o=e.flowPositions[r];if(!i&&(!o||o.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(r),o=this.currentLayoutPosition.flowPositions[r],e!=this.currentLayoutPosition&&o&&(o=o.clone(),e.flowPositions[r]=o)),o)for(let s=0;s<o.positions.length;s++){let a=o.positions[s].chunkPosition.primary,h=this.getNodePositionOffset(a);h<n&&(n=h)}}return n}getPageStartCounterOffsets(e){var i;let n=this.getPageStartOffset(e);if(!isFinite(n))return{counterOffset:n,changeOffset:n};let r=this.xmldoc.body||this.xmldoc.root,o=r?this.getFirstInFlowElementAtOrAfter(r,n):null,s=r?this.xmldoc.getElementOffset(r):n,a=n<=s,h=o===r&&a&&(i=this.getFirstInFlowChildElement(r))!=null?i:o;if(!h)return a?{counterOffset:s,changeOffset:s}:{counterOffset:n,changeOffset:n};let l=this.xmldoc.getElementOffset(h),c=n;return a&&l!==n&&(c=l),l===n&&(this.isInlineLevelElement(h)?c=Math.max(0,n-1):c=this.getDeepestFirstInFlowChildOffset(h)),{counterOffset:c,changeOffset:l}}getPageStartElement(e,i=this.getPageStartOffset(e)){var n;if(!isFinite(i))return null;let r=this.xmldoc.body||this.xmldoc.root;if(!r)return null;let o=this.getFirstInFlowElementAtOrAfter(r,i),s=this.xmldoc.getElementOffset(r),a=i<=s;if(o===r&&a)return(n=this.getFirstInFlowChildElement(r))!=null?n:o;if((o?this.xmldoc.getElementOffset(o):Number.POSITIVE_INFINITY)>i){let h=this.xmldoc.getNodeByOffset(i);if(!Ee(h)){let l=h.nodeType===Node.ELEMENT_NODE?h:h.parentElement;for(;l;){if(this.xmldoc.getElementOffset(l)<=i&&this.isPageBoundaryCandidateElement(l))return l;l=l.parentElement}}}return o}isForcedPageBreakValue(e){return Ye(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let i=ge(e,"break-before");if(!i)return!1;let n=i.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(n)}getExplicitPageType(e){let i=ge(e,"page");if(!i||Z(i.value))return null;let n=i.evaluate(this,"page").toString();return!n||n.toLowerCase()==="auto"?null:n}getPageGroupPageType(e){if(this.isInlineLevelElement(e))return null;let i=this.styler.getStyle(e,!1);return i?this.getExplicitPageType(i):null}getPageStartPageType(e){let i=this.getPageStartOffset(e,!0),n=this.getPageStartElement(e,i);for(;n;){let r=this.getPageGroupPageType(n);if(r)return r;if(n===this.xmldoc.root)break;n=n.parentElement}return""}getPageStartPageTypeOverride(e){if(this.getPageStartPageType(e)!=="")return;let i=this.getPageStartOffset(e,!0),n=this.getPageStartElement(e,i);if(n&&this.xmldoc.getElementOffset(n)<i)return"";for(;n&&(n=this.getFirstInFlowChildElement(n),!!n);){let r=this.getPageGroupPageType(n);if(r)return r}return""}getPreviousInFlowSibling(e){let i=e.previousElementSibling;for(;i;){if(this.isPageBoundaryCandidateElement(i))return i;i=i.previousElementSibling}return null}getFirstDocumentFlowElement(){var e;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.xmldoc.getElementOffset(i),r=this.getFirstInFlowElementAtOrAfter(i,n);return r===i&&(e=this.getFirstInFlowChildElement(i))!=null?e:r}getEffectiveFirstPageType(e){let i=e,n=i?this.getPageGroupPageType(i):null;for(;i;){let r=this.getFirstInFlowChildElement(i);if(!r)return n;let o=this.getPageGroupPageType(r);o&&(n=o),i=r}return n}getEffectivePageGroupStartElement(e){let i=e,n=e;for(;n;){let r=this.getFirstInFlowChildElement(n);if(!r)return i;this.getPageGroupPageType(r)&&(i=r),n=r}return i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return this.getEffectiveFirstPageType(e)}shouldStartPageGroup(e,i,n){let r=this.styler.getStyle(e,!1);if(!r)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let o=this.xmldoc.getElementOffset(e),s=this.xmldoc.body||this.xmldoc.root,a=this.xmldoc.getElementOffset(s);if(n<=a&&e===s||!this.getPreviousInFlowSibling(e)&&n===o)return!0;if(o!==n)return!1;if(this.hasForcedPageBreakBefore(r))return!0;let h=this.getPreviousInFlowSibling(e);if(!h)return!1;let l=this.styler.getStyle(h,!1);return l?this.getExplicitPageType(l)!==i:!1}updatePageGroupPageIndices(e){let i=this.pageManager.pageCascadeInstance;i.pageTypePageIndices=Object.create(null);let n=e?.startSideOfFlow("body")||null,r=e?.flowPositions.body,o=!!(r&&r.positions.length),s=!!n&&un(n)&&!this.matchPageSide(n)&&!o,a=!(this.blankPageAtStart&&(!e||e.page===1))&&!(e!=null&&e.isBlankPage)&&!s,h=this.getPageStartOffset(e),l=this.getPageStartElement(e,h);if(!l)return;let c=this.getEffectivePageGroupStartElement(l),d=c===l?h:this.xmldoc.getElementOffset(c),p=c.ownerDocument,f=this.currentPageGroupDocument!==p&&a;f&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=p);let g=c;for(;g;){let m=this.getPageGroupPageType(g);if(m){let v=this.pageGroupPageCounts[m]||(this.pageGroupPageCounts[m]=new Map),b=v.get(g)||0;(b>0||a&&(f||this.shouldStartPageGroup(g,m,d)))&&(b+=1,v.set(g,b),(i.pageTypePageIndices[m]||(i.pageTypePageIndices[m]=[])).push(b))}if(g===this.xmldoc.root)break;g=g.parentElement}}preparePageGroupPageIndicesForRerender(e,i){this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=null;for(let n=0;n<i;n++){let r=e[n]||null;this.updatePageGroupPageIndices(r)}}getFirstInFlowElementAtOrAfter(e,i){if(this.isPageBoundaryCandidateElement(e)&&this.xmldoc.getElementOffset(e)>=i)return e;let n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{let o=r;return this.isNormalFlowElement(o)?this.isInlineLevelElement(o)||this.xmldoc.getElementOffset(o)<i?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return n??null}getDeepestFirstInFlowChildOffset(e){let i=e;for(;;){let n=this.getFirstInFlowChildElement(i);if(!n)return this.xmldoc.getElementOffset(i);i=n}}getFirstInFlowChildElement(e){let i=e.firstChild;for(;i;){if(i.nodeType===Node.TEXT_NODE){if(!Ee(i))return null;i=i.nextSibling;continue}if(i.nodeType!==Node.ELEMENT_NODE){i=i.nextSibling;continue}let n=i;if(this.isNormalFlowElement(n))return this.isInlineLevelElement(n)?null:n;i=i.nextSibling}return null}isPageBoundaryCandidateElement(e){return this.isNormalFlowElement(e)&&!this.isInlineLevelElement(e)}isNormalFlowElement(e){var i,n;let r=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===w.none)return!1;let o=(i=r?.position)==null?void 0:i.evaluate(this.styler.context,"position"),s=o&&!Z(o)?o:w.static;if(Nr(s)||Ur(s))return!1;let a=(n=r?.float)==null?void 0:n.evaluate(this.styler.context,"float");return(a&&!Z(a)?a:w.none)===w.none}isInlineLevelElement(e){return Wt(this.getDisplayValue(e))}getDisplayValue(e){var i;let n=this.styler.getStyle(e,!1),r=(i=n?.display)==null?void 0:i.evaluate(this.styler.context,"display");return r&&!Z(r)?r:w.inline}getPosition(e,i){if(!e)return 0;let n=Number.POSITIVE_INFINITY;for(let r in this.primaryFlows){let o=e.flowPositions[r];if(!i&&(!o||o.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(r),o=this.currentLayoutPosition.flowPositions[r],e!=this.currentLayoutPosition&&o&&(o=o.clone(),e.flowPositions[r]=o)),o){let s=this.getConsumedOffset(o);s<n&&(n=s)}}return n}dumpLocation(e){Y.debug("Location - page",this.currentLayoutPosition.page),Y.debug(" current:",e),Y.debug(" lookup:",this.lookupOffset);for(let i in this.currentLayoutPosition.flowPositions){let n=this.currentLayoutPosition.flowPositions[i];for(let r of n.positions)Y.debug(" Chunk",`${i}:`,r.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Qe(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let i in e.flowPositions){let n=e.flowPositions[i];if(n&&n.positions.length>0){let r=n.positions[0].flowChunk;if(this.getConsumedOffset(n)===r.startOffset){let o=n.positions[0].flowChunk.breakBefore,s=n.startBreakType;n.startBreakType=Bu(nt(s,o))}}}}selectPageMaster(e){var i;let n=this.currentLayoutPosition,r=this.getPosition(n);if(r==Number.POSITIVE_INFINITY&&this.hasActiveRootPageFloatLayoutContext()&&(r=(i=n.highestSeenOffset)!=null?i:this.styler.getReachedOffset()),r==Number.POSITIVE_INFINITY)return null;let o=this.rootPageBoxInstance.children,s;for(let a=0;a<o.length;a++){if(s=o[a],s.pageBox.pseudoName===jh)continue;let h=1;s.pageBox.pseudoName===Uh&&!(this.actualPageWidth&&this.actualPageHeight)&&(h=1/0);let l=s.getProp(this,"utilization");l&&l.isNum()&&(h=l.num);let c=this.queryUnitSize("em",!1),d=this.pageWidth()*this.pageHeight(),p=Math.ceil(h*d/(c*c)),f=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(r,p),this.styler.cascade.currentPageType=f,this.updateStartSide(n),this.layoutPositionAtPageStart=n.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let g=s.getProp(this,"enabled");if(!g||g===w._true){if(n.page===1&&this.blankPageAtStart){s.style={};let m=e.size;e={},m&&(e.size=m)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let i=this.layoutPositionAtPageStart.flows,n=i[e.flowName].parentFlowName;if(n){let r=e.startOffset,o=i[n].forcedBreakOffsets;if(!o.length||r<o[0])return!1;let s=yi(o.length,c=>o[c]>r)-1,a=o[s],h=this.layoutPositionAtPageStart.flowPositions[n],l=this.getConsumedOffset(h);return a<l?!1:l<a?!0:!this.matchPageSide(h.startBreakType)}return!1}beginIsolatedRootPageFloatLayoutContext(e){let i=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=Hu.createRoot(),e&&this.rootPageFloatLayoutContext.addPageFloatLayoutContextAsPreviousSibling(e),i}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}hasOnlyDeferredPageFloats(e){return this.noMorePrimaryFlows(e)&&this.hasActiveRootPageFloatLayoutContext()}layoutDeferredPageFloats(e){let i=e.pageFloatLayoutContext,n=i.getDeferredPageFloatContinuations(),r=this.counterStore.currentPageCountersStack.length>0,o=l=>{var c,d;if(!r||l.floatReference!==Ne.PAGE)return!1;let p=((d=(c=this.layoutPositionAtPageStart)==null?void 0:c.flowPositions)==null?void 0:d.body)||null,f=p?this.getConsumedOffset(p):Number.NaN,g=isFinite(f)?f:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),m=this.xmldoc.getNodeOffset(l.nodePosition.steps[0].node,0,!1);return m!=null&&isFinite(g)&&m>g},s=V("layoutDeferredPageFloats"),a=!1,h=0;return s.loopWithFrame(l=>{if(h===n.length){l.breakLoop();return}let c=n[h++],d=c.float;if(o(d)){l.breakLoop();return}let p=new Wn().findByFloat(d),f=p.findPageFloatFragment(d,i);if(f&&f.hasFloat(d)){l.continueLoop();return}else if(i.isForbidden(d)||i.hasPrecedingFloatsDeferredToNext(d)){i.deferPageFloat(c),l.breakLoop();return}e.layoutPageFloatInner(c,p,null,f).then(g=>{if(!g){l.breakLoop();return}let m=i.parent.isInvalidated();if(m){l.breakLoop();return}else i.isInvalidated()&&!m&&(a=!0,i.validate());l.continueLoop()})}).then(()=>{a&&i.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,i){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let n;return i?(n=i.clone(),n.primary=e.lastAfterPosition):n=new zi(e.lastAfterPosition),n}else return null;else return null}flowRootFormattingContextFor(e){var i,n;return(n=(i=this.currentLayoutPosition.flows[e])==null?void 0:i.formattingContext)!=null?n:new ra(null)}layoutColumn(e,i){let n=this.currentLayoutPosition.flowPositions[i];if(!n||!this.matchPageSide(n.startBreakType))return n?this.layoutDeferredPageFloats(e):F(!0);this.primaryFlows[i]&&e.bands.length>0&&(e.forceNonfitting=!1);let r=V("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){r.finish(!0);return}let o=[],s=[],a=!0;r.loopWithFrame(h=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(i)){h.breakLoop();return}for(;n.positions.length-s.length>0;){let l=0;for(;s.includes(l);)l++;let c=n.positions[l];if(c.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(c.flowChunk))break;for(let f=l+1;f<n.positions.length;f++){if(s.includes(f))continue;let g=n.positions[f];if(g.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(g.flowChunk))break;g.flowChunk.isBetter(c.flowChunk)&&(c=g,l=f)}let d=c.flowChunk,p=!0;if(e.layout(c.chunkPosition,a,n.breakAfter).then(f=>{if(e.pageFloatLayoutContext.isInvalidated()){h.breakLoop();return}if(a=!1,c.flowChunk.repeated&&(f===null||d.exclusive)&&o.push(l),d.exclusive){s.push(l),h.breakLoop();return}else{let g=!!f||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,f);if(!f&&e.pageBreakType&&n.positions.length-s.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&m?(c.chunkPosition=m,n.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(l),(f||m)&&(c.chunkPosition=f||m,o.push(l)),n.startBreakType=Bu(e.pageBreakType)),g){h.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:h.continueLoop()}),p){p=!1;return}}h.breakLoop()}).then(()=>{var h;if(!e.pageFloatLayoutContext.isInvalidated()){n.positions=n.positions.filter((c,d)=>o.includes(d)||!s.includes(d)),n.breakAfter==="column"&&(n.breakAfter=null),e.saveDistanceToBlockEndFloats();let l=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(l),e.computedBlockSize===0){let c=e.pageFloatLayoutContext,d=c;for(;d;){let p=d.floatFragments.filter(f=>"isFootnote"in f.area&&f.area.isFootnote);if(p.length>0&&!d.ignoreFootnoteAreaMaxHeight&&p.some(f=>{let g=getComputedStyle(f.area.element),m=v=>v!==""&&v!=="none";return m(g.getPropertyValue("max-block-size"))||m(f.area.vertical?g.maxWidth:g.maxHeight)})){d.ignoreFootnoteAreaMaxHeight=!0;for(let f of p){c.removePageFloatFragment(f,!0);let g=(h=f.continuations[0])==null?void 0:h.float;g&&d.removeFloatDeferredToNext(g)}c.invalidate();break}d=d.parent}}}r.finish(!0)})}),r.result()}createLayoutConstraint(e){let i=this.currentLayoutPosition.page-1,n=this.counterStore.createLayoutConstraint(i);return new eS([n].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,i,n,r,o,s,a,h,l,c,d,p,f,g){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth||e.isAutoHeight:e.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,v=o.element,b=Oi.create(h,Ne.COLUMN,a,null,null,null),x=this.currentLayoutPosition.clone(),C=V("createAndLayoutColumn"),y;return C.loopWithFrame(k=>{let S=this.createLayoutConstraint(b);if(l>1){let N=this.viewport.document.createElement("div");R(N,"position","absolute"),v.appendChild(N);let L,I,D,J;if(o.vertical){let te=(o.rtl?l-s-1:s)*(d+c)+o.paddingTop,P=parseFloat(v.style.width);L=o.paddingLeft+P-o.width,D=o.width,I=te,J=d}else L=(o.rtl?l-s-1:s)*(d+c)+o.paddingLeft,D=d,I=o.paddingTop,J=o.height;R(N,"left",`${L}px`),R(N,"top",`${I}px`),y=new Us(N,f,this.clientLayout,S,b,{vertical:o.vertical,rtl:o.rtl,snapWidth:o.snapWidth,snapHeight:o.snapHeight,originX:i,originY:n,left:L,top:I,width:D,height:J,marginLeft:0,marginRight:0,marginTop:0,marginBottom:0,borderLeft:0,borderRight:0,borderTop:0,borderBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,paddingBottom:0,borderBoxSizing:!1},p,m?[]:r.concat(),this.flowRootFormattingContextFor(a)),y.isNonFirstColumn=s>0,y.forceNonfitting=g}else y=new Us(v,f,this.clientLayout,S,b,o,p,m?[]:r.concat(),this.flowRootFormattingContextFor(a)),y.isNonFirstColumn=!1;if((y.vertical?y.height:y.width)>=0){let N=y.pageFloatLayoutContext;this.layoutColumn(y,a).then(()=>{N.isInvalidated()||N.finish(),y.pageFloatLayoutContext.isInvalidated()&&!h.isInvalidated()?(y.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),y.element!==v&&v.removeChild(y.element),k.continueLoop()):k.breakLoop()})}else y.pageFloatLayoutContext.finish(),k.breakLoop()}).then(()=>{C.finish(y)}),C.result()}getRegionPageFloatLayoutContext(e,i,n,r){i instanceof Yn;let o=i.getProp(this,"writing-mode")||null,s=i.getProp(this,"direction")||null;return Oi.createWithContainer(n,e,Ne.REGION,r,null,o,s)}layoutFlowColumnsWithBalancing(e,i,n,r,o,s,a,h,l){let c=this.currentLayoutPosition.clone(),d=this.getRegionPageFloatLayoutContext(s,i,a,h),p=!0,f=()=>(this.currentLayoutPosition=c.clone(),this.layoutFlowColumns(e,i,n,r,o,s,d,a,h,l,p).thenAsync(g=>F(g?{columns:g,position:this.currentLayoutPosition}:null)));return f().thenAsync(g=>{if(!g)return F(null);if(l<=1)return F(g.columns);let m=i.getProp(this,"column-fill")||w.balance,v=this.currentLayoutPosition.flowPositions[h],b=HS(l,m,f,d,a,g.columns,v);return b?(p=!1,s.lock(),d.lock(),b.balanceColumns(g).thenAsync(x=>(s.unlock(),s.validate(),d.unlock(),this.currentLayoutPosition=x.position,F(x.columns)))):F(g.columns)})}layoutFlowColumns(e,i,n,r,o,s,a,h,l,c,d){let p=V("layoutFlowColumns"),f=this.currentLayoutPosition.clone(),g=Mc(this.currentLayoutPosition),m=i.getPropAsNumber(this,"column-gap"),v=c>1?i.getPropAsNumber(this,"column-width"):h.vertical?h.height:h.width,b=i.getActiveRegions(this),x=i.getProp(this,"shape-inside"),C=Xd(x,0,0,h.width,h.height,this),y=new dC(l,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),k=0,S=null,N=[];return p.loopWithFrame(L=>{this.createAndLayoutColumn(i,n,r,o,h,k++,l,a,c,m,v,C,y,d).then(I=>{if(s.isInvalidated()){N=null,L.breakLoop();return}if((I.pageBreakType&&I.pageBreakType!=="column"||k===c)&&!a.isInvalidated()&&a.finish(),a.isInvalidated()){k=0,this.currentLayoutPosition=f.clone(),_c(g),a.validate(),a.isLocked()?(N=null,L.breakLoop()):L.continueLoop();return}S=I,N[k-1]=S,S.pageBreakType&&S.pageBreakType!="column"&&(k=c,S.pageBreakType!="region"&&(this.pageBreaks[l]=!0)),k<c?L.continueLoop():L.breakLoop()})}).then(()=>{p.finish(N)}),p.result()}openPageBox(e,i,n,r,o,s){let a=i.getProp(this,"wrap-flow")===w.auto,h=i.getProp(this,"flow-from"),l=this.viewport.document.createElement("div");l.role=i instanceof tm?"complementary":"presentation";let c=i.getProp(this,"position");R(l,"position",c?c.name:"absolute");let d=i instanceof to;i instanceof Yn?n.appendChild(l):n.insertBefore(l,n.firstChild);let p=new Vp(l);return p.vertical=i.vertical,p.rtl=i.rtl,p.borderBoxSizing=i.borderBoxSizing,p.exclusions=s,i.prepareContainer(this,p,e,this.faces,this.clientLayout),(p.width<=0||p.height<=0)&&(i instanceof to||h&&h.isIdent())&&(this.invalidPageAreaOnCurrentPage=!0,Y.warn("Negative or zero page area size")),p.originX=r,p.originY=o,{boxContainer:l,container:p,offsetX:r+p.left+p.marginLeft+p.borderLeft,offsetY:o+p.top+p.marginTop+p.borderTop,flowName:h,dontExclude:a,forwardOrderInLayout:d,removed:!1}}layoutGeneratedContent(e,i,n,r){let o=n.boxContainer,s=[],a=i.getProp(this,"content");if(a instanceof j&&a.expr instanceof be&&a.expr.str.startsWith("running-element-"))a.visit(new Wr(o,this,a,this.counterStore.getExprContentListener()));else if(At(a)){let h="span";a instanceof et&&(h="img");let l=this.viewport.document.createElement(h);a.visit(new Wr(l,this,a,this.counterStore.getExprContentListener())),o.appendChild(l),h=="img"&&i.transferSingleUriContentProps(this,l,this.faces),i.transferContentProps(this,n.container,e,this.faces);let c=l.querySelectorAll("img[src]");for(let p=0;p<c.length;p++){let f=c[p],g=f.getAttribute("src");if(!g)continue;let m=Pt(f,g);s.push(m),e.fetchers.push(m)}let d=l.getAttribute("src");if(d){let p=l.querySelector("img");p||(p=l);let f=Pt(p,d);s.push(f),e.fetchers.push(f)}h=="span"&&jx(l,i.getProp(this,"text-autospace"),i.getProp(this,"text-spacing-trim"),i.getProp(this,"hanging-punctuation"),this.lang,i.vertical)}else i.suppressEmptyBoxGeneration&&(r.removeChild(o),n.removed=!0);return n.removed||i.finishContainer(this,n.container,e,null,1,this.clientLayout,this.faces),s.length?Hn(s).thenReturn(!0):F(!0)}layoutPageBoxContent(e,i,n,r,o,s){let a=n.boxContainer,h=n.flowName;if(!h||!h.isIdent())return this.layoutGeneratedContent(e,i,n,r);if(!this.pageBreaks[h.toString()]){let l=V("layoutPageBoxContent.inner"),c=h.toString(),d=i.getPropAsNumber(this,"column-count");return this.layoutFlowColumnsWithBalancing(e,i,n.offsetX,n.offsetY,o,s,n.container,c,d).then(p=>{if(!s.isInvalidated()){let f=p[0];f.element===a&&(n.container=f),n.container.computedBlockSize=Math.max.apply(null,p.map(m=>m.computedBlockSize)),i.finishContainer(this,n.container,e,f,d,this.clientLayout,this.faces);let g=this.currentLayoutPosition.flowPositions[c];g&&g.breakAfter==="region"&&(g.breakAfter=null)}l.finish(!0)}),l.result()}return s.isInvalidated()||i.finishContainer(this,n.container,e,null,1,this.clientLayout,this.faces),F(!0)}excludeOrRemovePageBox(e,i,n,r){if(!e.isAutoHeight||Math.floor(i.container.computedBlockSize)>0){if(!i.removed&&!i.dontExclude){let o=e.getProp(this,"shape-outside"),s=i.container.getOuterShape(o,this);r.push(s)}}else if(e.children.length==0)return n.removeChild(i.boxContainer),!1;return!0}layoutPageBoxChildren(e,i,n,r,o,s=null){let a=V("layoutPageBoxChildren"),h=n.forwardOrderInLayout,l=h?0:i.children.length-1;return a.loop(()=>{for(;l>=0&&l<i.children.length;){let c=i.children[h?l++:l--];if(c===s)continue;let d=this.layoutContainer(e,c,n.boxContainer,n.offsetX,n.offsetY,r,o);if(d.isPending())return d.thenAsync(()=>F(!o.isInvalidated()));if(o.isInvalidated())break}return F(!1)}).then(()=>{a.finish(!0)}),a.result()}layoutPageAreaEstablishingContainer(e,i,n,r,o,s,a){i.reset();let h=V("layoutPageAreaEstablishingContainer"),l=this.openPageBox(e,i,n,r,o,s),c=i.pageAreaEstablishingChild;if(c===null){let d=a.withContainer(l.container);return this.layoutPageBoxContent(e,i,l,n,s,d).then(()=>{if(d.isInvalidated()||!this.excludeOrRemovePageBox(i,l,n,s)){h.finish(d);return}this.layoutPageBoxChildren(e,i,l,s,d).then(()=>{h.finish(d)})}),h.result()}return this.layoutGeneratedContent(e,i,l,n).then(()=>{this.excludeOrRemovePageBox(i,l,n,s),this.layoutPageAreaEstablishingContainer(e,c,l.boxContainer,l.offsetX,l.offsetY,s,a).then(d=>{if(d.isInvalidated()){h.finish(d);return}this.layoutPageBoxChildren(e,i,l,s,d,c).then(()=>{h.finish(d)})})}),h.result()}layoutContainer(e,i,n,r,o,s,a){i.reset();let h=i.getProp(this,"enabled");if(h&&h!==w._true)return F(!0);let l=V("layoutContainer"),c=this.openPageBox(e,i,n,r,o,s);return this.layoutPageBoxContent(e,i,c,n,s,a).then(()=>{if(a.isInvalidated()){l.finish(!0);return}if(!this.excludeOrRemovePageBox(i,c,n,s)){l.finish(!0);return}this.layoutPageBoxChildren(e,i,c,s,a).then(()=>{l.finish(!0)})}),l.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let i in this.currentLayoutPosition.flowPositions){let n=this.currentLayoutPosition.flowPositions[i];for(let r=n.positions.length-1;r>=0;r--){let o=n.positions[r];o.flowChunk.startPage>=0&&o.flowChunk.startPage+o.flowChunk.linger-1<=e&&n.positions.splice(r,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let i in this.currentLayoutPosition.flowPositions){let n=this.currentLayoutPosition.flowPositions[i];for(let r=n.positions.length-1;r>=0;r--){let o=n.positions[r];o.flowChunk.startPage<0&&o.flowChunk.startOffset<this.lookupOffset&&(o.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let i in this.primaryFlows){let n=e.flowPositions[i];if(n&&n.positions.length>0)return!1}return!0}hasSameFlowPositions(e,i){if(e===i)return!0;if(!e||!i)return!1;let n=Object.keys(e.flowPositions),r=Object.keys(i.flowPositions);if(n.length!==r.length)return!1;for(let o of n)if(!e.flowPositions[o].isSamePosition(i.flowPositions[o]))return!1;return!0}checkRepeatedInvalidPageArea(e){let i=this.invalidPageAreaOnCurrentPage;if(this.invalidPageAreaOnCurrentPage=!1,!i){this.repeatedInvalidPageAreaLayoutPosition=null;return}if(e.isBlankPage||this.noMorePrimaryFlows(e))return;if(!this.hasSameFlowPositions(this.layoutPositionAtPageStart,e)){this.repeatedInvalidPageAreaLayoutPosition=null;return}let n=!!this.repeatedInvalidPageAreaLayoutPosition&&this.hasSameFlowPositions(this.repeatedInvalidPageAreaLayoutPosition,this.layoutPositionAtPageStart);if(this.repeatedInvalidPageAreaLayoutPosition=this.layoutPositionAtPageStart.clone(),n)throw new Error("Negative or zero page area size")}layoutNextPage(e,i){var n,r,o,s;let a=e.container===e.bleedBox;this.pageBreaks={},i?(this.currentLayoutPosition=i.clone(),this.styler.replayFlowElementsFromOffset(i.highestSeenOffset)):(this.currentLayoutPosition=new $w,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),this.invalidPageAreaOnCurrentPage=!1,i=this.currentLayoutPosition;let h=i.startSideOfFlow("body");i.isBlankPage=un(h)&&this.matchPageSide(h),e.isBlankPage=i.isBlankPage,i.page++;let l=this.hasOnlyDeferredPageFloats(i),c=l?void 0:this.getPageStartPageTypeOverride(i);if(c===""?e.pageType="":c&&(e.pageType=c),e.pageType==null){let y=i.page===1?this.resolveFirstPageType():null,k=(n=this.styler.cascade.currentPageType)!=null?n:this.styler.cascade.previousPageType,S=e.isBlankPage?this.styler.cascade.previousPageType:l?k:y??this.styler.cascade.currentPageType;if(e.pageType=S,!e.pageType){let N=this.getPageStartPageType(i);N&&(e.pageType=N)}e.pageType=(r=e.pageType)!=null?r:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType}this.updatePageGroupPageIndices(i),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=i.clone();let d=Mc(i),p=a?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=p,this.styler.cascade.applyVarFilter([p],null),Xn(p,!0)&&this.styler.cascade.applyVarFilter([p],null),this.styler.cascade.applyCalcFilter(p,this.styler.context),this.styler.cascade.applyCmykFilter(p),!a){let y=new Qe(this.style.pageScope,"left-page");e.side=y.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let f=this.selectPageMaster(p);if(!f)return F(null);let g=0;if(!a){e.setAutoPageWidth(f.pageBox.specified.width.value===so),e.setAutoPageHeight(f.pageBox.specified.height.value===ao);let{counterOffset:y,changeOffset:k}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(y)||(y=this.lookupOffset,k=this.lookupOffset),isFinite(y)&&this.styler.styleUntil(y,0);let S=this.styler.getCounterSnapshotAtOffset(y),N=k===y?S:this.styler.getCounterSnapshotAtOffset(k);S||(S=this.styler.getLastCounterSnapshot()),N||(N=S);let L=N&&N.offset===k?N:null;this.counterStore.setCurrentPageDocCounters((o=S?.counters)!=null?o:null,(s=L?.changes)!=null?s:null,L?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(p,this);let I=Lc(js(p),this);this.setPageSizeAndBleed(I,e),AC(p,I,e,this),g=I.bleedOffset+I.bleed}let m=!a&&f.getProp(this,"writing-mode")||w.horizontal_tb;this.pageVertical=m!=w.horizontal_tb;let v=f.getProp(this,"direction")||w.ltr,b=Oi.create(this.rootPageFloatLayoutContext,Ne.PAGE,null,null,m,v,null,e.side),x=V("layoutNextPage"),C=null;return x.loopWithFrame(y=>{this.layoutPageAreaEstablishingContainer(e,f,e.bleedBox,g,g,[],b).then(k=>{if(C=k,b.isInvalidated()||k.finish(),b.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),_c(d),b.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);y.continueLoop()}else y.breakLoop()})}).then(()=>{e.pageFloatLayoutContext=C,f.adjustPageLayout(this,e,this.clientLayout),a||(this.processLinger(),i=this.currentLayoutPosition,this.checkRepeatedInvalidPageArea(i),Object.keys(i.flowPositions).forEach(k=>{let S=i.flowPositions[k],N=S.breakAfter;N&&(N==="page"||!this.matchPageSide(N))&&(S.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,i.highestSeenOffset=this.styler.getReachedOffset();let y=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(y,this.clientLayout),this.noMorePrimaryFlows(i)&&!this.hasActiveRootPageFloatLayoutContext()&&(i=null),x.finish(i)}),x.result()}setPageSizeAndBleed(e,i){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,i.container.style.width=`${this.pageSheetWidth}px`,i.container.style.height=`${this.pageSheetHeight}px`,i.bleedBox.style.left=`${e.bleedOffset}px`,i.bleedBox.style.right=`${e.bleedOffset}px`,i.bleedBox.style.top=`${e.bleedOffset}px`,i.bleedBox.style.bottom=`${e.bleedOffset}px`,i.bleedBox.style.padding=`${e.bleed}px`}},rk=class cs extends $s{constructor(e,i,n,r,o,s,a,h){super(n,i,o,s,a,r,h),u(this,"masterHandler",e),u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,i,n){let r=new Ug(this.masterHandler.pageScope,e,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity(),this.layer);this.owner.delegateTo(o=>new CC(r.scope,this.owner,r,this.validatorSet,o))}startWhenRule(e){let i=e.expr;this.condition!=null&&(i=Xt(this.scope,this.condition,i)),this.owner.delegateTo(n=>new cs(this.masterHandler,this.owner,this.scope,this.validatorSet,i,this,this.regionId,n))}startLayerRule(e){let i=this.cascade.registerLayer(this.flavor,this.layer,e);this.owner.delegateTo(n=>{let r=new cs(this.masterHandler,this.owner,this.scope,this.validatorSet,this.condition,this,this.regionId,n);return r.layer=i,r})}startDefineRule(){this.owner.delegateTo(e=>new Lx(this.scope,this.owner,e))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition,priority:this.getBaseSpecificity(),layer:this.layer}),this.owner.delegateTo(i=>new hs(this.scope,this.owner,null,e,this.masterHandler.validatorSet,i,"font-face",this.layer))}startCounterStyleRule(e){this.owner.delegateTo(i=>new ik(this.scope,this.owner,{},this.masterHandler.validatorSet,e,this.masterHandler.counterStyles,i,this.layer))}startFlowRule(e){let i=this.masterHandler.flowProps[e];i||(i={},this.masterHandler.flowProps[e]=i),this.owner.delegateTo(n=>new hs(this.scope,this.owner,null,i,this.masterHandler.validatorSet,n,void 0,this.layer))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.owner.delegateTo(i=>new hs(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet,i,void 0,this.layer))}startFootnoteRule(e){let i=this.masterHandler.footnoteProps;if(e){let n=li(i,"_pseudos");i=n[e],i||(i={},n[e]=i)}this.owner.delegateTo(n=>new im(this.scope,this.owner,this.masterHandler.validatorSet,i,n,this.layer))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){this.owner.delegateTo(e=>new ZC(this.masterHandler.pageScope,this.owner,this,this.validatorSet,this.masterHandler.pageProps,e)).startPageRule()}startRuleBody(){if($s.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",_(e)),this.endRule(),this.owner.delegateTo(i=>new cs(this.masterHandler,this.owner,this.scope,this.validatorSet,this.condition,this,e,i)).startRuleBody()}}},am=class extends iw{constructor(t){let e=new qa(null);super(e,i=>new rk(i,i,e,t,null,null,null,null)),u(this,"validatorSet",t),u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"counterStyles",new r0),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=e,this.pageScope=new qa(this.rootScope),this.rootBox=new mC(this.rootScope),this.cascadeParserHandler=this.initialSlave}};function Dc(t,e){return t.text!=null?{url:t.url?Ie(_n(t.url),an):t.url,text:t.text,flavor:e,classes:null,media:null}:{url:t.url?Ie(_n(t.url),an):t.url,flavor:e,classes:null,media:null}}function ok(t,e){return e.parseOPSResource(t)}var sk=class extends lh{constructor(t,e=null,i=null){super(ok,"document"),u(this,"fontDeobfuscator",t),u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",k0()),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1),this.setStyleSheets(e,i)}getStyleForDoc(t){return this.styleByDocURL[t.url]}getTriggersForDoc(t){return this.triggersByDocURL[t.url]}setStyleSheets(t,e){this.clearStyleSheets(),t&&t.forEach(this.addAuthorStyleSheet,this),e&&e.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(t){this.styleSheets.push(Dc(t,"Author"))}addUserStyleSheet(t){this.styleSheets.push(Dc(t,"User"))}parseOPSResource(t){let e=V("OPSDocStore.load"),i=t.url,n=Ys(i);return rm(t,this).then(r=>{var o;if(!r){e.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=zt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){Y.warn("Error during single document preprocessing:",g)}}let s=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),v=f.getAttribute("action"),b=f.getAttribute("ref");g&&m&&v&&b&&s.push({observer:g,event:m,action:v,ref:b})}this.triggersByDocURL[i]=s;let h=[];if(h.push({url:Ie("user-agent-base.css",Ei),text:dp,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-page.css",Ei),text:cp,flavor:"UA",classes:null,media:null}),h.push({url:Ie("user-agent-counter-styles.css",Ei),text:gp,flavor:"UA",classes:null,media:null}),n)h.push({url:Ie("user-agent-toc.css",Ei),text:pp,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let v=f.getAttribute("class"),b=f.getAttribute("media"),x=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:x?v:null,media:b})}else if(m=="link"){let v=f.getAttribute("href"),b=(o=f.getAttribute("rel"))==null?void 0:o.split(/\s+/),x=f.getAttribute("class"),C=f.getAttribute("media");if(v&&b!=null&&b.includes("stylesheet")&&(!b.includes("alternate")||x)){let y=Ie(v,i),k=f.getAttribute("title");h.push({url:y,text:null,classes:k?x:null,media:C,flavor:"Author"})}}else m=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,e.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new Qs(()=>{let p=V("fetchStylesheet"),f=0,g=new am(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!=null?xp(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Sp(m.url,g,m.classes,m.media)}return F(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();c=new nk(this,g.rootScope,g.pageScope,m,g.rootBox,tk(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,e.finish(r)})}),e.result()}processViewportMeta(t){return""}},zr="\u25B8",zc="\u25BE",ak="\u25B9";function qh(t){let e=Array.from(t.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(e.length>0||(e=Array.from(t.querySelectorAll("[role=doc-toc]")),e.length>0))return e;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of t.querySelectorAll(i)){if(e.find(o=>o.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&e.push(r)}return e}function lk(t){let e=qh(t),i=[];for(let n of e)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var hk=class{constructor(t,e,i,n,r,o,s,a,h,l,c){u(this,"store",t),u(this,"url",e),u(this,"lang",i),u(this,"clientLayout",n),u(this,"fontMapper",r),u(this,"rendererFactory",s),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=ud(o),this.pref.spreadView=!1}setAutoHeight(t,e){if(e--!=0){for(let i=t.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;Ni(n,"height","auto")!="auto"&&(R(n,"height","auto"),this.setAutoHeight(n,e)),Ni(n,"position","static")=="absolute"&&(R(n,"position","relative"),this.setAutoHeight(n,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(i,n,r)=>{let o=r.behavior;if(o)switch(o.toString()){case"toc-node-anchor":r.color=w.inherit,r["text-decoration"]=w.none;break;case"toc-node":r.display=w.block,r.margin=Oe,r.padding=Oe,r["padding-inline-start"]=new B(1.25,"em");break;case"toc-node-first-child":r.display=w.inline_block,r.margin=new B(.2,"em"),r["vertical-align"]=w.top,r.color=w.inherit,r["text-decoration"]=w.none;break;case"toc-container":r.padding=Oe;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return e(i,n,r);let s=i.firstChild;s&&s.nodeType!==1&&Ee(s)&&i.replaceChild(i.ownerDocument.createComment(s.textContent),s);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=zr&&(l.textContent=zr,R(l,"cursor","pointer"),l.addEventListener("click",uk,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),o.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=ak,R(l,"margin","0.2em 0 0 -1em"),R(l,"margin-inline-start","-1em"),R(l,"margin-inline-end","0"),R(l,"display","inline-block"),R(l,"width","1em"),R(l,"text-align","center"),R(l,"vertical-align","top"),R(l,"cursor","default"),R(l,"font-family","Menlo,sans-serif"),h.appendChild(l),R(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){R(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 F(h)}}showTOC(t,e,i,n,r){if(this.page)return F(this.page);let o=V("showTOC"),s=new Ip(t,t);this.page=s;let a=Ua(this.url);return this.store.load(a).then(h=>{for(let p of qh(h.document))p.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,r);e=new Gs(e.window,c.fontSize,0,t,c.width,c.height);let d=this.makeCustomRenderer(h);Xh.create(l,h,this.lang,e,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore,this.pref,null,null).then(p=>{this.instance=p,p.layoutNextPage(s,null).then(()=>{this.setAutoHeight(t,2),o.finish(s)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function t(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(e)}function e(n){let r=new URL(n.href),[,o]=r.hash.match(/^#?(.*)$/),s=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=t(a);return{id:o,title:s,children:h}}let i=this.page.container.querySelector("[role=tree]");return t(i)}};function uk(t){let e=t.target,i=e.textContent==zr;e.textContent=i?zc:zr;let n=e.parentNode;e.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let o=r,s=o.getAttribute("data-adapt-class");if(s==="toc-container"){if(o.setAttribute("aria-hidden",i?"false":"true"),o.firstChild){r=o.firstChild;continue}}else if(s==="toc-node"&&(o.style.height=i?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=i?0:-1),o.children.length>=3&&(o.children[0].tabIndex=i?0:-1,!i))){let a=o.children[0];if(a.textContent==zc){a.textContent=zr,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),r=o.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}t.stopPropagation()}function Go(t){let e={};return Object.keys(t).forEach(i=>{e[i]=Array.from(t[i])}),e}function ck(t){let e=Object.create(null);return Object.keys(t).forEach(i=>{e[i]=new Map(t[i])}),e}function dk(t){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(t)||/^(?:about:|data:|blob:)/i.test(ft(t))}function Vc(t){return t.split("/").map(encodeURIComponent).join("/")}var $c=class lm extends sk{constructor(e=null,i=null){super(null,e,i),u(this,"plainXMLStore"),u(this,"jsonStore"),u(this,"opfByURL",{}),u(this,"primaryOPFByEPubURL",{}),u(this,"deobfuscators",{}),u(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=QC(),this.jsonStore=Kv()}static create(e,i){let n=new lm(e,i);return n.triggerSingleDocumentPreprocessing=!0,F(n)}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,i,n){return this.plainXMLStore.load(e,i,n)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,i,n){return this.jsonStore.load(e,i,n)}loadWebPubManifest(e,i){this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),i.finish(null);return}Ji.fromWebPubManifest(this,e,n,void 0,e).then(r=>{i.finish(r)})})}loadPubDoc(e){let i=V("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(i)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,i):dk(e)?this.loadWebPub(e).then(n=>{if(n){i.finish(n);return}this.reportLoadError(e),i.finish(null)}):ea(e,void 0,"HEAD").then(n=>{if(n.status>=400)this.loadEPUBDoc(e).then(r=>{if(r){i.finish(r);return}Y.error(`Failed to fetch a source document from ${e} (${n.status}${n.statusText?" "+n.statusText:""})`),i.finish(null)});else if(!n.status&&!n.responseXML&&!n.responseText&&!n.responseBlob&&!n.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),n.contentType=="application/oebps-package+xml"){let[,r,o]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(r,o).thenFinish(i)}else n.contentType=="application/ld+json"||n.contentType=="application/webpub+json"||n.contentType=="application/audiobook+json"||n.contentType=="application/json"?this.loadWebPubManifest(e,i):this.loadWebPub(e).then(r=>{if(r){i.finish(r);return}this.loadEPUBDoc(e).then(o=>{if(o){i.finish(o);return}this.reportLoadError(e),i.finish(null)})})});return i.result()}loadEPUBDoc(e){let i=V("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let n=e+"META-INF/container.xml";return this.loadAsPlainXML(n).then(r=>{if(r){let o=r.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let s of o)if(s){this.loadOPF(e,s).thenFinish(i);return}}i.finish(null)}),i.result()}loadOPF(e,i){let n=e+i,r=this.opfByURL[n];if(r)return F(r);let o=V("loadOPF");return this.loadAsPlainXML(n,!0,`Failed to fetch EPUB OPF ${n}`).then(s=>{if(!s)this.reportLoadError(n);else{let a=h=>{this.opfByURL[n]=h,this.primaryOPFByEPubURL[e]=h,o.finish(h)};this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(h=>{a(Ji.fromXMLDoc(this,e,s,h))}):a(Ji.fromXMLDoc(this,e,s,null))}}),o.result()}loadWebPub(e){let i=V("loadWebPub");return this.load(e).then(n=>{if(!n)this.reportLoadError(e),i.finish(null);else if(n.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))i.finish(null);else{let r=n.document,o=r.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(o){let s=o.getAttribute("href");if(/^#/.test(s)){let a=Yl(r.getElementById(s.substr(1)).textContent);Ji.fromWebPubManifest(this,e,a,r).then(h=>{i.finish(h)})}else{let a=Ie(o.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{Ji.fromWebPubManifest(this,e,h,r,a).then(l=>{i.finish(l)})})}}else Ji.fromWebPubManifest(this,e,{},r).then(s=>{s.toc&&s.toc.src===n.url&&qh(r).length===0&&(s.toc=null),i.finish(s)})}}),i.result()}addDocument(e,i){let n=V("EPUBDocStore.load"),r=ft(e);return(this.documents[r]=this.parseOPSResource({status:200,statusText:"",url:r,contentType:i.contentType,responseText:null,responseXML:i,responseBlob:null})).thenFinish(n),n.result()}reportLoadError(e){let i=r=>r.replace(/([^:/?#]|^)[/?#].*/,"$1"),n=()=>{let r=i(e);return!(r===i(an)||Object.keys(this.resources).find(o=>this.resources[o]&&i(o)===r)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?Y.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&an.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?Y.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):n()?Y.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):Y.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let i=ft(e),n=this.documents[i];if(n)return n.isPending()?n:F(n.get());{let r=V("EPUBDocStore.load");return n=super.load(i,!0,`Failed to fetch a source document from ${i}`),n.then(o=>{o?r.finish(o):this.reportLoadError(i)}),r.result()}}processViewportMeta(e){let i=e.getAttribute("content");if(!i)return"";let n={},r;for(;(r=i.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)i=i.substr(r[0].length),n[r[1]]=r[2];let o=n.width-0,s=n.height-0;if(o&&s){let a=!!Object.values(this.primaryOPFByEPubURL).find(h=>h.prePaginated);return`@-epubx-viewport{width:${o}px;height:${s}px;}`+(a?`@page{size:${o}px ${s}px;margin:0;}`:"@page{margin:0;}")}return""}},Hc=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=jm}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=Ie(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let i=t.getAttribute("properties");i&&(this.itemProperties=ty(i.split(/\s+/)))}initWithParam(t){this.spineIndex=t.index,this.id=`item${t.index+1}`,this.src=t.url,this.startPage=t.startPage,this.skipPagesBefore=t.skipPagesBefore}};function pk(t){return t.id}function fk(t){return e=>{let i=V("deobfuscator");return gk("SHA-1",t).then(n=>{let r=e.slice(0,1040),o=e.slice(1040,e.size);qv(r).then(s=>{let a=new DataView(s);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(mp([a,o]))})}),i.result()}}function gk(t,e){let i=V("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(t,new TextEncoder().encode(e)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var Ai={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"},kr="http://idpf.org/epub/vocab/package/meta/#",Xe={language:`${Ai.dcterms}language`,title:`${Ai.dcterms}title`,creator:`${Ai.dcterms}creator`,layout:`${Ai.rendition}layout`,titleType:`${kr}title-type`,displaySeq:`${kr}display-seq`,alternateScript:`${kr}alternate-script`,role:`${kr}role`};function mk(t,e){let i={};return(n,r)=>{var o,s,a,h,l,c;let d,p,f=n.r||i,g=r.r||i;if(t==Xe.title&&(d=((o=f[Xe.titleType])==null?void 0:o[0].v)=="main",p=((s=g[Xe.titleType])==null?void 0:s[0].v)=="main",d!=p))return d?-1:1;let m=parseInt((a=f[Xe.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let v=parseInt((h=g[Xe.displaySeq])==null?void 0:h[0].v,10);return isNaN(v)&&(v=Number.MAX_VALUE),m!=v?m-v:t!=Xe.language&&e&&(d=((l=f[Xe.language]||f[Xe.alternateScript])==null?void 0:l[0].v)==e,p=((c=g[Xe.language]||g[Xe.alternateScript])==null?void 0:c[0].v)==e,d!=p)?d?-1:1:n.o-r.o}}function yk(t,e){let i;if(!e)i=Ai;else{i={};for(let p in Ai)i[p]=Ai[p];let d;for(;(d=e.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)e=e.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]]:kr;if(f)return f+p[3]}}return null},r=1,o=t.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:Ai.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),s=xa(o,d=>d.refines),a=d=>iy(d,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let v=s[`#${g.id}`]||[];if(v.length||g.lang||g.role){g.lang&&v.push({name:Xe.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&v.push({name:Xe.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let b=xa(v,x=>x.name);m.r=a(b)}return m})),h=a(xa(o,d=>d.refines?null:d.name)),l=null;h[Xe.language]&&(l=h[Xe.language][0].v);let c=d=>{for(let p in d){let f=d[p];f.sort(mk(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&c(m)}}};return c(h),h}function vk(){let t=window.MathJax;return t?t.Hub:null}var Uc={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Ha="viv-id-";function pr(t,e){if(t.startsWith("data:"))return t===e?"":t;if(e){let i=Ie("",e);return t===i||t+"/"===i?"":(i.charAt(i.length-1)!="/"&&(i+="/"),t.substr(0,i.length)==i?decodeURIComponent(t.substr(i.length)):null)}else return t}var Ji=class Pr{constructor(e,i,n){u(this,"store",e),u(this,"pubURL",i),u(this,"opfXML"),u(this,"encXML",null),u(this,"items"),u(this,"spine"),u(this,"itemMap"),u(this,"itemMapByPath"),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.opfXML=n.opfXML,this.items=n.items,this.spine=n.spine,this.itemMap=n.itemMap,this.itemMapByPath=n.itemMapByPath,this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class i{constructor(){u(this,"canonicalDocumentURLCache",new Map)}getCanonicalDocumentURL(r){var o,s;let a=ft(bn(r)),h=this.canonicalDocumentURLCache.get(a);if(h)return h;for(let l of e.spine){let c=ft(bn(l.src));if(c===a)return this.canonicalDocumentURLCache.set(a,c),c;let d=(s=(o=e.store)==null?void 0:o.get(c))==null?void 0:s.url;if(d&&ft(bn(d))===a)return this.canonicalDocumentURLCache.set(a,c),c}return this.canonicalDocumentURLCache.set(a,a),a}transformFragment(r,o){let s=this.getCanonicalDocumentURL(o)+(r?`#${r}`:"");return Ha+ad(s,":")}transformURL(r,o){let s=r.match(/^([^#]*)#?(.*)$/);if(s){let a=this.getCanonicalDocumentURL(s[1]||bn(o)),h=decodeURIComponent(s[2]);if(a&&e.spine.some(l=>ft(bn(l.src))===a))return`#${this.transformFragment(h,a)}`}return r}restoreURL(r){r.charAt(0)==="#"&&(r=r.substring(1)),r.indexOf(Ha)===0&&(r=r.substring(Ha.length));let o=ey(r,":").match(/^([^#]*)#?(.*)$/);return o?[o[1],o[2]]:[]}}return new i}getMetadata(){return this.metadata}getPathFromURL(e){return pr(e,this.pubURL)}static fromXMLDoc(e,i,n,r){let o=n.doc().child("package"),s=null,a=o.attribute("unique-identifier")[0];if(a){let y=n.getElement(`${n.url}#${a}`);y&&(s=y.textContent.replace(/[ \n\r\t]/g,""))}let h={},l=null,c=null,d=o.child("manifest").child("item").asArray().map(y=>{let k=new Hc,S=y;k.initWithElement(S,n.url);let N=S.getAttribute("fallback");return N&&!Uc[k.mediaType]&&(h[k.src]=N),!l&&k.itemProperties.nav&&(l=k),!c&&k.itemProperties["cover-image"]&&(c=k),k}),p=su(d,pk),f=su(d,y=>pr(y.src,i)),g={};for(let y in h){let k=y;for(;;){let S=p[h[k]];if(!S)break;if(Uc[S.mediaType]){g[y]=S.src;break}k=S.src}}let m=o.child("spine").child("itemref").asArray().map((y,k)=>{let S=y,N=S.getAttribute("idref"),L=p[N];return L&&(L.itemRefElement=S,L.spineIndex=k),L}),v=new Pr(e,i,{opfXML:n,items:d,spine:m,itemMap:p,itemMapByPath:f});v.encXML=r,v.uid=s,v.toc=l,v.cover=c,v.fallbackMap=g;let b=o.child("spine").attribute("page-progression-direction")[0];b&&(v.pageProgression=Qc(b));let x=r?r.doc().child("encryption").child("EncryptedData").predicate(Bc.withChild("EncryptionMethod",Bc.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],C=o.child("bindings").child("mediaType").asArray();for(let y=0;y<C.length;y++){let k=C[y].getAttribute("handler"),S=C[y].getAttribute("media-type");S&&k&&p[k]&&(v.bindings[S]=p[k].src)}if(v.metadata=yk(o.child("metadata"),o.attribute("prefix")[0]),v.metadata[Xe.language]&&(v.lang=v.metadata[Xe.language][0].v),v.metadata[Xe.layout]&&(v.prePaginated=v.metadata[Xe.layout][0].v==="pre-paginated"),x.length>0&&s){let y=fk(s);for(let k=0;k<x.length;k++)e.deobfuscators[i+x[k]]=y}return v.prePaginated&&v.assignAutoPages(),v}assignAutoPages(){let e=0;for(let i of this.spine){let n=this.prePaginated?1:Math.ceil(i.compressedSize/1024);i.epage=e,i.epageCount=n,e+=n}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(),F(!0);let i=0,n=0,r=V("countEPages");return r.loopWithFrame(o=>{if(n===this.spine.length){o.breakLoop();return}let s=this.spine[n++];s.epage=i,this.store.load(s.src).then(a=>{if(!a){o.continueLoop();return}let h=1800,l=a.lang||this.lang;l&&l.match(/^(ja|ko|zh)/)&&(h/=3),s.epageCount=Math.ceil(a.getTotalOffset()/h),i+=s.epageCount,this.epageCount=i,this.epageCountCallback&&this.epageCountCallback(this.epageCount),o.continueLoop()})}).thenFinish(r),r.result()}static buildChapters(e,i){let n={},r={},o=[],s=o,a=new nm(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return i.forEach(h=>{let l=new Hc;l.initWithParam(h),l.id;let c=a.document.createElement("itemref");c.setAttribute("idref",l.id),a.root.appendChild(c),l.itemRefElement=c,n[l.id]=l;let d=pr(h.url,e);d==null&&(d=h.url),r[d]=l,o.push(l)}),{opfXML:a,items:o,spine:s,itemMap:n,itemMapByPath:r}}static fromChapters(e,i,n,r){let o=new Pr(e,i,Pr.buildChapters(i,n));return r?e.addDocument(n[0].url,r).thenReturn(o):F(o)}static fromWebPubManifest(e,i,n,r,o){var s,a,h,l;let c=null;n.readingProgression&&(c=n.readingProgression);let d={},p=n.name||((s=n.metadata)==null?void 0:s.title)||r?.title;p&&(d[Xe.title]=(Array.isArray(p)?p:[p]).map(S=>{var N;return{v:(N=S.value)!=null?N:S}}));let f=n.author||n.creator||((a=n.metadata)==null?void 0:a.author)||Array.from((h=r?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?h:[]).map(S=>S.content);f&&f.length!==0&&(d[Xe.creator]=(Array.isArray(f)?f:[f]).map(S=>{var N;return{v:(N=S.name)!=null?N:S}}));let g=n.inLanguage||((l=n.metadata)==null?void 0:l.language)||r?.documentElement.lang||r?.documentElement.getAttribute("xml:lang");g&&(d[Xe.language]=(Array.isArray(g)?g:[g]).map(S=>({v:S})));let m=ft(i),v=pr(m,i),b=v!==null?Vc(v):/^(?:about:|blob:)/i.test(m)?m:null;if(!n.readingOrder&&r&&b!==null){n.readingOrder=[b];for(let S of lk(r)){let N=S.getAttribute("href");if(/^(https?:)?\/\//.test(N)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(N))continue;let L=ft(Ie(N,i)),I=pr(L,i),D=I!==null?Vc(I):L;n.readingOrder.indexOf(D)==-1&&n.readingOrder.push(D)}}let x=[],C=0,y=-1;[n.readingOrder,n.resources].forEach(S=>{S instanceof Array&&S.forEach(N=>{let L=S===n.readingOrder,I=typeof N=="string"?N:N.url||N.href,D=typeof N=="string"?"":N.encodingFormat||N.href&&N.type||"";if(L||D==="text/html"||D==="application/xhtml+xml"||!D&&N.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(I)){let J=o?o.replace(/\/[^/]+$/,"/"):i,te={url:Ie(_n(I),J),index:C++,startPage:null,skipPagesBefore:null};N.rel==="contents"&&y===-1&&(y=te.index),x.push(te)}})});let k=V("fromWebPubManifest");return Pr.fromChapters(e,i,x).then(S=>{var N,L;S.pageProgression=c,S.metadata=d,y!==-1&&(S.toc=S.items[y]),S.toc||(S.toc=o?(N=S.items[0])!=null?N:null:S.itemMapByPath[v]);let I=(L=n.readingOrder)==null?void 0:L.length;I&&I<S.items.length&&S.items.splice(I),k.finish(S)}),k.result()}getCFI(e,i){let n=this.spine[e],r=V("getCFI");return this.store.load(n.src).then(o=>{let s=o.getNodeByOffset(i),a=null;if(s){let h=o.getNodeOffset(s,0,!1),l=i-h,c=new wu;c.prependPathFromNode(s,l,!1,null),n.itemRefElement&&c.prependPathFromNode(n.itemRefElement,0,!1,null),a=c.toString()}r.finish(a)}),r.result()}resolveFragment(e){return hn("resolveFragment",i=>{if(!e){i.finish(null);return}let n=new wu;n.fromString(e);let r;if(this.opfXML){let o=n.navigate(this.opfXML.document);if(o.node.nodeType!=1||o.after||!o.ref){i.finish(null);return}let s=o.node,a=s.getAttribute("idref");if(s.localName!="itemref"||!a||!this.itemMap[a]){i.finish(null);return}r=this.itemMap[a],n=o.ref}else r=this.spine[0];this.store.load(r.src).then(o=>{let s=n.navigate(o.document),a=o.getNodeOffset(s.node,s.offset,s.after);i.finish({spineIndex:r.spineIndex,offsetInItem:a,pageIndex:-1})})},(i,n)=>{Y.warn(n,"Cannot resolve fragment:",e),i.finish(null)})}resolveEPage(e){return hn("resolveEPage",i=>{if(e<=0){i.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let o=this.spine.findIndex(h=>h.epage==0&&h.epageCount==0||h.epage<=e&&h.epage+h.epageCount>e);o==-1&&(o=this.spine.length-1);let s=this.spine[o];(!s||s.epageCount==0)&&(s=this.spine[--o]);let a=Math.floor(e-s.epage);i.finish({spineIndex:o,offsetInItem:-1,pageIndex:a});return}let n=yi(this.spine.length,o=>{let s=this.spine[o];return s.epage+s.epageCount>e});n==this.spine.length&&n--;let r=this.spine[n];this.store.load(r.src).then(o=>{e-=r.epage,e>r.epageCount&&(e=r.epageCount);let s=0;if(e>0){let a=o.getTotalOffset();s=Math.round(a*e/r.epageCount),s==a&&s--}i.finish({spineIndex:n,offsetInItem:s,pageIndex:-1})})},(i,n)=>{Y.warn(n,"Cannot resolve epage:",e),i.finish(null)})}getEPageFromPosition(e){let i=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let r=i.epage+e.pageIndex;return F(r)}if(e.offsetInItem<=0)return F(i.epage);let n=V("getEPage");return this.store.load(i.src).then(r=>{let o=r.getTotalOffset(),s=Math.min(o,e.offsetInItem);n.finish(i.epage+s*i.epageCount/o)}),n.result()}},jo=(t,e)=>({page:t,position:{spineIndex:t.spineIndex,pageIndex:e,offsetInItem:t.offset}}),wk=class{constructor(t,e,i,n,r,o){u(this,"opf",t),u(this,"viewport",e),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:[],totalOffsetsReady:!1,lastReportedPages:0,lastReportedFraction:0,lastReportedSpineIndex:-1,lastReportedHref:""}),u(this,"renderingPageTasks",new Map),this.pref=ud(n),this.clientLayout=new fC(e),this.counterStore=new Yy(t.documentURLTransformer),this.cmykStore=new zd,o!=null&&o.length&&this.cmykStore.registerCmykReserveMap(o)}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}waitForPreviousSpines(t,e){if(e||t===0)return F(!0);let i=V("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let o=0;o<t;o++){let s=this.spineItems[o];if(!s||!s.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(t){if(this.opf.pageProgression)return this.opf.pageProgression;{let e=this.spineItems[t?t.spineIndex:0];return e?e.instance.pageProgression:null}}finishPageContainer(t,e,i){e.container.style.display="none",e.container.style.visibility="visible",e.container.style.position="",e.container.style.top="",e.container.style.left="",e.container.setAttribute("data-vivliostyle-page-side",e.side);let n=t.pages[i];if(e.isFirstPage=t.item.spineIndex==0&&i==0,t.pages[i]=e,this.opf.epageIsRenderedPage){if(i==0&&t.item.spineIndex>0){let r=this.opf.spine[t.item.spineIndex-1];t.item.epage=r.epage+r.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,o)=>r+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)t.instance.viewport.contentContainer.replaceChild(e.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:e});else{let r=null;if(i>0)r=t.pages[i-1].container.nextElementSibling;else for(let o=t.item.spineIndex+1;o<this.spineItems.length;o++){let s=this.spineItems[o];if(s&&s.pages[0]){r=s.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,r)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+i)}getRenderedPageCount(){let t=0;for(let e of this.spineItems)e&&(t+=e.pages.length);return t}markSpineItemCompleteIfReady(t){t.complete=t.layoutPositions.length===t.pages.length,t.complete&&t.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(t){let e=t.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[e];return i==null&&(i=t.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[e]=i),i}collectTotalOffsets(){if(this.paginationProgress.totalOffsetsReady)return F(!0);let t=this.paginationProgress.totalOffsetsBySpine,e=0,i=V("collectTotalOffsets");return i.loopWithFrame(n=>{if(e===this.opf.spine.length){n.breakLoop();return}let r=e++;if(t[r]!=null){n.continueLoop();return}let o=this.opf.spine[r];this.opf.store.load(o.src).then(s=>{s&&(t[r]=s.getTotalOffset()),n.continueLoop()})}).then(()=>{this.paginationProgress.totalOffsetsReady=!0,i.finish(!0)}),i.result()}getTotalOffsetAll(){let t=0;for(let e of this.paginationProgress.totalOffsetsBySpine)e&&(t+=e);return t}getRenderedOffsetAll(){var t;let e=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let o=i[r];if(!o)continue;let s=(t=n[r])!=null?t:0;e+=Math.min(o,s)}return e}reportPaginationProgress(t,e){var i,n;let r=zt("PAGINATION_PROGRESS");if(!r.length)return;let o=t.item.spineIndex,s=this.getTotalOffsetForViewItem(t),a=s;e&&(a=t.instance.getPosition(e,!0)),a<0&&(a=0),a>s&&(a=s);let h=this.paginationProgress.renderedOffsetsBySpine[o];h!=null&&a<h&&(a=h),this.paginationProgress.renderedOffsetsBySpine[o]=a;let l=this.getRenderedPageCount(),c=this.getTotalOffsetAll(),d=this.getRenderedOffsetAll(),p=c>0?d/c:0;p<this.paginationProgress.lastReportedFraction?p=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=p,l>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=l);let f=t.item.src;o>=((i=this.paginationProgress.lastReportedSpineIndex)!=null?i:-1)?(this.paginationProgress.lastReportedSpineIndex=o,this.paginationProgress.lastReportedHref=f):f=(n=this.paginationProgress.lastReportedHref)!=null?n:f;let g={fraction:p,pages:this.paginationProgress.lastReportedPages,href:f};for(let m of r)try{m(g)}catch(v){Y.warn(v)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(t){return!!(t!=null&&t.pageType)&&t.pageType!==""}hasPageTypeBoundaryBetween(t,e){return t?.pageType!=null&&e?.pageType!=null&&t.pageType!==e.pageType}resolvePageTypeForRenderSlot(t,e,i,n,r,o,s){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=o?.pageType===n.pageType,c=n.offset!==e.offset,d=s&&!c&&i>0;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),e.pageType=a?n.pageType:null,s){let p=t.instance.getPageStartPageTypeOverride(e.position);p===""?e.pageType="":p&&(e.pageType=p)}if(!s&&!a){let p=i>1&&h&&l?r.pageType:null;t.instance.styler.cascade.currentPageType=p,t.instance.pageManager.pageCascadeInstance.currentPageType=p}}!s&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(o)&&r.pageType!==o.pageType&&(!n||n.pageType==null)&&(e.pageType=r.pageType)}evaluateNextPageRelayout(t,e,i,n,r){if(!t||e&&!i)return{needsRelayout:!1,shouldCascade:!1};let o=!!e&&(t.pageType===e.pageType||!e.pageType);return e&&n&&(!r||o)&&(e.pageType==null||t.pageType==null||t.pageType!==e.pageType)&&(e.pageType=null),{needsRelayout:!0,shouldCascade:!!e||!r}}preparePageCountersForRender(t,e){let i=t.pages[e],n=t.pageCounterStarts[e];i&&n&&(this.counterStore.currentPageCounters=Go(n));let r=Go(this.counterStore.currentPageCounters);return(!n||!i)&&(t.pageCounterStarts[e]=r),i}maybeRelayoutFollowingPage(t,e,i,n){if(!e)return F(!0);let r=t.layoutPositions[e.page];t.layoutPositions[e.page]=e;let o=t.pages[e.page],s=!!i&&n.offset!==i.offset,a=t.instance.hasActiveRootPageFloatLayoutContext(),h=!r||!e.isSamePosition(r)||e.highestSeenOffset!==r.highestSeenOffset||s||a,l=this.isInCounterResolveScope(),c=this.evaluateNextPageRelayout(i,o,h,s,l);return c.needsRelayout?(t.complete=!1,c.shouldCascade?this.renderSinglePage(t,e):F(!0)):F(!0)}resolveUnresolvedReferencesForPage(t,e,i,n){let r=V("resolveUnresolvedReferencesForPage"),o=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(e),s=0,a=e;return r.loopWithFrame(h=>{if(s++,s>o.length){h.breakLoop();return}let l=o[s-1];if(l.refs=l.refs.filter(c=>!c.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(c=>{var d;if(!c){h.continueLoop();return}let p=c.instance.styler.cascade,f=c.instance.pageManager.pageCascadeInstance,g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m={currentPageType:f.currentPageType,previousPageType:f.previousPageType},v=ck(c.instance.pageGroupPageCounts),b=c.instance.currentPageGroupDocument,x=c.instance.scopes;c.instance.scopes={};let C=l.pageIndex<c.pages.length-1,y=!!c.pages[l.pageIndex],k=y&&C,S=k&&l.pageIndex>0?(d=c.pages[l.pageIndex-1])==null?void 0:d.pageFloatLayoutContext:null,N=k?c.instance.beginIsolatedRootPageFloatLayoutContext(S):null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let L=c.layoutPositions[l.pageIndex];y&&c.instance.preparePageGroupPageIndicesForRerender(c.layoutPositions,l.pageIndex),this.renderSinglePage(c,L).then(I=>{k&&c.instance.endIsolatedRootPageFloatLayoutContext(N);let D=p.currentPageType;p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,f.currentPageType=m.currentPageType,f.previousPageType=m.previousPageType,c.instance.pageGroupPageCounts=v,c.instance.currentPageGroupDocument=b,c.instance.scopes=x;let J=Go(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),I.pageAndPosition.position.spineIndex===a.spineIndex&&I.pageAndPosition.position.pageIndex===i&&(a=I.pageAndPosition.page),a.pageType&&a.pageType!==g.currentPageType&&D!==I.pageAndPosition.page.pageType&&(p.currentPageType=a.pageType);let te=c!==t,P=c.pages.length,M=c.layoutPositions[P],A=c.instance.hasActiveRootPageFloatLayoutContext();if(M&&!A){let H=te?Go(this.counterStore.currentPageCounters):null;te&&(this.counterStore.currentPageCounters=J);let z=P;this.renderSinglePage(c,M).then(()=>{te&&this.markSpineItemCompleteIfReady(c);let E=c.pages.length-z;if(te&&E>0){this.counterStore.adjustPageCountersOfLaterSpines(c.item.spineIndex,E),this.counterStore.updateTargetCounterNodesInPages(c.pages);let O=c.item.spineIndex;for(let T=O+1;T<this.spineItems.length;T++){let $=this.spineItems[T];if($){$.item.epage+=E;for(let G of $.pageCounterStarts)G!=null&&G.page&&(G.page=G.page.map(q=>q+E));this.counterStore.updatePageCounterNodesInPages($.pages,$.pageCounterStarts)}}if(H){let T=H.page;T&&(H.page=T.map($=>$+E))}}H&&(this.counterStore.currentPageCounters=H),h.continueLoop()});return}te&&this.markSpineItemCompleteIfReady(c),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=t.pages[i]),a.isLastPage=!n&&t.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&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(t,e){let i=V("renderSinglePage"),n=e?Math.max(e.page,0):0,r=t.instance.getPageNumberContextDepth();t.instance.pushPageNumberContext(n+1);let o=()=>{t.instance.restorePageNumberContextDepth(r)};i.handler=(d,p)=>{o(),d.task.raise(p,d.parent)};let s=this.isInCounterResolveScope(),a=this.preparePageCountersForRender(t,n),h=n>0?t.pages[n-1]:null,l=t.pages[n+1],c=this.makePage(t,e);return this.resolvePageTypeForRenderSlot(t,c,n,a,h,l,s),t.instance.layoutNextPage(c,e).then(d=>{e=d;let p=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,c,p),this.counterStore.finishPage(c.spineIndex,p),(zt("PAGINATION_PROGRESS").length?this.collectTotalOffsets():F(!0)).then(()=>{this.reportPaginationProgress(t,e),this.maybeRelayoutFollowingPage(t,e,a,c).thenAsync(()=>this.resolveUnresolvedReferencesForPage(t,c,p,e)).then(f=>{o(),i.finish({pageAndPosition:jo(f,p),nextLayoutPosition:e})})})}),i.result()}normalizeSeekPosition(t,e){let i=t.pageIndex,n=-1;if(i<0){n=t.offsetInItem;let r=yi(e.layoutPositions.length,o=>e.instance.getPosition(e.layoutPositions[o],!0)>n);r===e.layoutPositions.length?e.complete?i=e.pages.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&t.offsetInItem!==-1&&(n=t.offsetInItem);return{spineIndex:t.spineIndex,pageIndex:i,offsetInItem:n}}findPage(t,e){let i=V("findPage");return this.waitForPreviousSpines(t.spineIndex,e).then(()=>{this.getPageViewItem(t.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,o;i.loopWithFrame(s=>{let a=this.normalizeSeekPosition(t,n);o=a.pageIndex,r=n.pages[o],r?s.breakLoop():n.complete?(o=n.pages.length-1,r=n.pages[o],s.breakLoop()):e?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):this.isRenderingPageInAnotherTask()?i.sleep(100).then(()=>{s.continueLoop()}):o<n.layoutPositions.length&&!n.pages[o]?this.renderPage(a).then(h=>{h&&(r=h.page,o=h.position.pageIndex),s.breakLoop()}):i.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{i.finish(jo(r,o))})})}),i.result()}renderPage(t){let e=Hr();this.beginRenderingPage(e);let i=!1,n=()=>{i||(i=!0,this.endRenderingPage(e))};return hn("renderPage",r=>{this.renderPageTracked(t).then(o=>{n(),r.finish(o)})},(r,o)=>{n(),r.task.raise(o,r.parent)})}beginRenderingPage(t){this.renderingPageTasks.set(t,(this.renderingPageTasks.get(t)||0)+1)}endRenderingPage(t){let e=this.renderingPageTasks.get(t);e===1?this.renderingPageTasks.delete(t):e&&this.renderingPageTasks.set(t,e-1)}isRenderingPageInAnotherTask(){let t=Hr();return Array.from(this.renderingPageTasks.keys()).some(e=>e!==t)}renderPageTracked(t){let e=V("renderPageTracked");return this.getPageViewItem(t.spineIndex).then(i=>{if(!i){e.finish(null);return}let n=this.normalizeSeekPosition(t,i),r=n.pageIndex,o=n.offsetInItem,s=i.pages[r];if(s){e.finish(jo(s,r));return}e.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(o>=0&&i.instance.getPosition(h)>o){s=c,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else s=c,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{s=s||i.pages[r];let a=i.layoutPositions[r];if(s){e.finish(jo(s,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),e.finish(h.pageAndPosition)})})}),e.result()}renderAllPages(){let t=V("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(e=>{t.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(o=>!o.arrived)))?t.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let i=V("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let n=t.spineIndex,r=t.pageIndex,o=0;e&&(o=n);let s=null;return i.loopWithFrame(a=>{let h={spineIndex:o,pageIndex:o===n?r:Number.POSITIVE_INFINITY,offsetInItem:o===n?t.offsetInItem:-1};this.renderPage(h).then(l=>{s=l,++o>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(s)}),i.result()}firstPage(t,e){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},e)}lastPage(t,e){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},e)}nextPage(t,e){let i=t.spineIndex,n=t.pageIndex,r=V("nextPage");return this.getPageViewItem(i).then(o=>{if(!o){r.finish(null);return}if(o.complete&&n==o.pages.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let s=this.spineItems[i],a=s&&s.pages[0],h=o.pages[o.pages.length-1];a&&h&&a.side==h.side&&(s.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},e).thenFinish(r)}),r.result()}previousPage(t,e){let i=t.spineIndex,n=t.pageIndex;if(n==0){if(i==0)return F(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},e)}isRectoPage(t,e){let i=t.side==="left",n=this.getCurrentPageProgression(e)==="ltr";return!i&&n||i&&!n}getSpread(t,e){let i=this.getPage(t);if(!i)return F({left:null,right:null});let n=V("getSpread"),r=i.side==="left",o;return this.isRectoPage(i,t)?o=this.previousPage(t,e):o=this.nextPage(t,e),o.then(s=>{let a=this.getPage(t),h=s&&s.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(t,e){let i=this.getPage(t);if(!i)return F(null);let n=this.isRectoPage(i,t),r=this.nextPage(t,e);return n?r:r.thenAsync(o=>{if(o){if(o.page.side===i.side)return r;let s=this.nextPage(o.position,e);return s.thenAsync(a=>a?s:r)}else return F(null)})}previousSpread(t,e){let i=this.getPage(t);if(!i)return F(null);let n=this.isRectoPage(i,t),r=this.previousPage(t,e),o=i.container.previousElementSibling;return n?r.thenAsync(s=>s?s.page.side===i.side||s.page.container!==o?r:this.previousPage(s.position,e):F(null)):r}navigateToEPage(t,e,i){let n=V("navigateToEPage");return this.opf.resolveEPage(t).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(t,e,i){let n=V("navigateToCFI");return this.opf.resolveFragment(t).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(t,e){if(!Et(e))return null;let i=e.getAttribute("id");if(!i)return null;let n=Ie(`#${i}`,t.xmldoc.url),r=t.xmldoc.document.getElementsByTagName("a");for(let o=0;o<r.length;o++){let s=r.item(o);if(!qt(s))continue;let a=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ie(a,t.xmldoc.url)===n)return t.xmldoc.getElementOffset(s)}return null}navigateTo(t,e,i){Y.debug("Navigate to",t);let n=this.opf.getPathFromURL(ft(t));if(!n){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let s=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(n=this.opf.getPathFromURL(s[0]),n==null&&(n=s[0])):n=s[0],t=s[0]+(s[1]?`#${s[1]}`:"")}if(n==null)return F(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let s=t.indexOf("#");if(s>=0)return this.navigateToFragment(t.substr(s+1),e,i)}return F(null)}let o=V("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(s=>{if(!s){o.finish(null);return}let a=s.xmldoc.getElement(t),h=a&&this.resolveSemanticFootnoteNavigationOffset(s,a),l=h??(a?s.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},i).thenFinish(o)})}),o.result()}makePage(t,e){let i=t.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Vr||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let o=new Ip(n,r);if(o.spineIndex=t.item.spineIndex,o.position=e,o.offset=t.instance.getPosition(e),o.offset===0&&!(t.instance.blankPageAtStart&&t.pages.length===0)){let s=this.opf.documentURLTransformer.transformFragment("",t.item.src);r.setAttribute("id",s),o.registerElementWithId(r,s)}if(i!==this.viewport){let s=cd(this.viewport.width,this.viewport.height,i.width,i.height),a=Mi(t.instance.style.rootScope,new xt(s,null),"");o.delayedItems.push(new hh(n,"transform",a))}return o}makeObjectView(t,e,i,n){let r=e.getAttribute("data"),o=null;if(r){r=Ie(r,t.url);let s=e.getAttribute("media-type");if(!s){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(s=h.mediaType)}}if(s){let a=this.opf.bindings[s];if(a){o=this.viewport.document.createElement("iframe"),o.style.border="none";let h=ru(r),l=ru(s),c=new mi;c.append(a),c.append("?src="),c.append(h),c.append("&type="),c.append(l);for(let f=e.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),v=g.getAttribute("value");m&&v&&(c.append("&"),c.append(encodeURIComponent(m)),c.append("="),c.append(encodeURIComponent(v)))}}o.setAttribute("src",c.toString());let d=e.getAttribute("width");d&&o.setAttribute("width",d);let p=e.getAttribute("height");p&&o.setAttribute("height",p)}}}return o||(o=this.viewport.document.createElement("object"),r&&o.setAttribute("data",$r(r)),o.setAttribute("data-adapt-process-children","true")),F(o)}makeMathJaxView(t,e,i,n){let r=vk();if(r){let o=i.ownerDocument,s=o.createElement("span");i.appendChild(s);let a=o.importNode(e,!0);this.resolveURLsInMathML(a,t),s.appendChild(a);let h=r.queue;h.Push(["Typeset",r,s]);let l=V("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(s)}),l.result()}return F(null)}resolveURLsInMathML(t,e){if(t!=null){if(t.nodeType===1&&t.tagName==="mglyph"){let i=Array.from(t.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ie(n.nodeValue,e.url);n.namespaceURI?t.setAttributeNS(n.namespaceURI,n.name,r):t.setAttribute(n.name,r)}}t.firstChild&&this.resolveURLsInMathML(t.firstChild,e),t.nextSibling&&this.resolveURLsInMathML(t.nextSibling,e)}}makeCustomRenderer(t){return(e,i,n)=>e.localName=="object"&&e.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(t,e,i,n):e.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(t,e,i,n):e.dataset&&e.dataset.mathTypeset=="true"?this.makeMathJaxView(t,e,i,n):F(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return F(null);let e=this.spineItems[t];if(e)return F(e);let i=V("getPageViewItem"),n=this.spineItemLoadingContinuations[t];if(n){let s=i.suspend();return n.push(s),i.result()}else n=this.spineItemLoadingContinuations[t]=[];let r=this.opf.spine[t],o=this.opf.store;return o.load(r.src).then(s=>{var a;let h=r.itemRefElement.getAttribute("properties");h&&s.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=s.document.title;let l=o.getStyleForDoc(s),c=this.makeCustomRenderer(s),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new Gs(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[t-1],m,v;if(r.startPage!==null)m=r.startPage-1,v=m;else{if(t>0&&(!g||!g.complete))m=r.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,v=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let y=g&&g.pageCounterStarts[g.pages.length-1],k=y&&y.page;if(k&&k.length)v=k[k.length-1]+1;else{let S=this.counterStore.currentPageCounters.page;v=!S||!S.length?m:S[S.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,v+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(v);let b=this.opf.metadata&&this.opf.metadata[Xe.title],x=b&&b[0]&&b[0].v||"",C=r.title||"";Xh.create(l,s,this.opf.lang,d,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.pref,x,C,this.opf.pageProgression,f).then(y=>{!this.opf.pageProgression&&y.pageProgression&&(this.opf.pageProgression=y.pageProgression),e={item:r,xmldoc:s,instance:y,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[t]=e,i.finish(e),n.forEach(k=>{k.schedule(e)})})}),i.result()}removeRenderedPages(){let t=this.spineItems;for(let e of t)e&&e.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let t=this.spineItems;for(let e of t)if(e){let i=e.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(t=>t&&t.pages.length>0)}showTOC(t){let e=this.opf,i=e.toc;if(this.tocAutohide=t,!i)return F(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"),F(this.tocView.page);let n=V("showTOC");this.tocView||(this.tocView=new hk(e.store,i.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,o=Math.min(344,Math.round(.67*r.width)-16),s=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),Vr||(a.style.visibility="hidden"),a.style.width=`${o+16}px`,a.style.maxHeight=`${s}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,o,s,this.viewport.fontSize).then(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},Wc="data-vivliostyle-viewer-status",bk="data-vivliostyle-spread-view",hm=(t=>(t.SINGLE_PAGE="singlePage",t.SPREAD="spread",t.AUTO_SPREAD="autoSpread",t))(hm||{}),xk=class{constructor(t,e,i,n){u(this,"window",t),u(this,"viewportElement",e),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","loading"),u(this,"packageURL",[]),u(this,"opf",null),u(this,"touchActive",!1),u(this,"touchX",0),u(this,"touchY",0),u(this,"needResize",!1),u(this,"resized",!1),u(this,"needRefresh",!1),u(this,"viewportSize",null),u(this,"currentPage",null),u(this,"currentSpread",null),u(this,"pagePosition",null),u(this,"fontSize",16),u(this,"zoom",1),u(this,"fitToScreen",!1),u(this,"pageViewMode","singlePage"),u(this,"waitForLoading",!1),u(this,"renderAllPages",!0),u(this,"pref",hd()),u(this,"pageSizes",[]),u(this,"pixelRatioLimit",no==="chromium"&&"currentCSSZoom"in Element.prototype?16:0),u(this,"pixelRatio",Math.min(8,this.pixelRatioLimit)),u(this,"viewport",null),u(this,"opfView",null),u(this,"cmykReserveMap"),u(this,"cmykReserveMapUrl"),u(this,"paginationProgressHook",null);let r=e.ownerDocument,o=(s,a)=>{let h=r.getElementById(s);return h||(h=r.createElement("style"),h.id=s,a&&(h.textContent=a),r.head.appendChild(h)),h};o("vivliostyle-viewport-screen-css",ap),o("vivliostyle-viewport-css",lp),o("vivliostyle-polyfill-css",fp),e.setAttribute("data-vivliostyle-viewer-viewport",!0),Vr&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(Wc,"loading"),this.fontMapper=new KS(r.head,e),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=s=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}addLogListeners(){let t=id;Y.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),Y.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),Y.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),Y.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}ensurePaginationProgressListener(){if(this.paginationProgressHook)return;let t=e=>{this.callback({t:"paginationprogress",...e})};this.paginationProgressHook=t,Ft("PAGINATION_PROGRESS",t)}removePaginationProgressListener(){this.paginationProgressHook&&(ql("PAGINATION_PROGRESS",this.paginationProgressHook),this.paginationProgressHook=null)}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){if(this.readyState!==t){this.readyState=t,this.viewportElement.setAttribute(Wc,t);let e=this.getCurrentPageProgression();e&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",e),this.callback({t:"readystatechange"})}}loadPublication(t){Nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,i=t.fragment,n=t.authorStyleSheet,r=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let o=V("loadPublication");return this.configure(t).then(()=>{$c.create(n,r).then(s=>{let a=Ie(_n(e),this.window.location.href);this.packageURL=[a],s.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(s).then(()=>{this.render(i).then(()=>{o.finish(!0)})})):o.finish(!1)})})}),o.result()}loadXML(t){Nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,i=t.document,n=t.fragment,r=t.authorStyleSheet,o=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let s=V("loadXML");return this.configure(t).then(()=>{$c.create(r,o).then(a=>{let h=e.map((l,c)=>({url:Ie(_n(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),Ji.fromChapters(a,"",h,i).then(l=>{this.opf=l,this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{s.finish(!0)})})})})}),s.result()}render(t){this.cancelRenderingTask();let e;return t?e=this.opf.resolveFragment(t).thenAsync(i=>(this.pagePosition=i,F(!0))):e=F(!0),e.thenAsync(()=>(Nt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),i=/[a-z]+$/,n;if(typeof t=="string"&&(n=t.match(i))){let r=n[0];if(r==="em"||r==="rem")return e*this.fontSize;let o=vi[r];if(o)return e*o}return e}configure(t){if(typeof t.autoresize=="boolean"&&(t.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof t.fontSize=="number"){let e=t.fontSize;e>=5&&e<=72&&this.fontSize!=e&&(this.fontSize=e,this.needResize=!0)}if(typeof t.viewport=="object"&&t.viewport){let e=t.viewport,i={marginLeft:this.resolveLength(e["margin-left"])||0,marginRight:this.resolveLength(e["margin-right"])||0,marginTop:this.resolveLength(e["margin-top"])||0,marginBottom:this.resolveLength(e["margin-bottom"])||0,width:this.resolveLength(e.width)||0,height:this.resolveLength(e.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof t.hyphenate=="boolean"&&(this.pref.hyphenate=t.hyphenate,this.needResize=!0),typeof t.horizontal=="boolean"&&(this.pref.horizontal=t.horizontal,this.needResize=!0),typeof t.nightMode=="boolean"&&(this.pref.nightMode=t.nightMode,this.needResize=!0),typeof t.lineHeight=="number"&&(this.pref.lineHeight=t.lineHeight,this.needResize=!0),typeof t.columnWidth=="number"&&(this.pref.columnWidth=t.columnWidth,this.needResize=!0),typeof t.fontFamily=="string"&&(this.pref.fontFamily=t.fontFamily,this.needResize=!0),typeof t.load=="boolean"&&(this.waitForLoading=t.load),typeof t.renderAllPages=="boolean"&&(this.renderAllPages=t.renderAllPages),typeof t.userAgentRootURL=="string"&&(eu(t.userAgentRootURL.replace(/resources\/?$/,"")),tu(t.userAgentRootURL)),typeof t.rootURL=="string"&&(eu(t.rootURL),tu(`${an}resources/`)),typeof t.pageViewMode=="string"&&t.pageViewMode!==this.pageViewMode&&(this.pageViewMode=t.pageViewMode,this.needResize=!0),typeof t.pageBorder=="number"&&t.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=t.pageBorder,this.needResize=!0),typeof t.zoom=="number"&&t.zoom!==this.zoom&&(this.zoom=t.zoom,this.needRefresh=!0),typeof t.fitToScreen=="boolean"&&t.fitToScreen!==this.fitToScreen&&(this.fitToScreen=t.fitToScreen,this.needRefresh=!0),typeof t.defaultPaperSize=="object"&&typeof t.defaultPaperSize.width=="number"&&typeof t.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=t.defaultPaperSize,this.needResize=!0),typeof t.allowScripts=="boolean"&&t.allowScripts!==bi&&(JS(t.allowScripts),this.needResize=!0),typeof t.pixelRatio=="number"){let e=Math.min(t.pixelRatio,this.pixelRatioLimit);e!==this.pixelRatio&&(this.pixelRatio=e,this.needResize=!0)}return this.configurePlugins(t),F(!0)}configurePlugins(t){zt("CONFIGURATION").forEach(e=>{let i=e(t);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(t){let e=this.currentPage,i=this.currentSpread,n=t.target;i?(i.left===n||i.right===n)&&this.showCurrent(t.newPage):e===t.target&&this.showCurrent(t.newPage)}forCurrentPages(t){let e=[];this.currentPage&&e.push(this.currentPage),this.currentSpread&&(this.currentSpread.left&&e.push(this.currentSpread.left),this.currentSpread.right&&e.push(this.currentSpread.right)),e.forEach(i=>{i&&t(i)})}removePageListeners(){this.forCurrentPages(t=>{t.removeEventListener("hyperlink",this.hyperlinkListener,!1),t.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(t=>{R(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),R(t.container,"visibility","visible"),R(t.container,"display","block")}showPage(t){this.hidePages(),this.currentPage=t,t.container.style.marginLeft="",t.container.style.marginRight="",this.showSinglePage(t)}showSpread(t){if(this.hidePages(),this.currentSpread=t,t.left&&t.right){let e=parseFloat(t.left.container.style.width),i=parseFloat(t.right.container.style.width);e&&i&&e!==i&&(e<i?t.left.container.style.marginLeft=`${i-e}px`:t.right.container.style.marginRight=`${e-i}px`)}t.left&&(this.showSinglePage(t.left),t.right?t.left.container.removeAttribute("data-vivliostyle-unpaired-page"):t.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),t.right&&(this.showSinglePage(t.right),t.left?t.right.container.removeAttribute("data-vivliostyle-unpaired-page"):t.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let t=V("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(e=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?Hn(i.fetchers):F(!0)).then(()=>{this.sendLocationNotification(i,e).thenFinish(t)})}),t.result()}createViewport(){let t=this.viewportElement;if(this.viewportSize){let e=this.viewportSize;return t.style.marginLeft=`${e.marginLeft}px`,t.style.marginRight=`${e.marginRight}px`,t.style.marginTop=`${e.marginTop}px`,t.style.marginBottom=`${e.marginBottom}px`,new Gs(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new Gs(this.window,this.fontSize,this.pixelRatio,t)}resolveSpreadView(t,e){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;default:return t!=null&&(t.width-this.pref.pageBorder)/t.height>=(e?e.width*2/e.height:1.45)&&(!!e||t.width>800)}}updateSpreadView(t){this.pref.spreadView=t,this.viewportElement.setAttribute(bk,t.toString())}sizeIsGood(){var t;let e=this.createViewport(),i=((t=this.opfView)==null?void 0:t.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(e,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&&e.width==this.viewport.width&&e.height==this.viewport.height||!r&&e.width==this.viewport.width&&e.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=e.width,this.viewport.height=e.height,this.needRefresh=!0,!0):!1}setPageSize(t,e,i,n){this.pageSizes[n]=t,this.setPageSizePageRules(e,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,t))}setPageSizePageRules(t,e,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let s=function(g){let m=g*.75;return Math.ceil(m)};var o=s;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=s(a),c=s(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(t){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,F(!0);let e=Ie(_n(this.cmykReserveMapUrl),an),i=V("loadCmykReserveMap");return t.loadAsJSON(e).then(n=>{ky(n)?this.cmykReserveMap=n:(Y.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new wk(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,t.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,!!e).thenAsync(n=>!n.left&&!n.right?F(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(t),this.setPageZoom(t),this.currentPage=t,F(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=t.side==="left"?n.left:n.right,F(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,F(null))}setPageZoom(t){var e;let i=this.getAdjustedZoomFactor(t.dimensions);(e=this.viewport)==null||e.zoom(t.dimensions.width,t.dimensions.height,i)}setSpreadZoom(t){var e;let i=this.getSpreadDimensions(t);(e=this.viewport)==null||e.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(t){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(t):this.zoom}getSpreadDimensions(t){let e=0,i=0;return t.left&&(e+=t.left.dimensions.width,i=t.left.dimensions.height),t.right&&(e+=t.right.dimensions.width,i=Math.max(i,t.right.dimensions.height)),t.left&&t.right&&(e+=this.pref.pageBorder*2,e+=Math.abs(t.left.dimensions.width-t.right.dimensions.width)),{width:e,height:i}}queryZoomFactor(t){if(!this.currentPage)throw new Error("no page exists.");if(t==="fit inside viewport"){let e;return this.pref.spreadView?(this.currentSpread,e=this.getSpreadDimensions(this.currentSpread)):e=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(e)}else throw new Error(`unknown zoom type: ${t}`)}calculateZoomFactorToFitInsideViewPort(t){if(!this.viewport)return this.zoom;let e=this.viewport.width/t.width,i=this.viewport.height/t.height;return Math.min(e,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Gc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return F(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=Hr().getScheduler().run(()=>hn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,Nt.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){e.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():F(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),Nt.registerEndTiming("render (resize)"),bi&&Hg(this.window)?iC(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(n))})})})})})},(e,i)=>{if(i instanceof Gc)Nt.registerEndTiming("render (resize)"),Y.debug(i.message);else throw i}));return F(!0)}sendLocationNotification(t,e){let i=V("sendLocationNotification"),n={t:"nav",first:t.isFirstPage,last:this.isLastPageForNotification(t),metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,e&&(n.cfi=e),this.callback(n),i.finish(!0)}),i.result()}isLastPageForNotification(t){if(!this.opfView||!this.pagePosition)return t.isLastPage;let e=this.opfView.spineItems[this.pagePosition.spineIndex];if(!e||!e.complete)return!1;let i=e.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===e.pages.length-1;return i&&n}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(t){var e;let i;if(this.readyState!=="complete"&&t.where!=="next"&&this.setReadyState("loading"),typeof t.where=="string"){let r;switch(t.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 F(!0)}i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages)}else if(typeof t.epage=="number"){let r=t.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let r=t.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((e=t.position)==null?void 0:e.spineIndex)=="number"){let r=t.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return F(!0);if(!this.opfView)return F(!0);let n=V("moveTo");return i.call(this.opfView).then(r=>{let o;if(r){this.pagePosition=r.position;let s=V("moveTo.showCurrent");o=s.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(s)})}else o=F(!0);o.then(s=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(s)})}),n.result()}showTOC(t){let e=!!t.autohide,i=t.v,n=this.opfView.isTOCVisible(),r=e!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return F(!0)}else if(i=="hide")return F(!0);if(n&&i!="show")return this.opfView.hideTOC(),F(!0);{let o=V("showTOC");return this.opfView.showTOC(e).then(s=>{if(s){if(r&&(s.listeners={}),e){let a=()=>{this.opfView.hideTOC()};s.addEventListener("hyperlink",a,!1)}s.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(t){let e=t.a||"";return hn("runCommand",i=>{let n=this.actions[e];n?n.call(this,t).then(()=>{this.callback({t:"done",a:e}),i.finish(!0)}):(Y.error("No such action:",e),i.finish(!0))},(i,n)=>{Y.error(n,"Error during action:",e),i.finish(!0)})}initEmbed(t){let e=jc(t),i=null,n=this;Hv(()=>{let r=V("commandLoop"),o=Hr().getScheduler();return n.hyperlinkListener=s=>{let a=s,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){s.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};o.run(()=>(n.callback(l),F(!0)))}},r.loopWithFrame(s=>{if(n.needResize)n.resize().then(()=>{s.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{s.continueLoop()});else if(e){let a=e;e=null,n.runCommand(a).then(()=>{s.continueLoop()})}else{let a=V("waitForCommand");i=a.suspend(this),a.result().then(()=>{s.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>e?!1:(e=jc(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},um=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(um||{}),Gc=class cm extends Error{constructor(){var e;super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,cm.prototype),this.stack=(e=new Error().stack)!=null?e:""}};function jc(t){return typeof t=="string"?Yl(t):t}var Xc=Xl;function Sk(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function qc(t){let e={};return Object.keys(t).forEach(i=>{let n=t[i];switch(i){case"autoResize":e.autoresize=n;break;case"pageBorderWidth":e.pageBorder=n;break;default:e[i]=n}}),e}var dm=class{constructor(t,e){u(this,"settings",t),u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),Jc(!!t.debug),this.adaptViewer_=new xk(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=Sk(),e&&this.setOptions(e),this.eventTarget=new Jl,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},qc(t));this.adaptViewer_.sendCommand(e),Object.assign(this.options,t)}dispatcher(t){let e={type:t.t},i=t;Object.keys(i).forEach(n=>{n!=="t"&&(e[n]=i[n])}),this.eventTarget.dispatchEvent(e)}addListener(t,e){t==="paginationprogress"&&this.adaptViewer_.ensurePaginationProgressListener(),this.eventTarget.addEventListener(t,e,!1)}removeListener(t,e){var i;this.eventTarget.removeEventListener(t,e,!1),t==="paginationprogress"&&!((i=this.eventTarget.listeners[t])!=null&&i.length)&&this.adaptViewer_.removePaginationProgressListener()}loadDocument(t,e,i){if(!t||(Array.isArray(t)?!t[0]||typeof t[0]!="string"&&!t[0].url:typeof t!="string"&&!t.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(t,null,e,i)}loadPublication(t,e,i){if(!t){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,t,e,i)}loadDocumentOrPublication(t,e,i,n){let r=i||{};function o(l){if(l)return l.flatMap(c=>{let d=c.url||null,p=c.text||null;return p!==null?[{url:d,text:p}]:d!==null?[{url:d}]:[]})}let s=o(r.authorStyleSheet),a=o(r.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Ck(t)||e,document:r.documentObject,fragment:r.fragment,authorStyleSheet:s,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},qc(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(t){switch(t){case"left":return this.getCurrentPageProgression()===Xc.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Xc.LTR?"next":"previous";default:return t}}navigateToPage(t,e){t==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:e}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(t)})}navigateToInternalUrl(t){this.adaptViewer_.sendCommand({a:"moveTo",url:t})}navigateToPosition(t){var e,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:t.spineIndex,pageIndex:(e=t.pageIndex)!=null?e:-1,offsetInItem:(i=t.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(t,e){let i=t==null?"toggle":t?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:e})}queryZoomFactor(t){return this.adaptViewer_.queryZoomFactor(t)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var t,e,i;return(i=(e=(t=this.adaptViewer_.opfView)==null?void 0:t.tocView)==null?void 0:e.getTOC())!=null?i:[]}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var t;let e=(t=this.adaptViewer_)==null?void 0:t.opfView;return e!=null&&e.cmykStore?e.cmykStore.toJSON():{}}};function Ck(t){function e(n){return typeof n=="number"?n:null}function i(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:e(n.startPage),skipPagesBefore:e(n.skipPagesBefore)}}return Array.isArray(t)?t.map(i):t?[i(t)]:null}var pm=(t=>(t.PREVIOUS="previous",t.NEXT="next",t.LEFT="left",t.RIGHT="right",t.FIRST="first",t.LAST="last",t.EPAGE="epage",t))(pm||{}),kk=um,Pk=hm;Nt.forceRegisterEndTiming("load_vivliostyle");var Ek=class{constructor(t,{title:e="",printCallback:i=s=>s.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:o=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin",null),u(this,"window"),this.htmlDoc=t,this.title=e,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=o,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=`
1879
1883
  <!DOCTYPE html>
1880
1884
  <html data-vivliostyle-paginated="true">
1881
1885
  <head>
@@ -1903,6 +1907,6 @@ span[data-viv-leader] {
1903
1907
  <body onload='parent.printInstance.runInIframe(window)'>
1904
1908
  <div id="vivliostyle-viewer-viewport"></div>
1905
1909
  </body>
1906
- </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 bg({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1907
- `);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 sC(e,t){new oC(e,t).init()}});var aC={};Og(aC,{printHTML:()=>kg.printHTML});module.exports=Mg(aC);var kg=Bg(Cg());
1910
+ </html>`,document.body.appendChild(this.iframe)}runInIframe(t){return this.iframeWin=t,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let t=new Blob([this.htmlDoc],{type:"text/html"}),e=URL.createObjectURL(t),i=new dm({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var o,s;let a=(s=(o=r.content.error)==null?void 0:o.toString())!=null?s:r.content.messages.join(`
1911
+ `);this.errorCallback(a)}),i.loadDocument({url:e})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.remove()}};function Nk(t,e){new Ek(t,e)}});var Tk={};Em(Tk,{printHTML:()=>mm.printHTML});module.exports=Tm(Tk);var mm=Nm(gm());
1908
1912
  //# sourceMappingURL=index.cjs.js.map