@vivliostyle/print 2.31.1 → 2.31.2

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,10 +1,10 @@
1
- var nc=Object.create;var vn=Object.defineProperty;var sc=Object.getOwnPropertyDescriptor;var rc=Object.getOwnPropertyNames;var oc=Object.getPrototypeOf,ac=Object.prototype.hasOwnProperty;var lc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hc=(e,t)=>{for(var i in t)vn(e,i,{get:t[i],enumerable:!0})},mo=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rc(t))!ac.call(e,s)&&s!==i&&vn(e,s,{get:()=>t[s],enumerable:!(n=sc(t,s))||n.enumerable});return e};var uc=(e,t,i)=>(i=e!=null?nc(oc(e)):{},mo(t||!e||!e.__esModule?vn(i,"default",{value:e,enumerable:!0}):i,e)),cc=e=>mo(vn({},"__esModule",{value:!0}),e);var Ju=lc((Zw,Zu)=>{"use strict";var dc=Object.create,dn=Object.defineProperty,pc=Object.getOwnPropertyDescriptor,fc=Object.getOwnPropertyNames,gc=Object.getPrototypeOf,mc=Object.prototype.hasOwnProperty,wc=(e,t,i)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,bc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yc=(e,t)=>{for(var i in t)dn(e,i,{get:t[i],enumerable:!0})},$a=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of fc(t))!mc.call(e,s)&&s!==i&&dn(e,s,{get:()=>t[s],enumerable:!(n=pc(t,s))||n.enumerable});return e},vc=(e,t,i)=>(i=e!=null?dc(gc(e)):{},$a(t||!e||!e.__esModule?dn(i,"default",{value:e,enumerable:!0}):i,e)),xc=e=>$a(dn({},"__esModule",{value:!0}),e),u=(e,t,i)=>wc(e,typeof t!="symbol"?t+"":t,i),Sc=bc((e,t)=>{var i=-1,n=1,s=0;function r(x,P,C,E,A){if(x===P)return x?[[s,x]]:[];if(C!=null){var R=de(x,P,C);if(R)return R}var O=l(x,P),z=x.substring(0,O);x=x.substring(O),P=P.substring(O),O=p(x,P);var $=x.substring(x.length-O);x=x.substring(0,x.length-O),P=P.substring(0,P.length-O);var X=o(x,P);return z&&X.unshift([s,z]),$&&X.push([s,$]),I(X,A),E&&f(X),X}function o(x,P){var C;if(!x)return[[n,P]];if(!P)return[[i,x]];var E=x.length>P.length?x:P,A=x.length>P.length?P:x,R=E.indexOf(A);if(R!==-1)return C=[[n,E.substring(0,R)],[s,A],[n,E.substring(R+A.length)]],x.length>P.length&&(C[0][0]=C[2][0]=i),C;if(A.length===1)return[[i,x],[n,P]];var O=d(x,P);if(O){var z=O[0],$=O[1],X=O[2],Y=O[3],q=O[4],me=r(z,X),te=r($,Y);return me.concat([[s,q]],te)}return a(x,P)}function a(x,P){for(var C=x.length,E=P.length,A=Math.ceil((C+E)/2),R=A,O=2*A,z=new Array(O),$=new Array(O),X=0;X<O;X++)z[X]=-1,$[X]=-1;z[R+1]=0,$[R+1]=0;for(var Y=C-E,q=Y%2!==0,me=0,te=0,se=0,ye=0,be=0;be<A;be++){for(var Z=-be+me;Z<=be-te;Z+=2){var H=R+Z,oe;Z===-be||Z!==be&&z[H-1]<z[H+1]?oe=z[H+1]:oe=z[H-1]+1;for(var M=oe-Z;oe<C&&M<E&&x.charAt(oe)===P.charAt(M);)oe++,M++;if(z[H]=oe,oe>C)te+=2;else if(M>E)me+=2;else if(q){var Q=R+Y-Z;if(Q>=0&&Q<O&&$[Q]!==-1){var ee=C-$[Q];if(oe>=ee)return h(x,P,oe,M)}}}for(var he=-be+se;he<=be-ye;he+=2){var Q=R+he,ee;he===-be||he!==be&&$[Q-1]<$[Q+1]?ee=$[Q+1]:ee=$[Q-1]+1;for(var Ye=ee-he;ee<C&&Ye<E&&x.charAt(C-ee-1)===P.charAt(E-Ye-1);)ee++,Ye++;if($[Q]=ee,ee>C)ye+=2;else if(Ye>E)se+=2;else if(!q){var H=R+Y-he;if(H>=0&&H<O&&z[H]!==-1){var oe=z[H],M=R+oe-H;if(ee=C-ee,oe>=ee)return h(x,P,oe,M)}}}}return[[i,x],[n,P]]}function h(x,P,C,E){var A=x.substring(0,C),R=P.substring(0,E),O=x.substring(C),z=P.substring(E),$=r(A,R),X=r(O,z);return $.concat(X)}function l(x,P){if(!x||!P||x.charAt(0)!==P.charAt(0))return 0;for(var C=0,E=Math.min(x.length,P.length),A=E,R=0;C<A;)x.substring(R,A)==P.substring(R,A)?(C=A,R=C):E=A,A=Math.floor((E-C)/2+C);return L(x.charCodeAt(A-1))&&A--,A}function c(x,P){var C=x.length,E=P.length;if(C==0||E==0)return 0;C>E?x=x.substring(C-E):C<E&&(P=P.substring(0,C));var A=Math.min(C,E);if(x==P)return A;for(var R=0,O=1;;){var z=x.substring(A-O),$=P.indexOf(z);if($==-1)return R;O+=$,($==0||x.substring(A-O)==P.substring(0,O))&&(R=O,O++)}}function p(x,P){if(!x||!P||x.slice(-1)!==P.slice(-1))return 0;for(var C=0,E=Math.min(x.length,P.length),A=E,R=0;C<A;)x.substring(x.length-A,x.length-R)==P.substring(P.length-A,P.length-R)?(C=A,R=C):E=A,A=Math.floor((E-C)/2+C);return _(x.charCodeAt(x.length-A))&&A--,A}function d(x,P){var C=x.length>P.length?x:P,E=x.length>P.length?P:x;if(C.length<4||E.length*2<C.length)return null;function A(te,se,ye){for(var be=te.substring(ye,ye+Math.floor(te.length/4)),Z=-1,H="",oe,M,Q,ee;(Z=se.indexOf(be,Z+1))!==-1;){var he=l(te.substring(ye),se.substring(Z)),Ye=p(te.substring(0,ye),se.substring(0,Z));H.length<Ye+he&&(H=se.substring(Z-Ye,Z)+se.substring(Z,Z+he),oe=te.substring(0,ye-Ye),M=te.substring(ye+he),Q=se.substring(0,Z-Ye),ee=se.substring(Z+he))}return H.length*2>=te.length?[oe,M,Q,ee,H]:null}var R=A(C,E,Math.ceil(C.length/4)),O=A(C,E,Math.ceil(C.length/2)),z;if(!R&&!O)return null;O?R?z=R[4].length>O[4].length?R:O:z=O:z=R;var $,X,Y,q;x.length>P.length?($=z[0],X=z[1],Y=z[2],q=z[3]):(Y=z[0],q=z[1],$=z[2],X=z[3]);var me=z[4];return[$,X,Y,q,me]}function f(x){for(var P=!1,C=[],E=0,A=null,R=0,O=0,z=0,$=0,X=0;R<x.length;)x[R][0]==s?(C[E++]=R,O=$,z=X,$=0,X=0,A=x[R][1]):(x[R][0]==n?$+=x[R][1].length:X+=x[R][1].length,A&&A.length<=Math.max(O,z)&&A.length<=Math.max($,X)&&(x.splice(C[E-1],0,[i,A]),x[C[E-1]+1][0]=n,E--,E--,R=E>0?C[E-1]:-1,O=0,z=0,$=0,X=0,A=null,P=!0)),R++;for(P&&I(x),S(x),R=1;R<x.length;){if(x[R-1][0]==i&&x[R][0]==n){var Y=x[R-1][1],q=x[R][1],me=c(Y,q),te=c(q,Y);me>=te?(me>=Y.length/2||me>=q.length/2)&&(x.splice(R,0,[s,q.substring(0,me)]),x[R-1][1]=Y.substring(0,Y.length-me),x[R+1][1]=q.substring(me),R++):(te>=Y.length/2||te>=q.length/2)&&(x.splice(R,0,[s,Y.substring(0,te)]),x[R-1][0]=n,x[R-1][1]=q.substring(0,q.length-te),x[R+1][0]=i,x[R+1][1]=Y.substring(te),R++),R++}R++}}var g=/[^a-zA-Z0-9]/,m=/\s/,y=/[\r\n]/,b=/\n\r?\n$/,w=/^\r?\n\r?\n/;function S(x){function P(te,se){if(!te||!se)return 6;var ye=te.charAt(te.length-1),be=se.charAt(0),Z=ye.match(g),H=be.match(g),oe=Z&&ye.match(m),M=H&&be.match(m),Q=oe&&ye.match(y),ee=M&&be.match(y),he=Q&&te.match(b),Ye=ee&&se.match(w);return he||Ye?5:Q||ee?4:Z&&!oe&&M?3:oe||M?2:Z||H?1:0}for(var C=1;C<x.length-1;){if(x[C-1][0]==s&&x[C+1][0]==s){var E=x[C-1][1],A=x[C][1],R=x[C+1][1],O=p(E,A);if(O){var z=A.substring(A.length-O);E=E.substring(0,E.length-O),A=z+A.substring(0,A.length-O),R=z+R}for(var $=E,X=A,Y=R,q=P(E,A)+P(A,R);A.charAt(0)===R.charAt(0);){E+=A.charAt(0),A=A.substring(1)+R.charAt(0),R=R.substring(1);var me=P(E,A)+P(A,R);me>=q&&(q=me,$=E,X=A,Y=R)}x[C-1][1]!=$&&($?x[C-1][1]=$:(x.splice(C-1,1),C--),x[C][1]=X,Y?x[C+1][1]=Y:(x.splice(C+1,1),C--))}C++}}function I(x,P){x.push([s,""]);for(var C=0,E=0,A=0,R="",O="",z;C<x.length;){if(C<x.length-1&&!x[C][1]){x.splice(C,1);continue}switch(x[C][0]){case n:A++,O+=x[C][1],C++;break;case i:E++,R+=x[C][1],C++;break;case s:var $=C-A-E-1;if(P){if($>=0&&W(x[$][1])){var X=x[$][1].slice(-1);if(x[$][1]=x[$][1].slice(0,-1),R=X+R,O=X+O,!x[$][1]){x.splice($,1),C--;var Y=$-1;x[Y]&&x[Y][0]===n&&(A++,O=x[Y][1]+O,Y--),x[Y]&&x[Y][0]===i&&(E++,R=x[Y][1]+R,Y--),$=Y}}if(U(x[C][1])){var X=x[C][1].charAt(0);x[C][1]=x[C][1].slice(1),R+=X,O+=X}}if(C<x.length-1&&!x[C][1]){x.splice(C,1);break}if(R.length>0||O.length>0){R.length>0&&O.length>0&&(z=l(O,R),z!==0&&($>=0?x[$][1]+=O.substring(0,z):(x.splice(0,0,[s,O.substring(0,z)]),C++),O=O.substring(z),R=R.substring(z)),z=p(O,R),z!==0&&(x[C][1]=O.substring(O.length-z)+x[C][1],O=O.substring(0,O.length-z),R=R.substring(0,R.length-z)));var q=A+E;R.length===0&&O.length===0?(x.splice(C-q,q),C=C-q):R.length===0?(x.splice(C-q,q,[n,O]),C=C-q+1):O.length===0?(x.splice(C-q,q,[i,R]),C=C-q+1):(x.splice(C-q,q,[i,R],[n,O]),C=C-q+2)}C!==0&&x[C-1][0]===s?(x[C-1][1]+=x[C][1],x.splice(C,1)):C++,A=0,E=0,R="",O="";break}}x[x.length-1][1]===""&&x.pop();var me=!1;for(C=1;C<x.length-1;)x[C-1][0]===s&&x[C+1][0]===s&&(x[C][1].substring(x[C][1].length-x[C-1][1].length)===x[C-1][1]?(x[C][1]=x[C-1][1]+x[C][1].substring(0,x[C][1].length-x[C-1][1].length),x[C+1][1]=x[C-1][1]+x[C+1][1],x.splice(C-1,1),me=!0):x[C][1].substring(0,x[C+1][1].length)==x[C+1][1]&&(x[C-1][1]+=x[C+1][1],x[C][1]=x[C][1].substring(x[C+1][1].length)+x[C+1][1],x.splice(C+1,1),me=!0)),C++;me&&I(x,P)}function L(x){return x>=55296&&x<=56319}function _(x){return x>=56320&&x<=57343}function U(x){return _(x.charCodeAt(0))}function W(x){return L(x.charCodeAt(x.length-1))}function re(x){for(var P=[],C=0;C<x.length;C++)x[C][1].length>0&&P.push(x[C]);return P}function He(x,P,C,E){return W(x)||U(E)?null:re([[s,x],[i,P],[n,C],[s,E]])}function de(x,P,C){var E=typeof C=="number"?{index:C,length:0}:C.oldRange,A=typeof C=="number"?null:C.newRange,R=x.length,O=P.length;if(E.length===0&&(A===null||A.length===0)){var z=E.index,$=x.slice(0,z),X=x.slice(z),Y=A?A.index:null;e:{var q=z+O-R;if(Y!==null&&Y!==q||q<0||q>O)break e;var me=P.slice(0,q),te=P.slice(q);if(te!==X)break e;var se=Math.min(z,q),ye=$.slice(0,se),be=me.slice(0,se);if(ye!==be)break e;var Z=$.slice(se),H=me.slice(se);return He(ye,Z,H,X)}e:{if(Y!==null&&Y!==z)break e;var oe=z,me=P.slice(0,oe),te=P.slice(oe);if(me!==$)break e;var M=Math.min(R-oe,O-oe),Q=X.slice(X.length-M),ee=te.slice(te.length-M);if(Q!==ee)break e;var Z=X.slice(0,X.length-M),H=te.slice(0,te.length-M);return He($,Z,H,Q)}}if(E.length>0&&A&&A.length===0)e:{var ye=x.slice(0,E.index),Q=x.slice(E.index+E.length),se=ye.length,M=Q.length;if(O<se+M)break e;var be=P.slice(0,se),ee=P.slice(O-M);if(ye!==be||Q!==ee)break e;var Z=x.slice(se,R-M),H=P.slice(se,O-M);return He(ye,Z,H,Q)}return null}function pe(x,P,C,E){return r(x,P,C,E,!0)}pe.INSERT=n,pe.DELETE=i,pe.EQUAL=s,t.exports=pe}),Ga={};yc(Ga,{CoreViewer:()=>Yu,HOOKS:()=>ts,Navigation:()=>Ku,PageProgression:()=>Tr,PageSide:()=>Xa,PageViewMode:()=>Hw,Profiler:()=>Za,ReadyState:()=>qa,UserAgentBaseCss:()=>Gl,UserAgentPageCss:()=>$l,UserAgentTocCss:()=>Wl,UserAgentXml:()=>Hl,ValidationTxt:()=>Ul,VivliostylePolyfillCss:()=>jl,VivliostyleViewportCss:()=>Vl,VivliostyleViewportScreenCss:()=>Dl,ZoomType:()=>Uw,getHooksForName:()=>pt,isDebug:()=>Qi,pageProgressionOf:()=>ja,plugin:()=>Ec,printHTML:()=>Gw,profile:()=>Tc,profiler:()=>et,registerHook:()=>ht,removeHook:()=>Ka,setDebug:()=>Wa});Zu.exports=xc(Ga);var Qi=!1;function Wa(e){Qi=e}var Tr=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Tr||{});function ja(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Xa=(e=>(e.LEFT="left",e.RIGHT="right",e))(Xa||{}),qa=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(qa||{}),Ya=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Ya||{}),Cc=class{constructor(e){this.opt_console=e,u(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=xn(arguments);this.consoleDebug(Sn(t)),this.triggerListeners(1,t)}info(...e){let t=xn(arguments);this.consoleInfo(Sn(t)),this.triggerListeners(2,t)}warn(...e){let t=xn(arguments);this.consoleWarn(Sn(t)),this.triggerListeners(3,t)}error(...e){let t=xn(arguments);this.consoleError(Sn(t)),this.triggerListeners(4,t)}};function xn(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Sn(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ var sc=Object.create;var Sn=Object.defineProperty;var rc=Object.getOwnPropertyDescriptor;var oc=Object.getOwnPropertyNames;var ac=Object.getPrototypeOf,lc=Object.prototype.hasOwnProperty;var hc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),uc=(e,t)=>{for(var i in t)Sn(e,i,{get:t[i],enumerable:!0})},wo=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of oc(t))!lc.call(e,s)&&s!==i&&Sn(e,s,{get:()=>t[s],enumerable:!(n=rc(t,s))||n.enumerable});return e};var cc=(e,t,i)=>(i=e!=null?sc(ac(e)):{},wo(t||!e||!e.__esModule?Sn(i,"default",{value:e,enumerable:!0}):i,e)),dc=e=>wo(Sn({},"__esModule",{value:!0}),e);var Qu=hc((Jw,Ju)=>{"use strict";var pc=Object.create,fn=Object.defineProperty,fc=Object.getOwnPropertyDescriptor,gc=Object.getOwnPropertyNames,mc=Object.getPrototypeOf,wc=Object.prototype.hasOwnProperty,bc=(e,t,i)=>t in e?fn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,vc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yc=(e,t)=>{for(var i in t)fn(e,i,{get:t[i],enumerable:!0})},Ga=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of gc(t))!wc.call(e,s)&&s!==i&&fn(e,s,{get:()=>t[s],enumerable:!(n=fc(t,s))||n.enumerable});return e},xc=(e,t,i)=>(i=e!=null?pc(mc(e)):{},Ga(t||!e||!e.__esModule?fn(i,"default",{value:e,enumerable:!0}):i,e)),Sc=e=>Ga(fn({},"__esModule",{value:!0}),e),u=(e,t,i)=>bc(e,typeof t!="symbol"?t+"":t,i),Cc=vc((e,t)=>{var i=-1,n=1,s=0;function r(x,P,C,E,R){if(x===P)return x?[[s,x]]:[];if(C!=null){var A=de(x,P,C);if(A)return A}var O=l(x,P),z=x.substring(0,O);x=x.substring(O),P=P.substring(O),O=p(x,P);var $=x.substring(x.length-O);x=x.substring(0,x.length-O),P=P.substring(0,P.length-O);var X=o(x,P);return z&&X.unshift([s,z]),$&&X.push([s,$]),I(X,R),E&&f(X),X}function o(x,P){var C;if(!x)return[[n,P]];if(!P)return[[i,x]];var E=x.length>P.length?x:P,R=x.length>P.length?P:x,A=E.indexOf(R);if(A!==-1)return C=[[n,E.substring(0,A)],[s,R],[n,E.substring(A+R.length)]],x.length>P.length&&(C[0][0]=C[2][0]=i),C;if(R.length===1)return[[i,x],[n,P]];var O=d(x,P);if(O){var z=O[0],$=O[1],X=O[2],Y=O[3],q=O[4],me=r(z,X),te=r($,Y);return me.concat([[s,q]],te)}return a(x,P)}function a(x,P){for(var C=x.length,E=P.length,R=Math.ceil((C+E)/2),A=R,O=2*R,z=new Array(O),$=new Array(O),X=0;X<O;X++)z[X]=-1,$[X]=-1;z[A+1]=0,$[A+1]=0;for(var Y=C-E,q=Y%2!==0,me=0,te=0,se=0,ve=0,be=0;be<R;be++){for(var K=-be+me;K<=be-te;K+=2){var H=A+K,oe;K===-be||K!==be&&z[H-1]<z[H+1]?oe=z[H+1]:oe=z[H-1]+1;for(var M=oe-K;oe<C&&M<E&&x.charAt(oe)===P.charAt(M);)oe++,M++;if(z[H]=oe,oe>C)te+=2;else if(M>E)me+=2;else if(q){var Q=A+Y-K;if(Q>=0&&Q<O&&$[Q]!==-1){var ee=C-$[Q];if(oe>=ee)return h(x,P,oe,M)}}}for(var he=-be+se;he<=be-ve;he+=2){var Q=A+he,ee;he===-be||he!==be&&$[Q-1]<$[Q+1]?ee=$[Q+1]:ee=$[Q-1]+1;for(var Ye=ee-he;ee<C&&Ye<E&&x.charAt(C-ee-1)===P.charAt(E-Ye-1);)ee++,Ye++;if($[Q]=ee,ee>C)ve+=2;else if(Ye>E)se+=2;else if(!q){var H=A+Y-he;if(H>=0&&H<O&&z[H]!==-1){var oe=z[H],M=A+oe-H;if(ee=C-ee,oe>=ee)return h(x,P,oe,M)}}}}return[[i,x],[n,P]]}function h(x,P,C,E){var R=x.substring(0,C),A=P.substring(0,E),O=x.substring(C),z=P.substring(E),$=r(R,A),X=r(O,z);return $.concat(X)}function l(x,P){if(!x||!P||x.charAt(0)!==P.charAt(0))return 0;for(var C=0,E=Math.min(x.length,P.length),R=E,A=0;C<R;)x.substring(A,R)==P.substring(A,R)?(C=R,A=C):E=R,R=Math.floor((E-C)/2+C);return L(x.charCodeAt(R-1))&&R--,R}function c(x,P){var C=x.length,E=P.length;if(C==0||E==0)return 0;C>E?x=x.substring(C-E):C<E&&(P=P.substring(0,C));var R=Math.min(C,E);if(x==P)return R;for(var A=0,O=1;;){var z=x.substring(R-O),$=P.indexOf(z);if($==-1)return A;O+=$,($==0||x.substring(R-O)==P.substring(0,O))&&(A=O,O++)}}function p(x,P){if(!x||!P||x.slice(-1)!==P.slice(-1))return 0;for(var C=0,E=Math.min(x.length,P.length),R=E,A=0;C<R;)x.substring(x.length-R,x.length-A)==P.substring(P.length-R,P.length-A)?(C=R,A=C):E=R,R=Math.floor((E-C)/2+C);return _(x.charCodeAt(x.length-R))&&R--,R}function d(x,P){var C=x.length>P.length?x:P,E=x.length>P.length?P:x;if(C.length<4||E.length*2<C.length)return null;function R(te,se,ve){for(var be=te.substring(ve,ve+Math.floor(te.length/4)),K=-1,H="",oe,M,Q,ee;(K=se.indexOf(be,K+1))!==-1;){var he=l(te.substring(ve),se.substring(K)),Ye=p(te.substring(0,ve),se.substring(0,K));H.length<Ye+he&&(H=se.substring(K-Ye,K)+se.substring(K,K+he),oe=te.substring(0,ve-Ye),M=te.substring(ve+he),Q=se.substring(0,K-Ye),ee=se.substring(K+he))}return H.length*2>=te.length?[oe,M,Q,ee,H]:null}var A=R(C,E,Math.ceil(C.length/4)),O=R(C,E,Math.ceil(C.length/2)),z;if(!A&&!O)return null;O?A?z=A[4].length>O[4].length?A:O:z=O:z=A;var $,X,Y,q;x.length>P.length?($=z[0],X=z[1],Y=z[2],q=z[3]):(Y=z[0],q=z[1],$=z[2],X=z[3]);var me=z[4];return[$,X,Y,q,me]}function f(x){for(var P=!1,C=[],E=0,R=null,A=0,O=0,z=0,$=0,X=0;A<x.length;)x[A][0]==s?(C[E++]=A,O=$,z=X,$=0,X=0,R=x[A][1]):(x[A][0]==n?$+=x[A][1].length:X+=x[A][1].length,R&&R.length<=Math.max(O,z)&&R.length<=Math.max($,X)&&(x.splice(C[E-1],0,[i,R]),x[C[E-1]+1][0]=n,E--,E--,A=E>0?C[E-1]:-1,O=0,z=0,$=0,X=0,R=null,P=!0)),A++;for(P&&I(x),S(x),A=1;A<x.length;){if(x[A-1][0]==i&&x[A][0]==n){var Y=x[A-1][1],q=x[A][1],me=c(Y,q),te=c(q,Y);me>=te?(me>=Y.length/2||me>=q.length/2)&&(x.splice(A,0,[s,q.substring(0,me)]),x[A-1][1]=Y.substring(0,Y.length-me),x[A+1][1]=q.substring(me),A++):(te>=Y.length/2||te>=q.length/2)&&(x.splice(A,0,[s,Y.substring(0,te)]),x[A-1][0]=n,x[A-1][1]=q.substring(0,q.length-te),x[A+1][0]=i,x[A+1][1]=Y.substring(te),A++),A++}A++}}var g=/[^a-zA-Z0-9]/,m=/\s/,v=/[\r\n]/,b=/\n\r?\n$/,w=/^\r?\n\r?\n/;function S(x){function P(te,se){if(!te||!se)return 6;var ve=te.charAt(te.length-1),be=se.charAt(0),K=ve.match(g),H=be.match(g),oe=K&&ve.match(m),M=H&&be.match(m),Q=oe&&ve.match(v),ee=M&&be.match(v),he=Q&&te.match(b),Ye=ee&&se.match(w);return he||Ye?5:Q||ee?4:K&&!oe&&M?3:oe||M?2:K||H?1:0}for(var C=1;C<x.length-1;){if(x[C-1][0]==s&&x[C+1][0]==s){var E=x[C-1][1],R=x[C][1],A=x[C+1][1],O=p(E,R);if(O){var z=R.substring(R.length-O);E=E.substring(0,E.length-O),R=z+R.substring(0,R.length-O),A=z+A}for(var $=E,X=R,Y=A,q=P(E,R)+P(R,A);R.charAt(0)===A.charAt(0);){E+=R.charAt(0),R=R.substring(1)+A.charAt(0),A=A.substring(1);var me=P(E,R)+P(R,A);me>=q&&(q=me,$=E,X=R,Y=A)}x[C-1][1]!=$&&($?x[C-1][1]=$:(x.splice(C-1,1),C--),x[C][1]=X,Y?x[C+1][1]=Y:(x.splice(C+1,1),C--))}C++}}function I(x,P){x.push([s,""]);for(var C=0,E=0,R=0,A="",O="",z;C<x.length;){if(C<x.length-1&&!x[C][1]){x.splice(C,1);continue}switch(x[C][0]){case n:R++,O+=x[C][1],C++;break;case i:E++,A+=x[C][1],C++;break;case s:var $=C-R-E-1;if(P){if($>=0&&W(x[$][1])){var X=x[$][1].slice(-1);if(x[$][1]=x[$][1].slice(0,-1),A=X+A,O=X+O,!x[$][1]){x.splice($,1),C--;var Y=$-1;x[Y]&&x[Y][0]===n&&(R++,O=x[Y][1]+O,Y--),x[Y]&&x[Y][0]===i&&(E++,A=x[Y][1]+A,Y--),$=Y}}if(U(x[C][1])){var X=x[C][1].charAt(0);x[C][1]=x[C][1].slice(1),A+=X,O+=X}}if(C<x.length-1&&!x[C][1]){x.splice(C,1);break}if(A.length>0||O.length>0){A.length>0&&O.length>0&&(z=l(O,A),z!==0&&($>=0?x[$][1]+=O.substring(0,z):(x.splice(0,0,[s,O.substring(0,z)]),C++),O=O.substring(z),A=A.substring(z)),z=p(O,A),z!==0&&(x[C][1]=O.substring(O.length-z)+x[C][1],O=O.substring(0,O.length-z),A=A.substring(0,A.length-z)));var q=R+E;A.length===0&&O.length===0?(x.splice(C-q,q),C=C-q):A.length===0?(x.splice(C-q,q,[n,O]),C=C-q+1):O.length===0?(x.splice(C-q,q,[i,A]),C=C-q+1):(x.splice(C-q,q,[i,A],[n,O]),C=C-q+2)}C!==0&&x[C-1][0]===s?(x[C-1][1]+=x[C][1],x.splice(C,1)):C++,R=0,E=0,A="",O="";break}}x[x.length-1][1]===""&&x.pop();var me=!1;for(C=1;C<x.length-1;)x[C-1][0]===s&&x[C+1][0]===s&&(x[C][1].substring(x[C][1].length-x[C-1][1].length)===x[C-1][1]?(x[C][1]=x[C-1][1]+x[C][1].substring(0,x[C][1].length-x[C-1][1].length),x[C+1][1]=x[C-1][1]+x[C+1][1],x.splice(C-1,1),me=!0):x[C][1].substring(0,x[C+1][1].length)==x[C+1][1]&&(x[C-1][1]+=x[C+1][1],x[C][1]=x[C][1].substring(x[C+1][1].length)+x[C+1][1],x.splice(C+1,1),me=!0)),C++;me&&I(x,P)}function L(x){return x>=55296&&x<=56319}function _(x){return x>=56320&&x<=57343}function U(x){return _(x.charCodeAt(0))}function W(x){return L(x.charCodeAt(x.length-1))}function re(x){for(var P=[],C=0;C<x.length;C++)x[C][1].length>0&&P.push(x[C]);return P}function He(x,P,C,E){return W(x)||U(E)?null:re([[s,x],[i,P],[n,C],[s,E]])}function de(x,P,C){var E=typeof C=="number"?{index:C,length:0}:C.oldRange,R=typeof C=="number"?null:C.newRange,A=x.length,O=P.length;if(E.length===0&&(R===null||R.length===0)){var z=E.index,$=x.slice(0,z),X=x.slice(z),Y=R?R.index:null;e:{var q=z+O-A;if(Y!==null&&Y!==q||q<0||q>O)break e;var me=P.slice(0,q),te=P.slice(q);if(te!==X)break e;var se=Math.min(z,q),ve=$.slice(0,se),be=me.slice(0,se);if(ve!==be)break e;var K=$.slice(se),H=me.slice(se);return He(ve,K,H,X)}e:{if(Y!==null&&Y!==z)break e;var oe=z,me=P.slice(0,oe),te=P.slice(oe);if(me!==$)break e;var M=Math.min(A-oe,O-oe),Q=X.slice(X.length-M),ee=te.slice(te.length-M);if(Q!==ee)break e;var K=X.slice(0,X.length-M),H=te.slice(0,te.length-M);return He($,K,H,Q)}}if(E.length>0&&R&&R.length===0)e:{var ve=x.slice(0,E.index),Q=x.slice(E.index+E.length),se=ve.length,M=Q.length;if(O<se+M)break e;var be=P.slice(0,se),ee=P.slice(O-M);if(ve!==be||Q!==ee)break e;var K=x.slice(se,A-M),H=P.slice(se,O-M);return He(ve,K,H,Q)}return null}function pe(x,P,C,E){return r(x,P,C,E,!0)}pe.INSERT=n,pe.DELETE=i,pe.EQUAL=s,t.exports=pe}),Wa={};yc(Wa,{CoreViewer:()=>Zu,HOOKS:()=>ts,Navigation:()=>Ku,PageProgression:()=>Ir,PageSide:()=>qa,PageViewMode:()=>$w,Profiler:()=>Ja,ReadyState:()=>Ya,UserAgentBaseCss:()=>Wl,UserAgentPageCss:()=>Gl,UserAgentTocCss:()=>jl,UserAgentXml:()=>$l,ValidationTxt:()=>Hl,VivliostylePolyfillCss:()=>Xl,VivliostyleViewportCss:()=>Ul,VivliostyleViewportScreenCss:()=>Vl,ZoomType:()=>Hw,getHooksForName:()=>pt,isDebug:()=>tn,pageProgressionOf:()=>Xa,plugin:()=>kc,printHTML:()=>Ww,profile:()=>Ic,profiler:()=>tt,registerHook:()=>ht,removeHook:()=>Ka,setDebug:()=>ja});Ju.exports=Sc(Wa);var tn=!1;function ja(e){tn=e}var Ir=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Ir||{});function Xa(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var qa=(e=>(e.LEFT="left",e.RIGHT="right",e))(qa||{}),Ya=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Ya||{}),Za=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Za||{}),Ec=class{constructor(e){this.opt_console=e,u(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=Cn(arguments);this.consoleDebug(En(t)),this.triggerListeners(1,t)}info(...e){let t=Cn(arguments);this.consoleInfo(En(t)),this.triggerListeners(2,t)}warn(...e){let t=Cn(arguments);this.consoleWarn(En(t)),this.triggerListeners(3,t)}error(...e){let t=Cn(arguments);this.consoleError(En(t)),this.triggerListeners(4,t)}};function Cn(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function En(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
2
2
  `])),n=n.concat([t.toString()]),i&&(n=n.concat([`
3
- `]).concat(i))),n}var D=new Cc,ts=(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))(ts||{}),Un={};function ht(e,t,i){if(!ts[e])D.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Un[e];n||(n=Un[e]=[]),i?n.unshift(t):n.push(t)}}function Ka(e,t){if(!ts[e])D.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Un[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function pt(e){return Un[e]||[]}var Ec={registerHook:ht,removeHook:Ka},Za=class{constructor(e){this.performanceInstance=e,u(this,"timestamps",{}),u(this,"registerTiming"),u(this,"registerStartTiming"),u(this,"registerEndTiming"),this.registerTiming=ti,this.registerStartTiming=this.registerStartTiming=ti,this.registerEndTiming=this.registerEndTiming=ti}forceRegisterStartTiming(e,t){ys.call(this,e,"start",t)}forceRegisterEndTiming(e,t){ys.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],s=n.length;for(let r=0;r<s;r++){let o=n[r];t+=i,s>1&&(t+=`(${r})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
4
- `}}),D.info(t)}disable(){this.registerTiming=ti,this.registerStartTiming=this.registerStartTiming=ti,this.registerEndTiming=this.registerEndTiming=ti}enable(){this.registerTiming=ys,this.registerStartTiming=this.registerStartTiming=wo,this.registerEndTiming=this.registerEndTiming=kc}isEnabled(){return this.registerStartTiming===wo}};function ti(){}function ys(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let s,r=n.length;for(let o=r-1;o>=0&&(s=n[o],!(s&&!s[t]));o--)s=null;s||(s={},n.push(s)),s[t]=i}function wo(e,t){this.registerTiming(e,"start",t)}function kc(e,t){this.registerTiming(e,"end",t)}var Nc={now:Date.now},Pc=window&&window.performance,et=new Za(Pc||Nc);et.forceRegisterStartTiming("load_vivliostyle");var Tc={profiler:{registerStartTiming:et.registerStartTiming,registerEndTiming:et.registerEndTiming,printTimings:et.printTimings,disable:et.disable,enable:et.enable}},Os=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,xt="data-adapt-eloff",Ic={};function Ir(e){return JSON.parse(e)}function Ct(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Rc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var yi=window.location.href;function bo(e){yi=e}var Zt=window.location.href;function yo(e){Zt=e}function ke(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Rc(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let s=t.substr(0,n+1)+e,r="";for(i=s.match(/^([^?#]*)([?#].*)$/),i&&(s=i[1],r=i[2]);n=s.indexOf("/../"),!(n<=0);){let o=s.lastIndexOf("/",n-1);if(o<=0)break;s=s.substr(0,o)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+r}function en(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function vo(e){return e==null?e:e.toString()}var Ac=class{constructor(){u(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let s=n*2;if(s>=i)break;if(this.queue[s].compare(t)>0)s+1<i&&this.queue[s+1].compare(this.queue[s])>0&&s++;else if(s+1<i&&this.queue[s+1].compare(t)>0)s++;else break;this.queue[n]=this.queue[s],n=s}this.queue[n]=t}return e}},Ja=["","-webkit-","-moz-"],ni={};function vs(e,t){return CSS.supports(e+t,"unset")}function Qa(e){let t=ni[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return ni[e]=null,null;case"text-combine-upright":if(vs("-webkit-","text-combine")&&!vs("","text-combine-upright"))return ni[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Ja)if(vs(i,e))return t=[i+e],ni[e]=t,t;return D.warn("Property not supported by the browser: ",e),ni[e]=null,null}function k(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let s=Qa(t);if(s)for(let r of s){switch(r){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(r,i)}}function li(e,t,i){try{let n=ni[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function Bs(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 kt=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 el(e){return`\\${e.charCodeAt(0).toString(16)} `}function Ft(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,el)}function pn(e){return e.replace(/[\u0000-\u001F"\\]/g,el)}function xo(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function So(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Lc(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function tl(e,t){function i(n){return Lc(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Rt(e){return tl(e)}function Fc(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Oc(e,t){t=typeof t=="string"?t:"\\u";function i(s){return Fc(s,t)}let n=new RegExp(`${Rt(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function Bt(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let s=i+n>>1;t(s)?n=s:i=s+1}}function il(e,t){return e-t}function Co(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function Bc(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function xs(e,t){let i={};for(let n of e){let s=t(n);s&&(i[s]?i[s].push(n):i[s]=[n])}return i}function _c(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Rr=class{constructor(){u(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let s=n.indexOf(t);s>=0&&n.splice(s,1)}}},jt={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function nl(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Mc(e){return`^${e}`}function Eo(e){return e.replace(/[\[\]\(\),=;^]/g,Mc)}function zc(e){return e.substr(1)}function _s(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,zc)}function Dc(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=_s(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function ko(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Dc(i[2]),e=e.substr(i[0].length)}return t}var No=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Po=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,s,r=Math.floor(this.index/2)-1;if(r<0||n==0)s=t.firstChild,e.node=s||t;else{if(s=i[Math.min(r,n-1)],this.index&1){let o=s.nextSibling;!o||o.nodeType==1?e.after=!0:s=o}e.node=s}if(this.id&&(e.after||this.id!=nl(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:D.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},To=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let s=i.nextSibling;if(3<=n&&n<=5){let r=i.textContent.length;if(t<=r)break;if(!s){t=r;break}t-=r}if(!s){t=0;break}i=s}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Eo(this.textBefore)),e.append(","),this.textAfter&&e.append(Eo(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Io=class sl{constructor(){u(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),s=0,r=[];for(;;){let o;switch(n.charAt(s)){case"/":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[3];o=ko(i[4]),r.push(new Po(a,h,vo(o.s)));break}case":":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=_s(h));let l=i[7];l&&(l=_s(l)),o=ko(i[10]),r.push(new To(a,h,l,vo(o.s)));break}case"!":s++,r.push(new No);break;case"~":case"@":case"":this.steps=r;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new sl,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,s){let r=[],o=t.parentNode,a="",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),r.push(new To(i,a,h,s)),s=null);o&&!(!o||o.nodeType==9);){let l=n?null:nl(t),c=n?1:0;for(;t;)t.nodeType==1&&(c+=2),t=t.previousSibling;r.push(new Po(c,l,s)),s=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new No),this.steps=r.concat(this.steps)):this.steps=r}toString(){if(!this.steps)return"";let t=new kt;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function rl(){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 ol(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 Vc=rl(),Ro={PENDING:{}};function al(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function Ss(e){return`"${pn(`${e}`)}"`}function Uc(e){return Ft(`${e}`)}function Ms(e,t){return e?`${Ft(e)}.${Ft(t)}`:Ft(t)}var ll=0,zs=class{constructor(e,t){if(this.parent=e,this.resolver=t,u(this,"scopeKey"),u(this,"children",[]),u(this,"zero"),u(this,"one"),u(this,"_true"),u(this,"_false"),u(this,"values",{}),u(this,"funcs",{}),u(this,"builtIns",{}),this.scopeKey=`S${ll++}`,this.zero=new Fe(this,0),this.one=new Fe(this,1),this._true=new Fe(this,!0),this._false=new Fe(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=al,i["css-string"]=Ss,i["css-name"]=Uc,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 Ss(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Ss(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new De(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 Hc(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function hl(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 $c(e){switch(e?.toLowerCase()){case"em":case"ex":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Gc(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var we={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,ex:8,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function ul(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 Ds=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,u(this,"actualPageWidth",null),u(this,"pageWidth"),u(this,"actualPageHeight",null),u(this,"pageHeight"),u(this,"initialFontSize"),u(this,"rootFontSize",null),u(this,"isRelativeRootFontSize",null),u(this,"fontSize"),u(this,"rootLineHeight",null),u(this,"pref"),u(this,"scopes",{}),u(this,"pageAreaWidth",null),u(this,"pageAreaHeight",null),u(this,"pageVertical",null),u(this,"pubTitle",null),u(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=Vc}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(hl(e)){let n=this.pageWidth()/100,s=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:s,a=i??this.pageVertical;switch(e){case"vw":return r;case"vh":return o;case"vi":return a?o:r;case"vb":return a?r:o;case"vmin":return r<o?r:o;case"vmax":return r>o?r:o;case"pvw":return n;case"pvh":return s;case"pvi":return a?s:n;case"pvb":return a?n:s;case"pvmin":return n<s?n:s;case"pvmax":return n>s?n:s}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="ex"?we.ex*(t?this.initialFontSize:this.fontSize())/we.em:e=="lh"||e=="rlh"?this.rootLineHeight:we[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let s=e.funcs[t];if(s||e.resolver&&(s=e.resolver.call(this,t,!0),s))return s;let r=e.builtIns[t];if(r){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new Fe(e,r.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let s=null,r=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(s=t.evaluate(this));break}switch(e){case"width":r=this.pageWidth();break;case"height":r=this.pageHeight();break;case"device-width":r=window.screen.availWidth;break;case"device-height":r=window.screen.availHeight;break;case"color":r=window.screen.pixelDepth;break}if(r!=null&&s!=null)switch(i){case"min":return r>=Number(s);case"max":return r<=Number(s);default:return r==s}else if(r!=null&&t==null)return r!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},ut=class{constructor(e){this.scope=e,u(this,"key"),this.scope=e,this.key=`_${ll++}`}toString(){let e=new kt;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===Ro.PENDING?!1:n;{i[this.key]=Ro.PENDING;let s=this.dependCore(e,t,i);return i[this.key]=s,s}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},cl=class extends ut{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},is=class extends ut{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},dl=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ci=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},pl=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ar=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Ot=class extends cl{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Wc=class extends Ot{constructor(e,t){super(e,t)}getOp(){return"not "}},fl=class extends cl{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Lr=class extends dl{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},jc=class extends Lr{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Fr=class extends dl{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Xc=class extends Fr{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},qc=class extends Fr{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Yc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},Kc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Zc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Vs=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Or=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Jc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},gl=class extends pl{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},ml=class extends pl{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Br=class extends Ar{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},wl=class extends Ar{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},bl=class extends Ar{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Jt=class extends ut{constructor(e,t,i){var n;super(e),this.num=t,u(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(Ft(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},ze=class extends ut{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},Ao=class extends ut{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(Ft(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},De=class extends ut{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function Qc(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function ed(e,t,i){let n=t;for(let s=0;s<t.length;s++){let r=t[s].expand(e,i);if(t!==n)n[s]=r;else if(r!==t[s]){n=Array(t.length);for(let o=0;o<s;o++)n[o]=t[o];n[s]=r}}return n}var $i=class yl extends ut{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Qc(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let s=0;s<this.params.length;s++)if(this.params[s].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=ed(t,this.params,i);return n===this.params?this:new yl(this.scope,this.qualifiedName,n)}},td=class vl extends ut{constructor(t,i,n,s){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=s}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),s=this.ifTrue.expand(t,i),r=this.ifFalse.expand(t,i);return n===this.cond&&s===this.ifTrue&&r===this.ifFalse?this:new vl(this.scope,n,s,r)}},Fe=class extends ut{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(pn(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Lo=class xl extends ut{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(pn(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 xl(this.scope,this.name,n)}},id=class extends ut{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Sl=class extends ut{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function lt(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 Lr(e,t,i)}function j(e,t,i){return t===e.zero?i:i===e.zero?t:new gl(e,t,i)}function ae(e,t,i){return t===e.zero?new fl(e,i):i===e.zero?t:new ml(e,t,i)}function An(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Br(e,t,i)}function Us(e,t,i){return t===e.zero?e.zero:i===e.one?t:new wl(e,t,i)}var It=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}},Ei=class extends It{constructor(){super(),u(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],s=n.visit(this);if(this.error)return[];if(t)t[i]=s;else if(n!==s){t=new Array(e.length);for(let r=0;r<i;r++)t[r]=e[r];t[i]=s}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new ve(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new qe(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new ki(e.name,t)}visitExpr(e){return e}},$e=class{toString(){let e=new kt;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new kt;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}},Cl=class El extends $e{static get instance(){return this.empty||(this.empty=new El),this.empty}constructor(){super()}toExpr(t,i){return new Fe(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};u(Cl,"empty");var nd=Cl,G=nd.instance,kl=class Nl extends $e{static get instance(){return this.slash||(this.slash=new Nl),this.slash}constructor(){super()}toExpr(t,i){return new Fe(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};u(kl,"slash");var sd=kl,ns=sd.instance,Ae=class extends $e{constructor(e){super(),this.str=e}toExpr(e,t){return new Fe(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(pn(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Hs={},ft=class extends $e{constructor(e){if(super(),this.name=e,Hs[e])throw new Error("E_INVALID_CALL");Hs[e]=this}toExpr(e,t){return new Fe(e,this.name)}appendTo(e,t){t?e.append(Ft(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=Hs[e];return t||(t=new ft(e)),t}var T=class extends $e{constructor(e,t){var i;super(),this.num=e,u(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Br(e,t,new Fe(e,this.num/100)):new Jt(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}},Vt=class extends $e{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Fe(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Qt=class extends Vt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Pl=class extends $e{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ct=class extends $e{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(pn(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Tl=class extends $e{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function _r(e,t,i,n){var s,r;let o=t.length;if(o>0){(s=t[0])==null||s.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(r=t[a])==null||r.appendTo(e,n)}}var ve=class extends $e{constructor(e){super(),this.values=e}appendTo(e,t){_r(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},qe=class extends $e{constructor(e){super(),this.values=e}appendTo(e,t){_r(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ki=class extends $e{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(Ft(this.name)),e.append("("),_r(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},V=class extends $e{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Fe||this.expr instanceof Jt?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}},Ai=class extends $e{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function We(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function Il(e,t){return new T(We(e,t),"px")}var v={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),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"),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")},Fo=new T(100,"%"),Ni=new T(100,"pvw"),Pi=new T(100,"pvh"),le=new T(0,"px"),rd=new Tl("U+0-10FFFF"),Oo={"font-size":1,"line-height":2,color:3};function J(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Bo(e,t){let i=Oo[e]||Number.MAX_VALUE,n=Oo[t]||Number.MAX_VALUE;return i-n}function Nt(e){return e?.length>2&&e.startsWith("--")}var nt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},At=class{constructor(e,t){this.x=e,this.y=t}},Cs=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},_o=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Et=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,u(this,"left",null),u(this,"right",null)}};function od(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var ss=class Rl{constructor(t){this.points=t}addSegments(t,i){let n=this.points,s=n.length,r=n[s-1];for(let o=0;o<s;o++){let a=n[o],h;r.y<a.y?h=new _o(r,a,1,i):h=new _o(a,r,-1,i),t.push(h),r=a}}withOffset(t,i){let n=[];for(let s of this.points)n.push(new At(s.x+t,s.y+i));return new Rl(n)}};function Mo(e,t,i,n){let s=[];for(let r=0;r<20;r++){let o=r*2*Math.PI/20;s.push(new At(e+i*Math.sin(o),t+n*Math.cos(o)))}return new ss(s)}function Mr(e,t,i,n){return new ss([new At(e,t),new At(i,t),new At(i,n),new At(e,n)])}var Cn=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function zo(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 ad(e,t,i,n){let s,r,o,a;t.high.y<i&&D.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=zo(t,i),r=t.winding):(s=t.low.x,r=0),t.high.y>=n?(o=zo(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(e.push(new Cn(s,r,t.shapeId,-1)),e.push(new Cn(o,a,t.shapeId,1))):(e.push(new Cn(o,a,t.shapeId,-1)),e.push(new Cn(s,r,t.shapeId,1)))}function ld(e,t,i){let n=t+i,s=Array(n),r=Array(n),o;for(o=0;o<=n;o++)s[o]=0,r[o]=0;let a=[],h=!1,l=e.length;for(let c=0;c<l;c++){let p=e[c];s[p.shapeId]+=p.winding,r[p.shapeId]+=p.lowOrHigh;let d=!1;for(o=0;o<t;o++)if(s[o]&&!r[o]){d=!0;break}if(d){for(o=t;o<=n;o++)if(s[o]||r[o]){d=!1;break}}h!=d&&(a.push(p.x),h=d)}return a}function hd(e,t){return t?Math.ceil(e/t)*t:e}function Do(e,t){return t?Math.floor(e/t)*t:e}function ud(e){return new At(e.y,-e.x)}function Hn(e){return new nt(e.y1,-e.x2,e.y2,-e.x1)}function Al(e){return new nt(-e.y2,e.x1,-e.y1,e.x2)}function Vo(e){return new ss(e.points.map(t=>ud(t)))}function cd(e,t,i,n,s,r){r&&(e=Hn(e),t=t.map(w=>Vo(w)),i=i.map(w=>Vo(w)));let o=t.length,a=i?i.length:0,h=[],l=[],c,p,d;for(c=0;c<o;c++)t[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+o);let f=l.length;l.sort(od);let g=0;for(;l[g].shapeId>=o;)g++;let m=l[g].low.y;m>e.y1&&h.push(new Et(e.y1,m,e.x2,e.x2));let y=0,b=[];for(;y<f&&(d=l[y]).low.y<m;)d.high.y>m&&b.push(d),y++;for(;y<f||b.length>0;){let w=e.y2,S=Math.min(hd(Math.ceil(m+n),s),e.y2);for(p=0;p<b.length&&w>S;p++)d=b[p],d.low.x==d.high.x?d.high.y<w&&(w=Math.max(Do(d.high.y,s),S)):d.low.x!=d.high.x&&(w=S);for(w>e.y2&&(w=e.y2);y<f&&(d=l[y]).low.y<w;){if(d.high.y<m){y++;continue}if(d.low.y<S)d.low.y==d.high.y&&d.low.y==m||(b.push(d),w=S),y++;else{let _=Do(d.low.y,s);_<w&&(w=_);break}}let I=[];for(p=0;p<b.length;p++)ad(I,b[p],m,w);I.sort((_,U)=>_.x-U.x||_.lowOrHigh-U.lowOrHigh);let L=ld(I,o,a);if(L.length==0)h.push(new Et(m,w,e.x2,e.x2));else{let _=0,U=e.x1;for(p=0;p<L.length;p+=2){let W=Math.max(e.x1,L[p]),re=Math.min(e.x2,L[p+1])-W;re>_&&(_=re,U=W)}_==0?h.push(new Et(m,w,e.x2,e.x2)):h.push(new Et(m,w,Math.max(U,e.x1),Math.min(U+_,e.x2)))}if(w==e.y2)break;for(m=w,p=b.length-1;p>=0;p--)b[p].high.y<=w&&b.splice(p,1)}return Ll(e,h),h}function Ll(e,t){let i=t.length-1,n=new Et(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let s=n;n=t[i],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(i,1),n=s),i--}}function Fl(e,t){let i=0,n=e.length;for(;i<n;){let s=Math.floor((i+n)/2);t>=e[s].y2?i=s+1:n=s}return i}function dd(e,t){if(!e.length)return t;let i=t.y1,n,s;for(s=0;s<e.length&&(n=e[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)i=Math.max(i,n.y2);let r=i;for(;s<e.length&&(n=e[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)r=n.y2;return s===e.length?r=t.y2:r=Math.min(r,t.y2),r<=i?null:new nt(t.x1,i,t.x2,r)}function pd(e,t){if(!e.length)return t;let i=t.y2,n,s;for(s=e.length-1;s>=0&&(n=e[s],!(s===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);s--)i=Math.min(i,n.y1);let r=Math.min(i,n.y2);for(;s>=0&&(n=e[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)r=n.y1;return r=Math.max(r,t.y1),i<=r?null:new nt(t.x1,r,t.x2,i)}function fd(e,t,i,n){let s=i.y1,r=i.x2-i.x1,o=i.y2-i.y1,a=Fl(t,s);for(;;){let h=s+o;if(h>e.y2)return!1;let l=e.x1,c=e.x2;for(let p=a;p<t.length&&t[p].y1<h;p++){let d=t[p];d.x1>l&&(l=d.x1),d.x2<c&&(c=d.x2)}if(l+r<=c||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+r):(i.x1=c-r,i.x2=c),i.y2+=s-i.y1,i.y1=s,!0;s=t[a].y2,a++}}function gd(e,t,i,n,s){for(n||(n=[new Et(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let r,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Et(o,e.y2,e.x1,e.x2));let a=Fl(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(r=t[a],a++,t.splice(a,0,new Et(h.y1,r.y2,r.x1,r.x2)),r.y2=h.y1);a<t.length&&(r=t[a++],r.y2>h.y2&&(t.splice(a,0,new Et(h.y2,r.y2,r.x1,r.x2)),r.y2=h.y2),h.x1!=h.x2&&(s=="left"?r.x1=Math.min(h.x2,e.x2):r.x2=Math.max(h.x1,e.x1)),r.y2!=h.y2););}Ll(e,t)}var md=class extends It{constructor(){super(),u(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function wd(e){if(e){let t=new md;try{return e.visit(t),t.propSet}catch(i){D.warn(i,"toSet:")}}return{}}var bd=class extends It{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Uo(e,t){if(e){let i=new bd(t);try{return e.visit(i),i.value}catch(n){D.warn(n,"toInt: ")}}return t}var yd=class extends It{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 T(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,s){if(this.coords.length>0){let r=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),r.push(o.num*h/100)}else r.push(o.num*s.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(r.length%2==0){let o=[];for(let a=0;a<r.length;a+=2)o.push(new At(e+r[a],t+r[a+1]));return new ss(o)}break;case"rectangle":if(r.length==4)return Mr(e+r[0],t+r[1],e+r[0]+r[2],t+r[1]+r[3]);break;case"ellipse":if(r.length==4)return Mo(e+r[0],t+r[1],r[2],r[3]);break;case"circle":if(r.length==3)return Mo(e+r[0],t+r[1],r[2],r[2]);break}}return null}};function Ol(e,t,i,n,s,r){if(e){let o=new yd;try{return e.visit(o),o.getShape(t,i,n,s,r)}catch(a){D.warn(a,"toShape:")}}return Mr(t,i,t+n,i+s)}var vd=class extends It{constructor(e){super(),this.reset=e,u(this,"counters",{}),u(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+1,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:1)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function Gi(e,t){let i=new vd(t);try{e.visit(i)}catch(n){D.warn(n,"toCounters:")}return i.counters}var xd=class extends Ei{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ct(this.transformer.transformURL(e.url,this.baseUrl))}};function Es(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Sd=class{constructor(e,t){this.targetId=e,this.resolved=t,u(this,"pageCounters",null),u(this,"spineIndex",-1),u(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Cd=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},Ed=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,u(this,"styler",null),u(this,"namedStringValues",{}),u(this,"runningElements",{})}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(ke(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let r=this.counterStore.currentPageCounters[e];return r&&r.length?r[r.length-1]:null},n=new De(this.pageScope,()=>t(i()),`page-counter-${e}`),s=r=>t(r[r.length-1]);return this.counterStore.registerPageCounterExpr(e,s,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new De(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}getTargetCounterVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e),r=this.getTargetCounters(n,s,!1);if(r&&r[t]){let a=r[t];return new Fe(this.rootScope,i(a[a.length-1]||null))}let o=new De(this.pageScope,()=>{if(r=this.getTargetCounters(n,s,!0),r)if(r[t]){let a=r[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(s);if(a)if(this.counterStore.resolveReference(s),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,s),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e);return new De(this.pageScope,()=>{let r=this.getTargetPageCounters(s);if(r){this.counterStore.resolveReference(s);let o=r[t]||[],a=this.getTargetCounters(n,s,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counters-${t}-of-${e}`)}getNamedStringVal(e,t){return new De(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new De(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let s=Object.keys(n).map(d=>parseInt(d,10)).sort(il),r=this.counterStore.currentPage,o=r.isBlankPage?r.offset-1:r.offset,a=r.isBlankPage?o:Math.max(o,...Array.from(r.container.querySelectorAll(`[${xt}]`)).map(d=>parseInt(d.getAttribute(xt),10))),h=-1,l=-1,c=-1,p=-1;for(let d=0;d<s.length;d++){let f=s[d],g=d>0?s[d-1]:-1,m=d<s.length-1?s[d+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,p=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let y=r.container.querySelector(`[${xt}="${f}"]`);if(!y)l<0&&(l=f);else{let b=r.container.querySelector(`[${xt}="${o}"]`);if(b||(b=r.container.querySelector(`[${xt}="0"]`)),b){for(let w=b;w;w=w.firstElementChild)if(w===y){l=f;break}}}}c=f}else(m>a||m<0)&&(h=l=c=p=f)}return n[{first:h,start:l,last:c,"first-except":p}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]={});n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]={});i[t]=String(t)}},kd=class{constructor(e){this.documentURLTransformer=e,u(this,"countersById",{}),u(this,"pageCountersById",{}),u(this,"currentPageCounters",{}),u(this,"previousPageCounters",{}),u(this,"currentPageCountersStack",[]),u(this,"pageIndicesById",{}),u(this,"currentPage",null),u(this,"newReferencesOfCurrentPage",[]),u(this,"referencesToSolve",[]),u(this,"referencesToSolveStack",[]),u(this,"unresolvedReferences",{}),u(this,"resolvedReferences",{}),u(this,"pagesCounterExprs",[]),u(this,"pageCounterExprs",[]),u(this,"targetCounterExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Cd(this,e)}createCounterResolver(e,t,i){return new Ed(this,e,t,i)}setCurrentPage(e){this.currentPage=e}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Es(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let o=n.evaluate(t);o&&(i=Gi(o,!0))}if(i)for(let o in i)this.definePageCounter(o,i[o]);let s,r=e["counter-increment"];if(r){let o=r.evaluate(t);o&&(s=Gi(o,!1))}s?"page"in s||(s.page=1):(s={},s.page=1);for(let o in s){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=s[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Es(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let s=0;s<this.referencesToSolve.length;){let r=this.referencesToSolve[s];if(r.targetId===e){if(r.resolve(),this.referencesToSolve.splice(s,1),t){let o=t.indexOf(r);o>=0&&t.splice(o,1)}i.push(r),n=!0}else s++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Sd(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let r=Es(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=r;let a=this.pageIndicesById[o];if(a&&a.pageIndex<t){let h=this.resolvedReferences[o];if(h){let l=this.unresolvedReferences[o];l||(l=this.unresolvedReferences[o]=[]);let c;for(;c=h.shift();)c.unresolve(),l.push(c)}}this.pageIndicesById[o]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,s;for(;s=this.newReferencesOfCurrentPage.shift();){s.pageCounters=n,s.spineIndex=e,s.pageIndex=t;let r;s.isResolved()?(r=this.resolvedReferences[s.targetId],r||(r=this.resolvedReferences[s.targetId]=[])):(r=this.unresolvedReferences[s.targetId],r||(r=this.unresolvedReferences[s.targetId]=[])),r.every(o=>!s.equals(o))&&r.push(s)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(s=>{let r=this.unresolvedReferences[s];r&&(t=t.concat(r))}),t.sort((s,r)=>s.spineIndex-r.spineIndex||s.pageIndex-r.pageIndex);let i=[],n=null;return t.forEach(s=>{!n||n.spineIndex!==s.spineIndex||n.pageIndex!==s.pageIndex?(n={spineIndex:s.spineIndex,pageIndex:s.pageIndex,pageCounters:s.pageCounters,refs:[s]},i.push(n)):n.refs.push(s)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof De){if(e.str=="viv-leader"){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute("data-viv-leader",e.key),r.setAttribute("data-viv-leader-value",t),r}else if(e.str.startsWith("running-element-")){let r=t&&i.querySelectorAll(`[${xt}="${t}"]`);if(!r||r.length===0)return null;let o=r[r.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(Ps,e.key),r}}let n=this.pagesCounterExprs.findIndex(r=>r.expr===e)>=0,s=!n&&this.pageCounterExprs.findIndex(r=>r.expr===e)>=0;if(n||s){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(n?ks:Ns,e.key),r}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Ns}]`);for(let n of t){let s=n.getAttribute(Ns),r=this.pageCounterExprs.find(l=>l.expr.key===s),o=(r?.expr).str,a=o?.replace(/^page-counters?-/,""),h=this.currentPageCounters[a];h&&(n.textContent=r.format(h))}let i=e.querySelectorAll(`[${Ps}]`);for(let n of i)n.setAttribute(Ho,!0)}finishLastPage(e){let t=e.root.querySelectorAll(`[${ks}]`),i=e.contentContainer.childElementCount;for(let s of t){let r=s.getAttribute(ks),o=this.pagesCounterExprs.findIndex(a=>a.expr.key===r);o>=0,s.textContent=this.pagesCounterExprs[o].format([i])}let n=e.root.querySelectorAll(`[${Ho}]`);for(let s of n){let r=s.getAttribute(Ps),o=this.targetCounterExprs.find(a=>a.expr.key===r);if(o&&o.transformedId){let a=this.pageCountersById[o.transformedId];if(a){let h=a[o.name];h&&(s.textContent=o.format(h[h.length-1]))}}}}createLayoutConstraint(e){return new Nd(this,e)}},ks="data-vivliostyle-pages-counter",Ns="data-vivliostyle-page-counter",Ps="data-vivliostyle-target-counter",Ho="data-vivliostyle-target-counter-in-running",Nd=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}};function Pd(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 Ht(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Pd)}var Td=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 Oe(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 vt=[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];vt[NaN]=80;var wt=[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];wt[NaN]=43;var Id=[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];wt[NaN]=43;var Bl=[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];Bl[NaN]=35;var _l=[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];_l[NaN]=45;var $s=[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];$s[NaN]=37;var Gs=[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];Gs[NaN]=38;var $t=Oe(35,[61,36]),Rd=Oe(35,[58,77]),Ad=Oe(35,[61,36,124,50]),Ld=Oe(35,[38,51]),Fd=Oe(35,[42,54]),Od=Oe(39,[42,55]),Bd=Oe(54,[42,55,47,56]),_d=Oe(62,[62,82]),Md=Oe(35,[61,36,33,70]),zd=Oe(62,[45,71]),Dd=Oe(63,[45,81]),Ts=Oe(76,[10,72,13,72]),Vd=Oe(39,[39,46,10,72,13,72,92,48]),Ud=Oe(39,[34,46,10,72,13,72,92,49]),Hd=Oe(39,[39,47,10,74,13,74,92,48]),$d=Oe(39,[34,47,10,74,13,74,92,49]),$o=Oe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Gd=Oe(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]),Wd=Oe(39,[39,68,10,74,13,74,92,75,NaN,67]),jd=Oe(39,[34,68,10,74,13,74,92,75,NaN,67]),Xd=Oe(72,[9,39,10,39,13,39,32,39,41,69]),qd=15,gt=class{constructor(e,t){this.input=e,this.handler=t,u(this,"indexMask"),u(this,"buffer"),u(this,"tail",0),u(this,"curr",0),u(this,"position",0),this.indexMask=qd,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Td}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=vt,s=this.input,r=this.position,o=this.buffer,a=0,h=0,l="",c=0,p=!1,d=o[e],f=-9;for(;;){let g=s.charCodeAt(r);switch(n[g]||n[65]){case 72:l=s.substring(h,r),isNaN(g)?a=0:a=54,n=vt;break;case 1:r++,p=!0;continue;case 2:h=r++,n=$s;continue;case 3:a=1,h=r++,n=wt;continue;case 4:h=r++,a=31,n=$t;continue;case 33:a=2,h=++r,n=Vd;continue;case 34:a=2,h=++r,n=Ud;continue;case 6:h=++r,a=7,n=wt;continue;case 7:h=r++,a=32,n=$t;continue;case 8:h=r++,a=21;break;case 9:h=r++,a=32,n=Ld;continue;case 10:h=r++,a=10;break;case 11:h=r++,a=11;break;case 12:h=r++,a=36,n=$t;continue;case 13:h=r++,a=23;break;case 14:h=r++,a=16;break;case 15:a=24,h=r++,n=Bl;continue;case 16:h=r++,n=Id;continue;case 78:h=r++,a=9,n=wt;continue;case 17:h=r++,a=19,n=Fd;continue;case 18:h=r++,a=18,n=Rd;continue;case 77:r++,a=50;break;case 19:h=r++,a=17;break;case 20:h=r++,a=38,n=Md;continue;case 21:h=r++,a=39,n=$t;continue;case 22:h=r++,a=37,n=$t;continue;case 23:h=r++,a=22;break;case 24:h=++r,a=20,n=wt;continue;case 25:h=r++,a=14;break;case 26:h=r++,a=15;break;case 27:h=r++,a=12;break;case 28:h=r++,a=13;break;case 29:h=r++,f=h,a=1,n=Ts;continue;case 30:h=r++,a=33,n=$t;continue;case 31:h=r++,a=34,n=Ad;continue;case 32:h=r++,a=35,n=$t;continue;case 35:break;case 36:r++,a=a+41-31;break;case 37:a=5,c=parseInt(s.substring(h,r),10);break;case 38:a=4,c=parseFloat(s.substring(h,r));break;case 39:r++;continue;case 40:a=3,c=parseFloat(s.substring(h,r)),h=r++,n=wt;continue;case 41:a=3,c=parseFloat(s.substring(h,r)),l="%",h=r++;break;case 42:r++,n=Gs;continue;case 43:if(l=Ht(s.substring(h,r)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(s.substring(r-1))){a=27,r++;continue}break;case 44:f=r++,n=Ts;continue;case 45:l=Ht(s.substring(h,r));break;case 46:l=s.substring(h,r),r++;break;case 47:l=Ht(s.substring(h,r)),r++;break;case 48:f=r,r+=2,n=Hd;continue;case 49:f=r,r+=2,n=$d;continue;case 50:r++,a=25;break;case 51:r++,a=26;break;case 52:if(l=s.substring(h,r),a==1){if(r++,l.toLowerCase()=="url"){n=$o;continue}a=6}break;case 53:if(l=Ht(s.substring(h,r)),a==1){if(r++,l.toLowerCase()=="url"){n=$o;continue}a=6}break;case 54:n=Od,r++;continue;case 55:n=Bd,r++;continue;case 56:n=vt,r++;continue;case 57:n=_d,r++,s[r]!==">"&&(a=1,n=wt);continue;case 81:a=51,l=s.substring(h,++r),n=vt;break;case 82:a=52,l=s.substring(h,++r),n=vt;break;case 58:a=5,n=$s,r++;continue;case 59:a=4,n=Gs,r++;continue;case 60:a=1,n=wt,r++;continue;case 61:a=1,n=Ts,f=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:h=r++,n=Gd;continue;case 65:h=++r,n=Wd;continue;case 66:h=++r,n=jd;continue;case 67:a=8,l=Ht(s.substring(h,r)),r++;break;case 69:r++;break;case 70:n=zd,r++;continue;case 71:n=Dd,r++;continue;case 79:if(r-f<8&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:a=8,l=Ht(s.substring(h,r)),r++,n=Xd;continue;case 74:if(r++,r-f<9&&s.substring(f+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=vt;break;case 73:if(r-f<9&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,n=wt;continue}l=Ht(s.substring(h,r));break;case 75:f=r++;continue;case 76:r++,n=_l;continue;default:if(n!==vt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=r,a=0}if(d.type=a,d.precededBySpace=p,d.num=c,d.text=l,d.position=h,e++,e>=t)break;n=vt,p=!1,d=o[e&i]}this.position=r,this.tail=e&i}},Ie=null,Ws=null;function js(){return Ie}function F(e){if(!Ie)throw new Error("E_TASK_NO_CONTEXT");Ie.name||(Ie.name=e);let t=Ie,i=new rs(t,t.top,e);return t.top=i,i.state=1,i}function Yd(e){return new Jd(e||new Zd)}function N(e){return new Xs(e)}function vi(e,t,i){let n=F(e);n.handler=i;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function Kd(e,t){return(Ie?Ie.getScheduler():Ws||Yd()).run(e,t)}var Zd=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Jd=class{constructor(e){this.timer=e,u(this,"timeout",1),u(this,"slice",25),u(this,"sliceOverTime",0),u(this,"queue"),u(this,"wakeupTime",null),u(this,"timeoutToken",null),u(this,"inTimeSlice",!1),u(this,"order",0),this.queue=new Ac,Ws||(Ws=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){D.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Qd(this,t||"");i.top=new rs(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let s=()=>{i.running=!1;for(let r of i.callbacks)try{r()}catch(o){D.error(o)}};try{e().then(r=>{i.result=r,s()})}catch(r){i.raise(r),s()}});let n=Ie;return Ie=i,this.schedule(i.top.suspend("bootstrap")),Ie=n,i}},Ml=class{constructor(e){this.task=e,u(this,"scheduledTime",0),u(this,"order",0),u(this,"result",null),u(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Ie;return Ie=e,e.top.finish(this.result),Ie=t,!0}return!1}cancel(){this.canceled=!0}},Qd=class{constructor(e,t){this.scheduler=e,this.name=t,u(this,"callbacks",[]),u(this,"exception",null),u(this,"running",!0),u(this,"result",null),u(this,"waitTarget",null),u(this,"top",null),u(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Ie&&this.continuation){this.continuation.cancel();let t=new Ml(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=F("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&D.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
3
+ `]).concat(i))),n}var D=new Ec,ts=(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))(ts||{}),Un={};function ht(e,t,i){if(!ts[e])D.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Un[e];n||(n=Un[e]=[]),i?n.unshift(t):n.push(t)}}function Ka(e,t){if(!ts[e])D.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Un[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function pt(e){return Un[e]||[]}var kc={registerHook:ht,removeHook:Ka},Ja=class{constructor(e){this.performanceInstance=e,u(this,"timestamps",{}),u(this,"registerTiming"),u(this,"registerStartTiming"),u(this,"registerEndTiming"),this.registerTiming=ii,this.registerStartTiming=this.registerStartTiming=ii,this.registerEndTiming=this.registerEndTiming=ii}forceRegisterStartTiming(e,t){vs.call(this,e,"start",t)}forceRegisterEndTiming(e,t){vs.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],s=n.length;for(let r=0;r<s;r++){let o=n[r];t+=i,s>1&&(t+=`(${r})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
4
+ `}}),D.info(t)}disable(){this.registerTiming=ii,this.registerStartTiming=this.registerStartTiming=ii,this.registerEndTiming=this.registerEndTiming=ii}enable(){this.registerTiming=vs,this.registerStartTiming=this.registerStartTiming=bo,this.registerEndTiming=this.registerEndTiming=Nc}isEnabled(){return this.registerStartTiming===bo}};function ii(){}function vs(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let s,r=n.length;for(let o=r-1;o>=0&&(s=n[o],!(s&&!s[t]));o--)s=null;s||(s={},n.push(s)),s[t]=i}function bo(e,t){this.registerTiming(e,"start",t)}function Nc(e,t){this.registerTiming(e,"end",t)}var Pc={now:Date.now},Tc=window&&window.performance,tt=new Ja(Tc||Pc);tt.forceRegisterStartTiming("load_vivliostyle");var Ic={profiler:{registerStartTiming:tt.registerStartTiming,registerEndTiming:tt.registerEndTiming,printTimings:tt.printTimings,disable:tt.disable,enable:tt.enable}},Bs=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,xt="data-adapt-eloff",Ac={};function Ar(e){return JSON.parse(e)}function Ct(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Rc(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var vi=window.location.href;function vo(e){vi=e}var Jt=window.location.href;function yo(e){Jt=e}function ke(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Rc(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let s=t.substr(0,n+1)+e,r="";for(i=s.match(/^([^?#]*)([?#].*)$/),i&&(s=i[1],r=i[2]);n=s.indexOf("/../"),!(n<=0);){let o=s.lastIndexOf("/",n-1);if(o<=0)break;s=s.substr(0,o)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+r}function nn(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function xo(e){return e==null?e:e.toString()}var Lc=class{constructor(){u(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let s=n*2;if(s>=i)break;if(this.queue[s].compare(t)>0)s+1<i&&this.queue[s+1].compare(this.queue[s])>0&&s++;else if(s+1<i&&this.queue[s+1].compare(t)>0)s++;else break;this.queue[n]=this.queue[s],n=s}this.queue[n]=t}return e}},Qa=["","-webkit-","-moz-"],si={};function ys(e,t){return CSS.supports(e+t,"unset")}function el(e){let t=si[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return si[e]=null,null;case"text-combine-upright":if(ys("-webkit-","text-combine")&&!ys("","text-combine-upright"))return si[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Qa)if(ys(i,e))return t=[i+e],si[e]=t,t;return D.warn("Property not supported by the browser: ",e),si[e]=null,null}function k(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let s=el(t);if(s)for(let r of s){switch(r){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(r,i)}}function Rt(e,t,i){try{let n=si[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function _s(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var kt=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 tl(e){return`\\${e.charCodeAt(0).toString(16)} `}function Ot(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,tl)}function gn(e){return e.replace(/[\u0000-\u001F"\\]/g,tl)}function So(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Co(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Fc(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function il(e,t){function i(n){return Fc(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function At(e){return il(e)}function Oc(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Bc(e,t){t=typeof t=="string"?t:"\\u";function i(s){return Oc(s,t)}let n=new RegExp(`${At(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function _t(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let s=i+n>>1;t(s)?n=s:i=s+1}}function nl(e,t){return e-t}function Eo(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function _c(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function xs(e,t){let i={};for(let n of e){let s=t(n);s&&(i[s]?i[s].push(n):i[s]=[n])}return i}function Mc(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Rr=class{constructor(){u(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let s=n.indexOf(t);s>=0&&n.splice(s,1)}}},Xt={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function sl(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function zc(e){return`^${e}`}function ko(e){return e.replace(/[\[\]\(\),=;^]/g,zc)}function Dc(e){return e.substr(1)}function Ms(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Dc)}function Vc(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Ms(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function No(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Vc(i[2]),e=e.substr(i[0].length)}return t}var Po=class{appendTo(e){e.append("!")}applyTo(e){return!1}},To=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,s,r=Math.floor(this.index/2)-1;if(r<0||n==0)s=t.firstChild,e.node=s||t;else{if(s=i[Math.min(r,n-1)],this.index&1){let o=s.nextSibling;!o||o.nodeType==1?e.after=!0:s=o}e.node=s}if(this.id&&(e.after||this.id!=sl(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:D.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Io=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let s=i.nextSibling;if(3<=n&&n<=5){let r=i.textContent.length;if(t<=r)break;if(!s){t=r;break}t-=r}if(!s){t=0;break}i=s}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(ko(this.textBefore)),e.append(","),this.textAfter&&e.append(ko(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Ao=class rl{constructor(){u(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),s=0,r=[];for(;;){let o;switch(n.charAt(s)){case"/":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[3];o=No(i[4]),r.push(new To(a,h,xo(o.s)));break}case":":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),h=i[4];h&&(h=Ms(h));let l=i[7];l&&(l=Ms(l)),o=No(i[10]),r.push(new Io(a,h,l,xo(o.s)));break}case"!":s++,r.push(new Po);break;case"~":case"@":case"":this.steps=r;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new rl,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,s){let r=[],o=t.parentNode,a="",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),r.push(new Io(i,a,h,s)),s=null);o&&!(!o||o.nodeType==9);){let l=n?null:sl(t),c=n?1:0;for(;t;)t.nodeType==1&&(c+=2),t=t.previousSibling;r.push(new To(c,l,s)),s=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new Po),this.steps=r.concat(this.steps)):this.steps=r}toString(){if(!this.steps)return"";let t=new kt;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function ol(){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 al(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 Uc=ol(),Ro={PENDING:{}};function ll(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function Ss(e){return`"${gn(`${e}`)}"`}function Hc(e){return Ot(`${e}`)}function zs(e,t){return e?`${Ot(e)}.${Ot(t)}`:Ot(t)}var hl=0,Ds=class{constructor(e,t){if(this.parent=e,this.resolver=t,u(this,"scopeKey"),u(this,"children",[]),u(this,"zero"),u(this,"one"),u(this,"_true"),u(this,"_false"),u(this,"values",{}),u(this,"funcs",{}),u(this,"builtIns",{}),this.scopeKey=`S${hl++}`,this.zero=new Fe(this,0),this.one=new Fe(this,1),this._true=new Fe(this,!0),this._false=new Fe(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=ll,i["css-string"]=Ss,i["css-name"]=Hc,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 Ss(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Ss(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new De(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 $c(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function ul(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 Gc(e){switch(e?.toLowerCase()){case"em":case"ex":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Wc(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var we={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,ex:8,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function cl(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var Vs=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,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=Uc}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(ul(e)){let n=this.pageWidth()/100,s=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:s,a=i??this.pageVertical;switch(e){case"vw":return r;case"vh":return o;case"vi":return a?o:r;case"vb":return a?r:o;case"vmin":return r<o?r:o;case"vmax":return r>o?r:o;case"pvw":return n;case"pvh":return s;case"pvi":return a?s:n;case"pvb":return a?n:s;case"pvmin":return n<s?n:s;case"pvmax":return n>s?n:s}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="ex"?we.ex*(t?this.initialFontSize:this.fontSize())/we.em:e=="lh"||e=="rlh"?this.rootLineHeight:we[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let s=e.funcs[t];if(s||e.resolver&&(s=e.resolver.call(this,t,!0),s))return s;let r=e.builtIns[t];if(r){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new Fe(e,r.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let s=null,r=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(s=t.evaluate(this));break}switch(e){case"width":r=this.pageWidth();break;case"height":r=this.pageHeight();break;case"device-width":r=window.screen.availWidth;break;case"device-height":r=window.screen.availHeight;break;case"color":r=window.screen.pixelDepth;break}if(r!=null&&s!=null)switch(i){case"min":return r>=Number(s);case"max":return r<=Number(s);default:return r==s}else if(r!=null&&t==null)return r!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},ut=class{constructor(e){this.scope=e,u(this,"key"),this.scope=e,this.key=`_${hl++}`}toString(){let e=new kt;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===Ro.PENDING?!1:n;{i[this.key]=Ro.PENDING;let s=this.dependCore(e,t,i);return i[this.key]=s,s}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},dl=class extends ut{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},is=class extends ut{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},pl=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ci=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},fl=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Lr=class extends is{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},Bt=class extends dl{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},jc=class extends Bt{constructor(e,t){super(e,t)}getOp(){return"not "}},gl=class extends dl{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Fr=class extends pl{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Xc=class extends Fr{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Or=class extends pl{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},qc=class extends Or{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},Yc=class extends Or{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Zc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},Kc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Jc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Us=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Br=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Qc=class extends Ci{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},ml=class extends fl{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},wl=class extends fl{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},_r=class extends Lr{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},bl=class extends Lr{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},vl=class extends Lr{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Qt=class extends ut{constructor(e,t,i){var n;super(e),this.num=t,u(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(Ot(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},ze=class extends ut{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},Lo=class extends ut{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(Ot(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},De=class extends ut{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function ed(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function td(e,t,i){let n=t;for(let s=0;s<t.length;s++){let r=t[s].expand(e,i);if(t!==n)n[s]=r;else if(r!==t[s]){n=Array(t.length);for(let o=0;o<s;o++)n[o]=t[o];n[s]=r}}return n}var Gi=class yl extends ut{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),ed(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let s=0;s<this.params.length;s++)if(this.params[s].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=td(t,this.params,i);return n===this.params?this:new yl(this.scope,this.qualifiedName,n)}},id=class xl extends ut{constructor(t,i,n,s){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=s}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),s=this.ifTrue.expand(t,i),r=this.ifFalse.expand(t,i);return n===this.cond&&s===this.ifTrue&&r===this.ifFalse?this:new xl(this.scope,n,s,r)}},Fe=class extends ut{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(gn(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Fo=class Sl extends ut{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(gn(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 Sl(this.scope,this.name,n)}},nd=class extends ut{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Cl=class extends ut{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function lt(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 Fr(e,t,i)}function j(e,t,i){return t===e.zero?i:i===e.zero?t:new ml(e,t,i)}function ae(e,t,i){return t===e.zero?new gl(e,i):i===e.zero?t:new wl(e,t,i)}function Fn(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new _r(e,t,i)}function Hs(e,t,i){return t===e.zero?e.zero:i===e.one?t:new bl(e,t,i)}var It=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}},Ei=class extends It{constructor(){super(),u(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],s=n.visit(this);if(this.error)return[];if(t)t[i]=s;else if(n!==s){t=new Array(e.length);for(let r=0;r<i;r++)t[r]=e[r];t[i]=s}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new ye(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new qe(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?G:t===e.values?e:new ki(e.name,t)}visitExpr(e){return e}},$e=class{toString(){let e=new kt;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new kt;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}},El=class kl extends $e{static get instance(){return this.empty||(this.empty=new kl),this.empty}constructor(){super()}toExpr(t,i){return new Fe(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};u(El,"empty");var sd=El,G=sd.instance,Nl=class Pl extends $e{static get instance(){return this.slash||(this.slash=new Pl),this.slash}constructor(){super()}toExpr(t,i){return new Fe(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};u(Nl,"slash");var rd=Nl,ns=rd.instance,Re=class extends $e{constructor(e){super(),this.str=e}toExpr(e,t){return new Fe(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(gn(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},$s={},ft=class extends $e{constructor(e){if(super(),this.name=e,$s[e])throw new Error("E_INVALID_CALL");$s[e]=this}toExpr(e,t){return new Fe(e,this.name)}appendTo(e,t){t?e.append(Ot(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=$s[e];return t||(t=new ft(e)),t}var T=class extends $e{constructor(e,t){var i;super(),this.num=e,u(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new _r(e,t,new Fe(e,this.num/100)):new Qt(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}},Ut=class extends $e{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Fe(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},ei=class extends Ut{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Tl=class extends $e{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ct=class extends $e{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(gn(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Il=class extends $e{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Mr(e,t,i,n){var s,r;let o=t.length;if(o>0){(s=t[0])==null||s.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(r=t[a])==null||r.appendTo(e,n)}}var ye=class extends $e{constructor(e){super(),this.values=e}appendTo(e,t){Mr(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},qe=class extends $e{constructor(e){super(),this.values=e}appendTo(e,t){Mr(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},ki=class extends $e{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(Ot(this.name)),e.append("("),Mr(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},V=class extends $e{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Fe||this.expr instanceof Qt?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}},Ri=class extends $e{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function We(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function Al(e,t){return new T(We(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"),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"),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")},Oo=new T(100,"%"),Ni=new T(100,"pvw"),Pi=new T(100,"pvh"),le=new T(0,"px"),od=new Il("U+0-10FFFF"),Bo={"font-size":1,"line-height":2,color:3};function J(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function _o(e,t){let i=Bo[e]||Number.MAX_VALUE,n=Bo[t]||Number.MAX_VALUE;return i-n}function Nt(e){return e?.length>2&&e.startsWith("--")}var st=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},Lt=class{constructor(e,t){this.x=e,this.y=t}},Cs=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Mo=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Et=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,u(this,"left",null),u(this,"right",null)}};function ad(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var ss=class Rl{constructor(t){this.points=t}addSegments(t,i){let n=this.points,s=n.length,r=n[s-1];for(let o=0;o<s;o++){let a=n[o],h;r.y<a.y?h=new Mo(r,a,1,i):h=new Mo(a,r,-1,i),t.push(h),r=a}}withOffset(t,i){let n=[];for(let s of this.points)n.push(new Lt(s.x+t,s.y+i));return new Rl(n)}};function zo(e,t,i,n){let s=[];for(let r=0;r<20;r++){let o=r*2*Math.PI/20;s.push(new Lt(e+i*Math.sin(o),t+n*Math.cos(o)))}return new ss(s)}function zr(e,t,i,n){return new ss([new Lt(e,t),new Lt(i,t),new Lt(i,n),new Lt(e,n)])}var kn=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function Do(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 ld(e,t,i,n){let s,r,o,a;t.high.y<i&&D.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=Do(t,i),r=t.winding):(s=t.low.x,r=0),t.high.y>=n?(o=Do(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(e.push(new kn(s,r,t.shapeId,-1)),e.push(new kn(o,a,t.shapeId,1))):(e.push(new kn(o,a,t.shapeId,-1)),e.push(new kn(s,r,t.shapeId,1)))}function hd(e,t,i){let n=t+i,s=Array(n),r=Array(n),o;for(o=0;o<=n;o++)s[o]=0,r[o]=0;let a=[],h=!1,l=e.length;for(let c=0;c<l;c++){let p=e[c];s[p.shapeId]+=p.winding,r[p.shapeId]+=p.lowOrHigh;let d=!1;for(o=0;o<t;o++)if(s[o]&&!r[o]){d=!0;break}if(d){for(o=t;o<=n;o++)if(s[o]||r[o]){d=!1;break}}h!=d&&(a.push(p.x),h=d)}return a}function ud(e,t){return t?Math.ceil(e/t)*t:e}function Vo(e,t){return t?Math.floor(e/t)*t:e}function cd(e){return new Lt(e.y,-e.x)}function Hn(e){return new st(e.y1,-e.x2,e.y2,-e.x1)}function Ll(e){return new st(-e.y2,e.x1,-e.y1,e.x2)}function Uo(e){return new ss(e.points.map(t=>cd(t)))}function dd(e,t,i,n,s,r){r&&(e=Hn(e),t=t.map(w=>Uo(w)),i=i.map(w=>Uo(w)));let o=t.length,a=i?i.length:0,h=[],l=[],c,p,d;for(c=0;c<o;c++)t[c].addSegments(l,c);for(c=0;c<a;c++)i[c].addSegments(l,c+o);let f=l.length;l.sort(ad);let g=0;for(;l[g].shapeId>=o;)g++;let m=l[g].low.y;m>e.y1&&h.push(new Et(e.y1,m,e.x2,e.x2));let v=0,b=[];for(;v<f&&(d=l[v]).low.y<m;)d.high.y>m&&b.push(d),v++;for(;v<f||b.length>0;){let w=e.y2,S=Math.min(ud(Math.ceil(m+n),s),e.y2);for(p=0;p<b.length&&w>S;p++)d=b[p],d.low.x==d.high.x?d.high.y<w&&(w=Math.max(Vo(d.high.y,s),S)):d.low.x!=d.high.x&&(w=S);for(w>e.y2&&(w=e.y2);v<f&&(d=l[v]).low.y<w;){if(d.high.y<m){v++;continue}if(d.low.y<S)d.low.y==d.high.y&&d.low.y==m||(b.push(d),w=S),v++;else{let _=Vo(d.low.y,s);_<w&&(w=_);break}}let I=[];for(p=0;p<b.length;p++)ld(I,b[p],m,w);I.sort((_,U)=>_.x-U.x||_.lowOrHigh-U.lowOrHigh);let L=hd(I,o,a);if(L.length==0)h.push(new Et(m,w,e.x2,e.x2));else{let _=0,U=e.x1;for(p=0;p<L.length;p+=2){let W=Math.max(e.x1,L[p]),re=Math.min(e.x2,L[p+1])-W;re>_&&(_=re,U=W)}_==0?h.push(new Et(m,w,e.x2,e.x2)):h.push(new Et(m,w,Math.max(U,e.x1),Math.min(U+_,e.x2)))}if(w==e.y2)break;for(m=w,p=b.length-1;p>=0;p--)b[p].high.y<=w&&b.splice(p,1)}return Fl(e,h),h}function Fl(e,t){let i=t.length-1,n=new Et(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let s=n;n=t[i],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(i,1),n=s),i--}}function Ol(e,t){let i=0,n=e.length;for(;i<n;){let s=Math.floor((i+n)/2);t>=e[s].y2?i=s+1:n=s}return i}function pd(e,t){if(!e.length)return t;let i=t.y1,n,s;for(s=0;s<e.length&&(n=e[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)i=Math.max(i,n.y2);let r=i;for(;s<e.length&&(n=e[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)r=n.y2;return s===e.length?r=t.y2:r=Math.min(r,t.y2),r<=i?null:new st(t.x1,i,t.x2,r)}function fd(e,t){if(!e.length)return t;let i=t.y2,n,s;for(s=e.length-1;s>=0&&(n=e[s],!(s===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);s--)i=Math.min(i,n.y1);let r=Math.min(i,n.y2);for(;s>=0&&(n=e[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)r=n.y1;return r=Math.max(r,t.y1),i<=r?null:new st(t.x1,r,t.x2,i)}function gd(e,t,i,n){let s=i.y1,r=i.x2-i.x1,o=i.y2-i.y1,a=Ol(t,s);for(;;){let h=s+o;if(h>e.y2)return!1;let l=e.x1,c=e.x2;for(let p=a;p<t.length&&t[p].y1<h;p++){let d=t[p];d.x1>l&&(l=d.x1),d.x2<c&&(c=d.x2)}if(l+r<=c||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+r):(i.x1=c-r,i.x2=c),i.y2+=s-i.y1,i.y1=s,!0;s=t[a].y2,a++}}function md(e,t,i,n,s){for(n||(n=[new Et(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let r,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Et(o,e.y2,e.x1,e.x2));let a=Ol(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(r=t[a],a++,t.splice(a,0,new Et(h.y1,r.y2,r.x1,r.x2)),r.y2=h.y1);a<t.length&&(r=t[a++],r.y2>h.y2&&(t.splice(a,0,new Et(h.y2,r.y2,r.x1,r.x2)),r.y2=h.y2),h.x1!=h.x2&&(s=="left"?r.x1=Math.min(h.x2,e.x2):r.x2=Math.max(h.x1,e.x1)),r.y2!=h.y2););}Fl(e,t)}var wd=class extends It{constructor(){super(),u(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function bd(e){if(e){let t=new wd;try{return e.visit(t),t.propSet}catch(i){D.warn(i,"toSet:")}}return{}}var vd=class extends It{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Ho(e,t){if(e){let i=new vd(t);try{return e.visit(i),i.value}catch(n){D.warn(n,"toInt: ")}}return t}var yd=class extends It{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 T(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,s){if(this.coords.length>0){let r=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),r.push(o.num*h/100)}else r.push(o.num*s.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(r.length%2==0){let o=[];for(let a=0;a<r.length;a+=2)o.push(new Lt(e+r[a],t+r[a+1]));return new ss(o)}break;case"rectangle":if(r.length==4)return zr(e+r[0],t+r[1],e+r[0]+r[2],t+r[1]+r[3]);break;case"ellipse":if(r.length==4)return zo(e+r[0],t+r[1],r[2],r[3]);break;case"circle":if(r.length==3)return zo(e+r[0],t+r[1],r[2],r[2]);break}}return null}};function Bl(e,t,i,n,s,r){if(e){let o=new yd;try{return e.visit(o),o.getShape(t,i,n,s,r)}catch(a){D.warn(a,"toShape:")}}return zr(t,i,t+n,i+s)}var xd=class extends It{constructor(e){super(),this.reset=e,u(this,"counters",{}),u(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+1,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:1)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function Wi(e,t){let i=new xd(t);try{e.visit(i)}catch(n){D.warn(n,"toCounters:")}return i.counters}var Sd=class extends Ei{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ct(this.transformer.transformURL(e.url,this.baseUrl))}};function Es(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Cd=class{constructor(e,t){this.targetId=e,this.resolved=t,u(this,"pageCounters",null),u(this,"spineIndex",-1),u(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Ed=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},kd=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,u(this,"styler",null),u(this,"namedStringValues",{}),u(this,"runningElements",{})}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(ke(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let r=this.counterStore.currentPageCounters[e];return r&&r.length?r[r.length-1]:null},n=new De(this.pageScope,()=>t(i()),`page-counter-${e}`),s=r=>t(r[r.length-1]);return this.counterStore.registerPageCounterExpr(e,s,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new De(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}getTargetCounterVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e),r=this.getTargetCounters(n,s,!1);if(r&&r[t]){let a=r[t];return new Fe(this.rootScope,i(a[a.length-1]||null))}let o=new De(this.pageScope,()=>{if(r=this.getTargetCounters(n,s,!0),r)if(r[t]){let a=r[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(s);if(a)if(this.counterStore.resolveReference(s),a[t]){let h=a[t];return i(h[h.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,s),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e);return new De(this.pageScope,()=>{let r=this.getTargetPageCounters(s);if(r){this.counterStore.resolveReference(s);let o=r[t]||[],a=this.getTargetCounters(n,s,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counters-${t}-of-${e}`)}getNamedStringVal(e,t){return new De(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new De(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let s=Object.keys(n).map(d=>parseInt(d,10)).sort(nl),r=this.counterStore.currentPage,o=r.isBlankPage?r.offset-1:r.offset,a=r.isBlankPage?o:Math.max(o,...Array.from(r.container.querySelectorAll(`[${xt}]`)).map(d=>parseInt(d.getAttribute(xt),10))),h=-1,l=-1,c=-1,p=-1;for(let d=0;d<s.length;d++){let f=s[d],g=d>0?s[d-1]:-1,m=d<s.length-1?s[d+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,p=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let v=r.container.querySelector(`[${xt}="${f}"]`);if(!v)l<0&&(l=f);else{let b=r.container.querySelector(`[${xt}="${o}"]`);if(b||(b=r.container.querySelector(`[${xt}="0"]`)),b){for(let w=b;w;w=w.firstElementChild)if(w===v){l=f;break}}}}c=f}else(m>a||m<0)&&(h=l=c=p=f)}return n[{first:h,start:l,last:c,"first-except":p}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]={});n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]={});i[t]=String(t)}},Nd=class{constructor(e){this.documentURLTransformer=e,u(this,"countersById",{}),u(this,"pageCountersById",{}),u(this,"currentPageCounters",{}),u(this,"previousPageCounters",{}),u(this,"currentPageCountersStack",[]),u(this,"pageIndicesById",{}),u(this,"currentPage",null),u(this,"newReferencesOfCurrentPage",[]),u(this,"referencesToSolve",[]),u(this,"referencesToSolveStack",[]),u(this,"unresolvedReferences",{}),u(this,"resolvedReferences",{}),u(this,"pagesCounterExprs",[]),u(this,"pageCounterExprs",[]),u(this,"targetCounterExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Ed(this,e)}createCounterResolver(e,t,i){return new kd(this,e,t,i)}setCurrentPage(e){this.currentPage=e}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Es(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let o=n.evaluate(t);o&&(i=Wi(o,!0))}if(i)for(let o in i)this.definePageCounter(o,i[o]);let s,r=e["counter-increment"];if(r){let o=r.evaluate(t);o&&(s=Wi(o,!1))}s?"page"in s||(s.page=1):(s={},s.page=1);for(let o in s){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=s[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Es(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let s=0;s<this.referencesToSolve.length;){let r=this.referencesToSolve[s];if(r.targetId===e){if(r.resolve(),this.referencesToSolve.splice(s,1),t){let o=t.indexOf(r);o>=0&&t.splice(o,1)}i.push(r),n=!0}else s++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Cd(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let r=Es(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=r;let a=this.pageIndicesById[o];if(a&&a.pageIndex<t){let h=this.resolvedReferences[o];if(h){let l=this.unresolvedReferences[o];l||(l=this.unresolvedReferences[o]=[]);let c;for(;c=h.shift();)c.unresolve(),l.push(c)}}this.pageIndicesById[o]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,s;for(;s=this.newReferencesOfCurrentPage.shift();){s.pageCounters=n,s.spineIndex=e,s.pageIndex=t;let r;s.isResolved()?(r=this.resolvedReferences[s.targetId],r||(r=this.resolvedReferences[s.targetId]=[])):(r=this.unresolvedReferences[s.targetId],r||(r=this.unresolvedReferences[s.targetId]=[])),r.every(o=>!s.equals(o))&&r.push(s)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(s=>{let r=this.unresolvedReferences[s];r&&(t=t.concat(r))}),t.sort((s,r)=>s.spineIndex-r.spineIndex||s.pageIndex-r.pageIndex);let i=[],n=null;return t.forEach(s=>{!n||n.spineIndex!==s.spineIndex||n.pageIndex!==s.pageIndex?(n={spineIndex:s.spineIndex,pageIndex:s.pageIndex,pageCounters:s.pageCounters,refs:[s]},i.push(n)):n.refs.push(s)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof De){if(e.str=="viv-leader"){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute("data-viv-leader",e.key),r.setAttribute("data-viv-leader-value",t),r}else if(e.str.startsWith("running-element-")){let r=t&&i.querySelectorAll(`[${xt}="${t}"]`);if(!r||r.length===0)return null;let o=r[r.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(Ps,e.key),r}}let n=this.pagesCounterExprs.findIndex(r=>r.expr===e)>=0,s=!n&&this.pageCounterExprs.findIndex(r=>r.expr===e)>=0;if(n||s){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(n?ks:Ns,e.key),r}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Ns}]`);for(let n of t){let s=n.getAttribute(Ns),r=this.pageCounterExprs.find(l=>l.expr.key===s),o=(r?.expr).str,a=o?.replace(/^page-counters?-/,""),h=this.currentPageCounters[a];h&&(n.textContent=r.format(h))}let i=e.querySelectorAll(`[${Ps}]`);for(let n of i)n.setAttribute($o,!0)}finishLastPage(e){let t=e.root.querySelectorAll(`[${ks}]`),i=e.contentContainer.childElementCount;for(let s of t){let r=s.getAttribute(ks),o=this.pagesCounterExprs.findIndex(a=>a.expr.key===r);o>=0,s.textContent=this.pagesCounterExprs[o].format([i])}let n=e.root.querySelectorAll(`[${$o}]`);for(let s of n){let r=s.getAttribute(Ps),o=this.targetCounterExprs.find(a=>a.expr.key===r);if(o&&o.transformedId){let a=this.pageCountersById[o.transformedId];if(a){let h=a[o.name];h&&(s.textContent=o.format(h[h.length-1]))}}}}createLayoutConstraint(e){return new Pd(this,e)}},ks="data-vivliostyle-pages-counter",Ns="data-vivliostyle-page-counter",Ps="data-vivliostyle-target-counter",$o="data-vivliostyle-target-counter-in-running",Pd=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}};function Td(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 $t(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Td)}var Id=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 Oe(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 yt=[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];yt[NaN]=80;var wt=[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];wt[NaN]=43;var Ad=[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];wt[NaN]=43;var _l=[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];_l[NaN]=35;var Ml=[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];Ml[NaN]=45;var Gs=[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];Gs[NaN]=37;var Ws=[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];Ws[NaN]=38;var Gt=Oe(35,[61,36]),Rd=Oe(35,[58,77]),Ld=Oe(35,[61,36,124,50]),Fd=Oe(35,[38,51]),Od=Oe(35,[42,54]),Bd=Oe(39,[42,55]),_d=Oe(54,[42,55,47,56]),Md=Oe(62,[62,82]),zd=Oe(35,[61,36,33,70]),Dd=Oe(62,[45,71]),Vd=Oe(63,[45,81]),Ts=Oe(76,[10,72,13,72]),Ud=Oe(39,[39,46,10,72,13,72,92,48]),Hd=Oe(39,[34,46,10,72,13,72,92,49]),$d=Oe(39,[39,47,10,74,13,74,92,48]),Gd=Oe(39,[34,47,10,74,13,74,92,49]),Go=Oe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Wd=Oe(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]),jd=Oe(39,[39,68,10,74,13,74,92,75,NaN,67]),Xd=Oe(39,[34,68,10,74,13,74,92,75,NaN,67]),qd=Oe(72,[9,39,10,39,13,39,32,39,41,69]),Yd=15,gt=class{constructor(e,t){this.input=e,this.handler=t,u(this,"indexMask"),u(this,"buffer"),u(this,"tail",0),u(this,"curr",0),u(this,"position",0),this.indexMask=Yd,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Id}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=yt,s=this.input,r=this.position,o=this.buffer,a=0,h=0,l="",c=0,p=!1,d=o[e],f=-9;for(;;){let g=s.charCodeAt(r);switch(n[g]||n[65]){case 72:l=s.substring(h,r),isNaN(g)?a=0:a=54,n=yt;break;case 1:r++,p=!0;continue;case 2:h=r++,n=Gs;continue;case 3:a=1,h=r++,n=wt;continue;case 4:h=r++,a=31,n=Gt;continue;case 33:a=2,h=++r,n=Ud;continue;case 34:a=2,h=++r,n=Hd;continue;case 6:h=++r,a=7,n=wt;continue;case 7:h=r++,a=32,n=Gt;continue;case 8:h=r++,a=21;break;case 9:h=r++,a=32,n=Fd;continue;case 10:h=r++,a=10;break;case 11:h=r++,a=11;break;case 12:h=r++,a=36,n=Gt;continue;case 13:h=r++,a=23;break;case 14:h=r++,a=16;break;case 15:a=24,h=r++,n=_l;continue;case 16:h=r++,n=Ad;continue;case 78:h=r++,a=9,n=wt;continue;case 17:h=r++,a=19,n=Od;continue;case 18:h=r++,a=18,n=Rd;continue;case 77:r++,a=50;break;case 19:h=r++,a=17;break;case 20:h=r++,a=38,n=zd;continue;case 21:h=r++,a=39,n=Gt;continue;case 22:h=r++,a=37,n=Gt;continue;case 23:h=r++,a=22;break;case 24:h=++r,a=20,n=wt;continue;case 25:h=r++,a=14;break;case 26:h=r++,a=15;break;case 27:h=r++,a=12;break;case 28:h=r++,a=13;break;case 29:h=r++,f=h,a=1,n=Ts;continue;case 30:h=r++,a=33,n=Gt;continue;case 31:h=r++,a=34,n=Ld;continue;case 32:h=r++,a=35,n=Gt;continue;case 35:break;case 36:r++,a=a+41-31;break;case 37:a=5,c=parseInt(s.substring(h,r),10);break;case 38:a=4,c=parseFloat(s.substring(h,r));break;case 39:r++;continue;case 40:a=3,c=parseFloat(s.substring(h,r)),h=r++,n=wt;continue;case 41:a=3,c=parseFloat(s.substring(h,r)),l="%",h=r++;break;case 42:r++,n=Ws;continue;case 43:if(l=$t(s.substring(h,r)),a===27&&g===63||a===1&&l.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(s.substring(r-1))){a=27,r++;continue}break;case 44:f=r++,n=Ts;continue;case 45:l=$t(s.substring(h,r));break;case 46:l=s.substring(h,r),r++;break;case 47:l=$t(s.substring(h,r)),r++;break;case 48:f=r,r+=2,n=$d;continue;case 49:f=r,r+=2,n=Gd;continue;case 50:r++,a=25;break;case 51:r++,a=26;break;case 52:if(l=s.substring(h,r),a==1){if(r++,l.toLowerCase()=="url"){n=Go;continue}a=6}break;case 53:if(l=$t(s.substring(h,r)),a==1){if(r++,l.toLowerCase()=="url"){n=Go;continue}a=6}break;case 54:n=Bd,r++;continue;case 55:n=_d,r++;continue;case 56:n=yt,r++;continue;case 57:n=Md,r++,s[r]!==">"&&(a=1,n=wt);continue;case 81:a=51,l=s.substring(h,++r),n=yt;break;case 82:a=52,l=s.substring(h,++r),n=yt;break;case 58:a=5,n=Gs,r++;continue;case 59:a=4,n=Ws,r++;continue;case 60:a=1,n=wt,r++;continue;case 61:a=1,n=Ts,f=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:h=r++,n=Wd;continue;case 65:h=++r,n=jd;continue;case 66:h=++r,n=Xd;continue;case 67:a=8,l=$t(s.substring(h,r)),r++;break;case 69:r++;break;case 70:n=Dd,r++;continue;case 71:n=Vd,r++;continue;case 79:if(r-f<8&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:a=8,l=$t(s.substring(h,r)),r++,n=qd;continue;case 74:if(r++,r-f<9&&s.substring(f+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,l="E_CSS_UNEXPECTED_NEWLINE",n=yt;break;case 73:if(r-f<9&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,n=wt;continue}l=$t(s.substring(h,r));break;case 75:f=r++;continue;case 76:r++,n=Ml;continue;default:if(n!==yt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=r,a=0}if(d.type=a,d.precededBySpace=p,d.num=c,d.text=l,d.position=h,e++,e>=t)break;n=yt,p=!1,d=o[e&i]}this.position=r,this.tail=e&i}},Ie=null,js=null;function Xs(){return Ie}function F(e){if(!Ie)throw new Error("E_TASK_NO_CONTEXT");Ie.name||(Ie.name=e);let t=Ie,i=new rs(t,t.top,e);return t.top=i,i.state=1,i}function Zd(e){return new Qd(e||new Jd)}function N(e){return new qs(e)}function yi(e,t,i){let n=F(e);n.handler=i;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function Kd(e,t){return(Ie?Ie.getScheduler():js||Zd()).run(e,t)}var Jd=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Qd=class{constructor(e){this.timer=e,u(this,"timeout",1),u(this,"slice",25),u(this,"sliceOverTime",0),u(this,"queue"),u(this,"wakeupTime",null),u(this,"timeoutToken",null),u(this,"inTimeSlice",!1),u(this,"order",0),this.queue=new Lc,js||(js=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){D.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new ep(this,t||"");i.top=new rs(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let s=()=>{i.running=!1;for(let r of i.callbacks)try{r()}catch(o){D.error(o)}};try{e().then(r=>{i.result=r,s()})}catch(r){i.raise(r),s()}});let n=Ie;return Ie=i,this.schedule(i.top.suspend("bootstrap")),Ie=n,i}},zl=class{constructor(e){this.task=e,u(this,"scheduledTime",0),u(this,"order",0),u(this,"result",null),u(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Ie;return Ie=e,e.top.finish(this.result),Ie=t,!0}return!1}cancel(){this.canceled=!0}},ep=class{constructor(e,t){this.scheduler=e,this.name=t,u(this,"callbacks",[]),u(this,"exception",null),u(this,"running",!0),u(this,"result",null),u(this,"waitTarget",null),u(this,"top",null),u(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Ie&&this.continuation){this.continuation.cancel();let t=new zl(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=F("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&D.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
5
5
  ---- async ---
6
6
  `:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
7
- `;e.frameTrace=t}}},Xs=class zl{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new zl(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},ep=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new rs(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 Xs(e)):new Xs(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}},rs=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,u(this,"res",null),u(this,"state"),u(this,"callback",null),u(this,"handler",null),this.state=0}checkEnvironment(){if(!Ie)throw new Error("F_TASK_NO_CONTEXT");if(this!==Ie.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new ep(this)}finish(e){this.checkEnvironment(),Ie&&!Ie.exception&&(this.res=e),this.state=2;let t=this.parent;if(Ie&&(Ie.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=F("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(D.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=F("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=F("Frame.loop"),i=n=>{try{for(;n;){let s=e();if(s.isPending()){s.then(i);return}else s.then(r=>{n=r})}t.finish(!0)}catch(s){t.task.raise(s,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Ie;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new tp(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 Ml(this.task);return this.task.continuation=t,Ie=null,this.task.waitTarget=e||null,t}},tp=class extends rs{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},fn=class{constructor(e,t){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=js().getScheduler().run(()=>{let e=F("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(s){D.error(s,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?N(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},os=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=F("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return N(!1)}).then(()=>{t.finish(!0)}),t.result()},Dl=`
7
+ `;e.frameTrace=t}}},qs=class Dl{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Dl(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},tp=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new rs(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 qs(e)):new qs(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}},rs=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,u(this,"res",null),u(this,"state"),u(this,"callback",null),u(this,"handler",null),this.state=0}checkEnvironment(){if(!Ie)throw new Error("F_TASK_NO_CONTEXT");if(this!==Ie.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new tp(this)}finish(e){this.checkEnvironment(),Ie&&!Ie.exception&&(this.res=e),this.state=2;let t=this.parent;if(Ie&&(Ie.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=F("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(D.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=F("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=F("Frame.loop"),i=n=>{try{for(;n;){let s=e();if(s.isPending()){s.then(i);return}else s.then(r=>{n=r})}t.finish(!0)}catch(s){t.task.raise(s,t)}};return i(!0),t.result()}loopWithFrame(e){let t=Ie;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new ip(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 zl(this.task);return this.task.continuation=t,Ie=null,this.task.waitTarget=e||null,t}},ip=class extends rs{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},mn=class{constructor(e,t){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=Xs().getScheduler().run(()=>{let e=F("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(s){D.error(s,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?N(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},os=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=F("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return N(!1)}).then(()=>{t.finish(!0)}),t.result()},Vl=`
8
8
  @media screen {
9
9
  [data-vivliostyle-viewer-viewport] {
10
10
  background: #aaaaaa;
@@ -70,7 +70,7 @@ var nc=Object.create;var vn=Object.defineProperty;var sc=Object.getOwnPropertyDe
70
70
  transform-origin: center top;
71
71
  }
72
72
  }
73
- `,Vl=`
73
+ `,Ul=`
74
74
  [data-vivliostyle-layout-box] {
75
75
  position: absolute;
76
76
  left: 0;
@@ -201,7 +201,7 @@ var nc=Object.create;var vn=Object.defineProperty;var sc=Object.getOwnPropertyDe
201
201
  }
202
202
  }
203
203
  }
204
- `,Ul=`
204
+ `,Hl=`
205
205
  /*
206
206
  * Copyright 2013 Google, Inc.
207
207
  * Copyright 2015 Daishinsha Inc.
@@ -805,7 +805,7 @@ word-wrap = overflow-wrap;
805
805
  [adapt,webkit]start = inline-start;
806
806
  [adapt,webkit]end = inline-end;
807
807
 
808
- `,Hl=`
808
+ `,$l=`
809
809
  <!DOCTYPE html>
810
810
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
811
811
  <head>
@@ -828,7 +828,7 @@ word-wrap = overflow-wrap;
828
828
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
829
829
 
830
830
  </body>
831
- </html>`,$l=`
831
+ </html>`,Gl=`
832
832
  @namespace "http://www.w3.org/1999/xhtml";
833
833
 
834
834
  :root {
@@ -955,7 +955,7 @@ word-wrap = overflow-wrap;
955
955
  margin: 10%;
956
956
  }
957
957
  }
958
- `,Gl=`
958
+ `,Wl=`
959
959
  @namespace "http://www.w3.org/1999/xhtml";
960
960
  @namespace m "http://www.w3.org/1998/Math/MathML";
961
961
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1329,7 +1329,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1329
1329
  epub|case[required-namespace::supported] ~ epub|default {
1330
1330
  display: none;
1331
1331
  }
1332
- `,Wl=`
1332
+ `,jl=`
1333
1333
  @namespace "http://www.w3.org/1999/xhtml";
1334
1334
 
1335
1335
  *:not([data-vivliostyle-role=doc-toc],
@@ -1359,7 +1359,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1359
1359
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1360
1360
  -adapt-behavior: toc-container;
1361
1361
  }
1362
- `,jl=`
1362
+ `,Xl=`
1363
1363
  [data-viv-margin-discard~="block-start"] {
1364
1364
  margin-block-start: 0 !important;
1365
1365
  }
@@ -1478,12 +1478,12 @@ span[data-viv-leader] {
1478
1478
  text-orientation: mixed;
1479
1479
  white-space: pre;
1480
1480
  }
1481
- `;function as(e,t,i,n,s){let r=F("ajax"),o=new XMLHttpRequest,a=r.suspend(o),h={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};o.open(i||"GET",e,!0),t&&(o.responseType=t),o.onreadystatechange=()=>{if(o.readyState===4){if(h.status=o.status,h.url=o.responseURL,h.statusText=o.statusText||o.status==404&&"Not Found"||"",h.status==200||h.status==0)if((!t||t==="document")&&o.responseXML&&o.responseXML.documentElement.localName!="parsererror")h.responseXML=o.responseXML,h.contentType=o.responseXML.contentType;else if((!t||t==="document")&&o.response instanceof Document)h.responseXML=o.response,h.contentType=o.response.contentType;else{let l=o.response;(!t||t==="text")&&typeof l=="string"?h.responseText=l:l?typeof l=="string"?h.responseBlob=Xl([l]):h.responseBlob=l:D.warn("Unexpected empty success response for",e);let c=o.getResponseHeader("Content-Type");c&&(h.contentType=c.replace(/(.*);.*$/,"$1"))}a.schedule(h)}};try{n?(o.setRequestHeader("Content-Type",s||"text/plain; charset=UTF-8"),o.send(n)):(/^file:|^https?:\/\/[^/]+\.githubusercontent\.com|\.(xhtml|xht|opf)$/i.test(e)?/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?o.overrideMimeType("text/html; charset=Shift_JIS"):/\.(html|htm)$/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/\.(xhtml|xht|xml|opf)$/i.test(e)?o.overrideMimeType("application/xml; charset=UTF-8"):/\.(txt|css)$/i.test(e)?o.overrideMimeType("text/plain; charset=UTF-8"):o.overrideMimeType("text/html; charset=UTF-8"):/^data:,(<|%3c)/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/^data:,/i.test(e)&&o.overrideMimeType("text/plain; charset=UTF-8"),o.send(null))}catch(l){D.warn(l,`Error fetching ${e}`),a.schedule(h)}return r.result()}function Xl(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function ip(e){let t=F("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function np(e){return URL.createObjectURL(e)}var zr=class{constructor(e,t){this.parser=e,this.type=t,u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Ct(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=F("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=ke("user-agent.xml",Zt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent(Hl)}`),as(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);s?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=r),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ct(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new fn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ct(e)]}delete(e){delete this.resources[Ct(e)]}};function sp(e,t){let i=e.responseText;return N(i?Ir(i):null)}function rp(){return new zr(sp,"text")}function si(e,t,i){let n=new fn(()=>{let s=F("loadElement"),r=s.suspend(e),o=!1,a=h=>{o||(o=!0,r.schedule(h?h.type:"timeout"))};return e.addEventListener("load",a,!1),e.addEventListener("error",a,!1),e.addEventListener("abort",a,!1),e.namespaceURI=="http://www.w3.org/2000/svg"?(t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),setTimeout(a,300)):e.localName==="script"?setTimeout(a,3e3):t&&(e.src=t,i&&(e.alt=i)),s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Go=0,op=16777216,ql=33554432,Yl=50331648,Kl=67108864,ap=83886080,lp=100663296,Dr=class{constructor(e){this.scope=e,u(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Go;case"User":return lp;default:return ap}}getBaseSpecificity(){switch(this.flavor){case"UA":return Go;case"User":return op;default:return ql}}},hp=class extends Dr{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;D.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},Wo=class extends Dr{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,u(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},gn=class extends Wo{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Wo(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ee=[],$n=[],fe=[],Ce=[],ot=[],Qe=[],Se=[],Le=[],ce=[],Me=[],je=[],_e=[],xe=[],ri=55,oi=56,En=57;Ee[1]=28,Ee[36]=29,Ee[7]=29,Ee[9]=29,Ee[14]=29,Ee[18]=29,Ee[50]=29,Ee[20]=30,Ee[13]=27,Ee[0]=200,$n[1]=46,$n[0]=200,Qe[1]=2,Qe[36]=4,Qe[7]=6,Qe[9]=8,Qe[14]=10,Qe[18]=14,Qe[50]=42,fe[37]=11,fe[23]=12,fe[35]=56,fe[1]=1,fe[36]=3,fe[7]=5,fe[9]=7,fe[14]=9,fe[12]=13,fe[18]=55,fe[50]=58,fe[16]=41,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[18]=55,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[18]=14,ot[50]=42,ot[14]=10,ot[12]=13,Se[1]=15,Se[7]=16,Se[4]=17,Se[5]=18,Se[3]=19,Se[2]=20,Se[8]=21,Se[27]=57,Se[16]=22,Se[19]=23,Se[6]=24,Se[11]=25,Se[17]=26,Se[13]=48,Se[31]=47,Se[23]=54,Se[0]=44,Le[1]=31,Le[4]=32,Le[5]=32,Le[3]=33,Le[2]=34,Le[10]=40,Le[6]=38,Le[31]=36,Le[24]=36,Le[32]=35,ce[1]=45,ce[16]=37,ce[37]=37,ce[38]=37,ce[47]=37,ce[48]=37,ce[39]=37,ce[49]=37,ce[41]=37,ce[26]=37,ce[25]=37,ce[23]=37,ce[24]=37,ce[19]=37,ce[21]=37,ce[36]=37,ce[18]=37,ce[22]=37,ce[11]=39,ce[12]=43,ce[17]=49,Me[0]=200,Me[12]=50,Me[13]=51,Me[14]=50,Me[15]=51,Me[10]=50,Me[11]=51,Me[17]=53,je[0]=200,je[12]=50,je[13]=52,je[14]=50,je[15]=51,je[10]=50,je[11]=51,je[17]=53,_e[0]=200,_e[12]=50,_e[13]=51,_e[14]=50,_e[15]=51,_e[10]=50,_e[11]=51,xe[11]=0,xe[16]=0,xe[22]=1,xe[18]=1,xe[26]=2,xe[25]=2,xe[38]=3,xe[37]=3,xe[48]=3,xe[47]=3,xe[39]=3,xe[49]=3,xe[41]=3,xe[23]=4,xe[24]=4,xe[36]=5,xe[19]=5,xe[21]=5,xe[0]=6,xe[ri]=2,xe[oi]=2;var mn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(G)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof Ai){if(r.text===")")s++;else if(r.text==="("){if(s===0)return null;s--}}while(typeof r<"u"&&typeof r!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new ve(i.slice(n+1,i.length))),e==",")return null;n++;do r=i[--n];while(typeof r<"u"&&(typeof r!="string"||r==","));if(o=i.length-(n+1),r=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=je);let h=new ki(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof ft&&h.values[0].name;(!Nt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=je)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=je,null;if(o>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof $e?a:a?new Ai(a.toString()):G}exprError(e,t){this.actions=this.propName?je:Me,D.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,s=i.pop(),r;for(;;){let o=i.pop();if(e==11){let a=[s];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new Xc(n.getScope(),h,l);a.unshift(c)}return i.push(new V(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();s=new $i(n.getScope(),Ms(l,h),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new Lo(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new Ot(n.getScope(),s);else if(o==-24)s=new fl(n.getScope(),s);else if(o==-En)s=new Wc(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(xe[e]>xe[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Lr(n.getScope(),r,s);break;case ri:s=new jc(n.getScope(),r,s);break;case oi:s=new qc(n.getScope(),r,s);break;case 25:s=new Fr(n.getScope(),r,s);break;case 38:s=new Yc(n.getScope(),r,s);break;case 37:s=new Zc(n.getScope(),r,s);break;case 48:s=new Kc(n.getScope(),r,s);break;case 47:s=new Vs(n.getScope(),r,s);break;case 39:case 49:s=new Or(n.getScope(),r,s);break;case 41:s=new Jc(n.getScope(),r,s);break;case 23:s=new gl(n.getScope(),r,s);break;case 24:s=new ml(n.getScope(),r,s);break;case 36:s=new Br(n.getScope(),r,s);break;case 19:s=new wl(n.getScope(),r,s);break;case 21:s=new bl(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new td(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new Lo(n.getScope(),r,s);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(r),i.push(o),i.push(s),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(s),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,s;if(t)s=e.text,n=e.position+s.length+1;else if(e.type===10){let c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),s=c.text,n=p.position+1;else{if(c.type===10||c.type===6||c.type===1&&c.text.toLowerCase()==="not"&&(p.type===10||p.type===6))return null;n=e.position+1}}else return null;let r=0,o,a=0;for(;r>=0;)switch(i.consume(),o=i.token(),o.type){case 11:r--;break;case 10:case 6:r++;break;case 16:r===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let h=o.position,l=t&&s==="selector"&&a>0?"":i.input.substring(n,h).trim();return new id(this.handler.getScope(),s,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let s=t.type===24,r=t.type===23||s;if(r&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,r)return null}else if(n<0){if(r)return null}else if(n>=0&&!r)return null;this.tokenizer.consume()}else if(r)return null;return[i,s&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let s of n)switch(s){case"vertical":t=lt(i,t,new Ot(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=lt(i,t,new ze(i,"pref-horizontal"));break;case"day":t=lt(i,t,new Ot(i,new ze(i,"pref-night-mode")));break;case"night":t=lt(i,t,new ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new V(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(e,t,i,n,s,r){let o=this.handler,a=this.tokenizer,h=this.valStack,l,c,p,d,f,g,m,y=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),s&&y===null&&(y=l.position-1,a.input[y]==="("&&y++),this.actions===Se&&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 Ai(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=je):(this.actions=Qe,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Se,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=je,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Se,h.splice(0,h.length);continue;case 29:this.actions=Qe,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=_e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),p=this.namespacePrefixToURI[l.text],p!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(p,l.text),s?this.actions=Ce:this.actions=fe,a.consume();break;case 36:o.tagSelector(p,null),s?this.actions=Ce:this.actions=fe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else this.actions=Me,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=_e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),s?this.actions=Ce:this.actions=fe,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Ce:this.actions=fe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),s?this.actions=Ce:this.actions=fe;continue;case 6:switch(d=l.text,a.consume(),d){case"is":case"not":case"where":case"has":this.actions=Qe,o.startFuncWithSelector(d),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,d==="has")?this.actions=fe:this.actions=_e;continue;case"lang":case"href-epub-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),d==="href-epub-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)break;break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(d,m),a.consume(),s?this.actions=Ce:this.actions=fe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Me;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 6:if(d=l.text,a.consume(),d=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(d,m),s?this.actions=Ce:this.actions=fe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Me;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)d=l.text,a.consume();else if(l.type==36)d=null,a.consume();else if(l.type==34)d="";else{this.actions=_e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(p=d&&this.namespacePrefixToURI[d],p===void 0){this.actions=_e,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=_e,o.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}d=l.text,a.consume(),l=a.token()}else p="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:o.attributeSelector(p,d,0,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;default:this.actions=_e,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:o.attributeSelector(p,d,f,l.text),a.consume(),l=a.token();break;default:this.actions=_e,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=_e,o.error("E_CSS_ATTR",l);continue}s?this.actions=Ce:this.actions=fe,a.consume();continue;case 11:o.childSelector(),this.actions=ot,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=ot,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=ot,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=Ee,a.consume();continue;case 41:o.nextSelector(),this.actions=Qe,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Pl(l.text)),a.consume();continue;case 17:h.push(new Vt(l.num)),a.consume();continue;case 18:h.push(new Qt(l.num)),a.consume();continue;case 19:h.push(new T(l.num,l.text)),a.consume();continue;case 20:h.push(new Ae(l.text)),a.consume();continue;case 21:h.push(new ct(ke(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Tl(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(ns),a.consume();continue;case 24:d=l.text.toLowerCase(),d=="-epubx-expr"||d=="env"?(this.actions=Le,this.exprContext=0,h.push("{")):(h.push(d),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new Ai("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?$n:Ee;continue;case 44:for(a.consume();h.length>0;){let b=h.length;if(g=this.valStackReduce(";",l),!g||h.length===b)break}return t?(this.result=g,!0):(this.propName&&g&&o.property(this.propName,g,this.propImportant),!0);case 31:if(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new ze(o.getScope(),Ms(l.text,c.text))),this.actions=ce),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Ao(o.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Ao(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==ri&&h[h.length-1]!==oi&&(c.type===10||c.type===6)){h.push(-En),a.consume();continue}else h.push(new ze(o.getScope(),l.text));this.actions=ce}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ce;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Fe(o.getScope(),l.num)),a.consume(),this.actions=ce;continue;case 33:d=l.text,d=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?d="vh":d="vw"),h.push(new Jt(o.getScope(),l.num,d)),a.consume(),this.actions=ce;continue;case 34:h.push(new Fe(o.getScope(),l.text)),a.consume(),this.actions=ce;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Sl(o.getScope(),l.num)),a.consume(),this.actions=ce);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Le,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==oi&&h[h.length-2]!==-En?(this.actions=Le,this.exprStackReduce(ri,l),h.push(ri),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==ri&&h[h.length-2]!==-En?(this.actions=Le,this.exprStackReduce(oi,l),h.push(oi),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Se),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ee)),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=Ee,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Ee,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ce;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Ee,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(d=l.text.toLowerCase(),d){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Le,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Me;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(d=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[d]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Me;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){d=l.text.toLowerCase(),d!="utf-8"&&d!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${d}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Me;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),d){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(d),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){d=l.text,a.consume(),a.consume(),o.startFootnoteRule(d),this.ruleStack.push("-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=Qe;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=ot;continue;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(d),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Le,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Le,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Le,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(d),o.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,w=null,S=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(w=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(),d){case"-epubx-page-master":o.startPageMasterRule(b,w,S);break;case"-epubx-partition":o.startPartitionRule(b,w,S);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,w,S);break}this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${d}`,l),this.actions=_e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${d}`,l),this.actions=Me;continue}o.error(`E_CSS_AT_SYNTAX ${d}`,l),this.actions=Me;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ee;continue}case 51:if(s&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=Ee),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ee),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(s){switch(l.type){case 16:case 11:if(this.actions===Qe)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(y,l.position);o.pushSelectorText(b),y=l.position+1}if(l.type===16){o.nextSelector(),this.actions=Qe,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=fe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=_e;continue}if(this.actions!==Me&&this.actions!==_e&&this.actions!==je){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===Se){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ai(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Le&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ee,a.consume();continue}else{if(l.type===17&&this.actions==Le)return this.actions=Ee,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=je:this.actions=_e;continue}a.consume();continue}}return!1}},Zl=class extends Dr{constructor(e){super(null),this.scope=e}error(e,t){D.warn(e,t.toString())}getScope(){return this.scope}};function up(e,t,i,n,s){let r=F("parseStylesheet"),o=new mn(Ee,e,t,i),a=null;return s&&(a=dp(new gt(s,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),r.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let l=ke(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let c=F("parseStylesheet.import");return Jl(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,c.finish(!0)}),c.result()}let h=r.timeSlice();if(h.isPending)return h}return N(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function Vr(e,t,i,n,s){return vi("parseStylesheetFromText",r=>{let o=new gt(e,t);up(o,t,i,n,s).thenFinish(r)},(r,o)=>{D.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Jl(e,t,i,n){return vi("parseStylesheetFromURL",s=>{as(e).then(r=>{r.responseText?Vr(r.responseText,t,e,i,n).then(o=>{o||D.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{D.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function Ti(e,t,i){let n=new mn(Se,t,new Zl(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function cp(e,t,i){new mn($n,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function dp(e,t,i){let n=new mn(Le,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var pp={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function fp(e){return!!pp[e]}function gp(e,t,i){let n=t.evaluate(e);switch(typeof n){case"number":return fp(i)?n==Math.round(n)?new Qt(n):new Vt(n):new T(n,"px");case"string":return n?Ti(t.scope,new gt(n,null),""):G;case"boolean":return n?v._true:v._false;case"undefined":return G}throw new Error("E_UNEXPECTED")}function Ql(e,t){let i={};return Object.keys(e).forEach(n=>{let s=i[n]={},r=e[n];Object.keys(r).forEach(o=>{s[o]=r[o].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function eh(e,t,i,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let r=s[i||"ltr"];if(!r)throw new Error(`unknown direction: ${i}`);for(let o of r){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var th={"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"}]}},mp=Ql(th,!0);function ih(e,t,i){return eh(e,t,i||null,mp)}var wp=Ql(th,!1);function nh(e,t,i){return eh(e,t,i||null,wp)}var bp={"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 yp(e,t){let i=bp[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 Ur(e,t,i){let n={display:t.style.display,position:t.style.position,width:t.style.width,maxWidth:t.style.maxWidth,minWidth:t.style.minWidth,height:t.style.height,maxHeight:t.style.maxHeight,minHeight:t.style.minHeight,top:t.style.top,right:t.style.right,bottom:t.style.bottom,left:t.style.left},s=t.ownerDocument,r=t.parentNode,o=s.createElement("div");k(o,"position",n.position),r.insertBefore(o,t),o.appendChild(t),k(t,"width","auto"),k(t,"max-width","none"),k(t,"min-width","0"),k(t,"height","auto"),k(t,"max-height","none"),k(t,"min-height","0");function a(I){return e.getElementComputedStyle(t).getPropertyValue(I)}let h=Qa("writing-mode"),l=(h?a(h[0]):null)||a("writing-mode"),c=l==="vertical-rl"||l==="tb-rl"||l==="vertical-lr"||l==="tb-lr",p=c?"height":"width",d=c?"width":"height";function f(){(n.position==="absolute"||n.position==="fixed")&&(k(o,"width",n.width),k(o,"height",n.height),k(o,"top",n.top),k(o,"right",n.right),k(o,"bottom",n.bottom),k(o,"left",n.left)),k(t,"display","block"),k(t,"position","static");let I=a(p);return k(o,"width",""),k(o,"height",""),k(o,"top",""),k(o,"right",""),k(o,"bottom",""),k(o,"left",""),I}function g(){k(t,"display","inline-block"),k(o,p,"99999999px");let I=a(p);return k(o,p,""),I}function m(){k(t,"display","inline-block"),k(o,p,"0");let I=a(p);return k(o,p,""),I}function y(){let I=f(),L=m(),_=parseFloat(I);if(_<=parseFloat(L))return L;{let U=g();return _<=parseFloat(U)?I:U}}function b(){return a(d)}function w(){throw new Error("Getting fill-available block size is not implemented")}let S={};return i.forEach(I=>{var L;let _;switch(I){case"fill-available inline size":_=f();break;case"max-content inline size":_=g();break;case"min-content inline size":_=m();break;case"fit-content inline size":_=y();break;case"fill-available block size":_=w();break;case"max-content block size":case"min-content block size":case"fit-content block size":_=b();break;case"fill-available width":_=c?w():f();break;case"fill-available height":_=c?f():w();break;case"max-content width":_=c?b():g();break;case"max-content height":_=c?g():b();break;case"min-content width":_=c?b():m();break;case"min-content height":_=c?m():b();break;case"fit-content width":_=c?b():y();break;case"fit-content height":_=c?y():b();break}_==="0px"&&t.childNodes.length===1&&((L=t.firstElementChild)==null?void 0:L.localName)==="img"&&!t.firstElementChild.complete&&(_="1px"),S[I]=parseFloat(_),k(t,"position",n.position),k(t,"display",n.display)}),k(t,"width",n.width),k(t,"max-width",n.maxWidth),k(t,"min-width",n.minWidth),k(t,"height",n.height),k(t,"max-height",n.maxHeight),k(t,"min-height",n.minHeight),r.insertBefore(t,o),r.removeChild(o),S}function _i(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 sh(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function rh(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function it(e,t){let i=sh(e);i.includes(t)||(i.push(t),rh(e,i))}function vp(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function xp(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Is(e,t){let i=vp(e);i.includes(t)||(i.push(t),xp(e,i))}function Sp(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var qs={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ke(e){return!!qs[e]}var Cp={left:!0,right:!0,recto:!0,verso:!0};function tn(e){return!!Cp[e]}var Ep={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Gn(e){return!!Ep[e]}function Xe(e,t){if(e)if(t){if(tn(t))return t;if(tn(e))return e;{let i=Ke(e),n=Ke(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:Gn(t)?t:Gn(e)?e:t}}else return e;else return t}function jo(e){return Ke(e)?e:"auto"}ht("SIMPLE_PROPERTY",Sp);var Wi=vc(Sc());function kp(e,t){return(0,Wi.default)(e,t,0)}function Xo(e){return e.reduce((t,i)=>i[0]===Wi.default.DELETE?t:t+i[1],"")}function Np(e,t){return oh(e,t,1)}function Pp(e,t){return oh(e,t,-1)}function oh(e,t,i){let n=0,s=0;return e.some(r=>{for(let o=0;o<r[1].length;o++){switch(r[0]*i){case Wi.default.INSERT:n++;break;case Wi.default.DELETE:n--,s++;break;case Wi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Ys;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Ys||(Ys={}));var fi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(fi||(fi={}));var Wn;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Wn||(Wn={}));var qt;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||_t.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||_t.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(qt||(qt={}));var _t;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(_t||(_t={}));var Pt;(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={}))})(Pt||(Pt={}));var Tp={transform:!0,"transform-origin":!0},Ip={top:!0,bottom:!0,left:!0,right:!0},Hr=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Rp={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 Ap(e,t){let i=Rp[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Ks=class Mi extends Rr{constructor(t,i){super(),this.container=t,this.bleedBox=i,u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(this,"pageType",null),this.hrefHandler=n=>{let s=n.currentTarget,r=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:s,href:r,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(r=>{let o=this.elementsById[r];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[r]});let n=this.delayedItems;for(let r=0;r<n.length;r++){let o=n[r];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||k(o.target,o.name,o.value.toString())}let s=i.getElementClientRect(this.container);this.dimensions.width=s.width,this.dimensions.height=s.height;for(let r=0;r<t.length;r++){let o=t[r],a=this.elementsById[o.ref],h=this.elementsById[o.observer];if(a&&h){let l=Ap(a,o.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(o.event,l,!1)}}}};u(Ks,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Ks,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var ah=Ks,xi="data-adapt-spec",Ze=Pt.Whitespace;function lh(e){switch(e){case"normal":case"nowrap":return Ze.IGNORE;case"pre-line":return Ze.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Ze.PRESERVE;default:return null}}function Ue(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case Ze.PRESERVE:return i.length==0;case Ze.NEWLINE:return!!i.match(/^[ \t]*$/);case Ze.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Lp=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Fp=class{constructor(e,t,i,n,s,r,o,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=s,this.exclusive=r,this.repeated=o,this.last=a,this.breakBefore=h,u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Op(e,t){return e.top-t.top}function Bp(e,t){return t.right-e.right}function hh(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Pt.ShadowType.ROOTLESS&&t.shadowType===Pt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Js(e.shadowContext,t.shadowContext)&&Js(e.nodeShadow,t.nodeShadow)&&hh(e.shadowSibling,t.shadowSibling)}function Mt(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(!hh(e.steps[i],t.steps[i]))return!1;return!0}function _p(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function jn(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Xn(e,t){let i=new zi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Xn(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=Pt.ShadowType,Zs=class{constructor(e,t,i,n,s,r,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=r,this.styler=o,u(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Js(this.parentShadow,e.parentShadow):!1}};function Js(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Mp=class{constructor(e,t){this.outer=e,this.count=t}},zi=class uh{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"verticalAlign","baseline"),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=fi.FloatReference.INLINE,this.whitespace=i?i.whitespace:Ze.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=fi.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.verticalAlign="baseline",this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:Ze.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new uh(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.verticalAlign=this.verticalAlign,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:this.fragmentIndex}}toNodePosition(){var t,i,n;let s=this,r=[];s.shadowType===Pt.ShadowType.ROOTLESS&&(s.floatReference!==fi.FloatReference.INLINE||s.floatSide==="footnote")&&(n=(i=(t=s.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(s=s.parent);do(!s.firstPseudo||!s.parent||s.parent.firstPseudo===s.firstPseudo)&&r.push(s.toNodePositionStep()),s=s.parent;while(s);let o=this.preprocessedTextContent?Pp(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:r,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},zt=class ch{constructor(t){this.primary=t,u(this,"floats",null)}clone(){let t=new ch(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(!Mt(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(!Mt(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},zp=class dh{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new dh(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Dp=class ph{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new ph,i=this.positions,n=t.positions;for(let s=0;s<i.length;s++)n[s]=i[s].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Vp=class fh{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 fh;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let s of i)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&tn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},gh=class{constructor(e){this.element=e,u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1)}getInsetTop(){return this.marginTop+this.borderTop+this.paddingTop}getInsetBottom(){return this.marginBottom+this.borderBottom+this.paddingBottom}getInsetLeft(){return this.marginLeft+this.borderLeft+this.paddingLeft}getInsetRight(){return this.marginRight+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}setVerticalPosition(e,t){this.top=e,this.height=t,k(this.element,"top",`${e}px`),k(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,k(this.element,"left",`${e}px`),k(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+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.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.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):Mr(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 nt(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 nt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Ol(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 nt(e,t,e+i,t+n)}},qn=class extends It{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue.url)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){t instanceof ze&&(i=Ti(t.scope,new gt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof De&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Dt(e){return e!=null&&e!==G&&e!==v.normal&&e!==v.none&&!J(e)}var Re=fi.FloatReference;function Up(e){switch(e){case"inline":return Re.INLINE;case"column":return Re.COLUMN;case"region":return Re.REGION;case"page":return Re.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function gi(e){switch(e){case Re.INLINE:return!1;case Re.COLUMN:case Re.REGION:case Re.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function qo(e,t,i){let n=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=nh(e,n,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=ih(e,n,i),r=yp(s,n);r==="line-left"?e="left":r==="line-right"&&(e="right")}return e!=="left"&&e!=="right"&&(D.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var mh=class{constructor(e,t,i,n,s,r){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=s,this.floatMinWrapBlock=r,u(this,"order",null),u(this,"id",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(e){return!1}},Hp=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=>Mt(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(i=>Mt(i.nodePosition,e));return t>=0?this.floats[t]:null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},wh=class{constructor(e,t,i,n,s){this.floatReference=e,this.floatSide=t,this.continuations=i,this.area=n,this.continues=s}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Yo=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Mt(this.nodePosition,e.nodePosition):!1}},Di=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),e&&e.children.push(this),this.writingMode=r||e&&e.writingMode||v.horizontal_tb,this.direction=o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Hp;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}getParent(e){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${e}`);return this.parent}getPreviousSiblingOf(e,t,i,n){let s=this.children.indexOf(e);s<0&&(s=this.children.length);for(let r=s-1;r>=0;r--){let o=this.children[r];if(o.floatReference===t&&o.flowName===i&&Mt(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Si().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,s)=>n.getOrder()-s.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let s=this.floatFragments.splice(n,1)[0],r=s.area&&s.area.element;r&&r.parentNode&&r.parentNode.removeChild(r),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e)}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(s=>{let r=s.float,o=r.getOrder();o>t&&(!i||o>i.getOrder())&&(i=r)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(s=>s.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i)return this.locked?this.invalidate():(this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)),!0}return this.floatReference===Re.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(s=>s.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(s=>!i.isAllowedToPrecede(s)&&n>s.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let s=this.findPageFloatFragment(i);this.removePageFloatFragment(s)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();return nh(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return ih(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],s=!1,r=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?s||(i.slice(o+1).some(h=>h.includes("block"))?(n.push("snap-block"),s=!0):n.push(a)):a.includes("inline")&&(r||(i.slice(o+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),r=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n],r=this.toLogicalFloatSides(s.floatSide)[0];(r===i||i==="snap-block"&&r==="block-end"||i==="snap-inline"&&r==="inline-end")&&s.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(s),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n){this.container;let s=this.toLogical(e),r=this.toPhysical(e),o=this.getLimitValueInner(s,t,i,n);if(this.parent&&this.parent.container){let a=this.parent.getLimitValue(r,t,i,n);switch(r){case"top":return Math.max(o,a);case"left":return Math.max(o,a);case"bottom":return Math.min(o,a);case"right":return Math.min(o,a);default:}}return o}getLimitValueInner(e,t,i,n){this.container;let s=this.getLimitValuesInner(t,i,n);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){this.container;let n=this.container.originX,s=this.container.originY,r=this.container.getPaddingRect(),o={top:r.y1-s,left:r.x1-n,bottom:r.y2-s,right:r.x2-n,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function a(l,c,p){return l.unit==="%"?p*l.num/100:e.convertLengthToPx(l,c,t)}let h=this.floatFragments;return h.length>0&&(o=h.reduce((l,c)=>{if(i&&!i(c,this))return l;let p=this.toLogicalFloatSides(c.floatSide)[0],d=c.area,f=c.continuations[0].float.floatMinWrapBlock,g=l.top,m=l.left,y=l.bottom,b=l.right,w=l.floatMinWrapBlockStart,S=l.floatMinWrapBlockEnd;switch(p){case"inline-start":d.vertical?g=Math.max(g,d.top+d.height):m=Math.max(m,d.left+d.width);break;case"block-start":d.vertical?(f&&d.left<b&&(w=a(f,d.rootViewNodes[0],r.x2-r.x1)),b=Math.min(b,d.left)):(f&&d.top+d.height>g&&(w=a(f,d.rootViewNodes[0],r.y2-r.y1)),g=Math.max(g,d.top+d.height));break;case"inline-end":d.vertical?y=Math.min(y,d.top):b=Math.min(b,d.left);break;case"block-end":d.vertical?(f&&d.left+d.width>m&&(S=a(f,d.rootViewNodes[0],r.x2-r.x1)),m=Math.max(m,d.left+d.width)):(f&&d.top<y&&(S=a(f,d.rootViewNodes[0],r.y2-r.y1)),y=Math.min(y,d.top));break;default:throw new Error(`Unknown logical float side: ${p}`)}return{top:g,left:m,bottom:y,right:b,floatMinWrapBlockStart:w,floatMinWrapBlockEnd:S}},o)),o.left+=n,o.right+=n,o.top+=s,o.bottom+=s,o}setFloatAreaDimensions(e,t,i,n,s,r,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,s,r,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0]==="snap-inline"){if(!o["inline-start"]&&!o["inline-end"])return null}else if(!o[a[0]])return null;e.clientLayout;let h=this.getLimitValue("block-start",e.layoutContext,e.clientLayout),l=this.getLimitValue("block-end",e.layoutContext,e.clientLayout),c=this.getLimitValue("inline-start",e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-end",e.layoutContext,e.clientLayout),d=e.vertical?e.originX:e.originY,f=e.vertical?e.originY:e.originX;h=e.vertical?Math.min(h,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+d):Math.max(h,e.top+d),l=e.vertical?Math.max(l,e.left+d):Math.min(l,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+d);function g(S,I){let L=S(e.bands,I);return L?(e.vertical&&(L=Al(L)),h=e.vertical?Math.min(h,L.x2):Math.max(h,L.y1),l=e.vertical?Math.max(l,L.x1):Math.min(l,L.y2),!0):r}let m,y,b,w;if(s){let S=e.vertical?Hn(new nt(l,c,h,p)):new nt(c,h,p,l);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!g(dd,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!g(pd,S)||(b=(l-h)*e.getBoxDir(),m=b-e.getInsetBefore()-e.getInsetAfter(),w=(p-c)*e.getInlineDir(),y=w-e.getInsetStart()-e.getInsetEnd(),!r&&(m<=0||y<=0)))return null}else{m=e.computedBlockSize,b=m+e.getInsetBefore()+e.getInsetAfter();let S=(l-h)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let L=this.container.getPaddingRect(),_=this.container.getBoxDir()*(n-(this.container.vertical?L.x2:L.y1)),U=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-n-b);_<=U?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!r&&S<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=Ur(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,w=y+e.getInsetStart()+e.getInsetEnd();let I=(p-c)*e.getInlineDir();if(!r&&I<w)return null}return h-=d,l-=d,c-=f,p-=f,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(c,y):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(p-w*e.getInlineDir(),y),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(h,m):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(l-b*e.getBoxDir(),m),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let e=this.getContainer().vertical;return this.floatFragments.filter(t=>t.floatSide==="block-end").reduce((t,i)=>{let n=i.getOuterRect();return e?Math.max(t,n.x2):Math.min(t,n.y1)},e?0:1/0)}getPageFloatClearEdge(e,t){function i(h){return l=>h.isAnchorAlreadyAppeared(l.float.getId())}function n(h,l){return h.continuations.some(i(l))}let s=t.getPaddingRect(),r=t.vertical?s.x1:s.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return r;o=o.parent}t.clientLayout;let a=this.getLimitValue("block-start",t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",t.layoutContext,t.clientLayout,n)*t.getBoxDir()<r*t.getBoxDir()?r:a}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let s=this.toLogicalFloatSides(t)[0],r=this.toLogical(i),o;r==="all"?o=["block-start","block-end","inline-start","inline-end"]:r==="both"?o=["inline-start","inline-end"]:r==="same"?s==="snap-block"?o=["block-start","block-end"]:o=[s]:o=[r];let a=e.getOrder();function h(p){return d=>d.floatSide===p&&d.getOrder()<a}function l(p,d){return p.children.some(f=>f.floatFragments.some(h(d))||l(f,d))}function c(p,d){let f=p.parent;return!!f&&(f.floatFragments.some(h(d))||c(f,d))}return o.forEach(p=>{switch(p){case"block-start":case"inline-start":n[p]=!l(this,p);break;case"block-end":case"inline-end":n[p]=!c(this,p);break;default:throw new Error(`Unexpected side: ${p}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,s=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);s?e.vertical?(o.right<s.right&&(s.right=o.right,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>s.left&&(s.left=o.left,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>s.top&&(s.top=o.top,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<s.bottom&&(s.bottom=o.bottom,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):s=o,n=n.parent}let r=Math.max(s.floatMinWrapBlockStart,s.floatMinWrapBlockEnd);return(e.vertical?s.right-s.left:s.bottom-s.top)<=r}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},Li=[],Si=class{static register(e){Li.push(e)}findByNodeContext(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},$p=class{appliesToNodeContext(e){return gi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let s=e.floatSide,r=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new mh(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new wh(s.floatReference,t,e,i,n)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Si.register(new $p);var Gp=wh,Qs=class bh extends mh{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof bh)}},Ko=class extends Gp{constructor(e,t,i,n){super(e,"block-end",t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Qs?!0:this.getOrder()<e.getOrder()}},Wp=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!Mt(t,this.footnote.nodePosition)}},jp=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Qs}createPageFloat(e,t,i){let n=Re.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Re.PAGE).hasSameContainerAs(s)&&(n=Re.PAGE);let r=e.toNodePosition();t.flowName;let o=new Qs(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new Ko(s.floatReference,e,i,n)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Ko);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;e.vertical=i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n),e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e)}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=new Wp(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Si.register(new jp);var Xp="data-vivliostyle-flow-root";function qp(e){return e.getAttribute(Xp)==="true"}function Zo(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function $r(e){return e===v.absolute||e===v.fixed}function er(e){return e instanceof ki&&e.name==="running"}function yh(e,t,i,n){return e===v.none||($r(t)?(i=v.none,e=Zo(e)):(i&&i!==v.none&&!J(i)||n)&&(e=Zo(e))),{display:e,position:t,float:i}}function vh(e,t,i,n){return yh(e,t,i,n).display===v.block}function Xt(e){switch(e.toString()){case"inline":case"inline-block":case"inline-list-item":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return!1}}function xh(e){switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Yp(e,t,i,n,s,r,o){return s=s||r||v.horizontal_tb,!!o||!!i&&i!==v.none&&!J(i)||$r(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!J(n)||!!r&&s!==r}function Kp(e){return e===v.relative||e===v.absolute||e===v.fixed}function ai(e,t,i,n){let s=e.viewNode;if(!s)return NaN;let r=s.nodeType===1?s:s.parentElement;if(r&&r.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=r.style;if(o&&Xt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(s===r){if(e.after||!e.inline){if(e.after&&!e.inline&&r.querySelector("ruby")){let a=r.parentNode,h=r.nextSibling;a.removeChild(r),a.insertBefore(r,h)}let o=t.getElementClientRect(r);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=s.ownerDocument.createRange(),h=s.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(s,i),a.setEnd(s,i+1);let l=t.getRangeClientRects(a);return l=l.filter(c=>c.right>c.left&&c.bottom>c.top),l.length?(n?o=Math.min.apply(null,l.map(c=>c.left)):o=Math.max.apply(null,l.map(c=>c.bottom)),o):NaN}}function tr(e,t,i){let n=t.clientLayout.getElementClientRect(e),s=t.getComputedMargin(e);return i?n.width+s.left+s.right:n.height+s.top+s.bottom}function hi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Sh(e,t){var i;if(e)for(let n=e.lastChild,s=n;n!==t;n=s)s=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}function Gr(e){return!!e.getAttribute(xi)}function Ln(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Gr(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function ui(e){let t=e?.viewNode;return t?.nodeType===1&&Gr(t)}function Zp(e){return e!=="inline"&&(Xt(e)||xh(e))}function Jo(e){for(let t=e.parent;t;t=t.parent)if(t.display!=="inline"&&Xt(t.display))return t;return null}var Wr=class{calculateOffset(e){return mi(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mi(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var wn=class extends Wr{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Gn(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=ai(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,s=n?.closest("table, [style*='display: table;']");if(s){let r=s.style.borderCollapse==="collapse",o=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===s&&!r)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===s&&!r&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===s)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===s)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!qt.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Fi=class{find(e){let t=pt("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()}`)}},ci=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 wn(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var s;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Pt.ShadowType.ROOTLESS&&ui(i))return;let r=i.viewNode;((s=r.parentElement)==null?void 0:s.localName)==="viv-ts-inner"&&(r=r.parentElement.parentElement);let o=r.parentNode;Sh(o,r),n&&o.removeChild(r)}finishBreak(e,t,i,n){let s=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,s),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},jr=class{constructor(e){this.parent=e,u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Xr=new ci,Jp=Ys.isInstanceOfBlockFormattingContext;ht("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,s,r)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&vh(i,n,s,r)?new jr(o?o.formattingContext:null):null});ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof jr?Xr:null);var qr=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=F("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(s=>{let r=n.accept(s,t);r=n.postLayout(s,this.initialPosition,t,r),r?i.finish(s):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},Qp=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){}},ir=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=F("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ue(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?r=t.afterIgnoredTextNode(i):r=t.startIgnoredTextNode(i):i.nodeContext.after?r=t.afterNonElementNode(i):r=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?r=t.afterInlineElementNode(i):r=t.startInlineElementNode(i):i.nodeContext.after?r=t.afterNonInlineElementNode(i):r=t.startNonInlineElementNode(i):i.nodeContext.after?r=t.afterNonDisplayableNode(i):r=t.startNonDisplayableNode(i);let o=(r&&r.isPending()?r:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?s.breakLoop():(i.nodeContext=a,s.continueLoop())});return}else if(i.break){s.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),s.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},ji=class extends Qp{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&Ke(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,s=!t.allowLayout(n);return s&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),s}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:N(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),N(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:N(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},nr=[];function ef(){nr=[]}function Ch(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var tf=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},nf=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Eh=class Fn{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=Fn.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Fn.fragmentIndices={}}matches(){let t=Fn.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Ch(t.fragmentIndex,this.a,this.b)}};u(Eh,"fragmentIndices",{});var ls=Eh,kn=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new ls(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new nf(e)}static buildAnyMatcher(e){return new tf(e)}},kh={"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-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-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-position":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},sf=["image-resolution","orphans","widows"];function rf(){return pt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(sf))}var of={"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},sr=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],af=["max-%","min-%","%"],lf=(()=>{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<sr.length;i++)for(let n=0;n<e.length;n++){let s=sr[i].replace("%",e[n]);t[s]=!0}return t})();function hs(e,t){let i={};for(let n of sr)for(let s in e){let r=n.replace("%",s),o=n.replace("%",e[s]);i[r]=o,i[o]=r}for(let n of af)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var Nh=hs({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Ph=hs({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),hf=hs({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),uf=hs({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),K=class rr{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new rr(i,this.priority)}increaseSpecificity(t){return t==0?this:new rr(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&Nt(i)?this.value:Kn(t,this.value,i,n,s)}isEnabled(t){return!0}},or=class ar extends K{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new K(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ar(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new ar(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){D.warn(i)}return!1}};function lr(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Tt(e,t,i,n){if(e)if(!i)delete e[t];else{let s=e[t];(!s||i.priority>=s.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Th={"region-id":!0,"fragment-selector-id":!0};function cf(e){return!!Th[e]}function hr(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function wi(e){return e.charAt(0)!=="_"&&!Th[e]}function Xi(e){return!!kh[e]||Nt(e)}function Ve(e,t){return e[t]}function Yt(e,t,i){i?e[t]=i:delete e[t]}function dt(e,t){return e[t]}function us(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Ih=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Rh(e,t){return e[t]}function Ah(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Yn(e,t,i,n,s,r,o){var a,h;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=us(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),o){let l=Ih(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!hr(l))if(cf(l)){let c=Rh(i,l),p=Ah(t,l);Array.prototype.push.apply(p,c)}else{let c=Ve(i,l);if(!c.isEnabled(e))continue;let p=c.increaseSpecificity(n);Tt(t,l,p,e);let d=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(d)for(let f of d){let g=new K(G,p.priority);Tt(t,f,g,e)}}}function df(e,t){let i={};for(let n=0;n<t.length;n++)Yn(e,i,t[n],0,null,null,null);return i}function Lh(e,t){if(e.length>0){e.sort((n,s)=>s.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var pf=class extends Ei{constructor(e,t){super(),this.props=e,this.context=t,u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Ve(this.props,"font-size");if(!e.value.isNumeric())return we.em;let t=e.value;if(!Hc(t.unit))throw new Error("Unexpected state");return t.num*we[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Fh(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="ex"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Yr(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Kn(this.context,e,this.propName).visit(this):e}};function Yr(e,t,i){let n=e.unit,s=e.num;if(n==="em"||n==="ex"){let r=we[n]/we.em;return new T(s*r*t,"px")}else return n==="rem"?new T(s*i.fontSize(),"px"):n==="rlh"?new T(s*i.rootLineHeight,"px"):e}function Fh(e,t,i){e=Yr(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new T(s/100*t,"px"):new T(s*i.queryUnitSize(n,!1),"px")}var Ii=class{apply(e){}mergeWith(e){return new ff([this,e])}clone(){return this}},Nn=class extends Ii{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},ff=class Oh extends Ii{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Oh([].concat(this.list))}},Kr=class extends Ii{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){Yn(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ge=class extends Ii{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},gf=class extends ge{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},mf=class extends ge{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},Qo=class extends ge{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},wf=class extends ge{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},bf=class extends ge{constructor(e,t){super(),this.epubTypePatt=e,this.targetLocalName=t}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let s=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");s&&s.match(this.epubTypePatt)&&this.chained.apply(e)}}}},yf=class extends ge{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function cs(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let s of e.getAttributeNames())if((s===i||s.endsWith(`:${i}`))&&n(e,s===i?"":e.lookupNamespaceURI(s.split(":")[0]),i))return!0;return!1}var ea=class extends ge{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},vf=class extends ge{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},xf=class extends ge{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>!!of[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Oi=class extends ge{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>{var s;return!!((s=t.getAttributeNS(i,n))!=null&&s.match(this.regexp))})&&this.chained.apply(e)}},Sf=class extends ge{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},ta=class extends ge{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Cf=class extends ge{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},bn=class extends ge{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Ch(e,this.a,this.b)}},Ef=class extends bn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},ur=class extends bn{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}},cr=class extends bn{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}},dr=class extends bn{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,s=i.localName,r=t[n];r||(r=t[n]={}),r[s]=(r[s]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},kf=class extends ge{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}},Nf=class extends ge{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Pf=class extends ge{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Tf=class extends ge{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ge=class extends ge{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},If=class Bh extends Ii{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Bh;return t.applied=this.applied,t}},Zr=class extends ge{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new If;for(let t of e)this.firstActions.push(Lh(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 ge?e.getPriority():0))}positive(){return!0}relational(){return!1}},Rf=class extends Zr{positive(){return!1}},Af=class extends Zr{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},ds=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Lf=class _h extends ds{constructor(t,i,n){super(t,i,n)}fresh(t){return new _h(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}},Ff=class Mh extends ds{constructor(t,i,n){super(t,i,n)}fresh(t){return new Mh(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)}},Of=class zh extends ds{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new zh(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)}},Bf=class Dh extends ds{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new Dh(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}},_f=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Mf=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},zf=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Df=class extends Ei{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ct(e):new ct("about:invalid");case"string":default:return e?new Ae(e):new Ae("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof ve){let s=e.values[0].values;s.length>=2&&(t=s[1].stringValue()),i=s[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function qi(e){if(Dt(e)){if(e instanceof Ae)return e.stringValue();if(e instanceof ve)return e.values.map(t=>qi(t)).join("")}return""}var pr=class extends Ei{constructor(e,t,i){super(),this.cascade=e,this.element=t,this.counterResolver=i}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let s=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,s}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new Ae("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Ae("")}return e}format(e,t){let i=!1,n=!1,s;(s=t.match(/^upper-(.*)/))!=null?(i=!0,t=s[1]):(s=t.match(/^lower-(.*)/))!=null&&(n=!0,t=s[1]);let r="";return ia[t]?r=Uf(ia[t],e):na[t]?r=$f(na[t],e):sa[t]!=null?r=sa[t]:t=="decimal-leading-zero"?(r=`${e}`,r.length==1&&(r=`0${r}`)):t=="cjk-ideographic"||t=="trad-chinese-informal"?r=Wf(e,Gf):r=`${e}`,i?r.toUpperCase():n?r.toLowerCase():r}visitFuncCounter(e){let t=e[0].toString(),i=e.length>1?e[1].stringValue():"decimal",n=this.cascade.counters[t];if(n&&n.length){let s=n&&n.length&&n[n.length-1]||0;return new Ae(this.format(s,i))}else{let s=new V(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new ve([s])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",s=this.cascade.counters[t],r=new kt;if(s&&s.length)for(let a=0;a<s.length;a++)a>0&&r.append(i),r.append(this.format(s[a],n));let o=new V(this.counterResolver.getPageCountersVal(t,a=>{let h=[];if(a.length)for(let c=0;c<a.length;c++)h.push(this.format(a[c],n));let l=r.toString();return l.length&&h.push(l),h.length?h.join(i):this.format(0,n)}));return new ve([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new V(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new ve([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e[2].stringValue(),r=e.length>3?e[3].stringValue():"decimal",o=new V(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,r));return h.length?h.join(s):this.format(0,r)}));return new ve([o])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,r,o;let a=e.length>0?e[0].stringValue():"text",h="";switch(a){case"text":h=this.element.textContent;break;case"before":case"after":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(i=(t=l?.[a])==null?void 0:t.content)==null?void 0:i.value;h=qi(c)}break;case"first-letter":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(qi((s=(n=l?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||qi((o=(r=l?.after)==null?void 0:r.content)==null?void 0:o.value)).match(Os);h=c?c[0]:""}break}return new Ae(h)}visitFuncLeader(e){let t="";if(e[0]instanceof ft)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Ae&&(t=e[0].stringValue());return t.length==0?new Ae(""):new V(new De(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"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}},Vf=(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(de){if(S==="rtl"){let pe="\u200F";g.textContent=(de.startsWith(pe)?"":pe)+de+(de.endsWith(pe)?"":pe)}else g.textContent=de},c=function(){let de=i.clientLayout.getElementClientRect(m);return L.left>de.left||L.right<de.right||L.top>de.top||L.bottom<de.bottom},p=function(){let de,pe;if(l(b),c())de=1,pe=b.length/y.length;else{de=b.length/y.length,pe=de;for(let x=0;x<16;x++){let P=b;for(let C=0;C<1<<x;C++)P+=y;if(l(P),c()){pe+=1<<x;break}}}for(let x=0;x<16;x++){let P="",C=Math.floor((de+pe)/2);for(let E=0;E<C;E++)P+=y;if(l(P),c())pe=C;else{if(de==C)return;de=C}}l(y)},d=function(de){let pe=0,x=m.parentElement;for(;x&&x!==f.viewNode;)pe+=i.getComputedInsets(x)[de],x=x.parentElement;return pe};var s=l,r=c,o=p,a=d;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,y=g.getAttribute("data-viv-leader-value"),b=g.textContent||y,{writingMode:w,direction:S,marginInlineEnd:I}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(y),m.style.display="inline-block",m.style.textIndent="0";let L=i.clientLayout.getElementClientRect(f.viewNode),_=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(I);w==="vertical-rl"||w==="vertical-lr"?(S==="rtl"?L.top+=U:L.bottom-=U,L.left=_.left,L.right=_.right,L.top=Math.min(_.top,L.top),L.bottom=Math.max(_.bottom,L.bottom)):(S==="rtl"?L.left+=U:L.right-=U,L.top=_.top,L.bottom=_.bottom,L.left=Math.min(_.left,L.left),L.right=Math.max(_.right,L.right)),p();let W=i.clientLayout.getElementClientRect(m);S=="rtl"?m.style.float="left":m.style.float="right";let re=i.clientLayout.getElementClientRect(m),He=0;S=="rtl"?w=="vertical-rl"||w=="vertical-lr"?He=W.top-re.top-d("top"):He=W.left-re.left-d("left"):w=="vertical-rl"||w=="vertical-lr"?He=re.bottom-W.bottom-d("bottom"):He=re.right-W.right-d("right"),He=Math.max(0,He-.1),m.style.float="",g.style.marginInlineStart=`${He}px`}};ht("POST_LAYOUT_BLOCK",Vf);var ia={roman:[4999,1e3,"M",900,"CM",500,"D",400,"CD",100,"C",90,"XC",50,"L",40,"XL",10,"X",9,"IX",5,"V",4,"IV",1,"I"],armenian:[9999,9e3,"\u0584",8e3,"\u0583",7e3,"\u0582",6e3,"\u0581",5e3,"\u0580",4e3,"\u057F",3e3,"\u057E",2e3,"\u057D",1e3,"\u057C",900,"\u057B",800,"\u057A",700,"\u0579",600,"\u0578",500,"\u0577",400,"\u0576",300,"\u0575",200,"\u0574",100,"\u0573",90,"\u0572",80,"\u0571",70,"\u0570",60,"\u056F",50,"\u056E",40,"\u056D",30,"\u056C",20,"\u056B",10,"\u056A",9,"\u0569",8,"\u0568",7,"\u0567",6,"\u0566",5,"\u0565",4,"\u0564",3,"\u0563",2,"\u0562",1,"\u0561"],georgian:[19999,1e4,"\u10F5",9e3,"\u10F0",8e3,"\u10EF",7e3,"\u10F4",6e3,"\u10EE",5e3,"\u10ED",4e3,"\u10EC",3e3,"\u10EB",2e3,"\u10EA",1e3,"\u10E9",900,"\u10E8",800,"\u10E7",700,"\u10E6",600,"\u10E5",500,"\u10E4",400,"\u10F3",300,"\u10E2",200,"\u10E1",100,"\u10E0",90,"\u10DF",80,"\u10DE",70,"\u10DD",60,"\u10F2",50,"\u10DC",40,"\u10DB",30,"\u10DA",20,"\u10D9",10,"\u10D8",9,"\u10D7",8,"\u10F1",7,"\u10D6",6,"\u10D5",5,"\u10D4",4,"\u10D3",3,"\u10D2",2,"\u10D1",1,"\u10D0"],hebrew:[999,400,"\u05EA",300,"\u05E9",200,"\u05E8",100,"\u05E7",90,"\u05E6",80,"\u05E4",70,"\u05E2",60,"\u05E1",50,"\u05E0",40,"\u05DE",30,"\u05DC",20,"\u05DB",19,"\u05D9\u05D8",18,"\u05D9\u05D7",17,"\u05D9\u05D6",16,"\u05D8\u05D6",15,"\u05D8\u05D5",10,"\u05D9",9,"\u05D8",8,"\u05D7",7,"\u05D6",6,"\u05D5",5,"\u05D4",4,"\u05D3",3,"\u05D2",2,"\u05D1",1,"\u05D0"]},na={latin:"a-z",alpha:"a-z",greek:"\u03B1-\u03C1\u03C3-\u03C9",russian:"\u0430-\u0438\u043A-\u0449\u044D-\u044F"},sa={square:"\u25A0",disc:"\u2022",circle:"\u25E6",none:""};function Uf(e,t){let i=e[0];if(t>i||t<=0||t!=Math.round(t))return"";let n="";for(let s=1;s<e.length;s+=2){let r=e[s],o=Math.floor(t/r);if(o>20)return"";for(t-=o*r;o>0;)n+=e[s+1],o--}return n}function Hf(e){let t=[],i=0;for(;i<e.length;)if(e.substr(i+1,1)=="-"){let n=e.charCodeAt(i),s=e.charCodeAt(i+2);i+=3;for(let r=n;r<=s;r++)t.push(String.fromCharCode(r))}else t.push(e.substr(i++,1));return t}function $f(e,t){if(t<=0||t!=Math.round(t))return"";let i=Hf(e),n="";do{t--;let s=t%i.length;n=i[s]+n,t=(t-s)/i.length}while(t>0);return n}var Gf={formal:!1,digits:"\u96F6\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D",markers:"\u5341\u767E\u5343",negative:"\u8CA0"};function Wf(e,t){if(e>9999||e<-9999)return`${e}`;if(e==0)return t.digits.charAt(0);let i=new kt;if(e<0&&(i.append(t.negative),e=-e),e<10)i.append(t.digits.charAt(e));else if(!t.formal&&e<=19)i.append(t.markers.charAt(0)),e!=0&&i.append(t.digits.charAt(e-10));else{let n=Math.floor(e/1e3);n&&(i.append(t.digits.charAt(n)),i.append(t.markers.charAt(2)));let s=Math.floor(e/100)%10;s&&(i.append(t.digits.charAt(s)),i.append(t.markers.charAt(1)));let r=Math.floor(e/10)%10;r&&(i.append(t.digits.charAt(r)),i.append(t.markers.charAt(0)));let o=e%10;o&&i.append(t.digits.charAt(o))}return i.toString()}var Jr=1/1048576;function ii(e,t){for(let i in e)t[i]=e[i].clone()}var jf=class Vh{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 Vh;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return ii(this.tags,t.tags),ii(this.nstags,t.nstags),ii(this.epubtypes,t.epubtypes),ii(this.classes,t.classes),ii(this.ids,t.ids),ii(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let s=t[i];s&&(n=s.mergeWith(n)),t[i]=n}createInstance(t,i,n,s){return new Xf(this,t,i,n,s)}nextOrder(){return this.order+=Jr}},Xf=class{constructor(e,t,i,n,s){this.context=t,this.counterListener=i,this.counterResolver=n,u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",{}),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",{}),u(this,"counterScoping",[{}]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",{}),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=e,this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(e){this.stack[this.stack.length-1].push(e)}increment(e,t){this.conditions[e]=(this.conditions[e]||0)+1,t&&(this.viewConditions[e]?this.viewConditions[e].push(t):this.viewConditions[e]=[t])}decrement(e,t){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(i=>i!==t),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let t=null;e&&(this.currentElementOffset,t=kn.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let s=this.viewConditions[n];return s&&s.length>0?s.length===1?s[0]:kn.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:kn.buildAllMatcher(i):kn.buildAllMatcher([t].concat(i))}applyAction(e,t){let i=e[t];i&&i.apply(this)}pushRule(e,t,i){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=i,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=e,this.currentNSTag="",this.currentEpubTypes=Rs,this.currentPageType=t,this.applyActions()}defineCounter(e,t){let i=this.counterScoping[this.counterScoping.length-1];i||(i={},this.counterScoping[this.counterScoping.length-1]=i),this.counters[e]?(i[e]&&this.counters[e].pop(),this.counters[e].push(t)):this.counters[e]=[t],i[e]=!0}pushCounters(e){var t,i,n,s,r,o,a;let h=v.inline,l=e.display;if(l&&(h=l.evaluate(this.context)),h===v.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.counterScoping.push(null);return}let c=v.inline,p=e.float;p&&(c=p.evaluate(this.context));let d=null,f=null,g=null,m=e["counter-reset"];if(m){let w=m.evaluate(this.context);w&&(d=Gi(w,!0))}let y=e["counter-set"];if(y){let w=y.evaluate(this.context);w&&(g=Gi(w,!1))}let b=e["counter-increment"];if(b){let w=b.evaluate(this.context);w&&(f=Gi(w,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(d||(d={}),d["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),h===v.list_item&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((r=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?r:"")&&(g||(g={}),g["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(d||(d={}),d.footnote===void 0&&(d.footnote=0)),c===v.footnote&&(f||(f={}),f.footnote===void 0)){let w=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!w||!(w===v.footnote||w instanceof ve&&w.values.includes(v.footnote)))&&(f.footnote=1)}if(d)for(let w in d)this.defineCounter(w,d[w]);if(f)for(let w in f){this.counters[w]||this.defineCounter(w,0);let S=this.counters[w];S[S.length-1]+=f[w]}if(g)for(let w in g)if(!this.counters[w])this.defineCounter(w,g[w]);else{let S=this.counters[w];S[S.length-1]=g[w]}if(h===v.list_item){let w=this.counters["list-item"],S=w[w.length-1];e["ua-list-item-count"]=new K(new Vt(S),0)}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let t in e){let i=this.counters[t];i&&(i.length==1?delete this.counters[t]:i.pop())}}setNamedStrings(e){let t=e["string-set"];if(!t)return;t=t.filterValue(new pr(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof ve){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>qi(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof ki&&t.value.name==="running"){let i=t.value.values[0].stringValue();this.counterResolver.setRunningElement(i,this.currentElementOffset)}}processPseudoelementProps(e,t){this.pushCounters(e);let i=e.content;i&&(e.content=i.filterValue(new pr(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let a=t.getAttribute("class");a?this.currentClassNames=a.split(/\s+/):this.currentClassNames=Rs;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Rs;let l=Bs(t);l&&(this.stack[this.stack.length-1].push(new Mf(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let d=this.siblingTypeCountsStack,f=this.currentSiblingTypeCounts=d[d.length-1],g=f[this.currentNamespace];g||(g=f[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,d.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let y=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=y[y.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,y.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let w=i.quotes,S=null;if(w){let _=w.evaluate(this.context);_&&(S=new zf(this.quotes),_===v.none?this.quotes=[new Ae(""),new Ae("")]:_===v.auto||_===v.initial?this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\u2019")]:_ instanceof ve&&(this.quotes=_.values))}this.pushCounters(this.currentStyle);let I=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(c||I){let _={};Object.keys(this.counters).forEach(U=>{_[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(I,_)}let L=dt(this.currentStyle,"_pseudos");if(L){let _=!0;for(let U of qf){U||(_=!1);let W=L[U];W&&((U==="before"||U==="after")&&!Dt((s=W.content)==null?void 0:s.value)||(U==="footnote-call"||U==="footnote-marker")&&((r=Ve(this.currentStyle,"float"))==null?void 0:r.value)!==v.footnote?delete L[U]:_?this.processPseudoelementProps(W,t):this.stack[this.stack.length-2].push(new _f(W,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}applyAttrFilterInner(e,t){for(let i in t)wi(i)&&!Nt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Df(e),i=this.currentStyle,n=dt(i,"_pseudos");for(let s in n)this.applyAttrFilterInner(t,n[s]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,s,r;let o=e[0],a=new ng(e,t,i),h=32,l={};for(let c in o)if(hr(c)){let p=dt(o,c);for(let d in p)this.applyVarFilter([p[d],...e],t,i)}else if(wi(c)){let p=Ve(o,c),d=p.value;for(let f=0;;f++){if(f>=h){d=G;break}let g=d.visit(a);if(a.error){d=G,a.error=!1;break}if(g===d)break;d=g}if(d!==p.value){let f=t.validatorSet,g=(n=f?.shorthands[c])==null?void 0:n.clone();if(g)if(J(d)){for(let m of g.propList){let y=new K(d,p.priority),b=Ve(o,m);Yt(l,m,lr(this.context,b,y))}delete o[c]}else{let m=Ti(t.scope,new gt(d.toString(),null),"");if(m&&(m.visit(g),!g.error)){for(let y of g.propList){let b=new K((r=(s=g.values[y])!=null?s:f.defaultValues[y])!=null?r:v.initial,p.priority),w=Ve(o,y);Yt(l,y,lr(this.context,w,b))}delete o[c]}}else o[c]=new K(d,p.priority)}if(l[c]){let f=Ve(o,c);f&&f.value!==G&&Tt(l,c,f,this.context)}}for(let c in l)o[c]=l[c]}applyCalcFilter(e,t){let i=new qh(t);for(let n in e)if(hr(n)){let s=dt(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(wi(n)&&!Nt(n)){let s=Ve(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new K(r,s.priority))}}applyActions(){let e;for(e=0;e<this.currentClassNames.length;e++)this.applyAction(this.code.classes,this.currentClassNames[e]);for(e=0;e<this.currentEpubTypes.length;e++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[e]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2];for(e=0;e<i.length;)i[e].push(this,t)?i.splice(e,1):e++}this.isFirst=!0,this.isRoot=!1}pop(){for(let e=1;e>=-1;--e){let t=this.stack[this.stack.length-e-2],i=0;for(;i<t.length;)t[i].pop(this,e)?t.splice(i,1):i++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},Rs=[],qf=["before","transclusion-before","footnote-call","footnote-marker","inner","first-letter","first-line","","transclusion-after","after"],fr=null;function Yf(e){fr=e}var nn=class extends gn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:fr?fr.clone():new jf,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Lh(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||(t&&(this.specificity+=1),t&&e?this.chain.push(new wf(e,t.toLowerCase())):t?this.chain.push(new Qo(t.toLowerCase())):this.chain.push(new yf(e)))}invalidSelector(e){D.warn(e),this.chain.push(new Ge("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof sn;e=e.parent)e.parent.invalid=!0}classSelector(e){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by .${e}`);return}this.specificity+=256,this.chain.push(new gf(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Nf);break;case"disabled":this.chain.push(new Pf);break;case"checked":this.chain.push(new Tf);break;case"root":case"scope":this.chain.push(new Cf);break;case"link":this.chain.push(new Qo("a")),this.chain.push(new ea("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${Rt(i)}($|\\s)`),s=t[1];this.chain.push(new bf(n,s))}else this.chain.push(new Ge(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ge(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Sf(new RegExp(`^${Rt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ge(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Kf[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ge(""));break}case"first-child":this.chain.push(new ta);break;case"last-child":this.chain.push(new cr(0,1));break;case"first-of-type":this.chain.push(new ur(0,1));break;case"last-of-type":this.chain.push(new dr(0,1));break;case"only-child":this.chain.push(new ta),this.chain.push(new cr(0,1));break;case"only-of-type":this.chain.push(new ur(0,1)),this.chain.push(new dr(0,1));break;case"empty":this.chain.push(new kf);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,t){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ge(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ge(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new mf(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new ea(e,t);break;case 39:s=new vf(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ge(""):s=new Oi(e,t,new RegExp(`(^|\\s)${Rt(n)}($|\\s)`));break;case 44:s=new Oi(e,t,new RegExp(`^${Rt(n)}($|-)`));break;case 43:n?s=new Oi(e,t,new RegExp(`^${Rt(n)}`)):s=new Ge("");break;case 42:n?s=new Oi(e,t,new RegExp(`${Rt(n)}$`)):s=new Ge("");break;case 46:n?s=new Oi(e,t,new RegExp(Rt(n))):s=new Ge("");break;case 50:if(n=="supported")s=new xf(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){let e=`d${Pn++}`;this.processChain(new Nn(new Lf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}childSelector(){let e=`c${Pn++}`;this.processChain(new Nn(new Ff(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Pn++}`;this.processChain(new Nn(new Of(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Pn++}`;this.processChain(new Nn(new Bf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new Kr(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new or(t,0,this.condition):i=new K(t,0),Ah(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new ve([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),pt("SIMPLE_PROPERTY").forEach(r=>{let o=r({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),s=this.condition?new or(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new sn(this);break;case"not":t=new Zf(this);break;case"where":t=new Jf(this);break;case"has":t=new Qf(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},Kf={"nth-child":Ef,"nth-of-type":ur,"nth-last-child":cr,"nth-last-of-type":dr},Pn=0,sn=class Uh extends nn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(this,"selectorTexts",[]),this.parentChain=t.chain}nextSelector(){this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Af(this.selectorTexts):this.positive()?new Zr(this.chains):new Rf(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ge("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let s=this;s instanceof Uh;s=s.parent)if(s.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Zf=class extends sn{positive(){return!1}forgiving(){return!1}},Jf=class extends sn{increasingSpecificity(){return!1}},Qf=class extends sn{relational(){return!0}},eg=class extends gn{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",s=new Jt(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},Tn=class extends gn{constructor(e,t,i,n,s,r){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=s,this.ruleType=r,u(this,"order"),this.order=0}property(e,t,i){i?D.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Jr;let s=this.condition?new or(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}},tg=class extends Zl{constructor(e,t){super(e),this.validatorSet=t,u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Kl:Yl;n+=this.order,this.order+=Jr;let s=new K(t,n);Tt(this.elementStyle,e,s)}};function Hh(e,t){let i=Ih(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function gr(e,t,i){Hh(i,n=>{Yi(e,n,t)})}function ig(e,t,i,n){let s=new tg(e,t),r=new gt(n,s);try{cp(r,s,i)}catch(o){D.warn(o,"Style attribute parse error:")}return s.elementStyle}function $h(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.vertical_rl}return i}function Gh(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.rtl}return i}function Wh(e,t,i,n,s){let r={};for(let o in e)wi(o)&&(r[o]=Ve(e,o));return gr(r,t,e),jh(e,i,n,(o,a)=>{Yi(r,a,t),gr(r,t,a)}),r}function jh(e,t,i,n){let s=dt(e,"_regions");if((t||i)&&s){if(i){let r=["footnote"];t?t=t.concat(r):t=r}for(let r of t){let o=s[r];o&&n(r,o)}}}function Yi(e,t,i){for(let n in t)if(wi(n)){let s=Ve(t,n),r=e[n];e[n]=lr(i,r,s)}}var Xh=(e,t,i,n,s)=>{let r=i?n?hf:Nh:n?uf:Ph;for(let o in e)if(e.hasOwnProperty(o)){let a=e[o];if(!a)continue;let h=r[o],l;if(h){let c=e[h];if(c&&c.priority>a.priority)continue;l=lf[h]?h:o}else l=o;t[l]=s(o,a)}},ng=class extends Ei{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,s,r;let o=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(r=(s=this.styler.getStyle(o,!1))==null?void 0:s[e])==null?void 0:r.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof ft&&e.values[0].name;return!t||!Nt(t)?(this.error=!0,G):this.getVarValue(t)||(e.values.length<2?(this.error=!0,G):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},qh=class extends Ei{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=Ti(this.context.rootScope,new gt(i,null),"");if(n instanceof V)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&!isNaN(s)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new T(s,"px"):/\d[a-z]/i.test(i)||(t=new Vt(s)))}catch(s){D.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(hl(e.unit)||Gc(e.unit))?new T(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new T(e.num*this.percentRef/100,"px"):e}};function Kn(e,t,i,n,s){try{if(t instanceof V)return t.expr instanceof De&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:gp(e,t.expr,i);if(t instanceof T||t instanceof ki||t instanceof ve||t instanceof qe)return t.visit(new qh(e,!0,n,s))}catch(r){return D.warn(r),G}return t}var ra={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function oa(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.none;if(t===v.none)return ra;let i=t instanceof ve?t.values:[t],n=Object.create(ra);for(let s of i)if(s instanceof ft)switch(s.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function aa(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var sg={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},la={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},ha={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function ua(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return la;if(t===v.auto)return ha;let i=t instanceof ve?t.values:[t],n=Object.create(la);for(let s of i)if(s instanceof ft)switch(s.name){case"trim-both":case"trim-auto":return ha;case"space-all":return sg;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 As={ideographAlpha:!1,ideographNumeric:!1},rg={ideographAlpha:!0,ideographNumeric:!0};function ca(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return rg;if(t===v.none)return As;let i=t instanceof ve?t.values:[t],n=Object.create(As);for(let s of i)if(s instanceof ft)switch(s.name){case"no-autospace":return As;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function da(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function pa(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 og=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let s=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(s.length>1){let r=s.length-1;for(let o=0;o<r;o++)n.parentNode.insertBefore(document.createTextNode(s[o]),n);n.textContent=s[r]}}}processGeneratedContent(e,t,i,n,s,r){s=pa(s);let o=ca(t),a=ua(i),h=oa(n);if(aa(h)&&da(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(r?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),p=null,d=null;for(let f=c.nextNode();f;f=d){d=c.nextNode();let g=!p,m=!p||/\n$/.test(p.textContent),y=!d||/^\n/.test(d.textContent),b=!d;this.processTextSpacing(f,g||m,g,m,y,b,p,d,o,a,h,s,r),p=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,s,r,o,a,h;let l=!e||e.fragmentIndex===1&&d(),c=l||f();function p(b){var w;if(b?.nodeType!==1)return!1;let S=b;if(S.hasAttribute(xi))return!0;let{position:I,float:L}=(w=S.style)!=null?w:{};return I==="absolute"||I==="fixed"||L&&L!=="none"}function d(){let b=t[0];for(let w=b;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let w=b.viewNode.previousSibling;w;w=w.previousSibling)if(!Ue(w,b.whitespace)&&!p(w))return!1;return!0}function f(){var b,w;let S=t[0],I;for(;S&&S.inline&&(I=(b=S.viewNode)==null?void 0:b.previousSibling,!(I&&(I.nodeType===3&&/^[ \t\r\n\f]*$/.test(I.textContent)&&S.whitespace!==Ze.PRESERVE&&(I=I.previousSibling),I)));)S=S.parent;for(;I;){if(I.nodeType===1){if(I.localName==="br")return!0;let L=(w=I.style)==null?void 0:w.display;if(L&&L!=="inline")return!/^(inline|ruby)\b/.test(L)}else if(I.nodeType===3){if(S.whitespace===Ze.PRESERVE){if(/\n$/.test(I.textContent))return!0}else if(S.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(I.textContent))return!0}I=I.lastChild}return!1}let g=-1;for(let b=0;b<t.length;b++){let w=t[b];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ue(w.viewNode,w.whitespace)){let S=function(E){var A,R,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((R=E.viewNode)==null?void 0:R.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/\n$/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.previousElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1},I=function(E){var A,R,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((R=E.viewNode)==null?void 0:R.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/^\n/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/^[ \t\r\n\f]*\n/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.nextElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1};var m=S,y=I;let L=pa((r=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),_=ca(w.inheritedProps["text-autospace"]),U=ua(w.inheritedProps["text-spacing-trim"]),W=oa(w.inheritedProps["hanging-punctuation"]);if(aa(W)&&da(_,U)||/\b(flex|grid)\b/.test(w.parent.display))continue;g<0&&(g=b);let re=null,He=null,de=b===g,pe=b===g&&l,x=b===g&&c,P=!1,C=!1;for(let E=b-1;E>=0;E--){let A=t[E];if(S(A)){x=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){re=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((o=A.viewNode)==null?void 0:o.nodeType)===1&&(A.viewNode.localName==="br"||jt[A.viewNode.localName]))break;E===0&&(de=!0,l&&(pe=!0,x=!0))}for(let E=b+1;E<t.length;E++){let A=t[E];if(I(A)){P=!0;break}if(A.viewNode!==w.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){He=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===1&&(A.viewNode.localName==="br"||jt[A.viewNode.localName])){E===t.length-1&&p(A.viewNode)&&(C=!0);break}if(E===t.length-1){P=!0,C=!0;for(let R=A.viewNode.nextSibling;R;R=R.nextSibling)if(!p(R)){C=!1;break}}}if(((h=w.parent)==null?void 0:h.display)==="inline-block"){if(!pe){let E=w.parent.viewNode.firstChild;for(;Ue(E,w.whitespace);)E=E.nextSibling;w.viewNode===E&&(pe=!0)}if(!C){let E=w.parent.viewNode.lastChild;for(;Ue(E,w.whitespace);)E=E.previousSibling;w.viewNode===E&&(C=!0)}}this.processTextSpacing(w.viewNode,de,pe,x,P,C,re,He,_,U,W,L,w.vertical)}}}processTextSpacing(e,t,i,n,s,r,o,a,h,l,c,p,d){let f=e.textContent,g=e.ownerDocument,m,y,b;function w(){if(t)return!0;if(!o)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];y||(y=g.createRange(),y.selectNode(o));let C=y.getClientRects(),E=C[C.length-1];return!P||!E?!1:d?P.top<E.top+E.height-P.width||P.left+P.width<E.left+P.width/10||P.left>E.left+E.width-P.width/10:P.left<E.left+E.width-P.height||P.top>E.top+E.height-P.height/10||P.top+P.height<E.top+P.height/10}function S(){if(!a)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];b||(b=g.createRange(),b.selectNode(a));let C=b.getClientRects()[0];return!P||!C?!1:d?P.top+P.height>C.top+P.width||P.left>C.left+C.width-P.width/10||P.left+P.width<C.left+P.width/10:P.left+P.width>C.left+P.height||P.top+P.height<C.top+P.height/10||P.top>C.top+C.height-P.height/10}let I=!1,L=!1,_=!1,U=!1,W;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(W="viv-ts-open",I=!0,L=!0):r&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(W="viv-ts-close",I=!0,_=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(W="viv-ts-close",I=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(W="viv-ts-open",I=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||p==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||p!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(W="viv-ts-close",I=!0),I){let P=function(O){let z=parseFloat(g.defaultView.getComputedStyle(O).fontSize)*.7;return(d?O.offsetHeight:O.offsetWidth)>z},C=function(){return d?E.offsetLeft:E.offsetTop};var re=P,He=C;if(e.parentElement.localName==="viv-ts-inner")return;let E=g.createElement(W),A=g.createElement("viv-ts-inner");E.appendChild(A),e.parentNode.insertBefore(E,e),A.appendChild(e);let R=P(A);if(R||L||_||U){if(W==="viv-ts-open"){if(L)E.className="viv-hang-first";else if(i||n)l.trimStart?E.className="viv-ts-trim":E.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&w())E.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&P(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let O=C();E.className="viv-ts-auto",O===C()&&!w()&&(E.className="viv-ts-trim")}}else if(W==="viv-ts-close"){if(_)E.className=R?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let O=C();U?(E.className=R?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&O===C()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",O===C()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",O===C()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))R&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let O=S(),z=O&&c.allowEnd;z||(E.className=R?"viv-hang-end":"viv-hang-end viv-hang-hw"),R?z&&l.trimEnd?E.className="viv-ts-auto":!z&&!S()?E.className="":!O&&c.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):(E.className="viv-ts-space",S()||(l.allowEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!O&&!S()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let O=C();E.className="viv-ts-auto",O===C()&&(E.className="")}}}}let de=!1;function pe(P){var C;let E=(C=P?.ownerDocument.defaultView)==null?void 0:C.getComputedStyle(P);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function x(P,C){if(P.nodeType===1){let R=g.defaultView.getComputedStyle(P);if(parseFloat(R.marginInlineEnd)||parseFloat(R.borderInlineEndWidth)||parseFloat(R.paddingInlineEnd))return!0}let E=P.parentElement;if(E&&!E.contains(C))return x(E,C);if(C.nodeType===1){let R=g.defaultView.getComputedStyle(C);if(parseFloat(R.marginInlineStart)||parseFloat(R.borderInlineStartWidth)||parseFloat(R.paddingInlineStart))return!0}let A=C.parentElement;return A&&!A.contains(P)?x(P,A):!1}(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(d&&pe(o.parentElement))&&!x(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),de=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(d&&pe(a.parentElement))&&!x(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),de=!0))}registerHooks(){ht("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),ht("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),ht("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Qr=new og;Qr.registerHooks();function ag(e){Qr.preprocessForTextSpacing(e)}function lg(e,t,i,n,s,r){Qr.processGeneratedContent(e,t,i,n,s,r)}var On=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),hg=["footnote-marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],eo="data-adapt-pseudo";function di(e){return e.getAttribute(eo)||""}function mr(e,t){e.setAttribute(eo,t)}var fa=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,u(this,"contentProcessed",{})}getStyle(e,t){let i=di(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=dt(this.style,"_pseudos")[i]||{};if(i.match(/^first-/)&&!n["x-first-pseudo"]){let s=1,r;i=="first-letter"?s=0:(r=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=r[1]-0),n["x-first-pseudo"]=new K(new Qt(s),0)}return n}processContent(e,t,i){let n=di(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let s=t.content;s&&Dt(s)&&(s.visit(new qn(e,this.context,s,this.exprContentListener)),ag(e))}}},Xw=Wn.isInstanceOfAfterIfContinuesLayoutConstraint,ug=ls.registerFragmentIndex,qw=ls.clearFragmentIndices,cg=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new to(e,i,t),s=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=s;let r=i.firstChild;return k(r,"display","block"),N(r)})}createNodePositionForPseudoElement(){let e=On.createElementNS("http://www.w3.org/1999/xhtml","div");mr(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 zt(i)}createShadowContext(e){return new Zs(this.sourceNode,e,null,null,null,Pt.ShadowType.ROOTED,this.styler)}},dg=class Yh{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,u(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,s){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),N(!0))):N(!0)}getRepetitiveElements(){return new pg(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Yh?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},pg=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function Kh(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return N(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=gg(e,t,n);return t.fragmentLayoutConstraints.push(new dg(e,i,s)),N(e)})}function Zh(e,t){return e.thenAsync(i=>Kh(i,t))}function fg(e,t){let i=F("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=Kh(n,t);return n=n.parent,s.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function gg(e,t,i){let n=e.viewNode;n.appendChild(i);let s=tr(i,t,e.vertical);return n.removeChild(i),s}var mg=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Bn=class extends Wr{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,u(this,"alreadyEvaluated",!1),u(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Zn=class extends gh{constructor(e,t,i,n,s){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=s,u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"breakAtTheEdgeBeforeFloat",null),this.last=e.lastChild,this.viewDocument=e.ownerDocument,s.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}isOverflown(e){return this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=F("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,s=null;return t.loop(()=>{for(;n>=0;){let r=s,o=i[n];if(s=Xn(o,r),n===i.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),n==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),s.after=e.after,s.preprocessedTextContent=e.preprocessedTextContent,s.after))break;let a=this.layoutContext.setCurrent(s,n==0&&s.offsetInNode==0);if(n--,a.isPending())return a}return N(!1)}).then(()=>{t.finish(s)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Np(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 s=e.viewNode.textContent,r=s.match(Os),o=r?r[0].length:0;if(!r&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&s===e.sourceNode.textContent){let a=s+e.sourceNode.nextSibling.textContent,h=a.match(Os);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return N(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=F("buildViewToNextBlockEdge");return n.loopWithFrame(s=>{var r;e.viewNode&&!ui(e)&&((r=e.viewNode.parentElement)==null?void 0:r.namespaceURI)==="http://www.w3.org/1999/xhtml"&&t.push(e.copy()),this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,ui(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){s.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(gi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){s.breakLoop();return}s.continueLoop()}):e.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return Zh(i,this)}buildDeepElementView(e){if(!e.viewNode)return N(e);let t=[],i=e.sourceNode,n=F("buildDeepElementView");return n.loopWithFrame(s=>{e.viewNode&&e.inline&&!ui(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(r=>{let o=r;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,s.breakLoop();return}ui(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{e=a,!e||e.sourceNode==i?s.breakLoop():this.layoutConstraint.allowLayout(e)?s.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let s=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),k(s,"height",`${i}px`),k(s,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),k(s,"width",`${i}px`),k(s,"height",`${n}px`)),k(s,"float",t),k(s,"clear",t),this.element.insertBefore(s,e),s}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(),s=null;for(let r of t){let o=r.y2-r.y1;r.left=this.createFloat(e,"left",r.x1-i,o),r.right=this.createFloat(e,"right",n-r.x2,o),r.x1<n&&r.x2>i?s=r:s||k(r.right,"float","none")}if(s){let r=t[t.length-1],o=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==r&&r.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(e,t,i,n){let s;if(e&&hi(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(s=ai(e,this.clientLayout,0,this.vertical),!isNaN(s)))return s;e=t[i];let r=n-e.boxOffset;for(;;){if(s=ai(e,this.clientLayout,r,this.vertical),!isNaN(s))return s;if(r>0){r--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(r=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 Cs(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 Cs(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 Cs(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=F("layoutFloat"),i=e.viewNode,n=qo(e.floatSide,e.vertical,e.direction);return k(i,"float","none"),k(i,"display","inline-block"),k(i,"vertical-align","top"),this.buildDeepElementView(e).then(s=>{let r=this.clientLayout.getElementClientRect(i),o=this.getComputedMargin(i),a=new nt(r.left-o.left,r.top-o.top,r.right+o.right,r.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let S=c.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),c.viewNode.appendChild(S);let I=this.clientLayout.getElementClientRect(S);h=Math.max(this.rtl?this.getEndEdge(I):this.getStartEdge(I),h),l=Math.min(this.rtl?this.getStartEdge(I):this.getEndEdge(I),l),c.viewNode.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!==e.parent&&!e.firstPseudo&&(c.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new nt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),d=a;this.vertical&&(d=Hn(a));let f=this.getBoxDir();if(d.y1<this.bottommostFloatTop*f){let S=d.y2-d.y1;d.y1=this.bottommostFloatTop*f,d.y2=d.y1+S}fd(p,this.bands,d,n),this.vertical&&(a=Al(d));let g=this.getComputedInsets(i);k(i,"width",`${a.x2-a.x1-g.left-g.right}px`),k(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),k(i,"position","absolute"),e.display,k(i,"display",e.display);let m,y=null;if(c&&(c.containingBlockForAbsolute?y=c:y=c.getContainingBlockForAbsolute()),y){let S=y.viewNode.ownerDocument.createElement("div");S.style.position="absolute",y.vertical?S.style.right="0":S.style.left="0",S.style.top="0",y.viewNode.appendChild(S),m=this.clientLayout.getElementClientRect(S),y.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(y?y.vertical:this.vertical)?k(i,"right",`${m.right-a.x2}px`):k(i,"left",`${a.x1-m.left}px`),k(i,"top",`${a.y1-m.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,w=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),p=new nt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Hn(p)),gd(p,this.bands,d,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(b),t.finish(s)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,s,r){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),s.adjustPageFloatArea(e,a,this),e.init();let c=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),r);return c?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),c}createPageFloatArea(e,t,i,n,s){let r=this.element.ownerDocument.createElement("div");k(r,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new Di(null,Re.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),h=o.getContainer(),l=new yg(t,r,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,s)?l:null}layoutSinglePageFloatFragment(e,t,i,n,s,r,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c=this.createPageFloatArea(h,t,r,s,l),p={floatArea:c,pageFloatFragment:null,newPosition:null};if(!c)return N(p);let d=F("layoutSinglePageFloatFragment"),f=!1,g=0;return d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let y=e[g],b=new zt(y.nodePosition);c.layout(b,!0).then(w=>{p.newPosition=w,!w||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){let m=a.setFloatAreaDimensions(c,h.floatReference,t,r,!1,n,l);if(!m)f=!0;else{let y=s.createPageFloatFragment(e,m,c,!!p.newPosition);a.addPageFloatFragment(y,!0),p.pageFloatFragment=y}}d.finish(p)}),d.result()}layoutPageFloatInner(e,t,i,n){let s=this.pageFloatLayoutContext,r=e.float;s.stashEndFloatFragments(r);function o(h,l){l?s.removePageFloatFragment(l,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(r.floatReference),s.deferPageFloat(e)}let a=F("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],r.floatSide,r.clearSide,!s.hasFloatFragments(),t,i,n).then(h=>{let l=h.floatArea,c=h.pageFloatFragment,p=h.newPosition;c?this.layoutStashedPageFloats(r.floatReference,[n]).then(d=>{if(d){if(s.addPageFloatFragment(c),s.discardStashedFragments(r.floatReference),p){let f=new Yo(r,p.primary);s.deferPageFloat(f)}a.finish(!0)}else o(l,c),a.finish(!1)}):(o(l,c),a.finish(!1))}),a.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),s=[],r=[],o=!1,a=F("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 p=new Si().findByFloat(c.continuations[0].float);this.layoutSinglePageFloatFragment(c.continuations,c.floatSide,null,!1,p,null).then(d=>{let f=d.floatArea;f&&s.push(f);let g=d.pageFloatFragment;g?(r.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(r.forEach(l=>{i.removePageFloatFragment(l,!0)}),s.forEach(l=>{let c=l.element;c&&c.parentNode&&c.parentNode.removeChild(c)})):n.forEach(l=>{let c=l.area.element;c&&c.parentNode&&c.parentNode.removeChild(c)}),a.finish(!o)}),a.result()}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");i.setAttribute(xi,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",i),t.appendChild(i),t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=F("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,r=s.getPageFloatLayoutContext(Re.REGION);return s.getContainer().width<r.getContainer().width&&e===Re.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Ur(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(Re.REGION):n.finish(e)}):t===v.all?n.finish(Re.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Si().findByNodeContext(e),n,s=t.findPageFloatByNodePosition(e.toNodePosition());return s?n=N(s):n=i.createPageFloat(e,t,this),n.thenAsync(r=>{let o=jn(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(r,t),l=new Yo(r,o);if(h&&h.hasFloat(r))return t.registerPageFloatAnchor(r,a.viewNode),N(a);if(t.isForbidden(r)||t.hasPrecedingFloatsDeferredToNext(r))return t.deferPageFloat(l),t.registerPageFloatAnchor(r,a.viewNode),N(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let c=ai(a,this.clientLayout,0,this.vertical);return this.isOverflown(c)?N(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?N(null):(t.registerPageFloatAnchor(r,a.viewNode),N(a)))}})}processLineStyling(e,t,i){let n=F("processLineStyling"),s=i.concat([]);i.splice(0,i.length);let r=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(s),l=o.count-r;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(s,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{r+=l,this.layoutContext.peelOff(c,0).then(p=>{e=p,o=e.firstPseudo,s=[],this.buildViewToNextBlockEdge(e,s).then(d=>{t=d,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,s),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&jt[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let s=e[n];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let r=this.getComputedMargin(s.viewNode),o=this.vertical?-r.left:r.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=F("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let s=i.length-1;if(s<0){t.finish(n);return}this.postLayoutBlock(n,i);let r=this.calculateEdge(n,i,s,i[s].boxOffset),o=!1;if(!n||!hi(n.viewNode)){let h=mi(n,this.collectElementsOffset());o=this.isOverflown(r+(this.vertical?-1:1)*h.minimum),this.isOverflown(r+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(r+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(r);let a;e.firstPseudo?a=this.processLineStyling(e,n,i):a=N(n),a.then(h=>{i.length>0&&(this.saveBoxBreakPosition(i),o&&!this.isLoneImage(i)&&h&&(h=h.modify(),h.overflow=!0)),t.finish(h)})}),t.result()}postLayoutBlock(e,t){pt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,s=0,r=t[0].boxOffset,o=s,a=t.length-1,h=t[a].boxOffset,l;for(;r<h;){l=r+Math.ceil((h-r)/2),o=s;let c=a;for(;o<c;){let d=o+Math.ceil((c-o)/2);t[d].boxOffset>l?c=d-1:o=d}let p=this.calculateEdge(null,t,o,l);if(this.vertical?p<=n:p>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(p),r=l,s=o}return{nodeContext:t[o],index:r,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,s;let r=this.findEndOfLine(t,e,!0),o=r.nodeContext;if(r.checkPointIndex===0&&r.index===o.boxOffset)return null;let a=o.viewNode;if(a.nodeType!=1&&((n=a.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let h=a;o=this.resolveTextNodeBreaker(o).breakTextNode(h,o,r.index,e,r.checkPointIndex,i)}else{let h=Jo(o);if(h){if(((s=this.breakPositions)==null?void 0:s[0])instanceof Bn&&h!=null&&h.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;o=h}}return this.clearOverflownViewNodes(o,!1),o}resolveTextNodeBreaker(e){return pt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Jn.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),s=!1,r=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;r==t&&(t.nodeType===1?h=!(!t.firstChild||s):h=!1);let p=r.nodeType===1?r:null;p?s?s=!1:Gr(p)?l=!a:!p.firstChild||jt[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Zp(this.clientLayout.getElementComputedStyle(p).display)?(l=!a,l?(p.localName==="ruby"&&r.firstChild&&(r=r.firstChild),n.setStartBefore(r),a=!0,o=r):/^r(uby|tc?)$/.test(p.localName)||(o=r),r.contains(t)&&(h=!1)):c=r.firstChild:(a||(r.parentNode==null?h=!1:(n.setStartBefore(r),a=!0)),o=r),c||(c=r.nextSibling,c||(s=!0,c=r.parentNode)),r=c}while(l&&h);if(a){n.setEndAfter(o);let c=this.clientLayout.getRangeClientRects(n);for(let p=0;p<c.length;p++)i.push(c[p]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Bp:Op);let n=0,s=0,r=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(o>0){let p=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?c=h*(this.getAfterEdge(l)-n)/p:h*this.getAfterEdge(l)>h*s?c=h*(s-this.getBeforeEdge(l))/p:c=1}if(o==0||c>=.6||c>=.2&&this.getStartEdge(l)>=r-1){r=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),s=o==0?l.left:Math.min(s,l.left)):(n=o==0?l.top:Math.min(n,l.top),s=o==0?l.bottom:Math.max(s,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(s),o=0),a>=i.length)break}return t.sort(il),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&_i(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=mi(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 s=e.checkPoints,r=s[0];for(;r.parent&&r.inline;)r=r.parent;let o,a;t?(o=1,a=1):(o=Math.max((r.inheritedProps.widows||2)-0,1),a=Math.max((r.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(r),l=this.findLinePositions(s),c=this.footnoteEdge-h,p=this.getBoxDir(),d=this.getOffsetByRepetitiveElements(e);c-=p*d;let f=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(f.edge)&&(f.edge=p*(1/0));let g=Bt(l.length,w=>{let S=l[w];return this.vertical?S<c||S<=f.edge:S>c||S>=f.edge}),m=g<=0;m&&(g=Bt(l.length,w=>this.vertical?l[w]<c:l[w]>c));let y=s[s.length-1].viewNode;if(y?.parentElement.localName==="viv-ts-inner"&&(y=y.parentElement.parentElement),(g===l.length&&y.nextSibling||g>=l.length-1&&y.parentElement.querySelector(".MJXc-display"))&&(o=0),g=Math.min(l.length-o,g),g<a)return null;c=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,c,t),b){let w=this.getAfterEdgeOfBlockContainer(b);!isNaN(w)&&p*(c-w)>0&&(c=w),this.computedBlockSize=p*(c-this.beforeEdge)+d}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,ai(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 Fi().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Xr.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 s=this.breakPositions.length-1;s>=0&&!t;--s){e=this.breakPositions[s],t=e.findAcceptableBreak(this,i);let r=e.getMinBreakPenalty();r>i&&(n=Math.min(n,r))}}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 N(e);let s=F("doFinishBreak"),r=!1;if(!e){if(this.forceNonfitting)return D.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,r,!0).then(()=>{s.finish(o)})):s.finish(o)}),s.result();e=i,r=!0,this.computedBlockSize=n}return this.finishBreak(e,r,!0).then(()=>{s.finish(e)}),s.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Ln(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}zeroIndent(e){let t=e.toString();return t==""||t=="auto"||!!t.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let r=e;r;r=r.parent)if(Ln(r.viewNode))return!1;if(hi(e.viewNode))return!1;let i=ai(e,this.clientLayout,0,this.vertical),n=mi(e,this.collectElementsOffset()),s=this.isOverflown(i+(this.vertical?-1:1)*n.minimum);if(this.isOverflown(i+(this.vertical?-1:1)*n.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let r=i+this.getTrailingMarginEdgeAdjustment(t),o=this.footnoteEdge-this.getBoxDir()*n.current;i=this.vertical?Math.min(i,Math.max(r,o)):Math.max(i,Math.min(r,o))}return this.updateMaxReachedAfterEdge(i),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||hi(e.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(e,t);return(i||!s)&&this.saveEdgeBreakPosition(e,n,s),s}applyClearance(e){if(!e.viewNode.parentNode)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=this.clientLayout.getElementClientRect(i),s=this.getBeforeEdge(n),r=this.getBoxDir(),o=e.clearSide,a=-this.getBoxDir()*(1/0);switch(o==="all"&&(a=this.pageFloatLayoutContext.getPageFloatClearEdge(o,this)),/^(top|bottom|(block|inline)-(start|end))$/.test(o)?qo(o,e.vertical,e.direction):o){case"left":a=r*Math.max(a*r,this.leftFloatEdge*r);break;case"right":a=r*Math.max(a*r,this.rightFloatEdge*r);break;default:a=r*Math.max(a*r,Math.max(this.rightFloatEdge*r,this.leftFloatEdge*r))}if(s*r>=a*r)return e.viewNode.parentNode.removeChild(i),!1;{let h=Math.max(1,(a-s)*r);this.vertical?i.style.width=`${h}px`:i.style.height=`${h}px`,n=this.clientLayout.getElementClientRect(i);let l=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let c=l+t.right-a;c>0==t.right>=0&&(c+=t.right),i.style.marginLeft=`${c}px`}else{let c=a-(l+t.top);c>0==t.top>=0&&(c+=t.top),i.style.marginBottom=`${c}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Jp(e)||qt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,t,i){var n;let s=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(s&&!this.isBFC(s))return N(e);let r=F("skipEdges"),o=!i&&t&&e&&e.after,a=i,h=null,l=[],c=[],p=!1;function d(){return!!i||!t&&Ke(a)&&!f()}function f(){var m;if(!h||e.floatSide)return!1;for(let y=h;y!=null&&y.parent;y=y.parent){let b=y.after?y.viewNode:(m=y.viewNode)==null?void 0:m.previousSibling;for(;b&&(Ue(b,y.parent.whitespace)||Ln(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{e=l[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=a};return r.loopWithFrame(m=>{for(var y;e;){e.formattingContext;let b=new Fi().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)?(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=a),m.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Gn(a)?a:null),b&&b.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),a,!1),!e.inline&&!e.repeatOnBreak&&(h?Jo(h):this.breakPositions[this.breakPositions.length-1]instanceof Bn)&&this.saveEdgeBreakPosition(e.copy(),a,!1),!this.isBFC(e.formattingContext)||qt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ue(e.sourceNode.firstChild,e.whitespace)){l.push(e.copy()),a=Xe(a,e.breakBefore),d()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let S=e.viewNode.style;if(e.after){e.floatSide&&(a=a??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let I=e.sourceNode;if(I.localName==="svg"||I.localName==="math"||I.getAttribute("data-math-typeset")==="true"){p=!1,h=e.copy(),c.push(h),a=Xe(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a);break}if(e.inline||b&&b.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(d()){g(),m.breakLoop();return}l=[],t=!1,o=!1,a=null}p=!1,h=e.copy(),c.push(h),a=Xe(a,e.breakAfter),S&&!(this.zeroIndent(S.paddingBottom)&&this.zeroIndent(S.borderBottomWidth))&&(c=[h])}else{if(l.push(e.copy()),a=Xe(a,e.breakBefore),(e.pageType!=((y=e.parent)==null?void 0:y.pageType)||!Ke(a))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){m.breakLoop();return}let I=e.viewNode.localName;if(jt[I]){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}S&&!(this.zeroIndent(S.paddingTop)&&this.zeroIndent(S.borderTopWidth))&&(o=!1,c=[]),p=!0}}while(!1);let w=this.nextInTree(e,o);if(w.isPending()){w.then(S=>{e=S,m.continueLoop()});return}else e=w.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,c,!this.stopAtOverflow,a)?h&&this.stopAtOverflow&&(e=h.modify(),e.overflow=!0):Ke(a)&&(this.pageBreakType=a),m.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let t=e.copy(),i=F("skipEdges"),n=null,s=!1;return i.loopWithFrame(r=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=Xe(n,e.breakBefore),Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(s){if(Ke(n)){this.pageBreakType=n,r.breakLoop();return}n=null}s=!1,n=Xe(n,e.breakAfter)}else{n=Xe(n,e.breakBefore);let h=e.viewNode.localName;if(jt[h]){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(a&&!(this.zeroIndent(a.paddingTop)&&this.zeroIndent(a.borderTopWidth))){r.breakLoop();return}}s=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,r.continueLoop()});return}else e=o.get()}t=null,r.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){return gi(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,t,i){let n=F("layoutNext");return this.skipEdges(e,t,i||null).then(s=>{if(e=s,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let r=e.formattingContext;new Fi().find(r).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 Fi().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 nt(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=cd(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],k(this.element,"width",`${this.width}px`),k(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),s=new Fi().find(e.formattingContext),r=this.calculateClonedPaddingBorder(n),o=s.createEdgeBreakPosition(n,t,i,this.computedBlockSize+r);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new Bn(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 N(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?N(null):N(e);let n=F("layout");return this.openAllViews(e.primary).then(s=>{let r=null;if(s.viewNode)r=s.copy();else{let a=h=>{h.nodeContext.viewNode&&(r=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new wg(t,i);o.layout(s,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,r,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=N(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let c=new zt(h.toNodePosition());n.finish(c)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=F("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((s,r)=>s.getPriorityOfFinishBreak()-r.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):N(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=F("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(r=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())r.breakLoop();else if(this.pageBreakType)r.breakLoop();else if(e&&this.stopByOverflow(e)){s=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),r.breakLoop()}else o?o=!1:r.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),r.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:s})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=F("redoLayout"),n=0,s=null,r=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,r).then(h=>{r=!1,h?(s=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(s)}),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(qt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Wn.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},to=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(this,"column"),this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let s=this;this.column.openAllViews=function(r){return Zn.prototype.openAllViews.call(this,r).thenAsync(o=>(s.startNodeContexts.push(o.copy()),N(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new wn(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 Mt(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Jn=class{breakTextNode(e,t,i,n,s,r){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let s=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":s+ga(n)),s){let r=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=r.slice(0,i+1)+s+r.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let s=t.charAt(i);i++;let r=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&So(s)&&So(r)?ga(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Jn,"instance");Jn.instance=new Jn;function ga(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var wg=class extends qr{constructor(e,t){super(),this.leadingEdge=e,u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new bg(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||ef()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Sh(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown}},bg=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=F("DefaultLayoutMode.doLayout");return fg(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(s=>s.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(s=>{s.postLayout(n,e,t,i)}),n}},yg=class extends Zn{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),this.floatSide=e,this.parentContainer=o,u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),N(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function s(r,o){r.forEach(a=>{let h=li(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=o*l/100;k(e,a,`${c}px`)}})}s(["width","max-width","min-width"],i),s(["height","max-height","min-height"],n),s(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(r=>{li(e,r)==="auto"&&k(e,r,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=li(t,"height");n!==""&&n!=="auto"&&k(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=li(t,"width");n!==""&&n!=="auto"&&k(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.clientLayout.getElementClientRect(e),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},ei=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||nr.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new vg(e,this.rootSourceNode),nr.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},vg=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=jn(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=jn(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=tr(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=tr(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?N(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?N(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let s=t.viewNode.ownerDocument,r=t.viewNode,o=s.createElement("div");r.appendChild(o);let a=new to(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new zt(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),a.getColumn().pageBreakType=h,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(xi,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(s=>s.nodeContext.sourceNode===e.sourceNode&&s.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let s=i(e);return t.push({nodeContext:e,result:s}),s}}isAfterNodeContextOf(e,t,i){let n=[];for(let s=e;s;s=s.parentNode){if(t.sourceNode===s)return t.after;n.push(s)}for(let s=t.sourceNode;s;s=s.parentNode){let r=n.indexOf(s);if(r>=0)return i?r===0:!1;for(let o=s;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Jh=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let s=this.formattingContext.getRepetitiveElements();return s&&(i.clientLayout,s.doneInitialLayout||(s.updateHeight(i),s.doneInitialLayout=!0)),n}},Qh=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},xg=class extends Jh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Sg=class extends Qh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new io(e)),this.processor.doLayout(e,t)}},io=class eu{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=St(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,s){let r=this.getRepetitiveElements();r&&t&&s.stopAtOverflow&&(i==null||r.isAfterLastContent(i))&&r.preventSkippingFooter()}finishBreak(t,i){let n=St(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return N(!0);let r=this.nodeContext;return Pg(n,r,i).thenAsync(()=>Tg(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return St(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof eu?St(this.nodeContext.formattingContext)===St(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Cg=class extends qr{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new xg(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Sg(this.formattingContext,this.processor))}},Eg=class extends ji{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),N(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),N(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return ji.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?N(!0):ji.prototype.afterNonInlineElementNode.call(this,e)}},kg=class extends ci{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=St(e.formattingContext);return n.getRootViewNode(e)?(i&&tu(e.parent,t),e.belongsTo(n)?ci.prototype.layout.call(this,e,t,i):new Cg(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=Ig(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=St(e.formattingContext),n=F("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=St(e.formattingContext),n=new Eg(i,t);return new ir(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=St(e.formattingContext),n=F("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Zh(s,t).then(r=>{let o=r;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return ci.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ng(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof ei&&!i.belongsTo(n)&&t(n,i)}}function tu(e,t){e&&Ng(e.after?e.parent:e,(i,n)=>{_t.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new io(n))})}function Pg(e,t,i){let n=e.getRepetitiveElements();if(n){let s=e.getRootNodeContext(t);if(s.viewNode){let r=s.viewNode.firstChild;return n.appendHeaderToFragment(s,r,i)}}return N(!0)}function Tg(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=e.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,i)}return N(!0)}function Ig(e){let t=e.formattingContext;return!t||!(t instanceof ei)?null:t}function St(e){return e instanceof ei,e}var Rg=new kg;ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof ei&&!_t.isInstanceOfTableFormattingContext(e)?Rg:null);var iu=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,u(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Ag=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},Lg=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Fg=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new to(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&k(e,"vertical-align","top"),i&&i!=="normal"&&k(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return k(e,"vertical-align",t),i&&i!=="normal"&&k(e,"align-content",i),n}},Og=class{constructor(e,t){this.viewNode=e,this.side=t}},Bg=class extends wn{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?i:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},_g=class extends Wr{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),s=n.every(r=>!!r.nodeContext)&&n.some((r,o)=>{let a=i[o].pseudoColumn,h=r.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext,t=e.getRowByIndex(this.rowIndex),i=this.beforeNodeContext.breakPenalty,n=this.getAcceptableCellBreakPositions(),s=this.getCellFragments();i+=Math.max(0,...s.map(o=>o.cellNodeContext.breakPenalty));let r=n.some((o,a)=>o.breakPosition instanceof Bn&&s[a].cellNodeContext.sourceNode.rowSpan>1);return!r&&!e.isFreelyFragmentableRow(t)&&(i+=10),n.forEach((o,a)=>{let h=o.breakPosition.getMinBreakPenalty();r&&o.breakPosition instanceof wn&&o.breakPosition.overflows&&h>=3&&(s[a].column.checkOverflowAndSaveEdge(o.nodeContext,null)||(h-=3)),i+=h}),i}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)}},bi=class extends ei{constructor(e,t){super(e,t),this.tableSourceNode=t,u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(i=>i.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new iu(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,s=this.getRowSlots(e),r=0;for(;s[r];)r++;for(;e<n;e++){s=this.getRowSlots(e);for(let o=r;o<r+t.colSpan;o++){let a=s[o]=new Lg(e,o,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}isFreelyFragmentableRow(e){return e.getMinimumHeight()>this.tableWidth/2}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=e.getElementClientRect(i.viewElement);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let s=this.slots[i][n];if(s.cell===t)return{rowIndex:s.rowIndex,columnIndex:s.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,s)=>{if(s>=e.rowIndex)return i;let r=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!r||t.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),i),t.push(r)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let s=e[n],r=this.getCellFragmentOfCell(i);!r||s.collected.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),s.elements),s.collected.push(r))})}),[new Mg(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(qt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Mg=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let s=mi(e,n);i=Math.max(i,t(s))}),i}};function at(e){return e instanceof bi,e}function zg(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Dg(e){return e==="table"||e==="inline-table"}function ma(e){return zg(e)||Dg(e)}function nu(e,t,i){let n=e.nodeContext,s=n.display,r=n.parent?n.parent.display:null,o=!1;if(r==="inline-table"&&!(n.formattingContext instanceof bi)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bi){o=a.formattingContext===t;break}}return o||s==="table-row"&&!ma(r)||s==="table-cell"&&r!=="table-row"&&!ma(r)||n.formattingContext instanceof bi&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var Vg=class extends ji{constructor(e,t){super(),this.formattingContext=e,this.column=t,u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=nu(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,s=n.display,r=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new Og(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new iu(this.rowIndex,n.sourceNode)),r.firstContentSourceNode||(r.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,s=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let r=s.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(r[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,N(!0);break;case"table-row":this.inHeaderOrFooter||(t.lastRowViewNode=i.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let r=i.viewNode;t.addCell(this.rowIndex,new Ag(this.rowIndex,this.columnIndex,r)),this.columnIndex++}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!ui(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},su=class ru extends ji{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let s=0;s<t.colSpan;s++)n+=i[t.anchorSlot.columnIndex+s];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let s=t.rowIndex,r=t.columnIndex,o=t.colSpan,a=i.viewNode,h=i.verticalAlign;o>1&&(k(a,"box-sizing","border-box"),k(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let l=a.ownerDocument.createElement("div");a.appendChild(l);let c=new Fg(this.column,l,i);return this.formattingContext.addCellFragment(s,r,c),n.primary.steps.length===1&&n.primary.after&&(c.empty=!0),c.pseudoColumn.layout(n,!0).thenReturn(!0)}hasBrokenCellAtSlot(t){let i=this.formattingContext.cellBreakPositions[0];return i?i.cell.anchorSlot.columnIndex===t:!1}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let s=t[n],r=s.cell.rowIndex;if(r<this.currentRowIndex){let o=i[r];o||(o=i[r]=[]),o.push(s),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),s=n.reduce(p=>p+1,0);if(s===0)return N(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=F("layoutRowSpanningCellsFromPreviousFragment"),h=N(!0),l=0,c=[];return n.forEach(p=>{h=h.thenAsync(()=>{let d=Xn(p[0].cellNodePosition.steps[1],o.parent);return r.setCurrent(d,!1).thenAsync(()=>{let f=N(!0),g=0;function m(y){for(;g<y;){if(!c.includes(g)){let b=d.viewNode.ownerDocument.createElement("td");k(b,"padding","0"),d.viewNode.appendChild(b)}g++}}return p.forEach(y=>{f=f.thenAsync(()=>{let b=y.cell;m(b.anchorSlot.columnIndex);let w=y.cellNodePosition,S=Xn(w.steps[0],d);return S.offsetInNode=w.offsetInNode,S.after=w.after,S.fragmentIndex=w.steps[0].fragmentIndex+1,r.setCurrent(S,!1).thenAsync(()=>{let I=y.breakChunkPosition;for(let L=0;L<b.colSpan;L++)c.push(g+L);return g+=b.colSpan,this.layoutCell(b,S,I).thenAsync(()=>(S.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+s-l,N(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,N(!0)))})})}),h.then(()=>{r.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),N(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions[t.columnIndex];if(i&&i.cell.anchorSlot.columnIndex==t.anchorSlot.columnIndex){let n=i.cellNodePosition.steps[0],s=this.column.layoutContext.xmldoc.getElementOffset(n.node);ug(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,N(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=F("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=N(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let h=jn(a,0);return N(new zt(h))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=nu(t,at(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,s=this.formattingContext.getRepetitiveElements(),r=n.display;return r==="table-header-group"&&s&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):r==="table-row"?this.startTableRow(t):r==="table-cell"?this.startTableCell(t):N(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let s=new _g(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),s=i.display;if(s==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):k(i.viewNode,"display","table-row-group"):s==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):k(i.viewNode,"display","table-row-group")),s&&ru.ignoreList[s])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return N(!0)}};u(su,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ug=su,rn=[];function Hg(e){let t=rn.findIndex(n=>n.root===e),i=rn[t];return i?i.tableLayoutOption:null}function $g(e){let t=rn.findIndex(i=>i.root===e);t>=0&&rn.splice(t,1)}var ou=class{layoutEntireTable(e,t){let i=at(e.formattingContext),n=new Vg(i,t);return new ir(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=s.createElement("td");r.appendChild(l),o.push(l)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(h=>{let l=n.getElementClientRect(h),c=i?l.height:l.width;return Math.ceil(c)});return e.parentNode.removeChild(r),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let s=i.firstElementChild;for(;s;){if(s.localName==="col"){let r=s.span;for(s.removeAttribute("span"),n-=r;r-- >1;){let o=s.cloneNode(!0);i.insertBefore(o,s),t.push(o)}t.push(s)}s=s.nextElementSibling}for(;n-- >0;)s=i.ownerDocument.createElement("col"),i.appendChild(s),t.push(s)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let s=n.ownerDocument.createElement("colgroup");t.push(s);for(let r=e.length;r<i;r++){let o=n.ownerDocument.createElement("col");s.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,s=e.lastRowViewNode;if(!s)return;e.lastRowViewNode=null;let r=s.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=r;return}let a=e.colWidths=this.getColumnWidths(s,o,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((c,p)=>{k(c,n?"height":"width",`${a[p]}px`)}),h.forEach(c=>{r.appendChild(c.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=at(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Hg(e.sourceNode);$g(e.sourceNode);let s=F("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=t.clientLayout.getElementClientRect(a),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mi(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Xg(r)),s.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),s.finish(null)}),s.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((s,r)=>{s&&(t.insertBefore(s.viewNode,i),s.side==="top"&&(n[r]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&t.insertBefore(e.colGroups.cloneNode(!0),i)}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=at(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Ug(i,t),o=new ir(r,t.layoutContext),a=F("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=at(e.formattingContext);return n.getRootViewNode(e)?(i&&tu(e.parent,t),new Wg(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Bg(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}finishBreak(e,t,i,n){let s=at(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let r=s.findRowIndexBySourceNode(t.sourceNode);s.cellBreakPositions=[];let o;if(t.after?o=s.getRowSpanningCellsOverflowingTheRow(r):o=s.getCellsFallingOnRow(r),o.length){let a=F("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let c=o[h++],p=s.getCellFragmentOfCell(c),d=p.findAcceptableBreakPosition().nodeContext,f=p.cellNodeContext,g=f.toNodePosition(),m=new zt(d.toNodePosition());s.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:c});let y=f.viewNode;p.column.layoutContext.processFragmentedBlockEdge(p.cellNodeContext),r<c.rowIndex+c.rowSpan-1&&(y.rowSpan=r-c.rowIndex+1),p.empty?l.continueLoop():p.pseudoColumn.finishBreak(d,!1,!0).then(()=>{Gg(p,s,d),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),s.finishFragment(),a.finish(!0)}),a.result()}}return s.finishFragment(),Xr.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Gg(e,t,i){let n=t.getRepetitiveElements();if(!n)return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=r.clientLayout.getElementClientRect(a),l=r.getComputedPaddingBorder(a);if(s){let c=h.right-r.footnoteEdge-n.calculateOffset(i)-l.right;k(o,"max-width",`${c}px`)}else{let c=r.footnoteEdge-n.calculateOffset(i)-h.top-l.top;k(o,"max-height",`${c}px`)}k(o,"overflow","hidden")}var Wg=class extends qr{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new jg(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Yg(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()}},jg=class extends Jh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Xg=class extends wn{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 qg(this.position.sourceNode))}},qg=class au{constructor(t){this.tableRootNode=t,u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,rn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof au&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Yg=class extends Qh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Kg(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Kg=class lu extends io{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=at(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(s=>s.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,s){let r=at(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,r),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,s)})}),!t){let o=r.getRootViewNode(this.nodeContext);new ou().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=at(this.nodeContext.formattingContext),s=F("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),o=0;return s.loop(()=>{if(o<r.length){let a=r[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{s.finish(!0)}),s.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let s=[];for(let r=0;r<n;r++)i.cellFragments[r]&&i.cellFragments[r].forEach(o=>{o&&s.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return s}getElementsOffsetsForTableCell(t){let i=at(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof lu?at(this.nodeContext.formattingContext)===at(t.nodeContext.formattingContext):!1}},Zg=new ou;function Jg(e,t,i,n,s,r){if(!t)return null;if(i===v.table){let o=e.parent;return new bi(o?o.formattingContext:null,e.sourceNode)}return null}function Qg(e){return e instanceof bi?Zg:null}ht("RESOLVE_FORMATTING_CONTEXT",Jg);ht("RESOLVE_LAYOUT_PROCESSOR",Qg);function wa(e){return e.reduce((t,i)=>t+i,0)/e.length}function em(e){let t=wa(e);return wa(e.map(i=>{let n=i-t;return n*n}))}var tm=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function on(e){return e.vertical?e.width:e.height}function an(e,t){e.vertical?e.width=t:e.height=t}var hu=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=on(e)}balanceColumns(e){let t=F("ColumnBalancer#balanceColumns");this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(s=>{if(this.savePageFloatLayoutContexts(s),this.layoutContainer.clear(),!s){n.breakLoop();return}i.push(this.createTrialResult(s)),n.continueLoop()})}).then(()=>{let n=i.reduce((s,r)=>r.penalty<s.penalty?r:s,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new tm(e,t)}preBalance(e){}postBalance(){an(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},wr=1;function uu(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,s=Math.max.apply(null,n.map(o=>o.computedBlockSize)),r=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return s>r+wr}function cu(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(s=>isNaN(s.blockDistanceToBlockEndFloats)?s.computedBlockSize:s.computedBlockSize-s.blockDistanceToBlockEndFloats+wr))-wr;n<on(t)?an(t,n):an(t,on(t)-1)}var im=class extends hu{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);an(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 ba(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return uu(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!ba(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):on(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)cu(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,on(this.layoutContainer)+this.originalContainerBlockSize*.1);an(this.layoutContainer,t)}}};function ba(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize;return e.slice(0,e.length-1).every(i=>t>i.computedBlockSize)}var nm=class extends hu{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 em(t)}hasNextCandidate(e){return uu(e)}updateCondition(e){cu(e,this.layoutContainer)}};function sm(e,t,i,n,s,r,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=r[r.length-1],l=!!(h&&h.pageBreakType);return a||l?new im(i,n,s,e):t===v.balance_all?new nm(i,n,s):(v.balance,null)}}var Ls=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},rm=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 Ls(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 Ls(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Ls(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=Bt(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=Bt(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},om=class br{constructor(t,i,n,s,r,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=r.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new br(t,l.before,n,!1,r,this.isBlock(),a,!0),p=c.styleValue("content");Dt(p)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=Xe(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ke(this.breakBefore)&&(r.breakBefore=Xe(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new br(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Dt(o)&&(this.afterBox=r)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=vh(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!er(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}},am=class{constructor(e){this.context=e,u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==v.none)}push(e,t,i,n){let s=this.lastBox();n&&s&&n.flowName!==s.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=n||s.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new om(this.context,e,t,i,r,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=lh(i);n&&!Ue(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=Xe(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},ya=class{constructor(e,t,i,n,s,r,o,a){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,this.counterListener=o,u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang),this.offsetMap=new rm;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new am(n),this.offsetMap.addStuckRange(h);let l=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,l,h),this.postprocessTopStyle(l,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${h}`]=l,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let s=t[i];s&&(this.rootStyle[i]=new K(s,ql))}}}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)Xi(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,s=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<va.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,va[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"ex":h*=this.context.initialFontSize*we.ex/we.em;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*we.lh/we.em;break;default:{let l=we[a.unit];l&&(h*=l),s=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=s}}let r=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!J(o.value)){let a=o.evaluate(this.context);if(a instanceof Vt)this.context.rootLineHeight=a.num*r;else if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=r;break;case"ex":h*=r*we.ex/we.em;break;case"%":h*=r/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*we.lh/we.em;break;default:{let l=we[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*we.lh/we.em}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return ig(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let r=this.getStyle(this.root,!1),o=Ve(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),s=this.xmldoc.getNodeOffset(n,0,!1);if(!(s>=this.lastOffset))for(;;){if(n.nodeType!=1)s+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,o,s)}s++}if(s>=this.lastOffset)break;let r=n.firstChild;if(r==null){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n===this.root)return}n=r}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let s=0,r=Number.POSITIVE_INFINITY,o=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=wd(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let c=t["flow-linger"];c&&(r=Uo(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let p=t["flow-priority"];p&&(s=Uo(p.evaluate(this.context,"flow-priority"),0));let d=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Lp(e,m)}let g=new Fp(e,i,n,s,r,o,a,h,d);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ke(e)){let s=this.flows[i].forcedBreakOffsets;(s.length===0||s[s.length-1]<t)&&s.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=Xe(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let s=this.context;for(;;){let r=this.last.firstChild;if(r==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=Xe(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(r=this.last.nextSibling,r)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=r,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,c=a["flow-into"];if(c){let d=c.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(d,a,o,this.lastOffset);this.primary=!!this.primaryFlows[d],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=Xe(l.flowChunk.breakBefore,l.breakBefore));let p=this.boxStack.nearestBlockStartOffset(l);if(p===0){let d=a.page,f=d&&!J(d.value)&&d.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,p,l.flowName),l.beforeBox){let d=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(d,l.beforeBox.atBlockStart?p:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&p===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},va=["column-count","column-width","column-fill"],pi=class{constructor(e){this.validator=e,u(this,"success",null),u(this,"failure",null),u(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Gt=class{constructor(e,t){this.where=e,this.success=t,u(this,"what",-1)}},Bi=class du{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 du;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new pi(n.validator);s.code=n.code,t.nodes.push(s)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],s=new Gt(n.where,n.success);s.what=n.what,t.connections.push(s)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let s=this.nodes.length,r=new pi(xa);n>=0?i?r.markAsStartAlternate(n):r.markAsEndAlternate(n):i?r.markAsStartGroup():r.markAsEndGroup(),this.nodes.push(r),this.connect(t,s);let o=new Gt(s,!0),a=new Gt(s,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new pi(xa);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Gt(0,!0),s=new Gt(0,!1);this.nomatch.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new pi(t));let n=new Gt(i,!0),s=new Gt(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof Pe}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let r=0;r<t.nodes.length;r++)this.nodes.push(t.nodes[r]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let r=0;r<t.connections.length;r++){let o=t.connections[r];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let r=0;r<t.match.length;r++)this.match.push(t.match[r]+s);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let r=0;r<t.nomatch.length;r++)this.match.push(t.nomatch[r]+s);else if(this.emptyHead){for(let r=0;r<t.nomatch.length;r++)this.nomatch.push(t.nomatch[r]+s);this.emptyHead=t.emptyHead}else for(let r=0;r<t.nomatch.length;r++)this.error.push(t.nomatch[r]+s);for(let r=0;r<t.error.length;r++)this.error.push(t.error[r]+s);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let s of this.connections)s.success?this.nodes[s.where].success=this.nodes[s.what]:this.nodes[s.where].failure=this.nodes[s.what];for(let s=0;s<n;s++)if(this.nodes[s].failure==null||this.nodes[s].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},lm=1,pu=2,fu=4,Wt=8,_n=16,yr=32,Mn=64,gu=128,Vi=256,Ui=512,vr=1024,mu=2048,wu=4096,bu=8192,yu=class extends It{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Pe=class vu extends yu{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&lm?t:null}visitSlash(t){return this.allowed&mu?t:null}visitStr(t){return this.allowed&pu?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&fu||this.allowed&Mn&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Ui)?t.unit=="%"&&this.allowed&vr?t:null:t.num<0&&!(this.allowed&Vi)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&_n?t:null}visitInt(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&(yr|_n)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Mn&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&gu?t:null}visitURange(t){return this.allowed&wu?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&Mn&&CSS.supports("color",t.toString())||this.allowed&bu&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(Wt|_n|yr|Vi|Ui|vr)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let s in this.idents)i[s]=this.idents[s];for(let s in t.idents)i[s]=t.idents[s];for(let s in this.units)n[s]=this.units[s];for(let s in t.units)n[s]=t.units[s];return new vu(this.allowed|t.allowed,i,n)}},ne={},xa=new Pe(0,ne,ne),no=class extends yu{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new pi(null),this.failureTerminal=new pi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,s=this.first,r=i,o=null,a=null;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(r>=e.length){s=s.failure;continue}let h=e[r],l=h;if(s.isSpecial()){let c=!0;s.isStartGroup()?(o?o.push(a):o=[a],a=[]):s.isEndGroup()?o.length>0?a=o.pop():a=null:s.isEndAlternate()?a[s.getAlternate()]="taken":c=a[s.getAlternate()]==null,s=c?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof Ki&&this instanceof Ki){if(l=new ve(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof so&&this instanceof Ki){if(l=new qe(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else l=h.visit(s.validator);if(!l){s=s.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<r;c++)n[c]=e[c]}e!==n&&(n[r-i]=l),r++,s=s.success}}return s===this.successTerminal&&(t?n.length>0:r==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Ki=class extends no{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ve(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof so){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},so=class extends no{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new qe(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},hm=class extends no{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ki(e.name,t):null}},xu=class{tryParse(e,t,i){return t}success(e,t){}},Su=class extends xu{constructor(e,t){super(),this.name=t,u(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let s=n.length,r=s>1?new ve(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},um=class extends Su{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},cm=class extends xu{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==ns){if(++t==e.length)return n}else return n;let s=this.nodes[0].tryParse(e,t,i);if(s==t)return n;t=s;for(let r=1;r<this.nodes.length&&t<e.length&&(s=this.nodes[r].tryParse(e,t,i),s!=t);r++)t=s;return t}},ro=class extends It{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 Su(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let s of this.propList)t.simpleProperty(s,(n=(i=this.values[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Ri=class extends ro{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}},Cu=class extends ro{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 um(this.validatorSet,this.propList)}},dm=class extends ro{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===ns){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let s;if(t+1<e.length)for(s=t+i+1;s>=e.length;)s=s-(s==t+2?1:2);else s=n;let r=[e[n],e[s]];if(this.syntax[i].tryParse(r,0,this)!=2)return this.error=!0,0}return e.length}},pm=class extends Ri{constructor(){super()}mergeIn(e,t){var i,n;for(let s of this.propList){let r=(n=(i=t[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:v.initial,o=e[s];o||(o=[],e[s]=o),o.push(r)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof qe?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new qe(t[i]);return null}},fm=class extends Ri{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let s=this.validatorSet.validators;if(!e[t].visit(s["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===ns){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(s["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let r=t==e.length-1?e[t]:new ve(e.slice(t,e.length));return r.visit(s["font-family"])?(this.values["font-family"]=r,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new qe(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},gm=class extends Ri{validateList(e){if(e.length===1&&e[0]instanceof ft)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},mm=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],wm=class extends Ri{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)mm.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Sa={SIMPLE:Ri,INSETS:Cu,INSETS_SLASH:dm,COMMA:pm,FONT:fm,TEXT_SPACING:gm,ALL:wm},bm=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new T(t.num,t.text);else if(t.type==7)i=new Pl(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Bi;if(e=="||"){for(let s=0;s<t.length;s++){let r=new Bi;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new Bi;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let s=0;s<t.length;s++)i.addGroup(t[s],s==0?1:n);return i}}addCounts(e,t,i){let n=new Bi;for(let s=0;s<t;s++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let s=t;s<i;s++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Bi;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new so(t);break;case"SPACE":i=new Ki(t);break;default:i=new hm(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Pe(Mn,ne,ne)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Pe(bu,ne,ne)),this.namedValidators.POS_INT=this.primitive(new Pe(yr,ne,ne)),this.namedValidators.POS_NUM=this.primitive(new Pe(_n,ne,ne)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Pe(Wt,ne,{"%":G})),this.namedValidators.NEGATIVE=this.primitive(new Pe(Vi,ne,ne)),this.namedValidators.ZERO=this.primitive(new Pe(Ui,ne,ne)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Pe(vr,ne,ne)),this.namedValidators.POS_LENGTH=this.primitive(new Pe(Wt,ne,{em:G,ex:G,ch:G,rem:G,lh:G,rlh:G,vw:G,vh:G,vi:G,vb:G,vmin:G,vmax:G,pvw:G,pvh:G,pvi:G,pvb:G,pvmin:G,pvmax:G,cm:G,mm:G,in:G,px:G,pt:G,pc:G,q:G})),this.namedValidators.POS_ANGLE=this.primitive(new Pe(Wt,ne,{deg:G,grad:G,rad:G,turn:G})),this.namedValidators.POS_TIME=this.primitive(new Pe(Wt,ne,{s:G,ms:G})),this.namedValidators.FREQUENCY=this.primitive(new Pe(Wt,ne,{Hz:G,kHz:G})),this.namedValidators.RESOLUTION=this.primitive(new Pe(Wt,ne,{dpi:G,dpcm:G,dppx:G})),this.namedValidators.URI=this.primitive(new Pe(gu,ne,ne)),this.namedValidators.URANGE=this.primitive(new Pe(wu,ne,ne)),this.namedValidators.IDENT=this.primitive(new Pe(fu,ne,ne)),this.namedValidators.STRING=this.primitive(new Pe(pu,ne,ne)),this.namedValidators.SLASH=this.primitive(new Pe(mu,ne,ne));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let s=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(s)||(this.prefixes[s]=n)}else if(e.token().type!=18)throw new Error("':' expected");return s}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],s="",r,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(s,i)},h=c=>{if(o)throw new Error(`'${c}': unexpected`);if(s&&s!=c)throw new Error(`mixed operators: '${c}' and '${s}'`);s=c,o=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(o||h(" "),this.isBuiltIn(c.text)){let p=this.namedValidators[c.text];if(!p)throw new Error(`'${c.text}' unexpected`);i.push(p.clone())}else{let p={};p[c.text.toLowerCase()]=B(c.text),i.push(this.primitive(new Pe(0,p,ne)))}o=!1;break;case 5:{let p={};p[`${c.num}`]=new Qt(c.num),i.push(this.primitive(new Pe(0,p,ne))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:s,b:"(",fn:c.text}),s="",i=[],o=!0;break;case 15:{r=a();let p=n.pop();if(p.b!="[")throw new Error("']' unexpected");i=p.vals,i.push(r),s=p.op,o=!1;break}case 11:{r=a();let p=n.pop();if(p.b!="(")throw new Error("')' unexpected");i=p.vals,i.push(this.newFunc(p.fn,r)),s=p.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");let p=c.num,d=p;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");d=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),p,d));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new Ki(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 Vt(n.num));break;case 5:i.push(new Qt(n.num));break;case 3:i.push(new T(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new ve(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Sa[i.text]?(n=new Sa[i.text],e.consume()):n=new Ri,n.setOwner(this);let s=!1,r=[],o=!1,a=[],h=[];for(;!s;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])r.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Cu){let l=this.shorthands[i.text];r.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(r.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:r}),r=[],o=!1;break;case 15:{let l=new cm(r,o),c=a.pop();r=c.syntax,o=c.slash,r.push(l);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,h),this.shorthands[t]=n}}parse(e){let t=new gt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let s=this.shorthands[n],r=s?s.propList:[n];for(let o of r)i[o]=(t=this.defaultValues[o])!=null?t:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){if(Nt(e)||n.ruleType==="font-face"||vm(t)){n.simpleProperty(e,t,i);return}let s="",r=e;e=e.toLowerCase();let o=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);o&&(s=o[1],e=o[2]);let a=this.prefixes[e];if(!a||!a[s]){CSS.supports(e,t.toString())?n.simpleProperty(r,t,i):s&&!Ja.includes(`-${s}-`)||n.unknownProperty(r,t);return}let h=this.validators[e];if(h){let l=J(t)||t.isExpr()?t:t.visit(h);l?n.simpleProperty(e,l,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(r,t)}else{let l=this.shorthands[e].clone();J(t)?l.propagateDefaultingValue(t,i,n):(t.visit(l),l.finish(i,n)||n.invalidPropertyValue(r,t))}}};function Eu(){let e=new bm;return e.initBuiltInValidators(),e.parse(Ul),e}var ym=class extends It{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function vm(e){let t=new ym;return e.visit(t),t.varFound}var ln={"font-style":v.auto,"font-stretch":v.auto,"font-weight":v.auto,"unicode-range":rd},Yw=`OTTO${new Date().valueOf()}`;function xm(e){let t=new kt;for(let i in ln)t.append(" "),t.append(e[i].toString());return t.toString()}function Sm(e){for(let t in ln)e[t]||(e[t]=ln[t])}function Cm(e,t){let i={};for(let n in e)i[n]=Ve(e,n).evaluate(t,n);return Sm(i),i}var ku=class{constructor(e){this.properties=e,u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=xm(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 kt;i.append(`@font-face {
1481
+ `;function as(e,t,i){let n=F("fetchFromURL"),s={method:i||"GET",mode:"cors"},r=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,s).then(a=>{var h;return o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=ql([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),r.schedule(o)}).catch(a=>{D.warn(a,`Error fetching ${e}`),r.schedule(o)}),n.result()}function ql(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function np(e){let t=F("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function sp(e){return URL.createObjectURL(e)}var Dr=class{constructor(e,t){this.parser=e,this.type=t,u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Ct(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=F("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=ke("user-agent.xml",Jt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent($l)}`),as(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);s?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=r),this.parser(a,this).then(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ct(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new mn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ct(e)]}delete(e){delete this.resources[Ct(e)]}};function rp(e,t){let i=e.responseText;return N(i?Ar(i):null)}function op(){return new Dr(rp,"text")}function ri(e,t,i){let n=new mn(()=>{let s=F("loadElement"),r=s.suspend(e),o=!1,a=h=>{o||(o=!0,r.schedule(h?h.type:"timeout"))};return e.addEventListener("load",a,!1),e.addEventListener("error",a,!1),e.addEventListener("abort",a,!1),e.namespaceURI=="http://www.w3.org/2000/svg"?(t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),setTimeout(a,300)):e.localName==="script"?setTimeout(a,3e3):t&&(e.src=t,i&&(e.alt=i)),s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Wo=0,ap=16777216,Yl=33554432,Zl=50331648,Kl=67108864,lp=83886080,hp=100663296,Vr=class{constructor(e){this.scope=e,u(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Wo;case"User":return hp;default:return lp}}getBaseSpecificity(){switch(this.flavor){case"UA":return Wo;case"User":return ap;default:return Yl}}},up=class extends Vr{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;D.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},jo=class extends Vr{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,u(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},wn=class extends jo{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new jo(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ee=[],$n=[],fe=[],Ce=[],ot=[],et=[],Se=[],Le=[],ce=[],Me=[],je=[],_e=[],xe=[],oi=55,ai=56,Nn=57;Ee[1]=28,Ee[36]=29,Ee[7]=29,Ee[9]=29,Ee[14]=29,Ee[18]=29,Ee[50]=29,Ee[20]=30,Ee[13]=27,Ee[0]=200,$n[1]=46,$n[0]=200,et[1]=2,et[36]=4,et[7]=6,et[9]=8,et[14]=10,et[18]=14,et[50]=42,fe[37]=11,fe[23]=12,fe[35]=56,fe[1]=1,fe[36]=3,fe[7]=5,fe[9]=7,fe[14]=9,fe[12]=13,fe[18]=55,fe[50]=58,fe[16]=41,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[18]=55,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[18]=14,ot[50]=42,ot[14]=10,ot[12]=13,Se[1]=15,Se[7]=16,Se[4]=17,Se[5]=18,Se[3]=19,Se[2]=20,Se[8]=21,Se[27]=57,Se[16]=22,Se[19]=23,Se[6]=24,Se[11]=25,Se[17]=26,Se[13]=48,Se[31]=47,Se[23]=54,Se[0]=44,Le[1]=31,Le[4]=32,Le[5]=32,Le[3]=33,Le[2]=34,Le[10]=40,Le[6]=38,Le[31]=36,Le[24]=36,Le[32]=35,ce[1]=45,ce[16]=37,ce[37]=37,ce[38]=37,ce[47]=37,ce[48]=37,ce[39]=37,ce[49]=37,ce[41]=37,ce[26]=37,ce[25]=37,ce[23]=37,ce[24]=37,ce[19]=37,ce[21]=37,ce[36]=37,ce[18]=37,ce[22]=37,ce[11]=39,ce[12]=43,ce[17]=49,Me[0]=200,Me[12]=50,Me[13]=51,Me[14]=50,Me[15]=51,Me[10]=50,Me[11]=51,Me[17]=53,je[0]=200,je[12]=50,je[13]=52,je[14]=50,je[15]=51,je[10]=50,je[11]=51,je[17]=53,_e[0]=200,_e[12]=50,_e[13]=51,_e[14]=50,_e[15]=51,_e[10]=50,_e[11]=51,xe[11]=0,xe[16]=0,xe[22]=1,xe[18]=1,xe[26]=2,xe[25]=2,xe[38]=3,xe[37]=3,xe[48]=3,xe[47]=3,xe[39]=3,xe[49]=3,xe[41]=3,xe[23]=4,xe[24]=4,xe[36]=5,xe[19]=5,xe[21]=5,xe[0]=6,xe[oi]=2,xe[ai]=2;var bn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(G)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof Ri){if(r.text===")")s++;else if(r.text==="("){if(s===0)return null;s--}}while(typeof r<"u"&&typeof r!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new ye(i.slice(n+1,i.length))),e==",")return null;n++;do r=i[--n];while(typeof r<"u"&&(typeof r!="string"||r==","));if(o=i.length-(n+1),r=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=je);let h=new ki(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof ft&&h.values[0].name;(!Nt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=je)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=je,null;if(o>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof $e?a:a?new Ri(a.toString()):G}exprError(e,t){this.actions=this.propName?je:Me,D.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,s=i.pop(),r;for(;;){let o=i.pop();if(e==11){let a=[s];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let h=a.shift(),l=a.shift(),c=new qc(n.getScope(),h,l);a.unshift(c)}return i.push(new V(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();s=new Gi(n.getScope(),zs(l,h),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new Fo(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new Bt(n.getScope(),s);else if(o==-24)s=new gl(n.getScope(),s);else if(o==-Nn)s=new jc(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(xe[e]>xe[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Fr(n.getScope(),r,s);break;case oi:s=new Xc(n.getScope(),r,s);break;case ai:s=new Yc(n.getScope(),r,s);break;case 25:s=new Or(n.getScope(),r,s);break;case 38:s=new Zc(n.getScope(),r,s);break;case 37:s=new Jc(n.getScope(),r,s);break;case 48:s=new Kc(n.getScope(),r,s);break;case 47:s=new Us(n.getScope(),r,s);break;case 39:case 49:s=new Br(n.getScope(),r,s);break;case 41:s=new Qc(n.getScope(),r,s);break;case 23:s=new ml(n.getScope(),r,s);break;case 24:s=new wl(n.getScope(),r,s);break;case 36:s=new _r(n.getScope(),r,s);break;case 19:s=new bl(n.getScope(),r,s);break;case 21:s=new vl(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new id(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new Fo(n.getScope(),r,s);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(r),i.push(o),i.push(s),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(s),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,s;if(t)s=e.text,n=e.position+s.length+1;else if(e.type===10){let c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),s=c.text,n=p.position+1;else{if(c.type===10||c.type===6||c.type===1&&c.text.toLowerCase()==="not"&&(p.type===10||p.type===6))return null;n=e.position+1}}else return null;let r=0,o,a=0;for(;r>=0;)switch(i.consume(),o=i.token(),o.type){case 11:r--;break;case 10:case 6:r++;break;case 16:r===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let h=o.position,l=t&&s==="selector"&&a>0?"":i.input.substring(n,h).trim();return new nd(this.handler.getScope(),s,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let s=t.type===24,r=t.type===23||s;if(r&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,r)return null}else if(n<0){if(r)return null}else if(n>=0&&!r)return null;this.tokenizer.consume()}else if(r)return null;return[i,s&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let s of n)switch(s){case"vertical":t=lt(i,t,new Bt(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=lt(i,t,new ze(i,"pref-horizontal"));break;case"day":t=lt(i,t,new Bt(i,new ze(i,"pref-night-mode")));break;case"night":t=lt(i,t,new ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new V(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(e,t,i,n,s,r){let o=this.handler,a=this.tokenizer,h=this.valStack,l,c,p,d,f,g,m,v=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),s&&v===null&&(v=l.position-1,a.input[v]==="("&&v++),this.actions===Se&&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 Ri(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=je):(this.actions=et,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Se,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=je,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Se,h.splice(0,h.length);continue;case 29:this.actions=et,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=_e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),p=this.namespacePrefixToURI[l.text],p!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(p,l.text),s?this.actions=Ce:this.actions=fe,a.consume();break;case 36:o.tagSelector(p,null),s?this.actions=Ce:this.actions=fe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else this.actions=Me,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=_e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),s?this.actions=Ce:this.actions=fe,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Ce:this.actions=fe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),s?this.actions=Ce:this.actions=fe;continue;case 6:switch(d=l.text,a.consume(),d){case"is":case"not":case"where":case"has":this.actions=et,o.startFuncWithSelector(d),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,d==="has")?this.actions=fe:this.actions=_e;continue;case"lang":case"href-epub-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),d==="href-epub-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)break;break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(d,m),a.consume(),s?this.actions=Ce:this.actions=fe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Me;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;case 6:if(d=l.text,a.consume(),d=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(d,m),s?this.actions=Ce:this.actions=fe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Me;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)d=l.text,a.consume();else if(l.type==36)d=null,a.consume();else if(l.type==34)d="";else{this.actions=_e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(p=d&&this.namespacePrefixToURI[d],p===void 0){this.actions=_e,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=_e,o.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}d=l.text,a.consume(),l=a.token()}else p="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:o.attributeSelector(p,d,0,null),s?this.actions=Ce:this.actions=fe,a.consume();continue;default:this.actions=_e,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:o.attributeSelector(p,d,f,l.text),a.consume(),l=a.token();break;default:this.actions=_e,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=_e,o.error("E_CSS_ATTR",l);continue}s?this.actions=Ce:this.actions=fe,a.consume();continue;case 11:o.childSelector(),this.actions=ot,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=ot,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=ot,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=Ee,a.consume();continue;case 41:o.nextSelector(),this.actions=et,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Tl(l.text)),a.consume();continue;case 17:h.push(new Ut(l.num)),a.consume();continue;case 18:h.push(new ei(l.num)),a.consume();continue;case 19:h.push(new T(l.num,l.text)),a.consume();continue;case 20:h.push(new Re(l.text)),a.consume();continue;case 21:h.push(new ct(ke(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Il(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(ns),a.consume();continue;case 24:d=l.text.toLowerCase(),d=="-epubx-expr"||d=="env"?(this.actions=Le,this.exprContext=0,h.push("{")):(h.push(d),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new Ri("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?$n:Ee;continue;case 44:for(a.consume();h.length>0;){let b=h.length;if(g=this.valStackReduce(";",l),!g||h.length===b)break}return t?(this.result=g,!0):(this.propName&&g&&o.property(this.propName,g,this.propImportant),!0);case 31:if(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new ze(o.getScope(),zs(l.text,c.text))),this.actions=ce),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Lo(o.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Lo(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==oi&&h[h.length-1]!==ai&&(c.type===10||c.type===6)){h.push(-Nn),a.consume();continue}else h.push(new ze(o.getScope(),l.text));this.actions=ce}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ce;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Fe(o.getScope(),l.num)),a.consume(),this.actions=ce;continue;case 33:d=l.text,d=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?d="vh":d="vw"),h.push(new Qt(o.getScope(),l.num,d)),a.consume(),this.actions=ce;continue;case 34:h.push(new Fe(o.getScope(),l.text)),a.consume(),this.actions=ce;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Cl(o.getScope(),l.num)),a.consume(),this.actions=ce);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Le,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==ai&&h[h.length-2]!==-Nn?(this.actions=Le,this.exprStackReduce(oi,l),h.push(oi),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==oi&&h[h.length-2]!==-Nn?(this.actions=Le,this.exprStackReduce(ai,l),h.push(ai),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Se),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ee)),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=Ee,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Ee,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ce;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Ee,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(d=l.text.toLowerCase(),d){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Le,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Me;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(d=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[d]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=Me;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){d=l.text.toLowerCase(),d!="utf-8"&&d!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${d}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Me;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),d){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(d),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){d=l.text,a.consume(),a.consume(),o.startFootnoteRule(d),this.ruleStack.push("-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=et;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=ot;continue;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(d),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Le,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Le,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Le,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(d),o.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,w=null,S=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(w=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(),d){case"-epubx-page-master":o.startPageMasterRule(b,w,S);break;case"-epubx-partition":o.startPartitionRule(b,w,S);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,w,S);break}this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${d}`,l),this.actions=_e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${d}`,l),this.actions=Me;continue}o.error(`E_CSS_AT_SYNTAX ${d}`,l),this.actions=Me;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ee;continue}case 51:if(s&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=Ee),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ee),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(s){switch(l.type){case 16:case 11:if(this.actions===et)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(v,l.position);o.pushSelectorText(b),v=l.position+1}if(l.type===16){o.nextSelector(),this.actions=et,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=fe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=_e;continue}if(this.actions!==Me&&this.actions!==_e&&this.actions!==je){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===Se){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ri(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Le&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ee,a.consume();continue}else{if(l.type===17&&this.actions==Le)return this.actions=Ee,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=je:this.actions=_e;continue}a.consume();continue}}return!1}},Jl=class extends Vr{constructor(e){super(null),this.scope=e}error(e,t){D.warn(e,t.toString())}getScope(){return this.scope}};function cp(e,t,i,n,s){let r=F("parseStylesheet"),o=new bn(Ee,e,t,i),a=null;return s&&(a=pp(new gt(s,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),r.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let l=ke(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let c=F("parseStylesheet.import");return Ql(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,c.finish(!0)}),c.result()}let h=r.timeSlice();if(h.isPending)return h}return N(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function Ur(e,t,i,n,s){return yi("parseStylesheetFromText",r=>{let o=new gt(e,t);cp(o,t,i,n,s).thenFinish(r)},(r,o)=>{D.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Ql(e,t,i,n){return yi("parseStylesheetFromURL",s=>{as(e).then(r=>{r.responseText?Ur(r.responseText,t,e,i,n).then(o=>{o||D.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{D.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function Ti(e,t,i){let n=new bn(Se,t,new Jl(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function dp(e,t,i){new bn($n,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function pp(e,t,i){let n=new bn(Le,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var fp={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function gp(e){return!!fp[e]}function mp(e,t,i){let n=t.evaluate(e);switch(typeof n){case"number":return gp(i)?n==Math.round(n)?new ei(n):new Ut(n):new T(n,"px");case"string":return n?Ti(t.scope,new gt(n,null),""):G;case"boolean":return n?y._true:y._false;case"undefined":return G}throw new Error("E_UNEXPECTED")}function eh(e,t){let i={};return Object.keys(e).forEach(n=>{let s=i[n]={},r=e[n];Object.keys(r).forEach(o=>{s[o]=r[o].map(a=>{let h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function th(e,t,i,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let r=s[i||"ltr"];if(!r)throw new Error(`unknown direction: ${i}`);for(let o of r){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var ih={"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"}]}},wp=eh(ih,!0);function nh(e,t,i){return th(e,t,i||null,wp)}var bp=eh(ih,!1);function sh(e,t,i){return th(e,t,i||null,bp)}var vp={"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 yp(e,t){let i=vp[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 Hr(e,t,i){let n={display:t.style.display,position:t.style.position,width:t.style.width,maxWidth:t.style.maxWidth,minWidth:t.style.minWidth,height:t.style.height,maxHeight:t.style.maxHeight,minHeight:t.style.minHeight,top:t.style.top,right:t.style.right,bottom:t.style.bottom,left:t.style.left},s=t.ownerDocument,r=t.parentNode,o=s.createElement("div");k(o,"position",n.position),r.insertBefore(o,t),o.appendChild(t),k(t,"width","auto"),k(t,"max-width","none"),k(t,"min-width","0"),k(t,"height","auto"),k(t,"max-height","none"),k(t,"min-height","0");function a(I){return e.getElementComputedStyle(t).getPropertyValue(I)}let h=el("writing-mode"),l=(h?a(h[0]):null)||a("writing-mode"),c=l==="vertical-rl"||l==="tb-rl"||l==="vertical-lr"||l==="tb-lr",p=c?"height":"width",d=c?"width":"height";function f(){(n.position==="absolute"||n.position==="fixed")&&(k(o,"width",n.width),k(o,"height",n.height),k(o,"top",n.top),k(o,"right",n.right),k(o,"bottom",n.bottom),k(o,"left",n.left)),k(t,"display","block"),k(t,"position","static");let I=a(p);return k(o,"width",""),k(o,"height",""),k(o,"top",""),k(o,"right",""),k(o,"bottom",""),k(o,"left",""),I}function g(){k(t,"display","inline-block"),k(o,p,"99999999px");let I=a(p);return k(o,p,""),I}function m(){k(t,"display","inline-block"),k(o,p,"0");let I=a(p);return k(o,p,""),I}function v(){let I=f(),L=m(),_=parseFloat(I);if(_<=parseFloat(L))return L;{let U=g();return _<=parseFloat(U)?I:U}}function b(){return a(d)}function w(){throw new Error("Getting fill-available block size is not implemented")}let S={};return i.forEach(I=>{var L;let _;switch(I){case"fill-available inline size":_=f();break;case"max-content inline size":_=g();break;case"min-content inline size":_=m();break;case"fit-content inline size":_=v();break;case"fill-available block size":_=w();break;case"max-content block size":case"min-content block size":case"fit-content block size":_=b();break;case"fill-available width":_=c?w():f();break;case"fill-available height":_=c?f():w();break;case"max-content width":_=c?b():g();break;case"max-content height":_=c?g():b();break;case"min-content width":_=c?b():m();break;case"min-content height":_=c?m():b();break;case"fit-content width":_=c?b():v();break;case"fit-content height":_=c?v():b();break}_==="0px"&&t.childNodes.length===1&&((L=t.firstElementChild)==null?void 0:L.localName)==="img"&&!t.firstElementChild.complete&&(_="1px"),S[I]=parseFloat(_),k(t,"position",n.position),k(t,"display",n.display)}),k(t,"width",n.width),k(t,"max-width",n.maxWidth),k(t,"min-width",n.minWidth),k(t,"height",n.height),k(t,"max-height",n.maxHeight),k(t,"min-height",n.minHeight),r.insertBefore(t,o),r.removeChild(o),S}function _i(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 rh(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function oh(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function nt(e,t){let i=rh(e);i.includes(t)||(i.push(t),oh(e,i))}function xp(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Sp(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Is(e,t){let i=xp(e);i.includes(t)||(i.push(t),Sp(e,i))}function Cp(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 Ys={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ke(e){return!!Ys[e]}var Ep={left:!0,right:!0,recto:!0,verso:!0};function sn(e){return!!Ep[e]}var kp={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Gn(e){return!!kp[e]}function Xe(e,t){if(e)if(t){if(sn(t))return t;if(sn(e))return e;{let i=Ke(e),n=Ke(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:Gn(t)?t:Gn(e)?e:t}}else return e;else return t}function Xo(e){return Ke(e)?e:"auto"}ht("SIMPLE_PROPERTY",Cp);var ji=xc(Cc());function Np(e,t){return(0,ji.default)(e,t,0)}function qo(e){return e.reduce((t,i)=>i[0]===ji.default.DELETE?t:t+i[1],"")}function Pp(e,t){return ah(e,t,1)}function Tp(e,t){return ah(e,t,-1)}function ah(e,t,i){let n=0,s=0;return e.some(r=>{for(let o=0;o<r[1].length;o++){switch(r[0]*i){case ji.default.INSERT:n++;break;case ji.default.DELETE:n--,s++;break;case ji.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Zs;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Zs||(Zs={}));var fi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(fi||(fi={}));var Wn;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Wn||(Wn={}));var Yt;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||Mt.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||Mt.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Yt||(Yt={}));var Mt;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(Mt||(Mt={}));var Pt;(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={}))})(Pt||(Pt={}));var Ip={transform:!0,"transform-origin":!0},Ap={top:!0,bottom:!0,left:!0,right:!0},$r=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Rp={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 Lp(e,t){let i=Rp[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Ks=class Mi extends Rr{constructor(t,i){super(),this.container=t,this.bleedBox=i,u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(this,"pageType",null),this.hrefHandler=n=>{let s=n.currentTarget,r=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:s,href:r,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(r=>{let o=this.elementsById[r];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[r]});let n=this.delayedItems;for(let r=0;r<n.length;r++){let o=n[r];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||k(o.target,o.name,o.value.toString())}let s=i.getElementClientRect(this.container);this.dimensions.width=s.width,this.dimensions.height=s.height;for(let r=0;r<t.length;r++){let o=t[r],a=this.elementsById[o.ref],h=this.elementsById[o.observer];if(a&&h){let l=Lp(a,o.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(o.event,l,!1)}}}};u(Ks,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Ks,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var lh=Ks,xi="data-adapt-spec",Je=Pt.Whitespace;function hh(e){switch(e){case"normal":case"nowrap":return Je.IGNORE;case"pre-line":return Je.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Je.PRESERVE;default:return null}}function Ve(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case Je.PRESERVE:return i.length==0;case Je.NEWLINE:return!!i.match(/^[ \t]*$/);case Je.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Fp=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Op=class{constructor(e,t,i,n,s,r,o,a,h){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=s,this.exclusive=r,this.repeated=o,this.last=a,this.breakBefore=h,u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Bp(e,t){return e.top-t.top}function _p(e,t){return t.right-e.right}function uh(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Pt.ShadowType.ROOTLESS&&t.shadowType===Pt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Qs(e.shadowContext,t.shadowContext)&&Qs(e.nodeShadow,t.nodeShadow)&&uh(e.shadowSibling,t.shadowSibling)}function zt(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(!uh(e.steps[i],t.steps[i]))return!1;return!0}function Mp(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function jn(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Xn(e,t){let i=new zi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Xn(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=Pt.ShadowType,Js=class{constructor(e,t,i,n,s,r,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=r,this.styler=o,u(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Qs(this.parentShadow,e.parentShadow):!1}};function Qs(e,t){return e===t||!!e&&!!t&&e.equals(t)}var zp=class{constructor(e,t){this.outer=e,this.count=t}},zi=class ch{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"verticalAlign","baseline"),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=fi.FloatReference.INLINE,this.whitespace=i?i.whitespace:Je.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=fi.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.verticalAlign="baseline",this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:Je.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new ch(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.verticalAlign=this.verticalAlign,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:this.fragmentIndex}}toNodePosition(){var t,i,n;let s=this,r=[];s.shadowType===Pt.ShadowType.ROOTLESS&&(s.floatReference!==fi.FloatReference.INLINE||s.floatSide==="footnote")&&(n=(i=(t=s.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(s=s.parent);do(!s.firstPseudo||!s.parent||s.parent.firstPseudo===s.firstPseudo)&&r.push(s.toNodePositionStep()),s=s.parent;while(s);let o=this.preprocessedTextContent?Tp(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:r,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},Dt=class dh{constructor(t){this.primary=t,u(this,"floats",null)}clone(){let t=new dh(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(!zt(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(!zt(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Dp=class ph{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new ph(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Vp=class fh{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new fh,i=this.positions,n=t.positions;for(let s=0;s<i.length;s++)n[s]=i[s].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Up=class gh{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 gh;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let s of i)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&sn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},mh=class{constructor(e){this.element=e,u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1)}getInsetTop(){return this.marginTop+this.borderTop+this.paddingTop}getInsetBottom(){return this.marginBottom+this.borderBottom+this.paddingBottom}getInsetLeft(){return this.marginLeft+this.borderLeft+this.paddingLeft}getInsetRight(){return this.marginRight+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}setVerticalPosition(e,t){this.top=e,this.height=t,k(this.element,"top",`${e}px`),k(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,k(this.element,"left",`${e}px`),k(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+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.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.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):zr(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 st(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 st(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Bl(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 st(e,t,e+i,t+n)}},qn=class extends It{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue.url)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){t instanceof ze&&(i=Ti(t.scope,new gt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof De&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Vt(e){return e!=null&&e!==G&&e!==y.normal&&e!==y.none&&!J(e)}var Ae=fi.FloatReference;function Hp(e){switch(e){case"inline":return Ae.INLINE;case"column":return Ae.COLUMN;case"region":return Ae.REGION;case"page":return Ae.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function gi(e){switch(e){case Ae.INLINE:return!1;case Ae.COLUMN:case Ae.REGION:case Ae.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Yo(e,t,i){let n=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=sh(e,n,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=nh(e,n,i),r=yp(s,n);r==="line-left"?e="left":r==="line-right"&&(e="right")}return e!=="left"&&e!=="right"&&(D.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var wh=class{constructor(e,t,i,n,s,r){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=s,this.floatMinWrapBlock=r,u(this,"order",null),u(this,"id",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(e){return!1}},$p=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=>zt(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(i=>zt(i.nodePosition,e));return t>=0?this.floats[t]:null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},bh=class{constructor(e,t,i,n,s){this.floatReference=e,this.floatSide=t,this.continuations=i,this.area=n,this.continues=s}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},Zo=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&zt(this.nodePosition,e.nodePosition):!1}},Di=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),e&&e.children.push(this),this.writingMode=r||e&&e.writingMode||y.horizontal_tb,this.direction=o||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new $p;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}getParent(e){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${e}`);return this.parent}getPreviousSiblingOf(e,t,i,n){let s=this.children.indexOf(e);s<0&&(s=this.children.length);for(let r=s-1;r>=0;r--){let o=this.children[r];if(o.floatReference===t&&o.flowName===i&&zt(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Si().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,s)=>n.getOrder()-s.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let s=this.floatFragments.splice(n,1)[0],r=s.area&&s.area.element;r&&r.parentNode&&r.parentNode.removeChild(r),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e)}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(s=>{let r=s.float,o=r.getOrder();o>t&&(!i||o>i.getOrder())&&(i=r)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(s=>s.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i)return this.locked?this.invalidate():(this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)),!0}return this.floatReference===Ae.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(s=>s.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(s=>!i.isAllowedToPrecede(s)&&n>s.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let s=this.findPageFloatFragment(i);this.removePageFloatFragment(s)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();return sh(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return nh(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],s=!1,r=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?s||(i.slice(o+1).some(h=>h.includes("block"))?(n.push("snap-block"),s=!0):n.push(a)):a.includes("inline")&&(r||(i.slice(o+1).some(h=>h.includes("inline"))?(n.push("snap-inline"),r=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n],r=this.toLogicalFloatSides(s.floatSide)[0];(r===i||i==="snap-block"&&r==="block-end"||i==="snap-inline"&&r==="inline-end")&&s.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(s),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n){this.container;let s=this.toLogical(e),r=this.toPhysical(e),o=this.getLimitValueInner(s,t,i,n);if(this.parent&&this.parent.container){let a=this.parent.getLimitValue(r,t,i,n);switch(r){case"top":return Math.max(o,a);case"left":return Math.max(o,a);case"bottom":return Math.min(o,a);case"right":return Math.min(o,a);default:}}return o}getLimitValueInner(e,t,i,n){this.container;let s=this.getLimitValuesInner(t,i,n);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){this.container;let n=this.container.originX,s=this.container.originY,r=this.container.getPaddingRect(),o={top:r.y1-s,left:r.x1-n,bottom:r.y2-s,right:r.x2-n,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function a(l,c,p){return l.unit==="%"?p*l.num/100:e.convertLengthToPx(l,c,t)}let h=this.floatFragments;return h.length>0&&(o=h.reduce((l,c)=>{if(i&&!i(c,this))return l;let p=this.toLogicalFloatSides(c.floatSide)[0],d=c.area,f=c.continuations[0].float.floatMinWrapBlock,g=l.top,m=l.left,v=l.bottom,b=l.right,w=l.floatMinWrapBlockStart,S=l.floatMinWrapBlockEnd;switch(p){case"inline-start":d.vertical?g=Math.max(g,d.top+d.height):m=Math.max(m,d.left+d.width);break;case"block-start":d.vertical?(f&&d.left<b&&(w=a(f,d.rootViewNodes[0],r.x2-r.x1)),b=Math.min(b,d.left)):(f&&d.top+d.height>g&&(w=a(f,d.rootViewNodes[0],r.y2-r.y1)),g=Math.max(g,d.top+d.height));break;case"inline-end":d.vertical?v=Math.min(v,d.top):b=Math.min(b,d.left);break;case"block-end":d.vertical?(f&&d.left+d.width>m&&(S=a(f,d.rootViewNodes[0],r.x2-r.x1)),m=Math.max(m,d.left+d.width)):(f&&d.top<v&&(S=a(f,d.rootViewNodes[0],r.y2-r.y1)),v=Math.min(v,d.top));break;default:throw new Error(`Unknown logical float side: ${p}`)}return{top:g,left:m,bottom:v,right:b,floatMinWrapBlockStart:w,floatMinWrapBlockEnd:S}},o)),o.left+=n,o.right+=n,o.top+=s,o.bottom+=s,o}setFloatAreaDimensions(e,t,i,n,s,r,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,s,r,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0]==="snap-inline"){if(!o["inline-start"]&&!o["inline-end"])return null}else if(!o[a[0]])return null;e.clientLayout;let h=this.getLimitValue("block-start",e.layoutContext,e.clientLayout),l=this.getLimitValue("block-end",e.layoutContext,e.clientLayout),c=this.getLimitValue("inline-start",e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-end",e.layoutContext,e.clientLayout),d=e.vertical?e.originX:e.originY,f=e.vertical?e.originY:e.originX;h=e.vertical?Math.min(h,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+d):Math.max(h,e.top+d),l=e.vertical?Math.max(l,e.left+d):Math.min(l,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+d);function g(S,I){let L=S(e.bands,I);return L?(e.vertical&&(L=Ll(L)),h=e.vertical?Math.min(h,L.x2):Math.max(h,L.y1),l=e.vertical?Math.max(l,L.x1):Math.min(l,L.y2),!0):r}let m,v,b,w;if(s){let S=e.vertical?Hn(new st(l,c,h,p)):new st(c,h,p,l);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!g(pd,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!g(fd,S)||(b=(l-h)*e.getBoxDir(),m=b-e.getInsetBefore()-e.getInsetAfter(),w=(p-c)*e.getInlineDir(),v=w-e.getInsetStart()-e.getInsetEnd(),!r&&(m<=0||v<=0)))return null}else{m=e.computedBlockSize,b=m+e.getInsetBefore()+e.getInsetAfter();let S=(l-h)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let L=this.container.getPaddingRect(),_=this.container.getBoxDir()*(n-(this.container.vertical?L.x2:L.y1)),U=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-n-b);_<=U?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!r&&S<b)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?v=Hr(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?v=e.getContentInlineSize():v=e.vertical?e.height:e.width,w=v+e.getInsetStart()+e.getInsetEnd();let I=(p-c)*e.getInlineDir();if(!r&&I<w)return null}return h-=d,l-=d,c-=f,p-=f,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(c,v):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(p-w*e.getInlineDir(),v),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(h,m):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(l-b*e.getBoxDir(),m),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let e=this.getContainer().vertical;return this.floatFragments.filter(t=>t.floatSide==="block-end").reduce((t,i)=>{let n=i.getOuterRect();return e?Math.max(t,n.x2):Math.min(t,n.y1)},e?0:1/0)}getPageFloatClearEdge(e,t){function i(h){return l=>h.isAnchorAlreadyAppeared(l.float.getId())}function n(h,l){return h.continuations.some(i(l))}let s=t.getPaddingRect(),r=t.vertical?s.x1:s.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return r;o=o.parent}t.clientLayout;let a=this.getLimitValue("block-start",t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",t.layoutContext,t.clientLayout,n)*t.getBoxDir()<r*t.getBoxDir()?r:a}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let s=this.toLogicalFloatSides(t)[0],r=this.toLogical(i),o;r==="all"?o=["block-start","block-end","inline-start","inline-end"]:r==="both"?o=["inline-start","inline-end"]:r==="same"?s==="snap-block"?o=["block-start","block-end"]:o=[s]:o=[r];let a=e.getOrder();function h(p){return d=>d.floatSide===p&&d.getOrder()<a}function l(p,d){return p.children.some(f=>f.floatFragments.some(h(d))||l(f,d))}function c(p,d){let f=p.parent;return!!f&&(f.floatFragments.some(h(d))||c(f,d))}return o.forEach(p=>{switch(p){case"block-start":case"inline-start":n[p]=!l(this,p);break;case"block-end":case"inline-end":n[p]=!c(this,p);break;default:throw new Error(`Unexpected side: ${p}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,s=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);s?e.vertical?(o.right<s.right&&(s.right=o.right,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>s.left&&(s.left=o.left,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>s.top&&(s.top=o.top,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<s.bottom&&(s.bottom=o.bottom,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):s=o,n=n.parent}let r=Math.max(s.floatMinWrapBlockStart,s.floatMinWrapBlockEnd);return(e.vertical?s.right-s.left:s.bottom-s.top)<=r}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},Li=[],Si=class{static register(e){Li.push(e)}findByNodeContext(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Gp=class{appliesToNodeContext(e){return gi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let s=e.floatSide,r=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new wh(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new bh(s.floatReference,t,e,i,n)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Si.register(new Gp);var Wp=bh,er=class vh extends wh{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof vh)}},Ko=class extends Wp{constructor(e,t,i,n){super(e,"block-end",t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof er?!0:this.getOrder()<e.getOrder()}},jp=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!zt(t,this.footnote.nodePosition)}},Xp=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof er}createPageFloat(e,t,i){let n=Ae.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Ae.PAGE).hasSameContainerAs(s)&&(n=Ae.PAGE);let r=e.toNodePosition();t.flowName;let o=new er(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new Ko(s.floatReference,e,i,n)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Ko);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;e.vertical=i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n),e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e)}forbid(e,t){let i=e;switch(i.footnotePolicy){case y.line:{let n=new jp(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Si.register(new Xp);var qp="data-vivliostyle-flow-root";function Yp(e){return e.getAttribute(qp)==="true"}function Jo(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function Gr(e){return e===y.absolute||e===y.fixed}function tr(e){return e instanceof ki&&e.name==="running"}function yh(e,t,i,n){return e===y.none||(Gr(t)?(i=y.none,e=Jo(e)):(i&&i!==y.none&&!J(i)||n)&&(e=Jo(e))),{display:e,position:t,float:i}}function xh(e,t,i,n){return yh(e,t,i,n).display===y.block}function qt(e){switch(e.toString()){case"inline":case"inline-block":case"inline-list-item":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return!1}}function Sh(e){switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Zp(e,t,i,n,s,r,o){return s=s||r||y.horizontal_tb,!!o||!!i&&i!==y.none&&!J(i)||Gr(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&&!J(n)||!!r&&s!==r}function Kp(e){return e===y.relative||e===y.absolute||e===y.fixed}function li(e,t,i,n){let s=e.viewNode;if(!s)return NaN;let r=s.nodeType===1?s:s.parentElement;if(r&&r.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=r.style;if(o&&qt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(s===r){if(e.after||!e.inline){if(e.after&&!e.inline&&r.querySelector("ruby")){let a=r.parentNode,h=r.nextSibling;a.removeChild(r),a.insertBefore(r,h)}let o=t.getElementClientRect(r);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=s.ownerDocument.createRange(),h=s.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(s,i),a.setEnd(s,i+1);let l=t.getRangeClientRects(a);return l=l.filter(c=>c.right>c.left&&c.bottom>c.top),l.length?(n?o=Math.min.apply(null,l.map(c=>c.left)):o=Math.max.apply(null,l.map(c=>c.bottom)),o):NaN}}function ir(e,t,i){let n=t.clientLayout.getElementClientRect(e),s=t.getComputedMargin(e);return i?n.width+s.left+s.right:n.height+s.top+s.bottom}function hi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Ch(e,t){var i;if(e)for(let n=e.lastChild,s=n;n!==t;n=s)s=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}function Wr(e){return!!e.getAttribute(xi)}function Vi(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Wr(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function ui(e){let t=e?.viewNode;return t?.nodeType===1&&Wr(t)}function Jp(e){return e!=="inline"&&(qt(e)||Sh(e))}function Qo(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))&&qt(i.display))return i;return null}var jr=class{calculateOffset(e){return mi(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mi(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var vn=class extends jr{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Gn(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=li(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,s=n?.closest("table, [style*='display: table;']");if(s){let r=s.style.borderCollapse==="collapse",o=0,a=0;for(let h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===s&&!r)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===s&&!r&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===s)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===s)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Yt.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Fi=class{find(e){let t=pt("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()}`)}},ci=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 vn(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var s;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Pt.ShadowType.ROOTLESS&&ui(i))return;let r=i.viewNode;((s=r.parentElement)==null?void 0:s.localName)==="viv-ts-inner"&&(r=r.parentElement.parentElement);let o=r.parentNode;Ch(o,r),n&&o.removeChild(r)}finishBreak(e,t,i,n){let s=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,s),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},Xr=class{constructor(e){this.parent=e,u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},qr=new ci,Qp=Zs.isInstanceOfBlockFormattingContext;ht("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,s,r)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&xh(i,n,s,r)?new Xr(o?o.formattingContext:null):null});ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Xr?qr:null);var Yr=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=F("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(s=>{let r=n.accept(s,t);r=n.postLayout(s,this.initialPosition,t,r),r?i.finish(s):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},ef=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){}},nr=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=F("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ve(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?r=t.afterIgnoredTextNode(i):r=t.startIgnoredTextNode(i):i.nodeContext.after?r=t.afterNonElementNode(i):r=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?r=t.afterInlineElementNode(i):r=t.startInlineElementNode(i):i.nodeContext.after?r=t.afterNonInlineElementNode(i):r=t.startNonInlineElementNode(i):i.nodeContext.after?r=t.afterNonDisplayableNode(i):r=t.startNonDisplayableNode(i);let o=(r&&r.isPending()?r:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?s.breakLoop():(i.nodeContext=a,s.continueLoop())});return}else if(i.break){s.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),s.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},Xi=class extends ef{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&Ke(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,s=!t.allowLayout(n);return s&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),s}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:N(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),N(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:N(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},sr=[];function tf(){sr=[]}function Eh(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var nf=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},sf=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},kh=class On{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=On.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){On.fragmentIndices={}}matches(){let t=On.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Eh(t.fragmentIndex,this.a,this.b)}};u(kh,"fragmentIndices",{});var ls=kh,Pn=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new ls(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new sf(e)}static buildAnyMatcher(e){return new nf(e)}},Nh={"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-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-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-position":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},rf=["image-resolution","orphans","widows"];function of(){return pt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(rf))}var af={"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},rr=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],lf=["max-%","min-%","%"],hf=(()=>{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<rr.length;i++)for(let n=0;n<e.length;n++){let s=rr[i].replace("%",e[n]);t[s]=!0}return t})();function hs(e,t){let i={};for(let n of rr)for(let s in e){let r=n.replace("%",s),o=n.replace("%",e[s]);i[r]=o,i[o]=r}for(let n of lf)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var Ph=hs({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Th=hs({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),uf=hs({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),cf=hs({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Z=class or{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new or(i,this.priority)}increaseSpecificity(t){return t==0?this:new or(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&Nt(i)?this.value:Zn(t,this.value,i,n,s)}isEnabled(t){return!0}},ar=class lr extends Z{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new Z(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new lr(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new lr(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){D.warn(i)}return!1}};function hr(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Tt(e,t,i,n){if(e)if(!i)delete e[t];else{let s=e[t];(!s||i.priority>=s.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Ih={"region-id":!0,"fragment-selector-id":!0};function df(e){return!!Ih[e]}function ur(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function wi(e){return e.charAt(0)!=="_"&&!Ih[e]}function qi(e){return!!Nh[e]||Nt(e)}function Ue(e,t){return e[t]}function Zt(e,t,i){i?e[t]=i:delete e[t]}function dt(e,t){return e[t]}function us(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Ah=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Rh(e,t){return e[t]}function Lh(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Yn(e,t,i,n,s,r,o){var a,h;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=us(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),o){let l=Ah(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!ur(l))if(df(l)){let c=Rh(i,l),p=Lh(t,l);Array.prototype.push.apply(p,c)}else{let c=Ue(i,l);if(!c.isEnabled(e))continue;let p=c.increaseSpecificity(n);Tt(t,l,p,e);let d=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(d)for(let f of d){let g=new Z(G,p.priority);Tt(t,f,g,e)}}}function pf(e,t){let i={};for(let n=0;n<t.length;n++)Yn(e,i,t[n],0,null,null,null);return i}function Fh(e,t){if(e.length>0){e.sort((n,s)=>s.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var ff=class extends Ei{constructor(e,t){super(),this.props=e,this.context=t,u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Ue(this.props,"font-size");if(!e.value.isNumeric())return we.em;let t=e.value;if(!$c(t.unit))throw new Error("Unexpected state");return t.num*we[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Oh(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="ex"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Zr(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Zn(this.context,e,this.propName).visit(this):e}};function Zr(e,t,i){let n=e.unit,s=e.num;if(n==="em"||n==="ex"){let r=we[n]/we.em;return new T(s*r*t,"px")}else return n==="rem"?new T(s*i.fontSize(),"px"):n==="rlh"?new T(s*i.rootLineHeight,"px"):e}function Oh(e,t,i){e=Zr(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new T(s/100*t,"px"):new T(s*i.queryUnitSize(n,!1),"px")}var Ii=class{apply(e){}mergeWith(e){return new gf([this,e])}clone(){return this}},Tn=class extends Ii{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},gf=class Bh extends Ii{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Bh([].concat(this.list))}},Kr=class extends Ii{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){Yn(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ge=class extends Ii{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},mf=class extends ge{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},wf=class extends ge{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},ea=class extends ge{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},bf=class extends ge{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},vf=class extends ge{constructor(e,t){super(),this.epubTypePatt=e,this.targetLocalName=t}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let s=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");s&&s.match(this.epubTypePatt)&&this.chained.apply(e)}}}},yf=class extends ge{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function cs(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let s of e.getAttributeNames())if((s===i||s.endsWith(`:${i}`))&&n(e,s===i?"":e.lookupNamespaceURI(s.split(":")[0]),i))return!0;return!1}var ta=class extends ge{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},xf=class extends ge{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},Sf=class extends ge{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>!!af[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Oi=class extends ge{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){cs(e.currentElement,this.ns,this.name,(t,i,n)=>{var s;return!!((s=t.getAttributeNS(i,n))!=null&&s.match(this.regexp))})&&this.chained.apply(e)}},Cf=class extends ge{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},ia=class extends ge{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Ef=class extends ge{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},yn=class extends ge{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Eh(e,this.a,this.b)}},kf=class extends yn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},cr=class extends yn{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}},dr=class extends yn{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}},pr=class extends yn{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,s=i.localName,r=t[n];r||(r=t[n]={}),r[s]=(r[s]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},Nf=class extends ge{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}},Pf=class extends ge{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Tf=class extends ge{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},If=class extends ge{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ge=class extends ge{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},Af=class _h extends Ii{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new _h;return t.applied=this.applied,t}},Jr=class extends ge{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new Af;for(let t of e)this.firstActions.push(Fh(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 ge?e.getPriority():0))}positive(){return!0}relational(){return!1}},Rf=class extends Jr{positive(){return!1}},Lf=class extends Jr{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},ds=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Ff=class Mh extends ds{constructor(t,i,n){super(t,i,n)}fresh(t){return new Mh(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}},Of=class zh extends ds{constructor(t,i,n){super(t,i,n)}fresh(t){return new zh(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)}},Bf=class Dh extends ds{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new Dh(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)}},_f=class Vh extends ds{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new Vh(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}},Mf=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},zf=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Df=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Vf=class extends Ei{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ct(e):new ct("about:invalid");case"string":default:return e?new Re(e):new Re("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof ye){let s=e.values[0].values;s.length>=2&&(t=s[1].stringValue()),i=s[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Yi(e){if(Vt(e)){if(e instanceof Re)return e.stringValue();if(e instanceof ye)return e.values.map(t=>Yi(t)).join("")}return""}var fr=class extends Ei{constructor(e,t,i){super(),this.cascade=e,this.element=t,this.counterResolver=i}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let s=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,s}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new Re("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Re("")}return e}format(e,t){let i=!1,n=!1,s;(s=t.match(/^upper-(.*)/))!=null?(i=!0,t=s[1]):(s=t.match(/^lower-(.*)/))!=null&&(n=!0,t=s[1]);let r="";return na[t]?r=Hf(na[t],e):sa[t]?r=Gf(sa[t],e):ra[t]!=null?r=ra[t]:t=="decimal-leading-zero"?(r=`${e}`,r.length==1&&(r=`0${r}`)):t=="cjk-ideographic"||t=="trad-chinese-informal"?r=jf(e,Wf):r=`${e}`,i?r.toUpperCase():n?r.toLowerCase():r}visitFuncCounter(e){let t=e[0].toString(),i=e.length>1?e[1].stringValue():"decimal",n=this.cascade.counters[t];if(n&&n.length){let s=n&&n.length&&n[n.length-1]||0;return new Re(this.format(s,i))}else{let s=new V(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new ye([s])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",s=this.cascade.counters[t],r=new kt;if(s&&s.length)for(let a=0;a<s.length;a++)a>0&&r.append(i),r.append(this.format(s[a],n));let o=new V(this.counterResolver.getPageCountersVal(t,a=>{let h=[];if(a.length)for(let c=0;c<a.length;c++)h.push(this.format(a[c],n));let l=r.toString();return l.length&&h.push(l),h.length?h.join(i):this.format(0,n)}));return new ye([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new V(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new ye([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e[2].stringValue(),r=e.length>3?e[3].stringValue():"decimal",o=new V(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,r));return h.length?h.join(s):this.format(0,r)}));return new ye([o])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,r,o;let a=e.length>0?e[0].stringValue():"text",h="";switch(a){case"text":h=this.element.textContent;break;case"before":case"after":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(i=(t=l?.[a])==null?void 0:t.content)==null?void 0:i.value;h=Yi(c)}break;case"first-letter":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(Yi((s=(n=l?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||Yi((o=(r=l?.after)==null?void 0:r.content)==null?void 0:o.value)).match(Bs);h=c?c[0]:""}break}return new Re(h)}visitFuncLeader(e){let t="";if(e[0]instanceof ft)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Re&&(t=e[0].stringValue());return t.length==0?new Re(""):new V(new De(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"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}},Uf=(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(de){if(S==="rtl"){let pe="\u200F";g.textContent=(de.startsWith(pe)?"":pe)+de+(de.endsWith(pe)?"":pe)}else g.textContent=de},c=function(){let de=i.clientLayout.getElementClientRect(m);return L.left>de.left||L.right<de.right||L.top>de.top||L.bottom<de.bottom},p=function(){let de,pe;if(l(b),c())de=1,pe=b.length/v.length;else{de=b.length/v.length,pe=de;for(let x=0;x<16;x++){let P=b;for(let C=0;C<1<<x;C++)P+=v;if(l(P),c()){pe+=1<<x;break}}}for(let x=0;x<16;x++){let P="",C=Math.floor((de+pe)/2);for(let E=0;E<C;E++)P+=v;if(l(P),c())pe=C;else{if(de==C)return;de=C}}l(v)},d=function(de){let pe=0,x=m.parentElement;for(;x&&x!==f.viewNode;)pe+=i.getComputedInsets(x)[de],x=x.parentElement;return pe};var s=l,r=c,o=p,a=d;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,v=g.getAttribute("data-viv-leader-value"),b=g.textContent||v,{writingMode:w,direction:S,marginInlineEnd:I}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(v),m.style.display="inline-block",m.style.textIndent="0";let L=i.clientLayout.getElementClientRect(f.viewNode),_=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(I);w==="vertical-rl"||w==="vertical-lr"?(S==="rtl"?L.top+=U:L.bottom-=U,L.left=_.left,L.right=_.right,L.top=Math.min(_.top,L.top),L.bottom=Math.max(_.bottom,L.bottom)):(S==="rtl"?L.left+=U:L.right-=U,L.top=_.top,L.bottom=_.bottom,L.left=Math.min(_.left,L.left),L.right=Math.max(_.right,L.right)),p();let W=i.clientLayout.getElementClientRect(m);S=="rtl"?m.style.float="left":m.style.float="right";let re=i.clientLayout.getElementClientRect(m),He=0;S=="rtl"?w=="vertical-rl"||w=="vertical-lr"?He=W.top-re.top-d("top"):He=W.left-re.left-d("left"):w=="vertical-rl"||w=="vertical-lr"?He=re.bottom-W.bottom-d("bottom"):He=re.right-W.right-d("right"),He=Math.max(0,He-.1),m.style.float="",g.style.marginInlineStart=`${He}px`}};ht("POST_LAYOUT_BLOCK",Uf);var na={roman:[4999,1e3,"M",900,"CM",500,"D",400,"CD",100,"C",90,"XC",50,"L",40,"XL",10,"X",9,"IX",5,"V",4,"IV",1,"I"],armenian:[9999,9e3,"\u0584",8e3,"\u0583",7e3,"\u0582",6e3,"\u0581",5e3,"\u0580",4e3,"\u057F",3e3,"\u057E",2e3,"\u057D",1e3,"\u057C",900,"\u057B",800,"\u057A",700,"\u0579",600,"\u0578",500,"\u0577",400,"\u0576",300,"\u0575",200,"\u0574",100,"\u0573",90,"\u0572",80,"\u0571",70,"\u0570",60,"\u056F",50,"\u056E",40,"\u056D",30,"\u056C",20,"\u056B",10,"\u056A",9,"\u0569",8,"\u0568",7,"\u0567",6,"\u0566",5,"\u0565",4,"\u0564",3,"\u0563",2,"\u0562",1,"\u0561"],georgian:[19999,1e4,"\u10F5",9e3,"\u10F0",8e3,"\u10EF",7e3,"\u10F4",6e3,"\u10EE",5e3,"\u10ED",4e3,"\u10EC",3e3,"\u10EB",2e3,"\u10EA",1e3,"\u10E9",900,"\u10E8",800,"\u10E7",700,"\u10E6",600,"\u10E5",500,"\u10E4",400,"\u10F3",300,"\u10E2",200,"\u10E1",100,"\u10E0",90,"\u10DF",80,"\u10DE",70,"\u10DD",60,"\u10F2",50,"\u10DC",40,"\u10DB",30,"\u10DA",20,"\u10D9",10,"\u10D8",9,"\u10D7",8,"\u10F1",7,"\u10D6",6,"\u10D5",5,"\u10D4",4,"\u10D3",3,"\u10D2",2,"\u10D1",1,"\u10D0"],hebrew:[999,400,"\u05EA",300,"\u05E9",200,"\u05E8",100,"\u05E7",90,"\u05E6",80,"\u05E4",70,"\u05E2",60,"\u05E1",50,"\u05E0",40,"\u05DE",30,"\u05DC",20,"\u05DB",19,"\u05D9\u05D8",18,"\u05D9\u05D7",17,"\u05D9\u05D6",16,"\u05D8\u05D6",15,"\u05D8\u05D5",10,"\u05D9",9,"\u05D8",8,"\u05D7",7,"\u05D6",6,"\u05D5",5,"\u05D4",4,"\u05D3",3,"\u05D2",2,"\u05D1",1,"\u05D0"]},sa={latin:"a-z",alpha:"a-z",greek:"\u03B1-\u03C1\u03C3-\u03C9",russian:"\u0430-\u0438\u043A-\u0449\u044D-\u044F"},ra={square:"\u25A0",disc:"\u2022",circle:"\u25E6",none:""};function Hf(e,t){let i=e[0];if(t>i||t<=0||t!=Math.round(t))return"";let n="";for(let s=1;s<e.length;s+=2){let r=e[s],o=Math.floor(t/r);if(o>20)return"";for(t-=o*r;o>0;)n+=e[s+1],o--}return n}function $f(e){let t=[],i=0;for(;i<e.length;)if(e.substr(i+1,1)=="-"){let n=e.charCodeAt(i),s=e.charCodeAt(i+2);i+=3;for(let r=n;r<=s;r++)t.push(String.fromCharCode(r))}else t.push(e.substr(i++,1));return t}function Gf(e,t){if(t<=0||t!=Math.round(t))return"";let i=$f(e),n="";do{t--;let s=t%i.length;n=i[s]+n,t=(t-s)/i.length}while(t>0);return n}var Wf={formal:!1,digits:"\u96F6\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D",markers:"\u5341\u767E\u5343",negative:"\u8CA0"};function jf(e,t){if(e>9999||e<-9999)return`${e}`;if(e==0)return t.digits.charAt(0);let i=new kt;if(e<0&&(i.append(t.negative),e=-e),e<10)i.append(t.digits.charAt(e));else if(!t.formal&&e<=19)i.append(t.markers.charAt(0)),e!=0&&i.append(t.digits.charAt(e-10));else{let n=Math.floor(e/1e3);n&&(i.append(t.digits.charAt(n)),i.append(t.markers.charAt(2)));let s=Math.floor(e/100)%10;s&&(i.append(t.digits.charAt(s)),i.append(t.markers.charAt(1)));let r=Math.floor(e/10)%10;r&&(i.append(t.digits.charAt(r)),i.append(t.markers.charAt(0)));let o=e%10;o&&i.append(t.digits.charAt(o))}return i.toString()}var Qr=1/1048576;function ni(e,t){for(let i in e)t[i]=e[i].clone()}var Xf=class Uh{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 Uh;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return ni(this.tags,t.tags),ni(this.nstags,t.nstags),ni(this.epubtypes,t.epubtypes),ni(this.classes,t.classes),ni(this.ids,t.ids),ni(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let s=t[i];s&&(n=s.mergeWith(n)),t[i]=n}createInstance(t,i,n,s){return new qf(this,t,i,n,s)}nextOrder(){return this.order+=Qr}},qf=class{constructor(e,t,i,n,s){this.context=t,this.counterListener=i,this.counterResolver=n,u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",{}),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",{}),u(this,"counterScoping",[{}]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",{}),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=e,this.quotes=[new Re("\u201C"),new Re("\u201D"),new Re("\u2018"),new Re("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(e){this.stack[this.stack.length-1].push(e)}increment(e,t){this.conditions[e]=(this.conditions[e]||0)+1,t&&(this.viewConditions[e]?this.viewConditions[e].push(t):this.viewConditions[e]=[t])}decrement(e,t){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(i=>i!==t),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let t=null;e&&(this.currentElementOffset,t=Pn.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let s=this.viewConditions[n];return s&&s.length>0?s.length===1?s[0]:Pn.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:Pn.buildAllMatcher(i):Pn.buildAllMatcher([t].concat(i))}applyAction(e,t){let i=e[t];i&&i.apply(this)}pushRule(e,t,i){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=i,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=e,this.currentNSTag="",this.currentEpubTypes=As,this.currentPageType=t,this.applyActions()}defineCounter(e,t){let i=this.counterScoping[this.counterScoping.length-1];i||(i={},this.counterScoping[this.counterScoping.length-1]=i),this.counters[e]?(i[e]&&this.counters[e].pop(),this.counters[e].push(t)):this.counters[e]=[t],i[e]=!0}pushCounters(e){var t,i,n,s,r,o,a;let h=y.inline,l=e.display;if(l&&(h=l.evaluate(this.context)),h===y.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.counterScoping.push(null);return}let c=y.inline,p=e.float;p&&(c=p.evaluate(this.context));let d=null,f=null,g=null,m=e["counter-reset"];if(m){let w=m.evaluate(this.context);w&&(d=Wi(w,!0))}let v=e["counter-set"];if(v){let w=v.evaluate(this.context);w&&(g=Wi(w,!1))}let b=e["counter-increment"];if(b){let w=b.evaluate(this.context);w&&(f=Wi(w,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(d||(d={}),d["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),h===y.list_item&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((r=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?r:"")&&(g||(g={}),g["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(d||(d={}),d.footnote===void 0&&(d.footnote=0)),c===y.footnote&&(f||(f={}),f.footnote===void 0)){let w=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!w||!(w===y.footnote||w instanceof ye&&w.values.includes(y.footnote)))&&(f.footnote=1)}if(d)for(let w in d)this.defineCounter(w,d[w]);if(f)for(let w in f){this.counters[w]||this.defineCounter(w,0);let S=this.counters[w];S[S.length-1]+=f[w]}if(g)for(let w in g)if(!this.counters[w])this.defineCounter(w,g[w]);else{let S=this.counters[w];S[S.length-1]=g[w]}if(h===y.list_item){let w=this.counters["list-item"],S=w[w.length-1];e["ua-list-item-count"]=new Z(new Ut(S),0)}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let t in e){let i=this.counters[t];i&&(i.length==1?delete this.counters[t]:i.pop())}}setNamedStrings(e){let t=e["string-set"];if(!t)return;t=t.filterValue(new fr(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof ye){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>Yi(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof ki&&t.value.name==="running"){let i=t.value.values[0].stringValue();this.counterResolver.setRunningElement(i,this.currentElementOffset)}}processPseudoelementProps(e,t){this.pushCounters(e);let i=e.content;i&&(e.content=i.filterValue(new fr(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let a=t.getAttribute("class");a?this.currentClassNames=a.split(/\s+/):this.currentClassNames=As;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=As;let l=_s(t);l&&(this.stack[this.stack.length-1].push(new zf(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let d=this.siblingTypeCountsStack,f=this.currentSiblingTypeCounts=d[d.length-1],g=f[this.currentNamespace];g||(g=f[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,d.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let v=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=v[v.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,v.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let w=i.quotes,S=null;if(w){let _=w.evaluate(this.context);_&&(S=new Df(this.quotes),_===y.none?this.quotes=[new Re(""),new Re("")]:_===y.auto||_===y.initial?this.quotes=[new Re("\u201C"),new Re("\u201D"),new Re("\u2018"),new Re("\u2019")]:_ instanceof ye&&(this.quotes=_.values))}this.pushCounters(this.currentStyle);let I=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(c||I){let _={};Object.keys(this.counters).forEach(U=>{_[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(I,_)}let L=dt(this.currentStyle,"_pseudos");if(L){let _=!0;for(let U of Yf){U||(_=!1);let W=L[U];W&&((U==="before"||U==="after")&&!Vt((s=W.content)==null?void 0:s.value)||(U==="footnote-call"||U==="footnote-marker")&&((r=Ue(this.currentStyle,"float"))==null?void 0:r.value)!==y.footnote?delete L[U]:_?this.processPseudoelementProps(W,t):this.stack[this.stack.length-2].push(new Mf(W,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}applyAttrFilterInner(e,t){for(let i in t)wi(i)&&!Nt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Vf(e),i=this.currentStyle,n=dt(i,"_pseudos");for(let s in n)this.applyAttrFilterInner(t,n[s]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,s,r;let o=e[0],a=new sg(e,t,i),h=32,l={};for(let c in o)if(ur(c)){let p=dt(o,c);for(let d in p)this.applyVarFilter([p[d],...e],t,i)}else if(wi(c)){let p=Ue(o,c),d=p.value;for(let f=0;;f++){if(f>=h){d=G;break}let g=d.visit(a);if(a.error){d=G,a.error=!1;break}if(g===d)break;d=g}if(d!==p.value){let f=t.validatorSet,g=(n=f?.shorthands[c])==null?void 0:n.clone();if(g)if(J(d)){for(let m of g.propList){let v=new Z(d,p.priority),b=Ue(o,m);Zt(l,m,hr(this.context,b,v))}delete o[c]}else{let m=Ti(t.scope,new gt(d.toString(),null),"");if(m&&(m.visit(g),!g.error)){for(let v of g.propList){let b=new Z((r=(s=g.values[v])!=null?s:f.defaultValues[v])!=null?r:y.initial,p.priority),w=Ue(o,v);Zt(l,v,hr(this.context,w,b))}delete o[c]}}else o[c]=new Z(d,p.priority)}if(l[c]){let f=Ue(o,c);f&&f.value!==G&&Tt(l,c,f,this.context)}}for(let c in l)o[c]=l[c]}applyCalcFilter(e,t){let i=new Yh(t);for(let n in e)if(ur(n)){let s=dt(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(wi(n)&&!Nt(n)){let s=Ue(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new Z(r,s.priority))}}applyActions(){let e;for(e=0;e<this.currentClassNames.length;e++)this.applyAction(this.code.classes,this.currentClassNames[e]);for(e=0;e<this.currentEpubTypes.length;e++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[e]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2];for(e=0;e<i.length;)i[e].push(this,t)?i.splice(e,1):e++}this.isFirst=!0,this.isRoot=!1}pop(){for(let e=1;e>=-1;--e){let t=this.stack[this.stack.length-e-2],i=0;for(;i<t.length;)t[i].pop(this,e)?t.splice(i,1):i++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},As=[],Yf=["before","transclusion-before","footnote-call","footnote-marker","inner","first-letter","first-line","","transclusion-after","after"],gr=null;function Zf(e){gr=e}var rn=class extends wn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:gr?gr.clone():new Xf,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Fh(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||(t&&(this.specificity+=1),t&&e?this.chain.push(new bf(e,t.toLowerCase())):t?this.chain.push(new ea(t.toLowerCase())):this.chain.push(new yf(e)))}invalidSelector(e){D.warn(e),this.chain.push(new Ge("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof on;e=e.parent)e.parent.invalid=!0}classSelector(e){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by .${e}`);return}this.specificity+=256,this.chain.push(new mf(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Pf);break;case"disabled":this.chain.push(new Tf);break;case"checked":this.chain.push(new If);break;case"root":case"scope":this.chain.push(new Ef);break;case"link":this.chain.push(new ea("a")),this.chain.push(new ta("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${At(i)}($|\\s)`),s=t[1];this.chain.push(new vf(n,s))}else this.chain.push(new Ge(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ge(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Cf(new RegExp(`^${At(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ge(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Kf[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ge(""));break}case"first-child":this.chain.push(new ia);break;case"last-child":this.chain.push(new dr(0,1));break;case"first-of-type":this.chain.push(new cr(0,1));break;case"last-of-type":this.chain.push(new pr(0,1));break;case"only-child":this.chain.push(new ia),this.chain.push(new dr(0,1));break;case"only-of-type":this.chain.push(new cr(0,1)),this.chain.push(new pr(0,1));break;case"empty":this.chain.push(new Nf);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,t){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ge(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ge(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new wf(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new ta(e,t);break;case 39:s=new xf(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ge(""):s=new Oi(e,t,new RegExp(`(^|\\s)${At(n)}($|\\s)`));break;case 44:s=new Oi(e,t,new RegExp(`^${At(n)}($|-)`));break;case 43:n?s=new Oi(e,t,new RegExp(`^${At(n)}`)):s=new Ge("");break;case 42:n?s=new Oi(e,t,new RegExp(`${At(n)}$`)):s=new Ge("");break;case 46:n?s=new Oi(e,t,new RegExp(At(n))):s=new Ge("");break;case 50:if(n=="supported")s=new Sf(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){let e=`d${In++}`;this.processChain(new Tn(new Ff(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}childSelector(){let e=`c${In++}`;this.processChain(new Tn(new Of(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${In++}`;this.processChain(new Tn(new Bf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${In++}`;this.processChain(new Tn(new _f(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new Kr(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ar(t,0,this.condition):i=new Z(t,0),Lh(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 ye([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),pt("SIMPLE_PROPERTY").forEach(r=>{let o=r({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),s=this.condition?new ar(t,n,this.condition):new Z(t,n);Tt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new on(this);break;case"not":t=new Jf(this);break;case"where":t=new Qf(this);break;case"has":t=new eg(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},Kf={"nth-child":kf,"nth-of-type":cr,"nth-last-child":dr,"nth-last-of-type":pr},In=0,on=class Hh extends rn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(this,"selectorTexts",[]),this.parentChain=t.chain}nextSelector(){this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Lf(this.selectorTexts):this.positive()?new Jr(this.chains):new Rf(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ge("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let s=this;s instanceof Hh;s=s.parent)if(s.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Jf=class extends on{positive(){return!1}forgiving(){return!1}},Qf=class extends on{increasingSpecificity(){return!1}},eg=class extends on{relational(){return!0}},tg=class extends wn{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",s=new Qt(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},An=class extends wn{constructor(e,t,i,n,s,r){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=s,this.ruleType=r,u(this,"order"),this.order=0}property(e,t,i){i?D.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Qr;let s=this.condition?new ar(t,n,this.condition):new Z(t,n);Tt(this.elementStyle,e,s)}},ig=class extends Jl{constructor(e,t){super(e),this.validatorSet=t,u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Kl:Zl;n+=this.order,this.order+=Qr;let s=new Z(t,n);Tt(this.elementStyle,e,s)}};function $h(e,t){let i=Ah(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function mr(e,t,i){$h(i,n=>{Zi(e,n,t)})}function ng(e,t,i,n){let s=new ig(e,t),r=new gt(n,s);try{dp(r,s,i)}catch(o){D.warn(o,"Style attribute parse error:")}return s.elementStyle}function Gh(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.vertical_rl}return i}function Wh(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.rtl}return i}function jh(e,t,i,n,s){let r={};for(let o in e)wi(o)&&(r[o]=Ue(e,o));return mr(r,t,e),Xh(e,i,n,(o,a)=>{Zi(r,a,t),mr(r,t,a)}),r}function Xh(e,t,i,n){let s=dt(e,"_regions");if((t||i)&&s){if(i){let r=["footnote"];t?t=t.concat(r):t=r}for(let r of t){let o=s[r];o&&n(r,o)}}}function Zi(e,t,i){for(let n in t)if(wi(n)){let s=Ue(t,n),r=e[n];e[n]=hr(i,r,s)}}var qh=(e,t,i,n,s)=>{let r=i?n?uf:Ph:n?cf:Th;for(let o in e)if(e.hasOwnProperty(o)){let a=e[o];if(!a)continue;let h=r[o],l;if(h){let c=e[h];if(c&&c.priority>a.priority)continue;l=hf[h]?h:o}else l=o;t[l]=s(o,a)}},sg=class extends Ei{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,s,r;let o=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(r=(s=this.styler.getStyle(o,!1))==null?void 0:s[e])==null?void 0:r.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof ft&&e.values[0].name;return!t||!Nt(t)?(this.error=!0,G):this.getVarValue(t)||(e.values.length<2?(this.error=!0,G):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},Yh=class extends Ei{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=Ti(this.context.rootScope,new gt(i,null),"");if(n instanceof V)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&!isNaN(s)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new T(s,"px"):/\d[a-z]/i.test(i)||(t=new Ut(s)))}catch(s){D.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(ul(e.unit)||Wc(e.unit))?new T(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new T(e.num*this.percentRef/100,"px"):e}};function Zn(e,t,i,n,s){try{if(t instanceof V)return t.expr instanceof De&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:mp(e,t.expr,i);if(t instanceof T||t instanceof ki||t instanceof ye||t instanceof qe)return t.visit(new Yh(e,!0,n,s))}catch(r){return D.warn(r),G}return t}var oa={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function aa(e){let t=e instanceof $e?e:typeof e=="string"?B(e):y.none;if(t===y.none)return oa;let i=t instanceof ye?t.values:[t],n=Object.create(oa);for(let s of i)if(s instanceof ft)switch(s.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function la(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var rg={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},ha={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},ua={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function ca(e){let t=e instanceof $e?e:typeof e=="string"?B(e):y.normal;if(t===y.normal)return ha;if(t===y.auto)return ua;let i=t instanceof ye?t.values:[t],n=Object.create(ha);for(let s of i)if(s instanceof ft)switch(s.name){case"trim-both":case"trim-auto":return ua;case"space-all":return rg;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 Rs={ideographAlpha:!1,ideographNumeric:!1},og={ideographAlpha:!0,ideographNumeric:!0};function da(e){let t=e instanceof $e?e:typeof e=="string"?B(e):y.normal;if(t===y.normal||t===y.auto)return og;if(t===y.none)return Rs;let i=t instanceof ye?t.values:[t],n=Object.create(Rs);for(let s of i)if(s instanceof ft)switch(s.name){case"no-autospace":return Rs;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function pa(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function fa(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 ag=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let s=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(s.length>1){let r=s.length-1;for(let o=0;o<r;o++)n.parentNode.insertBefore(document.createTextNode(s[o]),n);n.textContent=s[r]}}}processGeneratedContent(e,t,i,n,s,r){s=fa(s);let o=da(t),a=ca(i),h=aa(n);if(la(h)&&pa(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(r?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),p=null,d=null;for(let f=c.nextNode();f;f=d){d=c.nextNode();let g=!p,m=!p||/\n$/.test(p.textContent),v=!d||/^\n/.test(d.textContent),b=!d;this.processTextSpacing(f,g||m,g,m,v,b,p,d,o,a,h,s,r),p=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,s,r,o,a,h;let l=!e||e.fragmentIndex===1&&d(),c=l||f();function p(b){var w;if(b?.nodeType!==1)return!1;let S=b;if(S.hasAttribute(xi))return!0;let{position:I,float:L}=(w=S.style)!=null?w:{};return I==="absolute"||I==="fixed"||L&&L!=="none"}function d(){let b=t[0];for(let w=b;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let w=b.viewNode.previousSibling;w;w=w.previousSibling)if(!Ve(w,b.whitespace)&&!p(w))return!1;return!0}function f(){var b,w;let S=t[0],I;for(;S&&S.inline&&(I=(b=S.viewNode)==null?void 0:b.previousSibling,!(I&&(I.nodeType===3&&/^[ \t\r\n\f]*$/.test(I.textContent)&&S.whitespace!==Je.PRESERVE&&(I=I.previousSibling),I)));)S=S.parent;for(;I;){if(I.nodeType===1){if(I.localName==="br")return!0;let L=(w=I.style)==null?void 0:w.display;if(L&&L!=="inline")return!/^(inline|ruby)\b/.test(L)}else if(I.nodeType===3){if(S.whitespace===Je.PRESERVE){if(/\n$/.test(I.textContent))return!0}else if(S.whitespace===Je.NEWLINE&&/\n[ \t\r\n\f]*$/.test(I.textContent))return!0}I=I.lastChild}return!1}let g=-1;for(let b=0;b<t.length;b++){let w=t[b];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ve(w.viewNode,w.whitespace)){let S=function(E){var R,A,O;if(((R=E.viewNode)==null?void 0:R.nodeType)===1)return E.viewNode.localName==="br";if(((A=E.viewNode)==null?void 0:A.nodeType)===3){if(E.whitespace===Je.PRESERVE){if(/\n$/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Je.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.previousElementSibling)==null?void 0:O.localName)==="br")return Ve(E.viewNode,E.whitespace)}return!1},I=function(E){var R,A,O;if(((R=E.viewNode)==null?void 0:R.nodeType)===1)return E.viewNode.localName==="br";if(((A=E.viewNode)==null?void 0:A.nodeType)===3){if(E.whitespace===Je.PRESERVE){if(/^\n/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Je.NEWLINE&&/^[ \t\r\n\f]*\n/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.nextElementSibling)==null?void 0:O.localName)==="br")return Ve(E.viewNode,E.whitespace)}return!1};var m=S,v=I;let L=fa((r=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),_=da(w.inheritedProps["text-autospace"]),U=ca(w.inheritedProps["text-spacing-trim"]),W=aa(w.inheritedProps["hanging-punctuation"]);if(la(W)&&pa(_,U)||/\b(flex|grid)\b/.test(w.parent.display))continue;g<0&&(g=b);let re=null,He=null,de=b===g,pe=b===g&&l,x=b===g&&c,P=!1,C=!1;for(let E=b-1;E>=0;E--){let R=t[E];if(S(R)){x=!0;break}if(!R.display&&R.viewNode.nodeType===Node.TEXT_NODE&&R.viewNode.textContent.length>0){re=R.viewNode;break}if(R.display&&!/^(inline|ruby)\b/.test(R.display)||((o=R.viewNode)==null?void 0:o.nodeType)===1&&(R.viewNode.localName==="br"||Xt[R.viewNode.localName]))break;E===0&&(de=!0,l&&(pe=!0,x=!0))}for(let E=b+1;E<t.length;E++){let R=t[E];if(I(R)){P=!0;break}if(R.viewNode!==w.viewNode&&!R.display&&R.viewNode.nodeType===Node.TEXT_NODE&&R.viewNode.textContent.length>0){He=R.viewNode;break}if(R.display&&!/^(inline|ruby)\b/.test(R.display)||((a=R.viewNode)==null?void 0:a.nodeType)===1&&(R.viewNode.localName==="br"||Xt[R.viewNode.localName])){E===t.length-1&&p(R.viewNode)&&(C=!0);break}if(E===t.length-1){P=!0,C=!0;for(let A=R.viewNode.nextSibling;A;A=A.nextSibling)if(!p(A)){C=!1;break}}}if(((h=w.parent)==null?void 0:h.display)==="inline-block"){if(!pe){let E=w.parent.viewNode.firstChild;for(;Ve(E,w.whitespace);)E=E.nextSibling;w.viewNode===E&&(pe=!0)}if(!C){let E=w.parent.viewNode.lastChild;for(;Ve(E,w.whitespace);)E=E.previousSibling;w.viewNode===E&&(C=!0)}}this.processTextSpacing(w.viewNode,de,pe,x,P,C,re,He,_,U,W,L,w.vertical)}}}processTextSpacing(e,t,i,n,s,r,o,a,h,l,c,p,d){let f=e.textContent,g=e.ownerDocument,m,v,b;function w(){if(t)return!0;if(!o)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];v||(v=g.createRange(),v.selectNode(o));let C=v.getClientRects(),E=C[C.length-1];return!P||!E?!1:d?P.top<E.top+E.height-P.width||P.left+P.width<E.left+P.width/10||P.left>E.left+E.width-P.width/10:P.left<E.left+E.width-P.height||P.top>E.top+E.height-P.height/10||P.top+P.height<E.top+P.height/10}function S(){if(!a)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];b||(b=g.createRange(),b.selectNode(a));let C=b.getClientRects()[0];return!P||!C?!1:d?P.top+P.height>C.top+P.width||P.left>C.left+C.width-P.width/10||P.left+P.width<C.left+P.width/10:P.left+P.width>C.left+P.height||P.top+P.height<C.top+P.height/10||P.top>C.top+C.height-P.height/10}let I=!1,L=!1,_=!1,U=!1,W;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(W="viv-ts-open",I=!0,L=!0):r&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(W="viv-ts-close",I=!0,_=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(W="viv-ts-close",I=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(W="viv-ts-open",I=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||p==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||p!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(W="viv-ts-close",I=!0),I){let P=function(O){let z=parseFloat(g.defaultView.getComputedStyle(O).fontSize)*.7;return(d?O.offsetHeight:O.offsetWidth)>z},C=function(){return d?E.offsetLeft:E.offsetTop};var re=P,He=C;if(e.parentElement.localName==="viv-ts-inner")return;let E=g.createElement(W),R=g.createElement("viv-ts-inner");E.appendChild(R),e.parentNode.insertBefore(E,e),R.appendChild(e);let A=P(R);if(A||L||_||U){if(W==="viv-ts-open"){if(L)E.className="viv-hang-first";else if(i||n)l.trimStart?E.className="viv-ts-trim":E.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&w())E.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&P(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let O=C();E.className="viv-ts-auto",O===C()&&!w()&&(E.className="viv-ts-trim")}}else if(W==="viv-ts-close"){if(_)E.className=A?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let O=C();U?(E.className=A?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&O===C()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",O===C()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",O===C()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))A&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let O=S(),z=O&&c.allowEnd;z||(E.className=A?"viv-hang-end":"viv-hang-end viv-hang-hw"),A?z&&l.trimEnd?E.className="viv-ts-auto":!z&&!S()?E.className="":!O&&c.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):(E.className="viv-ts-space",S()||(l.allowEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!O&&!S()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let O=C();E.className="viv-ts-auto",O===C()&&(E.className="")}}}}let de=!1;function pe(P){var C;let E=(C=P?.ownerDocument.defaultView)==null?void 0:C.getComputedStyle(P);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function x(P,C){if(P.nodeType===1){let A=g.defaultView.getComputedStyle(P);if(parseFloat(A.marginInlineEnd)||parseFloat(A.borderInlineEndWidth)||parseFloat(A.paddingInlineEnd))return!0}let E=P.parentElement;if(E&&!E.contains(C))return x(E,C);if(C.nodeType===1){let A=g.defaultView.getComputedStyle(C);if(parseFloat(A.marginInlineStart)||parseFloat(A.borderInlineStartWidth)||parseFloat(A.paddingInlineStart))return!0}let R=C.parentElement;return R&&!R.contains(P)?x(P,R):!1}(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(d&&pe(o.parentElement))&&!x(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),de=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(d&&pe(a.parentElement))&&!x(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),de=!0))}registerHooks(){ht("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),ht("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),ht("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},eo=new ag;eo.registerHooks();function lg(e){eo.preprocessForTextSpacing(e)}function hg(e,t,i,n,s,r){eo.processGeneratedContent(e,t,i,n,s,r)}var Bn=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),ug=["footnote-marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],to="data-adapt-pseudo";function di(e){return e.getAttribute(to)||""}function wr(e,t){e.setAttribute(to,t)}var ga=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,u(this,"contentProcessed",{})}getStyle(e,t){let i=di(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=dt(this.style,"_pseudos")[i]||{};if(i.match(/^first-/)&&!n["x-first-pseudo"]){let s=1,r;i=="first-letter"?s=0:(r=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=r[1]-0),n["x-first-pseudo"]=new Z(new ei(s),0)}return n}processContent(e,t,i){let n=di(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let s=t.content;s&&Vt(s)&&(s.visit(new qn(e,this.context,s,this.exprContentListener)),lg(e))}}},qw=Wn.isInstanceOfAfterIfContinuesLayoutConstraint,cg=ls.registerFragmentIndex,Yw=ls.clearFragmentIndices,dg=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new io(e,i,t),s=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=s;let r=i.firstChild;return k(r,"display","block"),N(r)})}createNodePositionForPseudoElement(){let e=Bn.createElementNS("http://www.w3.org/1999/xhtml","div");wr(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new Dt(i)}createShadowContext(e){return new Js(this.sourceNode,e,null,null,null,Pt.ShadowType.ROOTED,this.styler)}},pg=class Zh{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,u(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,s){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),N(!0))):N(!0)}getRepetitiveElements(){return new fg(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Zh?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},fg=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function Kh(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return N(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=mg(e,t,n);return t.fragmentLayoutConstraints.push(new pg(e,i,s)),N(e)})}function Jh(e,t){return e.thenAsync(i=>Kh(i,t))}function gg(e,t){let i=F("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=Kh(n,t);return n=n.parent,s.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function mg(e,t,i){let n=e.viewNode;n.appendChild(i);let s=ir(i,t,e.vertical);return n.removeChild(i),s}var wg=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},_n=class extends jr{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,u(this,"alreadyEvaluated",!1),u(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Kn=class extends mh{constructor(e,t,i,n,s){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=s,u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"breakAtTheEdgeBeforeFloat",null),this.last=e.lastChild,this.viewDocument=e.ownerDocument,s.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}isOverflown(e){return this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=F("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,s=null;return t.loop(()=>{for(;n>=0;){let r=s,o=i[n];if(s=Xn(o,r),n===i.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),n==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),s.after=e.after,s.preprocessedTextContent=e.preprocessedTextContent,s.after))break;let a=this.layoutContext.setCurrent(s,n==0&&s.offsetInNode==0);if(n--,a.isPending())return a}return N(!1)}).then(()=>{t.finish(s)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Pp(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 s=e.viewNode.textContent,r=s.match(Bs),o=r?r[0].length:0;if(!r&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&s===e.sourceNode.textContent){let a=s+e.sourceNode.nextSibling.textContent,h=a.match(Bs);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return N(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=F("buildViewToNextBlockEdge");return n.loopWithFrame(s=>{var r;e.viewNode&&!ui(e)&&((r=e.viewNode.parentElement)==null?void 0:r.namespaceURI)==="http://www.w3.org/1999/xhtml"&&t.push(e.copy()),this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,ui(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){s.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(gi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){s.breakLoop();return}s.continueLoop()}):e.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return Jh(i,this)}buildDeepElementView(e){if(!e.viewNode)return N(e);let t=[],i=e.sourceNode,n=F("buildDeepElementView");return n.loopWithFrame(s=>{e.viewNode&&e.inline&&!ui(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(r=>{let o=r;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,s.breakLoop();return}ui(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{e=a,!e||e.sourceNode==i?s.breakLoop():this.layoutConstraint.allowLayout(e)?s.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let s=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),k(s,"height",`${i}px`),k(s,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),k(s,"width",`${i}px`),k(s,"height",`${n}px`)),k(s,"float",t),k(s,"clear",t),this.element.insertBefore(s,e),s}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(),s=null;for(let r of t){let o=r.y2-r.y1;r.left=this.createFloat(e,"left",r.x1-i,o),r.right=this.createFloat(e,"right",n-r.x2,o),r.x1<n&&r.x2>i?s=r:s||k(r.right,"float","none")}if(s){let r=t[t.length-1],o=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==r&&r.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(e,t,i,n){let s;if(e&&hi(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(s=li(e,this.clientLayout,0,this.vertical),!isNaN(s)))return s;e=t[i];let r=n-e.boxOffset;for(;;){if(s=li(e,this.clientLayout,r,this.vertical),!isNaN(s))return s;if(r>0){r--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(r=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 Cs(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 Cs(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 Cs(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=F("layoutFloat"),i=e.viewNode,n=Yo(e.floatSide,e.vertical,e.direction);return k(i,"float","none"),k(i,"display","inline-block"),k(i,"vertical-align","top"),this.buildDeepElementView(e).then(s=>{let r=this.clientLayout.getElementClientRect(i),o=this.getComputedMargin(i),a=new st(r.left-o.left,r.top-o.top,r.right+o.right,r.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let S=c.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),c.viewNode.appendChild(S);let I=this.clientLayout.getElementClientRect(S);h=Math.max(this.rtl?this.getEndEdge(I):this.getStartEdge(I),h),l=Math.min(this.rtl?this.getStartEdge(I):this.getEndEdge(I),l),c.viewNode.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!==e.parent&&!e.firstPseudo&&(c.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new st(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),d=a;this.vertical&&(d=Hn(a));let f=this.getBoxDir();if(d.y1<this.bottommostFloatTop*f){let S=d.y2-d.y1;d.y1=this.bottommostFloatTop*f,d.y2=d.y1+S}gd(p,this.bands,d,n),this.vertical&&(a=Ll(d));let g=this.getComputedInsets(i);k(i,"width",`${a.x2-a.x1-g.left-g.right}px`),k(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),k(i,"position","absolute"),e.display,k(i,"display",e.display);let m,v=null;if(c&&(c.containingBlockForAbsolute?v=c:v=c.getContainingBlockForAbsolute()),v){let S=v.viewNode.ownerDocument.createElement("div");S.style.position="absolute",v.vertical?S.style.right="0":S.style.left="0",S.style.top="0",v.viewNode.appendChild(S),m=this.clientLayout.getElementClientRect(S),v.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(v?v.vertical:this.vertical)?k(i,"right",`${m.right-a.x2}px`):k(i,"left",`${a.x1-m.left}px`),k(i,"top",`${a.y1-m.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,w=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),p=new st(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Hn(p)),md(p,this.bands,d,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(b),t.finish(s)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,s,r){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),s.adjustPageFloatArea(e,a,this),e.init();let c=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),r);return c?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),c}createPageFloatArea(e,t,i,n,s){let r=this.element.ownerDocument.createElement("div");k(r,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new Di(null,Ae.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),h=o.getContainer(),l=new yg(t,r,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,s)?l:null}layoutSinglePageFloatFragment(e,t,i,n,s,r,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c=this.createPageFloatArea(h,t,r,s,l),p={floatArea:c,pageFloatFragment:null,newPosition:null};if(!c)return N(p);let d=F("layoutSinglePageFloatFragment"),f=!1,g=0;return d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let v=e[g],b=new Dt(v.nodePosition);c.layout(b,!0).then(w=>{p.newPosition=w,!w||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){let m=a.setFloatAreaDimensions(c,h.floatReference,t,r,!1,n,l);if(!m)f=!0;else{let v=s.createPageFloatFragment(e,m,c,!!p.newPosition);a.addPageFloatFragment(v,!0),p.pageFloatFragment=v}}d.finish(p)}),d.result()}layoutPageFloatInner(e,t,i,n){let s=this.pageFloatLayoutContext,r=e.float;s.stashEndFloatFragments(r);function o(h,l){l?s.removePageFloatFragment(l,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(r.floatReference),s.deferPageFloat(e)}let a=F("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],r.floatSide,r.clearSide,!s.hasFloatFragments(),t,i,n).then(h=>{let l=h.floatArea,c=h.pageFloatFragment,p=h.newPosition;c?this.layoutStashedPageFloats(r.floatReference,[n]).then(d=>{if(d){if(s.addPageFloatFragment(c),s.discardStashedFragments(r.floatReference),p){let f=new Zo(r,p.primary);s.deferPageFloat(f)}a.finish(!0)}else o(l,c),a.finish(!1)}):(o(l,c),a.finish(!1))}),a.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),s=[],r=[],o=!1,a=F("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 p=new Si().findByFloat(c.continuations[0].float);this.layoutSinglePageFloatFragment(c.continuations,c.floatSide,null,!1,p,null).then(d=>{let f=d.floatArea;f&&s.push(f);let g=d.pageFloatFragment;g?(r.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(r.forEach(l=>{i.removePageFloatFragment(l,!0)}),s.forEach(l=>{let c=l.element;c&&c.parentNode&&c.parentNode.removeChild(c)})):n.forEach(l=>{let c=l.area.element;c&&c.parentNode&&c.parentNode.removeChild(c)}),a.finish(!o)}),a.result()}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");i.setAttribute(xi,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",i),t.appendChild(i),t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=F("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,r=s.getPageFloatLayoutContext(Ae.REGION);return s.getContainer().width<r.getContainer().width&&e===Ae.COLUMN?t===y.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Hr(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(Ae.REGION):n.finish(e)}):t===y.all?n.finish(Ae.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Si().findByNodeContext(e),n,s=t.findPageFloatByNodePosition(e.toNodePosition());return s?n=N(s):n=i.createPageFloat(e,t,this),n.thenAsync(r=>{let o=jn(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(r,t),l=new Zo(r,o);if(h&&h.hasFloat(r))return t.registerPageFloatAnchor(r,a.viewNode),N(a);if(t.isForbidden(r)||t.hasPrecedingFloatsDeferredToNext(r))return t.deferPageFloat(l),t.registerPageFloatAnchor(r,a.viewNode),N(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let c=li(a,this.clientLayout,0,this.vertical);return this.isOverflown(c)?N(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?N(null):(t.registerPageFloatAnchor(r,a.viewNode),N(a)))}})}processLineStyling(e,t,i){let n=F("processLineStyling"),s=i.concat([]);i.splice(0,i.length);let r=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(s),l=o.count-r;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(s,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{r+=l,this.layoutContext.peelOff(c,0).then(p=>{e=p,o=e.firstPseudo,s=[],this.buildViewToNextBlockEdge(e,s).then(d=>{t=d,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,s),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Xt[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let s=e[n];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let r=this.getComputedMargin(s.viewNode),o=this.vertical?-r.left:r.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=F("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let s=i.length-1;if(s<0){t.finish(n);return}this.postLayoutBlock(n,i);let r=this.calculateEdge(n,i,s,i[s].boxOffset),o=!1;if(!n||!hi(n.viewNode)){let h=mi(n,this.collectElementsOffset());o=this.isOverflown(r+(this.vertical?-1:1)*h.minimum),this.isOverflown(r+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(r+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(r);let a;e.firstPseudo?a=this.processLineStyling(e,n,i):a=N(n),a.then(h=>{i.length>0&&(this.saveBoxBreakPosition(i),o&&!this.isLoneImage(i)&&h&&(h=h.modify(),h.overflow=!0)),t.finish(h)})}),t.result()}postLayoutBlock(e,t){pt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,s=0,r=t[0].boxOffset,o=s,a=t.length-1,h=t[a].boxOffset,l;for(;r<h;){l=r+Math.ceil((h-r)/2),o=s;let c=a;for(;o<c;){let d=o+Math.ceil((c-o)/2);t[d].boxOffset>l?c=d-1:o=d}let p=this.calculateEdge(null,t,o,l);if(this.vertical?p<=n:p>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(p),r=l,s=o}return{nodeContext:t[o],index:r,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,s,r;let o=this.findEndOfLine(t,e,!0),a=o.nodeContext;if(o.checkPointIndex===0&&o.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,o.index,e,o.checkPointIndex,i)}else{let l=Qo(a);if(l){if(((s=this.breakPositions)==null?void 0:s[0])instanceof _n&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let c=(r=a.viewNode)==null?void 0:r.previousSibling;for(;c&&(Ve(c,a.parent.whitespace)||Vi(c));)c=c.previousSibling;if(c)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return pt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Jn.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),s=!1,r=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;r==t&&(t.nodeType===1?h=!(!t.firstChild||s):h=!1);let p=r.nodeType===1?r:null;p?s?s=!1:Wr(p)?l=!a:!p.firstChild||Xt[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Jp(this.clientLayout.getElementComputedStyle(p).display)?(l=!a,l?(p.localName==="ruby"&&r.firstChild&&(r=r.firstChild),n.setStartBefore(r),a=!0,o=r):/^r(uby|tc?)$/.test(p.localName)||(o=r),r.contains(t)&&(h=!1)):c=r.firstChild:(a||(r.parentNode==null?h=!1:(n.setStartBefore(r),a=!0)),o=r),c||(c=r.nextSibling,c||(s=!0,c=r.parentNode)),r=c}while(l&&h);if(a){n.setEndAfter(o);let c=this.clientLayout.getRangeClientRects(n);for(let p=0;p<c.length;p++)i.push(c[p]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?_p:Bp);let n=0,s=0,r=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(o>0){let p=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?c=h*(this.getAfterEdge(l)-n)/p:h*this.getAfterEdge(l)>h*s?c=h*(s-this.getBeforeEdge(l))/p:c=1}if(o==0||c>=.6||c>=.2&&this.getStartEdge(l)>=r-1){r=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),s=o==0?l.left:Math.min(s,l.left)):(n=o==0?l.top:Math.min(n,l.top),s=o==0?l.bottom:Math.max(s,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(s),o=0),a>=i.length)break}return t.sort(nl),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&_i(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=mi(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 s=e.checkPoints,r=s[0];for(;r.parent&&r.inline;)r=r.parent;let o,a;t?(o=1,a=1):(o=Math.max((r.inheritedProps.widows||2)-0,1),a=Math.max((r.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(r),l=this.findLinePositions(s),c=this.footnoteEdge-h,p=this.getBoxDir(),d=this.getOffsetByRepetitiveElements(e);c-=p*d;let f=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(f.edge)&&(f.edge=p*(1/0));let g=_t(l.length,w=>{let S=l[w];return this.vertical?S<c||S<=f.edge:S>c||S>=f.edge}),m=g<=0;m&&(g=_t(l.length,w=>this.vertical?l[w]<c:l[w]>c));let v=s[s.length-1].viewNode;if(v?.parentElement.localName==="viv-ts-inner"&&(v=v.parentElement.parentElement),(g===l.length&&v.nextSibling||g>=l.length-1&&v.parentElement.querySelector(".MJXc-display"))&&(o=0),g=Math.min(l.length-o,g),g<a)return null;c=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,c,t),b){let w=this.getAfterEdgeOfBlockContainer(b);!isNaN(w)&&p*(c-w)>0&&(c=w),this.computedBlockSize=p*(c-this.beforeEdge)+d}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,li(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 Fi().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=qr.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 s=this.breakPositions.length-1;s>=0&&!t;--s){e=this.breakPositions[s],t=e.findAcceptableBreak(this,i);let r=e.getMinBreakPenalty();r>i&&(n=Math.min(n,r))}}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 N(e);let s=F("doFinishBreak"),r=!1;if(!e){if(this.forceNonfitting)return D.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,r,!0).then(()=>{s.finish(o)})):s.finish(o)}),s.result();e=i,r=!0,this.computedBlockSize=n}return this.finishBreak(e,r,!0).then(()=>{s.finish(e)}),s.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(Vi(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}zeroIndent(e){let t=e.toString();return t==""||t=="auto"||!!t.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let r=e;r;r=r.parent)if(Vi(r.viewNode))return!1;if(hi(e.viewNode))return!1;let i=li(e,this.clientLayout,0,this.vertical),n=mi(e,this.collectElementsOffset()),s=this.isOverflown(i+(this.vertical?-1:1)*n.minimum);if(this.isOverflown(i+(this.vertical?-1:1)*n.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let r=i+this.getTrailingMarginEdgeAdjustment(t),o=this.footnoteEdge-this.getBoxDir()*n.current;i=this.vertical?Math.min(i,Math.max(r,o)):Math.max(i,Math.min(r,o))}return this.updateMaxReachedAfterEdge(i),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||hi(e.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(e,t);return(i||!s)&&this.saveEdgeBreakPosition(e,n,s),s}applyClearance(e){if(!e.viewNode.parentNode)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=this.clientLayout.getElementClientRect(i),s=this.getBeforeEdge(n),r=this.getBoxDir(),o=e.clearSide,a=-this.getBoxDir()*(1/0);switch(o==="all"&&(a=this.pageFloatLayoutContext.getPageFloatClearEdge(o,this)),/^(top|bottom|(block|inline)-(start|end))$/.test(o)?Yo(o,e.vertical,e.direction):o){case"left":a=r*Math.max(a*r,this.leftFloatEdge*r);break;case"right":a=r*Math.max(a*r,this.rightFloatEdge*r);break;default:a=r*Math.max(a*r,Math.max(this.rightFloatEdge*r,this.leftFloatEdge*r))}if(s*r>=a*r)return e.viewNode.parentNode.removeChild(i),!1;{let h=Math.max(1,(a-s)*r);this.vertical?i.style.width=`${h}px`:i.style.height=`${h}px`,n=this.clientLayout.getElementClientRect(i);let l=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let c=l+t.right-a;c>0==t.right>=0&&(c+=t.right),i.style.marginLeft=`${c}px`}else{let c=a-(l+t.top);c>0==t.top>=0&&(c+=t.top),i.style.marginBottom=`${c}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Qp(e)||Yt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,t,i){var n;let s=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(s&&!this.isBFC(s))return N(e);let r=F("skipEdges"),o=!i&&t&&e&&e.after,a=i,h=null,l=[],c=[],p=!1;function d(){return!!i||!t&&Ke(a)&&!f()}function f(){var m;if(!h||e.floatSide)return!1;for(let v=h;v!=null&&v.parent;v=v.parent){let b=v.after?v.viewNode:(m=v.viewNode)==null?void 0:m.previousSibling;for(;b&&(Ve(b,v.parent.whitespace)||Vi(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{e=l[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=a};return r.loopWithFrame(m=>{for(var v;e;){e.formattingContext;let b=new Fi().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace))break;if(!e.after){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)?(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=a),m.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Gn(a)?a:null),b&&b.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),a,!1),!e.inline&&!e.repeatOnBreak&&(h?Qo(h):this.breakPositions[this.breakPositions.length-1]instanceof _n)&&this.saveEdgeBreakPosition(e.copy(),a,!1),!this.isBFC(e.formattingContext)||Yt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ve(e.sourceNode.firstChild,e.whitespace)){l.push(e.copy()),a=Xe(a,e.breakBefore),d()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let S=e.viewNode.style;if(e.after){e.floatSide&&(a=a??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let I=e.sourceNode;if(I.localName==="svg"||I.localName==="math"||I.getAttribute("data-math-typeset")==="true"){p=!1,h=e.copy(),c.push(h),a=Xe(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a);break}if(e.inline||b&&b.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(d()){g(),m.breakLoop();return}l=[],t=!1,o=!1,a=null}p=!1,h=e.copy(),c.push(h),a=Xe(a,e.breakAfter),S&&!(this.zeroIndent(S.paddingBottom)&&this.zeroIndent(S.borderBottomWidth))&&(c=[h])}else{if(l.push(e.copy()),a=Xe(a,e.breakBefore),(e.pageType!=((v=e.parent)==null?void 0:v.pageType)||!Ke(a))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){m.breakLoop();return}let I=e.viewNode.localName;if(Xt[I]){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}S&&!(this.zeroIndent(S.paddingTop)&&this.zeroIndent(S.borderTopWidth))&&(o=!1,c=[]),p=!0}}while(!1);let w=this.nextInTree(e,o);if(w.isPending()){w.then(S=>{e=S,m.continueLoop()});return}else e=w.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,c,!this.stopAtOverflow,a)?h&&this.stopAtOverflow&&(e=h.modify(),e.overflow=!0):Ke(a)&&(this.pageBreakType=a),m.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let t=e.copy(),i=F("skipEdges"),n=null,s=!1;return i.loopWithFrame(r=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ve(e.viewNode,e.whitespace))break;if(!e.after){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=Xe(n,e.breakBefore),Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(s){if(Ke(n)){this.pageBreakType=n,r.breakLoop();return}n=null}s=!1,n=Xe(n,e.breakAfter)}else{n=Xe(n,e.breakBefore);let h=e.viewNode.localName;if(Xt[h]){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(a&&!(this.zeroIndent(a.paddingTop)&&this.zeroIndent(a.borderTopWidth))){r.breakLoop();return}}s=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,r.continueLoop()});return}else e=o.get()}t=null,r.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){return gi(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,t,i){let n=F("layoutNext");return this.skipEdges(e,t,i||null).then(s=>{if(e=s,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let r=e.formattingContext;new Fi().find(r).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 Fi().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 st(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=dd(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],k(this.element,"width",`${this.width}px`),k(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),s=new Fi().find(e.formattingContext),r=this.calculateClonedPaddingBorder(n),o=s.createEdgeBreakPosition(n,t,i,this.computedBlockSize+r);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new _n(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 N(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?N(null):N(e);let n=F("layout");return this.openAllViews(e.primary).then(s=>{let r=null;if(s.viewNode)r=s.copy();else{let a=h=>{h.nodeContext.viewNode&&(r=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new bg(t,i);o.layout(s,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,r,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=N(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let c=new Dt(h.toNodePosition());n.finish(c)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=F("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((s,r)=>s.getPriorityOfFinishBreak()-r.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):N(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=F("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(r=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())r.breakLoop();else if(this.pageBreakType)r.breakLoop();else if(e&&this.stopByOverflow(e)){s=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),r.breakLoop()}else o?o=!1:r.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),r.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:s})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=F("redoLayout"),n=0,s=null,r=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,r).then(h=>{r=!1,h?(s=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(s)}),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(Yt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Wn.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}Mt.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},io=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(this,"column"),this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let s=this;this.column.openAllViews=function(r){return Kn.prototype.openAllViews.call(this,r).thenAsync(o=>(s.startNodeContexts.push(o.copy()),N(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new vn(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 zt(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Jn=class{breakTextNode(e,t,i,n,s,r){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let s=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":s+ma(n)),s){let r=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=r.slice(0,i+1)+s+r.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let s=t.charAt(i);i++;let r=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Co(s)&&Co(r)?ma(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Jn,"instance");Jn.instance=new Jn;function ma(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var bg=class extends Yr{constructor(e,t){super(),this.leadingEdge=e,u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new vg(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||tf()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Ch(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown}},vg=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=F("DefaultLayoutMode.doLayout");return gg(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(s=>s.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(s=>{s.postLayout(n,e,t,i)}),n}},yg=class extends Kn{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),this.floatSide=e,this.parentContainer=o,u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),N(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function s(r,o){r.forEach(a=>{let h=Rt(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=o*l/100;k(e,a,`${c}px`)}})}s(["width","max-width","min-width"],i),s(["height","max-height","min-height"],n),s(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(r=>{Rt(e,r)==="auto"&&k(e,r,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=Rt(t,"height");n!==""&&n!=="auto"&&k(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=Rt(t,"width");n!==""&&n!=="auto"&&k(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.clientLayout.getElementClientRect(e),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},ti=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||sr.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new xg(e,this.rootSourceNode),sr.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},xg=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=jn(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=jn(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=ir(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=ir(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?N(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?N(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let s=t.viewNode.ownerDocument,r=t.viewNode,o=s.createElement("div");r.appendChild(o);let a=new io(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new Dt(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),a.getColumn().pageBreakType=h,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(xi,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(s=>s.nodeContext.sourceNode===e.sourceNode&&s.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let s=i(e);return t.push({nodeContext:e,result:s}),s}}isAfterNodeContextOf(e,t,i){let n=[];for(let s=e;s;s=s.parentNode){if(t.sourceNode===s)return t.after;n.push(s)}for(let s=t.sourceNode;s;s=s.parentNode){let r=n.indexOf(s);if(r>=0)return i?r===0:!1;for(let o=s;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Qh=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let s=this.formattingContext.getRepetitiveElements();return s&&(i.clientLayout,s.doneInitialLayout||(s.updateHeight(i),s.doneInitialLayout=!0)),n}},eu=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},Sg=class extends Qh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Cg=class extends eu{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new no(e)),this.processor.doLayout(e,t)}},no=class tu{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=St(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,s){let r=this.getRepetitiveElements();r&&t&&s.stopAtOverflow&&(i==null||r.isAfterLastContent(i))&&r.preventSkippingFooter()}finishBreak(t,i){let n=St(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return N(!0);let r=this.nodeContext;return Tg(n,r,i).thenAsync(()=>Ig(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return St(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof tu?St(this.nodeContext.formattingContext)===St(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Eg=class extends Yr{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new Sg(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Cg(this.formattingContext,this.processor))}},kg=class extends Xi{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),N(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),N(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return Xi.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?N(!0):Xi.prototype.afterNonInlineElementNode.call(this,e)}},Ng=class extends ci{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=St(e.formattingContext);return n.getRootViewNode(e)?(i&&iu(e.parent,t),e.belongsTo(n)?ci.prototype.layout.call(this,e,t,i):new Eg(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=Ag(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=St(e.formattingContext),n=F("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=St(e.formattingContext),n=new kg(i,t);return new nr(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=St(e.formattingContext),n=F("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Jh(s,t).then(r=>{let o=r;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return ci.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Pg(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof ti&&!i.belongsTo(n)&&t(n,i)}}function iu(e,t){e&&Pg(e.after?e.parent:e,(i,n)=>{Mt.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new no(n))})}function Tg(e,t,i){let n=e.getRepetitiveElements();if(n){let s=e.getRootNodeContext(t);if(s.viewNode){let r=s.viewNode.firstChild;return n.appendHeaderToFragment(s,r,i)}}return N(!0)}function Ig(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=e.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,i)}return N(!0)}function Ag(e){let t=e.formattingContext;return!t||!(t instanceof ti)?null:t}function St(e){return e instanceof ti,e}var Rg=new Ng;ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof ti&&!Mt.isInstanceOfTableFormattingContext(e)?Rg:null);var nu=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,u(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Lg=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},Fg=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Og=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new io(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&k(e,"vertical-align","top"),i&&i!=="normal"&&k(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return k(e,"vertical-align",t),i&&i!=="normal"&&k(e,"align-content",i),n}},Bg=class{constructor(e,t){this.viewNode=e,this.side=t}},_g=class extends vn{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?i:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Mg=class extends jr{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),s=n.every(r=>!!r.nodeContext)&&n.some((r,o)=>{let a=i[o].pseudoColumn,h=r.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(r=>r.cellNodeContext.breakPenalty));let s=i.some((r,o)=>r.breakPosition instanceof _n&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((r,o)=>{let a=r.breakPosition.getMinBreakPenalty();s&&r.breakPosition instanceof vn&&r.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(r.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},bi=class extends ti{constructor(e,t){super(e,t),this.tableSourceNode=t,u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(i=>i.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new nu(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,s=this.getRowSlots(e),r=0;for(;s[r];)r++;for(;e<n;e++){s=this.getRowSlots(e);for(let o=r;o<r+t.colSpan;o++){let a=s[o]=new Fg(e,o,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=e.getElementClientRect(i.viewElement);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let s=this.slots[i][n];if(s.cell===t)return{rowIndex:s.rowIndex,columnIndex:s.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,s)=>{if(s>=e.rowIndex)return i;let r=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!r||t.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),i),t.push(r)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let s=e[n],r=this.getCellFragmentOfCell(i);!r||s.collected.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),s.elements),s.collected.push(r))})}),[new zg(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Yt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}Mt.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},zg=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let s=mi(e,n);i=Math.max(i,t(s))}),i}};function at(e){return e instanceof bi,e}function Dg(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Vg(e){return e==="table"||e==="inline-table"}function wa(e){return Dg(e)||Vg(e)}function su(e,t,i){let n=e.nodeContext,s=n.display,r=n.parent?n.parent.display:null,o=!1;if(r==="inline-table"&&!(n.formattingContext instanceof bi)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bi){o=a.formattingContext===t;break}}return o||s==="table-row"&&!wa(r)||s==="table-cell"&&r!=="table-row"&&!wa(r)||n.formattingContext instanceof bi&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var Ug=class extends Xi{constructor(e,t){super(),this.formattingContext=e,this.column=t,u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=su(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,s=n.display,r=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new Bg(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new nu(this.rowIndex,n.sourceNode)),r.firstContentSourceNode||(r.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,s=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let r=s.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(r[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,N(!0);break;case"table-row":this.inHeaderOrFooter||(t.lastRowViewNode=i.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let r=i.viewNode;t.addCell(this.rowIndex,new Lg(this.rowIndex,this.columnIndex,r)),this.columnIndex++}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!ui(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},ru=class ou extends Xi{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let s=0;s<t.colSpan;s++)n+=i[t.anchorSlot.columnIndex+s];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let s=t.rowIndex,r=t.columnIndex,o=t.colSpan,a=i.viewNode,h=i.verticalAlign;o>1&&(k(a,"box-sizing","border-box"),k(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let l=a.ownerDocument.createElement("div");a.appendChild(l);let c=new Og(this.column,l,i);return this.formattingContext.addCellFragment(s,r,c),n.primary.steps.length===1&&n.primary.after&&(c.empty=!0),c.pseudoColumn.layout(n,!0).thenReturn(!0)}hasBrokenCellAtSlot(t){let i=this.formattingContext.cellBreakPositions[0];return i?i.cell.anchorSlot.columnIndex===t:!1}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let s=t[n],r=s.cell.rowIndex;if(r<this.currentRowIndex){let o=i[r];o||(o=i[r]=[]),o.push(s),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),s=n.reduce(p=>p+1,0);if(s===0)return N(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=F("layoutRowSpanningCellsFromPreviousFragment"),h=N(!0),l=0,c=[];return n.forEach(p=>{h=h.thenAsync(()=>{let d=Xn(p[0].cellNodePosition.steps[1],o.parent);return r.setCurrent(d,!1).thenAsync(()=>{let f=N(!0),g=0;function m(v){for(;g<v;){if(!c.includes(g)){let b=d.viewNode.ownerDocument.createElement("td");k(b,"padding","0"),d.viewNode.appendChild(b)}g++}}return p.forEach(v=>{f=f.thenAsync(()=>{let b=v.cell;m(b.anchorSlot.columnIndex);let w=v.cellNodePosition,S=Xn(w.steps[0],d);return S.offsetInNode=w.offsetInNode,S.after=w.after,S.fragmentIndex=w.steps[0].fragmentIndex+1,r.setCurrent(S,!1).thenAsync(()=>{let I=v.breakChunkPosition;for(let L=0;L<b.colSpan;L++)c.push(g+L);return g+=b.colSpan,this.layoutCell(b,S,I).thenAsync(()=>(S.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+s-l,N(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,N(!0)))})})}),h.then(()=>{r.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),N(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions[t.columnIndex];if(i&&i.cell.anchorSlot.columnIndex==t.anchorSlot.columnIndex){let n=i.cellNodePosition.steps[0],s=this.column.layoutContext.xmldoc.getElementOffset(n.node);cg(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,N(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=F("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=N(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let h=jn(a,0);return N(new Dt(h))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=su(t,at(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,s=this.formattingContext.getRepetitiveElements(),r=n.display;return r==="table-header-group"&&s&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):r==="table-row"?this.startTableRow(t):r==="table-cell"?this.startTableCell(t):N(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let s=new Mg(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),s=i.display;if(s==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):k(i.viewNode,"display","table-row-group"):s==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):k(i.viewNode,"display","table-row-group")),s&&ou.ignoreList[s])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return N(!0)}};u(ru,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Hg=ru,an=[];function $g(e){let t=an.findIndex(n=>n.root===e),i=an[t];return i?i.tableLayoutOption:null}function Gg(e){let t=an.findIndex(i=>i.root===e);t>=0&&an.splice(t,1)}var au=class{layoutEntireTable(e,t){let i=at(e.formattingContext),n=new Ug(i,t);return new nr(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=s.createElement("td");r.appendChild(l),o.push(l)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(h=>{let l=n.getElementClientRect(h),c=i?l.height:l.width;return Math.ceil(c)});return e.parentNode.removeChild(r),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let s=i.firstElementChild;for(;s;){if(s.localName==="col"){let r=s.span;for(s.removeAttribute("span"),n-=r;r-- >1;){let o=s.cloneNode(!0);i.insertBefore(o,s),t.push(o)}t.push(s)}s=s.nextElementSibling}for(;n-- >0;)s=i.ownerDocument.createElement("col"),i.appendChild(s),t.push(s)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let s=n.ownerDocument.createElement("colgroup");t.push(s);for(let r=e.length;r<i;r++){let o=n.ownerDocument.createElement("col");s.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,s=e.lastRowViewNode;if(!s)return;e.lastRowViewNode=null;let r=s.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=r;return}let a=e.colWidths=this.getColumnWidths(s,o,n,i.clientLayout),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((c,p)=>{k(c,n?"height":"width",`${a[p]}px`)}),h.forEach(c=>{r.appendChild(c.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=at(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=$g(e.sourceNode);Gg(e.sourceNode);let s=F("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=t.clientLayout.getElementClientRect(a),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mi(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new qg(r)),s.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),s.finish(null)}),s.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((s,r)=>{s&&(t.insertBefore(s.viewNode,i),s.side==="top"&&(n[r]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&t.insertBefore(e.colGroups.cloneNode(!0),i)}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=at(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Hg(i,t),o=new nr(r,t.layoutContext),a=F("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=at(e.formattingContext);return n.getRootViewNode(e)?(i&&iu(e.parent,t),new jg(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new _g(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Ls(e),!1}finishBreak(e,t,i,n){let s=at(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let r=s.findRowIndexBySourceNode(t.sourceNode);s.cellBreakPositions=[];let o;if(t.after?o=s.getRowSpanningCellsOverflowingTheRow(r):o=s.getCellsFallingOnRow(r),o.length){let a=F("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let c=o[h++],p=s.getCellFragmentOfCell(c),d=p.findAcceptableBreakPosition().nodeContext,f=p.cellNodeContext,g=f.toNodePosition(),m=new Dt(d.toNodePosition());s.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:c});let v=f.viewNode;p.column.layoutContext.processFragmentedBlockEdge(p.cellNodeContext),r<c.rowIndex+c.rowSpan-1&&(v.rowSpan=r-c.rowIndex+1),p.empty?l.continueLoop():p.pseudoColumn.finishBreak(d,!1,!0).then(()=>{Wg(p,s,d),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Ls(t),s.finishFragment(),a.finish(!0)}),a.result()}}return Ls(t),s.finishFragment(),qr.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Wg(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=r.clientLayout.getElementClientRect(a),l=r.getComputedPaddingBorder(a);if(s){let c=h.right-r.footnoteEdge-n.calculateOffset(i)-l.right;k(o,"max-width",`${c}px`)}else{let c=r.footnoteEdge-n.calculateOffset(i)-h.top-l.top;k(o,"max-height",`${c}px`)}}function Ls(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))");if(i.length===0)return;let n=Array.from(i).reduce((p,d)=>{let f=d.getBoundingClientRect(),g=e.vertical?f.width:f.height;return p+g},0),s=i[i.length-1],r=Array.from(t.children).indexOf(s),o=Array.from(s.children).reduce((p,d)=>{let f=d.rowSpan;return f>1&&r+f<t.childElementCount?Math.max(p,f):p},0),a=o?t.children[r+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let p=a;p&&p!==t.lastElementChild;p=p.nextElementSibling)if(p.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=p;break}}let h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,c=n+l;k(a,e.vertical?"width":"height",`${c}px`)}var jg=class extends Yr{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Xg(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Zg(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()}},Xg=class extends Qh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},qg=class extends vn{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 Yg(this.position.sourceNode))}},Yg=class lu{constructor(t){this.tableRootNode=t,u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,an.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof lu&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Zg=class extends eu{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Kg(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Kg=class hu extends no{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=at(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(s=>s.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,s){let r=at(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,r),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,s)})}),!t){let o=r.getRootViewNode(this.nodeContext);new au().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=at(this.nodeContext.formattingContext),s=F("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.breakPosition}))),[]),o=0;return s.loop(()=>{if(o<r.length){let a=r[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{s.finish(!0)}),s.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let s=[];for(let r=0;r<n;r++)i.cellFragments[r]&&i.cellFragments[r].forEach(o=>{o&&s.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return s}getElementsOffsetsForTableCell(t){let i=at(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof hu?at(this.nodeContext.formattingContext)===at(t.nodeContext.formattingContext):!1}},Jg=new au;function Qg(e,t,i,n,s,r){if(!t)return null;if(i===y.table){let o=e.parent;return new bi(o?o.formattingContext:null,e.sourceNode)}return null}function em(e){return e instanceof bi?Jg:null}ht("RESOLVE_FORMATTING_CONTEXT",Qg);ht("RESOLVE_LAYOUT_PROCESSOR",em);function ba(e){return e.reduce((t,i)=>t+i,0)/e.length}function tm(e){let t=ba(e);return ba(e.map(i=>{let n=i-t;return n*n}))}var im=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function ln(e){return e.vertical?e.width:e.height}function hn(e,t){e.vertical?e.width=t:e.height=t}var uu=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=ln(e)}balanceColumns(e){let t=F("ColumnBalancer#balanceColumns");this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(s=>{if(this.savePageFloatLayoutContexts(s),this.layoutContainer.clear(),!s){n.breakLoop();return}i.push(this.createTrialResult(s)),n.continueLoop()})}).then(()=>{let n=i.reduce((s,r)=>r.penalty<s.penalty?r:s,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new im(e,t)}preBalance(e){}postBalance(){hn(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},br=1;function cu(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,s=Math.max.apply(null,n.map(o=>o.computedBlockSize)),r=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return s>r+br}function du(e,t){var i;let n=e[e.length-1].layoutResult.columns,s=Math.max.apply(null,n.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+br))-br;if(s<ln(t)?hn(t,s):hn(t,ln(t)-1),t.vertical){let r=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=r-t.width}}var nm=class extends uu{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);hn(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return va(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return cu(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!va(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):ln(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)du(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,ln(this.layoutContainer)+this.originalContainerBlockSize*.1);hn(this.layoutContainer,t)}}};function va(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=6;return i.every(s=>t>s.computedBlockSize+n)}var sm=class extends uu{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 tm(t)}hasNextCandidate(e){return cu(e)}updateCondition(e){du(e,this.layoutContainer)}};function rm(e,t,i,n,s,r,o){if(t===y.auto)return null;{let a=o.positions.length===0,h=r[r.length-1],l=!!(h&&h.pageBreakType);return a||l?new nm(i,n,s,e):t===y.balance_all?new sm(i,n,s):(y.balance,null)}}var Fs=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},om=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 Fs(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 Fs(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Fs(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=_t(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=_t(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},am=class vr{constructor(t,i,n,s,r,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=r.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new vr(t,l.before,n,!1,r,this.isBlock(),a,!0),p=c.styleValue("content");Vt(p)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=Xe(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ke(this.breakBefore)&&(r.breakBefore=Xe(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new vr(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Vt(o)&&(this.afterBox=r)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=xh(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!tr(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}},lm=class{constructor(e){this.context=e,u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==y.none)}push(e,t,i,n){let s=this.lastBox();n&&s&&n.flowName!==s.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=n||s.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),h=new am(this.context,e,t,i,r,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",y.normal).toString(),n=hh(i);n&&!Ve(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=Xe(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},ya=class{constructor(e,t,i,n,s,r,o,a){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,this.counterListener=o,u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang),this.offsetMap=new om;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new lm(n),this.offsetMap.addStuckRange(h);let l=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,l,h),this.postprocessTopStyle(l,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${h}`]=l,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let s=t[i];s&&(this.rootStyle[i]=new Z(s,Yl))}}}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)qi(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,s=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<xa.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,xa[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"ex":h*=this.context.initialFontSize*we.ex/we.em;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*we.lh/we.em;break;default:{let l=we[a.unit];l&&(h*=l),s=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=s}}let r=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!J(o.value)){let a=o.evaluate(this.context);if(a instanceof Ut)this.context.rootLineHeight=a.num*r;else if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=r;break;case"ex":h*=r*we.ex/we.em;break;case"%":h*=r/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*we.lh/we.em;break;default:{let l=we[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*we.lh/we.em}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return ng(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let r=this.getStyle(this.root,!1),o=Ue(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,h)}let n=this.xmldoc.getNodeByOffset(e),s=this.xmldoc.getNodeOffset(n,0,!1);if(!(s>=this.lastOffset))for(;;){if(n.nodeType!=1)s+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,a,o,s)}s++}if(s>=this.lastOffset)break;let r=n.firstChild;if(r==null){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n===this.root)return}n=r}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let s=0,r=Number.POSITIVE_INFINITY,o=!1,a=!1,h=!1,l=t["flow-options"];if(l){let m=bd(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let c=t["flow-linger"];c&&(r=Ho(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let p=t["flow-priority"];p&&(s=Ho(p.evaluate(this.context,"flow-priority"),0));let d=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Fp(e,m)}let g=new Op(e,i,n,s,r,o,a,h,d);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ke(e)){let s=this.flows[i].forcedBreakOffsets;(s.length===0||s[s.length-1]<t)&&s.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=Xe(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let s=this.context;for(;;){let r=this.last.firstChild;if(r==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=Xe(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(r=this.last.nextSibling,r)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=r,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,c=a["flow-into"];if(c){let d=c.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(d,a,o,this.lastOffset);this.primary=!!this.primaryFlows[d],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=Xe(l.flowChunk.breakBefore,l.breakBefore));let p=this.boxStack.nearestBlockStartOffset(l);if(p===0){let d=a.page,f=d&&!J(d.value)&&d.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,p,l.flowName),l.beforeBox){let d=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(d,l.beforeBox.atBlockStart?p:l.offset,l.flowName)}if(this.primary&&l.displayValue()===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&&p===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},xa=["column-count","column-width","column-fill"],pi=class{constructor(e){this.validator=e,u(this,"success",null),u(this,"failure",null),u(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Wt=class{constructor(e,t){this.where=e,this.success=t,u(this,"what",-1)}},Bi=class pu{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 pu;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new pi(n.validator);s.code=n.code,t.nodes.push(s)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],s=new Wt(n.where,n.success);s.what=n.what,t.connections.push(s)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let s=this.nodes.length,r=new pi(Sa);n>=0?i?r.markAsStartAlternate(n):r.markAsEndAlternate(n):i?r.markAsStartGroup():r.markAsEndGroup(),this.nodes.push(r),this.connect(t,s);let o=new Wt(s,!0),a=new Wt(s,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new pi(Sa);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Wt(0,!0),s=new Wt(0,!1);this.nomatch.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new pi(t));let n=new Wt(i,!0),s=new Wt(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof Pe}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let r=0;r<t.nodes.length;r++)this.nodes.push(t.nodes[r]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let r=0;r<t.connections.length;r++){let o=t.connections[r];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let r=0;r<t.match.length;r++)this.match.push(t.match[r]+s);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let r=0;r<t.nomatch.length;r++)this.match.push(t.nomatch[r]+s);else if(this.emptyHead){for(let r=0;r<t.nomatch.length;r++)this.nomatch.push(t.nomatch[r]+s);this.emptyHead=t.emptyHead}else for(let r=0;r<t.nomatch.length;r++)this.error.push(t.nomatch[r]+s);for(let r=0;r<t.error.length;r++)this.error.push(t.error[r]+s);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let s of this.connections)s.success?this.nodes[s.where].success=this.nodes[s.what]:this.nodes[s.where].failure=this.nodes[s.what];for(let s=0;s<n;s++)if(this.nodes[s].failure==null||this.nodes[s].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},hm=1,fu=2,gu=4,jt=8,Mn=16,yr=32,zn=64,mu=128,Ui=256,Hi=512,xr=1024,wu=2048,bu=4096,vu=8192,yu=class extends It{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Pe=class xu extends yu{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&hm?t:null}visitSlash(t){return this.allowed&wu?t:null}visitStr(t){return this.allowed&fu?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&gu||this.allowed&zn&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Hi)?t.unit=="%"&&this.allowed&xr?t:null:t.num<0&&!(this.allowed&Ui)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Hi?t:null:t.num<=0&&!(this.allowed&Ui)?null:this.allowed&Mn?t:null}visitInt(t){return t.num==0?this.allowed&Hi?t:null:t.num<=0&&!(this.allowed&Ui)?null:this.allowed&(yr|Mn)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&zn&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&mu?t:null}visitURange(t){return this.allowed&bu?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&zn&&CSS.supports("color",t.toString())||this.allowed&vu&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(jt|Mn|yr|Ui|Hi|xr)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let s in this.idents)i[s]=this.idents[s];for(let s in t.idents)i[s]=t.idents[s];for(let s in this.units)n[s]=this.units[s];for(let s in t.units)n[s]=t.units[s];return new xu(this.allowed|t.allowed,i,n)}},ne={},Sa=new Pe(0,ne,ne),so=class extends yu{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new pi(null),this.failureTerminal=new pi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,s=this.first,r=i,o=null,a=null;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(r>=e.length){s=s.failure;continue}let h=e[r],l=h;if(s.isSpecial()){let c=!0;s.isStartGroup()?(o?o.push(a):o=[a],a=[]):s.isEndGroup()?o.length>0?a=o.pop():a=null:s.isEndAlternate()?a[s.getAlternate()]="taken":c=a[s.getAlternate()]==null,s=c?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof Ki&&this instanceof Ki){if(l=new ye(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof ro&&this instanceof Ki){if(l=new qe(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else l=h.visit(s.validator);if(!l){s=s.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<r;c++)n[c]=e[c]}e!==n&&(n[r-i]=l),r++,s=s.success}}return s===this.successTerminal&&(t?n.length>0:r==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Ki=class extends so{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ye(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof ro){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},ro=class extends so{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new qe(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},um=class extends so{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ki(e.name,t):null}},Su=class{tryParse(e,t,i){return t}success(e,t){}},Cu=class extends Su{constructor(e,t){super(),this.name=t,u(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let s=n.length,r=s>1?new ye(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},cm=class extends Cu{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},dm=class extends Su{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==ns){if(++t==e.length)return n}else return n;let s=this.nodes[0].tryParse(e,t,i);if(s==t)return n;t=s;for(let r=1;r<this.nodes.length&&t<e.length&&(s=this.nodes[r].tryParse(e,t,i),s!=t);r++)t=s;return t}},oo=class extends It{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 Cu(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let s of this.propList)t.simpleProperty(s,(n=(i=this.values[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n: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)}},Ai=class extends oo{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}},Eu=class extends oo{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 cm(this.validatorSet,this.propList)}},pm=class extends oo{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===ns){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let s;if(t+1<e.length)for(s=t+i+1;s>=e.length;)s=s-(s==t+2?1:2);else s=n;let r=[e[n],e[s]];if(this.syntax[i].tryParse(r,0,this)!=2)return this.error=!0,0}return e.length}},fm=class extends Ai{constructor(){super()}mergeIn(e,t){var i,n;for(let s of this.propList){let r=(n=(i=t[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:y.initial,o=e[s];o||(o=[],e[s]=o),o.push(r)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof qe?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new qe(t[i]);return null}},gm=class extends Ai{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let s=this.validatorSet.validators;if(!e[t].visit(s["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===ns){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(s["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let r=t==e.length-1?e[t]:new ye(e.slice(t,e.length));return r.visit(s["font-family"])?(this.values["font-family"]=r,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new qe(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},mm=class extends Ai{validateList(e){if(e.length===1&&e[0]instanceof ft)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)}},wm=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],bm=class extends Ai{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)wm.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Ca={SIMPLE:Ai,INSETS:Eu,INSETS_SLASH:pm,COMMA:fm,FONT:gm,TEXT_SPACING:mm,ALL:bm},vm=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new T(t.num,t.text);else if(t.type==7)i=new Tl(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Bi;if(e=="||"){for(let s=0;s<t.length;s++){let r=new Bi;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new Bi;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let s=0;s<t.length;s++)i.addGroup(t[s],s==0?1:n);return i}}addCounts(e,t,i){let n=new Bi;for(let s=0;s<t;s++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let s=t;s<i;s++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Bi;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new ro(t);break;case"SPACE":i=new Ki(t);break;default:i=new um(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Pe(zn,ne,ne)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Pe(vu,ne,ne)),this.namedValidators.POS_INT=this.primitive(new Pe(yr,ne,ne)),this.namedValidators.POS_NUM=this.primitive(new Pe(Mn,ne,ne)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Pe(jt,ne,{"%":G})),this.namedValidators.NEGATIVE=this.primitive(new Pe(Ui,ne,ne)),this.namedValidators.ZERO=this.primitive(new Pe(Hi,ne,ne)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Pe(xr,ne,ne)),this.namedValidators.POS_LENGTH=this.primitive(new Pe(jt,ne,{em:G,ex:G,ch:G,rem:G,lh:G,rlh:G,vw:G,vh:G,vi:G,vb:G,vmin:G,vmax:G,pvw:G,pvh:G,pvi:G,pvb:G,pvmin:G,pvmax:G,cm:G,mm:G,in:G,px:G,pt:G,pc:G,q:G})),this.namedValidators.POS_ANGLE=this.primitive(new Pe(jt,ne,{deg:G,grad:G,rad:G,turn:G})),this.namedValidators.POS_TIME=this.primitive(new Pe(jt,ne,{s:G,ms:G})),this.namedValidators.FREQUENCY=this.primitive(new Pe(jt,ne,{Hz:G,kHz:G})),this.namedValidators.RESOLUTION=this.primitive(new Pe(jt,ne,{dpi:G,dpcm:G,dppx:G})),this.namedValidators.URI=this.primitive(new Pe(mu,ne,ne)),this.namedValidators.URANGE=this.primitive(new Pe(bu,ne,ne)),this.namedValidators.IDENT=this.primitive(new Pe(gu,ne,ne)),this.namedValidators.STRING=this.primitive(new Pe(fu,ne,ne)),this.namedValidators.SLASH=this.primitive(new Pe(wu,ne,ne));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let s=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(s)||(this.prefixes[s]=n)}else if(e.token().type!=18)throw new Error("':' expected");return s}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],s="",r,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(s,i)},h=c=>{if(o)throw new Error(`'${c}': unexpected`);if(s&&s!=c)throw new Error(`mixed operators: '${c}' and '${s}'`);s=c,o=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(o||h(" "),this.isBuiltIn(c.text)){let p=this.namedValidators[c.text];if(!p)throw new Error(`'${c.text}' unexpected`);i.push(p.clone())}else{let p={};p[c.text.toLowerCase()]=B(c.text),i.push(this.primitive(new Pe(0,p,ne)))}o=!1;break;case 5:{let p={};p[`${c.num}`]=new ei(c.num),i.push(this.primitive(new Pe(0,p,ne))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:s,b:"(",fn:c.text}),s="",i=[],o=!0;break;case 15:{r=a();let p=n.pop();if(p.b!="[")throw new Error("']' unexpected");i=p.vals,i.push(r),s=p.op,o=!1;break}case 11:{r=a();let p=n.pop();if(p.b!="(")throw new Error("')' unexpected");i=p.vals,i.push(this.newFunc(p.fn,r)),s=p.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");let p=c.num,d=p;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");d=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),p,d));break}case 17:if(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new Ki(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 Ut(n.num));break;case 5:i.push(new ei(n.num));break;case 3:i.push(new T(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new ye(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Ca[i.text]?(n=new Ca[i.text],e.consume()):n=new Ai,n.setOwner(this);let s=!1,r=[],o=!1,a=[],h=[];for(;!s;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])r.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof Eu){let l=this.shorthands[i.text];r.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(r.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:r}),r=[],o=!1;break;case 15:{let l=new dm(r,o),c=a.pop();r=c.syntax,o=c.slash,r.push(l);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,h),this.shorthands[t]=n}}parse(e){let t=new gt(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let s=this.shorthands[n],r=s?s.propList:[n];for(let o of r)i[o]=(t=this.defaultValues[o])!=null?t:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){if(Nt(e)||n.ruleType==="font-face"||xm(t)){n.simpleProperty(e,t,i);return}let s="",r=e;e=e.toLowerCase();let o=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);o&&(s=o[1],e=o[2]);let a=this.prefixes[e];if(!a||!a[s]){CSS.supports(e,t.toString())?n.simpleProperty(r,t,i):s&&!Qa.includes(`-${s}-`)||n.unknownProperty(r,t);return}let h=this.validators[e];if(h){let l=J(t)||t.isExpr()?t:t.visit(h);l?n.simpleProperty(e,l,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(r,t)}else{let l=this.shorthands[e].clone();J(t)?l.propagateDefaultingValue(t,i,n):(t.visit(l),l.finish(i,n)||n.invalidPropertyValue(r,t))}}};function ku(){let e=new vm;return e.initBuiltInValidators(),e.parse(Hl),e}var ym=class extends It{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function xm(e){let t=new ym;return e.visit(t),t.varFound}var un={"font-style":y.auto,"font-stretch":y.auto,"font-weight":y.auto,"unicode-range":od},Zw=`OTTO${new Date().valueOf()}`;function Sm(e){let t=new kt;for(let i in un)t.append(" "),t.append(e[i].toString());return t.toString()}function Cm(e){for(let t in un)e[t]||(e[t]=un[t])}function Em(e,t){let i={};for(let n in e)i[n]=Ue(e,n).evaluate(t,n);return Cm(i),i}var Nu=class{constructor(e){this.properties=e,u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=Sm(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 kt;i.append(`@font-face {
1482
1482
  font-family: `),i.append(this.family),i.append(`;
1483
- `);for(let n in ln)i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1484
- `);if(t){i.append('src: url("');let n=np(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1483
+ `);for(let n in un)i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
1484
+ `);if(t){i.append('src: url("');let n=sp(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
1485
1485
  }
1486
- `),i.toString()}},Em=class{constructor(e){this.deobfuscator=e,u(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof qe){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(B(s)),i.push(n)}return new qe(i)}else{let t=this.familyMap[e.stringValue()];return t?new qe([B(t),e]):e}}},km=class{constructor(e,t,i){this.head=e,this.body=t,u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=F("initFont"),s=e.src,r={};for(let l in ln)r[l]=e.properties[l];let o=this.getViewFontFamily(e,i);r["font-family"]=B(o);let a=new ku(r),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(s,t),this.head.appendChild(h),D.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),D.debug("Found already-loaded font:",i)):D.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new fn(()=>{let r=F("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?as(o,"blob").then(h=>{if(!h.responseBlob){r.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){D.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return os(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=F("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Nm=1,ps=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${Nm++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Pm=class extends ps{constructor(e){super(e,null,null,[],null),this.specified.width=new K(Ni,0),this.specified.height=new K(Pi,0)}},Ca=class extends zs{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return r?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},Nu=class Pu extends ps{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,u(this,"keyMap",{}),t instanceof Ca||(this._scope=new Ca(t,this)),this.pageMaster=this,this.specified.width=new K(Ni,0),this.specified.height=new K(Pi,0),this.specified["wrap-flow"]=new K(v.auto,0),this.specified.position=new K(v.relative,0),this.specified.overflow=new K(v.visible,0)}createInstance(t){return new ao(t,this)}clone(t){let i=new Pu(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}},Tu=class Iu extends ps{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new K(v.auto,0)}createInstance(t){return new Am(t,this)}clone(t){let i=new Iu(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},fs=class Ru extends ps{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new hn(t,this)}clone(t){let i=new Ru(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Tm(e,t,i){return!t||J(t)?new Fe(e,i):t.toExpr(e,e.zero)}function ue(e,t,i){return!t||t===v.auto||J(t)?null:t.toExpr(e,i)}function Im(e,t,i){return!t||t===v.normal||J(t)?null:t.toExpr(e,i)}function tt(e,t,i){return!t||t===v.auto||J(t)?e.zero:t.toExpr(e,i)}function Ea(e,t,i){return!t||J(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function bt(e,t,i,n){return!t||i===v.none||J(t)?e.zero:t.toExpr(e,n)}function Au(e,t,i){return!t||J(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var gs=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),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 j(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let s=this.vertical?Nh:Ph;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Sl(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ae(i,An(i,new $i(i,"min",[n,s]),j(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Au(e,t.enabled,e._true),n=ue(e,t.page,e.zero);if(n){let o=new ze(e,"page-number");i=lt(e,i,new Or(e,n,o))}let s=ue(e,t["min-page-width"],e.zero);s&&(i=lt(e,i,new Vs(e,new ze(e,"page-width"),s)));let r=ue(e,t["min-page-height"],e.zero);r&&(i=lt(e,i,new Vs(e,new ze(e,"page-height"),r))),i=this.boxSpecificEnabled(i),t.enabled=new V(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ue(e,t.left,i),s=ue(e,t["margin-left"],i),r=bt(e,t["border-left-width"],t["border-left-style"],i),o=tt(e,t["padding-left"],i),a=ue(e,t.width,i),h=ue(e,t["max-width"],i),l=tt(e,t["padding-right"],i),c=bt(e,t["border-right-width"],t["border-right-style"],i),p=ue(e,t["margin-right"],i),d=ue(e,t.right,i),f=j(e,r,o),g=j(e,r,l);if(n&&d&&a){let b=ae(e,i,j(e,a,j(e,j(e,n,f),g)));s?p?d=ae(e,b,p):p=ae(e,b,j(e,d,s)):(b=ae(e,b,d),p?s=ae(e,b,p):(s=An(e,b,new Fe(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!n&&!d&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!d?n=e.zero:!a&&!d&&(a=this.autoWidth,this.isAutoWidth=!0);let b=ae(e,i,j(e,j(e,s,f),j(e,p,g)));this.isAutoWidth&&(h||(h=ae(e,b,n||d)),!this.vertical&&(ue(e,t["column-width"],null)||ue(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?d||(d=ae(e,b,j(e,n,a))):a=ae(e,b,j(e,n,d)):n=ae(e,b,j(e,d,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),y=tt(e,m,i);t.left=new V(n),t["margin-left"]=new V(s),t["border-left-width"]=new V(r),t["padding-left"]=new V(o),t.width=new V(a),t["max-width"]=new V(h||a),t["padding-right"]=new V(l),t["border-right-width"]=new V(c),t["margin-right"]=new V(p),t.right=new V(d),t["snap-width"]=new V(y)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=ue(e,t.top,n),r=ue(e,t["margin-top"],i),o=bt(e,t["border-top-width"],t["border-top-style"],i),a=tt(e,t["padding-top"],i),h=ue(e,t.height,n),l=ue(e,t["max-height"],n),c=tt(e,t["padding-bottom"],i),p=bt(e,t["border-bottom-width"],t["border-bottom-style"],i),d=ue(e,t["margin-bottom"],i),f=ue(e,t.bottom,n),g=j(e,o,a),m=j(e,p,c);if(s&&f&&h){let w=ae(e,n,j(e,h,j(e,j(e,s,g),m)));r?d?f=ae(e,w,r):d=ae(e,w,j(e,f,r)):(w=ae(e,w,f),d?r=ae(e,w,d):(r=An(e,w,new Fe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!s&&!f&&!h&&(s=e.zero),!s&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let w=ae(e,n,j(e,j(e,r,g),j(e,d,m)));this.isAutoHeight&&(l||(l=ae(e,w,s||f)),this.vertical&&(ue(e,t["column-width"],null)||ue(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),s?h?f||(f=ae(e,w,j(e,s,h))):h=ae(e,w,j(e,f,s)):s=ae(e,w,j(e,f,h))}let y=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=tt(e,y,i);t.top=new V(s),t["margin-top"]=new V(r),t["border-top-width"]=new V(o),t["padding-top"]=new V(a),t.height=new V(h),t["max-height"]=new V(l||h),t["padding-bottom"]=new V(c),t["border-bottom-width"]=new V(p),t["margin-bottom"]=new V(d),t.bottom=new V(f),t["snap-height"]=new V(b)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ue(e,t[this.vertical?"height":"width"],null),n=ue(e,t["column-width"],i),s=ue(e,t["column-count"],null),r=Im(e,t["column-gap"],null);r||(r=new Jt(e,1,"em")),n&&!s&&(s=new $i(e,"floor",[Us(e,j(e,i,r),j(e,n,r))]),s=new $i(e,"max",[e.one,s])),s||(s=e.one),n=ae(e,Us(e,j(e,i,r),s),r),t["column-width"]=new V(n),t["column-count"]=new V(s),t["column-gap"]=new V(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){e.registerInstance(this.pageBox.key,this);let t=this.pageBox.scope,i=this.style,n=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=Wh(this.cascaded,e,n,!1,null);this.vertical=$h(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Gh(s,e,this.parentInstance?this.parentInstance.rtl:!1),Xh(s,i,this.vertical,this.rtl,(r,o)=>o.value),this.autoWidth=new De(t,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new De(t,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&Xi(t)&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new T(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=Kn(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=Kn(e,s,t,r)}return We(s,e)}getSpecial(e,t){let i=Rh(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==G&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&ul(s.unit)&&(s=Il(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),k(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new Hr(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),k(t.element,"margin-left",`${n}px`),k(t.element,"padding-left",`${s}px`),k(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(k(t.element,"margin-right",`${s}px`),k(t.element,"padding-right",`${r}px`),k(t.element,"border-right-width",`${o}px`),t.marginRight=s,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,r+=t.snapOffsetY)}t.paddingTop=r,k(t.element,"top",`${n}px`),k(t.element,"margin-top",`${s}px`),k(t.element,"padding-top",`${r}px`),k(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;k(t.element,"height",`${r}px`),k(t.element,"margin-bottom",`${i}px`),k(t.element,"padding-bottom",`${n}px`),k(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){k(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,k(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){k(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");k(t.element,"right",`${n}px`),k(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,s){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&k(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&k(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let r=0;r<ka.length;r++)this.propagateProperty(e,t,ka[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<Pa.length;s++)this.propagateProperty(e,t,Pa[s],n)}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!J(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==v.auto&&!J(a)};for(let r=0;r<Ta.length;r++){let o=Ta[r];o==="width"&&!n()||o==="height"&&!s()||this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,h=(!this.vertical||!n)&&this.isAutoWidth,l=null;if((h||a)&&(h&&k(t.element,"width","auto"),a&&k(t.element,"height","auto"),l=r.getElementClientRect(n?n.element:t.element),h&&(this.calculatedWidth=Math.ceil(l.right-l.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=l.bottom-l.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))),(this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let c=this.getPropAsNumber(e,"column-rule-width"),p=this.getProp(e,"column-rule-style"),d=this.getProp(e,"column-rule-color");if(c>0&&p&&p!=v.none&&d!=v.transparent){let f=this.getPropAsNumber(e,"column-gap"),g=this.vertical?t.height:t.width,m=this.vertical?"border-top":"border-left";for(let y=1;y<s;y++){let b=this.vertical?(g+f)*y/s-f/2+t.paddingTop-c/2:(g+f)*y/s-f/2+t.paddingLeft-c/2,w=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,S=t.element.ownerDocument.createElement("div");k(S,"position","absolute"),k(S,this.vertical?"left":"top","0px"),k(S,this.vertical?"top":"left",`${b}px`),k(S,this.vertical?"height":"width","0px"),k(S,this.vertical?"width":"height",`${w}px`),k(S,m,`${c}px ${p.toString()}${d?` ${d.toString()}`:""}`),t.element.insertBefore(S,t.element.firstChild)}}}for(let c=0;c<Na.length;c++)this.propagateProperty(e,t,Na[c],o);for(let c=0;c<Ia.length;c++)this.propagateDelayedProperty(e,t,Ia[c],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||wi(r)&&Yt(i,r,Ve(n,r));if(this.pageBox.pseudoName==oo)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new pr(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},ka=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","outline-style","outline-color","outline-width","overflow","visibility"],Na=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-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","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],Pa=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-transform","white-space","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-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-position"],Ta=["width","height","image-resolution","object-fit","object-position"],Ia=["transform","transform-origin"],oo="background-host",Rm=class extends gs{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)}},ao=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=lt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Am=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},hn=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ft&&(n=[t]),t instanceof qe&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof ft){let o=Ms(n[r].name,"enabled"),a=new ze(s,o);i&&(a=new Ot(s,a)),e=lt(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Au(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Tm(t,i["flow-from"],"body"),r=new $i(t,"has-content",[s]);e=lt(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=lt(t,r,e),this.pageMasterInstance.style.enabled=new V(r)}return e}prepareContainer(e,t,i,n,s){i.pageAreaElement||k(t.element,"overflow","hidden"),super.prepareContainer(e,t,i,n,s)}},lo=class extends gn{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new K(t,i?Yl:Kl)}},Lu=class extends lo{constructor(e,t,i,n){super(e,t,i,n)}},Lm=class Fu extends lo{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new K(Fo,0),n.specified.height=new K(Fo,0)}startPartitionRule(t,i,n){let s=new fs(this.scope,t,i,n,this.target),r=new Lu(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new Tu(this.scope,t,i,n,this.target),r=new Fu(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},Fm=class extends lo{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new fs(this.scope,e,t,i,this.target),s=new Lu(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new Tu(this.scope,e,t,i,this.target),s=new Lm(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function Ou(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===v.vertical_lr||n!==v.vertical_rl&&s!==v.rtl?"ltr":"rtl"}var Om={a10:{width:new T(26,"mm"),height:new T(37,"mm")},a9:{width:new T(37,"mm"),height:new T(52,"mm")},a8:{width:new T(52,"mm"),height:new T(74,"mm")},a7:{width:new T(74,"mm"),height:new T(105,"mm")},a6:{width:new T(105,"mm"),height:new T(148,"mm")},a5:{width:new T(148,"mm"),height:new T(210,"mm")},a4:{width:new T(210,"mm"),height:new T(297,"mm")},a3:{width:new T(297,"mm"),height:new T(420,"mm")},a2:{width:new T(420,"mm"),height:new T(594,"mm")},a1:{width:new T(594,"mm"),height:new T(841,"mm")},a0:{width:new T(841,"mm"),height:new T(1189,"mm")},b10:{width:new T(31,"mm"),height:new T(44,"mm")},b9:{width:new T(44,"mm"),height:new T(62,"mm")},b8:{width:new T(62,"mm"),height:new T(88,"mm")},b7:{width:new T(88,"mm"),height:new T(125,"mm")},b6:{width:new T(125,"mm"),height:new T(176,"mm")},b5:{width:new T(176,"mm"),height:new T(250,"mm")},b4:{width:new T(250,"mm"),height:new T(353,"mm")},b3:{width:new T(353,"mm"),height:new T(500,"mm")},b2:{width:new T(500,"mm"),height:new T(707,"mm")},b1:{width:new T(707,"mm"),height:new T(1e3,"mm")},b0:{width:new T(1e3,"mm"),height:new T(1414,"mm")},c10:{width:new T(28,"mm"),height:new T(40,"mm")},c9:{width:new T(40,"mm"),height:new T(57,"mm")},c8:{width:new T(57,"mm"),height:new T(81,"mm")},c7:{width:new T(81,"mm"),height:new T(114,"mm")},c6:{width:new T(114,"mm"),height:new T(162,"mm")},c5:{width:new T(162,"mm"),height:new T(229,"mm")},c4:{width:new T(229,"mm"),height:new T(324,"mm")},c3:{width:new T(324,"mm"),height:new T(458,"mm")},c2:{width:new T(458,"mm"),height:new T(648,"mm")},c1:{width:new T(648,"mm"),height:new T(917,"mm")},c0:{width:new T(917,"mm"),height:new T(1297,"mm")},"jis-b10":{width:new T(32,"mm"),height:new T(45,"mm")},"jis-b9":{width:new T(45,"mm"),height:new T(64,"mm")},"jis-b8":{width:new T(64,"mm"),height:new T(91,"mm")},"jis-b7":{width:new T(91,"mm"),height:new T(128,"mm")},"jis-b6":{width:new T(128,"mm"),height:new T(182,"mm")},"jis-b5":{width:new T(182,"mm"),height:new T(257,"mm")},"jis-b4":{width:new T(257,"mm"),height:new T(364,"mm")},"jis-b3":{width:new T(364,"mm"),height:new T(515,"mm")},"jis-b2":{width:new T(515,"mm"),height:new T(728,"mm")},"jis-b1":{width:new T(728,"mm"),height:new T(1030,"mm")},"jis-b0":{width:new T(1030,"mm"),height:new T(1456,"mm")},letter:{width:new T(8.5,"in"),height:new T(11,"in")},legal:{width:new T(8.5,"in"),height:new T(14,"in")},ledger:{width:new T(11,"in"),height:new T(17,"in")}},Bm=new T(.24,"pt"),Kw=new T(3,"mm"),_m=new T(10,"mm"),Mm=new T(13,"mm");function Qn(e){let t={width:Ni,height:Pi,bleed:le,bleedOffset:le,cropOffset:le},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,c,p;if(l.isSpaceList()?(c=l.values[0],p=l.values[1]):(c=l,p=null),c.isNumeric())t.width=c,t.height=p||c;else{let d=c.name&&Om[c.name.toLowerCase()];d&&(p&&p===v.landscape?(t.width=d.height,t.height=d.width):(t.width=d.width,t.height=d.height))}}let n=e.marks,s=e.bleed,r=n&&!J(n.value)?n.value:v.none,o=s&&!J(s.value)?s.value:v.auto;if(o===v.auto){if(r!==v.none){let l=!1;r.isSpaceList()?l=r.values.some(c=>c===v.crop):l=r===v.crop,l&&(t.bleed=new T(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!J(a.value)?a.value:v.auto;return h===v.auto?r!==v.none&&(t.bleedOffset=Mm):h.isNumeric()&&(t.cropOffset=h),t}function Ra(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===Ni?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===Pi?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function Bu(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 Zi(e,t,i){i=i||"polyline";let n=e.createElementNS("http://www.w3.org/2000/svg",i);return n.setAttribute("stroke","#010101"),n.setAttribute("stroke-width",t),n.setAttribute("fill","none"),n}var xr=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(xr||{});function zm(e,t,i,n,s,r){let o=n;o<=s+2*we.mm&&(o=s+n/2);let a=Math.max(n,o),h=s+a+i/2,l=Bu(e,h,h),c=[[0,s+n],[n,s+n],[n,s+n-o]],p=c.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(g=>[s+a-g[0],g[1]]),p=p.map(g=>[s+a-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(g=>[g[0],s+a-g[1]]),p=p.map(g=>[g[0],s+a-g[1]]));let d=Zi(e,i);d.setAttribute("points",c.map(g=>g.join(",")).join(" ")),l.appendChild(d);let f=Zi(e,i);return f.setAttribute("points",p.map(g=>g.join(",")).join(" ")),l.appendChild(f),t.split(" ").forEach(g=>{l.style[g]=`${r}px`}),l}var un=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(un||{});function Dm(e,t,i,n,s){let r=n*2,o,a;t==="top"||t==="bottom"?(o=r,a=n):(o=n,a=r);let h=Bu(e,o,a),l=Zi(e,i);l.setAttribute("points",`0,${a/2} ${o},${a/2}`),h.appendChild(l);let c=Zi(e,i);c.setAttribute("points",`${o/2},0 ${o/2},${a}`),h.appendChild(c);let p=Zi(e,i,"circle");p.setAttribute("cx",o/2),p.setAttribute("cy",a/2),p.setAttribute("r",n/4),h.appendChild(p);let d;switch(t){case"top":d="bottom";break;case"bottom":d="top";break;case"left":d="right";break;case"right":d="left";break}return Object.keys(un).forEach(f=>{let g=un[f];g===t?h.style[g]=`${s}px`:g!==d&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function Vm(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let f=o.value;f instanceof ve?f.values.forEach(g=>{g===v.crop?s=!0:g===v.cross&&(r=!0)}):f===v.crop?s=!0:f===v.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let h=i.container,l=h.ownerDocument,c=We(Bm,n),p=Math.max(0,t.bleedOffset-We(_m,n)),d=t.bleedOffset-p;s&&Object.keys(xr).forEach(f=>{let g=xr[f],m=zm(l,g,c,d,a,p);h.appendChild(m)}),r&&Object.keys(un).forEach(f=>{let g=un[f],m=Dm(l,g,c,d,p);h.appendChild(m)})}var Sr=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end"],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};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})(),ho={"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"}},Um=(()=>{let e=ho;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),uo="vivliostyle-page-rule-master",cn="_marginBoxes",Hm=class extends Nu{constructor(e,t,i){super(e,null,uo,[],t,null,0),u(this,"bodyPartitionKey"),u(this,"pageMarginBoxes",{});let n=Qn(i),s=new $m(this.scope,this,i,n);this.bodyPartitionKey=s.key,this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[cn];t&&Um.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Gm(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new K(v.relative,0),this.specified.width=new K(t.width,0),this.specified.height=new K(t.height,0);for(let i in e)!Sr[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new zn(e,this)}},$m=class extends fs{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n,this.specified["z-index"]=new K(new Qt(0),0),this.applySpecified(i)}applySpecified(e){this.specified["flow-from"]=new K(B("body"),0),this.specified.position=new K(v.absolute,0),this.specified.overflow=new K(v.visible,0);for(let t in Sr)Sr.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new Mu(e,this)}},Gm=class extends fs{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[cn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(kh[i]||s&&s.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==G&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new jm(e,this)}},zn=class extends ao{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 V(e.borderBoxWidth),t.height=new V(e.borderBoxHeight),t["padding-left"]=new V(e.marginLeft),t["padding-right"]=new V(e.marginRight),t["padding-top"]=new V(e.marginTop),t["padding-bottom"]=new V(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",h=this.pageBox.scope,l={},c={},p={};for(let S in e){let I=ho[S];if(I){let L=e[S],_=this.pageMarginBoxInstances[S],U=new _u(L,_.style,t,h,s);l[I.positionAlongVariableDimension]=L,c[I.positionAlongVariableDimension]=_,p[I.positionAlongVariableDimension]=U}}let d={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),g=!1,m={};Object.keys(l).forEach(S=>{let I=S,L=ue(h,c[I].style[t?"max-width":"max-height"],i.extent);if(L){let _=L.evaluate(n);if(f[I]>_){let U=p[I]=new Aa(l[I],c[I].style,t,h,s,_);m[I]=U.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),g=!1,[r,o,a].forEach(S=>{f[S]=m[S]||f[S]}));let y={};Object.keys(l).forEach(S=>{let I=S,L=ue(h,c[I].style[t?"min-width":"min-height"],i.extent);if(L){let _=L.evaluate(n);if(f[I]<_){let U=p[I]=new Aa(l[I],c[I].style,t,h,s,_);y[I]=U.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),[r,o,a].forEach(S=>{f[S]=y[S]||f[S]}));let b=d.start+d.extent,w=d.start+(d.start+d.extent);[r,o,a].forEach(S=>{let I=f[S];if(I){let L=l[S],_=0;switch(S){case r:_=t?L.left:L.top;break;case o:_=(w-I)/2;break;case a:_=b-I;break}t?L.setHorizontalPosition(_,I-L.getInsetLeft()-L.getInsetRight()):L.setVerticalPosition(_,I-L.getInsetTop()-L.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){let i=e.start,n=e.center,s=e.end,r={};if(n){let o=[i,s].filter(p=>p),a=o.length?new Wm(o):null,h=this.distributeAutoMarginBoxSizes(n,a,t);h.xSize&&(r.center=h.xSize);let l=h.xSize||n.getOuterSize(),c=(t-l)/2;i&&i.hasAutoSize()&&(r.start=c),s&&s.hasAutoSize()&&(r.end=c)}else{let o=this.distributeAutoMarginBoxSizes(i,s,t);o.xSize&&(r.start=o.xSize),o.ySize&&(r.end=o.ySize)}return r}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(s-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){super.prepareContainer(e,t,i,n,s),t.element.setAttribute("data-vivliostyle-page-box",!0)}},_u=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,u(this,"hasAutoSize_"),u(this,"size",null);let r=t[i?"width":"height"];this.hasAutoSize_=!r||r===v.auto||J(r)}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width"]:["max-content height","min-content height"];this.size=Ur(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()}},Wm=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>e.hasAutoSize())}getOuterMaxContentSize(){let e=this.params.map(t=>t.getOuterMaxContentSize());return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>t.getOuterMinContentSize());return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>t.getOuterSize());return Math.max.apply(null,e)*e.length}},Aa=class extends _u{constructor(e,t,i,n,s,r){super(e,t,i,n,s),u(this,"fixedSize"),this.fixedSize=r}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},Mu=class extends hn{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(n.match(/^column.*$/)||n.match(/^background-/))&&(i[n]=t[n]);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.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),h=ue(n,t[o],a),l=ue(n,t[`margin-${s}`],a),c=ue(n,t[`margin-${r}`],a),p=tt(n,t[`padding-${s}`],a),d=tt(n,t[`padding-${r}`],a),f=bt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),g=bt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),m=ae(n,a,j(n,j(n,f,p),j(n,g,d)));return h?(m=ae(n,m,h),!l&&!c?(l=An(n,m,new Fe(n,.5)),c=l):l?c=ae(n,m,l):l=ae(n,m,c)):(l||(l=n.zero),c||(c=n.zero),h=ae(n,m,j(n,l,c))),i.width!==Ni||i.height!==Pi||this.hasBorderOrOutline()||l instanceof Jt&&l.num<0||c instanceof Jt&&c.num<0?(t[s]=new V(l),t[r]=new V(c),t[`margin-${s}`]=le,t[`margin-${r}`]=le,t[`border-${s}-width`]=new V(f),t[`border-${r}-width`]=new V(g)):(t[s]=le,t[r]=le,t[`margin-${s}`]=le,t[`margin-${r}`]=le,t[`border-${s}-width`]=new V(l),t[`border-${r}-width`]=new V(c),t[`border-${s}-style`]=v.solid,t[`border-${r}-style`]=v.solid,t[`border-${s}-color`]=v.transparent,t[`border-${r}-color`]=v.transparent,t["background-clip"]=v.padding_box),t[`padding-${s}`]=new V(p),t[`padding-${r}`]=new V(d),t[o]=new V(h),t[`max-${o}`]=new V(h),{borderBoxExtent:ae(n,a,j(n,l,c)),marginStart:l,marginEnd:c}}hasBorderOrOutline(){let e=t=>{var i;let n=(i=Ve(this.cascaded,t))==null?void 0:i.value;return!!n&&n!==v.none};return e("border-top-style")||e("border-bottom-style")||e("border-left-style")||e("border-right-style")||e("border-block-start-style")||e("border-block-end-style")||e("border-inline-start-style")||e("border-inline-end-style")||e("outline-style")}prepareContainer(e,t,i,n,s){i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=parseFloat(i.pageAreaElement.style.width),e.pageAreaHeight=parseFloat(i.pageAreaElement.style.height)}},jm=class extends hn{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=ho[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){k(t,"display","flex"),k(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&&k(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof ct||s instanceof V&&s.expr instanceof De&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),k(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ue(n,i[o],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new V(c);else if(l){let p=tt(n,i[`margin-${s}`],h),d=tt(n,i[`margin-${r}`],h),f=tt(n,i[`padding-${s}`],h),g=tt(n,i[`padding-${r}`],h),m=bt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),y=bt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),b=j(n,l,j(n,j(n,f,g),j(n,j(n,m,y),j(n,p,d))));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new V(j(n,c,Us(n,ae(n,h,b),new Fe(n,2))));break;case"end":i[s]=new V(ae(n,j(n,c,h),b));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.inside,r=e.outside,o=e.extent,a=t[`margin${r.charAt(0).toUpperCase()}${r.substring(1)}`],h=Ea(n,i[`margin-${s}`],a),l=Ea(n,i[`margin-${r}`],a),c=tt(n,i[`padding-${s}`],a),p=tt(n,i[`padding-${r}`],a),d=bt(n,i[`border-${s}-width`],i[`border-${s}-style`],a),f=bt(n,i[`border-${r}-width`],i[`border-${r}-style`],a),g=ue(n,i[o],a),m=null;function y(b){if(m)return m;m={extent:g?g.evaluate(b):null,marginInside:h?h.evaluate(b):null,marginOutside:l?l.evaluate(b):null};let w=a.evaluate(b),S=0;return[d,c,p,f].forEach(I=>{I&&(S+=I.evaluate(b))}),(m.marginInside===null||m.marginOutside===null)&&S+m.extent+m.marginInside+m.marginOutside>w&&(m.marginInside===null&&(m.marginInside=0),m.marginOutside===null&&(m.marginOutside=0)),m.extent!==null&&m.marginInside!==null&&m.marginOutside!==null&&(m.marginOutside=null),m.extent===null&&m.marginInside!==null&&m.marginOutside!==null?m.extent=w-S-m.marginInside-m.marginOutside:m.extent!==null&&m.marginInside===null&&m.marginOutside!==null?m.marginInside=w-S-m.extent-m.marginOutside:m.extent!==null&&m.marginInside!==null&&m.marginOutside===null?m.marginOutside=w-S-m.extent-m.marginInside:m.extent===null?(m.marginInside=m.marginOutside=0,m.extent=w-S):m.marginInside=m.marginOutside=(w-S-m.extent)/2,m}i[o]=new V(new De(n,function(){let b=y(this).extent;return b===null?0:b},o)),i[`margin-${s}`]=new V(new De(n,function(){let b=y(this).marginInside;return b===null?0:b},`margin-${s}`)),i[`margin-${r}`]=new V(new De(n,function(){let b=y(this).marginOutside;return b===null?0:b},`margin-${r}`)),s==="left"?i.left=new V(j(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new V(j(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,s,r,o){super.finishContainer(e,t,i,n,s,r,o);let a=i.marginBoxes,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))}},Xm=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,u(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new ze(e,"page-number"),s=new Or(e,new bl(e,n,new Fe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Ot(e,s)),e.defineName("verso-page",s),(t.pageProgression||Ou(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new Ot(e,s))):(e.defineName("left-page",new Ot(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===oo?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){let i=this.makeCascadeValueObjectKey(e);return`${t.key}^${i}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof K?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new Hm(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:uo}),n=i.specified,s=e.size;if(s&&!J(s.value)){let o=Qn(e),a=s.priority;Tt(n,"width",new K(o.width,a),this.context),Tt(n,"height",new K(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},qm=class extends ge{constructor(e){super(),this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},Ym=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Km=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Zm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Jm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Qm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},ew=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},tw=class extends bn{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},iw=class extends Kr{constructor(e,t){super(e,t,null,null,null)}apply(e){nw(e.context,e.currentStyle,this.style,this.specificity,e)}};function nw(e,t,i,n,s){Yn(e,t,i,n,null,null,null);let r=i[cn];if(r){let o=us(t,cn);for(let a in r)if(r.hasOwnProperty(a)){let h=o[a];h||(h={},o[a]=h),Yn(e,h,r[a],n,null,null,null)}}}var sw=class extends nn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new qm(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new tw(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 Ym(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Km(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Zm(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Jm(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Qm(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new ew(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=Ve(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{Yt(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new K(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=s[h];l?Tt(l,e,a):(l=s[h]={},Yt(l,e,a),r&&["bleed","marks"].forEach(c=>{r[c]&&Yt(l,c,r[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new iw(this.elementStyle,e)}startPageMarginBoxRule(e){let t=us(this.elementStyle,cn),i=t[e];i||(i={},t[e]=i);let n=new rw(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},rw=class extends gn{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new K(t,n);Yt(this.boxStyle,e,s)}},yt=!0;function ow(e){yt=e}var Kt=[];function La(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function zu(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 co(e,t,i){var n,s;if(!yt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&zu(e.ownerDocument).includes(e))return N(!1);let r=e.textContent,o=e.src,a=e.type==="module",h=(a||o)&&e.async,l=a&&!h||o&&e.defer,c=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||h);if(Du(t)||(t.onload=null),c)return Kt.some(d=>La(d,e))||Kt.push(e),N(!0);if(o.includes("/mathjax")){let d=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(d){if(o.includes("/mathjax@3"))t.document.head.removeChild(d),(s=(n=t.MathJax)==null?void 0:n.version)!=null&&s.startsWith("2.")&&delete t.MathJax;else if(o.includes("/MathJax.js"))return N(!0)}}for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&La(d,e)&&t.document.head.removeChild(d);let p=t.document.createElement("script");p.textContent=r,o&&(p.src=o),p.async=h,p.defer=l,p.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||p.setAttribute(d.name,d.value);if(D.debug("script:",o),o){let d=si(p);return t.document.head.appendChild(p),os([d])}else return t.document.head.appendChild(p),N(!0)}function aw(e,t){var i;let n={},s=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let c of Object.values(l))s(c)},r=o=>{if(o instanceof Kr)s(o.style);else if(o instanceof Ii||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function lw(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=aw(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function hw(e,t,i){if(!yt)return N(!1);let n=zu(e);if(n.length===0)return N(!1);let s=n.some(c=>!(c.async||c.defer||c.type==="module")),r=s?lw(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=F("loadScripts");return l.loop(()=>{if(n.length===0)return s?l.sleep(20).thenAsync(()=>{var p,d;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(p=t.FontJSON)!=null&&p.Font&&(d=t.ret)!=null&&d.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let c=n.shift();return co(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Kt.push(c),h=!0),n.length===0&&s&&(D.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),l.finish(!0)}),l.result()}function uw(e){if(!yt)return N(!1);let t=F("loadScripts");return t.loop(()=>Kt.length===0?N(!1):co(Kt.shift(),e,{atEnd:!0}).thenReturn(Kt.length>0)).then(()=>{D.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),D.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Du(e){return yt?Kt.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var cw=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),dw={};function pw(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Vu=class Cr extends Rr{constructor(t,i,n,s,r,o,a,h,l,c,p,d,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=c,this.customRenderer=p,this.fallbackMap=d,this.documentURLTransformer=f,u(this,"document"),u(this,"exprContentListener"),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new 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)}createPseudoelementShadow(t,i,n,s,r,o,a,h){let l=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!l)return h;let c=[],p=On.createElementNS("http://www.pyroxy.com/ns/shadow","root"),d=p;for(let g of hg){let m;if(g){if(!l[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let y=s.display;if(!y||y===v.inline)continue;let b=t.firstElementChild;if(b&&Ue(b.previousSibling)){let w=r.getStyle(b,!1);if(w){let S=Ve(w,"display");if(S!=null&&S.value&&S.value!==v.inline)continue}}}if(g==="before"||g==="after"){let y=l[g].content;if(!y||!Dt(y.value))continue}c.push(g),m=On.createElementNS("http://www.w3.org/1999/xhtml","span"),mr(m,g)}else m=On.createElementNS("http://www.pyroxy.com/ns/shadow","content");d.appendChild(m),g.match(/^first-/)&&(d=m)}if(!c.length)return h;let f=new fa(t,n,r,o,this.exprContentListener);return new Zs(t,p,null,a,h,rt.ROOTLESS,f)}getPseudoMap(t,i,n,s,r){let o=dt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Yi(l,o[h],r),gr(l,r,o[h]),jh(o[h],i,n,(c,p)=>{Yi(l,p,r),Hh(p,d=>{Yi(l,d,r)})})}return a}createRefShadow(t,i,n,s,r){let o=F("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);r=new Zs(n,l,h,s,r,i,c)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let h=F("createShadows"),l=null,c=s.template,p;if(c instanceof ct||c===v.footnote){let d=c instanceof ct?c.url:ke("user-agent.xml#footnote",Zt);p=this.createRefShadow(d,rt.ROOTLESS,t,a,l)}else p=N(l);return p.then(d=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),y=null;m?y=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),y=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=ke(m,y.url),f=this.createRefShadow(m,rt.ROOTED,t,a,d))}f==null&&(f=N(d));let g=null;f.then(m=>{if(s.display===v.table_cell){let y=ke("user-agent.xml#table-cell",Zt);g=this.createRefShadow(y,rt.ROOTLESS,t,a,m)}else g=N(m);g.then(y=>{y=this.createPseudoelementShadow(t,i,n,s,r,o,a,y),h.finish(y)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=Wh(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((r=this.nodeContext)!=null&&r.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=$h(a,o,t);let c=!h&&t!==l;if(i=Gh(a,o,i),Xh(a,s,t,i,(m,y)=>{let b;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(m)&&(b=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(m)&&(b=o.pageAreaWidth));let w=y.evaluate(o,m,b,t);return m=="font-family"&&(w=this.docFaces.filterFontFamily(w)),w}),c){let m=s[t?"height":"width"];(!m||m===v.auto)&&(s[t?"height":"width"]=v.max_content)}if(er(s.position))return s.position=v.fixed,s.visibility=v.hidden,t;let p=s.position,d=s.float,f=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),g=yh(f,p,d,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(m=>{g[m]&&(s[m]=g[m])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let p=r&&r.root==i;if(!p||r.type==rt.ROOTLESS){let d=(r?r.styler:this.styler).getStyle(i,!1);n.push(d),s=s||Bs(i)}p?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,h=this.context.queryUnitSize("em",a),l={"font-size":new K(new T(h,"px"),0)},c=new pf(l,this.context);for(let p=n.length-1;p>=0;--p){let d=n[p],f=[];for(let y in d)Xi(y)&&f.push(y);f.sort(Bo);let g,m;for(let y of f){c.setPropName(y);let b=Ve(d,y),w=b;J(b.value)||(y==="font-size"&&p===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize?w=new K(new T(this.context.rootFontSize,"px"),b.priority):y==="line-height"&&p===n.length-1&&this.context.rootLineHeight&&b.value instanceof T&&(b.value.unit==="lh"||b.value.unit==="rlh")?w=new K(new T(this.context.rootLineHeight,"px"),b.priority):p===0&&b.value instanceof T&&b.value.unit==="lh"?w=new K(new T(b.value.num*this.getLineHeightUnitSize(y,g,m),"px"),b.priority):Nt(y)||(w=b.filterValue(c)),y==="font-size"?g=w.value:y==="line-height"&&(m=w.value),l[y]=w)}}for(let p in t)Xi(p)||(l[p]=t[p]);return{lang:s,elementStyle:l}}resolveURL(t){return t=ke(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Bs(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=rf().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(J(r))r===v.initial&&(n[s]=void 0);else if(r instanceof Qt)n[s]=r.num;else if(r instanceof ft)n[s]=r.name;else if(r instanceof T){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*we[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=pt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,s,r,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,s,r,o;let a=!0,h=F("createElementView"),l=this.sourceNode,c=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,p=c.getStyle(l,!1);if(!this.nodeContext.shadowContext){let I=this.xmldoc.getElementOffset(l);ls.registerFragmentIndex(I,this.nodeContext.fragmentIndex,0)}let d={};if(!this.nodeContext.parent){let I=this.inheritFromSourceParent(p);p=I.elementStyle,this.nodeContext.lang=I.lang}let f=p.position,g=p.float,m=p["float-reference"],y=g&&!J(g.value)&&g.value!==v.none&&m&&!J(m.value)?Up(m.value.toString()):null;if(this.nodeContext.parent&&(er(f?.value)||y&&gi(y))){let I=this.inheritFromSourceParent(p);p=I.elementStyle,this.nodeContext.lang=I.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",p,d),y&&gi(y)&&d.display===v.block&&(d.display=v.flow_root),c.processContent(l,d,(s=this.nodeContext.viewNode)!=null?s:(n=this.nodeContext.parent)==null?void 0:n.viewNode),this.transferPolyfilledInheritedProps(d),this.inheritLangAttribute(),d.direction&&(this.nodeContext.direction=d.direction.toString());let b=d["flow-into"];if(b&&b.toString()!=this.flowName)return h.finish(!1),h.result();if(yt&&l.localName==="script"&&l.namespaceURI==="http://www.w3.org/1999/xhtml")return co(l,this.viewport.window).thenFinish(h),h.result();let w=d.display;if(J(w)&&(w===v.initial||w===v.unset?w=v.inline:w===v.inherit?w=((r=this.nodeContext.parent)==null?void 0:r.display)&&B((o=this.nodeContext.parent)==null?void 0:o.display):w=null),w===v.none)return h.finish(!1),h.result();let S=this.nodeContext.parent==null;return this.nodeContext.flexContainer=w===v.flex,this.createShadows(l,S,p,d,c,this.context,this.nodeContext.shadowContext).then(I=>{var L,_;this.nodeContext.nodeShadow=I;let U=d.position,W=d.float,re=d.clear,He=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,de=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:He,pe=qp(l);this.nodeContext.establishesBFC=Yp(w,U,W,d.overflow,He,de,pe),this.nodeContext.containingBlockForAbsolute=Kp(U),this.nodeContext.isInsideBFC()&&W!==v.footnote&&!(y&&gi(y))&&(W=null,re=null);let x=W instanceof ve||W===v.left||W===v.right||W===v.top||W===v.bottom||W===v.inline_start||W===v.inline_end||W===v.block_start||W===v.block_end||W===v.snap_block||W===v.snap_inline||W===v.footnote;W&&(delete d.float,W===v.footnote&&(this.isFootnote?(x=!1,d.display=v.block):d.display=v.inline)),re&&(re===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(re=B(this.nodeContext.parent.clearSide)),(re===v.left||re===v.right||re===v.top||re===v.bottom||re===v.inline_start||re===v.inline_end||re===v.block_start||re===v.block_end||re===v.both||re===v.all||re===v.same)&&(delete d.clear,d.display&&d.display!=v.inline&&(this.nodeContext.clearSide=re.toString())));let P=w===v.list_item&&d["ua-list-item-count"],C=d["break-inside"];(x||C&&!J(C)&&C!==v.auto)&&this.nodeContext.breakPenalty++,w&&w!==v.inline&&Xt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!x&&!w||Xt(w)||xh(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=x?W.toString():null,this.nodeContext.floatReference=y||Re.INLINE;let E=d["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=E&&!J(E)?E:null;let A=this.isInsideNonRootMultiColumn(),R=d["column-span"];if(this.nodeContext.columnSpan=!A&&R&&!J(R)?R:null,!this.nodeContext.inline){let M=d["break-after"];M&&!J(M)&&!(A&&M===v.column)&&(this.nodeContext.breakAfter=M.toString(),qs[this.nodeContext.breakAfter]&&delete d["break-after"]);let Q=d["break-before"];Q&&!J(Q)&&!(A&&Q===v.column)&&(this.nodeContext.fragmentIndex===1&&(this.nodeContext.breakBefore=Q.toString()),qs[this.nodeContext.breakBefore]&&delete d["break-before"]);let ee=d.page,he=ee&&!J(ee)&&ee.toString();!he&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||w===v.table_header_group||w===v.table_footer_group)&&(he=this.styler.cascade.currentPageType),!he||he.toLowerCase()==="auto"?he=this.nodeContext.pageType:this.nodeContext.pageType=he,this.styler.cascade.currentPageType!==he&&!(!he&&d.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!tn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),he!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=he)}this.nodeContext.verticalAlign=d["vertical-align"]&&d["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=d["caption-side"]&&d["caption-side"].toString()||"top";let O=d["border-collapse"];if(!O||O===B("separate")){let M=d["border-spacing"],Q,ee;M&&(M instanceof ve?(Q=M.values[0],ee=M.values[1]):Q=ee=M,Q.isNumeric()&&(this.nodeContext.inlineBorderSpacing=We(Q,this.context)),ee.isNumeric()&&(this.nodeContext.blockBorderSpacing=We(ee,this.context)))}let z=d["footnote-policy"];this.nodeContext.footnotePolicy=z&&!J(z)?z:null;let $=d["x-first-pseudo"];if($){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Mp(M,$.num)}this.nodeContext.inline||this.processAfterIfcontinues(l,p,c,this.context);let X=d["white-space"];if(X){let M=lh(X.toString());M!==null&&(this.nodeContext.whitespace=M)}let Y=d["hyphenate-character"];Y&&Y instanceof Ae&&(this.nodeContext.hyphenateCharacter=Y.str);let q=d["word-break"],me=d["line-break"],te=d["overflow-wrap"];(q===v.break_all||me===v.anywhere||te===v.break_word||te===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,w,U,W,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(d),this.findAndProcessRepeatingElements(l,c));let se=!1,ye=null,be=[],Z=l.namespaceURI,H=l.localName;if(Z=="http://www.w3.org/1999/xhtml"?(H=="html"||H=="body"||H=="script"||H=="link"||H=="meta"?H="div":H=="vide_"?H="video":H=="audi_"?H="audio":H=="object"&&(se=!!this.customRenderer),l.getAttribute(eo)&&(_=(L=p.content)==null?void 0:L.value)!=null&&_.url&&(H="img")):Z=="http://www.idpf.org/2007/ops"?(H="span",Z="http://www.w3.org/1999/xhtml"):Z=="http://www.pyroxy.com/ns/shadow"?(Z="http://www.w3.org/1999/xhtml",H=this.nodeContext.inline?"span":"div"):se=!!this.customRenderer,P)t?H="li":(H="div",w=v.block,d.display=w);else if(H=="body"||H=="li")H="div";else if(H=="q")H="span";else if(H=="a"){let M=d["hyperlink-processing"];M&&M.toString()!="normal"&&(H="span")}d.behavior&&d.behavior.toString()!="none"&&this.customRenderer&&(se=!0),l.dataset&&l.getAttribute("data-math-typeset")==="true"&&(se=!0);let oe;if(se){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;oe=this.customRenderer(l,M,d)}else oe=N(null);oe.then(M=>{if(M)se&&(a=M.getAttribute("data-adapt-process-children")=="true");else if(d.display===v.none){h.finish(!1);return}else M=this.createElement(Z,H);H=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),ye&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ye),M.appendChild(ye)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&pw(M);let Q=this.nodeContext.inheritedProps["image-resolution"],ee=[],he=d.width,Ye=d.height,ec=l.getAttribute("width"),tc=l.getAttribute("height"),ms=he===v.auto||!he&&!ec,ws=Ye===v.auto||!Ye&&!tc,fo=l.attributes,ic=fo.length,yn=null,go=null;for(let st=0;st<ic;st++){let mt=fo[st],Je=mt.namespaceURI,ie=mt.localName,Ne=mt.nodeValue;if(Je){if(Je=="http://www.w3.org/2000/xmlns/")continue;Je=="http://www.w3.org/1999/xlink"&&ie=="href"&&(Ne=this.documentURLTransformer.transformURL(this.resolveURL(Ne),this.xmldoc.url))}else{if(!yt&&ie.match(/^on/)||ie=="style")continue;if((ie=="id"||ie=="name")&&t){let Be=this.documentURLTransformer.transformFragment(Ne,this.xmldoc.url);if(yt&&M.localName!=="tr"&&!(M.namespaceURI==="http://www.w3.org/2000/svg"&&M.localName!=="svg")&&!M.ownerDocument.getElementById(Ne)){M.setAttribute(ie,Ne),M.setAttribute("data-vivliostyle-id",Be);let Ut=M.ownerDocument.createElement("a");Ut.setAttribute(ie,Be),Ut.setAttribute(xi,"1"),Ut.style.position="absolute",M.appendChild(Ut)}else M.setAttribute(ie,Be);this.page.registerElementWithId(M,Be);continue}if(ie=="src"||ie=="href"||ie=="poster")Ne=this.resolveURL(Ne),ie==="href"&&(Ne=this.documentURLTransformer.transformURL(Ne,this.xmldoc.url));else if(ie=="srcset")Ne=Ne.split(",").map(Be=>this.resolveURL(Be.trim())).join(",");else if(ie==="data"&&se&&H==="object"&&M.hasAttribute("data"))continue;if(ie==="poster"&&H==="video"&&Z==="http://www.w3.org/1999/xhtml"&&ms&&ws){let Be=new Image,Ut=si(Be,Ne);be.push(Ut),ee.push({image:Be,element:M,fetcher:Ut})}}if(Z=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ie)&&(ie=ie.toLowerCase()),this.isSVGUrlAttribute(ie)&&(Ne=cw(Ne,this.xmldoc.url,this.documentURLTransformer)),Je){let Be=dw[Je];Be&&(ie=`${Be}:${ie}`)}if(ie=="src"&&!Je&&(H=="img"||H=="input")&&Z=="http://www.w3.org/1999/xhtml")yn=Ne;else if(ie=="alt"&&!Je&&H=="img"&&Z=="http://www.w3.org/1999/xhtml")go=Ne;else if(ie=="href"&&H=="image"&&Z=="http://www.w3.org/2000/svg"&&Je=="http://www.w3.org/1999/xlink")this.page.fetchers.push(si(M,Ne));else if(Je)M.setAttributeNS(Je,ie,Ne);else try{M.setAttribute(ie,Ne)}catch(Be){D.warn(Be)}}if(yn){let st=H==="input"?new Image:M,mt=si(st,yn,go);st!==M&&(M.src=yn);let Je=()=>{var ie,Ne;if(d.position===v.fixed)return!0;for(let Be=(ie=this.nodeContext.parent)==null?void 0:ie.viewNode;Be&&Be!==this.viewRoot;Be=Be.parentElement)if(((Ne=Be.style)==null?void 0:Ne.position)==="fixed")return!0;return!1};!ms&&!ws&&!(()=>{let ie=this.nodeContext.vertical?he:Ye;return ie instanceof T&&ie.unit==="%"})()&&!Je()?this.page.fetchers.push(mt):(ms&&ws&&Q&&Q!==1&&ee.push({image:st,element:M,fetcher:mt}),be.push(mt))}delete d.content;let bs=d["list-style-image"];if(bs&&bs instanceof ct){let st=bs.url;be.push(si(new Image,st))}if(this.preprocessElementStyle(d),this.applyComputedStyles(M,d),this.nodeContext.inline)t||(it(M,"inline-start"),_i(M)&&it(M,"clone"));else if(!t)it(M,"block-start"),_i(M)&&it(M,"clone"),Is(M,"block-start");else if(!$r(d.position)){let st=d["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),Je=mt!==null,ie=mt==="auto";(st===v.discard&&Je||st!==v.keep&&ie&&!this.nodeContext.floatSide)&&Is(M,"block-start")}P&&M.setAttribute("value",d["ua-list-item-count"].stringValue()),this.viewNode=M,be.length?os(be).then(()=>{Q>0&&this.modifyElemDimensionWithImageResolution(ee,Q,d,this.nodeContext.vertical),h.finish(a)}):h.timeSlice().then(()=>{h.finish(a)})})}),h.result()}isInsideNonRootMultiColumn(){var t;for(let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;i;i=i.parentNode){let n=i.nodeType===1?i.style:null;if(!n)break;if(!isNaN(parseFloat(n.columnCount))||!isNaN(parseFloat(n.columnWidth)))return!0;if(n.position==="absolute")break}return!1}getBreakTypeAt(t){var i,n,s,r,o;for(let h=t;h&&!h.after;h=h.parent){if(Ke(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),p=parseFloat(c.paddingBlockStart),d=parseFloat(c.borderBlockStartWidth);if(p||d)return null;let f=l?.firstChild;for(;f&&(Ue(f,h.parent.whitespace)||!h.floatSide&&Ln(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Ke(a)?a:"auto"}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new fa(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new cg(t,o)}}isSVGUrlAttribute(t){return Cr.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,h=o.height/i,l=r.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=We(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=We(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=We(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=We(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||v.none,p=n["max-height"]||v.none;if(c===v.none&&p===v.none)k(l,"max-width",`${a}px`);else if(c!==v.none&&p===v.none)k(l,"width",`${a}px`);else if(c===v.none&&p!==v.none)k(l,"height",`${h}px`);else{c.isNumeric(),p.isNumeric();let d=c,f=p;d.unit!=="%"?k(l,"max-width",`${Math.min(a,We(d,this.context))}px`):f.unit!=="%"?k(l,"max-height",`${Math.min(h,We(f,this.context))}px`):s?k(l,"height",`${h}px`):k(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||le,p=n["min-height"]||le;c.isNumeric(),c.isNumeric();let d=c,f=p;d.num===0&&f.num===0?k(l,"min-width",`${a}px`):d.num!==0&&f.num===0?k(l,"width",`${a}px`):d.num===0&&f.num!==0?k(l,"height",`${h}px`):d.unit!=="%"?k(l,"min-width",`${Math.max(a,We(d,this.context))}px`):f.unit!=="%"?k(l,"min-height",`${Math.max(h,We(f,this.context))}px`):s?k(l,"height",`${h}px`):k(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){pt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof ei&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new ei(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||J(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=F("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Xo(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=F("preprocessTextContent"),s=pt("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=kp(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=F("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(p,d)=>p?.nodeType===1&&di(p)===d,l=this.nodeContext.parent,c=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;c&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Ue(this.viewNode))&&!c.hasChildNodes()&&sh(c).includes("block-start")&&it(c,"text-start"),c.appendChild(this.viewNode))}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==rt.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=rt.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let l=new zi(r,s,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,l}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=rt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==rt.ROOTLESS&&(s=s.firstChild),s){let r=new zi(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new zi(n,t,i));if(t.sourceNode.nodeType!=1){let s=Xo(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=Ve(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=F("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof qe){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ct){let i=t.url;this.page.fetchers.push(si(new Image,i))}}applyComputedStyles(t,i){var n,s,r;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===v.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),l=Object.keys(i);l.sort(Bo);let c,p;for(let d of l){if(gw[d])continue;let f=i[d];if(!(!f||f===G&&!Nt(d))){if(f=f.visit(new xd(this.xmldoc.url,this.documentURLTransformer)),f instanceof T&&ul(f.unit)&&(f.unit==="lh"?f=new T(f.num*this.getLineHeightUnitSize(d,c,p),"px"):f=Il(f,this.context)),d==="font-size"?c=f:d==="line-height"&&(p=f),Tp[d]||a&&Ip[d]){this.page.delayedItems.push(new Hr(t,d,f));continue}h&&this.page.pageAreaElement&&Xi(d)?k(this.page.pageAreaElement.parentElement,d,f.toString()):k(t,d,f.toString())}}}getLineHeightUnitSize(t,i,n){var s,r,o,a;let h=we.lh/we.em,l=((r=(s=this.nodeContext.parent)==null?void 0:s.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,c=l?parseFloat(l.fontSize):this.context.fontSize(),p=l?l.lineHeight==="normal"?c*h:parseFloat(l.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return p;let d=null;if(n){if(n instanceof Vt||n instanceof T&&(n.unit==="em"||n.unit==="%"))d=n instanceof T&&n.unit==="%"?n.num/100:n.num;else if(n instanceof T)return n.num*this.context.queryUnitSize(n.unit,!1)}else for(let f=(o=this.nodeContext.parent)==null?void 0:o.viewNode;;f=f.parentNode){if(!f||f.nodeType!==1){d=h;break}let g=(a=f?.style)==null?void 0:a.lineHeight;if(g){/^[0-9.]+$/.test(g)&&(d=parseFloat(g)),g==="normal"&&(d=h);break}}return d!==null?i instanceof T?d*Fh(i,c,this.context).num:d*c:p}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=dt(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let h=a.content;Dt(h)&&(h.visit(new qn(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=F("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let p=t.viewNode.textContent;t.viewNode.textContent=p.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let p=t.viewNode.parentNode;p&&p.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===s;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new zi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=r,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let p=this.setCurrent(t,!1);if(p.isPending())return p}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},r=dt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");mr(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=Ve(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!Xt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=r;h;h=h.parent){if(((s=h.viewNode)==null?void 0:s.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(it(l,"inline-end"),_i(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;it(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{if(it(l,"block-end"),!a++&&h!==r){let{textAlign:c}=this.viewport.window.getComputedStyle(l);if(c==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?rh(p,["block-start","text-start","block-end","text-end","justify"]):(it(l,"text-end"),it(l,"justify")):it(l,"text-end")}else it(l,"text-end")}_i(l)&&it(l,"clone"),Is(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||jt[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let l=r.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===r.lastChild&&Ue(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let p=i(c);if(p||p===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||r.hasAttribute(xi)){let l=r.previousElementSibling;return l&&(l.nextSibling===r||l.nextSibling===r.previousSibling&&Ue(l.nextSibling))?i(l):!1}return!(!o||Xt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ue(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if($c(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Yr(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&di(n)===di(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!di(t)}};u(Vu,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var fw=Vu,gw={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},Dn=null,mw=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"scaleRatio"),this.layoutBox=e.layoutBox,this.window=e.window,this.scaleRatio=e.scaleRatio}scaleRect(e){return Dn?{left:e.left*this.scaleRatio,top:e.top*this.scaleRatio,right:e.right*this.scaleRatio,bottom:e.bottom*this.scaleRatio,width:e.width*this.scaleRatio,height:e.height*this.scaleRatio}:e}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.scaleRect(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.scaleRect(this.subtractOffsets(t,i))}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){let t=64*(this.scaleRatio||1);return Math.floor(e*t)/t}},es=class{constructor(e,t,i,n,s,r){this.window=e,this.fontSize=t,this.pixelRatio=i,u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),this.root.appendChild(o));let a=o.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(k(this.root,"--viv-outputPixelRatio",`${i}`),k(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio,Dn===null&&(Dn=!("currentCSSZoom"in a)),Dn&&k(this.root,"--viv-scaleRectRatio",`${this.scaleRatio}`));let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&c)&&(this.width=l.width),(!this.height||!r&&c)&&(this.height=l.height)}resetZoom(){k(this.outerZoomBox,"width",""),k(this.outerZoomBox,"height",""),k(this.contentContainer,"width",""),k(this.contentContainer,"height",""),k(this.contentContainer,"transform","")}zoom(e,t,i){k(this.root,"--viv-outputScale",`${i}`),k(this.outerZoomBox,"width",`${e*i}px`),k(this.outerZoomBox,"height",`${t*i}px`),k(this.contentContainer,"width",`${e}px`),k(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},Uu=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(xt,"0")}doc(){return new $u([this.document])}getElementOffset(e){let t=e.getAttribute(xt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(xt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=Bt(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Er=(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))(Er||{});function In(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function ww(e){let t=e.contentType;if(t){let n=Object.keys(Er);for(let s=0;s<n.length;s++)if(Er[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./]+)$/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Hu(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=ww(e);if(i=In(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=In(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=In(r,"image/svg+xml",s))}i||(i=In(r,"text/html",s))}}let n=i?new Uu(t,e.url,i):null;return N(n)}function bw(){return new zr(Hu,"document")}var yw=class kr{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new kr(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new kr(n=>{if(!this.check(n))return!1;let s=new $u([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},Fa=new yw(e=>!0),$u=class Nr{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Nr(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new Nr(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},vw=new fn(()=>{let e=F("uaStylesheetBase"),t=Eu(),i=ke("user-agent-base.css",Zt),n=new nn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Yf(n.cascade),Vr(Gl,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function xw(){return vw.get()}var Sw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,d=p.currentLayoutPosition,f=d.firstFlowChunkOfFlow(c);return p.matchPageSide(d.startSideOfFlow(c))&&d.hasContent(c,p.lookupOffset)&&!!f&&!p.flowChunkIsAfterParentFlowForcedBreak(f)}),this.pageScope.defineName("page-number",new De(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new De(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Ds(this.rootScope,e,t,i),r=df(s,this.viewportProps),o=r.width,a=r.height,h=r["text-zoom"],l=1;if(o&&a||h){let c=we.em;if((h?h.evaluate(s,"text-zoom"):null)===v.scale&&(l=c/i,i=c,e*=l,t*=l),o&&a){let p=We(o.evaluate(s,"width"),s),d=We(a.evaluate(s,"height"),s);if(p>0&&d>0)return{width:n&&n.spreadView?(p+n.pageBorder)*2:p,height:d,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},Gu=class extends Ds{constructor(e,t,i,n,s,r,o,a,h,l,c,p,d){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=c,u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Em(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Di(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!d;for(let f in e.flowProps){let g=e.flowProps[f],m=Ve(g,"flow-consume");m&&(m.evaluate(this,"flow-consume")==v.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=F("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new ya(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=Ou(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new Rm(s);let r=this.style.cascade.createInstance(this,t,i,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new Xm(r,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Cm(h.properties,this),c=new ku(l);o.push(c)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{hw(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context);let c=Ra(Qn(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 Ds(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new ya(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r),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 Dp,i.flowPositions[e.flowName]=n);let s=_p(e.element),r=new zt(s),o=new zp(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,c){}}let r=new s,o=Ti(this.style.rootScope,new gt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new Wu(null),i=new gt(e+"{}",t);return new mn(Ee,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let h=this.xmldoc.getNodeOffset(s,r,o);h<t&&(t=h)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){D.debug("Location - page",this.currentLayoutPosition.page),D.debug(" current:",e),D.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)D.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new ze(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=jo(Xe(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===uo)continue;let o=1;s.pageBox.pseudoName===oo&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(o*l/(h*h)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=p,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let d=s.getProp(this,"enabled");if(!d||d===v._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=Bt(s.length,l=>s[l]>n)-1,o=s[r],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new jr(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Re.PAGE)return!1;let h=this.layoutPositionAtPageStart.flowPositions.body,l=h&&this.getConsumedOffset(h),c=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return c!=null&&l!=null&&c>l},s=F("layoutDeferredPageFloats"),r=!1,o=0;return s.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let h=i[o++],l=h.float;if(n(l)){a.breakLoop();return}let c=new Si().findByFloat(l),p=c.findPageFloatFragment(l,t);if(p&&p.hasFloat(l)){a.continueLoop();return}else if(t.isForbidden(l)||t.hasPrecedingFloatsDeferredToNext(l)){t.deferPageFloat(h),a.breakLoop();return}e.layoutPageFloatInner(h,c,null,p).then(d=>{if(!d){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new zt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=F("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let h=0;for(;r.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let d=h+1;d<i.positions.length;d++){if(r.includes(d))continue;let f=i.positions[d];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=d)}let c=l.flowChunk,p=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(d=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(d===null||c.exclusive)&&s.push(h),c.exclusive){r.push(h),a.breakLoop();return}else{let f=!!d||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,d);if(e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(r.push(h),(d||g)&&(l.chunkPosition=d||g,s.push(h)),i.startBreakType=jo(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:a.continueLoop()}),p){p=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>s.includes(l)||!r.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new mg([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,h,l,c,p,d,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=s.element,y=new Di(a,Re.COLUMN,null,o,null,null,null),b=this.currentLayoutPosition.clone(),w=F("createAndLayoutColumn"),S;return w.loopWithFrame(I=>{let L=this.createLayoutConstraint(y);if(h>1){let _=this.viewport.document.createElement("div");if(k(_,"position","absolute"),m.appendChild(_),S=new Zn(_,d,this.clientLayout,L,y),S.forceNonfitting=f,S.vertical=s.vertical,S.rtl=s.rtl,S.snapHeight=s.snapHeight,S.snapWidth=s.snapWidth,s.vertical){let U=(s.rtl?h-r-1:r)*(c+l)+s.paddingTop,W=parseFloat(m.style.width);S.setHorizontalPosition(s.paddingLeft+W-s.width,s.width),S.setVerticalPosition(U,c)}else{let U=(s.rtl?h-r-1:r)*(c+l)+s.paddingLeft;S.setVerticalPosition(s.paddingTop,s.height),S.setHorizontalPosition(U,c)}S.originX=t,S.originY=i}else S=new Zn(m,d,this.clientLayout,L,y),S.copyFrom(s);S.exclusions=g?[]:n.concat(),S.innerShape=p,y.setContainer(S),S.width>=0?this.layoutColumn(S,o).then(()=>{y.isInvalidated()||y.finish(),S.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=b.clone(),S.element!==m&&m.removeChild(S.element),I.continueLoop()):I.breakLoop()}):(y.finish(),I.breakLoop())}).then(()=>{w.finish(S)}),w.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Mu||t instanceof ao&&!(t instanceof zn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof hn;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new Di(e,Re.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(r,t,o,a),p=!0,d=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,s,r,c,o,a,h,p).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return d().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let g=t.getProp(this,"column-fill")||v.balance,m=this.currentLayoutPosition.flowPositions[a],y=sm(h,g,d,c,o,f.columns,m);return y?(p=!1,r.lock(),c.lock(),y.balanceColumns(f).thenAsync(b=>(r.unlock(),r.validate(),c.unlock(),this.currentLayoutPosition=b.position,N(b.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,h,l,c){let p=F("layoutFlowColumns"),d=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),g=l>1?t.getPropAsNumber(this,"column-width"):a.width,m=t.getActiveRegions(this),y=t.getProp(this,"shape-inside"),b=Ol(y,0,0,a.width,a.height,this),w=new fw(h,this,this.viewport,this.styler,m,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,I=null,L=[];return p.loopWithFrame(_=>{this.createAndLayoutColumn(t,i,n,s,a,S++,h,o,l,f,g,b,w,c).then(U=>{if(r.isInvalidated()){L=null,_.breakLoop();return}if((U.pageBreakType&&U.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=d.clone(),o.validate(),o.isLocked()?(L=null,_.breakLoop()):_.continueLoop();return}I=U,L[S-1]=I,I.pageBreakType&&I.pageBreakType!="column"&&(S=l,I.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?_.continueLoop():_.breakLoop()})}).then(()=>{p.finish(L)}),p.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return N(!0);let h=F("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,c=t.getProp(this,"flow-from"),p=this.viewport.document.createElement("div"),d=t.getProp(this,"position");k(p,"position",d?d.name:"absolute");let f=t instanceof zn;t instanceof hn?i.appendChild(p):i.insertBefore(p,i.firstChild);let g=new gh(p);g.vertical=t.vertical,g.rtl=t.rtl,g.exclusions=r,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof zn&&(g.width<=0||g.height<=0)&&D.warn("Negative or zero page area size"),g.originX=n,g.originY=s,n+=g.left+g.marginLeft+g.borderLeft,s+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let m,y=!1;if(!c||!c.isIdent()){let b=t.getProp(this,"content");if(b instanceof V&&b.expr instanceof De&&b.expr.str.startsWith("running-element-"))b.visit(new qn(p,this,b,this.counterStore.getExprContentListener()));else if(b&&Dt(b)){let w="span";b.url&&(w="img");let S=this.viewport.document.createElement(w);b.visit(new qn(S,this,b,this.counterStore.getExprContentListener())),p.appendChild(S),w=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces),w=="span"&&lg(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(p),y=!0);y||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0)}else if(this.pageBreaks[c.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0);else{let b=F("layoutContainer.inner"),w=c.toString(),S=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,g,w,S).then(I=>{if(!o.isInvalidated()){let L=I[0];L.element===p&&(g=L),g.computedBlockSize=Math.max.apply(null,I.map(U=>U.computedBlockSize)),t.finishContainer(this,g,e,L,S,this.clientLayout,this.faces);let _=this.currentLayoutPosition.flowPositions[w];_&&_.breakAfter==="region"&&(_.breakAfter=null)}b.finish(!0)}),m=b.result()}return m.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!y&&!l){let w=t.getProp(this,"shape-outside"),S=g.getOuterShape(w,this);r.push(S)}}else if(t.children.length==0){i.removeChild(p),h.finish(!0);return}let b=f?0:t.children.length-1;h.loop(()=>{for(;b>=0&&b<t.children.length;){let w=t.children[f?b++:b--],S=this.layoutContainer(e,w,p,n,s,r,o);if(S.isPending())return S.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Vp,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);t.page++;let r=t.startSideOfFlow("body");t.isBlankPage=tn(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let o=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);this.styler.cascade.applyVarFilter([o],this.styler,null),this.styler.cascade.applyCalcFilter(o,this.styler.context);let a=this.selectPageMaster(o);if(!a)return N(null);let h=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===Ni),e.setAutoPageHeight(a.pageBox.specified.height.value===Pi),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(o,this);let f=Ra(Qn(o),this);this.setPageSizeAndBleed(f,e),Vm(o,f,e,this),h=f.bleedOffset+f.bleed}let l=!n&&a.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=l!=v.horizontal_tb;let c=a.getProp(this,"direction")||v.ltr,p=new Di(this.rootPageFloatLayoutContext,Re.PAGE,null,null,null,l,c),d=F("layoutNextPage");return d.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,h,h,[],p).then(()=>{p.isInvalidated()||p.finish(),p.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),p.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{if(a.adjustPageLayout(this,e,this.clientLayout),!n){let g=new ze(a.pageBox.scope,"left-page");e.side=g.evaluate(this)?"left":"right",this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let y=t.flowPositions[m],b=y.breakAfter;b&&(b==="page"||!this.matchPageSide(b))&&(y.breakAfter=null)})}this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),d.finish(t)}),d.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},Cw=class Pr extends nn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new Nu(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Fm(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=lt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Pr(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new eg(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new Tn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new Tn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new Tn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=us(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new Tn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new sw(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(nn.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 Pr(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Wu=class extends hp{constructor(e){super(),this.validatorSet=e,u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new zs(null),this.pageScope=new zs(this.rootScope),this.rootBox=new Pm(this.rootScope),this.cascadeParserHandler=new Cw(this,null,null,null),this.slave=this.cascadeParserHandler}};function Ew(e,t){return t.parseOPSResource(e)}var kw=class extends zr{constructor(e){super(Ew,"document"),this.fontDeobfuscator=e,u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=F("OPSDocStore.init");return this.validatorSet=Eu(),xw().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=ke(en(t),yi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=ke(en(t),yi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=F("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return Hu(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let d=pt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<d.length;f++)try{d[f](s.document)}catch(g){D.warn("Error during single document preprocessing:",g)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let d=0;d<a.length;d++){let f=a[d],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),y=f.getAttribute("action"),b=f.getAttribute("ref");g&&m&&y&&b&&o.push({observer:g,event:m,action:y,ref:b})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:ke("user-agent-page.css",Zt),text:$l,flavor:"UA",classes:null,media:null}),n)h.push({url:ke("user-agent-toc.css",Zt),text:Wl,flavor:"UA",classes:null,media:null});else{let d=s.document.querySelectorAll("style, link, meta");for(let f of d){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let y=f.getAttribute("class"),b=f.getAttribute("media"),w=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:w?y:null,media:b})}else if(m=="link"){let y=f.getAttribute("href"),b=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),w=f.getAttribute("class"),S=f.getAttribute("media");if(y&&b!=null&&b.includes("stylesheet")&&(!b.includes("alternate")||w)){let I=ke(y,i),L=f.getAttribute("title");h.push({url:I,text:null,classes:L?w:null,media:S,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 d=0;d<h.length;d++)l+=h[d].url,l+="^",h[d].text&&(l+=h[d].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(s);return}let p=this.styleFetcherByKey[l];p||(p=new fn(()=>{let d=F("fetchStylesheet"),f=0,g=new Wu(this.validatorSet);return d.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Vr(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Jl(m.url,g,m.classes,m.media)}return N(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();c=new Sw(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],d.finish(c)}),d.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=p,p.start()),p.get().then(d=>{this.styleByDocURL[i]=d,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},Ji="\u25B8",Oa="\u25BE",Nw="\u25B9";function po(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function Pw(e){let t=po(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var Tw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=ol(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;li(n,"height","auto")!="auto"&&(k(n,"height","auto"),this.setAutoHeight(n,t)),li(n,"position","static")=="absolute"&&(k(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-node":s.display=v.block,s.margin=le,s.padding=le,s["padding-inline-start"]=new T(1.25,"em");break;case"toc-node-first-child":s.display=v.inline_block,s.margin=new T(.2,"em"),s["vertical-align"]=v.top,s.color=v.inherit,s["text-decoration"]=v.none;break;case"toc-container":s.padding=le;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&Ue(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=Ji&&(l.textContent=Ji,k(l,"cursor","pointer"),l.addEventListener("click",Iw,!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"),r.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Nw,k(l,"margin","0.2em 0 0 -1em"),k(l,"margin-inline-start","-1em"),k(l,"margin-inline-end","0"),k(l,"display","inline-block"),k(l,"width","1em"),k(l,"text-align","center"),k(l,"vertical-align","top"),k(l,"cursor","default"),k(l,"font-family","Menlo,sans-serif"),h.appendChild(l),k(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){k(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 N(h)}}showTOC(e,t,i,n,s){if(this.page)return N(this.page);let r=F("showTOC"),o=new ah(e,e);this.page=o;let a=Ct(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of po(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,s);t=new es(t.window,c.fontSize,0,t.root,c.width,c.height);let p=this.makeCustomRenderer(h),d=new Gu(l,h,this.lang,t,this.clientLayout,this.fontMapper,p,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=d,d.pref=this.pref,d.init().then(()=>{d.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:r,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Iw(e){let t=e.target,i=t.textContent==Ji;t.textContent=i?Oa:Ji;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==Oa){a.textContent=Ji,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var Ba=class extends kw{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=bw(),this.jsonStore=rp()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=F("loadPubDoc");return as(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}D.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Vn(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}D.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=F("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=F("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?this.loadAsPlainXML(`${e}META-INF/encryption.xml`).then(o=>{n=new Vn(this,e),n.initWithXMLDoc(r,o).then(()=>{this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,s.finish(n)})}):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=F("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Vn(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Ir(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=ke(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{s.initWithWebPubManifest(h,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&po(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=F("EPUBDocStore.load"),n=Ct(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(yi)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?D.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&yi.startsWith("https:")?D.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?D.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):D.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Ct(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=F("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},_a=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=Ic}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=ke(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Bc(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 Rw(e){return e.id}function Aw(e){return t=>{let i=F("deobfuscator");return Lw("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);ip(s).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(Xl([a,r]))})}),i.result()}}function Lw(e,t){let i=F("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Lt={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"},Hi="http://idpf.org/epub/vocab/package/meta/#",Te={language:`${Lt.dcterms}language`,title:`${Lt.dcterms}title`,creator:`${Lt.dcterms}creator`,layout:`${Lt.rendition}layout`,titleType:`${Hi}title-type`,displaySeq:`${Hi}display-seq`,alternateScript:`${Hi}alternate-script`,role:`${Hi}role`};function Fw(e,t){let i={};return(n,s)=>{var r,o,a,h,l,c;let p,d,f=n.r||i,g=s.r||i;if(e==Te.title&&(p=((r=f[Te.titleType])==null?void 0:r[0].v)=="main",d=((o=g[Te.titleType])==null?void 0:o[0].v)=="main",p!=d))return p?-1:1;let m=parseInt((a=f[Te.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let y=parseInt((h=g[Te.displaySeq])==null?void 0:h[0].v,10);return isNaN(y)&&(y=Number.MAX_VALUE),m!=y?m-y:e!=Te.language&&t&&(p=((l=f[Te.language]||f[Te.alternateScript])==null?void 0:l[0].v)==t,d=((c=g[Te.language]||g[Te.alternateScript])==null?void 0:c[0].v)==t,p!=d)?p?-1:1:n.o-s.o}}function Ow(e,t){let i;if(!t)i=Lt;else{i={};for(let d in Lt)i[d]=Lt[d];let p;for(;(p=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(p[0].length),i[p[1]]=p[2]}let n=p=>{if(p){let d=p.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(d){let f=d[2]?i[d[2]]:Hi;if(f)return f+d[3]}}return null},s=1,r=e.childElements().forEachNonNull(p=>{if(p.localName=="meta"){let d=n(p.getAttribute("property"));if(d)return{name:d,value:p.textContent,id:p.getAttribute("id"),order:s++,refines:p.getAttribute("refines"),lang:null,scheme:n(p.getAttribute("scheme")),role:null}}else if(p.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Lt.dcterms+p.localName,order:s++,lang:p.getAttribute("xml:lang"),value:p.textContent,id:p.getAttribute("id"),refines:null,scheme:null,role:p.getAttribute("role")||p.getAttribute("opf:role")};return null}),o=xs(r,p=>p.refines),a=p=>_c(p,(d,f)=>d.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let y=o[`#${g.id}`]||[];if(y.length||g.lang||g.role){g.lang&&y.push({name:Te.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&y.push({name:Te.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let b=xs(y,w=>w.name);m.r=a(b)}return m})),h=a(xs(r,p=>p.refines?null:p.name)),l=null;h[Te.language]&&(l=h[Te.language][0].v);let c=p=>{for(let d in p){let f=p[d];f.sort(Fw(d,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&c(m)}}};return c(h),h}function Bw(){let e=window.MathJax;return e?e.Hub:null}var Ma={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Fs="viv-id-",Vn=class{constructor(e,t){this.store=e,this.pubURL=t,u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let r=s+(n?`#${n}`:"");return Fs+tl(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s,a=decodeURIComponent(r[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Fs)===0&&(n=n.substring(Fs.length));let s=Oc(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=ke("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new _a,c=h;l.initWithElement(c,e.url);let p=c.getAttribute("fallback");return p&&!Ma[l.mediaType]&&(s[l.src]=p),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Co(this.items,Rw),this.itemMapByPath=Co(this.items,h=>this.getPathFromURL(h.src));for(let h in s){let l=h;for(;;){let c=this.itemMap[s[l]];if(!c)break;if(Ma[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,p=c.getAttribute("idref"),d=this.itemMap[p];return d&&(d.itemRefElement=c,d.spineIndex=l),d});let r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=ja(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Fa.withChild("EncryptionMethod",Fa.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=Ow(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Te.language]&&(this.lang=this.metadata[Te.language][0].v),this.metadata[Te.layout]&&(this.prePaginated=this.metadata[Te.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=Aw(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=F("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Uu(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new _a;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Te.title]=(Array.isArray(a)?a:[a]).map(m=>{var y;return{v:(y=m.value)!=null?y:m}}));let h=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(m=>m.content);h&&h.length!==0&&(this.metadata[Te.creator]=(Array.isArray(h)?h:[h]).map(m=>{var y;return{v:(y=m.name)!=null?y:m}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Te.language]=(Array.isArray(l)?l:[l]).map(m=>({v:m})));let c=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&c!==null){e.readingOrder=[encodeURI(c)];for(let m of Pw(t)){let y=m.getAttribute("href");if(/^(https?:)?\/\//.test(y)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(y))continue;let b=Ct(ke(y,this.pubURL)),w=this.getPathFromURL(b),S=w!==null?encodeURI(w):b;e.readingOrder.indexOf(S)==-1&&e.readingOrder.push(S)}}let p=[],d=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(y=>{let b=m===e.readingOrder,w=typeof y=="string"?y:y.url||y.href,S=typeof y=="string"?"":y.encodingFormat||y.href&&y.type||"";if(b||S==="text/html"||S==="application/xhtml+xml"||!S&&y.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(w)){let I=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,L={url:ke(en(w),I),index:d++,startPage:null,skipPagesBefore:null};y.rel==="contents"&&f===-1&&(f=L.index),p.push(L)}})});let g=F("initWithWebPubManifest");return this.initWithChapters(p).then(()=>{var m,y;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(m=this.items)==null?void 0:m[0]:this.itemMapByPath[c]);let b=(y=e.readingOrder)==null?void 0:y.length;b&&b<this.items.length&&this.items.splice(b),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=F("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),h=t-a,l=new Io;l.prependPathFromNode(r,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return vi("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Io;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{D.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return vi("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=Bt(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{D.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=F("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},Rn=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),_w=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),this.pref=ol(n),this.clientLayout=new mw(t),this.counterStore=new kd(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=F("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let h=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,h&&e.pages[t.page]&&(t.isSamePosition(h)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let h=this.counterStore.getUnresolvedRefsToPage(s),l=0;i.loopWithFrame(c=>{if(l++,l>h.length){c.breakLoop();return}let p=h[l-1];if(p.refs=p.refs.filter(d=>!d.isResolved()),p.refs.length===0){c.continueLoop();return}this.getPageViewItem(p.spineIndex).then(d=>{if(!d){c.continueLoop();return}let{currentPageType:f,previousPageType:g}=d.instance.styler.cascade,m=Object.entries(d.instance.scopes);this.counterStore.pushPageCounters(p.pageCounters),this.counterStore.pushReferencesToSolve(p.refs);let y=d.layoutPositions[p.pageIndex];this.renderSinglePage(d,y).then(b=>{d.instance.styler.cascade.currentPageType=f,d.instance.styler.cascade.previousPageType=g,d.instance.scopes=Object.fromEntries(m),this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let w=b.pageAndPosition.position;w.spineIndex===s.spineIndex&&w.pageIndex===o&&(s=b.pageAndPosition.page),c.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:Rn(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=Bt(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=F("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(s=h.page,r=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Rn(s,r))})}),i.result()}renderPage(e){let t=F("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(Rn(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(r>=0&&i.instance.getPosition(h)>r){o=c,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=c,s=l.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(Rn(o,s));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||(i.complete=!0),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=F("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=F("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=F("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=r.pages[r.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=F("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),s?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=F("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=F("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){D.debug("Navigate to",e);let n=this.opf.getPathFromURL(Ct(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=F("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.setAttribute("role","region"),n.style.position="absolute",n.style.top="0",n.style.left="0",Qi||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),n.appendChild(s);let r=new ah(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=al(this.viewport.width,this.viewport.height,i.width,i.height),a=Ti(null,new gt(o,null),"");r.delayedItems.push(new Hr(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=ke(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let h=xo(s),l=xo(o),c=new kt;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 m=g.getAttribute("name"),y=g.getAttribute("value");m&&y&&(c.append("&"),c.append(encodeURIComponent(m)),c.append("="),c.append(encodeURIComponent(y)))}}r.setAttribute("src",c.toString());let p=t.getAttribute("width");p&&r.setAttribute("width",p);let d=t.getAttribute("height");d&&r.setAttribute("height",d)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=Bw();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=s.queue;h.Push(["Typeset",s,o]);let l=F("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(o)}),l.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=ke(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=F("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let h=s.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),s.title=o.document.title;let l=r.getStyleForDoc(o),c=this.makeCustomRenderer(o),p=this.viewport,d=l.sizeViewport(p.width,p.height,p.fontSize,this.pref);(d.width!=p.width||d.height!=p.height||d.fontSize!=p.fontSize)&&(p=new es(p.window,d.fontSize,p.pixelRatio,p.root,d.width,d.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,y;if(s.startPage!==null)m=s.startPage-1,y=m;else{if(e>0&&(!g||!g.complete))m=s.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,y=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let S=this.counterStore.currentPageCounters.page;y=!S||!S.length?m:S[S.length-1]}s.skipPagesBefore!==null&&(m+=s.skipPagesBefore,y+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(y);let b=new Gu(l,o,this.opf.lang,p,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);b.pref=this.pref;let w=this.opf.metadata&&this.opf.metadata[Te.title];b.pubTitle=w&&w[0]&&w[0].v||"",b.docTitle=s.title||"",b.init().then(()=>{!this.opf.pageProgression&&b.pageProgression&&(this.opf.pageProgression=b.pageProgression),t={item:s,xmldoc:o,instance:b,layoutPositions:[null],pages:[],complete:!1},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 N(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),N(this.tocView.page);let n=F("showTOC");this.tocView||(this.tocView=new Tw(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),Qi||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(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()}},za="data-vivliostyle-viewer-status",Mw="data-vivliostyle-spread-view",ju=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(ju||{}),zw=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView");let s=t.ownerDocument,r=(o,a)=>{let h=s.getElementById(o);return h||(h=s.createElement("style"),h.id=o,a&&(h.textContent=a),s.head.appendChild(h)),h};r("vivliostyle-viewport-screen-css",Dl),r("vivliostyle-viewport-css",Vl),r("vivliostyle-polyfill-css",jl),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Qi&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(za,"loading"),this.fontMapper=new km(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=rl(),this.pageSizes=[],this.pixelRatioLimit=/Chrome/.test(navigator.userAgent)?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Ya;D.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),D.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),D.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),D.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(za,e),this.callback({t:"readystatechange"}))}loadPublication(e){et.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=F("loadPublication");return this.configure(e).then(()=>{let o=new Ba;o.init(n,s).then(()=>{let a=ke(en(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){et.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=F("loadXML");return this.configure(e).then(()=>{let a=new Ba;a.init(s,r).then(()=>{let h=t.map((l,c)=>({url:ke(en(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Vn(a,""),this.opf.initWithChapters(h,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(et.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;if(s==="ex")return t*we.ex*this.fontSize/we.em;let r=we[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(bo(e.userAgentRootURL.replace(/resources\/?$/,"")),yo(e.userAgentRootURL)),typeof e.rootURL=="string"&&(bo(e.rootURL),yo(`${yi}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!==yt&&(ow(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){pt("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=>{k(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),k(e.container,"visibility","visible"),k(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=F("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?os(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new es(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new es(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return(e.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(Mw,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(g){let m=g*.75;return Math.ceil(m)};var r=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),c=o(h),p=l*((this.pixelRatio||1)-1)+2,d=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-p}pt ${-d}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new _w(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){let t=this.getAdjustedZoomFactor(e.dimensions);this.viewport.zoom(e.dimensions.width,e.dimensions.height,t)}setSpreadZoom(e){let t=this.getSpreadDimensions(e);this.viewport.zoom(t.width,t.height,this.getAdjustedZoomFactor(t))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Da),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=js().getScheduler().run(()=>vi("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,et.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),et.registerEndTiming("render (resize)"),yt&&Du(this.window)?uw(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 Da)et.registerEndTiming("render (resize)"),D.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=F("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=F("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=F("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=F("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return vi("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(D.error("No such action:",t),i.finish(!0))},(i,n)=>{D.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=Va(e),i=null,n=this;Kd(()=>{let s=F("commandLoop"),r=js().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};r.run(()=>(n.callback(l),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=F("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=Va(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},Xu=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(Xu||{}),Da=class qu extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,qu.prototype),this.stack=new Error().stack}};function Va(e){return typeof e=="string"?Ir(e):e}var Ua=Tr;function Dw(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Ha(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 Yu=class{constructor(e,t){this.settings=e,u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),Wa(e.debug),this.adaptViewer_=new zw(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=Dw(),t&&this.setOptions(t),this.eventTarget=new Rr,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Ha(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Vw(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},Ha(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()===Ua.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Ua.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function Vw(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 Ku=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Ku||{}),Uw=Xu,Hw=ju;et.forceRegisterEndTiming("load_vivliostyle");var $w=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=r}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1486
+ `),i.toString()}},km=class{constructor(e){this.deobfuscator=e,u(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof qe){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(B(s)),i.push(n)}return new qe(i)}else{let t=this.familyMap[e.stringValue()];return t?new qe([B(t),e]):e}}},Nm=class{constructor(e,t,i){this.head=e,this.body=t,u(this,"srcURLMap",{}),u(this,"familyPrefix"),u(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=F("initFont"),s=e.src,r={};for(let l in un)r[l]=e.properties[l];let o=this.getViewFontFamily(e,i);r["font-family"]=B(o);let a=new Nu(r),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(s,t),this.head.appendChild(h),D.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),D.debug("Found already-loaded font:",i)):D.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new mn(()=>{let r=F("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?as(o,"blob").then(h=>{if(!h.responseBlob){r.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){D.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return os(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=F("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Pm=1,ps=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,u(this,"specified",{}),u(this,"children",[]),u(this,"pageMaster",null),u(this,"index",0),u(this,"key"),u(this,"_scope"),this._scope=e,this.key=`p${Pm++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Tm=class extends ps{constructor(e){super(e,null,null,[],null),this.specified.width=new Z(Ni,0),this.specified.height=new Z(Pi,0)}},Ea=class extends Ds{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let h=this.lookupInstance(a);if(h)return r?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},Pu=class Tu extends ps{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,u(this,"keyMap",{}),t instanceof Ea||(this._scope=new Ea(t,this)),this.pageMaster=this,this.specified.width=new Z(Ni,0),this.specified.height=new Z(Pi,0),this.specified["wrap-flow"]=new Z(y.auto,0),this.specified.position=new Z(y.relative,0),this.specified.overflow=new Z(y.visible,0)}createInstance(t){return new lo(t,this)}clone(t){let i=new Tu(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}},Iu=class Au extends ps{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new Z(y.auto,0)}createInstance(t){return new Lm(t,this)}clone(t){let i=new Au(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},fs=class Ru extends ps{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new cn(t,this)}clone(t){let i=new Ru(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Im(e,t,i){return!t||J(t)?new Fe(e,i):t.toExpr(e,e.zero)}function ue(e,t,i){return!t||t===y.auto||J(t)?null:t.toExpr(e,i)}function Am(e,t,i){return!t||t===y.normal||J(t)?null:t.toExpr(e,i)}function it(e,t,i){return!t||t===y.auto||J(t)?e.zero:t.toExpr(e,i)}function ka(e,t,i){return!t||J(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function bt(e,t,i,n){return!t||i===y.none||J(t)?e.zero:t.toExpr(e,n)}function Lu(e,t,i){return!t||J(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var gs=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,u(this,"cascaded",{}),u(this,"style",{}),u(this,"autoWidth",null),u(this,"autoHeight",null),u(this,"children",[]),u(this,"isAutoWidth",!1),u(this,"isAutoHeight",!1),u(this,"isTopDependentOnAutoHeight",!1),u(this,"isRightDependentOnAutoWidth",!1),u(this,"calculatedWidth",0),u(this,"calculatedHeight",0),u(this,"pageMasterInstance",null),u(this,"namedValues",{}),u(this,"namedFuncs",{}),u(this,"vertical",!1),u(this,"rtl",!1),u(this,"suppressEmptyBoxGeneration",!1),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 j(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let s=this.vertical?Ph:Th;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Cl(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ae(i,Fn(i,new Gi(i,"min",[n,s]),j(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Lu(e,t.enabled,e._true),n=ue(e,t.page,e.zero);if(n){let o=new ze(e,"page-number");i=lt(e,i,new Br(e,n,o))}let s=ue(e,t["min-page-width"],e.zero);s&&(i=lt(e,i,new Us(e,new ze(e,"page-width"),s)));let r=ue(e,t["min-page-height"],e.zero);r&&(i=lt(e,i,new Us(e,new ze(e,"page-height"),r))),i=this.boxSpecificEnabled(i),t.enabled=new V(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=ue(e,t.left,i),s=ue(e,t["margin-left"],i),r=bt(e,t["border-left-width"],t["border-left-style"],i),o=it(e,t["padding-left"],i),a=ue(e,t.width,i),h=ue(e,t["max-width"],i),l=it(e,t["padding-right"],i),c=bt(e,t["border-right-width"],t["border-right-style"],i),p=ue(e,t["margin-right"],i),d=ue(e,t.right,i),f=j(e,r,o),g=j(e,r,l);if(n&&d&&a){let b=ae(e,i,j(e,a,j(e,j(e,n,f),g)));s?p?d=ae(e,b,p):p=ae(e,b,j(e,d,s)):(b=ae(e,b,d),p?s=ae(e,b,p):(s=Fn(e,b,new Fe(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!n&&!d&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!d?n=e.zero:!a&&!d&&(a=this.autoWidth,this.isAutoWidth=!0);let b=ae(e,i,j(e,j(e,s,f),j(e,p,g)));this.isAutoWidth&&(h||(h=ae(e,b,n||d)),!this.vertical&&(ue(e,t["column-width"],null)||ue(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?d||(d=ae(e,b,j(e,n,a))):a=ae(e,b,j(e,n,d)):n=ae(e,b,j(e,d,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),v=it(e,m,i);t.left=new V(n),t["margin-left"]=new V(s),t["border-left-width"]=new V(r),t["padding-left"]=new V(o),t.width=new V(a),t["max-width"]=new V(h||a),t["padding-right"]=new V(l),t["border-right-width"]=new V(c),t["margin-right"]=new V(p),t.right=new V(d),t["snap-width"]=new V(v)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=ue(e,t.top,n),r=ue(e,t["margin-top"],i),o=bt(e,t["border-top-width"],t["border-top-style"],i),a=it(e,t["padding-top"],i),h=ue(e,t.height,n),l=ue(e,t["max-height"],n),c=it(e,t["padding-bottom"],i),p=bt(e,t["border-bottom-width"],t["border-bottom-style"],i),d=ue(e,t["margin-bottom"],i),f=ue(e,t.bottom,n),g=j(e,o,a),m=j(e,p,c);if(s&&f&&h){let w=ae(e,n,j(e,h,j(e,j(e,s,g),m)));r?d?f=ae(e,w,r):d=ae(e,w,j(e,f,r)):(w=ae(e,w,f),d?r=ae(e,w,d):(r=Fn(e,w,new Fe(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!s&&!f&&!h&&(s=e.zero),!s&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let w=ae(e,n,j(e,j(e,r,g),j(e,d,m)));this.isAutoHeight&&(l||(l=ae(e,w,s||f)),this.vertical&&(ue(e,t["column-width"],null)||ue(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),s?h?f||(f=ae(e,w,j(e,s,h))):h=ae(e,w,j(e,f,s)):s=ae(e,w,j(e,f,h))}let v=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=it(e,v,i);t.top=new V(s),t["margin-top"]=new V(r),t["border-top-width"]=new V(o),t["padding-top"]=new V(a),t.height=new V(h),t["max-height"]=new V(l||h),t["padding-bottom"]=new V(c),t["border-bottom-width"]=new V(p),t["margin-bottom"]=new V(d),t.bottom=new V(f),t["snap-height"]=new V(b)}initColumns(){let e=this.pageBox.scope,t=this.style,i=ue(e,t[this.vertical?"height":"width"],null),n=ue(e,t["column-width"],i),s=ue(e,t["column-count"],null),r=Am(e,t["column-gap"],null);r||(r=new Qt(e,1,"em")),n&&!s&&(s=new Gi(e,"floor",[Hs(e,j(e,i,r),j(e,n,r))]),s=new Gi(e,"max",[e.one,s])),s||(s=e.one),n=ae(e,Hs(e,j(e,i,r),s),r),t["column-width"]=new V(n),t["column-count"]=new V(s),t["column-gap"]=new V(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){e.registerInstance(this.pageBox.key,this);let t=this.pageBox.scope,i=this.style,n=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=jh(this.cascaded,e,n,!1,null);this.vertical=Gh(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Wh(s,e,this.parentInstance?this.parentInstance.rtl:!1),qh(s,i,this.vertical,this.rtl,(r,o)=>o.value),this.autoWidth=new De(t,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new De(t,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&qi(t)&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new T(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=Zn(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=Zn(e,s,t,r)}return We(s,e)}getSpecial(e,t){let i=Rh(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==G&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&cl(s.unit)&&(s=Al(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),k(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new $r(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),k(t.element,"margin-left",`${n}px`),k(t.element,"padding-left",`${s}px`),k(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(k(t.element,"margin-right",`${s}px`),k(t.element,"padding-right",`${r}px`),k(t.element,"border-right-width",`${o}px`),t.marginRight=s,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,r+=t.snapOffsetY)}t.paddingTop=r,k(t.element,"top",`${n}px`),k(t.element,"margin-top",`${s}px`),k(t.element,"padding-top",`${r}px`),k(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;k(t.element,"height",`${r}px`),k(t.element,"margin-bottom",`${i}px`),k(t.element,"padding-bottom",`${n}px`),k(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){k(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,k(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){k(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");k(t.element,"right",`${n}px`),k(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,s){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&k(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&k(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let r=0;r<Na.length;r++)this.propagateProperty(e,t,Na[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<Ta.length;s++)this.propagateProperty(e,t,Ta[s],n)}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==y.auto&&!J(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==y.auto&&!J(a)};for(let r=0;r<Ia.length;r++){let o=Ia[r];o==="width"&&!n()||o==="height"&&!s()||this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,h=(!this.vertical||!n)&&this.isAutoWidth,l=null;if((h||a)&&(h&&k(t.element,"width","auto"),a&&k(t.element,"height","auto"),l=r.getElementClientRect(n?n.element:t.element),h&&(this.calculatedWidth=Math.ceil(l.right-l.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=l.bottom-l.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))),(this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let c=this.getPropAsNumber(e,"column-rule-width"),p=this.getProp(e,"column-rule-style"),d=this.getProp(e,"column-rule-color");if(c>0&&p&&p!=y.none&&d!=y.transparent){let f=this.getPropAsNumber(e,"column-gap"),g=this.vertical?t.height:t.width,m=this.vertical?"border-top":"border-left";for(let v=1;v<s;v++){let b=this.vertical?(g+f)*v/s-f/2+t.paddingTop-c/2:(g+f)*v/s-f/2+t.paddingLeft-c/2,w=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,S=t.element.ownerDocument.createElement("div");k(S,"position","absolute"),k(S,this.vertical?"left":"top","0px"),k(S,this.vertical?"top":"left",`${b}px`),k(S,this.vertical?"height":"width","0px"),k(S,this.vertical?"width":"height",`${w}px`),k(S,m,`${c}px ${p.toString()}${d?` ${d.toString()}`:""}`),t.element.insertBefore(S,t.element.firstChild)}}}for(let c=0;c<Pa.length;c++)this.propagateProperty(e,t,Pa[c],o);for(let c=0;c<Aa.length;c++)this.propagateDelayedProperty(e,t,Aa[c],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this instanceof Qi&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||wi(r)&&Zt(i,r,Ue(n,r));if(this.pageBox.pseudoName==ao)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new fr(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Na=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","outline-style","outline-color","outline-width","overflow","visibility"],Pa=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-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","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],Ta=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-transform","white-space","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-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-position"],Ia=["width","height","image-resolution","object-fit","object-position"],Aa=["transform","transform-origin"],ao="background-host",Rm=class extends gs{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)}},lo=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=lt(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Lm=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},cn=class extends gs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ft&&(n=[t]),t instanceof qe&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof ft){let o=zs(n[r].name,"enabled"),a=new ze(s,o);i&&(a=new Bt(s,a)),e=lt(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Lu(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Im(t,i["flow-from"],"body"),r=new Gi(t,"has-content",[s]);e=lt(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=lt(t,r,e),this.pageMasterInstance.style.enabled=new V(r)}return e}prepareContainer(e,t,i,n,s){i.pageAreaElement||k(t.element,"overflow","hidden"),super.prepareContainer(e,t,i,n,s)}},ho=class extends wn{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new Z(t,i?Zl:Kl)}},Fu=class extends ho{constructor(e,t,i,n){super(e,t,i,n)}},Fm=class Ou extends ho{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new Z(Oo,0),n.specified.height=new Z(Oo,0)}startPartitionRule(t,i,n){let s=new fs(this.scope,t,i,n,this.target),r=new Fu(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new Iu(this.scope,t,i,n,this.target),r=new Ou(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},Om=class extends ho{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new fs(this.scope,e,t,i,this.target),s=new Fu(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new Iu(this.scope,e,t,i,this.target),s=new Fm(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function Bu(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===y.vertical_lr||n!==y.vertical_rl&&s!==y.rtl?"ltr":"rtl"}var Bm={a10:{width:new T(26,"mm"),height:new T(37,"mm")},a9:{width:new T(37,"mm"),height:new T(52,"mm")},a8:{width:new T(52,"mm"),height:new T(74,"mm")},a7:{width:new T(74,"mm"),height:new T(105,"mm")},a6:{width:new T(105,"mm"),height:new T(148,"mm")},a5:{width:new T(148,"mm"),height:new T(210,"mm")},a4:{width:new T(210,"mm"),height:new T(297,"mm")},a3:{width:new T(297,"mm"),height:new T(420,"mm")},a2:{width:new T(420,"mm"),height:new T(594,"mm")},a1:{width:new T(594,"mm"),height:new T(841,"mm")},a0:{width:new T(841,"mm"),height:new T(1189,"mm")},b10:{width:new T(31,"mm"),height:new T(44,"mm")},b9:{width:new T(44,"mm"),height:new T(62,"mm")},b8:{width:new T(62,"mm"),height:new T(88,"mm")},b7:{width:new T(88,"mm"),height:new T(125,"mm")},b6:{width:new T(125,"mm"),height:new T(176,"mm")},b5:{width:new T(176,"mm"),height:new T(250,"mm")},b4:{width:new T(250,"mm"),height:new T(353,"mm")},b3:{width:new T(353,"mm"),height:new T(500,"mm")},b2:{width:new T(500,"mm"),height:new T(707,"mm")},b1:{width:new T(707,"mm"),height:new T(1e3,"mm")},b0:{width:new T(1e3,"mm"),height:new T(1414,"mm")},c10:{width:new T(28,"mm"),height:new T(40,"mm")},c9:{width:new T(40,"mm"),height:new T(57,"mm")},c8:{width:new T(57,"mm"),height:new T(81,"mm")},c7:{width:new T(81,"mm"),height:new T(114,"mm")},c6:{width:new T(114,"mm"),height:new T(162,"mm")},c5:{width:new T(162,"mm"),height:new T(229,"mm")},c4:{width:new T(229,"mm"),height:new T(324,"mm")},c3:{width:new T(324,"mm"),height:new T(458,"mm")},c2:{width:new T(458,"mm"),height:new T(648,"mm")},c1:{width:new T(648,"mm"),height:new T(917,"mm")},c0:{width:new T(917,"mm"),height:new T(1297,"mm")},"jis-b10":{width:new T(32,"mm"),height:new T(45,"mm")},"jis-b9":{width:new T(45,"mm"),height:new T(64,"mm")},"jis-b8":{width:new T(64,"mm"),height:new T(91,"mm")},"jis-b7":{width:new T(91,"mm"),height:new T(128,"mm")},"jis-b6":{width:new T(128,"mm"),height:new T(182,"mm")},"jis-b5":{width:new T(182,"mm"),height:new T(257,"mm")},"jis-b4":{width:new T(257,"mm"),height:new T(364,"mm")},"jis-b3":{width:new T(364,"mm"),height:new T(515,"mm")},"jis-b2":{width:new T(515,"mm"),height:new T(728,"mm")},"jis-b1":{width:new T(728,"mm"),height:new T(1030,"mm")},"jis-b0":{width:new T(1030,"mm"),height:new T(1456,"mm")},letter:{width:new T(8.5,"in"),height:new T(11,"in")},legal:{width:new T(8.5,"in"),height:new T(14,"in")},ledger:{width:new T(11,"in"),height:new T(17,"in")}},_m=new T(.24,"pt"),Kw=new T(3,"mm"),Mm=new T(10,"mm"),zm=new T(13,"mm");function Qn(e){let t={width:Ni,height:Pi,bleed:le,bleedOffset:le,cropOffset:le},i=e.size;if(!(!i||i.value===y.auto)){let l=i.value,c,p;if(l.isSpaceList()?(c=l.values[0],p=l.values[1]):(c=l,p=null),c.isNumeric())t.width=c,t.height=p||c;else{let d=c.name&&Bm[c.name.toLowerCase()];d&&(p&&p===y.landscape?(t.width=d.height,t.height=d.width):(t.width=d.width,t.height=d.height))}}let n=e.marks,s=e.bleed,r=n&&!J(n.value)?n.value:y.none,o=s&&!J(s.value)?s.value:y.auto;if(o===y.auto){if(r!==y.none){let l=!1;r.isSpaceList()?l=r.values.some(c=>c===y.crop):l=r===y.crop,l&&(t.bleed=new T(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!J(a.value)?a.value:y.auto;return h===y.auto?r!==y.none&&(t.bleedOffset=zm):h.isNumeric()&&(t.cropOffset=h),t}function Ra(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===Ni?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===Pi?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function _u(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 Ji(e,t,i){i=i||"polyline";let n=e.createElementNS("http://www.w3.org/2000/svg",i);return n.setAttribute("stroke","#010101"),n.setAttribute("stroke-width",t),n.setAttribute("fill","none"),n}var Sr=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Sr||{});function Dm(e,t,i,n,s,r){let o=n;o<=s+2*we.mm&&(o=s+n/2);let a=Math.max(n,o),h=s+a+i/2,l=_u(e,h,h),c=[[0,s+n],[n,s+n],[n,s+n-o]],p=c.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(c=c.map(g=>[s+a-g[0],g[1]]),p=p.map(g=>[s+a-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(c=c.map(g=>[g[0],s+a-g[1]]),p=p.map(g=>[g[0],s+a-g[1]]));let d=Ji(e,i);d.setAttribute("points",c.map(g=>g.join(",")).join(" ")),l.appendChild(d);let f=Ji(e,i);return f.setAttribute("points",p.map(g=>g.join(",")).join(" ")),l.appendChild(f),t.split(" ").forEach(g=>{l.style[g]=`${r}px`}),l}var dn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(dn||{});function Vm(e,t,i,n,s){let r=n*2,o,a;t==="top"||t==="bottom"?(o=r,a=n):(o=n,a=r);let h=_u(e,o,a),l=Ji(e,i);l.setAttribute("points",`0,${a/2} ${o},${a/2}`),h.appendChild(l);let c=Ji(e,i);c.setAttribute("points",`${o/2},0 ${o/2},${a}`),h.appendChild(c);let p=Ji(e,i,"circle");p.setAttribute("cx",o/2),p.setAttribute("cy",a/2),p.setAttribute("r",n/4),h.appendChild(p);let d;switch(t){case"top":d="bottom";break;case"bottom":d="top";break;case"left":d="right";break;case"right":d="left";break}return Object.keys(dn).forEach(f=>{let g=dn[f];g===t?h.style[g]=`${s}px`:g!==d&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function Um(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let f=o.value;f instanceof ye?f.values.forEach(g=>{g===y.crop?s=!0:g===y.cross&&(r=!0)}):f===y.crop?s=!0:f===y.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let h=i.container,l=h.ownerDocument,c=We(_m,n),p=Math.max(0,t.bleedOffset-We(Mm,n)),d=t.bleedOffset-p;s&&Object.keys(Sr).forEach(f=>{let g=Sr[f],m=Dm(l,g,c,d,a,p);h.appendChild(m)}),r&&Object.keys(dn).forEach(f=>{let g=dn[f],m=Vm(l,g,c,d,p);h.appendChild(m)})}var Cr=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end"],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};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})(),uo={"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"}},Hm=(()=>{let e=uo;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),co="vivliostyle-page-rule-master",pn="_marginBoxes",$m=class extends Pu{constructor(e,t,i){super(e,null,co,[],t,null,0),u(this,"bodyPartitionKey"),u(this,"pageMarginBoxes",{});let n=Qn(i),s=new Gm(this.scope,this,i,n);this.bodyPartitionKey=s.key,this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[pn];t&&Hm.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Wm(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new Z(y.relative,0),this.specified.width=new Z(t.width,0),this.specified.height=new Z(t.height,0);for(let i in e)!Cr[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Qi(e,this)}},Gm=class extends fs{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n,this.specified["z-index"]=new Z(new ei(0),0),this.applySpecified(i)}applySpecified(e){this.specified["flow-from"]=new Z(B("body"),0),this.specified.position=new Z(y.absolute,0),this.specified.overflow=new Z(y.visible,0);for(let t in Cr)Cr.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new zu(e,this)}},Wm=class extends fs{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[pn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(Nh[i]||s&&s.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!==G&&n.value!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new Xm(e,this)}},Qi=class extends lo{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 V(e.borderBoxWidth),t.height=new V(e.borderBoxHeight),t["padding-left"]=new V(e.marginLeft),t["padding-right"]=new V(e.marginRight),t["padding-top"]=new V(e.marginTop),t["padding-bottom"]=new V(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",h=this.pageBox.scope,l={},c={},p={};for(let S in e){let I=uo[S];if(I){let L=e[S],_=this.pageMarginBoxInstances[S],U=new Mu(L,_.style,t,h,s);l[I.positionAlongVariableDimension]=L,c[I.positionAlongVariableDimension]=_,p[I.positionAlongVariableDimension]=U}}let d={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),g=!1,m={};Object.keys(l).forEach(S=>{let I=S,L=ue(h,c[I].style[t?"max-width":"max-height"],i.extent);if(L){let _=L.evaluate(n);if(f[I]>_){let U=p[I]=new La(l[I],c[I].style,t,h,s,_);m[I]=U.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),g=!1,[r,o,a].forEach(S=>{f[S]=m[S]||f[S]}));let v={};Object.keys(l).forEach(S=>{let I=S,L=ue(h,c[I].style[t?"min-width":"min-height"],i.extent);if(L){let _=L.evaluate(n);if(f[I]<_){let U=p[I]=new La(l[I],c[I].style,t,h,s,_);v[I]=U.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(p,d.extent),[r,o,a].forEach(S=>{f[S]=v[S]||f[S]}));let b=d.start+d.extent,w=d.start+(d.start+d.extent);[r,o,a].forEach(S=>{let I=f[S];if(I){let L=l[S],_=0;switch(S){case r:_=t?L.left:L.top;break;case o:_=(w-I)/2;break;case a:_=b-I;break}t?L.setHorizontalPosition(_,I-L.getInsetLeft()-L.getInsetRight()):L.setVerticalPosition(_,I-L.getInsetTop()-L.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){let i=e.start,n=e.center,s=e.end,r={};if(n){let o=[i,s].filter(p=>p),a=o.length?new jm(o):null,h=this.distributeAutoMarginBoxSizes(n,a,t);h.xSize&&(r.center=h.xSize);let l=h.xSize||n.getOuterSize(),c=(t-l)/2;i&&i.hasAutoSize()&&(r.start=c),s&&s.hasAutoSize()&&(r.end=c)}else{let o=this.distributeAutoMarginBoxSizes(i,s,t);o.xSize&&(r.start=o.xSize),o.ySize&&(r.end=o.ySize)}return r}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(s-a)/(o-l):l>0&&(n.xSize=i*a/l)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){super.prepareContainer(e,t,i,n,s),t.element.setAttribute("data-vivliostyle-page-box",!0)}},Mu=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,u(this,"hasAutoSize_"),u(this,"size",null);let r=t[i?"width":"height"];this.hasAutoSize_=!r||r===y.auto||J(r)}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width"]:["max-content height","min-content height"];this.size=Hr(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()}},jm=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>e.hasAutoSize())}getOuterMaxContentSize(){let e=this.params.map(t=>t.getOuterMaxContentSize());return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>t.getOuterMinContentSize());return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>t.getOuterSize());return Math.max.apply(null,e)*e.length}},La=class extends Mu{constructor(e,t,i,n,s,r){super(e,t,i,n,s),u(this,"fixedSize"),this.fixedSize=r}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},zu=class extends cn{constructor(e,t){super(e,t),u(this,"borderBoxWidth",null),u(this,"borderBoxHeight",null),u(this,"marginTop",null),u(this,"marginRight",null),u(this,"marginBottom",null),u(this,"marginLeft",null)}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(n.match(/^column.*$/)||n.match(/^background-/))&&(i[n]=t[n]);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.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),h=ue(n,t[o],a),l=ue(n,t[`margin-${s}`],a),c=ue(n,t[`margin-${r}`],a),p=it(n,t[`padding-${s}`],a),d=it(n,t[`padding-${r}`],a),f=bt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),g=bt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),m=ae(n,a,j(n,j(n,f,p),j(n,g,d)));return h?(m=ae(n,m,h),!l&&!c?(l=Fn(n,m,new Fe(n,.5)),c=l):l?c=ae(n,m,l):l=ae(n,m,c)):(l||(l=n.zero),c||(c=n.zero),h=ae(n,m,j(n,l,c))),i.width!==Ni||i.height!==Pi||this.hasBorderOrOutline()||l instanceof Qt&&l.num<0||c instanceof Qt&&c.num<0?(t[s]=new V(l),t[r]=new V(c),t[`margin-${s}`]=le,t[`margin-${r}`]=le,t[`border-${s}-width`]=new V(f),t[`border-${r}-width`]=new V(g)):(t[s]=le,t[r]=le,t[`margin-${s}`]=le,t[`margin-${r}`]=le,t[`border-${s}-width`]=new V(l),t[`border-${r}-width`]=new V(c),t[`border-${s}-style`]=y.solid,t[`border-${r}-style`]=y.solid,t[`border-${s}-color`]=y.transparent,t[`border-${r}-color`]=y.transparent,t["background-clip"]=y.padding_box),t[`padding-${s}`]=new V(p),t[`padding-${r}`]=new V(d),t[o]=new V(h),t[`max-${o}`]=new V(h),{borderBoxExtent:ae(n,a,j(n,l,c)),marginStart:l,marginEnd:c}}hasBorderOrOutline(){let e=t=>{var i;let n=(i=Ue(this.cascaded,t))==null?void 0:i.value;return!!n&&n!==y.none};return e("border-top-style")||e("border-bottom-style")||e("border-left-style")||e("border-right-style")||e("border-block-start-style")||e("border-block-end-style")||e("border-inline-start-style")||e("border-inline-end-style")||e("outline-style")}prepareContainer(e,t,i,n,s){i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=parseFloat(i.pageAreaElement.style.width),e.pageAreaHeight=parseFloat(i.pageAreaElement.style.height)}},Xm=class extends cn{constructor(e,t){super(e,t),u(this,"boxInfo"),u(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=uo[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){k(t,"display","flex"),k(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&&k(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof ct||s instanceof V&&s.expr instanceof De&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),k(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",h=a?t.borderBoxWidth:t.borderBoxHeight,l=ue(n,i[o],h),c=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new V(c);else if(l){let p=it(n,i[`margin-${s}`],h),d=it(n,i[`margin-${r}`],h),f=it(n,i[`padding-${s}`],h),g=it(n,i[`padding-${r}`],h),m=bt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),v=bt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),b=j(n,l,j(n,j(n,f,g),j(n,j(n,m,v),j(n,p,d))));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new V(j(n,c,Hs(n,ae(n,h,b),new Fe(n,2))));break;case"end":i[s]=new V(ae(n,j(n,c,h),b));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.inside,r=e.outside,o=e.extent,a=t[`margin${r.charAt(0).toUpperCase()}${r.substring(1)}`],h=ka(n,i[`margin-${s}`],a),l=ka(n,i[`margin-${r}`],a),c=it(n,i[`padding-${s}`],a),p=it(n,i[`padding-${r}`],a),d=bt(n,i[`border-${s}-width`],i[`border-${s}-style`],a),f=bt(n,i[`border-${r}-width`],i[`border-${r}-style`],a),g=ue(n,i[o],a),m=null;function v(b){if(m)return m;m={extent:g?g.evaluate(b):null,marginInside:h?h.evaluate(b):null,marginOutside:l?l.evaluate(b):null};let w=a.evaluate(b),S=0;return[d,c,p,f].forEach(I=>{I&&(S+=I.evaluate(b))}),(m.marginInside===null||m.marginOutside===null)&&S+m.extent+m.marginInside+m.marginOutside>w&&(m.marginInside===null&&(m.marginInside=0),m.marginOutside===null&&(m.marginOutside=0)),m.extent!==null&&m.marginInside!==null&&m.marginOutside!==null&&(m.marginOutside=null),m.extent===null&&m.marginInside!==null&&m.marginOutside!==null?m.extent=w-S-m.marginInside-m.marginOutside:m.extent!==null&&m.marginInside===null&&m.marginOutside!==null?m.marginInside=w-S-m.extent-m.marginOutside:m.extent!==null&&m.marginInside!==null&&m.marginOutside===null?m.marginOutside=w-S-m.extent-m.marginInside:m.extent===null?(m.marginInside=m.marginOutside=0,m.extent=w-S):m.marginInside=m.marginOutside=(w-S-m.extent)/2,m}i[o]=new V(new De(n,function(){let b=v(this).extent;return b===null?0:b},o)),i[`margin-${s}`]=new V(new De(n,function(){let b=v(this).marginInside;return b===null?0:b},`margin-${s}`)),i[`margin-${r}`]=new V(new De(n,function(){let b=v(this).marginOutside;return b===null?0:b},`margin-${r}`)),s==="left"?i.left=new V(j(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new V(j(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,s,r,o){super.finishContainer(e,t,i,n,s,r,o);let a=i.marginBoxes,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))}},qm=class{constructor(e,t,i,n,s){this.cascadeInstance=e,this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,u(this,"pageMasterCache",{}),this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new ze(e,"page-number"),s=new Br(e,new vl(e,n,new Fe(e,2)),i?e.one:e.zero);e.defineName("recto-page",new Bt(e,s)),e.defineName("verso-page",s),(t.pageProgression||Bu(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new Bt(e,s))):(e.defineName("left-page",new Bt(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.cascadeInstance.pushRule([],e,t),this.cascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===ao?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){let i=this.makeCascadeValueObjectKey(e);return`${t.key}^${i}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof Z?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new $m(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:co}),n=i.specified,s=e.size;if(s&&!J(s.value)){let o=Qn(e),a=s.priority;Tt(n,"width",new Z(o.width,a),this.context),Tt(n,"height",new Z(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.cascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},Ym=class extends ge{constructor(e){super(),this.pageType=e}apply(e){e.currentPageType===this.pageType&&this.chained.apply(e)}getPriority(){return 3}makePrimary(e){return this.chained&&e.insertInTable(e.pagetypes,this.pageType,this.chained),!0}},Zm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Km=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Jm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Qm=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},ew=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},tw=class extends ge{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},iw=class extends yn{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},nw=class extends Kr{constructor(e,t){super(e,t,null,null,null)}apply(e){sw(e.context,e.currentStyle,this.style,this.specificity,e)}};function sw(e,t,i,n,s){Yn(e,t,i,n,null,null,null);let r=i[pn];if(r){let o=us(t,pn);for(let a in r)if(r.hasOwnProperty(a)){let h=o[a];h||(h={},o[a]=h),Yn(e,h,r[a],n,null,null,null)}}}var rw=class extends rn{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,u(this,"currentPageSelectors",[]),u(this,"currentNamedPageSelector",""),u(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new Ym(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let[i,n]=t;this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new iw(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 Zm(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Km(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Jm(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Qm(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new ew(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new tw(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=Ue(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{Zt(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new Z(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=s[h];l?Tt(l,e,a):(l=s[h]={},Zt(l,e,a),r&&["bleed","marks"].forEach(c=>{r[c]&&Zt(l,c,r[c])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new nw(this.elementStyle,e)}startPageMarginBoxRule(e){let t=us(this.elementStyle,pn),i=t[e];i||(i={},t[e]=i);let n=new ow(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},ow=class extends wn{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new Z(t,n);Zt(this.boxStyle,e,s)}},vt=!0;function aw(e){vt=e}var Kt=[];function Fa(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Du(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 po(e,t,i){var n,s;if(!vt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Du(e.ownerDocument).includes(e))return N(!1);let r=e.textContent,o=e.src,a=e.type==="module",h=(a||o)&&e.async,l=a&&!h||o&&e.defer,c=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||h);if(Vu(t)||(t.onload=null),c)return Kt.some(d=>Fa(d,e))||Kt.push(e),N(!0);if(o.includes("/mathjax")){let d=t.document.head.querySelector("script[src*='MathJax.js']:not([data-vivliostyle-scripting])");if(d){if(o.includes("/mathjax@3"))t.document.head.removeChild(d),(s=(n=t.MathJax)==null?void 0:n.version)!=null&&s.startsWith("2.")&&delete t.MathJax;else if(o.includes("/MathJax.js"))return N(!0)}}for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Fa(d,e)&&t.document.head.removeChild(d);let p=t.document.createElement("script");p.textContent=r,o&&(p.src=o),p.async=h,p.defer=l,p.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||p.setAttribute(d.name,d.value);if(D.debug("script:",o),o){let d=ri(p);return t.document.head.appendChild(p),os([d])}else return t.document.head.appendChild(p),N(!0)}function lw(e,t){var i;let n={},s=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let c of h.values)n[c.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let c of Object.values(l))s(c)},r=o=>{if(o instanceof Kr)s(o.style);else if(o instanceof Ii||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function hw(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=lw(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function uw(e,t,i){if(!vt)return N(!1);let n=Du(e);if(n.length===0)return N(!1);let s=n.some(c=>!(c.async||c.defer||c.type==="module")),r=s?hw(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=F("loadScripts");return l.loop(()=>{if(n.length===0)return s?l.sleep(20).thenAsync(()=>{var p,d;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(p=t.FontJSON)!=null&&p.Font&&(d=t.ret)!=null&&d.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let c=n.shift();return po(c,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(Kt.push(c),h=!0),n.length===0&&s&&(D.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),l.finish(!0)}),l.result()}function cw(e){if(!vt)return N(!1);let t=F("loadScripts");return t.loop(()=>Kt.length===0?N(!1):po(Kt.shift(),e,{atEnd:!0}).thenReturn(Kt.length>0)).then(()=>{D.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),D.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Vu(e){return vt?Kt.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var dw=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),pw={};function fw(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Uu=class Er extends Rr{constructor(t,i,n,s,r,o,a,h,l,c,p,d,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=c,this.customRenderer=p,this.fallbackMap=d,this.documentURLTransformer=f,u(this,"document"),u(this,"exprContentListener"),u(this,"nodeContext",null),u(this,"viewRoot",null),u(this,"isFootnote",!1),u(this,"sourceNode",null),u(this,"offsetInNode",0),u(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new Er(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,s,r,o,a,h){let l=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!l)return h;let c=[],p=Bn.createElementNS("http://www.pyroxy.com/ns/shadow","root"),d=p;for(let g of ug){let m;if(g){if(!l[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let v=s.display;if(!v||v===y.inline)continue;let b=t.firstElementChild;if(b&&Ve(b.previousSibling)){let w=r.getStyle(b,!1);if(w){let S=Ue(w,"display");if(S!=null&&S.value&&S.value!==y.inline)continue}}}if(g==="before"||g==="after"){let v=l[g].content;if(!v||!Vt(v.value))continue}c.push(g),m=Bn.createElementNS("http://www.w3.org/1999/xhtml","span"),wr(m,g)}else m=Bn.createElementNS("http://www.pyroxy.com/ns/shadow","content");d.appendChild(m),g.match(/^first-/)&&(d=m)}if(!c.length)return h;let f=new ga(t,n,r,o,this.exprContentListener);return new Js(t,p,null,a,h,rt.ROOTLESS,f)}getPseudoMap(t,i,n,s,r){let o=dt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Zi(l,o[h],r),mr(l,r,o[h]),Xh(o[h],i,n,(c,p)=>{Zi(l,p,r),$h(p,d=>{Zi(l,d,r)})})}return a}createRefShadow(t,i,n,s,r){let o=F("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let c=this.stylerProducer.getStylerForDoc(h);r=new Js(n,l,h,s,r,i,c)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let h=F("createShadows"),l=null,c=s.template,p;if(c instanceof ct||c===y.footnote){let d=c instanceof ct?c.url:ke("user-agent.xml#footnote",Jt);p=this.createRefShadow(d,rt.ROOTLESS,t,a,l)}else p=N(l);return p.then(d=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),v=null;m?v=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),v=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=ke(m,v.url),f=this.createRefShadow(m,rt.ROOTED,t,a,d))}f==null&&(f=N(d));let g=null;f.then(m=>{if(s.display===y.table_cell){let v=ke("user-agent.xml#table-cell",Jt);g=this.createRefShadow(v,rt.ROOTLESS,t,a,m)}else g=N(m);g.then(v=>{v=this.createPseudoelementShadow(t,i,n,s,r,o,a,v),h.finish(v)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=jh(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((r=this.nodeContext)!=null&&r.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=Gh(a,o,t);let c=!h&&t!==l;if(i=Wh(a,o,i),qh(a,s,t,i,(m,v)=>{let b;c&&(t?/^(min-|max-)?(height|inline-size)$/.test(m)&&(b=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(m)&&(b=o.pageAreaWidth));let w=v.evaluate(o,m,b,t);return m=="font-family"&&(w=this.docFaces.filterFontFamily(w)),w}),c){let m=s[t?"height":"width"];(!m||m===y.auto)&&(s[t?"height":"width"]=y.max_content)}if(tr(s.position))return s.position=y.fixed,s.visibility=y.hidden,t;let p=s.position,d=s.float,f=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),g=yh(f,p,d,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(m=>{g[m]&&(s[m]=g[m])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let p=r&&r.root==i;if(!p||r.type==rt.ROOTLESS){let d=(r?r.styler:this.styler).getStyle(i,!1);n.push(d),s=s||_s(i)}p?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,h=this.context.queryUnitSize("em",a),l={"font-size":new Z(new T(h,"px"),0)},c=new ff(l,this.context);for(let p=n.length-1;p>=0;--p){let d=n[p],f=[];for(let v in d)qi(v)&&f.push(v);f.sort(_o);let g,m;for(let v of f){c.setPropName(v);let b=Ue(d,v),w=b;J(b.value)||(v==="font-size"&&p===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize?w=new Z(new T(this.context.rootFontSize,"px"),b.priority):v==="line-height"&&p===n.length-1&&this.context.rootLineHeight&&b.value instanceof T&&(b.value.unit==="lh"||b.value.unit==="rlh")?w=new Z(new T(this.context.rootLineHeight,"px"),b.priority):p===0&&b.value instanceof T&&b.value.unit==="lh"?w=new Z(new T(b.value.num*this.getLineHeightUnitSize(v,g,m),"px"),b.priority):Nt(v)||(w=b.filterValue(c)),v==="font-size"?g=w.value:v==="line-height"&&(m=w.value),l[v]=w)}}for(let p in t)qi(p)||(l[p]=t[p]);return{lang:s,elementStyle:l}}resolveURL(t){return t=ke(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=_s(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=of().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(J(r))r===y.initial&&(n[s]=void 0);else if(r instanceof ei)n[s]=r.num;else if(r instanceof ft)n[s]=r.name;else if(r instanceof T){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*we[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=pt("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,s,r,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,s,r,o;let a=!0,h=F("createElementView"),l=this.sourceNode,c=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,p=c.getStyle(l,!1);if(!this.nodeContext.shadowContext){let I=this.xmldoc.getElementOffset(l);ls.registerFragmentIndex(I,this.nodeContext.fragmentIndex,0)}let d={};if(!this.nodeContext.parent){let I=this.inheritFromSourceParent(p);p=I.elementStyle,this.nodeContext.lang=I.lang}let f=p.position,g=p.float,m=p["float-reference"],v=g&&!J(g.value)&&g.value!==y.none&&m&&!J(m.value)?Hp(m.value.toString()):null;if(this.nodeContext.parent&&(tr(f?.value)||v&&gi(v))){let I=this.inheritFromSourceParent(p);p=I.elementStyle,this.nodeContext.lang=I.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",p,d),v&&gi(v)&&d.display===y.block&&(d.display=y.flow_root),c.processContent(l,d,(s=this.nodeContext.viewNode)!=null?s:(n=this.nodeContext.parent)==null?void 0:n.viewNode),this.transferPolyfilledInheritedProps(d),this.inheritLangAttribute(),d.direction&&(this.nodeContext.direction=d.direction.toString());let b=d["flow-into"];if(b&&b.toString()!=this.flowName)return h.finish(!1),h.result();if(vt&&l.localName==="script"&&l.namespaceURI==="http://www.w3.org/1999/xhtml")return po(l,this.viewport.window).thenFinish(h),h.result();let w=d.display;if(J(w)&&(w===y.initial||w===y.unset?w=y.inline:w===y.inherit?w=((r=this.nodeContext.parent)==null?void 0:r.display)&&B((o=this.nodeContext.parent)==null?void 0:o.display):w=null),w===y.none)return h.finish(!1),h.result();let S=this.nodeContext.parent==null;return this.nodeContext.flexContainer=w===y.flex,this.createShadows(l,S,p,d,c,this.context,this.nodeContext.shadowContext).then(I=>{var L,_;this.nodeContext.nodeShadow=I;let U=d.position,W=d.float,re=d.clear,He=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,de=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:He,pe=Yp(l);this.nodeContext.establishesBFC=Zp(w,U,W,d.overflow,He,de,pe),this.nodeContext.containingBlockForAbsolute=Kp(U),this.nodeContext.isInsideBFC()&&W!==y.footnote&&!(v&&gi(v))&&(W=null,re=null);let x=W instanceof ye||W===y.left||W===y.right||W===y.top||W===y.bottom||W===y.inline_start||W===y.inline_end||W===y.block_start||W===y.block_end||W===y.snap_block||W===y.snap_inline||W===y.footnote;W&&(delete d.float,W===y.footnote&&(this.isFootnote?(x=!1,d.display=y.block):d.display=y.inline)),re&&(re===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(re=B(this.nodeContext.parent.clearSide)),(re===y.left||re===y.right||re===y.top||re===y.bottom||re===y.inline_start||re===y.inline_end||re===y.block_start||re===y.block_end||re===y.both||re===y.all||re===y.same)&&(delete d.clear,d.display&&d.display!=y.inline&&(this.nodeContext.clearSide=re.toString())));let P=w===y.list_item&&d["ua-list-item-count"],C=d["break-inside"];(x||C&&!J(C)&&C!==y.auto)&&this.nodeContext.breakPenalty++,w&&w!==y.inline&&qt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!x&&!w||qt(w)||Sh(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=x?W.toString():null,this.nodeContext.floatReference=v||Ae.INLINE;let E=d["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=E&&!J(E)?E:null;let R=this.isInsideNonRootMultiColumn(),A=d["column-span"];if(this.nodeContext.columnSpan=!R&&A&&!J(A)?A:null,!this.nodeContext.inline){let M=d["break-after"];M&&!J(M)&&!(R&&M===y.column)&&(this.nodeContext.breakAfter=M.toString(),Ys[this.nodeContext.breakAfter]&&delete d["break-after"]);let Q=d["break-before"];Q&&!J(Q)&&!(R&&Q===y.column)&&(this.nodeContext.fragmentIndex===1&&(this.nodeContext.breakBefore=Q.toString()),Ys[this.nodeContext.breakBefore]&&delete d["break-before"]);let ee=d.page,he=ee&&!J(ee)&&ee.toString();!he&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||w===y.table_header_group||w===y.table_footer_group)&&(he=this.styler.cascade.currentPageType),!he||he.toLowerCase()==="auto"?he=this.nodeContext.pageType:this.nodeContext.pageType=he,this.styler.cascade.currentPageType!==he&&!(!he&&d.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!sn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),he!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=he)}this.nodeContext.verticalAlign=d["vertical-align"]&&d["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=d["caption-side"]&&d["caption-side"].toString()||"top";let O=d["border-collapse"];if(!O||O===B("separate")){let M=d["border-spacing"],Q,ee;M&&(M instanceof ye?(Q=M.values[0],ee=M.values[1]):Q=ee=M,Q.isNumeric()&&(this.nodeContext.inlineBorderSpacing=We(Q,this.context)),ee.isNumeric()&&(this.nodeContext.blockBorderSpacing=We(ee,this.context)))}let z=d["footnote-policy"];this.nodeContext.footnotePolicy=z&&!J(z)?z:null;let $=d["x-first-pseudo"];if($){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new zp(M,$.num)}this.nodeContext.inline||this.processAfterIfcontinues(l,p,c,this.context);let X=d["white-space"];if(X){let M=hh(X.toString());M!==null&&(this.nodeContext.whitespace=M)}let Y=d["hyphenate-character"];Y&&Y instanceof Re&&(this.nodeContext.hyphenateCharacter=Y.str);let q=d["word-break"],me=d["line-break"],te=d["overflow-wrap"];(q===y.break_all||me===y.anywhere||te===y.break_word||te===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,w,U,W,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(d),this.findAndProcessRepeatingElements(l,c));let se=!1,ve=null,be=[],K=l.namespaceURI,H=l.localName;if(K=="http://www.w3.org/1999/xhtml"?(H=="html"||H=="body"||H=="script"||H=="link"||H=="meta"?H="div":H=="vide_"?H="video":H=="audi_"?H="audio":H=="object"&&(se=!!this.customRenderer),l.getAttribute(to)&&(_=(L=p.content)==null?void 0:L.value)!=null&&_.url&&(H="img")):K=="http://www.idpf.org/2007/ops"?(H="span",K="http://www.w3.org/1999/xhtml"):K=="http://www.pyroxy.com/ns/shadow"?(K="http://www.w3.org/1999/xhtml",H=this.nodeContext.inline?"span":"div"):se=!!this.customRenderer,P)t?H="li":(H="div",w=y.block,d.display=w);else if(H=="body"||H=="li")H="div";else if(H=="q")H="span";else if(H=="a"){let M=d["hyperlink-processing"];M&&M.toString()!="normal"&&(H="span")}d.behavior&&d.behavior.toString()!="none"&&this.customRenderer&&(se=!0),l.dataset&&l.getAttribute("data-math-typeset")==="true"&&(se=!0);let oe;if(se){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;oe=this.customRenderer(l,M,d)}else oe=N(null);oe.then(M=>{if(M)se&&(a=M.getAttribute("data-adapt-process-children")=="true");else if(d.display===y.none){h.finish(!1);return}else M=this.createElement(K,H);H=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),ve&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ve),M.appendChild(ve)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&fw(M);let Q=this.nodeContext.inheritedProps["image-resolution"],ee=[],he=d.width,Ye=d.height,tc=l.getAttribute("width"),ic=l.getAttribute("height"),ms=he===y.auto||!he&&!tc,ws=Ye===y.auto||!Ye&&!ic,go=l.attributes,nc=go.length,xn=null,mo=null;for(let Ze=0;Ze<nc;Ze++){let mt=go[Ze],Qe=mt.namespaceURI,ie=mt.localName,Ne=mt.nodeValue;if(Qe){if(Qe=="http://www.w3.org/2000/xmlns/")continue;Qe=="http://www.w3.org/1999/xlink"&&ie=="href"&&(Ne=this.documentURLTransformer.transformURL(this.resolveURL(Ne),this.xmldoc.url))}else{if(!vt&&ie.match(/^on/)||ie=="style")continue;if((ie=="id"||ie=="name")&&t){let Be=this.documentURLTransformer.transformFragment(Ne,this.xmldoc.url);if(vt&&M.localName!=="tr"&&!(M.namespaceURI==="http://www.w3.org/2000/svg"&&M.localName!=="svg")&&!M.ownerDocument.getElementById(Ne)){M.setAttribute(ie,Ne),M.setAttribute("data-vivliostyle-id",Be);let Ht=M.ownerDocument.createElement("a");Ht.setAttribute(ie,Be),Ht.setAttribute(xi,"1"),Ht.style.position="absolute",M.appendChild(Ht)}else M.setAttribute(ie,Be);this.page.registerElementWithId(M,Be);continue}if(ie=="src"||ie=="href"||ie=="poster")Ne=this.resolveURL(Ne),ie==="href"&&(Ne=this.documentURLTransformer.transformURL(Ne,this.xmldoc.url));else if(ie=="srcset")Ne=Ne.split(",").map(Be=>this.resolveURL(Be.trim())).join(",");else if(ie==="data"&&se&&H==="object"&&M.hasAttribute("data"))continue;if(ie==="poster"&&H==="video"&&K==="http://www.w3.org/1999/xhtml"&&ms&&ws){let Be=new Image,Ht=ri(Be,Ne);be.push(Ht),ee.push({image:Be,element:M,fetcher:Ht})}}if(K=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ie)&&(ie=ie.toLowerCase()),this.isSVGUrlAttribute(ie)&&(Ne=dw(Ne,this.xmldoc.url,this.documentURLTransformer)),Qe){let Be=pw[Qe];Be&&(ie=`${Be}:${ie}`)}if(ie=="src"&&!Qe&&(H=="img"||H=="input")&&K=="http://www.w3.org/1999/xhtml")xn=Ne;else if(ie=="alt"&&!Qe&&H=="img"&&K=="http://www.w3.org/1999/xhtml")mo=Ne;else if(ie=="href"&&H=="image"&&K=="http://www.w3.org/2000/svg"&&Qe=="http://www.w3.org/1999/xlink")this.page.fetchers.push(ri(M,Ne));else if(Qe)M.setAttributeNS(Qe,ie,Ne);else try{M.setAttribute(ie,Ne)}catch(Be){D.warn(Be)}}if(xn){let Ze=H==="input"?new Image:M,mt=ri(Ze,xn,mo);Ze!==M&&(M.src=xn);let Qe=()=>{var ie,Ne;if(d.position===y.fixed)return!0;for(let Be=(ie=this.nodeContext.parent)==null?void 0:ie.viewNode;Be&&Be!==this.viewRoot;Be=Be.parentElement)if(((Ne=Be.style)==null?void 0:Ne.position)==="fixed")return!0;return!1};!ms&&!ws&&!(()=>{let ie=this.nodeContext.vertical?he:Ye;return ie instanceof T&&ie.unit==="%"})()&&!Qe()?this.page.fetchers.push(mt):(ms&&ws&&Q&&Q!==1&&ee.push({image:Ze,element:M,fetcher:mt}),be.push(mt))}delete d.content;let bs=d["list-style-image"];if(bs&&bs instanceof ct){let Ze=bs.url;be.push(ri(new Image,Ze))}if(this.preprocessElementStyle(d),this.applyComputedStyles(M,d),this.nodeContext.inline)t||(nt(M,"inline-start"),_i(M)&&nt(M,"clone"));else if(t){if(!Gr(d.position)){let Ze=d["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),Qe=mt!==null,ie=mt==="auto";(Ze===y.discard&&Qe||Ze!==y.keep&&ie&&!this.nodeContext.floatSide)&&Is(M,"block-start")}}else{let Ze=this.nodeContext.vertical?"width":"height";Rt(M,Ze)&&k(M,Ze,this.nodeContext.display==="table-row"?"0.01px":""),nt(M,"block-start"),_i(M)&&nt(M,"clone"),Is(M,"block-start")}P&&M.setAttribute("value",d["ua-list-item-count"].stringValue()),this.viewNode=M,be.length?os(be).then(()=>{Q>0&&this.modifyElemDimensionWithImageResolution(ee,Q,d,this.nodeContext.vertical),h.finish(a)}):h.timeSlice().then(()=>{h.finish(a)})})}),h.result()}isInsideNonRootMultiColumn(){var t;for(let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;i;i=i.parentNode){let n=i.nodeType===1?i.style:null;if(!n)break;if(!isNaN(parseFloat(n.columnCount))||!isNaN(parseFloat(n.columnWidth)))return!0;if(n.position==="absolute")break}return!1}getBreakTypeAt(t){var i,n,s,r,o;for(let h=t;h&&!h.after;h=h.parent){if(Ke(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let c=this.viewport.window.getComputedStyle(l),p=parseFloat(c.paddingBlockStart),d=parseFloat(c.borderBlockStartWidth);if(p||d)return null;let f=l?.firstChild;for(;f&&(Ve(f,h.parent.whitespace)||!h.floatSide&&Vi(f));)f=f.nextSibling;if(f&&f!==h.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return Ke(a)?a:"auto"}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new ga(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new dg(t,o)}}isSVGUrlAttribute(t){return Er.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,h=o.height/i,l=r.element;if(a>0&&h>0){if(n["box-sizing"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=We(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=We(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(h+=We(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(h+=We(n["border-bottom-width"],this.context))),i>1){let c=n["max-width"]||y.none,p=n["max-height"]||y.none;if(c===y.none&&p===y.none)k(l,"max-width",`${a}px`);else if(c!==y.none&&p===y.none)k(l,"width",`${a}px`);else if(c===y.none&&p!==y.none)k(l,"height",`${h}px`);else{c.isNumeric(),p.isNumeric();let d=c,f=p;d.unit!=="%"?k(l,"max-width",`${Math.min(a,We(d,this.context))}px`):f.unit!=="%"?k(l,"max-height",`${Math.min(h,We(f,this.context))}px`):s?k(l,"height",`${h}px`):k(l,"width",`${a}px`)}}else if(i<1){let c=n["min-width"]||le,p=n["min-height"]||le;c.isNumeric(),c.isNumeric();let d=c,f=p;d.num===0&&f.num===0?k(l,"min-width",`${a}px`):d.num!==0&&f.num===0?k(l,"width",`${a}px`):d.num===0&&f.num!==0?k(l,"height",`${h}px`):d.unit!=="%"?k(l,"min-width",`${Math.max(a,We(d,this.context))}px`):f.unit!=="%"?k(l,"min-height",`${Math.max(h,We(f,this.context))}px`):s?k(l,"height",`${h}px`):k(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){pt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof ti&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new ti(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||J(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=F("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=qo(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=F("preprocessTextContent"),s=pt("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Np(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=F("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let h=(p,d)=>p?.nodeType===1&&di(p)===d,l=this.nodeContext.parent,c=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;c&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Ve(this.viewNode))&&!c.hasChildNodes()&&rh(c).includes("block-start")&&nt(c,"text-start"),c.appendChild(this.viewNode))}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==rt.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=rt.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let l=new zi(r,s,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,l}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=rt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==rt.ROOTLESS&&(s=s.firstChild),s){let r=new zi(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new zi(n,t,i));if(t.sourceNode.nodeType!=1){let s=qo(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=Ue(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=F("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof qe){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ct){let i=t.url;this.page.fetchers.push(ri(new Image,i))}}applyComputedStyles(t,i){var n,s,r;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===y.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),l=Object.keys(i);l.sort(_o);let c,p;for(let d of l){if(mw[d])continue;let f=i[d];if(!(!f||f===G&&!Nt(d))){if(f=f.visit(new Sd(this.xmldoc.url,this.documentURLTransformer)),f instanceof T&&cl(f.unit)&&(f.unit==="lh"?f=new T(f.num*this.getLineHeightUnitSize(d,c,p),"px"):f=Al(f,this.context)),d==="font-size"?c=f:d==="line-height"&&(p=f),Ip[d]||a&&Ap[d]){this.page.delayedItems.push(new $r(t,d,f));continue}h&&this.page.pageAreaElement&&qi(d)?k(this.page.pageAreaElement.parentElement,d,f.toString()):k(t,d,f.toString())}}}getLineHeightUnitSize(t,i,n){var s,r,o,a;let h=we.lh/we.em,l=((r=(s=this.nodeContext.parent)==null?void 0:s.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,c=l?parseFloat(l.fontSize):this.context.fontSize(),p=l?l.lineHeight==="normal"?c*h:parseFloat(l.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return p;let d=null;if(n){if(n instanceof Ut||n instanceof T&&(n.unit==="em"||n.unit==="%"))d=n instanceof T&&n.unit==="%"?n.num/100:n.num;else if(n instanceof T)return n.num*this.context.queryUnitSize(n.unit,!1)}else for(let f=(o=this.nodeContext.parent)==null?void 0:o.viewNode;;f=f.parentNode){if(!f||f.nodeType!==1){d=h;break}let g=(a=f?.style)==null?void 0:a.lineHeight;if(g){/^[0-9.]+$/.test(g)&&(d=parseFloat(g)),g==="normal"&&(d=h);break}}return d!==null?i instanceof T?d*Oh(i,c,this.context).num:d*c:p}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=dt(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let h=a.content;Vt(h)&&(h.visit(new qn(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=F("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let p=t.viewNode.textContent;t.viewNode.textContent=p.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let p=t.viewNode.parentNode;p&&p.removeChild(t.viewNode)}let a=t.boxOffset+i,h=[];for(;t.firstPseudo===s;)h.push(t),t=t.parent;let l=h.pop(),c=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new zi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=r,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.shadowSibling:c,c=null;let p=this.setCurrent(t,!1);if(p.isPending())return p}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},r=dt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");wr(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let h=t.sourceNode.nextSibling,l=(n=Ue(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!qt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=r;h;h=h.parent){if(((s=h.viewNode)==null?void 0:s.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(nt(l,"inline-end"),_i(l)){let c=h.vertical?l.offsetWidth:l.offsetHeight;nt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>c&&this.fixClonedBoxDecorationOverflow(l)}}else{let c=this.nodeContext.vertical?"width":"height";if(Rt(l,c)&&k(l,c,""),nt(l,"block-end"),!a++&&h!==r){let{textAlign:p}=this.viewport.window.getComputedStyle(l);if(p==="justify"&&!o){let d=this.createChildAnonymousBlockIfNeeded(l);d?d!==l?oh(d,["block-start","text-start","block-end","text-end","justify"]):(nt(l,"text-end"),nt(l,"justify")):nt(l,"text-end")}else nt(l,"text-end")}_i(l)&&nt(l,"clone"),Is(l,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:h}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||Xt[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let l=r.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===r.lastChild&&Ve(l.nextSibling))){let c=i(l);if(c||c===null)return c}for(let c=l?.previousElementSibling;c;c=c.previousElementSibling){let p=i(c);if(p||p===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||r.hasAttribute(xi)){let l=r.previousElementSibling;return l&&(l.nextSibling===r||l.nextSibling===r.previousSibling&&Ve(l.nextSibling))?i(l):!1}return!(!o||qt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&Ve(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if(Gc(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,Zr(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&di(n)===di(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!di(t)}};u(Uu,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var gw=Uu,mw={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},Dn=null,ww=class{constructor(e){u(this,"layoutBox"),u(this,"window"),u(this,"scaleRatio"),this.layoutBox=e.layoutBox,this.window=e.window,this.scaleRatio=e.scaleRatio}scaleRect(e){return Dn?{left:e.left*this.scaleRatio,top:e.top*this.scaleRatio,right:e.right*this.scaleRatio,bottom:e.bottom*this.scaleRatio,width:e.width*this.scaleRatio,height:e.height*this.scaleRatio}:e}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.scaleRect(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.scaleRect(this.subtractOffsets(t,i))}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){let t=64*(this.scaleRatio||1);return Math.floor(e*t)/t}},es=class{constructor(e,t,i,n,s,r){this.window=e,this.fontSize=t,this.pixelRatio=i,u(this,"document"),u(this,"root"),u(this,"outerZoomBox"),u(this,"contentContainer"),u(this,"layoutBox"),u(this,"width"),u(this,"height"),u(this,"scaleRatio",1),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),this.root.appendChild(o));let a=o.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(k(this.root,"--viv-outputPixelRatio",`${i}`),k(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio,Dn===null&&(Dn=!("currentCSSZoom"in a)),Dn&&k(this.root,"--viv-scaleRectRatio",`${this.scaleRatio}`));let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,this.width=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let l={width:794,height:1056},c=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&c)&&(this.width=l.width),(!this.height||!r&&c)&&(this.height=l.height)}resetZoom(){k(this.outerZoomBox,"width",""),k(this.outerZoomBox,"height",""),k(this.contentContainer,"width",""),k(this.contentContainer,"height",""),k(this.contentContainer,"transform","")}zoom(e,t,i){k(this.root,"--viv-outputScale",`${i}`),k(this.outerZoomBox,"width",`${e*i}px`),k(this.outerZoomBox,"height",`${t*i}px`),k(this.contentContainer,"width",`${e}px`),k(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},Hu=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,u(this,"lang",null),u(this,"totalOffset",-1),u(this,"root"),u(this,"body"),u(this,"head"),u(this,"last"),u(this,"lastOffset",1),u(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(xt,"0")}doc(){return new Gu([this.document])}getElementOffset(e){let t=e.getAttribute(xt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(xt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let h=_t(a.length,l=>{let c=a[l];return this.getElementOffset(c)>e});if(h==0)break;i=a[h-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},kr=(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))(kr||{});function Rn(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function bw(e){let t=e.contentType;if(t){let n=Object.keys(kr);for(let s=0;s<n.length;s++)if(kr[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./]+)$/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function $u(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=bw(e);if(i=Rn(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=Rn(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=Rn(r,"image/svg+xml",s))}i||(i=Rn(r,"text/html",s))}}let n=i?new Hu(t,e.url,i):null;return N(n)}function vw(){return new Dr($u,"document")}var yw=class Nr{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Nr(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Nr(n=>{if(!this.check(n))return!1;let s=new Gu([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},Oa=new yw(e=>!0),Gu=class Pr{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new Pr(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new Pr(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},xw=new mn(()=>{let e=F("uaStylesheetBase"),t=ku(),i=ke("user-agent-base.css",Jt),n=new rn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Zf(n.cascade),Ur(Wl,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Sw(){return xw.get()}var Cw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=h,this.pageProps=l,u(this,"fontDeobfuscator"),u(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(c){c=c;let p=this,d=p.currentLayoutPosition,f=d.firstFlowChunkOfFlow(c);return p.matchPageSide(d.startSideOfFlow(c))&&d.hasContent(c,p.lookupOffset)&&!!f&&!p.flowChunkIsAfterParentFlowForcedBreak(f)}),this.pageScope.defineName("page-number",new De(this.pageScope,function(){let c=this;return c.pageNumberOffset+c.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new De(this.pageScope,function(){let c=this.currentLayoutPosition;return c?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Vs(this.rootScope,e,t,i),r=pf(s,this.viewportProps),o=r.width,a=r.height,h=r["text-zoom"],l=1;if(o&&a||h){let c=we.em;if((h?h.evaluate(s,"text-zoom"):null)===y.scale&&(l=c/i,i=c,e*=l,t*=l),o&&a){let p=We(o.evaluate(s,"width"),s),d=We(a.evaluate(s,"height"),s);if(p>0&&d>0)return{width:n&&n.spreadView?(p+n.pageBorder)*2:p,height:d,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},Wu=class extends Vs{constructor(e,t,i,n,s,r,o,a,h,l,c,p,d){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=h,this.documentURLTransformer=l,this.counterStore=c,u(this,"lang"),u(this,"primaryFlows",{body:!0}),u(this,"rootPageBoxInstance",null),u(this,"styler",null),u(this,"stylerMap",null),u(this,"currentLayoutPosition",null),u(this,"layoutPositionAtPageStart",null),u(this,"lookupOffset",0),u(this,"faces"),u(this,"pageBoxInstances",{}),u(this,"pageManager",null),u(this,"rootPageFloatLayoutContext"),u(this,"pageBreaks",{}),u(this,"pageProgression",null),u(this,"isVersoFirstPage",!1),u(this,"blankPageAtStart",!1),u(this,"pageSheetSize",{}),u(this,"pageSheetHeight",0),u(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new km(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Di(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!d;for(let f in e.flowProps){let g=e.flowProps[f],m=Ue(g,"flow-consume");m&&(m.evaluate(this,"flow-consume")==y.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=F("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new ya(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=Bu(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new Rm(s);let r=this.style.cascade.createInstance(this,t,i,this.lang);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new qm(r,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Em(h.properties,this),c=new Nu(l);o.push(c)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{uw(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context);let c=Ra(Qn(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 Vs(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new ya(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r),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 Vp,i.flowPositions[e.flowName]=n);let s=Mp(e.element),r=new Dt(s),o=new Dp(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,c){}}let r=new s,o=Ti(this.style.rootScope,new gt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new ju(null),i=new gt(e+"{}",t);return new bn(Ee,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let h=this.xmldoc.getNodeOffset(s,r,o);h<t&&(t=h)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){D.debug("Location - page",this.currentLayoutPosition.page),D.debug(" current:",e),D.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)D.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new ze(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=Xo(Xe(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===co)continue;let o=1;s.pageBox.pseudoName===ao&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),c=Math.ceil(o*l/(h*h)),p=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,c),this.styler.cascade.currentPageType=p,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let d=s.getProp(this,"enabled");if(!d||d===y._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=_t(s.length,l=>s[l]>n)-1,o=s[r],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Xr(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Ae.PAGE)return!1;let h=this.layoutPositionAtPageStart.flowPositions.body,l=h&&this.getConsumedOffset(h),c=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return c!=null&&l!=null&&c>l},s=F("layoutDeferredPageFloats"),r=!1,o=0;return s.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let h=i[o++],l=h.float;if(n(l)){a.breakLoop();return}let c=new Si().findByFloat(l),p=c.findPageFloatFragment(l,t);if(p&&p.hasFloat(l)){a.continueLoop();return}else if(t.isForbidden(l)||t.hasPrecedingFloatsDeferredToNext(l)){t.deferPageFloat(h),a.breakLoop();return}e.layoutPageFloatInner(h,c,null,p).then(d=>{if(!d){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new Dt(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=F("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let h=0;for(;r.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let d=h+1;d<i.positions.length;d++){if(r.includes(d))continue;let f=i.positions[d];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(l.flowChunk)&&(l=f,h=d)}let c=l.flowChunk,p=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(d=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(d===null||c.exclusive)&&s.push(h),c.exclusive){r.push(h),a.breakLoop();return}else{let f=!!d||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,d);if(e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(r.push(h),(d||g)&&(l.chunkPosition=d||g,s.push(h)),i.startBreakType=Xo(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,p?p=!1:a.continueLoop()}),p){p=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((h,l)=>s.includes(l)||!r.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new wg([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,h,l,c,p,d,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=s.element,v=new Di(a,Ae.COLUMN,null,o,null,null,null),b=this.currentLayoutPosition.clone(),w=F("createAndLayoutColumn"),S;return w.loopWithFrame(I=>{let L=this.createLayoutConstraint(v);if(h>1){let _=this.viewport.document.createElement("div");if(k(_,"position","absolute"),m.appendChild(_),S=new Kn(_,d,this.clientLayout,L,v),S.forceNonfitting=f,S.vertical=s.vertical,S.rtl=s.rtl,S.snapHeight=s.snapHeight,S.snapWidth=s.snapWidth,s.vertical){let U=(s.rtl?h-r-1:r)*(c+l)+s.paddingTop,W=parseFloat(m.style.width);S.setHorizontalPosition(s.paddingLeft+W-s.width,s.width),S.setVerticalPosition(U,c)}else{let U=(s.rtl?h-r-1:r)*(c+l)+s.paddingLeft;S.setVerticalPosition(s.paddingTop,s.height),S.setHorizontalPosition(U,c)}S.originX=t,S.originY=i}else S=new Kn(m,d,this.clientLayout,L,v),S.copyFrom(s);S.exclusions=g?[]:n.concat(),S.innerShape=p,v.setContainer(S),(S.vertical?S.height:S.width)>=0?this.layoutColumn(S,o).then(()=>{v.isInvalidated()||v.finish(),S.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(S.pageFloatLayoutContext.validate(),this.currentLayoutPosition=b.clone(),S.element!==m&&m.removeChild(S.element),I.continueLoop()):I.breakLoop()}):(v.finish(),I.breakLoop())}).then(()=>{w.finish(S)}),w.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof zu||t instanceof lo&&!(t instanceof Qi))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof cn;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new Di(e,Ae.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,h){let l=this.currentLayoutPosition.clone(),c=this.getRegionPageFloatLayoutContext(r,t,o,a),p=!0,d=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,s,r,c,o,a,h,p).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return d().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let g=t.getProp(this,"column-fill")||y.balance,m=this.currentLayoutPosition.flowPositions[a],v=rm(h,g,d,c,o,f.columns,m);return v?(p=!1,r.lock(),c.lock(),v.balanceColumns(f).thenAsync(b=>(r.unlock(),r.validate(),c.unlock(),this.currentLayoutPosition=b.position,N(b.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,h,l,c){let p=F("layoutFlowColumns"),d=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),g=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,m=t.getActiveRegions(this),v=t.getProp(this,"shape-inside"),b=Bl(v,0,0,a.width,a.height,this),w=new gw(h,this,this.viewport,this.styler,m,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),S=0,I=null,L=[];return p.loopWithFrame(_=>{this.createAndLayoutColumn(t,i,n,s,a,S++,h,o,l,f,g,b,w,c).then(U=>{if(r.isInvalidated()){L=null,_.breakLoop();return}if((U.pageBreakType&&U.pageBreakType!=="column"||S===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){S=0,this.currentLayoutPosition=d.clone(),o.validate(),o.isLocked()?(L=null,_.breakLoop()):_.continueLoop();return}I=U,L[S-1]=I,I.pageBreakType&&I.pageBreakType!="column"&&(S=l,I.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),S<l?_.continueLoop():_.breakLoop()})}).then(()=>{p.finish(L)}),p.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return N(!0);let h=F("layoutContainer"),l=t.getProp(this,"wrap-flow")===y.auto,c=t.getProp(this,"flow-from"),p=this.viewport.document.createElement("div"),d=t.getProp(this,"position");k(p,"position",d?d.name:"absolute");let f=t instanceof Qi;t instanceof cn?i.appendChild(p):i.insertBefore(p,i.firstChild);let g=new mh(p);g.vertical=t.vertical,g.rtl=t.rtl,g.exclusions=r,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof Qi&&(g.width<=0||g.height<=0)&&D.warn("Negative or zero page area size"),g.originX=n,g.originY=s,n+=g.left+g.marginLeft+g.borderLeft,s+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let m,v=!1;if(!c||!c.isIdent()){let b=t.getProp(this,"content");if(b instanceof V&&b.expr instanceof De&&b.expr.str.startsWith("running-element-"))b.visit(new qn(p,this,b,this.counterStore.getExprContentListener()));else if(b&&Vt(b)){let w="span";b.url&&(w="img");let S=this.viewport.document.createElement(w);b.visit(new qn(S,this,b,this.counterStore.getExprContentListener())),p.appendChild(S),w=="img"&&t.transferSingleUriContentProps(this,S,this.faces),t.transferContentProps(this,g,e,this.faces),w=="span"&&hg(S,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(p),v=!0);v||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0)}else if(this.pageBreaks[c.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0);else{let b=F("layoutContainer.inner"),w=c.toString(),S=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,g,w,S).then(I=>{if(!o.isInvalidated()){let L=I[0];L.element===p&&(g=L),g.computedBlockSize=Math.max.apply(null,I.map(U=>U.computedBlockSize)),t.finishContainer(this,g,e,L,S,this.clientLayout,this.faces);let _=this.currentLayoutPosition.flowPositions[w];_&&_.breakAfter==="region"&&(_.breakAfter=null)}b.finish(!0)}),m=b.result()}return m.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!v&&!l){let w=t.getProp(this,"shape-outside"),S=g.getOuterShape(w,this);r.push(S)}}else if(t.children.length==0){i.removeChild(p),h.finish(!0);return}let b=f?0:t.children.length-1;h.loop(()=>{for(;b>=0&&b<t.children.length;){let w=t.children[f?b++:b--],S=this.layoutContainer(e,w,p,n,s,r,o);if(S.isPending())return S.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Up,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);t.page++;let r=t.startSideOfFlow("body");t.isBlankPage=sn(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let o=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);this.styler.cascade.applyVarFilter([o],this.styler,null),this.styler.cascade.applyCalcFilter(o,this.styler.context);let a=this.selectPageMaster(o);if(!a)return N(null);let h=0;if(!n){e.setAutoPageWidth(a.pageBox.specified.width.value===Ni),e.setAutoPageHeight(a.pageBox.specified.height.value===Pi),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(o,this);let f=Ra(Qn(o),this);this.setPageSizeAndBleed(f,e),Um(o,f,e,this),h=f.bleedOffset+f.bleed}let l=!n&&a.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=l!=y.horizontal_tb;let c=a.getProp(this,"direction")||y.ltr,p=new Di(this.rootPageFloatLayoutContext,Ae.PAGE,null,null,null,l,c),d=F("layoutNextPage");return d.loopWithFrame(f=>{this.layoutContainer(e,a,e.bleedBox,h,h,[],p).then(()=>{p.isInvalidated()||p.finish(),p.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),p.validate(),f.continueLoop()):f.breakLoop()})}).then(()=>{if(a.adjustPageLayout(this,e,this.clientLayout),!n){let g=new ze(a.pageBox.scope,"left-page");e.side=g.evaluate(this)?"left":"right",this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(m=>{let v=t.flowPositions[m],b=v.breakAfter;b&&(b==="page"||!this.matchPageSide(b))&&(v.breakAfter=null)})}this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let f=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(f,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),d.finish(t)}),d.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},Ew=class Tr extends rn{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,u(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new Pu(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Om(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=lt(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Tr(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new tg(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new An(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new An(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new An(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=us(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new An(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new rw(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(rn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Tr(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},ju=class extends up{constructor(e){super(),this.validatorSet=e,u(this,"rootScope"),u(this,"pageScope"),u(this,"rootBox"),u(this,"cascadeParserHandler"),u(this,"regionCount",0),u(this,"fontFaces",[]),u(this,"footnoteProps",{}),u(this,"flowProps",{}),u(this,"viewportProps",[]),u(this,"pageProps",{}),this.rootScope=new Ds(null),this.pageScope=new Ds(this.rootScope),this.rootBox=new Tm(this.rootScope),this.cascadeParserHandler=new Ew(this,null,null,null),this.slave=this.cascadeParserHandler}};function kw(e,t){return t.parseOPSResource(e)}var Nw=class extends Dr{constructor(e){super(kw,"document"),this.fontDeobfuscator=e,u(this,"styleByKey",{}),u(this,"styleFetcherByKey",{}),u(this,"styleByDocURL",{}),u(this,"triggersByDocURL",{}),u(this,"validatorSet",null),u(this,"styleSheets",[]),u(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=F("OPSDocStore.init");return this.validatorSet=ku(),Sw().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=ke(nn(t),vi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=ke(nn(t),vi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=F("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return $u(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let d=pt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<d.length;f++)try{d[f](s.document)}catch(g){D.warn("Error during single document preprocessing:",g)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let d=0;d<a.length;d++){let f=a[d],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&&o.push({observer:g,event:m,action:v,ref:b})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:ke("user-agent-page.css",Jt),text:Gl,flavor:"UA",classes:null,media:null}),n)h.push({url:ke("user-agent-toc.css",Jt),text:jl,flavor:"UA",classes:null,media:null});else{let d=s.document.querySelectorAll("style, link, meta");for(let f of d){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"),w=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:w?v:null,media:b})}else if(m=="link"){let v=f.getAttribute("href"),b=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),w=f.getAttribute("class"),S=f.getAttribute("media");if(v&&b!=null&&b.includes("stylesheet")&&(!b.includes("alternate")||w)){let I=ke(v,i),L=f.getAttribute("title");h.push({url:I,text:null,classes:L?w:null,media:S,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 d=0;d<h.length;d++)l+=h[d].url,l+="^",h[d].text&&(l+=h[d].text),l+="^";let c=this.styleByKey[l];if(c){this.styleByDocURL[i]=c,t.finish(s);return}let p=this.styleFetcherByKey[l];p||(p=new mn(()=>{let d=F("fetchStylesheet"),f=0,g=new ju(this.validatorSet);return d.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Ur(m.text,g,m.url,m.classes,m.media).thenReturn(!0):Ql(m.url,g,m.classes,m.media)}return N(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();c=new Cw(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps),this.styleByKey[l]=c,delete this.styleFetcherByKey[l],d.finish(c)}),d.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=p,p.start()),p.get().then(d=>{this.styleByDocURL[i]=d,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},en="\u25B8",Ba="\u25BE",Pw="\u25B9";function fo(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function Tw(e){let t=fo(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var Iw=class{constructor(e,t,i,n,s,r,o,a,h,l){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,u(this,"pref"),u(this,"page",null),u(this,"instance",null),this.pref=al(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;Rt(n,"height","auto")!="auto"&&(k(n,"height","auto"),this.setAutoHeight(n,t)),Rt(n,"position","static")=="absolute"&&(k(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=y.inherit,s["text-decoration"]=y.none;break;case"toc-node":s.display=y.block,s.margin=le,s.padding=le,s["padding-inline-start"]=new T(1.25,"em");break;case"toc-node-first-child":s.display=y.inline_block,s.margin=new T(.2,"em"),s["vertical-align"]=y.top,s.color=y.inherit,s["text-decoration"]=y.none;break;case"toc-container":s.padding=le;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&Ve(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=en&&(l.textContent=en,k(l,"cursor","pointer"),l.addEventListener("click",Aw,!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"),r.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Pw,k(l,"margin","0.2em 0 0 -1em"),k(l,"margin-inline-start","-1em"),k(l,"margin-inline-end","0"),k(l,"display","inline-block"),k(l,"width","1em"),k(l,"text-align","center"),k(l,"vertical-align","top"),k(l,"cursor","default"),k(l,"font-family","Menlo,sans-serif"),h.appendChild(l),k(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){k(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 N(h)}}showTOC(e,t,i,n,s){if(this.page)return N(this.page);let r=F("showTOC"),o=new lh(e,e);this.page=o;let a=Ct(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of fo(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),c=l.sizeViewport(i,1e5,s);t=new es(t.window,c.fontSize,0,t.root,c.width,c.height);let p=this.makeCustomRenderer(h),d=new Wu(l,h,this.lang,t,this.clientLayout,this.fontMapper,p,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=d,d.pref=this.pref,d.init().then(()=>{d.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),h=e(a);return{id:r,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function Aw(e){let t=e.target,i=t.textContent==en;t.textContent=i?Ba:en;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==Ba){a.textContent=en,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var _a=class extends Nw{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=vw(),this.jsonStore=op()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=F("loadPubDoc");return as(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}D.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Vn(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}D.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=F("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=F("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?this.loadAsPlainXML(`${e}META-INF/encryption.xml`).then(o=>{n=new Vn(this,e),n.initWithXMLDoc(r,o).then(()=>{this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,s.finish(n)})}):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=F("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Vn(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Ar(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=ke(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{s.initWithWebPubManifest(h,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&fo(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=F("EPUBDocStore.load"),n=Ct(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(vi)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?D.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&vi.startsWith("https:")?D.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?D.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):D.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Ct(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=F("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},Ma=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=Ac}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=ke(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=_c(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 Rw(e){return e.id}function Lw(e){return t=>{let i=F("deobfuscator");return Fw("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);np(s).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(ql([a,r]))})}),i.result()}}function Fw(e,t){let i=F("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Ft={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"},$i="http://idpf.org/epub/vocab/package/meta/#",Te={language:`${Ft.dcterms}language`,title:`${Ft.dcterms}title`,creator:`${Ft.dcterms}creator`,layout:`${Ft.rendition}layout`,titleType:`${$i}title-type`,displaySeq:`${$i}display-seq`,alternateScript:`${$i}alternate-script`,role:`${$i}role`};function Ow(e,t){let i={};return(n,s)=>{var r,o,a,h,l,c;let p,d,f=n.r||i,g=s.r||i;if(e==Te.title&&(p=((r=f[Te.titleType])==null?void 0:r[0].v)=="main",d=((o=g[Te.titleType])==null?void 0:o[0].v)=="main",p!=d))return p?-1:1;let m=parseInt((a=f[Te.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let v=parseInt((h=g[Te.displaySeq])==null?void 0:h[0].v,10);return isNaN(v)&&(v=Number.MAX_VALUE),m!=v?m-v:e!=Te.language&&t&&(p=((l=f[Te.language]||f[Te.alternateScript])==null?void 0:l[0].v)==t,d=((c=g[Te.language]||g[Te.alternateScript])==null?void 0:c[0].v)==t,p!=d)?p?-1:1:n.o-s.o}}function Bw(e,t){let i;if(!t)i=Ft;else{i={};for(let d in Ft)i[d]=Ft[d];let p;for(;(p=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(p[0].length),i[p[1]]=p[2]}let n=p=>{if(p){let d=p.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(d){let f=d[2]?i[d[2]]:$i;if(f)return f+d[3]}}return null},s=1,r=e.childElements().forEachNonNull(p=>{if(p.localName=="meta"){let d=n(p.getAttribute("property"));if(d)return{name:d,value:p.textContent,id:p.getAttribute("id"),order:s++,refines:p.getAttribute("refines"),lang:null,scheme:n(p.getAttribute("scheme")),role:null}}else if(p.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Ft.dcterms+p.localName,order:s++,lang:p.getAttribute("xml:lang"),value:p.textContent,id:p.getAttribute("id"),refines:null,scheme:null,role:p.getAttribute("role")||p.getAttribute("opf:role")};return null}),o=xs(r,p=>p.refines),a=p=>Mc(p,(d,f)=>d.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let v=o[`#${g.id}`]||[];if(v.length||g.lang||g.role){g.lang&&v.push({name:Te.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&v.push({name:Te.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let b=xs(v,w=>w.name);m.r=a(b)}return m})),h=a(xs(r,p=>p.refines?null:p.name)),l=null;h[Te.language]&&(l=h[Te.language][0].v);let c=p=>{for(let d in p){let f=p[d];f.sort(Ow(d,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&c(m)}}};return c(h),h}function _w(){let e=window.MathJax;return e?e.Hub:null}var za={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Os="viv-id-",Vn=class{constructor(e,t){this.store=e,this.pubURL=t,u(this,"opfXML",null),u(this,"encXML",null),u(this,"items",null),u(this,"spine",null),u(this,"itemMap",null),u(this,"itemMapByPath",null),u(this,"uid",null),u(this,"bindings",{}),u(this,"lang",null),u(this,"epageCount",0),u(this,"prePaginated",!1),u(this,"epageIsRenderedPage",!0),u(this,"epageCountCallback",null),u(this,"metadata",{}),u(this,"toc",null),u(this,"cover",null),u(this,"fallbackMap",{}),u(this,"pageProgression",null),u(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let r=s+(n?`#${n}`:"");return Os+il(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s,a=decodeURIComponent(r[2]);if(o&&e.spine.some(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Os)===0&&(n=n.substring(Os.length));let s=Bc(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=ke("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new Ma,c=h;l.initWithElement(c,e.url);let p=c.getAttribute("fallback");return p&&!za[l.mediaType]&&(s[l.src]=p),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Eo(this.items,Rw),this.itemMapByPath=Eo(this.items,h=>this.getPathFromURL(h.src));for(let h in s){let l=h;for(;;){let c=this.itemMap[s[l]];if(!c)break;if(za[c.mediaType]){this.fallbackMap[h]=c.src;break}l=c.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let c=h,p=c.getAttribute("idref"),d=this.itemMap[p];return d&&(d.itemRefElement=c,d.spineIndex=l),d});let r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=Xa(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Oa.withChild("EncryptionMethod",Oa.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=Bw(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Te.language]&&(this.lang=this.metadata[Te.language][0].v),this.metadata[Te.layout]&&(this.prePaginated=this.metadata[Te.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=Lw(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=F("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,h=o.lang||this.lang;h&&h.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Hu(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new Ma;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Te.title]=(Array.isArray(a)?a:[a]).map(m=>{var v;return{v:(v=m.value)!=null?v:m}}));let h=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(m=>m.content);h&&h.length!==0&&(this.metadata[Te.creator]=(Array.isArray(h)?h:[h]).map(m=>{var v;return{v:(v=m.name)!=null?v:m}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Te.language]=(Array.isArray(l)?l:[l]).map(m=>({v:m})));let c=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&c!==null){e.readingOrder=[encodeURI(c)];for(let m of Tw(t)){let v=m.getAttribute("href");if(/^(https?:)?\/\//.test(v)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(v))continue;let b=Ct(ke(v,this.pubURL)),w=this.getPathFromURL(b),S=w!==null?encodeURI(w):b;e.readingOrder.indexOf(S)==-1&&e.readingOrder.push(S)}}let p=[],d=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(v=>{let b=m===e.readingOrder,w=typeof v=="string"?v:v.url||v.href,S=typeof v=="string"?"":v.encodingFormat||v.href&&v.type||"";if(b||S==="text/html"||S==="application/xhtml+xml"||!S&&v.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(w)){let I=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,L={url:ke(nn(w),I),index:d++,startPage:null,skipPagesBefore:null};v.rel==="contents"&&f===-1&&(f=L.index),p.push(L)}})});let g=F("initWithWebPubManifest");return this.initWithChapters(p).then(()=>{var m,v;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(m=this.items)==null?void 0:m[0]:this.itemMapByPath[c]);let b=(v=e.readingOrder)==null?void 0:v.length;b&&b<this.items.length&&this.items.splice(b),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=F("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),h=t-a,l=new Ao;l.prependPathFromNode(r,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return yi("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Ao;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{D.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return yi("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=_t(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{D.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=F("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},Ln=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),Mw=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,u(this,"spineItems",[]),u(this,"spineItemLoadingContinuations",[]),u(this,"pref"),u(this,"clientLayout"),u(this,"counterStore"),u(this,"tocAutohide",!1),u(this,"tocVisible",!1),u(this,"tocView"),this.pref=al(n),this.clientLayout=new ww(t),this.counterStore=new Nd(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=F("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let h=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,h&&e.pages[t.page]&&(t.isSamePosition(h)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let h=this.counterStore.getUnresolvedRefsToPage(s),l=0;i.loopWithFrame(c=>{if(l++,l>h.length){c.breakLoop();return}let p=h[l-1];if(p.refs=p.refs.filter(d=>!d.isResolved()),p.refs.length===0){c.continueLoop();return}this.getPageViewItem(p.spineIndex).then(d=>{if(!d){c.continueLoop();return}let{currentPageType:f,previousPageType:g}=d.instance.styler.cascade,m=Object.entries(d.instance.scopes);this.counterStore.pushPageCounters(p.pageCounters),this.counterStore.pushReferencesToSolve(p.refs);let v=d.layoutPositions[p.pageIndex];this.renderSinglePage(d,v).then(b=>{d.instance.styler.cascade.currentPageType=f,d.instance.styler.cascade.previousPageType=g,d.instance.scopes=Object.fromEntries(m),this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let w=b.pageAndPosition.position;w.spineIndex===s.spineIndex&&w.pageIndex===o&&(s=b.pageAndPosition.page),c.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:Ln(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=_t(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=F("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(s=h.page,r=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Ln(s,r))})}),i.result()}renderPage(e){let t=F("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(Ln(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let c=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(r>=0&&i.instance.getPosition(h)>r){o=c,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=c,s=l.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(Ln(o,s));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||(i.complete=!0),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=F("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=F("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let h={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=F("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],h=r.pages[r.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=F("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),h=o&&o.page;h&&h.side===a.side&&(h=null),s?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=F("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=F("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){D.debug("Navigate to",e);let n=this.opf.getPathFromURL(Ct(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=F("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.setAttribute("role","region"),n.style.position="absolute",n.style.top="0",n.style.left="0",tn||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),n.appendChild(s);let r=new lh(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=ll(this.viewport.width,this.viewport.height,i.width,i.height),a=Ti(null,new gt(o,null),"");r.delayedItems.push(new $r(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=ke(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let h=So(s),l=So(o),c=new kt;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 m=g.getAttribute("name"),v=g.getAttribute("value");m&&v&&(c.append("&"),c.append(encodeURIComponent(m)),c.append("="),c.append(encodeURIComponent(v)))}}r.setAttribute("src",c.toString());let p=t.getAttribute("width");p&&r.setAttribute("width",p);let d=t.getAttribute("height");d&&r.setAttribute("height",d)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=_w();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let h=s.queue;h.Push(["Typeset",s,o]);let l=F("makeMathJaxView"),c=l.suspend();return h.Push(()=>{c.schedule(o)}),l.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=ke(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=F("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let h=s.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),s.title=o.document.title;let l=r.getStyleForDoc(o),c=this.makeCustomRenderer(o),p=this.viewport,d=l.sizeViewport(p.width,p.height,p.fontSize,this.pref);(d.width!=p.width||d.height!=p.height||d.fontSize!=p.fontSize)&&(p=new es(p.window,d.fontSize,p.pixelRatio,p.root,d.width,d.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,v;if(s.startPage!==null)m=s.startPage-1,v=m;else{if(e>0&&(!g||!g.complete))m=s.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,v=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let S=this.counterStore.currentPageCounters.page;v=!S||!S.length?m:S[S.length-1]}s.skipPagesBefore!==null&&(m+=s.skipPagesBefore,v+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(v);let b=new Wu(l,o,this.opf.lang,p,this.clientLayout,this.fontMapper,c,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);b.pref=this.pref;let w=this.opf.metadata&&this.opf.metadata[Te.title];b.pubTitle=w&&w[0]&&w[0].v||"",b.docTitle=s.title||"",b.init().then(()=>{!this.opf.pageProgression&&b.pageProgression&&(this.opf.pageProgression=b.pageProgression),t={item:s,xmldoc:o,instance:b,layoutPositions:[null],pages:[],complete:!1},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 N(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),N(this.tocView.page);let n=F("showTOC");this.tocView||(this.tocView=new Iw(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),tn||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(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()}},Da="data-vivliostyle-viewer-status",zw="data-vivliostyle-spread-view",Xu=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Xu||{}),Dw=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,u(this,"fontMapper"),u(this,"kick"),u(this,"sendCommand"),u(this,"resizeListener"),u(this,"hyperlinkListener"),u(this,"pageRuleStyleElement"),u(this,"pageSheetSizeAlreadySet",!1),u(this,"renderTask",null),u(this,"actions"),u(this,"readyState"),u(this,"packageURL"),u(this,"opf"),u(this,"touchActive"),u(this,"touchX"),u(this,"touchY"),u(this,"needResize"),u(this,"resized"),u(this,"needRefresh"),u(this,"viewportSize"),u(this,"currentPage"),u(this,"currentSpread"),u(this,"pagePosition"),u(this,"fontSize"),u(this,"zoom"),u(this,"fitToScreen"),u(this,"pageViewMode"),u(this,"waitForLoading"),u(this,"renderAllPages"),u(this,"pref"),u(this,"pageSizes"),u(this,"pixelRatio"),u(this,"pixelRatioLimit"),u(this,"viewport"),u(this,"opfView");let s=t.ownerDocument,r=(o,a)=>{let h=s.getElementById(o);return h||(h=s.createElement("style"),h.id=o,a&&(h.textContent=a),s.head.appendChild(h)),h};r("vivliostyle-viewport-screen-css",Vl),r("vivliostyle-viewport-css",Ul),r("vivliostyle-polyfill-css",Xl),t.setAttribute("data-vivliostyle-viewer-viewport",!0),tn&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(Da,"loading"),this.fontMapper=new Nm(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=ol(),this.pageSizes=[],this.pixelRatioLimit=/Chrome/.test(navigator.userAgent)?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Za;D.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),D.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),D.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),D.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(Da,e),this.callback({t:"readystatechange"}))}loadPublication(e){tt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=F("loadPublication");return this.configure(e).then(()=>{let o=new _a;o.init(n,s).then(()=>{let a=ke(nn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){tt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=F("loadXML");return this.configure(e).then(()=>{let a=new _a;a.init(s,r).then(()=>{let h=t.map((l,c)=>({url:ke(nn(l.url),this.window.location.href),index:c,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new Vn(a,""),this.opf.initWithChapters(h,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(tt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;if(s==="ex")return t*we.ex*this.fontSize/we.em;let r=we[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(vo(e.userAgentRootURL.replace(/resources\/?$/,"")),yo(e.userAgentRootURL)),typeof e.rootURL=="string"&&(vo(e.rootURL),yo(`${vi}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!==vt&&(aw(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){pt("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=>{k(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),k(e.container,"visibility","visible"),k(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=F("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?os(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new es(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new es(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return(e.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(zw,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(g){let m=g*.75;return Math.ceil(m)};var r=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),c=o(h),p=l*((this.pixelRatio||1)-1)+2,d=c*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}pt ${c}pt; margin: 0 ${-p}pt ${-d}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new Mw(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){let t=this.getAdjustedZoomFactor(e.dimensions);this.viewport.zoom(e.dimensions.width,e.dimensions.height,t)}setSpreadZoom(e){let t=this.getSpreadDimensions(e);this.viewport.zoom(t.width,t.height,this.getAdjustedZoomFactor(t))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Va),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Xs().getScheduler().run(()=>yi("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,tt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),tt.registerEndTiming("render (resize)"),vt&&Vu(this.window)?cw(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 Va)tt.registerEndTiming("render (resize)"),D.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=F("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=F("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=F("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=F("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return yi("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(D.error("No such action:",t),i.finish(!0))},(i,n)=>{D.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=Ua(e),i=null,n=this;Kd(()=>{let s=F("commandLoop"),r=Xs().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};r.run(()=>(n.callback(l),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=F("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=Ua(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},qu=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(qu||{}),Va=class Yu extends Error{constructor(){super(),u(this,"name","RenderingCanceledError"),u(this,"message","Page rendering has been canceled"),u(this,"stack"),Object.setPrototypeOf(this,Yu.prototype),this.stack=new Error().stack}};function Ua(e){return typeof e=="string"?Ar(e):e}var Ha=Ir;function Vw(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function $a(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 Zu=class{constructor(e,t){this.settings=e,u(this,"initialized",!1),u(this,"adaptViewer_"),u(this,"options"),u(this,"eventTarget"),u(this,"readyState"),ja(e.debug),this.adaptViewer_=new Dw(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=Vw(),t&&this.setOptions(t),this.eventTarget=new Rr,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},$a(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(l){if(l)return l.map(c=>({url:c.url||null,text:c.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Uw(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},$a(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()===Ha.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Ha.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function Uw(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 Ku=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Ku||{}),Hw=qu,$w=Xu;tt.forceRegisterEndTiming("load_vivliostyle");var Gw=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!0}){u(this,"htmlDoc"),u(this,"title"),u(this,"printCallback"),u(this,"errorCallback"),u(this,"hideIframe"),u(this,"removeIframe"),u(this,"iframe"),u(this,"iframeWin"),u(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=r}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1487
1487
  <!DOCTYPE html>
1488
1488
  <html data-vivliostyle-paginated="true">
1489
1489
  <head>
@@ -1511,6 +1511,6 @@ span[data-viv-leader] {
1511
1511
  <body onload='parent.printInstance.runInIframe(window)'>
1512
1512
  <div id="vivliostyle-viewer-viewport"></div>
1513
1513
  </body>
1514
- </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 Yu({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",s=>{var r,o;let a=(o=(r=s.content.error)==null?void 0:r.toString())!=null?o:s.content.messages.join(`
1515
- `);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 Gw(e,t){new $w(e,t).init()}});var Ww={};hc(Ww,{printHTML:()=>Qu.printHTML});module.exports=cc(Ww);var Qu=uc(Ju());
1514
+ </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 Zu({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",s=>{var r,o;let a=(o=(r=s.content.error)==null?void 0:r.toString())!=null?o:s.content.messages.join(`
1515
+ `);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 Ww(e,t){new Gw(e,t).init()}});var jw={};uc(jw,{printHTML:()=>ec.printHTML});module.exports=dc(jw);var ec=cc(Qu());
1516
1516
  //# sourceMappingURL=index.cjs.js.map