@vivliostyle/core 2.39.0 → 2.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- "use strict";var bC=Object.create;var no=Object.defineProperty;var yC=Object.getOwnPropertyDescriptor;var xC=Object.getOwnPropertyNames;var SC=Object.getPrototypeOf,EC=Object.prototype.hasOwnProperty;var of=r=>{throw TypeError(r)};var NC=(r,t,e)=>t in r?no(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var vC=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),TC=(r,t)=>{for(var e in t)no(r,e,{get:t[e],enumerable:!0})},rf=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of xC(t))!EC.call(r,s)&&s!==e&&no(r,s,{get:()=>t[s],enumerable:!(n=yC(t,s))||n.enumerable});return r};var wC=(r,t,e)=>(e=r!=null?bC(SC(r)):{},rf(t||!r||!r.__esModule?no(e,"default",{value:r,enumerable:!0}):e,r)),PC=r=>rf(no({},"__esModule",{value:!0}),r);var p=(r,t,e)=>NC(r,typeof t!="symbol"?t+"":t,e),Tc=(r,t,e)=>t.has(r)||of("Cannot "+e);var G=(r,t,e)=>(Tc(r,t,"read from private field"),e?e.call(r):t.get(r)),J=(r,t,e)=>t.has(r)?of("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),yt=(r,t,e,n)=>(Tc(r,t,"write to private field"),n?n.call(r,e):t.set(r,e),e),ye=(r,t,e)=>(Tc(r,t,"access private method"),e);var lg=vC((dS,ag)=>{var Ft=-1,ut=1,We=0;function No(r,t,e,n,s){if(r===t)return r?[[We,r]]:[];if(e!=null){var i=Wb(r,t,e);if(i)return i}var o=Hu(r,t),a=r.substring(0,o);r=r.substring(o),t=t.substring(o),o=Pa(r,t);var l=r.substring(r.length-o);r=r.substring(0,r.length-o),t=t.substring(0,t.length-o);var c=Ob(r,t);return a&&c.unshift([We,a]),l&&c.push([We,l]),zu(c,s),n&&_b(c),c}function Ob(r,t){var e;if(!r)return[[ut,t]];if(!t)return[[Ft,r]];var n=r.length>t.length?r:t,s=r.length>t.length?t:r,i=n.indexOf(s);if(i!==-1)return e=[[ut,n.substring(0,i)],[We,s],[ut,n.substring(i+s.length)]],r.length>t.length&&(e[0][0]=e[2][0]=Ft),e;if(s.length===1)return[[Ft,r],[ut,t]];var o=Mb(r,t);if(o){var a=o[0],l=o[1],c=o[2],u=o[3],d=o[4],h=No(a,c),f=No(l,u);return h.concat([[We,d]],f)}return Db(r,t)}function Db(r,t){for(var e=r.length,n=t.length,s=Math.ceil((e+n)/2),i=s,o=2*s,a=new Array(o),l=new Array(o),c=0;c<o;c++)a[c]=-1,l[c]=-1;a[i+1]=0,l[i+1]=0;for(var u=e-n,d=u%2!==0,h=0,f=0,g=0,m=0,y=0;y<s;y++){for(var S=-y+h;S<=y-f;S+=2){var C=i+S,x;S===-y||S!==y&&a[C-1]<a[C+1]?x=a[C+1]:x=a[C-1]+1;for(var N=x-S;x<e&&N<n&&r.charAt(x)===t.charAt(N);)x++,N++;if(a[C]=x,x>e)f+=2;else if(N>n)h+=2;else if(d){var E=i+u-S;if(E>=0&&E<o&&l[E]!==-1){var v=e-l[E];if(x>=v)return Qf(r,t,x,N)}}}for(var L=-y+g;L<=y-m;L+=2){var E=i+L,v;L===-y||L!==y&&l[E-1]<l[E+1]?v=l[E+1]:v=l[E-1]+1;for(var B=v-L;v<e&&B<n&&r.charAt(e-v-1)===t.charAt(n-B-1);)v++,B++;if(l[E]=v,v>e)m+=2;else if(B>n)g+=2;else if(!d){var C=i+u-L;if(C>=0&&C<o&&a[C]!==-1){var x=a[C],N=i+x-C;if(v=e-v,x>=v)return Qf(r,t,x,N)}}}}return[[Ft,r],[ut,t]]}function Qf(r,t,e,n){var s=r.substring(0,e),i=t.substring(0,n),o=r.substring(e),a=t.substring(n),l=No(s,i),c=No(o,a);return l.concat(c)}function Hu(r,t){if(!r||!t||r.charAt(0)!==t.charAt(0))return 0;for(var e=0,n=Math.min(r.length,t.length),s=n,i=0;e<s;)r.substring(i,s)==t.substring(i,s)?(e=s,i=e):n=s,s=Math.floor((n-e)/2+e);return sg(r.charCodeAt(s-1))&&s--,s}function Jf(r,t){var e=r.length,n=t.length;if(e==0||n==0)return 0;e>n?r=r.substring(e-n):e<n&&(t=t.substring(0,e));var s=Math.min(e,n);if(r==t)return s;for(var i=0,o=1;;){var a=r.substring(s-o),l=t.indexOf(a);if(l==-1)return i;o+=l,(l==0||r.substring(s-o)==t.substring(0,o))&&(i=o,o++)}}function Pa(r,t){if(!r||!t||r.slice(-1)!==t.slice(-1))return 0;for(var e=0,n=Math.min(r.length,t.length),s=n,i=0;e<s;)r.substring(r.length-s,r.length-i)==t.substring(t.length-s,t.length-i)?(e=s,i=e):n=s,s=Math.floor((n-e)/2+e);return ig(r.charCodeAt(r.length-s))&&s--,s}function Mb(r,t){var e=r.length>t.length?r:t,n=r.length>t.length?t:r;if(e.length<4||n.length*2<e.length)return null;function s(f,g,m){for(var y=f.substring(m,m+Math.floor(f.length/4)),S=-1,C="",x,N,E,v;(S=g.indexOf(y,S+1))!==-1;){var L=Hu(f.substring(m),g.substring(S)),B=Pa(f.substring(0,m),g.substring(0,S));C.length<B+L&&(C=g.substring(S-B,S)+g.substring(S,S+L),x=f.substring(0,m-B),N=f.substring(m+L),E=g.substring(0,S-B),v=g.substring(S+L))}return C.length*2>=f.length?[x,N,E,v,C]:null}var i=s(e,n,Math.ceil(e.length/4)),o=s(e,n,Math.ceil(e.length/2)),a;if(!i&&!o)return null;o?i?a=i[4].length>o[4].length?i:o:a=o:a=i;var l,c,u,d;r.length>t.length?(l=a[0],c=a[1],u=a[2],d=a[3]):(u=a[0],d=a[1],l=a[2],c=a[3]);var h=a[4];return[l,c,u,d,h]}function _b(r){for(var t=!1,e=[],n=0,s=null,i=0,o=0,a=0,l=0,c=0;i<r.length;)r[i][0]==We?(e[n++]=i,o=l,a=c,l=0,c=0,s=r[i][1]):(r[i][0]==ut?l+=r[i][1].length:c+=r[i][1].length,s&&s.length<=Math.max(o,a)&&s.length<=Math.max(l,c)&&(r.splice(e[n-1],0,[Ft,s]),r[e[n-1]+1][0]=ut,n--,n--,i=n>0?e[n-1]:-1,o=0,a=0,l=0,c=0,s=null,t=!0)),i++;for(t&&zu(r),zb(r),i=1;i<r.length;){if(r[i-1][0]==Ft&&r[i][0]==ut){var u=r[i-1][1],d=r[i][1],h=Jf(u,d),f=Jf(d,u);h>=f?(h>=u.length/2||h>=d.length/2)&&(r.splice(i,0,[We,d.substring(0,h)]),r[i-1][1]=u.substring(0,u.length-h),r[i+1][1]=d.substring(h),i++):(f>=u.length/2||f>=d.length/2)&&(r.splice(i,0,[We,u.substring(0,f)]),r[i-1][0]=ut,r[i-1][1]=d.substring(0,d.length-f),r[i+1][0]=Ft,r[i+1][1]=u.substring(f),i++),i++}i++}}var eg=/[^a-zA-Z0-9]/,tg=/\s/,ng=/[\r\n]/,Ub=/\n\r?\n$/,Hb=/^\r?\n\r?\n/;function zb(r){function t(f,g){if(!f||!g)return 6;var m=f.charAt(f.length-1),y=g.charAt(0),S=m.match(eg),C=y.match(eg),x=S&&m.match(tg),N=C&&y.match(tg),E=x&&m.match(ng),v=N&&y.match(ng),L=E&&f.match(Ub),B=v&&g.match(Hb);return L||B?5:E||v?4:S&&!x&&N?3:x||N?2:S||C?1:0}for(var e=1;e<r.length-1;){if(r[e-1][0]==We&&r[e+1][0]==We){var n=r[e-1][1],s=r[e][1],i=r[e+1][1],o=Pa(n,s);if(o){var a=s.substring(s.length-o);n=n.substring(0,n.length-o),s=a+s.substring(0,s.length-o),i=a+i}for(var l=n,c=s,u=i,d=t(n,s)+t(s,i);s.charAt(0)===i.charAt(0);){n+=s.charAt(0),s=s.substring(1)+i.charAt(0),i=i.substring(1);var h=t(n,s)+t(s,i);h>=d&&(d=h,l=n,c=s,u=i)}r[e-1][1]!=l&&(l?r[e-1][1]=l:(r.splice(e-1,1),e--),r[e][1]=c,u?r[e+1][1]=u:(r.splice(e+1,1),e--))}e++}}function zu(r,t){r.push([We,""]);for(var e=0,n=0,s=0,i="",o="",a;e<r.length;){if(e<r.length-1&&!r[e][1]){r.splice(e,1);continue}switch(r[e][0]){case ut:s++,o+=r[e][1],e++;break;case Ft:n++,i+=r[e][1],e++;break;case We:var l=e-s-n-1;if(t){if(l>=0&&rg(r[l][1])){var c=r[l][1].slice(-1);if(r[l][1]=r[l][1].slice(0,-1),i=c+i,o=c+o,!r[l][1]){r.splice(l,1),e--;var u=l-1;r[u]&&r[u][0]===ut&&(s++,o=r[u][1]+o,u--),r[u]&&r[u][0]===Ft&&(n++,i=r[u][1]+i,u--),l=u}}if(og(r[e][1])){var c=r[e][1].charAt(0);r[e][1]=r[e][1].slice(1),i+=c,o+=c}}if(e<r.length-1&&!r[e][1]){r.splice(e,1);break}if(i.length>0||o.length>0){i.length>0&&o.length>0&&(a=Hu(o,i),a!==0&&(l>=0?r[l][1]+=o.substring(0,a):(r.splice(0,0,[We,o.substring(0,a)]),e++),o=o.substring(a),i=i.substring(a)),a=Pa(o,i),a!==0&&(r[e][1]=o.substring(o.length-a)+r[e][1],o=o.substring(0,o.length-a),i=i.substring(0,i.length-a)));var d=s+n;i.length===0&&o.length===0?(r.splice(e-d,d),e=e-d):i.length===0?(r.splice(e-d,d,[ut,o]),e=e-d+1):o.length===0?(r.splice(e-d,d,[Ft,i]),e=e-d+1):(r.splice(e-d,d,[Ft,i],[ut,o]),e=e-d+2)}e!==0&&r[e-1][0]===We?(r[e-1][1]+=r[e][1],r.splice(e,1)):e++,s=0,n=0,i="",o="";break}}r[r.length-1][1]===""&&r.pop();var h=!1;for(e=1;e<r.length-1;)r[e-1][0]===We&&r[e+1][0]===We&&(r[e][1].substring(r[e][1].length-r[e-1][1].length)===r[e-1][1]?(r[e][1]=r[e-1][1]+r[e][1].substring(0,r[e][1].length-r[e-1][1].length),r[e+1][1]=r[e-1][1]+r[e+1][1],r.splice(e-1,1),h=!0):r[e][1].substring(0,r[e+1][1].length)==r[e+1][1]&&(r[e-1][1]+=r[e+1][1],r[e][1]=r[e][1].substring(r[e+1][1].length)+r[e+1][1],r.splice(e+1,1),h=!0)),e++;h&&zu(r,t)}function sg(r){return r>=55296&&r<=56319}function ig(r){return r>=56320&&r<=57343}function og(r){return ig(r.charCodeAt(0))}function rg(r){return sg(r.charCodeAt(r.length-1))}function Gb(r){for(var t=[],e=0;e<r.length;e++)r[e][1].length>0&&t.push(r[e]);return t}function Uu(r,t,e,n){return rg(r)||og(n)?null:Gb([[We,r],[Ft,t],[ut,e],[We,n]])}function Wb(r,t,e){var n=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,i=r.length,o=t.length;if(n.length===0&&(s===null||s.length===0)){var a=n.index,l=r.slice(0,a),c=r.slice(a),u=s?s.index:null;e:{var d=a+o-i;if(u!==null&&u!==d||d<0||d>o)break e;var h=t.slice(0,d),f=t.slice(d);if(f!==c)break e;var g=Math.min(a,d),m=l.slice(0,g),y=h.slice(0,g);if(m!==y)break e;var S=l.slice(g),C=h.slice(g);return Uu(m,S,C,c)}e:{if(u!==null&&u!==a)break e;var x=a,h=t.slice(0,x),f=t.slice(x);if(h!==l)break e;var N=Math.min(i-x,o-x),E=c.slice(c.length-N),v=f.slice(f.length-N);if(E!==v)break e;var S=c.slice(0,c.length-N),C=f.slice(0,f.length-N);return Uu(l,S,C,E)}}if(n.length>0&&s&&s.length===0)e:{var m=r.slice(0,n.index),E=r.slice(n.index+n.length),g=m.length,N=E.length;if(o<g+N)break e;var y=t.slice(0,g),v=t.slice(o-N);if(m!==y||E!==v)break e;var S=r.slice(g,i-N),C=t.slice(g,o-N);return Uu(m,S,C,E)}return null}function ka(r,t,e,n){return No(r,t,e,n,!0)}ka.INSERT=ut;ka.DELETE=Ft;ka.EQUAL=We;ag.exports=ka});var Xx={};TC(Xx,{CoreViewer:()=>Vr,HOOKS:()=>kt,Navigation:()=>pC,PageProgression:()=>ks,PageSide:()=>so,PageViewMode:()=>Gx,Profiler:()=>_r,ReadyState:()=>kc,UserAgentBaseCss:()=>Pu,UserAgentCounterStylesCss:()=>Lu,UserAgentPageCss:()=>wu,UserAgentTocCss:()=>ku,UserAgentXml:()=>Tu,ValidationTxt:()=>vu,VivliostylePolyfillCss:()=>Au,VivliostyleViewportCss:()=>Nu,VivliostyleViewportScreenCss:()=>Eu,ZoomType:()=>zx,getHooksForName:()=>qe,isDebug:()=>Ps,pageProgressionOf:()=>Pc,plugin:()=>kC,printHTML:()=>Wx,profile:()=>IC,profiler:()=>Je,registerHook:()=>je,removeHook:()=>af,setDebug:()=>wc});module.exports=PC(Xx);var Ps=!1;function wc(r){Ps=r}var ks=(e=>(e.LTR="ltr",e.RTL="rtl",e))(ks||{});function Pc(r){switch(r){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${r}`)}}var so=(e=>(e.LEFT="left",e.RIGHT="right",e))(so||{}),kc=(n=>(n.LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete",n))(kc||{});var Lc=(s=>(s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s))(Lc||{}),Ac=class{constructor(t){this.opt_console=t;p(this,"listeners",{})}consoleDebug(t){this.opt_console?this.opt_console.debug?this.opt_console.debug(...t):this.opt_console.log(...t):console.debug(...t)}consoleInfo(t){this.opt_console?this.opt_console.info?this.opt_console.info(...t):this.opt_console.log(...t):console.info(...t)}consoleWarn(t){this.opt_console?this.opt_console.warn?this.opt_console.warn(...t):this.opt_console.log(...t):console.warn(...t)}consoleError(t){this.opt_console?this.opt_console.error?this.opt_console.error(...t):this.opt_console.log(...t):console.error(...t)}triggerListeners(t,e){let n=this.listeners[t];n&&n(e)}addListener(t,e){this.listeners[t]=e}debug(...t){let e=Or(arguments);this.consoleDebug(Dr(e)),this.triggerListeners(1,e)}info(...t){let e=Or(arguments);this.consoleInfo(Dr(e)),this.triggerListeners(2,e)}warn(...t){let e=Or(arguments);this.consoleWarn(Dr(e)),this.triggerListeners(3,e)}error(...t){let e=Or(arguments);this.consoleError(Dr(e)),this.triggerListeners(4,e)}};function Or(r){let t=Array.from(r),e=null;return t[0]instanceof Error&&(e=t.shift()),{error:e,messages:t}}function Dr(r){let t=r.error,e=t&&(t.frameTrace||t.stack),n=[].concat(r.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ "use strict";var HC=Object.create;var br=Object.defineProperty;var zC=Object.getOwnPropertyDescriptor;var GC=Object.getOwnPropertyNames;var WC=Object.getPrototypeOf,XC=Object.prototype.hasOwnProperty;var Pf=o=>{throw TypeError(o)};var $C=(o,t,e)=>t in o?br(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var jC=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),YC=(o,t)=>{for(var e in t)br(o,e,{get:t[e],enumerable:!0})},kf=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of GC(t))!XC.call(o,s)&&s!==e&&br(o,s,{get:()=>t[s],enumerable:!(n=zC(t,s))||n.enumerable});return o};var KC=(o,t,e)=>(e=o!=null?HC(WC(o)):{},kf(t||!o||!o.__esModule?br(e,"default",{value:o,enumerable:!0}):e,o)),qC=o=>kf(br({},"__esModule",{value:!0}),o);var p=(o,t,e)=>$C(o,typeof t!="symbol"?t+"":t,e),Xc=(o,t,e)=>t.has(o)||Pf("Cannot "+e);var V=(o,t,e)=>(Xc(o,t,"read from private field"),e?e.call(o):t.get(o)),j=(o,t,e)=>t.has(o)?Pf("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(o):t.set(o,e),Se=(o,t,e,n)=>(Xc(o,t,"write to private field"),n?n.call(o,e):t.set(o,e),e),ae=(o,t,e)=>(Xc(o,t,"access private method"),e);var Ig=jC((OS,Rg)=>{var Dt=-1,pt=1,$e=0;function Ur(o,t,e,n,s){if(o===t)return o?[[$e,o]]:[];if(e!=null){var i=fy(o,t,e);if(i)return i}var r=ud(o,t),a=o.substring(0,r);o=o.substring(r),t=t.substring(r),r=$a(o,t);var l=o.substring(o.length-r);o=o.substring(0,o.length-r),t=t.substring(0,t.length-r);var c=oy(o,t);return a&&c.unshift([$e,a]),l&&c.push([$e,l]),dd(c,s),n&&cy(c),c}function oy(o,t){var e;if(!o)return[[pt,t]];if(!t)return[[Dt,o]];var n=o.length>t.length?o:t,s=o.length>t.length?t:o,i=n.indexOf(s);if(i!==-1)return e=[[pt,n.substring(0,i)],[$e,s],[pt,n.substring(i+s.length)]],o.length>t.length&&(e[0][0]=e[2][0]=Dt),e;if(s.length===1)return[[Dt,o],[pt,t]];var r=ly(o,t);if(r){var a=r[0],l=r[1],c=r[2],u=r[3],d=r[4],h=Ur(a,c),f=Ur(l,u);return h.concat([[$e,d]],f)}return ay(o,t)}function ay(o,t){for(var e=o.length,n=t.length,s=Math.ceil((e+n)/2),i=s,r=2*s,a=new Array(r),l=new Array(r),c=0;c<r;c++)a[c]=-1,l[c]=-1;a[i+1]=0,l[i+1]=0;for(var u=e-n,d=u%2!==0,h=0,f=0,g=0,m=0,y=0;y<s;y++){for(var S=-y+h;S<=y-f;S+=2){var C=i+S,x;S===-y||S!==y&&a[C-1]<a[C+1]?x=a[C+1]:x=a[C-1]+1;for(var v=x-S;x<e&&v<n&&o.charAt(x)===t.charAt(v);)x++,v++;if(a[C]=x,x>e)f+=2;else if(v>n)h+=2;else if(d){var E=i+u-S;if(E>=0&&E<r&&l[E]!==-1){var N=e-l[E];if(x>=N)return Eg(o,t,x,v)}}}for(var L=-y+g;L<=y-m;L+=2){var E=i+L,N;L===-y||L!==y&&l[E-1]<l[E+1]?N=l[E+1]:N=l[E-1]+1;for(var O=N-L;N<e&&O<n&&o.charAt(e-N-1)===t.charAt(n-O-1);)N++,O++;if(l[E]=N,N>e)m+=2;else if(O>n)g+=2;else if(!d){var C=i+u-L;if(C>=0&&C<r&&a[C]!==-1){var x=a[C],v=i+x-C;if(N=e-N,x>=N)return Eg(o,t,x,v)}}}}return[[Dt,o],[pt,t]]}function Eg(o,t,e,n){var s=o.substring(0,e),i=t.substring(0,n),r=o.substring(e),a=t.substring(n),l=Ur(s,i),c=Ur(r,a);return l.concat(c)}function ud(o,t){if(!o||!t||o.charAt(0)!==t.charAt(0))return 0;for(var e=0,n=Math.min(o.length,t.length),s=n,i=0;e<s;)o.substring(i,s)==t.substring(i,s)?(e=s,i=e):n=s,s=Math.floor((n-e)/2+e);return Pg(o.charCodeAt(s-1))&&s--,s}function vg(o,t){var e=o.length,n=t.length;if(e==0||n==0)return 0;e>n?o=o.substring(e-n):e<n&&(t=t.substring(0,e));var s=Math.min(e,n);if(o==t)return s;for(var i=0,r=1;;){var a=o.substring(s-r),l=t.indexOf(a);if(l==-1)return i;r+=l,(l==0||o.substring(s-r)==t.substring(0,r))&&(i=r,r++)}}function $a(o,t){if(!o||!t||o.slice(-1)!==t.slice(-1))return 0;for(var e=0,n=Math.min(o.length,t.length),s=n,i=0;e<s;)o.substring(o.length-s,o.length-i)==t.substring(t.length-s,t.length-i)?(e=s,i=e):n=s,s=Math.floor((n-e)/2+e);return kg(o.charCodeAt(o.length-s))&&s--,s}function ly(o,t){var e=o.length>t.length?o:t,n=o.length>t.length?t:o;if(e.length<4||n.length*2<e.length)return null;function s(f,g,m){for(var y=f.substring(m,m+Math.floor(f.length/4)),S=-1,C="",x,v,E,N;(S=g.indexOf(y,S+1))!==-1;){var L=ud(f.substring(m),g.substring(S)),O=$a(f.substring(0,m),g.substring(0,S));C.length<O+L&&(C=g.substring(S-O,S)+g.substring(S,S+L),x=f.substring(0,m-O),v=f.substring(m+L),E=g.substring(0,S-O),N=g.substring(S+L))}return C.length*2>=f.length?[x,v,E,N,C]:null}var i=s(e,n,Math.ceil(e.length/4)),r=s(e,n,Math.ceil(e.length/2)),a;if(!i&&!r)return null;r?i?a=i[4].length>r[4].length?i:r:a=r:a=i;var l,c,u,d;o.length>t.length?(l=a[0],c=a[1],u=a[2],d=a[3]):(u=a[0],d=a[1],l=a[2],c=a[3]);var h=a[4];return[l,c,u,d,h]}function cy(o){for(var t=!1,e=[],n=0,s=null,i=0,r=0,a=0,l=0,c=0;i<o.length;)o[i][0]==$e?(e[n++]=i,r=l,a=c,l=0,c=0,s=o[i][1]):(o[i][0]==pt?l+=o[i][1].length:c+=o[i][1].length,s&&s.length<=Math.max(r,a)&&s.length<=Math.max(l,c)&&(o.splice(e[n-1],0,[Dt,s]),o[e[n-1]+1][0]=pt,n--,n--,i=n>0?e[n-1]:-1,r=0,a=0,l=0,c=0,s=null,t=!0)),i++;for(t&&dd(o),py(o),i=1;i<o.length;){if(o[i-1][0]==Dt&&o[i][0]==pt){var u=o[i-1][1],d=o[i][1],h=vg(u,d),f=vg(d,u);h>=f?(h>=u.length/2||h>=d.length/2)&&(o.splice(i,0,[$e,d.substring(0,h)]),o[i-1][1]=u.substring(0,u.length-h),o[i+1][1]=d.substring(h),i++):(f>=u.length/2||f>=d.length/2)&&(o.splice(i,0,[$e,u.substring(0,f)]),o[i-1][0]=pt,o[i-1][1]=d.substring(0,d.length-f),o[i+1][0]=Dt,o[i+1][1]=u.substring(f),i++),i++}i++}}var Ng=/[^a-zA-Z0-9]/,Tg=/\s/,wg=/[\r\n]/,uy=/\n\r?\n$/,dy=/^\r?\n\r?\n/;function py(o){function t(f,g){if(!f||!g)return 6;var m=f.charAt(f.length-1),y=g.charAt(0),S=m.match(Ng),C=y.match(Ng),x=S&&m.match(Tg),v=C&&y.match(Tg),E=x&&m.match(wg),N=v&&y.match(wg),L=E&&f.match(uy),O=N&&g.match(dy);return L||O?5:E||N?4:S&&!x&&v?3:x||v?2:S||C?1:0}for(var e=1;e<o.length-1;){if(o[e-1][0]==$e&&o[e+1][0]==$e){var n=o[e-1][1],s=o[e][1],i=o[e+1][1],r=$a(n,s);if(r){var a=s.substring(s.length-r);n=n.substring(0,n.length-r),s=a+s.substring(0,s.length-r),i=a+i}for(var l=n,c=s,u=i,d=t(n,s)+t(s,i);s.charAt(0)===i.charAt(0);){n+=s.charAt(0),s=s.substring(1)+i.charAt(0),i=i.substring(1);var h=t(n,s)+t(s,i);h>=d&&(d=h,l=n,c=s,u=i)}o[e-1][1]!=l&&(l?o[e-1][1]=l:(o.splice(e-1,1),e--),o[e][1]=c,u?o[e+1][1]=u:(o.splice(e+1,1),e--))}e++}}function dd(o,t){o.push([$e,""]);for(var e=0,n=0,s=0,i="",r="",a;e<o.length;){if(e<o.length-1&&!o[e][1]){o.splice(e,1);continue}switch(o[e][0]){case pt:s++,r+=o[e][1],e++;break;case Dt:n++,i+=o[e][1],e++;break;case $e:var l=e-s-n-1;if(t){if(l>=0&&Lg(o[l][1])){var c=o[l][1].slice(-1);if(o[l][1]=o[l][1].slice(0,-1),i=c+i,r=c+r,!o[l][1]){o.splice(l,1),e--;var u=l-1;o[u]&&o[u][0]===pt&&(s++,r=o[u][1]+r,u--),o[u]&&o[u][0]===Dt&&(n++,i=o[u][1]+i,u--),l=u}}if(Ag(o[e][1])){var c=o[e][1].charAt(0);o[e][1]=o[e][1].slice(1),i+=c,r+=c}}if(e<o.length-1&&!o[e][1]){o.splice(e,1);break}if(i.length>0||r.length>0){i.length>0&&r.length>0&&(a=ud(r,i),a!==0&&(l>=0?o[l][1]+=r.substring(0,a):(o.splice(0,0,[$e,r.substring(0,a)]),e++),r=r.substring(a),i=i.substring(a)),a=$a(r,i),a!==0&&(o[e][1]=r.substring(r.length-a)+o[e][1],r=r.substring(0,r.length-a),i=i.substring(0,i.length-a)));var d=s+n;i.length===0&&r.length===0?(o.splice(e-d,d),e=e-d):i.length===0?(o.splice(e-d,d,[pt,r]),e=e-d+1):r.length===0?(o.splice(e-d,d,[Dt,i]),e=e-d+1):(o.splice(e-d,d,[Dt,i],[pt,r]),e=e-d+2)}e!==0&&o[e-1][0]===$e?(o[e-1][1]+=o[e][1],o.splice(e,1)):e++,s=0,n=0,i="",r="";break}}o[o.length-1][1]===""&&o.pop();var h=!1;for(e=1;e<o.length-1;)o[e-1][0]===$e&&o[e+1][0]===$e&&(o[e][1].substring(o[e][1].length-o[e-1][1].length)===o[e-1][1]?(o[e][1]=o[e-1][1]+o[e][1].substring(0,o[e][1].length-o[e-1][1].length),o[e+1][1]=o[e-1][1]+o[e+1][1],o.splice(e-1,1),h=!0):o[e][1].substring(0,o[e+1][1].length)==o[e+1][1]&&(o[e-1][1]+=o[e+1][1],o[e][1]=o[e][1].substring(o[e+1][1].length)+o[e+1][1],o.splice(e+1,1),h=!0)),e++;h&&dd(o,t)}function Pg(o){return o>=55296&&o<=56319}function kg(o){return o>=56320&&o<=57343}function Ag(o){return kg(o.charCodeAt(0))}function Lg(o){return Pg(o.charCodeAt(o.length-1))}function hy(o){for(var t=[],e=0;e<o.length;e++)o[e][1].length>0&&t.push(o[e]);return t}function cd(o,t,e,n){return Lg(o)||Ag(n)?null:hy([[$e,o],[Dt,t],[pt,e],[$e,n]])}function fy(o,t,e){var n=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,i=o.length,r=t.length;if(n.length===0&&(s===null||s.length===0)){var a=n.index,l=o.slice(0,a),c=o.slice(a),u=s?s.index:null;e:{var d=a+r-i;if(u!==null&&u!==d||d<0||d>r)break e;var h=t.slice(0,d),f=t.slice(d);if(f!==c)break e;var g=Math.min(a,d),m=l.slice(0,g),y=h.slice(0,g);if(m!==y)break e;var S=l.slice(g),C=h.slice(g);return cd(m,S,C,c)}e:{if(u!==null&&u!==a)break e;var x=a,h=t.slice(0,x),f=t.slice(x);if(h!==l)break e;var v=Math.min(i-x,r-x),E=c.slice(c.length-v),N=f.slice(f.length-v);if(E!==N)break e;var S=c.slice(0,c.length-v),C=f.slice(0,f.length-v);return cd(l,S,C,E)}}if(n.length>0&&s&&s.length===0)e:{var m=o.slice(0,n.index),E=o.slice(n.index+n.length),g=m.length,v=E.length;if(r<g+v)break e;var y=t.slice(0,g),N=t.slice(r-v);if(m!==y||E!==N)break e;var S=o.slice(g,i-v),C=t.slice(g,r-v);return cd(m,S,C,E)}return null}function ja(o,t,e,n){return Ur(o,t,e,n,!0)}ja.INSERT=pt;ja.DELETE=Dt;ja.EQUAL=$e;Rg.exports=ja});var gS={};YC(gS,{CoreViewer:()=>Qo,HOOKS:()=>It,Navigation:()=>BC,PageProgression:()=>Ms,PageSide:()=>yr,PageViewMode:()=>hS,Profiler:()=>ia,ReadyState:()=>Yc,UserAgentBaseCss:()=>qu,UserAgentCounterStylesCss:()=>Ju,UserAgentPageCss:()=>Ku,UserAgentTocCss:()=>Zu,UserAgentXml:()=>Yu,ValidationTxt:()=>ju,VivliostylePolyfillCss:()=>Qu,VivliostyleViewportCss:()=>$u,VivliostyleViewportScreenCss:()=>Xu,ZoomType:()=>pS,getHooksForName:()=>Ze,isDebug:()=>Ds,pageProgressionOf:()=>jc,plugin:()=>ZC,printHTML:()=>fS,profile:()=>tb,profiler:()=>nt,registerHook:()=>Ke,removeHook:()=>Af,setDebug:()=>$c});module.exports=qC(gS);var Ds=!1;function $c(o){Ds=o}var Ms=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Ms||{});function jc(o){switch(o){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${o}`)}}var yr=(e=>(e.LEFT="left",e.RIGHT="right",e))(yr||{}),Yc=(n=>(n.LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete",n))(Yc||{});var qc=(s=>(s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s))(qc||{}),Kc=class{constructor(t){this.opt_console=t;p(this,"listeners",{})}consoleDebug(t){this.opt_console?this.opt_console.debug?this.opt_console.debug(...t):this.opt_console.log(...t):console.debug(...t)}consoleInfo(t){this.opt_console?this.opt_console.info?this.opt_console.info(...t):this.opt_console.log(...t):console.info(...t)}consoleWarn(t){this.opt_console?this.opt_console.warn?this.opt_console.warn(...t):this.opt_console.log(...t):console.warn(...t)}consoleError(t){this.opt_console?this.opt_console.error?this.opt_console.error(...t):this.opt_console.log(...t):console.error(...t)}triggerListeners(t,e){let n=this.listeners[t];n&&n(e)}addListener(t,e){this.listeners[t]=e}debug(...t){let e=ta(arguments);this.consoleDebug(na(e)),this.triggerListeners(1,e)}info(...t){let e=ta(arguments);this.consoleInfo(na(e)),this.triggerListeners(2,e)}warn(...t){let e=ta(arguments);this.consoleWarn(na(e)),this.triggerListeners(3,e)}error(...t){let e=ta(arguments);this.consoleError(na(e)),this.triggerListeners(4,e)}};function ta(o){let t=Array.from(o),e=null;return t[0]instanceof Error&&(e=t.shift()),{error:e,messages:t}}function na(o){let t=o.error,e=t&&(t.frameTrace||t.stack),n=[].concat(o.messages);return t&&(n.length>0&&(n=n.concat([`
2
2
  `])),n=n.concat([t.toString()]),e&&(n=n.concat([`
3
- `]).concat(e))),n}var F=new Ac;var kt=(u=>(u.SIMPLE_PROPERTY="SIMPLE_PROPERTY",u.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",u.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",u.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",u.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",u.CONFIGURATION="CONFIGURATION",u.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",u.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",u.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",u.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",u))(kt||{}),Mr={};function je(r,t,e){if(!kt[r])F.warn(new Error(`Skipping unknown plugin hook '${r}'.`));else{let n=Mr[r];n||(n=Mr[r]=[]),e?n.unshift(t):n.push(t)}}function af(r,t){if(!kt[r])F.warn(new Error(`Ignoring unknown plugin hook '${r}'.`));else{let e=Mr[r];if(e){let n=e.indexOf(t);n>=0&&e.splice(n,1)}}}function qe(r){return Mr[r]||[]}var kC={registerHook:je,removeHook:af};var _r=class{constructor(t){this.performanceInstance=t;p(this,"timestamps",{});p(this,"registerTiming");p(this,"registerStartTiming");p(this,"registerEndTiming");this.registerTiming=ci,this.registerStartTiming=this.registerStartTiming=ci,this.registerEndTiming=this.registerEndTiming=ci}forceRegisterStartTiming(t,e){Rc.call(this,t,"start",e)}forceRegisterEndTiming(t,e){Rc.call(this,t,"end",e)}printTimings(){let t=this.timestamps,e="";Object.keys(t).forEach(n=>{let s=t[n],i=s.length;for(let o=0;o<i;o++){let a=s[o];e+=n,i>1&&(e+=`(${o})`),e+=` => start: ${a.start}, end: ${a.end}, duration: ${a.end-a.start}
4
- `}}),F.info(e)}disable(){this.registerTiming=ci,this.registerStartTiming=this.registerStartTiming=ci,this.registerEndTiming=this.registerEndTiming=ci}enable(){this.registerTiming=Rc,this.registerStartTiming=this.registerStartTiming=lf,this.registerEndTiming=this.registerEndTiming=AC}isEnabled(){return this.registerStartTiming===lf}};function ci(){}function Rc(r,t,e){e||(e=this.performanceInstance.now());let n=this.timestamps[r];n||(n=this.timestamps[r]=[]);let s,i=n.length;for(let o=i-1;o>=0&&(s=n[o],!(s&&!s[t]));o--)s=null;s||(s={},n.push(s)),s[t]=e}function lf(r,t){this.registerTiming(r,"start",t)}function AC(r,t){this.registerTiming(r,"end",t)}var LC={now:Date.now},RC=window&&window.performance,Je=new _r(RC||LC);Je.forceRegisterStartTiming("load_vivliostyle");var IC={profiler:{registerStartTiming:Je.registerStartTiming,registerEndTiming:Je.registerEndTiming,printTimings:Je.printTimings,disable:Je.disable,enable:Je.enable}};var Hr=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",As=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Zt="data-adapt-eloff",uf={};function di(r){return JSON.parse(r)}function Wt(r){let t=r.match(/^([^#]*)/);return t?t[1]:r}function VC(r){let t=r.match(/^([^#?]*)/);return t?t[1]:r}var kn=window.location.href;function Ic(r){kn=r}var Qt=window.location.href;function Vc(r){Qt=r}function te(r,t){if(/^data:/i.test(t))return r||t;if(!t||r.match(/^\w{2,}:/))return r.toLowerCase().match("^javascript:")?"#":(r.match(/^\w{2,}:\/\/[^\/]+$/)&&(r=`${r}/`),r);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let e;if(r.match(/^\/\//))return e=t.match(/^(\w{2,}:)\/\//),e?e[1]+r:r;if(r.match(/^\//))return e=t.match(/^(\w{2,}:\/\/[^\/]+)\//),e?e[1]+r:r;if(r.match(/^\.(\/|$)/)&&(r=r.substr(2)),t=VC(t),r.match(/^#/))return t+r;let n=t.lastIndexOf("/");if(n<0)return r;let s=t.substr(0,n+1)+r,i="";for(e=s.match(/^([^?#]*)([?#].*)$/),e&&(s=e[1],i=e[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,"/")+i}function Zn(r){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(r))?r=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(r))?r=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(r))?r=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(r))?r=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(r))&&(r=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),r}function Fc(r){return r==null?r:r.toString()}var Ur=class{constructor(){p(this,"queue",[null])}length(){return this.queue.length-1}add(t){let e=this.queue.length;for(;e>1;){let n=Math.floor(e/2),s=this.queue[n];if(s.compare(t)>0){this.queue[e]=t;return}this.queue[e]=s,e=n}this.queue[1]=t}peek(){return this.queue[1]}remove(){let t=this.queue[1],e=this.queue.pop(),n=this.queue.length;if(n>1){let s=1;for(;;){let i=s*2;if(i>=n)break;if(this.queue[i].compare(e)>0)i+1<n&&this.queue[i+1].compare(this.queue[i])>0&&i++;else if(i+1<n&&this.queue[i+1].compare(e)>0)i++;else break;this.queue[s]=this.queue[i],s=i}this.queue[s]=e}return t}},Bc=["","-webkit-","-moz-"],ui={};function oo(r,t){return CSS.supports(r+t,"unset")}function FC(r){let t=ui[r];if(t||t===null)return t;switch(r){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return ui[r]=null,null;case"text-combine-upright":if(oo("-webkit-","text-combine")&&!oo("","text-combine-upright"))return ui[r]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let e of Bc)if(oo(e,r))return t=[e+r],ui[r]=t,t;return F.warn("Property not supported by the browser: ",r),ui[r]=null,null}function w(r,t,e){let n=r==null?void 0:r.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,e||" ");return}let s=FC(t);if(s)for(let i of s){switch(i){case"-webkit-text-combine":switch(e){case"all":e="horizontal";break}break;case"text-combine-upright":switch(e){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(i,e)}}function Jt(r,t,e){try{let n=ui[t];return r.style.getPropertyValue(n?n[0]:t)}catch(n){}return e||""}function ro(r){let t=r.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&r.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=r.getAttribute("lang")),t}var et=class{constructor(){p(this,"list",[])}append(t){return this.list.push(t),this}clear(){this.list=[]}toString(){let t=this.list.join("");return this.list=[t],t}};function df(r){return`\\${r.charCodeAt(0).toString(16)} `}function dn(r){return r.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,df)}function Ls(r){return r.replace(/[\u0000-\u001F"\\]/g,df)}function Oc(r){return r.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Dc(r){return!!r.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function BC(r,t){return t=typeof t=="string"?t:"\\u",t+(65536|r.charCodeAt(0)).toString(16).substr(1)}function Mc(r,t){function e(n){return BC(n,t)}return r.replace(/[^-a-zA-Z0-9_]/g,e)}function An(r){return Mc(r)}function OC(r,t){return t=typeof t=="string"?t:"\\u",r.indexOf(t)===0?String.fromCharCode(parseInt(r.substring(t.length),16)):r}function pf(r,t){t=typeof t=="string"?t:"\\u";function e(s){return OC(s,t)}let n=new RegExp(`${An(t)}[0-9a-fA-F]{4}`,"g");return r.replace(n,e)}function At(r,t){let e=0,n=r;for(;;){if(e<=n,e==0||t(e-1),n==r||t(n),e==n)return e;let s=e+n>>1;t(s)?n=s:e=s+1}}function zr(r,t){return r-t}function _c(r,t){let e={};for(let n of r){let s=t(n);s&&!e[s]&&(e[s]=n)}return e}function hf(r){let t={};for(let e=0;e<r.length;e++)t[r[e]]=!0;return t}function Gr(r,t){let e={};for(let n of r){let s=t(n);s&&(e[s]?e[s].push(n):e[s]=[n])}return e}function ff(r,t){let e={};for(let n in r)e[n]=t(r[n],n);return e}var Kn=class{constructor(){p(this,"listeners",{})}dispatchEvent(t){let e=this.listeners[t.type];if(e){t.target=this,t.currentTarget=this;for(let n=0;n<e.length;n++)e[n](t)}}addEventListener(t,e,n){if(n)return;let s=this.listeners[t];s?s.includes(e)||s.push(e):this.listeners[t]=[e]}removeEventListener(t,e,n){if(n)return;let s=this.listeners[t];if(s){let i=s.indexOf(e);i>=0&&s.splice(i,1)}}},pn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Cf(r){if(r.nodeType==1){let t=r.getAttribute("id");if(t)return t}return null}function DC(r){return`^${r}`}function gf(r){return r.replace(/[\[\]\(\),=;^]/g,DC)}function MC(r){return r.substr(1)}function Uc(r){return r&&r.replace(/\^[\[\]\(\),=;^]/g,MC)}function _C(r){let t=[];do{let e=r.match(/^(\^,|[^,])*/),n=Uc(e[0]);if(r=r.substr(e[0].length+1),!r&&!t.length)return n;t.push(n)}while(r);return t}function mf(r){let t={};for(;r;){let e=r.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!e)return t;t[e[1]]=_C(e[2]),r=r.substr(e[0].length)}return t}var Wr=class{appendTo(t){t.append("!")}applyTo(t){return!1}},Xr=class{constructor(t,e,n){this.index=t;this.id=e;this.sideBias=n}appendTo(t){t.append("/"),t.append(this.index.toString()),(this.id||this.sideBias)&&(t.append("["),this.id&&t.append(this.id),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}applyTo(t){if(t.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let e=t.node,n=e.children,s=n.length,i,o=Math.floor(this.index/2)-1;if(o<0||s==0)i=e.firstChild,t.node=i||e;else{if(i=n[Math.min(o,s-1)],this.index&1){let a=i.nextSibling;!a||a.nodeType==1?t.after=!0:i=a}t.node=i}if(this.id&&(t.after||this.id!=Cf(t.node))){let a=e.ownerDocument.getElementById(this.id);a?t.node=a:F.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},$r=class{constructor(t,e,n,s){this.offset=t;this.textBefore=e;this.textAfter=n;this.sideBias=s}applyTo(t){if(this.offset>0&&!t.after){let e=this.offset,n=t.node;for(;;){let s=n.nodeType;if(s==1)break;let i=n.nextSibling;if(3<=s&&s<=5){let o=n.textContent.length;if(e<=o)break;if(!i){e=o;break}e-=o}if(!i){e=0;break}n=i}t.node=n,t.offset=e}return t.sideBias=this.sideBias,!0}appendTo(t){t.append(":"),t.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(t.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&t.append(gf(this.textBefore)),t.append(","),this.textAfter&&t.append(gf(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},ao=class r{constructor(){p(this,"steps",null)}fromString(t){let e=t.match(/^#?epubcfi\((.*)\)$/);if(!e)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(e[1]),s=0,i=[];for(;;){let o;switch(n.charAt(s)){case"/":{if(s++,e=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!e)throw new Error("E_CFI_NUMBER_EXPECTED");s+=e[0].length;let a=parseInt(e[1],10),l=e[3];o=mf(e[4]),i.push(new Xr(a,l,Fc(o.s)));break}case":":{if(s++,e=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!e)throw new Error("E_CFI_NUMBER_EXPECTED");s+=e[0].length;let a=parseInt(e[1],10),l=e[4];l&&(l=Uc(l));let c=e[7];c&&(c=Uc(c)),o=mf(e[10]),i.push(new $r(a,l,c,Fc(o.s)));break}case"!":s++,i.push(new Wr);break;case"~":case"@":case"":this.steps=i;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let e={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(e)){e.ref=new r,e.ref.steps=this.steps.slice(n+1);break}return e}trim(t,e){return t.replace(/\s+/g," ").match(e?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,e,n,s){let i=[],o=t.parentNode,a="",l="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let c=t.textContent,u=c.length;n?(e+=u,a||(a=c)):(e>u&&(e=u),n=!0,a=c.substr(0,e),l=c.substr(e)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((e>0||a||l)&&(a=this.trim(a,!1),l=this.trim(l,!0),i.push(new $r(e,a,l,s)),s=null);o&&!(!o||o.nodeType==9);){let c=n?null:Cf(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;i.push(new Xr(u,c,s)),s=null,t=o,o=o.parentNode,n=!1}i.reverse(),this.steps?(i.push(new Wr),this.steps=i.concat(this.steps)):this.steps=i}toString(){if(!this.steps)return"";let t=new et;t.append("epubcfi(");for(let e=0;e<this.steps.length;e++)this.steps[e].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function zc(){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 ra(r){return{fontFamily:r.fontFamily,lineHeight:r.lineHeight,margin:r.margin,hyphenate:r.hyphenate,columnWidth:r.columnWidth,horizontal:r.horizontal,nightMode:r.nightMode,spreadView:r.spreadView,pageBorder:r.pageBorder,enabledMediaTypes:Object.assign({},r.enabledMediaTypes),defaultPaperSize:r.defaultPaperSize?Object.assign({},r.defaultPaperSize):void 0}}var HC=zc(),bf={PENDING:{}};function Gc(r,t,e,n){let s=Math.min((r-0)/e,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function Hc(r){return`"${Ls(`${r}`)}"`}function zC(r){return dn(`${r}`)}function go(r,t){return r?`${dn(r)}.${dn(t)}`:dn(t)}var yf=0,Rs=class{constructor(t,e){this.parent=t;this.resolver=e;p(this,"scopeKey");p(this,"children",[]);p(this,"zero");p(this,"one");p(this,"_true");p(this,"_false");p(this,"values",{});p(this,"funcs",{});p(this,"builtIns",{});if(this.scopeKey=`S${yf++}`,this.zero=new de(this,0),this.one=new de(this,1),this._true=new de(this,!0),this._false=new de(this,!1),t&&t.children.push(this),!t){let n=this.builtIns;n.floor=Math.floor,n.ceil=Math.ceil,n.round=Math.round,n.sqrt=Math.sqrt,n.min=Math.min,n.max=Math.max,n.letterbox=Gc,n["css-string"]=Hc,n["css-name"]=zC,n.typeof=s=>typeof s,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 Hc(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Hc(this.docTitle?this.docTitle:"")})}}defineBuiltInName(t,e){this.values[t]=new ne(this,e,t)}defineName(t,e){this.values[t]=e}defineFunc(t,e){this.funcs[t]=e}defineBuiltIn(t,e){this.builtIns[t]=e}};function xf(r){switch(r==null?void 0:r.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Wc(r){switch(r==null?void 0:r.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 Sf(r){switch(r==null?void 0:r.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Ef(r){switch(r==null?void 0:r.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Ze={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function aa(r){switch(r){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 pi=class{constructor(t,e,n,s){this.rootScope=t;this.viewportWidth=e;this.viewportHeight=n;p(this,"actualPageWidth",null);p(this,"pageWidth");p(this,"actualPageHeight",null);p(this,"pageHeight");p(this,"initialFontSize");p(this,"rootFontSize",null);p(this,"isRelativeRootFontSize",null);p(this,"fontSize");p(this,"rootLineHeight",null);p(this,"pref");p(this,"scopes",{});p(this,"pageAreaWidth",null);p(this,"pageAreaHeight",null);p(this,"pageVertical",null);p(this,"pubTitle",null);p(this,"docTitle",null);this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(e/2)-this.pref.pageBorder:e},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:n},this.initialFontSize=s,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:s},this.pref=HC}getScopeContext(t){let e=this.scopes[t.scopeKey];return e||(e={},this.scopes[t.scopeKey]=e),e}clearScope(t){this.scopes[t.scopeKey]={};for(let e=0;e<t.children.length;e++)this.clearScope(t.children[e])}queryUnitSize(t,e,n){if(Wc(t)){let s=this.pageWidth()/100,i=this.pageHeight()/100,o=this.pageAreaWidth!=null?this.pageAreaWidth/100:s,a=this.pageAreaHeight!=null?this.pageAreaHeight/100:i,l=n!=null?n:this.pageVertical;switch(t){case"vw":return o;case"vh":return a;case"vi":return l?a:o;case"vb":return l?o:a;case"vmin":return o<a?o:a;case"vmax":return o>a?o:a;case"pvw":return s;case"pvh":return i;case"pvi":return l?i:s;case"pvb":return l?s:i;case"pvmin":return s<i?s:i;case"pvmax":return s>i?s:i}}return t=="em"||t=="rem"?e?this.initialFontSize:this.fontSize():t=="lh"||t=="rlh"?this.rootLineHeight:Ze[t]}evalName(t,e){do{let n=t.values[e];if(n||t.resolver&&(n=t.resolver.call(this,e,!1),n))return n;t=t.parent}while(t);throw new Error(`Name '${e}' is undefined`)}evalCall(t,e,n,s){do{let i=t.funcs[e];if(i||t.resolver&&(i=t.resolver.call(this,e,!0),i))return i;let o=t.builtIns[e];if(o){if(s)return t.zero;let a=Array(n.length);for(let l=0;l<n.length;l++)a[l]=n[l].evaluate(this);return new de(t,o.apply(this,a))}t=t.parent}while(t);throw new Error(`Function '${e}' is undefined`)}evalMediaName(t,e){let n=t==="all"||!!this.pref.enabledMediaTypes[t];return e?!n:n}evalMediaTest(t,e){let n="",s=t.match(/^(min|max)-(.*)$/);s&&(n=s[1],t=s[2]);let i=null,o=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(i=e.evaluate(this));break}switch(t){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth;break}if(o!=null&&i!=null)switch(n){case"min":return o>=Number(i);case"max":return o<=Number(i);default:return o==i}else if(o!=null&&e==null)return o!==0;return!1}evalSupportsTest(t,e,n){return!1}queryVal(t,e){let n=t&&this.scopes[t.scopeKey];return n?n[e]:void 0}storeVal(t,e,n){this.getScopeContext(t)[e]=n}},xt=class{constructor(t){this.scope=t;p(this,"key");this.scope=t,this.key=`_${yf++}`}toString(){let t=new et;return this.appendTo(t,0),t.toString()}appendTo(t,e){throw new Error("F_ABSTRACT")}evaluateCore(t){throw new Error("F_ABSTRACT")}expand(t,e){return this}dependCore(t,e,n){return t===this}dependOuter(t,e,n){let s=n[this.key];if(s!=null)return s===bf.PENDING?!1:s;{n[this.key]=bf.PENDING;let i=this.dependCore(t,e,n);return n[this.key]=i,i}}depend(t,e){return this.dependOuter(t,e,{})}evaluate(t){let e=t.queryVal(this.scope,this.key);return typeof e!="undefined"||(e=this.evaluateCore(t),this.scope&&t.storeVal(this.scope,this.key,e)),e}isMediaName(){return!1}},jr=class extends xt{constructor(e,n){super(e);this.val=n}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let n=this.val.evaluate(e);return this.evalPrefix(n)}dependCore(e,n,s){return e===this||this.val.dependOuter(e,n,s)}appendTo(e,n){10<n&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<n&&e.append(")")}expand(e,n){let s=this.val.expand(e,n);return s===this.val?this:new this.constructor(this.scope,s)}},hi=class extends xt{constructor(e,n,s){super(e);this.lhs=n;this.rhs=s}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,n){throw new Error("F_ABSTRACT")}evaluateCore(e){let n=this.lhs.evaluate(e),s=this.rhs.evaluate(e);return this.evalInfix(n,s)}dependCore(e,n,s){return e===this||this.lhs.dependOuter(e,n,s)||this.rhs.dependOuter(e,n,s)}appendTo(e,n){let s=this.getPriority();s<=n&&e.append("("),this.lhs.appendTo(e,s),e.append(this.getOp()),this.rhs.appendTo(e,s),s<=n&&e.append(")")}expand(e,n){let s=this.lhs.expand(e,n),i=this.rhs.expand(e,n);return s===this.lhs&&i===this.rhs?this:new this.constructor(this.scope,s,i)}},Yr=class extends hi{constructor(t,e,n){super(t,e,n)}getPriority(){return 1}},Qn=class extends hi{constructor(t,e,n){super(t,e,n)}getPriority(){return 2}},qr=class extends hi{constructor(t,e,n){super(t,e,n)}getPriority(){return 3}},lo=class extends hi{constructor(t,e,n){super(t,e,n)}getPriority(){return 4}},Lt=class extends jr{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},Kr=class extends Lt{constructor(t,e){super(t,e)}getOp(){return"not "}},hn=class extends jr{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},fi=class extends Yr{constructor(t,e,n){super(t,e,n)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},Zr=class extends fi{constructor(t,e,n){super(t,e,n)}getOp(){return" and "}},gi=class extends Yr{constructor(t,e,n){super(t,e,n)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},Qr=class extends gi{constructor(t,e,n){super(t,e,n)}getOp(){return", "}},Jr=class extends gi{constructor(t,e,n){super(t,e,n)}getOp(){return" or "}},ea=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return"<"}evalInfix(t,e){return t<e}},ta=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return"<="}evalInfix(t,e){return t<=e}},na=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return">"}evalInfix(t,e){return t>e}},Is=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return">="}evalInfix(t,e){return t>=e}},Jn=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return"=="}evalInfix(t,e){return t==e}},sa=class extends Qn{constructor(t,e,n){super(t,e,n)}getOp(){return"!="}evalInfix(t,e){return t!=e}},co=class extends qr{constructor(t,e,n){super(t,e,n)}getOp(){return"+"}evalInfix(t,e){return t+e}},uo=class extends qr{constructor(t,e,n){super(t,e,n)}getOp(){return" - "}evalInfix(t,e){return t-e}},Vs=class extends lo{constructor(t,e,n){super(t,e,n)}getOp(){return"*"}evalInfix(t,e){return t*e}},po=class extends lo{constructor(t,e,n){super(t,e,n)}getOp(){return"/"}evalInfix(t,e){return t/e}},mi=class extends lo{constructor(t,e,n){super(t,e,n)}getOp(){return"%"}evalInfix(t,e){return t%e}},en=class extends xt{constructor(e,n,s){var i;super(e);this.num=n;p(this,"unit");this.unit=(i=s==null?void 0:s.toLowerCase())!=null?i:""}appendTo(e,n){e.append(this.num.toString()),e.append(dn(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},oe=class extends xt{constructor(e,n){super(e);this.qualifiedName=n}appendTo(e,n){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,n,s){return e===this||n.evalName(this.scope,this.qualifiedName).dependOuter(e,n,s)}},ho=class extends xt{constructor(e,n,s){super(e);this.not=n;this.name=s}appendTo(e,n){this.not&&e.append("not "),e.append(dn(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},ne=class extends xt{constructor(e,n,s){super(e);this.fn=n;this.str=s}appendTo(e,n){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function GC(r,t){r.append("(");for(let e=0;e<t.length;e++)e&&r.append(","),t[e].appendTo(r,0);r.append(")")}function WC(r,t,e){let n=t;for(let s=0;s<t.length;s++){let i=t[s].expand(r,e);if(t!==n)n[s]=i;else if(i!==t[s]){n=Array(t.length);for(let o=0;o<s;o++)n[o]=t[o];n[s]=i}}return n}var Ln=class r extends xt{constructor(e,n,s){super(e);this.qualifiedName=n;this.params=s}appendTo(e,n){e.append(this.qualifiedName),GC(e,this.params)}evaluateCore(e){return e.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(e,this.params).evaluate(e)}dependCore(e,n,s){if(e===this)return!0;for(let o=0;o<this.params.length;o++)if(this.params[o].dependOuter(e,n,s))return!0;return n.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(e,n,s)}expand(e,n){let s=WC(e,this.params,n);return s===this.params?this:new r(this.scope,this.qualifiedName,s)}},ia=class r extends xt{constructor(e,n,s,i){super(e);this.cond=n;this.ifTrue=s;this.ifFalse=i}appendTo(e,n){n>0&&e.append("("),this.cond.appendTo(e,0),e.append("?"),this.ifTrue.appendTo(e,0),e.append(":"),this.ifFalse.appendTo(e,0),n>0&&e.append(")")}evaluateCore(e){return this.cond.evaluate(e)?this.ifTrue.evaluate(e):this.ifFalse.evaluate(e)}dependCore(e,n,s){return e===this||this.cond.dependOuter(e,n,s)||this.ifTrue.dependOuter(e,n,s)||this.ifFalse.dependOuter(e,n,s)}expand(e,n){let s=this.cond.expand(e,n),i=this.ifTrue.expand(e,n),o=this.ifFalse.expand(e,n);return s===this.cond&&i===this.ifTrue&&o===this.ifFalse?this:new r(this.scope,s,i,o)}},de=class extends xt{constructor(e,n){super(e);this.val=n}appendTo(e,n){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(Ls(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},fo=class r extends xt{constructor(e,n,s){super(e);this.name=n;this.value=s}appendTo(e,n){e.append("("),e.append(Ls(this.name.name)),e.append(":"),this.value.appendTo(e,0),e.append(")")}evaluateCore(e){return e.evalMediaTest(this.name.name,this.value)}dependCore(e,n,s){return e===this||this.value.dependOuter(e,n,s)}expand(e,n){let s=this.value.expand(e,n);return s===this.value?this:new r(this.scope,this.name,s)}},oa=class extends xt{constructor(e,n,s,i){super(e);this.name=n;this.value=s;this.isFunc=i}appendTo(e,n){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)}},Ci=class extends xt{constructor(e,n){super(e);this.index=n}appendTo(e,n){e.append("$"),e.append(this.index.toString())}expand(e,n){let s=n[this.index];if(!s)throw new Error(`Parameter missing: ${this.index}`);return s}};function lt(r,t,e){return t===r._false||t===r.zero||e==r._false||e==r.zero?r._false:t===r._true||t===r.one?e:e===r._true||e===r.one?t:new fi(r,t,e)}function $(r,t,e){return t===r.zero?e:e===r.zero?t:new co(r,t,e)}function ee(r,t,e){return t===r.zero?new hn(r,e):e===r.zero?t:new uo(r,t,e)}function bi(r,t,e){return t===r.zero||e===r.zero?r.zero:t===r.one?e:e===r.one?t:new Vs(r,t,e)}function mo(r,t,e){return t===r.zero?r.zero:e===r.one?t:new po(r,t,e)}var St=class{visitValues(t){for(let e=0;e<t.length;e++)t[e].visit(this);return null}visitEmpty(t){return null}visitSlash(t){return null}visitStr(t){return null}visitIdent(t){return null}visitNumeric(t){return null}visitNum(t){return null}visitInt(t){return this.visitNum(t)}visitHexColor(t){return null}visitURL(t){return null}visitURange(t){return null}visitSpaceList(t){return this.visitValues(t.values),null}visitCommaList(t){return this.visitValues(t.values),null}visitFunc(t){return this.visitValues(t.values),null}visitExpr(t){return null}},fn=class extends St{constructor(){super();p(this,"error",!1)}visitValues(e){let n=null;for(let s=0;s<e.length;s++){let i=e[s],o=i.visit(this);if(this.error)return[];if(n)n[s]=o;else if(i!==o){n=new Array(e.length);for(let a=0;a<s;a++)n[a]=e[a];n[s]=o}}return n||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 n=this.visitValues(e.values);return this.error?U:n===e.values?e:new W(n)}visitCommaList(e){let n=this.visitValues(e.values);return this.error?U:n===e.values?e:new ge(n)}visitFunc(e){let n=this.visitValues(e.values);return this.error?U:n===e.values?e:new Xt(e.name,n)}visitExpr(e){return e}},ke=class{toString(){let t=new et;return this.appendTo(t,!0),t.toString()}stringValue(){let t=new et;return this.appendTo(t,!1),t.toString()}toExpr(t,e){return null}appendTo(t,e){t.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(t){return this}},la=class la extends ke{static get instance(){return this.empty||(this.empty=new la),this.empty}constructor(){super()}toExpr(t,e){return new de(t,"")}appendTo(t,e){}visit(t){return t.visitEmpty(this)}};p(la,"empty");var Xc=la,U=Xc.instance,ca=class ca extends ke{static get instance(){return this.slash||(this.slash=new ca),this.slash}constructor(){super()}toExpr(t,e){return new de(t,"/")}appendTo(t,e){t.append("/")}visit(t){return t.visitSlash(this)}};p(ca,"slash");var $c=ca,xi=$c.instance,D=class extends ke{constructor(e){super();this.str=e}toExpr(e,n){return new de(e,this.str)}appendTo(e,n){n?(e.append('"'),e.append(Ls(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},jc={},j=class extends ke{constructor(e){super();this.name=e;if(jc[e])throw new Error("E_INVALID_CALL");jc[e]=this}toExpr(e,n){return new de(e,this.name)}appendTo(e,n){n?e.append(dn(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function k(r){let t=jc[r];return t||(t=new j(r)),t}var P=class extends ke{constructor(e,n){var s;super();this.num=e;p(this,"unit");this.unit=(s=n==null?void 0:n.toLowerCase())!=null?s:""}toExpr(e,n){return this.num==0?e.zero:n&&this.unit=="%"?this.num==100?n:new Vs(e,n,new de(e,this.num/100)):new en(e,this.num,this.unit)}appendTo(e,n){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},nt=class extends ke{constructor(e){super();this.num=e}toExpr(e,n){return this.num==0?e.zero:this.num==1?e.one:new de(e,this.num)}appendTo(e,n){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},se=class extends nt{constructor(t){super(t)}visit(t){return t.visitInt(this)}},yi=class extends ke{constructor(e){super();this.hex=e}appendTo(e,n){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},fe=class extends ke{constructor(e){super();this.url=e}appendTo(e,n){e.append('url("'),e.append(Ls(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Co=class extends ke{constructor(e){super();this.urangeText=e}appendTo(e,n){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Yc(r,t,e,n){var i,o;let s=t.length;if(s>0){(i=t[0])==null||i.appendTo(r,n);for(let a=1;a<s;a++)r.append(e),(o=t[a])==null||o.appendTo(r,n)}}var W=class extends ke{constructor(e){super();this.values=e}appendTo(e,n){Yc(e,this.values," ",n)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},ge=class extends ke{constructor(e){super();this.values=e}appendTo(e,n){Yc(e,this.values,",",n)}visit(e){return e.visitCommaList(this)}},Xt=class extends ke{constructor(e,n){super();this.name=e;this.values=n}appendTo(e,n){e.append(dn(this.name)),e.append("("),Yc(e,this.values,",",n),e.append(")")}visit(e){return e.visitFunc(this)}},O=class extends ke{constructor(e){super();this.expr=e}toExpr(){return this.expr}appendTo(e,n){this.expr instanceof de||this.expr instanceof en?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}},gn=class extends ke{constructor(e){super();this.text=e}appendTo(e,n){e.append(this.text||" ")}};function Be(r,t){if(r){if(r.isNumeric()){let e=r;return t.queryUnitSize(e.unit,!1)*e.num}if(r.isNum())return r.num}return 0}function ua(r,t){return new P(Be(r,t),"px")}var b={absolute:k("absolute"),all:k("all"),always:k("always"),anywhere:k("anywhere"),auto:k("auto"),avoid:k("avoid"),balance:k("balance"),balance_all:k("balance-all"),block:k("block"),block_end:k("block-end"),block_start:k("block-start"),both:k("both"),bottom:k("bottom"),border_box:k("border-box"),break_all:k("break-all"),break_word:k("break-word"),clip:k("clip"),crop:k("crop"),cross:k("cross"),column:k("column"),discard:k("discard"),exclusive:k("exclusive"),_false:k("false"),fixed:k("fixed"),flex:k("flex"),flow_root:k("flow-root"),footnote:k("footnote"),footer:k("footer"),grid:k("grid"),header:k("header"),hidden:k("hidden"),horizontal_tb:k("horizontal-tb"),inherit:k("inherit"),initial:k("initial"),inline:k("inline"),inline_block:k("inline-block"),inline_end:k("inline-end"),inline_start:k("inline-start"),inside:k("inside"),keep:k("keep"),landscape:k("landscape"),left:k("left"),line:k("line"),list_item:k("list-item"),ltr:k("ltr"),manual:k("manual"),max_content:k("max-content"),min_content:k("min-content"),none:k("none"),normal:k("normal"),oeb_page_foot:k("oeb-page-foot"),oeb_page_head:k("oeb-page-head"),outside:k("outside"),padding_box:k("padding-box"),page:k("page"),relative:k("relative"),revert:k("revert"),right:k("right"),same:k("same"),scale:k("scale"),snap_block:k("snap-block"),snap_inline:k("snap-inline"),solid:k("solid"),spread:k("spread"),_static:k("static"),rtl:k("rtl"),table:k("table"),table_caption:k("table-caption"),table_cell:k("table-cell"),table_footer_group:k("table-footer-group"),table_header_group:k("table-header-group"),table_row:k("table-row"),top:k("top"),transparent:k("transparent"),unset:k("unset"),vertical_lr:k("vertical-lr"),vertical_rl:k("vertical-rl"),visible:k("visible"),_true:k("true")},qc=new P(100,"%"),es=new P(100,"pvw"),ts=new P(100,"pvh"),ae=new P(0,"px"),Qx=new Co("U+0-10FFFF"),Nf={"font-size":1,"line-height":2,color:3};function X(r){return r===b.inherit||r===b.initial||r===b.revert||r===b.unset}function Kc(r,t){let e=Nf[r]||Number.MAX_VALUE,n=Nf[t]||Number.MAX_VALUE;return e-n}function It(r){return(r==null?void 0:r.length)>2&&r.startsWith("--")}var Ye=class{constructor(t,e,n,s){this.x1=t;this.y1=e;this.x2=n;this.y2=s}},tn=class{constructor(t,e){this.x=t;this.y=e}},Ei=class{constructor(t,e,n,s){this.left=t;this.top=e;this.right=n;this.bottom=s}},da=class{constructor(t,e,n,s){this.low=t;this.high=e;this.winding=n;this.shapeId=s}},nn=class{constructor(t,e,n,s){this.y1=t;this.y2=e;this.x1=n;this.x2=s;p(this,"left",null);p(this,"right",null)}};function XC(r,t){return r.low.y-t.low.y||r.low.x-t.low.x}var Fs=class r{constructor(t){this.points=t}addSegments(t,e){let n=this.points,s=n.length,i=n[s-1];for(let o=0;o<s;o++){let a=n[o],l;i.y<a.y?l=new da(i,a,1,e):l=new da(a,i,-1,e),t.push(l),i=a}}withOffset(t,e){let n=[];for(let s of this.points)n.push(new tn(s.x+t,s.y+e));return new r(n)}};function Zc(r,t,e,n){let i=[];for(let o=0;o<20;o++){let a=o*2*Math.PI/20;i.push(new tn(r+e*Math.sin(a),t+n*Math.cos(a)))}return new Fs(i)}function bo(r,t,e,n){return new Fs([new tn(r,t),new tn(e,t),new tn(e,n),new tn(r,n)])}var Si=class{constructor(t,e,n,s){this.x=t;this.winding=e;this.shapeId=n;this.lowOrHigh=s}};function vf(r,t){let e=r.low.x+(r.high.x-r.low.x)*(t-r.low.y)/(r.high.y-r.low.y);if(isNaN(e))throw new Error("Bad intersection");return e}function $C(r,t,e,n){let s,i,o,a;t.high.y<e&&F.warn("Error: inconsistent segment (1)"),t.low.y<=e?(s=vf(t,e),i=t.winding):(s=t.low.x,i=0),t.high.y>=n?(o=vf(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(r.push(new Si(s,i,t.shapeId,-1)),r.push(new Si(o,a,t.shapeId,1))):(r.push(new Si(o,a,t.shapeId,-1)),r.push(new Si(s,i,t.shapeId,1)))}function jC(r,t,e){let n=t+e,s=Array(n),i=Array(n),o;for(o=0;o<=n;o++)s[o]=0,i[o]=0;let a=[],l=!1,c=r.length;for(let u=0;u<c;u++){let d=r[u];s[d.shapeId]+=d.winding,i[d.shapeId]+=d.lowOrHigh;let h=!1;for(o=0;o<t;o++)if(s[o]&&!i[o]){h=!0;break}if(h){for(o=t;o<=n;o++)if(s[o]||i[o]){h=!1;break}}l!=h&&(a.push(d.x),l=h)}return a}function YC(r,t){return t?Math.ceil(r/t)*t:r}function Tf(r,t){return t?Math.floor(r/t)*t:r}function qC(r){return new tn(r.y,-r.x)}function Ni(r){return new Ye(r.y1,-r.x2,r.y2,-r.x1)}function pa(r){return new Ye(-r.y2,r.x1,-r.y1,r.x2)}function wf(r){return new Fs(r.points.map(t=>qC(t)))}function Pf(r,t,e,n,s,i){i&&(r=Ni(r),t=t.map(C=>wf(C)),e=e.map(C=>wf(C)));let o=t.length,a=e?e.length:0,l=[],c=[],u,d,h;for(u=0;u<o;u++)t[u].addSegments(c,u);for(u=0;u<a;u++)e[u].addSegments(c,u+o);let f=c.length;c.sort(XC);let g=0;for(;c[g].shapeId>=o;)g++;let m=c[g].low.y;m>r.y1&&l.push(new nn(r.y1,m,r.x2,r.x2));let y=0,S=[];for(;y<f&&(h=c[y]).low.y<m;)h.high.y>m&&S.push(h),y++;for(;y<f||S.length>0;){let C=r.y2,x=Math.min(YC(Math.ceil(m+n),s),r.y2);for(d=0;d<S.length&&C>x;d++)h=S[d],h.low.x==h.high.x?h.high.y<C&&(C=Math.max(Tf(h.high.y,s),x)):h.low.x!=h.high.x&&(C=x);for(C>r.y2&&(C=r.y2);y<f&&(h=c[y]).low.y<C;){if(h.high.y<m){y++;continue}if(h.low.y<x)h.low.y==h.high.y&&h.low.y==m||(S.push(h),C=x),y++;else{let v=Tf(h.low.y,s);v<C&&(C=v);break}}let N=[];for(d=0;d<S.length;d++)$C(N,S[d],m,C);N.sort((v,L)=>v.x-L.x||v.lowOrHigh-L.lowOrHigh);let E=jC(N,o,a);if(E.length==0)l.push(new nn(m,C,r.x2,r.x2));else{let v=0,L=r.x1;for(d=0;d<E.length;d+=2){let B=Math.max(r.x1,E[d]),H=Math.min(r.x2,E[d+1])-B;H>v&&(v=H,L=B)}v==0?l.push(new nn(m,C,r.x2,r.x2)):l.push(new nn(m,C,Math.max(L,r.x1),Math.min(L+v,r.x2)))}if(C==r.y2)break;for(m=C,d=S.length-1;d>=0;d--)S[d].high.y<=C&&S.splice(d,1)}return kf(r,l),l}function kf(r,t){let e=t.length-1,n=new nn(r.y2,r.y2,r.x1,r.x2);for(;e>=0;){let s=n;n=t[e],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(e,1),n=s),e--}}function Af(r,t){let e=0,n=r.length;for(;e<n;){let s=Math.floor((e+n)/2);t>=r[s].y2?e=s+1:n=s}return e}function Lf(r,t){if(!r.length)return t;let e=t.y1,n,s;for(s=0;s<r.length&&(n=r[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)e=Math.max(e,n.y2);let i=e;for(;s<r.length&&(n=r[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)i=n.y2;return s===r.length?i=t.y2:i=Math.min(i,t.y2),i<=e?null:new Ye(t.x1,e,t.x2,i)}function Rf(r,t){if(!r.length)return t;let e=t.y2,n,s;for(s=r.length-1;s>=0&&(n=r[s],!(s===r.length-1&&n.y2<t.y2));s--){if(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2)break;e=Math.min(e,n.y1)}let i=Math.min(e,n.y2);for(;s>=0&&(n=r[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)i=n.y1;return i=Math.max(i,t.y1),e<=i?null:new Ye(t.x1,i,t.x2,e)}function If(r,t,e,n){let s=e.y1,i=e.x2-e.x1,o=e.y2-e.y1,a=Af(t,s);for(;;){let l=s+o;if(l>r.y2)return!1;let c=r.x1,u=r.x2;for(let d=a;d<t.length&&t[d].y1<l;d++){let h=t[d];h.x1>c&&(c=h.x1),h.x2<u&&(u=h.x2)}if(c+i<=u||a>=t.length)return n=="left"?(e.x1=c,e.x2=c+i):(e.x1=u-i,e.x2=u),e.y2+=s-e.y1,e.y1=s,!0;s=t[a].y2,a++}}function Vf(r,t,e,n,s){for(n||(n=[new nn(e.y1,e.y2,e.x1,e.x2)]);n.length>0&&n[0].y2<=r.y1;)n.shift();if(n.length==0)return;n[0].y1<r.y1&&(n[0].y1=r.y1);let i,o=t.length==0?r.y1:t[t.length-1].y2;o<r.y2&&t.push(new nn(o,r.y2,r.x1,r.x2));let a=Af(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(i=t[a],a++,t.splice(a,0,new nn(l.y1,i.y2,i.x1,i.x2)),i.y2=l.y1);a<t.length&&(i=t[a++],i.y2>l.y2&&(t.splice(a,0,new nn(l.y2,i.y2,i.x1,i.x2)),i.y2=l.y2),l.x1!=l.x2&&(s=="left"?i.x1=Math.min(l.x2,r.x2):i.x2=Math.max(l.x1,r.x1)),i.y2!=l.y2););}kf(r,t)}var Qc=class extends St{constructor(){super();p(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Ff(r){if(r){let t=new Qc;try{return r.visit(t),t.propSet}catch(e){F.warn(e,"toSet:")}}return{}}var Jc=class extends St{constructor(e){super();this.value=e}visitInt(e){return this.value=e.num,e}};function nu(r,t){if(r){let e=new Jc(t);try{return r.visit(e),e.value}catch(n){F.warn(n,"toInt: ")}}return t}var eu=class extends St{constructor(){super();p(this,"collect",!1);p(this,"coords",[]);p(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 P(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,n,s,i,o){if(this.coords.length>0){let a=[];switch(this.coords.forEach((l,c)=>{if(l.unit=="%"){let u=c%2==0?s:i;c==3&&this.name=="circle"&&(u=Math.sqrt((s*s+i*i)/2)),a.push(l.num*u/100)}else a.push(l.num*o.queryUnitSize(l.unit,!1))}),this.name){case"polygon":if(a.length%2==0){let l=[];for(let c=0;c<a.length;c+=2)l.push(new tn(e+a[c],n+a[c+1]));return new Fs(l)}break;case"rectangle":if(a.length==4)return bo(e+a[0],n+a[1],e+a[0]+a[2],n+a[1]+a[3]);break;case"ellipse":if(a.length==4)return Zc(e+a[0],n+a[1],a[2],a[3]);break;case"circle":if(a.length==3)return Zc(e+a[0],n+a[1],a[2],a[2]);break}}return null}};function ga(r,t,e,n,s,i){if(r){let o=new eu;try{return r.visit(o),o.getShape(t,e,n,s,i)}catch(a){F.warn(a,"toShape:")}}return bo(t,e,t+n,e+s)}var tu=class extends St{constructor(e){super();this.reset=e;p(this,"counters",{});p(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 Bs(r,t){let e=new tu(t);try{r.visit(e)}catch(n){F.warn(n,"toCounters:")}return e.counters}var fa=class extends fn{constructor(e,n){super();this.baseUrl=e;this.transformer=n}visitURL(e){return new fe(this.transformer.transformURL(e.url,this.baseUrl))}};function su(r){let t={};return Object.keys(r).forEach(e=>{t[e]=Array.from(r[e])}),t}function Ti(r,t){if(t==="content"){let e=r.cloneNode(!0);return e.querySelectorAll("[data-adapt-pseudo]").forEach(s=>s.remove()),e.textContent||""}else{let e=r.querySelector(`[data-adapt-pseudo="${t}"]`);return e&&e.textContent||""}}var lu=class{constructor(t,e){this.targetId=t;this.resolved=e;p(this,"pageCounters",null);p(this,"spineIndex",-1);p(this,"pageIndex",-1)}equals(t){return this===t?!0:t?this.targetId===t.targetId&&this.resolved===t.resolved&&this.spineIndex===t.spineIndex&&this.pageIndex===t.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},cu=class{constructor(t,e){this.counterStore=t;this.baseURL=e}countersOfId(t,e){t=this.counterStore.documentURLTransformer.transformFragment(t,this.baseURL),this.counterStore.countersById[t]=e}getExprContentListener(){return this.counterStore.getExprContentListener()}},uu=class{constructor(t,e,n,s){this.counterStore=t;this.baseURL=e;this.rootScope=n;this.pageScope=s;p(this,"styler",null);p(this,"namedStringValues",{});p(this,"runningElements",{})}setStyler(t){this.styler=t}getFragment(t){let e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null}getTransformedId(t){let e=this.counterStore.documentURLTransformer.transformURL(te(t,this.baseURL),this.baseURL);return e.charAt(0)==="#"&&(e=e.substring(1)),e}getPageCounterVal(t,e){let n=()=>{let o=this.counterStore.currentPageCounters[t];return o&&o.length?o[o.length-1]:null},s=new ne(this.pageScope,()=>e(n()),`page-counter-${t}`),i=o=>e(o[o.length-1]);return this.counterStore.registerPageCounterExpr(t,i,s),s}getPageCountersVal(t,e){let n=()=>this.counterStore.currentPageCounters[t]||[],s=new ne(this.pageScope,()=>e(n()),`page-counters-${t}`);return this.counterStore.registerPageCounterExpr(t,e,s),s}getTargetCounters(t,e,n){let s=this.counterStore.countersById[e];return!s&&n&&t&&(this.styler.styleUntilIdIsReached(t),s=this.counterStore.countersById[e]),s||null}getTargetPageCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[t]||null}getTargetPageText(t,e){if(this.counterStore.currentPage.elementsById[t]){let n=this.counterStore.currentPage.elementsById[t];if(n&&n.length>0){let s=n[0];return e==="before"||e==="after"||e==="marker"?Ti(s,e):Ti(s,"content")}return""}else{if(t in this.counterStore.pageTextById){let n=this.counterStore.pageTextById[t];return n[e]!==void 0?n[e]:n.content||""}return null}}getTargetCounterVal(t,e,n){let s=this.getFragment(t),i=this.getTransformedId(t),o=this.getTargetCounters(s,i,!1);if(o&&o[e]){let l=o[e];return new de(this.rootScope,n(l[l.length-1]||null))}let a=new ne(this.pageScope,()=>{if(o=this.getTargetCounters(s,i,!0),o)if(o[e]){let l=o[e];return n(l[l.length-1]||null)}else{let l=this.getTargetPageCounters(i);if(l)if(this.counterStore.resolveReference(i),l[e]){let c=l[e];return n(c[c.length-1]||null)}else return n(0);else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"},`target-counter-${e}-of-${t}`);return this.counterStore.registerTargetCounterExpr(e,n,a,i),a}getTargetCountersVal(t,e,n){let s=this.getFragment(t),i=this.getTransformedId(t);return new ne(this.pageScope,()=>{let o=this.getTargetPageCounters(i);if(o){this.counterStore.resolveReference(i);let a=o[e]||[],c=this.getTargetCounters(s,i,!0)[e]||[];return n(a.concat(c))}else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"},`target-counters-${e}-of-${t}`)}getTargetTextVal(t,e){let n=this.getTransformedId(t),s=new ne(this.pageScope,()=>{if(e==="first-letter"){let o=this.getTargetPageText(n,"before"),a=this.getTargetPageText(n,"content"),l=this.getTargetPageText(n,"after");if(o===null&&a===null&&l===null)return this.counterStore.saveReferenceOfCurrentPage(n,!1),"??";let c=(o!=null?o:"")+(a!=null?a:"")+(l!=null?l:"");this.counterStore.resolveReference(n);let u=c.match(As);return u?u[0]:""}let i=this.getTargetPageText(n,e);return i!==null?(this.counterStore.resolveReference(n),i):(this.counterStore.saveReferenceOfCurrentPage(n,!1),"??")},`target-text-${e}-of-${t}`);return this.counterStore.registerTargetTextExpr(e,s,n),s}getNamedStringVal(t,e){return new ne(this.pageScope,()=>this.getRunningValue(this.namedStringValues,t,e),`named-string-${e}-${t}`)}getRunningElementVal(t,e){return new ne(this.pageScope,()=>this.getRunningValue(this.runningElements,t,e),`running-element-${e}-${t}`)}getRunningValue(t,e,n){let s=t[e];if(!s)return"";let i=Object.keys(s).map(g=>parseInt(g,10)).sort(zr),o=this.counterStore.currentPage,a=o.isBlankPage?o.offset-1:o.offset,l=o.isBlankPage?a:Math.max(a,...Array.from(o.container.querySelectorAll(`[${Zt}]`)).map(g=>parseInt(g.getAttribute(Zt),10))),c=-1,u=-1,d=-1,h=-1;for(let g=0;g<i.length;g++){let m=i[g],y=g>0?i[g-1]:-1,S=g<i.length-1?i[g+1]:-1;if(m>l)break;if(m>=a){if(c<0&&(c=m,h=-1),u<0)if(m===a)u=m;else{y<c&&(u=y);let C=o.container.querySelector(`[${Zt}="${m}"]`);if(!C)u<0&&(u=m);else{let x=o.container.querySelector(`[${Zt}="${a}"]`);if(x||(x=o.container.querySelector(`[${Zt}="0"]`)),x){for(let N=x;N;N=N.firstElementChild)if(N===C){u=m;break}}}}d=m}else(S>l||S<0)&&(c=u=d=h=m)}return s[{first:c,start:u,last:d,"first-except":h}[n]]||""}setNamedString(t,e,n){let s=this.namedStringValues[t]||(this.namedStringValues[t]={});s[n]=e}setRunningElement(t,e){let n=this.runningElements[t]||(this.runningElements[t]={});n[e]=String(e)}},ma=class{constructor(t){this.documentURLTransformer=t;p(this,"countersById",{});p(this,"pageCountersById",{});p(this,"pageTextById",{});p(this,"currentPageCounters",{});p(this,"previousPageCounters",{});p(this,"currentPageCountersStack",[]);p(this,"pageIndicesById",{});p(this,"currentPage",null);p(this,"newReferencesOfCurrentPage",[]);p(this,"referencesToSolve",[]);p(this,"referencesToSolveStack",[]);p(this,"unresolvedReferences",{});p(this,"resolvedReferences",{});p(this,"pagesCounterExprs",[]);p(this,"pageCounterExprs",[]);p(this,"targetCounterExprs",[]);p(this,"targetTextExprs",[]);this.currentPageCounters.page=[0]}createCounterListener(t){return new cu(this,t)}createCounterResolver(t,e,n){return new uu(this,t,e,n)}setCurrentPage(t){this.currentPage=t}definePageCounter(t,e){this.currentPageCounters[t]?this.currentPageCounters[t].push(e):this.currentPageCounters[t]=[e]}forceSetPageCounter(t){let e=this.currentPageCounters.page;!e||!e.length?this.currentPageCounters.page=[t]:e[e.length-1]=t}updatePageCounters(t,e){this.previousPageCounters=su(this.currentPageCounters);let n,s=t["counter-reset"];if(s){let a=s.evaluate(e);a&&(n=Bs(a,!0))}if(n)for(let a in n)this.definePageCounter(a,n[a]);let i,o=t["counter-increment"];if(o){let a=o.evaluate(e);a&&(i=Bs(a,!1))}i?"page"in i||(i.page=1):(i={},i.page=1);for(let a in i){this.currentPageCounters[a]||this.definePageCounter(a,0);let l=this.currentPageCounters[a];l[l.length-1]+=i[a]}}pushPageCounters(t){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=su(t)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(t){let e=this.unresolvedReferences[t],n=this.resolvedReferences[t];n||(n=this.resolvedReferences[t]=[]);let s=!1;for(let i=0;i<this.referencesToSolve.length;){let o=this.referencesToSolve[i];if(o.targetId===t){if(o.resolve(),this.referencesToSolve.splice(i,1),e){let a=e.indexOf(o);a>=0&&e.splice(a,1)}n.push(o),s=!0}else i++}s||this.saveReferenceOfCurrentPage(t,!0)}saveReferenceOfCurrentPage(t,e){if(!this.newReferencesOfCurrentPage.some(n=>n.targetId===t)){let n=new lu(t,e);this.newReferencesOfCurrentPage.push(n)}}finishPage(t,e){let n=Object.keys(this.currentPage.elementsById);if(n.length>0){let o=su(this.currentPageCounters);n.forEach(a=>{this.pageCountersById[a]=o;let l=this.currentPage.elementsById[a];if(l&&l.length>0){let u=l[0];this.pageTextById[a]={content:Ti(u,"content"),before:Ti(u,"before"),after:Ti(u,"after"),marker:Ti(u,"marker")}}let c=this.pageIndicesById[a];if(c&&c.pageIndex<e){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let h;for(;h=u.shift();)h.unresolve(),d.push(h)}}this.pageIndicesById[a]={spineIndex:t,pageIndex:e}})}let s=this.previousPageCounters,i;for(;i=this.newReferencesOfCurrentPage.shift();){i.pageCounters=s,i.spineIndex=t,i.pageIndex=e;let o;i.isResolved()?(o=this.resolvedReferences[i.targetId],o||(o=this.resolvedReferences[i.targetId]=[])):(o=this.unresolvedReferences[i.targetId],o||(o=this.unresolvedReferences[i.targetId]=[])),o.every(a=>!i.equals(a))&&o.push(i)}this.currentPage=null}getUnresolvedRefsToPage(t){let e=[];Object.keys(t.elementsById).forEach(o=>{let a=this.unresolvedReferences[o];a&&(e=e.concat(a))}),e.sort((o,a)=>o.spineIndex-a.spineIndex||o.pageIndex-a.pageIndex);let s=[],i=null;return e.forEach(o=>{!i||i.spineIndex!==o.spineIndex||i.pageIndex!==o.pageIndex?(i={spineIndex:o.spineIndex,pageIndex:o.pageIndex,pageCounters:o.pageCounters,refs:[o]},s.push(i)):i.refs.push(o)}),s}pushReferencesToSolve(t){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=t}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(t,e,n){t==="pages"?this.pagesCounterExprs.push({expr:n,format:e}):this.pageCounterExprs.push({expr:n,format:e})}registerTargetCounterExpr(t,e,n,s){this.targetCounterExprs.push({name:t,expr:n,format:e,transformedId:s})}registerTargetTextExpr(t,e,n){this.targetTextExprs.push({pseudoElement:t,expr:e,transformedId:n})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(t,e,n){if(t instanceof ne){if(t.str=="viv-leader"){let o=n.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute("data-viv-leader",t.key),o.setAttribute("data-viv-leader-value",e),o}else if(t.str.startsWith("running-element-")){let o=e&&n.querySelectorAll(`[${Zt}="${e}"]`);if(!o||o.length===0)return null;let l=o[o.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(l),l.style.position="",l.style.visibility="",l}else if(t.str.startsWith("target-counter-")){let o=n.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(ru,t.key),o}else if(t.str.startsWith("target-text-")){let o=n.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(au,t.key),o}}let s=this.pagesCounterExprs.findIndex(o=>o.expr===t)>=0,i=!s&&this.pageCounterExprs.findIndex(o=>o.expr===t)>=0;if(s||i){let o=n.createElementNS("http://www.w3.org/1999/xhtml","span");return o.textContent=e,o.setAttribute(s?iu:ou,t.key),o}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${ou}]`);for(let i of e){let o=i.getAttribute(ou),a=this.pageCounterExprs.find(d=>d.expr.key===o),l=(a==null?void 0:a.expr).str,c=l==null?void 0:l.replace(/^page-counters?-/,""),u=this.currentPageCounters[c];u&&(i.textContent=a.format(u))}let n=t.querySelectorAll(`[${ru}]`);for(let i of n)i.setAttribute(Bf,!0);let s=t.querySelectorAll(`[${au}]`);for(let i of s)i.setAttribute(Of,!0)}finishLastPage(t){var o;let e=t.root.querySelectorAll(`[${iu}]`),n=t.contentContainer.childElementCount;for(let a of e){let l=a.getAttribute(iu),c=this.pagesCounterExprs.findIndex(u=>u.expr.key===l);c>=0,a.textContent=this.pagesCounterExprs[c].format([n])}let s=t.root.querySelectorAll(`[${Bf}]`);for(let a of s){let l=a.getAttribute(ru),c=this.targetCounterExprs.find(u=>u.expr.key===l);if(c&&c.transformedId){let u=this.pageCountersById[c.transformedId];if(u){let d=u[c.name];d&&(a.textContent=c.format(d[d.length-1]))}}}let i=t.root.querySelectorAll(`[${Of}]`);for(let a of i){let l=a.getAttribute(au),c=this.targetTextExprs.find(u=>u.expr.key===l);if(c&&c.transformedId){let u=this.pageTextById[c.transformedId];u&&(a.textContent=(o=u[c.pseudoElement])!=null?o:"")}}}createLayoutConstraint(t){return new du(this,t)}},iu="data-vivliostyle-pages-counter",ou="data-vivliostyle-page-counter",ru="data-vivliostyle-target-counter",au="data-vivliostyle-target-text",Bf="data-vivliostyle-target-counter-in-running",Of="data-vivliostyle-target-text-in-running",du=class{constructor(t,e){this.counterStore=t;this.pageIndex=e}allowLayout(t){if(!t||t.after)return!0;let e=t.viewNode;if(!e||e.nodeType!==1)return!0;let n=e.getAttribute("data-vivliostyle-id")||e.getAttribute("id")||e.getAttribute("name");if(!n||!this.counterStore.resolvedReferences[n]&&!this.counterStore.unresolvedReferences[n])return!0;let s=this.counterStore.pageIndicesById[n];return s?this.pageIndex>=s.pageIndex:!0}};function ZC(r){if(r=r.substr(1),r.match(/^[^0-9a-fA-F\n\r]$/))return r;let t=parseInt(r,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function Os(r){return r.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,ZC)}var hu=class{constructor(){p(this,"type");p(this,"precededBySpace",!1);p(this,"num",0);p(this,"text","");p(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 Ie(r,t){let e=Array(128),n;for(n=0;n<128;n++)e[n]=r;for(e[NaN]=r==35?35:72,n=0;n<t.length;n+=2)e[t[n]]=t[n+1];return e}var Rn=[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];Rn[NaN]=80;var mn=[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];mn[NaN]=43;var QC=[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];mn[NaN]=43;var Mf=[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];Mf[NaN]=35;var _f=[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];_f[NaN]=45;var fu=[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];fu[NaN]=37;var gu=[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];gu[NaN]=38;var Ds=Ie(35,[61,36]),JC=Ie(35,[58,77]),eb=Ie(35,[61,36,124,50]),tb=Ie(35,[38,51]),nb=Ie(35,[42,54]),sb=Ie(39,[42,55]),ib=Ie(54,[42,55,47,56]),ob=Ie(62,[62,82]),rb=Ie(35,[61,36,33,70]),ab=Ie(62,[45,71]),lb=Ie(63,[45,81]),pu=Ie(76,[10,72,13,72]),cb=Ie(39,[39,46,10,72,13,72,92,48]),ub=Ie(39,[34,46,10,72,13,72,92,49]),db=Ie(39,[39,47,10,74,13,74,92,48]),pb=Ie(39,[34,47,10,74,13,74,92,49]),Df=Ie(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),hb=Ie(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]),fb=Ie(39,[39,68,10,74,13,74,92,75,NaN,67]),gb=Ie(39,[34,68,10,74,13,74,92,75,NaN,67]),mb=Ie(72,[9,39,10,39,13,39,32,39,41,69]),Cb=15,Ge=class{constructor(t,e){this.input=t;this.handler=e;p(this,"indexMask");p(this,"buffer");p(this,"tail",0);p(this,"curr",0);p(this,"position",0);this.indexMask=Cb,this.buffer=Array(this.indexMask+1);for(let n=0;n<=this.indexMask;n++)this.buffer[n]=new hu}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(t){return(this.tail-this.curr&this.indexMask)<=t&&this.fillBuffer(),this.buffer[this.curr+t&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let t=this.tail,e=this.curr,n=this.indexMask;if(t>=e?e+=n:e--,e==t)throw new Error("F_CSSTOK_INTERNAL");let s=Rn,i=this.input,o=this.position,a=this.buffer,l=0,c=0,u="",d=0,h=!1,f=a[t],g=-9;for(;;){let m=i.charCodeAt(o);switch(s[m]||s[65]){case 72:u=i.substring(c,o),isNaN(m)?l=0:l=54,s=Rn;break;case 1:o++,h=!0;continue;case 2:c=o++,s=fu;continue;case 3:l=1,c=o++,s=mn;continue;case 4:c=o++,l=31,s=Ds;continue;case 33:l=2,c=++o,s=cb;continue;case 34:l=2,c=++o,s=ub;continue;case 6:c=++o,l=7,s=mn;continue;case 7:c=o++,l=32,s=Ds;continue;case 8:c=o++,l=21;break;case 9:c=o++,l=32,s=tb;continue;case 10:c=o++,l=10;break;case 11:c=o++,l=11;break;case 12:c=o++,l=36,s=Ds;continue;case 13:c=o++,l=23;break;case 14:c=o++,l=16;break;case 15:l=24,c=o++,s=Mf;continue;case 16:c=o++,s=QC;continue;case 78:c=o++,l=9,s=mn;continue;case 17:c=o++,l=19,s=nb;continue;case 18:c=o++,l=18,s=JC;continue;case 77:o++,l=50;break;case 19:c=o++,l=17;break;case 20:c=o++,l=38,s=rb;continue;case 21:c=o++,l=39,s=Ds;continue;case 22:c=o++,l=37,s=Ds;continue;case 23:c=o++,l=22;break;case 24:c=++o,l=20,s=mn;continue;case 25:c=o++,l=14;break;case 26:c=o++,l=15;break;case 27:c=o++,l=12;break;case 28:c=o++,l=13;break;case 29:c=o++,g=c,l=1,s=pu;continue;case 30:c=o++,l=33,s=Ds;continue;case 31:c=o++,l=34,s=eb;continue;case 32:c=o++,l=35,s=Ds;continue;case 35:break;case 36:o++,l=l+41-31;break;case 37:l=5,d=parseInt(i.substring(c,o),10);break;case 38:l=4,d=parseFloat(i.substring(c,o));break;case 39:o++;continue;case 40:l=3,d=parseFloat(i.substring(c,o)),c=o++,s=mn;continue;case 41:l=3,d=parseFloat(i.substring(c,o)),u="%",c=o++;break;case 42:o++,s=gu;continue;case 43:if(u=Os(i.substring(c,o)),l===27&&m===63||l===1&&u.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(i.substring(o-1))){l=27,o++;continue}break;case 44:g=o++,s=pu;continue;case 45:u=Os(i.substring(c,o));break;case 46:u=i.substring(c,o),o++;break;case 47:u=Os(i.substring(c,o)),o++;break;case 48:g=o,o+=2,s=db;continue;case 49:g=o,o+=2,s=pb;continue;case 50:o++,l=25;break;case 51:o++,l=26;break;case 52:if(u=i.substring(c,o),l==1){if(o++,u.toLowerCase()=="url"){s=Df;continue}l=6}break;case 53:if(u=Os(i.substring(c,o)),l==1){if(o++,u.toLowerCase()=="url"){s=Df;continue}l=6}break;case 54:s=sb,o++;continue;case 55:s=ib,o++;continue;case 56:s=Rn,o++;continue;case 57:s=ob,o++,i[o]!==">"&&(l=1,s=mn);continue;case 81:l=51,u=i.substring(c,++o),s=Rn;break;case 82:l=52,u=i.substring(c,++o),s=Rn;break;case 58:l=5,s=fu,o++;continue;case 59:l=4,s=gu,o++;continue;case 60:l=1,s=mn,o++;continue;case 61:l=1,s=pu,g=o++;continue;case 62:o--;break;case 63:o-=2;break;case 64:c=o++,s=hb;continue;case 65:c=++o,s=fb;continue;case 66:c=++o,s=gb;continue;case 67:l=8,u=Os(i.substring(c,o)),o++;break;case 69:o++;break;case 70:s=ab,o++;continue;case 71:s=lb,o++;continue;case 79:if(o-g<8&&i.substring(g+1,o+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){o++;continue}case 68:l=8,u=Os(i.substring(c,o)),o++,s=mb;continue;case 74:if(o++,o-g<9&&i.substring(g+1,o).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;l=54,u="E_CSS_UNEXPECTED_NEWLINE",s=Rn;break;case 73:if(o-g<9&&i.substring(g+1,o+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){o++,s=mn;continue}u=Os(i.substring(c,o));break;case 75:g=o++;continue;case 76:o++,s=_f;continue;default:if(s!==Rn){l=54,u="E_CSS_UNEXPECTED_STATE";break}c=o,l=0}if(f.type=l,f.precededBySpace=h,f.num=d,f.text=u,f.position=c,t++,t>=e)break;s=Rn,h=!1,f=a[t&n]}this.position=o,this.tail=t&n}};var Le=null,mu=null;function xo(){return Le}function A(r){if(!Le)throw new Error("E_TASK_NO_CONTEXT");Le.name||(Le.name=r);let t=Le,e=new Pi(t,t.top,r);return t.top=e,e.state=1,e}function bb(r){return new bu(r||new Cu)}function T(r){return new yo(r)}function In(r,t,e){let n=A(r);n.handler=e;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function Uf(r,t){return(Le?Le.getScheduler():mu||bb()).run(r,t)}var Cu=class{currentTime(){return new Date().valueOf()}setTimeout(t,e){return setTimeout(t,e)}clearTimeout(t){clearTimeout(t)}},bu=class{constructor(t){this.timer=t;p(this,"timeout",1);p(this,"slice",25);p(this,"sliceOverTime",0);p(this,"queue");p(this,"wakeupTime",null);p(this,"timeoutToken",null);p(this,"inTimeSlice",!1);p(this,"order",0);this.queue=new Ur,mu||(mu=this)}setSlice(t){this.slice=t}setTimeout(t){this.timeout=t}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,n=this.timer.currentTime();if(this.timeoutToken!=null){if(n+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let s=e-n;s<=this.timeout&&(s=this.timeout),this.wakeupTime=n+s,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},s)}schedule(t,e){let n=t,s=this.timer.currentTime();n.order=this.order++,n.scheduledTime=s+(e||0),this.queue.add(n),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let t=this.timer.currentTime();for(this.sliceOverTime=t+this.slice;this.queue.length();){let e=this.queue.peek();if(e.scheduledTime>t||(this.queue.remove(),e.canceled||e.resumeInternal(),t=this.timer.currentTime(),t>=this.sliceOverTime))break}}catch(t){F.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let n=new yu(this,e||"");n.top=new Pi(n,null,"bootstrap"),n.top.state=1,n.top.then(()=>{let i=()=>{n.running=!1;for(let o of n.callbacks)try{o()}catch(a){F.error(a)}};try{t().then(o=>{n.result=o,i()})}catch(o){n.raise(o),i()}});let s=Le;return Le=n,this.schedule(n.top.suspend("bootstrap")),Le=s,n}},Ca=class{constructor(t){this.task=t;p(this,"scheduledTime",0);p(this,"order",0);p(this,"result",null);p(this,"canceled",!1)}compare(t){let e=t;return e.scheduledTime-this.scheduledTime||e.order-this.order}getTask(){return this.task}schedule(t,e){this.result=t,this.task.scheduler.schedule(this,e)}resumeInternal(){let t=this.task;if(this.task=null,t&&t.continuation==this){t.continuation=null;let e=Le;return Le=t,t.top.finish(this.result),Le=e,!0}return!1}cancel(){this.canceled=!0}},yu=class{constructor(t,e){this.scheduler=t;this.name=e;p(this,"callbacks",[]);p(this,"exception",null);p(this,"running",!0);p(this,"result",null);p(this,"waitTarget",null);p(this,"top",null);p(this,"continuation",null)}getName(){return this.name}interrupt(t){if(this.raise(t||new Error("E_TASK_INTERRUPT")),this!==Le&&this.continuation){this.continuation.cancel();let e=new Ca(this);this.waitTarget="interrupt",this.continuation=e,this.scheduler.schedule(e)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(t){this.callbacks.push(t)}join(){let t=A("Task.join");if(!this.running)t.finish(this.result);else{let e=t.suspend(this);this.whenDone(()=>{e.schedule(this.result)})}return t.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let t=this.exception;this.exception=null,this.top.handler(this.top,t)}else this.exception&&F.error(this.exception,"Unhandled exception in task",this.name)}raise(t,e){if(this.fillStack(t),e){let n=this.top;for(;n&&n!=e;)n=n.parent;n==e&&(this.top=n)}this.exception=t,this.unwind()}fillStack(t){let e=t.frameTrace;if(!e){e=t.stack?`${t.stack}
3
+ `]).concat(e))),n}var F=new Kc;var It=(u=>(u.SIMPLE_PROPERTY="SIMPLE_PROPERTY",u.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",u.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",u.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",u.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",u.CONFIGURATION="CONFIGURATION",u.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",u.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",u.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",u.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",u))(It||{}),sa={};function Ke(o,t,e){if(!It[o])F.warn(new Error(`Skipping unknown plugin hook '${o}'.`));else{let n=sa[o];n||(n=sa[o]=[]),e?n.unshift(t):n.push(t)}}function Af(o,t){if(!It[o])F.warn(new Error(`Ignoring unknown plugin hook '${o}'.`));else{let e=sa[o];if(e){let n=e.indexOf(t);n>=0&&e.splice(n,1)}}}function Ze(o){return sa[o]||[]}var ZC={registerHook:Ke,removeHook:Af};var ia=class{constructor(t){this.performanceInstance=t;p(this,"timestamps",{});p(this,"registerTiming");p(this,"registerStartTiming");p(this,"registerEndTiming");this.registerTiming=Ei,this.registerStartTiming=this.registerStartTiming=Ei,this.registerEndTiming=this.registerEndTiming=Ei}forceRegisterStartTiming(t,e){Zc.call(this,t,"start",e)}forceRegisterEndTiming(t,e){Zc.call(this,t,"end",e)}printTimings(){let t=this.timestamps,e="";Object.keys(t).forEach(n=>{let s=t[n],i=s.length;for(let r=0;r<i;r++){let a=s[r];e+=n,i>1&&(e+=`(${r})`),e+=` => start: ${a.start}, end: ${a.end}, duration: ${a.end-a.start}
4
+ `}}),F.info(e)}disable(){this.registerTiming=Ei,this.registerStartTiming=this.registerStartTiming=Ei,this.registerEndTiming=this.registerEndTiming=Ei}enable(){this.registerTiming=Zc,this.registerStartTiming=this.registerStartTiming=Lf,this.registerEndTiming=this.registerEndTiming=QC}isEnabled(){return this.registerStartTiming===Lf}};function Ei(){}function Zc(o,t,e){e||(e=this.performanceInstance.now());let n=this.timestamps[o];n||(n=this.timestamps[o]=[]);let s,i=n.length;for(let r=i-1;r>=0&&(s=n[r],!(s&&!s[t]));r--)s=null;s||(s={},n.push(s)),s[t]=e}function Lf(o,t){this.registerTiming(o,"start",t)}function QC(o,t){this.registerTiming(o,"end",t)}var JC={now:Date.now},eb=window&&window.performance,nt=new ia(eb||JC);nt.forceRegisterStartTiming("load_vivliostyle");var tb={profiler:{registerStartTiming:nt.registerStartTiming,registerEndTiming:nt.registerEndTiming,printTimings:nt.printTimings,disable:nt.disable,enable:nt.enable}};var oa=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",_s=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Qt="data-adapt-eloff",If={};function Ni(o){return JSON.parse(o)}function Xt(o){let t=o.match(/^([^#]*)/);return t?t[1]:o}function nb(o){let t=o.match(/^([^#?]*)/);return t?t[1]:o}var In=window.location.href;function Qc(o){In=o}var Jt=window.location.href;function Jc(o){Jt=o}function te(o,t){if(/^data:/i.test(t))return o||t;if(!t||o.match(/^\w{2,}:/))return o.toLowerCase().match("^javascript:")?"#":(o.match(/^\w{2,}:\/\/[^\/]+$/)&&(o=`${o}/`),o);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let e;if(o.match(/^\/\//))return e=t.match(/^(\w{2,}:)\/\//),e?e[1]+o:o;if(o.match(/^\//))return e=t.match(/^(\w{2,}:\/\/[^\/]+)\//),e?e[1]+o:o;if(o.match(/^\.(\/|$)/)&&(o=o.substr(2)),t=nb(t),o.match(/^#/))return t+o;let n=t.lastIndexOf("/");if(n<0)return o;let s=t.substr(0,n+1)+o,i="";for(e=s.match(/^([^?#]*)([?#].*)$/),e&&(s=e[1],i=e[2]);n=s.indexOf("/../"),!(n<=0);){let r=s.lastIndexOf("/",n-1);if(r<=0)break;s=s.substr(0,r)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+i}function ns(o){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(o))?o=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(o))?o=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(o))?o=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(o))?o=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(o))&&(o=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),o}function eu(o){return o==null?o:o.toString()}var ra=class{constructor(){p(this,"queue",[null])}length(){return this.queue.length-1}add(t){let e=this.queue.length;for(;e>1;){let n=Math.floor(e/2),s=this.queue[n];if(s.compare(t)>0){this.queue[e]=t;return}this.queue[e]=s,e=n}this.queue[1]=t}peek(){return this.queue[1]}remove(){let t=this.queue[1],e=this.queue.pop(),n=this.queue.length;if(n>1){let s=1;for(;;){let i=s*2;if(i>=n)break;if(this.queue[i].compare(e)>0)i+1<n&&this.queue[i+1].compare(this.queue[i])>0&&i++;else if(i+1<n&&this.queue[i+1].compare(e)>0)i++;else break;this.queue[s]=this.queue[i],s=i}this.queue[s]=e}return t}},tu=["","-webkit-","-moz-"],vi={};function Sr(o,t){return CSS.supports(o+t,"unset")}function sb(o){let t=vi[o];if(t||t===null)return t;switch(o){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return vi[o]=null,null;case"text-combine-upright":if(Sr("-webkit-","text-combine")&&!Sr("","text-combine-upright"))return vi[o]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let e of tu)if(Sr(e,o))return t=[e+o],vi[o]=t,t;return F.warn("Property not supported by the browser: ",o),vi[o]=null,null}function w(o,t,e){let n=o==null?void 0:o.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,e||" ");return}let s=sb(t);if(s)for(let i of s){switch(i){case"-webkit-text-combine":switch(e){case"all":e="horizontal";break}break;case"text-combine-upright":switch(e){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(i,e)}}function en(o,t,e){try{let n=vi[t];return o.style.getPropertyValue(n?n[0]:t)}catch(n){}return e||""}function Er(o){let t=o.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&o.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=o.getAttribute("lang")),t}var st=class{constructor(){p(this,"list",[])}append(t){return this.list.push(t),this}clear(){this.list=[]}toString(){let t=this.list.join("");return this.list=[t],t}};function Vf(o){return`\\${o.charCodeAt(0).toString(16)} `}function fn(o){return o.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Vf)}function Us(o){return o.replace(/[\u0000-\u001F"\\]/g,Vf)}function nu(o){return o.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function su(o){return!!o.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function ib(o,t){return t=typeof t=="string"?t:"\\u",t+(65536|o.charCodeAt(0)).toString(16).substr(1)}function iu(o,t){function e(n){return ib(n,t)}return o.replace(/[^-a-zA-Z0-9_]/g,e)}function Vn(o){return iu(o)}function rb(o,t){return t=typeof t=="string"?t:"\\u",o.indexOf(t)===0?String.fromCharCode(parseInt(o.substring(t.length),16)):o}function Ff(o,t){t=typeof t=="string"?t:"\\u";function e(s){return rb(s,t)}let n=new RegExp(`${Vn(t)}[0-9a-fA-F]{4}`,"g");return o.replace(n,e)}function Vt(o,t){let e=0,n=o;for(;;){if(e<=n,e==0||t(e-1),n==o||t(n),e==n)return e;let s=e+n>>1;t(s)?n=s:e=s+1}}function aa(o,t){return o-t}function ru(o,t){let e={};for(let n of o){let s=t(n);s&&!e[s]&&(e[s]=n)}return e}function Bf(o){let t={};for(let e=0;e<o.length;e++)t[o[e]]=!0;return t}function la(o,t){let e={};for(let n of o){let s=t(n);s&&(e[s]?e[s].push(n):e[s]=[n])}return e}function Of(o,t){let e={};for(let n in o)e[n]=t(o[n],n);return e}var ts=class{constructor(){p(this,"listeners",{})}dispatchEvent(t){let e=this.listeners[t.type];if(e){t.target=this,t.currentTarget=this;for(let n=0;n<e.length;n++)e[n](t)}}addEventListener(t,e,n){if(n)return;let s=this.listeners[t];s?s.includes(e)||s.push(e):this.listeners[t]=[e]}removeEventListener(t,e,n){if(n)return;let s=this.listeners[t];if(s){let i=s.indexOf(e);i>=0&&s.splice(i,1)}}},gn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function _f(o){if(o.nodeType==1){let t=o.getAttribute("id");if(t)return t}return null}function ob(o){return`^${o}`}function Df(o){return o.replace(/[\[\]\(\),=;^]/g,ob)}function ab(o){return o.substr(1)}function ou(o){return o&&o.replace(/\^[\[\]\(\),=;^]/g,ab)}function lb(o){let t=[];do{let e=o.match(/^(\^,|[^,])*/),n=ou(e[0]);if(o=o.substr(e[0].length+1),!o&&!t.length)return n;t.push(n)}while(o);return t}function Mf(o){let t={};for(;o;){let e=o.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!e)return t;t[e[1]]=lb(e[2]),o=o.substr(e[0].length)}return t}var ca=class{appendTo(t){t.append("!")}applyTo(t){return!1}},ua=class{constructor(t,e,n){this.index=t;this.id=e;this.sideBias=n}appendTo(t){t.append("/"),t.append(this.index.toString()),(this.id||this.sideBias)&&(t.append("["),this.id&&t.append(this.id),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}applyTo(t){if(t.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let e=t.node,n=e.children,s=n.length,i,r=Math.floor(this.index/2)-1;if(r<0||s==0)i=e.firstChild,t.node=i||e;else{if(i=n[Math.min(r,s-1)],this.index&1){let a=i.nextSibling;!a||a.nodeType==1?t.after=!0:i=a}t.node=i}if(this.id&&(t.after||this.id!=_f(t.node))){let a=e.ownerDocument.getElementById(this.id);a?t.node=a:F.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},da=class{constructor(t,e,n,s){this.offset=t;this.textBefore=e;this.textAfter=n;this.sideBias=s}applyTo(t){if(this.offset>0&&!t.after){let e=this.offset,n=t.node;for(;;){let s=n.nodeType;if(s==1)break;let i=n.nextSibling;if(3<=s&&s<=5){let r=n.textContent.length;if(e<=r)break;if(!i){e=r;break}e-=r}if(!i){e=0;break}n=i}t.node=n,t.offset=e}return t.sideBias=this.sideBias,!0}appendTo(t){t.append(":"),t.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(t.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&t.append(Df(this.textBefore)),t.append(","),this.textAfter&&t.append(Df(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},vr=class o{constructor(){p(this,"steps",null)}fromString(t){let e=t.match(/^#?epubcfi\((.*)\)$/);if(!e)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(e[1]),s=0,i=[];for(;;){let r;switch(n.charAt(s)){case"/":{if(s++,e=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!e)throw new Error("E_CFI_NUMBER_EXPECTED");s+=e[0].length;let a=parseInt(e[1],10),l=e[3];r=Mf(e[4]),i.push(new ua(a,l,eu(r.s)));break}case":":{if(s++,e=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!e)throw new Error("E_CFI_NUMBER_EXPECTED");s+=e[0].length;let a=parseInt(e[1],10),l=e[4];l&&(l=ou(l));let c=e[7];c&&(c=ou(c)),r=Mf(e[10]),i.push(new da(a,l,c,eu(r.s)));break}case"!":s++,i.push(new ca);break;case"~":case"@":case"":this.steps=i;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let e={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(e)){e.ref=new o,e.ref.steps=this.steps.slice(n+1);break}return e}trim(t,e){return t.replace(/\s+/g," ").match(e?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,e,n,s){let i=[],r=t.parentNode,a="",l="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let c=t.textContent,u=c.length;n?(e+=u,a||(a=c)):(e>u&&(e=u),n=!0,a=c.substr(0,e),l=c.substr(e)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((e>0||a||l)&&(a=this.trim(a,!1),l=this.trim(l,!0),i.push(new da(e,a,l,s)),s=null);r&&!(!r||r.nodeType==9);){let c=n?null:_f(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;i.push(new ua(u,c,s)),s=null,t=r,r=r.parentNode,n=!1}i.reverse(),this.steps?(i.push(new ca),this.steps=i.concat(this.steps)):this.steps=i}toString(){if(!this.steps)return"";let t=new st;t.append("epubcfi(");for(let e=0;e<this.steps.length;e++)this.steps[e].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function lu(){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 Ta(o){return{fontFamily:o.fontFamily,lineHeight:o.lineHeight,margin:o.margin,hyphenate:o.hyphenate,columnWidth:o.columnWidth,horizontal:o.horizontal,nightMode:o.nightMode,spreadView:o.spreadView,pageBorder:o.pageBorder,enabledMediaTypes:Object.assign({},o.enabledMediaTypes),defaultPaperSize:o.defaultPaperSize?Object.assign({},o.defaultPaperSize):void 0}}var ub=lu(),Uf={PENDING:{}};function cu(o,t,e,n){let s=Math.min((o-0)/e,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function au(o){return`"${Us(`${o}`)}"`}function db(o){return fn(`${o}`)}function Lr(o,t){return o?`${fn(o)}.${fn(t)}`:fn(t)}var Hf=0,Hs=class{constructor(t,e){this.parent=t;this.resolver=e;p(this,"scopeKey");p(this,"children",[]);p(this,"zero");p(this,"one");p(this,"_true");p(this,"_false");p(this,"values",{});p(this,"funcs",{});p(this,"builtIns",{});if(this.scopeKey=`S${Hf++}`,this.zero=new he(this,0),this.one=new he(this,1),this._true=new he(this,!0),this._false=new he(this,!1),t&&t.children.push(this),!t){let n=this.builtIns;n.floor=Math.floor,n.ceil=Math.ceil,n.round=Math.round,n.sqrt=Math.sqrt,n.min=Math.min,n.max=Math.max,n.letterbox=cu,n["css-string"]=au,n["css-name"]=db,n.typeof=s=>typeof s,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 au(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return au(this.docTitle?this.docTitle:"")})}}defineBuiltInName(t,e){this.values[t]=new ne(this,e,t)}defineName(t,e){this.values[t]=e}defineFunc(t,e){this.funcs[t]=e}defineBuiltIn(t,e){this.builtIns[t]=e}};function zf(o){switch(o==null?void 0:o.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function uu(o){switch(o==null?void 0:o.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 Gf(o){switch(o==null?void 0:o.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Wf(o){switch(o==null?void 0:o.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Je={px:1,in:96,pt:4/3,pc:96/6,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,lh:20,rlh:20,dppx:1,dpi:1/96,dpcm:2.54/96};function wa(o){switch(o){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 Ti=class{constructor(t,e,n,s){this.rootScope=t;this.viewportWidth=e;this.viewportHeight=n;p(this,"actualPageWidth",null);p(this,"pageWidth");p(this,"actualPageHeight",null);p(this,"pageHeight");p(this,"initialFontSize");p(this,"rootFontSize",null);p(this,"isRelativeRootFontSize",null);p(this,"fontSize");p(this,"rootLineHeight",null);p(this,"pref");p(this,"scopes",{});p(this,"pageAreaWidth",null);p(this,"pageAreaHeight",null);p(this,"pageVertical",null);p(this,"pubTitle",null);p(this,"docTitle",null);this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(e/2)-this.pref.pageBorder:e},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:n},this.initialFontSize=s,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:s},this.pref=ub}getScopeContext(t){let e=this.scopes[t.scopeKey];return e||(e={},this.scopes[t.scopeKey]=e),e}clearScope(t){this.scopes[t.scopeKey]={};for(let e=0;e<t.children.length;e++)this.clearScope(t.children[e])}queryUnitSize(t,e,n){if(uu(t)){let s=this.pageWidth()/100,i=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:s,a=this.pageAreaHeight!=null?this.pageAreaHeight/100:i,l=n!=null?n:this.pageVertical;switch(t){case"vw":return r;case"vh":return a;case"vi":return l?a:r;case"vb":return l?r:a;case"vmin":return r<a?r:a;case"vmax":return r>a?r:a;case"pvw":return s;case"pvh":return i;case"pvi":return l?i:s;case"pvb":return l?s:i;case"pvmin":return s<i?s:i;case"pvmax":return s>i?s:i}}return t=="em"||t=="rem"?e?this.initialFontSize:this.fontSize():t=="lh"||t=="rlh"?this.rootLineHeight:Je[t]}evalName(t,e){do{let n=t.values[e];if(n||t.resolver&&(n=t.resolver.call(this,e,!1),n))return n;t=t.parent}while(t);throw new Error(`Name '${e}' is undefined`)}evalCall(t,e,n,s){do{let i=t.funcs[e];if(i||t.resolver&&(i=t.resolver.call(this,e,!0),i))return i;let r=t.builtIns[e];if(r){if(s)return t.zero;let a=Array(n.length);for(let l=0;l<n.length;l++)a[l]=n[l].evaluate(this);return new he(t,r.apply(this,a))}t=t.parent}while(t);throw new Error(`Function '${e}' is undefined`)}evalMediaName(t,e){let n=t==="all"||!!this.pref.enabledMediaTypes[t];return e?!n:n}evalMediaTest(t,e){let n="",s=t.match(/^(min|max)-(.*)$/);s&&(n=s[1],t=s[2]);let i=null,r=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(i=e.evaluate(this));break}switch(t){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&&i!=null)switch(n){case"min":return r>=Number(i);case"max":return r<=Number(i);default:return r==i}else if(r!=null&&e==null)return r!==0;return!1}evalSupportsTest(t,e,n){return!1}queryVal(t,e){let n=t&&this.scopes[t.scopeKey];return n?n[e]:void 0}storeVal(t,e,n){this.getScopeContext(t)[e]=n}},St=class{constructor(t){this.scope=t;p(this,"key");this.scope=t,this.key=`_${Hf++}`}toString(){let t=new st;return this.appendTo(t,0),t.toString()}appendTo(t,e){throw new Error("F_ABSTRACT")}evaluateCore(t){throw new Error("F_ABSTRACT")}expand(t,e){return this}dependCore(t,e,n){return t===this}dependOuter(t,e,n){let s=n[this.key];if(s!=null)return s===Uf.PENDING?!1:s;{n[this.key]=Uf.PENDING;let i=this.dependCore(t,e,n);return n[this.key]=i,i}}depend(t,e){return this.dependOuter(t,e,{})}evaluate(t){let e=t.queryVal(this.scope,this.key);return typeof e!="undefined"||(e=this.evaluateCore(t),this.scope&&t.storeVal(this.scope,this.key,e)),e}isMediaName(){return!1}},pa=class extends St{constructor(e,n){super(e);this.val=n}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let n=this.val.evaluate(e);return this.evalPrefix(n)}dependCore(e,n,s){return e===this||this.val.dependOuter(e,n,s)}appendTo(e,n){10<n&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<n&&e.append(")")}expand(e,n){let s=this.val.expand(e,n);return s===this.val?this:new this.constructor(this.scope,s)}},wi=class extends St{constructor(e,n,s){super(e);this.lhs=n;this.rhs=s}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,n){throw new Error("F_ABSTRACT")}evaluateCore(e){let n=this.lhs.evaluate(e),s=this.rhs.evaluate(e);return this.evalInfix(n,s)}dependCore(e,n,s){return e===this||this.lhs.dependOuter(e,n,s)||this.rhs.dependOuter(e,n,s)}appendTo(e,n){let s=this.getPriority();s<=n&&e.append("("),this.lhs.appendTo(e,s),e.append(this.getOp()),this.rhs.appendTo(e,s),s<=n&&e.append(")")}expand(e,n){let s=this.lhs.expand(e,n),i=this.rhs.expand(e,n);return s===this.lhs&&i===this.rhs?this:new this.constructor(this.scope,s,i)}},ha=class extends wi{constructor(t,e,n){super(t,e,n)}getPriority(){return 1}},ss=class extends wi{constructor(t,e,n){super(t,e,n)}getPriority(){return 2}},fa=class extends wi{constructor(t,e,n){super(t,e,n)}getPriority(){return 3}},Nr=class extends wi{constructor(t,e,n){super(t,e,n)}getPriority(){return 4}},Ft=class extends pa{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},ga=class extends Ft{constructor(t,e){super(t,e)}getOp(){return"not "}},mn=class extends pa{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},Pi=class extends ha{constructor(t,e,n){super(t,e,n)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},ma=class extends Pi{constructor(t,e,n){super(t,e,n)}getOp(){return" and "}},ki=class extends ha{constructor(t,e,n){super(t,e,n)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},Ca=class extends ki{constructor(t,e,n){super(t,e,n)}getOp(){return", "}},ba=class extends ki{constructor(t,e,n){super(t,e,n)}getOp(){return" or "}},ya=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return"<"}evalInfix(t,e){return t<e}},xa=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return"<="}evalInfix(t,e){return t<=e}},Sa=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return">"}evalInfix(t,e){return t>e}},zs=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return">="}evalInfix(t,e){return t>=e}},is=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return"=="}evalInfix(t,e){return t==e}},Ea=class extends ss{constructor(t,e,n){super(t,e,n)}getOp(){return"!="}evalInfix(t,e){return t!=e}},Tr=class extends fa{constructor(t,e,n){super(t,e,n)}getOp(){return"+"}evalInfix(t,e){return t+e}},wr=class extends fa{constructor(t,e,n){super(t,e,n)}getOp(){return" - "}evalInfix(t,e){return t-e}},Gs=class extends Nr{constructor(t,e,n){super(t,e,n)}getOp(){return"*"}evalInfix(t,e){return t*e}},Pr=class extends Nr{constructor(t,e,n){super(t,e,n)}getOp(){return"/"}evalInfix(t,e){return t/e}},Ai=class extends Nr{constructor(t,e,n){super(t,e,n)}getOp(){return"%"}evalInfix(t,e){return t%e}},tn=class extends St{constructor(e,n,s){var i;super(e);this.num=n;p(this,"unit");this.unit=(i=s==null?void 0:s.toLowerCase())!=null?i:""}appendTo(e,n){e.append(this.num.toString()),e.append(fn(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},re=class extends St{constructor(e,n){super(e);this.qualifiedName=n}appendTo(e,n){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,n,s){return e===this||n.evalName(this.scope,this.qualifiedName).dependOuter(e,n,s)}},kr=class extends St{constructor(e,n,s){super(e);this.not=n;this.name=s}appendTo(e,n){this.not&&e.append("not "),e.append(fn(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},ne=class extends St{constructor(e,n,s){super(e);this.fn=n;this.str=s}appendTo(e,n){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function pb(o,t){o.append("(");for(let e=0;e<t.length;e++)e&&o.append(","),t[e].appendTo(o,0);o.append(")")}function hb(o,t,e){let n=t;for(let s=0;s<t.length;s++){let i=t[s].expand(o,e);if(t!==n)n[s]=i;else if(i!==t[s]){n=Array(t.length);for(let r=0;r<s;r++)n[r]=t[r];n[s]=i}}return n}var Fn=class o extends St{constructor(e,n,s){super(e);this.qualifiedName=n;this.params=s}appendTo(e,n){e.append(this.qualifiedName),pb(e,this.params)}evaluateCore(e){return e.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(e,this.params).evaluate(e)}dependCore(e,n,s){if(e===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(e,n,s))return!0;return n.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(e,n,s)}expand(e,n){let s=hb(e,this.params,n);return s===this.params?this:new o(this.scope,this.qualifiedName,s)}},va=class o extends St{constructor(e,n,s,i){super(e);this.cond=n;this.ifTrue=s;this.ifFalse=i}appendTo(e,n){n>0&&e.append("("),this.cond.appendTo(e,0),e.append("?"),this.ifTrue.appendTo(e,0),e.append(":"),this.ifFalse.appendTo(e,0),n>0&&e.append(")")}evaluateCore(e){return this.cond.evaluate(e)?this.ifTrue.evaluate(e):this.ifFalse.evaluate(e)}dependCore(e,n,s){return e===this||this.cond.dependOuter(e,n,s)||this.ifTrue.dependOuter(e,n,s)||this.ifFalse.dependOuter(e,n,s)}expand(e,n){let s=this.cond.expand(e,n),i=this.ifTrue.expand(e,n),r=this.ifFalse.expand(e,n);return s===this.cond&&i===this.ifTrue&&r===this.ifFalse?this:new o(this.scope,s,i,r)}},he=class extends St{constructor(e,n){super(e);this.val=n}appendTo(e,n){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(Us(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Ar=class o extends St{constructor(e,n,s){super(e);this.name=n;this.value=s}appendTo(e,n){e.append("("),e.append(Us(this.name.name)),e.append(":"),this.value.appendTo(e,0),e.append(")")}evaluateCore(e){return e.evalMediaTest(this.name.name,this.value)}dependCore(e,n,s){return e===this||this.value.dependOuter(e,n,s)}expand(e,n){let s=this.value.expand(e,n);return s===this.value?this:new o(this.scope,this.name,s)}},Na=class extends St{constructor(e,n,s,i){super(e);this.name=n;this.value=s;this.isFunc=i}appendTo(e,n){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)}},Li=class extends St{constructor(e,n){super(e);this.index=n}appendTo(e,n){e.append("$"),e.append(this.index.toString())}expand(e,n){let s=n[this.index];if(!s)throw new Error(`Parameter missing: ${this.index}`);return s}};function ut(o,t,e){return t===o._false||t===o.zero||e==o._false||e==o.zero?o._false:t===o._true||t===o.one?e:e===o._true||e===o.one?t:new Pi(o,t,e)}function $(o,t,e){return t===o.zero?e:e===o.zero?t:new Tr(o,t,e)}function ee(o,t,e){return t===o.zero?new mn(o,e):e===o.zero?t:new wr(o,t,e)}function Ri(o,t,e){return t===o.zero||e===o.zero?o.zero:t===o.one?e:e===o.one?t:new Gs(o,t,e)}function Rr(o,t,e){return t===o.zero?o.zero:e===o.one?t:new Pr(o,t,e)}var Et=class{visitValues(t){for(let e=0;e<t.length;e++)t[e].visit(this);return null}visitEmpty(t){return null}visitSlash(t){return null}visitStr(t){return null}visitIdent(t){return null}visitNumeric(t){return null}visitNum(t){return null}visitInt(t){return this.visitNum(t)}visitHexColor(t){return null}visitURL(t){return null}visitURange(t){return null}visitSpaceList(t){return this.visitValues(t.values),null}visitCommaList(t){return this.visitValues(t.values),null}visitFunc(t){return this.visitValues(t.values),null}visitExpr(t){return null}},$t=class extends Et{constructor(){super();p(this,"error",!1)}visitValues(e){let n=null;for(let s=0;s<e.length;s++){let i=e[s],r=i.visit(this);if(this.error)return[];if(n)n[s]=r;else if(i!==r){n=new Array(e.length);for(let a=0;a<s;a++)n[a]=e[a];n[s]=r}}return n||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 n=this.visitValues(e.values);return this.error?H:n===e.values?e:new G(n)}visitCommaList(e){let n=this.visitValues(e.values);return this.error?H:n===e.values?e:new me(n)}visitFunc(e){let n=this.visitValues(e.values);return this.error?H:n===e.values?e:new vt(e.name,n)}visitExpr(e){return e}},Le=class{toString(){let t=new st;return this.appendTo(t,!0),t.toString()}stringValue(){let t=new st;return this.appendTo(t,!1),t.toString()}toExpr(t,e){return null}appendTo(t,e){t.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(t){return this}},Pa=class Pa extends Le{static get instance(){return this.empty||(this.empty=new Pa),this.empty}constructor(){super()}toExpr(t,e){return new he(t,"")}appendTo(t,e){}visit(t){return t.visitEmpty(this)}};p(Pa,"empty");var du=Pa,H=du.instance,ka=class ka extends Le{static get instance(){return this.slash||(this.slash=new ka),this.slash}constructor(){super()}toExpr(t,e){return new he(t,"/")}appendTo(t,e){t.append("/")}visit(t){return t.visitSlash(this)}};p(ka,"slash");var pu=ka,Bn=pu.instance,M=class extends Le{constructor(e){super();this.str=e}toExpr(e,n){return new he(e,this.str)}appendTo(e,n){n?(e.append('"'),e.append(Us(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},hu={},Y=class extends Le{constructor(e){super();this.name=e;if(hu[e])throw new Error("E_INVALID_CALL");hu[e]=this}toExpr(e,n){return new he(e,this.name)}appendTo(e,n){n?e.append(fn(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function k(o){let t=hu[o];return t||(t=new Y(o)),t}var P=class extends Le{constructor(e,n){var s;super();this.num=e;p(this,"unit");this.unit=(s=n==null?void 0:n.toLowerCase())!=null?s:""}toExpr(e,n){return this.num==0?e.zero:n&&this.unit=="%"?this.num==100?n:new Gs(e,n,new he(e,this.num/100)):new tn(e,this.num,this.unit)}appendTo(e,n){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},Re=class extends Le{constructor(e){super();this.num=e}toExpr(e,n){return this.num==0?e.zero:this.num==1?e.one:new he(e,this.num)}appendTo(e,n){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},se=class extends Re{constructor(t){super(t)}visit(t){return t.visitInt(this)}},Ii=class extends Le{constructor(e){super();this.hex=e}appendTo(e,n){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ge=class extends Le{constructor(e){super();this.url=e}appendTo(e,n){e.append('url("'),e.append(Us(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Ir=class extends Le{constructor(e){super();this.urangeText=e}appendTo(e,n){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function fu(o,t,e,n){var i,r;let s=t.length;if(s>0){(i=t[0])==null||i.appendTo(o,n);for(let a=1;a<s;a++)o.append(e),(r=t[a])==null||r.appendTo(o,n)}}var G=class extends Le{constructor(e){super();this.values=e}appendTo(e,n){fu(e,this.values," ",n)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},me=class extends Le{constructor(e){super();this.values=e}appendTo(e,n){fu(e,this.values,",",n)}visit(e){return e.visitCommaList(this)}},vt=class extends Le{constructor(e,n){super();this.name=e;this.values=n}appendTo(e,n){e.append(fn(this.name)),e.append("("),fu(e,this.values,",",n),e.append(")")}visit(e){return e.visitFunc(this)}},D=class extends Le{constructor(e){super();this.expr=e}toExpr(){return this.expr}appendTo(e,n){this.expr instanceof he||this.expr instanceof tn?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}},Cn=class extends Le{constructor(e){super();this.text=e}appendTo(e,n){e.append(this.text||" ")}};function Me(o,t){if(o){if(o.isNumeric()){let e=o;return t.queryUnitSize(e.unit,!1)*e.num}if(o.isNum())return o.num}return 0}function Aa(o,t){return new P(Me(o,t),"px")}var b={absolute:k("absolute"),all:k("all"),always:k("always"),anywhere:k("anywhere"),auto:k("auto"),avoid:k("avoid"),balance:k("balance"),balance_all:k("balance-all"),block:k("block"),block_end:k("block-end"),block_start:k("block-start"),both:k("both"),bottom:k("bottom"),border_box:k("border-box"),break_all:k("break-all"),break_word:k("break-word"),clip:k("clip"),crop:k("crop"),cross:k("cross"),column:k("column"),discard:k("discard"),exclusive:k("exclusive"),_false:k("false"),fixed:k("fixed"),flex:k("flex"),flow_root:k("flow-root"),footnote:k("footnote"),footer:k("footer"),grid:k("grid"),header:k("header"),hidden:k("hidden"),horizontal_tb:k("horizontal-tb"),inherit:k("inherit"),initial:k("initial"),inline:k("inline"),inline_block:k("inline-block"),inline_end:k("inline-end"),inline_start:k("inline-start"),inside:k("inside"),keep:k("keep"),landscape:k("landscape"),left:k("left"),line:k("line"),list_item:k("list-item"),ltr:k("ltr"),manual:k("manual"),max_content:k("max-content"),min_content:k("min-content"),none:k("none"),normal:k("normal"),oeb_page_foot:k("oeb-page-foot"),oeb_page_head:k("oeb-page-head"),outside:k("outside"),padding_box:k("padding-box"),page:k("page"),relative:k("relative"),revert:k("revert"),right:k("right"),same:k("same"),scale:k("scale"),snap_block:k("snap-block"),snap_inline:k("snap-inline"),solid:k("solid"),spread:k("spread"),_static:k("static"),rtl:k("rtl"),table:k("table"),table_caption:k("table-caption"),table_cell:k("table-cell"),table_footer_group:k("table-footer-group"),table_header_group:k("table-header-group"),table_row:k("table-row"),top:k("top"),transparent:k("transparent"),unset:k("unset"),vertical_lr:k("vertical-lr"),vertical_rl:k("vertical-rl"),visible:k("visible"),_true:k("true")},gu=new P(100,"%"),rs=new P(100,"pvw"),os=new P(100,"pvh"),le=new P(0,"px"),ES=new Ir("U+0-10FFFF"),Xf={"font-size":1,"line-height":2,color:3};function X(o){return o===b.inherit||o===b.initial||o===b.revert||o===b.unset}function mu(o,t){let e=Xf[o]||Number.MAX_VALUE,n=Xf[t]||Number.MAX_VALUE;return e-n}function Nt(o){return(o==null?void 0:o.length)>2&&o.startsWith("--")}var Ws,Xs,$s,nn=class nn{constructor(t,e,n){j(this,Ws);j(this,Xs);j(this,$s);Se(this,Ws,Math.round(Math.max(0,Math.min(t,nn.MAX)))),Se(this,Xs,Math.round(Math.max(0,Math.min(e,nn.MAX)))),Se(this,$s,Math.round(Math.max(0,Math.min(n,nn.MAX))))}static fromInt(t,e,n){return new nn(t,e,n)}offset(t,e,n){return new nn(V(this,Ws)+t,V(this,Xs)+e,V(this,$s)+n)}toKey(){return JSON.stringify([V(this,Ws),V(this,Xs),V(this,$s)])}toColorFunc(t){return new vt("color",[new G([k("srgb"),new Re(V(this,Ws)/nn.MAX),new Re(V(this,Xs)/nn.MAX),new Re(V(this,$s)/nn.MAX),...t!==null?[Bn,new Re(t)]:[]])])}};Ws=new WeakMap,Xs=new WeakMap,$s=new WeakMap,p(nn,"MAX",1e4);var bn=nn,as,ls,cs,sn,et=class et{constructor(t,e,n,s){j(this,as);j(this,ls);j(this,cs);j(this,sn);Se(this,as,Math.round(Math.max(0,Math.min(t,et.MAX)))),Se(this,ls,Math.round(Math.max(0,Math.min(e,et.MAX)))),Se(this,cs,Math.round(Math.max(0,Math.min(n,et.MAX)))),Se(this,sn,Math.round(Math.max(0,Math.min(s,et.MAX))))}static fromInt(t,e,n,s){return new et(t,e,n,s)}static fromNumber(t,e,n,s){return new et(t*et.MAX,e*et.MAX,n*et.MAX,s*et.MAX)}toSRGB(){let t=et.MAX-V(this,sn);return bn.fromInt(bn.MAX-Math.min(bn.MAX,Math.round(V(this,as)*t/et.MAX)+V(this,sn)),bn.MAX-Math.min(bn.MAX,Math.round(V(this,ls)*t/et.MAX)+V(this,sn)),bn.MAX-Math.min(bn.MAX,Math.round(V(this,cs)*t/et.MAX)+V(this,sn)))}equals(t){return V(this,as)===V(t,as)&&V(this,ls)===V(t,ls)&&V(this,cs)===V(t,cs)&&V(this,sn)===V(t,sn)}toJSON(){return{c:V(this,as),m:V(this,ls),y:V(this,cs),k:V(this,sn)}}};as=new WeakMap,ls=new WeakMap,cs=new WeakMap,sn=new WeakMap,p(et,"MAX",1e4);var Cu=et;function Vi(o){return o instanceof Re?Math.max(0,Math.min(1,o.num)):o instanceof P&&o.unit==="%"?Math.max(0,Math.min(1,o.num/100)):null}function bu(o){if(o.name!=="device-cmyk")return null;let t=o.values.length===1&&o.values[0]instanceof G?o.values[0].values:o.values;if(t.length<4||t.length>6)return null;let e=Vi(t[0]),n=Vi(t[1]),s=Vi(t[2]),i=Vi(t[3]);if(e===null||n===null||s===null||i===null)return null;let r=null;if(t.length>=5){if(t[4]===Bn){if(t.length!==6)return null;r=Vi(t[5])}else{if(t.length!==5)return null;r=Vi(t[4])}if(r===null)return null}return{cmyk:Cu.fromNumber(e,n,s,i),alpha:r}}function*fb(o){for(let t=-o;t<=o;t++)for(let e=-o;e<=o;e++)for(let n=-o;n<=o;n++)Math.abs(t)+Math.abs(e)+Math.abs(n)===o&&(yield[t,e,n])}var us,Di,$f,jf,Vr=class{constructor(){j(this,Di);j(this,us,new Map)}registerDeviceCmyk(t){let e=bu(t);return e?ae(this,Di,$f).call(this,e.cmyk).toColorFunc(e.alpha):null}toJSON(){let t={};return V(this,us).forEach((e,n)=>{t[n]=e.toJSON()}),t}};us=new WeakMap,Di=new WeakSet,$f=function(t){let e=t.toSRGB(),n=e.toKey(),s=V(this,us).get(n);return s?s.equals(t)?e:ae(this,Di,jf).call(this,t,e):(V(this,us).set(n,t),e)},jf=function(t,e){for(let n=1;n<=bn.MAX;n++)for(let[s,i,r]of fb(n)){let a=e.offset(s,i,r),l=a.toKey();if(!V(this,us).has(l))return V(this,us).set(l,t),a}return F.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(t.toJSON())}`),e};var Fr,Fi,Bi,Oi=class extends $t{constructor(e){super();j(this,Fr);j(this,Fi,new Map);j(this,Bi,!1);Se(this,Fr,e!=null?e:new Vr)}reset(){Se(this,Bi,!1)}hadDeviceCmyk(){return V(this,Bi)}recordConversion(e,n){V(this,Fi).set(e,n)}getConversions(){if(V(this,Fi).size===0)return null;let e={};return V(this,Fi).forEach((n,s)=>{e[s]=n}),e}visitFunc(e){let n=V(this,Fr).registerDeviceCmyk(e);return n?(Se(this,Bi,!0),n):super.visitFunc(e)}};Fr=new WeakMap,Fi=new WeakMap,Bi=new WeakMap;var qe=class{constructor(t,e,n,s){this.x1=t;this.y1=e;this.x2=n;this.y2=s}},rn=class{constructor(t,e){this.x=t;this.y=e}},_i=class{constructor(t,e,n,s){this.left=t;this.top=e;this.right=n;this.bottom=s}},La=class{constructor(t,e,n,s){this.low=t;this.high=e;this.winding=n;this.shapeId=s}},on=class{constructor(t,e,n,s){this.y1=t;this.y2=e;this.x1=n;this.x2=s;p(this,"left",null);p(this,"right",null)}};function gb(o,t){return o.low.y-t.low.y||o.low.x-t.low.x}var js=class o{constructor(t){this.points=t}addSegments(t,e){let n=this.points,s=n.length,i=n[s-1];for(let r=0;r<s;r++){let a=n[r],l;i.y<a.y?l=new La(i,a,1,e):l=new La(a,i,-1,e),t.push(l),i=a}}withOffset(t,e){let n=[];for(let s of this.points)n.push(new rn(s.x+t,s.y+e));return new o(n)}};function xu(o,t,e,n){let i=[];for(let r=0;r<20;r++){let a=r*2*Math.PI/20;i.push(new rn(o+e*Math.sin(a),t+n*Math.cos(a)))}return new js(i)}function Br(o,t,e,n){return new js([new rn(o,t),new rn(e,t),new rn(e,n),new rn(o,n)])}var Mi=class{constructor(t,e,n,s){this.x=t;this.winding=e;this.shapeId=n;this.lowOrHigh=s}};function Yf(o,t){let e=o.low.x+(o.high.x-o.low.x)*(t-o.low.y)/(o.high.y-o.low.y);if(isNaN(e))throw new Error("Bad intersection");return e}function mb(o,t,e,n){let s,i,r,a;t.high.y<e&&F.warn("Error: inconsistent segment (1)"),t.low.y<=e?(s=Yf(t,e),i=t.winding):(s=t.low.x,i=0),t.high.y>=n?(r=Yf(t,n),a=t.winding):(r=t.high.x,a=0),s<r?(o.push(new Mi(s,i,t.shapeId,-1)),o.push(new Mi(r,a,t.shapeId,1))):(o.push(new Mi(r,a,t.shapeId,-1)),o.push(new Mi(s,i,t.shapeId,1)))}function Cb(o,t,e){let n=t+e,s=Array(n),i=Array(n),r;for(r=0;r<=n;r++)s[r]=0,i[r]=0;let a=[],l=!1,c=o.length;for(let u=0;u<c;u++){let d=o[u];s[d.shapeId]+=d.winding,i[d.shapeId]+=d.lowOrHigh;let h=!1;for(r=0;r<t;r++)if(s[r]&&!i[r]){h=!0;break}if(h){for(r=t;r<=n;r++)if(s[r]||i[r]){h=!1;break}}l!=h&&(a.push(d.x),l=h)}return a}function bb(o,t){return t?Math.ceil(o/t)*t:o}function Kf(o,t){return t?Math.floor(o/t)*t:o}function yb(o){return new rn(o.y,-o.x)}function Ui(o){return new qe(o.y1,-o.x2,o.y2,-o.x1)}function Ra(o){return new qe(-o.y2,o.x1,-o.y1,o.x2)}function qf(o){return new js(o.points.map(t=>yb(t)))}function Zf(o,t,e,n,s,i){i&&(o=Ui(o),t=t.map(C=>qf(C)),e=e.map(C=>qf(C)));let r=t.length,a=e?e.length:0,l=[],c=[],u,d,h;for(u=0;u<r;u++)t[u].addSegments(c,u);for(u=0;u<a;u++)e[u].addSegments(c,u+r);let f=c.length;c.sort(gb);let g=0;for(;c[g].shapeId>=r;)g++;let m=c[g].low.y;m>o.y1&&l.push(new on(o.y1,m,o.x2,o.x2));let y=0,S=[];for(;y<f&&(h=c[y]).low.y<m;)h.high.y>m&&S.push(h),y++;for(;y<f||S.length>0;){let C=o.y2,x=Math.min(bb(Math.ceil(m+n),s),o.y2);for(d=0;d<S.length&&C>x;d++)h=S[d],h.low.x==h.high.x?h.high.y<C&&(C=Math.max(Kf(h.high.y,s),x)):h.low.x!=h.high.x&&(C=x);for(C>o.y2&&(C=o.y2);y<f&&(h=c[y]).low.y<C;){if(h.high.y<m){y++;continue}if(h.low.y<x)h.low.y==h.high.y&&h.low.y==m||(S.push(h),C=x),y++;else{let N=Kf(h.low.y,s);N<C&&(C=N);break}}let v=[];for(d=0;d<S.length;d++)mb(v,S[d],m,C);v.sort((N,L)=>N.x-L.x||N.lowOrHigh-L.lowOrHigh);let E=Cb(v,r,a);if(E.length==0)l.push(new on(m,C,o.x2,o.x2));else{let N=0,L=o.x1;for(d=0;d<E.length;d+=2){let O=Math.max(o.x1,E[d]),z=Math.min(o.x2,E[d+1])-O;z>N&&(N=z,L=O)}N==0?l.push(new on(m,C,o.x2,o.x2)):l.push(new on(m,C,Math.max(L,o.x1),Math.min(L+N,o.x2)))}if(C==o.y2)break;for(m=C,d=S.length-1;d>=0;d--)S[d].high.y<=C&&S.splice(d,1)}return Qf(o,l),l}function Qf(o,t){let e=t.length-1,n=new on(o.y2,o.y2,o.x1,o.x2);for(;e>=0;){let s=n;n=t[e],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(e,1),n=s),e--}}function Jf(o,t){let e=0,n=o.length;for(;e<n;){let s=Math.floor((e+n)/2);t>=o[s].y2?e=s+1:n=s}return e}function eg(o,t){if(!o.length)return t;let e=t.y1,n,s;for(s=0;s<o.length&&(n=o[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)e=Math.max(e,n.y2);let i=e;for(;s<o.length&&(n=o[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)i=n.y2;return s===o.length?i=t.y2:i=Math.min(i,t.y2),i<=e?null:new qe(t.x1,e,t.x2,i)}function tg(o,t){if(!o.length)return t;let e=t.y2,n,s;for(s=o.length-1;s>=0&&(n=o[s],!(s===o.length-1&&n.y2<t.y2));s--){if(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2)break;e=Math.min(e,n.y1)}let i=Math.min(e,n.y2);for(;s>=0&&(n=o[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)i=n.y1;return i=Math.max(i,t.y1),e<=i?null:new qe(t.x1,i,t.x2,e)}function ng(o,t,e,n){let s=e.y1,i=e.x2-e.x1,r=e.y2-e.y1,a=Jf(t,s);for(;;){let l=s+r;if(l>o.y2)return!1;let c=o.x1,u=o.x2;for(let d=a;d<t.length&&t[d].y1<l;d++){let h=t[d];h.x1>c&&(c=h.x1),h.x2<u&&(u=h.x2)}if(c+i<=u||a>=t.length)return n=="left"?(e.x1=c,e.x2=c+i):(e.x1=u-i,e.x2=u),e.y2+=s-e.y1,e.y1=s,!0;s=t[a].y2,a++}}function sg(o,t,e,n,s){for(n||(n=[new on(e.y1,e.y2,e.x1,e.x2)]);n.length>0&&n[0].y2<=o.y1;)n.shift();if(n.length==0)return;n[0].y1<o.y1&&(n[0].y1=o.y1);let i,r=t.length==0?o.y1:t[t.length-1].y2;r<o.y2&&t.push(new on(r,o.y2,o.x1,o.x2));let a=Jf(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(i=t[a],a++,t.splice(a,0,new on(l.y1,i.y2,i.x1,i.x2)),i.y2=l.y1);a<t.length&&(i=t[a++],i.y2>l.y2&&(t.splice(a,0,new on(l.y2,i.y2,i.x1,i.x2)),i.y2=l.y2),l.x1!=l.x2&&(s=="left"?i.x1=Math.min(l.x2,o.x2):i.x2=Math.max(l.x1,o.x1)),i.y2!=l.y2););}Qf(o,t)}var Su=class extends Et{constructor(){super();p(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function ig(o){if(o){let t=new Su;try{return o.visit(t),t.propSet}catch(e){F.warn(e,"toSet:")}}return{}}var Eu=class extends Et{constructor(e){super();this.value=e}visitInt(e){return this.value=e.num,e}};function Tu(o,t){if(o){let e=new Eu(t);try{return o.visit(e),e.value}catch(n){F.warn(n,"toInt: ")}}return t}var vu=class extends Et{constructor(){super();p(this,"collect",!1);p(this,"coords",[]);p(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 P(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,n,s,i,r){if(this.coords.length>0){let a=[];switch(this.coords.forEach((l,c)=>{if(l.unit=="%"){let u=c%2==0?s:i;c==3&&this.name=="circle"&&(u=Math.sqrt((s*s+i*i)/2)),a.push(l.num*u/100)}else a.push(l.num*r.queryUnitSize(l.unit,!1))}),this.name){case"polygon":if(a.length%2==0){let l=[];for(let c=0;c<a.length;c+=2)l.push(new rn(e+a[c],n+a[c+1]));return new js(l)}break;case"rectangle":if(a.length==4)return Br(e+a[0],n+a[1],e+a[0]+a[2],n+a[1]+a[3]);break;case"ellipse":if(a.length==4)return xu(e+a[0],n+a[1],a[2],a[3]);break;case"circle":if(a.length==3)return xu(e+a[0],n+a[1],a[2],a[2]);break}}return null}};function Fa(o,t,e,n,s,i){if(o){let r=new vu;try{return o.visit(r),r.getShape(t,e,n,s,i)}catch(a){F.warn(a,"toShape:")}}return Br(t,e,t+n,e+s)}var Nu=class extends Et{constructor(e){super();this.reset=e;p(this,"counters",{});p(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 Ys(o,t){let e=new Nu(t);try{o.visit(e)}catch(n){F.warn(n,"toCounters:")}return e.counters}var Va=class extends $t{constructor(e,n){super();this.baseUrl=e;this.transformer=n}visitURL(e){return new ge(this.transformer.transformURL(e.url,this.baseUrl))}};function wu(o){let t={};return Object.keys(o).forEach(e=>{t[e]=Array.from(o[e])}),t}function zi(o,t){if(t==="content"){let e=o.cloneNode(!0);return e.querySelectorAll("[data-adapt-pseudo]").forEach(s=>s.remove()),e.textContent||""}else{let e=o.querySelector(`[data-adapt-pseudo="${t}"]`);return e&&e.textContent||""}}var Ru=class{constructor(t,e){this.targetId=t;this.resolved=e;p(this,"pageCounters",null);p(this,"spineIndex",-1);p(this,"pageIndex",-1)}equals(t){return this===t?!0:t?this.targetId===t.targetId&&this.resolved===t.resolved&&this.spineIndex===t.spineIndex&&this.pageIndex===t.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Iu=class{constructor(t,e){this.counterStore=t;this.baseURL=e}countersOfId(t,e){t=this.counterStore.documentURLTransformer.transformFragment(t,this.baseURL),this.counterStore.countersById[t]=e}getExprContentListener(){return this.counterStore.getExprContentListener()}},Vu=class{constructor(t,e,n,s){this.counterStore=t;this.baseURL=e;this.rootScope=n;this.pageScope=s;p(this,"styler",null);p(this,"namedStringValues",{});p(this,"runningElements",{})}setStyler(t){this.styler=t}getFragment(t){let e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null}getTransformedId(t){let e=this.counterStore.documentURLTransformer.transformURL(te(t,this.baseURL),this.baseURL);return e.charAt(0)==="#"&&(e=e.substring(1)),e}getPageCounterVal(t,e){let n=()=>{let r=this.counterStore.currentPageCounters[t];return r&&r.length?r[r.length-1]:null},s=new ne(this.pageScope,()=>e(n()),`page-counter-${t}`),i=r=>e(r[r.length-1]);return this.counterStore.registerPageCounterExpr(t,i,s),s}getPageCountersVal(t,e){let n=()=>this.counterStore.currentPageCounters[t]||[],s=new ne(this.pageScope,()=>e(n()),`page-counters-${t}`);return this.counterStore.registerPageCounterExpr(t,e,s),s}getTargetCounters(t,e,n){let s=this.counterStore.countersById[e];return!s&&n&&t&&(this.styler.styleUntilIdIsReached(t),s=this.counterStore.countersById[e]),s||null}getTargetPageCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[t]||null}getTargetPageText(t,e){if(this.counterStore.currentPage.elementsById[t]){let n=this.counterStore.currentPage.elementsById[t];if(n&&n.length>0){let s=n[0];return e==="before"||e==="after"||e==="marker"?zi(s,e):zi(s,"content")}return""}else{if(t in this.counterStore.pageTextById){let n=this.counterStore.pageTextById[t];return n[e]!==void 0?n[e]:n.content||""}return null}}getTargetCounterVal(t,e,n){let s=this.getFragment(t),i=this.getTransformedId(t),r=this.getTargetCounters(s,i,!1);if(r&&r[e]){let l=r[e];return new he(this.rootScope,n(l[l.length-1]||null))}let a=new ne(this.pageScope,()=>{if(r=this.getTargetCounters(s,i,!0),r)if(r[e]){let l=r[e];return n(l[l.length-1]||null)}else{let l=this.getTargetPageCounters(i);if(l)if(this.counterStore.resolveReference(i),l[e]){let c=l[e];return n(c[c.length-1]||null)}else return n(0);else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"},`target-counter-${e}-of-${t}`);return this.counterStore.registerTargetCounterExpr(e,n,a,i),a}getTargetCountersVal(t,e,n){let s=this.getFragment(t),i=this.getTransformedId(t);return new ne(this.pageScope,()=>{let r=this.getTargetPageCounters(i);if(r){this.counterStore.resolveReference(i);let a=r[e]||[],c=this.getTargetCounters(s,i,!0)[e]||[];return n(a.concat(c))}else return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??"},`target-counters-${e}-of-${t}`)}getTargetTextVal(t,e){let n=this.getTransformedId(t),s=new ne(this.pageScope,()=>{if(e==="first-letter"){let r=this.getTargetPageText(n,"before"),a=this.getTargetPageText(n,"content"),l=this.getTargetPageText(n,"after");if(r===null&&a===null&&l===null)return this.counterStore.saveReferenceOfCurrentPage(n,!1),"??";let c=(r!=null?r:"")+(a!=null?a:"")+(l!=null?l:"");this.counterStore.resolveReference(n);let u=c.match(_s);return u?u[0]:""}let i=this.getTargetPageText(n,e);return i!==null?(this.counterStore.resolveReference(n),i):(this.counterStore.saveReferenceOfCurrentPage(n,!1),"??")},`target-text-${e}-of-${t}`);return this.counterStore.registerTargetTextExpr(e,s,n),s}getNamedStringVal(t,e){return new ne(this.pageScope,()=>this.getRunningValue(this.namedStringValues,t,e),`named-string-${e}-${t}`)}getRunningElementVal(t,e){return new ne(this.pageScope,()=>this.getRunningValue(this.runningElements,t,e),`running-element-${e}-${t}`)}getRunningValue(t,e,n){let s=t[e];if(!s)return"";let i=Object.keys(s).map(g=>parseInt(g,10)).sort(aa),r=this.counterStore.currentPage,a=r.isBlankPage?r.offset-1:r.offset,l=r.isBlankPage?a:Math.max(a,...Array.from(r.container.querySelectorAll(`[${Qt}]`)).map(g=>parseInt(g.getAttribute(Qt),10))),c=-1,u=-1,d=-1,h=-1;for(let g=0;g<i.length;g++){let m=i[g],y=g>0?i[g-1]:-1,S=g<i.length-1?i[g+1]:-1;if(m>l)break;if(m>=a){if(c<0&&(c=m,h=-1),u<0)if(m===a)u=m;else{y<c&&(u=y);let C=r.container.querySelector(`[${Qt}="${m}"]`);if(!C)u<0&&(u=m);else{let x=r.container.querySelector(`[${Qt}="${a}"]`);if(x||(x=r.container.querySelector(`[${Qt}="0"]`)),x){for(let v=x;v;v=v.firstElementChild)if(v===C){u=m;break}}}}d=m}else(S>l||S<0)&&(c=u=d=h=m)}return s[{first:c,start:u,last:d,"first-except":h}[n]]||""}setNamedString(t,e,n){let s=this.namedStringValues[t]||(this.namedStringValues[t]={});s[n]=e}setRunningElement(t,e){let n=this.runningElements[t]||(this.runningElements[t]={});n[e]=String(e)}},Ba=class{constructor(t){this.documentURLTransformer=t;p(this,"countersById",{});p(this,"pageCountersById",{});p(this,"pageTextById",{});p(this,"currentPageCounters",{});p(this,"previousPageCounters",{});p(this,"currentPageCountersStack",[]);p(this,"pageIndicesById",{});p(this,"currentPage",null);p(this,"newReferencesOfCurrentPage",[]);p(this,"referencesToSolve",[]);p(this,"referencesToSolveStack",[]);p(this,"unresolvedReferences",{});p(this,"resolvedReferences",{});p(this,"pagesCounterExprs",[]);p(this,"pageCounterExprs",[]);p(this,"targetCounterExprs",[]);p(this,"targetTextExprs",[]);this.currentPageCounters.page=[0]}createCounterListener(t){return new Iu(this,t)}createCounterResolver(t,e,n){return new Vu(this,t,e,n)}setCurrentPage(t){this.currentPage=t}definePageCounter(t,e){this.currentPageCounters[t]?this.currentPageCounters[t].push(e):this.currentPageCounters[t]=[e]}forceSetPageCounter(t){let e=this.currentPageCounters.page;!e||!e.length?this.currentPageCounters.page=[t]:e[e.length-1]=t}updatePageCounters(t,e){this.previousPageCounters=wu(this.currentPageCounters);let n,s=t["counter-reset"];if(s){let a=s.evaluate(e);a&&(n=Ys(a,!0))}if(n)for(let a in n)this.definePageCounter(a,n[a]);let i,r=t["counter-increment"];if(r){let a=r.evaluate(e);a&&(i=Ys(a,!1))}i?"page"in i||(i.page=1):(i={},i.page=1);for(let a in i){this.currentPageCounters[a]||this.definePageCounter(a,0);let l=this.currentPageCounters[a];l[l.length-1]+=i[a]}}pushPageCounters(t){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=wu(t)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(t){let e=this.unresolvedReferences[t],n=this.resolvedReferences[t];n||(n=this.resolvedReferences[t]=[]);let s=!1;for(let i=0;i<this.referencesToSolve.length;){let r=this.referencesToSolve[i];if(r.targetId===t){if(r.resolve(),this.referencesToSolve.splice(i,1),e){let a=e.indexOf(r);a>=0&&e.splice(a,1)}n.push(r),s=!0}else i++}s||this.saveReferenceOfCurrentPage(t,!0)}saveReferenceOfCurrentPage(t,e){if(!this.newReferencesOfCurrentPage.some(n=>n.targetId===t)){let n=new Ru(t,e);this.newReferencesOfCurrentPage.push(n)}}finishPage(t,e){let n=Object.keys(this.currentPage.elementsById);if(n.length>0){let r=wu(this.currentPageCounters);n.forEach(a=>{this.pageCountersById[a]=r;let l=this.currentPage.elementsById[a];if(l&&l.length>0){let u=l[0];this.pageTextById[a]={content:zi(u,"content"),before:zi(u,"before"),after:zi(u,"after"),marker:zi(u,"marker")}}let c=this.pageIndicesById[a];if(c&&c.pageIndex<e){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let h;for(;h=u.shift();)h.unresolve(),d.push(h)}}this.pageIndicesById[a]={spineIndex:t,pageIndex:e}})}let s=this.previousPageCounters,i;for(;i=this.newReferencesOfCurrentPage.shift();){i.pageCounters=s,i.spineIndex=t,i.pageIndex=e;let r;i.isResolved()?(r=this.resolvedReferences[i.targetId],r||(r=this.resolvedReferences[i.targetId]=[])):(r=this.unresolvedReferences[i.targetId],r||(r=this.unresolvedReferences[i.targetId]=[])),r.every(a=>!i.equals(a))&&r.push(i)}this.currentPage=null}getUnresolvedRefsToPage(t){let e=[];Object.keys(t.elementsById).forEach(r=>{let a=this.unresolvedReferences[r];a&&(e=e.concat(a))}),e.sort((r,a)=>r.spineIndex-a.spineIndex||r.pageIndex-a.pageIndex);let s=[],i=null;return e.forEach(r=>{!i||i.spineIndex!==r.spineIndex||i.pageIndex!==r.pageIndex?(i={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},s.push(i)):i.refs.push(r)}),s}pushReferencesToSolve(t){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=t}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(t,e,n){t==="pages"?this.pagesCounterExprs.push({expr:n,format:e}):this.pageCounterExprs.push({expr:n,format:e})}registerTargetCounterExpr(t,e,n,s){this.targetCounterExprs.push({name:t,expr:n,format:e,transformedId:s})}registerTargetTextExpr(t,e,n){this.targetTextExprs.push({pseudoElement:t,expr:e,transformedId:n})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(t,e,n){if(t instanceof ne){if(t.str=="viv-leader"){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute("data-viv-leader",t.key),r.setAttribute("data-viv-leader-value",e),r}else if(t.str.startsWith("running-element-")){let r=e&&n.querySelectorAll(`[${Qt}="${e}"]`);if(!r||r.length===0)return null;let l=r[r.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(l),l.style.position="",l.style.visibility="",l}else if(t.str.startsWith("target-counter-")){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute(Au,t.key),r}else if(t.str.startsWith("target-text-")){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute(Lu,t.key),r}}let s=this.pagesCounterExprs.findIndex(r=>r.expr===t)>=0,i=!s&&this.pageCounterExprs.findIndex(r=>r.expr===t)>=0;if(s||i){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute(s?Pu:ku,t.key),r}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${ku}]`);for(let i of e){let r=i.getAttribute(ku),a=this.pageCounterExprs.find(d=>d.expr.key===r),l=(a==null?void 0:a.expr).str,c=l==null?void 0:l.replace(/^page-counters?-/,""),u=this.currentPageCounters[c];u&&(i.textContent=a.format(u))}let n=t.querySelectorAll(`[${Au}]`);for(let i of n)i.setAttribute(rg,!0);let s=t.querySelectorAll(`[${Lu}]`);for(let i of s)i.setAttribute(og,!0)}finishLastPage(t){var r;let e=t.root.querySelectorAll(`[${Pu}]`),n=t.contentContainer.childElementCount;for(let a of e){let l=a.getAttribute(Pu),c=this.pagesCounterExprs.findIndex(u=>u.expr.key===l);c>=0,a.textContent=this.pagesCounterExprs[c].format([n])}let s=t.root.querySelectorAll(`[${rg}]`);for(let a of s){let l=a.getAttribute(Au),c=this.targetCounterExprs.find(u=>u.expr.key===l);if(c&&c.transformedId){let u=this.pageCountersById[c.transformedId];if(u){let d=u[c.name];d&&(a.textContent=c.format(d[d.length-1]))}}}let i=t.root.querySelectorAll(`[${og}]`);for(let a of i){let l=a.getAttribute(Lu),c=this.targetTextExprs.find(u=>u.expr.key===l);if(c&&c.transformedId){let u=this.pageTextById[c.transformedId];u&&(a.textContent=(r=u[c.pseudoElement])!=null?r:"")}}}createLayoutConstraint(t){return new Fu(this,t)}},Pu="data-vivliostyle-pages-counter",ku="data-vivliostyle-page-counter",Au="data-vivliostyle-target-counter",Lu="data-vivliostyle-target-text",rg="data-vivliostyle-target-counter-in-running",og="data-vivliostyle-target-text-in-running",Fu=class{constructor(t,e){this.counterStore=t;this.pageIndex=e}allowLayout(t){if(!t||t.after)return!0;let e=t.viewNode;if(!e||e.nodeType!==1)return!0;let n=e.getAttribute("data-vivliostyle-id")||e.getAttribute("id")||e.getAttribute("name");if(!n||!this.counterStore.resolvedReferences[n]&&!this.counterStore.unresolvedReferences[n])return!0;let s=this.counterStore.pageIndicesById[n];return s?this.pageIndex>=s.pageIndex:!0}};function Sb(o){if(o=o.substr(1),o.match(/^[^0-9a-fA-F\n\r]$/))return o;let t=parseInt(o,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function Ks(o){return o.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Sb)}var Ou=class{constructor(){p(this,"type");p(this,"precededBySpace",!1);p(this,"num",0);p(this,"text","");p(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 Fe(o,t){let e=Array(128),n;for(n=0;n<128;n++)e[n]=o;for(e[NaN]=o==35?35:72,n=0;n<t.length;n+=2)e[t[n]]=t[n+1];return e}var On=[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];On[NaN]=80;var yn=[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];yn[NaN]=43;var Eb=[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];yn[NaN]=43;var lg=[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];lg[NaN]=35;var cg=[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];cg[NaN]=45;var Du=[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];Du[NaN]=37;var Mu=[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];Mu[NaN]=38;var qs=Fe(35,[61,36]),vb=Fe(35,[58,77]),Nb=Fe(35,[61,36,124,50]),Tb=Fe(35,[38,51]),wb=Fe(35,[42,54]),Pb=Fe(39,[42,55]),kb=Fe(54,[42,55,47,56]),Ab=Fe(62,[62,82]),Lb=Fe(35,[61,36,33,70]),Rb=Fe(62,[45,71]),Ib=Fe(63,[45,81]),Bu=Fe(76,[10,72,13,72]),Vb=Fe(39,[39,46,10,72,13,72,92,48]),Fb=Fe(39,[34,46,10,72,13,72,92,49]),Bb=Fe(39,[39,47,10,74,13,74,92,48]),Ob=Fe(39,[34,47,10,74,13,74,92,49]),ag=Fe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Db=Fe(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]),Mb=Fe(39,[39,68,10,74,13,74,92,75,NaN,67]),_b=Fe(39,[34,68,10,74,13,74,92,75,NaN,67]),Ub=Fe(72,[9,39,10,39,13,39,32,39,41,69]),Hb=15,Xe=class{constructor(t,e){this.input=t;this.handler=e;p(this,"indexMask");p(this,"buffer");p(this,"tail",0);p(this,"curr",0);p(this,"position",0);this.indexMask=Hb,this.buffer=Array(this.indexMask+1);for(let n=0;n<=this.indexMask;n++)this.buffer[n]=new Ou}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(t){return(this.tail-this.curr&this.indexMask)<=t&&this.fillBuffer(),this.buffer[this.curr+t&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let t=this.tail,e=this.curr,n=this.indexMask;if(t>=e?e+=n:e--,e==t)throw new Error("F_CSSTOK_INTERNAL");let s=On,i=this.input,r=this.position,a=this.buffer,l=0,c=0,u="",d=0,h=!1,f=a[t],g=-9;for(;;){let m=i.charCodeAt(r);switch(s[m]||s[65]){case 72:u=i.substring(c,r),isNaN(m)?l=0:l=54,s=On;break;case 1:r++,h=!0;continue;case 2:c=r++,s=Du;continue;case 3:l=1,c=r++,s=yn;continue;case 4:c=r++,l=31,s=qs;continue;case 33:l=2,c=++r,s=Vb;continue;case 34:l=2,c=++r,s=Fb;continue;case 6:c=++r,l=7,s=yn;continue;case 7:c=r++,l=32,s=qs;continue;case 8:c=r++,l=21;break;case 9:c=r++,l=32,s=Tb;continue;case 10:c=r++,l=10;break;case 11:c=r++,l=11;break;case 12:c=r++,l=36,s=qs;continue;case 13:c=r++,l=23;break;case 14:c=r++,l=16;break;case 15:l=24,c=r++,s=lg;continue;case 16:c=r++,s=Eb;continue;case 78:c=r++,l=9,s=yn;continue;case 17:c=r++,l=19,s=wb;continue;case 18:c=r++,l=18,s=vb;continue;case 77:r++,l=50;break;case 19:c=r++,l=17;break;case 20:c=r++,l=38,s=Lb;continue;case 21:c=r++,l=39,s=qs;continue;case 22:c=r++,l=37,s=qs;continue;case 23:c=r++,l=22;break;case 24:c=++r,l=20,s=yn;continue;case 25:c=r++,l=14;break;case 26:c=r++,l=15;break;case 27:c=r++,l=12;break;case 28:c=r++,l=13;break;case 29:c=r++,g=c,l=1,s=Bu;continue;case 30:c=r++,l=33,s=qs;continue;case 31:c=r++,l=34,s=Nb;continue;case 32:c=r++,l=35,s=qs;continue;case 35:break;case 36:r++,l=l+41-31;break;case 37:l=5,d=parseInt(i.substring(c,r),10);break;case 38:l=4,d=parseFloat(i.substring(c,r));break;case 39:r++;continue;case 40:l=3,d=parseFloat(i.substring(c,r)),c=r++,s=yn;continue;case 41:l=3,d=parseFloat(i.substring(c,r)),u="%",c=r++;break;case 42:r++,s=Mu;continue;case 43:if(u=Ks(i.substring(c,r)),l===27&&m===63||l===1&&u.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(i.substring(r-1))){l=27,r++;continue}break;case 44:g=r++,s=Bu;continue;case 45:u=Ks(i.substring(c,r));break;case 46:u=i.substring(c,r),r++;break;case 47:u=Ks(i.substring(c,r)),r++;break;case 48:g=r,r+=2,s=Bb;continue;case 49:g=r,r+=2,s=Ob;continue;case 50:r++,l=25;break;case 51:r++,l=26;break;case 52:if(u=i.substring(c,r),l==1){if(r++,u.toLowerCase()=="url"){s=ag;continue}l=6}break;case 53:if(u=Ks(i.substring(c,r)),l==1){if(r++,u.toLowerCase()=="url"){s=ag;continue}l=6}break;case 54:s=Pb,r++;continue;case 55:s=kb,r++;continue;case 56:s=On,r++;continue;case 57:s=Ab,r++,i[r]!==">"&&(l=1,s=yn);continue;case 81:l=51,u=i.substring(c,++r),s=On;break;case 82:l=52,u=i.substring(c,++r),s=On;break;case 58:l=5,s=Du,r++;continue;case 59:l=4,s=Mu,r++;continue;case 60:l=1,s=yn,r++;continue;case 61:l=1,s=Bu,g=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:c=r++,s=Db;continue;case 65:c=++r,s=Mb;continue;case 66:c=++r,s=_b;continue;case 67:l=8,u=Ks(i.substring(c,r)),r++;break;case 69:r++;break;case 70:s=Rb,r++;continue;case 71:s=Ib,r++;continue;case 79:if(r-g<8&&i.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:l=8,u=Ks(i.substring(c,r)),r++,s=Ub;continue;case 74:if(r++,r-g<9&&i.substring(g+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;l=54,u="E_CSS_UNEXPECTED_NEWLINE",s=On;break;case 73:if(r-g<9&&i.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,s=yn;continue}u=Ks(i.substring(c,r));break;case 75:g=r++;continue;case 76:r++,s=cg;continue;default:if(s!==On){l=54,u="E_CSS_UNEXPECTED_STATE";break}c=r,l=0}if(f.type=l,f.precededBySpace=h,f.num=d,f.text=u,f.position=c,t++,t>=e)break;s=On,h=!1,f=a[t&n]}this.position=r,this.tail=t&n}};var Ie=null,_u=null;function Dr(){return Ie}function A(o){if(!Ie)throw new Error("E_TASK_NO_CONTEXT");Ie.name||(Ie.name=o);let t=Ie,e=new Wi(t,t.top,o);return t.top=e,e.state=1,e}function zb(o){return new Hu(o||new Uu)}function T(o){return new Or(o)}function Dn(o,t,e){let n=A(o);n.handler=e;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function ug(o,t){return(Ie?Ie.getScheduler():_u||zb()).run(o,t)}var Uu=class{currentTime(){return new Date().valueOf()}setTimeout(t,e){return setTimeout(t,e)}clearTimeout(t){clearTimeout(t)}},Hu=class{constructor(t){this.timer=t;p(this,"timeout",1);p(this,"slice",25);p(this,"sliceOverTime",0);p(this,"queue");p(this,"wakeupTime",null);p(this,"timeoutToken",null);p(this,"inTimeSlice",!1);p(this,"order",0);this.queue=new ra,_u||(_u=this)}setSlice(t){this.slice=t}setTimeout(t){this.timeout=t}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,n=this.timer.currentTime();if(this.timeoutToken!=null){if(n+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let s=e-n;s<=this.timeout&&(s=this.timeout),this.wakeupTime=n+s,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},s)}schedule(t,e){let n=t,s=this.timer.currentTime();n.order=this.order++,n.scheduledTime=s+(e||0),this.queue.add(n),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let t=this.timer.currentTime();for(this.sliceOverTime=t+this.slice;this.queue.length();){let e=this.queue.peek();if(e.scheduledTime>t||(this.queue.remove(),e.canceled||e.resumeInternal(),t=this.timer.currentTime(),t>=this.sliceOverTime))break}}catch(t){F.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let n=new zu(this,e||"");n.top=new Wi(n,null,"bootstrap"),n.top.state=1,n.top.then(()=>{let i=()=>{n.running=!1;for(let r of n.callbacks)try{r()}catch(a){F.error(a)}};try{t().then(r=>{n.result=r,i()})}catch(r){n.raise(r),i()}});let s=Ie;return Ie=n,this.schedule(n.top.suspend("bootstrap")),Ie=s,n}},Oa=class{constructor(t){this.task=t;p(this,"scheduledTime",0);p(this,"order",0);p(this,"result",null);p(this,"canceled",!1)}compare(t){let e=t;return e.scheduledTime-this.scheduledTime||e.order-this.order}getTask(){return this.task}schedule(t,e){this.result=t,this.task.scheduler.schedule(this,e)}resumeInternal(){let t=this.task;if(this.task=null,t&&t.continuation==this){t.continuation=null;let e=Ie;return Ie=t,t.top.finish(this.result),Ie=e,!0}return!1}cancel(){this.canceled=!0}},zu=class{constructor(t,e){this.scheduler=t;this.name=e;p(this,"callbacks",[]);p(this,"exception",null);p(this,"running",!0);p(this,"result",null);p(this,"waitTarget",null);p(this,"top",null);p(this,"continuation",null)}getName(){return this.name}interrupt(t){if(this.raise(t||new Error("E_TASK_INTERRUPT")),this!==Ie&&this.continuation){this.continuation.cancel();let e=new Oa(this);this.waitTarget="interrupt",this.continuation=e,this.scheduler.schedule(e)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(t){this.callbacks.push(t)}join(){let t=A("Task.join");if(!this.running)t.finish(this.result);else{let e=t.suspend(this);this.whenDone(()=>{e.schedule(this.result)})}return t.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let t=this.exception;this.exception=null,this.top.handler(this.top,t)}else this.exception&&F.error(this.exception,"Unhandled exception in task",this.name)}raise(t,e){if(this.fillStack(t),e){let n=this.top;for(;n&&n!=e;)n=n.parent;n==e&&(this.top=n)}this.exception=t,this.unwind()}fillStack(t){let e=t.frameTrace;if(!e){e=t.stack?`${t.stack}
5
5
  ---- async ---
6
6
  `:"";for(let n=this.top;n;n=n.parent)e+=" ",e+=n.getName(),e+=`
7
- `;t.frameTrace=e}}},yo=class r{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new r(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},xu=class{constructor(t){this.frame=t}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new Pi(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return e.state=1,this.frame.parent=e,this.frame.then(n=>{t(n).then(s=>{e.finish(s)})}),e.result()}else return t(this.frame.res)}thenReturn(t){return this.isPending()?this.thenAsync(()=>new yo(t)):new yo(t)}thenFinish(t){this.isPending()?this.then(e=>{t.finish(e)}):t.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Pi=class{constructor(t,e,n){this.task=t;this.parent=e;this.name=n;p(this,"res",null);p(this,"state");p(this,"callback",null);p(this,"handler",null);this.state=0}checkEnvironment(){if(!Le)throw new Error("F_TASK_NO_CONTEXT");if(this!==Le.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new xu(this)}finish(t){this.checkEnvironment(),Le&&!Le.exception&&(this.res=t),this.state=2;let e=this.parent;if(Le&&(Le.top=e),this.callback){try{this.callback(t)}catch(n){this.task.raise(n,e)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(t){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=t;break;case 2:{let e=this.task,n=this.parent;try{t(this.res),this.state=3}catch(s){this.state=3,e.raise(s,n)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let t=A("Frame.timeSlice");return t.getScheduler().isTimeSliceOver()?(F.debug("-- time slice --"),t.suspend().schedule(!0)):t.finish(!0),t.result()}sleep(t){let e=A("Frame.sleep");return e.suspend().schedule(!0,t),e.result()}loop(t){let e=A("Frame.loop"),n=s=>{try{for(;s;){let i=t();if(i.isPending()){i.then(n);return}else i.then(o=>{s=o})}e.finish(!0)}catch(i){e.task.raise(i,e)}};return n(!0),e.result()}loopWithFrame(t){let e=Le;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let n;do{let s=new Su(e,e.top);e.top=s,s.state=1,t(s),n=s.result()}while(!n.isPending()&&n.get());return n})}suspend(t){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let e=new Ca(this.task);return this.task.continuation=e,Le=null,this.task.waitTarget=t||null,e}},Su=class extends Pi{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}};var Cn=class{constructor(t,e){this.fetch=t;p(this,"name");p(this,"arrived",!1);p(this,"resource",null);p(this,"task",null);p(this,"piggybacks",[]);this.name=e}start(){this.task||(this.task=xo().getScheduler().run(()=>{let t=A("Fetcher.run");return this.fetch().then(e=>{let n=this.piggybacks;if(this.arrived=!0,this.resource=e,this.task=null,this.piggybacks=[],n)for(let s=0;s<n.length;s++)try{n[s](e)}catch(i){F.error(i,"Error:")}t.finish(e)}),t.result()},this.name))}piggyback(t){this.arrived?t(this.resource):this.piggybacks.push(t)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},ns=r=>{if(r.length==0)return T(!0);if(r.length==1)return r[0].get().thenReturn(!0);let t=A("waitForFetches"),e=0;return t.loop(()=>{for(;e<r.length;){let n=r[e++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()};var Eu=`
7
+ `;t.frameTrace=e}}},Or=class o{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new o(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},Gu=class{constructor(t){this.frame=t}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new Wi(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return e.state=1,this.frame.parent=e,this.frame.then(n=>{t(n).then(s=>{e.finish(s)})}),e.result()}else return t(this.frame.res)}thenReturn(t){return this.isPending()?this.thenAsync(()=>new Or(t)):new Or(t)}thenFinish(t){this.isPending()?this.then(e=>{t.finish(e)}):t.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},Wi=class{constructor(t,e,n){this.task=t;this.parent=e;this.name=n;p(this,"res",null);p(this,"state");p(this,"callback",null);p(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 Gu(this)}finish(t){this.checkEnvironment(),Ie&&!Ie.exception&&(this.res=t),this.state=2;let e=this.parent;if(Ie&&(Ie.top=e),this.callback){try{this.callback(t)}catch(n){this.task.raise(n,e)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(t){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=t;break;case 2:{let e=this.task,n=this.parent;try{t(this.res),this.state=3}catch(s){this.state=3,e.raise(s,n)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let t=A("Frame.timeSlice");return t.getScheduler().isTimeSliceOver()?(F.debug("-- time slice --"),t.suspend().schedule(!0)):t.finish(!0),t.result()}sleep(t){let e=A("Frame.sleep");return e.suspend().schedule(!0,t),e.result()}loop(t){let e=A("Frame.loop"),n=s=>{try{for(;s;){let i=t();if(i.isPending()){i.then(n);return}else i.then(r=>{s=r})}e.finish(!0)}catch(i){e.task.raise(i,e)}};return n(!0),e.result()}loopWithFrame(t){let e=Ie;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let n;do{let s=new Wu(e,e.top);e.top=s,s.state=1,t(s),n=s.result()}while(!n.isPending()&&n.get());return n})}suspend(t){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let e=new Oa(this.task);return this.task.continuation=e,Ie=null,this.task.waitTarget=t||null,e}},Wu=class extends Wi{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}};var xn=class{constructor(t,e){this.fetch=t;p(this,"name");p(this,"arrived",!1);p(this,"resource",null);p(this,"task",null);p(this,"piggybacks",[]);this.name=e}start(){this.task||(this.task=Dr().getScheduler().run(()=>{let t=A("Fetcher.run");return this.fetch().then(e=>{let n=this.piggybacks;if(this.arrived=!0,this.resource=e,this.task=null,this.piggybacks=[],n)for(let s=0;s<n.length;s++)try{n[s](e)}catch(i){F.error(i,"Error:")}t.finish(e)}),t.result()},this.name))}piggyback(t){this.arrived?t(this.resource):this.piggybacks.push(t)}get(){return this.arrived?T(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},ds=o=>{if(o.length==0)return T(!0);if(o.length==1)return o[0].get().thenReturn(!0);let t=A("waitForFetches"),e=0;return t.loop(()=>{for(;e<o.length;){let n=o[e++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()};var Xu=`
8
8
  @media screen {
9
9
  [data-vivliostyle-viewer-viewport] {
10
10
  background: #aaaaaa;
@@ -45,7 +45,7 @@
45
45
  flex-direction: row-reverse;
46
46
  }
47
47
 
48
- [data-vivliostyle-viewer-viewport] [data-vivliostyle-page-container] {
48
+ [data-vivliostyle-spread-container] [data-vivliostyle-page-container] {
49
49
  margin: 0 auto;
50
50
  flex: none;
51
51
  transform-origin: center top;
@@ -73,7 +73,7 @@
73
73
  transform-origin: center top;
74
74
  }
75
75
  }
76
- `,Nu=`
76
+ `,$u=`
77
77
  [data-vivliostyle-layout-box] {
78
78
  position: absolute;
79
79
  left: 0;
@@ -86,12 +86,13 @@
86
86
  }
87
87
 
88
88
  [data-vivliostyle-debug] [data-vivliostyle-layout-box] {
89
- right: auto;
90
- bottom: auto;
91
- overflow: visible;
92
89
  z-index: auto;
93
90
  }
94
91
 
92
+ [data-vivliostyle-layout-box] [data-vivliostyle-page-container] {
93
+ margin: 0 auto 0 0;
94
+ }
95
+
95
96
  [data-vivliostyle-spread-container] {
96
97
  transform: scale(var(--viv-outputScale,1));
97
98
  transform-origin: left top;
@@ -206,7 +207,7 @@
206
207
  }
207
208
  }
208
209
  }
209
- `,vu=`
210
+ `,ju=`
210
211
  /*
211
212
  * Copyright 2013 Google, Inc.
212
213
  * Copyright 2015 Daishinsha Inc.
@@ -838,7 +839,7 @@ word-wrap = overflow-wrap;
838
839
  [adapt,webkit]start = inline-start;
839
840
  [adapt,webkit]end = inline-end;
840
841
 
841
- `,Tu=`
842
+ `,Yu=`
842
843
  <!DOCTYPE html>
843
844
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
844
845
  <head>
@@ -861,7 +862,7 @@ word-wrap = overflow-wrap;
861
862
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
862
863
 
863
864
  </body>
864
- </html>`,wu=`
865
+ </html>`,Ku=`
865
866
  @namespace "http://www.w3.org/1999/xhtml";
866
867
 
867
868
  :root {
@@ -988,7 +989,7 @@ word-wrap = overflow-wrap;
988
989
  margin: 10%;
989
990
  }
990
991
  }
991
- `,Pu=`
992
+ `,qu=`
992
993
  @namespace "http://www.w3.org/1999/xhtml";
993
994
  @namespace m "http://www.w3.org/1998/Math/MathML";
994
995
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1385,7 +1386,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1385
1386
  epub|case[required-namespace::supported] ~ epub|default {
1386
1387
  display: none;
1387
1388
  }
1388
- `,ku=`
1389
+ `,Zu=`
1389
1390
  @namespace "http://www.w3.org/1999/xhtml";
1390
1391
 
1391
1392
  *:not([data-vivliostyle-role=doc-toc],
@@ -1415,7 +1416,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1415
1416
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1416
1417
  -adapt-behavior: toc-container;
1417
1418
  }
1418
- `,Au=`
1419
+ `,Qu=`
1419
1420
  [data-viv-margin-discard~="block-start"] {
1420
1421
  margin-block-start: 0 !important;
1421
1422
  }
@@ -1566,7 +1567,7 @@ span[data-viv-leader] {
1566
1567
  -webkit-initial-letter: var(--viv-initialLetter);
1567
1568
  initial-letter: var(--viv-initialLetter);
1568
1569
  }
1569
- `,Lu=String.raw`
1570
+ `,Ju=String.raw`
1570
1571
  @counter-style decimal-leading-zero {
1571
1572
  system: extends decimal;
1572
1573
  pad: 2 '0';
@@ -1790,12 +1791,12 @@ span[data-viv-leader] {
1790
1791
  @counter-style upper-russian {
1791
1792
  system: alphabetic;
1792
1793
  symbols: \u0410 \u0411 \u0412 \u0413 \u0414 \u0415 \u0416 \u0417 \u0418 \u041A \u041B \u041C \u041D \u041E \u041F \u0420 \u0421 \u0422 \u0423 \u0424 \u0425 \u0426 \u0427 \u0428 \u0429 \u042D \u042E \u042F;
1793
- }`;function _s(r,t,e){let n=A("fetchFromURL"),s={method:e||"GET",mode:"cors"},i=n.suspend(),o={status:0,statusText:"",url:r,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(r,s).then(a=>{var l;return o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(l=a.headers.get("Content-Type"))==null?void 0:l.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(r)?(o.contentType="text/html",a.arrayBuffer().then(c=>new TextDecoder("Shift_JIS").decode(c))):(/^data:,(<|%3c)/i.test(r)&&(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=Ru([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),i.schedule(o)}).catch(a=>{F.warn(a,`Error fetching ${r}`),i.schedule(o)}),n.result()}function Ru(r,t){let e=t||"application/octet-stream";return new Blob(r,{type:e})}function Hf(r){let t=A("readBlob"),e=new FileReader,n=t.suspend(e);return e.addEventListener("load",()=>{n.schedule(e.result)},!1),e.readAsArrayBuffer(r),t.result()}function zf(r){return URL.createObjectURL(r)}var Ms=class{constructor(t,e){this.parser=t;this.type=e;p(this,"resources",{});p(this,"fetchers",{})}load(t,e,n){t=Wt(t);let s=this.resources[t];return typeof s!="undefined"?T(s):this.fetch(t,e,n).get()}fetchInner(t,e,n){let s=A("fetch"),i=t.endsWith("?viv-toc-box");i&&(t=t.replace("?viv-toc-box",""));let o=te("user-agent.xml",Qt),a=!i&&t===o;return a&&(t=`data:application/xml,${encodeURIComponent(Tu)}`),_s(t,this.type).then(l=>{if(l.status>=400&&e)throw new Error((n||`Failed to fetch required resource: ${t}`)+` (${l.status}${l.statusText?" "+l.statusText:""})`);i?(t+="?viv-toc-box",l.url+="?viv-toc-box"):a&&(l.url=t=o),this.parser(l,this).then(c=>{delete this.fetchers[t],this.resources[t]=c,s.finish(c)})}),s.result()}fetch(t,e,n){if(t=Wt(t),this.resources[t])return null;let i=this.fetchers[t];return i||(i=new Cn(()=>this.fetchInner(t,e,n),`Fetch ${t}`),this.fetchers[t]=i,i.start()),i}get(t){return this.resources[Wt(t)]}delete(t){delete this.resources[Wt(t)]}};function yb(r,t){let e=r.responseText;return T(e?di(e):null)}function Gf(){return new Ms(yb,"text")}function ss(r,t,e){let n=new Cn(()=>{let s=A("loadElement"),i=s.suspend(r),o=!1,a=null,l=c=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),i.schedule(c?c.type:"timeout"))};if(r.addEventListener("load",l,!1),r.addEventListener("error",l,!1),r.addEventListener("abort",l,!1),r.namespaceURI=="http://www.w3.org/2000/svg")t&&r.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(r.localName==="script")a=setTimeout(l,3e3);else if(t)if(r.localName==="img"){let c=r;c.loading==="lazy"&&(c.loading="eager"),c.src=t,e&&(c.alt=e),c.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4)}else r.src=t,e&&(r.alt=e);return s.result()},`loadElement ${t||r.localName}`);return n.start(),n}var Wf=0,xb=16777216,Iu=33554432,Ea=50331648,Na=67108864,Sb=83886080,Eb=100663296;var So=class{constructor(t){this.scope=t;p(this,"flavor");this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(t,e){}startStylesheet(t){this.flavor=t}tagSelector(t,e){}classSelector(t){}pseudoclassSelector(t,e){}pseudoelementSelector(t,e){}idSelector(t){}attributeSelector(t,e,n,s){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(t){}startFootnoteRule(t){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(t){}startWhenRule(t){}startMediaRule(t){this.startWhenRule(t)}startFlowRule(t){}startPageTemplateRule(){}startPageMasterRule(t,e,n){}startPartitionRule(t,e,n){}startPartitionGroupRule(t,e,n){}startRuleBody(){}property(t,e,n){}endRule(){}startFuncWithSelector(t,e){}endFuncWithSelector(){}pushSelectorText(t){}getImportantSpecificity(){switch(this.flavor){case"UA":return Wf;case"User":return Eb;default:return Sb}}getBaseSpecificity(){switch(this.flavor){case"UA":return Wf;case"User":return xb;default:return Iu}}},ya=class extends So{constructor(){super(null);p(this,"stack",[]);p(this,"tokenizer",null);p(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,n){this.slave.error(e,n)}errorMsg(e,n){var s;F.warn(e,(s=n==null?void 0:n.toString())!=null?s:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,n){this.slave.tagSelector(e,n)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,n){this.slave.pseudoclassSelector(e,n)}pseudoelementSelector(e,n){this.slave.pseudoelementSelector(e,n)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,n,s,i){this.slave.attributeSelector(e,n,s,i)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,n,s){this.slave.startPageMasterRule(e,n,s)}startPartitionRule(e,n,s){this.slave.startPartitionRule(e,n,s)}startPartitionGroupRule(e,n,s){this.slave.startPartitionGroupRule(e,n,s)}startRuleBody(){this.slave.startRuleBody()}property(e,n,s){this.slave.property(e,n,s)}endRule(){this.slave.endRule()}startFuncWithSelector(e,n){this.slave.startFuncWithSelector(e,n)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},xa=class extends So{constructor(e,n,s){super(e);this.owner=n;this.topLevel=s;p(this,"depth",0);n&&(this.flavor=n.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,n){var s;(s=this.owner)==null||s.errorMsg(e,n)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},bn=class extends xa{constructor(t,e,n){super(t,e,n)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.pushHandler(new xa(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(t,e){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(t,e,n){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ne=[],Sa=[],ce=[],Ee=[],$t=[],ct=[],we=[],Fe=[],le=[],De=[],st=[],Ve=[],Te=[];var Ai=55,Li=56,ba=57;Ne[1]=28,Ne[36]=29,Ne[7]=29,Ne[9]=29,Ne[14]=29,Ne[18]=29,Ne[50]=29,Ne[20]=30,Ne[13]=27,Ne[0]=200,Sa[1]=46,Sa[0]=200,ct[1]=2,ct[36]=4,ct[7]=6,ct[9]=8,ct[14]=10,ct[18]=14,ct[50]=42,ce[37]=11,ce[23]=12,ce[35]=56,ce[1]=1,ce[36]=3,ce[7]=5,ce[9]=7,ce[14]=9,ce[12]=13,ce[18]=55,ce[50]=58,ce[16]=41,Ee[37]=11,Ee[23]=12,Ee[35]=56,Ee[1]=1,Ee[36]=3,Ee[7]=5,Ee[9]=7,Ee[14]=9,Ee[18]=55,$t[1]=2,$t[36]=4,$t[7]=6,$t[9]=8,$t[18]=14,$t[50]=42,$t[14]=10,$t[12]=13,we[1]=15,we[7]=16,we[4]=17,we[5]=18,we[3]=19,we[2]=20,we[8]=21,we[27]=57,we[16]=22,we[19]=23,we[6]=24,we[11]=25,we[17]=26,we[13]=48,we[31]=47,we[23]=54,we[0]=44,Fe[1]=31,Fe[4]=32,Fe[5]=32,Fe[3]=33,Fe[2]=34,Fe[10]=40,Fe[6]=38,Fe[31]=36,Fe[24]=36,Fe[32]=35,le[1]=45,le[16]=37,le[37]=37,le[38]=37,le[47]=37,le[48]=37,le[39]=37,le[49]=37,le[41]=37,le[26]=37,le[25]=37,le[23]=37,le[24]=37,le[19]=37,le[21]=37,le[36]=37,le[18]=37,le[22]=37,le[11]=39,le[12]=43,le[17]=49,De[0]=200,De[12]=50,De[13]=51,De[14]=50,De[15]=51,De[10]=50,De[11]=51,De[17]=53,st[0]=200,st[12]=50,st[13]=52,st[14]=50,st[15]=51,st[10]=50,st[11]=51,st[17]=53,Ve[0]=200,Ve[12]=50,Ve[13]=51,Ve[14]=50,Ve[15]=51,Ve[10]=50,Ve[11]=51,Te[11]=0,Te[16]=0,Te[22]=1,Te[18]=1,Te[26]=2,Te[25]=2,Te[38]=3,Te[37]=3,Te[48]=3,Te[47]=3,Te[39]=3,Te[49]=3,Te[41]=3,Te[23]=4,Te[24]=4,Te[36]=5,Te[19]=5,Te[21]=5,Te[0]=6,Te[Ai]=2,Te[Li]=2;var is=class{constructor(t,e,n,s){this.actions=t;this.tokenizer=e;this.handler=n;this.baseURL=s;p(this,"valStack",[]);p(this,"namespacePrefixToURI",{});p(this,"defaultNamespaceURI",null);p(this,"propName",null);p(this,"propImportant",!1);p(this,"exprContext");p(this,"result",null);p(this,"importReady",!1);p(this,"importURL",null);p(this,"importCondition",null);p(this,"errorBrackets",[]);p(this,"ruleStack",[]);p(this,"regionRule",!1);p(this,"pageRule",!1);p(this,"inStyleDeclaration",!1);this.exprContext=2}extractVals(t,e){let n=[],s=this.valStack;for(;e<s.length&&(n.push(s[e++]),e!==s.length);){if(s[e++]!==t)throw new Error("Unexpected state");e===s.length&&n.push(U)}return n}valStackReduce(t,e){let n=this.valStack,s=n.length,i=0,o;do if(o=n[--s],t===")"&&o instanceof gn){if(o.text===")")i++;else if(o.text==="("){if(i===0)return null;i--}}while(typeof o!="undefined"&&typeof o!="string");let a=n.length-(s+1);if(a>1&&n.splice(s+1,a,new W(n.slice(s+1,n.length))),t==",")return null;s++;do o=n[--s];while(typeof o!="undefined"&&(typeof o!="string"||o==","));if(a=n.length-(s+1),o=="("){t!=")"&&e.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",e),this.actions=st);let c=new Xt(n[s-1],this.extractVals(",",s+1));if(n.splice(s-1,a+2,c),c.name==="var"){let u=c.values[0]instanceof j&&c.values[0].name;(!It(u)||u===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${c.toString()}`,e),this.actions=st)}return c}if(t!=";"||s>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=st,null;if(a>1)return new ge(this.extractVals(",",s+1));let l=n[0];return l instanceof ke?l:l?new gn(l.toString()):U}exprError(t,e){this.actions=this.propName?st:De,F.warn(t,e.toString())}exprStackReduce(t,e){let n=this.valStack,s=this.handler,i=n.pop(),o;for(;;){let a=n.pop();if(t==11){let l=[i];for(;a==16;)l.unshift(n.pop()),a=n.pop();if(typeof a=="string"){if(a=="{"){for(;l.length>=2;){let c=l.shift(),u=l.shift(),d=new Qr(s.getScope(),c,u);l.unshift(d)}return n.push(new O(l[0])),!0}else if(a=="("){let c=n.pop(),u=n.pop();i=new Ln(s.getScope(),go(u,c),l),t=0;continue}}if(a==10){i.isMediaName()&&(i=new fo(s.getScope(),i,null)),t=0;continue}}else if(typeof a=="string"){n.push(a);break}if(a<0)if(a==-31)i=new Lt(s.getScope(),i);else if(a==-24)i=new hn(s.getScope(),i);else if(a==-ba)i=new Kr(s.getScope(),i);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if(Te[t]>Te[a]){n.push(a);break}switch(o=n.pop(),a){case 26:i=new fi(s.getScope(),o,i);break;case Ai:i=new Zr(s.getScope(),o,i);break;case Li:i=new Jr(s.getScope(),o,i);break;case 25:i=new gi(s.getScope(),o,i);break;case 38:i=new ea(s.getScope(),o,i);break;case 37:i=new na(s.getScope(),o,i);break;case 48:i=new ta(s.getScope(),o,i);break;case 47:i=new Is(s.getScope(),o,i);break;case 39:case 49:i=new Jn(s.getScope(),o,i);break;case 41:i=new sa(s.getScope(),o,i);break;case 23:i=new co(s.getScope(),o,i);break;case 24:i=new uo(s.getScope(),o,i);break;case 36:i=new Vs(s.getScope(),o,i);break;case 19:i=new po(s.getScope(),o,i);break;case 21:i=new mi(s.getScope(),o,i);break;case 18:if(n.length>1)switch(n[n.length-1]){case 22:n.pop(),i=new ia(s.getScope(),n.pop(),o,i);break;case 10:if(o.isMediaName())i=new fo(s.getScope(),o,i);else return this.exprError("E_CSS_MEDIA_TEST",e),!1;break}else return this.exprError("E_CSS_EXPR_COND",e),!1;break;case 22:if(t!=18)return this.exprError("E_CSS_EXPR_COND",e),!1;case 10:return n.push(o),n.push(a),n.push(i),!1;default:return this.exprError("F_UNEXPECTED_STATE",e),!1}}}return n.push(i),!1}readSupportsTest(t){let e=t.type===6,n=this.tokenizer,s,i;if(e)i=t.text,s=t.position+i.length+1;else if(t.type===10){let h=n.nthToken(1),f=n.nthToken(2);if(h.type===1&&f.type===18)n.consume(),n.consume(),i=h.text,s=f.position+1;else{if(h.type===10||h.type===6||h.type===1&&h.text.toLowerCase()==="not"&&(f.type===10||f.type===6))return null;s=t.position+1}}else return null;let o=0,a,l=0;for(;o>=0;)switch(n.consume(),a=n.token(),a.type){case 11:o--;break;case 10:case 6:o++;break;case 16:o===0&&l++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",a),null}n.consume();let c=a.position,u=e&&i==="selector"&&l>0?"":n.input.substring(s,c).trim();return new oa(this.handler.getScope(),i,u,e)}readPseudoParams(){let t=[];for(;;){let e=this.tokenizer.token();switch(e.type){case 1:t.push(e.text);break;case 23:t.push("+");break;case 4:case 5:t.push(e.num);break;default:return t}this.tokenizer.consume()}}readNthPseudoParams(){let t=!1,e=this.tokenizer.token();if(e.type===23)t=!0,this.tokenizer.consume(),e=this.tokenizer.token();else if(e.type===1&&(e.text==="even"||e.text==="odd"))return this.tokenizer.consume(),[2,e.text==="odd"?1:0];switch(e.type){case 3:if(t&&e.num<0)return null;case 1:if(t&&e.text.charAt(0)==="-")return null;if(e.text==="n"||e.text==="-n"){if(t&&e.precededBySpace)return null;let n=e.text==="-n"?-1:1;e.type===3&&(n=e.num);let s=0;this.tokenizer.consume(),e=this.tokenizer.token();let i=e.type===24,o=e.type===23||i;if(o&&(this.tokenizer.consume(),e=this.tokenizer.token()),e.type===5){if(s=e.num,1/s===-1/0){if(s=0,o)return null}else if(s<0){if(o)return null}else if(s>=0&&!o)return null;this.tokenizer.consume()}else if(o)return null;return[n,i&&s>0?-s:s]}else if(e.text==="n-"||e.text==="-n-"){if(t&&e.precededBySpace)return null;let n=e.text==="-n-"?-1:1;if(e.type===3&&(n=e.num),this.tokenizer.consume(),e=this.tokenizer.token(),e.type===5)return e.num<0||1/e.num===-1/0?null:(this.tokenizer.consume(),[n,e.num])}else{let n=e.text.match(/^n(-[0-9]+)$/);if(n)return t&&e.precededBySpace?null:(this.tokenizer.consume(),[e.type===3?e.num:1,parseInt(n[1],10)]);if(n=e.text.match(/^-n(-[0-9]+)$/),n)return this.tokenizer.consume(),[-1,parseInt(n[1],10)]}return null;case 5:return t&&(e.precededBySpace||e.num<0)?null:(this.tokenizer.consume(),[0,e.num])}return null}makeCondition(t,e){let n=this.handler.getScope();if(!n)return null;if(e=e||n._true,t){let s=t.split(/\s+/);for(let i of s)switch(i){case"vertical":e=lt(n,e,new Lt(n,new oe(n,"pref-horizontal")));break;case"horizontal":e=lt(n,e,new oe(n,"pref-horizontal"));break;case"day":e=lt(n,e,new Lt(n,new oe(n,"pref-night-mode")));break;case"night":e=lt(n,e,new oe(n,"pref-night-mode"));break;default:e=n._false}}return e===n._true?null:new O(e)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(t,e,n,s,i,o){let a=this.handler,l=this.tokenizer,c=this.valStack,u,d,h,f,g,m,y,S=null;for(n&&(this.inStyleDeclaration=!0),s&&(this.exprContext=2,this.valStack.push("{"));t>0;--t){if(u=l.token(),i&&S===null&&(S=u.position-1,l.input[S]==="("&&S++),this.actions===we&&this.errorBrackets.length>0&&(u.type===this.errorBrackets[this.errorBrackets.length-1]||u.type===17||u.type===31)){if(u.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),u.type===11&&this.valStackReduce(")",u))){l.consume();continue}c.push(new gn(u.toString())),l.consume();continue}switch(this.actions[u.type]){case 28:if(!this.inStyleDeclaration||l.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(a.error("E_CSS_COLON_EXPECTED",l.nthToken(1)),this.actions=st):(this.actions=ct,a.startSelectorRule());continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=we,c.splice(0,c.length);continue;case 46:if(l.nthToken(1).type!=18){this.actions=st,a.error("E_CSS_COLON_EXPECTED",l.nthToken(1));continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=we,c.splice(0,c.length);continue;case 29:this.actions=ct,a.startSelectorRule();continue;case 1:if(!u.precededBySpace){this.actions=Ve,a.error("E_CSS_SPACE_EXPECTED",u);continue}a.descendantSelector();case 2:if(l.nthToken(1).type==34)if(l.consume(),l.consume(),h=this.namespacePrefixToURI[u.text],h!=null)switch(u=l.token(),u.type){case 1:a.tagSelector(h,u.text),i?this.actions=Ee:this.actions=ce,l.consume();break;case 36:a.tagSelector(h,null),i?this.actions=Ee:this.actions=ce,l.consume();break;default:this.actions=De,a.error("E_CSS_NAMESPACE",u)}else this.actions=De,a.error("E_CSS_UNDECLARED_PREFIX",u);else a.tagSelector(this.defaultNamespaceURI,u.text),i?this.actions=Ee:this.actions=ce,l.consume();continue;case 3:if(!u.precededBySpace){this.actions=Ve,a.error("E_CSS_SPACE_EXPECTED",u);continue}a.descendantSelector();case 4:if(l.nthToken(1).type==34)switch(l.consume(),l.consume(),u=l.token(),u.type){case 1:a.tagSelector(null,u.text),i?this.actions=Ee:this.actions=ce,l.consume();break;case 36:a.tagSelector(null,null),i?this.actions=Ee:this.actions=ce,l.consume();break;default:this.actions=De,a.error("E_CSS_NAMESPACE",u)}else a.tagSelector(this.defaultNamespaceURI,null),i?this.actions=Ee:this.actions=ce,l.consume();continue;case 5:u.precededBySpace&&a.descendantSelector();case 6:if(!u.text){a.error("E_CSS_SYNTAX",u),l.consume();continue}a.idSelector(u.text),i?this.actions=Ee:this.actions=ce,l.consume();continue;case 7:u.precededBySpace&&a.descendantSelector();case 8:a.classSelector(u.text),i?this.actions=Ee:this.actions=ce,l.consume();continue;case 55:u.precededBySpace&&a.descendantSelector();case 14:l.consume(),u=l.token();e:switch(u.type){case 1:a.pseudoclassSelector(u.text,null),l.consume(),i?this.actions=Ee:this.actions=ce;continue;case 6:switch(f=u.text,l.consume(),f){case"is":case"not":case"where":case"has":this.actions=ct,a.startFuncWithSelector(f),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,f==="has")?this.actions=ce:this.actions=Ve;continue;case"lang":case"href-epub-type":if(u=l.token(),u.type===1){y=[u.text],l.consume(),f==="href-epub-type"&&l.token().type===16&&(l.consume(),u=l.token(),u.type===1&&(y.push(u.text),l.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(y=this.readNthPseudoParams(),y)if(f==="nth-child"||f==="nth-last-child"){if(d=l.nthToken(0),d.type===1&&d.text==="of"){l.consume(),this.actions=ct,a.startFuncWithSelector(f,y),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?i?this.actions=Ee:this.actions=ce:this.actions=Ve;continue}break}else if(f==="nth"){if(d=l.nthToken(0),d.type===1&&d.text==="of")if(l.consume(),d=l.token(),d.type===1)y.push(d.text),l.consume();else break e;break}else break;else break e;default:y=this.readPseudoParams()}if(u=l.token(),u.type==11){a.pseudoclassSelector(f,y),l.consume(),i?this.actions=Ee:this.actions=ce;continue}break}a.error("E_CSS_PSEUDOCLASS_SYNTAX",u),this.actions=De;continue;case 58:u.precededBySpace&&a.descendantSelector();case 42:switch(l.consume(),u=l.token(),u.type){case 1:a.pseudoelementSelector(u.text,null),i?this.actions=Ee:this.actions=ce,l.consume();continue;case 6:if(f=u.text,l.consume(),f=="nth-fragment"){if(y=this.readNthPseudoParams(),y===null)break}else y=this.readPseudoParams();if(u=l.token(),u.type==11){a.pseudoelementSelector(f,y),i?this.actions=Ee:this.actions=ce,l.consume();continue}break}a.error("E_CSS_PSEUDOELEM_SYNTAX",u),this.actions=De;continue;case 9:u.precededBySpace&&a.descendantSelector();case 10:if(l.consume(),u=l.token(),u.type==1)f=u.text,l.consume();else if(u.type==36)f=null,l.consume();else if(u.type==34)f="";else{this.actions=Ve,a.error("E_CSS_ATTR",u),l.consume();continue}if(u=l.token(),u.type==34){if(h=f&&this.namespacePrefixToURI[f],h===void 0){this.actions=Ve,a.error("E_CSS_UNDECLARED_PREFIX",u),l.consume();continue}if(l.consume(),u=l.token(),u.type!=1){this.actions=Ve,a.error("E_CSS_ATTR_NAME_EXPECTED",u);continue}f=u.text,l.consume(),u=l.token()}else h="";switch(u.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:g=u.type,l.consume(),u=l.token();break;case 15:a.attributeSelector(h,f,0,null),i?this.actions=Ee:this.actions=ce,l.consume();continue;default:this.actions=Ve,a.error("E_CSS_ATTR_OP_EXPECTED",u);continue}switch(u.type){case 1:case 2:a.attributeSelector(h,f,g,u.text),l.consume(),u=l.token();break;default:this.actions=Ve,a.error("E_CSS_ATTR_VAL_EXPECTED",u);continue}if(u.type!=15){this.actions=Ve,a.error("E_CSS_ATTR",u);continue}i?this.actions=Ee:this.actions=ce,l.consume();continue;case 11:a.childSelector(),this.actions=$t,l.consume();continue;case 12:a.adjacentSiblingSelector(),this.actions=$t,l.consume();continue;case 56:a.followingSiblingSelector(),this.actions=$t,l.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),a.startRuleBody(),this.actions=Ne,l.consume();continue;case 41:a.nextSelector(),this.actions=ct,l.consume();continue;case 15:c.push(k(u.text)),l.consume();continue;case 16:g=parseInt(u.text,16),c.push(new yi(u.text)),l.consume();continue;case 17:c.push(new nt(u.num)),l.consume();continue;case 18:c.push(new se(u.num)),l.consume();continue;case 19:c.push(new P(u.num,u.text)),l.consume();continue;case 20:c.push(new D(u.text)),l.consume();continue;case 21:c.push(new fe(te(u.text,this.baseURL))),l.consume();continue;case 57:c.push(new Co(u.text)),l.consume();continue;case 22:this.valStackReduce(",",u),c.push(","),l.consume();continue;case 23:c.push(xi),l.consume();continue;case 24:f=u.text.toLowerCase(),f=="-epubx-expr"||f=="env"?(this.actions=Fe,this.exprContext=0,c.push("{")):(c.push(f),c.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),l.consume();continue;case 25:this.valStackReduce(")",u),l.consume();continue;case 47:if(l.consume(),u=l.token(),d=l.nthToken(1),u.type==1&&u.text.toLowerCase()=="important"&&(d.type==17||d.type==0||d.type==13)){l.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",u);continue;case 54:switch(d=l.nthToken(1),d.type){case 4:case 3:case 5:if(!d.precededBySpace){l.consume();continue}}c.push(new gn("+")),l.consume();continue;case 26:l.consume();case 48:m=this.valStackReduce(";",u),m&&this.propName&&a.property(this.propName,m,this.propImportant),this.actions=n?Sa:Ne;continue;case 44:for(l.consume();c.length>0;){let C=c.length;if(m=this.valStackReduce(";",u),!m||c.length===C)break}return e?(this.result=m,!0):(this.propName&&m&&a.property(this.propName,m,this.propImportant),!0);case 31:if(d=l.nthToken(1),d.type==9)l.nthToken(2).type==10&&!l.nthToken(2).precededBySpace?(c.push(u.text,d.text,"("),l.consume()):(c.push(new oe(a.getScope(),go(u.text,d.text))),this.actions=le),l.consume();else{if(this.exprContext==2||this.exprContext==3)u.text.toLowerCase()=="not"?(l.consume(),c.push(new ho(a.getScope(),!0,d.text))):(u.text.toLowerCase()=="only"&&(l.consume(),u=d),c.push(new ho(a.getScope(),!1,u.text)));else if(this.exprContext===4&&u.text.toLowerCase()==="not"&&c[c.length-1]!==Ai&&c[c.length-1]!==Li&&(d.type===10||d.type===6)){c.push(-ba),l.consume();continue}else c.push(new oe(a.getScope(),u.text));this.actions=le}l.consume();continue;case 38:if(this.exprContext===4){c.push(this.readSupportsTest(u)),this.actions=le;continue}c.push(null,u.text,"("),l.consume();continue;case 32:c.push(new de(a.getScope(),u.num)),l.consume(),this.actions=le;continue;case 33:f=u.text,f=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?f="vh":f="vw"),c.push(new en(a.getScope(),u.num,f)),l.consume(),this.actions=le;continue;case 34:c.push(new de(a.getScope(),u.text)),l.consume(),this.actions=le;continue;case 35:l.consume(),u=l.token(),u.type!=5||u.precededBySpace?this.exprError("E_CSS_SYNTAX",u):(c.push(new Ci(a.getScope(),u.num)),l.consume(),this.actions=le);continue;case 36:c.push(-u.type),l.consume();continue;case 37:this.actions=Fe,this.exprStackReduce(u.type,u),c.push(u.type),l.consume();continue;case 45:u.text.toLowerCase()==="and"&&c[c.length-2]!==Li&&c[c.length-2]!==-ba?(this.actions=Fe,this.exprStackReduce(Ai,u),c.push(Ai),l.consume()):u.text.toLowerCase()==="or"&&c[c.length-2]!==Ai&&c[c.length-2]!==-ba?(this.actions=Fe,this.exprStackReduce(Li,u),c.push(Li),l.consume()):this.exprError("E_CSS_SYNTAX",u);continue;case 39:this.exprStackReduce(u.type,u)&&(this.actions=we),l.consume();continue;case 43:this.exprStackReduce(11,u)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",u):(this.exprContext==1?a.startWhenRule(c.pop()):a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Ne)),l.consume();continue;case 49:if(this.exprStackReduce(11,u))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",u),this.actions=Ne,l.consume(),!1):(this.importCondition=c.pop(),this.importReady=!0,this.actions=Ne,l.consume(),!1);l.consume();continue;case 40:if(this.exprContext===4){let C=this.readSupportsTest(u);if(C){c.push(C),this.actions=le;continue}}c.push(u.type),l.consume();continue;case 27:if(this.actions=Ne,l.consume(),a.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(f=u.text.toLowerCase(),f){case"import":if(l.consume(),u=l.token(),u.type==2||u.type==8){if(this.importURL=u.text,l.consume(),u=l.token(),u.type==17||u.type==0)return this.importReady=!0,l.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Fe,c.push("{");continue}a.error("E_CSS_IMPORT_SYNTAX",u),this.actions=De;continue;case"namespace":switch(l.consume(),u=l.token(),u.type){case 1:if(f=u.text,l.consume(),u=l.token(),(u.type==2||u.type==8)&&l.nthToken(1).type==17){this.namespacePrefixToURI[f]=u.text,l.consume(),l.consume();continue}break;case 2:case 8:if(l.nthToken(1).type==17){this.defaultNamespaceURI=u.text,l.consume(),l.consume();continue}break}a.error("E_CSS_NAMESPACE_SYNTAX",u),this.actions=De;continue;case"charset":if(l.consume(),u=l.token(),u.type==2&&l.nthToken(1).type==17){f=u.text.toLowerCase(),f!="utf-8"&&f!="utf-16"&&a.error(`E_CSS_UNEXPECTED_CHARSET ${f}`,u),l.consume(),l.consume();continue}a.error("E_CSS_CHARSET_SYNTAX",u),this.actions=De;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(l.nthToken(1).type==12){switch(l.consume(),l.consume(),f){case"font-face":a.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":a.startPageTemplateRule();break;case"-epubx-define":a.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":a.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(f),a.startRuleBody();continue}break;case"-adapt-footnote-area":switch(l.consume(),u=l.token(),u.type){case 12:l.consume(),a.startFootnoteRule(null),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(l.consume(),u=l.token(),u.type==1&&l.nthToken(1).type==12){f=u.text,l.consume(),l.consume(),a.startFootnoteRule(f),this.ruleStack.push("-adapt-footnote-area"),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":l.consume(),a.startRegionRule(),this.regionRule=!0,this.actions=ct;continue;case"page":l.consume(),a.startPageRule(),this.pageRule=!0,this.actions=$t;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(l.consume(),u=l.token(),u.type==12){l.consume(),a.startPageMarginBoxRule(f),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":l.consume(),this.propName=null,this.exprContext=1,this.actions=Fe,c.push("{");continue;case"media":l.consume(),this.propName=null,this.exprContext=2,this.actions=Fe,c.push("{");continue;case"supports":l.consume(),this.propName=null,this.exprContext=4,this.actions=Fe,c.push("{");continue;case"-epubx-flow":if(l.nthToken(1).type==1&&l.nthToken(2).type==12){a.startFlowRule(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(l.nthToken(1).type==1&&l.nthToken(2).type==12){a.startCounterStyleRule(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{l.consume(),u=l.token();let C=null,x=null,N=[];for(u.type==1&&(C=u.text,l.consume(),u=l.token()),u.type==18&&l.nthToken(1).type==1&&(x=l.nthToken(1).text,l.consume(),l.consume(),u=l.token());u.type==6&&u.text.toLowerCase()=="class"&&l.nthToken(1).type==1&&l.nthToken(2).type==11;)N.push(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),u=l.token();if(u.type==12){switch(l.consume(),f){case"-epubx-page-master":a.startPageMasterRule(C,x,N);break;case"-epubx-partition":a.startPartitionRule(C,x,N);break;case"-epubx-partition-group":a.startPartitionGroupRule(C,x,N);break}this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":a.error(`E_CSS_UNEXPECTED_AT${f}`,u),this.actions=Ve;continue;default:a.error(`E_CSS_AT_UNKNOWN ${f}`,u),this.actions=De;continue}a.error(`E_CSS_AT_SYNTAX ${f}`,u),this.actions=De;continue;case 50:this.errorBrackets.push(u.type+1),l.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ne;continue}case 51:if(i&&this.errorBrackets.length==0&&u.type==11)return l.consume(),a.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==u.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&u.type==13&&(this.actions=Ne),l.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ne),l.consume();continue;case 200:return!0;default:if(s)return this.exprStackReduce(11,u)?(this.result=c.pop(),!0):!1;if(i){switch(u.type){case 16:case 11:if(this.actions===ct)a.error("E_CSS_SYNTAX",u);else{let C=l.input.substring(S,u.position);a.pushSelectorText(C),S=u.position+1}if(u.type===16){a.nextSelector(),this.actions=ct,l.consume();continue}else return a.endFuncWithSelector(),l.consume(),!0;case 37:case 23:case 35:if(o){this.actions=ce;continue}break;case 12:case 14:case 10:this.errorBrackets.push(u.type+1);break}a.error("E_CSS_SYNTAX",u),l.consume(),this.actions=Ve;continue}if(this.actions!==De&&this.actions!==Ve&&this.actions!==st){if(u.type==54)a.error("E_CSS_SYNTAX",u);else if(this.actions===we){switch(u.type){case 10:case 12:case 14:this.errorBrackets.push(u.type+1);break}c.push(new gn(u.toString())),l.consume();continue}else if(u.type===12&&this.actions==Fe&&c.length>0){a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Ne,l.consume();continue}else{if(u.type===17&&this.actions==Fe)return this.actions=Ne,l.consume(),!1;a.error("E_CSS_SYNTAX",u)}this.isInsidePropertyOnlyRule()?this.actions=st:this.actions=Ve;continue}l.consume();continue}}return!1}},Eo=class extends So{constructor(e){super(null);this.scope=e}error(e,n){F.warn(e,n.toString())}getScope(){return this.scope}};function Nb(r,t,e,n,s){let i=A("parseStylesheet"),o=new is(Ne,r,t,e),a=null;return s&&(a=vb(new Ge(s,t),t,e)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),i.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let c=te(o.importURL,e);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=A("parseStylesheet.import");return Vu(c,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let l=i.timeSlice();if(l.isPending)return l}return T(!1)}).then(()=>{a&&t.endRule(),i.finish(!0)}),i.result()}function va(r,t,e,n,s){return In("parseStylesheetFromText",i=>{let o=new Ge(r,t);Nb(o,t,e,n,s).thenFinish(i)},(i,o)=>{F.warn(o,`Failed to parse stylesheet text: ${r}`),i.finish(!1)})}function Vu(r,t,e,n){return In("parseStylesheetFromURL",s=>{_s(r).then(i=>{i.responseText?va(i.responseText,t,r,e,n).then(o=>{o||F.warn(`Failed to parse stylesheet from ${r}`),s.finish(!0)}):s.finish(!0)})},(s,i)=>{F.warn(i,"Exception while fetching and parsing:",r),s.finish(!0)})}function yn(r,t,e){let n=new is(we,t,new Eo(r),e);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function $f(r,t,e){new is(Sa,r,t,e).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function vb(r,t,e){let n=new is(Fe,r,t,e);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Tb={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function wb(r){return!!Tb[r]}function jf(r,t,e){if(t instanceof ne&&t.str==="viv-leader")return new O(t);let n=t.evaluate(r);switch(typeof n){case"number":return wb(e)?n==Math.round(n)?new se(n):new nt(n):new P(n,"px");case"string":return n?yn(t.scope,new Ge(n,null),""):U;case"boolean":return n?b._true:b._false;case"undefined":return U}throw new Error("E_UNEXPECTED")}function Yf(r,t){let e={};return Object.keys(r).forEach(n=>{let s=e[n]={},i=r[n];Object.keys(i).forEach(o=>{s[o]=i[o].map(a=>{let l=t?a.logical:a.physical,c=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${l}(-?)`),to:`$1${c}$2`}})})}),e}function qf(r,t,e,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let i=s[e||"ltr"];if(!i)throw new Error(`unknown direction: ${e}`);for(let o of i){let a=r.replace(o.regexp,o.to);if(a!==r)return a}return r}var Kf={"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"}]}},Pb=Yf(Kf,!0);function Fu(r,t,e){return qf(r,t,e||null,Pb)}var kb=Yf(Kf,!1);function Bu(r,t,e){return qf(r,t,e||null,kb)}var Ab={"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 Zf(r,t){let e=Ab[t];if(!e)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<e.length;n++)if(e[n].physical===r)return e[n].logical;return r}function Ri(r,t,e){var h;let n=t,s={width:n.style.width,height:n.style.height};function i(f){return r.getElementComputedStyle(t).getPropertyValue(f)}let a=i("writing-mode")!=="horizontal-tb",l=a?"height":"width",c=a?"width":"height";function u(f,g){n.style[f]=g;let m=i(f);return n.style[f]=s[f],m}let d={};for(let f of e){let g;switch(f){case"max-content inline size":g=u(l,"max-content");break;case"min-content inline size":g=u(l,"min-content");break;case"fit-content inline size":g=u(l,"fit-content");break;case"max-content block size":g=u(c,"max-content");break;case"min-content block size":g=u(c,"min-content");break;case"fit-content block size":g=u(c,"fit-content");break;case"max-content width":g=u("width","max-content");break;case"max-content height":g=u("height","max-content");break;case"min-content width":g=u("width","min-content");break;case"min-content height":g=u("height","min-content");break;case"fit-content width":g=u("width","fit-content");break;case"fit-content height":g=u("height","fit-content");break}g==="0px"&&t.childNodes.length===1&&((h=t.firstElementChild)==null?void 0:h.localName)==="img"&&!t.firstElementChild.complete&&(g="1px"),d[f]=parseFloat(g)}return d}function zs(r){var t,e;return((t=r==null?void 0:r.style)==null?void 0:t["box-decoration-break"])==="clone"||((e=r==null?void 0:r.style)==null?void 0:e["-webkit-box-decoration-break"])==="clone"}function Du(r){let t=r.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Mu(r,t){r.setAttribute("data-viv-box-break",t.join(" "))}function Et(r,t){let e=Du(r);e.includes(t)||(e.push(t),Mu(r,e))}function Rb(r){let t=r.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Ib(r,t){r.setAttribute("data-viv-margin-discard",t.join(" "))}function Ta(r,t){let e=Rb(r);e.includes(t)||(e.push(t),Ib(r,e))}function Vb(r){let t=r.name,e=r.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:e===b.always?b.page:e,important:r.important};default:return r}}var wa={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Me(r){return!!wa[r]}var Fb={left:!0,right:!0,recto:!0,verso:!0};function os(r){return!!Fb[r]}var Bb={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ii(r){return!!Bb[r]}function _e(r,t){if(r)if(t){if(os(t))return t;if(os(r))return r;{let e=Me(r),n=Me(t);if(e&&n)switch(t){case"column":return r;case"region":return r==="column"?t:r;default:return t}else return n?t:e?r:Ii(t)?t:Ii(r)?r:t}}else return r;else return t}function _u(r){return Me(r)?r:"auto"}je("SIMPLE_PROPERTY",Vb);var Vi=wC(lg());function cg(r,t){return(0,Vi.default)(r,t,0)}function Gu(r){return r.reduce((t,e)=>e[0]===Vi.default.DELETE?t:t+e[1],"")}function ug(r,t){return pg(r,t,1)}function dg(r,t){return pg(r,t,-1)}function pg(r,t,e){let n=0,s=0;return r.some(i=>{for(let o=0;o<i[1].length;o++){switch(i[0]*e){case Vi.default.INSERT:n++;break;case Vi.default.DELETE:n--,s++;break;case Vi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Aa;(t=>{function r(e){return e&&e.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=r})(Aa||(Aa={}));var rs;(t=>{let r;(o=>(o.INLINE="inline",o.COLUMN="column",o.REGION="region",o.PAGE="page"))(r=t.FloatReference||(t.FloatReference={}))})(rs||(rs={}));var vo;(t=>{function r(e){return e&&e.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=r})(vo||(vo={}));var xn;(e=>{function r(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||sn.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=r;function t(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||sn.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=t})(xn||(xn={}));var sn;(e=>{function r(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=r;function t(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=t})(sn||(sn={}));var jt;(e=>{let r;(o=>(o[o.IGNORE=0]="IGNORE",o[o.NEWLINE=1]="NEWLINE",o[o.PRESERVE=2]="PRESERVE"))(r=e.Whitespace||(e.Whitespace={}));let t;(a=>(a[a.NONE=0]="NONE",a[a.CONTENT=1]="CONTENT",a[a.ROOTLESS=2]="ROOTLESS",a[a.ROOTED=3]="ROOTED"))(t=e.ShadowType||(e.ShadowType={}))})(jt||(jt={}));var hg={transform:!0,"transform-origin":!0},fg={top:!0,bottom:!0,left:!0,right:!0},ls=class{constructor(t,e,n){this.target=t;this.name=e;this.value=n}},Xb={show:function(r){r.style.visibility="visible"},hide:function(r){r.style.visibility="hidden"},play:function(r){r.currentTime=0,r.play()},pause:function(r){r.pause()},resume:function(r){r.play()},mute:function(r){r.muted=!0},unmute:function(r){r.muted=!1}};function $b(r,t){let e=Xb[t];return e?()=>{for(let n=0;n<r.length;n++)try{e(r[n])}catch(s){}}:null}var as=class as extends Kn{constructor(e,n){super();this.container=e;this.bleedBox=n;p(this,"pageAreaElement",null);p(this,"delayedItems",[]);p(this,"hrefHandler");p(this,"elementsById",{});p(this,"dimensions",{width:0,height:0});p(this,"isFirstPage",!1);p(this,"isLastPage",!1);p(this,"isBlankPage",!1);p(this,"isAutoPageWidth",!0);p(this,"isAutoPageHeight",!0);p(this,"spineIndex",0);p(this,"position",null);p(this,"offset",-1);p(this,"side",null);p(this,"fetchers",[]);p(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}});p(this,"pageType",null);this.hrefHandler=s=>{let i=s.currentTarget,o=i.getAttribute("href")||i.getAttributeNS("http://www.w3.org/1999/xlink","href");if(o){let a={type:"hyperlink",target:null,currentTarget:null,anchorElement:i,href:o,preventDefault(){s.preventDefault()}};this.dispatchEvent(a)}}}setAutoPageWidth(e){this.isAutoPageWidth=e,e?this.container.setAttribute(as.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(as.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(as.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(as.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(e,n){let s=this.elementsById[n];s?s.push(e):this.elementsById[n]=[e]}finish(e,n){Object.keys(this.elementsById).forEach(o=>{let a=this.elementsById[o];for(let l=0;l<a.length;)this.container.contains(a[l])?l++:a.splice(l,1);a.length===0&&delete this.elementsById[o]});let s=this.delayedItems;for(let o=0;o<s.length;o++){let a=s[o];a.target===this.container&&a.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||w(a.target,a.name,a.value.toString())}let i=n.getElementClientRect(this.container);this.dimensions.width=i.width,this.dimensions.height=i.height;for(let o=0;o<e.length;o++){let a=e[o],l=this.elementsById[a.ref],c=this.elementsById[a.observer];if(l&&c){let u=$b(l,a.action);if(u)for(let d=0;d<c.length;d++)c[d].addEventListener(a.event,u,!1)}}}};p(as,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),p(as,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Fi=as,it=jt.Whitespace;function Oa(r){switch(r){case"normal":case"nowrap":return it.IGNORE;case"pre-line":return it.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return it.PRESERVE;default:return null}}function me(r,t){if(!r)return!0;if(r.nodeType==1)return!1;let e=r.textContent;switch(t){case it.PRESERVE:return e.length==0;case it.NEWLINE:return!!e.match(/^[ \t]*$/);case it.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var La=class{constructor(t,e){this.flowName=t;this.parentFlowName=e;p(this,"forcedBreakOffsets",[]);p(this,"formattingContext",null)}},Ra=class{constructor(t,e,n,s,i,o,a,l,c){this.flowName=t;this.element=e;this.startOffset=n;this.priority=s;this.linger=i;this.exclusive=o;this.repeated=a;this.last=l;this.breakBefore=c;p(this,"startPage",-1)}isBetter(t){return this.exclusive?!t.exclusive||this.priority>t.priority?!0:this.last:!1}};function gg(r,t){return r.top-t.top}function mg(r,t){return t.right-r.right}function Cg(r,t){var e,n;return r===t?!0:!r||!t?!1:(r.node===t.node||!!r.shadowContext&&!!t.shadowContext&&r.shadowType===jt.ShadowType.ROOTLESS&&t.shadowType===jt.ShadowType.ROOTLESS&&((e=r.node)==null?void 0:e.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&r.shadowType===t.shadowType&&Xu(r.shadowContext,t.shadowContext)&&Xu(r.nodeShadow,t.nodeShadow)&&Cg(r.shadowSibling,t.shadowSibling)}function on(r,t){if(r===t)return!0;if(!r||!t||r.offsetInNode!==t.offsetInNode||r.after!==t.after||r.steps.length!==t.steps.length)return!1;for(let e=0;e<r.steps.length;e++)if(!Cg(r.steps[e],t.steps[e]))return!1;return!0}function bg(r){return{steps:[{node:r,shadowType:Bt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Xs(r,t){return{steps:[{node:r.sourceNode,shadowType:Bt.NONE,shadowContext:r.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t!=null?t:r.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:r.preprocessedTextContent}}function Oi(r,t){let e=new cs(r.node,t,0);return e.shadowType=r.shadowType,e.shadowContext=r.shadowContext,e.nodeShadow=r.nodeShadow,e.shadowSibling=r.shadowSibling?Oi(r.shadowSibling,t.copy()):null,e.formattingContext=r.formattingContext,e.fragmentIndex=r.fragmentIndex+1,e}var Bt=jt.ShadowType,Ws=class{constructor(t,e,n,s,i,o,a){this.owner=t;this.root=e;this.xmldoc=n;this.parentShadow=s;this.type=o;this.styler=a;p(this,"subShadow",null);i&&(i.subShadow=this)}equals(t){return t?this.owner===t.owner&&this.xmldoc===t.xmldoc&&this.type===t.type&&Xu(this.parentShadow,t.parentShadow):!1}};function Xu(r,t){return r===t||!!r&&!!t&&r.equals(t)}var Ia=class{constructor(t,e){this.outer=t;this.count=e}},cs=class r{constructor(t,e,n){this.sourceNode=t;this.parent=e;this.boxOffset=n;p(this,"offsetInNode",0);p(this,"after",!1);p(this,"shadowType");p(this,"shadowContext");p(this,"nodeShadow",null);p(this,"shadowSibling",null);p(this,"shared",!1);p(this,"inline",!0);p(this,"overflow",!1);p(this,"breakPenalty");p(this,"display",null);p(this,"floatReference");p(this,"floatSide",null);p(this,"clearSide",null);p(this,"floatMinWrapBlock",null);p(this,"columnSpan",null);p(this,"verticalAlign","baseline");p(this,"captionSide","top");p(this,"inlineBorderSpacing",0);p(this,"blockBorderSpacing",0);p(this,"flexContainer",!1);p(this,"whitespace");p(this,"hyphenateCharacter");p(this,"breakWord");p(this,"establishesBFC",!1);p(this,"containingBlockForAbsolute",!1);p(this,"breakBefore",null);p(this,"breakAfter",null);p(this,"viewNode",null);p(this,"clearSpacer",null);p(this,"inheritedProps");p(this,"vertical");p(this,"direction");p(this,"firstPseudo");p(this,"lang",null);p(this,"preprocessedTextContent",null);p(this,"formattingContext");p(this,"repeatOnBreak",null);p(this,"pluginProps",{});p(this,"fragmentIndex",1);p(this,"afterIfContinues",null);p(this,"footnotePolicy",null);p(this,"pageType");this.shadowType=Bt.NONE,this.shadowContext=e?e.shadowContext:null,this.breakPenalty=e?e.breakPenalty:0,this.floatReference=rs.FloatReference.INLINE,this.whitespace=e?e.whitespace:it.IGNORE,this.hyphenateCharacter=e?e.hyphenateCharacter:null,this.breakWord=e?e.breakWord:!1,this.inheritedProps=e?e.inheritedProps:{},this.vertical=e?e.vertical:!1,this.direction=e?e.direction:"ltr",this.firstPseudo=e?e.firstPseudo:null,this.formattingContext=e?e.formattingContext:null,this.pageType=e?e.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=rs.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:it.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 r(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(),e=t,n;for(;(n=e.parent)!=null;)n=n.cloneItem(),e.parent=n,e=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var s,i,o;let t=this,e=[];t.shadowType===jt.ShadowType.ROOTLESS&&(t.floatReference!==rs.FloatReference.INLINE||t.floatSide==="footnote")&&((o=(i=(s=t.shadowContext)==null?void 0:s.styler)==null?void 0:i.style)!=null&&o._pseudos)&&(t=t.parent);do(!t.firstPseudo||!t.parent||t.parent.firstPseudo===t.firstPseudo)&&e.push(t.toNodePositionStep()),t=t.parent;while(t);let n=this.preprocessedTextContent?dg(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:e,offsetInNode:n,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}},Nt=class r{constructor(t){this.primary=t;p(this,"floats",null)}clone(){let t=new r(this.primary);if(this.floats){t.floats=[];for(let e=0;e<this.floats.length;++e)t.floats[e]=this.floats[e]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!on(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let e=0;e<this.floats.length;e++)if(!on(this.floats[e],t.floats[e]))return!1}else if(t.floats)return!1;return!0}},Va=class r{constructor(t,e){this.chunkPosition=t;this.flowChunk=e}clone(){return new r(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Fa=class r{constructor(){p(this,"positions",[]);p(this,"startBreakType",null);p(this,"breakAfter",null)}clone(){let t=new r,e=this.positions,n=t.positions;for(let s=0;s<e.length;s++)n[s]=e[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 e=0;e<this.positions.length;e++)if(!this.positions[e].isSamePosition(t.positions[e]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Ba=class r{constructor(){p(this,"page",0);p(this,"flows",{});p(this,"flowPositions",{});p(this,"isBlankPage",!1);p(this,"highestSeenOffset",0);p(this,"highestSeenNode");p(this,"lookupPositionOffset")}clone(){let t=new r;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 e in this.flowPositions)t.flowPositions[e]=this.flowPositions[e].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let e=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(e.length!==n.length)return!1;for(let s of e)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))return!1;return!0}hasContent(t,e){let n=this.flowPositions[t];return n?n.hasContent(e):!1}startSideOfFlow(t){var n;let e=(n=this.flowPositions[t])==null?void 0:n.startBreakType;return e&&os(e)?e:"any"}firstFlowChunkOfFlow(t){let e=this.flowPositions[t];if(!e)return null;let n=e.positions[0];return n?n.flowChunk:null}},Bi=class{constructor(t){this.element=t;p(this,"left",0);p(this,"top",0);p(this,"marginLeft",0);p(this,"marginRight",0);p(this,"marginTop",0);p(this,"marginBottom",0);p(this,"borderLeft",0);p(this,"borderRight",0);p(this,"borderTop",0);p(this,"borderBottom",0);p(this,"paddingLeft",0);p(this,"paddingRight",0);p(this,"paddingTop",0);p(this,"paddingBottom",0);p(this,"width",0);p(this,"height",0);p(this,"originX",0);p(this,"originY",0);p(this,"exclusions",null);p(this,"innerShape",null);p(this,"computedBlockSize",0);p(this,"snapWidth",0);p(this,"snapHeight",0);p(this,"snapOffsetX",0);p(this,"snapOffsetY",0);p(this,"vertical",!1);p(this,"rtl",!1);p(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(t){return this.vertical?t.right:t.top}getAfterEdge(t){return this.vertical?t.left:t.bottom}getStartEdge(t){return this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left}getEndEdge(t){return this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right}getInlineSize(t){return this.vertical?t.bottom-t.top:t.right-t.left}getBoxSize(t){return this.vertical?t.right-t.left:t.bottom-t.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(t){this.element=t.element,this.left=t.left,this.top=t.top,this.marginLeft=t.marginLeft,this.marginRight=t.marginRight,this.marginTop=t.marginTop,this.marginBottom=t.marginBottom,this.borderLeft=t.borderLeft,this.borderRight=t.borderRight,this.borderTop=t.borderTop,this.borderBottom=t.borderBottom,this.paddingLeft=t.paddingLeft,this.paddingRight=t.paddingRight,this.paddingTop=t.paddingTop,this.paddingBottom=t.paddingBottom,this.width=t.width,this.height=t.height,this.originX=t.originX,this.originY=t.originY,this.innerShape=t.innerShape,this.exclusions=t.exclusions,this.computedBlockSize=t.computedBlockSize,this.snapWidth=t.snapWidth,this.snapHeight=t.snapHeight,this.vertical=t.vertical,this.rtl=t.rtl,this.borderBoxSizing=t.borderBoxSizing}setVerticalPosition(t,e){this.top=t,this.height=e,w(this.element,"top",`${t}px`),w(this.element,"height",`${e}px`)}setHorizontalPosition(t,e){this.left=t,this.width=e,w(this.element,"left",`${t}px`),w(this.element,"width",`${e}px`)}setBlockPosition(t,e){if(this.vertical){let n=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+n*this.getBoxDir(),e)}else this.setVerticalPosition(t,e)}setInlinePosition(t,e){if(this.vertical)if(this.rtl){let n=e+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(t+n*this.getInlineDir(),e)}else this.setVerticalPosition(t,e);else if(this.rtl){let n=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+n*this.getInlineDir(),e)}else this.setHorizontalPosition(t,e)}clear(){let t=this.element,e;for(;e=t.lastChild;)t.removeChild(e)}getInnerShape(){let t=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(t.x1,t.y1):bo(t.x1,t.y1,t.x2,t.y2)}getInnerRect(){let t=this.originX+this.left+this.getInsetLeft(),e=this.originY+this.top+this.getInsetTop();return new Ye(t,e,t+this.width,e+this.height)}getPaddingRect(){let t=this.originX+this.left+this.marginLeft+this.borderLeft,e=this.originY+this.top+this.marginTop+this.borderTop,n=this.paddingLeft+this.width+this.paddingRight,s=this.paddingTop+this.height+this.paddingBottom;return new Ye(t,e,t+n,e+s)}getOuterShape(t,e){let n=this.getOuterRect();return ga(t,n.x1,n.y1,n.x2-n.x1,n.y2-n.y1,e)}getOuterRect(){let t=this.originX+this.left,e=this.originY+this.top,n=this.getInsetLeft()+this.width+this.getInsetRight(),s=this.getInsetTop()+this.height+this.getInsetBottom();return new Ye(t,e,t+n,e+s)}},Vn=class extends St{constructor(e,n,s,i){super();this.elem=e;this.context=n;this.rootContentValue=s;this.exprContentListener=i}visitStrInner(e,n){var s;if(!n){if(((s=this.elem.lastChild)==null?void 0:s.nodeType)===3){this.elem.lastChild.textContent+=e;return}n=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(n)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof fe)this.elem.setAttribute("src",e.url);else{let n=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");n.setAttribute("src",e.url),this.elem.appendChild(n)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let n=e.toExpr(),s=n.evaluate(this.context);if(typeof s=="string"){n instanceof oe&&(s=yn(n.scope,new Ge(s,null),"").stringValue()),this.elem.ownerDocument;let i=this.exprContentListener(n,s,this.elem.ownerDocument);!i&&s&&n instanceof ne&&n.str.startsWith("running-element-")&&(s=""),this.visitStrInner(s,i)}return null}};function dt(r){return r!=null&&r!==U&&r!==b.normal&&r!==b.none&&!X(r)}var Ce=rs.FloatReference;function xg(r){switch(r){case"inline":return Ce.INLINE;case"column":return Ce.COLUMN;case"region":return Ce.REGION;case"page":return Ce.PAGE;default:throw new Error(`Unknown float-reference: ${r}`)}}function us(r){switch(r){case Ce.INLINE:return!1;case Ce.COLUMN:case Ce.REGION:case Ce.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${r}`)}}function Yu(r,t,e,n){let s=t?"vertical-rl":"horizontal-tb";if((r==="top"||r==="bottom")&&(r=Bu(r,s,e)),r==="block-start"&&(r="inline-start"),r==="block-end"&&(r="inline-end"),r==="inline-start"||r==="inline-end"){let i=Fu(r,s,e),o=Zf(i,s);o==="line-left"?r="left":o==="line-right"&&(r="right")}else r==="inside"?r=n==="left"?"right":"left":r==="outside"&&(r=n==="left"?"left":"right");return r!=="left"&&r!=="right"&&(F.warn(`Invalid float value: ${r}. Fallback to left.`),r="left"),r}var wo=class{constructor(t,e,n,s,i,o){this.nodePosition=t;this.floatReference=e;this.floatSide=n;this.clearSide=s;this.flowName=i;this.floatMinWrapBlock=o;p(this,"order",null);p(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(t){return t.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(t){return!1}},$u=class{constructor(){p(this,"floats",[]);p(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(t){return`pf${t}`}addPageFloat(t){if(this.floats.findIndex(n=>on(n.nodePosition,t.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let n=t.order=this.nextOrder();t.id=this.createPageFloatId(n),this.floats.push(t)}}findPageFloatByNodePosition(t){let e=this.floats.findIndex(n=>on(n.nodePosition,t));return e>=0?this.floats[e]:null}findPageFloatById(t){let e=this.floats.findIndex(n=>n.id===t);return e>=0?this.floats[e]:null}},Po=class{constructor(t,e,n,s,i,o){this.floatReference=t;this.floatSide=e;this.clearSide=n;this.continuations=s;this.area=i;this.continues=o}hasFloat(t){return this.continuations.some(e=>e.float===t)}findNotAllowedFloat(t){for(let e=this.continuations.length-1;e>=0;e--){let n=this.continuations[e].float;if(!n.isAllowedOnContext(t))return n}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let t=this.continuations.map(e=>e.float);return Math.min.apply(null,t.map(e=>e.getOrder()))}shouldBeStashedBefore(t){return this.getOrder()<t.getOrder()}addContinuations(t){t.forEach(e=>{this.continuations.push(e)})}getFlowName(){let t=this.continuations[0].float.flowName;return this.continuations.every(e=>e.float.flowName===t),t}},ko=class{constructor(t,e){this.float=t;this.nodePosition=e}equals(t){return t?this===t?!0:this.float===t.float&&on(this.nodePosition,t.nodePosition):!1}},Fn=class{constructor(t,e,n,s,i,o,a){this.parent=t;this.floatReference=e;this.container=n;this.flowName=s;this.generatingNodePosition=i;p(this,"children",[]);p(this,"writingMode");p(this,"direction");p(this,"invalidated",!1);p(this,"floatStore");p(this,"forbiddenFloats",[]);p(this,"floatFragments",[]);p(this,"stashedFloatFragments",[]);p(this,"floatAnchors",{});p(this,"floatsDeferredToNext",[]);p(this,"floatsDeferredFromPrevious");p(this,"layoutConstraints",[]);p(this,"locked",!1);t&&t.children.push(this),this.writingMode=o||t&&t.writingMode||b.horizontal_tb,this.direction=a||t&&t.direction||b.ltr,this.floatStore=t?t.floatStore:new $u;let l=this.getPreviousSibling();this.floatsDeferredFromPrevious=l?[].concat(l.floatsDeferredToNext):[]}getParent(t){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${t}`);return this.parent}getPreviousSiblingOf(t,e,n,s){let i=this.children.indexOf(t);i<0&&(i=this.children.length);for(let o=i-1;o>=0;o--){let a=this.children[o];if(a.floatReference===e&&a.flowName===n&&on(a.generatingNodePosition,s))return a;if(a=a.getPreviousSiblingOf(null,e,n,s),a)return a}return null}getPreviousSibling(){let t=this,e=this.parent,n;for(;e;){if(n=e.getPreviousSiblingOf(t,this.floatReference,this.flowName,this.generatingNodePosition),n)return n;t=e,e=e.parent}return null}getContainer(t){return!t||t===this.floatReference?this.container:this.getParent(t).getContainer(t)}setContainer(t){this.container=t,this.reattachFloatFragments()}addPageFloat(t){this.floatStore.addPageFloat(t)}getPageFloatLayoutContext(t){return t===this.floatReference?this:this.getParent(t).getPageFloatLayoutContext(t)}findPageFloatByNodePosition(t){return this.floatStore.findPageFloatByNodePosition(t)}forbid(t){let e=t.getId(),n=t.floatReference;n===this.floatReference?this.forbiddenFloats.includes(e)||(this.forbiddenFloats.push(e),new rn().findByFloat(t).forbid(t,this)):this.getParent(n).forbid(t)}isForbidden(t){let e=t.getId(),n=t.floatReference;return n===this.floatReference?this.forbiddenFloats.includes(e):this.getParent(n).isForbidden(t)}addPageFloatFragment(t,e){let n=t.floatReference;n!==this.floatReference?this.getParent(n).addPageFloatFragment(t,e):this.floatFragments.includes(t)||(this.floatFragments.push(t),this.floatFragments.sort((s,i)=>s.getOrder()-i.getOrder())),e||this.invalidate()}removePageFloatFragment(t,e){let n=t.floatReference;if(n!==this.floatReference)this.getParent(n).removePageFloatFragment(t,e);else{let s=this.floatFragments.indexOf(t);if(s>=0){let i=this.floatFragments.splice(s,1)[0],o=i.area&&i.area.element;o&&o.parentNode&&o.parentNode.removeChild(o),e||this.invalidate()}}}findPageFloatFragment(t){if(t.floatReference!==this.floatReference)return this.getParent(t.floatReference).findPageFloatFragment(t);let e=this.floatFragments.findIndex(n=>n.hasFloat(t));return e>=0?this.floatFragments[e]:null}hasFloatFragments(t){return this.floatFragments.length>0&&(!t||this.floatFragments.some(t))?!0:this.parent?this.parent.hasFloatFragments(t):!1}hasContinuingFloatFragmentsInFlow(t){return this.hasFloatFragments(e=>e.continues&&e.getFlowName()===t)}registerPageFloatAnchor(t,e){this.floatAnchors[t.getId()]=e}collectPageFloatAnchors(){let t=Object.assign({},this.floatAnchors);return this.children.reduce((e,n)=>Object.assign(e,n.collectPageFloatAnchors()),t)}isAnchorAlreadyAppeared(t){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===t))return!0;let s=this.collectPageFloatAnchors()[t];return s&&this.container&&this.container.element?this.container.element.contains(s):!1}deferPageFloat(t){let e=t.float;if(e.floatReference===this.floatReference){let n=this.floatsDeferredToNext.findIndex(s=>s.float===e);n>=0?this.floatsDeferredToNext.splice(n,1,t):this.floatsDeferredToNext.push(t)}else this.getParent(e.floatReference).deferPageFloat(t)}hasPrecedingFloatsDeferredToNext(t,e){if(!e&&t.floatReference!==this.floatReference)return this.getParent(t.floatReference).hasPrecedingFloatsDeferredToNext(t,!1);let n=t.getOrder();return this.floatsDeferredToNext.some(i=>i.float.getOrder()<n&&!t.isAllowedToPrecede(i.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(t,!0):!1}getLastFollowingFloatInFragments(t){let e=t.getOrder(),n=null;if(this.floatFragments.forEach(s=>{s.continuations.forEach(i=>{let o=i.float,a=o.getOrder();a>e&&(!n||a>n.getOrder())&&(n=o)})}),this.parent){let s=this.parent.getLastFollowingFloatInFragments(t);s&&(!n||s.getOrder()>n.getOrder())&&(n=s)}return n}getDeferredPageFloatContinuations(t){t=t||this.flowName;let e=this.floatsDeferredFromPrevious.filter(n=>!t||n.float.flowName===t);return this.parent&&(e=this.parent.getDeferredPageFloatContinuations(t).concat(e)),e.sort((n,s)=>n.float.getOrder()-s.float.getOrder())}getPageFloatContinuationsDeferredToNext(t){t=t||this.flowName;let e=this.floatsDeferredToNext.filter(n=>!t||n.float.flowName===t);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(t).concat(e):e}getFloatsDeferredToNextInChildContexts(){let t=[],e=[];for(let n=this.children.length-1;n>=0;n--){let s=this.children[n];e.includes(s.flowName)||(e.push(s.flowName),t=t.concat(s.floatsDeferredToNext.map(i=>i.float)),t=t.concat(s.getFloatsDeferredToNextInChildContexts()))}return t}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let t=this.floatFragments.length-1;t>=0;t--){let e=this.floatFragments[t],n=e.findNotAllowedFloat(this);if(n)return this.locked?this.invalidate():(this.removePageFloatFragment(e),this.forbid(n),this.removeEndFloatFragments(e.floatSide)),!0}return this.floatReference===Ce.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let t=this.getFloatsDeferredToNextInChildContexts(),e=this.floatFragments.reduce((n,s)=>n.concat(s.continuations.map(i=>i.float)),[]);e.sort((n,s)=>s.getOrder()-n.getOrder());for(let n of e){let s=n.getOrder();if(t.some(i=>!n.isAllowedToPrecede(i)&&s>i.getOrder())){if(this.locked)this.invalidate();else{this.forbid(n);let i=this.findPageFloatFragment(n);this.removePageFloatFragment(i)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let t=this.floatsDeferredToNext.length-1;t>=0;t--)if(!this.floatsDeferredToNext[t].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(t,1)}this.floatsDeferredFromPrevious.forEach(t=>{this.floatsDeferredToNext.findIndex(e=>t.equals(e))>=0||this.floatFragments.some(e=>e.hasFloat(t.float))||this.floatsDeferredToNext.push(t)})}}hasSameContainerAs(t){return!!this.container&&!!t.container&&this.container.element===t.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(t=>{this.hasSameContainerAs(t)&&t.floatFragments.forEach(e=>{let n=e.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),this.container.clear()),this.children.forEach(t=>{t.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(t=>{delete this.floatAnchors[t]}))}detachChildren(){let t=this.children.splice(0);return t.forEach(e=>{e.floatFragments.forEach(n=>{let s=n.area.element;s&&s.parentNode&&s.parentNode.removeChild(s)})}),t}attachChildren(t){t.forEach(e=>{this.children.push(e),e.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(t){let e=this.writingMode.toString(),n=this.direction.toString();if(t==="inside"||t==="outside"){let s=!!this.container.element.closest("[data-vivliostyle-page-side='left']");t=t==="inside"?s?"right":"left":s?"left":"right"}return Bu(t,e,n)}toPhysical(t){let e=this.writingMode.toString(),n=this.direction.toString();return Fu(t,e,n)}toLogicalFloatSides(t){let e=t.split(" "),n=[];for(let a of e){let l=this.toLogical(a);n.includes(l)||n.push(l)}let s=[],i=!1,o=!1;for(let a=0;a<n.length;a++){let l=n[a];l.includes("block")?i||(n.slice(a+1).some(c=>c.includes("block"))?(s.push("snap-block"),i=!0):s.push(l)):l.includes("inline")&&(o||(n.slice(a+1).some(c=>c.includes("inline"))?(s.push("snap-inline"),o=!0):s.push(l)))}return s}removeEndFloatFragments(t){let e=this.toLogicalFloatSides(t)[0];if(e==="block-end"||e==="inline-end"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n];this.toLogicalFloatSides(s.floatSide)[0]===e?this.removePageFloatFragment(s):n++}}}stashEndFloatFragments(t){let e=t.floatReference;if(e!==this.floatReference){this.getParent(e).stashEndFloatFragments(t);return}let n=this.toLogicalFloatSides(t.floatSide)[0];if(n==="block-end"||n==="snap-block"||n==="inline-end"||n==="snap-inline"){let s=0;for(;s<this.floatFragments.length;){let i=this.floatFragments[s],o=this.toLogicalFloatSides(i.floatSide)[0];(o===n||n==="snap-block"&&o==="block-end"||n==="snap-inline"&&o==="inline-end")&&i.shouldBeStashedBefore(t)?(this.stashedFloatFragments.push(i),this.floatFragments.splice(s,1)):s++}}}restoreStashedFragments(t){if(t!==this.floatReference){this.getParent(t).restoreStashedFragments(t);return}this.stashedFloatFragments.forEach(e=>{this.addPageFloatFragment(e,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(t){if(t!==this.floatReference){this.getParent(t).discardStashedFragments(t);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(t){return t===this.floatReference?this.stashedFloatFragments.concat().sort((e,n)=>n.getOrder()-e.getOrder()):this.getParent(t).getStashedFloatFragments(t)}getLimitValue(t,e,n,s,i){this.container;let o=this.toLogical(t),a=this.toPhysical(t),l=e&&this.toLogical(e),c=e&&this.toPhysical(e),u=this.getLimitValueInner(o,l,n,s,i);if(this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,c,n,s,i);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(t,e,n,s,i){this.container;let o=this.getLimitValuesInner(n,s,i,t,e);switch(t){case"block-start":return this.container.vertical?o.right:o.top;case"block-end":return this.container.vertical?o.left:o.bottom;case"inline-start":return this.container.vertical?this.container.rtl?o.bottom:o.top:this.container.rtl?o.right:o.left;case"inline-end":return this.container.vertical?this.container.rtl?o.top:o.bottom:this.container.rtl?o.left:o.right;default:throw new Error(`Unknown logical side: ${t}`)}}getLimitValuesInner(t,e,n,s,i){this.container;let o=this.container.originX,a=this.container.originY,l=this.container.getPaddingRect(),c={top:l.y1-a,left:l.x1-o,bottom:l.y2-a,right:l.x2-o,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function u(h,f,g){return h.unit==="%"?g*h.num/100:t.convertLengthToPx(h,f,e)}let d=this.floatFragments;return d.length>0&&(c=d.reduce((h,f)=>{if(n&&!n(f,this))return h;let[g,m]=this.toLogicalFloatSides(f.floatSide);if(m&&(s&&m.includes("block")===s.includes("block")&&m!==s||i&&m.includes("block")===i.includes("block")&&m!==i))return h;let y=f.area,S=f.continuations[0].float.floatMinWrapBlock,C=h.top,x=h.left,N=h.bottom,E=h.right,v=h.floatMinWrapBlockStart,L=h.floatMinWrapBlockEnd;switch(g){case"inline-start":y.vertical?C=Math.max(C,y.top+y.height):x=Math.max(x,y.left+y.width);break;case"block-start":y.vertical?(S&&y.left<E&&(v=u(S,y.rootViewNodes[0],l.x2-l.x1)),E=Math.min(E,y.left)):(S&&y.top+y.height>C&&(v=u(S,y.rootViewNodes[0],l.y2-l.y1)),C=Math.max(C,y.top+y.height));break;case"inline-end":y.vertical?N=Math.min(N,y.top):E=Math.min(E,y.left);break;case"block-end":y.vertical?(S&&y.left+y.width>x&&(L=u(S,y.rootViewNodes[0],l.x2-l.x1)),x=Math.max(x,y.left+y.width)):(S&&y.top<N&&(L=u(S,y.rootViewNodes[0],l.y2-l.y1)),N=Math.min(N,y.top));break;default:throw new Error(`Unknown logical float side: ${g}`)}return{top:C,left:x,bottom:N,right:E,floatMinWrapBlockStart:v,floatMinWrapBlockEnd:L}},c)),c.left+=o,c.right+=o,c.top+=a,c.bottom+=a,c}setFloatAreaDimensions(t,e,n,s,i,o,a){if(e!==this.floatReference)return this.getParent(e).setFloatAreaDimensions(t,e,n,s,i,o,a);let l=this.toLogicalFloatSides(n);if(l[0]==="snap-block"){if(!a["block-start"]&&!a["block-end"])return null}else if(l[0].includes("block")&&!a[l[0]])return null;t.clientLayout;let c=l.find(v=>v.includes("inline")&&a[v==="inline-start"?"inline-end":"inline-start"]),u=l.find(v=>v.includes("block")),d=this.getLimitValue("block-start",c,t.layoutContext,t.clientLayout),h=this.getLimitValue("block-end",c,t.layoutContext,t.clientLayout),f=this.getLimitValue("inline-start",u,t.layoutContext,t.clientLayout),g=this.getLimitValue("inline-end",u,t.layoutContext,t.clientLayout),m=t.vertical?t.originX:t.originY,y=t.vertical?t.originY:t.originX;d=t.vertical?Math.min(d,t.left+t.getInsetLeft()+t.width+t.getInsetRight()+m):Math.max(d,t.top+m),h=t.vertical?Math.max(h,t.left+m):Math.min(h,t.top+t.getInsetTop()+t.height+t.getInsetBottom()+m);function S(v,L){let B=v(t.bands,L);return B?(t.vertical&&(B=pa(B)),d=t.vertical?Math.min(d,B.x2):Math.max(d,B.y1),h=t.vertical?Math.max(h,B.x1):Math.min(h,B.y2),!0):o}let C,x,N,E;if(i){let v=t.vertical?Ni(new Ye(h,f,d,g)):new Ye(f,d,g,h);if((l[0]==="block-start"||l[0]==="snap-block"||l[0]==="inline-start"||l[0]==="snap-inline")&&!S(Lf,v)||(l[0]==="block-end"||l[0]==="snap-block"||l[0]==="inline-end"||l[0]==="snap-inline")&&!S(Rf,v)||(N=(h-d)*t.getBoxDir(),C=N-t.getInsetBefore()-t.getInsetAfter(),E=(g-f)*t.getInlineDir(),x=E-t.getInsetStart()-t.getInsetEnd(),!o&&(C<=0||x<=0)))return null}else{C=t.computedBlockSize,N=C+t.getInsetBefore()+t.getInsetAfter();let v=(h-d)*t.getBoxDir();if(l[0]==="snap-block"){if(s===null)l[0]="block-start";else{let B=this.container.getPaddingRect(),H=this.container.getBoxDir()*(s-(this.container.vertical?B.x2:B.y1)),Y=this.container.getBoxDir()*((this.container.vertical?B.x1:B.y2)-s-N);H<=Y?l[0]="block-start":l[0]="block-end"}if(!a[l[0]])if(a["block-end"])l[0]="block-end";else return null}else if(l[0]==="snap-inline")if(s===null)l[0]="inline-start";else if(a["inline-start"])l[0]="inline-start";else if(a["inline-end"])l[0]="inline-end";else return null;if(!o&&v<N)return null;l[0]==="inline-start"||l[0]==="inline-end"||l[1]?x=Ri(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?x=t.getContentInlineSize():x=t.vertical?t.height:t.width,E=x+t.getInsetStart()+t.getInsetEnd();let L=(g-f)*t.getInlineDir();if(!o&&L<E)return null}return d-=m,h-=m,f-=y,g-=y,l.some(v=>v==="inline-start"||v==="snap-inline")||l.length===1&&(l[0]==="block-start"||l[0]==="snap-block")?t.setInlinePosition(f,x):(l.some(v=>v==="inline-end")||l.length===1&&l[0]==="block-end")&&t.setInlinePosition(g-E*t.getInlineDir(),x),l.some(v=>v==="block-start"||v==="snap-block")||l.length===1&&(l[0]==="inline-start"||l[0]==="snap-inline")?t.setBlockPosition(d,C):(l.some(v=>v==="block-end")||l.length===1&&l[0]==="inline-end")&&t.setBlockPosition(h-N*t.getBoxDir(),C),l.join(" ")}getFloatFragmentExclusions(){let t=this.floatFragments.map(e=>e.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(t):t}reattachFloatFragments(){let t=this.container.element&&this.container.element.parentNode;t&&this.floatFragments.forEach(e=>{t.appendChild(e.area.element)})}getMaxReachedAfterEdge(){let t=this.getContainer().vertical;return this.floatFragments.reduce((e,n)=>{let s=n.getOuterRect();return t?Math.min(e,s.x1):Math.max(e,s.y2)},t?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let t=this.getContainer().vertical;return this.floatFragments.filter(e=>e.floatSide==="block-end").reduce((e,n)=>{let s=n.getOuterRect();return t?Math.max(e,s.x2):Math.min(e,s.y1)},t?0:1/0)}getPageFloatClearEdge(t,e){function n(d){return h=>d.isAnchorAlreadyAppeared(h.float.getId())}function s(d,h){return t==="inline-start"&&(d.floatSide.includes("inline-end")||d.floatSide==="block-end")||t==="inline-end"&&(d.floatSide.includes("inline-start")||d.floatSide==="block-start")?!1:d.continuations.some(n(h))}let i=e.getPaddingRect(),o=e.vertical?i.x1:i.y2,a=this;for(;a;){if(a.floatsDeferredToNext.some(n(a)))return o;a=a.parent}function l(d){return d.floatFragments.some(h=>s(h,d))||d.children.some(h=>l(h))}if(t==="column"||t==="region"||t==="page"){for(a=this;a;a=a.parent)if(a.floatReference===t){if(l(a))return o;break}}e.clientLayout;let c=this.getLimitValue("block-start",null,e.layoutContext,e.clientLayout,s);return this.getLimitValue("block-end",null,e.layoutContext,e.clientLayout,s)*e.getBoxDir()<o*e.getBoxDir()?o:c}getPageFloatPlacementCondition(t,e,n){if(t.floatReference!==this.floatReference)return this.getParent(t.floatReference).getPageFloatPlacementCondition(t,e,n);let s={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!n)return s;let i=this.toLogicalFloatSides(e)[0],o=this.toLogical(n),a;o==="all"?a=["block-start","block-end","inline-start","inline-end"]:o==="both"?a=["inline-start","inline-end"]:o==="same"?i==="snap-block"?a=["block-start","block-end"]:a=[i]:a=[o];let l=t.getOrder();function c(h){return f=>(!h||f.floatSide.includes(h))&&f.getOrder()<l}function u(h,f){return h.children.some(g=>g.floatFragments.some(c(f))||u(g,f))}function d(h,f){let g=h.parent;return!!g&&(g.floatFragments.some(c(f))||d(g,f))}if(n==="column"||n==="region"||n==="page"){for(let h=this;h;h=h.parent)if(h.floatReference===n){(h.floatFragments.some(c(null))||u(h,null))&&(s["block-start"]=!1,s["block-end"]=!1,s["inline-start"]=!1,s["inline-end"]=!1);break}return s}return a.forEach(h=>{switch(h){case"block-start":s[h]=!u(this,h);break;case"block-end":s[h]=!d(this,h);break;case"inline-start":case"inline-end":s[h]=!this.floatFragments.some(c(h));break;default:throw new Error(`Unexpected side: ${h}`)}}),s}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(t,e){e===this.floatReference?this.layoutConstraints.push(t):this.getParent(e).addLayoutConstraint(t,e)}isColumnFullWithPageFloats(t){let e=t.layoutContext,n=t.clientLayout;let s=this,i=null;for(;s&&s.container;){let l=s.getLimitValuesInner(e,n);i?t.vertical?(l.right<i.right&&(i.right=l.right,i.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.left>i.left&&(i.left=l.left,i.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):(l.top>i.top&&(i.top=l.top,i.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.bottom<i.bottom&&(i.bottom=l.bottom,i.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):i=l,s=s.parent}let o=Math.max(i.floatMinWrapBlockStart,i.floatMinWrapBlockEnd);return(t.vertical?i.right-i.left:i.bottom-i.top)<=o}getMaxBlockSizeOfPageFloats(){let t=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(e=>{let n=e.area;return t?n.width:n.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},To=[],rn=class{static register(t){To.push(t)}findByNodeContext(t){for(let e=To.length-1;e>=0;e--){let n=To[e];if(n.appliesToNodeContext(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=To.length-1;e>=0;e--){let n=To[e];if(n.appliesToFloat(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},ju=class{appliesToNodeContext(t){return us(t.floatReference)}appliesToFloat(t){return!0}createPageFloat(t,e,n){let s=t.floatReference;t.floatSide;let i=t.floatSide,o=t.toNodePosition();return n.resolveFloatReferenceFromColumnSpan(s,t.columnSpan,t).thenAsync(a=>{s=a,e.flowName;let l=new wo(o,s,i,t.clearSide,e.flowName,t.floatMinWrapBlock);return e.addPageFloat(l),T(l)})}createPageFloatFragment(t,e,n,s,i){let o=t[0].float;return new Po(o.floatReference,e,n,t,s,i)}findPageFloatFragment(t,e){return e.findPageFloatFragment(t)}adjustPageFloatArea(t,e,n){}forbid(t,e){}};rn.register(new ju);var Yb=Po,Ao=class r extends wo{constructor(e,n,s,i,o){super(e,n,"block-end",null,s,o);this.footnotePolicy=i}isAllowedToPrecede(e){return!(e instanceof r)}},Ma=class extends Yb{constructor(t,e,n,s){super(t,"block-end",null,e,n,s)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof Ao?!0:this.getOrder()<t.getOrder()}},qu=class{constructor(t){this.footnote=t}allowLayout(t){let e=t.toNodePosition();return!on(e,this.footnote.nodePosition)}},Ku=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof Ao}createPageFloat(t,e,n){let s=Ce.REGION,i=e.getPageFloatLayoutContext(s);e.getPageFloatLayoutContext(Ce.PAGE).hasSameContainerAs(i)&&(s=Ce.PAGE);let a=t.toNodePosition();e.flowName;let l=new Ao(a,s,e.flowName,t.footnotePolicy,t.floatMinWrapBlock);return e.addPageFloat(l),T(l)}createPageFloatFragment(t,e,n,s,i){let o=t[0].float;return new Ma(o.floatReference,t,s,i)}findPageFloatFragment(t,e){let s=e.getPageFloatLayoutContext(t.floatReference).floatFragments.filter(i=>i instanceof Ma);return s.length<=1,s[0]||null}adjustPageFloatArea(t,e,n){t.isFootnote=!0,t.adjustContentRelativeSize=!1;let s=t.element;t.vertical=n.layoutContext.applyFootnoteStyle(e.vertical,n.layoutContext.nodeContext&&n.layoutContext.nodeContext.direction==="rtl",s),t.convertPercentageSizesToPx(s),n.setComputedInsets(s,t),n.setComputedWidthAndHeight(s,t)}forbid(t,e){let n=t;switch(n.footnotePolicy){case b.line:{let s=new qu(n);e.addLayoutConstraint(s,n.floatReference);break}}}};rn.register(new Ku);var qb="data-vivliostyle-flow-root";function Eg(r){return r.getAttribute(qb)==="true"}function Sg(r){let t=(r==null?void 0:r.toString())||"block",e;switch(t){case"inline-flex":e="flex";break;case"inline-grid":e="grid";break;case"inline-table":e="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":e="block";break;default:e=t}return k(e)}function _a(r){return r===b.absolute||r===b.fixed}function Lo(r){return r instanceof Xt&&r.name==="running"}function Zu(r,t,e,n){return r===b.none||(_a(t)?(e=b.none,r=Sg(r)):(e&&e!==b.none&&!X(e)||n)&&(r=Sg(r))),{display:r,position:t,float:e}}function Ua(r,t,e,n){return Zu(r,t,e,n).display===b.block}function Ha(r){return r instanceof j||r instanceof W||typeof r=="string"}function Ot(r){if(!Ha(r))return!1;let t=r.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function Bn(r){return Ha(r)?r.toString().includes("list-item"):!1}function Ng(r){if(!Ha(r))return!1;switch(r.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function za(r){if(!Ha(r))return!1;switch(r.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function vg(r,t,e,n,s,i,o){return s=s||i||b.horizontal_tb,!!o||!!e&&e!==b.none&&!X(e)||_a(t)||r===b.inline_block||r===b.table_cell||r===b.table_caption||r==b.flex||r==b.grid||r==b.flow_root||(r===b.block||r===b.list_item)&&!!n&&n!==b.visible&&n!==b.clip&&!X(n)||!!i&&s!==i}function Tg(r){return r===b.relative||r===b.absolute||r===b.fixed}var Dt=1e5;function Io(r){let t=r.element.style;t.columnGap=`${Dt-(r.vertical?r.height:r.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ju(r){let t=r.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function ed(r){return r.element.style.columnCount==="1"}function wg(r){r.element.setAttribute("data-vivliostyle-column","true")}function Pg(r){return r.element.hasAttribute("data-vivliostyle-column")}function Di(r,t){let e=t?r.bottom:Math.max(Math.abs(r.left),Math.abs(r.right));return Math.round(e/Dt)}function Qu(r,t){let e=Di(r,t);if(e===0)return 0;let n=t?r.top:Math.min(Math.abs(r.left),Math.abs(r.right)),s=Math.round(n/Dt),i=s*Dt,o=e*Dt;return t?(r.top-=i,r.bottom-=o,r.bottom<r.top&&(r.bottom+=Dt,o-=Dt),r.right-=i,r.left-=o):r.left<-Dt/2?(r.right+=i,r.left+=o,r.left>r.right&&(r.left-=Dt,o+=Dt),r.top+=i,r.bottom+=o):(r.left-=i,r.right-=o,r.right<r.left&&(r.right+=Dt,o-=Dt),r.top+=i,r.bottom+=o),r.width=r.right-r.left,r.height=r.bottom-r.top,s}function td(r,t){for(let e=0;e<r.length;e++)Qu(r[e],t)}function Mt(r,t,e){var i;let n=r.getElementClientRect(t),s=Qu(n,e);if(s===1){let o=r.getElementComputedStyle(t);if(o.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&((i=t.parentElement)!=null&&i.parentElement)&&(o=r.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),l=a==null?void 0:a.style,c=e?"width":"height",u=l&&parseFloat(l[c]);if(u){let d=u,h=s,f=parseFloat(o.paddingBlockEnd),g=parseFloat(o.borderBlockEndWidth),m=Math.ceil(f+g);for(;m-- >0&&h===s&&--d>0;){l[c]=`${d}px`;let y=r.getElementClientRect(t);if(h=Qu(y,e),h<s||h===s&&(e?y.right>n.right:y.top<n.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),y}l[c]=`${u}px`}}}return n}function kg(r,t){var e,n;if(r.nodeType===1){let s=r;((e=s.style)==null?void 0:e.breakAfter)==="column"&&(s.style.breakAfter="")}if(t.nodeType===1){let s=t;((n=s.style)==null?void 0:n.breakBefore)==="column"&&(s.style.breakBefore="")}}function Vo(r){for(let t=r.nodeType===1?r:r.parentElement;t;t=t.parentElement){let e=t.style;if(!e||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(e.columnCount))||!isNaN(parseFloat(e.columnWidth)))return t;if(e.position==="absolute")break}return null}function Ag(r){var C;if(r.nodeType!==1)return;let t=r,e=t.style,n=(e==null?void 0:e.breakBefore)==="column",s=t.previousElementSibling,i=s&&((C=s.style)==null?void 0:C.breakAfter)==="column";if(!n&&!i)return;let o=Vo(t);if(!o)return;let a=o.ownerDocument.defaultView.getComputedStyle(o),{writingMode:l,direction:c,columnGap:u,fontSize:d}=a,h=l==="vertical-rl"||l==="vertical-lr",f=c==="rtl",g=(parseFloat(u)||parseFloat(d)||16)/2,m=o.getBoundingClientRect(),y=t.getBoundingClientRect();(h?y.top>m.bottom+g:f?y.right<m.left-g:y.left>m.right+g)&&(n&&(e.breakBefore=""),i&&s&&(s.style.breakAfter=""),e.marginBlockStart=`${Dt}px`)}function ds(r,t,e,n){let s=r.viewNode;if(!s)return NaN;let i=s.nodeType===1?s:s.parentElement;if(i&&i.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=i.style;if(i.localName==="br"||i.localName==="wbr"||o&&Ot(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(s===i){if(r.after||!r.inline){if(r.after&&!r.inline&&i.querySelector("ruby")){let a=i.parentNode,l=i.nextSibling;a.removeChild(i),a.insertBefore(i,l)}let o=Mt(t,i,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return r.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=s.ownerDocument.createRange(),l=s.textContent.length;if(!l)return NaN;r.after&&(e+=l),e>=l&&(e=l-1),a.setStart(s,e),a.setEnd(s,e+1);let c=t.getRangeClientRects(a);return td(c,n),c=c.filter(u=>u.right>u.left&&u.bottom>u.top),c.length?(n?o=Math.min.apply(null,c.map(u=>u.left)):o=Math.max.apply(null,c.map(u=>u.bottom)),o):NaN}}function Fo(r,t,e){let n=ed(t);n&&Ju(t);let s=t.clientLayout.getElementClientRect(r);n&&Io(t);let i=t.getComputedMargin(r);return e?s.width+i.left+i.right:s.height+i.top+i.bottom}function On(r){for(;r;){if(r.parentNode===r.ownerDocument)return!1;r=r.parentNode}return!0}function Ga(r,t){var e;if(r)for(let n=r.lastChild,s=n;n!==t;n=s)s=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((e=t.style)==null?void 0:e.display)==="inline")&&r.removeChild(n)}var Sn="data-adapt-spec";function Wa(r){return!!r.getAttribute(Sn)}function ps(r){var n;if((r==null?void 0:r.nodeType)!==1)return!1;let t=r;if(Wa(t))return!0;let e=(n=t.style)==null?void 0:n.position;return e==="absolute"||e==="fixed"}function Dn(r){let t=r==null?void 0:r.viewNode;return(t==null?void 0:t.nodeType)===1&&Wa(t)}function Lg(r){return r!=="inline"&&(Ot(r)||za(r))}function nd(r){var t;for(let e=r.parent;e;e=e.parent)if((e.display!=="inline"||e.vertical!==((t=e.parent)==null?void 0:t.vertical))&&Ot(e.display))return e;return null}var $s=class{calculateOffset(t){return hs(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function hs(r,t){return{current:t.reduce((e,n)=>e+n.calculateOffset(r),0),minimum:t.reduce((e,n)=>e+n.calculateMinimumOffset(r),0)}}var En=class extends $s{constructor(e,n,s,i){super();this.position=e;this.breakOnEdge=n;this.overflows=s;this.computedBlockSize=i;p(this,"overflowIfRepetitiveElementsDropped");p(this,"isEdgeUpdated",!1);p(this,"edge",0);this.overflowIfRepetitiveElementsDropped=s}findAcceptableBreak(e,n){return this.updateOverflows(e),n<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(Ii(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var s;let n=e.calculateClonedPaddingBorder(this.position);if(this.edge=ds(this.position,e.clientLayout,0,e.vertical)+n,!this.position.after&&!this.position.inline){let i=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*i}else if(this.position.after&&((s=this.position.shadowContext)==null?void 0:s.root.id)==="table-cell"){let i=e.element.parentElement,o=i==null?void 0:i.closest("table, [style*='display: table;']");if(o){let a=o.style.borderCollapse==="collapse",l=0,c=0;for(let u=i;u;u=u.parentElement){let d=e.clientLayout.getElementComputedStyle(u);if((u===i||u===o&&!a)&&(l+=e.parseComputedLength(d.paddingBlockEnd)),u===o&&!a&&(l+=e.parseComputedLength(d.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),a?c=Math.max(c,e.parseComputedLength(d.borderBlockEndWidth)):(u===i||u===o)&&(c+=e.parseComputedLength(d.borderBlockEndWidth)),u===o)break}this.edge+=(e.vertical?-1:1)*(l+c)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let n=this.edge,s=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(n+(e.vertical?-1:1)*s.minimum),this.overflows=this.position.overflow=e.isOverflown(n+(e.vertical?-1:1)*s.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:n}=e.parent;if(!xn.isInstanceOfRepetitiveElementsOwnerFormattingContext(n))return!1;let s=n.getRepetitiveElements();return s?s.isFirstContentNode(e):!1}};var fs=class{find(t){let e=qe("RESOLVE_LAYOUT_PROCESSOR");for(let n=0;n<e.length;n++){let s=e[n](t);if(s)return s}throw new Error(`No processor found for a formatting context: ${t.getName()}`)}},Nn=class{layout(t,e,n){return e.isFloatNodeContext(t)?e.layoutFloatOrFootnote(t):e.isBreakable(t)?e.layoutBreakableBlock(t):e.layoutUnbreakable(t)}createEdgeBreakPosition(t,e,n,s){return new En(t.copy(),e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return!1}clearOverflownViewNodes(t,e,n,s){var a;if(!n.viewNode||!n.viewNode.parentNode||n.shadowType===jt.ShadowType.ROOTLESS&&Dn(n))return;let i=n.viewNode;((a=i.parentElement)==null?void 0:a.localName)==="viv-ts-inner"&&(i=i.parentElement.parentElement);let o=i.parentNode;Ga(o,i),s&&o.removeChild(i)}finishBreak(t,e,n,s){let i=n||e.viewNode!=null&&e.viewNode.nodeType==1&&!e.after;return t.clearOverflownViewNodes(e,i),s&&t.layoutContext.processFragmentedBlockEdge(e),T(!0)}},Mi=class{constructor(t){this.parent=t;p(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}saveState(){}restoreState(t){}},Bo=new Nn,Rg=Aa.isInstanceOfBlockFormattingContext;je("RESOLVE_FORMATTING_CONTEXT",(r,t,e,n,s,i)=>{let o=r.parent;return!o&&r.formattingContext||o&&r.formattingContext!==o.formattingContext?null:r.establishesBFC||!r.formattingContext&&Ua(e,n,s,i)?new Mi(o?o.formattingContext:null):null});je("RESOLVE_LAYOUT_PROCESSOR",r=>r instanceof Mi?Bo:null);var gs=class{constructor(){p(this,"initialBreakPositions",null);p(this,"initialStateOfFormattingContext",null);p(this,"initialPosition");p(this,"initialFragmentLayoutConstraints")}layout(t,e){return this.prepareLayout(t,e),this.tryLayout(t,e)}tryLayout(t,e){let n=A("AbstractLayoutRetryer.tryLayout");this.saveState(t,e);let s=this.resolveLayoutMode(t);return s.doLayout(t,e).then(i=>{let o=s.accept(i,e);o=s.postLayout(i,this.initialPosition,e,o),o?n.finish(i):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(t,e),this.tryLayout(this.initialPosition,e).thenFinish(n))}),n.result()}prepareLayout(t,e){}clearNodes(t){let e=t.viewNode||t.parent.viewNode,n;for(;n=e.lastChild;)e.removeChild(n);let s;for(;s=e.nextSibling;)s.parentNode.removeChild(s)}saveState(t,e){this.initialPosition=t.copy(),this.initialBreakPositions=[].concat(e.breakPositions),this.initialFragmentLayoutConstraints=[].concat(e.fragmentLayoutConstraints),t.formattingContext&&(this.initialStateOfFormattingContext=t.formattingContext.saveState())}restoreState(t,e){e.breakPositions=this.initialBreakPositions,e.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,t.formattingContext&&t.formattingContext.restoreState(this.initialStateOfFormattingContext)}};var od=class{initialState(t){return{nodeContext:t,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(t){}afterNonDisplayableNode(t){}startIgnoredTextNode(t){}afterIgnoredTextNode(t){}startNonElementNode(t){}afterNonElementNode(t){}startInlineElementNode(t){}afterInlineElementNode(t){}startNonInlineElementNode(t){}afterNonInlineElementNode(t){}finish(t){}},js=class{constructor(t,e){this.strategy=t;this.layoutContext=e}iterate(t){let e=this.strategy,n=e.initialState(t),s=A("LayoutIterator");return s.loopWithFrame(i=>{let o;for(;n.nodeContext;){n.nodeContext.viewNode?n.nodeContext.viewNode.nodeType!==1?me(n.nodeContext.viewNode,n.nodeContext.whitespace)?n.nodeContext.after?o=e.afterIgnoredTextNode(n):o=e.startIgnoredTextNode(n):n.nodeContext.after?o=e.afterNonElementNode(n):o=e.startNonElementNode(n):n.nodeContext.inline?n.nodeContext.after?o=e.afterInlineElementNode(n):o=e.startInlineElementNode(n):n.nodeContext.after?o=e.afterNonInlineElementNode(n):o=e.startNonInlineElementNode(n):n.nodeContext.after?o=e.afterNonDisplayableNode(n):o=e.startNonDisplayableNode(n);let l=(o&&o.isPending()?o:T(!0)).thenAsync(()=>n.break?T(null):this.layoutContext.nextInTree(n.nodeContext,n.atUnforcedBreak));if(l.isPending()){l.then(c=>{n.break?i.breakLoop():(n.nodeContext=c,i.continueLoop())});return}else if(n.break){i.breakLoop();return}else n.nodeContext=l.get()}e.finish(n),i.breakLoop()}).then(()=>{s.finish(n.nodeContext)}),s.result()}},_n=class extends od{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,n){let s=!e.leadingEdge&&Me(e.breakAtTheEdge);if(s){let i=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;i.viewNode.parentNode.removeChild(i.viewNode),n.pageBreakType=e.breakAtTheEdge}return s}saveEdgeAndProcessOverflow(e,n){let s=n.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return s&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),s}processLayoutConstraint(e,n,s){let i=e.nodeContext,o=!n.allowLayout(i);return o&&(s.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),i=e.nodeContext=i.modify(),i.overflow=!0),o}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=_e(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let n,s;return e.onStartEdges?(n=this.endEmptyNonInlineBox(e),s=n&&n.isPending()?n:T(!0),s=s.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(n=this.endNonInlineBox(e),s=n&&n.isPending()?n:T(!0)),s.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=_e(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}};var $a=[];function Vg(){$a=[]}function ld(r,t,e){return r-=e,t===0?r===0:r%t===0&&r/t>=0}var rd=class{constructor(t){this.matchers=t}matches(){return this.matchers.some(t=>t.matches())}},ad=class{constructor(t){this.matchers=t}matches(){return this.matchers.every(t=>t.matches())}},_i=class _i{constructor(t,e,n){this.elementOffset=t;this.a=e;this.b=n}static registerFragmentIndex(t,e,n){let s=_i.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:e,priority:n})}static clearFragmentIndices(){_i.fragmentIndices={}}matches(){let t=_i.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&ld(t.fragmentIndex,this.a,this.b)}};p(_i,"fragmentIndices",{});var ms=_i,Ys=class{static buildViewConditionMatcher(t,e){let n=e.split("_");return n[0]=="NFS"?new ms(t,parseInt(n[1],10),parseInt(n[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new ad(t)}static buildAnyMatcher(t){return new rd(t)}};var Kd={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},Kb=["image-resolution","orphans","widows"];function Og(){return qe("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(Kb))}var Zb={"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},pd=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Qb=["max-%","min-%","%"],Bg=(()=>{let r=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let e=0;e<pd.length;e++)for(let n=0;n<r.length;n++){let s=pd[e].replace("%",r[n]);t[s]=!0}return t})();function Wi(r,t){let e={};for(let n of pd)for(let s in r){let i=n.replace("%",s),o=n.replace("%",r[s]);e[i]=o,e[o]=i}for(let n of Qb)for(let s in t){let i=n.replace("%",s),o=n.replace("%",t[s]);e[i]=o,e[o]=i}return e}var Zd=Wi({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Qd=Wi({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Jb=Wi({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),ey=Wi({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),ty=Wi({inside:"right",outside:"left"},{}),ny=Wi({inside:"left",outside:"right"},{}),I=class r{constructor(t,e){this.value=t;this.priority=e}getBaseValue(){return this}filterValue(t){let e=this.value.visit(t);return e===this.value?this:new r(e,this.priority)}increaseSpecificity(t){return t==0?this:new r(this.value,this.priority+t)}evaluate(t,e,n,s){return e&&It(e)?this.value:Go(t,this.value,e,n,s)}isEnabled(t){return!0}},Do=class r extends I{constructor(e,n,s){super(e,n);this.condition=s}getBaseValue(){return new I(this.value,this.priority)}filterValue(e){let n=this.value.visit(e);return n===this.value?this:new r(n,this.priority,this.condition)}increaseSpecificity(e){return e==0?this:new r(this.value,this.priority+e,this.condition)}isEnabled(e){try{return!!this.condition.evaluate(e)}catch(n){F.warn(n)}return!1}};function hd(r,t,e){return(!t||e.priority>=t.priority)&&e.isEnabled(r)?e.getBaseValue():t}function vn(r,t,e,n){if(r)if(!e)delete r[t];else{let s=r[t];(!s||e.priority>=s.priority)&&(n?e.isEnabled(n)&&(r[t]=e.getBaseValue()):r[t]=e)}}var Dg={"region-id":!0,"fragment-selector-id":!0};function sy(r){return!!Dg[r]}function fd(r){return r.charAt(0)==="_"&&r!=="_viewConditionalStyles"}function Ks(r){return r.charAt(0)!=="_"&&!Dg[r]}function ys(r){return!!Kd[r]||It(r)}function pe(r,t){return r[t]}function Un(r,t,e){e?r[t]=e:delete r[t]}function _t(r,t){return r[t]}function Qs(r,t){let e=r[t];return e||(e={},r[t]=e),e}var Mg=r=>{let t=r._viewConditionalStyles;return t||(t=[],r._viewConditionalStyles=t),t};function Jd(r,t){return r[t]}function _g(r,t){let e=r[t];return e||(e=[],r[t]=e),e}function zo(r,t,e,n,s,i,o){var l,c;if([{id:s,styleKey:"_pseudos"},{id:i,styleKey:"_regions"}].forEach(u=>{if(u.id){let d=Qs(t,u.styleKey);t=d[u.id],t||(t={},d[u.id]=t)}}),o){let u=Mg(t);t={},u.push({styles:t,matcher:o})}for(let u in e)if(!fd(u))if(sy(u)){let d=Jd(e,u),h=_g(t,u);Array.prototype.push.apply(h,d)}else{let d=pe(e,u);if(!d.isEnabled(r))continue;let h=d.increaseSpecificity(n);vn(t,u,h,r);let f=(c=(l=r.style)==null?void 0:l.validatorSet.shorthands[u])==null?void 0:c.propList;if(f)for(let g of f){let m=new I(U,h.priority);vn(t,g,m,r)}}}function Ug(r,t){let e={};for(let n=0;n<t.length;n++)zo(r,e,t[n],0,null,null,null);return e}function ep(r,t){if(r.length>0){r.sort((n,s)=>s.getPriority()-n.getPriority());let e=null;for(let n=r.length-1;n>=0;n--)e=r[n],e.chained=t,t=e;return e}return t}var Ya=class extends fn{constructor(e,n){super();this.props=e;this.context=n;p(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=pe(this.props,"font-size");if(!e.value.isNumeric())return Ze.em;let n=e.value;if(!xf(n.unit))throw new Error("Unexpected state");return n.num*Ze[n.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?ol(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?il(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Go(this.context,e,this.propName).visit(this):e}};function il(r,t,e){let n=r.unit,s=r.num;return n==="em"?new P(s*t,"px"):n==="rem"?new P(s*e.fontSize(),"px"):n==="rlh"?new P(s*e.rootLineHeight,"px"):r}function ol(r,t,e){r=il(r,t,e);let n=r.unit,s=r.num;return n==="px"?r:n==="%"?new P(s/100*t,"px"):new P(s*e.queryUnitSize(n,!1),"px")}var Hn=class{apply(t){}mergeWith(t){return new gd([this,t])}clone(){return this}},Hi=class extends Hn{constructor(e){super();this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},gd=class r extends Hn{constructor(e){super();this.list=e}apply(e){for(let n=0;n<this.list.length;n++)this.list[n].apply(e)}mergeWith(e){return this.list.push(e),this}clone(){return new r([].concat(this.list))}},Zs=class extends Hn{constructor(e,n,s,i,o){super();this.style=e;this.specificity=n;this.pseudoelement=s;this.regionId=i;this.viewConditionId=o}apply(e){zo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ie=class extends Hn{constructor(){super();p(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},md=class extends ie{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}},Cd=class extends ie{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}},qa=class extends ie{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}},bd=class extends ie{constructor(e,n){super();this.ns=e;this.localName=n}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let n=e.nsPrefix[this.ns];n||(n=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=n);let s=n+this.localName;e.insertInTable(e.nstags,s,this.chained)}return!0}},yd=class extends ie{constructor(e,n){super();this.epubTypePatt=e;this.targetLocalName=n}apply(e){let n=e.currentElement;if(n instanceof HTMLAnchorElement&&n.hash&&n.href==n.baseURI.replace(/#.*$/,"")+n.hash){let s=n.hash.substring(1),i=n.ownerDocument.getElementById(s);if(i&&(!this.targetLocalName||i.localName==this.targetLocalName)){let o=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");o&&o.match(this.epubTypePatt)&&this.chained.apply(e)}}}},xd=class extends ie{constructor(e){super();this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function rl(r,t,e,n){if(!r)return!1;if(t!==null)return n(r,t,e);for(let s of r.getAttributeNames())if((s===e||s.endsWith(`:${e}`))&&n(r,s===e?"":r.lookupNamespaceURI(s.split(":")[0]),e))return!0;return!1}var Ka=class extends ie{constructor(e,n){super();this.ns=e;this.name=n}apply(e){rl(e.currentElement,this.ns,this.name,(n,s,i)=>n.hasAttributeNS(s,i))&&this.chained.apply(e)}},Sd=class extends ie{constructor(e,n,s){super();this.ns=e;this.name=n;this.value=s}apply(e){rl(e.currentElement,this.ns,this.name,(n,s,i)=>n.getAttributeNS(s,i)==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}},Ed=class extends ie{constructor(e,n){super();this.ns=e;this.name=n}apply(e){rl(e.currentElement,this.ns,this.name,(n,s,i)=>!!Zb[n.getAttributeNS(s,i)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},qs=class extends ie{constructor(e,n,s){super();this.ns=e;this.name=n;this.regexp=s}apply(e){rl(e.currentElement,this.ns,this.name,(n,s,i)=>{var o;return!!((o=n.getAttributeNS(s,i))!=null&&o.match(this.regexp))})&&this.chained.apply(e)}},Nd=class extends ie{constructor(e){super();this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Za=class extends ie{constructor(){super()}apply(t){t.isFirst&&this.chained.apply(t)}getPriority(){return 6}},vd=class extends ie{constructor(){super()}apply(t){t.isRoot&&this.chained.apply(t)}getPriority(){return 12}},Tn=class extends ie{constructor(e,n){super();this.a=e;this.b=n}matchANPlusB(e){return ld(e,this.a,this.b)}},Td=class extends Tn{constructor(t,e){super(t,e)}apply(t){this.matchANPlusB(t.currentSiblingOrder)&&this.chained.apply(t)}getPriority(){return 5}},Mo=class extends Tn{constructor(t,e){super(t,e)}apply(t){let e=t.currentSiblingTypeCounts[t.currentNamespace][t.currentLocalName];this.matchANPlusB(e)&&this.chained.apply(t)}getPriority(){return 5}},_o=class extends Tn{constructor(t,e){super(t,e)}apply(t){let e=t.currentFollowingSiblingOrder;e===null&&(e=t.currentFollowingSiblingOrder=t.currentElement.parentNode.childElementCount-t.currentSiblingOrder+1),this.matchANPlusB(e)&&this.chained.apply(t)}getPriority(){return 4}},Uo=class extends Tn{constructor(t,e){super(t,e)}apply(t){let e=t.currentFollowingSiblingTypeCounts;if(!e[t.currentNamespace]){let n=t.currentElement;do{let s=n.namespaceURI,i=n.localName,o=e[s];o||(o=e[s]={}),o[i]=(o[i]||0)+1}while(n=n.nextElementSibling)}this.matchANPlusB(e[t.currentNamespace][t.currentLocalName])&&this.chained.apply(t)}getPriority(){return 4}},wd=class extends ie{constructor(){super()}apply(t){let e=t.currentElement.firstChild;for(;e;){switch(e.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(e.length>0)return}e=e.nextSibling}this.chained.apply(t)}getPriority(){return 4}},Pd=class extends ie{constructor(){super()}apply(t){t.currentElement.disabled===!1&&this.chained.apply(t)}getPriority(){return 5}},kd=class extends ie{constructor(){super()}apply(t){t.currentElement.disabled===!0&&this.chained.apply(t)}getPriority(){return 5}},Ad=class extends ie{constructor(){super()}apply(t){let e=t.currentElement;(e.selected===!0||e.checked===!0)&&this.chained.apply(t)}getPriority(){return 5}},Ue=class extends ie{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}},Qa=class r extends Hn{constructor(){super();p(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new r;return e.applied=this.applied,e}},Ho=class extends ie{constructor(e){super();p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Qa;for(let n of e)this.firstActions.push(ep(n,this.checkAppliedAction))}apply(e){for(let n of this.firstActions)if(n.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 ie?e.getPriority():0))}positive(){return!0}relational(){return!1}},Ld=class extends Ho{positive(){return!1}},Rd=class extends Ho{constructor(e){super([]);this.selectorTexts=e}apply(e){for(let n of this.selectorTexts){let s,i;/^\s*[+~]/.test(n)?(i=e.currentElement.parentNode,s=`:scope > :nth-child(${Array.from(i.children).indexOf(e.currentElement)+1}) ${n}`):(i=e.currentElement,s=`:scope ${n}`);try{if(i.querySelector(s)){this.checkAppliedAction.apply(e);break}}catch(o){}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},Ja=class extends Tn{constructor(e,n,s){super(e,n);p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Qa;for(let i of s)this.firstActions.push(ep(i,this.checkAppliedAction))}apply(e){for(let o of this.firstActions)if(o.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let n=e.currentElement,s=1,i=n.previousElementSibling;for(;i;)this.matchesSelector(i,e)&&s++,i=i.previousElementSibling;this.matchANPlusB(s)&&this.chained.apply(e)}matchesSelector(e,n){let s=n.currentElement,i=n.currentNamespace,o=n.currentLocalName,a=n.currentId,l=n.currentClassNames,c=n.currentSiblingOrder;n.currentElement=e,n.currentNamespace=e.namespaceURI||"",n.currentLocalName=e.localName,n.currentId=e.id,n.currentClassNames=e.classList?Array.from(e.classList):[];let u=1,d=e.previousElementSibling;for(;d;)u++,d=d.previousElementSibling;n.currentSiblingOrder=u;for(let f of this.firstActions)if(f.apply(n),this.checkAppliedAction.applied)break;let h=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,n.currentElement=s,n.currentNamespace=i,n.currentLocalName=o,n.currentId=a,n.currentClassNames=l,n.currentSiblingOrder=c,h}getPriority(){return 5}},Id=class extends Ja{constructor(t,e,n){super(t,e,n)}apply(t){for(let i of this.firstActions)if(i.apply(t),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let e=t.currentElement,n=1,s=e.nextElementSibling;for(;s;)this.matchesSelector(s,t)&&n++,s=s.nextElementSibling;this.matchANPlusB(n)&&this.chained.apply(t)}getPriority(){return 4}},zi=class{constructor(t,e,n){this.condition=t;this.viewConditionId=e;this.viewCondition=n}increment(t){t.increment(this.condition,this.viewCondition)}decrement(t){t.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(t){return t.buildViewConditionMatcher(this.viewConditionId)}},Vd=class r extends zi{constructor(t,e,n){super(t,e,n)}fresh(t){return new r(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,e){return e==0&&this.increment(t),!1}pop(t,e){return e==0?(this.decrement(t),!0):!1}},Fd=class r extends zi{constructor(t,e,n){super(t,e,n)}fresh(t){return new r(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,e){return e==0?this.increment(t):e==1&&this.decrement(t),!1}pop(t,e){return e==0?(this.decrement(t),!0):(e==1&&this.increment(t),!1)}},Bd=class r extends zi{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new r(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,n){return this.fired?(this.decrement(e),!0):!1}pop(e,n){return this.fired?(this.decrement(e),!0):(n==0&&(this.fired=!0,this.increment(e)),!1)}},Od=class r extends zi{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new r(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,n){return this.fired&&(n==-1?this.increment(e):n==0&&this.decrement(e)),!1}pop(e,n){if(this.fired){if(n==-1)return this.decrement(e),!0;n==0&&this.increment(e)}else n==0&&(this.fired=!0,this.increment(e));return!1}},Dd=class{constructor(t,e){this.afterprop=t;this.element=e}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Md=class{constructor(t){this.lang=t}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.lang=this.lang,!0):!1}},_d=class{constructor(t){this.oldQuotes=t}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.quotes=this.oldQuotes,!0):!1}},Ud=class extends fn{constructor(e){super();this.element=e}createValueFromString(e,n){switch(n){case"url":return e?new fe(e):new fe("about:invalid");case"string":default:return e?new D(e):new D("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let n="string",s=null,i=null;if(e.values[0]instanceof W){let o=e.values[0].values;o.length>=2&&(n=o[1].stringValue()),s=o[0].stringValue()}else s=e.values[0].stringValue();return e.values.length>1?i=this.createValueFromString(e.values[1].stringValue(),n):i=this.createValueFromString(null,n),this.element&&this.element.hasAttribute(s)?this.createValueFromString(this.element.getAttribute(s),n):i}};function Oo(r){if(dt(r)){if(r instanceof D)return r.stringValue();if(r instanceof W)return r.values.map(t=>Oo(t)).join("")}return""}var Gi=class extends fn{constructor(e,n,s){super();this.cascade=e;this.element=n;this.counterResolver=s}visitIdent(e){let n=this.cascade,s=n.quotes,i=Math.floor(s.length/2)-1;switch(e.name){case"open-quote":{let o=s[2*Math.min(i,n.quoteDepth)];return n.quoteDepth++,o}case"close-quote":return n.quoteDepth>0&&n.quoteDepth--,s[2*Math.min(i,n.quoteDepth)+1];case"no-open-quote":return n.quoteDepth++,new D("");case"no-close-quote":return n.quoteDepth>0&&n.quoteDepth--,new D("")}return e}format(e,n){return this.cascade.counterStyleStore.format(n,e)}visitFuncCounter(e){let n=e[0].toString(),s=e.length>1?e[1].stringValue():"decimal",i=this.cascade.counters[n];if(i&&i.length){let o=i&&i.length&&i[i.length-1]||0;return new D(this.format(o,s))}else{let o=new O(this.counterResolver.getPageCounterVal(n,a=>this.format(a||0,s)));return new W([o])}}visitFuncCounters(e){let n=e[0].toString(),s=e[1].stringValue(),i=e.length>2?e[2].stringValue():"decimal",o=this.cascade.counters[n],a=new et;if(o&&o.length)for(let c=0;c<o.length;c++)c>0&&a.append(s),a.append(this.format(o[c],i));let l=new O(this.counterResolver.getPageCountersVal(n,c=>{let u=[];if(c.length)for(let h=0;h<c.length;h++)u.push(this.format(c[h],i));let d=a.toString();return d.length&&u.push(d),u.length?u.join(s):this.format(0,i)}));return new W([l])}visitFuncTargetCounter(e){let n=e[0],s;n instanceof fe?s=n.url:s=n.stringValue();let i=e[1].toString(),o=e.length>2?e[2].stringValue():"decimal",a=new O(this.counterResolver.getTargetCounterVal(s,i,l=>this.format(l||0,o)));return new W([a])}visitFuncTargetCounters(e){let n=e[0],s;n instanceof fe?s=n.url:s=n.stringValue();let i=e[1].toString(),o=e[2].stringValue(),a=e.length>3?e[3].stringValue():"decimal",l=new O(this.counterResolver.getTargetCountersVal(s,i,c=>{let u=c.map(d=>this.format(d,a));return u.length?u.join(o):this.format(0,a)}));return new W([l])}visitFuncTargetText(e){let n=e[0],s;n instanceof fe?s=n.url:s=n.stringValue();let i=e.length>1?e[1].stringValue():"content",o=new O(this.counterResolver.getTargetTextVal(s,i));return new W([o])}visitFuncString(e){let n=e.length>0?e[0].stringValue():"",s=e.length>1?e[1].stringValue():"first";return new O(this.counterResolver.getNamedStringVal(n,s))}visitFuncElement(e){let n=e.length>0?e[0].stringValue():"",s=e.length>1?e[1].stringValue():"first";return new O(this.counterResolver.getRunningElementVal(n,s))}visitFuncContent(e){var i,o,a,l,c,u;let n=e.length>0?e[0].stringValue():"text",s="";switch(n){case"text":s=this.element.textContent;break;case"before":case"after":case"marker":{let d=_t(this.cascade.currentStyle,"_pseudos"),h=(o=(i=d==null?void 0:d[n])==null?void 0:i.content)==null?void 0:o.value;s=Oo(h)}break;case"first-letter":{let d=_t(this.cascade.currentStyle,"_pseudos"),h=(Oo((l=(a=d==null?void 0:d.before)==null?void 0:a.content)==null?void 0:l.value)||this.element.textContent||Oo((u=(c=d==null?void 0:d.after)==null?void 0:c.content)==null?void 0:u.value)).match(As);s=h?h[0]:""}break}return new D(s)}visitFuncLeader(e){let n="";if(e[0]instanceof j)switch(e[0].stringValue()){case"dotted":n=".";break;case"solid":n="_";break;case"space":n=" ";break}else e[0]instanceof D&&(n=e[0].stringValue());return n.length==0?new D(""):new O(new ne(null,()=>n,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function ud(r,t,e){let n;if(r.nodeType===1)n=Array.from(r.getClientRects());else{let i=r.ownerDocument.createRange();i.selectNodeContents(r),n=t.getRangeClientRects(i)}return n.reduce((i,o)=>i+(e==="vertical-rl"||e==="vertical-lr"?o.height:o.width),0)}var iy=(r,t,e)=>{let n=t.filter(l=>l.after&&l.viewNode.nodeType===1&&l.viewNode.getAttribute("data-viv-leader"));for(let l of n){let S=function(M){m==="rtl"?u.textContent=(M.startsWith("\u200F")?"":"\u200F")+M+(M.endsWith("\u200F")?"":"\u200F"):u.textContent=M},Xe=function(){let M=e.clientLayout.getElementClientRect(d);return g==="vertical-rl"||g==="vertical-lr"?m==="rtl"?M.top-=Y:M.bottom+=Y:m==="rtl"?M.left-=Y:M.right+=Y,N.left>M.left||N.right<M.right||N.top>M.top||N.bottom<M.bottom},rt=function(){let M,V,z=f.repeat(1e4);if(S(z),Xe())M=1,V=1e4;else return;for(let q=0;q<16;q++){let he="",zt=Math.floor((M+V)/2);for(let qn=0;qn<zt;qn++)he+=f;if(S(he),Xe())V=zt;else{if(M==zt)return;M=zt}}S(f)},Tt=function(M){let V=0,z=d.parentElement;for(;z&&z!==c.viewNode;)V+=e.getComputedInsets(z)[M],z=z.parentElement;return V};var s=S,i=Xe,o=rt,a=Tt;let c=l.parent;for(;c&&c.inline;)c=c.parent;let u=l.viewNode,d=u.parentElement,h=d.getAttribute("data-adapt-pseudo"),f=u.getAttribute("data-viv-leader-value"),{writingMode:g,direction:m,marginInlineEnd:y}=e.clientLayout.getElementComputedStyle(d);u.style.marginInlineStart="1px",S(f),d.style.display="inline-block",d.style.textIndent="0";let C=Vo(c.viewNode),x=(C==null?void 0:C.style.columnFill)||null;C&&(C.style.columnFill="auto");let N=e.clientLayout.getElementClientRect(c.viewNode),E=e.clientLayout.getElementClientRect(d),v=e.parseComputedLength(y),L=[],B=d.parentElement;for(;B.parentElement&&B.parentElement!==c.viewNode;)B=B.parentElement;let H=B.nextSibling;for(;H;){if(H.nodeType===1){let M=H,{display:V,float:z,position:q}=e.clientLayout.getElementComputedStyle(M);if(z!=="none"||q==="absolute"||q==="fixed"){H=H.nextSibling;continue}if(Ot(V))L.push(M);else if(Ng(V))break}else if(H.nodeType===3){let M=H;M.length>0&&L.push(M)}H=H.nextSibling}let Y=L.reduce((M,V)=>M+ud(V,e.clientLayout,g),0);if(h!=="after"){let M=ud(B,e.clientLayout,g),V=ud(d,e.clientLayout,g);Y+=M-V}g==="vertical-rl"||g==="vertical-lr"?(m==="rtl"?N.top+=v:N.bottom-=v,N.top=Math.min(E.top,N.top),N.bottom=Math.max(E.bottom,N.bottom)):(m==="rtl"?N.left+=v:N.right-=v,N.left=Math.min(E.left,N.left),N.right=Math.max(E.right,N.right)),rt();let $e=e.clientLayout.getElementClientRect(d);m=="rtl"?d.style.float="left":d.style.float="right";let at=e.clientLayout.getElementClientRect(d),R=0;m=="rtl"?g=="vertical-rl"||g=="vertical-lr"?R=$e.top-at.top-Tt("top"):R=$e.left-at.left-Tt("left"):g=="vertical-rl"||g=="vertical-lr"?R=at.bottom-$e.bottom-Tt("bottom"):R=at.right-$e.right-Tt("right"),R-=Y,R=Math.max(0,R-.1),d.style.float="",u.style.marginInlineStart=`${R}px`,C&&(x?C.style.columnFill=x:C.style.removeProperty("column-fill"))}};je("POST_LAYOUT_BLOCK",iy);var tp=1/1048576;function Ui(r,t){for(let e in r)t[e]=r[e].clone()}var Hd=class r{constructor(){p(this,"nsCount",0);p(this,"nsPrefix",{});p(this,"tags",{});p(this,"nstags",{});p(this,"epubtypes",{});p(this,"classes",{});p(this,"ids",{});p(this,"pagetypes",{});p(this,"order",0)}clone(){let t=new r;t.nsCount=this.nsCount;for(let e in this.nsPrefix)t.nsPrefix[e]=this.nsPrefix[e];return Ui(this.tags,t.tags),Ui(this.nstags,t.nstags),Ui(this.epubtypes,t.epubtypes),Ui(this.classes,t.classes),Ui(this.ids,t.ids),Ui(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,e,n){let s=t[e];s&&(n=s.mergeWith(n)),t[e]=n}createInstance(t,e,n,s,i){return new zd(this,t,e,n,s,i)}nextOrder(){return this.order+=tp}},zd=class{constructor(t,e,n,s,i,o){this.context=e;this.counterListener=n;this.counterResolver=s;this.counterStyleStore=o;p(this,"code");p(this,"stack",[[],[]]);p(this,"conditions",{});p(this,"currentElement",null);p(this,"currentElementOffset",null);p(this,"currentStyle",null);p(this,"currentClassNames",null);p(this,"currentLocalName","");p(this,"currentNamespace","");p(this,"currentId","");p(this,"currentXmlId","");p(this,"currentNSTag","");p(this,"currentEpubTypes",null);p(this,"currentPageType",null);p(this,"previousPageType",null);p(this,"firstPageType",null);p(this,"pageTypePageCounts",{});p(this,"isFirst",!0);p(this,"isRoot",!0);p(this,"counters",{});p(this,"counterScoping",[{}]);p(this,"quotes");p(this,"quoteDepth",0);p(this,"lang","");p(this,"siblingOrderStack",[0]);p(this,"currentSiblingOrder",0);p(this,"siblingTypeCountsStack",[{}]);p(this,"currentSiblingTypeCounts");p(this,"currentFollowingSiblingOrder",null);p(this,"followingSiblingOrderStack");p(this,"followingSiblingTypeCountsStack",[{}]);p(this,"currentFollowingSiblingTypeCounts");p(this,"viewConditions",{});p(this,"dependentConditions",[]);p(this,"elementStack");this.code=t,this.quotes=[new D("\u201C"),new D("\u201D"),new D("\u2018"),new D("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,e){this.conditions[t]=(this.conditions[t]||0)+1,e&&(this.viewConditions[t]?this.viewConditions[t].push(e):this.viewConditions[t]=[e])}decrement(t,e){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==e),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let e=null;t&&(this.currentElementOffset,e=Ys.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(s=>{let i=this.viewConditions[s];return i&&i.length>0?i.length===1?i[0]:Ys.buildAnyMatcher([].concat(i)):null}).filter(s=>s);return n.length<=0?e:e===null?n.length===1?n[0]:Ys.buildAllMatcher(n):Ys.buildAllMatcher([e].concat(n))}applyAction(t,e){let n=t[e];n&&n.apply(this)}pushRule(t,e,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=dd,this.currentPageType=e,this.applyActions()}defineCounter(t,e){let n=this.counterScoping[this.counterScoping.length-1];n||(n={},this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(e)):this.counters[t]=[e],n[t]=!0}pushCounters(t){var h,f,g,m,y,S,C;let e=b.inline,n=t.display;if(n&&(e=n.evaluate(this.context)),e===b.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 s=b.inline,i=t.float;i&&(s=i.evaluate(this.context));let o=null,a=null,l=null,c=t["counter-reset"];if(c){let x=c.evaluate(this.context);x&&(o=Bs(x,!0))}let u=t["counter-set"];if(u){let x=u.evaluate(this.context);x&&(l=Bs(x,!1))}let d=t["counter-increment"];if(d){let x=d.evaluate(this.context);x&&(a=Bs(x,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(o||(o={}),o["list-item"]=((f=(h=this.currentElement)==null?void 0:h.start)!=null?f:1)-1),Bn(e)&&(a||(a={}),a["list-item"]=(g=a["list-item"])!=null?g:1,/^\s*[-+]?\d/.test((y=(m=this.currentElement)==null?void 0:m.getAttribute("value"))!=null?y:"")&&(l||(l={}),l["list-item"]=this.currentElement.value)),((S=this.currentElement)==null?void 0:S.parentNode.nodeType)===Node.DOCUMENT_NODE&&(o||(o={}),o.footnote===void 0&&(o.footnote=0)),s===b.footnote&&(a||(a={}),a.footnote===void 0)){let x=(C=this.currentStyle["counter-increment"])==null?void 0:C.value;(!x||!(x===b.footnote||x instanceof W&&x.values.includes(b.footnote)))&&(a.footnote=1)}if(o)for(let x in o)this.defineCounter(x,o[x]);if(a)for(let x in a){this.counters[x]||this.defineCounter(x,0);let N=this.counters[x];N[N.length-1]+=a[x]}if(l)for(let x in l)if(!this.counters[x])this.defineCounter(x,l[x]);else{let N=this.counters[x];N[N.length-1]=l[x]}if(Bn(e)){let x=this.counters["list-item"],N=x[x.length-1];t["ua-list-item-count"]=new I(new nt(N),0);let E=Qs(t,"_pseudos");E.marker||(E.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let e in t){let n=this.counters[e];n&&(n.length==1?delete this.counters[e]:n.pop())}}setNamedStrings(t){let e=t["string-set"];if(!e)return;e=e.filterValue(new Gi(this,this.currentElement,this.counterResolver));let n=e.value instanceof ge?e.value.values:[e.value];for(let s of n)if(s instanceof W){let i=s.values[0].stringValue(),o=s.values.slice(1).map(a=>Oo(a)).join("");this.counterResolver.setNamedString(i,o,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let e=t.position;if((e==null?void 0:e.value)instanceof Xt&&e.value.name==="running"){let n=e.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,e){this.pushCounters(t);let n=t.content;n&&(t.content=n.filterValue(new Gi(this,e,this.counterResolver))),this.popCounters()}pushElement(t,e,n,s){var E,v,L;this.currentPageType=null,this.currentElement=e,this.currentElementOffset=s,this.currentStyle=n,this.currentNamespace=e.namespaceURI,this.currentLocalName=e.localName;let i=this.code.nsPrefix[this.currentNamespace];i?this.currentNSTag=i+this.currentLocalName:this.currentNSTag="",this.currentId=e.getAttribute("id"),this.currentXmlId=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let o=e.getAttribute("class");o?this.currentClassNames=o.split(/\s+/):this.currentClassNames=dd;let a=e.getAttributeNS("http://www.idpf.org/2007/ops","type");a?this.currentEpubTypes=a.split(/\s+/):this.currentEpubTypes=dd;let l=ro(e);l&&(this.stack[this.stack.length-1].push(new Md(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,u=this.siblingOrderStack;this.currentSiblingOrder=++u[u.length-1],u.push(0);let d=this.siblingTypeCountsStack,h=this.currentSiblingTypeCounts=d[d.length-1],f=h[this.currentNamespace];f||(f=h[this.currentNamespace]={}),f[this.currentLocalName]=(f[this.currentLocalName]||0)+1,d.push({});let g=this.followingSiblingOrderStack;g[g.length-1]!==null?this.currentFollowingSiblingOrder=--g[g.length-1]:this.currentFollowingSiblingOrder=null,g.push(null);let m=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=m[m.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,m.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,e),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(e);let S=n.quotes,C=null;if(S){let B=S.evaluate(this.context);B&&(C=new _d(this.quotes),B===b.none?this.quotes=[new D(""),new D("")]:B===b.auto||B===b.initial?this.quotes=[new D("\u201C"),new D("\u201D"),new D("\u2018"),new D("\u2019")]:B instanceof W&&(this.quotes=B.values))}this.pushCounters(this.currentStyle);let x=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(c||x){let B={};Object.keys(this.counters).forEach(H=>{B[H]=Array.from(this.counters[H])}),this.counterListener.countersOfId(x,B)}let N=_t(this.currentStyle,"_pseudos");if(N){let B=!0;for(let H of oy){H||(B=!1);let Y=N[H];if(Y)if((H==="before"||H==="after")&&!dt((E=Y.content)==null?void 0:E.value)||H==="marker"&&!Bn((v=pe(this.currentStyle,"display"))==null?void 0:v.value)||(H==="footnote-call"||H==="footnote-marker")&&((L=pe(this.currentStyle,"float"))==null?void 0:L.value)!==b.footnote)delete N[H];else if(B){if(this.processPseudoelementProps(Y,e),H==="marker")this.processMarkerPseudoelementProps(Y,e,t);else if(H==="first-letter"&&Y["initial-letter"]){let rt=Y["initial-letter"].evaluate(this.context);rt!==b.normal&&!X(rt)&&(this.currentStyle["--viv-initialLetter"]=new I(rt,0)),delete Y["initial-letter"]}}else this.stack[this.stack.length-2].push(new Dd(Y,e))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}processMarkerPseudoelementProps(t,e,n){var s,i,o,a,l;if(!dt((s=t.content)==null?void 0:s.value)&&Bn((i=this.currentStyle.display)==null?void 0:i.value)){let c=this.getInheritedPropertyValue("list-style-type",n,e),u=this.getInheritedPropertyValue("list-style-image",n,e);if(u instanceof fe)t.content=new I(new W([u,new D(" ")]),0);else if(c instanceof D)t.content=new I(c,0);else if(c instanceof j&&c!==b.none){let d=(a=(o=this.currentStyle["ua-list-item-count"])==null?void 0:o.value)==null?void 0:a.num;d!=null&&(t.content=new I(new D(this.counterStyleStore.formatMarker(c.name,d)),0)),t["list-style-type"]=new I(c,0)}}if(!Ot((l=pe(this.currentStyle,"display"))==null?void 0:l.value)){let c=this.getInheritedPropertyValue("list-style-position",n,e);c&&(t["list-style-position"]=new I(c,0))}}getInheritedPropertyValue(t,e,n){var i;for(let o=n;o;o=o.parentElement){let l=(o===this.currentElement?this.currentStyle:e.getStyle(o,!1))[t];if(l){let c=l.evaluate(this.context,t);if(c===b.inherit||c===b.unset||c===b.revert)continue;if(c===b.initial)break;return c}}let s=e.validatorSet;return(i=s==null?void 0:s.defaultValues[t])!=null?i:null}applyAttrFilterInner(t,e){for(let n in e)Ks(n)&&!It(n)&&(e[n]=e[n].filterValue(t))}applyAttrFilter(t){let e=new Ud(t),n=this.currentStyle,s=_t(n,"_pseudos");for(let i in s)this.applyAttrFilterInner(e,s[i]);this.applyAttrFilterInner(e,n)}applyVarFilter(t,e,n){var l,c,u;let s=t[0],i=new qd(t,e,n),o=32,a={};for(let d in s)if(fd(d)){let h=_t(s,d);for(let f in h)this.applyVarFilter([h[f],...t],e,n)}else if(Ks(d)){let h=pe(s,d),f=h.value;for(let g=0;;g++){if(g>=o){f=U;break}let m=f.visit(i);if(i.error){f=U,i.error=!1;break}if(m===f)break;f=m}if(f!==h.value){let g=e.validatorSet,m=(l=g==null?void 0:g.shorthands[d])==null?void 0:l.clone();if(m)if(X(f)){for(let y of m.propList){let S=new I(f,h.priority),C=pe(s,y);Un(a,y,hd(this.context,C,S))}delete s[d]}else{let y=yn(e.scope,new Ge(f.toString(),null),"");if(y&&(y.visit(m),!m.error)){for(let S of m.propList){let C=new I((u=(c=m.values[S])!=null?c:g.defaultValues[S])!=null?u:b.initial,h.priority),x=pe(s,S);Un(a,S,hd(this.context,x,C))}delete s[d]}}else s[d]=new I(f,h.priority)}if(a[d]){let g=pe(s,d);g&&g.value!==U&&vn(a,d,g,this.context)}}for(let d in a)s[d]=a[d]}applyCalcFilter(t,e){let n=new sl(e);for(let s in t)if(fd(s)){let i=_t(t,s);for(let o in i)this.applyCalcFilter(i[o],e)}else if(Ks(s)&&!It(s)){let i=pe(t,s),o=i.value.visit(n);o!==i.value&&(t[s]=new I(o,i.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let e=1;e>=-1;--e){let n=this.stack[this.stack.length-e-2];for(t=0;t<n.length;)n[t].push(this,e)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let e=this.stack[this.stack.length-t-2],n=0;for(;n<e.length;)e[n].pop(this,t)?e.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},dd=[],oy=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"];var Gd=null;function Hg(r){Gd=r}var zn=class extends bn{constructor(e,n,s,i,o,a,l){super(e,n,l);this.condition=s;this.regionId=o;this.validatorSet=a;p(this,"chain",null);p(this,"specificity",0);p(this,"elementStyle",null);p(this,"conditionCount",0);p(this,"pseudoelement",null);p(this,"footnoteContent",!1);p(this,"cascade");p(this,"state");p(this,"viewConditionId",null);p(this,"insideSelectorRule");p(this,"invalid",!1);this.cascade=i?i.cascade:Gd?Gd.clone():new Hd,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let n=ep(this.chain,e);n!==e&&n.makePrimary(this.cascade)||this.insertNonPrimary(n)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,n){!n&&!e||(n&&(this.specificity+=1),n&&e?this.chain.push(new bd(e,n.toLowerCase())):n?this.chain.push(new qa(n.toLowerCase())):this.chain.push(new xd(e)))}invalidSelector(e){F.warn(e),this.chain.push(new Ue("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Cs;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 md(e))}pseudoclassSelector(e,n){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Pd);break;case"disabled":this.chain.push(new kd);break;case"checked":this.chain.push(new Ad);break;case"root":case"scope":this.chain.push(new vd);break;case"link":this.chain.push(new qa("a")),this.chain.push(new Ka("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(n&&n.length>=1&&typeof n[0]=="string"){let s=n[0],i=new RegExp(`(^|\\s)${An(s)}($|\\s)`),o=n[1];this.chain.push(new yd(i,o))}else this.chain.push(new Ue(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ue(""));break;case"lang":if(n&&n.length==1&&typeof n[0]=="string"){let s=n[0];this.chain.push(new Nd(new RegExp(`^${An(s.toLowerCase())}($|-)`)))}else this.chain.push(new Ue(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let s=ry[e.toLowerCase()];n&&n.length==2?this.chain.push(new s(n[0],n[1])):this.chain.push(new Ue(""));break}case"first-child":this.chain.push(new Za);break;case"last-child":this.chain.push(new _o(0,1));break;case"first-of-type":this.chain.push(new Mo(0,1));break;case"last-of-type":this.chain.push(new Uo(0,1));break;case"only-child":this.chain.push(new Za),this.chain.push(new _o(0,1));break;case"only-of-type":this.chain.push(new Mo(0,1)),this.chain.push(new Uo(0,1));break;case"empty":this.chain.push(new wd);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,n);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,n){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(n&&n.length==1&&typeof n[0]=="number"){let s=Math.round(n[0]);if(s>0&&s==n[0]){if(!this.pseudoelement)this.pseudoelement=`first-${s}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ue(""));break;case"nth-fragment":n&&n.length==2?this.viewConditionId=`NFS_${n[0]}_${n[1]}`:this.chain.push(new Ue(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new Cd(e))}attributeSelector(e,n,s,i){this.specificity+=256,n=n.toLowerCase(),i=i||"";let o;switch(s){case 0:o=new Ka(e,n);break;case 39:o=new Sd(e,n,i);break;case 45:!i||i.match(/\s/)?o=new Ue(""):o=new qs(e,n,new RegExp(`(^|\\s)${An(i)}($|\\s)`));break;case 44:o=new qs(e,n,new RegExp(`^${An(i)}($|-)`));break;case 43:i?o=new qs(e,n,new RegExp(`^${An(i)}`)):o=new Ue("");break;case 42:i?o=new qs(e,n,new RegExp(`${An(i)}$`)):o=new Ue("");break;case 46:i?o=new qs(e,n,new RegExp(An(i))):o=new Ue("");break;case 50:if(i=="supported")o=new Ed(e,n);else{this.invalidSelector(`Unsupported :: attr selector op: ${i}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${s}`);return}this.chain.push(o)}descendantSelector(){let e=`d${ja++}`;this.processChain(new Hi(new Vd(e,this.viewConditionId,null))),this.chain=[new Ue(e)],this.viewConditionId=null}childSelector(){let e=`c${ja++}`;this.processChain(new Hi(new Fd(e,this.viewConditionId,null))),this.chain=[new Ue(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${ja++}`;this.processChain(new Hi(new Bd(e,this.viewConditionId,null))),this.chain=[new Ue(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${ja++}`;this.processChain(new Hi(new Od(e,this.viewConditionId,null))),this.chain=[new Ue(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,n){super.error(e,n),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 n=this.regionId;return this.footnoteContent&&(n?n="xxx-bogus-xxx":n="footnote"),new Zs(this.elementStyle,e,this.pseudoelement,n,this.viewConditionId)}special(e,n){let s;this.condition?s=new Do(n,0,this.condition):s=new I(n,0),_g(this.elementStyle,e).push(s)}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){e=="display"&&(n===b.oeb_page_head||n===b.oeb_page_foot)&&(this.simpleProperty("flow-options",new W([b.exclusive,b._static]),s),this.simpleProperty("flow-into",n,s),n=b.block),qe("SIMPLE_PROPERTY").forEach(c=>{let d=c({name:e,value:n,important:s});e=d.name,n=d.value,s=d.important});let a=(s?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),l=this.condition?new Do(n,a,this.condition):new I(n,a);vn(this.elementStyle,e,l)}finish(){return this.cascade}startFuncWithSelector(e,n){let s;switch(e){case"is":s=new Cs(this);break;case"not":s=new Wd(this);break;case"where":s=new Xd(this);break;case"has":s=new $d(this);break;case"nth-child":n&&n.length>=2&&(s=new el(this,n[0],n[1]));break;case"nth-last-child":n&&n.length>=2&&(s=new jd(this,n[0],n[1]));break}s&&(s.startSelectorRule(),this.owner.pushHandler(s))}},ry={"nth-child":Td,"nth-of-type":Mo,"nth-last-child":_o,"nth-last-of-type":Uo},ja=0,Cs=class r extends zn{constructor(e){super(e.scope,e.owner,e.condition,e,e.regionId,e.validatorSet,!1);this.parent=e;p(this,"parentChain");p(this,"chains",[]);p(this,"maxSpecificity",0);p(this,"selectorTexts",[]);this.parentChain=e.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 Rd(this.selectorTexts):this.positive()?new Ho(this.chains):new Ld(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ue("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(e,n){super.error(e,n),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let s=!1;for(let i=this;i instanceof r;i=i.parent)if(i.forgiving()){s=!0;break}s||this.owner.popHandler()}pushSelectorText(e){this.chain&&this.relational()&&this.selectorTexts.push(e)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Wd=class extends Cs{positive(){return!1}forgiving(){return!1}},Xd=class extends Cs{increasingSpecificity(){return!1}},$d=class extends Cs{relational(){return!0}},el=class extends Cs{constructor(e,n,s){super(e);this.a=n;this.b=s}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Ja(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ue("")),this.owner.popHandler()}forgiving(){return!0}},jd=class extends el{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Id(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ue("")),this.owner.popHandler()}},tl=class extends bn{constructor(t,e){super(t,e,!1)}property(t,e,n){if(this.scope.values[t])this.error(`E_CSS_NAME_REDEFINED ${t}`,this.getCurrentToken());else{let s=t.match(/height|^(top|bottom)$/)?"vh":"vw",i=new en(this.scope,100,s);this.scope.defineName(t,e.toExpr(this.scope,i))}}},bs=class extends bn{constructor(e,n,s,i,o,a){super(e,n,!1);this.condition=s;this.elementStyle=i;this.validatorSet=o;this.ruleType=a;p(this,"order");this.order=0}property(e,n,s){s?F.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){F.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){F.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let i=s?this.getImportantSpecificity():this.getBaseSpecificity();i+=this.order,this.order+=tp;let o=this.condition?new Do(n,i,this.condition):new I(n,i);vn(this.elementStyle,e,o)}},Yd=class extends Eo{constructor(e,n){super(e);this.validatorSet=n;p(this,"elementStyle",{});p(this,"order",0)}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){F.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){F.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let i=s?Na:Ea;i+=this.order,this.order+=tp;let o=new I(n,i);vn(this.elementStyle,e,o)}};function np(r,t){let e=Mg(r);e&&e.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function nl(r,t,e){np(e,n=>{Xi(r,n,t)})}function zg(r,t,e,n){let s=new Yd(r,t),i=new Ge(n,s);try{$f(i,s,e)}catch(o){F.warn(o,"Style attribute parse error:")}return s.elementStyle}function al(r,t,e){let n=r["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.vertical_rl}return e}function ll(r,t,e){let n=r.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.rtl}return e}function cl(r,t,e,n,s){let i={};for(let o in r)Ks(o)&&(i[o]=pe(r,o));return nl(i,t,r),sp(r,e,n,(o,a)=>{Xi(i,a,t),nl(i,t,a)}),i}function sp(r,t,e,n){let s=_t(r,"_regions");if((t||e)&&s){if(e){let i=["footnote"];t?t=t.concat(i):t=i}for(let i of t){let o=s[i];o&&n(i,o)}}}function Xi(r,t,e){for(let n in t)if(Ks(n)){let s=pe(t,n),i=r[n];r[n]=hd(e,i,s)}}var ul=(r,t,e,n,s,i)=>{var l,c;let o=e?n?Jb:Zd:n?ey:Qd,a=s?ty:ny;for(let u in r){let d=r[u];if(!d)continue;let h=(l=o[u])!=null?l:o[a[u]],f=(c=a[u])!=null?c:a[o[u]],g=h!=null?h:f,m;if(g){let y=r[g];if(y&&y.priority>d.priority||h&&f&&h!==f&&(g=f,y=r[g],y&&y.priority>d.priority))continue;m=Bg[h]?h:Bg[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===b.inside||d.value===b.outside)&&(d=new I(s===(d.value===b.inside)?b.right:b.left,d.priority));t[m]=i(u,d)}},qd=class extends fn{constructor(e,n,s){super();this.elementStyles=e;this.styler=n;this.element=s}getVarValue(e){var s,i,o,a,l;let n=(s=this.element)!=null?s:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let c of this.elementStyles){let u=(o=c[e])==null?void 0:o.value;if(u)return u}this.element&&(n=this.element.parentElement)}for(;n;n=n.parentElement){let c=(l=(a=this.styler.getStyle(n,!1))==null?void 0:a[e])==null?void 0:l.value;if(c)return c}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let n=e.values[0]instanceof j&&e.values[0].name;if(!n||!It(n))return this.error=!0,U;let s=this.getVarValue(n);return s||(e.values.length<2?(this.error=!0,U):e.values.length===2?e.values[1]:new ge(e.values.slice(1)))}},sl=class extends fn{constructor(e,n,s,i){super();this.context=e;this.resolveViewportUnit=n;this.percentRef=s;this.vertical=i}visitFunc(e){let n=super.visitFunc(e);if(e.name!=="calc")return n;let s=n.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(s))return n;let i=yn(this.context.rootScope,new Ge(s,null),"");if(i instanceof O)try{let o=i.expr.evaluate(this.context);typeof o=="number"&&!isNaN(o)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(s)?n=new P(o,"px"):/\d[a-z]/i.test(s)||(n=new nt(o)))}catch(o){F.warn(o)}return n}visitNumeric(e){return this.resolveViewportUnit&&(Wc(e.unit)||Ef(e.unit))?new P(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new P(e.num*this.percentRef/100,"px"):e}};function Go(r,t,e,n,s){try{if(t instanceof O)return t.expr instanceof ne&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:jf(r,t.expr,e);if(t instanceof P||t instanceof Xt||t instanceof W||t instanceof ge)return t.visit(new sl(r,!0,n,s))}catch(i){return F.warn(i),U}return t}var Gg={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Wg(r){let t=r instanceof ke?r:typeof r=="string"?k(r):b.none;if(t===b.none)return Gg;let e=t instanceof W?t.values:[t],n=Object.create(Gg);for(let s of e)if(s instanceof j)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 Xg(r){return!r.first&&!r.last&&!r.forceEnd&&!r.allowEnd}var ay={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},$g={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},jg={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Yg(r){let t=r instanceof ke?r:typeof r=="string"?k(r):b.normal;if(t===b.normal)return $g;if(t===b.auto)return jg;let e=t instanceof W?t.values:[t],n=Object.create($g);for(let s of e)if(s instanceof j)switch(s.name){case"trim-both":case"trim-auto":return jg;case"space-all":return ay;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 ip={ideographAlpha:!1,ideographNumeric:!1},ly={ideographAlpha:!0,ideographNumeric:!0};function qg(r){let t=r instanceof ke?r:typeof r=="string"?k(r):b.normal;if(t===b.normal||t===b.auto)return ly;if(t===b.none)return ip;let e=t instanceof W?t.values:[t],n=Object.create(ip);for(let s of e)if(s instanceof j)switch(s.name){case"no-autospace":return ip;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Kg(r,t){return!r.ideographAlpha&&!r.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Zg(r){return r?(r=r.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(r)?"zh-hant":/^zh\b/.test(r)?"zh-hans":/^ja\b/.test(r)?"ja":/^ko\b/.test(r)?"ko":r):null}var op=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(t){t.body&&this.preprocessForTextSpacing(t.body)}preprocessForTextSpacing(t){var n;let e=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT);for(let s=e.nextNode();s;s=e.nextNode()){if(s.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((n=s.parentElement.dataset)==null?void 0:n.mathTypeset)==="true")continue;let i=s.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(i.length>1){let o=i.length-1;for(let a=0;a<o;a++)s.parentNode.insertBefore(document.createTextNode(i[a]),s);s.textContent=i[o]}}}processGeneratedContent(t,e,n,s,i,o){i=Zg(i);let a=qg(e),l=Yg(n),c=Wg(s);if(Xg(c)&&Kg(a,l))return;this.preprocessForTextSpacing(t);let u=t.style.whiteSpace;(o?t.offsetHeight:t.offsetWidth)===0&&(t.style.whiteSpace="pre");let d=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),h=null,f=null;for(let g=d.nextNode();g;g=f){f=d.nextNode();let m=!h,y=!h||/\n$/.test(h.textContent),S=!f||/^\n/.test(f.textContent),C=!f;this.processTextSpacing(g,m||y,m,y,S,C,h,f,a,l,c,i,o),h=g}t.style.whiteSpace=u}postLayoutBlock(t,e){var d,h,f,g,m,y,S;let n=!t||t.fragmentIndex===1&&o(),s=n||a();function i(C){var v;if((C==null?void 0:C.nodeType)!==1)return!1;let x=C;if(x.hasAttribute(Sn))return!0;let{position:N,float:E}=(v=x.style)!=null?v:{};return N==="absolute"||N==="fixed"||E&&E!=="none"}function o(){let C=e[0];for(let x=C;;x=x.parent)if(!x||!x.inline){if((x==null?void 0:x.fragmentIndex)!==1)return!1;break}if(!C.inline)return!0;for(let x=C.viewNode.previousSibling;x;x=x.previousSibling)if(!me(x,C.whitespace)&&!i(x))return!1;return!0}function a(){var N,E;let C=e[0],x;for(;C&&C.inline&&(x=(N=C.viewNode)==null?void 0:N.previousSibling,!(x&&(x.nodeType===3&&/^[ \t\r\n\f]*$/.test(x.textContent)&&C.whitespace!==it.PRESERVE&&(x=x.previousSibling),x)));)C=C.parent;for(;x;){if(x.nodeType===1){if(x.localName==="br")return!0;let v=(E=x.style)==null?void 0:E.display;if(v&&v!=="inline")return!/^(inline|ruby)\b/.test(v)}else if(x.nodeType===3){if(C.whitespace===it.PRESERVE){if(/\n$/.test(x.textContent))return!0}else if(C.whitespace===it.NEWLINE&&/\n[ \t\r\n\f]*$/.test(x.textContent))return!0}x=x.lastChild}return!1}let l=-1;for(let C=0;C<e.length;C++){let x=e[C];if(!x.after&&x.inline&&!x.display&&x.parent&&x.viewNode.parentNode&&x.viewNode.nodeType===Node.TEXT_NODE&&!me(x.viewNode,x.whitespace)){let Tt=function(V){var z,q,he;if(((z=V.viewNode)==null?void 0:z.nodeType)===1)return V.viewNode.localName==="br";if(((q=V.viewNode)==null?void 0:q.nodeType)===3){if(V.whitespace===it.PRESERVE){if(/\n$/.test(V.viewNode.textContent))return!0}else if(V.whitespace===it.NEWLINE&&/\n[ \t\r\n\f]*$/.test(V.viewNode.textContent))return!0;if(((he=V.viewNode.previousElementSibling)==null?void 0:he.localName)==="br")return me(V.viewNode,V.whitespace)}return!1},R=function(V){var z,q,he;if(((z=V.viewNode)==null?void 0:z.nodeType)===1)return V.viewNode.localName==="br";if(((q=V.viewNode)==null?void 0:q.nodeType)===3){if(V.whitespace===it.PRESERVE){if(/^\n/.test(V.viewNode.textContent))return!0}else if(V.whitespace===it.NEWLINE&&/^[ \t\r\n\f]*\n/.test(V.viewNode.textContent))return!0;if(((he=V.viewNode.nextElementSibling)==null?void 0:he.localName)==="br")return me(V.viewNode,V.whitespace)}return!1};var c=Tt,u=R;let N=Zg((g=(h=(d=x.lang)!=null?d:x.parent.lang)!=null?h:t==null?void 0:t.lang)!=null?g:(f=t==null?void 0:t.parent)==null?void 0:f.lang),E=qg(x.inheritedProps["text-autospace"]),v=Yg(x.inheritedProps["text-spacing-trim"]),L=Wg(x.inheritedProps["hanging-punctuation"]);if(Xg(L)&&Kg(E,v)||/\b(flex|grid)\b/.test(x.parent.display))continue;l<0&&(l=C);let B=null,H=null,Y=C===l,Xe=C===l&&n,rt=C===l&&s,$e=!1,at=!1;for(let V=C-1;V>=0;V--){let z=e[V];if(Tt(z)){rt=!0;break}if(!z.display&&z.viewNode.nodeType===Node.TEXT_NODE&&z.viewNode.textContent.length>0){B=z.viewNode;break}if(z.display&&!/^(inline|ruby)\b/.test(z.display)||((m=z.viewNode)==null?void 0:m.nodeType)===1&&(z.viewNode.localName==="br"||pn[z.viewNode.localName]))break;V===0&&(Y=!0,n&&(Xe=!0,rt=!0))}for(let V=C+1;V<e.length;V++){let z=e[V];if(R(z)){$e=!0;break}if(z.viewNode!==x.viewNode&&!z.display&&z.viewNode.nodeType===Node.TEXT_NODE&&z.viewNode.textContent.length>0){H=z.viewNode;break}if(z.display&&!/^(inline|ruby)\b/.test(z.display)||((y=z.viewNode)==null?void 0:y.nodeType)===1&&(z.viewNode.localName==="br"||pn[z.viewNode.localName])){V===e.length-1&&i(z.viewNode)&&(at=!0);break}if(V===e.length-1){$e=!0,at=!0;for(let q=z.viewNode.nextSibling;q;q=q.nextSibling)if(!i(q)){at=!1;break}}}if(((S=x.parent)==null?void 0:S.display)==="inline-block"){if(!Xe){let V=x.parent.viewNode.firstChild;for(;me(V,x.whitespace);)V=V.nextSibling;x.viewNode===V&&(Xe=!0)}if(!at){let V=x.parent.viewNode.lastChild;for(;me(V,x.whitespace);)V=V.previousSibling;x.viewNode===V&&(at=!0)}}if(this.processTextSpacing(x.viewNode,Y,Xe,rt,$e,at,B,H,E,v,L,N,x.vertical)>0)break}}}processTextSpacing(t,e,n,s,i,o,a,l,c,u,d,h,f){let g=t.textContent,m=t.ownerDocument,y=0,S,C,x;function N(){if(e)return!0;if(!a)return!1;S||(S=m.createRange(),S.selectNode(t));let R=S.getClientRects()[0];if(!R)return!1;C||(C=m.createRange(),C.selectNode(a));let M=C.getClientRects(),V=M[M.length-1];return V?(y||(y=Di(V,f)),f?R.top<V.top+V.height-R.width||R.left+R.width<V.left+R.width/10||R.left>V.left+V.width-R.width/10:R.left<V.left+V.width-R.height||R.top>V.top+V.height-R.height/10||R.top+R.height<V.top+R.height/10):!1}function E(){if(!l)return!1;S||(S=m.createRange(),S.selectNode(t));let R=S.getClientRects()[0];if(!R)return!1;y||(y=Di(R,f)),x||(x=m.createRange(),x.selectNode(l));let M=x.getClientRects()[0];return M?f?R.top+R.height>M.top+R.width||R.left>M.left+M.width-R.width/10||R.left+R.width<M.left+R.width/10:R.left+R.width>M.left+R.height||R.top+R.height<M.top+R.height/10||R.top>M.top+M.height-R.height/10:!1}let v=!1,L=!1,B=!1,H=!1,Y;if(n&&d.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(g)?(Y="viv-ts-open",v=!0,L=!0):o&&d.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(g)?(Y="viv-ts-close",v=!0,B=!0):(d.forceEnd||d.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(g)?(Y="viv-ts-close",v=!0,H=!0):(u.trimStart||u.spaceFirst||u.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(g)?(Y="viv-ts-open",v=!0):(u.trimEnd||u.allowEnd||u.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(g)||h==="zh-hans"&&/^[:;]\p{M}*$/u.test(g)||h!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(g))&&(Y="viv-ts-close",v=!0),v){let V=function(he){let qn=parseFloat(m.defaultView.getComputedStyle(he).fontSize)*.7;return(f?he.offsetHeight:he.offsetWidth)>qn},q=function(){return f?R.offsetLeft:R.offsetTop};var at=V,Tt=q;if(t.parentElement.localName==="viv-ts-inner")return 0;let R=m.createElement(Y),M=m.createElement("viv-ts-inner");R.appendChild(M),t.parentNode.insertBefore(R,t),M.appendChild(t);let z=V(M);if(z||L||B||H){if(Y==="viv-ts-open"){if(L)R.className="viv-hang-first";else if(n||s)u.trimStart?R.className="viv-ts-trim":R.className="viv-ts-space";else if(!(u.trimStart||u.spaceFirst)&&N())R.className="viv-ts-space";else if(u.trimAdjacent&&a&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(a.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(a.textContent)||a.parentElement.localName==="viv-ts-inner"&&V(a.parentElement)))R.className="viv-ts-trim";else if((u.trimStart||u.spaceFirst)&&N()){let he=q();R.className="viv-ts-auto",he===q()&&!N()&&(R.className="viv-ts-trim")}}else if(Y==="viv-ts-close"){if(B)R.className=z?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(o||i){let he=q();H?(R.className=z?d.allowEnd&&u.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",d.allowEnd&&he===q()&&(u.trimEnd?R.className="viv-ts-trim":u.allowEnd?(R.className="viv-hang-end",he===q()&&(R.className="")):R.className="viv-ts-space")):u.trimEnd?R.className="viv-ts-trim":u.allowEnd?(R.className="viv-ts-auto",he===q()&&(R.className="")):R.className="viv-ts-space"}else if(l&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(l.textContent))z&&u.trimAdjacent&&(R.className="viv-ts-trim");else if(H){let he=E(),zt=he&&d.allowEnd;zt||(R.className=z?"viv-hang-end":"viv-hang-end viv-hang-hw"),z?zt&&u.trimEnd?R.className="viv-ts-auto":!zt&&!E()?R.className="":!he&&d.allowEnd&&(u.trimEnd?(R.className="viv-ts-auto",E()||(R.className="viv-hang-end")):(R.className="viv-ts-space",E()||(u.allowEnd?(R.className="viv-ts-auto",E()||(R.className="viv-hang-end")):R.className="viv-hang-end"))):!he&&!E()&&(R.className="")}else if(u.trimEnd||u.allowEnd)if(E())u.allowEnd?R.className="viv-ts-space":R.className="viv-ts-auto";else{let he=q();R.className="viv-ts-auto",he===q()&&(R.className="")}}}}let Xe=!1;function rt(R){var V;let M=(V=R==null?void 0:R.ownerDocument.defaultView)==null?void 0:V.getComputedStyle(R);return!!M&&(M.textOrientation==="upright"||M.textCombineUpright==="all"||M["-webkit-text-combine"]==="horizontal")}function $e(R,M){if(R.nodeType===1){let q=m.defaultView.getComputedStyle(R);if(parseFloat(q.marginInlineEnd)||parseFloat(q.borderInlineEndWidth)||parseFloat(q.paddingInlineEnd))return!0}let V=R.parentElement;if(V&&!V.contains(M))return $e(V,M);if(M.nodeType===1){let q=m.defaultView.getComputedStyle(M);if(parseFloat(q.marginInlineStart)||parseFloat(q.borderInlineStartWidth)||parseFloat(q.paddingInlineStart))return!0}let z=M.parentElement;return z&&!z.contains(R)?$e(R,z):!1}return(c.ideographAlpha||c.ideographNumeric)&&(a&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(g)&&(c.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(a.textContent)||c.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(a.textContent))&&!(f&&rt(a.parentElement))&&!$e(a,t)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t),Xe=!0),l&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(g)&&(c.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(l.textContent)||c.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(l.textContent))&&!(f&&rt(l.parentElement))&&!$e(t,l)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t.nextSibling),Xe=!0)),y}registerHooks(){je("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),je("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),je("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},rp=new op;rp.registerHooks();function Qg(r){rp.preprocessForTextSpacing(r)}function Jg(r,t,e,n,s,i){rp.processGeneratedContent(r,t,e,n,s,i)}var $i=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),tm=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],dl="data-adapt-pseudo";function Js(r){return r.getAttribute(dl)||""}function Xo(r,t){r.setAttribute(dl,t)}var Wo=class{constructor(t,e,n,s,i){this.element=t;this.style=e;this.styler=n;this.context=s;this.exprContentListener=i;p(this,"contentProcessed",{})}getStyle(t,e){let n=Js(t);this.styler&&n&&n.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let s=_t(this.style,"_pseudos"),i=(s==null?void 0:s[n])||{};if(n.match(/^first-/)&&!i["x-first-pseudo"]){let o=1,a;n=="first-letter"?o=0:(a=n.match(/^first-([0-9]+)-lines$/))!=null&&(o=a[1]-0),i["x-first-pseudo"]=new I(new se(o),0)}return i}processContent(t,e,n){let s=Js(t);if(!this.contentProcessed[s]){this.contentProcessed[s]=!0,s==="marker"&&this.processMarker(t,e,n);let i=e.content;dt(i)&&(i.visit(new Vn(t.classList.contains("_viv-marker-outside")&&t.firstElementChild||t,this.context,i,this.exprContentListener)),Qg(t))}}processMarker(t,e,n){let s=e.content,i=e["list-style-position"],o=e["list-style-type"];if(dt(s)){if(s instanceof fe)e.content=new W([s]);else if(s instanceof D&&o instanceof j){let a=o.name.toLowerCase();if((a==="disc"||a==="circle"||a==="square"||a==="disclosure-open"||a==="disclosure-closed")&&(t.classList.add("_viv-marker-bullet"),a==="disclosure-open"||a==="disclosure-closed")){let l=n.direction==="rtl",c=n.vertical;e.content=new D(a==="disclosure-open"?c?"\u25C2 ":"\u25BE ":c?l?"\u25B4 ":"\u25BE ":l?"\u25C2 ":"\u25B8 ")}}}if(i===b.outside){t.classList.add("_viv-marker-outside");let a=t.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","span");a.classList.add("_viv-marker-outside-content"),t.appendChild(a);let l=n.inheritedProps["text-spacing-trim"];l&&l!=="space-all"&&(e["text-spacing-trim"]=b.normal),n.inheritedProps["hanging-punctuation"]&&(e["hanging-punctuation"]=b.none)}delete e["list-style-position"],delete e["list-style-type"]}};var HS=vo.isInstanceOfAfterIfContinuesLayoutConstraint,im=ms.registerFragmentIndex,zS=ms.clearFragmentIndices,pl=class{constructor(t,e){this.sourceNode=t;this.styler=e}createElement(t,e){let s=e.viewNode.ownerDocument.createElement("div"),i=new ni(t,s,e),o=i.getColumn().pageBreakType;return i.getColumn().pageBreakType=null,i.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,i.getColumn().pageBreakType=o;let a=s.firstChild;return w(a,"display","block"),T(a)})}createNodePositionForPseudoElement(){let t=$i.createElementNS("http://www.w3.org/1999/xhtml","div");Xo(t,"after-if-continues");let e=this.createShadowContext(t),s={steps:[{node:t,shadowType:e.type,shadowContext:e,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new Nt(s)}createShadowContext(t){return new Ws(this.sourceNode,t,null,null,null,jt.ShadowType.ROOTED,this.styler)}},ap=class r{constructor(t,e,n){this.nodeContext=t;this.afterIfContinues=e;this.pseudoElementHeight=n;p(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,e,n){return!(e&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,e,n,s){}finishBreak(t,e){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(e,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new lp(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof r?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},lp=class{constructor(t,e){this.nodeContext=t;this.pseudoElementHeight=e}calculateOffset(t){return this.affectTo(t)?this.pseudoElementHeight:0}calculateMinimumOffset(t){return this.calculateOffset(t)}affectTo(t){if(!t)return!1;let e=t.shadowContext?t.shadowContext.owner:t.sourceNode;if(e===this.nodeContext.sourceNode)return!!t.after;for(let n=e.parentNode;n;n=n.parentNode)if(n===this.nodeContext.sourceNode)return!0;return!1}};function om(r,t){if(!r||!r.afterIfContinues||r.after||t.isFloatNodeContext(r))return T(r);let e=r.afterIfContinues;return e.createElement(t,r).thenAsync(n=>{let s=uy(r,t,n);return t.fragmentLayoutConstraints.push(new ap(r,e,s)),T(r)})}function pp(r,t){return r.thenAsync(e=>om(e,t))}function cy(r,t){let e=A("processAfterIfContinuesOfAncestors"),n=r;return e.loop(()=>{if(n!==null){let s=om(n,t);return n=n.parent,s.thenReturn(!0)}else return T(!1)}).then(()=>{e.finish(!0)}),e.result()}function uy(r,t,e){let n=r.viewNode;n.appendChild(e);let s=Fo(e,t,r.vertical);return n.removeChild(e),s}var hl=class{constructor(t){this.constraints=t}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},ei=class extends $s{constructor(e,n){super();this.checkPoints=e;this.penalty=n;p(this,"alreadyEvaluated",!1);p(this,"breakNodeContext",null)}findAcceptableBreak(e,n){return n<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,n>0),this.alreadyEvaluated=!!this.breakNodeContext||n>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}};var ti=class r extends Bi{constructor(e,n,s,i,o){super(e);this.layoutContext=n;this.clientLayout=s;this.layoutConstraint=i;this.pageFloatLayoutContext=o;p(this,"last");p(this,"viewDocument");p(this,"flowRootFormattingContext",null);p(this,"isFloat",!1);p(this,"isFootnote",!1);p(this,"startEdge",0);p(this,"endEdge",0);p(this,"beforeEdge",0);p(this,"afterEdge",0);p(this,"footnoteEdge",0);p(this,"box",null);p(this,"chunkPositions",null);p(this,"bands",null);p(this,"overflown",!1);p(this,"breakPositions",null);p(this,"pageBreakType",null);p(this,"forceNonfitting",!0);p(this,"leftFloatEdge",0);p(this,"rightFloatEdge",0);p(this,"bottommostFloatTop",0);p(this,"stopAtOverflow",!0);p(this,"lastAfterPosition",null);p(this,"fragmentLayoutConstraints",[]);p(this,"pseudoParent",null);p(this,"nodeContextOverflowingDueToRepetitiveElements",null);p(this,"blockDistanceToBlockEndFloats",NaN);p(this,"breakAtTheEdgeBeforeFloat",null);new.target===r&&wg(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,o.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 n=A("openAllViews"),s=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let i=s.length-1,o=null;return n.loop(()=>{for(;i>=0;){let a=o,l=s[i];if(o=Oi(l,a),i===s.length-1&&!o.formattingContext&&(o.formattingContext=this.flowRootFormattingContext),i==0&&(o.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),o.after=e.after,o.preprocessedTextContent=e.preprocessedTextContent,o.after))break;let c=this.layoutContext.setCurrent(o,i==0&&o.offsetInNode==0);if(i--,c.isPending())return c}return T(!1)}).then(()=>{n.finish(o)}),n.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?ug(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,n){var s,i;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let o=e.viewNode.textContent,a=o.match(As),l=a?a[0].length:0;if(!a&&((s=e.sourceNode)==null?void 0:s.nodeType)===3&&((i=e.sourceNode.nextSibling)==null?void 0:i.nodeType)===3&&o===e.sourceNode.textContent){let c=o+e.sourceNode.nextSibling.textContent,u=c.match(As);if(u){let d=u[0];l=d.length,e.sourceNode.textContent=d,e.viewNode.textContent=d,e.sourceNode.nextSibling.textContent=c.substr(l)}}return this.layoutContext.peelOff(e,l)}return T(e)}buildViewToNextBlockEdge(e,n){let s=!1,i=A("buildViewToNextBlockEdge");return i.loopWithFrame(o=>{var a;if(e.viewNode&&!Dn(e)&&((a=e.viewNode.parentElement)==null?void 0:a.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(n.push(e.copy()),n.length>1e3)){let c=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,u=this.clientLayout.getElementClientRect(c);if(Di(u,this.vertical)>=2){o.breakLoop();return}}this.maybePeelOff(e,0).then(l=>{let c=l;c!==e&&(e=c,Dn(e)||n.push(e.copy())),this.nextInTree(e).then(u=>{if(e=u,!e){o.breakLoop();return}(s||!this.layoutConstraint.allowLayout(e))&&(s=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(us(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(d=>{if(e=d,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){o.breakLoop();return}o.continueLoop()}):e.inline?o.continueLoop():o.breakLoop()})})}).then(()=>{i.finish(e)}),i.result()}nextInTree(e,n){let s=this.layoutContext.nextInTree(e,n);return pp(s,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let n=[],s=e.sourceNode,i=A("buildDeepElementView");return i.loopWithFrame(o=>{e.viewNode&&e.inline&&!Dn(e)?n.push(e.copy()):(n.length>0&&this.postLayoutBlock(e,n),n=[]),this.maybePeelOff(e,0).then(a=>{let l=a;if(l!==e){let c=l;for(;c&&c.sourceNode!=s;)c=c.parent;if(c==null){e=l,o.breakLoop();return}Dn(l)||n.push(l.copy())}this.nextInTree(l).then(c=>{e=c,!e||e.sourceNode==s?o.breakLoop():this.layoutConstraint.allowLayout(e)?o.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?o.breakLoop():o.continueLoop())})})}).then(()=>{n.length>0&&this.postLayoutBlock(e,n),i.finish(e)}),i.result()}createFloat(e,n,s,i){let o=this.viewDocument.createElement("div");return this.vertical?(i>=this.height&&(i-=.1),i<1&&(i=0),w(o,"height",`${s}px`),w(o,"width",`${i}px`)):(s>=this.width&&(s-=.1),s<1&&(s=0),w(o,"width",`${s}px`),w(o,"height",`${i}px`)),w(o,"float",n),w(o,"clear",n),this.element.insertBefore(o,e),o}killFloats(){let e=this.element.firstChild;for(;e;){let n=e.nextSibling;if(e.nodeType==1){let s=e,i=s.style.cssFloat;if(i=="left"||i=="right"||i==="none")this.element.removeChild(s);else break}e=n}}createFloats(){let e=this.element.firstChild,n=this.bands,s=this.vertical?this.getTopEdge():this.getLeftEdge(),i=this.vertical?this.getBottomEdge():this.getRightEdge(),o=null;for(let a of n){let l=a.y2-a.y1;a.left=this.createFloat(e,"left",a.x1-s,l),a.right=this.createFloat(e,"right",i-a.x2,l),a.x1<i&&a.x2>s?o=a:o||w(a.right,"float","none")}if(o){let a=n[n.length-1],l=this.vertical?-this.getLeftEdge():this.getBottomEdge();o!==a&&a.y2>=l&&(this.footnoteEdge=this.vertical?-o.y2:o.y2)}}calculateEdge(e,n,s,i){let o;if(e&&On(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(o=ds(e,this.clientLayout,0,this.vertical),!isNaN(o)))return o;e=n[s];let a=i-e.boxOffset;for(;;){if(o=ds(e,this.clientLayout,a,this.vertical),!isNaN(o))return o;if(a>0){a--;continue}if(s--,s<0)return this.beforeEdge;e=n[s],e.viewNode.nodeType!=1&&(a=e.viewNode.textContent.length)}}parseComputedLength(e){let n=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return n?this.clientLayout.adjustLengthValue(parseFloat(n[0])):0}getComputedMargin(e){let n=this.clientLayout.getElementComputedStyle(e),s=new Ei(0,0,0,0);return n&&(s.left=this.parseComputedLength(n.marginLeft),s.top=this.parseComputedLength(n.marginTop),s.right=this.parseComputedLength(n.marginRight),s.bottom=this.parseComputedLength(n.marginBottom)),s}getComputedPaddingBorder(e){let n=this.clientLayout.getElementComputedStyle(e),s=new Ei(0,0,0,0);return n&&(s.left=this.parseComputedLength(n.borderLeftWidth)+this.parseComputedLength(n.paddingLeft),s.top=this.parseComputedLength(n.borderTopWidth)+this.parseComputedLength(n.paddingTop),s.right=this.parseComputedLength(n.borderRightWidth)+this.parseComputedLength(n.paddingRight),s.bottom=this.parseComputedLength(n.borderBottomWidth)+this.parseComputedLength(n.paddingBottom)),s}getComputedInsets(e){let n=this.clientLayout.getElementComputedStyle(e),s=new Ei(0,0,0,0);if(n){if(n.boxSizing=="border-box")return this.getComputedMargin(e);s.left=this.parseComputedLength(n.marginLeft)+this.parseComputedLength(n.borderLeftWidth)+this.parseComputedLength(n.paddingLeft),s.top=this.parseComputedLength(n.marginTop)+this.parseComputedLength(n.borderTopWidth)+this.parseComputedLength(n.paddingTop),s.right=this.parseComputedLength(n.marginRight)+this.parseComputedLength(n.borderRightWidth)+this.parseComputedLength(n.paddingRight),s.bottom=this.parseComputedLength(n.marginBottom)+this.parseComputedLength(n.borderBottomWidth)+this.parseComputedLength(n.paddingBottom)}return s}setComputedInsets(e,n){let s=this.clientLayout.getElementComputedStyle(e);s&&(n.marginLeft=this.parseComputedLength(s.marginLeft),n.borderLeft=this.parseComputedLength(s.borderLeftWidth),n.paddingLeft=this.parseComputedLength(s.paddingLeft),n.marginTop=this.parseComputedLength(s.marginTop),n.borderTop=this.parseComputedLength(s.borderTopWidth),n.paddingTop=this.parseComputedLength(s.paddingTop),n.marginRight=this.parseComputedLength(s.marginRight),n.borderRight=this.parseComputedLength(s.borderRightWidth),n.paddingRight=this.parseComputedLength(s.paddingRight),n.marginBottom=this.parseComputedLength(s.marginBottom),n.borderBottom=this.parseComputedLength(s.borderBottomWidth),n.paddingBottom=this.parseComputedLength(s.paddingBottom))}setComputedWidthAndHeight(e,n){let s=this.clientLayout.getElementComputedStyle(e);s&&(n.width=this.parseComputedLength(s.width),n.height=this.parseComputedLength(s.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let n=A("layoutFloat"),s=e.viewNode,i=Yu(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return w(s,"float","none"),w(s,"display","inline-block"),w(s,"vertical-align","top"),this.buildDeepElementView(e).then(o=>{let a=Mt(this.clientLayout,s,this.vertical),l=this.getComputedMargin(s),c=new Ye(a.left-l.left,a.top-l.top,a.right+l.right,a.bottom+l.bottom),u=this.rtl?this.endEdge:this.startEdge,d=this.rtl?this.startEdge:this.endEdge,h=e.parent;for(;h&&h.inline;)h=h.parent;if(h){let E=h.viewNode.ownerDocument.createElement("div");E.style.left="0px",E.style.top="0px",this.vertical?(E.style.bottom="0px",E.style.width="1px"):(E.style.right="0px",E.style.height="1px"),h.viewNode.appendChild(E);let v=Mt(this.clientLayout,E,this.vertical);u=Math.max(this.rtl?this.getEndEdge(v):this.getStartEdge(v),u),d=Math.min(this.rtl?this.getStartEdge(v):this.getEndEdge(v),d),h.viewNode.removeChild(E);let L=this.vertical?c.y2-c.y1:c.x2-c.x1;i=="left"?d=Math.max(d,u+L):u=Math.min(u,d-L),h!==e.parent&&!e.firstPseudo&&(h.viewNode.appendChild(s),s.setAttribute("data-vivliostyle-float-box-moved","true"))}let f=new Ye(u,this.getBoxDir()*this.beforeEdge,d,this.getBoxDir()*this.afterEdge),g=c;this.vertical&&(g=Ni(c));let m=this.getBoxDir();if(g.y1<this.bottommostFloatTop*m){let E=g.y2-g.y1;g.y1=this.bottommostFloatTop*m,g.y2=g.y1+E}If(f,this.bands,g,i),this.vertical&&(c=pa(g));let y=this.getComputedInsets(s);w(s,"width",`${c.x2-c.x1-y.left-y.right}px`),w(s,"height",`${c.y2-c.y1-y.top-y.bottom}px`),w(s,"position","absolute"),e.display,w(s,"display",e.display);let S,C=null;if(h&&(h.containingBlockForAbsolute?C=h:C=h.getContainingBlockForAbsolute()),C){let E=C.viewNode.ownerDocument.createElement("div");E.style.position="absolute",C.vertical?E.style.right="0":E.style.left="0",E.style.top="0",C.viewNode.appendChild(E),S=Mt(this.clientLayout,E,this.vertical),C.viewNode.removeChild(E)}else S={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(C?C.vertical:this.vertical)?w(s,"right",`${S.right-c.x2}px`):w(s,"left",`${c.x1-S.left}px`),w(s,"top",`${c.y1-S.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let x=this.vertical?c.x1:c.y2,N=this.vertical?c.x2:c.y1;!this.isOverflown(x)||this.breakPositions.length==0?(this.killFloats(),f=new Ye(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(f=Ni(f)),Vf(f,this.bands,g,null,i),this.createFloats(),i=="left"?this.leftFloatEdge=x:this.rightFloatEdge=x,this.bottommostFloatTop=N,this.updateMaxReachedAfterEdge(x),n.finish(o)):(e=e.modify(),e.overflow=!0,n.finish(e))}),n.result()}setupFloatArea(e,n,s,i,o,a){let l=this.pageFloatLayoutContext,c=l.getContainer(n),u=e.element;c.element.parentNode.appendChild(u),e.isFloat=!0,e.originX=c.originX,e.originY=c.originY,e.vertical=c.vertical,e.rtl=c.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=(c.exclusions||[]).concat(),e.forceNonfitting=!l.hasFloatFragments(),e.innerShape=null;let d=c.getPaddingRect();e.setHorizontalPosition(d.x1-c.originX,d.x2-d.x1),e.setVerticalPosition(d.y1-c.originY,d.y2-d.y1),o.adjustPageFloatArea(e,c,this),e.init();let h=!!l.setFloatAreaDimensions(e,n,s,i,!0,!l.hasFloatFragments(),a);return h?(e.killFloats(),e.init()):c.element.parentNode.removeChild(u),h}createPageFloatArea(e,n,s,i,o){let a=this.element.ownerDocument.createElement("div");w(a,"position","absolute");let l=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),c=new Fn(null,Ce.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),u=l.getContainer(),d=new dp(n,a,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,c,u);return c.setContainer(d),this.setupFloatArea(d,e.floatReference,n,s,i,o)?d:null}layoutSinglePageFloatFragment(e,n,s,i,o,a,l){let c=this.pageFloatLayoutContext;e=(l?l.continuations:[]).concat(e);let d=e[0].float,h=c.getPageFloatPlacementCondition(d,n,s),f=this.createPageFloatArea(d,n,a,o,h),g={floatArea:f,pageFloatFragment:null,newPosition:null};if(!f)return T(g);let m=A("layoutSinglePageFloatFragment"),y=!1,S=0;return m.loopWithFrame(C=>{if(S>=e.length){C.breakLoop();return}let x=e[S],N=new Nt(x.nodePosition);f.layout(N,!0).then(E=>{g.newPosition=E,!E||i?(S++,C.continueLoop()):(y=!0,C.breakLoop())})}).then(()=>{if(!y){let C=c.setFloatAreaDimensions(f,d.floatReference,n,a,!1,i,h);if(!C)y=!0;else{let x=o.createPageFloatFragment(e,C,s,f,!!g.newPosition);c.addPageFloatFragment(x,!0),g.pageFloatFragment=x}}m.finish(g)}),m.result()}layoutPageFloatInner(e,n,s,i){let o=this.pageFloatLayoutContext,a=e.float;o.stashEndFloatFragments(a);function l(u,d){d?o.removePageFloatFragment(d,!0):u&&u.element.parentNode.removeChild(u.element),o.restoreStashedFragments(a.floatReference),o.deferPageFloat(e)}let c=A("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],a.floatSide,a.clearSide,!o.hasFloatFragments(),n,s,i).then(u=>{let d=u.floatArea,h=u.pageFloatFragment,f=u.newPosition;h?this.layoutStashedPageFloats(a.floatReference,[i]).then(g=>{if(g){if(o.addPageFloatFragment(h),o.discardStashedFragments(a.floatReference),f){let m=new ko(a,f.primary);o.deferPageFloat(m)}c.finish(!0)}else l(d,h),c.finish(!1)}):(l(d,h),c.finish(!1))}),c.result()}layoutStashedPageFloats(e,n){let s=this.pageFloatLayoutContext,i=s.getStashedFloatFragments(e),o=[],a=[],l=!1,c=A("layoutStashedPageFloats"),u=0;return c.loopWithFrame(d=>{if(u>=i.length){d.breakLoop();return}let h=i[u];if(n.includes(h)){u++,d.continueLoop();return}let f=new rn().findByFloat(h.continuations[0].float);this.layoutSinglePageFloatFragment(h.continuations,h.floatSide,h.clearSide,!1,f,null).then(g=>{let m=g.floatArea;m&&o.push(m);let y=g.pageFloatFragment;y?(a.push(y),u++,d.continueLoop()):(l=!0,d.breakLoop())})}).then(()=>{l?(a.forEach(d=>{s.removePageFloatFragment(d,!0)}),o.forEach(d=>{let h=d.element;h&&h.parentNode&&h.parentNode.removeChild(h)})):i.forEach(d=>{let h=d.area.element;h&&h.parentNode&&h.parentNode.removeChild(h)}),c.finish(!l)}),c.result()}setFloatAnchorViewNode(e){let n=e.viewNode.parentNode,s=n.ownerDocument.createElement("span");s.setAttribute(Sn,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",s),n.appendChild(s),n.removeChild(e.viewNode);let i=e.modify();return i.after=!0,i.viewNode=s,i}resolveFloatReferenceFromColumnSpan(e,n,s){let i=A("resolveFloatReferenceFromColumnSpan"),o=this.pageFloatLayoutContext,a=o.getPageFloatLayoutContext(Ce.REGION);return o.getContainer().width<a.getContainer().width&&e===Ce.COLUMN?n===b.auto?this.buildDeepElementView(s.copy()).then(c=>{let u=c.viewNode,d=Ri(this.clientLayout,u,["min-content inline size"])["min-content inline size"],h=this.getComputedMargin(u);this.vertical?d+=h.top+h.bottom:d+=h.left+h.right,d>this.width?i.finish(Ce.REGION):i.finish(e)}):n===b.all?i.finish(Ce.REGION):i.finish(e):i.finish(e),i.result()}layoutPageFloat(e){let n=this.pageFloatLayoutContext,s=new rn().findByNodeContext(e),i,o=n.findPageFloatByNodePosition(e.toNodePosition());return o?i=T(o):i=s.createPageFloat(e,n,this),i.thenAsync(a=>{let l=Xs(e,0),c=this.setFloatAnchorViewNode(e),u=s.findPageFloatFragment(a,n),d=new ko(a,l);if(u&&u.hasFloat(a))return n.registerPageFloatAnchor(a,c.viewNode),T(c);if(n.isForbidden(a)||n.hasPrecedingFloatsDeferredToNext(a))return n.deferPageFloat(d),n.registerPageFloatAnchor(a,c.viewNode),T(c);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let h=ds(c,this.clientLayout,0,this.vertical);return this.isOverflown(h)?T(c):this.layoutPageFloatInner(d,s,h,u).thenAsync(f=>f?T(null):(n.registerPageFloatAnchor(a,c.viewNode),T(c)))}})}processLineStyling(e,n,s){let i=A("processLineStyling"),o=s.concat([]);s.splice(0,s.length);let a=0,l=e.firstPseudo;return l.count==0&&(l=l.outer),i.loopWithFrame(c=>{if(!l){c.breakLoop();return}let u=this.findLinePositions(o),d=l.count-a;if(u.length<=d){c.breakLoop();return}let h=this.findAcceptableBreakInside(o,u[d-1],!0);if(h==null){c.breakLoop();return}this.finishBreak(h,!1,!1).then(()=>{a+=d,this.layoutContext.peelOff(h,0).then(f=>{e=f,l=e.firstPseudo,o=[],this.buildViewToNextBlockEdge(e,o).then(g=>{n=g,c.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(s,o),i.finish(n)}),i.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&pn[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let n=0,s=0;for(let i=e.length-1;i>=0;i--){let o=e[i];if(!o.after||!o.viewNode||o.viewNode.nodeType!=1)break;let a=this.getComputedMargin(o.viewNode),l=this.vertical?-a.left:a.bottom;l>0?n=Math.max(n,l):s=Math.min(s,l)}return n+s}layoutBreakableBlock(e){let n=A("layoutBreakableBlock"),s=[];return this.buildViewToNextBlockEdge(e,s).then(i=>{let o=s.length-1;if(o<0){n.finish(i);return}this.postLayoutBlock(i,s);let a=this.calculateEdge(i,s,o,s[o].boxOffset),l=!1;if(!i||!On(i.viewNode)){let u=hs(i,this.collectElementsOffset());l=this.isOverflown(a+(this.vertical?-1:1)*u.minimum),this.isOverflown(a+(this.vertical?-1:1)*u.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=i)}i==null&&(a+=this.getTrailingMarginEdgeAdjustment(s)),this.updateMaxReachedAfterEdge(a);let c;e.firstPseudo?c=this.processLineStyling(e,i,s):c=T(i),c.then(u=>{s.length>0&&(this.saveBoxBreakPosition(s),l&&!this.isLoneImage(s)&&u&&(u=u.modify(),u.overflow=!0)),n.finish(u)})}),n.result()}postLayoutBlock(e,n){qe("POST_LAYOUT_BLOCK").forEach(i=>{i(e,n,this)})}findEndOfLine(e,n,s){let i=this.vertical?e-1:e+1,o=0,a=n[0].boxOffset,l=o,c=n.length-1,u=n[c].boxOffset,d;for(;a<u;){d=a+Math.ceil((u-a)/2),l=o;let h=c;for(;l<h;){let g=l+Math.ceil((h-l)/2);n[g].boxOffset>d?h=g-1:l=g}let f=this.calculateEdge(null,n,l,d);if(this.vertical?f<=i:f>=i){for(u=d-1;n[l].boxOffset==d;)l--;c=l}else s&&this.updateMaxReachedAfterEdge(f),a=d,o=l}return{nodeContext:n[l],index:a,checkPointIndex:l}}findAcceptableBreakInside(e,n,s){var l,c,u;let i=this.findEndOfLine(n,e,!0),o=i.nodeContext;if(i.checkPointIndex===0&&i.index===o.boxOffset)return null;let a=o.viewNode;if(a.nodeType!=1&&((l=a.parentElement)==null?void 0:l.localName)!=="viv-ts-inner"){let d=a;o=this.resolveTextNodeBreaker(o).breakTextNode(d,o,i.index,e,i.checkPointIndex,s)}else{let d=nd(o);if(d){if(((c=this.breakPositions)==null?void 0:c[0])instanceof ei&&(d!=null&&d.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode)))return null;for(o=d;!o.after&&o.inline&&o.parent;){let h=(u=o.viewNode)==null?void 0:u.previousSibling;for(;h&&(me(h,o.parent.whitespace)||ps(h));)h=h.previousSibling;if(h)break;o=o.parent}}}return this.clearOverflownViewNodes(o,!1),o}resolveTextNodeBreaker(e){return qe("RESOLVE_TEXT_NODE_BREAKER").reduce((s,i)=>i(e)||s,ji.instance)}getRangeBoxes(e,n){let s=[],i=e.ownerDocument.createRange(),o=!1,a=e,l=null,c=!1,u=!0;for(;u;){let d=!0;do{let h=null;a==n&&(n.nodeType===1?u=!(!n.firstChild||o):u=!1);let f=a.nodeType===1?a:null;f?o?o=!1:Wa(f)?d=!c:!f.firstChild||pn[f.localName]||/^r(uby|[bt]c?)$/.test(f.localName)||Lg(this.clientLayout.getElementComputedStyle(f).display)?(d=!c,d?(f.localName==="ruby"&&a.firstChild&&(a=a.firstChild),i.setStartBefore(a),c=!0,l=a):/^r(uby|tc?)$/.test(f.localName)||(l=a),a.contains(n)&&(u=!1)):h=a.firstChild:(c||(a.parentNode==null?u=!1:(i.setStartBefore(a),c=!0)),l=a),h||(h=a.nextSibling,h||(o=!0,h=a.parentNode)),a=h}while(d&&u);if(c){i.setEndAfter(l);let h=this.clientLayout.getRangeClientRects(i);td(h,this.vertical);for(let f=0;f<h.length;f++)s.push(h[f]);c=!1}}return s}findLinePositions(e){let i=[],o=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);o.sort(this.vertical?mg:gg);let a=0,l=0,c=0,u=0,d=0,h=this.getBoxDir();for(;;){if(d<o.length){let f=o[d],g=1;if(u>0){let m=Math.max(this.getBoxSize(f),1);h*this.getBeforeEdge(f)<h*a?g=h*(this.getAfterEdge(f)-a)/m:h*this.getAfterEdge(f)>h*l?g=h*(l-this.getBeforeEdge(f))/m:g=1}if(u==0||g>=.6||g>=.2&&this.getStartEdge(f)>=c-1){c=this.getEndEdge(f),this.vertical?(a=u==0?f.right:Math.max(a,f.right),l=u==0?f.left:Math.min(l,f.left)):(a=u==0?f.top:Math.min(a,f.top),l=u==0?f.bottom:Math.max(l,f.bottom)),u++,d++;continue}}if(u>0&&(i.push(l),u=0),d>=o.length)break}return i.sort(zr),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(e){let n=0;for(let s=e;s;s=s.parent)if(!s.inline&&zs(s.viewNode)){let i=this.getComputedPaddingBorder(s.viewNode);n+=s.vertical?-i.left:i.bottom,s.display==="table"&&(n+=(s.vertical?-1:1)*s.blockBorderSpacing)}return n}getOffsetByRepetitiveElements(e){let n;return e?n=e.calculateOffset(this):n=hs(null,this.collectElementsOffset()),n.current}findBoxBreakPosition(e,n){let s=this.element.parentNode,i=this.element.nextSibling;s.removeChild(this.element),s.insertBefore(this.element,i);let o=e.checkPoints,a=o[0];for(;a.parent&&a.inline;)a=a.parent;let l,c;n?(l=1,c=1):(l=Math.max((a.inheritedProps.widows||2)-0,1),c=Math.max((a.inheritedProps.orphans||2)-0,1));let u=this.calculateClonedPaddingBorder(a),d=this.findLinePositions(o),h=this.footnoteEdge-u,f=this.getBoxDir(),g=this.getOffsetByRepetitiveElements(e);h-=f*g;let m=this.findFirstOverflowingEdgeAndCheckPoint(o);isNaN(m.edge)&&(m.edge=f*(1/0));let y=At(d.length,N=>{let E=d[N];return this.vertical?E<h||E<=m.edge:E>h||E>=m.edge}),S=y<=0;S&&(y=At(d.length,N=>this.vertical?d[N]<h:d[N]>h));let C=o[o.length-1].viewNode;if((C==null?void 0:C.parentElement.localName)==="viv-ts-inner"&&(C=C.parentElement.parentElement),(y===d.length&&C.nextSibling||y>=d.length-1&&C.parentElement.querySelector(".MJXc-display"))&&(l=0),y=Math.min(d.length-l,y),y<c)return null;h=d[y-1];let x;if(S?x=m.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,h,n),x){let N=this.getAfterEdgeOfBlockContainer(x);!isNaN(N)&&f*(h-N)>0&&(h=N),this.computedBlockSize=f*(h-this.beforeEdge)+g}return x}getAfterEdgeOfBlockContainer(e){let n=e;do n=n.parent;while(n&&n.inline);return n?(n=n.copy().modify(),n.after=!0,ds(n,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let n=e.findIndex(i=>i.overflow);if(n<0)return{edge:NaN,checkPoint:null};let s=e[n];return{edge:this.calculateEdge(null,e,n,s.boxOffset),checkPoint:s}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,n,s){e.formattingContext;let o=new fs().find(e.formattingContext).finishBreak(this,e,n,s);return o||(o=Bo.finishBreak(this,e,n,s)),o}findAcceptableBreakPosition(){let e=null,n=null,s=0,i=0;do{s=i,i=Number.MAX_VALUE;for(let o=this.breakPositions.length-1;o>=0&&!n;--o){e=this.breakPositions[o],n=e.findAcceptableBreak(this,s);let a=e.getMinBreakPenalty();a>s&&(i=Math.min(i,a))}}while(i>s&&!n&&this.forceNonfitting);return{breakPosition:n?e:null,nodeContext:n}}doFinishBreak(e,n,s,i){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!n)return T(e);let o=A("doFinishBreak"),a=!1;if(!e){if(this.forceNonfitting)return F.warn("Could not find any page breaks?!!"),this.skipTailEdges(n).then(l=>{l?(l=l.modify(),l.overflow=!1,this.finishBreak(l,a,!0).then(()=>{o.finish(l)})):o.finish(l)}),o.result();e=s,a=!0,this.computedBlockSize=i}return this.finishBreak(e,a,!0).then(()=>{o.finish(e)}),o.result()}isBreakable(e){for(let n=e;n;n=n.parent)if(ps(n.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 n=e.toString();return n==""||n=="auto"||!!n.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,n){if(!e)return!1;for(let a=e;a;a=a.parent)if(ps(a.viewNode))return!1;if(On(e.viewNode))return!1;let s=ds(e,this.clientLayout,0,this.vertical),i=hs(e,this.collectElementsOffset()),o=this.isOverflown(s+(this.vertical?-1:1)*i.minimum);if(this.isOverflown(s+(this.vertical?-1:1)*i.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(n){let a=s+this.getTrailingMarginEdgeAdjustment(n),l=this.footnoteEdge-this.getBoxDir()*i.current;s=this.vertical?Math.min(s,Math.max(a,l)):Math.max(s,Math.min(a,l))}return this.updateMaxReachedAfterEdge(s),o}checkOverflowAndSaveEdgeAndBreakPosition(e,n,s,i){if(!e||On(e.viewNode))return!1;let o=this.checkOverflowAndSaveEdge(e,n);return(s||!o)&&this.saveEdgeBreakPosition(e,i,o),o}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Ce.INLINE)return!1;let n=this.getComputedMargin(e.viewNode),s=e.viewNode.ownerDocument.createElement("div");this.vertical?(s.style.bottom="0px",s.style.width="1px",s.style.marginRight=`${n.right}px`):(s.style.right="0px",s.style.height="1px",s.style.marginTop=`${n.top}px`),e.viewNode.parentNode.insertBefore(s,e.viewNode);let i=Mt(this.clientLayout,s,this.vertical),o=this.getBeforeEdge(i),a=this.getBoxDir(),l=e.clearSide==="same"?e.floatSide:e.clearSide,c=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(l)?Yu(l,e.vertical,e.direction,this.layoutContext.page.side):l,u=c==="left"||c==="right"?e.direction==="rtl"==(c==="left")?"inline-end":"inline-start":c,d=this.pageFloatLayoutContext.getPageFloatClearEdge(u,this);switch(c){case"left":d=a*Math.max(d*a,this.leftFloatEdge*a);break;case"right":d=a*Math.max(d*a,this.rightFloatEdge*a);break;default:d=a*Math.max(d*a,Math.max(this.rightFloatEdge*a,this.leftFloatEdge*a))}let h=1/(this.clientLayout.pixelRatio||1);if(o*a+h>d*a)return e.viewNode.parentNode.removeChild(s),!1;{let f=Math.max(1,(d-o)*a);this.vertical?s.style.width=`${f}px`:s.style.height=`${f}px`,i=Mt(this.clientLayout,s,this.vertical);let g=this.getAfterEdge(i);if(!e.floatSide)if(this.vertical){let m=g-n.right-d;m>0==n.right>=0&&(m+=n.right),s.style.marginLeft=`${m}px`}else{let m=d-(g+n.top);m>0==n.top>=0&&(m+=n.top),s.style.marginBottom=`${m}px`}return e.clearSpacer=s,!0}}isBFC(e){return!!(Rg(e)||xn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,n,s){var y;let i=e.after?(y=e.parent)==null?void 0:y.formattingContext:e.formattingContext;if(i&&!this.isBFC(i))return T(e);let o=A("skipEdges"),a=!s&&n&&e&&e.after,l=s,c=null,u=[],d=[],h=!1;function f(){return!!s||!n&&Me(l)&&!g()}function g(){var S;if(!c||e.floatSide)return!1;for(let C=c;C!=null&&C.parent;C=C.parent){let x=C.after?C.viewNode:(S=C.viewNode)==null?void 0:S.previousSibling;for(;x&&(me(x,C.parent.whitespace)||ps(x));)x=x.previousSibling;if(x)return!1}return!0}let m=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=l};return o.loopWithFrame(S=>{var C;for(;e;){e.formattingContext;let x=new fs().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(me(e.viewNode,e.whitespace))break;if(!e.after){f()?m():this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)?(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=l),S.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ii(l)?l:null),x&&x.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&n&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),l,!1),!e.inline&&!e.repeatOnBreak&&(c?nd(c):this.breakPositions[this.breakPositions.length-1]instanceof ei)&&this.saveEdgeBreakPosition(e.copy(),l,!1),!this.isBFC(e.formattingContext)||xn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&me(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),l=_e(l,e.breakBefore),f()?m():(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0),S.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let v=e.viewNode.style;if(e.after){e.floatSide&&(l=l!=null?l:this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let L=e.sourceNode;if(L.localName==="svg"||L.localName==="math"||L.getAttribute("data-math-typeset")==="true"){h=!1,c=e.copy(),d.push(c),l=_e(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l);break}if(e.inline||x&&x.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(h){if(f()){m(),S.breakLoop();return}u=[],n=!1,a=!1,l=null}h=!1,c=e.copy(),d.push(c),l=_e(l,e.breakAfter),v&&!(this.zeroIndent(v.paddingBottom)&&this.zeroIndent(v.borderBottomWidth))&&(d=[c])}else{if(u.push(e.copy()),l=_e(l,e.breakBefore),c&&Me(l)&&kg(c.viewNode,e.viewNode),(e.pageType!=((C=e.parent)==null?void 0:C.pageType)||!Me(l))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){S.breakLoop();return}let L=e.viewNode.localName;if(pn[L]){f()?m():this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)&&(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0),S.breakLoop();return}v&&!(this.zeroIndent(v.paddingTop)&&this.zeroIndent(v.borderTopWidth))&&(a=!1,d=[]),h=!0}}while(!1);let N=this.nextInTree(e,a);if(N.isPending()){N.then(E=>{e=E,S.continueLoop()});return}else e=N.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(c,d,!this.stopAtOverflow,l)?c&&this.stopAtOverflow&&(e=c.modify(),e.overflow=!0):Me(l)&&(this.pageBreakType=l),S.breakLoop()}).then(()=>{c&&(this.lastAfterPosition=c.toNodePosition()),o.finish(e)}),o.result()}skipTailEdges(e){let n=e.copy(),s=A("skipEdges"),i=null,o=!1;return s.loopWithFrame(a=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(me(e.viewNode,e.whitespace))break;if(!e.after){Me(i)&&(this.pageBreakType=i),a.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){i=_e(i,e.breakBefore),Me(i)&&(this.pageBreakType=i),a.breakLoop();return}if(e.viewNode.nodeType!=1)break;let c=e.viewNode.style;if(e.after){if(o){if(Me(i)){this.pageBreakType=i,a.breakLoop();return}i=null}o=!1,i=_e(i,e.breakAfter)}else{i=_e(i,e.breakBefore);let u=e.viewNode.localName;if(pn[u]){Me(i)&&(this.pageBreakType=i),a.breakLoop();return}if(c&&!(this.zeroIndent(c.paddingTop)&&this.zeroIndent(c.borderTopWidth))){a.breakLoop();return}}o=!0}while(!1);let l=this.layoutContext.nextInTree(e);if(l.isPending()){l.then(c=>{e=c,a.continueLoop()});return}else e=l.get()}n=null,a.breakLoop()}).then(()=>{s.finish(n)}),s.result()}layoutFloatOrFootnote(e){return us(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,n,s){let i=A("layoutNext");return this.skipEdges(e,n,s||null).then(o=>{if(e=o,!e||this.pageBreakType||this.stopByOverflow(e))i.finish(e);else{let a=e.formattingContext;new fs().find(a).layout(e,this,n).thenFinish(i)}}),i.result()}clearOverflownViewNodes(e,n){if(e)for(let s=e.parent;e;e=s,s=s?s.parent:null){let i=(s||e).formattingContext;new fs().find(i).clearOverflownViewNodes(this,s,e,n),n=!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 n=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let s=this.originX+this.left+this.getInsetLeft(),i=this.originY+this.top+this.getInsetTop();this.box=new Ye(s,i,s+this.width,i+this.height),this.startEdge=n?this.vertical?this.rtl?n.bottom:n.top:this.rtl?n.right:n.left:0,this.endEdge=n?this.vertical?this.rtl?n.top:n.bottom:this.rtl?n.left:n.right:0,this.beforeEdge=n?this.vertical?n.right:n.top:0,this.afterEdge=n?this.vertical?n.left:n.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Pf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],w(this.element,"width",`${this.width}px`),w(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,n,s){e.formattingContext;let i=e.copy(),o=new fs().find(e.formattingContext),a=this.calculateClonedPaddingBorder(i),l=o.createEdgeBreakPosition(i,n,s,this.computedBlockSize+a);this.breakPositions.push(l)}saveBoxBreakPosition(e){let n=e[0].breakPenalty;if(n){let i=e[0];for(;i.parent&&i.inline;)i=i.parent;n=i.breakPenalty}let s=new ei(e,n);this.breakPositions.push(s)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let n=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(n,this.computedBlockSize)}}layout(e,n,s){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);Pg(this)&&Io(this);let i=A("layout");return this.openAllViews(e.primary).then(o=>{let a=null;if(o.viewNode)a=o.copy();else{let c=u=>{u.nodeContext.viewNode&&(a=u.nodeContext,this.layoutContext.removeEventListener("nextInTree",c))};this.layoutContext.addEventListener("nextInTree",c)}let l=new cp(n,s);l.layout(o,this).then(c=>{this.doFinishBreak(c,l.context.overflownNodeContext,a,l.initialComputedBlockSize).then(u=>{let d=null;this.pseudoParent?d=T(null):d=this.doFinishBreakOfFragmentLayoutConstraints(u),d.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){i.finish(null);return}if(!u)i.finish(null);else{this.overflown=!0;let h=new Nt(u.toNodePosition());i.finish(h)}})})})}),i.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let n=A("doFinishBreakOfFragmentLayoutConstraints"),s=[].concat(this.fragmentLayoutConstraints);s.sort((o,a)=>o.getPriorityOfFinishBreak()-a.getPriorityOfFinishBreak());let i=0;return n.loop(()=>i<s.length?s[i++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{n.finish(!0)}),n.result()}doLayout(e,n,s){let i=A("doLayout"),o=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,i.loopWithFrame(a=>{for(;e;){let l=!0;if(this.layoutNext(e,n,s||null).then(c=>{if(n=!1,s=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=c,this.pageFloatLayoutContext.isInvalidated())a.breakLoop();else if(this.pageBreakType)a.breakLoop();else if(e&&this.stopByOverflow(e)){o=e;let u=this.findAcceptableBreakPosition();e=u.nodeContext,u.breakPosition&&u.breakPosition.breakPositionChosen(this),a.breakLoop()}else l?l=!1:a.continueLoop()}),l){l=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),a.breakLoop()}).then(()=>{i.finish({nodeContext:e,overflownNodeContext:o})}),i.result()}redoLayout(){let e=this.chunkPositions,n=this.element.lastChild;for(;n!=this.last;){let l=n.previousSibling;this.element===n.parentNode&&this.layoutContext.isPseudoelement(n)||this.element.removeChild(n),n=l}this.killFloats(),this.init();let s=A("redoLayout"),i=0,o=null,a=!0;return s.loopWithFrame(l=>{if(i<e.length){let c=e[i++];this.layout(c,a).then(u=>{a=!1,u?(o=u,l.breakLoop()):l.continueLoop()});return}l.breakLoop()}).then(()=>{s.finish(o)}),s.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 n=this;n;n=n.pseudoParent)n.fragmentLayoutConstraints.forEach(s=>{if(xn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let i=s.getRepetitiveElements();e.push(i)}if(vo.isInstanceOfAfterIfContinuesLayoutConstraint(s)){let i=s.getRepetitiveElements();e.push(i)}sn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(this).forEach(i=>{e.push(i)})});return e}},ni=class{constructor(t,e,n){p(this,"startNodeContexts",[]);p(this,"column");this.column=Object.create(t),this.column.element=e,this.column.layoutContext=t.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=n.formattingContext,this.column.pseudoParent=t;let s=this.column.calculateClonedPaddingBorder(n);this.column.footnoteEdge=this.column.footnoteEdge-s;let i=this;this.column.openAllViews=function(o){return ti.prototype.openAllViews.call(this,o).thenAsync(a=>(i.startNodeContexts.push(a.copy()),T(a)))}}layout(t,e){return this.column.layout(t,e)}findAcceptableBreakPosition(t){let e=this.column.findAcceptableBreakPosition();if(t){let n=this.startNodeContexts[0].copy(),s=new En(n,null,n.overflow,0);if(s.findAcceptableBreak(this.column,0),!e.nodeContext)return{breakPosition:s,nodeContext:n}}return e}finishBreak(t,e,n){return this.column.finishBreak(t,e,n)}doFinishBreakOfFragmentLayoutConstraints(t){this.column.doFinishBreakOfFragmentLayoutConstraints(t)}isStartNodeContext(t){let e=this.startNodeContexts[0];return e.viewNode===t.viewNode&&e.after===t.after&&e.offsetInNode===t.offsetInNode}isLastAfterNodeContext(t){return on(t.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},ji=class{breakTextNode(t,e,n,s,i,o){if(e.after)e.offsetInNode=t.length;else{let a=n-e.boxOffset,l=t.data;l.charCodeAt(a)==173?a=this.breakAfterSoftHyphen(t,l,a,e):a=this.breakAfterOtherCharacter(t,l,a,e),a>0&&(e=this.updateNodeContext(e,a,t))}return e}breakAfterSoftHyphen(t,e,n,s){let o=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(e.slice(0,n))?"\u200D":"";if(t.replaceData(n,e.length-n,s.breakWord?"":o+sm(s)),o){let a=s.preprocessedTextContent[0][1];s.preprocessedTextContent[0][1]=a.slice(0,n+1)+o+a.slice(n+1)}return n+1}breakAfterOtherCharacter(t,e,n,s){let i=e.charAt(n);n++;let o=e.charAt(n);return t.replaceData(n,e.length-n,!s.breakWord&&Dc(i)&&Dc(o)?sm(s):""),n}updateNodeContext(t,e,n){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};p(ji,"instance");ji.instance=new ji;function sm(r){return r.hyphenateCharacter||r.parent&&r.parent.hyphenateCharacter||"-"}var cp=class extends gs{constructor(e,n){super();this.leadingEdge=e;p(this,"breakAfter");p(this,"initialPageBreakType",null);p(this,"initialComputedBlockSize",0);p(this,"initialOverflown",!1);p(this,"context",{overflownNodeContext:null});this.breakAfter=n||null}resolveLayoutMode(e){return new up(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,n){n.fragmentLayoutConstraints=[],n.pseudoParent||Vg()}clearNodes(e){super.clearNodes(e);let n=e;for(;n;){let s=n.viewNode;s&&Ga(s.parentNode,s),n=n.parent}}saveState(e,n){super.saveState(e,n),this.initialPageBreakType=n.pageBreakType,this.initialComputedBlockSize=n.computedBlockSize,this.initialOverflown=n.overflown}restoreState(e,n){super.restoreState(e,n),n.pageBreakType=this.initialPageBreakType,n.computedBlockSize=this.initialComputedBlockSize,n.overflown=this.initialOverflown}},up=class{constructor(t,e,n){this.leadingEdge=t;this.breakAfter=e;this.context=n}doLayout(t,e){let n=A("DefaultLayoutMode.doLayout");return cy(t,e).then(()=>{e.doLayout(t,this.leadingEdge,this.breakAfter).then(s=>{this.context.overflownNodeContext=s.overflownNodeContext,n.finish(s.nodeContext)})}),n.result()}accept(t,e){return e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||e.fragmentLayoutConstraints.length<=0?!0:e.fragmentLayoutConstraints.every(n=>n.allowLayout(t,this.context.overflownNodeContext,e))}postLayout(t,e,n,s){return s||(s=!n.fragmentLayoutConstraints.some(o=>o.nextCandidate(t))),n.fragmentLayoutConstraints.forEach(i=>{i.postLayout(s,t,e,n)}),s}},dp=class extends ti{constructor(e,n,s,i,o,a,l){super(n,s,i,o,a);this.floatSide=e;this.parentContainer=l;p(this,"rootViewNodes",[]);p(this,"floatMargins",[]);p(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(n=>(n&&this.fixFloatSizeAndPosition(n),T(n)))}convertPercentageSizesToPx(e){let n=this.parentContainer.getPaddingRect(),s=n.x2-n.x1,i=n.y2-n.y1;function o(a,l){a.forEach(c=>{let u=Jt(e,c);if(u&&u.charAt(u.length-1)==="%"){let d=parseFloat(u),h=l*d/100;w(e,c,`${h}px`)}})}o(["width","max-width","min-width"],s),o(["height","max-height","min-height"],i),o(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?i:s),["margin-top","margin-right","margin-bottom","margin-left"].forEach(a=>{Jt(e,a)==="auto"&&w(e,a,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let n=e.viewNode;if(this.rootViewNodes.push(n),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(n),this.floatMargins.push(this.getComputedMargin(n)),this.adjustContentRelativeSize){let s=this.floatSide;if(this.parentContainer.vertical){if(s==="block-end"||s==="left"){let o=Jt(n,"height");o!==""&&o!=="auto"&&w(n,"margin-top","auto")}}else if(s==="block-end"||s==="bottom"){let o=Jt(n,"width");o!==""&&o!=="auto"&&w(n,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=Mt(this.clientLayout,e,this.vertical),i=this.floatMargins[n];return this.vertical?i.top+s.height+i.bottom:i.left+s.width+i.right}))}};var an=class{constructor(t,e){this.parent=t;this.rootSourceNode=e;p(this,"formattingContextType","RepetitiveElementsOwner");p(this,"isRoot",!1);p(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(t){let e=this.getRootNodeContext(t);return e?e.viewNode:null}getRootNodeContext(t){do if(!t.belongsTo(this)&&t.sourceNode===this.rootSourceNode)return t;while(t=t.parent);return null}initializeRepetitiveElements(t){if(this.repetitiveElements)return;$a.some(n=>n.root===this.rootSourceNode?(this.repetitiveElements=n.elements,!0):!1)||(this.repetitiveElements=new hp(t,this.rootSourceNode),$a.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},hp=class{constructor(t,e){this.vertical=t;this.ownerSourceNode=e;p(this,"headerSourceNode",null);p(this,"footerSourceNode",null);p(this,"headerViewNode",null);p(this,"footerViewNode",null);p(this,"headerNodePosition",null);p(this,"footerNodePosition",null);p(this,"headerHeight",0);p(this,"footerHeight",0);p(this,"isSkipHeader",!1);p(this,"isSkipFooter",!1);p(this,"enableSkippingFooter",!0);p(this,"enableSkippingHeader",!0);p(this,"doneInitialLayout",!1);p(this,"firstContentSourceNode",null);p(this,"lastContentSourceNode",null);p(this,"affectedNodeCache",[]);p(this,"afterLastContentNodeCache",[]);p(this,"allowInsert",!1);p(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(t){this.headerNodePosition||(this.headerNodePosition=Xs(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=Xs(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=Fo(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Fo(this.footerViewNode,t,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(t,e,n){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,t,e,n)}appendFooterToFragment(t,e,n){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,t,e,n)}appendElementToFragment(t,e,n,s){let i=e.viewNode.ownerDocument,o=e.viewNode,a=i.createElement("div");o.appendChild(a);let l=new ni(s,a,e),c=l.getColumn().pageBreakType;return l.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,l.layout(new Nt(t),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,o.removeChild(a),this.moveChildren(a,o,n),l.getColumn().pageBreakType=c,T(!0)))}moveChildren(t,e,n){if(e)for(;t.firstChild;){let s=t.firstChild;t.removeChild(s),s.setAttribute(Sn,"1"),n?e.insertBefore(s,n):e.appendChild(s)}}calculateOffset(t){let e=0;return t&&!this.affectTo(t)||((!this.isSkipFooter||t&&this.isAfterLastContent(t))&&(e+=this.footerHeight),this.isSkipHeader||(e+=this.headerHeight)),e}calculateMinimumOffset(t){let e=0;return t&&!this.affectTo(t)||(!this.enableSkippingFooter&&t&&this.isAfterLastContent(t)&&(e+=this.footerHeight),this.enableSkippingHeader||(e+=this.headerHeight)),e}isAfterLastContent(t){return this.findResultFromCache(t,this.afterLastContentNodeCache,e=>this.isAfterNodeContextOf(this.lastContentSourceNode,t,!1))}affectTo(t){return this.findResultFromCache(t,this.affectedNodeCache,e=>this.isAfterNodeContextOf(this.ownerSourceNode,t,!0))}findResultFromCache(t,e,n){let s=e.filter(i=>i.nodeContext.sourceNode===t.sourceNode&&i.nodeContext.after===t.after);if(s.length>0)return s[0].result;{let i=n(t);return e.push({nodeContext:t,result:i}),i}}isAfterNodeContextOf(t,e,n){let s=[];for(let i=t;i;i=i.parentNode){if(e.sourceNode===i)return e.after;s.push(i)}for(let i=e.sourceNode;i;i=i.parentNode){let o=s.indexOf(i);if(o>=0)return n?o===0:!1;for(let a=i;a;a=a.previousElementSibling)if(s.includes(a))return!0}return e.after}isFirstContentNode(t){return t&&this.firstContentSourceNode===t.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(t){return this.headerSourceNode===t}isFooterSourceNode(t){return this.footerSourceNode===t}},$o=class{constructor(t){this.formattingContext=t}accept(t,e){return!!t}postLayout(t,e,n,s){let i=this.formattingContext.getRepetitiveElements();return i&&(n.clientLayout,i.doneInitialLayout||(i.updateHeight(n),i.doneInitialLayout=!0)),s}},jo=class{constructor(t){this.formattingContext=t}accept(t,e){return!0}postLayout(t,e,n,s){return s}},fp=class extends $o{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}accept(e,n){return!1}},gp=class extends jo{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return!e.belongsTo(this.formattingContext)&&!e.after&&n.fragmentLayoutConstraints.unshift(new Yi(e)),this.processor.doLayout(e,n)}},Yi=class r{constructor(t){p(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner");p(this,"nodeContext");let e=Wn(t.formattingContext);this.nodeContext=e.getRootNodeContext(t)}allowLayout(t,e,n){let s=this.getRepetitiveElements();return!s||On(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(e&&!t||t&&t.overflow)}nextCandidate(t){let e=this.getRepetitiveElements();return e&&e.isEnableToUpdateState()?(e.updateState(),!0):!1}postLayout(t,e,n,s){let i=this.getRepetitiveElements();i&&t&&s.stopAtOverflow&&(e==null||i.isAfterLastContent(e))&&i.preventSkippingFooter()}finishBreak(t,e){let n=Wn(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return T(!0);let i=this.nodeContext;return py(n,i,e).thenAsync(()=>hy(n,i,e).thenAsync(()=>(s.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return Wn(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof r?Wn(this.nodeContext.formattingContext)===Wn(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},mp=class extends gs{constructor(e,n){super();this.formattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!n.doneInitialLayout?new fp(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&n&&n.preventSkippingHeader(),new gp(this.formattingContext,this.processor))}},Cp=class extends _n{constructor(e,n){super();this.formattingContext=e;this.column=n}startNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,i=n.getRepetitiveElements();if(s.parent&&n.rootSourceNode===s.parent.sourceNode){switch(s.repeatOnBreak){case"header":if(i.isHeaderRegistered())s.repeatOnBreak="none";else return i.setHeaderNodeContext(s),T(!0);break;case"footer":if(i.isFooterRegistered())s.repeatOnBreak="none";else return i.setFooterNodeContext(s),T(!0);break}i.firstContentSourceNode||(i.firstContentSourceNode=s.sourceNode)}return _n.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext;return s.sourceNode===n.rootSourceNode&&(n.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),s.repeatOnBreak==="header"||s.repeatOnBreak==="footer"?T(!0):_n.prototype.afterNonInlineElementNode.call(this,e)}};var bp=class extends Nn{layout(t,e,n){if(e.isFloatNodeContext(t))return e.layoutFloatOrFootnote(t);let s=Wn(t.formattingContext);return s.getRootViewNode(t)?(n&&yp(t.parent,e),t.belongsTo(s)?Nn.prototype.layout.call(this,t,e,n):new mp(s,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let n=fy(t).getRepetitiveElements();return n&&!n.allowInsertRepeatitiveElements&&(n.isHeaderSourceNode(t.sourceNode)||n.isFooterSourceNode(t.sourceNode))&&t.viewNode.parentNode.removeChild(t.viewNode),!1}doInitialLayout(t,e){let n=Wn(t.formattingContext),s=A("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(s),s.result()}layoutEntireBlock(t,e){let n=Wn(t.formattingContext),s=new Cp(n,e);return new js(s,e.layoutContext).iterate(t)}doLayout(t,e){let n=Wn(t.formattingContext),s=A("doLayout"),i=e.layoutContext.nextInTree(t,!1);return pp(i,e).then(o=>{let a=o;s.loopWithFrame(l=>{for(;a;){let c=!0;if(e.layoutNext(a,!1).then(u=>{a=u,e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||a&&e.stopByOverflow(a)||a&&a.after&&a.sourceNode==n.rootSourceNode?l.breakLoop():c?c=!1:l.continueLoop()}),c){c=!1;return}}l.breakLoop()}).then(()=>{s.finish(a)})}),s.result()}finishBreak(t,e,n,s){return Nn.prototype.finishBreak.call(this,t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Nn.prototype.clearOverflownViewNodes(t,e,n,s)}};function dy(r,t){for(let e=r;e;e=e.parent){let n=e.formattingContext;n&&n instanceof an&&!e.belongsTo(n)&&t(n,e)}}function yp(r,t){r&&dy(r.after?r.parent:r,(e,n)=>{sn.isInstanceOfTableFormattingContext(e)||t.fragmentLayoutConstraints.push(new Yi(n))})}function py(r,t,e){let n=r.getRepetitiveElements();if(n){let s=r.getRootNodeContext(t);if(s.viewNode){let i=s.viewNode.firstChild;return n.appendHeaderToFragment(s,i,e)}}return T(!0)}function hy(r,t,e){let n=r.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=r.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,e)}return T(!0)}function fy(r){let t=r.formattingContext;return!t||!(t instanceof an)?null:t}function Wn(r){return r instanceof an,r}var gy=new bp;je("RESOLVE_LAYOUT_PROCESSOR",r=>r instanceof an&&!sn.isInstanceOfTableFormattingContext(r)?gy:null);var gl=class{constructor(t,e){this.rowIndex=t;this.sourceNode=e;p(this,"cells",[])}addCell(t){this.cells.push(t)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(t=>t.height))}},Sp=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;p(this,"viewElement");p(this,"colSpan");p(this,"rowSpan");p(this,"height",0);p(this,"anchorSlot",null);this.viewElement=n,this.colSpan=n.colSpan||1,this.rowSpan=n.rowSpan||1}setHeight(t){this.height=t}setAnchorSlot(t){this.anchorSlot=t}},Ep=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;this.cell=n}},Np=class{constructor(t,e,n){this.column=t;this.cellNodeContext=n;p(this,"pseudoColumn");p(this,"empty",!1);this.pseudoColumn=new ni(t,e,n)}findAcceptableBreakPosition(){let t=this.cellNodeContext.viewNode,{verticalAlign:e,alignContent:n}=t.style;e!=="top"&&e!=="baseline"&&w(t,"vertical-align","top"),n&&n!=="normal"&&w(t,"align-content","normal");let s=this.pseudoColumn.findAcceptableBreakPosition(!0);return w(t,"vertical-align",e),n&&n!=="normal"&&w(t,"align-content",n),s}},vp=class{constructor(t,e){this.viewNode=t;this.side=e}},Tp=class extends En{constructor(e,n,s,i){super(e,n,s,i);p(this,"formattingContext");p(this,"acceptableCellBreakPositions",null);p(this,"rowIndex",null);this.formattingContext=e.formattingContext}findAcceptableBreak(e,n){let s=super.findAcceptableBreak(e,n);return n<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(o=>!!o.nodeContext)?s:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(s=>{e+=s.breakPosition.getMinBreakPenalty()});let n=this.getCellFragments();return e+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,n=this.getCellFragments();this.acceptableCellBreakPositions=n.map(s=>s.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)}},wp=class extends $s{constructor(e,n,s){super();this.rowIndex=e;this.beforeNodeContext=n;this.formattingContext=s;p(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,n){if(this!==e.breakPositions[0]&&n<this.getMinBreakPenalty())return null;let s=this.getCellFragments(),i=this.getAcceptableCellBreakPositions(),o=i.every(a=>!!a.nodeContext)&&i.some((a,l)=>{let c=s[l].pseudoColumn,u=a.nodeContext;return!c.isStartNodeContext(u)&&!c.isLastAfterNodeContext(u)});return this.beforeNodeContext.overflow=i.some(a=>a.nodeContext&&a.nodeContext.overflow),o?this.beforeNodeContext:null}getMinBreakPenalty(){let n=this.formattingContext.getRowByIndex(this.rowIndex),s=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),o=this.getCellFragments();s+=Math.max(0,...o.map(l=>l.cellNodeContext.breakPenalty));let a=i.some((l,c)=>l.breakPosition instanceof ei&&o[c].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((l,c)=>{let u=l.breakPosition.getMinBreakPenalty();a&&l.breakPosition instanceof En&&l.breakPosition.overflows&&u>=3&&(o[c].column.checkOverflowAndSaveEdge(l.nodeContext,null)||(u-=3)),s+=u}),s}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(n=>n.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},xs=class extends an{constructor(e,n){super(e,n);this.tableSourceNode=n;p(this,"formattingContextType","Table");p(this,"vertical",!1);p(this,"columnCount",-1);p(this,"tableWidth",0);p(this,"captions",[]);p(this,"colGroups",null);p(this,"colWidths",null);p(this,"inlineBorderSpacing",0);p(this,"rows",[]);p(this,"slots",[]);p(this,"cellFragments",[]);p(this,"lastRowViewNode",null);p(this,"cellBreakPositions",[]);p(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,n){if(!n)return n;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(s=>s.cellNodePosition.steps[0].node===e.sourceNode);default:return n}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,n){this.rows[e]=n}getRowSlots(e){let n=this.slots[e];return n||(n=this.slots[e]=[]),n}addCell(e,n){let s=this.rows[e];s||(this.addRow(e,new gl(e,null)),s=this.rows[e]),s.addCell(n);let i=e+n.rowSpan,o=this.getRowSlots(e),a=0;for(;o[a];)a++;for(;e<i;e++){o=this.getRowSlots(e);for(let l=a;l<a+n.colSpan;l++){let c=o[l]=new Ep(e,l,n);n.anchorSlot||n.setAnchorSlot(c)}}}getRowByIndex(e){let n=this.rows[e];return n}findRowIndexBySourceNode(e){return this.rows.findIndex(n=>e===n.sourceNode)}addCellFragment(e,n,s){let i=this.cellFragments[e];i||(i=this.cellFragments[e]=[]),i[n]=s}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((s,i)=>i.cell!==s[s.length-1]?s.concat(i.cell):s,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(n=>n.rowIndex+n.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((n,s)=>n+s.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(n=>{n.cells.forEach(s=>{let i=Mt(e,s.viewElement,this.vertical);s.viewElement=null,s.setHeight(this.vertical?i.width:i.height)})})}findCellFromColumn(e){if(!e)return null;let n=null,s=0,i=0;e:for(s=0;s<this.cellFragments.length;s++)if(this.cellFragments[s]){for(i=0;i<this.cellFragments[s].length;i++)if(this.cellFragments[s][i]&&e===this.cellFragments[s][i].pseudoColumn.getColumn()){n=this.rows[s].cells[i];break e}}if(!n)return null;for(;s<this.slots.length;s++)for(;i<this.slots[s].length;i++){let o=this.slots[s][i];if(o.cell===n)return{rowIndex:o.rowIndex,columnIndex:o.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let n=[];return this.slots.reduce((s,i,o)=>{if(o>=e.rowIndex)return s;let a=i[e.columnIndex]&&this.getCellFragmentOfCell(i[e.columnIndex].cell);return!a||n.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),s),n.push(a)),s},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(n=>{n.cells.forEach((s,i)=>{e[i]||(e[i]={collected:[],elements:[]});let o=e[i],a=this.getCellFragmentOfCell(s);!a||o.collected.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),o.elements),o.collected.push(a))})}),[new Pp(e.map(n=>n.elements))]}collectElementsOffsetFromColumn(e,n){e.fragmentLayoutConstraints.forEach(s=>{if(xn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let i=s.getRepetitiveElements();n.push(i)}sn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(null).forEach(i=>{n.push(i)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Pp=class{constructor(t){this.repeatitiveElementsInColumns=t}calculateOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.current)}calculateMinimumOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.minimum)}calculateMaxOffsetOfColumn(t,e){let n=0;return this.repeatitiveElementsInColumns.forEach(s=>{let i=hs(t,s);n=Math.max(n,e(i))}),n}};function Yt(r){return r instanceof xs,r}function my(r){return r==="table-row-group"||r==="table-header-group"||r==="table-footer-group"}function Cy(r){return r==="table"||r==="inline-table"}function am(r){return my(r)||Cy(r)}function lm(r,t,e){let n=r.nodeContext,s=n.display,i=n.parent?n.parent.display:null,o=!1;if(i==="inline-table"&&!(n.formattingContext instanceof xs)){for(let l=n.parent;l;l=l.parent)if(l.formattingContext instanceof xs){o=l.formattingContext===t;break}}return o||s==="table-row"&&!am(i)||s==="table-cell"&&i!=="table-row"&&!am(i)||n.formattingContext instanceof xs&&n.formattingContext!==t?e.buildDeepElementView(n).thenAsync(l=>(r.nodeContext=l,T(!0))):null}var kp=class extends _n{constructor(e,n){super();this.formattingContext=e;this.column=n;p(this,"rowIndex",-1);p(this,"columnIndex",0);p(this,"inRow",!1);p(this,"checkPoints",[]);p(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let n=this.formattingContext,s=lm(e,n,this.column);if(s)return s;this.postLayoutBlockContents(e);let i=e.nodeContext,o=i.display,a=n.getRepetitiveElements();switch(o){case"table":n.inlineBorderSpacing=i.inlineBorderSpacing;break;case"table-caption":{let l=new vp(i.viewNode,i.captionSide);n.captions.push(l);break}case"table-header-group":return a.isHeaderRegistered()||(this.inHeaderOrFooter=!0,a.setHeaderNodeContext(i)),T(!0);case"table-footer-group":return a.isFooterRegistered()||(this.inHeaderOrFooter=!0,a.setFooterNodeContext(i)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,i.sourceNode,this.columnIndex=0,n.addRow(this.rowIndex,new gl(this.rowIndex,i.sourceNode)),a.firstContentSourceNode||(a.firstContentSourceNode=i.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,i=s.display,o=this.column.clientLayout;if(this.postLayoutBlockContents(e),s.sourceNode===n.tableSourceNode){let a=o.getElementComputedStyle(n.getRootViewNode(s));n.tableWidth=parseFloat(a[n.vertical?"height":"width"]),n.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(i){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":this.inHeaderOrFooter||(n.lastRowViewNode=s.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let a=s.viewNode;n.addCell(this.rowIndex,new Sp(this.rowIndex,this.columnIndex,a)),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 n=e.nodeContext;n&&n.viewNode&&!Dn(n)&&this.checkPoints.push(n.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Cl=class Cl extends _n{constructor(e,n){super(!0);this.formattingContext=e;this.column=n;p(this,"inRow",!1);p(this,"currentRowIndex",-1);p(this,"currentColumnIndex",0);p(this,"originalStopAtOverflow");p(this,"inHeader");p(this,"inFooter");this.originalStopAtOverflow=n.stopAtOverflow,n.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(e){let n=this.formattingContext.colWidths;let s=0;for(let i=0;i<e.colSpan;i++)s+=n[e.anchorSlot.columnIndex+i];return s+=this.formattingContext.inlineBorderSpacing*(e.colSpan-1),s}layoutCell(e,n,s){let i=e.rowIndex,o=e.columnIndex,a=e.colSpan,l=n.viewNode,c=n.verticalAlign;a>1&&(w(l,"box-sizing","border-box"),w(l,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(e)}px`));let u=l.ownerDocument.createElement("div");l.appendChild(u);let d=new Np(this.column,u,n);return this.formattingContext.addCellFragment(i,o,d),s.primary.steps.length===1&&s.primary.after&&(d.empty=!0),d.pseudoColumn.layout(s,!0).thenReturn(!0)}hasBrokenCellAtSlot(e){let n=this.formattingContext.cellBreakPositions[0];return n?n.cell.anchorSlot.columnIndex===e:!1}extractRowSpanningCellBreakPositions(){let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let n=[],s=0;do{let i=e[s],o=i.cell.rowIndex;if(o<this.currentRowIndex){let a=n[o];a||(a=n[o]=[]),a.push(i),e.splice(s,1)}else s++}while(s<e.length);return n}layoutRowSpanningCellsFromPreviousFragment(e){let n=this.formattingContext,s=this.extractRowSpanningCellBreakPositions(),i=s.reduce(h=>h+1,0);if(i===0)return T(!0);let o=this.column.layoutContext,a=e.nodeContext;a.viewNode.parentNode.removeChild(a.viewNode);let l=A("layoutRowSpanningCellsFromPreviousFragment"),c=T(!0),u=0,d=[];return s.forEach(h=>{c=c.thenAsync(()=>{let f=Oi(h[0].cellNodePosition.steps[1],a.parent);return o.setCurrent(f,!1).thenAsync(()=>{let g=T(!0),m=0;function y(S){for(;m<S;){if(!d.includes(m)){let C=f.viewNode.ownerDocument.createElement("td");w(C,"padding","0"),f.viewNode.appendChild(C)}m++}}return h.forEach(S=>{g=g.thenAsync(()=>{let C=S.cell;y(C.anchorSlot.columnIndex);let x=S.cellNodePosition,N=Oi(x.steps[0],f);return N.offsetInNode=x.offsetInNode,N.after=x.after,N.fragmentIndex=x.steps[0].fragmentIndex+1,o.setCurrent(N,!1).thenAsync(()=>{let E=S.breakChunkPosition;for(let v=0;v<C.colSpan;v++)d.push(m+v);return m+=C.colSpan,this.layoutCell(C,N,E).thenAsync(()=>(N.viewNode.rowSpan=C.rowIndex+C.rowSpan-this.currentRowIndex+i-u,T(!0)))})})}),g.thenAsync(()=>(y(n.getColumnCount()),u++,T(!0)))})})}),c.then(()=>{o.setCurrent(a,!0,e.atUnforcedBreak).then(()=>{l.finish(!0)})}),l.result()}startTableRow(e){if(this.inHeader||this.inFooter)return T(!0);let n=e.nodeContext,s=this.formattingContext;return this.currentRowIndex<0?(n.sourceNode,this.currentRowIndex=s.findRowIndexBySourceNode(n.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(e).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge)&&s.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),n.overflow=!0,e.break=!0),T(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(n=>{let s=this.formattingContext.cellBreakPositions[n.columnIndex];if(s&&s.cell.anchorSlot.columnIndex==n.anchorSlot.columnIndex){let i=s.cellNodePosition.steps[0],o=this.column.layoutContext.xmldoc.getElementOffset(i.node);im(o,i.fragmentIndex+1,1)}})}startTableCell(e){if(this.inHeader||this.inFooter)return T(!0);let n=e.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let s=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!s)return e.break=!0,T(!0);let i=n.copy().modify();i.after=!0,e.nodeContext=i;let o=A("startTableCell"),a;if(this.hasBrokenCellAtSlot(s.anchorSlot.columnIndex)){let l=this.formattingContext.cellBreakPositions.shift();n.fragmentIndex=l.cellNodePosition.steps[0].fragmentIndex+1,a=T(l.breakChunkPosition)}else a=this.column.nextInTree(n,e.atUnforcedBreak).thenAsync(l=>{l.viewNode&&n.viewNode.removeChild(l.viewNode);let c=Xs(l,0);return T(new Nt(c))});return a.then(l=>{this.layoutCell(s,n,l).then(()=>{this.afterNonInlineElementNode(e),this.currentColumnIndex++,o.finish(!0)})}),o.result()}startNonInlineBox(e){let n=lm(e,Yt(this.formattingContext),this.column);if(n)return n;let s=e.nodeContext,i=this.formattingContext.getRepetitiveElements(),o=s.display;return o==="table-header-group"&&i&&i.isHeaderSourceNode(s.sourceNode)?(this.inHeader=!0,T(!0)):o==="table-footer-group"&&i&&i.isFooterSourceNode(s.sourceNode)?(this.inFooter=!0,T(!0)):o==="table-row"?this.startTableRow(e):o==="table-cell"?this.startTableCell(e):T(!0)}endNonInlineBox(e){let n=e.nodeContext;if(n.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let i=n.copy().modify();i.after=!1;let o=new wp(this.currentRowIndex,i,this.formattingContext);this.column.breakPositions.push(o)}return T(!0)}afterNonInlineElementNode(e){let n=e.nodeContext,s=this.formattingContext.getRepetitiveElements(),i=n.display;if(i==="table-header-group"?s&&!s.allowInsertRepeatitiveElements&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!1,n.viewNode.parentNode.removeChild(n.viewNode)):w(n.viewNode,"display","table-row-group"):i==="table-footer-group"&&(s&&!s.allowInsertRepeatitiveElements&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!1,n.viewNode.parentNode.removeChild(n.viewNode)):w(n.viewNode,"display","table-row-group")),i&&Cl.ignoreList[i])n.viewNode.parentNode.removeChild(n.viewNode);else if(n.sourceNode===this.formattingContext.tableSourceNode)n.overflow=this.column.checkOverflowAndSaveEdge(n,null),this.resetColumn(),e.break=!0;else return super.afterNonInlineElementNode(e);return T(!0)}};p(Cl,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ap=Cl,Yo=[];function by(r){let t=Yo.findIndex(n=>n.root===r),e=Yo[t];return e?e.tableLayoutOption:null}function yy(r){let t=Yo.findIndex(e=>e.root===r);t>=0&&Yo.splice(t,1)}var ml=class{layoutEntireTable(t,e){let n=Yt(t.formattingContext),s=new kp(n,e);return new js(s,e.layoutContext).iterate(t)}getColumnWidths(t,e,n,s){let i=t.ownerDocument,o=i.createElement("tr"),a=[];for(let c=0;c<e;c++){let u=i.createElement("td");o.appendChild(u),a.push(u)}t.parentNode.insertBefore(o,t.nextSibling);let l=a.map(c=>{let u=Mt(s,c,n),d=n?u.height:u.width;return Math.ceil(d)});return t.parentNode.removeChild(o),l}getColGroupElements(t){let e=[],n=t.firstElementChild;for(;n;)n.localName==="colgroup"&&e.push(n),n=n.nextElementSibling;return e}normalizeAndGetColElements(t){let e=[];return t.forEach(n=>{let s=n.span;n.removeAttribute("span");let i=n.firstElementChild;for(;i;){if(i.localName==="col"){let o=i.span;for(i.removeAttribute("span"),s-=o;o-- >1;){let a=i.cloneNode(!0);n.insertBefore(a,i),e.push(a)}e.push(i)}i=i.nextElementSibling}for(;s-- >0;)i=n.ownerDocument.createElement("col"),n.appendChild(i),e.push(i)}),e}addMissingColElements(t,e,n,s){if(t.length<n){let i=s.ownerDocument.createElement("colgroup");e.push(i);for(let o=t.length;o<n;o++){let a=s.ownerDocument.createElement("col");i.appendChild(a),t.push(a)}}}normalizeColGroups(t,e,n){let s=t.vertical,i=t.lastRowViewNode;if(!i)return;t.lastRowViewNode=null;let a=i.ownerDocument.createDocumentFragment(),l=t.getColumnCount();if(!(l>0)){t.colGroups=a;return}let c=t.colWidths=this.getColumnWidths(i,l,s,n.clientLayout),u=this.getColGroupElements(e),d=this.normalizeAndGetColElements(u);this.addMissingColElements(d,u,l,e),d.forEach((h,f)=>{w(h,s?"height":"width",`${c[f]}px`)}),u.forEach(h=>{a.appendChild(h.cloneNode(!0))}),t.colGroups=a}doInitialLayout(t,e){let n=Yt(t.formattingContext);n.vertical=t.vertical,n.initializeRepetitiveElements(t.vertical),t.sourceNode;let s=by(t.sourceNode);yy(t.sourceNode);let i=A("TableLayoutProcessor.doInitialLayout"),o=t.copy();return this.layoutEntireTable(t,e).then(a=>{let l=a.viewNode,c=Mt(e.clientLayout,l,e.vertical),u=e.vertical?c.left:c.bottom;if(u+=(e.vertical?-1:1)*hs(t,e.collectElementsOffset()).current,!e.isOverflown(u)&&(!s||!s.calculateBreakPositionsInside)){e.breakPositions.push(new Ip(o)),i.finish(a);return}this.normalizeColGroups(n,l,e),n.updateCellSizes(e.clientLayout),i.finish(null)}),i.result()}addCaptions(t,e,n){let s=t.captions;s.forEach((i,o)=>{i&&(e.insertBefore(i.viewNode,n),i.side==="top"&&(s[o]=null))})}addColGroups(t,e,n){t.colGroups&&this.getColGroupElements(e).length===0&&(e.insertBefore(t.colGroups.cloneNode(!0),n),w(e,"table-layout","fixed"),w(e,t.vertical?"height":"width",`${t.tableWidth}px`))}removeColGroups(t,e){if(t.colGroups&&e){let n=this.getColGroupElements(e);n&&n.forEach(s=>{e.removeChild(s)})}}doLayout(t,e){let n=Yt(t.formattingContext),s=n.getRootViewNode(t),i=s.firstChild;this.addCaptions(n,s,i),this.addColGroups(n,s,i);let o=new Ap(n,e),a=new js(o,e.layoutContext),l=A("TableFormattingContext.doLayout");return a.iterate(t).thenFinish(l),l.result()}layout(t,e,n){let s=Yt(t.formattingContext),i=s.getRootViewNode(t),o=A("TableFormattingContext.layout"),a;return i?(n&&yp(t.parent,e),a=new Lp(s,this).layout(t,e)):a=e.buildDeepElementView(t),a.then(l=>{o.finish(l),e.element.hasAttribute("data-vivliostyle-column-height-adjusted")&&(w(e.element,"width",`${e.width}px`),w(e.element,"height",`${e.height}px`),e.element.removeAttribute("data-vivliostyle-column-height-adjusted"))}),o.result()}createEdgeBreakPosition(t,e,n,s){return new Tp(t,e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return xp(t),!1}finishBreak(t,e,n,s){let i=Yt(e.formattingContext);if(e.display==="table-row"){e.sourceNode;let o=i.findRowIndexBySourceNode(e.sourceNode);i.cellBreakPositions=[];let a;if(e.after?a=i.getRowSpanningCellsOverflowingTheRow(o):a=i.getCellsFallingOnRow(o),a.length){let l=A("TableLayoutProcessor.finishBreak"),c=0;return l.loopWithFrame(u=>{if(c===a.length){u.breakLoop();return}let d=a[c++],h=i.getCellFragmentOfCell(d),f=h.findAcceptableBreakPosition().nodeContext;let g=h.cellNodeContext,m=g.toNodePosition(),y=new Nt(f.toNodePosition());i.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:y,cell:d});let S=g.viewNode;h.column.layoutContext.processFragmentedBlockEdge(h.cellNodeContext),o<d.rowIndex+d.rowSpan-1&&(S.rowSpan=o-d.rowIndex+1),h.empty?u.continueLoop():h.pseudoColumn.finishBreak(f,!1,!0).then(()=>{xy(h,i,f),u.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),xp(e),i.finishFragment(),l.finish(!0)}),l.result()}}return xp(e),i.finishFragment(),Bo.finishBreak(t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Nn.prototype.clearOverflownViewNodes(t,e,n,s)}};function xy(r,t,e){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,i=r.column,o=r.pseudoColumn.getColumnElement(),a=r.cellNodeContext.viewNode,l=Mt(i.clientLayout,a,s),c=i.getComputedPaddingBorder(a);if(s){let u=l.right-i.footnoteEdge-n.calculateOffset(e)-c.right;w(o,"max-width",`${u}px`)}else{let u=i.footnoteEdge-n.calculateOffset(e)-l.top-c.top;w(o,"max-height",`${u}px`)}}function xp(r){let t=r.display==="table-row"?r.viewNode.parentElement:r.display==="table"?r.viewNode.querySelector("tbody"):null;if(!t)return;let e;try{e=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch(d){return}if(e.length===0)return;let n=Array.from(e).reduce((d,h)=>{let f=h.getBoundingClientRect(),g=r.vertical?f.width:f.height;return d+g},0),s=e[e.length-1],i=Array.from(t.children).indexOf(s),o=Array.from(s.children).reduce((d,h)=>{let f=h.rowSpan;return f>1&&i+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[i+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let l=a.getBoundingClientRect(),c=r.vertical?l.width:l.height,u=n+c;w(a,r.vertical?"width":"height",`${u}px`)}var Lp=class extends gs{constructor(e,n){super();this.tableFormattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.tableFormattingContext.getRepetitiveElements();return!n||!n.doneInitialLayout?new Rp(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&n&&n.preventSkippingHeader(),new Fp(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let n=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,n)}restoreState(e,n){super.restoreState(e,n),this.tableFormattingContext.finishFragment()}},Rp=class extends $o{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}},Ip=class extends En{constructor(t){super(t,null,t.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(t){t.fragmentLayoutConstraints.push(new Vp(this.position.sourceNode))}},Vp=class r{constructor(t){this.tableRootNode=t;p(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,e,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,e,n,s){e.sourceNode,Yo.push({root:e.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,e){return T(!0)}equalsTo(t){return t instanceof r&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Fp=class extends jo{constructor(e,n){super(e);this.processor=n}doLayout(e,n){let s=this.formattingContext.getRepetitiveElements();if(s&&!s.isAfterLastContent(e)){let i=new Bp(e);n.fragmentLayoutConstraints.some(o=>i.equalsTo(o))||n.fragmentLayoutConstraints.unshift(i)}return this.processor.doLayout(e,n)}},Bp=class r extends Yi{constructor(e){super(e);p(this,"flagmentLayoutConstraintType","TableRow");p(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,n,s){let i=this.getRepetitiveElements();return!i||s.pseudoParent||On(this.nodeContext.viewNode)||!i.isEnableToUpdateState()?!0:!(n&&!e||e&&e.overflow)}nextCandidate(e){let n=Yt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(e,n).some(i=>i.constraints.some(o=>o.nextCandidate(e)))?!0:super.nextCandidate(e)}postLayout(e,n,s,i){let o=Yt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(n,o),this.cellFragmentLayoutConstraints.forEach(a=>{a.constraints.forEach(l=>{l.postLayout(e,a.breakPosition,s,i)})}),!e){let a=o.getRootViewNode(this.nodeContext);new ml().removeColGroups(o,a),this.removeDummyRowNodes(s)}super.postLayout(e,n,s,i)}finishBreak(e,n){let s=Yt(this.nodeContext.formattingContext),i=A("finishBreak"),o=this.cellFragmentLayoutConstraints.reduce((l,c)=>l.concat(c.constraints.map(u=>({constraint:u,breakPosition:c.breakPosition}))),[]),a=0;return i.loop(()=>{if(a<o.length){let l=o[a++];return l.constraint.finishBreak(l.breakPosition,n).thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result().thenAsync(()=>super.finishBreak(e,n))}removeDummyRowNodes(e){if(!(!e||e.display!=="table-row"||!e.viewNode))for(;e.viewNode.previousElementSibling;){let n=e.viewNode.previousElementSibling;n.parentNode&&n.parentNode.removeChild(n)}}collectCellFragmentLayoutConstraints(e,n){return this.getCellFragemnts(e,n).map(s=>({constraints:s.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:s.breakPosition}))}getCellFragemnts(e,n){let s=Number.MAX_VALUE;e&&e.display==="table-row"&&(e.sourceNode,s=n.findRowIndexBySourceNode(e.sourceNode)+1),s=Math.min(n.cellFragments.length,s);let i=[];for(let o=0;o<s;o++)n.cellFragments[o]&&n.cellFragments[o].forEach(a=>{a&&i.push({fragment:a,breakPosition:a.findAcceptableBreakPosition().nodeContext})});return i}getElementsOffsetsForTableCell(e){let n=Yt(this.nodeContext.formattingContext),s=n.findCellFromColumn(e);return s?n.collectElementsOffsetOfUpperCells(s):n.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof r?Yt(this.nodeContext.formattingContext)===Yt(e.nodeContext.formattingContext):!1}},Sy=new ml;function Ey(r,t,e,n,s,i){if(!t)return null;if(e===b.table){let o=r.parent;return new xs(o?o.formattingContext:null,r.sourceNode)}return null}function Ny(r){return r instanceof xs?Sy:null}je("RESOLVE_FORMATTING_CONTEXT",Ey);je("RESOLVE_LAYOUT_PROCESSOR",Ny);function cm(r){return r.reduce((t,e)=>t+e,0)/r.length}function um(r){let t=cm(r);return cm(r.map(e=>{let n=e-t;return n*n}))}var Op=class{constructor(t,e){this.layoutResult=t;this.penalty=e}};function qo(r){return r.vertical?r.width:r.height}function Ko(r,t){r.vertical?r.width=t:r.height=t}var bl=class{constructor(t,e,n){this.layoutContainer=t;this.columnGenerator=e;this.regionPageFloatLayoutContext=n;p(this,"originalContainerBlockSize");this.originalContainerBlockSize=qo(t)}balanceColumns(t){let e=A("ColumnBalancer#balanceColumns");this.preBalance(t),this.savePageFloatLayoutContexts(t),this.layoutContainer.clear();let n=[this.createTrialResult(t)];return e.loopWithFrame(s=>{if(!this.hasNextCandidate(n)){s.breakLoop();return}this.updateCondition(n),this.columnGenerator().then(i=>{if(this.savePageFloatLayoutContexts(i),this.layoutContainer.clear(),!i){s.breakLoop();return}n.push(this.createTrialResult(i)),s.continueLoop()})}).then(()=>{let s=n.reduce((i,o)=>o.penalty<i.penalty?o:i,n[0]);this.restoreContents(s.layoutResult),this.postBalance(),e.finish(s.layoutResult)}),e.result()}createTrialResult(t){let e=this.calculatePenalty(t);return new Op(t,e)}preBalance(t){}postBalance(){Ko(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(t){let e=this.regionPageFloatLayoutContext.detachChildren();t&&(t.columnPageFloatLayoutContexts=e)}restoreContents(t){let e=this.layoutContainer.element;t.columns.forEach(n=>{e.appendChild(n.element)}),t.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(t.columnPageFloatLayoutContexts)}},Dp=1;function pm(r){let t=r[r.length-1];if(t.penalty===0)return!1;let e=r[r.length-2];if(e&&t.penalty>=e.penalty)return!1;let n=t.layoutResult.columns,s=Math.max.apply(null,n.map(o=>o.computedBlockSize)),i=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return s>i+Dp}function hm(r,t){var i;let e=r[r.length-1].layoutResult.columns,s=Math.max.apply(null,e.map(o=>isNaN(o.blockDistanceToBlockEndFloats)?o.computedBlockSize:o.computedBlockSize-o.blockDistanceToBlockEndFloats+Dp))-Dp;if(s<qo(t)?Ko(t,s):Ko(t,qo(t)-1),t.vertical){let o=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=o-t.width}}var Mp=class extends bl{constructor(e,n,s,i){super(s,e,n);this.columnCount=i;p(this,"originalPosition",null);p(this,"foundUpperBound",!1)}preBalance(e){let s=e.columns.reduce((i,o)=>i+o.computedBlockSize,0);Ko(this.layoutContainer,s/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 n=e.columns;return dm(n)?1/0:Math.max.apply(null,n.map(s=>s.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return pm(e);{let n=e[e.length-1];return this.checkPosition(n.layoutResult.position)&&!dm(n.layoutResult.columns)?(this.foundUpperBound=!0,!0):qo(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)hm(e,this.layoutContainer);else{let n=Math.min(this.originalContainerBlockSize,qo(this.layoutContainer)+this.originalContainerBlockSize*.1);Ko(this.layoutContainer,n)}}};function dm(r){if(r.length<=1)return!1;let t=r[r.length-1].computedBlockSize,e=r.slice(0,r.length-1),n=6;return e.every(s=>t>s.computedBlockSize+n)}var _p=class extends bl{constructor(t,e,n){super(n,t,e)}calculatePenalty(t){if(t.columns.every(n=>n.computedBlockSize===0))return 1/0;let e=t.columns.filter(n=>!n.pageBreakType).map(n=>n.computedBlockSize);return um(e)}hasNextCandidate(t){return pm(t)}updateCondition(t){hm(t,this.layoutContainer)}};function fm(r,t,e,n,s,i,o){if(t===b.auto)return null;{let a=o.positions.length===0,l=i[i.length-1],c=!!(l&&l.pageBreakType);return a||c?new Mp(e,n,s,r):t===b.balance_all?new _p(e,n,s):(b.balance,null)}}var wy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Py=new Set(wy);function ky(r){return!(r.toLowerCase()==="none"||Py.has(r))}var Ay=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Ly=new Set(Ay),Ry=["fixed","extends"],Iy=new Set(Ry),oE=Symbol();function ur(r){return r instanceof j&&r.name.toLowerCase()!=="none"}function mm(r){return r.name}function Vy(r){if(r instanceof j)return Ly.has(r.name);if(r instanceof W&&r.values.length===2){let t=r.values[0],e=r.values[1];if(t instanceof j){let n=t.name;return Iy.has(n)&&(n==="fixed"&&e instanceof se||n==="extends"&&ur(e))}}return!1}function Fy(r){let t=ot(r,"system");return t instanceof j&&t.name==="cyclic"}function By(r){let t=ot(r,"system");if(t instanceof j&&t.name==="fixed")return!0;if(t instanceof W&&t.values.length===2){let[e,n]=t.values;return e instanceof j&&e.name==="fixed"&&n instanceof se}return!1}function Oy(r){let t=ot(r,"system");return t instanceof j?1:t.values[1].num}function Dy(r){let t=ot(r,"system");return t instanceof j&&t.name==="alphabetic"}function My(r){let t=ot(r,"system");return t instanceof j&&t.name==="numeric"}function _y(r){let t=ot(r,"system");return t instanceof j&&t.name==="additive"}function Uy(r){let t=ot(r,"system");if(t instanceof W&&t.values.length===2){let[e,n]=t.values;return e instanceof j&&e.name==="extends"&&ur(n)}return!1}function Hy(r){let t=ot(r,"system");return mm(t.values[1])}function qt(r){return r instanceof D||r instanceof j}function $n(r){return r instanceof D?r.str:r.name}function Cm(r){if(qt(r))return!0;if(r instanceof W&&r.values.length===2){let t=r.values[0],e=r.values[1];return qt(t)&&qt(e)}return!1}function zy(r){if(qt(r))return{prefix:$n(r),suffix:null};{let t=r.values[0],e=r.values[1];return{prefix:$n(t),suffix:$n(e)}}}function gm(r){return r instanceof se||r instanceof j&&r.name==="infinite"}function yl(r,t){return r instanceof se?r.num:t?-1/0:1/0}var rE=Symbol();function Up(r){if(!(r instanceof W&&r.values.length===2))return!1;let t=r.values[0],e=r.values[1];if(!(gm(t)&&gm(e)))return!1;let n=yl(t,!0),s=yl(e,!1);return!(n>s)}function Gy(r){return{lower:yl(r.values[0],!0),upper:yl(r.values[1],!1)}}function bm(r){return r instanceof j&&r.name==="auto"||Up(r)||r instanceof ge&&r.values.length>=1&&r.values.every(t=>Up(t))}function Wy(r){return r instanceof j?null:(Up(r)?[r]:r.values).map(e=>Gy(e))}var aE=Symbol();function xl(r){if(!(r instanceof W&&r.values.length===2))return!1;let t=r.values[0],e=r.values[1];return t instanceof se&&t.num>=0&&qt(e)||qt(t)&&e instanceof se&&e.num>=0}function Sl(r){let[t,e]=r.values;return t instanceof se?[t.num,$n(e)]:[e.num,$n(t)]}function ym(r){return xl(r)}function Xy(r){let[t,e]=Sl(r);return{minLength:t,symbol:e}}function xm(r){return qt(r)||r instanceof W&&r.values.length>=1&&r.values.every(t=>qt(t))}function $y(r){return qt(r)?[$n(r)]:r.values.map(t=>$n(t))}var lE=Symbol();function Sm(r){if(xl(r))return!0;if(r instanceof ge&&r.values.length>=1){let t=1/0;for(let e of r.values){if(!xl(e))return!1;let[n]=Sl(e);if(n>=t)return!1;t=n}return!0}return!1}function jy(r){if(xl(r)){let[t,e]=Sl(r);return[{weight:t,symbol:e}]}else return r.values.map(t=>{let[e,n]=Sl(t);return{weight:e,symbol:n}})}var Yy=["auto","bullets","numbers","words","spell-out"],qy=new Set(Yy);function Ky(r){return r instanceof j&&qy.has(r.name)||ur(r)}function Em(r,t){switch(r){case"system":return Vy(t);case"negative":return Cm(t);case"prefix":case"suffix":return qt(t);case"range":return bm(t);case"pad":return ym(t);case"fallback":return ur(t);case"symbols":return xm(t);case"additive-symbols":return Sm(t);case"speak-as":return Ky(t);default:return!0}}function ot(r,t){var n;let e=(n=r[t])==null?void 0:n.value;return e==null?null:e}function Zy(r,t){return t.some(({lower:e,upper:n})=>r>=e&&r<=n)}function Ki(r){let t=r.get("decimal");return t||(t=Z.createDecimal(r),r.set("decimal",t)),t}var Qo,Jo,er,tr,nr,sr,ir,or,Tl,wl,Pl,kl,Al,Ll,Rl,Pe,Hp,Nm,vm,Tm,wm,zp,Pm,Zo,ht=class ht{constructor(t,e){J(this,Pe);p(this,"_store");J(this,Qo);J(this,Jo);J(this,er);J(this,tr);J(this,nr);J(this,sr);J(this,ir);J(this,or);this._store=t;let n=ot(e,"negative");yt(this,Qo,n&&Cm(n)?zy(n):null);let s=ot(e,"prefix");yt(this,Jo,s&&qt(s)?$n(s):null);let i=ot(e,"suffix");yt(this,er,i&&qt(i)?$n(i):null);let o=ot(e,"range");yt(this,tr,o&&bm(o)?Wy(o):null);let a=ot(e,"pad");yt(this,nr,a&&ym(a)?Xy(a):null);let l=ot(e,"fallback");yt(this,sr,l&&ur(l)?mm(l):null);let c=ot(e,"symbols");yt(this,ir,c&&xm(c)?$y(c):null);let u=ot(e,"additive-symbols");yt(this,or,u&&Sm(u)?jy(u):null)}static create(t,e){return Fy(e)?new Xn(t,e):By(e)?new Gp(t,e):Dy(e)?new Xp(t,e):My(e)?new El(t,e):_y(e)?new $p(t,e):Uy(e)?new jp(t,e):new Wp(t,e)}static createDecimal(t){return new El(t,G(ht,Tl))}static createDisc(t){return new Xn(t,G(ht,wl))}static createSquare(t){return new Xn(t,G(ht,Pl))}static createCircle(t){return new Xn(t,G(ht,kl))}static createDisclosureOpen(t){return new Xn(t,G(ht,Al))}static createDisclosureClosed(t){return new Xn(t,G(this,Ll))}static createNone(t){return new Xn(t,G(ht,Rl))}static get CHINESE_LONGHAND_NAMES(){return Nl.NAMES}static createChineseLonghand(t,e){return new Nl(t,e)}static createEthiopicNumeric(t){return new Yp(t)}_getNegative(){return G(this,Qo)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return G(this,Jo)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return G(this,er)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return G(this,tr)}static _getRangeFrom(t){return t._getRange()}_getPad(){return G(this,nr)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(G(this,sr)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return G(this,ir)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return G(this,or)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,e){return t._usesNegativeSign(e)}static _generateInitialRepresentationFrom(t,e){return t._generateInitialRepresentation(e)}format(t){return ye(this,Pe,Zo).call(this,t,new Set)}formatMarker(t){return ye(this,Pe,Nm).call(this)+this.format(t)+ye(this,Pe,vm).call(this)}};Qo=new WeakMap,Jo=new WeakMap,er=new WeakMap,tr=new WeakMap,nr=new WeakMap,sr=new WeakMap,ir=new WeakMap,or=new WeakMap,Tl=new WeakMap,wl=new WeakMap,Pl=new WeakMap,kl=new WeakMap,Al=new WeakMap,Ll=new WeakMap,Rl=new WeakMap,Pe=new WeakSet,Hp=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},Nm=function(){var t;return(t=this._getPrefix())!=null?t:""},vm=function(){var t;return(t=this._getSuffix())!=null?t:". "},Tm=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},wm=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},zp=function(){var t;return(t=this._getFallback())!=null?t:Ki(this._store)},Pm=function(t,e){let{minLength:n,symbol:s}=ye(this,Pe,wm).call(this);if(n===0||s==="")return t;let{prefix:i,suffix:o}=ye(this,Pe,Hp).call(this),a=e?[...i].length+(o?[...o].length:0):0,l=n-[...t].length-a;if(l<=0)return t;let c=[...s].length,u=Math.ceil(l/c);return s.repeat(u)+t},Zo=function(t,e){var a,l,c;if(e.has(this))return ye(a=Ki(this._store),Pe,Zo).call(a,t,new Set);if(e.add(this),!Zy(t,ye(this,Pe,Tm).call(this))){let u=ye(this,Pe,zp).call(this);return ye(l=u,Pe,Zo).call(l,t,e)}let n=this._usesNegativeSign(t),s=n?Math.abs(t):t,i=this._generateInitialRepresentation(s);if(i===null){let u=ye(this,Pe,zp).call(this);return ye(c=u,Pe,Zo).call(c,t,e)}let o=ye(this,Pe,Pm).call(this,i,n);if(n){let{prefix:u,suffix:d}=ye(this,Pe,Hp).call(this);o=u+o+(d!=null?d:"")}return o},J(ht,Tl,{system:new I(k("numeric"),0),symbols:new I(new W([new D("0"),new D("1"),new D("2"),new D("3"),new D("4"),new D("5"),new D("6"),new D("7"),new D("8"),new D("9")]),0)}),J(ht,wl,{system:new I(k("cyclic"),0),symbols:new I(new D("\u2022"),0),suffix:new I(new D(" "),0)}),J(ht,Pl,{system:new I(k("cyclic"),0),symbols:new I(new D("\u25AA"),0),suffix:new I(new D(" "),0)}),J(ht,kl,{system:new I(k("cyclic"),0),symbols:new I(new D("\u25E6"),0),suffix:new I(new D(" "),0)}),J(ht,Al,{system:new I(k("cyclic"),0),symbols:new I(new D("\u25BE"),0),suffix:new I(new D(" "),0)}),J(ht,Ll,{system:new I(k("cyclic"),0),symbols:new I(new D("\u25B8"),0),suffix:new I(new D(" "),0)}),J(ht,Rl,{system:new I(k("cyclic"),0),symbols:new I(new D(""),0),suffix:new I(new D(""),0)});var Z=ht,Xn=class extends Z{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0)return null;let n=e.length,s=((t-1)%n+n)%n;return e[s]}},rr,Gp=class extends Z{constructor(e,n){super(e,n);J(this,rr);yt(this,rr,Oy(n))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var i;let n=this._getSymbols();if(!n||n.length===0)return null;let s=e-G(this,rr);return(i=n[s])!=null?i:null}};rr=new WeakMap;var Wp=class extends Z{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0||t<1)return null;let n=e.length,s=e[(t-1)%n],i=Math.ceil(t/n);return s.repeat(i)}},Xp=class extends Z{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2||t<1)return null;let n=e.length,s="",i=t;for(;i!==0;)i=i-1,s=e[i%n]+s,i=Math.floor(i/n);return s}},El=class extends Z{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2)return null;let n=e.length;if(t===0)return e[0];let s="",i=t;for(;i!==0;)s=e[i%n]+s,i=Math.floor(i/n);return s}},$p=class extends Z{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getAdditiveSymbols();if(!e||e.length===0)return null;let n="";if(t===0){let i=e.find(o=>o.weight===0);return i?i.symbol:null}let s=t;for(let i of e){let{weight:o,symbol:a}=i;if(o===0||o>s)continue;let l=Math.floor(s/o);if(n+=a.repeat(l),s-=o*l,s===0)return n}return null}},qi,ft,Ut,qp=class qp extends Z{constructor(e,n){super(e,n);J(this,ft);J(this,qi);let s=Hy(n),i=s.toLowerCase();i==="disc"||i==="circle"||i==="square"||i==="disclosure-open"||i==="disclosure-closed"?yt(this,qi,i):yt(this,qi,s)}_getNegative(){var e;return(e=super._getNegative())!=null?e:Z._getNegativeFrom(ye(this,ft,Ut).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:Z._getPrefixFrom(ye(this,ft,Ut).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:Z._getSuffixFrom(ye(this,ft,Ut).call(this))}_getAutoRange(){return Z._getAutoRangeFrom(ye(this,ft,Ut).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:Z._getRangeFrom(ye(this,ft,Ut).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:Z._getPadFrom(ye(this,ft,Ut).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:Z._getFallbackFrom(ye(this,ft,Ut).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:Z._getSymbolsFrom(ye(this,ft,Ut).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:Z._getAdditiveSymbolsFrom(ye(this,ft,Ut).call(this))}_usesNegativeSign(e){return Z._useNegativeSignFrom(ye(this,ft,Ut).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:Z._generateInitialRepresentationFrom(ye(this,ft,Ut).call(this),e)}};qi=new WeakMap,ft=new WeakSet,Ut=function(e=new Set){var s;if(e.has(this))return Ki(this._store);e.add(this);let n=this._store.get(G(this,qi));return n?n instanceof qp?ye(s=n,ft,Ut).call(s,e):n:Ki(this._store)};var jp=qp,Qy=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Il,Vl,ar,Fl,Bl,lr,vt=class vt extends Z{constructor(e,n){let{chars:s,descriptors:i}=G(vt,Bl).get(n);super(e,i);J(this,lr);yt(this,lr,s)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let n=G(this,lr);if(e===0)return n.digits[0];let s=[],i=0,o=e;for(;o>0;)s.unshift({digit:o%10,position:i}),o=Math.floor(o/10),i++;let a=n.informal&&e>=10&&e<=19,l="",c=!1;for(let u=0;u<s.length;u++){let{digit:d,position:h}=s[u],f=u===s.length-1;d===0?!f&&!c&&(c=!0):(c&&(l+=n.digits[0],c=!1),a&&h===1?l+=n.markers[h]:(l+=n.digits[d],h>0&&(l+=n.markers[h])))}return l}};Il=new WeakMap,Vl=new WeakMap,ar=new WeakMap,Fl=new WeakMap,Bl=new WeakMap,lr=new WeakMap,J(vt,Il,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new I(new D("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new W([new se(-9999),new se(9999)]),0),negative:new I(new D("\u8D1F"),0)}}),J(vt,Vl,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new I(new D("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new W([new se(-9999),new se(9999)]),0),negative:new I(new D("\u8D1F"),0)}}),J(vt,ar,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new I(new D("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new W([new se(-9999),new se(9999)]),0),negative:new I(new D("\u8CA0"),0)}}),J(vt,Fl,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new I(new D("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new W([new se(-9999),new se(9999)]),0),negative:new I(new D("\u8CA0"),0)}}),p(vt,"NAMES",new Set(Qy)),J(vt,Bl,new Map([["simp-chinese-informal",G(vt,Il)],["simp-chinese-formal",G(vt,Vl)],["trad-chinese-informal",G(vt,ar)],["trad-chinese-formal",G(vt,Fl)],["cjk-ideographic",G(vt,ar)]]));var Nl=vt,Ol,Dl,cr,Ml,_l,Ht=class Ht extends Z{constructor(t){super(t,G(Ht,Ol))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return G(Ht,cr)[1];let e=[],n=t;for(;n>0;)e.push(n%100),n=Math.floor(n/100);let s=e.length,i="";for(let o=s-1;o>=0;o--){let a=e[o],l=o%2===1,c=o===s-1;if(!(a===0||c&&a===1||l&&a===1)){let d=Math.floor(a/10),h=a%10;i+=G(Ht,Dl)[d]+G(Ht,cr)[h]}l?a!==0&&(i+=G(Ht,Ml)):o!==0&&(i+=G(Ht,_l))}return i}};Ol=new WeakMap,Dl=new WeakMap,cr=new WeakMap,Ml=new WeakMap,_l=new WeakMap,J(Ht,Ol,{range:new I(new W([new se(1),k("infinite")]),0),suffix:new I(new D("/ "),0)}),J(Ht,Dl,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),J(Ht,cr,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),J(Ht,Ml,"\u137B"),J(Ht,_l,"\u137C");var Yp=Ht,be,vl=class{constructor(){J(this,be);yt(this,be,new Map),G(this,be).set("none",Z.createNone(G(this,be))),G(this,be).set("decimal",Z.createDecimal(G(this,be))),G(this,be).set("disc",Z.createDisc(G(this,be))),G(this,be).set("square",Z.createSquare(G(this,be))),G(this,be).set("circle",Z.createCircle(G(this,be))),G(this,be).set("disclosure-open",Z.createDisclosureOpen(G(this,be))),G(this,be).set("disclosure-closed",Z.createDisclosureClosed(G(this,be)));for(let t of Z.CHINESE_LONGHAND_NAMES)G(this,be).set(t,Z.createChineseLonghand(G(this,be),t));G(this,be).set("ethiopic-numeric",Z.createEthiopicNumeric(G(this,be)))}define(t,e){if(!ky(t))return null;let n=Z.create(G(this,be),e);return G(this,be).set(t,n),n}getStyle(t){var e;return(e=G(this,be).get(t))!=null?e:null}format(t,e){var n;return((n=this.getStyle(t))!=null?n:Ki(G(this,be))).format(e)}formatMarker(t,e){var n;return((n=this.getStyle(t))!=null?n:Ki(G(this,be))).formatMarker(e)}};be=new WeakMap;var dr=class{constructor(t,e,n){p(this,"endStuckFixed");p(this,"endFixed");p(this,"endSlipped");this.endStuckFixed=t,this.endFixed=e,this.endSlipped=n}},Kp=class{constructor(){p(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(t){if(this.map.length==0)this.map.push(new dr(t,t,t));else{let e=this.map[this.map.length-1],n=e.endSlipped+t-e.endFixed;e.endFixed==e.endStuckFixed?(e.endFixed=t,e.endStuckFixed=t,e.endSlipped=n):this.map.push(new dr(t,t,n))}}addSlippedRange(t){this.map.length==0?this.map.push(new dr(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=At(this.map.length,s=>t<=this.map[s].endFixed),n=this.map[e];return n.endSlipped-Math.max(0,n.endStuckFixed-t)}fixedBySlipped(t){let e=At(this.map.length,s=>t<=this.map[s].endSlipped),n=this.map[e];return n.endStuckFixed-(n.endSlipped-t)}},Zp=class r{constructor(t,e,n,s,i,o,a,l){this.context=t;this.style=e;this.offset=n;this.isRoot=s;this.flowChunk=i;this.atBlockStart=o;this.atFlowStart=a;this.isParentBoxDisplayed=l;p(this,"flowName");p(this,"isBlockValue",null);p(this,"hasBoxValue",null);p(this,"styleValues",{});p(this,"beforeBox",null);p(this,"afterBox",null);p(this,"breakBefore",null);if(this.flowName=i.flowName,this.hasBox()){let c=e._pseudos;if(c&&c.before){let u=new r(t,c.before,n,!1,i,this.isBlock(),a,!0),d=u.styleValue("content");dt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=_e(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Me(this.breakBefore)&&(i.breakBefore=_e(i.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,e,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let i=new r(this.context,s.after,t,!1,this.flowChunk,e,n,!0),o=i.styleValue("content");dt(o)&&(this.afterBox=i)}}}styleValue(t,e){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):e||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",b.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),e=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Ua(t,e,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==b.none&&!Lo(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let e=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(e=n.toString())}return e}},Qp=class{constructor(t){this.context=t;p(this,"stack",[]);p(this,"atBlockStart",!0);p(this,"atFlowStart",!0);p(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let t=this.lastBox();return t?t.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(t=>t.displayValue()!==b.none)}push(t,e,n,s){let i=this.lastBox();s&&i&&s.flowName!==i.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let o=s||i.flowChunk,a=this.atFlowStart||!!s,l=this.isCurrentBoxDisplayed(),c=new Zp(this.context,t,e,n,o,a||this.atBlockStart,a,l);return this.stack.push(c),this.atBlockStart=c.hasBox()?!c.beforeBox&&c.isBlock():this.atBlockStart,this.atFlowStart=c.hasBox()?!c.beforeBox&&a:this.atFlowStart,c}encounteredTextNode(t){let e=this.lastBox();if((t.nodeType===Node.TEXT_NODE||t.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&e.hasBox()){let n=e.styleValue("white-space",b.normal).toString(),s=Oa(n);s&&!me(t,s)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(t){let e=this.stack.pop();if(e.buildAfterPseudoElementBox(t,this.atBlockStart,this.atFlowStart),this.atFlowStart&&e.afterBox){let s=e.afterBox.getBreakValue("before");e.flowChunk.breakBefore=_e(e.flowChunk.breakBefore,s)}let n=this.lastBox();if(n)if(n.flowName===e.flowName)e.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let s=this.atStartStack.pop();this.atBlockStart=s.atBlockStart,this.atFlowStart=s.atFlowStart}return e}nearestBlockStartOffset(t){if(!t.atBlockStart)return t.offset;let e=this.stack.length-1,n=this.stack[e];for(n===t&&(e--,n=this.stack[e]);e>=0;){if(n.flowName!==t.flowName)return t.offset;if(!n.atBlockStart||n.isRoot)return n.offset;t=n,n=this.stack[--e]}throw new Error("No block start offset found!")}},pr=class{constructor(t,e,n,s,i,o,a,l,c){this.xmldoc=t;this.scope=n;this.context=s;this.primaryFlows=i;this.validatorSet=o;this.counterListener=a;p(this,"root");p(this,"cascadeHolder");p(this,"last");p(this,"rootStyle",{});p(this,"styleMap",{});p(this,"flows",{});p(this,"flowChunks",[]);p(this,"flowListener",null);p(this,"flowToReach",null);p(this,"idToReach",null);p(this,"cascade");p(this,"offsetMap");p(this,"primary",!0);p(this,"primaryStack",[]);p(this,"rootBackgroundAssigned",!1);p(this,"rootLayoutAssigned",!1);p(this,"lastOffset");p(this,"breakBeforeValues",{});p(this,"boxStack");p(this,"bodyReached",!0);this.root=t.root,this.cascadeHolder=e,this.last=this.root,this.cascade=e.createInstance(s,a,l,t.lang,c),this.offsetMap=new Kp;let u=t.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Qp(s),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.postprocessTopStyle(d,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(t,e,n){let s=t[n];return s&&s.evaluate(this.context)!==e[n]}transferPropsToRoot(t,e){for(let n in e){let s=t[n];if(s)this.rootStyle[n]=s,delete t[n];else{let i=e[n];i&&(this.rootStyle[n]=new I(i,Iu))}}}postprocessTopStyle(t,e){var n;if(e)for(let s of["writing-mode","direction"])t[s]&&!(e&&this.rootStyle[s])&&(this.rootStyle[s]=t[s]);else for(let s in t)ys(s)&&(this.rootStyle[s]=t[s]);if(!this.rootBackgroundAssigned){let s=this.hasProp(t,this.validatorSet.backgroundProps,"background-color")?t["background-color"].evaluate(this.context):null,i=this.hasProp(t,this.validatorSet.backgroundProps,"background-image")?t["background-image"].evaluate(this.context):null;(s&&!X(s)||i&&!X(i))&&(this.transferPropsToRoot(t,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let s=0;s<Am.length;s++)if(this.hasProp(t,this.validatorSet.layoutProps,Am[s])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!e){let s=t["font-size"],i=!0;if(s&&!X(s.value)){let l=s.evaluate(this.context);if(l instanceof P){let c=l.num;switch(l.unit){case"em":case"rem":c*=this.context.initialFontSize;break;case"%":c*=this.context.initialFontSize/100;break;case"lh":case"rlh":c*=this.context.initialFontSize*Ze.lh/Ze.em;break;default:{let u=Ze[l.unit];u&&(c*=u),i=!1}}this.context.rootFontSize=c,this.context.isRelativeRootFontSize=i}}let o=(n=this.context.rootFontSize)!=null?n:this.context.initialFontSize,a=t["line-height"];if(a&&!X(a.value)){let l=a.evaluate(this.context);if(l instanceof nt)this.context.rootLineHeight=l.num*o;else if(l instanceof P){let c=l.num;switch(l.unit){case"em":case"rem":c*=o;break;case"%":c*=o/100;break;case"lh":case"rlh":c*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let u=Ze[l.unit];u&&(c*=u)}}this.context.rootLineHeight=c}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let t=0;for(;!this.bodyReached&&(t+=5e3,this.styleUntil(t,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(t){if(t.style instanceof CSSStyleDeclaration){let e=t.getAttribute("style");if(e)return zg(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(t){if(t>=this.lastOffset)return;let e=this.context,n=this.xmldoc.getElementOffset(this.root);if(t<n){let o=this.getStyle(this.root,!1);let a=pe(o,"flow-into"),l=a?a.evaluate(e,"flow-into").toString():"body",c=this.encounteredFlowElement(l,o,this.root,n);this.boxStack.empty()&&this.boxStack.push(o,n,!0,c)}let s=this.xmldoc.getNodeByOffset(t),i=this.xmldoc.getNodeOffset(s,0,!1);if(!(i>=this.lastOffset))for(;;){if(s.nodeType!=1)i+=s.textContent.length;else{let a=s,l=this.getStyle(a,!1),c=l["flow-into"];if(c){let u=c.evaluate(e,"flow-into").toString();this.encounteredFlowElement(u,l,a,i)}i++}if(i>=this.lastOffset)break;let o=s.firstChild;if(o==null){for(;o=s.nextSibling,!o;)if(s=s.parentNode,s===this.root)return}s=o}}resetFlowChunkStream(t){this.flowListener=t;for(let e=0;e<this.flowChunks.length;e++)this.flowListener.encounteredFlowChunk(this.flowChunks[e],this.flows[this.flowChunks[e].flowName])}styleUntilFlowIsReached(t){this.flowToReach=t;let e=0;for(;!(this.flowToReach==null||(e+=5e3,this.styleUntil(e,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(t){if(!t)return;this.idToReach=t;let e=0;for(;!(!this.idToReach||(e+=5e3,this.styleUntil(e,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(t,e,n,s){let i=0,o=Number.POSITIVE_INFINITY,a=!1,l=!1,c=!1,u=e["flow-options"];if(u){let y=Ff(u.evaluate(this.context,"flow-options"));a=!!y.exclusive,l=!!y.static,c=!!y.last}let d=e["flow-linger"];d&&(o=nu(d.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let h=e["flow-priority"];h&&(i=nu(h.evaluate(this.context,"flow-priority"),0));let f=this.breakBeforeValues[s]||null,g=this.flows[t];if(!g){let y=this.boxStack.lastFlowName();g=this.flows[t]=new La(t,y)}let m=new Ra(t,n,s,i,o,a,l,c,f);return this.flowChunks.push(m),this.flowToReach==t&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,g),m}registerForcedBreakOffset(t,e,n){if(Me(t)){let i=this.flows[n].forcedBreakOffsets;(i.length===0||i[i.length-1]<e)&&i.push(e)}let s=this.breakBeforeValues[e];this.breakBeforeValues[e]=_e(s,t)}styleUntil(t,e){let n=-1,s;if(t<=this.lastOffset&&(s=this.offsetMap.slippedByFixed(t),n=s+e,n<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(n);if(this.last==null)return Number.POSITIVE_INFINITY;let i=this.context;for(;;){let o=this.last.firstChild;if(o==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let a=this.boxStack.pop(this.lastOffset),l=null;if(a.afterBox){let c=a.afterBox.getBreakValue("before");this.registerForcedBreakOffset(c,a.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(a):a.afterBox.offset,a.flowName),l=a.afterBox.getBreakValue("after")}l=_e(l,a.getBreakValue("after")),this.registerForcedBreakOffset(l,this.lastOffset,a.flowName)}if(o=this.last.nextSibling,o)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,t<this.lastOffset&&(n<0&&(s=this.offsetMap.slippedByFixed(t),n=s+e),n<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(n):Number.POSITIVE_INFINITY}if(this.last=o,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let a=this.last,l=this.getAttrStyle(a);this.primaryStack.push(this.primary),this.cascade.pushElement(this,a,l,this.lastOffset);let c=a.getAttribute("id")||a.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");c&&c===this.idToReach&&(this.idToReach=null),!this.bodyReached&&a.localName=="body"&&a.parentNode==this.root&&(this.postprocessTopStyle(l,!0),this.bodyReached=!0);let u,d=l["flow-into"];if(d){let f=d.evaluate(i,"flow-into").toString(),g=this.encounteredFlowElement(f,l,a,this.lastOffset);this.primary=!!this.primaryFlows[f],u=this.boxStack.push(l,this.lastOffset,a===this.root,g)}else u=this.boxStack.push(l,this.lastOffset,a===this.root),a===this.xmldoc.body&&(u.breakBefore=_e(u.flowChunk.breakBefore,u.breakBefore));let h=this.boxStack.nearestBlockStartOffset(u);if(h===0){let f=l.page,g=f&&!X(f.value)&&f.value.toString();g&&g.toLowerCase()!=="auto"&&(this.cascade.firstPageType=g)}if(this.registerForcedBreakOffset(u.breakBefore,h,u.flowName),u.beforeBox){let f=u.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(f,u.beforeBox.atBlockStart?h:u.offset,u.flowName)}if(this.primary&&u.displayValue()===b.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=l,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&h===0)continue;if(t<this.lastOffset&&(n<0&&(s=this.offsetMap.slippedByFixed(t),n=s+e),n<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(n)}}}getStyle(t,e){let n=this.xmldoc.getElementOffset(t),s=`e${n}`;return e&&(n=this.xmldoc.getNodeOffset(t,0,!0)),this.lastOffset<=n&&this.styleUntil(n,0),this.styleMap[s]}processContent(t,e,n){}},Am=["column-count","column-width","column-fill"];var Ss=class{constructor(t){this.validator=t;p(this,"success",null);p(this,"failure",null);p(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(t){this.code=2*t+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(t){this.code=2*t+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},jn=class{constructor(t,e){this.where=t;this.success=e;p(this,"what",-1)}};var ii=class r{constructor(){p(this,"nodes",[]);p(this,"connections",[]);p(this,"match",[]);p(this,"nomatch",[]);p(this,"error",[]);p(this,"emptyHead",!0)}connect(t,e){for(let n=0;n<t.length;n++)this.connections[t[n]].what=e;t.splice(0,t.length)}clone(){let t=new r;for(let e=0;e<this.nodes.length;e++){let n=this.nodes[e],s=new Ss(n.validator);s.code=n.code,t.nodes.push(s)}for(let e=0;e<this.connections.length;e++){let n=this.connections[e],s=new jn(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,e,n){let s=this.nodes.length,i=new Ss(Lm);n>=0?e?i.markAsStartAlternate(n):i.markAsEndAlternate(n):e?i.markAsStartGroup():i.markAsEndGroup(),this.nodes.push(i),this.connect(t,s);let o=new jn(s,!0),a=new jn(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 e=0;e<t.length;e++)this.addSpecialToArr(t[e],!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 e=new Ss(Lm);e.markAsStartAlternate(t),this.nodes.push(e);let n=new jn(0,!0),s=new jn(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 e=this.nodes.length;this.nodes.push(new Ss(t));let n=new jn(e,!0),s=new jn(e,!1);this.connect(this.match,e),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 ve}addGroup(t,e){if(t.nodes.length==0)return;let n=this.nodes.length;if(e==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let i=0;i<t.nodes.length;i++)this.nodes.push(t.nodes[i]);e==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let i=0;i<t.connections.length;i++){let o=t.connections[i];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let i=0;i<t.match.length;i++)this.match.push(t.match[i]+s);if(e==3&&this.connect(this.match,n),e==2||e==3)for(let i=0;i<t.nomatch.length;i++)this.match.push(t.nomatch[i]+s);else if(this.emptyHead){for(let i=0;i<t.nomatch.length;i++)this.nomatch.push(t.nomatch[i]+s);this.emptyHead=t.emptyHead}else for(let i=0;i<t.nomatch.length;i++)this.error.push(t.nomatch[i]+s);for(let i=0;i<t.error.length;i++)this.error.push(t.error[i]+s);t.nodes=null,t.connections=null}finish(t,e){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(e),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]}},ex=1,Im=2,Vm=4,si=8,Ul=16,Jp=32,Hl=64,Fm=128,hr=256,fr=512,eh=1024,Bm=2048,Om=4096,Dm=8192,zl=class extends St{constructor(){super()}validateForShorthand(t,e){let n=t[e].visit(this);return n?[n]:null}},ve=class r extends zl{constructor(e,n,s){super();this.allowed=e;this.idents=n;this.units=s}visitEmpty(e){return this.allowed&ex?e:null}visitSlash(e){return this.allowed&Bm?e:null}visitStr(e){return this.allowed&Im?e:null}visitIdent(e){let n=this.idents[e.name.toLowerCase()];return n||(this.allowed&Vm||this.allowed&Hl&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&fr)?e.unit=="%"&&this.allowed&eh?e:null:e.num<0&&!(this.allowed&hr)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&fr?e:null:e.num<=0&&!(this.allowed&hr)?null:this.allowed&Ul?e:null}visitInt(e){if(e.num==0)return this.allowed&fr?e:null;if(e.num<=0&&!(this.allowed&hr))return null;if(this.allowed&(Jp|Ul))return e;let n=this.idents[`${e.num}`];return n||null}visitHexColor(e){return this.allowed&Hl&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&Fm?e:null}visitURange(e){return this.allowed&Om?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.allowed&Hl&&CSS.supports("color",e.toString())||this.allowed&Dm&&CSS.supports("background-image",e.toString())||e.name==="calc"&&this.allowed&(si|Ul|Jp|hr|fr|eh)?e:null}visitExpr(e){return this.allowed&2046?e:null}combine(e){let n={},s={};for(let i in this.idents)n[i]=this.idents[i];for(let i in e.idents)n[i]=e.idents[i];for(let i in this.units)s[i]=this.units[i];for(let i in e.units)s[i]=e.units[i];return new r(this.allowed|e.allowed,n,s)}},Q={},Lm=new ve(0,Q,Q),gr=class extends zl{constructor(e){super();p(this,"successTerminal");p(this,"failureTerminal");p(this,"first");this.successTerminal=new Ss(null),this.failureTerminal=new Ss(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,n,s){let i=n?[]:e,o=this.first,a=s,l=null,c=null;for(;o!==this.successTerminal&&o!==this.failureTerminal;){if(a>=e.length){o=o.failure;continue}let u=e[a],d=u;if(o.isSpecial()){let h=!0;o.isStartGroup()?(l?l.push(c):l=[c],c=[]):o.isEndGroup()?l.length>0?c=l.pop():c=null:o.isEndAlternate()?c[o.getAlternate()]="taken":h=c[o.getAlternate()]==null,o=h?o.success:o.failure}else{if(a==0&&!n&&o.validator instanceof oi&&this instanceof oi){if(d=new W(e).visit(o.validator),d){a=e.length,o=o.success;continue}}else if(a==0&&!n&&o.validator instanceof mr&&this instanceof oi){if(d=new ge(e).visit(o.validator),d){a=e.length,o=o.success;continue}}else d=u.visit(o.validator);if(!d){o=o.failure;continue}if(d!==u&&e===i){i=[];for(let h=0;h<a;h++)i[h]=e[h]}e!==i&&(i[a-s]=d),a++,o=o.success}}return o===this.successTerminal&&(n?i.length>0:a==e.length)?i:null}validateSingle(e){let n=null,s=this.first;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(!e){s=s.failure;continue}if(s.isSpecial()){s=s.success;continue}if(n=e.visit(s.validator),!n){s=s.failure;continue}e=null,s=s.success}return s===this.successTerminal?n: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}},oi=class extends gr{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new W(e):null}visitCommaList(t){let e=this.first,n=!1;for(;e;){if(e.validator instanceof mr){n=!0;break}e=e.failure}if(n){let s=this.validateList(t.values,!1,0);return s===t.values?t:s?new ge(s):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},mr=class extends gr{constructor(t){super(t)}visitSpaceList(t){return this.validateSingle(t)}visitCommaList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new ge(e):null}validateForShorthand(t,e){let n=this.first,s;for(;n!==this.failureTerminal;){if(s=n.validator.validateForShorthand(t,e),s)return s;n=n.failure}return null}},th=class extends gr{constructor(e,n){super(n);this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new Xt(e.name,n):null}},Gl=class{tryParse(t,e,n){return e}success(t,e){}},Wl=class extends Gl{constructor(e,n){super();this.name=n;p(this,"validator");this.validator=e.validators[this.name]}tryParse(e,n,s){if(s.values[this.name])return n;let i=this.validator.validateForShorthand(e,n);if(i){let o=i.length,a=o>1?new W(i):i[0];return this.success(a,s),n+o}return n}success(e,n){n.values[this.name]=e}},nh=class extends Wl{constructor(e,n){super(e,n[0]);this.names=n}success(e,n){for(let s=0;s<this.names.length;s++)n.values[this.names[s]]=e}},sh=class extends Gl{constructor(e,n){super();this.nodes=e;this.slash=n}tryParse(e,n,s){let i=n;if(this.slash)if(e[n]==xi){if(++n==e.length)return i}else return i;let o=this.nodes[0].tryParse(e,n,s);if(o==n)return i;n=o;for(let a=1;a<this.nodes.length&&n<e.length&&(o=this.nodes[a].tryParse(e,n,s),o!=n);a++)n=o;return n}},Cr=class extends St{constructor(){super(...arguments);p(this,"syntax",null);p(this,"propList",null);p(this,"error",!1);p(this,"values",{});p(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Wl(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,n){this.syntax=e,this.propList=n}finish(e,n){var s,i;if(!this.error){for(let o of this.propList)n.simpleProperty(o,(i=(s=this.values[o])!=null?s:this.validatorSet.defaultValues[o])!=null?i:b.initial,e);return!0}return!1}propagateDefaultingValue(e,n,s){for(let i of this.propList)s.simpleProperty(i,e,n)}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)}},Es=class extends Cr{constructor(){super()}validateList(t){let e=0,n=0;for(;e<t.length;){let s=this.syntax[n].tryParse(t,e,this);if(s>e){e=s,n=0;continue}if(++n==this.syntax.length){this.error=!0;break}}return e}},Xl=class extends Cr{constructor(){super()}validateList(t){if(t.length>this.syntax.length||t.length==0)return this.error=!0,0;for(let e=0;e<this.syntax.length;e++){let n=e;for(;n>=t.length;)n=n==1?0:n-2;if(this.syntax[e].tryParse(t,n,this)!=n+1)return this.error=!0,0}return t.length}createSyntaxNode(){return new nh(this.validatorSet,this.propList)}},ih=class extends Cr{constructor(){super()}validateList(t){let e=t.length;for(let n=0;n<t.length;n++)if(t[n]===xi){e=n;break}if(e>this.syntax.length||t.length==0)return this.error=!0,0;for(let n=0;n<this.syntax.length;n++){let s=n;for(;s>=e;)s=s==1?0:s-2;let i;if(e+1<t.length)for(i=e+n+1;i>=t.length;)i=i-(i==e+2?1:2);else i=s;let o=[t[s],t[i]];if(this.syntax[n].tryParse(o,0,this)!=2)return this.error=!0,0}return t.length}},oh=class extends Es{constructor(){super()}mergeIn(t,e){var n,s;for(let i of this.propList){let o=(s=(n=e[i])!=null?n:this.validatorSet.defaultValues[i])!=null?s:b.initial,a=t[i];a||(a=[],t[i]=a),a.push(o)}}visitCommaList(t){let e={};for(let n=0;n<t.values.length;n++)if(this.values={},t.values[n]instanceof ge?this.error=!0:(t.values[n].visit(this),this.mergeIn(e,this.values),this.values["background-color"]&&n!=t.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let n in e)n=="background-color"?this.values[n]=e[n].pop():this.values[n]=new ge(e[n]);return null}},rh=class extends Es{constructor(){super()}init(t,e){super.init(t,e),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(t){let e=super.validateList(t),n=this.values["font-variant_css2"];n&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=n);let s=this.values["font-stretch_css3"];if(s&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=s),e+2>t.length)return this.error=!0,e;this.error=!1;let i=this.validatorSet.validators;if(!t[e].visit(i["font-size"]))return this.error=!0,e;if(this.values["font-size"]=t[e++],t[e]===xi){if(e++,e+2>t.length)return this.error=!0,e;if(!t[e].visit(i["line-height"]))return this.error=!0,e;this.values["line-height"]=t[e++]}let o=e==t.length-1?t[e]:new W(t.slice(e,t.length));return o.visit(i["font-family"])?(this.values["font-family"]=o,t.length):(this.error=!0,e)}visitCommaList(t){if(t.values[0].visit(this),this.error)return null;let e=[this.values["font-family"]];for(let s=1;s<t.values.length;s++)e.push(t.values[s]);let n=new ge(e);return n.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=n:this.error=!0,null}visitIdent(t){let e=this.validatorSet.systemFonts[t.name];if(e)for(let n in e)this.values[n]=e[n];else this.error=!0;return null}},ah=class extends Es{validateList(t){if(t.length===1&&t[0]instanceof j)switch(t[0].name.toLowerCase()){case"normal":t=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":t=[b.auto,b.auto];break;case"none":t=[k("no-autospace"),k("space-all")];break}return super.validateList(t)}},tx=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],lh=class extends Es{constructor(){super()}init(t,e){super.init(t,e);for(let n in this.validatorSet.validators)tx.includes(n)||this.propList.push(n)}validateList(t){return this.error=!0,0}},Rm={SIMPLE:Es,INSETS:Xl,INSETS_SLASH:ih,COMMA:oh,FONT:rh,TEXT_SPACING:ah,ALL:lh},nx=["initial-letter"],ch=class{constructor(){p(this,"validators",{});p(this,"prefixes",{});p(this,"defaultValues",{});p(this,"namedValidators",{});p(this,"systemFonts",{});p(this,"shorthands",{});p(this,"layoutProps",{});p(this,"backgroundProps",{})}addReplacement(t,e){let n;if(e.type==3)n=new P(e.num,e.text);else if(e.type==7)n=new yi(e.text);else if(e.type==1)n=k(e.text);else throw new Error("unexpected replacement");if(t.isPrimitive()){let i=t.nodes[0].validator.idents;for(let o in i)i[o]=n;return t}throw new Error("unexpected replacement")}newGroup(t,e){let n=new ii;if(t=="||"){for(let i=0;i<e.length;i++){let o=new ii;o.startClause(i),o.addGroup(e[i],1),o.endClause(i),n.addGroup(o,i==0?1:4)}let s=new ii;return s.startSpecialGroup(),s.addGroup(n,3),s.endSpecialGroup(),s}else{let s;switch(t){case" ":s=1;break;case"|":case"||":s=4;break;default:throw new Error("unexpected op")}for(let i=0;i<e.length;i++)n.addGroup(e[i],i==0?1:s);return n}}addCounts(t,e,n){let s=new ii;for(let i=0;i<e;i++)s.addGroup(t.clone(),1);if(n==Number.POSITIVE_INFINITY)s.addGroup(t,3);else for(let i=e;i<n;i++)s.addGroup(t.clone(),2);return s}primitive(t){let e=new ii;return e.addPrimitive(t),e}newFunc(t,e){let n;switch(t){case"COMMA":n=new mr(e);break;case"SPACE":n=new oi(e);break;default:n=new th(t.toLowerCase(),e);break}return this.primitive(n)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ve(Hl,Q,Q)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ve(Dm,Q,Q)),this.namedValidators.POS_INT=this.primitive(new ve(Jp,Q,Q)),this.namedValidators.POS_NUM=this.primitive(new ve(Ul,Q,Q)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ve(si,Q,{"%":U})),this.namedValidators.NEGATIVE=this.primitive(new ve(hr,Q,Q)),this.namedValidators.ZERO=this.primitive(new ve(fr,Q,Q)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ve(eh,Q,Q)),this.namedValidators.POS_LENGTH=this.primitive(new ve(si,Q,{em:U,ex:U,ch:U,rem:U,lh:U,rlh:U,vw:U,vh:U,vi:U,vb:U,vmin:U,vmax:U,pvw:U,pvh:U,pvi:U,pvb:U,pvmin:U,pvmax:U,cm:U,mm:U,in:U,px:U,pt:U,pc:U,q:U})),this.namedValidators.POS_ANGLE=this.primitive(new ve(si,Q,{deg:U,grad:U,rad:U,turn:U})),this.namedValidators.POS_TIME=this.primitive(new ve(si,Q,{s:U,ms:U})),this.namedValidators.FREQUENCY=this.primitive(new ve(si,Q,{Hz:U,kHz:U})),this.namedValidators.RESOLUTION=this.primitive(new ve(si,Q,{dpi:U,dpcm:U,dppx:U})),this.namedValidators.URI=this.primitive(new ve(Fm,Q,Q)),this.namedValidators.URANGE=this.primitive(new ve(Om,Q,Q)),this.namedValidators.IDENT=this.primitive(new ve(Vm,Q,Q)),this.namedValidators.STRING=this.primitive(new ve(Im,Q,Q)),this.namedValidators.SLASH=this.primitive(new ve(Bm,Q,Q));let t={"font-family":k("sans-serif")};this.systemFonts.caption=t,this.systemFonts.icon=t,this.systemFonts.menu=t,this.systemFonts["message-box"]=t,this.systemFonts["small-caption"]=t,this.systemFonts["status-bar"]=t}isBuiltIn(t){return!!t.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(t,e){let n=t.token();if(n.type==0)return null;let s={"":!0};if(n.type==14){do{if(t.consume(),n=t.token(),n.type!=1)throw new Error("Prefix name expected");s[n.text]=!0,t.consume(),n=t.token()}while(n.type==16);if(n.type!=15)throw new Error("']' expected");t.consume(),n=t.token()}if(n.type!=1)throw new Error("Property name expected");if(e==2?n.text=="SHORTHANDS":n.text=="DEFAULTS")return t.consume(),null;let i=n.text;if(t.consume(),e!=2){if(t.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(i)||(this.prefixes[i]=s)}else if(t.token().type!=18)throw new Error("':' expected");return i}parseValidators(t){for(;;){let e=this.readNameAndPrefixes(t,1);if(!e)return;let n=[],s=[],i="",o,a=!0,l=()=>{if(n.length==0)throw new Error("No values");return n.length==1?n[0]:this.newGroup(i,n)},c=d=>{if(a)throw new Error(`'${d}': unexpected`);if(i&&i!=d)throw new Error(`mixed operators: '${d}' and '${i}'`);i=d,a=!0},u=null;for(;!u;){t.consume();let d=t.token();switch(d.type){case 1:if(a||c(" "),this.isBuiltIn(d.text)){let h=this.namedValidators[d.text];if(!h)throw new Error(`'${d.text}' unexpected`);n.push(h.clone())}else{let h={};h[d.text.toLowerCase()]=k(d.text),n.push(this.primitive(new ve(0,h,Q)))}a=!1;break;case 5:{let h={};h[`${d.num}`]=new se(d.num),n.push(this.primitive(new ve(0,h,Q))),a=!1;break}case 34:c("|");break;case 25:c("||");break;case 14:a||c(" "),s.push({vals:n,op:i,b:"["}),i="",n=[],a=!0;break;case 6:a||c(" "),s.push({vals:n,op:i,b:"(",fn:d.text}),i="",n=[],a=!0;break;case 15:{o=l();let h=s.pop();if(h.b!="[")throw new Error("']' unexpected");n=h.vals,n.push(o),i=h.op,a=!1;break}case 11:{o=l();let h=s.pop();if(h.b!="(")throw new Error("')' unexpected");n=h.vals,n.push(this.newFunc(h.fn,o)),i=h.op,a=!1;break}case 18:if(a)throw new Error("':' unexpected");t.consume(),n.push(this.addReplacement(n.pop(),t.token()));break;case 22:if(a)throw new Error("'?' unexpected");n.push(this.addCounts(n.pop(),0,1));break;case 36:if(a)throw new Error("'*' unexpected");n.push(this.addCounts(n.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(a)throw new Error("'+' unexpected");n.push(this.addCounts(n.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(t.consume(),d=t.token(),d.type!=5)throw new Error("<int> expected");let h=d.num,f=h;if(t.consume(),d=t.token(),d.type==16){if(t.consume(),d=t.token(),d.type!=5)throw new Error("<int> expected");f=d.num,t.consume(),d=t.token()}if(d.type!=13)throw new Error("'}' expected");n.push(this.addCounts(n.pop(),h,f));break}case 17:if(u=l(),s.length>0)throw new Error(`unclosed '${s.pop().b}'`);break;default:throw new Error("unexpected token")}}t.consume(),this.isBuiltIn(e)?this.namedValidators[e]=u:u.isSimple()?this.validators[e]=u.nodes[0].validator:this.validators[e]=new oi(u)}}parseDefaults(t){for(;;){let e=this.readNameAndPrefixes(t,2);if(!e)return;let n=[];for(;;){t.consume();let s=t.token();if(s.type==17){t.consume();break}switch(s.type){case 1:n.push(k(s.text));break;case 4:n.push(new nt(s.num));break;case 5:n.push(new se(s.num));break;case 3:n.push(new P(s.num,s.text));break;default:throw new Error("unexpected token")}}this.defaultValues[e]=n.length>1?new W(n):n[0]}}parseShorthands(t){for(;;){let e=this.readNameAndPrefixes(t,3);if(!e)return;let n=t.nthToken(1),s;n.type==1&&Rm[n.text]?(s=new Rm[n.text],t.consume()):s=new Es,s.setOwner(this);let i=!1,o=[],a=!1,l=[],c=[];for(;!i;)switch(t.consume(),n=t.token(),n.type){case 1:if(this.validators[n.text])o.push(s.syntaxNodeForProperty(n.text)),n.text.includes("_")||c.push(n.text);else if(this.shorthands[n.text]instanceof Xl){let u=this.shorthands[n.text];o.push(u.createSyntaxNode()),c.push(...u.propList)}else throw new Error(`'${n.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(o.length>0||a)throw new Error("unexpected slash");a=!0;break;case 14:l.push({slash:a,syntax:o}),o=[],a=!1;break;case 15:{let u=new sh(o,a),d=l.pop();o=d.syntax,a=d.slash,o.push(u);break}case 17:i=!0,t.consume();break;default:throw new Error("unexpected token")}s.init(o,c),this.shorthands[e]=s}}parse(t){let e=new Ge(t,null);this.parseValidators(e),this.parseDefaults(e),this.parseShorthands(e),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(t){var n;let e={};for(let s of t){let i=this.shorthands[s],o=i?i.propList:[s];for(let a of o)e[a]=(n=this.defaultValues[a])!=null?n:b.initial}return e}validatePropertyAndHandleShorthand(t,e,n,s){let i=s.ruleType;if(It(t)||i==="font-face"||sx(e)){s.simpleProperty(t,e,n);return}if(i==="counter-style"){Em(t,e)?s.simpleProperty(t,e,n):s.invalidPropertyValue(t,e);return}let o="",a=t;t=t.toLowerCase();let l=t.match(/^-([a-z]+)-([-a-z0-9]+)$/);l&&(o=l[1],t=l[2]);let c=this.prefixes[t];if(!c||!c[o]){CSS.supports(a,e.toString())?s.simpleProperty(a,e,n):o&&!Bc.includes(`-${o}-`)||s.unknownProperty(a,e);return}else if(nx.includes(t)&&!Object.keys(c).some(d=>oo(d?`-${d}-`:"",t))){s.unknownProperty(a,e);return}let u=this.validators[t];if(u){let d=X(e)||e.isExpr()?e:e.visit(u);d?s.simpleProperty(t,d,n):!o&&CSS.supports(t,e.toString())?s.simpleProperty(t,e,n):s.invalidPropertyValue(a,e)}else{let d=this.shorthands[t].clone();X(e)?d.propagateDefaultingValue(e,n,s):(e.visit(d),d.finish(n,s)||s.invalidPropertyValue(a,e))}}};function dh(){let r=new ch;return r.initBuiltInValidators(),r.parse(vu),r}var uh=class extends St{constructor(){super(...arguments);p(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function sx(r){let t=new uh;return r.visit(t),t.varFound}var fE=`OTTO${new Date().valueOf()}`;function ph(r){return Object.keys(r).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function ox(r){let t=new et;for(let e of ph(r))t.append(`${e}:${r[e].toString()};`);return t.toString()}function _m(r,t){let e={};for(let n in r)e[n]=pe(r,n).evaluate(t,n);return e}var br=class{constructor(t){this.properties=t;p(this,"fontTraitKey");p(this,"src");p(this,"blobURLs",[]);p(this,"blobs",[]);p(this,"family");this.fontTraitKey=ox(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let e=this.properties["font-family"];this.family=e?e.stringValue():null}traitsEqual(t){return this.fontTraitKey==t.fontTraitKey}makeAtRule(t,e){let n=new et;n.append(`@font-face {
1794
+ }`;function Qs(o,t,e){let n=A("fetchFromURL"),s={method:e||"GET",mode:"cors"},i=n.suspend(),r={status:0,statusText:"",url:o,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(o,s).then(a=>{var l;return r.status=a.status,r.url=a.url,r.statusText=a.statusText,r.contentType=(l=a.headers.get("Content-Type"))==null?void 0:l.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(o)?(r.contentType="text/html",a.arrayBuffer().then(c=>new TextDecoder("Shift_JIS").decode(c))):(/^data:,(<|%3c)/i.test(o)&&(r.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?r.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?r.responseBlob=ed([a]):t==="json"?r.responseText=JSON.stringify(a):typeof a=="string"&&(r.responseText=a),i.schedule(r)}).catch(a=>{F.warn(a,`Error fetching ${o}`),i.schedule(r)}),n.result()}function ed(o,t){let e=t||"application/octet-stream";return new Blob(o,{type:e})}function dg(o){let t=A("readBlob"),e=new FileReader,n=t.suspend(e);return e.addEventListener("load",()=>{n.schedule(e.result)},!1),e.readAsArrayBuffer(o),t.result()}function pg(o){return URL.createObjectURL(o)}var Zs=class{constructor(t,e){this.parser=t;this.type=e;p(this,"resources",{});p(this,"fetchers",{})}load(t,e,n){t=Xt(t);let s=this.resources[t];return typeof s!="undefined"?T(s):this.fetch(t,e,n).get()}fetchInner(t,e,n){let s=A("fetch"),i=t.endsWith("?viv-toc-box");i&&(t=t.replace("?viv-toc-box",""));let r=te("user-agent.xml",Jt),a=!i&&t===r;return a&&(t=`data:application/xml,${encodeURIComponent(Yu)}`),Qs(t,this.type).then(l=>{if(l.status>=400&&e)throw new Error((n||`Failed to fetch required resource: ${t}`)+` (${l.status}${l.statusText?" "+l.statusText:""})`);i?(t+="?viv-toc-box",l.url+="?viv-toc-box"):a&&(l.url=t=r),this.parser(l,this).then(c=>{delete this.fetchers[t],this.resources[t]=c,s.finish(c)})}),s.result()}fetch(t,e,n){if(t=Xt(t),this.resources[t])return null;let i=this.fetchers[t];return i||(i=new xn(()=>this.fetchInner(t,e,n),`Fetch ${t}`),this.fetchers[t]=i,i.start()),i}get(t){return this.resources[Xt(t)]}delete(t){delete this.resources[Xt(t)]}};function Gb(o,t){let e=o.responseText;return T(e?Ni(e):null)}function hg(){return new Zs(Gb,"text")}function ps(o,t,e){let n=new xn(()=>{let s=A("loadElement"),i=s.suspend(o),r=!1,a=null,l=c=>{r||(r=!0,a!==null&&(clearTimeout(a),a=null),i.schedule(c?c.type:"timeout"))};if(o.addEventListener("load",l,!1),o.addEventListener("error",l,!1),o.addEventListener("abort",l,!1),o.namespaceURI=="http://www.w3.org/2000/svg")t&&o.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(o.localName==="script")a=setTimeout(l,3e3);else if(t)if(o.localName==="img"){let c=o;c.loading==="lazy"&&(c.loading="eager"),c.src=t,e&&(c.alt=e),c.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4)}else o.src=t,e&&(o.alt=e);return s.result()},`loadElement ${t||o.localName}`);return n.start(),n}var fg=0,Wb=16777216,td=33554432,Ha=50331648,za=67108864,Xb=83886080,$b=100663296;var Mr=class{constructor(t){this.scope=t;p(this,"flavor");this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(t,e){}startStylesheet(t){this.flavor=t}tagSelector(t,e){}classSelector(t){}pseudoclassSelector(t,e){}pseudoelementSelector(t,e){}idSelector(t){}attributeSelector(t,e,n,s){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(t){}startFootnoteRule(t){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(t){}startWhenRule(t){}startMediaRule(t){this.startWhenRule(t)}startFlowRule(t){}startPageTemplateRule(){}startPageMasterRule(t,e,n){}startPartitionRule(t,e,n){}startPartitionGroupRule(t,e,n){}startRuleBody(){}property(t,e,n){}endRule(){}startFuncWithSelector(t,e){}endFuncWithSelector(){}pushSelectorText(t){}getImportantSpecificity(){switch(this.flavor){case"UA":return fg;case"User":return $b;default:return Xb}}getBaseSpecificity(){switch(this.flavor){case"UA":return fg;case"User":return Wb;default:return td}}},Ma=class extends Mr{constructor(){super(null);p(this,"stack",[]);p(this,"tokenizer",null);p(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,n){this.slave.error(e,n)}errorMsg(e,n){var s;F.warn(e,(s=n==null?void 0:n.toString())!=null?s:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,n){this.slave.tagSelector(e,n)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,n){this.slave.pseudoclassSelector(e,n)}pseudoelementSelector(e,n){this.slave.pseudoelementSelector(e,n)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,n,s,i){this.slave.attributeSelector(e,n,s,i)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,n,s){this.slave.startPageMasterRule(e,n,s)}startPartitionRule(e,n,s){this.slave.startPartitionRule(e,n,s)}startPartitionGroupRule(e,n,s){this.slave.startPartitionGroupRule(e,n,s)}startRuleBody(){this.slave.startRuleBody()}property(e,n,s){this.slave.property(e,n,s)}endRule(){this.slave.endRule()}startFuncWithSelector(e,n){this.slave.startFuncWithSelector(e,n)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},_a=class extends Mr{constructor(e,n,s){super(e);this.owner=n;this.topLevel=s;p(this,"depth",0);n&&(this.flavor=n.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,n){var s;(s=this.owner)==null||s.errorMsg(e,n)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Sn=class extends _a{constructor(t,e,n){super(t,e,n)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.pushHandler(new _a(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(t){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(t,e,n){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(t,e){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(t,e,n){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ne=[],Ua=[],ue=[],ve=[],jt=[],dt=[],ke=[],Oe=[],ce=[],Ue=[],rt=[],Be=[],Pe=[];var $i=55,ji=56,Da=57;Ne[1]=28,Ne[36]=29,Ne[7]=29,Ne[9]=29,Ne[14]=29,Ne[18]=29,Ne[50]=29,Ne[20]=30,Ne[13]=27,Ne[0]=200,Ua[1]=46,Ua[0]=200,dt[1]=2,dt[36]=4,dt[7]=6,dt[9]=8,dt[14]=10,dt[18]=14,dt[50]=42,ue[37]=11,ue[23]=12,ue[35]=56,ue[1]=1,ue[36]=3,ue[7]=5,ue[9]=7,ue[14]=9,ue[12]=13,ue[18]=55,ue[50]=58,ue[16]=41,ve[37]=11,ve[23]=12,ve[35]=56,ve[1]=1,ve[36]=3,ve[7]=5,ve[9]=7,ve[14]=9,ve[18]=55,jt[1]=2,jt[36]=4,jt[7]=6,jt[9]=8,jt[18]=14,jt[50]=42,jt[14]=10,jt[12]=13,ke[1]=15,ke[7]=16,ke[4]=17,ke[5]=18,ke[3]=19,ke[2]=20,ke[8]=21,ke[27]=57,ke[16]=22,ke[19]=23,ke[6]=24,ke[11]=25,ke[17]=26,ke[13]=48,ke[31]=47,ke[23]=54,ke[0]=44,Oe[1]=31,Oe[4]=32,Oe[5]=32,Oe[3]=33,Oe[2]=34,Oe[10]=40,Oe[6]=38,Oe[31]=36,Oe[24]=36,Oe[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,Ue[0]=200,Ue[12]=50,Ue[13]=51,Ue[14]=50,Ue[15]=51,Ue[10]=50,Ue[11]=51,Ue[17]=53,rt[0]=200,rt[12]=50,rt[13]=52,rt[14]=50,rt[15]=51,rt[10]=50,rt[11]=51,rt[17]=53,Be[0]=200,Be[12]=50,Be[13]=51,Be[14]=50,Be[15]=51,Be[10]=50,Be[11]=51,Pe[11]=0,Pe[16]=0,Pe[22]=1,Pe[18]=1,Pe[26]=2,Pe[25]=2,Pe[38]=3,Pe[37]=3,Pe[48]=3,Pe[47]=3,Pe[39]=3,Pe[49]=3,Pe[41]=3,Pe[23]=4,Pe[24]=4,Pe[36]=5,Pe[19]=5,Pe[21]=5,Pe[0]=6,Pe[$i]=2,Pe[ji]=2;var hs=class{constructor(t,e,n,s){this.actions=t;this.tokenizer=e;this.handler=n;this.baseURL=s;p(this,"valStack",[]);p(this,"namespacePrefixToURI",{});p(this,"defaultNamespaceURI",null);p(this,"propName",null);p(this,"propImportant",!1);p(this,"exprContext");p(this,"result",null);p(this,"importReady",!1);p(this,"importURL",null);p(this,"importCondition",null);p(this,"errorBrackets",[]);p(this,"ruleStack",[]);p(this,"regionRule",!1);p(this,"pageRule",!1);p(this,"inStyleDeclaration",!1);this.exprContext=2}extractVals(t,e){let n=[],s=this.valStack;for(;e<s.length&&(n.push(s[e++]),e!==s.length);){if(s[e++]!==t)throw new Error("Unexpected state");e===s.length&&n.push(H)}return n}valStackReduce(t,e){let n=this.valStack,s=n.length,i=0,r;do if(r=n[--s],t===")"&&r instanceof Cn){if(r.text===")")i++;else if(r.text==="("){if(i===0)return null;i--}}while(typeof r!="undefined"&&typeof r!="string");let a=n.length-(s+1);if(a>1&&n.splice(s+1,a,new G(n.slice(s+1,n.length))),t==",")return null;s++;do r=n[--s];while(typeof r!="undefined"&&(typeof r!="string"||r==","));if(a=n.length-(s+1),r=="("){t!=")"&&e.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",e),this.actions=rt);let c=new vt(n[s-1],this.extractVals(",",s+1));if(n.splice(s-1,a+2,c),c.name==="var"){let u=c.values[0]instanceof Y&&c.values[0].name;(!Nt(u)||u===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${c.toString()}`,e),this.actions=rt)}return c}if(t!=";"||s>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=rt,null;if(a>1)return new me(this.extractVals(",",s+1));let l=n[0];return l instanceof Le?l:l?new Cn(l.toString()):H}exprError(t,e){this.actions=this.propName?rt:Ue,F.warn(t,e.toString())}exprStackReduce(t,e){let n=this.valStack,s=this.handler,i=n.pop(),r;for(;;){let a=n.pop();if(t==11){let l=[i];for(;a==16;)l.unshift(n.pop()),a=n.pop();if(typeof a=="string"){if(a=="{"){for(;l.length>=2;){let c=l.shift(),u=l.shift(),d=new Ca(s.getScope(),c,u);l.unshift(d)}return n.push(new D(l[0])),!0}else if(a=="("){let c=n.pop(),u=n.pop();i=new Fn(s.getScope(),Lr(u,c),l),t=0;continue}}if(a==10){i.isMediaName()&&(i=new Ar(s.getScope(),i,null)),t=0;continue}}else if(typeof a=="string"){n.push(a);break}if(a<0)if(a==-31)i=new Ft(s.getScope(),i);else if(a==-24)i=new mn(s.getScope(),i);else if(a==-Da)i=new ga(s.getScope(),i);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if(Pe[t]>Pe[a]){n.push(a);break}switch(r=n.pop(),a){case 26:i=new Pi(s.getScope(),r,i);break;case $i:i=new ma(s.getScope(),r,i);break;case ji:i=new ba(s.getScope(),r,i);break;case 25:i=new ki(s.getScope(),r,i);break;case 38:i=new ya(s.getScope(),r,i);break;case 37:i=new Sa(s.getScope(),r,i);break;case 48:i=new xa(s.getScope(),r,i);break;case 47:i=new zs(s.getScope(),r,i);break;case 39:case 49:i=new is(s.getScope(),r,i);break;case 41:i=new Ea(s.getScope(),r,i);break;case 23:i=new Tr(s.getScope(),r,i);break;case 24:i=new wr(s.getScope(),r,i);break;case 36:i=new Gs(s.getScope(),r,i);break;case 19:i=new Pr(s.getScope(),r,i);break;case 21:i=new Ai(s.getScope(),r,i);break;case 18:if(n.length>1)switch(n[n.length-1]){case 22:n.pop(),i=new va(s.getScope(),n.pop(),r,i);break;case 10:if(r.isMediaName())i=new Ar(s.getScope(),r,i);else return this.exprError("E_CSS_MEDIA_TEST",e),!1;break}else return this.exprError("E_CSS_EXPR_COND",e),!1;break;case 22:if(t!=18)return this.exprError("E_CSS_EXPR_COND",e),!1;case 10:return n.push(r),n.push(a),n.push(i),!1;default:return this.exprError("F_UNEXPECTED_STATE",e),!1}}}return n.push(i),!1}readSupportsTest(t){let e=t.type===6,n=this.tokenizer,s,i;if(e)i=t.text,s=t.position+i.length+1;else if(t.type===10){let h=n.nthToken(1),f=n.nthToken(2);if(h.type===1&&f.type===18)n.consume(),n.consume(),i=h.text,s=f.position+1;else{if(h.type===10||h.type===6||h.type===1&&h.text.toLowerCase()==="not"&&(f.type===10||f.type===6))return null;s=t.position+1}}else return null;let r=0,a,l=0;for(;r>=0;)switch(n.consume(),a=n.token(),a.type){case 11:r--;break;case 10:case 6:r++;break;case 16:r===0&&l++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",a),null}n.consume();let c=a.position,u=e&&i==="selector"&&l>0?"":n.input.substring(s,c).trim();return new Na(this.handler.getScope(),i,u,e)}readPseudoParams(){let t=[];for(;;){let e=this.tokenizer.token();switch(e.type){case 1:t.push(e.text);break;case 23:t.push("+");break;case 4:case 5:t.push(e.num);break;default:return t}this.tokenizer.consume()}}readNthPseudoParams(){let t=!1,e=this.tokenizer.token();if(e.type===23)t=!0,this.tokenizer.consume(),e=this.tokenizer.token();else if(e.type===1&&(e.text==="even"||e.text==="odd"))return this.tokenizer.consume(),[2,e.text==="odd"?1:0];switch(e.type){case 3:if(t&&e.num<0)return null;case 1:if(t&&e.text.charAt(0)==="-")return null;if(e.text==="n"||e.text==="-n"){if(t&&e.precededBySpace)return null;let n=e.text==="-n"?-1:1;e.type===3&&(n=e.num);let s=0;this.tokenizer.consume(),e=this.tokenizer.token();let i=e.type===24,r=e.type===23||i;if(r&&(this.tokenizer.consume(),e=this.tokenizer.token()),e.type===5){if(s=e.num,1/s===-1/0){if(s=0,r)return null}else if(s<0){if(r)return null}else if(s>=0&&!r)return null;this.tokenizer.consume()}else if(r)return null;return[n,i&&s>0?-s:s]}else if(e.text==="n-"||e.text==="-n-"){if(t&&e.precededBySpace)return null;let n=e.text==="-n-"?-1:1;if(e.type===3&&(n=e.num),this.tokenizer.consume(),e=this.tokenizer.token(),e.type===5)return e.num<0||1/e.num===-1/0?null:(this.tokenizer.consume(),[n,e.num])}else{let n=e.text.match(/^n(-[0-9]+)$/);if(n)return t&&e.precededBySpace?null:(this.tokenizer.consume(),[e.type===3?e.num:1,parseInt(n[1],10)]);if(n=e.text.match(/^-n(-[0-9]+)$/),n)return this.tokenizer.consume(),[-1,parseInt(n[1],10)]}return null;case 5:return t&&(e.precededBySpace||e.num<0)?null:(this.tokenizer.consume(),[0,e.num])}return null}makeCondition(t,e){let n=this.handler.getScope();if(!n)return null;if(e=e||n._true,t){let s=t.split(/\s+/);for(let i of s)switch(i){case"vertical":e=ut(n,e,new Ft(n,new re(n,"pref-horizontal")));break;case"horizontal":e=ut(n,e,new re(n,"pref-horizontal"));break;case"day":e=ut(n,e,new Ft(n,new re(n,"pref-night-mode")));break;case"night":e=ut(n,e,new re(n,"pref-night-mode"));break;default:e=n._false}}return e===n._true?null:new D(e)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(t,e,n,s,i,r){let a=this.handler,l=this.tokenizer,c=this.valStack,u,d,h,f,g,m,y,S=null;for(n&&(this.inStyleDeclaration=!0),s&&(this.exprContext=2,this.valStack.push("{"));t>0;--t){if(u=l.token(),i&&S===null&&(S=u.position-1,l.input[S]==="("&&S++),this.actions===ke&&this.errorBrackets.length>0&&(u.type===this.errorBrackets[this.errorBrackets.length-1]||u.type===17||u.type===31)){if(u.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),u.type===11&&this.valStackReduce(")",u))){l.consume();continue}c.push(new Cn(u.toString())),l.consume();continue}switch(this.actions[u.type]){case 28:if(!this.inStyleDeclaration||l.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(a.error("E_CSS_COLON_EXPECTED",l.nthToken(1)),this.actions=rt):(this.actions=dt,a.startSelectorRule());continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=ke,c.splice(0,c.length);continue;case 46:if(l.nthToken(1).type!=18){this.actions=rt,a.error("E_CSS_COLON_EXPECTED",l.nthToken(1));continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=ke,c.splice(0,c.length);continue;case 29:this.actions=dt,a.startSelectorRule();continue;case 1:if(!u.precededBySpace){this.actions=Be,a.error("E_CSS_SPACE_EXPECTED",u);continue}a.descendantSelector();case 2:if(l.nthToken(1).type==34)if(l.consume(),l.consume(),h=this.namespacePrefixToURI[u.text],h!=null)switch(u=l.token(),u.type){case 1:a.tagSelector(h,u.text),i?this.actions=ve:this.actions=ue,l.consume();break;case 36:a.tagSelector(h,null),i?this.actions=ve:this.actions=ue,l.consume();break;default:this.actions=Ue,a.error("E_CSS_NAMESPACE",u)}else this.actions=Ue,a.error("E_CSS_UNDECLARED_PREFIX",u);else a.tagSelector(this.defaultNamespaceURI,u.text),i?this.actions=ve:this.actions=ue,l.consume();continue;case 3:if(!u.precededBySpace){this.actions=Be,a.error("E_CSS_SPACE_EXPECTED",u);continue}a.descendantSelector();case 4:if(l.nthToken(1).type==34)switch(l.consume(),l.consume(),u=l.token(),u.type){case 1:a.tagSelector(null,u.text),i?this.actions=ve:this.actions=ue,l.consume();break;case 36:a.tagSelector(null,null),i?this.actions=ve:this.actions=ue,l.consume();break;default:this.actions=Ue,a.error("E_CSS_NAMESPACE",u)}else a.tagSelector(this.defaultNamespaceURI,null),i?this.actions=ve:this.actions=ue,l.consume();continue;case 5:u.precededBySpace&&a.descendantSelector();case 6:if(!u.text){a.error("E_CSS_SYNTAX",u),l.consume();continue}a.idSelector(u.text),i?this.actions=ve:this.actions=ue,l.consume();continue;case 7:u.precededBySpace&&a.descendantSelector();case 8:a.classSelector(u.text),i?this.actions=ve:this.actions=ue,l.consume();continue;case 55:u.precededBySpace&&a.descendantSelector();case 14:l.consume(),u=l.token();e:switch(u.type){case 1:a.pseudoclassSelector(u.text,null),l.consume(),i?this.actions=ve:this.actions=ue;continue;case 6:switch(f=u.text,l.consume(),f){case"is":case"not":case"where":case"has":this.actions=dt,a.startFuncWithSelector(f),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,f==="has")?this.actions=ue:this.actions=Be;continue;case"lang":case"href-epub-type":if(u=l.token(),u.type===1){y=[u.text],l.consume(),f==="href-epub-type"&&l.token().type===16&&(l.consume(),u=l.token(),u.type===1&&(y.push(u.text),l.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(y=this.readNthPseudoParams(),y)if(f==="nth-child"||f==="nth-last-child"){if(d=l.nthToken(0),d.type===1&&d.text==="of"){l.consume(),this.actions=dt,a.startFuncWithSelector(f,y),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?i?this.actions=ve:this.actions=ue:this.actions=Be;continue}break}else if(f==="nth"){if(d=l.nthToken(0),d.type===1&&d.text==="of")if(l.consume(),d=l.token(),d.type===1)y.push(d.text),l.consume();else break e;break}else break;else break e;default:y=this.readPseudoParams()}if(u=l.token(),u.type==11){a.pseudoclassSelector(f,y),l.consume(),i?this.actions=ve:this.actions=ue;continue}break}a.error("E_CSS_PSEUDOCLASS_SYNTAX",u),this.actions=Ue;continue;case 58:u.precededBySpace&&a.descendantSelector();case 42:switch(l.consume(),u=l.token(),u.type){case 1:a.pseudoelementSelector(u.text,null),i?this.actions=ve:this.actions=ue,l.consume();continue;case 6:if(f=u.text,l.consume(),f=="nth-fragment"){if(y=this.readNthPseudoParams(),y===null)break}else y=this.readPseudoParams();if(u=l.token(),u.type==11){a.pseudoelementSelector(f,y),i?this.actions=ve:this.actions=ue,l.consume();continue}break}a.error("E_CSS_PSEUDOELEM_SYNTAX",u),this.actions=Ue;continue;case 9:u.precededBySpace&&a.descendantSelector();case 10:if(l.consume(),u=l.token(),u.type==1)f=u.text,l.consume();else if(u.type==36)f=null,l.consume();else if(u.type==34)f="";else{this.actions=Be,a.error("E_CSS_ATTR",u),l.consume();continue}if(u=l.token(),u.type==34){if(h=f&&this.namespacePrefixToURI[f],h===void 0){this.actions=Be,a.error("E_CSS_UNDECLARED_PREFIX",u),l.consume();continue}if(l.consume(),u=l.token(),u.type!=1){this.actions=Be,a.error("E_CSS_ATTR_NAME_EXPECTED",u);continue}f=u.text,l.consume(),u=l.token()}else h="";switch(u.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:g=u.type,l.consume(),u=l.token();break;case 15:a.attributeSelector(h,f,0,null),i?this.actions=ve:this.actions=ue,l.consume();continue;default:this.actions=Be,a.error("E_CSS_ATTR_OP_EXPECTED",u);continue}switch(u.type){case 1:case 2:a.attributeSelector(h,f,g,u.text),l.consume(),u=l.token();break;default:this.actions=Be,a.error("E_CSS_ATTR_VAL_EXPECTED",u);continue}if(u.type!=15){this.actions=Be,a.error("E_CSS_ATTR",u);continue}i?this.actions=ve:this.actions=ue,l.consume();continue;case 11:a.childSelector(),this.actions=jt,l.consume();continue;case 12:a.adjacentSiblingSelector(),this.actions=jt,l.consume();continue;case 56:a.followingSiblingSelector(),this.actions=jt,l.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),a.startRuleBody(),this.actions=Ne,l.consume();continue;case 41:a.nextSelector(),this.actions=dt,l.consume();continue;case 15:c.push(k(u.text)),l.consume();continue;case 16:g=parseInt(u.text,16),c.push(new Ii(u.text)),l.consume();continue;case 17:c.push(new Re(u.num)),l.consume();continue;case 18:c.push(new se(u.num)),l.consume();continue;case 19:c.push(new P(u.num,u.text)),l.consume();continue;case 20:c.push(new M(u.text)),l.consume();continue;case 21:c.push(new ge(te(u.text,this.baseURL))),l.consume();continue;case 57:c.push(new Ir(u.text)),l.consume();continue;case 22:this.valStackReduce(",",u),c.push(","),l.consume();continue;case 23:c.push(Bn),l.consume();continue;case 24:f=u.text.toLowerCase(),f=="-epubx-expr"||f=="env"?(this.actions=Oe,this.exprContext=0,c.push("{")):(c.push(f),c.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),l.consume();continue;case 25:this.valStackReduce(")",u),l.consume();continue;case 47:if(l.consume(),u=l.token(),d=l.nthToken(1),u.type==1&&u.text.toLowerCase()=="important"&&(d.type==17||d.type==0||d.type==13)){l.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",u);continue;case 54:switch(d=l.nthToken(1),d.type){case 4:case 3:case 5:if(!d.precededBySpace){l.consume();continue}}c.push(new Cn("+")),l.consume();continue;case 26:l.consume();case 48:m=this.valStackReduce(";",u),m&&this.propName&&a.property(this.propName,m,this.propImportant),this.actions=n?Ua:Ne;continue;case 44:for(l.consume();c.length>0;){let C=c.length;if(m=this.valStackReduce(";",u),!m||c.length===C)break}return e?(this.result=m,!0):(this.propName&&m&&a.property(this.propName,m,this.propImportant),!0);case 31:if(d=l.nthToken(1),d.type==9)l.nthToken(2).type==10&&!l.nthToken(2).precededBySpace?(c.push(u.text,d.text,"("),l.consume()):(c.push(new re(a.getScope(),Lr(u.text,d.text))),this.actions=ce),l.consume();else{if(this.exprContext==2||this.exprContext==3)u.text.toLowerCase()=="not"?(l.consume(),c.push(new kr(a.getScope(),!0,d.text))):(u.text.toLowerCase()=="only"&&(l.consume(),u=d),c.push(new kr(a.getScope(),!1,u.text)));else if(this.exprContext===4&&u.text.toLowerCase()==="not"&&c[c.length-1]!==$i&&c[c.length-1]!==ji&&(d.type===10||d.type===6)){c.push(-Da),l.consume();continue}else c.push(new re(a.getScope(),u.text));this.actions=ce}l.consume();continue;case 38:if(this.exprContext===4){c.push(this.readSupportsTest(u)),this.actions=ce;continue}c.push(null,u.text,"("),l.consume();continue;case 32:c.push(new he(a.getScope(),u.num)),l.consume(),this.actions=ce;continue;case 33:f=u.text,f=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?f="vh":f="vw"),c.push(new tn(a.getScope(),u.num,f)),l.consume(),this.actions=ce;continue;case 34:c.push(new he(a.getScope(),u.text)),l.consume(),this.actions=ce;continue;case 35:l.consume(),u=l.token(),u.type!=5||u.precededBySpace?this.exprError("E_CSS_SYNTAX",u):(c.push(new Li(a.getScope(),u.num)),l.consume(),this.actions=ce);continue;case 36:c.push(-u.type),l.consume();continue;case 37:this.actions=Oe,this.exprStackReduce(u.type,u),c.push(u.type),l.consume();continue;case 45:u.text.toLowerCase()==="and"&&c[c.length-2]!==ji&&c[c.length-2]!==-Da?(this.actions=Oe,this.exprStackReduce($i,u),c.push($i),l.consume()):u.text.toLowerCase()==="or"&&c[c.length-2]!==$i&&c[c.length-2]!==-Da?(this.actions=Oe,this.exprStackReduce(ji,u),c.push(ji),l.consume()):this.exprError("E_CSS_SYNTAX",u);continue;case 39:this.exprStackReduce(u.type,u)&&(this.actions=ke),l.consume();continue;case 43:this.exprStackReduce(11,u)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",u):(this.exprContext==1?a.startWhenRule(c.pop()):a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Ne)),l.consume();continue;case 49:if(this.exprStackReduce(11,u))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",u),this.actions=Ne,l.consume(),!1):(this.importCondition=c.pop(),this.importReady=!0,this.actions=Ne,l.consume(),!1);l.consume();continue;case 40:if(this.exprContext===4){let C=this.readSupportsTest(u);if(C){c.push(C),this.actions=ce;continue}}c.push(u.type),l.consume();continue;case 27:if(this.actions=Ne,l.consume(),a.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(f=u.text.toLowerCase(),f){case"import":if(l.consume(),u=l.token(),u.type==2||u.type==8){if(this.importURL=u.text,l.consume(),u=l.token(),u.type==17||u.type==0)return this.importReady=!0,l.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Oe,c.push("{");continue}a.error("E_CSS_IMPORT_SYNTAX",u),this.actions=Ue;continue;case"namespace":switch(l.consume(),u=l.token(),u.type){case 1:if(f=u.text,l.consume(),u=l.token(),(u.type==2||u.type==8)&&l.nthToken(1).type==17){this.namespacePrefixToURI[f]=u.text,l.consume(),l.consume();continue}break;case 2:case 8:if(l.nthToken(1).type==17){this.defaultNamespaceURI=u.text,l.consume(),l.consume();continue}break}a.error("E_CSS_NAMESPACE_SYNTAX",u),this.actions=Ue;continue;case"charset":if(l.consume(),u=l.token(),u.type==2&&l.nthToken(1).type==17){f=u.text.toLowerCase(),f!="utf-8"&&f!="utf-16"&&a.error(`E_CSS_UNEXPECTED_CHARSET ${f}`,u),l.consume(),l.consume();continue}a.error("E_CSS_CHARSET_SYNTAX",u),this.actions=Ue;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(l.nthToken(1).type==12){switch(l.consume(),l.consume(),f){case"font-face":a.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":a.startPageTemplateRule();break;case"-epubx-define":a.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":a.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(f),a.startRuleBody();continue}break;case"-adapt-footnote-area":switch(l.consume(),u=l.token(),u.type){case 12:l.consume(),a.startFootnoteRule(null),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(l.consume(),u=l.token(),u.type==1&&l.nthToken(1).type==12){f=u.text,l.consume(),l.consume(),a.startFootnoteRule(f),this.ruleStack.push("-adapt-footnote-area"),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":l.consume(),a.startRegionRule(),this.regionRule=!0,this.actions=dt;continue;case"page":l.consume(),a.startPageRule(),this.pageRule=!0,this.actions=jt;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(l.consume(),u=l.token(),u.type==12){l.consume(),a.startPageMarginBoxRule(f),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":l.consume(),this.propName=null,this.exprContext=1,this.actions=Oe,c.push("{");continue;case"media":l.consume(),this.propName=null,this.exprContext=2,this.actions=Oe,c.push("{");continue;case"supports":l.consume(),this.propName=null,this.exprContext=4,this.actions=Oe,c.push("{");continue;case"-epubx-flow":if(l.nthToken(1).type==1&&l.nthToken(2).type==12){a.startFlowRule(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(l.nthToken(1).type==1&&l.nthToken(2).type==12){a.startCounterStyleRule(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{l.consume(),u=l.token();let C=null,x=null,v=[];for(u.type==1&&(C=u.text,l.consume(),u=l.token()),u.type==18&&l.nthToken(1).type==1&&(x=l.nthToken(1).text,l.consume(),l.consume(),u=l.token());u.type==6&&u.text.toLowerCase()=="class"&&l.nthToken(1).type==1&&l.nthToken(2).type==11;)v.push(l.nthToken(1).text),l.consume(),l.consume(),l.consume(),u=l.token();if(u.type==12){switch(l.consume(),f){case"-epubx-page-master":a.startPageMasterRule(C,x,v);break;case"-epubx-partition":a.startPartitionRule(C,x,v);break;case"-epubx-partition-group":a.startPartitionGroupRule(C,x,v);break}this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":a.error(`E_CSS_UNEXPECTED_AT${f}`,u),this.actions=Be;continue;default:a.error(`E_CSS_AT_UNKNOWN ${f}`,u),this.actions=Ue;continue}a.error(`E_CSS_AT_SYNTAX ${f}`,u),this.actions=Ue;continue;case 50:this.errorBrackets.push(u.type+1),l.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ne;continue}case 51:if(i&&this.errorBrackets.length==0&&u.type==11)return l.consume(),a.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==u.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&u.type==13&&(this.actions=Ne),l.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ne),l.consume();continue;case 200:return!0;default:if(s)return this.exprStackReduce(11,u)?(this.result=c.pop(),!0):!1;if(i){switch(u.type){case 16:case 11:if(this.actions===dt)a.error("E_CSS_SYNTAX",u);else{let C=l.input.substring(S,u.position);a.pushSelectorText(C),S=u.position+1}if(u.type===16){a.nextSelector(),this.actions=dt,l.consume();continue}else return a.endFuncWithSelector(),l.consume(),!0;case 37:case 23:case 35:if(r){this.actions=ue;continue}break;case 12:case 14:case 10:this.errorBrackets.push(u.type+1);break}a.error("E_CSS_SYNTAX",u),l.consume(),this.actions=Be;continue}if(this.actions!==Ue&&this.actions!==Be&&this.actions!==rt){if(u.type==54)a.error("E_CSS_SYNTAX",u);else if(this.actions===ke){switch(u.type){case 10:case 12:case 14:this.errorBrackets.push(u.type+1);break}c.push(new Cn(u.toString())),l.consume();continue}else if(u.type===12&&this.actions==Oe&&c.length>0){a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Ne,l.consume();continue}else{if(u.type===17&&this.actions==Oe)return this.actions=Ne,l.consume(),!1;a.error("E_CSS_SYNTAX",u)}this.isInsidePropertyOnlyRule()?this.actions=rt:this.actions=Be;continue}l.consume();continue}}return!1}},_r=class extends Mr{constructor(e){super(null);this.scope=e}error(e,n){F.warn(e,n.toString())}getScope(){return this.scope}};function jb(o,t,e,n,s){let i=A("parseStylesheet"),r=new hs(Ne,o,t,e),a=null;return s&&(a=Yb(new Xe(s,t),t,e)),a=r.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),i.loop(()=>{for(;!r.runParser(100,!1,!1,!1,!1);){if(r.importReady){let c=te(r.importURL,e);r.importCondition&&(t.startMediaRule(r.importCondition),t.startRuleBody());let u=A("parseStylesheet.import");return nd(c,t,null,null).then(()=>{r.importCondition&&t.endRule(),r.importReady=!1,r.importURL=null,r.importCondition=null,u.finish(!0)}),u.result()}let l=i.timeSlice();if(l.isPending)return l}return T(!1)}).then(()=>{a&&t.endRule(),i.finish(!0)}),i.result()}function Ga(o,t,e,n,s){return Dn("parseStylesheetFromText",i=>{let r=new Xe(o,t);jb(r,t,e,n,s).thenFinish(i)},(i,r)=>{F.warn(r,`Failed to parse stylesheet text: ${o}`),i.finish(!1)})}function nd(o,t,e,n){return Dn("parseStylesheetFromURL",s=>{Qs(o).then(i=>{i.responseText?Ga(i.responseText,t,o,e,n).then(r=>{r||F.warn(`Failed to parse stylesheet from ${o}`),s.finish(!0)}):s.finish(!0)})},(s,i)=>{F.warn(i,"Exception while fetching and parsing:",o),s.finish(!0)})}function En(o,t,e){let n=new hs(ke,t,new _r(o),e);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function mg(o,t,e){new hs(Ua,o,t,e).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Yb(o,t,e){let n=new hs(Oe,o,t,e);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Kb={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function qb(o){return!!Kb[o]}function Cg(o,t,e){if(t instanceof ne&&t.str==="viv-leader")return new D(t);let n=t.evaluate(o);switch(typeof n){case"number":return qb(e)?n==Math.round(n)?new se(n):new Re(n):new P(n,"px");case"string":return n?En(t.scope,new Xe(n,null),""):H;case"boolean":return n?b._true:b._false;case"undefined":return H}throw new Error("E_UNEXPECTED")}function bg(o,t){let e={};return Object.keys(o).forEach(n=>{let s=e[n]={},i=o[n];Object.keys(i).forEach(r=>{s[r]=i[r].map(a=>{let l=t?a.logical:a.physical,c=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${l}(-?)`),to:`$1${c}$2`}})})}),e}function yg(o,t,e,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let i=s[e||"ltr"];if(!i)throw new Error(`unknown direction: ${e}`);for(let r of i){let a=o.replace(r.regexp,r.to);if(a!==o)return a}return o}var xg={"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"}]}},Zb=bg(xg,!0);function sd(o,t,e){return yg(o,t,e||null,Zb)}var Qb=bg(xg,!1);function id(o,t,e){return yg(o,t,e||null,Qb)}var Jb={"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 Sg(o,t){let e=Jb[t];if(!e)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<e.length;n++)if(e[n].physical===o)return e[n].logical;return o}function Yi(o,t,e){var h;let n=t,s={width:n.style.width,height:n.style.height};function i(f){return o.getElementComputedStyle(t).getPropertyValue(f)}let a=i("writing-mode")!=="horizontal-tb",l=a?"height":"width",c=a?"width":"height";function u(f,g){n.style[f]=g;let m=i(f);return n.style[f]=s[f],m}let d={};for(let f of e){let g;switch(f){case"max-content inline size":g=u(l,"max-content");break;case"min-content inline size":g=u(l,"min-content");break;case"fit-content inline size":g=u(l,"fit-content");break;case"max-content block size":g=u(c,"max-content");break;case"min-content block size":g=u(c,"min-content");break;case"fit-content block size":g=u(c,"fit-content");break;case"max-content width":g=u("width","max-content");break;case"max-content height":g=u("height","max-content");break;case"min-content width":g=u("width","min-content");break;case"min-content height":g=u("height","min-content");break;case"fit-content width":g=u("width","fit-content");break;case"fit-content height":g=u("height","fit-content");break}g==="0px"&&t.childNodes.length===1&&((h=t.firstElementChild)==null?void 0:h.localName)==="img"&&!t.firstElementChild.complete&&(g="1px"),d[f]=parseFloat(g)}return d}function ti(o){var t,e;return((t=o==null?void 0:o.style)==null?void 0:t["box-decoration-break"])==="clone"||((e=o==null?void 0:o.style)==null?void 0:e["-webkit-box-decoration-break"])==="clone"}function od(o){let t=o.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function ad(o,t){o.setAttribute("data-viv-box-break",t.join(" "))}function Tt(o,t){let e=od(o);e.includes(t)||(e.push(t),ad(o,e))}function ty(o){let t=o.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function ny(o,t){o.setAttribute("data-viv-margin-discard",t.join(" "))}function Wa(o,t){let e=ty(o);e.includes(t)||(e.push(t),ny(o,e))}function sy(o){let t=o.name,e=o.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:e===b.always?b.page:e,important:o.important};default:return o}}var Xa={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function He(o){return!!Xa[o]}var iy={left:!0,right:!0,recto:!0,verso:!0};function fs(o){return!!iy[o]}var ry={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ki(o){return!!ry[o]}function ze(o,t){if(o)if(t){if(fs(t))return t;if(fs(o))return o;{let e=He(o),n=He(t);if(e&&n)switch(t){case"column":return o;case"region":return o==="column"?t:o;default:return t}else return n?t:e?o:Ki(t)?t:Ki(o)?o:t}}else return o;else return t}function ld(o){return He(o)?o:"auto"}Ke("SIMPLE_PROPERTY",sy);var qi=KC(Ig());function Vg(o,t){return(0,qi.default)(o,t,0)}function pd(o){return o.reduce((t,e)=>e[0]===qi.default.DELETE?t:t+e[1],"")}function Fg(o,t){return Og(o,t,1)}function Bg(o,t){return Og(o,t,-1)}function Og(o,t,e){let n=0,s=0;return o.some(i=>{for(let r=0;r<i[1].length;r++){switch(i[0]*e){case qi.default.INSERT:n++;break;case qi.default.DELETE:n--,s++;break;case qi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Ya;(t=>{function o(e){return e&&e.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=o})(Ya||(Ya={}));var gs;(t=>{let o;(r=>(r.INLINE="inline",r.COLUMN="column",r.REGION="region",r.PAGE="page"))(o=t.FloatReference||(t.FloatReference={}))})(gs||(gs={}));var Hr;(t=>{function o(e){return e&&e.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=o})(Hr||(Hr={}));var vn;(e=>{function o(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||an.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=o;function t(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||an.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=t})(vn||(vn={}));var an;(e=>{function o(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=o;function t(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=t})(an||(an={}));var Yt;(e=>{let o;(r=>(r[r.IGNORE=0]="IGNORE",r[r.NEWLINE=1]="NEWLINE",r[r.PRESERVE=2]="PRESERVE"))(o=e.Whitespace||(e.Whitespace={}));let t;(a=>(a[a.NONE=0]="NONE",a[a.CONTENT=1]="CONTENT",a[a.ROOTLESS=2]="ROOTLESS",a[a.ROOTED=3]="ROOTED"))(t=e.ShadowType||(e.ShadowType={}))})(Yt||(Yt={}));var Dg={transform:!0,"transform-origin":!0},Mg={top:!0,bottom:!0,left:!0,right:!0},Cs=class{constructor(t,e,n){this.target=t;this.name=e;this.value=n}},gy={show:function(o){o.style.visibility="visible"},hide:function(o){o.style.visibility="hidden"},play:function(o){o.currentTime=0,o.play()},pause:function(o){o.pause()},resume:function(o){o.play()},mute:function(o){o.muted=!0},unmute:function(o){o.muted=!1}};function my(o,t){let e=gy[t];return e?()=>{for(let n=0;n<o.length;n++)try{e(o[n])}catch(s){}}:null}var ms=class ms extends ts{constructor(e,n){super();this.container=e;this.bleedBox=n;p(this,"pageAreaElement",null);p(this,"delayedItems",[]);p(this,"hrefHandler");p(this,"elementsById",{});p(this,"dimensions",{width:0,height:0});p(this,"isFirstPage",!1);p(this,"isLastPage",!1);p(this,"isBlankPage",!1);p(this,"isAutoPageWidth",!0);p(this,"isAutoPageHeight",!0);p(this,"spineIndex",0);p(this,"position",null);p(this,"offset",-1);p(this,"side",null);p(this,"fetchers",[]);p(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}});p(this,"pageType",null);this.hrefHandler=s=>{let i=s.currentTarget,r=i.getAttribute("href")||i.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let a={type:"hyperlink",target:null,currentTarget:null,anchorElement:i,href:r,preventDefault(){s.preventDefault()}};this.dispatchEvent(a)}}}setAutoPageWidth(e){this.isAutoPageWidth=e,e?this.container.setAttribute(ms.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(ms.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(ms.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(ms.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(e,n){let s=this.elementsById[n];s?s.push(e):this.elementsById[n]=[e]}finish(e,n){Object.keys(this.elementsById).forEach(r=>{let a=this.elementsById[r];for(let l=0;l<a.length;)this.container.contains(a[l])?l++:a.splice(l,1);a.length===0&&delete this.elementsById[r]});let s=this.delayedItems;for(let r=0;r<s.length;r++){let a=s[r];a.target===this.container&&a.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||w(a.target,a.name,a.value.toString())}let i=n.getElementClientRect(this.container);this.dimensions.width=i.width,this.dimensions.height=i.height;for(let r=0;r<e.length;r++){let a=e[r],l=this.elementsById[a.ref],c=this.elementsById[a.observer];if(l&&c){let u=my(l,a.action);if(u)for(let d=0;d<c.length;d++)c[d].addEventListener(a.event,u,!1)}}}};p(ms,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),p(ms,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Zi=ms,ot=Yt.Whitespace;function tl(o){switch(o){case"normal":case"nowrap":return ot.IGNORE;case"pre-line":return ot.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ot.PRESERVE;default:return null}}function Ce(o,t){if(!o)return!0;if(o.nodeType==1)return!1;let e=o.textContent;switch(t){case ot.PRESERVE:return e.length==0;case ot.NEWLINE:return!!e.match(/^[ \t]*$/);case ot.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var Ka=class{constructor(t,e){this.flowName=t;this.parentFlowName=e;p(this,"forcedBreakOffsets",[]);p(this,"formattingContext",null)}},qa=class{constructor(t,e,n,s,i,r,a,l,c){this.flowName=t;this.element=e;this.startOffset=n;this.priority=s;this.linger=i;this.exclusive=r;this.repeated=a;this.last=l;this.breakBefore=c;p(this,"startPage",-1)}isBetter(t){return this.exclusive?!t.exclusive||this.priority>t.priority?!0:this.last:!1}};function _g(o,t){return o.top-t.top}function Ug(o,t){return t.right-o.right}function Hg(o,t){var e,n;return o===t?!0:!o||!t?!1:(o.node===t.node||!!o.shadowContext&&!!t.shadowContext&&o.shadowType===Yt.ShadowType.ROOTLESS&&t.shadowType===Yt.ShadowType.ROOTLESS&&((e=o.node)==null?void 0:e.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&o.shadowType===t.shadowType&&fd(o.shadowContext,t.shadowContext)&&fd(o.nodeShadow,t.nodeShadow)&&Hg(o.shadowSibling,t.shadowSibling)}function ln(o,t){if(o===t)return!0;if(!o||!t||o.offsetInNode!==t.offsetInNode||o.after!==t.after||o.steps.length!==t.steps.length)return!1;for(let e=0;e<o.steps.length;e++)if(!Hg(o.steps[e],t.steps[e]))return!1;return!0}function zg(o){return{steps:[{node:o,shadowType:Mt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function ii(o,t){return{steps:[{node:o.sourceNode,shadowType:Mt.NONE,shadowContext:o.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t!=null?t:o.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:o.preprocessedTextContent}}function Ji(o,t){let e=new bs(o.node,t,0);return e.shadowType=o.shadowType,e.shadowContext=o.shadowContext,e.nodeShadow=o.nodeShadow,e.shadowSibling=o.shadowSibling?Ji(o.shadowSibling,t.copy()):null,e.formattingContext=o.formattingContext,e.fragmentIndex=o.fragmentIndex+1,e}var Mt=Yt.ShadowType,si=class{constructor(t,e,n,s,i,r,a){this.owner=t;this.root=e;this.xmldoc=n;this.parentShadow=s;this.type=r;this.styler=a;p(this,"subShadow",null);i&&(i.subShadow=this)}equals(t){return t?this.owner===t.owner&&this.xmldoc===t.xmldoc&&this.type===t.type&&fd(this.parentShadow,t.parentShadow):!1}};function fd(o,t){return o===t||!!o&&!!t&&o.equals(t)}var Za=class{constructor(t,e){this.outer=t;this.count=e}},bs=class o{constructor(t,e,n){this.sourceNode=t;this.parent=e;this.boxOffset=n;p(this,"offsetInNode",0);p(this,"after",!1);p(this,"shadowType");p(this,"shadowContext");p(this,"nodeShadow",null);p(this,"shadowSibling",null);p(this,"shared",!1);p(this,"inline",!0);p(this,"overflow",!1);p(this,"breakPenalty");p(this,"display",null);p(this,"floatReference");p(this,"floatSide",null);p(this,"clearSide",null);p(this,"floatMinWrapBlock",null);p(this,"columnSpan",null);p(this,"verticalAlign","baseline");p(this,"captionSide","top");p(this,"inlineBorderSpacing",0);p(this,"blockBorderSpacing",0);p(this,"flexContainer",!1);p(this,"whitespace");p(this,"hyphenateCharacter");p(this,"breakWord");p(this,"establishesBFC",!1);p(this,"containingBlockForAbsolute",!1);p(this,"breakBefore",null);p(this,"breakAfter",null);p(this,"viewNode",null);p(this,"clearSpacer",null);p(this,"inheritedProps");p(this,"vertical");p(this,"direction");p(this,"firstPseudo");p(this,"lang",null);p(this,"preprocessedTextContent",null);p(this,"formattingContext");p(this,"repeatOnBreak",null);p(this,"pluginProps",{});p(this,"fragmentIndex",1);p(this,"afterIfContinues",null);p(this,"footnotePolicy",null);p(this,"pageType");this.shadowType=Mt.NONE,this.shadowContext=e?e.shadowContext:null,this.breakPenalty=e?e.breakPenalty:0,this.floatReference=gs.FloatReference.INLINE,this.whitespace=e?e.whitespace:ot.IGNORE,this.hyphenateCharacter=e?e.hyphenateCharacter:null,this.breakWord=e?e.breakWord:!1,this.inheritedProps=e?e.inheritedProps:{},this.vertical=e?e.vertical:!1,this.direction=e?e.direction:"ltr",this.firstPseudo=e?e.firstPseudo:null,this.formattingContext=e?e.formattingContext:null,this.pageType=e?e.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=gs.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:ot.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 o(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(),e=t,n;for(;(n=e.parent)!=null;)n=n.cloneItem(),e.parent=n,e=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var s,i,r;let t=this,e=[];t.shadowType===Yt.ShadowType.ROOTLESS&&(t.floatReference!==gs.FloatReference.INLINE||t.floatSide==="footnote")&&((r=(i=(s=t.shadowContext)==null?void 0:s.styler)==null?void 0:i.style)!=null&&r._pseudos)&&(t=t.parent);do(!t.firstPseudo||!t.parent||t.parent.firstPseudo===t.firstPseudo)&&e.push(t.toNodePositionStep()),t=t.parent;while(t);let n=this.preprocessedTextContent?Bg(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:e,offsetInNode:n,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}},wt=class o{constructor(t){this.primary=t;p(this,"floats",null)}clone(){let t=new o(this.primary);if(this.floats){t.floats=[];for(let e=0;e<this.floats.length;++e)t.floats[e]=this.floats[e]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!ln(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let e=0;e<this.floats.length;e++)if(!ln(this.floats[e],t.floats[e]))return!1}else if(t.floats)return!1;return!0}},Qa=class o{constructor(t,e){this.chunkPosition=t;this.flowChunk=e}clone(){return new o(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Ja=class o{constructor(){p(this,"positions",[]);p(this,"startBreakType",null);p(this,"breakAfter",null)}clone(){let t=new o,e=this.positions,n=t.positions;for(let s=0;s<e.length;s++)n[s]=e[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 e=0;e<this.positions.length;e++)if(!this.positions[e].isSamePosition(t.positions[e]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},el=class o{constructor(){p(this,"page",0);p(this,"flows",{});p(this,"flowPositions",{});p(this,"isBlankPage",!1);p(this,"highestSeenOffset",0);p(this,"highestSeenNode");p(this,"lookupPositionOffset")}clone(){let t=new o;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 e in this.flowPositions)t.flowPositions[e]=this.flowPositions[e].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let e=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(e.length!==n.length)return!1;for(let s of e)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))return!1;return!0}hasContent(t,e){let n=this.flowPositions[t];return n?n.hasContent(e):!1}startSideOfFlow(t){var n;let e=(n=this.flowPositions[t])==null?void 0:n.startBreakType;return e&&fs(e)?e:"any"}firstFlowChunkOfFlow(t){let e=this.flowPositions[t];if(!e)return null;let n=e.positions[0];return n?n.flowChunk:null}},Qi=class{constructor(t){this.element=t;p(this,"left",0);p(this,"top",0);p(this,"marginLeft",0);p(this,"marginRight",0);p(this,"marginTop",0);p(this,"marginBottom",0);p(this,"borderLeft",0);p(this,"borderRight",0);p(this,"borderTop",0);p(this,"borderBottom",0);p(this,"paddingLeft",0);p(this,"paddingRight",0);p(this,"paddingTop",0);p(this,"paddingBottom",0);p(this,"width",0);p(this,"height",0);p(this,"originX",0);p(this,"originY",0);p(this,"exclusions",null);p(this,"innerShape",null);p(this,"computedBlockSize",0);p(this,"snapWidth",0);p(this,"snapHeight",0);p(this,"snapOffsetX",0);p(this,"snapOffsetY",0);p(this,"vertical",!1);p(this,"rtl",!1);p(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(t){return this.vertical?t.right:t.top}getAfterEdge(t){return this.vertical?t.left:t.bottom}getStartEdge(t){return this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left}getEndEdge(t){return this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right}getInlineSize(t){return this.vertical?t.bottom-t.top:t.right-t.left}getBoxSize(t){return this.vertical?t.right-t.left:t.bottom-t.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(t){this.element=t.element,this.left=t.left,this.top=t.top,this.marginLeft=t.marginLeft,this.marginRight=t.marginRight,this.marginTop=t.marginTop,this.marginBottom=t.marginBottom,this.borderLeft=t.borderLeft,this.borderRight=t.borderRight,this.borderTop=t.borderTop,this.borderBottom=t.borderBottom,this.paddingLeft=t.paddingLeft,this.paddingRight=t.paddingRight,this.paddingTop=t.paddingTop,this.paddingBottom=t.paddingBottom,this.width=t.width,this.height=t.height,this.originX=t.originX,this.originY=t.originY,this.innerShape=t.innerShape,this.exclusions=t.exclusions,this.computedBlockSize=t.computedBlockSize,this.snapWidth=t.snapWidth,this.snapHeight=t.snapHeight,this.vertical=t.vertical,this.rtl=t.rtl,this.borderBoxSizing=t.borderBoxSizing}setVerticalPosition(t,e){this.top=t,this.height=e,w(this.element,"top",`${t}px`),w(this.element,"height",`${e}px`)}setHorizontalPosition(t,e){this.left=t,this.width=e,w(this.element,"left",`${t}px`),w(this.element,"width",`${e}px`)}setBlockPosition(t,e){if(this.vertical){let n=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+n*this.getBoxDir(),e)}else this.setVerticalPosition(t,e)}setInlinePosition(t,e){if(this.vertical)if(this.rtl){let n=e+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(t+n*this.getInlineDir(),e)}else this.setVerticalPosition(t,e);else if(this.rtl){let n=e+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(t+n*this.getInlineDir(),e)}else this.setHorizontalPosition(t,e)}clear(){let t=this.element,e;for(;e=t.lastChild;)t.removeChild(e)}getInnerShape(){let t=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(t.x1,t.y1):Br(t.x1,t.y1,t.x2,t.y2)}getInnerRect(){let t=this.originX+this.left+this.getInsetLeft(),e=this.originY+this.top+this.getInsetTop();return new qe(t,e,t+this.width,e+this.height)}getPaddingRect(){let t=this.originX+this.left+this.marginLeft+this.borderLeft,e=this.originY+this.top+this.marginTop+this.borderTop,n=this.paddingLeft+this.width+this.paddingRight,s=this.paddingTop+this.height+this.paddingBottom;return new qe(t,e,t+n,e+s)}getOuterShape(t,e){let n=this.getOuterRect();return Fa(t,n.x1,n.y1,n.x2-n.x1,n.y2-n.y1,e)}getOuterRect(){let t=this.originX+this.left,e=this.originY+this.top,n=this.getInsetLeft()+this.width+this.getInsetRight(),s=this.getInsetTop()+this.height+this.getInsetBottom();return new qe(t,e,t+n,e+s)}},Mn=class extends Et{constructor(e,n,s,i){super();this.elem=e;this.context=n;this.rootContentValue=s;this.exprContentListener=i}visitStrInner(e,n){var s;if(!n){if(((s=this.elem.lastChild)==null?void 0:s.nodeType)===3){this.elem.lastChild.textContent+=e;return}n=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(n)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof ge)this.elem.setAttribute("src",e.url);else{let n=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");n.setAttribute("src",e.url),this.elem.appendChild(n)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let n=e.toExpr(),s=n.evaluate(this.context);if(typeof s=="string"){n instanceof re&&(s=En(n.scope,new Xe(s,null),"").stringValue()),this.elem.ownerDocument;let i=this.exprContentListener(n,s,this.elem.ownerDocument);!i&&s&&n instanceof ne&&n.str.startsWith("running-element-")&&(s=""),this.visitStrInner(s,i)}return null}};function ht(o){return o!=null&&o!==H&&o!==b.normal&&o!==b.none&&!X(o)}var be=gs.FloatReference;function Wg(o){switch(o){case"inline":return be.INLINE;case"column":return be.COLUMN;case"region":return be.REGION;case"page":return be.PAGE;default:throw new Error(`Unknown float-reference: ${o}`)}}function ys(o){switch(o){case be.INLINE:return!1;case be.COLUMN:case be.REGION:case be.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${o}`)}}function Cd(o,t,e,n){let s=t?"vertical-rl":"horizontal-tb";if((o==="top"||o==="bottom")&&(o=id(o,s,e)),o==="block-start"&&(o="inline-start"),o==="block-end"&&(o="inline-end"),o==="inline-start"||o==="inline-end"){let i=sd(o,s,e),r=Sg(i,s);r==="line-left"?o="left":r==="line-right"&&(o="right")}else o==="inside"?o=n==="left"?"right":"left":o==="outside"&&(o=n==="left"?"left":"right");return o!=="left"&&o!=="right"&&(F.warn(`Invalid float value: ${o}. Fallback to left.`),o="left"),o}var Gr=class{constructor(t,e,n,s,i,r){this.nodePosition=t;this.floatReference=e;this.floatSide=n;this.clearSide=s;this.flowName=i;this.floatMinWrapBlock=r;p(this,"order",null);p(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(t){return t.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(t){return!1}},gd=class{constructor(){p(this,"floats",[]);p(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(t){return`pf${t}`}addPageFloat(t){if(this.floats.findIndex(n=>ln(n.nodePosition,t.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let n=t.order=this.nextOrder();t.id=this.createPageFloatId(n),this.floats.push(t)}}findPageFloatByNodePosition(t){let e=this.floats.findIndex(n=>ln(n.nodePosition,t));return e>=0?this.floats[e]:null}findPageFloatById(t){let e=this.floats.findIndex(n=>n.id===t);return e>=0?this.floats[e]:null}},Wr=class{constructor(t,e,n,s,i,r){this.floatReference=t;this.floatSide=e;this.clearSide=n;this.continuations=s;this.area=i;this.continues=r}hasFloat(t){return this.continuations.some(e=>e.float===t)}findNotAllowedFloat(t){for(let e=this.continuations.length-1;e>=0;e--){let n=this.continuations[e].float;if(!n.isAllowedOnContext(t))return n}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let t=this.continuations.map(e=>e.float);return Math.min.apply(null,t.map(e=>e.getOrder()))}shouldBeStashedBefore(t){return this.getOrder()<t.getOrder()}addContinuations(t){t.forEach(e=>{this.continuations.push(e)})}getFlowName(){let t=this.continuations[0].float.flowName;return this.continuations.every(e=>e.float.flowName===t),t}},Xr=class{constructor(t,e){this.float=t;this.nodePosition=e}equals(t){return t?this===t?!0:this.float===t.float&&ln(this.nodePosition,t.nodePosition):!1}},_n=class{constructor(t,e,n,s,i,r,a){this.parent=t;this.floatReference=e;this.container=n;this.flowName=s;this.generatingNodePosition=i;p(this,"children",[]);p(this,"writingMode");p(this,"direction");p(this,"invalidated",!1);p(this,"floatStore");p(this,"forbiddenFloats",[]);p(this,"floatFragments",[]);p(this,"stashedFloatFragments",[]);p(this,"floatAnchors",{});p(this,"floatsDeferredToNext",[]);p(this,"floatsDeferredFromPrevious");p(this,"layoutConstraints",[]);p(this,"locked",!1);t&&t.children.push(this),this.writingMode=r||t&&t.writingMode||b.horizontal_tb,this.direction=a||t&&t.direction||b.ltr,this.floatStore=t?t.floatStore:new gd;let l=this.getPreviousSibling();this.floatsDeferredFromPrevious=l?[].concat(l.floatsDeferredToNext):[]}getParent(t){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${t}`);return this.parent}getPreviousSiblingOf(t,e,n,s){let i=this.children.indexOf(t);i<0&&(i=this.children.length);for(let r=i-1;r>=0;r--){let a=this.children[r];if(a.floatReference===e&&a.flowName===n&&ln(a.generatingNodePosition,s))return a;if(a=a.getPreviousSiblingOf(null,e,n,s),a)return a}return null}getPreviousSibling(){let t=this,e=this.parent,n;for(;e;){if(n=e.getPreviousSiblingOf(t,this.floatReference,this.flowName,this.generatingNodePosition),n)return n;t=e,e=e.parent}return null}getContainer(t){return!t||t===this.floatReference?this.container:this.getParent(t).getContainer(t)}setContainer(t){this.container=t,this.reattachFloatFragments()}addPageFloat(t){this.floatStore.addPageFloat(t)}getPageFloatLayoutContext(t){return t===this.floatReference?this:this.getParent(t).getPageFloatLayoutContext(t)}findPageFloatByNodePosition(t){return this.floatStore.findPageFloatByNodePosition(t)}forbid(t){let e=t.getId(),n=t.floatReference;n===this.floatReference?this.forbiddenFloats.includes(e)||(this.forbiddenFloats.push(e),new cn().findByFloat(t).forbid(t,this)):this.getParent(n).forbid(t)}isForbidden(t){let e=t.getId(),n=t.floatReference;return n===this.floatReference?this.forbiddenFloats.includes(e):this.getParent(n).isForbidden(t)}addPageFloatFragment(t,e){let n=t.floatReference;n!==this.floatReference?this.getParent(n).addPageFloatFragment(t,e):this.floatFragments.includes(t)||(this.floatFragments.push(t),this.floatFragments.sort((s,i)=>s.getOrder()-i.getOrder())),e||this.invalidate()}removePageFloatFragment(t,e){let n=t.floatReference;if(n!==this.floatReference)this.getParent(n).removePageFloatFragment(t,e);else{let s=this.floatFragments.indexOf(t);if(s>=0){let i=this.floatFragments.splice(s,1)[0],r=i.area&&i.area.element;r&&r.parentNode&&r.parentNode.removeChild(r),e||this.invalidate()}}}findPageFloatFragment(t){if(t.floatReference!==this.floatReference)return this.getParent(t.floatReference).findPageFloatFragment(t);let e=this.floatFragments.findIndex(n=>n.hasFloat(t));return e>=0?this.floatFragments[e]:null}hasFloatFragments(t){return this.floatFragments.length>0&&(!t||this.floatFragments.some(t))?!0:this.parent?this.parent.hasFloatFragments(t):!1}hasContinuingFloatFragmentsInFlow(t){return this.hasFloatFragments(e=>e.continues&&e.getFlowName()===t)}registerPageFloatAnchor(t,e){this.floatAnchors[t.getId()]=e}collectPageFloatAnchors(){let t=Object.assign({},this.floatAnchors);return this.children.reduce((e,n)=>Object.assign(e,n.collectPageFloatAnchors()),t)}isAnchorAlreadyAppeared(t){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===t))return!0;let s=this.collectPageFloatAnchors()[t];return s&&this.container&&this.container.element?this.container.element.contains(s):!1}deferPageFloat(t){let e=t.float;if(e.floatReference===this.floatReference){let n=this.floatsDeferredToNext.findIndex(s=>s.float===e);n>=0?this.floatsDeferredToNext.splice(n,1,t):this.floatsDeferredToNext.push(t)}else this.getParent(e.floatReference).deferPageFloat(t)}hasPrecedingFloatsDeferredToNext(t,e){if(!e&&t.floatReference!==this.floatReference)return this.getParent(t.floatReference).hasPrecedingFloatsDeferredToNext(t,!1);let n=t.getOrder();return this.floatsDeferredToNext.some(i=>i.float.getOrder()<n&&!t.isAllowedToPrecede(i.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(t,!0):!1}getLastFollowingFloatInFragments(t){let e=t.getOrder(),n=null;if(this.floatFragments.forEach(s=>{s.continuations.forEach(i=>{let r=i.float,a=r.getOrder();a>e&&(!n||a>n.getOrder())&&(n=r)})}),this.parent){let s=this.parent.getLastFollowingFloatInFragments(t);s&&(!n||s.getOrder()>n.getOrder())&&(n=s)}return n}getDeferredPageFloatContinuations(t){t=t||this.flowName;let e=this.floatsDeferredFromPrevious.filter(n=>!t||n.float.flowName===t);return this.parent&&(e=this.parent.getDeferredPageFloatContinuations(t).concat(e)),e.sort((n,s)=>n.float.getOrder()-s.float.getOrder())}getPageFloatContinuationsDeferredToNext(t){t=t||this.flowName;let e=this.floatsDeferredToNext.filter(n=>!t||n.float.flowName===t);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(t).concat(e):e}getFloatsDeferredToNextInChildContexts(){let t=[],e=[];for(let n=this.children.length-1;n>=0;n--){let s=this.children[n];e.includes(s.flowName)||(e.push(s.flowName),t=t.concat(s.floatsDeferredToNext.map(i=>i.float)),t=t.concat(s.getFloatsDeferredToNextInChildContexts()))}return t}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let t=this.floatFragments.length-1;t>=0;t--){let e=this.floatFragments[t],n=e.findNotAllowedFloat(this);if(n)return this.locked?this.invalidate():(this.removePageFloatFragment(e),this.forbid(n),this.removeEndFloatFragments(e.floatSide)),!0}return this.floatReference===be.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let t=this.getFloatsDeferredToNextInChildContexts(),e=this.floatFragments.reduce((n,s)=>n.concat(s.continuations.map(i=>i.float)),[]);e.sort((n,s)=>s.getOrder()-n.getOrder());for(let n of e){let s=n.getOrder();if(t.some(i=>!n.isAllowedToPrecede(i)&&s>i.getOrder())){if(this.locked)this.invalidate();else{this.forbid(n);let i=this.findPageFloatFragment(n);this.removePageFloatFragment(i)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let t=this.floatsDeferredToNext.length-1;t>=0;t--)if(!this.floatsDeferredToNext[t].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(t,1)}this.floatsDeferredFromPrevious.forEach(t=>{this.floatsDeferredToNext.findIndex(e=>t.equals(e))>=0||this.floatFragments.some(e=>e.hasFloat(t.float))||this.floatsDeferredToNext.push(t)})}}hasSameContainerAs(t){return!!this.container&&!!t.container&&this.container.element===t.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(t=>{this.hasSameContainerAs(t)&&t.floatFragments.forEach(e=>{let n=e.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),this.container.clear()),this.children.forEach(t=>{t.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(t=>{delete this.floatAnchors[t]}))}detachChildren(){let t=this.children.splice(0);return t.forEach(e=>{e.floatFragments.forEach(n=>{let s=n.area.element;s&&s.parentNode&&s.parentNode.removeChild(s)})}),t}attachChildren(t){t.forEach(e=>{this.children.push(e),e.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(t){let e=this.writingMode.toString(),n=this.direction.toString();if(t==="inside"||t==="outside"){let s=!!this.container.element.closest("[data-vivliostyle-page-side='left']");t=t==="inside"?s?"right":"left":s?"left":"right"}return id(t,e,n)}toPhysical(t){let e=this.writingMode.toString(),n=this.direction.toString();return sd(t,e,n)}toLogicalFloatSides(t){let e=t.split(" "),n=[];for(let a of e){let l=this.toLogical(a);n.includes(l)||n.push(l)}let s=[],i=!1,r=!1;for(let a=0;a<n.length;a++){let l=n[a];l.includes("block")?i||(n.slice(a+1).some(c=>c.includes("block"))?(s.push("snap-block"),i=!0):s.push(l)):l.includes("inline")&&(r||(n.slice(a+1).some(c=>c.includes("inline"))?(s.push("snap-inline"),r=!0):s.push(l)))}return s}removeEndFloatFragments(t){let e=this.toLogicalFloatSides(t)[0];if(e==="block-end"||e==="inline-end"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n];this.toLogicalFloatSides(s.floatSide)[0]===e?this.removePageFloatFragment(s):n++}}}stashEndFloatFragments(t){let e=t.floatReference;if(e!==this.floatReference){this.getParent(e).stashEndFloatFragments(t);return}let n=this.toLogicalFloatSides(t.floatSide)[0];if(n==="block-end"||n==="snap-block"||n==="inline-end"||n==="snap-inline"){let s=0;for(;s<this.floatFragments.length;){let i=this.floatFragments[s],r=this.toLogicalFloatSides(i.floatSide)[0];(r===n||n==="snap-block"&&r==="block-end"||n==="snap-inline"&&r==="inline-end")&&i.shouldBeStashedBefore(t)?(this.stashedFloatFragments.push(i),this.floatFragments.splice(s,1)):s++}}}restoreStashedFragments(t){if(t!==this.floatReference){this.getParent(t).restoreStashedFragments(t);return}this.stashedFloatFragments.forEach(e=>{this.addPageFloatFragment(e,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(t){if(t!==this.floatReference){this.getParent(t).discardStashedFragments(t);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(t){return t===this.floatReference?this.stashedFloatFragments.concat().sort((e,n)=>n.getOrder()-e.getOrder()):this.getParent(t).getStashedFloatFragments(t)}getLimitValue(t,e,n,s,i){this.container;let r=this.toLogical(t),a=this.toPhysical(t),l=e&&this.toLogical(e),c=e&&this.toPhysical(e),u=this.getLimitValueInner(r,l,n,s,i);if(this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,c,n,s,i);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(t,e,n,s,i){this.container;let r=this.getLimitValuesInner(n,s,i,t,e);switch(t){case"block-start":return this.container.vertical?r.right:r.top;case"block-end":return this.container.vertical?r.left:r.bottom;case"inline-start":return this.container.vertical?this.container.rtl?r.bottom:r.top:this.container.rtl?r.right:r.left;case"inline-end":return this.container.vertical?this.container.rtl?r.top:r.bottom:this.container.rtl?r.left:r.right;default:throw new Error(`Unknown logical side: ${t}`)}}getLimitValuesInner(t,e,n,s,i){this.container;let r=this.container.originX,a=this.container.originY,l=this.container.getPaddingRect(),c={top:l.y1-a,left:l.x1-r,bottom:l.y2-a,right:l.x2-r,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function u(h,f,g){return h.unit==="%"?g*h.num/100:t.convertLengthToPx(h,f,e)}let d=this.floatFragments;return d.length>0&&(c=d.reduce((h,f)=>{if(n&&!n(f,this))return h;let[g,m]=this.toLogicalFloatSides(f.floatSide);if(m&&(s&&m.includes("block")===s.includes("block")&&m!==s||i&&m.includes("block")===i.includes("block")&&m!==i))return h;let y=f.area,S=f.continuations[0].float.floatMinWrapBlock,C=h.top,x=h.left,v=h.bottom,E=h.right,N=h.floatMinWrapBlockStart,L=h.floatMinWrapBlockEnd;switch(g){case"inline-start":y.vertical?C=Math.max(C,y.top+y.height):x=Math.max(x,y.left+y.width);break;case"block-start":y.vertical?(S&&y.left<E&&(N=u(S,y.rootViewNodes[0],l.x2-l.x1)),E=Math.min(E,y.left)):(S&&y.top+y.height>C&&(N=u(S,y.rootViewNodes[0],l.y2-l.y1)),C=Math.max(C,y.top+y.height));break;case"inline-end":y.vertical?v=Math.min(v,y.top):E=Math.min(E,y.left);break;case"block-end":y.vertical?(S&&y.left+y.width>x&&(L=u(S,y.rootViewNodes[0],l.x2-l.x1)),x=Math.max(x,y.left+y.width)):(S&&y.top<v&&(L=u(S,y.rootViewNodes[0],l.y2-l.y1)),v=Math.min(v,y.top));break;default:throw new Error(`Unknown logical float side: ${g}`)}return{top:C,left:x,bottom:v,right:E,floatMinWrapBlockStart:N,floatMinWrapBlockEnd:L}},c)),c.left+=r,c.right+=r,c.top+=a,c.bottom+=a,c}setFloatAreaDimensions(t,e,n,s,i,r,a){if(e!==this.floatReference)return this.getParent(e).setFloatAreaDimensions(t,e,n,s,i,r,a);let l=this.toLogicalFloatSides(n);if(l[0]==="snap-block"){if(!a["block-start"]&&!a["block-end"])return null}else if(l[0].includes("block")&&!a[l[0]])return null;t.clientLayout;let c=l.find(N=>N.includes("inline")&&a[N==="inline-start"?"inline-end":"inline-start"]),u=l.find(N=>N.includes("block")),d=this.getLimitValue("block-start",c,t.layoutContext,t.clientLayout),h=this.getLimitValue("block-end",c,t.layoutContext,t.clientLayout),f=this.getLimitValue("inline-start",u,t.layoutContext,t.clientLayout),g=this.getLimitValue("inline-end",u,t.layoutContext,t.clientLayout),m=t.vertical?t.originX:t.originY,y=t.vertical?t.originY:t.originX;d=t.vertical?Math.min(d,t.left+t.getInsetLeft()+t.width+t.getInsetRight()+m):Math.max(d,t.top+m),h=t.vertical?Math.max(h,t.left+m):Math.min(h,t.top+t.getInsetTop()+t.height+t.getInsetBottom()+m);function S(N,L){let O=N(t.bands,L);return O?(t.vertical&&(O=Ra(O)),d=t.vertical?Math.min(d,O.x2):Math.max(d,O.y1),h=t.vertical?Math.max(h,O.x1):Math.min(h,O.y2),!0):r}let C,x,v,E;if(i){let N=t.vertical?Ui(new qe(h,f,d,g)):new qe(f,d,g,h);if((l[0]==="block-start"||l[0]==="snap-block"||l[0]==="inline-start"||l[0]==="snap-inline")&&!S(eg,N)||(l[0]==="block-end"||l[0]==="snap-block"||l[0]==="inline-end"||l[0]==="snap-inline")&&!S(tg,N)||(v=(h-d)*t.getBoxDir(),C=v-t.getInsetBefore()-t.getInsetAfter(),E=(g-f)*t.getInlineDir(),x=E-t.getInsetStart()-t.getInsetEnd(),!r&&(C<=0||x<=0)))return null}else{C=t.computedBlockSize,v=C+t.getInsetBefore()+t.getInsetAfter();let N=(h-d)*t.getBoxDir();if(l[0]==="snap-block"){if(s===null)l[0]="block-start";else{let O=this.container.getPaddingRect(),z=this.container.getBoxDir()*(s-(this.container.vertical?O.x2:O.y1)),K=this.container.getBoxDir()*((this.container.vertical?O.x1:O.y2)-s-v);z<=K?l[0]="block-start":l[0]="block-end"}if(!a[l[0]])if(a["block-end"])l[0]="block-end";else return null}else if(l[0]==="snap-inline")if(s===null)l[0]="inline-start";else if(a["inline-start"])l[0]="inline-start";else if(a["inline-end"])l[0]="inline-end";else return null;if(!r&&N<v)return null;l[0]==="inline-start"||l[0]==="inline-end"||l[1]?x=Yi(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?x=t.getContentInlineSize():x=t.vertical?t.height:t.width,E=x+t.getInsetStart()+t.getInsetEnd();let L=(g-f)*t.getInlineDir();if(!r&&L<E)return null}return d-=m,h-=m,f-=y,g-=y,l.some(N=>N==="inline-start"||N==="snap-inline")||l.length===1&&(l[0]==="block-start"||l[0]==="snap-block")?t.setInlinePosition(f,x):(l.some(N=>N==="inline-end")||l.length===1&&l[0]==="block-end")&&t.setInlinePosition(g-E*t.getInlineDir(),x),l.some(N=>N==="block-start"||N==="snap-block")||l.length===1&&(l[0]==="inline-start"||l[0]==="snap-inline")?t.setBlockPosition(d,C):(l.some(N=>N==="block-end")||l.length===1&&l[0]==="inline-end")&&t.setBlockPosition(h-v*t.getBoxDir(),C),l.join(" ")}getFloatFragmentExclusions(){let t=this.floatFragments.map(e=>e.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(t):t}reattachFloatFragments(){let t=this.container.element&&this.container.element.parentNode;t&&this.floatFragments.forEach(e=>{t.appendChild(e.area.element)})}getMaxReachedAfterEdge(){let t=this.getContainer().vertical;return this.floatFragments.reduce((e,n)=>{let s=n.getOuterRect();return t?Math.min(e,s.x1):Math.max(e,s.y2)},t?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let t=this.getContainer().vertical;return this.floatFragments.filter(e=>e.floatSide==="block-end").reduce((e,n)=>{let s=n.getOuterRect();return t?Math.max(e,s.x2):Math.min(e,s.y1)},t?0:1/0)}getPageFloatClearEdge(t,e){function n(d){return h=>d.isAnchorAlreadyAppeared(h.float.getId())}function s(d,h){return t==="inline-start"&&(d.floatSide.includes("inline-end")||d.floatSide==="block-end")||t==="inline-end"&&(d.floatSide.includes("inline-start")||d.floatSide==="block-start")?!1:d.continuations.some(n(h))}let i=e.getPaddingRect(),r=e.vertical?i.x1:i.y2,a=this;for(;a;){if(a.floatsDeferredToNext.some(n(a)))return r;a=a.parent}function l(d){return d.floatFragments.some(h=>s(h,d))||d.children.some(h=>l(h))}if(t==="column"||t==="region"||t==="page"){for(a=this;a;a=a.parent)if(a.floatReference===t){if(l(a))return r;break}}e.clientLayout;let c=this.getLimitValue("block-start",null,e.layoutContext,e.clientLayout,s);return this.getLimitValue("block-end",null,e.layoutContext,e.clientLayout,s)*e.getBoxDir()<r*e.getBoxDir()?r:c}getPageFloatPlacementCondition(t,e,n){if(t.floatReference!==this.floatReference)return this.getParent(t.floatReference).getPageFloatPlacementCondition(t,e,n);let s={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!n)return s;let i=this.toLogicalFloatSides(e)[0],r=this.toLogical(n),a;r==="all"?a=["block-start","block-end","inline-start","inline-end"]:r==="both"?a=["inline-start","inline-end"]:r==="same"?i==="snap-block"?a=["block-start","block-end"]:a=[i]:a=[r];let l=t.getOrder();function c(h){return f=>(!h||f.floatSide.includes(h))&&f.getOrder()<l}function u(h,f){return h.children.some(g=>g.floatFragments.some(c(f))||u(g,f))}function d(h,f){let g=h.parent;return!!g&&(g.floatFragments.some(c(f))||d(g,f))}if(n==="column"||n==="region"||n==="page"){for(let h=this;h;h=h.parent)if(h.floatReference===n){(h.floatFragments.some(c(null))||u(h,null))&&(s["block-start"]=!1,s["block-end"]=!1,s["inline-start"]=!1,s["inline-end"]=!1);break}return s}return a.forEach(h=>{switch(h){case"block-start":s[h]=!u(this,h);break;case"block-end":s[h]=!d(this,h);break;case"inline-start":case"inline-end":s[h]=!this.floatFragments.some(c(h));break;default:throw new Error(`Unexpected side: ${h}`)}}),s}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(t,e){e===this.floatReference?this.layoutConstraints.push(t):this.getParent(e).addLayoutConstraint(t,e)}isColumnFullWithPageFloats(t){let e=t.layoutContext,n=t.clientLayout;let s=this,i=null;for(;s&&s.container;){let l=s.getLimitValuesInner(e,n);i?t.vertical?(l.right<i.right&&(i.right=l.right,i.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.left>i.left&&(i.left=l.left,i.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):(l.top>i.top&&(i.top=l.top,i.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.bottom<i.bottom&&(i.bottom=l.bottom,i.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):i=l,s=s.parent}let r=Math.max(i.floatMinWrapBlockStart,i.floatMinWrapBlockEnd);return(t.vertical?i.right-i.left:i.bottom-i.top)<=r}getMaxBlockSizeOfPageFloats(){let t=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(e=>{let n=e.area;return t?n.width:n.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},zr=[],cn=class{static register(t){zr.push(t)}findByNodeContext(t){for(let e=zr.length-1;e>=0;e--){let n=zr[e];if(n.appliesToNodeContext(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=zr.length-1;e>=0;e--){let n=zr[e];if(n.appliesToFloat(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},md=class{appliesToNodeContext(t){return ys(t.floatReference)}appliesToFloat(t){return!0}createPageFloat(t,e,n){let s=t.floatReference;t.floatSide;let i=t.floatSide,r=t.toNodePosition();return n.resolveFloatReferenceFromColumnSpan(s,t.columnSpan,t).thenAsync(a=>{s=a,e.flowName;let l=new Gr(r,s,i,t.clearSide,e.flowName,t.floatMinWrapBlock);return e.addPageFloat(l),T(l)})}createPageFloatFragment(t,e,n,s,i){let r=t[0].float;return new Wr(r.floatReference,e,n,t,s,i)}findPageFloatFragment(t,e){return e.findPageFloatFragment(t)}adjustPageFloatArea(t,e,n){}forbid(t,e){}};cn.register(new md);var by=Wr,$r=class o extends Gr{constructor(e,n,s,i,r){super(e,n,"block-end",null,s,r);this.footnotePolicy=i}isAllowedToPrecede(e){return!(e instanceof o)}},sl=class extends by{constructor(t,e,n,s){super(t,"block-end",null,e,n,s)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof $r?!0:this.getOrder()<t.getOrder()}},bd=class{constructor(t){this.footnote=t}allowLayout(t){let e=t.toNodePosition();return!ln(e,this.footnote.nodePosition)}},yd=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof $r}createPageFloat(t,e,n){let s=be.REGION,i=e.getPageFloatLayoutContext(s);e.getPageFloatLayoutContext(be.PAGE).hasSameContainerAs(i)&&(s=be.PAGE);let a=t.toNodePosition();e.flowName;let l=new $r(a,s,e.flowName,t.footnotePolicy,t.floatMinWrapBlock);return e.addPageFloat(l),T(l)}createPageFloatFragment(t,e,n,s,i){let r=t[0].float;return new sl(r.floatReference,t,s,i)}findPageFloatFragment(t,e){let s=e.getPageFloatLayoutContext(t.floatReference).floatFragments.filter(i=>i instanceof sl);return s.length<=1,s[0]||null}adjustPageFloatArea(t,e,n){t.isFootnote=!0,t.adjustContentRelativeSize=!1;let s=t.element;t.vertical=n.layoutContext.applyFootnoteStyle(e.vertical,n.layoutContext.nodeContext&&n.layoutContext.nodeContext.direction==="rtl",s),t.convertPercentageSizesToPx(s),n.setComputedInsets(s,t),n.setComputedWidthAndHeight(s,t)}forbid(t,e){let n=t;switch(n.footnotePolicy){case b.line:{let s=new bd(n);e.addLayoutConstraint(s,n.floatReference);break}}}};cn.register(new yd);var yy="data-vivliostyle-flow-root";function $g(o){return o.getAttribute(yy)==="true"}function Xg(o){let t=(o==null?void 0:o.toString())||"block",e;switch(t){case"inline-flex":e="flex";break;case"inline-grid":e="grid";break;case"inline-table":e="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":e="block";break;default:e=t}return k(e)}function il(o){return o===b.absolute||o===b.fixed}function jr(o){return o instanceof vt&&o.name==="running"}function xd(o,t,e,n){return o===b.none||(il(t)?(e=b.none,o=Xg(o)):(e&&e!==b.none&&!X(e)||n)&&(o=Xg(o))),{display:o,position:t,float:e}}function rl(o,t,e,n){return xd(o,t,e,n).display===b.block}function ol(o){return o instanceof Y||o instanceof G||typeof o=="string"}function _t(o){if(!ol(o))return!1;let t=o.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function Un(o){return ol(o)?o.toString().includes("list-item"):!1}function jg(o){if(!ol(o))return!1;switch(o.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function al(o){if(!ol(o))return!1;switch(o.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Yg(o,t,e,n,s,i,r){return s=s||i||b.horizontal_tb,!!r||!!e&&e!==b.none&&!X(e)||il(t)||o===b.inline_block||o===b.table_cell||o===b.table_caption||o==b.flex||o==b.grid||o==b.flow_root||(o===b.block||o===b.list_item)&&!!n&&n!==b.visible&&n!==b.clip&&!X(n)||!!i&&s!==i}function Kg(o){return o===b.relative||o===b.absolute||o===b.fixed}var Nn=1e5;function Kr(o){let t=o.element.style;t.columnGap=`${Nn-(o.vertical?o.height:o.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function qr(o){let t=o.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Ed(o){return o.element.style.columnCount==="1"}function qg(o){o.element.setAttribute("data-vivliostyle-column","true")}function vd(o){return o.element.hasAttribute("data-vivliostyle-column")}function ri(o,t){let e=t?o.bottom:Math.max(Math.abs(o.left),Math.abs(o.right));return Math.round(e/Nn)}function Sd(o,t){let e=ri(o,t);if(e===0)return 0;let n=t?o.top:Math.min(Math.abs(o.left),Math.abs(o.right)),s=Math.round(n/Nn),i=s*Nn,r=e*Nn;return t?(o.top-=i,o.bottom-=r,o.bottom<o.top&&(o.bottom+=Nn),o.right-=i,o.left-=r):o.left<-Nn/2?(o.right+=i,o.left+=r,o.left>o.right&&(o.left-=Nn),o.top+=i,o.bottom+=r):(o.left-=i,o.right-=r,o.right<o.left&&(o.right+=Nn),o.top+=i,o.bottom+=r),o.width=o.right-o.left,o.height=o.bottom-o.top,s}function Nd(o,t){for(let e=0;e<o.length;e++)Sd(o[e],t)}function Ut(o,t,e){var i;let n=o.getElementClientRect(t),s=Sd(n,e);if(s===1){let r=o.getElementComputedStyle(t);if(r.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&((i=t.parentElement)!=null&&i.parentElement)&&(r=o.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),l=a==null?void 0:a.style,c=e?"width":"height",u=l&&parseFloat(l[c]);if(u){let d=u,h=s,f=parseFloat(r.paddingBlockEnd),g=parseFloat(r.borderBlockEndWidth),m=Math.ceil(f+g);for(;m-- >0&&h===s&&--d>0;){l[c]=`${d}px`;let y=o.getElementClientRect(t);if(h=Sd(y,e),h<s||h===s&&(e?y.right>n.right:y.top<n.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),y}l[c]=`${u}px`}}}return n}function Zg(o,t){var e,n;if(o.nodeType===1){let s=o;((e=s.style)==null?void 0:e.breakAfter)==="column"&&(s.style.breakAfter="")}if(t.nodeType===1){let s=t;((n=s.style)==null?void 0:n.breakBefore)==="column"&&(s.style.breakBefore="")}}function Zr(o){for(let t=o.nodeType===1?o:o.parentElement;t;t=t.parentElement){let e=t.style;if(!e||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(e.columnCount))||!isNaN(parseFloat(e.columnWidth)))return t;if(e.position==="absolute")break}return null}function Qg(o){var C;if(o.nodeType!==1)return;let t=o,e=t.style,n=(e==null?void 0:e.breakBefore)==="column",s=t.previousElementSibling,i=s&&((C=s.style)==null?void 0:C.breakAfter)==="column";if(!n&&!i)return;let r=Zr(t);if(!r)return;let a=r.ownerDocument.defaultView.getComputedStyle(r),{writingMode:l,direction:c,columnGap:u,fontSize:d}=a,h=l==="vertical-rl"||l==="vertical-lr",f=c==="rtl",g=(parseFloat(u)||parseFloat(d)||16)/2,m=r.getBoundingClientRect(),y=t.getBoundingClientRect();(h?y.top>m.bottom+g:f?y.right<m.left-g:y.left>m.right+g)&&(n&&(e.breakBefore=""),i&&s&&(s.style.breakAfter=""),e.marginBlockStart=`${Nn}px`)}function xs(o,t,e,n){let s=o.viewNode;if(!s)return NaN;let i=s.nodeType===1?s:s.parentElement;if(i&&i.namespaceURI==="http://www.w3.org/1999/xhtml"){let r=i.style;if(i.localName==="br"||i.localName==="wbr"||r&&_t(r.display)&&/^([\d\.]|super|(text-)?top)/.test(r.verticalAlign))return NaN}if(s===i){if(o.after||!o.inline){if(o.after&&!o.inline&&i.querySelector("ruby")){let a=i.parentNode,l=i.nextSibling;a.removeChild(i),a.insertBefore(i,l)}let r=Ut(t,i,n);if(r.left===0&&r.top===0&&r.right===0&&r.bottom===0)return NaN;if(r.right>=r.left&&r.bottom>=r.top)return o.after?n?r.left:r.bottom:n?r.right:r.top}return NaN}else{let r=NaN,a=s.ownerDocument.createRange(),l=s.textContent.length;if(!l)return NaN;o.after&&(e+=l),e>=l&&(e=l-1),a.setStart(s,e),a.setEnd(s,e+1);let c=t.getRangeClientRects(a);return Nd(c,n),c=c.filter(u=>u.right>u.left&&u.bottom>u.top),c.length?(n?r=Math.min.apply(null,c.map(u=>u.left)):r=Math.max.apply(null,c.map(u=>u.bottom)),r):NaN}}function Qr(o,t,e){let n=Ed(t);n&&qr(t);let s=t.clientLayout.getElementClientRect(o);n&&Kr(t);let i=t.getComputedMargin(o);return e?s.width+i.left+i.right:s.height+i.top+i.bottom}function Hn(o){for(;o;){if(o.parentNode===o.ownerDocument)return!1;o=o.parentNode}return!0}function ll(o,t){var e;if(o)for(let n=o.lastChild,s=n;n!==t;n=s)s=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((e=t.style)==null?void 0:e.display)==="inline")&&o.removeChild(n)}var Tn="data-adapt-spec";function cl(o){return!!o.getAttribute(Tn)}function Ss(o){var n;if((o==null?void 0:o.nodeType)!==1)return!1;let t=o;if(cl(t))return!0;let e=(n=t.style)==null?void 0:n.position;return e==="absolute"||e==="fixed"}function zn(o){let t=o==null?void 0:o.viewNode;return(t==null?void 0:t.nodeType)===1&&cl(t)}function Jg(o){return o!=="inline"&&(_t(o)||al(o))}function Td(o){var t;for(let e=o.parent;e;e=e.parent)if((e.display!=="inline"||e.vertical!==((t=e.parent)==null?void 0:t.vertical))&&_t(e.display))return e;return null}var oi=class{calculateOffset(t){return Es(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function Es(o,t){return{current:t.reduce((e,n)=>e+n.calculateOffset(o),0),minimum:t.reduce((e,n)=>e+n.calculateMinimumOffset(o),0)}}var wn=class extends oi{constructor(e,n,s,i){super();this.position=e;this.breakOnEdge=n;this.overflows=s;this.computedBlockSize=i;p(this,"overflowIfRepetitiveElementsDropped");p(this,"isEdgeUpdated",!1);p(this,"edge",0);this.overflowIfRepetitiveElementsDropped=s}findAcceptableBreak(e,n){return this.updateOverflows(e),n<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(Ki(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var s;let n=e.calculateClonedPaddingBorder(this.position);if(this.edge=xs(this.position,e.clientLayout,0,e.vertical)+n,!this.position.after&&!this.position.inline){let i=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*i}else if(this.position.after&&((s=this.position.shadowContext)==null?void 0:s.root.id)==="table-cell"){let i=e.element.parentElement,r=i==null?void 0:i.closest("table, [style*='display: table;']");if(r){let a=r.style.borderCollapse==="collapse",l=0,c=0;for(let u=i;u;u=u.parentElement){let d=e.clientLayout.getElementComputedStyle(u);if((u===i||u===r&&!a)&&(l+=e.parseComputedLength(d.paddingBlockEnd)),u===r&&!a&&(l+=e.parseComputedLength(d.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),a?c=Math.max(c,e.parseComputedLength(d.borderBlockEndWidth)):(u===i||u===r)&&(c+=e.parseComputedLength(d.borderBlockEndWidth)),u===r)break}this.edge+=(e.vertical?-1:1)*(l+c)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let n=this.edge,s=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(n+(e.vertical?-1:1)*s.minimum),this.overflows=this.position.overflow=e.isOverflown(n+(e.vertical?-1:1)*s.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:n}=e.parent;if(!vn.isInstanceOfRepetitiveElementsOwnerFormattingContext(n))return!1;let s=n.getRepetitiveElements();return s?s.isFirstContentNode(e):!1}};var vs=class{find(t){let e=Ze("RESOLVE_LAYOUT_PROCESSOR");for(let n=0;n<e.length;n++){let s=e[n](t);if(s)return s}throw new Error(`No processor found for a formatting context: ${t.getName()}`)}},Pn=class{layout(t,e,n){return e.isFloatNodeContext(t)?e.layoutFloatOrFootnote(t):e.isBreakable(t)?e.layoutBreakableBlock(t):e.layoutUnbreakable(t)}createEdgeBreakPosition(t,e,n,s){return new wn(t.copy(),e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return!1}clearOverflownViewNodes(t,e,n,s){var a;if(!n.viewNode||!n.viewNode.parentNode||n.shadowType===Yt.ShadowType.ROOTLESS&&zn(n))return;let i=n.viewNode;((a=i.parentElement)==null?void 0:a.localName)==="viv-ts-inner"&&(i=i.parentElement.parentElement);let r=i.parentNode;ll(r,i),s&&r.removeChild(i)}finishBreak(t,e,n,s){let i=n||e.viewNode!=null&&e.viewNode.nodeType==1&&!e.after;return t.clearOverflownViewNodes(e,i),s&&t.layoutContext.processFragmentedBlockEdge(e),T(!0)}},er=class{constructor(t){this.parent=t;p(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}saveState(){}restoreState(t){}},Jr=new Pn,em=Ya.isInstanceOfBlockFormattingContext;Ke("RESOLVE_FORMATTING_CONTEXT",(o,t,e,n,s,i)=>{let r=o.parent;return!r&&o.formattingContext||r&&o.formattingContext!==r.formattingContext?null:o.establishesBFC||!o.formattingContext&&rl(e,n,s,i)?new er(r?r.formattingContext:null):null});Ke("RESOLVE_LAYOUT_PROCESSOR",o=>o instanceof er?Jr:null);var Ns=class{constructor(){p(this,"initialBreakPositions",null);p(this,"initialStateOfFormattingContext",null);p(this,"initialPosition");p(this,"initialFragmentLayoutConstraints")}layout(t,e){return this.prepareLayout(t,e),this.tryLayout(t,e)}tryLayout(t,e){let n=A("AbstractLayoutRetryer.tryLayout");this.saveState(t,e);let s=this.resolveLayoutMode(t);return s.doLayout(t,e).then(i=>{let r=s.accept(i,e);r=s.postLayout(i,this.initialPosition,e,r),r?n.finish(i):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(t,e),this.tryLayout(this.initialPosition,e).thenFinish(n))}),n.result()}prepareLayout(t,e){}clearNodes(t){let e=t.viewNode||t.parent.viewNode,n;for(;n=e.lastChild;)e.removeChild(n);let s;for(;s=e.nextSibling;)s.parentNode.removeChild(s)}saveState(t,e){this.initialPosition=t.copy(),this.initialBreakPositions=[].concat(e.breakPositions),this.initialFragmentLayoutConstraints=[].concat(e.fragmentLayoutConstraints),t.formattingContext&&(this.initialStateOfFormattingContext=t.formattingContext.saveState())}restoreState(t,e){e.breakPositions=this.initialBreakPositions,e.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,t.formattingContext&&t.formattingContext.restoreState(this.initialStateOfFormattingContext)}};var kd=class{initialState(t){return{nodeContext:t,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(t){}afterNonDisplayableNode(t){}startIgnoredTextNode(t){}afterIgnoredTextNode(t){}startNonElementNode(t){}afterNonElementNode(t){}startInlineElementNode(t){}afterInlineElementNode(t){}startNonInlineElementNode(t){}afterNonInlineElementNode(t){}finish(t){}},ai=class{constructor(t,e){this.strategy=t;this.layoutContext=e}iterate(t){let e=this.strategy,n=e.initialState(t),s=A("LayoutIterator");return s.loopWithFrame(i=>{let r;for(;n.nodeContext;){n.nodeContext.viewNode?n.nodeContext.viewNode.nodeType!==1?Ce(n.nodeContext.viewNode,n.nodeContext.whitespace)?n.nodeContext.after?r=e.afterIgnoredTextNode(n):r=e.startIgnoredTextNode(n):n.nodeContext.after?r=e.afterNonElementNode(n):r=e.startNonElementNode(n):n.nodeContext.inline?n.nodeContext.after?r=e.afterInlineElementNode(n):r=e.startInlineElementNode(n):n.nodeContext.after?r=e.afterNonInlineElementNode(n):r=e.startNonInlineElementNode(n):n.nodeContext.after?r=e.afterNonDisplayableNode(n):r=e.startNonDisplayableNode(n);let l=(r&&r.isPending()?r:T(!0)).thenAsync(()=>n.break?T(null):this.layoutContext.nextInTree(n.nodeContext,n.atUnforcedBreak));if(l.isPending()){l.then(c=>{n.break?i.breakLoop():(n.nodeContext=c,i.continueLoop())});return}else if(n.break){i.breakLoop();return}else n.nodeContext=l.get()}e.finish(n),i.breakLoop()}).then(()=>{s.finish(n.nodeContext)}),s.result()}},Wn=class extends kd{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,n){let s=!e.leadingEdge&&He(e.breakAtTheEdge);if(s){let i=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;i.viewNode.parentNode.removeChild(i.viewNode),n.pageBreakType=e.breakAtTheEdge}return s}saveEdgeAndProcessOverflow(e,n){let s=n.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return s&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),s}processLayoutConstraint(e,n,s){let i=e.nodeContext,r=!n.allowLayout(i);return r&&(s.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),i=e.nodeContext=i.modify(),i.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=ze(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let n,s;return e.onStartEdges?(n=this.endEmptyNonInlineBox(e),s=n&&n.isPending()?n:T(!0),s=s.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),T(!0)))):(n=this.endNonInlineBox(e),s=n&&n.isPending()?n:T(!0)),s.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=ze(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}};var dl=[];function nm(){dl=[]}function Rd(o,t,e){return o-=e,t===0?o===0:o%t===0&&o/t>=0}var Ad=class{constructor(t){this.matchers=t}matches(){return this.matchers.some(t=>t.matches())}},Ld=class{constructor(t){this.matchers=t}matches(){return this.matchers.every(t=>t.matches())}},tr=class tr{constructor(t,e,n){this.elementOffset=t;this.a=e;this.b=n}static registerFragmentIndex(t,e,n){let s=tr.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:e,priority:n})}static clearFragmentIndices(){tr.fragmentIndices={}}matches(){let t=tr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Rd(t.fragmentIndex,this.a,this.b)}};p(tr,"fragmentIndices",{});var Ts=tr,li=class{static buildViewConditionMatcher(t,e){let n=e.split("_");return n[0]=="NFS"?new Ts(t,parseInt(n[1],10),parseInt(n[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new Ld(t)}static buildAnyMatcher(t){return new Ad(t)}};var bp={"border-collapse":!0,"border-spacing":!0,"caption-side":!0,"clip-rule":!0,color:!0,"color-interpolation":!0,"color-rendering":!0,cursor:!0,direction:!0,"empty-cells":!0,fill:!0,"fill-opacity":!0,"fill-rule":!0,"font-kerning":!0,"font-size":!0,"font-size-adjust":!0,"font-family":!0,"font-feature-settings":!0,"font-style":!0,"font-stretch":!0,"font-variant-ligatures":!0,"font-variant-caps":!0,"font-variant-numeric":!0,"font-variant-east-asian":!0,"font-weight":!0,"glyph-orientation-vertical":!0,"hanging-punctuation":!0,hyphens:!0,"hyphenate-character":!0,"hyphenate-limit-chars":!0,"hyphenate-limit-last":!0,"image-rendering":!0,"image-resolution":!0,"letter-spacing":!0,"line-break":!0,"line-height":!0,"list-style-image":!0,"list-style-position":!0,"list-style-type":!0,marker:!0,"marker-end":!0,"marker-mid":!0,"marker-start":!0,orphans:!0,"overflow-wrap":!0,"paint-order":!0,"pointer-events":!0,quotes:!0,"ruby-align":!0,"ruby-position":!0,"shape-rendering":!0,stroke:!0,"stroke-dasharray":!0,"stroke-dashoffset":!0,"stroke-linecap":!0,"stroke-linejoin":!0,"stroke-miterlimit":!0,"stroke-opacity":!0,"stroke-width":!0,"tab-size":!0,"text-align":!0,"text-align-last":!0,"text-anchor":!0,"text-autospace":!0,"text-decoration-skip":!0,"text-decoration-skip-ink":!0,"text-emphasis-color":!0,"text-emphasis-position":!0,"text-emphasis-style":!0,"text-fill-color":!0,"text-combine-upright":!0,"text-indent":!0,"text-justify":!0,"text-orientation":!0,"text-rendering":!0,"text-shadow":!0,"text-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-offset":!0,"text-underline-position":!0,"text-wrap":!0,"text-wrap-mode":!0,"text-wrap-style":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},xy=["image-resolution","orphans","widows"];function rm(){return Ze("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(xy))}var Sy={"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},Bd=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Ey=["max-%","min-%","%"],im=(()=>{let o=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let e=0;e<Bd.length;e++)for(let n=0;n<o.length;n++){let s=Bd[e].replace("%",o[n]);t[s]=!0}return t})();function or(o,t){let e={};for(let n of Bd)for(let s in o){let i=n.replace("%",s),r=n.replace("%",o[s]);e[i]=r,e[r]=i}for(let n of Ey)for(let s in t){let i=n.replace("%",s),r=n.replace("%",t[s]);e[i]=r,e[r]=i}return e}var yp=or({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),xp=or({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),vy=or({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Ny=or({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Ty=or({inside:"right",outside:"left"},{}),wy=or({inside:"left",outside:"right"},{}),I=class o{constructor(t,e){this.value=t;this.priority=e}getBaseValue(){return this}filterValue(t){let e=this.value.visit(t);return e===this.value?this:new o(e,this.priority)}increaseSpecificity(t){return t==0?this:new o(this.value,this.priority+t)}evaluate(t,e,n,s){return e&&Nt(e)?this.value:ao(t,this.value,e,n,s)}isEnabled(t){return!0}},to=class o extends I{constructor(e,n,s){super(e,n);this.condition=s}getBaseValue(){return new I(this.value,this.priority)}filterValue(e){let n=this.value.visit(e);return n===this.value?this:new o(n,this.priority,this.condition)}increaseSpecificity(e){return e==0?this:new o(this.value,this.priority+e,this.condition)}isEnabled(e){try{return!!this.condition.evaluate(e)}catch(n){F.warn(n)}return!1}};function Od(o,t,e){return(!t||e.priority>=t.priority)&&e.isEnabled(o)?e.getBaseValue():t}function kn(o,t,e,n){if(o)if(!e)delete o[t];else{let s=o[t];(!s||e.priority>=s.priority)&&(n?e.isEnabled(n)&&(o[t]=e.getBaseValue()):o[t]=e)}}var om={"region-id":!0,"fragment-selector-id":!0};function Py(o){return!!om[o]}function hl(o){return o.charAt(0)==="_"&&o!=="_viewConditionalStyles"}function ws(o){return o.charAt(0)!=="_"&&!om[o]}function As(o){return!!bp[o]||Nt(o)}function de(o,t){return o[t]}function Xn(o,t,e){e?o[t]=e:delete o[t]}function Pt(o,t){return o[t]}function di(o,t){let e=o[t];return e||(e={},o[t]=e),e}var am=o=>{let t=o._viewConditionalStyles;return t||(t=[],o._viewConditionalStyles=t),t};function Sp(o,t){return o[t]}function lm(o,t){let e=o[t];return e||(e=[],o[t]=e),e}function oo(o,t,e,n,s,i,r){var l,c;if([{id:s,styleKey:"_pseudos"},{id:i,styleKey:"_regions"}].forEach(u=>{if(u.id){let d=di(t,u.styleKey);t=d[u.id],t||(t={},d[u.id]=t)}}),r){let u=am(t);t={},u.push({styles:t,matcher:r})}for(let u in e)if(!hl(u))if(Py(u)){let d=Sp(e,u),h=lm(t,u);Array.prototype.push.apply(h,d)}else{let d=de(e,u);if(!d.isEnabled(o))continue;let h=d.increaseSpecificity(n);kn(t,u,h,o);let f=(c=(l=o.style)==null?void 0:l.validatorSet.shorthands[u])==null?void 0:c.propList;if(f)for(let g of f){let m=new I(H,h.priority);kn(t,g,m,o)}}}function cm(o,t){let e={};for(let n=0;n<t.length;n++)oo(o,e,t[n],0,null,null,null);return e}function Ep(o,t){if(o.length>0){o.sort((n,s)=>s.getPriority()-n.getPriority());let e=null;for(let n=o.length-1;n>=0;n--)e=o[n],e.chained=t,t=e;return e}return t}var fl=class extends $t{constructor(e,n){super();this.props=e;this.context=n;p(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=de(this.props,"font-size");if(!e.value.isNumeric())return Je.em;let n=e.value;if(!zf(n.unit))throw new Error("Unexpected state");return n.num*Je[n.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Tl(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Nl(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?ao(this.context,e,this.propName).visit(this):e}};function Nl(o,t,e){let n=o.unit,s=o.num;return n==="em"?new P(s*t,"px"):n==="rem"?new P(s*e.fontSize(),"px"):n==="rlh"?new P(s*e.rootLineHeight,"px"):o}function Tl(o,t,e){o=Nl(o,t,e);let n=o.unit,s=o.num;return n==="px"?o:n==="%"?new P(s/100*t,"px"):new P(s*e.queryUnitSize(n,!1),"px")}var $n=class{apply(t){}mergeWith(t){return new Dd([this,t])}clone(){return this}},sr=class extends $n{constructor(e){super();this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Dd=class o extends $n{constructor(e){super();this.list=e}apply(e){for(let n=0;n<this.list.length;n++)this.list[n].apply(e)}mergeWith(e){return this.list.push(e),this}clone(){return new o([].concat(this.list))}},ui=class extends $n{constructor(e,n,s,i,r){super();this.style=e;this.specificity=n;this.pseudoelement=s;this.regionId=i;this.viewConditionId=r}apply(e){oo(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ie=class extends $n{constructor(){super();p(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Md=class extends ie{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}},_d=class extends ie{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}},gl=class extends ie{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}},Ud=class extends ie{constructor(e,n){super();this.ns=e;this.localName=n}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let n=e.nsPrefix[this.ns];n||(n=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=n);let s=n+this.localName;e.insertInTable(e.nstags,s,this.chained)}return!0}},Hd=class extends ie{constructor(e,n){super();this.epubTypePatt=e;this.targetLocalName=n}apply(e){let n=e.currentElement;if(n instanceof HTMLAnchorElement&&n.hash&&n.href==n.baseURI.replace(/#.*$/,"")+n.hash){let s=n.hash.substring(1),i=n.ownerDocument.getElementById(s);if(i&&(!this.targetLocalName||i.localName==this.targetLocalName)){let r=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},zd=class extends ie{constructor(e){super();this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function wl(o,t,e,n){if(!o)return!1;if(t!==null)return n(o,t,e);for(let s of o.getAttributeNames())if((s===e||s.endsWith(`:${e}`))&&n(o,s===e?"":o.lookupNamespaceURI(s.split(":")[0]),e))return!0;return!1}var ml=class extends ie{constructor(e,n){super();this.ns=e;this.name=n}apply(e){wl(e.currentElement,this.ns,this.name,(n,s,i)=>n.hasAttributeNS(s,i))&&this.chained.apply(e)}},Gd=class extends ie{constructor(e,n,s){super();this.ns=e;this.name=n;this.value=s}apply(e){wl(e.currentElement,this.ns,this.name,(n,s,i)=>n.getAttributeNS(s,i)==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}},Wd=class extends ie{constructor(e,n){super();this.ns=e;this.name=n}apply(e){wl(e.currentElement,this.ns,this.name,(n,s,i)=>!!Sy[n.getAttributeNS(s,i)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},ci=class extends ie{constructor(e,n,s){super();this.ns=e;this.name=n;this.regexp=s}apply(e){wl(e.currentElement,this.ns,this.name,(n,s,i)=>{var r;return!!((r=n.getAttributeNS(s,i))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},Xd=class extends ie{constructor(e){super();this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Cl=class extends ie{constructor(){super()}apply(t){t.isFirst&&this.chained.apply(t)}getPriority(){return 6}},$d=class extends ie{constructor(){super()}apply(t){t.isRoot&&this.chained.apply(t)}getPriority(){return 12}},An=class extends ie{constructor(e,n){super();this.a=e;this.b=n}matchANPlusB(e){return Rd(e,this.a,this.b)}},jd=class extends An{constructor(t,e){super(t,e)}apply(t){this.matchANPlusB(t.currentSiblingOrder)&&this.chained.apply(t)}getPriority(){return 5}},no=class extends An{constructor(t,e){super(t,e)}apply(t){let e=t.currentSiblingTypeCounts[t.currentNamespace][t.currentLocalName];this.matchANPlusB(e)&&this.chained.apply(t)}getPriority(){return 5}},so=class extends An{constructor(t,e){super(t,e)}apply(t){let e=t.currentFollowingSiblingOrder;e===null&&(e=t.currentFollowingSiblingOrder=t.currentElement.parentNode.childElementCount-t.currentSiblingOrder+1),this.matchANPlusB(e)&&this.chained.apply(t)}getPriority(){return 4}},io=class extends An{constructor(t,e){super(t,e)}apply(t){let e=t.currentFollowingSiblingTypeCounts;if(!e[t.currentNamespace]){let n=t.currentElement;do{let s=n.namespaceURI,i=n.localName,r=e[s];r||(r=e[s]={}),r[i]=(r[i]||0)+1}while(n=n.nextElementSibling)}this.matchANPlusB(e[t.currentNamespace][t.currentLocalName])&&this.chained.apply(t)}getPriority(){return 4}},Yd=class extends ie{constructor(){super()}apply(t){let e=t.currentElement.firstChild;for(;e;){switch(e.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(e.length>0)return}e=e.nextSibling}this.chained.apply(t)}getPriority(){return 4}},Kd=class extends ie{constructor(){super()}apply(t){t.currentElement.disabled===!1&&this.chained.apply(t)}getPriority(){return 5}},qd=class extends ie{constructor(){super()}apply(t){t.currentElement.disabled===!0&&this.chained.apply(t)}getPriority(){return 5}},Zd=class extends ie{constructor(){super()}apply(t){let e=t.currentElement;(e.selected===!0||e.checked===!0)&&this.chained.apply(t)}getPriority(){return 5}},Ge=class extends ie{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}},bl=class o extends $n{constructor(){super();p(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new o;return e.applied=this.applied,e}},ro=class extends ie{constructor(e){super();p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new bl;for(let n of e)this.firstActions.push(Ep(n,this.checkAppliedAction))}apply(e){for(let n of this.firstActions)if(n.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 ie?e.getPriority():0))}positive(){return!0}relational(){return!1}},Qd=class extends ro{positive(){return!1}},Jd=class extends ro{constructor(e){super([]);this.selectorTexts=e}apply(e){for(let n of this.selectorTexts){let s,i;/^\s*[+~]/.test(n)?(i=e.currentElement.parentNode,s=`:scope > :nth-child(${Array.from(i.children).indexOf(e.currentElement)+1}) ${n}`):(i=e.currentElement,s=`:scope ${n}`);try{if(i.querySelector(s)){this.checkAppliedAction.apply(e);break}}catch(r){}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},yl=class extends An{constructor(e,n,s){super(e,n);p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new bl;for(let i of s)this.firstActions.push(Ep(i,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let n=e.currentElement,s=1,i=n.previousElementSibling;for(;i;)this.matchesSelector(i,e)&&s++,i=i.previousElementSibling;this.matchANPlusB(s)&&this.chained.apply(e)}matchesSelector(e,n){let s=n.currentElement,i=n.currentNamespace,r=n.currentLocalName,a=n.currentId,l=n.currentClassNames,c=n.currentSiblingOrder;n.currentElement=e,n.currentNamespace=e.namespaceURI||"",n.currentLocalName=e.localName,n.currentId=e.id,n.currentClassNames=e.classList?Array.from(e.classList):[];let u=1,d=e.previousElementSibling;for(;d;)u++,d=d.previousElementSibling;n.currentSiblingOrder=u;for(let f of this.firstActions)if(f.apply(n),this.checkAppliedAction.applied)break;let h=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,n.currentElement=s,n.currentNamespace=i,n.currentLocalName=r,n.currentId=a,n.currentClassNames=l,n.currentSiblingOrder=c,h}getPriority(){return 5}},ep=class extends yl{constructor(t,e,n){super(t,e,n)}apply(t){for(let i of this.firstActions)if(i.apply(t),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let e=t.currentElement,n=1,s=e.nextElementSibling;for(;s;)this.matchesSelector(s,t)&&n++,s=s.nextElementSibling;this.matchANPlusB(n)&&this.chained.apply(t)}getPriority(){return 4}},ir=class{constructor(t,e,n){this.condition=t;this.viewConditionId=e;this.viewCondition=n}increment(t){t.increment(this.condition,this.viewCondition)}decrement(t){t.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(t){return t.buildViewConditionMatcher(this.viewConditionId)}},tp=class o extends ir{constructor(t,e,n){super(t,e,n)}fresh(t){return new o(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,e){return e==0&&this.increment(t),!1}pop(t,e){return e==0?(this.decrement(t),!0):!1}},np=class o extends ir{constructor(t,e,n){super(t,e,n)}fresh(t){return new o(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,e){return e==0?this.increment(t):e==1&&this.decrement(t),!1}pop(t,e){return e==0?(this.decrement(t),!0):(e==1&&this.increment(t),!1)}},sp=class o extends ir{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new o(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,n){return this.fired?(this.decrement(e),!0):!1}pop(e,n){return this.fired?(this.decrement(e),!0):(n==0&&(this.fired=!0,this.increment(e)),!1)}},ip=class o extends ir{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new o(this.condition,this.viewConditionId,this.buildViewConditionMatcher(e))}push(e,n){return this.fired&&(n==-1?this.increment(e):n==0&&this.decrement(e)),!1}pop(e,n){if(this.fired){if(n==-1)return this.decrement(e),!0;n==0&&this.increment(e)}else n==0&&(this.fired=!0,this.increment(e));return!1}},rp=class{constructor(t,e){this.afterprop=t;this.element=e}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.processPseudoelementProps(this.afterprop,this.element),!0):!1}},op=class{constructor(t){this.lang=t}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.lang=this.lang,!0):!1}},ap=class{constructor(t){this.oldQuotes=t}fresh(t){return this}push(t,e){return!1}pop(t,e){return e==0?(t.quotes=this.oldQuotes,!0):!1}},lp=class extends $t{constructor(e){super();this.element=e}createValueFromString(e,n){switch(n){case"url":return e?new ge(e):new ge("about:invalid");case"string":default:return e?new M(e):new M("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let n="string",s=null,i=null;if(e.values[0]instanceof G){let r=e.values[0].values;r.length>=2&&(n=r[1].stringValue()),s=r[0].stringValue()}else s=e.values[0].stringValue();return e.values.length>1?i=this.createValueFromString(e.values[1].stringValue(),n):i=this.createValueFromString(null,n),this.element&&this.element.hasAttribute(s)?this.createValueFromString(this.element.getAttribute(s),n):i}};function eo(o){if(ht(o)){if(o instanceof M)return o.stringValue();if(o instanceof G)return o.values.map(t=>eo(t)).join("")}return""}var rr=class extends $t{constructor(e,n,s){super();this.cascade=e;this.element=n;this.counterResolver=s}visitIdent(e){let n=this.cascade,s=n.quotes,i=Math.floor(s.length/2)-1;switch(e.name){case"open-quote":{let r=s[2*Math.min(i,n.quoteDepth)];return n.quoteDepth++,r}case"close-quote":return n.quoteDepth>0&&n.quoteDepth--,s[2*Math.min(i,n.quoteDepth)+1];case"no-open-quote":return n.quoteDepth++,new M("");case"no-close-quote":return n.quoteDepth>0&&n.quoteDepth--,new M("")}return e}format(e,n){return this.cascade.counterStyleStore.format(n,e)}visitFuncCounter(e){let n=e[0].toString(),s=e.length>1?e[1].stringValue():"decimal",i=this.cascade.counters[n];if(i&&i.length){let r=i&&i.length&&i[i.length-1]||0;return new M(this.format(r,s))}else{let r=new D(this.counterResolver.getPageCounterVal(n,a=>this.format(a||0,s)));return new G([r])}}visitFuncCounters(e){let n=e[0].toString(),s=e[1].stringValue(),i=e.length>2?e[2].stringValue():"decimal",r=this.cascade.counters[n],a=new st;if(r&&r.length)for(let c=0;c<r.length;c++)c>0&&a.append(s),a.append(this.format(r[c],i));let l=new D(this.counterResolver.getPageCountersVal(n,c=>{let u=[];if(c.length)for(let h=0;h<c.length;h++)u.push(this.format(c[h],i));let d=a.toString();return d.length&&u.push(d),u.length?u.join(s):this.format(0,i)}));return new G([l])}visitFuncTargetCounter(e){let n=e[0],s;n instanceof ge?s=n.url:s=n.stringValue();let i=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",a=new D(this.counterResolver.getTargetCounterVal(s,i,l=>this.format(l||0,r)));return new G([a])}visitFuncTargetCounters(e){let n=e[0],s;n instanceof ge?s=n.url:s=n.stringValue();let i=e[1].toString(),r=e[2].stringValue(),a=e.length>3?e[3].stringValue():"decimal",l=new D(this.counterResolver.getTargetCountersVal(s,i,c=>{let u=c.map(d=>this.format(d,a));return u.length?u.join(r):this.format(0,a)}));return new G([l])}visitFuncTargetText(e){let n=e[0],s;n instanceof ge?s=n.url:s=n.stringValue();let i=e.length>1?e[1].stringValue():"content",r=new D(this.counterResolver.getTargetTextVal(s,i));return new G([r])}visitFuncString(e){let n=e.length>0?e[0].stringValue():"",s=e.length>1?e[1].stringValue():"first";return new D(this.counterResolver.getNamedStringVal(n,s))}visitFuncElement(e){let n=e.length>0?e[0].stringValue():"",s=e.length>1?e[1].stringValue():"first";return new D(this.counterResolver.getRunningElementVal(n,s))}visitFuncContent(e){var i,r,a,l,c,u;let n=e.length>0?e[0].stringValue():"text",s="";switch(n){case"text":s=this.element.textContent;break;case"before":case"after":case"marker":{let d=Pt(this.cascade.currentStyle,"_pseudos"),h=(r=(i=d==null?void 0:d[n])==null?void 0:i.content)==null?void 0:r.value;s=eo(h)}break;case"first-letter":{let d=Pt(this.cascade.currentStyle,"_pseudos"),h=(eo((l=(a=d==null?void 0:d.before)==null?void 0:a.content)==null?void 0:l.value)||this.element.textContent||eo((u=(c=d==null?void 0:d.after)==null?void 0:c.content)==null?void 0:u.value)).match(_s);s=h?h[0]:""}break}return new M(s)}visitFuncLeader(e){let n="";if(e[0]instanceof Y)switch(e[0].stringValue()){case"dotted":n=".";break;case"solid":n="_";break;case"space":n=" ";break}else e[0]instanceof M&&(n=e[0].stringValue());return n.length==0?new M(""):new D(new ne(null,()=>n,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function Vd(o,t,e){let n;if(o.nodeType===1)n=Array.from(o.getClientRects());else{let i=o.ownerDocument.createRange();i.selectNodeContents(o),n=t.getRangeClientRects(i)}return n.reduce((i,r)=>i+(e==="vertical-rl"||e==="vertical-lr"?r.height:r.width),0)}var ky=(o,t,e)=>{let n=t.filter(l=>l.after&&l.viewNode.nodeType===1&&l.viewNode.getAttribute("data-viv-leader"));for(let l of n){let S=function(_){m==="rtl"?u.textContent=(_.startsWith("\u200F")?"":"\u200F")+_+(_.endsWith("\u200F")?"":"\u200F"):u.textContent=_},je=function(){let _=e.clientLayout.getElementClientRect(d);return g==="vertical-rl"||g==="vertical-lr"?m==="rtl"?_.top-=K:_.bottom+=K:m==="rtl"?_.left-=K:_.right+=K,v.left>_.left||v.right<_.right||v.top>_.top||v.bottom<_.bottom},lt=function(){let _,B,W=f.repeat(1e4);if(S(W),je())_=1,B=1e4;else return;for(let q=0;q<16;q++){let fe="",Gt=Math.floor((_+B)/2);for(let es=0;es<Gt;es++)fe+=f;if(S(fe),je())B=Gt;else{if(_==Gt)return;_=Gt}}S(f)},At=function(_){let B=0,W=d.parentElement;for(;W&&W!==c.viewNode;)B+=e.getComputedInsets(W)[_],W=W.parentElement;return B};var s=S,i=je,r=lt,a=At;let c=l.parent;for(;c&&c.inline;)c=c.parent;let u=l.viewNode,d=u.parentElement,h=d.getAttribute("data-adapt-pseudo"),f=u.getAttribute("data-viv-leader-value"),{writingMode:g,direction:m,marginInlineEnd:y}=e.clientLayout.getElementComputedStyle(d);u.style.marginInlineStart="1px",S(f),d.style.display="inline-block",d.style.textIndent="0";let C=Zr(c.viewNode),x=(C==null?void 0:C.style.columnFill)||null;C&&(C.style.columnFill="auto");let v=e.clientLayout.getElementClientRect(c.viewNode),E=e.clientLayout.getElementClientRect(d),N=e.parseComputedLength(y),L=[],O=d.parentElement;for(;O.parentElement&&O.parentElement!==c.viewNode;)O=O.parentElement;let z=O.nextSibling;for(;z;){if(z.nodeType===1){let _=z,{display:B,float:W,position:q}=e.clientLayout.getElementComputedStyle(_);if(W!=="none"||q==="absolute"||q==="fixed"){z=z.nextSibling;continue}if(_t(B))L.push(_);else if(jg(B))break}else if(z.nodeType===3){let _=z;_.length>0&&L.push(_)}z=z.nextSibling}let K=L.reduce((_,B)=>_+Vd(B,e.clientLayout,g),0);if(h!=="after"){let _=Vd(O,e.clientLayout,g),B=Vd(d,e.clientLayout,g);K+=_-B}g==="vertical-rl"||g==="vertical-lr"?(m==="rtl"?v.top+=N:v.bottom-=N,v.top=Math.min(E.top,v.top),v.bottom=Math.max(E.bottom,v.bottom)):(m==="rtl"?v.left+=N:v.right-=N,v.left=Math.min(E.left,v.left),v.right=Math.max(E.right,v.right)),lt();let Ye=e.clientLayout.getElementClientRect(d);m=="rtl"?d.style.float="left":d.style.float="right";let ct=e.clientLayout.getElementClientRect(d),R=0;m=="rtl"?g=="vertical-rl"||g=="vertical-lr"?R=Ye.top-ct.top-At("top"):R=Ye.left-ct.left-At("left"):g=="vertical-rl"||g=="vertical-lr"?R=ct.bottom-Ye.bottom-At("bottom"):R=ct.right-Ye.right-At("right"),R-=K,R=Math.max(0,R-.1),d.style.float="",u.style.marginInlineStart=`${R}px`,C&&(x?C.style.columnFill=x:C.style.removeProperty("column-fill"))}};Ke("POST_LAYOUT_BLOCK",ky);var vp=1/1048576;function nr(o,t){for(let e in o)t[e]=o[e].clone()}var cp=class o{constructor(){p(this,"nsCount",0);p(this,"nsPrefix",{});p(this,"tags",{});p(this,"nstags",{});p(this,"epubtypes",{});p(this,"classes",{});p(this,"ids",{});p(this,"pagetypes",{});p(this,"order",0)}clone(){let t=new o;t.nsCount=this.nsCount;for(let e in this.nsPrefix)t.nsPrefix[e]=this.nsPrefix[e];return nr(this.tags,t.tags),nr(this.nstags,t.nstags),nr(this.epubtypes,t.epubtypes),nr(this.classes,t.classes),nr(this.ids,t.ids),nr(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,e,n){let s=t[e];s&&(n=s.mergeWith(n)),t[e]=n}createInstance(t,e,n,s,i,r){return new up(this,t,e,n,s,i,r)}nextOrder(){return this.order+=vp}},up=class{constructor(t,e,n,s,i,r,a){this.context=e;this.counterListener=n;this.counterResolver=s;this.counterStyleStore=r;this.cmykStore=a;p(this,"code");p(this,"stack",[[],[]]);p(this,"conditions",{});p(this,"currentElement",null);p(this,"currentElementOffset",null);p(this,"currentStyle",null);p(this,"currentClassNames",null);p(this,"currentLocalName","");p(this,"currentNamespace","");p(this,"currentId","");p(this,"currentXmlId","");p(this,"currentNSTag","");p(this,"currentEpubTypes",null);p(this,"currentPageType",null);p(this,"previousPageType",null);p(this,"firstPageType",null);p(this,"pageTypePageCounts",{});p(this,"isFirst",!0);p(this,"isRoot",!0);p(this,"counters",{});p(this,"counterScoping",[{}]);p(this,"quotes");p(this,"quoteDepth",0);p(this,"lang","");p(this,"siblingOrderStack",[0]);p(this,"currentSiblingOrder",0);p(this,"siblingTypeCountsStack",[{}]);p(this,"currentSiblingTypeCounts");p(this,"currentFollowingSiblingOrder",null);p(this,"followingSiblingOrderStack");p(this,"followingSiblingTypeCountsStack",[{}]);p(this,"currentFollowingSiblingTypeCounts");p(this,"viewConditions",{});p(this,"dependentConditions",[]);p(this,"elementStack");this.code=t,this.quotes=[new M("\u201C"),new M("\u201D"),new M("\u2018"),new M("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,e){this.conditions[t]=(this.conditions[t]||0)+1,e&&(this.viewConditions[t]?this.viewConditions[t].push(e):this.viewConditions[t]=[e])}decrement(t,e){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==e),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let e=null;t&&(this.currentElementOffset,e=li.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(s=>{let i=this.viewConditions[s];return i&&i.length>0?i.length===1?i[0]:li.buildAnyMatcher([].concat(i)):null}).filter(s=>s);return n.length<=0?e:e===null?n.length===1?n[0]:li.buildAllMatcher(n):li.buildAllMatcher([e].concat(n))}applyAction(t,e){let n=t[e];n&&n.apply(this)}pushRule(t,e,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=Fd,this.currentPageType=e,this.applyActions()}defineCounter(t,e){let n=this.counterScoping[this.counterScoping.length-1];n||(n={},this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(e)):this.counters[t]=[e],n[t]=!0}pushCounters(t){var h,f,g,m,y,S,C;let e=b.inline,n=t.display;if(n&&(e=n.evaluate(this.context)),e===b.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 s=b.inline,i=t.float;i&&(s=i.evaluate(this.context));let r=null,a=null,l=null,c=t["counter-reset"];if(c){let x=c.evaluate(this.context);x&&(r=Ys(x,!0))}let u=t["counter-set"];if(u){let x=u.evaluate(this.context);x&&(l=Ys(x,!1))}let d=t["counter-increment"];if(d){let x=d.evaluate(this.context);x&&(a=Ys(x,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(r||(r={}),r["list-item"]=((f=(h=this.currentElement)==null?void 0:h.start)!=null?f:1)-1),Un(e)&&(a||(a={}),a["list-item"]=(g=a["list-item"])!=null?g:1,/^\s*[-+]?\d/.test((y=(m=this.currentElement)==null?void 0:m.getAttribute("value"))!=null?y:"")&&(l||(l={}),l["list-item"]=this.currentElement.value)),((S=this.currentElement)==null?void 0:S.parentNode.nodeType)===Node.DOCUMENT_NODE&&(r||(r={}),r.footnote===void 0&&(r.footnote=0)),s===b.footnote&&(a||(a={}),a.footnote===void 0)){let x=(C=this.currentStyle["counter-increment"])==null?void 0:C.value;(!x||!(x===b.footnote||x instanceof G&&x.values.includes(b.footnote)))&&(a.footnote=1)}if(r)for(let x in r)this.defineCounter(x,r[x]);if(a)for(let x in a){this.counters[x]||this.defineCounter(x,0);let v=this.counters[x];v[v.length-1]+=a[x]}if(l)for(let x in l)if(!this.counters[x])this.defineCounter(x,l[x]);else{let v=this.counters[x];v[v.length-1]=l[x]}if(Un(e)){let x=this.counters["list-item"],v=x[x.length-1];t["ua-list-item-count"]=new I(new Re(v),0);let E=di(t,"_pseudos");E.marker||(E.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let e in t){let n=this.counters[e];n&&(n.length==1?delete this.counters[e]:n.pop())}}setNamedStrings(t){let e=t["string-set"];if(!e)return;e=e.filterValue(new rr(this,this.currentElement,this.counterResolver));let n=e.value instanceof me?e.value.values:[e.value];for(let s of n)if(s instanceof G){let i=s.values[0].stringValue(),r=s.values.slice(1).map(a=>eo(a)).join("");this.counterResolver.setNamedString(i,r,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let e=t.position;if((e==null?void 0:e.value)instanceof vt&&e.value.name==="running"){let n=e.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,e){this.pushCounters(t);let n=t.content;n&&(t.content=n.filterValue(new rr(this,e,this.counterResolver))),this.popCounters()}pushElement(t,e,n,s){var E,N,L;this.currentPageType=null,this.currentElement=e,this.currentElementOffset=s,this.currentStyle=n,this.currentNamespace=e.namespaceURI,this.currentLocalName=e.localName;let i=this.code.nsPrefix[this.currentNamespace];i?this.currentNSTag=i+this.currentLocalName:this.currentNSTag="",this.currentId=e.getAttribute("id"),this.currentXmlId=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let r=e.getAttribute("class");r?this.currentClassNames=r.split(/\s+/):this.currentClassNames=Fd;let a=e.getAttributeNS("http://www.idpf.org/2007/ops","type");a?this.currentEpubTypes=a.split(/\s+/):this.currentEpubTypes=Fd;let l=Er(e);l&&(this.stack[this.stack.length-1].push(new op(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,u=this.siblingOrderStack;this.currentSiblingOrder=++u[u.length-1],u.push(0);let d=this.siblingTypeCountsStack,h=this.currentSiblingTypeCounts=d[d.length-1],f=h[this.currentNamespace];f||(f=h[this.currentNamespace]={}),f[this.currentLocalName]=(f[this.currentLocalName]||0)+1,d.push({});let g=this.followingSiblingOrderStack;g[g.length-1]!==null?this.currentFollowingSiblingOrder=--g[g.length-1]:this.currentFollowingSiblingOrder=null,g.push(null);let m=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=m[m.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,m.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,e),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(e);let S=n.quotes,C=null;if(S){let O=S.evaluate(this.context);O&&(C=new ap(this.quotes),O===b.none?this.quotes=[new M(""),new M("")]:O===b.auto||O===b.initial?this.quotes=[new M("\u201C"),new M("\u201D"),new M("\u2018"),new M("\u2019")]:O instanceof G&&(this.quotes=O.values))}this.pushCounters(this.currentStyle);let x=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(c||x){let O={};Object.keys(this.counters).forEach(z=>{O[z]=Array.from(this.counters[z])}),this.counterListener.countersOfId(x,O)}let v=Pt(this.currentStyle,"_pseudos");if(v){let O=!0;for(let z of Ay){z||(O=!1);let K=v[z];if(K)if((z==="before"||z==="after")&&!ht((E=K.content)==null?void 0:E.value)||z==="marker"&&!Un((N=de(this.currentStyle,"display"))==null?void 0:N.value)||(z==="footnote-call"||z==="footnote-marker")&&((L=de(this.currentStyle,"float"))==null?void 0:L.value)!==b.footnote)delete v[z];else if(O){if(this.processPseudoelementProps(K,e),z==="marker")this.processMarkerPseudoelementProps(K,e,t);else if(z==="first-letter"&&K["initial-letter"]){let lt=K["initial-letter"].evaluate(this.context);lt!==b.normal&&!X(lt)&&(this.currentStyle["--viv-initialLetter"]=new I(lt,0)),delete K["initial-letter"]}}else this.stack[this.stack.length-2].push(new rp(K,e))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}processMarkerPseudoelementProps(t,e,n){var s,i,r,a,l;if(!ht((s=t.content)==null?void 0:s.value)&&Un((i=this.currentStyle.display)==null?void 0:i.value)){let c=this.getInheritedPropertyValue("list-style-type",n,e),u=this.getInheritedPropertyValue("list-style-image",n,e);if(u instanceof ge)t.content=new I(new G([u,new M(" ")]),0);else if(c instanceof M)t.content=new I(c,0);else if(c instanceof Y&&c!==b.none){let d=(a=(r=this.currentStyle["ua-list-item-count"])==null?void 0:r.value)==null?void 0:a.num;d!=null&&(t.content=new I(new M(this.counterStyleStore.formatMarker(c.name,d)),0)),t["list-style-type"]=new I(c,0)}}if(!_t((l=de(this.currentStyle,"display"))==null?void 0:l.value)){let c=this.getInheritedPropertyValue("list-style-position",n,e);c&&(t["list-style-position"]=new I(c,0))}}getInheritedPropertyValue(t,e,n){var i;for(let r=n;r;r=r.parentElement){let l=(r===this.currentElement?this.currentStyle:e.getStyle(r,!1))[t];if(l){let c=l.evaluate(this.context,t);if(c===b.inherit||c===b.unset||c===b.revert)continue;if(c===b.initial)break;return c}}let s=e.validatorSet;return(i=s==null?void 0:s.defaultValues[t])!=null?i:null}applyAttrFilterInner(t,e){for(let n in e)ws(n)&&!Nt(n)&&(e[n]=e[n].filterValue(t))}applyAttrFilter(t){let e=new lp(t),n=this.currentStyle,s=Pt(n,"_pseudos");for(let i in s)this.applyAttrFilterInner(e,s[i]);this.applyAttrFilterInner(e,n)}applyVarFilter(t,e,n){var l,c,u;let s=t[0],i=new Cp(t,e,n),r=32,a={};for(let d in s)if(hl(d)){let h=Pt(s,d);for(let f in h)this.applyVarFilter([h[f],...t],e,n)}else if(ws(d)){let h=de(s,d),f=h.value;for(let g=0;;g++){if(g>=r){f=H;break}let m=f.visit(i);if(i.error){f=H,i.error=!1;break}if(m===f)break;f=m}if(f!==h.value){let g=e.validatorSet,m=(l=g==null?void 0:g.shorthands[d])==null?void 0:l.clone();if(m)if(X(f)){for(let y of m.propList){let S=new I(f,h.priority),C=de(s,y);Xn(a,y,Od(this.context,C,S))}delete s[d]}else{let y=En(e.scope,new Xe(f.toString(),null),"");if(y&&(y.visit(m),!m.error)){for(let S of m.propList){let C=new I((u=(c=m.values[S])!=null?c:g.defaultValues[S])!=null?u:b.initial,h.priority),x=de(s,S);Xn(a,S,Od(this.context,x,C))}delete s[d]}}else s[d]=new I(f,h.priority)}if(a[d]){let g=de(s,d);g&&g.value!==H&&kn(a,d,g,this.context)}}for(let d in a)s[d]=a[d]}applyCalcFilter(t,e){let n=new vl(e);for(let s in t)if(hl(s)){let i=Pt(t,s);for(let r in i)this.applyCalcFilter(i[r],e)}else if(ws(s)&&!Nt(s)){let i=de(t,s),r=i.value.visit(n);r!==i.value&&(t[s]=new I(r,i.priority))}}applyCmykFilter(t,e){let n=new Oi(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),e){let s=n.getConversions();s&&e.setAttribute("data-viv-device-cmyk",JSON.stringify(s))}}applyCmykFilterInternal(t,e,n){for(let s in t)if(hl(s)){let i=Pt(t,s);for(let r in i)this.applyCmykFilterInternal(i[r],e,`::${r}:`)}else if(ws(s)&&!Nt(s)){let i=de(t,s),r=i.value.toString();e.reset();let a=i.value.visit(e);a!==i.value&&(e.hadDeviceCmyk()&&e.recordConversion(n+s,r),t[s]=new I(a,i.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let e=1;e>=-1;--e){let n=this.stack[this.stack.length-e-2];for(t=0;t<n.length;)n[t].push(this,e)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let e=this.stack[this.stack.length-t-2],n=0;for(;n<e.length;)e[n].pop(this,t)?e.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},Fd=[],Ay=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"];var dp=null;function um(o){dp=o}var jn=class extends Sn{constructor(e,n,s,i,r,a,l){super(e,n,l);this.condition=s;this.regionId=r;this.validatorSet=a;p(this,"chain",null);p(this,"specificity",0);p(this,"elementStyle",null);p(this,"conditionCount",0);p(this,"pseudoelement",null);p(this,"footnoteContent",!1);p(this,"cascade");p(this,"state");p(this,"viewConditionId",null);p(this,"insideSelectorRule");p(this,"invalid",!1);this.cascade=i?i.cascade:dp?dp.clone():new cp,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let n=Ep(this.chain,e);n!==e&&n.makePrimary(this.cascade)||this.insertNonPrimary(n)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,n){!n&&!e||(n&&(this.specificity+=1),n&&e?this.chain.push(new Ud(e,n.toLowerCase())):n?this.chain.push(new gl(n.toLowerCase())):this.chain.push(new zd(e)))}invalidSelector(e){F.warn(e),this.chain.push(new Ge("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Ps;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 Md(e))}pseudoclassSelector(e,n){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Kd);break;case"disabled":this.chain.push(new qd);break;case"checked":this.chain.push(new Zd);break;case"root":case"scope":this.chain.push(new $d);break;case"link":this.chain.push(new gl("a")),this.chain.push(new ml("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(n&&n.length>=1&&typeof n[0]=="string"){let s=n[0],i=new RegExp(`(^|\\s)${Vn(s)}($|\\s)`),r=n[1];this.chain.push(new Hd(i,r))}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(n&&n.length==1&&typeof n[0]=="string"){let s=n[0];this.chain.push(new Xd(new RegExp(`^${Vn(s.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 s=Ly[e.toLowerCase()];n&&n.length==2?this.chain.push(new s(n[0],n[1])):this.chain.push(new Ge(""));break}case"first-child":this.chain.push(new Cl);break;case"last-child":this.chain.push(new so(0,1));break;case"first-of-type":this.chain.push(new no(0,1));break;case"last-of-type":this.chain.push(new io(0,1));break;case"only-child":this.chain.push(new Cl),this.chain.push(new so(0,1));break;case"only-of-type":this.chain.push(new no(0,1)),this.chain.push(new io(0,1));break;case"empty":this.chain.push(new Yd);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,n);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,n){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(n&&n.length==1&&typeof n[0]=="number"){let s=Math.round(n[0]);if(s>0&&s==n[0]){if(!this.pseudoelement)this.pseudoelement=`first-${s}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ge(""));break;case"nth-fragment":n&&n.length==2?this.viewConditionId=`NFS_${n[0]}_${n[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 _d(e))}attributeSelector(e,n,s,i){this.specificity+=256,n=n.toLowerCase(),i=i||"";let r;switch(s){case 0:r=new ml(e,n);break;case 39:r=new Gd(e,n,i);break;case 45:!i||i.match(/\s/)?r=new Ge(""):r=new ci(e,n,new RegExp(`(^|\\s)${Vn(i)}($|\\s)`));break;case 44:r=new ci(e,n,new RegExp(`^${Vn(i)}($|-)`));break;case 43:i?r=new ci(e,n,new RegExp(`^${Vn(i)}`)):r=new Ge("");break;case 42:i?r=new ci(e,n,new RegExp(`${Vn(i)}$`)):r=new Ge("");break;case 46:i?r=new ci(e,n,new RegExp(Vn(i))):r=new Ge("");break;case 50:if(i=="supported")r=new Wd(e,n);else{this.invalidSelector(`Unsupported :: attr selector op: ${i}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${s}`);return}this.chain.push(r)}descendantSelector(){let e=`d${pl++}`;this.processChain(new sr(new tp(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}childSelector(){let e=`c${pl++}`;this.processChain(new sr(new np(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${pl++}`;this.processChain(new sr(new sp(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${pl++}`;this.processChain(new sr(new ip(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,n){super.error(e,n),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 n=this.regionId;return this.footnoteContent&&(n?n="xxx-bogus-xxx":n="footnote"),new ui(this.elementStyle,e,this.pseudoelement,n,this.viewConditionId)}special(e,n){let s;this.condition?s=new to(n,0,this.condition):s=new I(n,0),lm(this.elementStyle,e).push(s)}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){e=="display"&&(n===b.oeb_page_head||n===b.oeb_page_foot)&&(this.simpleProperty("flow-options",new G([b.exclusive,b._static]),s),this.simpleProperty("flow-into",n,s),n=b.block),Ze("SIMPLE_PROPERTY").forEach(c=>{let d=c({name:e,value:n,important:s});e=d.name,n=d.value,s=d.important});let a=(s?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),l=this.condition?new to(n,a,this.condition):new I(n,a);kn(this.elementStyle,e,l)}finish(){return this.cascade}startFuncWithSelector(e,n){let s;switch(e){case"is":s=new Ps(this);break;case"not":s=new pp(this);break;case"where":s=new hp(this);break;case"has":s=new fp(this);break;case"nth-child":n&&n.length>=2&&(s=new xl(this,n[0],n[1]));break;case"nth-last-child":n&&n.length>=2&&(s=new gp(this,n[0],n[1]));break}s&&(s.startSelectorRule(),this.owner.pushHandler(s))}},Ly={"nth-child":jd,"nth-of-type":no,"nth-last-child":so,"nth-last-of-type":io},pl=0,Ps=class o extends jn{constructor(e){super(e.scope,e.owner,e.condition,e,e.regionId,e.validatorSet,!1);this.parent=e;p(this,"parentChain");p(this,"chains",[]);p(this,"maxSpecificity",0);p(this,"selectorTexts",[]);this.parentChain=e.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 Jd(this.selectorTexts):this.positive()?new ro(this.chains):new Qd(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(e,n){super.error(e,n),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let s=!1;for(let i=this;i instanceof o;i=i.parent)if(i.forgiving()){s=!0;break}s||this.owner.popHandler()}pushSelectorText(e){this.chain&&this.relational()&&this.selectorTexts.push(e)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},pp=class extends Ps{positive(){return!1}forgiving(){return!1}},hp=class extends Ps{increasingSpecificity(){return!1}},fp=class extends Ps{relational(){return!0}},xl=class extends Ps{constructor(e,n,s){super(e);this.a=n;this.b=s}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new yl(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ge("")),this.owner.popHandler()}forgiving(){return!0}},gp=class extends xl{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new ep(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ge("")),this.owner.popHandler()}},Sl=class extends Sn{constructor(t,e){super(t,e,!1)}property(t,e,n){if(this.scope.values[t])this.error(`E_CSS_NAME_REDEFINED ${t}`,this.getCurrentToken());else{let s=t.match(/height|^(top|bottom)$/)?"vh":"vw",i=new tn(this.scope,100,s);this.scope.defineName(t,e.toExpr(this.scope,i))}}},ks=class extends Sn{constructor(e,n,s,i,r,a){super(e,n,!1);this.condition=s;this.elementStyle=i;this.validatorSet=r;this.ruleType=a;p(this,"order");this.order=0}property(e,n,s){s?F.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){F.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){F.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let i=s?this.getImportantSpecificity():this.getBaseSpecificity();i+=this.order,this.order+=vp;let r=this.condition?new to(n,i,this.condition):new I(n,i);kn(this.elementStyle,e,r)}},mp=class extends _r{constructor(e,n){super(e);this.validatorSet=n;p(this,"elementStyle",{});p(this,"order",0)}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){F.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){F.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let i=s?za:Ha;i+=this.order,this.order+=vp;let r=new I(n,i);kn(this.elementStyle,e,r)}};function Np(o,t){let e=am(o);e&&e.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function El(o,t,e){Np(e,n=>{ar(o,n,t)})}function dm(o,t,e,n){let s=new mp(o,t),i=new Xe(n,s);try{mg(i,s,e)}catch(r){F.warn(r,"Style attribute parse error:")}return s.elementStyle}function Pl(o,t,e){let n=o["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.vertical_rl}return e}function kl(o,t,e){let n=o.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==b.inherit&&s!==b.revert&&s!==b.unset)return s===b.rtl}return e}function Al(o,t,e,n,s){let i={};for(let r in o)ws(r)&&(i[r]=de(o,r));return El(i,t,o),Tp(o,e,n,(r,a)=>{ar(i,a,t),El(i,t,a)}),i}function Tp(o,t,e,n){let s=Pt(o,"_regions");if((t||e)&&s){if(e){let i=["footnote"];t?t=t.concat(i):t=i}for(let i of t){let r=s[i];r&&n(i,r)}}}function ar(o,t,e){for(let n in t)if(ws(n)){let s=de(t,n),i=o[n];o[n]=Od(e,i,s)}}var Ll=(o,t,e,n,s,i)=>{var l,c;let r=e?n?vy:yp:n?Ny:xp,a=s?Ty:wy;for(let u in o){let d=o[u];if(!d)continue;let h=(l=r[u])!=null?l:r[a[u]],f=(c=a[u])!=null?c:a[r[u]],g=h!=null?h:f,m;if(g){let y=o[g];if(y&&y.priority>d.priority||h&&f&&h!==f&&(g=f,y=o[g],y&&y.priority>d.priority))continue;m=im[h]?h:im[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===b.inside||d.value===b.outside)&&(d=new I(s===(d.value===b.inside)?b.right:b.left,d.priority));t[m]=i(u,d)}},Cp=class extends $t{constructor(e,n,s){super();this.elementStyles=e;this.styler=n;this.element=s}getVarValue(e){var s,i,r,a,l;let n=(s=this.element)!=null?s:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let c of this.elementStyles){let u=(r=c[e])==null?void 0:r.value;if(u)return u}this.element&&(n=this.element.parentElement)}for(;n;n=n.parentElement){let c=(l=(a=this.styler.getStyle(n,!1))==null?void 0:a[e])==null?void 0:l.value;if(c)return c}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let n=e.values[0]instanceof Y&&e.values[0].name;if(!n||!Nt(n))return this.error=!0,H;let s=this.getVarValue(n);return s||(e.values.length<2?(this.error=!0,H):e.values.length===2?e.values[1]:new me(e.values.slice(1)))}},vl=class extends $t{constructor(e,n,s,i){super();this.context=e;this.resolveViewportUnit=n;this.percentRef=s;this.vertical=i}visitFunc(e){let n=super.visitFunc(e);if(e.name!=="calc")return n;let s=n.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(s))return n;let i=En(this.context.rootScope,new Xe(s,null),"");if(i instanceof D)try{let r=i.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(s)?n=new P(r,"px"):/\d[a-z]/i.test(s)||(n=new Re(r)))}catch(r){F.warn(r)}return n}visitNumeric(e){return this.resolveViewportUnit&&(uu(e.unit)||Wf(e.unit))?new P(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new P(e.num*this.percentRef/100,"px"):e}};function ao(o,t,e,n,s){try{if(t instanceof D)return t.expr instanceof ne&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Cg(o,t.expr,e);if(t instanceof P||t instanceof vt||t instanceof G||t instanceof me)return t.visit(new vl(o,!0,n,s))}catch(i){return F.warn(i),H}return t}var pm={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function hm(o){let t=o instanceof Le?o:typeof o=="string"?k(o):b.none;if(t===b.none)return pm;let e=t instanceof G?t.values:[t],n=Object.create(pm);for(let s of e)if(s instanceof Y)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 fm(o){return!o.first&&!o.last&&!o.forceEnd&&!o.allowEnd}var Ry={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},gm={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},mm={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Cm(o){let t=o instanceof Le?o:typeof o=="string"?k(o):b.normal;if(t===b.normal)return gm;if(t===b.auto)return mm;let e=t instanceof G?t.values:[t],n=Object.create(gm);for(let s of e)if(s instanceof Y)switch(s.name){case"trim-both":case"trim-auto":return mm;case"space-all":return Ry;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 wp={ideographAlpha:!1,ideographNumeric:!1},Iy={ideographAlpha:!0,ideographNumeric:!0};function bm(o){let t=o instanceof Le?o:typeof o=="string"?k(o):b.normal;if(t===b.normal||t===b.auto)return Iy;if(t===b.none)return wp;let e=t instanceof G?t.values:[t],n=Object.create(wp);for(let s of e)if(s instanceof Y)switch(s.name){case"no-autospace":return wp;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function ym(o,t){return!o.ideographAlpha&&!o.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function xm(o){return o?(o=o.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(o)?"zh-hant":/^zh\b/.test(o)?"zh-hans":/^ja\b/.test(o)?"ja":/^ko\b/.test(o)?"ko":o):null}var Pp=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(t){t.body&&this.preprocessForTextSpacing(t.body)}preprocessForTextSpacing(t){var n;let e=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT);for(let s=e.nextNode();s;s=e.nextNode()){if(s.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((n=s.parentElement.dataset)==null?void 0:n.mathTypeset)==="true")continue;let i=s.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(i.length>1){let r=i.length-1;for(let a=0;a<r;a++)s.parentNode.insertBefore(document.createTextNode(i[a]),s);s.textContent=i[r]}}}processGeneratedContent(t,e,n,s,i,r){i=xm(i);let a=bm(e),l=Cm(n),c=hm(s);if(fm(c)&&ym(a,l))return;this.preprocessForTextSpacing(t);let u=t.style.whiteSpace;(r?t.offsetHeight:t.offsetWidth)===0&&(t.style.whiteSpace="pre");let d=t.ownerDocument.createNodeIterator(t,NodeFilter.SHOW_TEXT),h=null,f=null;for(let g=d.nextNode();g;g=f){f=d.nextNode();let m=!h,y=!h||/\n$/.test(h.textContent),S=!f||/^\n/.test(f.textContent),C=!f;this.processTextSpacing(g,m||y,m,y,S,C,h,f,a,l,c,i,r),h=g}t.style.whiteSpace=u}postLayoutBlock(t,e){var d,h,f,g,m,y,S;let n=!t||t.fragmentIndex===1&&r(),s=n||a();function i(C){var N;if((C==null?void 0:C.nodeType)!==1)return!1;let x=C;if(x.hasAttribute(Tn))return!0;let{position:v,float:E}=(N=x.style)!=null?N:{};return v==="absolute"||v==="fixed"||E&&E!=="none"}function r(){let C=e[0];for(let x=C;;x=x.parent)if(!x||!x.inline){if((x==null?void 0:x.fragmentIndex)!==1)return!1;break}if(!C.inline)return!0;for(let x=C.viewNode.previousSibling;x;x=x.previousSibling)if(!Ce(x,C.whitespace)&&!i(x))return!1;return!0}function a(){var v,E;let C=e[0],x;for(;C&&C.inline&&(x=(v=C.viewNode)==null?void 0:v.previousSibling,!(x&&(x.nodeType===3&&/^[ \t\r\n\f]*$/.test(x.textContent)&&C.whitespace!==ot.PRESERVE&&(x=x.previousSibling),x)));)C=C.parent;for(;x;){if(x.nodeType===1){if(x.localName==="br")return!0;let N=(E=x.style)==null?void 0:E.display;if(N&&N!=="inline")return!/^(inline|ruby)\b/.test(N)}else if(x.nodeType===3){if(C.whitespace===ot.PRESERVE){if(/\n$/.test(x.textContent))return!0}else if(C.whitespace===ot.NEWLINE&&/\n[ \t\r\n\f]*$/.test(x.textContent))return!0}x=x.lastChild}return!1}let l=-1;for(let C=0;C<e.length;C++){let x=e[C];if(!x.after&&x.inline&&!x.display&&x.parent&&x.viewNode.parentNode&&x.viewNode.nodeType===Node.TEXT_NODE&&!Ce(x.viewNode,x.whitespace)){let At=function(B){var W,q,fe;if(((W=B.viewNode)==null?void 0:W.nodeType)===1)return B.viewNode.localName==="br";if(((q=B.viewNode)==null?void 0:q.nodeType)===3){if(B.whitespace===ot.PRESERVE){if(/\n$/.test(B.viewNode.textContent))return!0}else if(B.whitespace===ot.NEWLINE&&/\n[ \t\r\n\f]*$/.test(B.viewNode.textContent))return!0;if(((fe=B.viewNode.previousElementSibling)==null?void 0:fe.localName)==="br")return Ce(B.viewNode,B.whitespace)}return!1},R=function(B){var W,q,fe;if(((W=B.viewNode)==null?void 0:W.nodeType)===1)return B.viewNode.localName==="br";if(((q=B.viewNode)==null?void 0:q.nodeType)===3){if(B.whitespace===ot.PRESERVE){if(/^\n/.test(B.viewNode.textContent))return!0}else if(B.whitespace===ot.NEWLINE&&/^[ \t\r\n\f]*\n/.test(B.viewNode.textContent))return!0;if(((fe=B.viewNode.nextElementSibling)==null?void 0:fe.localName)==="br")return Ce(B.viewNode,B.whitespace)}return!1};var c=At,u=R;let v=xm((g=(h=(d=x.lang)!=null?d:x.parent.lang)!=null?h:t==null?void 0:t.lang)!=null?g:(f=t==null?void 0:t.parent)==null?void 0:f.lang),E=bm(x.inheritedProps["text-autospace"]),N=Cm(x.inheritedProps["text-spacing-trim"]),L=hm(x.inheritedProps["hanging-punctuation"]);if(fm(L)&&ym(E,N)||/\b(flex|grid)\b/.test(x.parent.display))continue;l<0&&(l=C);let O=null,z=null,K=C===l,je=C===l&&n,lt=C===l&&s,Ye=!1,ct=!1;for(let B=C-1;B>=0;B--){let W=e[B];if(At(W)){lt=!0;break}if(!W.display&&W.viewNode.nodeType===Node.TEXT_NODE&&W.viewNode.textContent.length>0){O=W.viewNode;break}if(W.display&&!/^(inline|ruby)\b/.test(W.display)||((m=W.viewNode)==null?void 0:m.nodeType)===1&&(W.viewNode.localName==="br"||gn[W.viewNode.localName]))break;B===0&&(K=!0,n&&(je=!0,lt=!0))}for(let B=C+1;B<e.length;B++){let W=e[B];if(R(W)){Ye=!0;break}if(W.viewNode!==x.viewNode&&!W.display&&W.viewNode.nodeType===Node.TEXT_NODE&&W.viewNode.textContent.length>0){z=W.viewNode;break}if(W.display&&!/^(inline|ruby)\b/.test(W.display)||((y=W.viewNode)==null?void 0:y.nodeType)===1&&(W.viewNode.localName==="br"||gn[W.viewNode.localName])){B===e.length-1&&i(W.viewNode)&&(ct=!0);break}if(B===e.length-1){Ye=!0,ct=!0;for(let q=W.viewNode.nextSibling;q;q=q.nextSibling)if(!i(q)){ct=!1;break}}}if(((S=x.parent)==null?void 0:S.display)==="inline-block"){if(!je){let B=x.parent.viewNode.firstChild;for(;Ce(B,x.whitespace);)B=B.nextSibling;x.viewNode===B&&(je=!0)}if(!ct){let B=x.parent.viewNode.lastChild;for(;Ce(B,x.whitespace);)B=B.previousSibling;x.viewNode===B&&(ct=!0)}}if(this.processTextSpacing(x.viewNode,K,je,lt,Ye,ct,O,z,E,N,L,v,x.vertical)>0)break}}}processTextSpacing(t,e,n,s,i,r,a,l,c,u,d,h,f){let g=t.textContent,m=t.ownerDocument,y=0,S,C,x;function v(){if(e)return!0;if(!a)return!1;S||(S=m.createRange(),S.selectNode(t));let R=S.getClientRects()[0];if(!R)return!1;C||(C=m.createRange(),C.selectNode(a));let _=C.getClientRects(),B=_[_.length-1];return B?(y||(y=ri(B,f)),f?R.top<B.top+B.height-R.width||R.left+R.width<B.left+R.width/10||R.left>B.left+B.width-R.width/10:R.left<B.left+B.width-R.height||R.top>B.top+B.height-R.height/10||R.top+R.height<B.top+R.height/10):!1}function E(){if(!l)return!1;S||(S=m.createRange(),S.selectNode(t));let R=S.getClientRects()[0];if(!R)return!1;y||(y=ri(R,f)),x||(x=m.createRange(),x.selectNode(l));let _=x.getClientRects()[0];return _?f?R.top+R.height>_.top+R.width||R.left>_.left+_.width-R.width/10||R.left+R.width<_.left+R.width/10:R.left+R.width>_.left+R.height||R.top+R.height<_.top+R.height/10||R.top>_.top+_.height-R.height/10:!1}let N=!1,L=!1,O=!1,z=!1,K;if(n&&d.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(g)?(K="viv-ts-open",N=!0,L=!0):r&&d.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(g)?(K="viv-ts-close",N=!0,O=!0):(d.forceEnd||d.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(g)?(K="viv-ts-close",N=!0,z=!0):(u.trimStart||u.spaceFirst||u.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(g)?(K="viv-ts-open",N=!0):(u.trimEnd||u.allowEnd||u.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(g)||h==="zh-hans"&&/^[:;]\p{M}*$/u.test(g)||h!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(g))&&(K="viv-ts-close",N=!0),N){let B=function(fe){let es=parseFloat(m.defaultView.getComputedStyle(fe).fontSize)*.7;return(f?fe.offsetHeight:fe.offsetWidth)>es},q=function(){return f?R.offsetLeft:R.offsetTop};var ct=B,At=q;if(t.parentElement.localName==="viv-ts-inner")return 0;let R=m.createElement(K),_=m.createElement("viv-ts-inner");R.appendChild(_),t.parentNode.insertBefore(R,t),_.appendChild(t);let W=B(_);if(W||L||O||z){if(K==="viv-ts-open"){if(L)R.className="viv-hang-first";else if(n||s)u.trimStart?R.className="viv-ts-trim":R.className="viv-ts-space";else if(!(u.trimStart||u.spaceFirst)&&v())R.className="viv-ts-space";else if(u.trimAdjacent&&a&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(a.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(a.textContent)||a.parentElement.localName==="viv-ts-inner"&&B(a.parentElement)))R.className="viv-ts-trim";else if((u.trimStart||u.spaceFirst)&&v()){let fe=q();R.className="viv-ts-auto",fe===q()&&!v()&&(R.className="viv-ts-trim")}}else if(K==="viv-ts-close"){if(O)R.className=W?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||i){let fe=q();z?(R.className=W?d.allowEnd&&u.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",d.allowEnd&&fe===q()&&(u.trimEnd?R.className="viv-ts-trim":u.allowEnd?(R.className="viv-hang-end",fe===q()&&(R.className="")):R.className="viv-ts-space")):u.trimEnd?R.className="viv-ts-trim":u.allowEnd?(R.className="viv-ts-auto",fe===q()&&(R.className="")):R.className="viv-ts-space"}else if(l&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(l.textContent))W&&u.trimAdjacent&&(R.className="viv-ts-trim");else if(z){let fe=E(),Gt=fe&&d.allowEnd;Gt||(R.className=W?"viv-hang-end":"viv-hang-end viv-hang-hw"),W?Gt&&u.trimEnd?R.className="viv-ts-auto":!Gt&&!E()?R.className="":!fe&&d.allowEnd&&(u.trimEnd?(R.className="viv-ts-auto",E()||(R.className="viv-hang-end")):(R.className="viv-ts-space",E()||(u.allowEnd?(R.className="viv-ts-auto",E()||(R.className="viv-hang-end")):R.className="viv-hang-end"))):!fe&&!E()&&(R.className="")}else if(u.trimEnd||u.allowEnd)if(E())u.allowEnd?R.className="viv-ts-space":R.className="viv-ts-auto";else{let fe=q();R.className="viv-ts-auto",fe===q()&&(R.className="")}}}}let je=!1;function lt(R){var B;let _=(B=R==null?void 0:R.ownerDocument.defaultView)==null?void 0:B.getComputedStyle(R);return!!_&&(_.textOrientation==="upright"||_.textCombineUpright==="all"||_["-webkit-text-combine"]==="horizontal")}function Ye(R,_){if(R.nodeType===1){let q=m.defaultView.getComputedStyle(R);if(parseFloat(q.marginInlineEnd)||parseFloat(q.borderInlineEndWidth)||parseFloat(q.paddingInlineEnd))return!0}let B=R.parentElement;if(B&&!B.contains(_))return Ye(B,_);if(_.nodeType===1){let q=m.defaultView.getComputedStyle(_);if(parseFloat(q.marginInlineStart)||parseFloat(q.borderInlineStartWidth)||parseFloat(q.paddingInlineStart))return!0}let W=_.parentElement;return W&&!W.contains(R)?Ye(R,W):!1}return(c.ideographAlpha||c.ideographNumeric)&&(a&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(g)&&(c.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(a.textContent)||c.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(a.textContent))&&!(f&&lt(a.parentElement))&&!Ye(a,t)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t),je=!0),l&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(g)&&(c.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(l.textContent)||c.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(l.textContent))&&!(f&&lt(l.parentElement))&&!Ye(t,l)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t.nextSibling),je=!0)),y}registerHooks(){Ke("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Ke("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Ke("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},kp=new Pp;kp.registerHooks();function Sm(o){kp.preprocessForTextSpacing(o)}function Em(o,t,e,n,s,i){kp.processGeneratedContent(o,t,e,n,s,i)}var lr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Nm=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],Rl="data-adapt-pseudo";function pi(o){return o.getAttribute(Rl)||""}function co(o,t){o.setAttribute(Rl,t)}var lo=class{constructor(t,e,n,s,i){this.element=t;this.style=e;this.styler=n;this.context=s;this.exprContentListener=i;p(this,"contentProcessed",{})}getStyle(t,e){let n=pi(t);this.styler&&n&&n.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let s=Pt(this.style,"_pseudos"),i=(s==null?void 0:s[n])||{};if(n.match(/^first-/)&&!i["x-first-pseudo"]){let r=1,a;n=="first-letter"?r=0:(a=n.match(/^first-([0-9]+)-lines$/))!=null&&(r=a[1]-0),i["x-first-pseudo"]=new I(new se(r),0)}return i}processContent(t,e,n){let s=pi(t);if(!this.contentProcessed[s]){this.contentProcessed[s]=!0,s==="marker"&&this.processMarker(t,e,n);let i=e.content;ht(i)&&(i.visit(new Mn(t.classList.contains("_viv-marker-outside")&&t.firstElementChild||t,this.context,i,this.exprContentListener)),Sm(t))}}processMarker(t,e,n){let s=e.content,i=e["list-style-position"],r=e["list-style-type"];if(ht(s)){if(s instanceof ge)e.content=new G([s]);else if(s instanceof M&&r instanceof Y){let a=r.name.toLowerCase();if((a==="disc"||a==="circle"||a==="square"||a==="disclosure-open"||a==="disclosure-closed")&&(t.classList.add("_viv-marker-bullet"),a==="disclosure-open"||a==="disclosure-closed")){let l=n.direction==="rtl",c=n.vertical;e.content=new M(a==="disclosure-open"?c?"\u25C2 ":"\u25BE ":c?l?"\u25B4 ":"\u25BE ":l?"\u25C2 ":"\u25B8 ")}}}if(i===b.outside){t.classList.add("_viv-marker-outside");let a=t.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","span");a.classList.add("_viv-marker-outside-content"),t.appendChild(a);let l=n.inheritedProps["text-spacing-trim"];l&&l!=="space-all"&&(e["text-spacing-trim"]=b.normal),n.inheritedProps["hanging-punctuation"]&&(e["hanging-punctuation"]=b.none)}delete e["list-style-position"],delete e["list-style-type"]}};var pE=Hr.isInstanceOfAfterIfContinuesLayoutConstraint,Pm=Ts.registerFragmentIndex,hE=Ts.clearFragmentIndices,Il=class{constructor(t,e){this.sourceNode=t;this.styler=e}createElement(t,e){let s=e.viewNode.ownerDocument.createElement("div"),i=new gi(t,s,e),r=i.getColumn().pageBreakType;return i.getColumn().pageBreakType=null,i.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,i.getColumn().pageBreakType=r;let a=s.firstChild;return w(a,"display","block"),T(a)})}createNodePositionForPseudoElement(){let t=lr.createElementNS("http://www.w3.org/1999/xhtml","div");co(t,"after-if-continues");let e=this.createShadowContext(t),s={steps:[{node:t,shadowType:e.type,shadowContext:e,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new wt(s)}createShadowContext(t){return new si(this.sourceNode,t,null,null,null,Yt.ShadowType.ROOTED,this.styler)}},Ap=class o{constructor(t,e,n){this.nodeContext=t;this.afterIfContinues=e;this.pseudoElementHeight=n;p(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,e,n){return!(e&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,e,n,s){}finishBreak(t,e){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(e,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),T(!0))):T(!0)}getRepetitiveElements(){return new Lp(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof o?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},Lp=class{constructor(t,e){this.nodeContext=t;this.pseudoElementHeight=e}calculateOffset(t){return this.affectTo(t)?this.pseudoElementHeight:0}calculateMinimumOffset(t){return this.calculateOffset(t)}affectTo(t){if(!t)return!1;let e=t.shadowContext?t.shadowContext.owner:t.sourceNode;if(e===this.nodeContext.sourceNode)return!!t.after;for(let n=e.parentNode;n;n=n.parentNode)if(n===this.nodeContext.sourceNode)return!0;return!1}};function km(o,t){if(!o||!o.afterIfContinues||o.after||t.isFloatNodeContext(o))return T(o);let e=o.afterIfContinues;return e.createElement(t,o).thenAsync(n=>{let s=Fy(o,t,n);return t.fragmentLayoutConstraints.push(new Ap(o,e,s)),T(o)})}function Fp(o,t){return o.thenAsync(e=>km(e,t))}function Vy(o,t){let e=A("processAfterIfContinuesOfAncestors"),n=o;return e.loop(()=>{if(n!==null){let s=km(n,t);return n=n.parent,s.thenReturn(!0)}else return T(!1)}).then(()=>{e.finish(!0)}),e.result()}function Fy(o,t,e){let n=o.viewNode;n.appendChild(e);let s=Qr(e,t,o.vertical);return n.removeChild(e),s}var Vl=class{constructor(t){this.constraints=t}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},hi=class extends oi{constructor(e,n){super();this.checkPoints=e;this.penalty=n;p(this,"alreadyEvaluated",!1);p(this,"breakNodeContext",null)}findAcceptableBreak(e,n){return n<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,n>0),this.alreadyEvaluated=!!this.breakNodeContext||n>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}};var fi=class o extends Qi{constructor(e,n,s,i,r){super(e);this.layoutContext=n;this.clientLayout=s;this.layoutConstraint=i;this.pageFloatLayoutContext=r;p(this,"last");p(this,"viewDocument");p(this,"flowRootFormattingContext",null);p(this,"isFloat",!1);p(this,"isFootnote",!1);p(this,"startEdge",0);p(this,"endEdge",0);p(this,"beforeEdge",0);p(this,"afterEdge",0);p(this,"footnoteEdge",0);p(this,"box",null);p(this,"chunkPositions",null);p(this,"bands",null);p(this,"overflown",!1);p(this,"breakPositions",null);p(this,"pageBreakType",null);p(this,"forceNonfitting",!0);p(this,"leftFloatEdge",0);p(this,"rightFloatEdge",0);p(this,"bottommostFloatTop",0);p(this,"stopAtOverflow",!0);p(this,"lastAfterPosition",null);p(this,"fragmentLayoutConstraints",[]);p(this,"pseudoParent",null);p(this,"nodeContextOverflowingDueToRepetitiveElements",null);p(this,"blockDistanceToBlockEndFloats",NaN);p(this,"breakAtTheEdgeBeforeFloat",null);new.target===o&&qg(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}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 n=A("openAllViews"),s=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let i=s.length-1,r=null;return n.loop(()=>{for(;i>=0;){let a=r,l=s[i];if(r=Ji(l,a),i===s.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),i==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let c=this.layoutContext.setCurrent(r,i==0&&r.offsetInNode==0);if(i--,c.isPending())return c}return T(!1)}).then(()=>{n.finish(r)}),n.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Fg(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,n){var s,i;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,a=r.match(_s),l=a?a[0].length:0;if(!a&&((s=e.sourceNode)==null?void 0:s.nodeType)===3&&((i=e.sourceNode.nextSibling)==null?void 0:i.nodeType)===3&&r===e.sourceNode.textContent){let c=r+e.sourceNode.nextSibling.textContent,u=c.match(_s);if(u){let d=u[0];l=d.length,e.sourceNode.textContent=d,e.viewNode.textContent=d,e.sourceNode.nextSibling.textContent=c.substr(l)}}return this.layoutContext.peelOff(e,l)}return T(e)}buildViewToNextBlockEdge(e,n){let s=!1,i=A("buildViewToNextBlockEdge");return i.loopWithFrame(r=>{var a;if(e.viewNode&&!zn(e)&&((a=e.viewNode.parentElement)==null?void 0:a.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(n.push(e.copy()),n.length>1e3)){let c=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,u=this.clientLayout.getElementClientRect(c);if(ri(u,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(l=>{let c=l;c!==e&&(e=c,zn(e)||n.push(e.copy())),this.nextInTree(e).then(u=>{if(e=u,!e){r.breakLoop();return}(s||!this.layoutConstraint.allowLayout(e))&&(s=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(ys(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(d=>{if(e=d,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{i.finish(e)}),i.result()}nextInTree(e,n){let s=this.layoutContext.nextInTree(e,n);return Fp(s,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let n=[],s=e.sourceNode,i=A("buildDeepElementView");return i.loopWithFrame(r=>{e.viewNode&&e.inline&&!zn(e)?n.push(e.copy()):(n.length>0&&this.postLayoutBlock(e,n),n=[]),this.maybePeelOff(e,0).then(a=>{let l=a;if(l!==e){let c=l;for(;c&&c.sourceNode!=s;)c=c.parent;if(c==null){e=l,r.breakLoop();return}zn(l)||n.push(l.copy())}this.nextInTree(l).then(c=>{e=c,!e||e.sourceNode==s?r.breakLoop():this.layoutConstraint.allowLayout(e)?r.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?r.breakLoop():r.continueLoop())})})}).then(()=>{n.length>0&&this.postLayoutBlock(e,n),i.finish(e)}),i.result()}createFloat(e,n,s,i){let r=this.viewDocument.createElement("div");return this.vertical?(i>=this.height&&(i-=.1),i<1&&(i=0),w(r,"height",`${s}px`),w(r,"width",`${i}px`)):(s>=this.width&&(s-=.1),s<1&&(s=0),w(r,"width",`${s}px`),w(r,"height",`${i}px`)),w(r,"float",n),w(r,"clear",n),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let n=e.nextSibling;if(e.nodeType==1){let s=e,i=s.style.cssFloat;if(i=="left"||i=="right"||i==="none")this.element.removeChild(s);else break}e=n}}createFloats(){let e=this.element.firstChild,n=this.bands,s=this.vertical?this.getTopEdge():this.getLeftEdge(),i=this.vertical?this.getBottomEdge():this.getRightEdge(),r=null;for(let a of n){let l=a.y2-a.y1;a.left=this.createFloat(e,"left",a.x1-s,l),a.right=this.createFloat(e,"right",i-a.x2,l),a.x1<i&&a.x2>s?r=a:r||w(a.right,"float","none")}if(r){let a=n[n.length-1],l=this.vertical?-this.getLeftEdge():this.getBottomEdge();r!==a&&a.y2>=l&&(this.footnoteEdge=this.vertical?-r.y2:r.y2)}}calculateEdge(e,n,s,i){let r;if(e&&Hn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=xs(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=n[s];let a=i-e.boxOffset;for(;;){if(r=xs(e,this.clientLayout,a,this.vertical),!isNaN(r))return r;if(a>0){a--;continue}if(s--,s<0)return this.beforeEdge;e=n[s],e.viewNode.nodeType!=1&&(a=e.viewNode.textContent.length)}}parseComputedLength(e){let n=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return n?this.clientLayout.adjustLengthValue(parseFloat(n[0])):0}getComputedMargin(e){let n=this.clientLayout.getElementComputedStyle(e),s=new _i(0,0,0,0);return n&&(s.left=this.parseComputedLength(n.marginLeft),s.top=this.parseComputedLength(n.marginTop),s.right=this.parseComputedLength(n.marginRight),s.bottom=this.parseComputedLength(n.marginBottom)),s}getComputedPaddingBorder(e){let n=this.clientLayout.getElementComputedStyle(e),s=new _i(0,0,0,0);return n&&(s.left=this.parseComputedLength(n.borderLeftWidth)+this.parseComputedLength(n.paddingLeft),s.top=this.parseComputedLength(n.borderTopWidth)+this.parseComputedLength(n.paddingTop),s.right=this.parseComputedLength(n.borderRightWidth)+this.parseComputedLength(n.paddingRight),s.bottom=this.parseComputedLength(n.borderBottomWidth)+this.parseComputedLength(n.paddingBottom)),s}getComputedInsets(e){let n=this.clientLayout.getElementComputedStyle(e),s=new _i(0,0,0,0);if(n){if(n.boxSizing=="border-box")return this.getComputedMargin(e);s.left=this.parseComputedLength(n.marginLeft)+this.parseComputedLength(n.borderLeftWidth)+this.parseComputedLength(n.paddingLeft),s.top=this.parseComputedLength(n.marginTop)+this.parseComputedLength(n.borderTopWidth)+this.parseComputedLength(n.paddingTop),s.right=this.parseComputedLength(n.marginRight)+this.parseComputedLength(n.borderRightWidth)+this.parseComputedLength(n.paddingRight),s.bottom=this.parseComputedLength(n.marginBottom)+this.parseComputedLength(n.borderBottomWidth)+this.parseComputedLength(n.paddingBottom)}return s}setComputedInsets(e,n){let s=this.clientLayout.getElementComputedStyle(e);s&&(n.marginLeft=this.parseComputedLength(s.marginLeft),n.borderLeft=this.parseComputedLength(s.borderLeftWidth),n.paddingLeft=this.parseComputedLength(s.paddingLeft),n.marginTop=this.parseComputedLength(s.marginTop),n.borderTop=this.parseComputedLength(s.borderTopWidth),n.paddingTop=this.parseComputedLength(s.paddingTop),n.marginRight=this.parseComputedLength(s.marginRight),n.borderRight=this.parseComputedLength(s.borderRightWidth),n.paddingRight=this.parseComputedLength(s.paddingRight),n.marginBottom=this.parseComputedLength(s.marginBottom),n.borderBottom=this.parseComputedLength(s.borderBottomWidth),n.paddingBottom=this.parseComputedLength(s.paddingBottom))}setComputedWidthAndHeight(e,n){let s=this.clientLayout.getElementComputedStyle(e);s&&(n.width=this.parseComputedLength(s.width),n.height=this.parseComputedLength(s.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let n=A("layoutFloat"),s=e.viewNode,i=Cd(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return w(s,"float","none"),w(s,"display","inline-block"),w(s,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let a=Ut(this.clientLayout,s,this.vertical),l=this.getComputedMargin(s),c=new qe(a.left-l.left,a.top-l.top,a.right+l.right,a.bottom+l.bottom),u=this.rtl?this.endEdge:this.startEdge,d=this.rtl?this.startEdge:this.endEdge,h=e.parent;for(;h&&h.inline;)h=h.parent;if(h){let E=h.viewNode.ownerDocument.createElement("div");E.style.left="0px",E.style.top="0px",this.vertical?(E.style.bottom="0px",E.style.width="1px"):(E.style.right="0px",E.style.height="1px"),h.viewNode.appendChild(E);let N=Ut(this.clientLayout,E,this.vertical);u=Math.max(this.rtl?this.getEndEdge(N):this.getStartEdge(N),u),d=Math.min(this.rtl?this.getStartEdge(N):this.getEndEdge(N),d),h.viewNode.removeChild(E);let L=this.vertical?c.y2-c.y1:c.x2-c.x1;i=="left"?d=Math.max(d,u+L):u=Math.min(u,d-L),h!==e.parent&&!e.firstPseudo&&(h.viewNode.appendChild(s),s.setAttribute("data-vivliostyle-float-box-moved","true"))}let f=new qe(u,this.getBoxDir()*this.beforeEdge,d,this.getBoxDir()*this.afterEdge),g=c;this.vertical&&(g=Ui(c));let m=this.getBoxDir();if(g.y1<this.bottommostFloatTop*m){let E=g.y2-g.y1;g.y1=this.bottommostFloatTop*m,g.y2=g.y1+E}ng(f,this.bands,g,i),this.vertical&&(c=Ra(g));let y=this.getComputedInsets(s);w(s,"width",`${c.x2-c.x1-y.left-y.right}px`),w(s,"height",`${c.y2-c.y1-y.top-y.bottom}px`),w(s,"position","absolute"),e.display,w(s,"display",e.display);let S,C=null;if(h&&(h.containingBlockForAbsolute?C=h:C=h.getContainingBlockForAbsolute()),C){let E=C.viewNode.ownerDocument.createElement("div");E.style.position="absolute",C.vertical?E.style.right="0":E.style.left="0",E.style.top="0",C.viewNode.appendChild(E),S=Ut(this.clientLayout,E,this.vertical),C.viewNode.removeChild(E)}else S={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(C?C.vertical:this.vertical)?w(s,"right",`${S.right-c.x2}px`):w(s,"left",`${c.x1-S.left}px`),w(s,"top",`${c.y1-S.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let x=this.vertical?c.x1:c.y2,v=this.vertical?c.x2:c.y1;!this.isOverflown(x)||this.breakPositions.length==0?(this.killFloats(),f=new qe(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(f=Ui(f)),sg(f,this.bands,g,null,i),this.createFloats(),i=="left"?this.leftFloatEdge=x:this.rightFloatEdge=x,this.bottommostFloatTop=v,this.updateMaxReachedAfterEdge(x),n.finish(r)):(e=e.modify(),e.overflow=!0,n.finish(e))}),n.result()}setupFloatArea(e,n,s,i,r,a){let l=this.pageFloatLayoutContext,c=l.getContainer(n),u=e.element;c.element.parentNode.appendChild(u),e.isFloat=!0,e.originX=c.originX,e.originY=c.originY,e.vertical=c.vertical,e.rtl=c.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=(c.exclusions||[]).concat(),e.forceNonfitting=!l.hasFloatFragments(),e.innerShape=null;let d=c.getPaddingRect();e.setHorizontalPosition(d.x1-c.originX,d.x2-d.x1),e.setVerticalPosition(d.y1-c.originY,d.y2-d.y1),r.adjustPageFloatArea(e,c,this),e.init();let h=!!l.setFloatAreaDimensions(e,n,s,i,!0,!l.hasFloatFragments(),a);return h?(e.killFloats(),e.init()):c.element.parentNode.removeChild(u),h}createPageFloatArea(e,n,s,i,r){let a=this.element.ownerDocument.createElement("div");w(a,"position","absolute");let l=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),c=new _n(null,be.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),u=l.getContainer(),d=new Vp(n,a,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,c,u);return c.setContainer(d),this.setupFloatArea(d,e.floatReference,n,s,i,r)?d:null}layoutSinglePageFloatFragment(e,n,s,i,r,a,l){let c=this.pageFloatLayoutContext;e=(l?l.continuations:[]).concat(e);let d=e[0].float,h=c.getPageFloatPlacementCondition(d,n,s),f=this.createPageFloatArea(d,n,a,r,h),g={floatArea:f,pageFloatFragment:null,newPosition:null};if(!f)return T(g);let m=A("layoutSinglePageFloatFragment"),y=!1,S=0;return m.loopWithFrame(C=>{if(S>=e.length){C.breakLoop();return}let x=e[S],v=new wt(x.nodePosition);f.layout(v,!0).then(E=>{g.newPosition=E,!E||i?(S++,C.continueLoop()):(y=!0,C.breakLoop())})}).then(()=>{if(!y){let C=c.setFloatAreaDimensions(f,d.floatReference,n,a,!1,i,h);if(!C)y=!0;else{let x=r.createPageFloatFragment(e,C,s,f,!!g.newPosition);c.addPageFloatFragment(x,!0),g.pageFloatFragment=x}}m.finish(g)}),m.result()}layoutPageFloatInner(e,n,s,i){let r=this.pageFloatLayoutContext,a=e.float;r.stashEndFloatFragments(a);function l(u,d){d?r.removePageFloatFragment(d,!0):u&&u.element.parentNode.removeChild(u.element),r.restoreStashedFragments(a.floatReference),r.deferPageFloat(e)}let c=A("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],a.floatSide,a.clearSide,!r.hasFloatFragments(),n,s,i).then(u=>{let d=u.floatArea,h=u.pageFloatFragment,f=u.newPosition;h?this.layoutStashedPageFloats(a.floatReference,[i]).then(g=>{if(g){if(r.addPageFloatFragment(h),r.discardStashedFragments(a.floatReference),f){let m=new Xr(a,f.primary);r.deferPageFloat(m)}c.finish(!0)}else l(d,h),c.finish(!1)}):(l(d,h),c.finish(!1))}),c.result()}layoutStashedPageFloats(e,n){let s=this.pageFloatLayoutContext,i=s.getStashedFloatFragments(e),r=[],a=[],l=!1,c=A("layoutStashedPageFloats"),u=0;return c.loopWithFrame(d=>{if(u>=i.length){d.breakLoop();return}let h=i[u];if(n.includes(h)){u++,d.continueLoop();return}let f=new cn().findByFloat(h.continuations[0].float);this.layoutSinglePageFloatFragment(h.continuations,h.floatSide,h.clearSide,!1,f,null).then(g=>{let m=g.floatArea;m&&r.push(m);let y=g.pageFloatFragment;y?(a.push(y),u++,d.continueLoop()):(l=!0,d.breakLoop())})}).then(()=>{l?(a.forEach(d=>{s.removePageFloatFragment(d,!0)}),r.forEach(d=>{let h=d.element;h&&h.parentNode&&h.parentNode.removeChild(h)})):i.forEach(d=>{let h=d.area.element;h&&h.parentNode&&h.parentNode.removeChild(h)}),c.finish(!l)}),c.result()}setFloatAnchorViewNode(e){let n=e.viewNode.parentNode,s=n.ownerDocument.createElement("span");s.setAttribute(Tn,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",s),n.appendChild(s),n.removeChild(e.viewNode);let i=e.modify();return i.after=!0,i.viewNode=s,i}resolveFloatReferenceFromColumnSpan(e,n,s){let i=A("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,a=r.getPageFloatLayoutContext(be.REGION);return r.getContainer().width<a.getContainer().width&&e===be.COLUMN?n===b.auto?this.buildDeepElementView(s.copy()).then(c=>{let u=c.viewNode,d=Yi(this.clientLayout,u,["min-content inline size"])["min-content inline size"],h=this.getComputedMargin(u);this.vertical?d+=h.top+h.bottom:d+=h.left+h.right,d>this.width?i.finish(be.REGION):i.finish(e)}):n===b.all?i.finish(be.REGION):i.finish(e):i.finish(e),i.result()}layoutPageFloat(e){let n=this.pageFloatLayoutContext,s=new cn().findByNodeContext(e),i,r=n.findPageFloatByNodePosition(e.toNodePosition());return r?i=T(r):i=s.createPageFloat(e,n,this),i.thenAsync(a=>{let l=ii(e,0),c=this.setFloatAnchorViewNode(e),u=s.findPageFloatFragment(a,n),d=new Xr(a,l);if(u&&u.hasFloat(a))return n.registerPageFloatAnchor(a,c.viewNode),T(c);if(n.isForbidden(a)||n.hasPrecedingFloatsDeferredToNext(a))return n.deferPageFloat(d),n.registerPageFloatAnchor(a,c.viewNode),T(c);if(this.nodeContextOverflowingDueToRepetitiveElements)return T(null);{let h=xs(c,this.clientLayout,0,this.vertical);return this.isOverflown(h)?T(c):this.layoutPageFloatInner(d,s,h,u).thenAsync(f=>f?T(null):(n.registerPageFloatAnchor(a,c.viewNode),T(c)))}})}processLineStyling(e,n,s){let i=A("processLineStyling"),r=s.concat([]);s.splice(0,s.length);let a=0,l=e.firstPseudo;return l.count==0&&(l=l.outer),i.loopWithFrame(c=>{if(!l){c.breakLoop();return}let u=this.findLinePositions(r),d=l.count-a;if(u.length<=d){c.breakLoop();return}let h=this.findAcceptableBreakInside(r,u[d-1],!0);if(h==null){c.breakLoop();return}this.finishBreak(h,!1,!1).then(()=>{a+=d,this.layoutContext.peelOff(h,0).then(f=>{e=f,l=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(g=>{n=g,c.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(s,r),i.finish(n)}),i.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&gn[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let n=0,s=0;for(let i=e.length-1;i>=0;i--){let r=e[i];if(!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let a=this.getComputedMargin(r.viewNode),l=this.vertical?-a.left:a.bottom;l>0?n=Math.max(n,l):s=Math.min(s,l)}return n+s}layoutBreakableBlock(e){let n=A("layoutBreakableBlock"),s=[];return this.buildViewToNextBlockEdge(e,s).then(i=>{let r=s.length-1;if(r<0){n.finish(i);return}this.postLayoutBlock(i,s);let a=this.calculateEdge(i,s,r,s[r].boxOffset),l=!1;if(!i||!Hn(i.viewNode)){let u=Es(i,this.collectElementsOffset());l=this.isOverflown(a+(this.vertical?-1:1)*u.minimum),this.isOverflown(a+(this.vertical?-1:1)*u.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=i)}i==null&&(a+=this.getTrailingMarginEdgeAdjustment(s)),this.updateMaxReachedAfterEdge(a);let c;e.firstPseudo?c=this.processLineStyling(e,i,s):c=T(i),c.then(u=>{s.length>0&&(this.saveBoxBreakPosition(s),l&&!this.isLoneImage(s)&&u&&(u=u.modify(),u.overflow=!0)),n.finish(u)})}),n.result()}postLayoutBlock(e,n){Ze("POST_LAYOUT_BLOCK").forEach(i=>{i(e,n,this)})}findEndOfLine(e,n,s){let i=this.vertical?e-1:e+1,r=0,a=n[0].boxOffset,l=r,c=n.length-1,u=n[c].boxOffset,d;for(;a<u;){d=a+Math.ceil((u-a)/2),l=r;let h=c;for(;l<h;){let g=l+Math.ceil((h-l)/2);n[g].boxOffset>d?h=g-1:l=g}let f=this.calculateEdge(null,n,l,d);if(this.vertical?f<=i:f>=i){for(u=d-1;n[l].boxOffset==d;)l--;c=l}else s&&this.updateMaxReachedAfterEdge(f),a=d,r=l}return{nodeContext:n[l],index:a,checkPointIndex:l}}findAcceptableBreakInside(e,n,s){var l,c,u;let i=this.findEndOfLine(n,e,!0),r=i.nodeContext;if(i.checkPointIndex===0&&i.index===r.boxOffset)return null;let a=r.viewNode;if(a.nodeType!=1&&((l=a.parentElement)==null?void 0:l.localName)!=="viv-ts-inner"){let d=a;r=this.resolveTextNodeBreaker(r).breakTextNode(d,r,i.index,e,i.checkPointIndex,s)}else{let d=Td(r);if(d){if(((c=this.breakPositions)==null?void 0:c[0])instanceof hi&&(d!=null&&d.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode)))return null;for(r=d;!r.after&&r.inline&&r.parent;){let h=(u=r.viewNode)==null?void 0:u.previousSibling;for(;h&&(Ce(h,r.parent.whitespace)||Ss(h));)h=h.previousSibling;if(h)break;r=r.parent}}}return this.clearOverflownViewNodes(r,!1),r}resolveTextNodeBreaker(e){return Ze("RESOLVE_TEXT_NODE_BREAKER").reduce((s,i)=>i(e)||s,cr.instance)}getRangeBoxes(e,n){let s=[],i=e.ownerDocument.createRange(),r=!1,a=e,l=null,c=!1,u=!0;for(;u;){let d=!0;do{let h=null;a==n&&(n.nodeType===1?u=!(!n.firstChild||r):u=!1);let f=a.nodeType===1?a:null;f?r?r=!1:cl(f)?d=!c:!f.firstChild||gn[f.localName]||/^r(uby|[bt]c?)$/.test(f.localName)||Jg(this.clientLayout.getElementComputedStyle(f).display)?(d=!c,d?(f.localName==="ruby"&&a.firstChild&&(a=a.firstChild),i.setStartBefore(a),c=!0,l=a):/^r(uby|tc?)$/.test(f.localName)||(l=a),a.contains(n)&&(u=!1)):h=a.firstChild:(c||(a.parentNode==null?u=!1:(i.setStartBefore(a),c=!0)),l=a),h||(h=a.nextSibling,h||(r=!0,h=a.parentNode)),a=h}while(d&&u);if(c){i.setEndAfter(l);let h=this.clientLayout.getRangeClientRects(i);Nd(h,this.vertical);for(let f=0;f<h.length;f++)s.push(h[f]);c=!1}}return s}findLinePositions(e){let i=[],r=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);r.sort(this.vertical?Ug:_g);let a=0,l=0,c=0,u=0,d=0,h=this.getBoxDir();for(;;){if(d<r.length){let f=r[d],g=1;if(u>0){let m=Math.max(this.getBoxSize(f),1);h*this.getBeforeEdge(f)<h*a?g=h*(this.getAfterEdge(f)-a)/m:h*this.getAfterEdge(f)>h*l?g=h*(l-this.getBeforeEdge(f))/m:g=1}if(u==0||g>=.6||g>=.2&&this.getStartEdge(f)>=c-1){c=this.getEndEdge(f),this.vertical?(a=u==0?f.right:Math.max(a,f.right),l=u==0?f.left:Math.min(l,f.left)):(a=u==0?f.top:Math.min(a,f.top),l=u==0?f.bottom:Math.max(l,f.bottom)),u++,d++;continue}}if(u>0&&(i.push(l),u=0),d>=r.length)break}return i.sort(aa),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(e){let n=0;for(let s=e;s;s=s.parent)if(!s.inline&&ti(s.viewNode)){let i=this.getComputedPaddingBorder(s.viewNode);n+=s.vertical?-i.left:i.bottom,s.display==="table"&&(n+=(s.vertical?-1:1)*s.blockBorderSpacing)}return n}getOffsetByRepetitiveElements(e){let n;return e?n=e.calculateOffset(this):n=Es(null,this.collectElementsOffset()),n.current}findBoxBreakPosition(e,n){let s=this.element.parentNode,i=this.element.nextSibling;s.removeChild(this.element),s.insertBefore(this.element,i);let r=e.checkPoints,a=r[0];for(;a.parent&&a.inline;)a=a.parent;let l,c;n?(l=1,c=1):(l=Math.max((a.inheritedProps.widows||2)-0,1),c=Math.max((a.inheritedProps.orphans||2)-0,1));let u=this.calculateClonedPaddingBorder(a),d=this.findLinePositions(r),h=this.footnoteEdge-u,f=this.getBoxDir(),g=this.getOffsetByRepetitiveElements(e);h-=f*g;let m=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(m.edge)&&(m.edge=f*(1/0));let y=Vt(d.length,v=>{let E=d[v];return this.vertical?E<h||E<=m.edge:E>h||E>=m.edge}),S=y<=0;S&&(y=Vt(d.length,v=>this.vertical?d[v]<h:d[v]>h));let C=r[r.length-1].viewNode;if((C==null?void 0:C.parentElement.localName)==="viv-ts-inner"&&(C=C.parentElement.parentElement),(y===d.length&&C.nextSibling||y>=d.length-1&&C.parentElement.querySelector(".MJXc-display"))&&(l=0),y=Math.min(d.length-l,y),y<c)return null;h=d[y-1];let x;if(S?x=m.checkPoint:x=this.findAcceptableBreakInside(e.checkPoints,h,n),x){let v=this.getAfterEdgeOfBlockContainer(x);!isNaN(v)&&f*(h-v)>0&&(h=v),this.computedBlockSize=f*(h-this.beforeEdge)+g}return x}getAfterEdgeOfBlockContainer(e){let n=e;do n=n.parent;while(n&&n.inline);return n?(n=n.copy().modify(),n.after=!0,xs(n,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let n=e.findIndex(i=>i.overflow);if(n<0)return{edge:NaN,checkPoint:null};let s=e[n];return{edge:this.calculateEdge(null,e,n,s.boxOffset),checkPoint:s}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,n,s){e.formattingContext;let r=new vs().find(e.formattingContext).finishBreak(this,e,n,s);return r||(r=Jr.finishBreak(this,e,n,s)),r}findAcceptableBreakPosition(){let e=null,n=null,s=0,i=0;do{s=i,i=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!n;--r){e=this.breakPositions[r],n=e.findAcceptableBreak(this,s);let a=e.getMinBreakPenalty();a>s&&(i=Math.min(i,a))}}while(i>s&&!n&&this.forceNonfitting);return{breakPosition:n?e:null,nodeContext:n}}doFinishBreak(e,n,s,i){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!n)return T(e);let r=A("doFinishBreak"),a=!1;if(!e){if(this.forceNonfitting)return F.warn("Could not find any page breaks?!!"),this.skipTailEdges(n).then(l=>{l?(l=l.modify(),l.overflow=!1,this.finishBreak(l,a,!0).then(()=>{r.finish(l)})):r.finish(l)}),r.result();e=s,a=!0,this.computedBlockSize=i}return this.finishBreak(e,a,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let n=e;n;n=n.parent)if(Ss(n.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 n=e.toString();return n==""||n=="auto"||!!n.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,n){if(!e)return!1;for(let a=e;a;a=a.parent)if(Ss(a.viewNode))return!1;if(Hn(e.viewNode))return!1;let s=xs(e,this.clientLayout,0,this.vertical),i=Es(e,this.collectElementsOffset()),r=this.isOverflown(s+(this.vertical?-1:1)*i.minimum);if(this.isOverflown(s+(this.vertical?-1:1)*i.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(n){let a=s+this.getTrailingMarginEdgeAdjustment(n),l=this.footnoteEdge-this.getBoxDir()*i.current;s=this.vertical?Math.min(s,Math.max(a,l)):Math.max(s,Math.min(a,l))}return this.updateMaxReachedAfterEdge(s),r}checkOverflowAndSaveEdgeAndBreakPosition(e,n,s,i){if(!e||Hn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,n);return(s||!r)&&this.saveEdgeBreakPosition(e,i,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==be.INLINE)return!1;let n=this.getComputedMargin(e.viewNode),s=e.viewNode.ownerDocument.createElement("div");this.vertical?(s.style.bottom="0px",s.style.width="1px",s.style.marginRight=`${n.right}px`):(s.style.right="0px",s.style.height="1px",s.style.marginTop=`${n.top}px`),e.viewNode.parentNode.insertBefore(s,e.viewNode);let i=Ut(this.clientLayout,s,this.vertical),r=this.getBeforeEdge(i),a=this.getBoxDir(),l=e.clearSide==="same"?e.floatSide:e.clearSide,c=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(l)?Cd(l,e.vertical,e.direction,this.layoutContext.page.side):l,u=c==="left"||c==="right"?e.direction==="rtl"==(c==="left")?"inline-end":"inline-start":c,d=this.pageFloatLayoutContext.getPageFloatClearEdge(u,this);switch(c){case"left":d=a*Math.max(d*a,this.leftFloatEdge*a);break;case"right":d=a*Math.max(d*a,this.rightFloatEdge*a);break;default:d=a*Math.max(d*a,Math.max(this.rightFloatEdge*a,this.leftFloatEdge*a))}let h=1/(this.clientLayout.pixelRatio||1);if(r*a+h>d*a)return e.viewNode.parentNode.removeChild(s),!1;{let f=Math.max(1,(d-r)*a);this.vertical?s.style.width=`${f}px`:s.style.height=`${f}px`,i=Ut(this.clientLayout,s,this.vertical);let g=this.getAfterEdge(i);if(!e.floatSide)if(this.vertical){let m=g-n.right-d;m>0==n.right>=0&&(m+=n.right),s.style.marginLeft=`${m}px`}else{let m=d-(g+n.top);m>0==n.top>=0&&(m+=n.top),s.style.marginBottom=`${m}px`}return e.clearSpacer=s,!0}}isBFC(e){return!!(em(e)||vn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,n,s){var y;let i=e.after?(y=e.parent)==null?void 0:y.formattingContext:e.formattingContext;if(i&&!this.isBFC(i))return T(e);let r=A("skipEdges"),a=!s&&n&&e&&e.after,l=s,c=null,u=[],d=[],h=!1;function f(){return!!s||!n&&He(l)&&!g()}function g(){var S;if(!c||e.floatSide)return!1;for(let C=c;C!=null&&C.parent;C=C.parent){let x=C.after?C.viewNode:(S=C.viewNode)==null?void 0:S.previousSibling;for(;x&&(Ce(x,C.parent.whitespace)||Ss(x));)x=x.previousSibling;if(x)return!1}return!0}let m=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=l};return r.loopWithFrame(S=>{var C;for(;e;){e.formattingContext;let x=new vs().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ce(e.viewNode,e.whitespace))break;if(!e.after){f()?m():this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)?(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=l),S.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ki(l)?l:null),x&&x.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&n&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),l,!1),!e.inline&&!e.repeatOnBreak&&(c?Td(c):this.breakPositions[this.breakPositions.length-1]instanceof hi)&&this.saveEdgeBreakPosition(e.copy(),l,!1),!this.isBFC(e.formattingContext)||vn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ce(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),l=ze(l,e.breakBefore),f()?m():(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0),S.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let N=e.viewNode.style;if(e.after){e.floatSide&&(l=l!=null?l:this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let L=e.sourceNode;if(L.localName==="svg"||L.localName==="math"||L.getAttribute("data-math-typeset")==="true"){h=!1,c=e.copy(),d.push(c),l=ze(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l);break}if(e.inline||x&&x.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(h){if(f()){m(),S.breakLoop();return}u=[],n=!1,a=!1,l=null}h=!1,c=e.copy(),d.push(c),l=ze(l,e.breakAfter),N&&!(this.zeroIndent(N.paddingBottom)&&this.zeroIndent(N.borderBottomWidth))&&(d=[c])}else{if(u.push(e.copy()),l=ze(l,e.breakBefore),c&&He(l)&&Zg(c.viewNode,e.viewNode),(e.pageType!=((C=e.parent)==null?void 0:C.pageType)||!He(l))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!this.stopAtOverflow,l),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){S.breakLoop();return}let L=e.viewNode.localName;if(gn[L]){f()?m():this.checkOverflowAndSaveEdgeAndBreakPosition(c,null,!0,l)&&(e=(this.stopAtOverflow&&c||e).modify(),e.overflow=!0),S.breakLoop();return}N&&!(this.zeroIndent(N.paddingTop)&&this.zeroIndent(N.borderTopWidth))&&(a=!1,d=[]),h=!0}}while(!1);let v=this.nextInTree(e,a);if(v.isPending()){v.then(E=>{e=E,S.continueLoop()});return}else e=v.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(c,d,!this.stopAtOverflow,l)?c&&this.stopAtOverflow&&(e=c.modify(),e.overflow=!0):He(l)&&(this.pageBreakType=l),S.breakLoop()}).then(()=>{c&&(this.lastAfterPosition=c.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let n=e.copy(),s=A("skipEdges"),i=null,r=!1;return s.loopWithFrame(a=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ce(e.viewNode,e.whitespace))break;if(!e.after){He(i)&&(this.pageBreakType=i),a.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){i=ze(i,e.breakBefore),He(i)&&(this.pageBreakType=i),a.breakLoop();return}if(e.viewNode.nodeType!=1)break;let c=e.viewNode.style;if(e.after){if(r){if(He(i)){this.pageBreakType=i,a.breakLoop();return}i=null}r=!1,i=ze(i,e.breakAfter)}else{i=ze(i,e.breakBefore);let u=e.viewNode.localName;if(gn[u]){He(i)&&(this.pageBreakType=i),a.breakLoop();return}if(c&&!(this.zeroIndent(c.paddingTop)&&this.zeroIndent(c.borderTopWidth))){a.breakLoop();return}}r=!0}while(!1);let l=this.layoutContext.nextInTree(e);if(l.isPending()){l.then(c=>{e=c,a.continueLoop()});return}else e=l.get()}n=null,a.breakLoop()}).then(()=>{s.finish(n)}),s.result()}layoutFloatOrFootnote(e){return ys(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,n,s){let i=A("layoutNext");return this.skipEdges(e,n,s||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))i.finish(e);else{let a=e.formattingContext;new vs().find(a).layout(e,this,n).thenFinish(i)}}),i.result()}clearOverflownViewNodes(e,n){if(e)for(let s=e.parent;e;e=s,s=s?s.parent:null){let i=(s||e).formattingContext;new vs().find(i).clearOverflownViewNodes(this,s,e,n),n=!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 n=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let s=this.originX+this.left+this.getInsetLeft(),i=this.originY+this.top+this.getInsetTop();this.box=new qe(s,i,s+this.width,i+this.height),this.startEdge=n?this.vertical?this.rtl?n.bottom:n.top:this.rtl?n.right:n.left:0,this.endEdge=n?this.vertical?this.rtl?n.top:n.bottom:this.rtl?n.left:n.right:0,this.beforeEdge=n?this.vertical?n.right:n.top:0,this.afterEdge=n?this.vertical?n.left:n.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Zf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],w(this.element,"width",`${this.width}px`),w(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,n,s){e.formattingContext;let i=e.copy(),r=new vs().find(e.formattingContext),a=this.calculateClonedPaddingBorder(i),l=r.createEdgeBreakPosition(i,n,s,this.computedBlockSize+a);this.breakPositions.push(l)}saveBoxBreakPosition(e){let n=e[0].breakPenalty;if(n){let i=e[0];for(;i.parent&&i.inline;)i=i.parent;n=i.breakPenalty}let s=new hi(e,n);this.breakPositions.push(s)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let n=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(n,this.computedBlockSize)}}layout(e,n,s){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return T(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?T(null):T(e);vd(this)&&Kr(this);let i=A("layout");return this.openAllViews(e.primary).then(r=>{let a=null;if(r.viewNode)a=r.copy();else{let c=u=>{u.nodeContext.viewNode&&(a=u.nodeContext,this.layoutContext.removeEventListener("nextInTree",c))};this.layoutContext.addEventListener("nextInTree",c)}let l=new Rp(n,s);l.layout(r,this).then(c=>{if(vd(this)){let u=this.element.lastElementChild&&this.clientLayout.getElementClientRect(this.element.lastElementChild);u&&ri(u,this.vertical)&&qr(this)}this.doFinishBreak(c,l.context.overflownNodeContext,a,l.initialComputedBlockSize).then(u=>{let d=null;this.pseudoParent?d=T(null):d=this.doFinishBreakOfFragmentLayoutConstraints(u),d.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){i.finish(null);return}if(!u)i.finish(null);else{this.overflown=!0;let h=new wt(u.toNodePosition());i.finish(h)}})})})}),i.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let n=A("doFinishBreakOfFragmentLayoutConstraints"),s=[].concat(this.fragmentLayoutConstraints);s.sort((r,a)=>r.getPriorityOfFinishBreak()-a.getPriorityOfFinishBreak());let i=0;return n.loop(()=>i<s.length?s[i++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{n.finish(!0)}),n.result()}doLayout(e,n,s){let i=A("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,i.loopWithFrame(a=>{for(;e;){let l=!0;if(this.layoutNext(e,n,s||null).then(c=>{if(n=!1,s=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=c,this.pageFloatLayoutContext.isInvalidated())a.breakLoop();else if(this.pageBreakType)a.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let u=this.findAcceptableBreakPosition();e=u.nodeContext,u.breakPosition&&u.breakPosition.breakPositionChosen(this),a.breakLoop()}else l?l=!1:a.continueLoop()}),l){l=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),a.breakLoop()}).then(()=>{i.finish({nodeContext:e,overflownNodeContext:r})}),i.result()}redoLayout(){let e=this.chunkPositions,n=this.element.lastChild;for(;n!=this.last;){let l=n.previousSibling;this.element===n.parentNode&&this.layoutContext.isPseudoelement(n)||this.element.removeChild(n),n=l}this.killFloats(),this.init();let s=A("redoLayout"),i=0,r=null,a=!0;return s.loopWithFrame(l=>{if(i<e.length){let c=e[i++];this.layout(c,a).then(u=>{a=!1,u?(r=u,l.breakLoop()):l.continueLoop()});return}l.breakLoop()}).then(()=>{s.finish(r)}),s.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 n=this;n;n=n.pseudoParent)n.fragmentLayoutConstraints.forEach(s=>{if(vn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let i=s.getRepetitiveElements();e.push(i)}if(Hr.isInstanceOfAfterIfContinuesLayoutConstraint(s)){let i=s.getRepetitiveElements();e.push(i)}an.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(this).forEach(i=>{e.push(i)})});return e}},gi=class{constructor(t,e,n){p(this,"startNodeContexts",[]);p(this,"column");this.column=Object.create(t),this.column.element=e,this.column.layoutContext=t.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=n.formattingContext,this.column.pseudoParent=t;let s=this.column.calculateClonedPaddingBorder(n);this.column.footnoteEdge=this.column.footnoteEdge-s;let i=this;this.column.openAllViews=function(r){return fi.prototype.openAllViews.call(this,r).thenAsync(a=>(i.startNodeContexts.push(a.copy()),T(a)))}}layout(t,e){return this.column.layout(t,e)}findAcceptableBreakPosition(t){let e=this.column.findAcceptableBreakPosition();if(t){let n=this.startNodeContexts[0].copy(),s=new wn(n,null,n.overflow,0);if(s.findAcceptableBreak(this.column,0),!e.nodeContext)return{breakPosition:s,nodeContext:n}}return e}finishBreak(t,e,n){return this.column.finishBreak(t,e,n)}doFinishBreakOfFragmentLayoutConstraints(t){this.column.doFinishBreakOfFragmentLayoutConstraints(t)}isStartNodeContext(t){let e=this.startNodeContexts[0];return e.viewNode===t.viewNode&&e.after===t.after&&e.offsetInNode===t.offsetInNode}isLastAfterNodeContext(t){return ln(t.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},cr=class{breakTextNode(t,e,n,s,i,r){if(e.after)e.offsetInNode=t.length;else{let a=n-e.boxOffset,l=t.data;l.charCodeAt(a)==173?a=this.breakAfterSoftHyphen(t,l,a,e):a=this.breakAfterOtherCharacter(t,l,a,e),a>0&&(e=this.updateNodeContext(e,a,t))}return e}breakAfterSoftHyphen(t,e,n,s){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(e.slice(0,n))?"\u200D":"";if(t.replaceData(n,e.length-n,s.breakWord?"":r+wm(s)),r){let a=s.preprocessedTextContent[0][1];s.preprocessedTextContent[0][1]=a.slice(0,n+1)+r+a.slice(n+1)}return n+1}breakAfterOtherCharacter(t,e,n,s){let i=e.charAt(n);n++;let r=e.charAt(n);return t.replaceData(n,e.length-n,!s.breakWord&&su(i)&&su(r)?wm(s):""),n}updateNodeContext(t,e,n){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};p(cr,"instance");cr.instance=new cr;function wm(o){return o.hyphenateCharacter||o.parent&&o.parent.hyphenateCharacter||"-"}var Rp=class extends Ns{constructor(e,n){super();this.leadingEdge=e;p(this,"breakAfter");p(this,"initialPageBreakType",null);p(this,"initialComputedBlockSize",0);p(this,"initialOverflown",!1);p(this,"context",{overflownNodeContext:null});this.breakAfter=n||null}resolveLayoutMode(e){return new Ip(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,n){n.fragmentLayoutConstraints=[],n.pseudoParent||nm()}clearNodes(e){super.clearNodes(e);let n=e;for(;n;){let s=n.viewNode;s&&ll(s.parentNode,s),n=n.parent}}saveState(e,n){super.saveState(e,n),this.initialPageBreakType=n.pageBreakType,this.initialComputedBlockSize=n.computedBlockSize,this.initialOverflown=n.overflown}restoreState(e,n){super.restoreState(e,n),n.pageBreakType=this.initialPageBreakType,n.computedBlockSize=this.initialComputedBlockSize,n.overflown=this.initialOverflown}},Ip=class{constructor(t,e,n){this.leadingEdge=t;this.breakAfter=e;this.context=n}doLayout(t,e){let n=A("DefaultLayoutMode.doLayout");return Vy(t,e).then(()=>{e.doLayout(t,this.leadingEdge,this.breakAfter).then(s=>{this.context.overflownNodeContext=s.overflownNodeContext,n.finish(s.nodeContext)})}),n.result()}accept(t,e){return e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||e.fragmentLayoutConstraints.length<=0?!0:e.fragmentLayoutConstraints.every(n=>n.allowLayout(t,this.context.overflownNodeContext,e))}postLayout(t,e,n,s){return s||(s=!n.fragmentLayoutConstraints.some(r=>r.nextCandidate(t))),n.fragmentLayoutConstraints.forEach(i=>{i.postLayout(s,t,e,n)}),s}},Vp=class extends fi{constructor(e,n,s,i,r,a,l){super(n,s,i,r,a);this.floatSide=e;this.parentContainer=l;p(this,"rootViewNodes",[]);p(this,"floatMargins",[]);p(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(n=>(n&&this.fixFloatSizeAndPosition(n),T(n)))}convertPercentageSizesToPx(e){let n=this.parentContainer.getPaddingRect(),s=n.x2-n.x1,i=n.y2-n.y1;function r(a,l){a.forEach(c=>{let u=en(e,c);if(u&&u.charAt(u.length-1)==="%"){let d=parseFloat(u),h=l*d/100;w(e,c,`${h}px`)}})}r(["width","max-width","min-width"],s),r(["height","max-height","min-height"],i),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?i:s),["margin-top","margin-right","margin-bottom","margin-left"].forEach(a=>{en(e,a)==="auto"&&w(e,a,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let n=e.viewNode;if(this.rootViewNodes.push(n),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(n),this.floatMargins.push(this.getComputedMargin(n)),this.adjustContentRelativeSize){let s=this.floatSide;if(this.parentContainer.vertical){if(s==="block-end"||s==="left"){let r=en(n,"height");r!==""&&r!=="auto"&&w(n,"margin-top","auto")}}else if(s==="block-end"||s==="bottom"){let r=en(n,"width");r!==""&&r!=="auto"&&w(n,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=Ut(this.clientLayout,e,this.vertical),i=this.floatMargins[n];return this.vertical?i.top+s.height+i.bottom:i.left+s.width+i.right}))}};var un=class{constructor(t,e){this.parent=t;this.rootSourceNode=e;p(this,"formattingContextType","RepetitiveElementsOwner");p(this,"isRoot",!1);p(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(t,e){return e}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(t){let e=this.getRootNodeContext(t);return e?e.viewNode:null}getRootNodeContext(t){do if(!t.belongsTo(this)&&t.sourceNode===this.rootSourceNode)return t;while(t=t.parent);return null}initializeRepetitiveElements(t){if(this.repetitiveElements)return;dl.some(n=>n.root===this.rootSourceNode?(this.repetitiveElements=n.elements,!0):!1)||(this.repetitiveElements=new Bp(t,this.rootSourceNode),dl.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},Bp=class{constructor(t,e){this.vertical=t;this.ownerSourceNode=e;p(this,"headerSourceNode",null);p(this,"footerSourceNode",null);p(this,"headerViewNode",null);p(this,"footerViewNode",null);p(this,"headerNodePosition",null);p(this,"footerNodePosition",null);p(this,"headerHeight",0);p(this,"footerHeight",0);p(this,"isSkipHeader",!1);p(this,"isSkipFooter",!1);p(this,"enableSkippingFooter",!0);p(this,"enableSkippingHeader",!0);p(this,"doneInitialLayout",!1);p(this,"firstContentSourceNode",null);p(this,"lastContentSourceNode",null);p(this,"affectedNodeCache",[]);p(this,"afterLastContentNodeCache",[]);p(this,"allowInsert",!1);p(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(t){this.headerNodePosition||(this.headerNodePosition=ii(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=ii(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=Qr(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Qr(this.footerViewNode,t,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(t,e,n){return!this.headerNodePosition||this.isSkipHeader?T(!0):this.appendElementToFragment(this.headerNodePosition,t,e,n)}appendFooterToFragment(t,e,n){return!this.footerNodePosition||this.isSkipFooter?T(!0):this.appendElementToFragment(this.footerNodePosition,t,e,n)}appendElementToFragment(t,e,n,s){let i=e.viewNode.ownerDocument,r=e.viewNode,a=i.createElement("div");r.appendChild(a);let l=new gi(s,a,e),c=l.getColumn().pageBreakType;return l.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,l.layout(new wt(t),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(a),this.moveChildren(a,r,n),l.getColumn().pageBreakType=c,T(!0)))}moveChildren(t,e,n){if(e)for(;t.firstChild;){let s=t.firstChild;t.removeChild(s),s.setAttribute(Tn,"1"),n?e.insertBefore(s,n):e.appendChild(s)}}calculateOffset(t){let e=0;return t&&!this.affectTo(t)||((!this.isSkipFooter||t&&this.isAfterLastContent(t))&&(e+=this.footerHeight),this.isSkipHeader||(e+=this.headerHeight)),e}calculateMinimumOffset(t){let e=0;return t&&!this.affectTo(t)||(!this.enableSkippingFooter&&t&&this.isAfterLastContent(t)&&(e+=this.footerHeight),this.enableSkippingHeader||(e+=this.headerHeight)),e}isAfterLastContent(t){return this.findResultFromCache(t,this.afterLastContentNodeCache,e=>this.isAfterNodeContextOf(this.lastContentSourceNode,t,!1))}affectTo(t){return this.findResultFromCache(t,this.affectedNodeCache,e=>this.isAfterNodeContextOf(this.ownerSourceNode,t,!0))}findResultFromCache(t,e,n){let s=e.filter(i=>i.nodeContext.sourceNode===t.sourceNode&&i.nodeContext.after===t.after);if(s.length>0)return s[0].result;{let i=n(t);return e.push({nodeContext:t,result:i}),i}}isAfterNodeContextOf(t,e,n){let s=[];for(let i=t;i;i=i.parentNode){if(e.sourceNode===i)return e.after;s.push(i)}for(let i=e.sourceNode;i;i=i.parentNode){let r=s.indexOf(i);if(r>=0)return n?r===0:!1;for(let a=i;a;a=a.previousElementSibling)if(s.includes(a))return!0}return e.after}isFirstContentNode(t){return t&&this.firstContentSourceNode===t.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(t){return this.headerSourceNode===t}isFooterSourceNode(t){return this.footerSourceNode===t}},uo=class{constructor(t){this.formattingContext=t}accept(t,e){return!!t}postLayout(t,e,n,s){let i=this.formattingContext.getRepetitiveElements();return i&&(n.clientLayout,i.doneInitialLayout||(i.updateHeight(n),i.doneInitialLayout=!0)),s}},po=class{constructor(t){this.formattingContext=t}accept(t,e){return!0}postLayout(t,e,n,s){return s}},Op=class extends uo{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}accept(e,n){return!1}},Dp=class extends po{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return!e.belongsTo(this.formattingContext)&&!e.after&&n.fragmentLayoutConstraints.unshift(new ur(e)),this.processor.doLayout(e,n)}},ur=class o{constructor(t){p(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner");p(this,"nodeContext");let e=Kn(t.formattingContext);this.nodeContext=e.getRootNodeContext(t)}allowLayout(t,e,n){let s=this.getRepetitiveElements();return!s||Hn(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(e&&!t||t&&t.overflow)}nextCandidate(t){let e=this.getRepetitiveElements();return e&&e.isEnableToUpdateState()?(e.updateState(),!0):!1}postLayout(t,e,n,s){let i=this.getRepetitiveElements();i&&t&&s.stopAtOverflow&&(e==null||i.isAfterLastContent(e))&&i.preventSkippingFooter()}finishBreak(t,e){let n=Kn(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return T(!0);let i=this.nodeContext;return Oy(n,i,e).thenAsync(()=>Dy(n,i,e).thenAsync(()=>(s.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return Kn(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof o?Kn(this.nodeContext.formattingContext)===Kn(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Mp=class extends Ns{constructor(e,n){super();this.formattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!n.doneInitialLayout?new Op(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&n&&n.preventSkippingHeader(),new Dp(this.formattingContext,this.processor))}},_p=class extends Wn{constructor(e,n){super();this.formattingContext=e;this.column=n}startNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,i=n.getRepetitiveElements();if(s.parent&&n.rootSourceNode===s.parent.sourceNode){switch(s.repeatOnBreak){case"header":if(i.isHeaderRegistered())s.repeatOnBreak="none";else return i.setHeaderNodeContext(s),T(!0);break;case"footer":if(i.isFooterRegistered())s.repeatOnBreak="none";else return i.setFooterNodeContext(s),T(!0);break}i.firstContentSourceNode||(i.firstContentSourceNode=s.sourceNode)}return Wn.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext;return s.sourceNode===n.rootSourceNode&&(n.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),s.repeatOnBreak==="header"||s.repeatOnBreak==="footer"?T(!0):Wn.prototype.afterNonInlineElementNode.call(this,e)}};var Up=class extends Pn{layout(t,e,n){if(e.isFloatNodeContext(t))return e.layoutFloatOrFootnote(t);let s=Kn(t.formattingContext);return s.getRootViewNode(t)?(n&&Hp(t.parent,e),t.belongsTo(s)?Pn.prototype.layout.call(this,t,e,n):new Mp(s,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let n=My(t).getRepetitiveElements();return n&&!n.allowInsertRepeatitiveElements&&(n.isHeaderSourceNode(t.sourceNode)||n.isFooterSourceNode(t.sourceNode))&&t.viewNode.parentNode.removeChild(t.viewNode),!1}doInitialLayout(t,e){let n=Kn(t.formattingContext),s=A("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(s),s.result()}layoutEntireBlock(t,e){let n=Kn(t.formattingContext),s=new _p(n,e);return new ai(s,e.layoutContext).iterate(t)}doLayout(t,e){let n=Kn(t.formattingContext),s=A("doLayout"),i=e.layoutContext.nextInTree(t,!1);return Fp(i,e).then(r=>{let a=r;s.loopWithFrame(l=>{for(;a;){let c=!0;if(e.layoutNext(a,!1).then(u=>{a=u,e.pageFloatLayoutContext.isInvalidated()||e.pageBreakType||a&&e.stopByOverflow(a)||a&&a.after&&a.sourceNode==n.rootSourceNode?l.breakLoop():c?c=!1:l.continueLoop()}),c){c=!1;return}}l.breakLoop()}).then(()=>{s.finish(a)})}),s.result()}finishBreak(t,e,n,s){return Pn.prototype.finishBreak.call(this,t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Pn.prototype.clearOverflownViewNodes(t,e,n,s)}};function By(o,t){for(let e=o;e;e=e.parent){let n=e.formattingContext;n&&n instanceof un&&!e.belongsTo(n)&&t(n,e)}}function Hp(o,t){o&&By(o.after?o.parent:o,(e,n)=>{an.isInstanceOfTableFormattingContext(e)||t.fragmentLayoutConstraints.push(new ur(n))})}function Oy(o,t,e){let n=o.getRepetitiveElements();if(n){let s=o.getRootNodeContext(t);if(s.viewNode){let i=s.viewNode.firstChild;return n.appendHeaderToFragment(s,i,e)}}return T(!0)}function Dy(o,t,e){let n=o.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=o.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,e)}return T(!0)}function My(o){let t=o.formattingContext;return!t||!(t instanceof un)?null:t}function Kn(o){return o instanceof un,o}var _y=new Up;Ke("RESOLVE_LAYOUT_PROCESSOR",o=>o instanceof un&&!an.isInstanceOfTableFormattingContext(o)?_y:null);var Bl=class{constructor(t,e){this.rowIndex=t;this.sourceNode=e;p(this,"cells",[])}addCell(t){this.cells.push(t)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(t=>t.height))}},Gp=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;p(this,"viewElement");p(this,"colSpan");p(this,"rowSpan");p(this,"height",0);p(this,"anchorSlot",null);this.viewElement=n,this.colSpan=n.colSpan||1,this.rowSpan=n.rowSpan||1}setHeight(t){this.height=t}setAnchorSlot(t){this.anchorSlot=t}},Wp=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;this.cell=n}},Xp=class{constructor(t,e,n){this.column=t;this.cellNodeContext=n;p(this,"pseudoColumn");p(this,"empty",!1);this.pseudoColumn=new gi(t,e,n)}findAcceptableBreakPosition(){let t=this.cellNodeContext.viewNode,{verticalAlign:e,alignContent:n}=t.style;e!=="top"&&e!=="baseline"&&w(t,"vertical-align","top"),n&&n!=="normal"&&w(t,"align-content","normal");let s=this.pseudoColumn.findAcceptableBreakPosition(!0);return w(t,"vertical-align",e),n&&n!=="normal"&&w(t,"align-content",n),s}},$p=class{constructor(t,e){this.viewNode=t;this.side=e}},jp=class extends wn{constructor(e,n,s,i){super(e,n,s,i);p(this,"formattingContext");p(this,"acceptableCellBreakPositions",null);p(this,"rowIndex",null);this.formattingContext=e.formattingContext}findAcceptableBreak(e,n){let s=super.findAcceptableBreak(e,n);return n<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(r=>!!r.nodeContext)?s:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(s=>{e+=s.breakPosition.getMinBreakPenalty()});let n=this.getCellFragments();return e+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,n=this.getCellFragments();this.acceptableCellBreakPositions=n.map(s=>s.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)}},Yp=class extends oi{constructor(e,n,s){super();this.rowIndex=e;this.beforeNodeContext=n;this.formattingContext=s;p(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,n){if(this!==e.breakPositions[0]&&n<this.getMinBreakPenalty())return null;let s=this.getCellFragments(),i=this.getAcceptableCellBreakPositions(),r=i.every(a=>!!a.nodeContext)&&i.some((a,l)=>{let c=s[l].pseudoColumn,u=a.nodeContext;return!c.isStartNodeContext(u)&&!c.isLastAfterNodeContext(u)});return this.beforeNodeContext.overflow=i.some(a=>a.nodeContext&&a.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let n=this.formattingContext.getRowByIndex(this.rowIndex),s=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),r=this.getCellFragments();s+=Math.max(0,...r.map(l=>l.cellNodeContext.breakPenalty));let a=i.some((l,c)=>l.breakPosition instanceof hi&&r[c].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((l,c)=>{let u=l.breakPosition.getMinBreakPenalty();a&&l.breakPosition instanceof wn&&l.breakPosition.overflows&&u>=3&&(r[c].column.checkOverflowAndSaveEdge(l.nodeContext,null)||(u-=3)),s+=u}),s}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(n=>n.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Ls=class extends un{constructor(e,n){super(e,n);this.tableSourceNode=n;p(this,"formattingContextType","Table");p(this,"vertical",!1);p(this,"columnCount",-1);p(this,"tableWidth",0);p(this,"captions",[]);p(this,"colGroups",null);p(this,"colWidths",null);p(this,"inlineBorderSpacing",0);p(this,"rows",[]);p(this,"slots",[]);p(this,"cellFragments",[]);p(this,"lastRowViewNode",null);p(this,"cellBreakPositions",[]);p(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,n){if(!n)return n;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(s=>s.cellNodePosition.steps[0].node===e.sourceNode);default:return n}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,n){this.rows[e]=n}getRowSlots(e){let n=this.slots[e];return n||(n=this.slots[e]=[]),n}addCell(e,n){let s=this.rows[e];s||(this.addRow(e,new Bl(e,null)),s=this.rows[e]),s.addCell(n);let i=e+n.rowSpan,r=this.getRowSlots(e),a=0;for(;r[a];)a++;for(;e<i;e++){r=this.getRowSlots(e);for(let l=a;l<a+n.colSpan;l++){let c=r[l]=new Wp(e,l,n);n.anchorSlot||n.setAnchorSlot(c)}}}getRowByIndex(e){let n=this.rows[e];return n}findRowIndexBySourceNode(e){return this.rows.findIndex(n=>e===n.sourceNode)}addCellFragment(e,n,s){let i=this.cellFragments[e];i||(i=this.cellFragments[e]=[]),i[n]=s}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((s,i)=>i.cell!==s[s.length-1]?s.concat(i.cell):s,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(n=>n.rowIndex+n.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((n,s)=>n+s.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(n=>{n.cells.forEach(s=>{let i=Ut(e,s.viewElement,this.vertical);s.viewElement=null,s.setHeight(this.vertical?i.width:i.height)})})}findCellFromColumn(e){if(!e)return null;let n=null,s=0,i=0;e:for(s=0;s<this.cellFragments.length;s++)if(this.cellFragments[s]){for(i=0;i<this.cellFragments[s].length;i++)if(this.cellFragments[s][i]&&e===this.cellFragments[s][i].pseudoColumn.getColumn()){n=this.rows[s].cells[i];break e}}if(!n)return null;for(;s<this.slots.length;s++)for(;i<this.slots[s].length;i++){let r=this.slots[s][i];if(r.cell===n)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let n=[];return this.slots.reduce((s,i,r)=>{if(r>=e.rowIndex)return s;let a=i[e.columnIndex]&&this.getCellFragmentOfCell(i[e.columnIndex].cell);return!a||n.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),s),n.push(a)),s},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(n=>{n.cells.forEach((s,i)=>{e[i]||(e[i]={collected:[],elements:[]});let r=e[i],a=this.getCellFragmentOfCell(s);!a||r.collected.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),r.elements),r.collected.push(a))})}),[new Kp(e.map(n=>n.elements))]}collectElementsOffsetFromColumn(e,n){e.fragmentLayoutConstraints.forEach(s=>{if(vn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let i=s.getRepetitiveElements();n.push(i)}an.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(null).forEach(i=>{n.push(i)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Kp=class{constructor(t){this.repeatitiveElementsInColumns=t}calculateOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.current)}calculateMinimumOffset(t){return this.calculateMaxOffsetOfColumn(t,e=>e.minimum)}calculateMaxOffsetOfColumn(t,e){let n=0;return this.repeatitiveElementsInColumns.forEach(s=>{let i=Es(t,s);n=Math.max(n,e(i))}),n}};function Kt(o){return o instanceof Ls,o}function Uy(o){return o==="table-row-group"||o==="table-header-group"||o==="table-footer-group"}function Hy(o){return o==="table"||o==="inline-table"}function Lm(o){return Uy(o)||Hy(o)}function Rm(o,t,e){let n=o.nodeContext,s=n.display,i=n.parent?n.parent.display:null,r=!1;if(i==="inline-table"&&!(n.formattingContext instanceof Ls)){for(let l=n.parent;l;l=l.parent)if(l.formattingContext instanceof Ls){r=l.formattingContext===t;break}}return r||s==="table-row"&&!Lm(i)||s==="table-cell"&&i!=="table-row"&&!Lm(i)||n.formattingContext instanceof Ls&&n.formattingContext!==t?e.buildDeepElementView(n).thenAsync(l=>(o.nodeContext=l,T(!0))):null}var qp=class extends Wn{constructor(e,n){super();this.formattingContext=e;this.column=n;p(this,"rowIndex",-1);p(this,"columnIndex",0);p(this,"inRow",!1);p(this,"checkPoints",[]);p(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let n=this.formattingContext,s=Rm(e,n,this.column);if(s)return s;this.postLayoutBlockContents(e);let i=e.nodeContext,r=i.display,a=n.getRepetitiveElements();switch(r){case"table":n.inlineBorderSpacing=i.inlineBorderSpacing;break;case"table-caption":{let l=new $p(i.viewNode,i.captionSide);n.captions.push(l);break}case"table-header-group":return a.isHeaderRegistered()||(this.inHeaderOrFooter=!0,a.setHeaderNodeContext(i)),T(!0);case"table-footer-group":return a.isFooterRegistered()||(this.inHeaderOrFooter=!0,a.setFooterNodeContext(i)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,i.sourceNode,this.columnIndex=0,n.addRow(this.rowIndex,new Bl(this.rowIndex,i.sourceNode)),a.firstContentSourceNode||(a.firstContentSourceNode=i.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,i=s.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),s.sourceNode===n.tableSourceNode){let a=r.getElementComputedStyle(n.getRootViewNode(s));n.tableWidth=parseFloat(a[n.vertical?"height":"width"]),n.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(i){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":this.inHeaderOrFooter||(n.lastRowViewNode=s.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let a=s.viewNode;n.addCell(this.rowIndex,new Gp(this.rowIndex,this.columnIndex,a)),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 n=e.nodeContext;n&&n.viewNode&&!zn(n)&&this.checkPoints.push(n.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Dl=class Dl extends Wn{constructor(e,n){super(!0);this.formattingContext=e;this.column=n;p(this,"inRow",!1);p(this,"currentRowIndex",-1);p(this,"currentColumnIndex",0);p(this,"originalStopAtOverflow");p(this,"inHeader");p(this,"inFooter");this.originalStopAtOverflow=n.stopAtOverflow,n.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(e){let n=this.formattingContext.colWidths;let s=0;for(let i=0;i<e.colSpan;i++)s+=n[e.anchorSlot.columnIndex+i];return s+=this.formattingContext.inlineBorderSpacing*(e.colSpan-1),s}layoutCell(e,n,s){let i=e.rowIndex,r=e.columnIndex,a=e.colSpan,l=n.viewNode,c=n.verticalAlign;a>1&&(w(l,"box-sizing","border-box"),w(l,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(e)}px`));let u=l.ownerDocument.createElement("div");l.appendChild(u);let d=new Xp(this.column,u,n);return this.formattingContext.addCellFragment(i,r,d),s.primary.steps.length===1&&s.primary.after&&(d.empty=!0),d.pseudoColumn.layout(s,!0).thenReturn(!0)}hasBrokenCellAtSlot(e){let n=this.formattingContext.cellBreakPositions[0];return n?n.cell.anchorSlot.columnIndex===e:!1}extractRowSpanningCellBreakPositions(){let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let n=[],s=0;do{let i=e[s],r=i.cell.rowIndex;if(r<this.currentRowIndex){let a=n[r];a||(a=n[r]=[]),a.push(i),e.splice(s,1)}else s++}while(s<e.length);return n}layoutRowSpanningCellsFromPreviousFragment(e){let n=this.formattingContext,s=this.extractRowSpanningCellBreakPositions(),i=s.reduce(h=>h+1,0);if(i===0)return T(!0);let r=this.column.layoutContext,a=e.nodeContext;a.viewNode.parentNode.removeChild(a.viewNode);let l=A("layoutRowSpanningCellsFromPreviousFragment"),c=T(!0),u=0,d=[];return s.forEach(h=>{c=c.thenAsync(()=>{let f=Ji(h[0].cellNodePosition.steps[1],a.parent);return r.setCurrent(f,!1).thenAsync(()=>{let g=T(!0),m=0;function y(S){for(;m<S;){if(!d.includes(m)){let C=f.viewNode.ownerDocument.createElement("td");w(C,"padding","0"),f.viewNode.appendChild(C)}m++}}return h.forEach(S=>{g=g.thenAsync(()=>{let C=S.cell;y(C.anchorSlot.columnIndex);let x=S.cellNodePosition,v=Ji(x.steps[0],f);return v.offsetInNode=x.offsetInNode,v.after=x.after,v.fragmentIndex=x.steps[0].fragmentIndex+1,r.setCurrent(v,!1).thenAsync(()=>{let E=S.breakChunkPosition;for(let N=0;N<C.colSpan;N++)d.push(m+N);return m+=C.colSpan,this.layoutCell(C,v,E).thenAsync(()=>(v.viewNode.rowSpan=C.rowIndex+C.rowSpan-this.currentRowIndex+i-u,T(!0)))})})}),g.thenAsync(()=>(y(n.getColumnCount()),u++,T(!0)))})})}),c.then(()=>{r.setCurrent(a,!0,e.atUnforcedBreak).then(()=>{l.finish(!0)})}),l.result()}startTableRow(e){if(this.inHeader||this.inFooter)return T(!0);let n=e.nodeContext,s=this.formattingContext;return this.currentRowIndex<0?(n.sourceNode,this.currentRowIndex=s.findRowIndexBySourceNode(n.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(e).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge)&&s.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),n.overflow=!0,e.break=!0),T(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(n=>{let s=this.formattingContext.cellBreakPositions[n.columnIndex];if(s&&s.cell.anchorSlot.columnIndex==n.anchorSlot.columnIndex){let i=s.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(i.node);Pm(r,i.fragmentIndex+1,1)}})}startTableCell(e){if(this.inHeader||this.inFooter)return T(!0);let n=e.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let s=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!s)return e.break=!0,T(!0);let i=n.copy().modify();i.after=!0,e.nodeContext=i;let r=A("startTableCell"),a;if(this.hasBrokenCellAtSlot(s.anchorSlot.columnIndex)){let l=this.formattingContext.cellBreakPositions.shift();n.fragmentIndex=l.cellNodePosition.steps[0].fragmentIndex+1,a=T(l.breakChunkPosition)}else a=this.column.nextInTree(n,e.atUnforcedBreak).thenAsync(l=>{l.viewNode&&n.viewNode.removeChild(l.viewNode);let c=ii(l,0);return T(new wt(c))});return a.then(l=>{this.layoutCell(s,n,l).then(()=>{this.afterNonInlineElementNode(e),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(e){let n=Rm(e,Kt(this.formattingContext),this.column);if(n)return n;let s=e.nodeContext,i=this.formattingContext.getRepetitiveElements(),r=s.display;return r==="table-header-group"&&i&&i.isHeaderSourceNode(s.sourceNode)?(this.inHeader=!0,T(!0)):r==="table-footer-group"&&i&&i.isFooterSourceNode(s.sourceNode)?(this.inFooter=!0,T(!0)):r==="table-row"?this.startTableRow(e):r==="table-cell"?this.startTableCell(e):T(!0)}endNonInlineBox(e){let n=e.nodeContext;if(n.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let i=n.copy().modify();i.after=!1;let r=new Yp(this.currentRowIndex,i,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(e){let n=e.nodeContext,s=this.formattingContext.getRepetitiveElements(),i=n.display;if(i==="table-header-group"?s&&!s.allowInsertRepeatitiveElements&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!1,n.viewNode.parentNode.removeChild(n.viewNode)):w(n.viewNode,"display","table-row-group"):i==="table-footer-group"&&(s&&!s.allowInsertRepeatitiveElements&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!1,n.viewNode.parentNode.removeChild(n.viewNode)):w(n.viewNode,"display","table-row-group")),i&&Dl.ignoreList[i])n.viewNode.parentNode.removeChild(n.viewNode);else if(n.sourceNode===this.formattingContext.tableSourceNode)n.overflow=this.column.checkOverflowAndSaveEdge(n,null),this.resetColumn(),e.break=!0;else return super.afterNonInlineElementNode(e);return T(!0)}};p(Dl,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Zp=Dl,ho=[];function zy(o){let t=ho.findIndex(n=>n.root===o),e=ho[t];return e?e.tableLayoutOption:null}function Gy(o){let t=ho.findIndex(e=>e.root===o);t>=0&&ho.splice(t,1)}var Ol=class{layoutEntireTable(t,e){let n=Kt(t.formattingContext),s=new qp(n,e);return new ai(s,e.layoutContext).iterate(t)}getColumnWidths(t,e,n,s){let i=t.ownerDocument,r=i.createElement("tr"),a=[];for(let c=0;c<e;c++){let u=i.createElement("td");r.appendChild(u),a.push(u)}t.parentNode.insertBefore(r,t.nextSibling);let l=a.map(c=>{let u=Ut(s,c,n),d=n?u.height:u.width;return Math.ceil(d)});return t.parentNode.removeChild(r),l}getColGroupElements(t){let e=[],n=t.firstElementChild;for(;n;)n.localName==="colgroup"&&e.push(n),n=n.nextElementSibling;return e}normalizeAndGetColElements(t){let e=[];return t.forEach(n=>{let s=n.span;n.removeAttribute("span");let i=n.firstElementChild;for(;i;){if(i.localName==="col"){let r=i.span;for(i.removeAttribute("span"),s-=r;r-- >1;){let a=i.cloneNode(!0);n.insertBefore(a,i),e.push(a)}e.push(i)}i=i.nextElementSibling}for(;s-- >0;)i=n.ownerDocument.createElement("col"),n.appendChild(i),e.push(i)}),e}addMissingColElements(t,e,n,s){if(t.length<n){let i=s.ownerDocument.createElement("colgroup");e.push(i);for(let r=t.length;r<n;r++){let a=s.ownerDocument.createElement("col");i.appendChild(a),t.push(a)}}}normalizeColGroups(t,e,n){let s=t.vertical,i=t.lastRowViewNode;if(!i)return;t.lastRowViewNode=null;let a=i.ownerDocument.createDocumentFragment(),l=t.getColumnCount();if(!(l>0)){t.colGroups=a;return}let c=t.colWidths=this.getColumnWidths(i,l,s,n.clientLayout),u=this.getColGroupElements(e),d=this.normalizeAndGetColElements(u);this.addMissingColElements(d,u,l,e),d.forEach((h,f)=>{w(h,s?"height":"width",`${c[f]}px`)}),u.forEach(h=>{a.appendChild(h.cloneNode(!0))}),t.colGroups=a}doInitialLayout(t,e){let n=Kt(t.formattingContext);n.vertical=t.vertical,n.initializeRepetitiveElements(t.vertical),t.sourceNode;let s=zy(t.sourceNode);Gy(t.sourceNode);let i=A("TableLayoutProcessor.doInitialLayout"),r=t.copy();return this.layoutEntireTable(t,e).then(a=>{let l=a.viewNode,c=Ut(e.clientLayout,l,e.vertical),u=e.vertical?c.left:c.bottom;if(u+=(e.vertical?-1:1)*Es(t,e.collectElementsOffset()).current,!e.isOverflown(u)&&(!s||!s.calculateBreakPositionsInside)){e.breakPositions.push(new eh(r)),i.finish(a);return}this.normalizeColGroups(n,l,e),n.updateCellSizes(e.clientLayout),i.finish(null)}),i.result()}addCaptions(t,e,n){let s=t.captions;s.forEach((i,r)=>{i&&(e.insertBefore(i.viewNode,n),i.side==="top"&&(s[r]=null))})}addColGroups(t,e,n){t.colGroups&&this.getColGroupElements(e).length===0&&(e.insertBefore(t.colGroups.cloneNode(!0),n),w(e,"table-layout","fixed"),w(e,t.vertical?"height":"width",`${t.tableWidth}px`))}removeColGroups(t,e){if(t.colGroups&&e){let n=this.getColGroupElements(e);n&&n.forEach(s=>{e.removeChild(s)})}}doLayout(t,e){let n=Kt(t.formattingContext),s=n.getRootViewNode(t),i=s.firstChild;this.addCaptions(n,s,i),this.addColGroups(n,s,i);let r=new Zp(n,e),a=new ai(r,e.layoutContext),l=A("TableFormattingContext.doLayout");return a.iterate(t).thenFinish(l),l.result()}layout(t,e,n){let s=Kt(t.formattingContext),i=s.getRootViewNode(t),r=A("TableFormattingContext.layout"),a;return i?(n&&Hp(t.parent,e),a=new Qp(s,this).layout(t,e)):a=e.buildDeepElementView(t),a.then(l=>{r.finish(l),e.element.hasAttribute("data-vivliostyle-column-height-adjusted")&&(w(e.element,"width",`${e.width}px`),w(e.element,"height",`${e.height}px`),e.element.removeAttribute("data-vivliostyle-column-height-adjusted"))}),r.result()}createEdgeBreakPosition(t,e,n,s){return new jp(t,e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return zp(t),!1}finishBreak(t,e,n,s){let i=Kt(e.formattingContext);if(e.display==="table-row"){e.sourceNode;let r=i.findRowIndexBySourceNode(e.sourceNode);i.cellBreakPositions=[];let a;if(e.after?a=i.getRowSpanningCellsOverflowingTheRow(r):a=i.getCellsFallingOnRow(r),a.length){let l=A("TableLayoutProcessor.finishBreak"),c=0;return l.loopWithFrame(u=>{if(c===a.length){u.breakLoop();return}let d=a[c++],h=i.getCellFragmentOfCell(d),f=h.findAcceptableBreakPosition().nodeContext;let g=h.cellNodeContext,m=g.toNodePosition(),y=new wt(f.toNodePosition());i.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:y,cell:d});let S=g.viewNode;h.column.layoutContext.processFragmentedBlockEdge(h.cellNodeContext),r<d.rowIndex+d.rowSpan-1&&(S.rowSpan=r-d.rowIndex+1),h.empty?u.continueLoop():h.pseudoColumn.finishBreak(f,!1,!0).then(()=>{Wy(h,i,f),u.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),zp(e),i.finishFragment(),l.finish(!0)}),l.result()}}return zp(e),i.finishFragment(),Jr.finishBreak(t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Pn.prototype.clearOverflownViewNodes(t,e,n,s)}};function Wy(o,t,e){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,i=o.column,r=o.pseudoColumn.getColumnElement(),a=o.cellNodeContext.viewNode,l=Ut(i.clientLayout,a,s),c=i.getComputedPaddingBorder(a);if(s){let u=l.right-i.footnoteEdge-n.calculateOffset(e)-c.right;w(r,"max-width",`${u}px`)}else{let u=i.footnoteEdge-n.calculateOffset(e)-l.top-c.top;w(r,"max-height",`${u}px`)}}function zp(o){let t=o.display==="table-row"?o.viewNode.parentElement:o.display==="table"?o.viewNode.querySelector("tbody"):null;if(!t)return;let e;try{e=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch(d){return}if(e.length===0)return;let n=Array.from(e).reduce((d,h)=>{let f=h.getBoundingClientRect(),g=o.vertical?f.width:f.height;return d+g},0),s=e[e.length-1],i=Array.from(t.children).indexOf(s),r=Array.from(s.children).reduce((d,h)=>{let f=h.rowSpan;return f>1&&i+f<t.childElementCount?Math.max(d,f):d},0),a=r?t.children[i+r-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let l=a.getBoundingClientRect(),c=o.vertical?l.width:l.height,u=n+c;w(a,o.vertical?"width":"height",`${u}px`)}var Qp=class extends Ns{constructor(e,n){super();this.tableFormattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.tableFormattingContext.getRepetitiveElements();return!n||!n.doneInitialLayout?new Jp(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&n&&n.preventSkippingHeader(),new nh(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let n=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,n)}restoreState(e,n){super.restoreState(e,n),this.tableFormattingContext.finishFragment()}},Jp=class extends uo{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}},eh=class extends wn{constructor(t){super(t,null,t.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(t){t.fragmentLayoutConstraints.push(new th(this.position.sourceNode))}},th=class o{constructor(t){this.tableRootNode=t;p(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,e,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,e,n,s){e.sourceNode,ho.push({root:e.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,e){return T(!0)}equalsTo(t){return t instanceof o&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},nh=class extends po{constructor(e,n){super(e);this.processor=n}doLayout(e,n){let s=this.formattingContext.getRepetitiveElements();if(s&&!s.isAfterLastContent(e)){let i=new sh(e);n.fragmentLayoutConstraints.some(r=>i.equalsTo(r))||n.fragmentLayoutConstraints.unshift(i)}return this.processor.doLayout(e,n)}},sh=class o extends ur{constructor(e){super(e);p(this,"flagmentLayoutConstraintType","TableRow");p(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,n,s){let i=this.getRepetitiveElements();return!i||s.pseudoParent||Hn(this.nodeContext.viewNode)||!i.isEnableToUpdateState()?!0:!(n&&!e||e&&e.overflow)}nextCandidate(e){let n=Kt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(e,n).some(i=>i.constraints.some(r=>r.nextCandidate(e)))?!0:super.nextCandidate(e)}postLayout(e,n,s,i){let r=Kt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(n,r),this.cellFragmentLayoutConstraints.forEach(a=>{a.constraints.forEach(l=>{l.postLayout(e,a.breakPosition,s,i)})}),!e){let a=r.getRootViewNode(this.nodeContext);new Ol().removeColGroups(r,a),this.removeDummyRowNodes(s)}super.postLayout(e,n,s,i)}finishBreak(e,n){let s=Kt(this.nodeContext.formattingContext),i=A("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((l,c)=>l.concat(c.constraints.map(u=>({constraint:u,breakPosition:c.breakPosition}))),[]),a=0;return i.loop(()=>{if(a<r.length){let l=r[a++];return l.constraint.finishBreak(l.breakPosition,n).thenReturn(!0)}else return T(!1)}).then(()=>{i.finish(!0)}),i.result().thenAsync(()=>super.finishBreak(e,n))}removeDummyRowNodes(e){if(!(!e||e.display!=="table-row"||!e.viewNode))for(;e.viewNode.previousElementSibling;){let n=e.viewNode.previousElementSibling;n.parentNode&&n.parentNode.removeChild(n)}}collectCellFragmentLayoutConstraints(e,n){return this.getCellFragemnts(e,n).map(s=>({constraints:s.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:s.breakPosition}))}getCellFragemnts(e,n){let s=Number.MAX_VALUE;e&&e.display==="table-row"&&(e.sourceNode,s=n.findRowIndexBySourceNode(e.sourceNode)+1),s=Math.min(n.cellFragments.length,s);let i=[];for(let r=0;r<s;r++)n.cellFragments[r]&&n.cellFragments[r].forEach(a=>{a&&i.push({fragment:a,breakPosition:a.findAcceptableBreakPosition().nodeContext})});return i}getElementsOffsetsForTableCell(e){let n=Kt(this.nodeContext.formattingContext),s=n.findCellFromColumn(e);return s?n.collectElementsOffsetOfUpperCells(s):n.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof o?Kt(this.nodeContext.formattingContext)===Kt(e.nodeContext.formattingContext):!1}},Xy=new Ol;function $y(o,t,e,n,s,i){if(!t)return null;if(e===b.table){let r=o.parent;return new Ls(r?r.formattingContext:null,o.sourceNode)}return null}function jy(o){return o instanceof Ls?Xy:null}Ke("RESOLVE_FORMATTING_CONTEXT",$y);Ke("RESOLVE_LAYOUT_PROCESSOR",jy);function Im(o){return o.reduce((t,e)=>t+e,0)/o.length}function Vm(o){let t=Im(o);return Im(o.map(e=>{let n=e-t;return n*n}))}var ih=class{constructor(t,e){this.layoutResult=t;this.penalty=e}};function fo(o){return o.vertical?o.width:o.height}function go(o,t){o.vertical?o.width=t:o.height=t}var Ml=class{constructor(t,e,n){this.layoutContainer=t;this.columnGenerator=e;this.regionPageFloatLayoutContext=n;p(this,"originalContainerBlockSize");this.originalContainerBlockSize=fo(t)}balanceColumns(t){let e=A("ColumnBalancer#balanceColumns");this.preBalance(t),this.savePageFloatLayoutContexts(t),this.layoutContainer.clear();let n=[this.createTrialResult(t)];return e.loopWithFrame(s=>{if(!this.hasNextCandidate(n)){s.breakLoop();return}this.updateCondition(n),this.columnGenerator().then(i=>{if(this.savePageFloatLayoutContexts(i),this.layoutContainer.clear(),!i){s.breakLoop();return}n.push(this.createTrialResult(i)),s.continueLoop()})}).then(()=>{let s=n.reduce((i,r)=>r.penalty<i.penalty?r:i,n[0]);this.restoreContents(s.layoutResult),this.postBalance(),e.finish(s.layoutResult)}),e.result()}createTrialResult(t){let e=this.calculatePenalty(t);return new ih(t,e)}preBalance(t){}postBalance(){go(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(t){let e=this.regionPageFloatLayoutContext.detachChildren();t&&(t.columnPageFloatLayoutContexts=e)}restoreContents(t){let e=this.layoutContainer.element;t.columns.forEach(n=>{e.appendChild(n.element)}),t.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(t.columnPageFloatLayoutContexts)}},rh=1;function Bm(o){let t=o[o.length-1];if(t.penalty===0)return!1;let e=o[o.length-2];if(e&&t.penalty>=e.penalty)return!1;let n=t.layoutResult.columns,s=Math.max.apply(null,n.map(r=>r.computedBlockSize)),i=Math.max.apply(null,n.map(r=>r.getMaxBlockSizeOfPageFloats()));return s>i+rh}function Om(o,t){var i;let e=o[o.length-1].layoutResult.columns,s=Math.max.apply(null,e.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+rh))-rh;if(s<fo(t)?go(t,s):go(t,fo(t)-1),t.vertical){let r=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=r-t.width}}var oh=class extends Ml{constructor(e,n,s,i){super(s,e,n);this.columnCount=i;p(this,"originalPosition",null);p(this,"foundUpperBound",!1)}preBalance(e){let s=e.columns.reduce((i,r)=>i+r.computedBlockSize,0);go(this.layoutContainer,s/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 n=e.columns;return Fm(n)?1/0:Math.max.apply(null,n.map(s=>s.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Bm(e);{let n=e[e.length-1];return this.checkPosition(n.layoutResult.position)&&!Fm(n.layoutResult.columns)?(this.foundUpperBound=!0,!0):fo(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Om(e,this.layoutContainer);else{let n=Math.min(this.originalContainerBlockSize,fo(this.layoutContainer)+this.originalContainerBlockSize*.1);go(this.layoutContainer,n)}}};function Fm(o){if(o.length<=1)return!1;let t=o[o.length-1].computedBlockSize,e=o.slice(0,o.length-1),n=6;return e.every(s=>t>s.computedBlockSize+n)}var ah=class extends Ml{constructor(t,e,n){super(n,t,e)}calculatePenalty(t){if(t.columns.every(n=>n.computedBlockSize===0))return 1/0;let e=t.columns.filter(n=>!n.pageBreakType).map(n=>n.computedBlockSize);return Vm(e)}hasNextCandidate(t){return Bm(t)}updateCondition(t){Om(t,this.layoutContainer)}};function Dm(o,t,e,n,s,i,r){if(t===b.auto)return null;{let a=r.positions.length===0,l=i[i.length-1],c=!!(l&&l.pageBreakType);return a||c?new oh(e,n,s,o):t===b.balance_all?new ah(e,n,s):(b.balance,null)}}var qy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Zy=new Set(qy);function Qy(o){return!(o.toLowerCase()==="none"||Zy.has(o))}var Jy=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],ex=new Set(Jy),tx=["fixed","extends"],nx=new Set(tx),LE=Symbol();function Ao(o){return o instanceof Y&&o.name.toLowerCase()!=="none"}function _m(o){return o.name}function sx(o){if(o instanceof Y)return ex.has(o.name);if(o instanceof G&&o.values.length===2){let t=o.values[0],e=o.values[1];if(t instanceof Y){let n=t.name;return nx.has(n)&&(n==="fixed"&&e instanceof se||n==="extends"&&Ao(e))}}return!1}function ix(o){let t=at(o,"system");return t instanceof Y&&t.name==="cyclic"}function rx(o){let t=at(o,"system");if(t instanceof Y&&t.name==="fixed")return!0;if(t instanceof G&&t.values.length===2){let[e,n]=t.values;return e instanceof Y&&e.name==="fixed"&&n instanceof se}return!1}function ox(o){let t=at(o,"system");return t instanceof Y?1:t.values[1].num}function ax(o){let t=at(o,"system");return t instanceof Y&&t.name==="alphabetic"}function lx(o){let t=at(o,"system");return t instanceof Y&&t.name==="numeric"}function cx(o){let t=at(o,"system");return t instanceof Y&&t.name==="additive"}function ux(o){let t=at(o,"system");if(t instanceof G&&t.values.length===2){let[e,n]=t.values;return e instanceof Y&&e.name==="extends"&&Ao(n)}return!1}function dx(o){let t=at(o,"system");return _m(t.values[1])}function qt(o){return o instanceof M||o instanceof Y}function Zn(o){return o instanceof M?o.str:o.name}function Um(o){if(qt(o))return!0;if(o instanceof G&&o.values.length===2){let t=o.values[0],e=o.values[1];return qt(t)&&qt(e)}return!1}function px(o){if(qt(o))return{prefix:Zn(o),suffix:null};{let t=o.values[0],e=o.values[1];return{prefix:Zn(t),suffix:Zn(e)}}}function Mm(o){return o instanceof se||o instanceof Y&&o.name==="infinite"}function _l(o,t){return o instanceof se?o.num:t?-1/0:1/0}var RE=Symbol();function lh(o){if(!(o instanceof G&&o.values.length===2))return!1;let t=o.values[0],e=o.values[1];if(!(Mm(t)&&Mm(e)))return!1;let n=_l(t,!0),s=_l(e,!1);return!(n>s)}function hx(o){return{lower:_l(o.values[0],!0),upper:_l(o.values[1],!1)}}function Hm(o){return o instanceof Y&&o.name==="auto"||lh(o)||o instanceof me&&o.values.length>=1&&o.values.every(t=>lh(t))}function fx(o){return o instanceof Y?null:(lh(o)?[o]:o.values).map(e=>hx(e))}var IE=Symbol();function Ul(o){if(!(o instanceof G&&o.values.length===2))return!1;let t=o.values[0],e=o.values[1];return t instanceof se&&t.num>=0&&qt(e)||qt(t)&&e instanceof se&&e.num>=0}function Hl(o){let[t,e]=o.values;return t instanceof se?[t.num,Zn(e)]:[e.num,Zn(t)]}function zm(o){return Ul(o)}function gx(o){let[t,e]=Hl(o);return{minLength:t,symbol:e}}function Gm(o){return qt(o)||o instanceof G&&o.values.length>=1&&o.values.every(t=>qt(t))}function mx(o){return qt(o)?[Zn(o)]:o.values.map(t=>Zn(t))}var VE=Symbol();function Wm(o){if(Ul(o))return!0;if(o instanceof me&&o.values.length>=1){let t=1/0;for(let e of o.values){if(!Ul(e))return!1;let[n]=Hl(e);if(n>=t)return!1;t=n}return!0}return!1}function Cx(o){if(Ul(o)){let[t,e]=Hl(o);return[{weight:t,symbol:e}]}else return o.values.map(t=>{let[e,n]=Hl(t);return{weight:e,symbol:n}})}var bx=["auto","bullets","numbers","words","spell-out"],yx=new Set(bx);function xx(o){return o instanceof Y&&yx.has(o.name)||Ao(o)}function Xm(o,t){switch(o){case"system":return sx(t);case"negative":return Um(t);case"prefix":case"suffix":return qt(t);case"range":return Hm(t);case"pad":return zm(t);case"fallback":return Ao(t);case"symbols":return Gm(t);case"additive-symbols":return Wm(t);case"speak-as":return xx(t);default:return!0}}function at(o,t){var n;let e=(n=o[t])==null?void 0:n.value;return e==null?null:e}function Sx(o,t){return t.some(({lower:e,upper:n})=>o>=e&&o<=n)}function pr(o){let t=o.get("decimal");return t||(t=Q.createDecimal(o),o.set("decimal",t)),t}var Co,bo,yo,xo,So,Eo,vo,No,Xl,$l,jl,Yl,Kl,ql,Zl,Ae,ch,$m,jm,Ym,Km,uh,qm,mo,gt=class gt{constructor(t,e){j(this,Ae);p(this,"_store");j(this,Co);j(this,bo);j(this,yo);j(this,xo);j(this,So);j(this,Eo);j(this,vo);j(this,No);this._store=t;let n=at(e,"negative");Se(this,Co,n&&Um(n)?px(n):null);let s=at(e,"prefix");Se(this,bo,s&&qt(s)?Zn(s):null);let i=at(e,"suffix");Se(this,yo,i&&qt(i)?Zn(i):null);let r=at(e,"range");Se(this,xo,r&&Hm(r)?fx(r):null);let a=at(e,"pad");Se(this,So,a&&zm(a)?gx(a):null);let l=at(e,"fallback");Se(this,Eo,l&&Ao(l)?_m(l):null);let c=at(e,"symbols");Se(this,vo,c&&Gm(c)?mx(c):null);let u=at(e,"additive-symbols");Se(this,No,u&&Wm(u)?Cx(u):null)}static create(t,e){return ix(e)?new qn(t,e):rx(e)?new dh(t,e):ax(e)?new hh(t,e):lx(e)?new zl(t,e):cx(e)?new fh(t,e):ux(e)?new gh(t,e):new ph(t,e)}static createDecimal(t){return new zl(t,V(gt,Xl))}static createDisc(t){return new qn(t,V(gt,$l))}static createSquare(t){return new qn(t,V(gt,jl))}static createCircle(t){return new qn(t,V(gt,Yl))}static createDisclosureOpen(t){return new qn(t,V(gt,Kl))}static createDisclosureClosed(t){return new qn(t,V(this,ql))}static createNone(t){return new qn(t,V(gt,Zl))}static get CHINESE_LONGHAND_NAMES(){return Gl.NAMES}static createChineseLonghand(t,e){return new Gl(t,e)}static createEthiopicNumeric(t){return new mh(t)}_getNegative(){return V(this,Co)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return V(this,bo)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return V(this,yo)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return V(this,xo)}static _getRangeFrom(t){return t._getRange()}_getPad(){return V(this,So)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(V(this,Eo)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return V(this,vo)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return V(this,No)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,e){return t._usesNegativeSign(e)}static _generateInitialRepresentationFrom(t,e){return t._generateInitialRepresentation(e)}format(t){return ae(this,Ae,mo).call(this,t,new Set)}formatMarker(t){return ae(this,Ae,$m).call(this)+this.format(t)+ae(this,Ae,jm).call(this)}};Co=new WeakMap,bo=new WeakMap,yo=new WeakMap,xo=new WeakMap,So=new WeakMap,Eo=new WeakMap,vo=new WeakMap,No=new WeakMap,Xl=new WeakMap,$l=new WeakMap,jl=new WeakMap,Yl=new WeakMap,Kl=new WeakMap,ql=new WeakMap,Zl=new WeakMap,Ae=new WeakSet,ch=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},$m=function(){var t;return(t=this._getPrefix())!=null?t:""},jm=function(){var t;return(t=this._getSuffix())!=null?t:". "},Ym=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},Km=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},uh=function(){var t;return(t=this._getFallback())!=null?t:pr(this._store)},qm=function(t,e){let{minLength:n,symbol:s}=ae(this,Ae,Km).call(this);if(n===0||s==="")return t;let{prefix:i,suffix:r}=ae(this,Ae,ch).call(this),a=e?[...i].length+(r?[...r].length:0):0,l=n-[...t].length-a;if(l<=0)return t;let c=[...s].length,u=Math.ceil(l/c);return s.repeat(u)+t},mo=function(t,e){var a,l,c;if(e.has(this))return ae(a=pr(this._store),Ae,mo).call(a,t,new Set);if(e.add(this),!Sx(t,ae(this,Ae,Ym).call(this))){let u=ae(this,Ae,uh).call(this);return ae(l=u,Ae,mo).call(l,t,e)}let n=this._usesNegativeSign(t),s=n?Math.abs(t):t,i=this._generateInitialRepresentation(s);if(i===null){let u=ae(this,Ae,uh).call(this);return ae(c=u,Ae,mo).call(c,t,e)}let r=ae(this,Ae,qm).call(this,i,n);if(n){let{prefix:u,suffix:d}=ae(this,Ae,ch).call(this);r=u+r+(d!=null?d:"")}return r},j(gt,Xl,{system:new I(k("numeric"),0),symbols:new I(new G([new M("0"),new M("1"),new M("2"),new M("3"),new M("4"),new M("5"),new M("6"),new M("7"),new M("8"),new M("9")]),0)}),j(gt,$l,{system:new I(k("cyclic"),0),symbols:new I(new M("\u2022"),0),suffix:new I(new M(" "),0)}),j(gt,jl,{system:new I(k("cyclic"),0),symbols:new I(new M("\u25AA"),0),suffix:new I(new M(" "),0)}),j(gt,Yl,{system:new I(k("cyclic"),0),symbols:new I(new M("\u25E6"),0),suffix:new I(new M(" "),0)}),j(gt,Kl,{system:new I(k("cyclic"),0),symbols:new I(new M("\u25BE"),0),suffix:new I(new M(" "),0)}),j(gt,ql,{system:new I(k("cyclic"),0),symbols:new I(new M("\u25B8"),0),suffix:new I(new M(" "),0)}),j(gt,Zl,{system:new I(k("cyclic"),0),symbols:new I(new M(""),0),suffix:new I(new M(""),0)});var Q=gt,qn=class extends Q{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0)return null;let n=e.length,s=((t-1)%n+n)%n;return e[s]}},To,dh=class extends Q{constructor(e,n){super(e,n);j(this,To);Se(this,To,ox(n))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var i;let n=this._getSymbols();if(!n||n.length===0)return null;let s=e-V(this,To);return(i=n[s])!=null?i:null}};To=new WeakMap;var ph=class extends Q{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length===0||t<1)return null;let n=e.length,s=e[(t-1)%n],i=Math.ceil(t/n);return s.repeat(i)}},hh=class extends Q{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2||t<1)return null;let n=e.length,s="",i=t;for(;i!==0;)i=i-1,s=e[i%n]+s,i=Math.floor(i/n);return s}},zl=class extends Q{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getSymbols();if(!e||e.length<2)return null;let n=e.length;if(t===0)return e[0];let s="",i=t;for(;i!==0;)s=e[i%n]+s,i=Math.floor(i/n);return s}},fh=class extends Q{constructor(t,e){super(t,e)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let e=this._getAdditiveSymbols();if(!e||e.length===0)return null;let n="";if(t===0){let i=e.find(r=>r.weight===0);return i?i.symbol:null}let s=t;for(let i of e){let{weight:r,symbol:a}=i;if(r===0||r>s)continue;let l=Math.floor(s/r);if(n+=a.repeat(l),s-=r*l,s===0)return n}return null}},dr,mt,Ht,Ch=class Ch extends Q{constructor(e,n){super(e,n);j(this,mt);j(this,dr);let s=dx(n),i=s.toLowerCase();i==="disc"||i==="circle"||i==="square"||i==="disclosure-open"||i==="disclosure-closed"?Se(this,dr,i):Se(this,dr,s)}_getNegative(){var e;return(e=super._getNegative())!=null?e:Q._getNegativeFrom(ae(this,mt,Ht).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:Q._getPrefixFrom(ae(this,mt,Ht).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:Q._getSuffixFrom(ae(this,mt,Ht).call(this))}_getAutoRange(){return Q._getAutoRangeFrom(ae(this,mt,Ht).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:Q._getRangeFrom(ae(this,mt,Ht).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:Q._getPadFrom(ae(this,mt,Ht).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:Q._getFallbackFrom(ae(this,mt,Ht).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:Q._getSymbolsFrom(ae(this,mt,Ht).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:Q._getAdditiveSymbolsFrom(ae(this,mt,Ht).call(this))}_usesNegativeSign(e){return Q._useNegativeSignFrom(ae(this,mt,Ht).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:Q._generateInitialRepresentationFrom(ae(this,mt,Ht).call(this),e)}};dr=new WeakMap,mt=new WeakSet,Ht=function(e=new Set){var s;if(e.has(this))return pr(this._store);e.add(this);let n=this._store.get(V(this,dr));return n?n instanceof Ch?ae(s=n,mt,Ht).call(s,e):n:pr(this._store)};var gh=Ch,Ex=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Ql,Jl,wo,ec,tc,Po,kt=class kt extends Q{constructor(e,n){let{chars:s,descriptors:i}=V(kt,tc).get(n);super(e,i);j(this,Po);Se(this,Po,s)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let n=V(this,Po);if(e===0)return n.digits[0];let s=[],i=0,r=e;for(;r>0;)s.unshift({digit:r%10,position:i}),r=Math.floor(r/10),i++;let a=n.informal&&e>=10&&e<=19,l="",c=!1;for(let u=0;u<s.length;u++){let{digit:d,position:h}=s[u],f=u===s.length-1;d===0?!f&&!c&&(c=!0):(c&&(l+=n.digits[0],c=!1),a&&h===1?l+=n.markers[h]:(l+=n.digits[d],h>0&&(l+=n.markers[h])))}return l}};Ql=new WeakMap,Jl=new WeakMap,wo=new WeakMap,ec=new WeakMap,tc=new WeakMap,Po=new WeakMap,j(kt,Ql,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new I(new M("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new G([new se(-9999),new se(9999)]),0),negative:new I(new M("\u8D1F"),0)}}),j(kt,Jl,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new I(new M("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new G([new se(-9999),new se(9999)]),0),negative:new I(new M("\u8D1F"),0)}}),j(kt,wo,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new I(new M("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new G([new se(-9999),new se(9999)]),0),negative:new I(new M("\u8CA0"),0)}}),j(kt,ec,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new I(new M("\u3001"),0),fallback:new I(k("cjk-decimal"),0),range:new I(new G([new se(-9999),new se(9999)]),0),negative:new I(new M("\u8CA0"),0)}}),p(kt,"NAMES",new Set(Ex)),j(kt,tc,new Map([["simp-chinese-informal",V(kt,Ql)],["simp-chinese-formal",V(kt,Jl)],["trad-chinese-informal",V(kt,wo)],["trad-chinese-formal",V(kt,ec)],["cjk-ideographic",V(kt,wo)]]));var Gl=kt,nc,sc,ko,ic,rc,zt=class zt extends Q{constructor(t){super(t,V(zt,nc))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return V(zt,ko)[1];let e=[],n=t;for(;n>0;)e.push(n%100),n=Math.floor(n/100);let s=e.length,i="";for(let r=s-1;r>=0;r--){let a=e[r],l=r%2===1,c=r===s-1;if(!(a===0||c&&a===1||l&&a===1)){let d=Math.floor(a/10),h=a%10;i+=V(zt,sc)[d]+V(zt,ko)[h]}l?a!==0&&(i+=V(zt,ic)):r!==0&&(i+=V(zt,rc))}return i}};nc=new WeakMap,sc=new WeakMap,ko=new WeakMap,ic=new WeakMap,rc=new WeakMap,j(zt,nc,{range:new I(new G([new se(1),k("infinite")]),0),suffix:new I(new M("/ "),0)}),j(zt,sc,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),j(zt,ko,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),j(zt,ic,"\u137B"),j(zt,rc,"\u137C");var mh=zt,ye,Wl=class{constructor(){j(this,ye);Se(this,ye,new Map),V(this,ye).set("none",Q.createNone(V(this,ye))),V(this,ye).set("decimal",Q.createDecimal(V(this,ye))),V(this,ye).set("disc",Q.createDisc(V(this,ye))),V(this,ye).set("square",Q.createSquare(V(this,ye))),V(this,ye).set("circle",Q.createCircle(V(this,ye))),V(this,ye).set("disclosure-open",Q.createDisclosureOpen(V(this,ye))),V(this,ye).set("disclosure-closed",Q.createDisclosureClosed(V(this,ye)));for(let t of Q.CHINESE_LONGHAND_NAMES)V(this,ye).set(t,Q.createChineseLonghand(V(this,ye),t));V(this,ye).set("ethiopic-numeric",Q.createEthiopicNumeric(V(this,ye)))}define(t,e){if(!Qy(t))return null;let n=Q.create(V(this,ye),e);return V(this,ye).set(t,n),n}getStyle(t){var e;return(e=V(this,ye).get(t))!=null?e:null}format(t,e){var n;return((n=this.getStyle(t))!=null?n:pr(V(this,ye))).format(e)}formatMarker(t,e){var n;return((n=this.getStyle(t))!=null?n:pr(V(this,ye))).formatMarker(e)}};ye=new WeakMap;var Lo=class{constructor(t,e,n){p(this,"endStuckFixed");p(this,"endFixed");p(this,"endSlipped");this.endStuckFixed=t,this.endFixed=e,this.endSlipped=n}},bh=class{constructor(){p(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(t){if(this.map.length==0)this.map.push(new Lo(t,t,t));else{let e=this.map[this.map.length-1],n=e.endSlipped+t-e.endFixed;e.endFixed==e.endStuckFixed?(e.endFixed=t,e.endStuckFixed=t,e.endSlipped=n):this.map.push(new Lo(t,t,n))}}addSlippedRange(t){this.map.length==0?this.map.push(new Lo(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=Vt(this.map.length,s=>t<=this.map[s].endFixed),n=this.map[e];return n.endSlipped-Math.max(0,n.endStuckFixed-t)}fixedBySlipped(t){let e=Vt(this.map.length,s=>t<=this.map[s].endSlipped),n=this.map[e];return n.endStuckFixed-(n.endSlipped-t)}},yh=class o{constructor(t,e,n,s,i,r,a,l){this.context=t;this.style=e;this.offset=n;this.isRoot=s;this.flowChunk=i;this.atBlockStart=r;this.atFlowStart=a;this.isParentBoxDisplayed=l;p(this,"flowName");p(this,"isBlockValue",null);p(this,"hasBoxValue",null);p(this,"styleValues",{});p(this,"beforeBox",null);p(this,"afterBox",null);p(this,"breakBefore",null);if(this.flowName=i.flowName,this.hasBox()){let c=e._pseudos;if(c&&c.before){let u=new o(t,c.before,n,!1,i,this.isBlock(),a,!0),d=u.styleValue("content");ht(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=ze(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&He(this.breakBefore)&&(i.breakBefore=ze(i.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,e,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let i=new o(this.context,s.after,t,!1,this.flowChunk,e,n,!0),r=i.styleValue("content");ht(r)&&(this.afterBox=i)}}}styleValue(t,e){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):e||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",b.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),e=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=rl(t,e,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==b.none&&!jr(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let e=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(e=n.toString())}return e}},xh=class{constructor(t){this.context=t;p(this,"stack",[]);p(this,"atBlockStart",!0);p(this,"atFlowStart",!0);p(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let t=this.lastBox();return t?t.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(t=>t.displayValue()!==b.none)}push(t,e,n,s){let i=this.lastBox();s&&i&&s.flowName!==i.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=s||i.flowChunk,a=this.atFlowStart||!!s,l=this.isCurrentBoxDisplayed(),c=new yh(this.context,t,e,n,r,a||this.atBlockStart,a,l);return this.stack.push(c),this.atBlockStart=c.hasBox()?!c.beforeBox&&c.isBlock():this.atBlockStart,this.atFlowStart=c.hasBox()?!c.beforeBox&&a:this.atFlowStart,c}encounteredTextNode(t){let e=this.lastBox();if((t.nodeType===Node.TEXT_NODE||t.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&e.hasBox()){let n=e.styleValue("white-space",b.normal).toString(),s=tl(n);s&&!Ce(t,s)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(t){let e=this.stack.pop();if(e.buildAfterPseudoElementBox(t,this.atBlockStart,this.atFlowStart),this.atFlowStart&&e.afterBox){let s=e.afterBox.getBreakValue("before");e.flowChunk.breakBefore=ze(e.flowChunk.breakBefore,s)}let n=this.lastBox();if(n)if(n.flowName===e.flowName)e.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let s=this.atStartStack.pop();this.atBlockStart=s.atBlockStart,this.atFlowStart=s.atFlowStart}return e}nearestBlockStartOffset(t){if(!t.atBlockStart)return t.offset;let e=this.stack.length-1,n=this.stack[e];for(n===t&&(e--,n=this.stack[e]);e>=0;){if(n.flowName!==t.flowName)return t.offset;if(!n.atBlockStart||n.isRoot)return n.offset;t=n,n=this.stack[--e]}throw new Error("No block start offset found!")}},Ro=class{constructor(t,e,n,s,i,r,a,l,c,u){this.xmldoc=t;this.scope=n;this.context=s;this.primaryFlows=i;this.validatorSet=r;this.counterListener=a;p(this,"root");p(this,"cascadeHolder");p(this,"last");p(this,"rootStyle",{});p(this,"styleMap",{});p(this,"flows",{});p(this,"flowChunks",[]);p(this,"flowListener",null);p(this,"flowToReach",null);p(this,"idToReach",null);p(this,"cascade");p(this,"offsetMap");p(this,"primary",!0);p(this,"primaryStack",[]);p(this,"rootBackgroundAssigned",!1);p(this,"rootLayoutAssigned",!1);p(this,"lastOffset");p(this,"breakBeforeValues",{});p(this,"boxStack");p(this,"bodyReached",!0);this.root=t.root,this.cascadeHolder=e,this.last=this.root,this.cascade=e.createInstance(s,a,l,t.lang,c,u),this.offsetMap=new bh;let d=t.getElementOffset(this.root);this.lastOffset=d,this.boxStack=new xh(s),this.offsetMap.addStuckRange(d);let h=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,h,d),this.postprocessTopStyle(h,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${d}`]=h,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(t,e,n){let s=t[n];return s&&s.evaluate(this.context)!==e[n]}transferPropsToRoot(t,e){for(let n in e){let s=t[n];if(s)this.rootStyle[n]=s,delete t[n];else{let i=e[n];i&&(this.rootStyle[n]=new I(i,td))}}}postprocessTopStyle(t,e){var n;if(e)for(let s of["writing-mode","direction"])t[s]&&!(e&&this.rootStyle[s])&&(this.rootStyle[s]=t[s]);else for(let s in t)As(s)&&(this.rootStyle[s]=t[s]);if(!this.rootBackgroundAssigned){let s=this.hasProp(t,this.validatorSet.backgroundProps,"background-color")?t["background-color"].evaluate(this.context):null,i=this.hasProp(t,this.validatorSet.backgroundProps,"background-image")?t["background-image"].evaluate(this.context):null;(s&&!X(s)||i&&!X(i))&&(this.transferPropsToRoot(t,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let s=0;s<Qm.length;s++)if(this.hasProp(t,this.validatorSet.layoutProps,Qm[s])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!e){let s=t["font-size"],i=!0;if(s&&!X(s.value)){let l=s.evaluate(this.context);if(l instanceof P){let c=l.num;switch(l.unit){case"em":case"rem":c*=this.context.initialFontSize;break;case"%":c*=this.context.initialFontSize/100;break;case"lh":case"rlh":c*=this.context.initialFontSize*Je.lh/Je.em;break;default:{let u=Je[l.unit];u&&(c*=u),i=!1}}this.context.rootFontSize=c,this.context.isRelativeRootFontSize=i}}let r=(n=this.context.rootFontSize)!=null?n:this.context.initialFontSize,a=t["line-height"];if(a&&!X(a.value)){let l=a.evaluate(this.context);if(l instanceof Re)this.context.rootLineHeight=l.num*r;else if(l instanceof P){let c=l.num;switch(l.unit){case"em":case"rem":c*=r;break;case"%":c*=r/100;break;case"lh":case"rlh":c*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let u=Je[l.unit];u&&(c*=u)}}this.context.rootLineHeight=c}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let t=0;for(;!this.bodyReached&&(t+=5e3,this.styleUntil(t,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(t){if(t.style instanceof CSSStyleDeclaration){let e=t.getAttribute("style");if(e)return dm(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(t){if(t>=this.lastOffset)return;let e=this.context,n=this.xmldoc.getElementOffset(this.root);if(t<n){let r=this.getStyle(this.root,!1);let a=de(r,"flow-into"),l=a?a.evaluate(e,"flow-into").toString():"body",c=this.encounteredFlowElement(l,r,this.root,n);this.boxStack.empty()&&this.boxStack.push(r,n,!0,c)}let s=this.xmldoc.getNodeByOffset(t),i=this.xmldoc.getNodeOffset(s,0,!1);if(!(i>=this.lastOffset))for(;;){if(s.nodeType!=1)i+=s.textContent.length;else{let a=s,l=this.getStyle(a,!1),c=l["flow-into"];if(c){let u=c.evaluate(e,"flow-into").toString();this.encounteredFlowElement(u,l,a,i)}i++}if(i>=this.lastOffset)break;let r=s.firstChild;if(r==null){for(;r=s.nextSibling,!r;)if(s=s.parentNode,s===this.root)return}s=r}}resetFlowChunkStream(t){this.flowListener=t;for(let e=0;e<this.flowChunks.length;e++)this.flowListener.encounteredFlowChunk(this.flowChunks[e],this.flows[this.flowChunks[e].flowName])}styleUntilFlowIsReached(t){this.flowToReach=t;let e=0;for(;!(this.flowToReach==null||(e+=5e3,this.styleUntil(e,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(t){if(!t)return;this.idToReach=t;let e=0;for(;!(!this.idToReach||(e+=5e3,this.styleUntil(e,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(t,e,n,s){let i=0,r=Number.POSITIVE_INFINITY,a=!1,l=!1,c=!1,u=e["flow-options"];if(u){let y=ig(u.evaluate(this.context,"flow-options"));a=!!y.exclusive,l=!!y.static,c=!!y.last}let d=e["flow-linger"];d&&(r=Tu(d.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let h=e["flow-priority"];h&&(i=Tu(h.evaluate(this.context,"flow-priority"),0));let f=this.breakBeforeValues[s]||null,g=this.flows[t];if(!g){let y=this.boxStack.lastFlowName();g=this.flows[t]=new Ka(t,y)}let m=new qa(t,n,s,i,r,a,l,c,f);return this.flowChunks.push(m),this.flowToReach==t&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,g),m}registerForcedBreakOffset(t,e,n){if(He(t)){let i=this.flows[n].forcedBreakOffsets;(i.length===0||i[i.length-1]<e)&&i.push(e)}let s=this.breakBeforeValues[e];this.breakBeforeValues[e]=ze(s,t)}styleUntil(t,e){let n=-1,s;if(t<=this.lastOffset&&(s=this.offsetMap.slippedByFixed(t),n=s+e,n<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(n);if(this.last==null)return Number.POSITIVE_INFINITY;let i=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 a=this.boxStack.pop(this.lastOffset),l=null;if(a.afterBox){let c=a.afterBox.getBreakValue("before");this.registerForcedBreakOffset(c,a.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(a):a.afterBox.offset,a.flowName),l=a.afterBox.getBreakValue("after")}l=ze(l,a.getBreakValue("after")),this.registerForcedBreakOffset(l,this.lastOffset,a.flowName)}if(r=this.last.nextSibling,r)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,t<this.lastOffset&&(n<0&&(s=this.offsetMap.slippedByFixed(t),n=s+e),n<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(n):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 a=this.last,l=this.getAttrStyle(a);this.primaryStack.push(this.primary),this.cascade.pushElement(this,a,l,this.lastOffset);let c=a.getAttribute("id")||a.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");c&&c===this.idToReach&&(this.idToReach=null),!this.bodyReached&&a.localName=="body"&&a.parentNode==this.root&&(this.postprocessTopStyle(l,!0),this.bodyReached=!0);let u,d=l["flow-into"];if(d){let f=d.evaluate(i,"flow-into").toString(),g=this.encounteredFlowElement(f,l,a,this.lastOffset);this.primary=!!this.primaryFlows[f],u=this.boxStack.push(l,this.lastOffset,a===this.root,g)}else u=this.boxStack.push(l,this.lastOffset,a===this.root),a===this.xmldoc.body&&(u.breakBefore=ze(u.flowChunk.breakBefore,u.breakBefore));let h=this.boxStack.nearestBlockStartOffset(u);if(h===0){let f=l.page,g=f&&!X(f.value)&&f.value.toString();g&&g.toLowerCase()!=="auto"&&(this.cascade.firstPageType=g)}if(this.registerForcedBreakOffset(u.breakBefore,h,u.flowName),u.beforeBox){let f=u.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(f,u.beforeBox.atBlockStart?h:u.offset,u.flowName)}if(this.primary&&u.displayValue()===b.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=l,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&h===0)continue;if(t<this.lastOffset&&(n<0&&(s=this.offsetMap.slippedByFixed(t),n=s+e),n<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(n)}}}getStyle(t,e){let n=this.xmldoc.getElementOffset(t),s=`e${n}`;return e&&(n=this.xmldoc.getNodeOffset(t,0,!0)),this.lastOffset<=n&&this.styleUntil(n,0),this.styleMap[s]}processContent(t,e,n){}},Qm=["column-count","column-width","column-fill"];var Rs=class{constructor(t){this.validator=t;p(this,"success",null);p(this,"failure",null);p(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(t){this.code=2*t+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(t){this.code=2*t+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},Qn=class{constructor(t,e){this.where=t;this.success=e;p(this,"what",-1)}};var Ci=class o{constructor(){p(this,"nodes",[]);p(this,"connections",[]);p(this,"match",[]);p(this,"nomatch",[]);p(this,"error",[]);p(this,"emptyHead",!0)}connect(t,e){for(let n=0;n<t.length;n++)this.connections[t[n]].what=e;t.splice(0,t.length)}clone(){let t=new o;for(let e=0;e<this.nodes.length;e++){let n=this.nodes[e],s=new Rs(n.validator);s.code=n.code,t.nodes.push(s)}for(let e=0;e<this.connections.length;e++){let n=this.connections[e],s=new Qn(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,e,n){let s=this.nodes.length,i=new Rs(Jm);n>=0?e?i.markAsStartAlternate(n):i.markAsEndAlternate(n):e?i.markAsStartGroup():i.markAsEndGroup(),this.nodes.push(i),this.connect(t,s);let r=new Qn(s,!0),a=new Qn(s,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(r)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let e=0;e<t.length;e++)this.addSpecialToArr(t[e],!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 e=new Rs(Jm);e.markAsStartAlternate(t),this.nodes.push(e);let n=new Qn(0,!0),s=new Qn(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 e=this.nodes.length;this.nodes.push(new Rs(t));let n=new Qn(e,!0),s=new Qn(e,!1);this.connect(this.match,e),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 Te}addGroup(t,e){if(t.nodes.length==0)return;let n=this.nodes.length;if(e==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let i=0;i<t.nodes.length;i++)this.nodes.push(t.nodes[i]);e==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let i=0;i<t.connections.length;i++){let r=t.connections[i];r.where+=n,r.what>=0&&(r.what+=n),this.connections.push(r)}for(let i=0;i<t.match.length;i++)this.match.push(t.match[i]+s);if(e==3&&this.connect(this.match,n),e==2||e==3)for(let i=0;i<t.nomatch.length;i++)this.match.push(t.nomatch[i]+s);else if(this.emptyHead){for(let i=0;i<t.nomatch.length;i++)this.nomatch.push(t.nomatch[i]+s);this.emptyHead=t.emptyHead}else for(let i=0;i<t.nomatch.length;i++)this.error.push(t.nomatch[i]+s);for(let i=0;i<t.error.length;i++)this.error.push(t.error[i]+s);t.nodes=null,t.connections=null}finish(t,e){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(e),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]}},Nx=1,tC=2,nC=4,mi=8,oc=16,Sh=32,ac=64,sC=128,Io=256,Vo=512,Eh=1024,iC=2048,rC=4096,oC=8192,lc=class extends Et{constructor(){super()}validateForShorthand(t,e){let n=t[e].visit(this);return n?[n]:null}},Te=class o extends lc{constructor(e,n,s){super();this.allowed=e;this.idents=n;this.units=s}visitEmpty(e){return this.allowed&Nx?e:null}visitSlash(e){return this.allowed&iC?e:null}visitStr(e){return this.allowed&tC?e:null}visitIdent(e){let n=this.idents[e.name.toLowerCase()];return n||(this.allowed&nC||this.allowed&ac&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&Vo)?e.unit=="%"&&this.allowed&Eh?e:null:e.num<0&&!(this.allowed&Io)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&Vo?e:null:e.num<=0&&!(this.allowed&Io)?null:this.allowed&oc?e:null}visitInt(e){if(e.num==0)return this.allowed&Vo?e:null;if(e.num<=0&&!(this.allowed&Io))return null;if(this.allowed&(Sh|oc))return e;let n=this.idents[`${e.num}`];return n||null}visitHexColor(e){return this.allowed&ac&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&sC?e:null}visitURange(e){return this.allowed&rC?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){if(this.allowed&ac){if(e.name==="device-cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&bu(e)!==null?e:null;if(CSS.supports("color",e.toString()))return e}if(this.allowed&oC){let n=e.visit(new Oi);if(CSS.supports("background-image",n.toString()))return e}return e.name==="calc"&&this.allowed&(mi|oc|Sh|Io|Vo|Eh)?e:null}visitExpr(e){return this.allowed&2046?e:null}combine(e){let n={},s={};for(let i in this.idents)n[i]=this.idents[i];for(let i in e.idents)n[i]=e.idents[i];for(let i in this.units)s[i]=this.units[i];for(let i in e.units)s[i]=e.units[i];return new o(this.allowed|e.allowed,n,s)}},J={},Jm=new Te(0,J,J),Fo=class extends lc{constructor(e){super();p(this,"successTerminal");p(this,"failureTerminal");p(this,"first");this.successTerminal=new Rs(null),this.failureTerminal=new Rs(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,n,s){let i=n?[]:e,r=this.first,a=s,l=null,c=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(a>=e.length){r=r.failure;continue}let u=e[a],d=u;if(r.isSpecial()){let h=!0;r.isStartGroup()?(l?l.push(c):l=[c],c=[]):r.isEndGroup()?l.length>0?c=l.pop():c=null:r.isEndAlternate()?c[r.getAlternate()]="taken":h=c[r.getAlternate()]==null,r=h?r.success:r.failure}else{if(a==0&&!n&&r.validator instanceof bi&&this instanceof bi){if(d=new G(e).visit(r.validator),d){a=e.length,r=r.success;continue}}else if(a==0&&!n&&r.validator instanceof Bo&&this instanceof bi){if(d=new me(e).visit(r.validator),d){a=e.length,r=r.success;continue}}else d=u.visit(r.validator);if(!d){r=r.failure;continue}if(d!==u&&e===i){i=[];for(let h=0;h<a;h++)i[h]=e[h]}e!==i&&(i[a-s]=d),a++,r=r.success}}return r===this.successTerminal&&(n?i.length>0:a==e.length)?i:null}validateSingle(e){let n=null,s=this.first;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(!e){s=s.failure;continue}if(s.isSpecial()){s=s.success;continue}if(n=e.visit(s.validator),!n){s=s.failure;continue}e=null,s=s.success}return s===this.successTerminal?n: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}},bi=class extends Fo{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new G(e):null}visitCommaList(t){let e=this.first,n=!1;for(;e;){if(e.validator instanceof Bo){n=!0;break}e=e.failure}if(n){let s=this.validateList(t.values,!1,0);return s===t.values?t:s?new me(s):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},Bo=class extends Fo{constructor(t){super(t)}visitSpaceList(t){return this.validateSingle(t)}visitCommaList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new me(e):null}validateForShorthand(t,e){let n=this.first,s;for(;n!==this.failureTerminal;){if(s=n.validator.validateForShorthand(t,e),s)return s;n=n.failure}return null}},vh=class extends Fo{constructor(e,n){super(n);this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new vt(e.name,n):null}},cc=class{tryParse(t,e,n){return e}success(t,e){}},uc=class extends cc{constructor(e,n){super();this.name=n;p(this,"validator");this.validator=e.validators[this.name]}tryParse(e,n,s){if(s.values[this.name])return n;let i=this.validator.validateForShorthand(e,n);if(i){let r=i.length,a=r>1?new G(i):i[0];return this.success(a,s),n+r}return n}success(e,n){n.values[this.name]=e}},Nh=class extends uc{constructor(e,n){super(e,n[0]);this.names=n}success(e,n){for(let s=0;s<this.names.length;s++)n.values[this.names[s]]=e}},Th=class extends cc{constructor(e,n){super();this.nodes=e;this.slash=n}tryParse(e,n,s){let i=n;if(this.slash)if(e[n]==Bn){if(++n==e.length)return i}else return i;let r=this.nodes[0].tryParse(e,n,s);if(r==n)return i;n=r;for(let a=1;a<this.nodes.length&&n<e.length&&(r=this.nodes[a].tryParse(e,n,s),r!=n);a++)n=r;return n}},Oo=class extends Et{constructor(){super(...arguments);p(this,"syntax",null);p(this,"propList",null);p(this,"error",!1);p(this,"values",{});p(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new uc(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,n){this.syntax=e,this.propList=n}finish(e,n){var s,i;if(!this.error){for(let r of this.propList)n.simpleProperty(r,(i=(s=this.values[r])!=null?s:this.validatorSet.defaultValues[r])!=null?i:b.initial,e);return!0}return!1}propagateDefaultingValue(e,n,s){for(let i of this.propList)s.simpleProperty(i,e,n)}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)}},Is=class extends Oo{constructor(){super()}validateList(t){let e=0,n=0;for(;e<t.length;){let s=this.syntax[n].tryParse(t,e,this);if(s>e){e=s,n=0;continue}if(++n==this.syntax.length){this.error=!0;break}}return e}},dc=class extends Oo{constructor(){super()}validateList(t){if(t.length>this.syntax.length||t.length==0)return this.error=!0,0;for(let e=0;e<this.syntax.length;e++){let n=e;for(;n>=t.length;)n=n==1?0:n-2;if(this.syntax[e].tryParse(t,n,this)!=n+1)return this.error=!0,0}return t.length}createSyntaxNode(){return new Nh(this.validatorSet,this.propList)}},wh=class extends Oo{constructor(){super()}validateList(t){let e=t.length;for(let n=0;n<t.length;n++)if(t[n]===Bn){e=n;break}if(e>this.syntax.length||t.length==0)return this.error=!0,0;for(let n=0;n<this.syntax.length;n++){let s=n;for(;s>=e;)s=s==1?0:s-2;let i;if(e+1<t.length)for(i=e+n+1;i>=t.length;)i=i-(i==e+2?1:2);else i=s;let r=[t[s],t[i]];if(this.syntax[n].tryParse(r,0,this)!=2)return this.error=!0,0}return t.length}},Ph=class extends Is{constructor(){super()}mergeIn(t,e){var n,s;for(let i of this.propList){let r=(s=(n=e[i])!=null?n:this.validatorSet.defaultValues[i])!=null?s:b.initial,a=t[i];a||(a=[],t[i]=a),a.push(r)}}visitCommaList(t){let e={};for(let n=0;n<t.values.length;n++)if(this.values={},t.values[n]instanceof me?this.error=!0:(t.values[n].visit(this),this.mergeIn(e,this.values),this.values["background-color"]&&n!=t.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let n in e)n=="background-color"?this.values[n]=e[n].pop():this.values[n]=new me(e[n]);return null}},kh=class extends Is{constructor(){super()}init(t,e){super.init(t,e),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(t){let e=super.validateList(t),n=this.values["font-variant_css2"];n&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=n);let s=this.values["font-stretch_css3"];if(s&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=s),e+2>t.length)return this.error=!0,e;this.error=!1;let i=this.validatorSet.validators;if(!t[e].visit(i["font-size"]))return this.error=!0,e;if(this.values["font-size"]=t[e++],t[e]===Bn){if(e++,e+2>t.length)return this.error=!0,e;if(!t[e].visit(i["line-height"]))return this.error=!0,e;this.values["line-height"]=t[e++]}let r=e==t.length-1?t[e]:new G(t.slice(e,t.length));return r.visit(i["font-family"])?(this.values["font-family"]=r,t.length):(this.error=!0,e)}visitCommaList(t){if(t.values[0].visit(this),this.error)return null;let e=[this.values["font-family"]];for(let s=1;s<t.values.length;s++)e.push(t.values[s]);let n=new me(e);return n.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=n:this.error=!0,null}visitIdent(t){let e=this.validatorSet.systemFonts[t.name];if(e)for(let n in e)this.values[n]=e[n];else this.error=!0;return null}},Ah=class extends Is{validateList(t){if(t.length===1&&t[0]instanceof Y)switch(t[0].name.toLowerCase()){case"normal":t=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":t=[b.auto,b.auto];break;case"none":t=[k("no-autospace"),k("space-all")];break}return super.validateList(t)}},Tx=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Lh=class extends Is{constructor(){super()}init(t,e){super.init(t,e);for(let n in this.validatorSet.validators)Tx.includes(n)||this.propList.push(n)}validateList(t){return this.error=!0,0}},eC={SIMPLE:Is,INSETS:dc,INSETS_SLASH:wh,COMMA:Ph,FONT:kh,TEXT_SPACING:Ah,ALL:Lh},wx=["initial-letter"],Rh=class{constructor(){p(this,"validators",{});p(this,"prefixes",{});p(this,"defaultValues",{});p(this,"namedValidators",{});p(this,"systemFonts",{});p(this,"shorthands",{});p(this,"layoutProps",{});p(this,"backgroundProps",{})}addReplacement(t,e){let n;if(e.type==3)n=new P(e.num,e.text);else if(e.type==7)n=new Ii(e.text);else if(e.type==1)n=k(e.text);else throw new Error("unexpected replacement");if(t.isPrimitive()){let i=t.nodes[0].validator.idents;for(let r in i)i[r]=n;return t}throw new Error("unexpected replacement")}newGroup(t,e){let n=new Ci;if(t=="||"){for(let i=0;i<e.length;i++){let r=new Ci;r.startClause(i),r.addGroup(e[i],1),r.endClause(i),n.addGroup(r,i==0?1:4)}let s=new Ci;return s.startSpecialGroup(),s.addGroup(n,3),s.endSpecialGroup(),s}else{let s;switch(t){case" ":s=1;break;case"|":case"||":s=4;break;default:throw new Error("unexpected op")}for(let i=0;i<e.length;i++)n.addGroup(e[i],i==0?1:s);return n}}addCounts(t,e,n){let s=new Ci;for(let i=0;i<e;i++)s.addGroup(t.clone(),1);if(n==Number.POSITIVE_INFINITY)s.addGroup(t,3);else for(let i=e;i<n;i++)s.addGroup(t.clone(),2);return s}primitive(t){let e=new Ci;return e.addPrimitive(t),e}newFunc(t,e){let n;switch(t){case"COMMA":n=new Bo(e);break;case"SPACE":n=new bi(e);break;default:n=new vh(t.toLowerCase(),e);break}return this.primitive(n)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Te(ac,J,J)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Te(oC,J,J)),this.namedValidators.POS_INT=this.primitive(new Te(Sh,J,J)),this.namedValidators.POS_NUM=this.primitive(new Te(oc,J,J)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Te(mi,J,{"%":H})),this.namedValidators.NEGATIVE=this.primitive(new Te(Io,J,J)),this.namedValidators.ZERO=this.primitive(new Te(Vo,J,J)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Te(Eh,J,J)),this.namedValidators.POS_LENGTH=this.primitive(new Te(mi,J,{em:H,ex:H,ch:H,rem:H,lh:H,rlh:H,vw:H,vh:H,vi:H,vb:H,vmin:H,vmax:H,pvw:H,pvh:H,pvi:H,pvb:H,pvmin:H,pvmax:H,cm:H,mm:H,in:H,px:H,pt:H,pc:H,q:H})),this.namedValidators.POS_ANGLE=this.primitive(new Te(mi,J,{deg:H,grad:H,rad:H,turn:H})),this.namedValidators.POS_TIME=this.primitive(new Te(mi,J,{s:H,ms:H})),this.namedValidators.FREQUENCY=this.primitive(new Te(mi,J,{Hz:H,kHz:H})),this.namedValidators.RESOLUTION=this.primitive(new Te(mi,J,{dpi:H,dpcm:H,dppx:H})),this.namedValidators.URI=this.primitive(new Te(sC,J,J)),this.namedValidators.URANGE=this.primitive(new Te(rC,J,J)),this.namedValidators.IDENT=this.primitive(new Te(nC,J,J)),this.namedValidators.STRING=this.primitive(new Te(tC,J,J)),this.namedValidators.SLASH=this.primitive(new Te(iC,J,J));let t={"font-family":k("sans-serif")};this.systemFonts.caption=t,this.systemFonts.icon=t,this.systemFonts.menu=t,this.systemFonts["message-box"]=t,this.systemFonts["small-caption"]=t,this.systemFonts["status-bar"]=t}isBuiltIn(t){return!!t.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(t,e){let n=t.token();if(n.type==0)return null;let s={"":!0};if(n.type==14){do{if(t.consume(),n=t.token(),n.type!=1)throw new Error("Prefix name expected");s[n.text]=!0,t.consume(),n=t.token()}while(n.type==16);if(n.type!=15)throw new Error("']' expected");t.consume(),n=t.token()}if(n.type!=1)throw new Error("Property name expected");if(e==2?n.text=="SHORTHANDS":n.text=="DEFAULTS")return t.consume(),null;let i=n.text;if(t.consume(),e!=2){if(t.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(i)||(this.prefixes[i]=s)}else if(t.token().type!=18)throw new Error("':' expected");return i}parseValidators(t){for(;;){let e=this.readNameAndPrefixes(t,1);if(!e)return;let n=[],s=[],i="",r,a=!0,l=()=>{if(n.length==0)throw new Error("No values");return n.length==1?n[0]:this.newGroup(i,n)},c=d=>{if(a)throw new Error(`'${d}': unexpected`);if(i&&i!=d)throw new Error(`mixed operators: '${d}' and '${i}'`);i=d,a=!0},u=null;for(;!u;){t.consume();let d=t.token();switch(d.type){case 1:if(a||c(" "),this.isBuiltIn(d.text)){let h=this.namedValidators[d.text];if(!h)throw new Error(`'${d.text}' unexpected`);n.push(h.clone())}else{let h={};h[d.text.toLowerCase()]=k(d.text),n.push(this.primitive(new Te(0,h,J)))}a=!1;break;case 5:{let h={};h[`${d.num}`]=new se(d.num),n.push(this.primitive(new Te(0,h,J))),a=!1;break}case 34:c("|");break;case 25:c("||");break;case 14:a||c(" "),s.push({vals:n,op:i,b:"["}),i="",n=[],a=!0;break;case 6:a||c(" "),s.push({vals:n,op:i,b:"(",fn:d.text}),i="",n=[],a=!0;break;case 15:{r=l();let h=s.pop();if(h.b!="[")throw new Error("']' unexpected");n=h.vals,n.push(r),i=h.op,a=!1;break}case 11:{r=l();let h=s.pop();if(h.b!="(")throw new Error("')' unexpected");n=h.vals,n.push(this.newFunc(h.fn,r)),i=h.op,a=!1;break}case 18:if(a)throw new Error("':' unexpected");t.consume(),n.push(this.addReplacement(n.pop(),t.token()));break;case 22:if(a)throw new Error("'?' unexpected");n.push(this.addCounts(n.pop(),0,1));break;case 36:if(a)throw new Error("'*' unexpected");n.push(this.addCounts(n.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(a)throw new Error("'+' unexpected");n.push(this.addCounts(n.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(t.consume(),d=t.token(),d.type!=5)throw new Error("<int> expected");let h=d.num,f=h;if(t.consume(),d=t.token(),d.type==16){if(t.consume(),d=t.token(),d.type!=5)throw new Error("<int> expected");f=d.num,t.consume(),d=t.token()}if(d.type!=13)throw new Error("'}' expected");n.push(this.addCounts(n.pop(),h,f));break}case 17:if(u=l(),s.length>0)throw new Error(`unclosed '${s.pop().b}'`);break;default:throw new Error("unexpected token")}}t.consume(),this.isBuiltIn(e)?this.namedValidators[e]=u:u.isSimple()?this.validators[e]=u.nodes[0].validator:this.validators[e]=new bi(u)}}parseDefaults(t){for(;;){let e=this.readNameAndPrefixes(t,2);if(!e)return;let n=[];for(;;){t.consume();let s=t.token();if(s.type==17){t.consume();break}switch(s.type){case 1:n.push(k(s.text));break;case 4:n.push(new Re(s.num));break;case 5:n.push(new se(s.num));break;case 3:n.push(new P(s.num,s.text));break;default:throw new Error("unexpected token")}}this.defaultValues[e]=n.length>1?new G(n):n[0]}}parseShorthands(t){for(;;){let e=this.readNameAndPrefixes(t,3);if(!e)return;let n=t.nthToken(1),s;n.type==1&&eC[n.text]?(s=new eC[n.text],t.consume()):s=new Is,s.setOwner(this);let i=!1,r=[],a=!1,l=[],c=[];for(;!i;)switch(t.consume(),n=t.token(),n.type){case 1:if(this.validators[n.text])r.push(s.syntaxNodeForProperty(n.text)),n.text.includes("_")||c.push(n.text);else if(this.shorthands[n.text]instanceof dc){let u=this.shorthands[n.text];r.push(u.createSyntaxNode()),c.push(...u.propList)}else throw new Error(`'${n.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(r.length>0||a)throw new Error("unexpected slash");a=!0;break;case 14:l.push({slash:a,syntax:r}),r=[],a=!1;break;case 15:{let u=new Th(r,a),d=l.pop();r=d.syntax,a=d.slash,r.push(u);break}case 17:i=!0,t.consume();break;default:throw new Error("unexpected token")}s.init(r,c),this.shorthands[e]=s}}parse(t){let e=new Xe(t,null);this.parseValidators(e),this.parseDefaults(e),this.parseShorthands(e),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(t){var n;let e={};for(let s of t){let i=this.shorthands[s],r=i?i.propList:[s];for(let a of r)e[a]=(n=this.defaultValues[a])!=null?n:b.initial}return e}validatePropertyAndHandleShorthand(t,e,n,s){let i=s.ruleType;if(Nt(t)||i==="font-face"||Px(e)){s.simpleProperty(t,e,n);return}if(i==="counter-style"){Xm(t,e)?s.simpleProperty(t,e,n):s.invalidPropertyValue(t,e);return}let r="",a=t;t=t.toLowerCase();let l=t.match(/^-([a-z]+)-([-a-z0-9]+)$/);l&&(r=l[1],t=l[2]);let c=this.prefixes[t];if(!c||!c[r]){CSS.supports(a,e.toString())?s.simpleProperty(a,e,n):r&&!tu.includes(`-${r}-`)||s.unknownProperty(a,e);return}else if(wx.includes(t)&&!Object.keys(c).some(d=>Sr(d?`-${d}-`:"",t))){s.unknownProperty(a,e);return}let u=this.validators[t];if(u){let d=X(e)||e.isExpr()?e:e.visit(u);d?s.simpleProperty(t,d,n):!r&&CSS.supports(t,e.toString())?s.simpleProperty(t,e,n):s.invalidPropertyValue(a,e)}else{let d=this.shorthands[t].clone();X(e)?d.propagateDefaultingValue(e,n,s):(e.visit(d),d.finish(n,s)||s.invalidPropertyValue(a,e))}}};function Vh(){let o=new Rh;return o.initBuiltInValidators(),o.parse(ju),o}var Ih=class extends Et{constructor(){super(...arguments);p(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function Px(o){let t=new Ih;return o.visit(t),t.varFound}var _E=`OTTO${new Date().valueOf()}`;function Fh(o){return Object.keys(o).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Ax(o){let t=new st;for(let e of Fh(o))t.append(`${e}:${o[e].toString()};`);return t.toString()}function lC(o,t){let e={};for(let n in o)e[n]=de(o,n).evaluate(t,n);return e}var Do=class{constructor(t){this.properties=t;p(this,"fontTraitKey");p(this,"src");p(this,"blobURLs",[]);p(this,"blobs",[]);p(this,"family");this.fontTraitKey=Ax(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let e=this.properties["font-family"];this.family=e?e.stringValue():null}traitsEqual(t){return this.fontTraitKey==t.fontTraitKey}makeAtRule(t,e){let n=new st;n.append(`@font-face {
1794
1795
  font-family: `),n.append(this.family),n.append(`;
1795
- `);for(let s of ph(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
1796
- `);if(e){n.append('src: url("');let s=zf(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
1796
+ `);for(let s of Fh(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
1797
+ `);if(e){n.append('src: url("');let s=pg(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
1797
1798
  }
1798
- `),n.toString()}},$l=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],i=e.family;if(s){if(s!=i)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=i}filterFontFamily(t){if(t instanceof ge){let e=t.values,n=[];for(let s of e){let i=this.familyMap[s.stringValue()];i&&n.push(k(i)),n.push(s)}return new ge(n)}else{let e=this.familyMap[t.stringValue()];return e?new ge([k(e),t]):t}}},jl=class{constructor(t,e,n){this.head=t;this.body=e;p(this,"srcURLMap",{});p(this,"familyPrefix");p(this,"familyCounter",0);this.familyPrefix=n||"Fnt_"}getViewFontFamily(t,e){let n=t.family,s=e.familyMap[n];return s||(s=this.familyPrefix+ ++this.familyCounter,e.familyMap[n]=s,s)}initFont(t,e,n){let s=A("initFont"),i=t.src,o={};for(let u of ph(t.properties))o[u]=t.properties[u];let a=this.getViewFontFamily(t,n);o["font-family"]=k(a);let l=new br(o),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(i,e),this.head.appendChild(c),F.debug("Load font:",i),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n,i=this.srcURLMap[s];return i?i.piggyback(o=>{let a=o;a.traitsEqual(t)?(e.registerFamily(t,a),F.debug("Found already-loaded font:",n)):F.warn("E_FONT_FACE_INCOMPATIBLE",t.src)}):(i=new Cn(()=>{let o=A("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?_s(a,"blob").then(c=>{if(!c.responseBlob){o.finish(null);return}l(c.responseBlob).then(u=>{this.initFont(t,u,e).thenFinish(o)})}):this.initFont(t,null,e).thenFinish(o),o.result()},`loadFont ${n}`),this.srcURLMap[s]=i,i.start()),i}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){F.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return ns(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(i=>{}))}),e===0)return T(!0);let n=A("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?T(!0):T(!1))).thenFinish(n),n.result()}};var rx=1,Zi=class{constructor(t,e,n,s,i){this.name=e;this.pseudoName=n;this.classes=s;this.parent=i;p(this,"specified",{});p(this,"children",[]);p(this,"pageMaster",null);p(this,"index",0);p(this,"key");p(this,"_scope");this._scope=t,this.key=`p${rx++}`,i&&(this.index=i.children.length,i.children.push(this))}get scope(){return this._scope}createInstance(t){throw new Error("E_UNEXPECTED_CALL")}clone(t){throw new Error("E_UNEXPECTED_CALL")}copySpecified(t){let e=this.specified,n=t.specified;for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}cloneChildren(t){for(let e=0;e<this.children.length;e++)this.children[e].clone({parent:t})}},Yl=class extends Zi{constructor(t){super(t,null,null,[],null),this.specified.width=new I(es,0),this.specified.height=new I(ts,0)}},ql=class extends Rs{constructor(e,n){super(e,i);this.pageMaster=n;let s=this;function i(o,a){let l=o.match(/^([^.]+)\.([^.]+)$/);if(l){let c=s.pageMaster.keyMap[l[1]];if(c){let d=this.lookupInstance(c);if(d)return a?d.resolveFunc(l[2]):d.resolveName(l[2])}}return null}}},Qi=class r extends Zi{constructor(e,n,s,i,o,a,l){super(e,n,s,i,o);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof ql||(this._scope=new ql(e,this)),this.pageMaster=this,this.specified.width=new I(es,0),this.specified.height=new I(ts,0),this.specified["wrap-flow"]=new I(b.auto,0),this.specified.position=new I(b.relative,0),this.specified.overflow=new I(b.visible,0)}createInstance(e){return new ri(e,this)}clone(e){let n=new r(this.scope,this.name,e.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(n),this.cloneChildren(n),n}resetScope(){this.scope.pageMaster=this}},Kl=class r extends Zi{constructor(t,e,n,s,i){super(t,e,n,s,i),this.pageMaster=i.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new I(b.auto,0)}createInstance(t){return new hh(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},Ns=class r extends Zi{constructor(t,e,n,s,i){super(t,e,n,s,i),this.pageMaster=i.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new wn(t,this)}clone(t){let e=new r(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function ax(r,t,e){return!t||X(t)?new de(r,e):t.toExpr(r,r.zero)}function re(r,t,e){return!t||t===b.auto||X(t)?null:t.toExpr(r,e)}function lx(r,t,e){return!t||t===b.normal||X(t)?null:t.toExpr(r,e)}function gt(r,t,e){return!t||t===b.auto||X(t)?r.zero:t.toExpr(r,e)}function gh(r,t,e){return!t||X(t)?r.zero:t===b.auto?null:t.toExpr(r,e)}function ln(r,t,e,n){return!t||e===b.none||X(t)?r.zero:t.toExpr(r,n)}function $m(r,t,e){return!t||X(t)?e:t===b._true?r._true:t===b._false?r._false:t.toExpr(r,r.zero)}var Ji=class{constructor(t,e){this.parentInstance=t;this.pageBox=e;p(this,"cascaded",{});p(this,"style",{});p(this,"autoWidth",null);p(this,"autoHeight",null);p(this,"children",[]);p(this,"isAutoWidth",!1);p(this,"isAutoHeight",!1);p(this,"isTopDependentOnAutoHeight",!1);p(this,"isRightDependentOnAutoWidth",!1);p(this,"calculatedWidth",0);p(this,"calculatedHeight",0);p(this,"pageMasterInstance",null);p(this,"namedValues",{});p(this,"namedFuncs",{});p(this,"vertical",!1);p(this,"rtl",!1);p(this,"suppressEmptyBoxGeneration",!1);p(this,"borderBoxSizing",!1);t&&t.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(t,e){let n=this.resolveName(t),s=this.resolveName(e);if(!n||!s)throw new Error("E_INTERNAL");return $(this.pageBox.scope,n,s)}resolveName(t){let e=this.namedValues[t];if(e)return e;let n=this.style[t];switch(n&&(e=n.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),t){case"margin-left-edge":e=this.resolveName("left");break;case"margin-top-edge":e=this.resolveName("top");break;case"margin-right-edge":e=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":e=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":e=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":e=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":e=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":e=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":e=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":e=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":e=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":e=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":e=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":e=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":e=this.addNamedValues("left-edge","width");break;case"bottom-edge":e=this.addNamedValues("top-edge","height");break}if(!e){let s;if(t=="extent")s=this.vertical?"width":"height";else if(t=="measure")s=this.vertical?"height":"width";else{let i=this.vertical?Zd:Qd;s=t;for(let o in i)s=s.replace(o,i[o])}s!=t&&(e=this.resolveName(s))}return e&&(this.namedValues[t]=e),e}resolveFunc(t){let e=this.namedFuncs[t];if(e)return e;switch(t){case"columns":{let n=this.pageBox.scope,s=new Ci(n,0),i=this.resolveName("column-count"),o=this.resolveName("column-width"),a=this.resolveName("column-gap");e=ee(n,bi(n,new Ln(n,"min",[s,i]),$(n,o,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=$m(t,e.enabled,t._true),s=re(t,e.page,t.zero);if(s){let a=new oe(t,"page-number");n=lt(t,n,new Jn(t,s,a))}let i=re(t,e["min-page-width"],t.zero);i&&(n=lt(t,n,new Is(t,new oe(t,"page-width"),i)));let o=re(t,e["min-page-height"],t.zero);o&&(n=lt(t,n,new Is(t,new oe(t,"page-height"),o))),n=this.boxSpecificEnabled(n),e.enabled=new O(n)}boxSpecificEnabled(t){return t}initHorizontal(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=re(t,e.left,n),i=re(t,e["margin-left"],n),o=ln(t,e["border-left-width"],e["border-left-style"],n),a=gt(t,e["padding-left"],n),l=re(t,e.width,n),c=re(t,e["max-width"],n),u=gt(t,e["padding-right"],n),d=ln(t,e["border-right-width"],e["border-right-style"],n),h=re(t,e["margin-right"],n),f=re(t,e.right,n),g=$(t,o,a),m=$(t,o,u);if(s&&f&&l){let C=ee(t,n,$(t,l,$(t,$(t,s,g),m)));i?h?f=ee(t,C,h):h=ee(t,C,$(t,f,i)):(C=ee(t,C,f),h?i=ee(t,C,h):(i=bi(t,C,new de(t,.5)),h=i))}else{i||(i=t.zero),h||(h=t.zero),!s&&!f&&!l&&(s=t.zero),!s&&!l?(l=this.autoWidth,this.isAutoWidth=!0):!s&&!f?s=t.zero:!l&&!f&&(l=this.autoWidth,this.isAutoWidth=!0);let C=ee(t,n,$(t,$(t,i,g),$(t,h,m)));this.isAutoWidth&&(c||(c=ee(t,C,s||f)),!this.vertical&&(re(t,e["column-width"],null)||re(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=ee(t,C,$(t,s,l))):l=ee(t,C,$(t,s,f)):s=ee(t,C,$(t,f,l))}let y=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),S=gt(t,y,n);e.left=new O(s),e["margin-left"]=new O(i),e["border-left-width"]=new O(o),e["padding-left"]=new O(a),e.width=new O(l),e["max-width"]=new O(c||l),e["padding-right"]=new O(u),e["border-right-width"]=new O(d),e["margin-right"]=new O(h),e.right=new O(f),e["snap-width"]=new O(S)}initVertical(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=this.parentInstance?this.parentInstance.style.height.toExpr(t,null):null,i=re(t,e.top,s),o=re(t,e["margin-top"],n),a=ln(t,e["border-top-width"],e["border-top-style"],n),l=gt(t,e["padding-top"],n),c=re(t,e.height,s),u=re(t,e["max-height"],s),d=gt(t,e["padding-bottom"],n),h=ln(t,e["border-bottom-width"],e["border-bottom-style"],n),f=re(t,e["margin-bottom"],n),g=re(t,e.bottom,s),m=$(t,a,l),y=$(t,h,d);if(i&&g&&c){let x=ee(t,s,$(t,c,$(t,$(t,i,m),y)));o?f?g=ee(t,x,o):f=ee(t,x,$(t,g,o)):(x=ee(t,x,g),f?o=ee(t,x,f):(o=bi(t,x,new de(t,.5)),f=o))}else{o||(o=t.zero),f||(f=t.zero),!i&&!g&&!c&&(i=t.zero),!i&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!i&&!g?i=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let x=ee(t,s,$(t,$(t,o,m),$(t,f,y)));this.isAutoHeight&&(u||(u=ee(t,x,i||g)),this.vertical&&(re(t,e["column-width"],null)||re(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),i?c?g||(g=ee(t,x,$(t,i,c))):c=ee(t,x,$(t,g,i)):i=ee(t,x,$(t,g,c))}let S=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=gt(t,S,n);e.top=new O(i),e["margin-top"]=new O(o),e["border-top-width"]=new O(a),e["padding-top"]=new O(l),e.height=new O(c),e["max-height"]=new O(u||c),e["padding-bottom"]=new O(d),e["border-bottom-width"]=new O(h),e["margin-bottom"]=new O(f),e.bottom=new O(g),e["snap-height"]=new O(C)}initColumns(){let t=this.pageBox.scope,e=this.style,n=re(t,e[this.vertical?"height":"width"],null),s=re(t,e["column-width"],n),i=re(t,e["column-count"],null),o=lx(t,e["column-gap"],null);o||(o=new en(t,1,"em")),s&&!i&&(i=new Ln(t,"floor",[mo(t,$(t,n,o),$(t,s,o))]),i=new Ln(t,"max",[t.one,i])),i||(i=t.one),s=ee(t,mo(t,$(t,n,o),i),o),e["column-width"]=new O(s),e["column-count"]=new O(i),e["column-gap"]=new O(o)}depends(t,e,n){return this.style[t].toExpr(this.pageBox.scope,null).depend(e,n)}init(t){var l;t.registerInstance(this.pageBox.key,this);let n=this.pageBox.scope,s=this.style,i=this.parentInstance?this.parentInstance.getActiveRegions(t):null,o=cl(this.cascaded,t,i,!1,null);this.vertical=al(o,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=ll(o,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((l=o["box-sizing"])==null?void 0:l.value)===b.border_box;let a=!!(t instanceof vs&&t.currentLayoutPosition&&new oe(n,"left-page").evaluate(t));ul(o,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new ne(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new ne(n,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(t,e){var s,i;let n=this.style[e];return!n&&ys(e)&&this.pageMasterInstance instanceof Pn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new P(t.rootFontSize,"px"):n=(i=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:i.value),n&&(n=Go(t,n,e)),n}getPropAsNumber(t,e){var s,i;let n=this.style[e];if(n){let o=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(i=t.pageAreaWidth)!=null?i:t.pageWidth();n=Go(t,n,e,o)}return Be(n,t)}getSpecial(t,e){let n=Jd(this.cascaded,e);if(n){let s=[];for(let i=0;i<n.length;i++){let o=n[i].evaluate(t,"");o&&o!==U&&s.push(o)}if(s.length)return s}return null}getActiveRegions(t){let e=this.getSpecial(t,"region-id");if(e){let n=[];for(let s=0;s<e.length;s++)n[s]=e[s].toString();return n}return null}propagateProperty(t,e,n,s){this.propagatePropertyToElement(t,e.element,n,s)}propagatePropertyToElement(t,e,n,s){let i=this.getProp(t,n);i&&(i.isNumeric()&&aa(i.unit)&&(i=ua(i,t)),n==="font-family"&&(i=s.filterFontFamily(i)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),w(e,n,i.toString()))}propagateDelayedProperty(t,e,n,s){let i=this.getProp(t,n);i&&s.push(new ls(e.element,n,i))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),i=this.getPropAsNumber(t,"padding-left"),o=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),w(e.element,"margin-left",`${s}px`),w(e.element,"padding-left",`${i}px`),w(e.element,"border-left-width",`${o}px`),e.marginLeft=s,e.borderLeft=o,e.paddingLeft=i}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),i=this.getPropAsNumber(t,"margin-right"),o=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(w(e.element,"margin-right",`${i}px`),w(e.element,"padding-right",`${o}px`),w(e.element,"border-right-width",`${a}px`),e.marginRight=i,e.borderRight=a,this.vertical&&s>0){let l=n+e.getInsetRight(),c=l-Math.floor(l/s)*s;c>0&&(e.snapOffsetX=s-c,o+=e.snapOffsetX)}e.paddingRight=o,e.snapWidth=s}assignTopPosition(t,e){let n=this.getPropAsNumber(t,"snap-height"),s=this.getPropAsNumber(t,"top"),i=this.getPropAsNumber(t,"margin-top"),o=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=i,e.borderTop=a,e.snapHeight=n,!this.vertical&&n>0){let l=s+e.getInsetTop(),c=l-Math.floor(l/n)*n;c>0&&(e.snapOffsetY=n-c,o+=e.snapOffsetY)}e.paddingTop=o,w(e.element,"top",`${s}px`),w(e.element,"margin-top",`${i}px`),w(e.element,"padding-top",`${o}px`),w(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),i=this.getPropAsNumber(t,"border-bottom-width"),o=this.getPropAsNumber(t,"height")-e.snapOffsetY;w(e.element,"height",`${o}px`),w(e.element,"margin-bottom",`${n}px`),w(e.element,"padding-bottom",`${s}px`),w(e.element,"border-bottom-width",`${i}px`),e.height=o-e.snapOffsetY,e.marginBottom=n,e.borderBottom=i,e.paddingBottom=s}assignBeforePosition(t,e){this.vertical?this.assignRightPosition(t,e):this.assignTopPosition(t,e)}assignAfterPosition(t,e){this.vertical?this.assignLeftPosition(t,e):this.assignBottomPosition(t,e)}assignStartEndPosition(t,e){this.vertical?(this.assignTopPosition(t,e),this.assignBottomPosition(t,e)):(this.assignRightPosition(t,e),this.assignLeftPosition(t,e))}sizeWithMaxHeight(t,e){w(e.element,"border-top-width","0px");let n=this.getPropAsNumber(t,"max-height");this.isTopDependentOnAutoHeight?e.setVerticalPosition(0,n):(this.assignTopPosition(t,e),n-=e.snapOffsetY,e.height=n,w(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){w(e.element,"border-left-width","0px");let n=this.getPropAsNumber(t,"max-width");if(this.isRightDependentOnAutoWidth)e.setHorizontalPosition(0,n);else{this.assignRightPosition(t,e),n-=e.snapOffsetX,e.width=n;let s=this.getPropAsNumber(t,"right");w(e.element,"right",`${s}px`),w(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,i){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&w(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&w(e.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(t,e):this.sizeWithMaxHeight(t,e):(this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(t,e):this.sizeWithMaxWidth(t,e):this.assignStartEndPosition(t,e);for(let o=0;o<Hm.length;o++)this.propagateProperty(t,e,Hm[o],s)}transferContentProps(t,e,n,s){for(let i=0;i<Gm.length;i++)this.propagateProperty(t,e,Gm[i],s);if(this.style["text-overflow"]){let i=e.element.firstElementChild;w(i,"text-overflow","inherit"),w(i,"overflow","inherit")}}transferSingleUriContentProps(t,e,n){let s=()=>{var a,l;let o=(l=(a=this.cascaded.width)!=null?a:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:l.value;return!!o&&o!==b.auto&&!X(o)},i=()=>{var a,l;let o=(l=(a=this.cascaded.height)!=null?a:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:l.value;return!!o&&o!==b.auto&&!X(o)};for(let o=0;o<Wm.length;o++){let a=Wm[o];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!i())continue;w(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,i,o,a){this.vertical?this.calculatedWidth=e.computedBlockSize+e.snapOffsetX:this.calculatedHeight=e.computedBlockSize+e.snapOffsetY;let l=(this.vertical||!s)&&this.isAutoHeight,c=(!this.vertical||!s)&&this.isAutoWidth,u=null;if(c||l){c&&w(e.element,"width","auto"),l&&w(e.element,"height","auto");let d=s&&ed(s);d&&Ju(s),u=o.getElementClientRect(s?s.element:e.element),d&&Io(s),c&&(this.calculatedWidth=Math.ceil(u.right-u.left-e.paddingLeft-e.borderLeft-e.paddingRight-e.borderRight),this.vertical&&(this.calculatedWidth+=e.snapOffsetX)),l&&(this.calculatedHeight=u.bottom-u.top-e.paddingTop-e.borderTop-e.paddingBottom-e.borderBottom,this.vertical||(this.calculatedHeight+=e.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(t,e),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),i>1){let d=this.getPropAsNumber(t,"column-rule-width"),h=this.getProp(t,"column-rule-style"),f=this.getProp(t,"column-rule-color");if(d>0&&h&&h!=b.none&&f!=b.transparent){let g=this.getPropAsNumber(t,"column-gap"),m=this.vertical?e.height:e.width,y=this.vertical?"border-top":"border-left";for(let S=1;S<i;S++){let C=this.vertical?(m+g)*S/i-g/2+e.paddingTop-d/2:(m+g)*S/i-g/2+e.paddingLeft-d/2,x=this.vertical?e.width+e.paddingLeft+e.paddingRight:e.height+e.paddingTop+e.paddingBottom,N=e.element.ownerDocument.createElement("div");w(N,"position","absolute"),w(N,this.vertical?"left":"top","0px"),w(N,this.vertical?"top":"left",`${C}px`),w(N,this.vertical?"height":"width","0px"),w(N,this.vertical?"width":"height",`${x}px`),w(N,y,`${d}px ${h.toString()}${f?` ${f.toString()}`:""}`),e.element.insertBefore(N,e.element.firstChild)}}}for(let d=0;d<zm.length;d++)this.propagateProperty(t,e,zm[d],a);for(let d=0;d<Xm.length;d++)this.propagateDelayedProperty(t,e,Xm[d],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let o in s)this instanceof Pn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(o==="writing-mode"||o==="direction")||Ks(o)&&Un(n,o,pe(s,o));if(this.pageBox.pseudoName==xr)for(let o in e)(o.match(/^background-/)||o=="writing-mode")&&(n[o]=e[o]);if(this.pageBox.pseudoName=="layout-host")for(let o in e)!o.match(/^background-/)&&o!="writing-mode"&&(n[o]=e[o]);t.pushRule(this.pageBox.classes,null,n);let i=n.content;i&&(n.content=i.filterValue(new Gi(t,null,t.counterResolver))),this.init(t.context);for(let o of this.pageBox.children)o.createInstance(this).applyCascadeAndInit(t,e);t.popRule()}resolveAutoSizing(t){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,t)||this.depends("margin-right",this.autoWidth,t)||this.depends("border-right-width",this.autoWidth,t)||this.depends("padding-right",this.autoWidth,t)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,t)||this.depends("margin-top",this.autoHeight,t)||this.depends("border-top-width",this.autoHeight,t)||this.depends("padding-top",this.autoHeight,t));for(let e of this.children)e.resolveAutoSizing(t)}},Hm=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],zm=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],Gm=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],Wm=["width","height","image-resolution","object-fit","object-position"],Xm=["transform","transform-origin"],xr="background-host",Zl=class extends Ji{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,i)=>i.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-i.pageBox.index)}},ri=class extends Ji{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=lt(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},hh=class extends Ji{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},wn=class extends Ji{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,n){let s=null;if(e instanceof j&&(s=[e]),e instanceof ge&&(s=e.values),s){let i=this.pageBox.scope;for(let o=0;o<s.length;o++)if(s[o]instanceof j){let a=go(s[o].name,"enabled"),l=new oe(i,a);n&&(l=new Lt(i,l)),t=lt(i,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=$m(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let i=ax(e,n["flow-from"],"body"),o=new Ln(e,"has-content",[i]);t=lt(e,t,o)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let i=this.pageMasterInstance.style.enabled,o=i?i.toExpr(e,null):e._true;o=lt(e,o,t),this.pageMasterInstance.style.enabled=new O(o)}return t}prepareContainer(t,e,n,s,i){var o;this.pageBox.pageMaster instanceof Sr||(w(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(o=this.pageBox.name)!=null?o:"")),super.prepareContainer(t,e,n,s,i)}},yr=class extends bn{constructor(e,n,s,i){super(e,n,!1);this.target=s;this.validatorSet=i}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}simpleProperty(e,n,s){this.target.specified[e]=new I(n,s?Ea:Na)}},Ql=class extends yr{constructor(t,e,n,s){super(t,e,n,s)}},fh=class r extends yr{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new I(qc,0),n.specified.height=new I(qc,0)}startPartitionRule(t,e,n){let s=new Ns(this.scope,t,e,n,this.target),i=new Ql(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}startPartitionGroupRule(t,e,n){let s=new Kl(this.scope,t,e,n,this.target),i=new r(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}},Jl=class extends yr{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new Ns(this.scope,t,e,n,this.target),i=new Ql(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}startPartitionGroupRule(t,e,n){let s=new Kl(this.scope,t,e,n,this.target),i=new fh(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}};function Fh(r){var n,s;let t=(n=r["writing-mode"])==null?void 0:n.value,e=(s=r.direction)==null?void 0:s.value;return t===b.vertical_lr||t!==b.vertical_rl&&e!==b.rtl?"ltr":"rtl"}var cx={a10:{width:new P(26,"mm"),height:new P(37,"mm")},a9:{width:new P(37,"mm"),height:new P(52,"mm")},a8:{width:new P(52,"mm"),height:new P(74,"mm")},a7:{width:new P(74,"mm"),height:new P(105,"mm")},a6:{width:new P(105,"mm"),height:new P(148,"mm")},a5:{width:new P(148,"mm"),height:new P(210,"mm")},a4:{width:new P(210,"mm"),height:new P(297,"mm")},a3:{width:new P(297,"mm"),height:new P(420,"mm")},a2:{width:new P(420,"mm"),height:new P(594,"mm")},a1:{width:new P(594,"mm"),height:new P(841,"mm")},a0:{width:new P(841,"mm"),height:new P(1189,"mm")},b10:{width:new P(31,"mm"),height:new P(44,"mm")},b9:{width:new P(44,"mm"),height:new P(62,"mm")},b8:{width:new P(62,"mm"),height:new P(88,"mm")},b7:{width:new P(88,"mm"),height:new P(125,"mm")},b6:{width:new P(125,"mm"),height:new P(176,"mm")},b5:{width:new P(176,"mm"),height:new P(250,"mm")},b4:{width:new P(250,"mm"),height:new P(353,"mm")},b3:{width:new P(353,"mm"),height:new P(500,"mm")},b2:{width:new P(500,"mm"),height:new P(707,"mm")},b1:{width:new P(707,"mm"),height:new P(1e3,"mm")},b0:{width:new P(1e3,"mm"),height:new P(1414,"mm")},c10:{width:new P(28,"mm"),height:new P(40,"mm")},c9:{width:new P(40,"mm"),height:new P(57,"mm")},c8:{width:new P(57,"mm"),height:new P(81,"mm")},c7:{width:new P(81,"mm"),height:new P(114,"mm")},c6:{width:new P(114,"mm"),height:new P(162,"mm")},c5:{width:new P(162,"mm"),height:new P(229,"mm")},c4:{width:new P(229,"mm"),height:new P(324,"mm")},c3:{width:new P(324,"mm"),height:new P(458,"mm")},c2:{width:new P(458,"mm"),height:new P(648,"mm")},c1:{width:new P(648,"mm"),height:new P(917,"mm")},c0:{width:new P(917,"mm"),height:new P(1297,"mm")},"jis-b10":{width:new P(32,"mm"),height:new P(45,"mm")},"jis-b9":{width:new P(45,"mm"),height:new P(64,"mm")},"jis-b8":{width:new P(64,"mm"),height:new P(91,"mm")},"jis-b7":{width:new P(91,"mm"),height:new P(128,"mm")},"jis-b6":{width:new P(128,"mm"),height:new P(182,"mm")},"jis-b5":{width:new P(182,"mm"),height:new P(257,"mm")},"jis-b4":{width:new P(257,"mm"),height:new P(364,"mm")},"jis-b3":{width:new P(364,"mm"),height:new P(515,"mm")},"jis-b2":{width:new P(515,"mm"),height:new P(728,"mm")},"jis-b1":{width:new P(728,"mm"),height:new P(1030,"mm")},"jis-b0":{width:new P(1030,"mm"),height:new P(1456,"mm")},letter:{width:new P(8.5,"in"),height:new P(11,"in")},legal:{width:new P(8.5,"in"),height:new P(14,"in")},ledger:{width:new P(11,"in"),height:new P(17,"in")}},ux=new P(.24,"pt"),yE=new P(3,"mm"),dx=new P(10,"mm"),px=new P(13,"mm");function Pr(r){let t={width:es,height:ts,bleed:ae,bleedOffset:ae,cropOffset:ae},e=r.size;if(!(!e||e.value===b.auto)){let c=e.value,u,d;if(c.isSpaceList()?(u=c.values[0],d=c.values[1]):(u=c,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let h=u.name&&cx[u.name.toLowerCase()];h&&(d&&d===b.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=r.marks,s=r.bleed,i=n&&!X(n.value)?n.value:b.none,o=s&&!X(s.value)?s.value:b.auto;if(o===b.auto){if(i!==b.none){let c=!1;i.isSpaceList()?c=i.values.some(u=>u===b.crop):c=i===b.crop,c&&(t.bleed=new P(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=r["crop-offset"],l=a&&!X(a.value)?a.value:b.auto;return l===b.auto?i!==b.none&&(t.bleedOffset=px):l.isNumeric()&&(t.cropOffset=l),t}function Bh(r,t){let e={},n=Math.max(0,r.bleed.num)*t.queryUnitSize(r.bleed.unit,!1),s=!r.cropOffset.num&&r.bleedOffset.num?r.bleedOffset.num*t.queryUnitSize(r.bleedOffset.unit,!1):Math.max(0,r.cropOffset.num*t.queryUnitSize(r.cropOffset.unit,!1)-n),i=n+s,o=r.width;o===es?t.pref.defaultPaperSize?e.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):e.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-i*2:e.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=r.height;return a===ts?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-i*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=i,e}function Ym(r,t,e){let n=r.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function Er(r,t,e,n){n=n||"polyline";let s=r.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===b.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var mh=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(mh||{});function hx(r,t,e,n,s,i,o){let a=s;a<=i+2*Ze.mm&&(a=i+s/2);let l=Math.max(s,a),c=i+l+e/2,u=Ym(r,c,c),d=[[0,i+s],[s,i+s],[s,i+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[i+l-m[0],m[1]]),h=h.map(m=>[i+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],i+l-m[1]]),h=h.map(m=>[m[0],i+l-m[1]]));let f=Er(r,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=Er(r,e,n);return g.setAttribute("points",h.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${o}px`}),u}var Nr=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(Nr||{});function fx(r,t,e,n,s,i){let o=s*2,a,l;t==="top"||t==="bottom"?(a=o,l=s):(a=s,l=o);let c=Ym(r,a,l),u=Er(r,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=Er(r,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=Er(r,e,n,"circle");h.setAttribute("cx",a/2),h.setAttribute("cy",l/2),h.setAttribute("r",s/4),c.appendChild(h);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Nr).forEach(g=>{let m=Nr[g];m===t?c.style[m]=`${i}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function qm(r,t,e,n){let s=!1,i=!1,o=r.marks;if(o){let m=o.value;m instanceof W?m.values.forEach(y=>{y===b.crop?s=!0:y===b.cross&&(i=!0)}):m===b.crop?s=!0:m===b.cross&&(i=!0)}let a=t.bleed;if(!s&&!i)return;let l=e.container,c=l.ownerDocument;let u=Be(ux,n),d=Math.max(0,t.bleedOffset-Be(dx,n)),h=t.bleedOffset-d,f=r["crop-marks-line-color"],g=f&&!X(f.value)?f.value:b.auto;s&&Object.keys(mh).forEach(m=>{let y=mh[m],S=hx(c,y,u,g,h,a,d);l.appendChild(S)}),i&&Object.keys(Nr).forEach(m=>{let y=Nr[m],S=fx(c,y,u,g,h,d);l.appendChild(S)})}var Ch=(()=>{let r=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return r.forEach(e=>{t[`margin-${e}`]=!0,t[`padding-${e}`]=!0,t[`border-${e}-width`]=!0,t[`border-${e}-style`]=!0,t[`border-${e}-color`]=!0}),t})();var Oh={"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"}},gx=(()=>{let r=Oh;return Object.keys(r).sort((t,e)=>r[t].order-r[e].order)})(),sc="vivliostyle-page-rule-master",vr="_marginBoxes",Sr=class extends Qi{constructor(e,n,s){super(e,null,sc,[],n,null,0);p(this,"pageMarginBoxes",{});let i=Pr(s),o=new bh(this.scope,this,s,i);this.createPageMarginBoxes(s),this.applySpecified(s,i)}createPageMarginBoxes(e){let n=e[vr];n&&gx.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new xh(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new I(b.relative,0),this.specified.width=new I(n.width,0),this.specified.height=new I(n.height,0);for(let s in e)!Ch[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new Pn(e,this)}},bh=class extends Ns{constructor(e,n,s,i){super(e,null,null,[],n);this.pageSize=i;let o=new yh(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new I(b.auto,0),this.specified["z-index"]=new I(new se(0),0),this.specified.position=new I(b.absolute,0),this.specified.overflow=new I(b.visible,0);for(let n in Ch)Ch.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new Eh(e,this)}},yh=class extends Ns{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new I(k("body"),0)}createInstance(t){return new Tr(t,this)}},xh=class extends Ns{constructor(e,n,s,i){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(i)}applySpecified(e){let n=e[vr][this.marginBoxName];for(let s in e){let i=e[s],o=n[s];(Kd[s]||o&&o.value===b.inherit)&&(this.specified[s]=i)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let i=n[s];i&&i.value!==U&&i.value!==b.inherit&&i.value!==b.unset&&i.value!==b.revert&&(this.specified[s]=i)}}createInstance(e){return new wr(e,this)}},Pn=class extends ri{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let i in n)if(Object.prototype.hasOwnProperty.call(n,i))switch(i){case"writing-mode":case"direction":s[i]=n[i]}super.applyCascadeAndInit(e,n)}initHorizontal(){let e=this.style;e.left=ae,e["margin-left"]=ae,e["border-left-width"]=ae,e["padding-left"]=ae,e["padding-right"]=ae,e["border-right-width"]=ae,e["margin-right"]=ae,e.right=ae}initVertical(){let e=this.style;e.top=ae,e["margin-top"]=ae,e["border-top-width"]=ae,e["padding-top"]=ae,e["padding-bottom"]=ae,e["border-bottom-width"]=ae,e["margin-bottom"]=ae,e.bottom=ae}setPageAreaDimension(e){this.pageAreaDimension=e;let n=this.style;n.width=new O(e.borderBoxWidth),n.height=new O(e.borderBoxHeight),n["padding-left"]=new O(e.marginLeft),n["padding-right"]=new O(e.marginRight),n["padding-top"]=new O(e.marginTop),n["padding-bottom"]=new O(e.marginBottom)}adjustPageLayout(e,n,s){let i=n.marginBoxes,o={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},a={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(i.top,!0,o,e,s),this.sizeMarginBoxesAlongVariableDimension(i.bottom,!0,o,e,s),this.sizeMarginBoxesAlongVariableDimension(i.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(i.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,i,o){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let E in e){let v=Oh[E];if(v){let L=e[E],B=this.pageMarginBoxInstances[E],H=new eo(L,B.style,n,u,o);d[v.positionAlongVariableDimension]=L,h[v.positionAlongVariableDimension]=B,f[v.positionAlongVariableDimension]=H}}let g={start:s.start.evaluate(i),end:s.end.evaluate(i),extent:s.extent.evaluate(i)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),y=!1,S={};Object.keys(d).forEach(E=>{let v=E,L=re(u,h[v].style[n?"max-width":"max-height"],s.extent);if(L){let B=L.evaluate(i);if(m[v]>B){let H=f[v]=new ec(d[v],h[v].style,n,u,o,B);S[v]=H.getOuterSize(),y=!0}}}),y&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),y=!1,[a,l,c].forEach(E=>{var v;m[E]=(v=S[E])!=null?v:m[E]}));let C={};Object.keys(d).forEach(E=>{let v=E,L=re(u,h[v].style[n?"min-width":"min-height"],s.extent);if(L){let B=L.evaluate(i);if(m[v]<B){let H=f[v]=new ec(d[v],h[v].style,n,u,o,B);C[v]=H.getOuterSize(),y=!0}}}),y&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(E=>{m[E]=C[E]||m[E]}));let x=g.start+g.extent,N=g.start+(g.start+g.extent);[a,l,c].forEach(E=>{let v=m[E];if(v!=null){let L=d[E],B=0;switch(E){case a:B=n?L.left:L.top;break;case l:B=(N-v)/2;break;case c:B=x-v;break}n?L.setHorizontalPosition(B,v-L.getInsetLeft()-L.getInsetRight()):L.setVerticalPosition(B,v-L.getInsetTop()-L.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,i=e.center,o=e.end,a={};if(i){let c=[s,o],u=new Sh(c),d=this.distributeAutoMarginBoxSizes(i,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:i.getOuterSize(),f=Math.max((n-h)/2,0);s&&(a.start=s.hasAutoSize()?f:s.getOuterSize()),o&&(a.end=o.hasAutoSize()?f:o.getOuterSize())}else{let c=this.distributeAutoMarginBoxSizes(s,o,n);c.xSize!=null&&(a.start=c.xSize),c.ySize!=null&&(a.end=c.ySize)}return a}distributeAutoMarginBoxSizes(e,n,s){let i={xSize:null,ySize:null};if(e instanceof eo&&e.minMaxFitContent&&(i.xSize=e.getOuterSize()),n instanceof eo&&n.minMaxFitContent&&(i.ySize=n.getOuterSize()),e&&n)if(e.hasAutoSize()&&n.hasAutoSize()){let o=e.getOuterMaxContentSize(),a=n.getOuterMaxContentSize();if(o>0&&a>0){let l=o+a;if(l<s)i.xSize=s*o/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?i.xSize=c+(s-d)*(o-c)/(l-d):d>0&&(i.xSize=s*c/d)}i.xSize>0&&(i.ySize=s-i.xSize)}else o>0?i.xSize=s:a>0&&(i.ySize=s)}else e.hasAutoSize()?i.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(i.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(i.xSize=s):n&&n.hasAutoSize()&&(i.ySize=s);return i}prepareContainer(e,n,s,i,o){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,i,o)}},eo=class{constructor(t,e,n,s,i){this.container=t;this.isHorizontal=n;this.clientLayout=i;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let o=e[n?"width":"height"];if(this.hasAutoSize_=!o||o===b.auto||X(o),this.minMaxFitContent=o instanceof j&&(o.name==="min-content"||o.name==="max-content"||o.name==="fit-content")?o.name:null,this.minMaxFitContent){let a=this.getSize();if(this.isHorizontal){let l=a[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,l)}else{let l=a[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,l)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let t=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Ri(this.clientLayout,this.container.element,t)}return this.size}getOuterMaxContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},Sh=class{constructor(t){this.params=t}hasAutoSize(){return this.params.some(t=>{var e;return(e=t==null?void 0:t.hasAutoSize())!=null?e:!1})}getOuterMaxContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMaxContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterMinContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMinContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterSize())!=null?n:0});return Math.max.apply(null,t)*t.length}},ec=class extends eo{constructor(e,n,s,i,o,a){super(e,n,s,i,o);p(this,"fixedSize");this.fixedSize=a}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()}},Eh=class extends wn{constructor(e,n){super(e,n);p(this,"borderBoxWidth",null);p(this,"borderBoxHeight",null);p(this,"contentBoxWidth",null);p(this,"contentBoxHeight",null);p(this,"marginTop",null);p(this,"marginRight",null);p(this,"marginBottom",null);p(this,"marginLeft",null)}applyCascadeAndInit(e,n){for(let i in n)i.match(/^background-/)&&(this.cascaded[i]=n[i]);super.applyCascadeAndInit(e,n),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let n=this.style,s=this.pageBox.pageSize,i=this.pageBox.scope,o=e.start,a=e.end,l=e.extent,c=s[l].toExpr(i,null),u=re(i,n[l],c),d=re(i,n[`margin-${o}`],c),h=re(i,n[`margin-${a}`],c),f=gt(i,n[`padding-${o}`],c),g=gt(i,n[`padding-${a}`],c),m=ln(i,n[`border-${o}-width`],n[`border-${o}-style`],c),y=ln(i,n[`border-${a}-width`],n[`border-${a}-style`],c),S=$(i,$(i,m,f),$(i,y,g)),C,x,N;return u?(this.borderBoxSizing?(x=u,N=ee(i,x,S)):(N=u,x=$(i,N,S)),C=ee(i,c,x),!d&&!h?(d=bi(i,C,new de(i,.5)),h=d):d?h=ee(i,C,d):d=ee(i,C,h)):(d||(d=i.zero),h||(h=i.zero),C=$(i,d,h),x=ee(i,c,C),N=ee(i,x,S),u=this.borderBoxSizing?x:N),n[o]=new O(d),n[a]=new O(h),n[`margin-${o}`]=ae,n[`margin-${a}`]=ae,n[`border-${o}-width`]=new O(m),n[`border-${a}-width`]=new O(y),n[`padding-${o}`]=new O(f),n[`padding-${a}`]=new O(g),n[l]=new O(u),n[`max-${l}`]=new O(u),{borderBoxExtent:x,contentBoxExtent:N,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,i,o){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,i,o)}},Tr=class extends wn{constructor(t,e){super(t,e)}applyCascadeAndInit(t,e){for(let n in e)n.match(/^column.*$/)&&(this.cascaded[n]=e[n]);super.applyCascadeAndInit(t,{})}initHorizontal(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.left=e["padding-left"],t.width=new O(this.parentInstance.contentBoxWidth),t["margin-left"]=new O(new hn(n,e.left.toExpr(n,null))),t["margin-right"]=new O(new hn(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=b.solid,t["border-right-style"]=b.solid,t["border-left-color"]=b.transparent,t["border-right-color"]=b.transparent}initVertical(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.top=e["padding-top"],t.height=new O(this.parentInstance.contentBoxHeight),t["margin-top"]=new O(new hn(n,e.top.toExpr(n,null))),t["margin-bottom"]=new O(new hn(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=b.solid,t["border-bottom-style"]=b.solid,t["border-top-color"]=b.transparent,t["border-bottom-color"]=b.transparent}prepareContainer(t,e,n,s,i){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,i),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},wr=class extends wn{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=Oh[s];let i=e;i.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,i,o){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,i,o)}applyVerticalAlign(e,n){w(n,"display","flex"),w(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),i=null;s===k("middle")?i="center":s===k("top")?i="flex-start":s===k("bottom")&&(i="flex-end"),i&&w(n,"justify-content",i);let o=this.getProp(e,"content");if(this.vertical||o instanceof fe||o instanceof O&&o.expr instanceof ne&&o.expr.str.startsWith("running-element-")){let a="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?a=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(a=this.vertical||this.rtl?"end":"start")),w(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,i=this.pageBox.scope,o=e.start,a=e.end,l=e.extent,c=o==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=re(i,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[o]=new O(h);else if(d){let f=gt(i,s[`margin-${o}`],u),g=gt(i,s[`margin-${a}`],u),m=gt(i,s[`padding-${o}`],u),y=gt(i,s[`padding-${a}`],u),S=ln(i,s[`border-${o}-width`],s[`border-${o}-style`],u),C=ln(i,s[`border-${a}-width`],s[`border-${a}-style`],u),x=$(i,d,$(i,this.borderBoxSizing?i.zero:$(i,$(i,m,y),$(i,S,C)),$(i,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[o]=new O($(i,h,mo(i,ee(i,u,x),new de(i,2))));break;case"end":s[o]=new O(ee(i,$(i,h,u),x));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,i=this.pageBox.scope,o=this.borderBoxSizing,a=e.inside,l=e.outside,c=e.extent,u=n[`margin${l.charAt(0).toUpperCase()}${l.substring(1)}`],d=gh(i,s[`margin-${a}`],u),h=gh(i,s[`margin-${l}`],u),f=gt(i,s[`padding-${a}`],u),g=gt(i,s[`padding-${l}`],u),m=ln(i,s[`border-${a}-width`],s[`border-${a}-style`],u),y=ln(i,s[`border-${l}-width`],s[`border-${l}-style`],u),S=re(i,s[c],u),C=null;function x(N){if(C)return C;C={extent:S?S.evaluate(N):null,marginInside:d?d.evaluate(N):null,marginOutside:h?h.evaluate(N):null};let E=u.evaluate(N),v=0;return o||[m,f,g,y].forEach(L=>{L&&(v+=L.evaluate(N))}),(C.marginInside===null||C.marginOutside===null)&&v+C.extent+C.marginInside+C.marginOutside>E&&(C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)),C.extent!==null&&C.marginInside!==null&&C.marginOutside!==null&&(C.marginOutside=null),C.extent===null?(C.extent=E-v-C.marginInside-C.marginOutside,C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)):typeof C.extent=="number"&&(C.marginInside===null&&typeof C.marginOutside=="number"?C.marginInside=E-v-C.extent-C.marginOutside:typeof C.marginInside=="number"&&C.marginOutside===null?C.marginOutside=E-v-C.extent-C.marginInside:C.marginInside=C.marginOutside=(E-v-C.extent)/2),C}s[c]=new O(new ne(i,function(){let N=x(this).extent;return N===null?"auto":N},c)),s[`margin-${a}`]=new O(new ne(i,function(){let N=x(this).marginInside;return N===null?"auto":N},`margin-${a}`)),s[`margin-${l}`]=new O(new ne(i,function(){let N=x(this).marginOutside;return N===null?"auto":N},`margin-${l}`)),a==="left"?s.left=new O($(i,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new O($(i,n.marginTop,n.borderBoxHeight)))}initHorizontal(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},n):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},n):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},n)}initVertical(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},n):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},n):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},n)}finishContainer(e,n,s,i,o,a,l){super.finishContainer(e,n,s,i,o,a,l);let c=s.marginBoxes,u=this.pageBox.marginBoxName,d=this.boxInfo;!d.isInLeftColumn&&!d.isInRightColumn?d.isInTopRow?c.top[u]=n:d.isInBottomRow&&(c.bottom[u]=n):!d.isInTopRow&&!d.isInBottomRow&&(d.isInLeftColumn?c.left[u]=n:d.isInRightColumn&&(c.right[u]=n));let h=this.parentInstance.pageAreaDimension,f=this.getProp(e,"width"),g=f instanceof j&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),y=this.getPropAsNumber(e,"max-width");if(g||m||y){g&&w(n.element,"width",g),m&&w(n.element,"min-width",`${m}px`),y&&w(n.element,"max-width",`${y}px`);let E=this.getProp(e,"margin-left"),v=this.getProp(e,"margin-right");if(d.isInLeftColumn){let L=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);w(n.element,"right",`${L}px`),(E===b.auto||v!==b.auto)&&w(n.element,"margin-left","auto"),v===b.auto&&w(n.element,"margin-right","auto")}else d.isInRightColumn&&(w(n.element,"right","0"),(v===b.auto||E!==b.auto)&&w(n.element,"margin-right","auto"),E===b.auto&&w(n.element,"margin-left","auto"))}let S=this.getProp(e,"height"),C=S instanceof j&&(S.name==="min-content"||S.name==="max-content"||S.name==="fit-content")?S.name:null,x=this.getPropAsNumber(e,"min-height"),N=this.getPropAsNumber(e,"max-height");if(C||x||N){C&&w(n.element,"height",C),x&&w(n.element,"min-height",`${x}px`),N&&w(n.element,"max-height",`${N}px`);let E=this.getProp(e,"margin-top"),v=this.getProp(e,"margin-bottom");if(d.isInTopRow){let L=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);w(n.element,"bottom",`${L}px`),(E===b.auto||v!==b.auto)&&w(n.element,"margin-top","auto"),v===b.auto&&w(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(w(n.element,"bottom","0"),(v===b.auto||E!==b.auto)&&w(n.element,"margin-bottom","auto"),E===b.auto&&w(n.element,"margin-top","auto"))}}},tc=class{constructor(t,e,n,s,i){this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=i;p(this,"pageMasterCache",{});p(this,"pageCascadeInstance");this.pageCascadeInstance=t,this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new oe(t,"page-number"),i=new Jn(t,new mi(t,s,new de(t,2)),n?t.one:t.zero);t.defineName("recto-page",new Lt(t,i)),t.defineName("verso-page",i),(e.pageProgression||Fh(this.docElementStyle))==="ltr"?(t.defineName("left-page",i),t.defineName("right-page",new Lt(t,i))):(t.defineName("left-page",new Lt(t,i)),t.defineName("right-page",i))}getCascadedPageStyle(t){let e={};return this.pageCascadeInstance.pushRule([],t,e),this.pageCascadeInstance.popRule(),e}getPageRulePageMaster(t,e){let n=t.pageBox;if(Object.keys(e).length===0)return n.resetScope(),t;let s=this.makeCacheKey(e,n),i=this.pageMasterCache[s];return i||(n.pseudoName===xr?i=this.generatePageRuleMaster(e):i=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=i),i.pageBox.resetScope(),i}makeCacheKey(t,e){var i;let n=this.makeCascadeValueObjectKey(t),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${e.key}^${n}^${s}`}makeCascadeValueObjectKey(t){let e=[];for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let s=t[n],i;s instanceof I?i=`${s.value}`:i=this.makeCascadeValueObjectKey(s),e.push(n+i+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new Sr(this.pageScope,this.rootPageBoxInstance.pageBox,t).createInstance(this.rootPageBoxInstance);return n.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),n.resolveAutoSizing(this.context),n}generateCascadedPageMaster(t,e){let n=e.clone({pseudoName:sc}),s=n.specified,i=t.size;if(i&&!X(i.value)){let a=Pr(t),l=i.priority;vn(s,"width",new I(a.width,l),this.context),vn(s,"height",new I(a.height,l),this.context)}["counter-reset","counter-increment"].forEach(a=>{s[a]&&(t[a]=s[a])});let o=n.createInstance(this.rootPageBoxInstance);return o.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),o.resolveAutoSizing(this.context),o}},Nh=class extends ie{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}},vh=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Th=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},wh=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ph=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},kh=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ah=class extends ie{constructor(e){super();this.scope=e}apply(e){new oe(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Lh=class extends Tn{constructor(e,n,s){super(n,s);this.scope=e;this.a=n;this.b=s}apply(e){let n=e.context,s=n.layoutPositionAtPageStart.page;n.blankPageAtStart&&s--,s&&this.matchANPlusB(s)&&this.chained.apply(e)}getPriority(){return 2}},Rh=class extends Tn{constructor(e,n,s,i){super(n,s);this.scope=e;this.a=n;this.b=s;this.pageType=i}apply(e){if(e.currentPageType!==this.pageType)return;let n=e.pageTypePageCounts[this.pageType]||0;this.matchANPlusB(n)&&this.chained.apply(e)}getPriority(){return 3}},Ih=class extends Zs{constructor(t,e){super(t,e,null,null,null)}apply(t){mx(t.context,t.currentStyle,this.style,this.specificity,t)}};function mx(r,t,e,n,s){zo(r,t,e,n,null,null,null);let i=e[vr];if(i){let o=Qs(t,vr);for(let a in i)if(i.hasOwnProperty(a)){let l=o[a];l||(l={},o[a]=l),zo(r,l,i[a],n,null,null,null)}}}var nc=class extends zn{constructor(e,n,s,i,o){super(e,n,s==null?void 0:s.condition,s,null,i,!1);this.pageProps=o;p(this,"currentPageSelectors",[]);p(this,"currentNamedPageSelector","");p(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,n){this.currentNamedPageSelector=n,n&&(this.chain.push(new Nh(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let s=n[0],i=n[1];if(n.length===3&&typeof n[2]=="string"){let o=n[2];this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${i<0?i:"+"+i} of ${o})`),this.chain.push(new Rh(this.scope,s,i,o)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${i<0?i:"+"+i})`),this.chain.push(new Lh(this.scope,s,i)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${n.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new vh(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Th(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new wh(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Ph(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new kh(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Ah(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,n,s){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(a=>a.selectors===null))return;super.simpleProperty(e,n,s);let i=pe(this.elementStyle,e),o=this.pageProps;if(e==="bleed"||e==="marks")o[""]||(o[""]={}),Object.keys(o).forEach(a=>{Un(o[a],e,i)});else if(e==="size"){let a=o[""];this.currentPageSelectors.forEach(l=>{let c=new I(i.value,i.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=o[u];d?vn(d,e,c):(d=o[u]={},Un(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&Un(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Ih(this.elementStyle,e)}startPageMarginBoxRule(e){let n=Qs(this.elementStyle,vr),s=n[e];s||(s={},n[e]=s);let i=new Vh(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(i)}},Vh=class extends bn{constructor(e,n,s,i){super(e,n,!1);this.validatorSet=s;this.boxStyle=i}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){let i=s?this.getImportantSpecificity():this.getBaseSpecificity(),o=new I(n,i);Un(this.boxStyle,e,o)}};var cn=!0;function Zm(r){cn=r}var ai=[];function Km(r,t){return r===t||(r.src||t.src?r.src===t.src:r.textContent===t.textContent)}function Qm(r){let t=Array.from(r.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(r.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function ic(r,t,e){if(!cn)return T(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&Qm(r.ownerDocument).includes(r))return T(!1);let n=r.textContent,s=r.src,i=r.type==="module",o=s&&s.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(i||s)&&r.async&&!o,l=(i&&!a||s&&r.defer)&&!o,c=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||l||a);if(Dh(t)||(t.onload=null),c)return ai.some(d=>Km(d,r))||ai.push(r),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Km(d,r)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,s&&(u.src=s),u.async=a,u.defer=l,u.setAttribute("data-vivliostyle-scripting","true");for(let d of r.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(F.debug("script:",s),s){let d=ss(u);return t.document.head.appendChild(u),ns([d])}else return t.document.head.appendChild(u),T(!0)}function bx(r,t){var i;let e={},n=o=>{var c;let a=(c=o["font-family"])==null?void 0:c.value;if(a)if(a.values)for(let u of a.values)e[u.stringValue()]=!0;else e[a.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let u of Object.values(l))n(u)},s=o=>{if(o instanceof Zs)n(o.style);else if(o instanceof Hn||Array.isArray(o))for(let a of Object.values(o))s(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o!=null?o:{}))s(a);for(let o of r.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(e[o.style.fontFamily]=!0);return Object.keys(e).join(",")}function yx(r,t,e){var s;let n=(s=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?s:t.document.createElement("div");return n.style.position="fixed",n.style.fontSize="0",n.setAttribute("data-vivliostyle-textcontent","true"),n.setAttribute("aria-hidden","true"),n.style.fontFamily=bx(r,e),n.textContent=r.documentElement.textContent,t.document.body.appendChild(n),n}function Jm(r,t,e){if(!cn)return T(!1);let n=Qm(r);if(n.length===0)return T(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),i=s?yx(r,t,e):null,o=t.document.fonts,a=t.$,l=!1,c=A("loadScripts");return c.loop(()=>{if(n.length===0)return s?c.sleep(20).thenAsync(()=>{var d,h;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&((h=t.ret)!=null&&h.readyState)&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return ic(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(ai.push(u),l=!0),n.length===0&&s&&(F.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{i&&i.remove(),c.finish(!0)}),c.result()}function eC(r){if(!cn)return T(!1);let t=A("loadScripts");return t.loop(()=>ai.length===0?T(!1):ic(ai.shift(),r,{atEnd:!0}).thenReturn(ai.length>0)).then(()=>{F.debug("dispatchEvent: DOMContentLoaded (window)"),r.dispatchEvent(new Event("DOMContentLoaded")),F.debug("dispatchEvent: load (window)"),r.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Dh(r){return cn?ai.length>0||!!r.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var tC=(r,t,e)=>r.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${e.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${e.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${e.transformURL(s,t)}`);var Sx={};function Ex(r){r.addEventListener("load",()=>{r.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,e){switch(t){case"mouse-events":return!0}return!1}}},!1)}var kr=class kr extends Kn{constructor(e,n,s,i,o,a,l,c,u,d,h,f,g){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=i;this.regionIds=o;this.xmldoc=a;this.docFaces=l;this.footnoteStyle=c;this.stylerProducer=u;this.page=d;this.customRenderer=h;this.fallbackMap=f;this.documentURLTransformer=g;p(this,"document");p(this,"exprContentListener");p(this,"nodeContext",null);p(this,"viewRoot",null);p(this,"isFootnote",!1);p(this,"sourceNode",null);p(this,"offsetInNode",0);p(this,"viewNode",null);this.document=s.document,this.exprContentListener=i.counterListener.getExprContentListener()}clone(){return new kr(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(e,n,s,i,o,a,l,c){var m;let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=$i.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h;for(let y of tm){let S;if(y){if(!u[y]||y=="footnote-marker"&&!(n&&this.isFootnote))continue;if(y.match(/^first-/)){let C=i.display;if(!C||C===b.inline)continue;let x=e.firstElementChild;if(x&&me(x.previousSibling)){let N=o.getStyle(x,!1);if(N){let E=pe(N,"display");if(E!=null&&E.value&&E.value!==b.inline)continue}}}if(y==="before"||y==="after"||y==="marker"){let C=u[y].content;if(!C||!dt(C.value)||y==="marker"&&(!Bn(i.display)||((m=pe(s,"behavior"))==null?void 0:m.value)===k("toc-node")))continue}d.push(y),S=$i.createElementNS("http://www.w3.org/1999/xhtml","span"),Xo(S,y)}else S=$i.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(S),y.match(/^first-/)&&(f=S)}if(!d.length)return c;let g=new Wo(e,s,o,a,this.exprContentListener);return new Ws(e,h,null,l,c,Bt.ROOTLESS,g)}getPseudoMap(e,n,s,i,o){let a=_t(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};Xi(u,a[c],o),nl(u,o,a[c]),sp(a[c],n,s,(d,h)=>{Xi(u,h,o),np(h,f=>{Xi(u,f,o)})})}return l}createRefShadow(e,n,s,i,o){let a=A("createRefShadow");return this.xmldoc.store.load(e).then(l=>{let c=l;if(c){let u=c.getElement(e);if(u){let d=this.stylerProducer.getStylerForDoc(c);o=new Ws(s,u,c,i,o,n,d)}}a.finish(o)}),a.result()}createShadows(e,n,s,i,o,a,l){let c=A("createShadows"),u=null,d=i.template,h;if(d instanceof fe||d===b.footnote){let f=d instanceof fe?d.url:te("user-agent.xml#footnote",Qt);h=this.createRefShadow(f,Bt.ROOTLESS,e,l,u)}else h=T(u);return h.then(f=>{let g=null;if(e.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&e.localName=="include"){let y=e.getAttribute("href"),S=null;y?S=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?y=l.owner.getAttribute("href"):y=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),S=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),y&&(y=te(y,S.url),g=this.createRefShadow(y,Bt.ROOTED,e,l,f))}g==null&&(g=T(f));let m=null;g.then(y=>{if(i.display===b.table_cell){let S=te("user-agent.xml#table-cell",Qt);m=this.createRefShadow(S,Bt.ROOTLESS,e,l,y)}else m=T(y);m.then(S=>{S=this.createPseudoelementShadow(e,n,s,i,o,a,l,S),c.finish(S)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,i){var S;let o=this.context,a=cl(s,o,this.regionIds,this.isFootnote,this.nodeContext),l=!((S=this.nodeContext)!=null&&S.parent);l&&(!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 c=e;e=al(a,o,e);let u=!l&&e!==c;n=ll(a,o,n);let d=(C,x)=>{let N;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(N=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(N=o.pageAreaWidth));let E=x.evaluate(o,C,N,e);return C=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},h=!!new oe(o.style.pageScope,"left-page").evaluate(o);if(ul(a,i,e,n,h,d),u){let C=i[e?"height":"width"];(!C||C===b.auto)&&(i[e?"height":"width"]=b.max_content)}if(Lo(i.position))return i.position=b.fixed,i.visibility=b.hidden,e;let f=i.position,g=i.float,m=i.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),y=Zu(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(C=>{y[C]&&(i[C]=y[C])}),e}inheritFromSourceParent(e){let n=this.nodeContext.sourceNode,s=[],i=null,o=this.nodeContext.shadowContext,a=-1;for(;n&&n.nodeType==1;){let h=o&&o.root==n;if(!h||o.type==Bt.ROOTLESS){let g=(o?o.styler:this.styler).getStyle(n,!1);s.push(g),i=i||ro(n)}h?(n=o.owner,o=o.parentShadow):(n=n.parentNode,a++)}let l=a===0,c=this.context.queryUnitSize("em",l),u={"font-size":new I(new P(c,"px"),0)};l&&(u["line-height"]=new I(new nt(this.context.pref.lineHeight),0));let d=new Ya(u,this.context);for(let h=s.length-1;h>=0;--h){let f=s[h],g=[];for(let S in f)ys(S)&&g.push(S);g.sort(Kc);let m,y;for(let S of g){d.setPropName(S);let C=pe(f,S),x=C;if(!X(C.value)){if(S==="font-size"&&h===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)x=new I(new P(this.context.rootFontSize,"px"),C.priority);else if(S==="line-height"&&h===s.length-1&&this.context.rootLineHeight&&C.value instanceof P&&(C.value.unit==="lh"||C.value.unit==="rlh"))x=new I(new P(this.context.rootLineHeight,"px"),C.priority);else if(h===0&&C.value instanceof P&&C.value.unit==="lh"){let N=this.getLineHeightUnitSize(S,m,y);N!=null&&(x=new I(new P(C.value.num*N,"px"),C.priority))}else It(S)||(x=C.filterValue(d));S==="font-size"?m=x.value:S==="line-height"&&(y=x.value),u[S]=x}}}for(let h in e)ys(h)||(u[h]=e[h]);return{lang:i,elementStyle:u}}resolveURL(e){return e=te(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=ro(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=Og().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let i in this.nodeContext.parent.inheritedProps)s[i]=this.nodeContext.parent.inheritedProps[i]}n.forEach(i=>{let o=e[i];if(o){if(X(o))o===b.initial&&(s[i]=void 0);else if(o instanceof se)s[i]=o.num;else if(o instanceof j)s[i]=o.name;else if(o instanceof P){let a=o;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[i]=a.num*Ze[a.unit];break;default:s[i]=o}}else s[i]=o;["widows","orphans"].includes(i)||delete e[i]}})}}resolveFormattingContext(e,n,s,i,o,a){let l=qe("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,i,o,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var S,C;let s=!0,i=A("createElementView"),o=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(o,!1);if(!this.nodeContext.shadowContext){let x=this.xmldoc.getElementOffset(o);ms.registerFragmentIndex(x,this.nodeContext.fragmentIndex,0)}let c={};if(!this.nodeContext.parent){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}let u=l.position,d=l.float,h=l["float-reference"],f=d&&!X(d.value)&&d.value!==b.none&&h&&!X(h.value)?xg(h.value.toString()):null;if(this.nodeContext.parent&&(Lo(u==null?void 0:u.value)||f&&us(f))){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),f&&us(f)&&c.display===b.block&&(c.display=b.flow_root),a.processContent(o,c,this.nodeContext),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let g=c["flow-into"];if(g&&g.toString()!=this.flowName)return i.finish(!1),i.result();if(cn&&o.localName==="script"&&o.namespaceURI==="http://www.w3.org/1999/xhtml")return ic(o,this.viewport.window).thenFinish(i),i.result();let m=c.display;if(X(m)&&(m===b.initial||m===b.unset?m=b.inline:m===b.inherit?m=((S=this.nodeContext.parent)==null?void 0:S.display)&&k((C=this.nodeContext.parent)==null?void 0:C.display):m=null),m===b.none)return i.finish(!1),i.result();let y=this.nodeContext.parent==null;return this.nodeContext.flexContainer=m===b.flex,this.createShadows(o,y,l,c,a,this.context,this.nodeContext.shadowContext).then(x=>{this.nodeContext.nodeShadow=x;let N=c.position,E=c.float,v=c.clear,L=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,B=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:L,H=Eg(o),Y=c["column-count"],Xe=c["column-width"],rt=Y&&Y!==b.auto&&!X(Y)||Xe&&Xe!==b.auto&&!X(Xe);this.nodeContext.establishesBFC=vg(m,N,E,c.overflow,L,B,rt||H),this.nodeContext.containingBlockForAbsolute=Tg(N),this.nodeContext.isInsideBFC()&&E!==b.footnote&&!(f&&us(f))&&(E=null,v=null);let $e=E instanceof W||E===b.left||E===b.right||E===b.top||E===b.bottom||E===b.inline_start||E===b.inline_end||E===b.block_start||E===b.block_end||E===b.snap_block||E===b.snap_inline||E===b.inside||E===b.outside||E===b.footnote;E&&(delete c.float,E===b.footnote&&(this.isFootnote?($e=!1,c.display=b.block):c.display=b.inline)),v&&(v===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(v=k(this.nodeContext.parent.clearSide)),(v===b.left||v===b.right||v===b.top||v===b.bottom||v===b.inline_start||v===b.inline_end||v===b.block_start||v===b.block_end||v===b.inside||v===b.outside||v===b.both||v===b.all||v===b.same||v===b.column||v===b.region||v===b.page)&&(delete c.clear,c.display&&c.display!=b.inline&&(this.nodeContext.clearSide=v.toString())));let at=Bn(m)&&!!c["ua-list-item-count"],Tt=c["break-inside"];($e||Tt&&!X(Tt)&&Tt!==b.auto)&&this.nodeContext.breakPenalty++,m&&m!==b.inline&&Ot(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!$e&&!m||Ot(m)||za(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=$e?E.toString():null,this.nodeContext.floatReference=f||Ce.INLINE;let R=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=R&&!X(R)?R:null;let M=this.isInsideNonRootMultiColumn(),V=c["column-span"];if(this.nodeContext.columnSpan=!M&&V&&!X(V)?V:null,!this.nodeContext.inline){let _=c["break-after"];_&&!X(_)&&!(M&&_===b.column)&&(this.nodeContext.breakAfter=_.toString(),wa[this.nodeContext.breakAfter]&&(c["break-after"]=b.column));let mt=c["break-before"];mt&&!X(mt)&&!(M&&mt===b.column)&&(this.nodeContext.breakBefore=mt.toString(),wa[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Gt=c.page,Ct=Gt&&!X(Gt)&&Gt.toString();!Ct&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===b.table_header_group||m===b.table_footer_group)&&(Ct=this.styler.cascade.currentPageType),!Ct||Ct.toLowerCase()==="auto"?Ct=this.nodeContext.pageType:this.nodeContext.pageType=Ct,this.styler.cascade.currentPageType!==Ct&&!(!Ct&&c.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!os(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Ct!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Ct)}this.nodeContext.verticalAlign=c["vertical-align"]&&c["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let z=c["border-collapse"];if(!z||z===k("separate")){let _=c["border-spacing"],mt,Gt;_&&(_ instanceof W?(mt=_.values[0],Gt=_.values[1]):mt=Gt=_,mt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Be(mt,this.context)),Gt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Be(Gt,this.context)))}let q=c["footnote-policy"];this.nodeContext.footnotePolicy=q&&!X(q)?q:null;let he=c["x-first-pseudo"];if(he){let _=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Ia(_,he.num)}this.nodeContext.inline||this.processAfterIfcontinues(o,l,a,this.context);let zt=c["white-space"];if(zt){let _=Oa(zt.toString());_!==null&&(this.nodeContext.whitespace=_)}let qn=c["hyphenate-character"];qn&&qn instanceof D&&(this.nodeContext.hyphenateCharacter=qn.str);let hC=c["word-break"],fC=c["line-break"],Kh=c["overflow-wrap"];(hC===b.break_all||fC===b.anywhere||Kh===b.break_word||Kh===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,m,N,E,y),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(e=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,e)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(o,a));let ws=!1,yc=null,to=[],Kt=o.namespaceURI,K=o.localName,Fr=K;if(Kt=="http://www.w3.org/1999/xhtml"?(K=="html"||K=="body"||K=="script"||K=="link"||K=="meta"?K="div":K=="vide_"?K="video":K=="audi_"?K="audio":K=="object"&&(ws=!!this.customRenderer),o.hasAttribute(dl)&&o.hasAttribute("src")&&c.content instanceof fe&&(K="img")):Kt=="http://www.idpf.org/2007/ops"?(K="span",Kt="http://www.w3.org/1999/xhtml"):Kt=="http://www.pyroxy.com/ns/shadow"?(Kt="http://www.w3.org/1999/xhtml",K=this.nodeContext.inline?"span":"div"):ws=!!this.customRenderer,at)m=Ot(m)?b.inline:b.block,c.display=m,e?K="li":K="div";else if(K=="body"||K=="li")K="div";else if(K=="q")K="span";else if(K=="a"){let _=c["hyperlink-processing"];_&&_.toString()!="normal"&&(K="span")}c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(ws=!0),o.dataset&&o.getAttribute("data-math-typeset")==="true"&&(ws=!0);let xc;if(ws){let _=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;xc=this.customRenderer(o,_,c)}else xc=T(null);xc.then(_=>{var Jh,ef,tf,nf,sf;if(_)ws&&(s=_.getAttribute("data-adapt-process-children")=="true");else if(c.display===b.none){i.finish(!1);return}else _=this.createElement(Kt,K);K!=Fr&&(_.setAttribute("data-vivliostyle-original-tag",Fr),(Fr==="html"||Fr==="body")&&(_.role="presentation")),K=="a"&&_.addEventListener("click",this.page.hrefHandler,!1),yc&&(this.applyPseudoelementStyle(this.nodeContext,"inner",yc),_.appendChild(yc)),_.localName=="iframe"&&_.namespaceURI=="http://www.w3.org/1999/xhtml"&&Ex(_);let mt=this.nodeContext.inheritedProps["image-resolution"],Gt=[],Ct=c.width,Sc=c.height,gC=o.getAttribute("width"),mC=o.getAttribute("height"),Ec=Ct===b.auto||!Ct&&!gC,Nc=Sc===b.auto||!Sc&&!mC,Zh=o.attributes,CC=Zh.length,Br=null,Qh=null;m===b.table_cell&&((tf=(ef=(Jh=this.nodeContext.parent)==null?void 0:Jh.viewNode)==null?void 0:ef.lastElementChild)==null?void 0:tf.localName)==="a"&&_.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let He=0;He<CC;He++){let wt=Zh[He],bt=wt.namespaceURI,ue=wt.localName,Se=wt.nodeValue;if(bt){if(bt=="http://www.w3.org/2000/xmlns/")continue;bt=="http://www.w3.org/1999/xlink"&&ue=="href"&&(Se=this.documentURLTransformer.transformURL(this.resolveURL(Se),this.xmldoc.url))}else{if(!cn&&ue.match(/^on/)||ue=="style")continue;if((ue=="id"||ue=="name")&&e){let Qe=this.documentURLTransformer.transformFragment(Se,this.xmldoc.url);_.setAttribute(ue,Se),_.setAttribute("data-vivliostyle-id",Qe);let Pt=_.ownerDocument.createElement("a");Pt.setAttribute(ue,Qe),Pt.setAttribute(Sn,"1"),Pt.style.position="absolute",_.appendChild(Pt),this.page.registerElementWithId(_,Qe);continue}if(ue=="src"||ue=="href"||ue=="poster")Se=this.resolveURL(Se),ue==="href"&&(Se=this.documentURLTransformer.transformURL(Se,this.xmldoc.url));else if(ue=="srcset")Se=Se.split(",").map(Qe=>this.resolveURL(Qe.trim())).join(",");else if(ue==="data"&&ws&&K==="object"&&_.hasAttribute("data"))continue;if(ue==="poster"&&K==="video"&&Kt==="http://www.w3.org/1999/xhtml"&&Ec&&Nc){let Qe=new Image,Pt=ss(Qe,Se);to.push(Pt),Gt.push({image:Qe,element:_,fetcher:Pt})}}if(Kt=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ue)&&(ue=ue.toLowerCase()),this.isSVGUrlAttribute(ue)&&(Se=tC(Se,this.xmldoc.url,this.documentURLTransformer)),bt){let Qe=Sx[bt];Qe&&(ue=`${Qe}:${ue}`)}if(ue=="src"&&!bt&&(K=="img"||K=="input")&&Kt=="http://www.w3.org/1999/xhtml")Br=Se;else if(ue=="alt"&&!bt&&K=="img"&&Kt=="http://www.w3.org/1999/xhtml")Qh=Se;else if(ue=="href"&&K=="image"&&Kt=="http://www.w3.org/2000/svg"&&bt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(ss(_,Se));else if(bt)_.setAttributeNS(bt,ue,Se);else try{_.setAttribute(ue,Se)}catch(Qe){F.warn(Qe)}}if(Br){let He=K==="input"?new Image:_,wt=ss(He,Br,Qh);He!==_&&(_.src=Br);let bt=()=>{var Se,Qe;if(c.position===b.fixed)return!0;for(let Pt=(Se=this.nodeContext.parent)==null?void 0:Se.viewNode;Pt&&Pt!==this.viewRoot;Pt=Pt.parentElement)if(((Qe=Pt.style)==null?void 0:Qe.position)==="fixed")return!0;return!1};!Ec&&!Nc&&!(()=>{let Se=this.nodeContext.vertical?Ct:Sc;return Se instanceof P&&Se.unit==="%"})()&&!bt()?this.page.fetchers.push(wt):(Ec&&Nc&&mt&&mt!==1&&Gt.push({image:He,element:_,fetcher:wt}),to.push(wt))}delete c.content;let vc=c["list-style-image"];if(vc&&vc instanceof fe){let He=vc.url;to.push(ss(new Image,He))}if(this.preprocessElementStyle(c),this.applyComputedStyles(_,c),this.nodeContext.inline)e||(Et(_,"inline-start"),zs(_)&&Et(_,"clone"));else if(e){if(!_a(c.position)){let He=c["margin-break"],wt=this.getBreakTypeAt(this.nodeContext),bt=wt!==null,ue=wt==="auto";(He===b.discard&&bt||He!==b.keep&&ue&&!this.nodeContext.floatSide)&&Ta(_,"block-start")}}else{let He=this.nodeContext.vertical?"width":"height";Jt(_,He)&&w(_,He,this.nodeContext.display==="table-row"?"0.01px":""),Et(_,"block-start"),zs(_)&&Et(_,"clone"),Ta(_,"block-start")}if(at&&_.setAttribute("value",c["ua-list-item-count"].stringValue()),_.classList.contains("_viv-marker-outside-content")&&Bn((sf=(nf=this.nodeContext.parent)==null?void 0:nf.parent)==null?void 0:sf.display)){let He=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),wt=parseFloat(He.borderInlineStartWidth)+parseFloat(He.paddingInlineStart)+parseFloat(He.textIndent);wt&&(_.style.insetInlineEnd=`${wt}px`)}this.viewNode=_,to.length?ns(to).then(()=>{mt>0&&this.modifyElemDimensionWithImageResolution(Gt,mt,c,this.nodeContext.vertical),i.finish(s)}):i.timeSlice().then(()=>{i.finish(s)})})}),i.result()}isAtStartOfPage(){var e,n;for(let s=this.nodeContext;s!=null&&s.parent&&!s.after;s=s.parent){let i=s===this.nodeContext&&!s.viewNode?(e=s.parent.viewNode)==null?void 0:e.lastChild:(n=s.viewNode)==null?void 0:n.previousSibling;for(;i&&(me(i,s.parent.whitespace)||ps(i));)i=i.previousSibling;if(i)return!1}return!0}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&Vo(e))}getBreakTypeAt(e){var s,i,o,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(Me(c.breakBefore))return c.breakBefore;if(c.fragmentIndex===1&&!c.parent)return c.sourceNode===c.sourceNode.ownerDocument.documentElement?"page":null;if((s=c.parent)!=null&&s.floatSide)return null;let u=(i=c.parent)==null?void 0:i.viewNode;if(u){let d=this.viewport.window.getComputedStyle(u),h=parseFloat(d.paddingBlockStart),f=parseFloat(d.borderBlockStartWidth);if(h||f)return null;let g=u==null?void 0:u.firstChild;for(;g&&(me(g,c.parent.whitespace)||!c.floatSide&&ps(g));)g=g.nextSibling;if(g&&g!==c.viewNode)return null}}let n=(l=(a=(o=this.context)==null?void 0:o.currentLayoutPosition)==null?void 0:a.flowPositions[this.flowName])==null?void 0:l.startBreakType;return Me(n)?n:"auto"}isInsideTable(e){for(let n=e;n&&!n.after;n=n.parent)if(n.display&&n.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(e,n,s,i){let o=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,i);if(o&&o["after-if-continues"]&&o["after-if-continues"].content){let a=new Wo(e,n,s,i,this.exprContentListener);this.nodeContext.afterIfContinues=new pl(e,a)}}isSVGUrlAttribute(e){return kr.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,i){e.forEach(o=>{if(o.fetcher.get().get()==="load"){let a=o.image,l=a.width/n,c=a.height/n,u=o.element;if(l>0&&c>0){if(s["box-sizing"]===b.border_box&&(s["border-left-style"]!==b.none&&(l+=Be(s["border-left-width"],this.context)),s["border-right-style"]!==b.none&&(l+=Be(s["border-right-width"],this.context)),s["border-top-style"]!==b.none&&(c+=Be(s["border-top-width"],this.context)),s["border-bottom-style"]!==b.none&&(c+=Be(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||b.none,h=s["max-height"]||b.none;if(d===b.none&&h===b.none)w(u,"max-width",`${l}px`);else if(d!==b.none&&h===b.none)w(u,"width",`${l}px`);else if(d===b.none&&h!==b.none)w(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?w(u,"max-width",`${Math.min(l,Be(f,this.context))}px`):g.unit!=="%"?w(u,"max-height",`${Math.min(c,Be(g,this.context))}px`):i?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||ae,h=s["min-height"]||ae;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?w(u,"min-width",`${l}px`):f.num!==0&&g.num===0?w(u,"width",`${l}px`):f.num===0&&g.num!==0?w(u,"height",`${c}px`):f.unit!=="%"?w(u,"min-width",`${Math.max(l,Be(f,this.context))}px`):g.unit!=="%"?w(u,"min-height",`${Math.max(c,Be(g,this.context))}px`):i?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){qe("PREPROCESS_ELEMENT_STYLE").forEach(s=>{s(this.nodeContext,e)})}findAndProcessRepeatingElements(e,n){for(let s=e.firstChild;s;s=s.nextSibling){if(s.nodeType!==1)continue;let i={},o=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",o,i),!this.processRepeatOnBreak(i))continue;if(this.nodeContext.formattingContext instanceof an&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new an(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==b.none&&((n===b.auto||X(n))&&(e.display===b.table_header_group?n=b.header:e.display===b.table_footer_group?n=b.footer:n=b.none),n&&n!==b.none)?n.toString():null}createTextNodeView(){let e=A("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=Gu(this.nodeContext.preprocessedTextContent).substr(n);this.viewNode=document.createTextNode(s),e.finish(!0)}),e.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let e,n=e=this.sourceNode.textContent,s=A("preprocessTextContent"),i=qe("PREPROCESS_TEXT_CONTENT"),o=0;return s.loop(()=>o>=i.length?T(!1):i[o++](this.nodeContext,n).thenAsync(a=>(n=a,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=cg(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=A("createNodeView"),i,o=!0;return this.sourceNode.nodeType==1?i=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,i=T(!0)):i=this.createTextNodeView(),i.then(a=>{var l;if(o=a,this.nodeContext.viewNode=this.viewNode,this.viewNode){let c=(h,f)=>(h==null?void 0:h.nodeType)===1&&Js(h)===f,u=this.nodeContext.parent,d=u?c(this.viewNode,"after")&&c(u.viewNode,"first-letter")&&((l=u.viewNode)!=null&&l.hasChildNodes())?u.parent.viewNode:u.viewNode:this.viewRoot;d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&me(this.viewNode))&&!d.hasChildNodes()&&Du(d).includes("block-start")&&Et(d,"text-start"),d.appendChild(this.viewNode),Ag(this.viewNode))}s.finish(o)}),s.result()}setCurrent(e,n,s){return this.nodeContext=e,e?(this.sourceNode=e.sourceNode,this.offsetInNode=e.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(n,!!s):T(!0)}processShadowContent(e){if(e.shadowContext==null||e.sourceNode.localName!="content"||e.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return e;let n=e.boxOffset,s=e.shadowContext,i=e.parent,o,a,l=s.subShadow||s.parentShadow;s.subShadow?(o=s.root,a=s.type,a==Bt.ROOTLESS&&(o=o.firstChild)):(o=s.owner.firstChild,a=Bt.ROOTLESS);let c=e.sourceNode.nextSibling;if(c?(e.sourceNode=c,e.resetView()):e.shadowSibling?e=e.shadowSibling:o?e=null:(e=e.parent.modify(),e.after=!0),o){let u=new cs(o,i,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,u}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=Bt.ROOTED){let s=e.sourceNode.nextSibling;if(s)return e=e.modify(),e.boxOffset=n,e.sourceNode=s,e.resetView(),this.processShadowContent(e)}return e.shadowSibling?(e=e.shadowSibling.modify(),e.boxOffset=n,e):(e=e.parent.modify(),e.boxOffset=n,e.after=!0,e)}else{if(e.nodeShadow){let i=e.nodeShadow.root;if(e.nodeShadow.type==Bt.ROOTLESS&&(i=i.firstChild),i){let o=new cs(i,e,n);return o.shadowContext=e.nodeShadow,o.shadowType=e.nodeShadow.type,this.processShadowContent(o)}}let s=e.sourceNode.firstChild;if(s)return this.processShadowContent(new cs(s,e,n));if(e.sourceNode.nodeType!=1){let i=Gu(e.preprocessedTextContent);n+=i.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}isTransclusion(e,n,s){let i=pe(n,"hyperlink-processing");if(!i)return!1;let o=i.evaluate(this.context,"hyperlink-processing");return o?o.toString()==s:!1}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return T(s);let i=A("nextInTree");return this.setCurrent(s,!0,n).then(o=>{(!s.viewNode||!o)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:s}),i.finish(s)}),i.result()}addImageFetchers(e){if(e instanceof ge){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof fe){let n=e.url;this.page.fetchers.push(ss(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let i=n.position===b.relative,o=((u=this.nodeContext)==null?void 0:u.parent)===null&&((d=this.sourceNode)==null?void 0:d.parentElement)===null&&!!((h=this.viewRoot)!=null&&h.parentElement),a=Object.keys(n);a.sort(Kc);let l,c;for(let f of a){if(Nx[f])continue;let g=n[f];if(!(!g||g===U&&!It(f))){if(g=g.visit(new fa(this.xmldoc.url,this.documentURLTransformer)),g instanceof P)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new P(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new P(g.num*m,"px"))}else aa(g.unit)&&(g=ua(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof P&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new gn(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),hg[f]||i&&fg[f]){this.page.delayedItems.push(new ls(e,f,g));continue}o&&this.page.pageAreaElement&&ys(f)?w(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()):w(e,f,g.toString())}}}parsePlusLayoutUnitAdj(e){if(e.endsWith("px")){let n=parseFloat(e);if(!isNaN(n))return Math.round((n+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(e,n,s){var l,c,u,d,h,f;let i=((u=(c=(l=this.nodeContext)==null?void 0:l.parent)==null?void 0:c.viewNode)==null?void 0:u.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,o=i?this.parsePlusLayoutUnitAdj(i.lineHeight):this.context.rootLineHeight;if(e==="line-height"||e==="font-size")return o;let a=null;if(s)if(s instanceof nt||s instanceof P&&(s.unit==="em"||s.unit==="%"))a=s instanceof P&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof P&&s.unit!=="lh"){let g=this.context.queryUnitSize(s.unit,!1);if(g!=null)return s.num*g}return null}if(a==null)for(let g=(h=(d=this.nodeContext)==null?void 0:d.parent)==null?void 0:h.viewNode;g&&g.nodeType===1;g=g.parentNode){let m=(f=g==null?void 0:g.style)==null?void 0:f.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(a=parseFloat(m));break}}if(a!=null){if(n&&!(n instanceof P))return null;let g=i?this.parsePlusLayoutUnitAdj(i.fontSize):this.context.rootFontSize;if(n instanceof P){let m=ol(n,g,this.context).num;return typeof m!="number"||isNaN(m)?null:a*m}else return g==null?null:a*g}return o}getEmUnitSize(e,n){var o,a,l;let s=((l=(a=(o=this.nodeContext)==null?void 0:o.parent)==null?void 0:a.viewNode)==null?void 0:l.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,i=s?this.parsePlusLayoutUnitAdj(s.fontSize):this.context.rootFontSize;if(e==="font-size"||n==null)return i;if(n instanceof P){let c=ol(n,i,this.context).num;if(typeof c=="number"&&!isNaN(c))return c}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let i=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(i,!1),l=_t(a,"_pseudos");if(!l||(a=l[n],!a))return;let c={};e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",a,c);let u=c.content;dt(u)&&(u.visit(new Vn(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=A("peelOff"),i=e.firstPseudo,o=e.offsetInNode,a=e.after;if(n>0){let h=e.viewNode.textContent;e.viewNode.textContent=h.substr(0,n),o+=n}else if(!a&&e.viewNode&&o==0){let h=e.viewNode.parentNode;h&&h.removeChild(e.viewNode)}let l=e.boxOffset+n,c=[];for(;e.firstPseudo===i;)c.push(e),e=e.parent;let u=c.pop(),d=u.shadowSibling;return s.loop(()=>{for(;c.length>0;){u=c.pop(),e=new cs(u.sourceNode,e,l),c.length==0&&(e.offsetInNode=o,e.after=a),e.shadowType=u.shadowType,e.shadowContext=u.shadowContext,e.nodeShadow=u.nodeShadow,e.shadowSibling=u.shadowSibling?u.shadowSibling:d,d=null;let h=this.setCurrent(e,!1);if(h.isPending())return h}return T(!1)}).then(()=>{s.finish(e)}),s.result()}createElement(e,n){return e=="http://www.w3.org/1999/xhtml"?this.document.createElement(n):this.document.createElementNS(e,n)}applyFootnoteStyle(e,n,s){let i={},o=_t(this.footnoteStyle,"_pseudos");if(e=this.computeStyle(e,n,this.footnoteStyle,i),o&&o.before){let a={},l=this.createElement("http://www.w3.org/1999/xhtml","span");Xo(l,"before"),s.appendChild(l),this.computeStyle(e,n,o.before,a),delete a.content,this.applyComputedStyles(l,a)}return delete i.content,this.applyComputedStyles(s,i),e}processFragmentedBlockEdge(e){var o,a,l;let n=!e.inline&&e.after?e.parent:e,s=!1;if(e.inline&&e.after&&!e.shadowContext&&((o=e.sourceNode.nextSibling)==null?void 0:o.nodeType)===1){let c=e.sourceNode.nextSibling,u=(a=pe(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!Ot(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let i=0;for(let c=n;c;c=c.parent){if(((l=c.viewNode)==null?void 0:l.nodeType)!==1)continue;let u=c.viewNode;if(u.style)if(c.inline){if(Et(u,"inline-end"),zs(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;Et(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(Jt(u,d)&&w(u,d,""),Et(u,"block-end"),!i++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?Mu(f,["block-start","text-start","block-end","text-end","justify"]):(Et(u,"text-end"),Et(u,"justify")):Et(u,"text-end")}else Et(u,"text-end")}zs(u)&&Et(u,"clone"),Ta(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),i=parseFloat(n.borderInlineEndWidth),o=-(s+i);isNaN(o)||(e.style.marginInlineEnd=`${o}px`)}createChildAnonymousBlockIfNeeded(e){let n=o=>{let{display:a,position:l,float:c}=this.viewport.window.getComputedStyle(o);if(o.localName==="ruby"||pn[o.localName])return!1;if(o.localName==="br")return!0;if((a==="inline"||a==="contents")&&o.hasChildNodes()){let u=o.lastElementChild;if(u&&(!u.nextSibling||u.nextSibling===o.lastChild&&me(u.nextSibling))){let d=n(u);if(d||d===null)return d}for(let d=u==null?void 0:u.previousElementSibling;d;d=d.previousElementSibling){let h=n(d);if(h||h===null)return null}return!1}if(a==="none"||l==="absolute"||l==="fixed"||c&&c!=="none"||o.hasAttribute(Sn)){let u=o.previousElementSibling;return u&&(u.nextSibling===o||u.nextSibling===o.previousSibling&&me(u.nextSibling))?n(u):!1}return!(!a||Ot(a))},s=null;for(let o=e.lastElementChild;o;o=o.previousElementSibling){let a=n(o);if(a){s=o;break}if(a===null)return null}if(!s)return e;if(s===e.lastElementChild&&(!s.nextSibling||s.nextSibling===e.lastChild&&me(s.nextSibling)))return null;let i=e.ownerDocument.createElement("span");i.className="viv-anonymous-block";for(let o=s.nextSibling,a=null;o;o=a)a=o.nextSibling,i.appendChild(o);return e.appendChild(i),i}convertLengthToPx(e,n,s){let i=e.num,o=e.unit;if(Sf(o)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,il(e,l,this.context).num}else{let a=this.context.queryUnitSize(o,!1);return a?i*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,i=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&Js(s)===Js(i)}else return e.node===n.node}isSameNodePosition(e,n){return e.offsetInNode===n.offsetInNode&&e.after==n.after&&e.steps.length===n.steps.length&&e.steps.every((s,i)=>{let o=n.steps[i];return this.isSameNodePositionStep(s,o)})}isPseudoelement(e){return!!Js(e)}};p(kr,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var oc=kr,Nx={"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},rc=class{constructor(t){p(this,"layoutBox");p(this,"window");p(this,"pixelRatio");p(this,"scaleRatio");p(this,"layoutUnitPerPixel");this.layoutBox=t.layoutBox,this.window=t.window,this.pixelRatio=t.pixelRatio,this.scaleRatio=t.scaleRatio,this.layoutUnitPerPixel=t.layoutUnitPerPixel}subtractOffsets(t,e){let n=e.left,s=e.top;return{left:t.left-n,top:t.top-s,right:t.right-n,bottom:t.bottom-s,width:t.width,height:t.height}}getRangeClientRects(t){let e=t.getClientRects(),n=this.layoutBox.getBoundingClientRect();return Array.from(e).map(s=>this.subtractOffsets(s,n))}getElementClientRect(t){let n=t.getBoundingClientRect();if(n.left===0&&n.top===0&&n.right===0&&n.bottom===0)return n;let s=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(n,s)}getElementComputedStyle(t){return this.window.getComputedStyle(t,null)}adjustLengthValue(t){return this.layoutUnitPerPixel?Math.floor(t*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:t}},Yn=class{constructor(t,e,n,s,i,o){this.window=t;this.fontSize=e;this.pixelRatio=n;p(this,"document");p(this,"root");p(this,"outerZoomBox");p(this,"contentContainer");p(this,"layoutBox");p(this,"width");p(this,"height");p(this,"scaleRatio",1);p(this,"layoutUnitPerPixel");p(this,"layoutUnitAdj",0);this.document=t.document,this.root=s||this.document.body;let a=this.root.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-outer-zoom-box","true"),a.role="presentation",this.root.appendChild(a));let l=a.firstElementChild;switch(l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-spread-container","true"),l.role="presentation",a.appendChild(l)),n>0&&CSS.supports("zoom","8")&&(w(this.root,"--viv-outputPixelRatio",`${n}`),w(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),Hr){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||t.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&w(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let c=a.nextElementSibling;c||(c=this.document.createElement("div"),c.setAttribute("data-vivliostyle-layout-box","true"),c.role="presentation",this.root.appendChild(c)),this.outerZoomBox=a,this.contentContainer=l,this.layoutBox=c,this.width=i||parseFloat(t.getComputedStyle(this.root).width)||this.root.offsetWidth||t.innerWidth,this.height=o||parseFloat(t.getComputedStyle(this.root).height)||this.root.offsetHeight||t.innerHeight;let u={width:794,height:1056},d=!t.outerWidth&&!t.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&t.innerWidth===800&&t.innerHeight===600;(!this.width||!i&&d)&&(this.width=u.width),(!this.height||!o&&d)&&(this.height=u.height)}resetZoom(){w(this.outerZoomBox,"width",""),w(this.outerZoomBox,"height",""),w(this.contentContainer,"width",""),w(this.contentContainer,"height",""),w(this.contentContainer,"transform","")}zoom(t,e,n){w(this.root,"--viv-outputScale",`${n}`),w(this.outerZoomBox,"width",`${t*n}px`),w(this.outerZoomBox,"height",`${e*n}px`),w(this.contentContainer,"width",`${t}px`),w(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var Ar=class{constructor(t,e,n){this.store=t;this.url=e;this.document=n;p(this,"lang",null);p(this,"totalOffset",-1);p(this,"root");p(this,"body");p(this,"head");p(this,"last");p(this,"lastOffset",1);p(this,"idMap");this.root=n.documentElement;let s=null,i=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let o=this.root.firstChild;o;o=o.nextSibling){if(o.nodeType!=1)continue;let a=o;if(a.namespaceURI=="http://www.w3.org/1999/xhtml")switch(a.localName){case"head":i=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=i,this.last=this.root,this.last.setAttribute(Zt,"0")}doc(){return new cc([this.document])}getElementOffset(t){let e=t.getAttribute(Zt);if(e)return parseInt(e,10);let n=this.lastOffset,s=this.last;for(;s!=t;){let i=s.firstChild;if(!i){for(;i=s.nextSibling,!i;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=i,i.nodeType==1?(i.setAttribute(Zt,n.toString()),++n):n+=i.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,i=t,o=null;if(i.nodeType==1){if(!n)return this.getElementOffset(i)}else{if(s=e,o=i.previousSibling,!o)return i=i.parentNode,s+=1,this.getElementOffset(i)+s;i=o}for(;;){for(;i.lastChild;)i=i.lastChild;if(i.nodeType==1)break;if(s+=i.textContent.length,o=i.previousSibling,!o){i=i.parentNode;break}i=o}return s+=1,this.getElementOffset(i)+s}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(t){let e,n=this.root;for(;;){if(e=this.getElementOffset(n),e>=t)return n;let l=n.children;if(!l)break;let c=At(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,i=n,o=i.firstChild||i.nextSibling,a=null;for(;;){if(o){if(o.nodeType==1||(i=o,a=i,s+=o.textContent.length,s>t&&!/^\s*$/.test(o.textContent)))break}else if(i=i.parentNode,!i)break;o=i.nextSibling}return o&&a&&/^\s*$/.test(a.textContent)&&(a=o),a||n}buildIdMap(t){let e=t.getAttribute("id");e&&!this.idMap[e]&&(this.idMap[e]=t);let n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");n&&!this.idMap[n]&&(this.idMap[n]=t);for(let s=t.firstElementChild;s;s=s.nextElementSibling)this.buildIdMap(s)}getElement(t){let e=t.match(/([^#]*)#(.+)$/);if(!e||e[1]&&e[1]!=this.url)return null;let n=e[2],s=this.document.getElementById(n);return!s&&this.document.getElementsByName&&(s=this.document.getElementsByName(n)[0]),s||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),s=this.idMap[n]),s}},_h=(i=>(i.TEXT_HTML="text/html",i.TEXT_XML="text/xml",i.APPLICATION_XML="application/xml",i.APPLICATION_XHTML_XML="application/xhtml+xml",i.IMAGE_SVG_XML="image/svg+xml",i))(_h||{});function lc(r,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(r,t)}catch(i){}if(s){let i=s.documentElement,o="parsererror";if(i.localName===o)return null;for(let a=i.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function vx(r){let t=r.contentType;if(t){let n=Object.keys(_h);for(let s=0;s<n.length;s++)if(_h[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=r.url.match(/\.([^./#?]+)([#?]|$)/);if(e)switch(e[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 Hh(r,t){let e=r.responseXML;if(!e){let s=new DOMParser,i=r.responseText;if(i){let o=vx(r);if(e=lc(i,o||"application/xml",s),e&&!o){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=lc(i,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=lc(i,"image/svg+xml",s))}e||(e=lc(i,"text/html",s))}}let n=e?new Ar(t,r.url,e):null;return T(n)}function nC(){return new Ms(Hh,"document")}var Uh=class r{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new r(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new r(n=>{if(!this.check(n))return!1;let s=new cc([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},zh=new Uh(r=>!0),cc=class r{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let e=[];for(let n of this.nodes)t.check(n)&&e.push(n);return new r(e)}forEachNode(t){let e=[],n=s=>{e.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new r(e)}forEach(t){let e=[];for(let n=0;n<this.nodes.length;n++)e.push(t(this.nodes[n]));return e}forEachNonNull(t){let e=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&e.push(s)}return e}child(t){return this.forEachNode((e,n)=>{for(let s=e.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,e)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&e(n)})}attribute(t){return this.forEachNonNull(e=>e.nodeType==1?e.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}};var Tx=new Cn(()=>{let r=A("uaStylesheetBase"),t=dh(),e=te("user-agent-base.css",Qt),n=new zn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Hg(n.cascade),va(Pu,n,e,null,null).thenFinish(r),r.result()},"uaStylesheetBaseFetcher");function wx(){return Tx.get()}var Gh=class extends bs{constructor(e,n,s,i,o,a){super(e,n,null,s,i,"counter-style");this.counterStyleName=o;this.counterStyles=a}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||F.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Wh=class{constructor(t,e,n,s,i,o,a,l,c,u,d){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=i;this.fontFaces=o;this.footnoteProps=a;this.flowProps=l;this.viewportProps=c;this.pageProps=u;this.counterStyleStore=d;p(this,"fontDeobfuscator");p(this,"validatorSet");this.fontDeobfuscator=t.fontDeobfuscator,this.validatorSet=t.validatorSet,this.pageScope.defineBuiltIn("has-content",function(h){h=h;let f=this,g=f.currentLayoutPosition,m=g.firstFlowChunkOfFlow(h);return f.matchPageSide(g.startSideOfFlow(h))&&g.hasContent(h,f.lookupOffset)&&!!m&&!f.flowChunkIsAfterParentFlowForcedBreak(m)}),this.pageScope.defineName("page-number",new ne(this.pageScope,function(){let h=this;return h.pageNumberOffset+h.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new ne(this.pageScope,function(){let f=this.currentLayoutPosition;return f==null?void 0:f.isBlankPage},"blank-page"))}sizeViewport(t,e,n,s){if(this.viewportProps.length){let i=new pi(this.rootScope,t,e,n),o=Ug(i,this.viewportProps),a=o.width,l=o.height,c=o["text-zoom"],u=1;if(a&&l||c){let d=Ze.em;if((c?c.evaluate(i,"text-zoom"):null)===b.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Be(a.evaluate(i,"width"),i),g=Be(l.evaluate(i,"height"),i);if(f>0&&g>0)return{width:s&&s.spreadView?(f+s.pageBorder)*2:f,height:g,fontSize:n}}}}return{width:t,height:e,fontSize:n}}},vs=class extends pi{constructor(e,n,s,i,o,a,l,c,u,d,h,f,g){super(e.rootScope,i.width,i.height,i.fontSize);this.style=e;this.xmldoc=n;this.viewport=i;this.clientLayout=o;this.fontMapper=a;this.customRenderer=l;this.fallbackMap=c;this.pageNumberOffset=u;this.documentURLTransformer=d;this.counterStore=h;p(this,"lang");p(this,"primaryFlows",{body:!0});p(this,"rootPageBoxInstance",null);p(this,"styler",null);p(this,"stylerMap",null);p(this,"currentLayoutPosition",null);p(this,"layoutPositionAtPageStart",null);p(this,"lookupOffset",0);p(this,"faces");p(this,"pageBoxInstances",{});p(this,"pageManager",null);p(this,"rootPageFloatLayoutContext");p(this,"pageBreaks",{});p(this,"pageProgression",null);p(this,"isVersoFirstPage",!1);p(this,"blankPageAtStart",!1);p(this,"pageSheetSize",{});p(this,"pageSheetHeight",0);p(this,"pageSheetWidth",0);this.lang=n.lang||s,this.faces=new $l(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Fn(null,null,null,null,null,null,null),this.pageProgression=f||null,this.isVersoFirstPage=!!g;for(let m in e.flowProps){let y=e.flowProps[m],S=pe(y,"flow-consume");S&&(S.evaluate(this,"flow-consume")==b.all?this.primaryFlows[m]=!0:delete this.primaryFlows[m])}}init(){let e=A("StyleInstance.init"),n=this.counterStore.createCounterListener(this.xmldoc.url),s=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new pr(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,n,s,this.style.counterStyleStore),s.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let i=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=Fh(i)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let o=this.style.rootBox;this.rootPageBoxInstance=new Zl(o);let a=this.style.cascade.createInstance(this,n,s,this.lang,this.style.counterStyleStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(a,i),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new tc(a,this.style.pageScope,this.rootPageBoxInstance,this,i);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=_m(u.properties,this),h=new br(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{Jm(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let c=this.style.pageProps;return c[""]||(c[""]={}),Object.keys(c).forEach(u=>{let d=c[u];this.styler.cascade.applyVarFilter([d],this.styler,null),this.styler.cascade.applyCalcFilter(d,this.styler.context);let h=Bh(Pr(d),this);this.pageSheetSize[u]={width:h.pageWidth+h.cropOffset*2,height:h.pageHeight+h.cropOffset*2}}),e.result()}matchStartPageSide(e){let n=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),s=this.pageProgression=="ltr";switch(e){case"left":return n!==s;case"right":return n===s;case"recto":return n;case"verso":return!n;default:return!0}}getStylerForDoc(e){let n=this.stylerMap[e.url];if(!n){let s=this.style.store.getStyleForDoc(e),i=new pi(s.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),o=this.counterStore.createCounterListener(e.url),a=this.counterStore.createCounterResolver(e.url,s.rootScope,s.pageScope);n=new pr(e,s.cascade,s.rootScope,i,this.primaryFlows,s.validatorSet,o,a,s.counterStyleStore),this.stylerMap[e.url]=n}return n}registerInstance(e,n){this.pageBoxInstances[e]=n}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,n){let s=this.currentLayoutPosition;if(s){s.flows[e.flowName]?n=s.flows[e.flowName]:s.flows[e.flowName]=n;let i=s.flowPositions[e.flowName];i||(i=new Fa,s.flowPositions[e.flowName]=i);let o=bg(e.element),a=new Nt(o),l=new Va(a,e);i.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let i=!0;class o{unknownProperty(d,h){i=!1}invalidPropertyValue(d,h){i=!1}simpleProperty(d,h,f){}}let a=new o,l=yn(this.style.rootScope,new Ge(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),i):!1}evalSupportsSelector(e){let n=new uc(null),s=new Ge(e+"{}",n);return new is(Ne,s,n,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!n.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let n=Number.POSITIVE_INFINITY;for(let s=0;s<e.positions.length;s++){let i=e.positions[s].chunkPosition.primary,o=i.steps[0].node,a=i.offsetInNode,l=i.after,c=0;for(;o.ownerDocument!=this.xmldoc.document;)c++,o=i.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(o,a,l);u<n&&(n=u)}return n}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let i in this.primaryFlows){let o=e.flowPositions[i];if(!n&&(!o||o.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(i),o=this.currentLayoutPosition.flowPositions[i],e!=this.currentLayoutPosition&&o&&(o=o.clone(),e.flowPositions[i]=o)),o){let a=this.getConsumedOffset(o);a<s&&(s=a)}}return s}dumpLocation(e){F.debug("Location - page",this.currentLayoutPosition.page),F.debug(" current:",e),F.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i of s.positions)F.debug(" Chunk",`${n}:`,i.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new oe(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let n in e.flowPositions){let s=e.flowPositions[n];if(s&&s.positions.length>0){let i=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===i.startOffset){let o=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=_u(_e(a,o))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let i=this.rootPageBoxInstance.children,o;for(let a=0;a<i.length;a++){if(o=i[a],o.pageBox.pseudoName===sc)continue;let l=1;o.pageBox.pseudoName===xr&&!(this.actualPageWidth&&this.actualPageHeight)&&(l=1/0);let c=o.getProp(this,"utilization");c&&c.isNum()&&(l=c.num);let u=this.queryUnitSize("em",!1),d=this.pageWidth()*this.pageHeight(),h=Math.ceil(l*d/(u*u)),f=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(s,h),this.styler.cascade.currentPageType=f,this.updateStartSide(n),this.layoutPositionAtPageStart=n.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let g=o.getProp(this,"enabled");if(!g||g===b._true){if(n.page===1&&this.blankPageAtStart){o.style={};let m=e.size;e={},m&&(e.size=m)}return this.pageManager.getPageRulePageMaster(o,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let n=this.layoutPositionAtPageStart.flows,s=n[e.flowName].parentFlowName;if(s){let i=e.startOffset,o=n[s].forcedBreakOffsets;if(!o.length||i<o[0])return!1;let a=At(o.length,d=>o[d]>i)-1,l=o[a],c=this.layoutPositionAtPageStart.flowPositions[s],u=this.getConsumedOffset(c);return l<u?!1:u<l?!0:!this.matchPageSide(c.startBreakType)}return!1}setFormattingContextToColumn(e,n){let s=this.currentLayoutPosition.flows[n];s.formattingContext||(s.formattingContext=new Mi(null)),e.flowRootFormattingContext=s.formattingContext}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),i=c=>{if(c.floatReference!==Ce.PAGE)return!1;let u=this.layoutPositionAtPageStart.flowPositions.body,d=u&&this.getConsumedOffset(u),h=this.xmldoc.getNodeOffset(c.nodePosition.steps[0].node,0,!1);return h!=null&&d!=null&&h>d},o=A("layoutDeferredPageFloats"),a=!1,l=0;return o.loopWithFrame(c=>{if(l===s.length){c.breakLoop();return}let u=s[l++],d=u.float;if(i(d)){c.breakLoop();return}let h=new rn().findByFloat(d),f=h.findPageFloatFragment(d,n);if(f&&f.hasFloat(d)){c.continueLoop();return}else if(n.isForbidden(d)||n.hasPrecedingFloatsDeferredToNext(d)){n.deferPageFloat(u),c.breakLoop();return}e.layoutPageFloatInner(u,h,null,f).then(g=>{if(!g){c.breakLoop();return}let m=n.parent.isInvalidated();if(m){c.breakLoop();return}else n.isInvalidated()&&!m&&(a=!0,n.validate());c.continueLoop()})}).then(()=>{a&&n.invalidate(),o.finish(!0)}),o.result()}getLastAfterPositionIfDeferredFloatsExists(e,n){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let o;return n?(o=n.clone(),o.primary=e.lastAfterPosition):o=new Nt(e.lastAfterPosition),o}else return null;else return null}layoutColumn(e,n){let s=this.currentLayoutPosition.flowPositions[n];if(!s||!this.matchPageSide(s.startBreakType))return T(!0);this.setFormattingContextToColumn(e,n),e.init(),this.primaryFlows[n]&&e.bands.length>0&&(e.forceNonfitting=!1);let i=A("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){i.finish(!0);return}let o=[],a=[],l=!0;i.loopWithFrame(c=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(n)){c.breakLoop();return}for(;s.positions.length-a.length>0;){let u=0;for(;a.includes(u);)u++;let d=s.positions[u];if(d.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(d.flowChunk))break;for(let g=u+1;g<s.positions.length;g++){if(a.includes(g))continue;let m=s.positions[g];if(m.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(m.flowChunk))break;m.flowChunk.isBetter(d.flowChunk)&&(d=m,u=g)}let h=d.flowChunk,f=!0;if(e.layout(d.chunkPosition,l,s.breakAfter).then(g=>{if(e.pageFloatLayoutContext.isInvalidated()){c.breakLoop();return}if(l=!1,d.flowChunk.repeated&&(g===null||h.exclusive)&&o.push(u),h.exclusive){a.push(u),c.breakLoop();return}else{let m=!!g||!!e.pageBreakType,y=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(e.pageBreakType&&y?(d.chunkPosition=y,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||y)&&(d.chunkPosition=g||y,o.push(u)),s.startBreakType=_u(e.pageBreakType)),m){c.breakLoop();return}}e.forceNonfitting=!1,f?f=!1:c.continueLoop()}),f){f=!1;return}}c.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){s.positions=s.positions.filter((u,d)=>o.includes(d)||!a.includes(d)),s.breakAfter==="column"&&(s.breakAfter=null),e.saveDistanceToBlockEndFloats();let c=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(c)}i.finish(!0)})}),i.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new hl([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,i,o,a,l,c,u,d,h,f,g,m){let y=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,S=o.element,C=new Fn(c,Ce.COLUMN,null,l,null,null,null),x=this.currentLayoutPosition.clone(),N=A("createAndLayoutColumn"),E;return N.loopWithFrame(v=>{let L=this.createLayoutConstraint(C);if(u>1){let B=this.viewport.document.createElement("div");if(w(B,"position","absolute"),S.appendChild(B),E=new ti(B,g,this.clientLayout,L,C),E.forceNonfitting=m,E.vertical=o.vertical,E.rtl=o.rtl,E.snapHeight=o.snapHeight,E.snapWidth=o.snapWidth,o.vertical){let H=(o.rtl?u-a-1:a)*(h+d)+o.paddingTop,Y=parseFloat(S.style.width);E.setHorizontalPosition(o.paddingLeft+Y-o.width,o.width),E.setVerticalPosition(H,h)}else{let H=(o.rtl?u-a-1:a)*(h+d)+o.paddingLeft;E.setVerticalPosition(o.paddingTop,o.height),E.setHorizontalPosition(H,h)}E.originX=n,E.originY=s}else E=new ti(S,g,this.clientLayout,L,C),E.copyFrom(o);E.exclusions=y?[]:i.concat(),E.innerShape=f,C.setContainer(E),(E.vertical?E.height:E.width)>=0?this.layoutColumn(E,l).then(()=>{C.isInvalidated()||C.finish(),E.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(E.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),E.element!==S&&S.removeChild(E.element),v.continueLoop()):v.breakLoop()}):(C.finish(),v.breakLoop())}).then(()=>{N.finish(E)}),N.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof Tr||n instanceof ri&&!(n instanceof Pn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,i){n instanceof wn;let o=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new Fn(e,Ce.REGION,s,i,null,o,a)}layoutFlowColumnsWithBalancing(e,n,s,i,o,a,l,c,u){let d=this.currentLayoutPosition.clone(),h=this.getRegionPageFloatLayoutContext(a,n,l,c),f=!0,g=()=>(this.currentLayoutPosition=d.clone(),this.layoutFlowColumns(e,n,s,i,o,a,h,l,c,u,f).thenAsync(m=>m?T({columns:m,position:this.currentLayoutPosition}):T(null)));return g().thenAsync(m=>{if(!m)return T(null);if(u<=1)return T(m.columns);let y=n.getProp(this,"column-fill")||b.balance,S=this.currentLayoutPosition.flowPositions[c];let C=fm(u,y,g,h,l,m.columns,S);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(x=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(m.columns)})}layoutFlowColumns(e,n,s,i,o,a,l,c,u,d,h){let f=A("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=n.getPropAsNumber(this,"column-gap"),y=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,S=n.getActiveRegions(this),C=n.getProp(this,"shape-inside"),x=ga(C,0,0,c.width,c.height,this),N=new oc(u,this,this.viewport,this.styler,S,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),E=0,v=null,L=[];return f.loopWithFrame(B=>{this.createAndLayoutColumn(n,s,i,o,c,E++,u,l,d,m,y,x,N,h).then(H=>{if(a.isInvalidated()){L=null,B.breakLoop();return}if((!!H.pageBreakType&&H.pageBreakType!=="column"||E===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){E=0,this.currentLayoutPosition=g.clone(),l.validate(),l.isLocked()?(L=null,B.breakLoop()):B.continueLoop();return}v=H,L[E-1]=v,v.pageBreakType&&v.pageBreakType!="column"&&(E=d,v.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),E<d?B.continueLoop():B.breakLoop()})}).then(()=>{f.finish(L)}),f.result()}layoutContainer(e,n,s,i,o,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==b._true)return T(!0);let u=A("layoutContainer"),h=n.getProp(this,"wrap-flow")===b.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof wr?"complementary":"presentation";let m=n.getProp(this,"position");w(g,"position",m?m.name:"absolute");let y=n instanceof Pn;n instanceof wn?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new Bi(g);C.vertical=n.vertical,C.rtl=n.rtl,C.borderBoxSizing=n.borderBoxSizing,C.exclusions=a,n.prepareContainer(this,C,e,this.faces,this.clientLayout),n instanceof Pn&&(C.width<=0||C.height<=0)&&F.warn("Negative or zero page area size"),C.originX=i,C.originY=o,i+=C.left+C.marginLeft+C.borderLeft,o+=C.top+C.marginTop+C.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,C);let x,N=!1;if(!f||!f.isIdent()){let E=n.getProp(this,"content");if(E instanceof O&&E.expr instanceof ne&&E.expr.str.startsWith("running-element-"))E.visit(new Vn(g,this,E,this.counterStore.getExprContentListener()));else if(dt(E)){let v="span";E instanceof fe&&(v="img");let L=this.viewport.document.createElement(v);E.visit(new Vn(L,this,E,this.counterStore.getExprContentListener())),g.appendChild(L),v=="img"&&n.transferSingleUriContentProps(this,L,this.faces),n.transferContentProps(this,C,e,this.faces),v=="span"&&Jg(L,n.getProp(this,"text-autospace"),n.getProp(this,"text-spacing-trim"),n.getProp(this,"hanging-punctuation"),this.lang,n.vertical)}else n.suppressEmptyBoxGeneration&&(s.removeChild(g),N=!0);N||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),x=T(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),x=T(!0);else{let E=A("layoutContainer.inner"),v=f.toString(),L=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,i,o,a,l,C,v,L).then(B=>{if(!l.isInvalidated()){let H=B[0];H.element===g&&(C=H),C.computedBlockSize=Math.max.apply(null,B.map(Xe=>Xe.computedBlockSize)),n.finishContainer(this,C,e,H,L,this.clientLayout,this.faces);let Y=this.currentLayoutPosition.flowPositions[v];Y&&Y.breakAfter==="region"&&(Y.breakAfter=null)}E.finish(!0)}),x=E.result()}return x.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!N&&!h){let v=n.getProp(this,"shape-outside"),L=C.getOuterShape(v,this);a.push(L)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let E=y?0:n.children.length-1;u.loop(()=>{for(;E>=0&&E<n.children.length;){let v=n.children[y?E++:E--],L=this.layoutContainer(e,v,g,i,o,a,l);if(L.isPending())return L.thenAsync(()=>T(!l.isInvalidated()));if(l.isInvalidated())break}return T(!1)}).then(()=>{u.finish(!0)})}),u.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i=s.positions.length-1;i>=0;i--){let o=s.positions[i];o.flowChunk.startPage>=0&&o.flowChunk.startPage+o.flowChunk.linger-1<=e&&s.positions.splice(i,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i=s.positions.length-1;i>=0;i--){let o=s.positions[i];o.flowChunk.startPage<0&&o.flowChunk.startOffset<this.lookupOffset&&(o.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let n in this.primaryFlows){let s=e.flowPositions[n];if(s&&s.positions.length>0)return!1}return!0}layoutNextPage(e,n){var y;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new Ba,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let i=1e4;if(n.page>i)throw new Error(`Too many pages generated (over ${i} pages)`);let o=n.startSideOfFlow("body");n.isBlankPage=os(o)&&this.matchPageSide(o),e.isBlankPage=n.isBlankPage,n.page++;let a=this.styler.cascade.previousPageType;e.pageType==null&&(e.pageType=(y=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?y:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType);let l=this.pageManager.pageCascadeInstance;e.pageType&&(a!==e.pageType&&(l.pageTypePageCounts[e.pageType]=0),l.pageTypePageCounts[e.pageType]=(l.pageTypePageCounts[e.pageType]||0)+1),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let c=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([c],this.styler,null),this.styler.cascade.applyCalcFilter(c,this.styler.context),!s){let S=new oe(this.style.pageScope,"left-page");e.side=S.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let u=this.selectPageMaster(c);if(!u)return T(null);let d=0;if(!s){e.setAutoPageWidth(u.pageBox.specified.width.value===es),e.setAutoPageHeight(u.pageBox.specified.height.value===ts),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(c,this);let S=Bh(Pr(c),this);this.setPageSizeAndBleed(S,e),qm(c,S,e,this),d=S.bleedOffset+S.bleed}let h=!s&&u.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=h!=b.horizontal_tb;let f=u.getProp(this,"direction")||b.ltr,g=new Fn(this.rootPageFloatLayoutContext,Ce.PAGE,null,null,null,h,f),m=A("layoutNextPage");return m.loopWithFrame(S=>{this.layoutContainer(e,u,e.bleedBox,d,d,[],g).then(()=>{g.isInvalidated()||g.finish(),g.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),g.validate(),S.continueLoop()):S.breakLoop()})}).then(()=>{u.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(C=>{let x=n.flowPositions[C],N=x.breakAfter;N&&(N==="page"||!this.matchPageSide(N))&&(x.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let S=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(S,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),m.finish(n)}),m.result()}setPageSizeAndBleed(e,n){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,n.container.style.width=`${this.pageSheetWidth}px`,n.container.style.height=`${this.pageSheetHeight}px`,n.bleedBox.style.left=`${e.bleedOffset}px`,n.bleedBox.style.right=`${e.bleedOffset}px`,n.bleedBox.style.top=`${e.bleedOffset}px`,n.bleedBox.style.bottom=`${e.bleedOffset}px`,n.bleedBox.style.padding=`${e.bleed}px`}},Xh=class r extends zn{constructor(e,n,s,i){super(e.rootScope,e,n,s,i,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let i=new Qi(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Jl(i.scope,this.masterHandler,i,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=lt(this.scope,this.condition,n)),this.masterHandler.pushHandler(new r(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new tl(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new bs(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(e){this.masterHandler.pushHandler(new Gh(this.scope,this.owner,{},this.masterHandler.validatorSet,e,this.masterHandler.counterStyles))}startFlowRule(e){let n=this.masterHandler.flowProps[e];n||(n={},this.masterHandler.flowProps[e]=n),this.masterHandler.pushHandler(new bs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new bs(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=Qs(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new bs(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new nc(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(zn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",k(e)),this.endRule();let n=new r(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},uc=class extends ya{constructor(e){super();this.validatorSet=e;p(this,"rootScope");p(this,"pageScope");p(this,"rootBox");p(this,"cascadeParserHandler");p(this,"regionCount",0);p(this,"fontFaces",[]);p(this,"counterStyles",new vl);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new Rs(null),this.pageScope=new Rs(this.rootScope),this.rootBox=new Yl(this.rootScope),this.cascadeParserHandler=new Xh(this,null,null,null),this.slave=this.cascadeParserHandler}};function Px(r,t){return t.parseOPSResource(r)}var dc=class extends Ms{constructor(e){super(Px,"document");this.fontDeobfuscator=e;p(this,"styleByKey",{});p(this,"styleFetcherByKey",{});p(this,"styleByDocURL",{});p(this,"triggersByDocURL",{});p(this,"validatorSet",null);p(this,"styleSheets",[]);p(this,"triggerSingleDocumentPreprocessing",!1)}init(e,n){this.setStyleSheets(e,n);let s=A("OPSDocStore.init");return this.validatorSet=dh(),wx().then(()=>{this.triggerSingleDocumentPreprocessing=!0,s.finish(!0)}),s.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,n){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),n&&n.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let n=e.url;n&&(n=te(Zn(n),kn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=te(Zn(n),kn)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=A("OPSDocStore.load"),s=e.url,i=s.endsWith("?viv-toc-box");return Hh(e,this).then(o=>{var f;if(!o){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=qe("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](o.document)}catch(y){F.warn("Error during single document preprocessing:",y)}}let a=[],l=o.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let g=0;g<l.length;g++){let m=l[g],y=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),S=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),x=m.getAttribute("ref");y&&S&&C&&x&&a.push({observer:y,event:S,action:C,ref:x})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:te("user-agent-page.css",Qt),text:wu,flavor:"UA",classes:null,media:null}),c.push({url:te("user-agent-counter-styles.css",Qt),text:Lu,flavor:"UA",classes:null,media:null}),i)c.push({url:te("user-agent-toc.css",Qt),text:ku,flavor:"UA",classes:null,media:null});else{let g=o.document.querySelectorAll("style, link, meta");for(let m of g){let y=m.namespaceURI,S=m.localName;if(y=="http://www.w3.org/1999/xhtml")if(S=="style"){let C=m.getAttribute("class"),x=m.getAttribute("media"),N=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:N?C:null,media:x})}else if(S=="link"){let C=m.getAttribute("href"),x=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),N=m.getAttribute("class"),E=m.getAttribute("media");if(C&&(x!=null&&x.includes("stylesheet"))&&(!x.includes("alternate")||N)){let v=te(C,s),L=m.getAttribute("title");c.push({url:v,text:null,classes:L?N:null,media:E,flavor:"Author"})}}else S=="meta"&&m.getAttribute("name")=="viewport"&&c.push({url:s,text:this.processViewportMeta(m),flavor:"Author",classes:null,media:null})}for(let m=0;m<this.styleSheets.length;m++)c.push(this.styleSheets[m])}let u="";for(let g=0;g<c.length;g++)u+=c[g].url,u+="^",c[g].text&&(u+=c[g].text),u+="^";let d=this.styleByKey[u];if(d){this.styleByDocURL[s]=d,n.finish(o);return}let h=this.styleFetcherByKey[u];h||(h=new Cn(()=>{let g=A("fetchStylesheet"),m=0,y=new uc(this.validatorSet);return g.loop(()=>{if(m<c.length){let S=c[m++];return y.startStylesheet(S.flavor),S.text!==null?va(S.text,y,S.url,S.classes,S.media).thenReturn(!0):Vu(S.url,y,S.classes,S.media)}return T(!1)}).then(()=>{let S=y.cascadeParserHandler.finish();d=new Wh(this,y.rootScope,y.pageScope,S,y.rootBox,y.fontFaces,y.footnoteProps,y.flowProps,y.viewportProps,y.pageProps,y.counterStyles),this.styleByKey[u]=d,delete this.styleFetcherByKey[u],g.finish(d)}),g.result()},`FetchStylesheet ${s}`),this.styleFetcherByKey[u]=h,h.start()),h.get().then(g=>{this.styleByDocURL[s]=g,n.finish(o)})}),n.result()}processViewportMeta(e){return""}};var Lr="\u25B8",oC="\u25BE",kx="\u25B9";function hc(r){let t=Array.from(r.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(r.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of r.querySelectorAll(e)){if(t.find(i=>i.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 rC(r){let t=hc(r),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var pc=class{constructor(t,e,n,s,i,o,a,l,c,u){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=i;this.rendererFactory=a;this.fallbackMap=l;this.documentURLTransformer=c;this.counterStore=u;p(this,"pref");p(this,"page",null);p(this,"instance",null);this.pref=ra(o),this.pref.spreadView=!1}setAutoHeight(t,e){if(e--!=0){for(let n=t.firstChild;n;n=n.nextSibling)if(n.nodeType==1){let s=n;Jt(s,"height","auto")!="auto"&&(w(s,"height","auto"),this.setAutoHeight(s,e)),Jt(s,"position","static")=="absolute"&&(w(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,i)=>{let o=i.behavior;if(o)switch(o.toString()){case"toc-node-anchor":i.color=b.inherit,i["text-decoration"]=b.none;break;case"toc-node":i.display=b.block,i.margin=ae,i.padding=ae,i["padding-inline-start"]=new P(1.25,"em");break;case"toc-node-first-child":i.display=b.inline_block,i.margin=new P(.2,"em"),i["vertical-align"]=b.top,i.color=b.inherit,i["text-decoration"]=b.none;break;case"toc-container":i.padding=ae;break}if(!o||o.toString()!="toc-node"&&o.toString()!="toc-container")return e(n,s,i);let a=n.firstChild;a&&a.nodeType!==1&&me(a)&&n.replaceChild(n.ownerDocument.createComment(a.textContent),a);let l=s.getAttribute("data-adapt-class");if(l=="toc-node"){let u=s.firstChild;u.textContent!=Lr&&(u.textContent=Lr,w(u,"cursor","pointer"),u.addEventListener("click",Ax,!1),u.setAttribute("role","button"),u.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),s.style.height!=="0px"&&(u.tabIndex=0))}let c=s.ownerDocument.createElement("div");if(c.setAttribute("data-adapt-process-children","true"),o.toString()=="toc-node"){let u=s.ownerDocument.createElement("div");if(u.textContent=kx,w(u,"margin","0.2em 0 0 -1em"),w(u,"margin-inline-start","-1em"),w(u,"margin-inline-end","0"),w(u,"display","inline-block"),w(u,"width","1em"),w(u,"text-align","center"),w(u,"vertical-align","top"),w(u,"cursor","default"),w(u,"font-family","Menlo,sans-serif"),c.appendChild(u),w(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){w(c,"height","0px");let d=n.firstElementChild;d&&d.localName==="a"&&(d.tabIndex=-1)}else s.setAttribute("role","tree")}else l=="toc-node"&&(c.setAttribute("data-adapt-class","toc-container"),c.setAttribute("role","group"),c.setAttribute("aria-hidden","true"));return T(c)}}showTOC(t,e,n,s,i){if(this.page)return T(this.page);let o=A("showTOC"),a=new Fi(t,t);this.page=a;let l=Wt(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of hc(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,i);e=new Yn(e.window,d.fontSize,0,e.root,d.width,d.height);let h=this.makeCustomRenderer(c),f=new vs(u,c,this.lang,e,this.clientLayout,this.fontMapper,h,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=f,f.pref=this.pref,f.init().then(()=>{f.layoutNextPage(a,null).then(()=>{this.setAutoHeight(t,2),o.finish(a)})})}),o.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function t(s){if(!s)return[];let i=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(i).map(e)}function e(s){let i=new URL(s.href),[,o]=i.hash.match(/^#?(.*)$/),a=s.innerText,l=s.parentElement.querySelector("[role=group]"),c=t(l);return{id:o,title:a,children:c}}let n=this.page.container.querySelector("[role=tree]");return t(n)}};function Ax(r){let t=r.target,e=t.textContent==Lr;t.textContent=e?oC:Lr;let n=t.parentNode;t.setAttribute("aria-expanded",e?"true":"false"),n.setAttribute("aria-expanded",e?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let i=s,o=i.getAttribute("data-adapt-class");if(o==="toc-container"){if(i.setAttribute("aria-hidden",e?"false":"true"),i.firstChild){s=i.firstChild;continue}}else if(o==="toc-node"&&(i.style.height=e?"auto":"0px",i.children.length>=2&&(i.children[1].tabIndex=e?0:-1),i.children.length>=3&&(i.children[0].tabIndex=e?0:-1,!e))){let a=i.children[0];if(a.textContent==oC){a.textContent=Lr,a.setAttribute("aria-expanded","false"),i.setAttribute("aria-expanded","false"),s=i.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}r.stopPropagation()}var Ir=class extends dc{constructor(){super(null);p(this,"plainXMLStore");p(this,"jsonStore");p(this,"opfByURL",{});p(this,"primaryOPFByEPubURL",{});p(this,"deobfuscators",{});p(this,"documents",{});this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=nC(),this.jsonStore=Gf()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,n,s){return this.plainXMLStore.load(e,n,s)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,n,s){return this.jsonStore.load(e,n,s)}loadPubDoc(e){let n=A("loadPubDoc");return _s(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(i=>{if(i){n.finish(i);return}F.error(`Failed to fetch a source document from ${e} (${s.status}${s.statusText?" "+s.statusText:""})`),n.finish(null)});else if(!s.status&&!s.responseXML&&!s.responseText&&!s.responseBlob&&!s.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),s.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,i,o]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,o).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),n.finish(null);return}let o=new li(this,e);o.initWithWebPubManifest(i,void 0,e).then(()=>{n.finish(o)})}):this.loadWebPub(e).then(i=>{if(i){n.finish(i);return}this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}F.error(`Failed to load ${e}.`),n.finish(null)})})}),n.result()}loadEPUBDoc(e){let n=A("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(i=>{if(i){let o=i.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let a of o)if(a){this.loadOPF(e,a).thenFinish(n);return}}n.finish(null)}),n.result()}loadOPF(e,n){let s=e+n,i=this.opfByURL[s];if(i)return T(i);let o=A("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(i=new li(this,e),this.opfByURL[s]=i,this.primaryOPFByEPubURL[e]=i,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{i.initWithXMLDoc(a,l).then(()=>{o.finish(i)})}):i.initWithXMLDoc(a,null).then(()=>{o.finish(i)})):this.reportLoadError(s)}),o.result()}loadWebPub(e){let n=A("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let i=s.document,o=new li(this,e),a=i.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=di(i.getElementById(l.substr(1)).textContent);o.initWithWebPubManifest(c,i).then(()=>{n.finish(o)})}else{let c=te(a.getAttribute("href"),e);this.loadAsJSON(c,!0,`Failed to fetch Publication Manifest ${c}`).then(u=>{o.initWithWebPubManifest(u,i,c).then(()=>{n.finish(o)})})}}else o.initWithWebPubManifest({},i).then(()=>{o.toc&&o.toc.src===s.url&&hc(i).length===0&&(o.toc=null),n.finish(o)})}}),n.result()}addDocument(e,n){let s=A("EPUBDocStore.load"),i=Wt(e);return(this.documents[i]=this.parseOPSResource({status:200,statusText:"",url:i,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=i=>i.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let i=n(e);return!(i===n(kn)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===i)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?F.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&kn.startsWith("https:")?F.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?F.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):F.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=Wt(e),s=this.documents[n];if(s)return s.isPending()?s:T(s.get());{let i=A("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(o=>{o?i.finish(o):this.reportLoadError(n)}),i.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},i;for(;(i=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(i[0].length),s[i[1]]=i[2];let o=s.width-0,a=s.height-0;if(o&&a){let l=!!Object.values(this.primaryOPFByEPubURL).find(c=>c.prePaginated);return`@-epubx-viewport{width:${o}px;height:${a}px;}`+(l?`@page{size:${o}px ${a}px;margin:0;}`:"@page{margin:0;}")}return""}},gc=class{constructor(){p(this,"id",null);p(this,"src","");p(this,"mediaType",null);p(this,"title",null);p(this,"itemRefElement",null);p(this,"spineIndex",-1);p(this,"compressedSize",0);p(this,"compressed",null);p(this,"epage",0);p(this,"epageCount",0);p(this,"startPage",null);p(this,"skipPagesBefore",null);p(this,"itemProperties");this.itemProperties=uf}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=te(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=hf(n.split(/\s+/)))}initWithParam(t){this.spineIndex=t.index,this.id=`item${t.index+1}`,this.src=t.url,this.startPage=t.startPage,this.skipPagesBefore=t.skipPagesBefore}};function Rx(r){return r.id}function Ix(r){return t=>{let e=A("deobfuscator");return Vx("SHA-1",r).then(n=>{let s=t.slice(0,1040),i=t.slice(1040,t.size);Hf(s).then(o=>{let a=new DataView(o);for(let l=0;l<a.byteLength;l++){let c=a.getUint8(l);c^=n[l%20],a.setUint8(l,c)}e.finish(Ru([a,i]))})}),e.result()}}function Vx(r,t){let e=A("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(r,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var Ts={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"},Rr="http://idpf.org/epub/vocab/package/meta/#",Re={language:`${Ts.dcterms}language`,title:`${Ts.dcterms}title`,creator:`${Ts.dcterms}creator`,layout:`${Ts.rendition}layout`,titleType:`${Rr}title-type`,displaySeq:`${Rr}display-seq`,alternateScript:`${Rr}alternate-script`,role:`${Rr}role`};function Fx(r,t){let e={};return(n,s)=>{var d,h,f,g,m,y;let i,o,a=n.r||e,l=s.r||e;if(r==Re.title&&(i=((d=a[Re.titleType])==null?void 0:d[0].v)=="main",o=((h=l[Re.titleType])==null?void 0:h[0].v)=="main",i!=o))return i?-1:1;let c=parseInt((f=a[Re.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[Re.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:r!=Re.language&&t&&(i=((m=a[Re.language]||a[Re.alternateScript])==null?void 0:m[0].v)==t,o=((y=l[Re.language]||l[Re.alternateScript])==null?void 0:y[0].v)==t,i!=o)?i?-1:1:n.o-s.o}}function Bx(r,t){let e;if(!t)e=Ts;else{e={};for(let h in Ts)e[h]=Ts[h];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),e[d[1]]=d[2]}let n=d=>{if(d){let h=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(h){let f=h[2]?e[h[2]]:Rr;if(f)return f+h[3]}}return null},s=1,i=r.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let h=n(d.getAttribute("property"));if(h)return{name:h,value:d.textContent,id:d.getAttribute("id"),order:s++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Ts.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=Gr(i,d=>d.refines),a=d=>ff(d,(h,f)=>h.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:Re.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&y.push({name:Re.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let S=Gr(y,C=>C.name);m.r=a(S)}return m})),l=a(Gr(i,d=>d.refines?null:d.name)),c=null;l[Re.language]&&(c=l[Re.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(Fx(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function Ox(){let r=window.MathJax;return r?r.Hub:null}var aC={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},$h="viv-id-",li=class{constructor(t,e){this.store=t;this.pubURL=e;p(this,"opfXML",null);p(this,"encXML",null);p(this,"items",null);p(this,"spine",null);p(this,"itemMap",null);p(this,"itemMapByPath",null);p(this,"uid",null);p(this,"bindings",{});p(this,"lang",null);p(this,"epageCount",0);p(this,"prePaginated",!1);p(this,"epageIsRenderedPage",!0);p(this,"epageCountCallback",null);p(this,"metadata",{});p(this,"toc",null);p(this,"cover",null);p(this,"fallbackMap",{});p(this,"pageProgression",null);p(this,"documentURLTransformer");this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let t=this;class e{transformFragment(s,i){let o=i+(s?`#${s}`:"");return $h+Mc(o,":")}transformURL(s,i){let o=s.match(/^([^#]*)#?(.*)$/);if(o){let a=o[1]||i.replace(/\?viv-toc-box$/,""),l=decodeURIComponent(o[2]);if(a&&t.spine.some(c=>c.src===a))return`#${this.transformFragment(l,a)}`}return s}restoreURL(s){s.charAt(0)==="#"&&(s=s.substring(1)),s.indexOf($h)===0&&(s=s.substring($h.length));let o=pf(s,":").match(/^([^#]*)#?(.*)$/);return o?[o[1],o[2]]:[]}}return new e}getMetadata(){return this.metadata}getPathFromURL(t){if(t.startsWith("data:"))return t===this.pubURL?"":t;if(this.pubURL){let e=te("",this.pubURL);return t===e||t+"/"===e?"":(e.charAt(e.length-1)!="/"&&(e+="/"),t.substr(0,e.length)==e?decodeURIComponent(t.substr(e.length)):null)}else return t}initWithXMLDoc(t,e){this.opfXML=t,this.encXML=e;let n=t.doc().child("package"),s=n.attribute("unique-identifier")[0];if(s){let c=t.getElement(`${t.url}#${s}`);c&&(this.uid=c.textContent.replace(/[ \n\r\t]/g,""))}let i={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new gc,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!aC[u.mediaType]&&(i[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=_c(this.items,Rx),this.itemMapByPath=_c(this.items,c=>this.getPathFromURL(c.src));for(let c in i){let u=c;for(;;){let d=this.itemMap[i[u]];if(!d)break;if(aC[d.mediaType]){this.fallbackMap[c]=d.src;break}u=d.src}}this.spine=n.child("spine").child("itemref").asArray().map((c,u)=>{let d=c,h=d.getAttribute("idref"),f=this.itemMap[h];return f&&(f.itemRefElement=d,f.spineIndex=u),f});let o=n.child("spine").attribute("page-progression-direction")[0];o&&(this.pageProgression=Pc(o));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(zh.withChild("EncryptionMethod",zh.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],l=n.child("bindings").child("mediaType").asArray();for(let c=0;c<l.length;c++){let u=l[c].getAttribute("handler"),d=l[c].getAttribute("media-type");d&&u&&this.itemMap[u]&&(this.bindings[d]=this.itemMap[u].src)}if(this.metadata=Bx(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[Re.language]&&(this.lang=this.metadata[Re.language][0].v),this.metadata[Re.layout]&&(this.prePaginated=this.metadata[Re.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=Ix(this.uid);for(let u=0;u<a.length;u++)this.store.deobfuscators[this.pubURL+a[u]]=c}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let t=0;for(let e of this.spine){let n=this.prePaginated?1:Math.ceil(e.compressedSize/1024);e.epage=t,e.epageCount=n,t+=n}this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(t){this.epageIsRenderedPage=t||this.prePaginated}countEPages(t){if(this.epageCountCallback=t,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let e=0,n=0,s=A("countEPages");return s.loopWithFrame(i=>{if(n===this.spine.length){i.breakLoop();return}let o=this.spine[n++];o.epage=e,this.store.load(o.src).then(a=>{let l=1800,c=a.lang||this.lang;c&&c.match(/^(ja|ko|zh)/)&&(l/=3),o.epageCount=Math.ceil(a.getTotalOffset()/l),e+=o.epageCount,this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount),i.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new Ar(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let i=new gc;i.initWithParam(s),i.id;let o=n.document.createElement("itemref");o.setAttribute("idref",i.id),n.root.appendChild(o),i.itemRefElement=o,this.itemMap[i.id]=i;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=i,this.items.push(i)}),e?this.store.addDocument(t[0].url,e):T(null)}initWithWebPubManifest(t,e,n){var h,f,g,m;t.readingProgression&&(this.pageProgression=t.readingProgression),this.metadata===void 0&&(this.metadata={});let s=t.name||((h=t.metadata)==null?void 0:h.title)||(e==null?void 0:e.title);s&&(this.metadata[Re.title]=(Array.isArray(s)?s:[s]).map(y=>{var S;return{v:(S=y.value)!=null?S:y}}));let i=t.author||t.creator||((f=t.metadata)==null?void 0:f.author)||Array.from((g=e==null?void 0:e.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?g:[]).map(y=>y.content);i&&i.length!==0&&(this.metadata[Re.creator]=(Array.isArray(i)?i:[i]).map(y=>{var S;return{v:(S=y.name)!=null?S:y}}));let o=t.inLanguage||((m=t.metadata)==null?void 0:m.language)||(e==null?void 0:e.documentElement.lang)||(e==null?void 0:e.documentElement.getAttribute("xml:lang"));o&&(this.metadata[Re.language]=(Array.isArray(o)?o:[o]).map(y=>({v:y})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let y of rC(e)){let S=y.getAttribute("href");if(/^(https?:)?\/\//.test(S)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(S))continue;let C=Wt(te(S,this.pubURL)),x=this.getPathFromURL(C),N=x!==null?encodeURI(x):C;t.readingOrder.indexOf(N)==-1&&t.readingOrder.push(N)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(y=>{y instanceof Array&&y.forEach(S=>{let C=y===t.readingOrder,x=typeof S=="string"?S:S.url||S.href,N=typeof S=="string"?"":S.encodingFormat||S.href&&S.type||"";if(C||N==="text/html"||N==="application/xhtml+xml"||!N&&S.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(x)){let E=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,v={url:te(Zn(x),E),index:c++,startPage:null,skipPagesBefore:null};S.rel==="contents"&&u===-1&&(u=v.index),l.push(v)}})});let d=A("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var S,C;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(S=this.items)==null?void 0:S[0]:this.itemMapByPath[a]);let y=(C=t.readingOrder)==null?void 0:C.length;y&&y<this.items.length&&this.items.splice(y),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=A("getCFI");return this.store.load(n.src).then(i=>{let o=i.getNodeByOffset(e),a=null;if(o){let l=i.getNodeOffset(o,0,!1),c=e-l,u=new ao;u.prependPathFromNode(o,c,!1,null),n.itemRefElement&&u.prependPathFromNode(n.itemRefElement,0,!1,null),a=u.toString()}s.finish(a)}),s.result()}resolveFragment(t){return In("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new ao;n.fromString(t);let s;if(this.opfXML){let i=n.navigate(this.opfXML.document);if(i.node.nodeType!=1||i.after||!i.ref){e.finish(null);return}let o=i.node,a=o.getAttribute("idref");if(o.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=i.ref}else s=this.spine[0];this.store.load(s.src).then(i=>{let o=n.navigate(i.document),a=i.getNodeOffset(o.node,o.offset,o.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return In("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let i=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);i==-1&&(i=this.spine.length-1);let o=this.spine[i];(!o||o.epageCount==0)&&(o=this.spine[--i]);let a=Math.floor(t-o.epage);e.finish({spineIndex:i,offsetInItem:-1,pageIndex:a});return}let n=At(this.spine.length,i=>{let o=this.spine[i];return o.epage+o.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(i=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let o=0;if(t>0){let a=i.getTotalOffset();o=Math.round(a*t/s.epageCount),o==a&&o--}e.finish({spineIndex:n,offsetInItem:o,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve epage:",t),e.finish(null)})}getEPageFromPosition(t){let e=this.spine[t.spineIndex];if(this.epageIsRenderedPage){let s=e.epage+t.pageIndex;return T(s)}if(t.offsetInItem<=0)return T(e.epage);let n=A("getEPage");return this.store.load(e.src).then(s=>{let i=s.getTotalOffset(),o=Math.min(i,t.offsetInItem);n.finish(e.epage+o*e.epageCount/i)}),n.result()}},fc=(r,t)=>({page:r,position:{spineIndex:r.spineIndex,pageIndex:t,offsetInItem:r.offset}}),mc=class{constructor(t,e,n,s,i){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=i;p(this,"spineItems",[]);p(this,"spineItemLoadingContinuations",[]);p(this,"pref");p(this,"clientLayout");p(this,"counterStore");p(this,"tocAutohide",!1);p(this,"tocVisible",!1);p(this,"tocView");this.pref=ra(s),this.clientLayout=new rc(e),this.counterStore=new ma(t.documentURLTransformer)}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}getCurrentPageProgression(t){if(this.opf.pageProgression)return this.opf.pageProgression;{let e=this.spineItems[t?t.spineIndex:0];return e?e.instance.pageProgression:null}}finishPageContainer(t,e,n){e.container.style.display="none",e.container.style.visibility="visible",e.container.style.position="",e.container.style.top="",e.container.style.left="",e.container.setAttribute("data-vivliostyle-page-side",e.side);let s=t.pages[n];if(e.isFirstPage=t.item.spineIndex==0&&n==0,t.pages[n]=e,this.opf.epageIsRenderedPage){if(n==0&&t.item.spineIndex>0){let i=this.opf.spine[t.item.spineIndex-1];t.item.epage=i.epage+i.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((i,o)=>i+o.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(s)t.instance.viewport.contentContainer.replaceChild(e.container,s.container),s.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:e});else{let i=null;if(n>0)i=t.pages[n-1].container.nextElementSibling;else for(let o=t.item.spineIndex+1;o<this.spineItems.length;o++){let a=this.spineItems[o];if(a&&a.pages[0]){i=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,i)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}renderSinglePage(t,e){let n=A("renderSinglePage"),s=t.pages[e?e.page:0],i=this.makePage(t,e);return s&&(i.pageType=s.pageType),t.instance.layoutNextPage(i,e).then(o=>{e=o;let a=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,i,a),this.counterStore.finishPage(i.spineIndex,a);let l=null;if(e){let c=t.layoutPositions[e.page];t.layoutPositions[e.page]=e,c&&t.pages[e.page]&&(e.isSamePosition(c)||(l=this.renderSinglePage(t,e)))}l||(l=T(!0)),l.then(()=>{let c=this.counterStore.getUnresolvedRefsToPage(i),u=0;n.loopWithFrame(d=>{if(u++,u>c.length){d.breakLoop();return}let h=c[u-1];if(h.refs=h.refs.filter(f=>!f.isResolved()),h.refs.length===0){d.continueLoop();return}this.getPageViewItem(h.spineIndex).then(f=>{if(!f){d.continueLoop();return}let{currentPageType:g,previousPageType:m}=f.instance.styler.cascade,y=f.instance.scopes;f.instance.scopes={},this.counterStore.pushPageCounters(h.pageCounters),this.counterStore.pushReferencesToSolve(h.refs);let S=f.layoutPositions[h.pageIndex];this.renderSinglePage(f,S).then(C=>{f.instance.styler.cascade.currentPageType=g,f.instance.styler.cascade.previousPageType=m,f.instance.scopes=y,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let x=C.pageAndPosition.position;x.spineIndex===i.spineIndex&&x.pageIndex===a&&(i=C.pageAndPosition.page),d.continueLoop()})})}).then(()=>{i.container.parentElement||(i=t.pages[a]),i.isLastPage=!e&&t.item.spineIndex===this.opf.spine.length-1,i.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),i.container.setAttribute("data-vivliostyle-page-index",a),i.container.setAttribute("data-vivliostyle-spine-index",i.spineIndex),n.finish({pageAndPosition:fc(i,a),nextLayoutPosition:e})})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let i=At(e.layoutPositions.length,o=>e.instance.getPosition(e.layoutPositions[o],!0)>s);i===e.layoutPositions.length?e.complete?n=e.layoutPositions.length-1:n=Number.POSITIVE_INFINITY:n=i-1}else n===Number.POSITIVE_INFINITY&&t.offsetInItem!==-1&&(s=t.offsetInItem);return{spineIndex:t.spineIndex,pageIndex:n,offsetInItem:s}}findPage(t,e){let n=A("findPage");return this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let i=null,o;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);o=l.pageIndex,i=s.pages[o],i?a.breakLoop():s.complete?(o=s.layoutPositions.length-1,i=s.pages[o],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(i=c.page,o=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(fc(i,o))})}),n.result()}renderPage(t){let e=A("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),i=s.pageIndex,o=s.offsetInItem,a=n.pages[i];if(a){e.finish(fc(a,i));return}e.loopWithFrame(l=>{if(i<n.layoutPositions.length){l.breakLoop();return}if(n.complete){i=n.layoutPositions.length-1,l.breakLoop();return}let c=n.layoutPositions[n.layoutPositions.length-1];this.renderSinglePage(n,c).then(u=>{let d=u.pageAndPosition.page;if(c=u.nextLayoutPosition,c){if(o>=0&&n.instance.getPosition(c)>o){a=d,i=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,i=u.pageAndPosition.position.pageIndex,n.complete=!0,l.breakLoop()})}).then(()=>{a=a||n.pages[i];let l=n.layoutPositions[i];if(a){e.finish(fc(a,i));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||(n.complete=!0),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=A("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(e=>{t.loopWithFrame(n=>{this.spineItems.some(s=>s==null?void 0:s.pages.some(i=>i==null?void 0:i.fetchers.some(o=>!o.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=A("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,i=t.pageIndex,o=0;e&&(o=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:o,pageIndex:o===s?i:Number.POSITIVE_INFINITY,offsetInItem:o===s?t.offsetInItem:-1};this.renderPage(c).then(u=>{a=u,++o>s?l.breakLoop():l.continueLoop()})}).then(()=>{n.finish(a)}),n.result()}firstPage(t,e){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},e)}lastPage(t,e){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},e)}nextPage(t,e){let n=t.spineIndex,s=t.pageIndex,i=A("nextPage");return this.getPageViewItem(n).then(o=>{if(!o){i.finish(null);return}if(o.complete&&s==o.layoutPositions.length-1){if(n>=this.opf.spine.length-1){i.finish(null);return}n++,s=0;let a=this.spineItems[n],l=a&&a.pages[0],c=o.pages[o.pages.length-1];l&&c&&l.side==c.side&&(a.pages.forEach(u=>{u.container&&u.container.remove()}),this.spineItems[n]=null,this.spineItemLoadingContinuations[n]=null)}else s++;this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e).thenFinish(i)}),i.result()}previousPage(t,e){let n=t.spineIndex,s=t.pageIndex;if(s==0){if(n==0)return T(null);n--,s=Number.POSITIVE_INFINITY}else s--;return this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e)}isRectoPage(t,e){let n=t.side==="left",s=this.getCurrentPageProgression(e)==="ltr";return!n&&s||n&&!s}getSpread(t,e){let n=this.getPage(t);if(!n)return T({left:null,right:null});let s=A("getSpread"),i=n.side==="left",o;return this.isRectoPage(n,t)?o=this.previousPage(t,e):o=this.nextPage(t,e),o.then(a=>{let l=this.getPage(t),c=a&&a.page;c&&c.side===l.side&&(c=null),i?s.finish({left:l,right:c}):s.finish({left:c,right:l})}),s.result()}nextSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),i=this.nextPage(t,e);return s?i:i.thenAsync(o=>{if(o){if(o.page.side===n.side)return i;let a=this.nextPage(o.position,e);return a.thenAsync(l=>l?a:i)}else return T(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),i=this.previousPage(t,e),o=n.container.previousElementSibling;return s?i.thenAsync(a=>a?a.page.side===n.side||a.page.container!==o?i:this.previousPage(a.position,e):T(null)):i}navigateToEPage(t,e,n){let s=A("navigateToEPage");return this.opf.resolveEPage(t).then(i=>{i?this.findPage(i,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=A("navigateToCFI");return this.opf.resolveFragment(t).then(i=>{i?this.findPage(i,n).thenFinish(s):s.finish(null)}),s.result()}navigateTo(t,e,n){F.debug("Navigate to",t);let s=this.opf.getPathFromURL(Wt(t));if(!s){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))s=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let a=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(s=this.opf.getPathFromURL(a[0]),s==null&&(s=a[0])):s=a[0],t=a[0]+(a[1]?`#${a[1]}`:"")}if(s==null)return T(null)}let i=this.opf.itemMapByPath[s];if(!i){if(this.opf.opfXML&&s==this.opf.getPathFromURL(this.opf.opfXML.url)){let a=t.indexOf("#");if(a>=0)return this.navigateToFragment(t.substr(a+1),e,n)}return T(null)}let o=A("navigateTo");return this.getPageViewItem(i.spineIndex).then(a=>{if(!a){o.finish(null);return}let l=a.xmldoc.getElement(t);this.findPage({spineIndex:i.spineIndex,pageIndex:-1,offsetInItem:l?a.xmldoc.getElementOffset(l):0},n).thenFinish(o)}),o.result()}makePage(t,e){let n=t.instance.viewport,s=n.document.createElement("div");s.setAttribute("data-vivliostyle-page-container","true"),s.role="presentation",Ps||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let i=n.document.createElement("div");i.setAttribute("data-vivliostyle-bleed-box","true"),i.role="presentation",s.appendChild(i);let o=new Fi(s,i);if(o.spineIndex=t.item.spineIndex,o.position=e,o.offset=t.instance.getPosition(e),o.offset===0&&!(t.instance.blankPageAtStart&&t.pages.length===0)){let a=this.opf.documentURLTransformer.transformFragment("",t.item.src);i.setAttribute("id",a),o.registerElementWithId(i,a)}if(n!==this.viewport){let a=Gc(this.viewport.width,this.viewport.height,n.width,n.height),l=yn(null,new Ge(a,null),"");o.delayedItems.push(new ls(s,"transform",l))}return o}makeObjectView(t,e,n,s){let i=e.getAttribute("data"),o=null;if(i){i=te(i,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(i);if(l){let c=this.opf.itemMapByPath[l];c&&(a=c.mediaType)}}if(a){let l=this.opf.bindings[a];if(l){o=this.viewport.document.createElement("iframe"),o.style.border="none";let c=Oc(i),u=Oc(a),d=new et;d.append(l),d.append("?src="),d.append(c),d.append("&type="),d.append(u);for(let g=e.firstChild;g;g=g.nextSibling)if(g.nodeType==1){let m=g;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let y=m.getAttribute("name"),S=m.getAttribute("value");y&&S&&(d.append("&"),d.append(encodeURIComponent(y)),d.append("="),d.append(encodeURIComponent(S)))}}o.setAttribute("src",d.toString());let h=e.getAttribute("width");h&&o.setAttribute("width",h);let f=e.getAttribute("height");f&&o.setAttribute("height",f)}}}return o||(o=this.viewport.document.createElement("object"),i&&o.setAttribute("data",i),o.setAttribute("data-adapt-process-children","true")),T(o)}makeMathJaxView(t,e,n,s){let i=Ox();if(i){let o=n.ownerDocument,a=o.createElement("span");n.appendChild(a);let l=o.importNode(e,!0);this.resolveURLsInMathML(l,t),a.appendChild(l);let c=i.queue;c.Push(["Typeset",i,a]);let u=A("makeMathJaxView"),d=u.suspend();return c.Push(()=>{d.schedule(a)}),u.result()}return T(null)}resolveURLsInMathML(t,e){if(t!=null){if(t.nodeType===1&&t.tagName==="mglyph"){let n=Array.from(t.attributes);for(let s of n){if(s.name!=="src")continue;let i=te(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,i):t.setAttribute(s.name,i)}}t.firstChild&&this.resolveURLsInMathML(t.firstChild,e),t.nextSibling&&this.resolveURLsInMathML(t.nextSibling,e)}}makeCustomRenderer(t){return(e,n,s)=>e.localName=="object"&&e.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(t,e,n,s):e.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(t,e,n,s):e.dataset&&e.dataset.mathTypeset=="true"?this.makeMathJaxView(t,e,n,s):T(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return T(null);let e=this.spineItems[t];if(e)return T(e);let n=A("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let i=this.opf.spine[t],o=this.opf.store;return o.load(i.src).then(a=>{var x;let l=i.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),i.title=a.document.title;let c=o.getStyleForDoc(a),u=this.makeCustomRenderer(a),d=this.viewport,h=c.sizeViewport(d.width,d.height,d.fontSize,this.pref);(h.width!=d.width||h.height!=d.height||h.fontSize!=d.fontSize)&&(d=new Yn(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(x=this.spineItems[0])==null?void 0:x.instance.isVersoFirstPage,g=this.spineItems[t-1],m,y;if(i.startPage!==null)m=i.startPage-1,y=m;else{if(t>0&&(!g||!g.complete))m=i.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,y=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let N=this.counterStore.currentPageCounters.page;y=!N||!N.length?m:N[N.length-1]}i.skipPagesBefore!==null&&(m+=i.skipPagesBefore,y+=i.skipPagesBefore)}this.counterStore.forceSetPageCounter(y);let S=new vs(c,a,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);S.pref=this.pref;let C=this.opf.metadata&&this.opf.metadata[Re.title];S.pubTitle=C&&C[0]&&C[0].v||"",S.docTitle=i.title||"",S.init().then(()=>{!this.opf.pageProgression&&S.pageProgression&&(this.opf.pageProgression=S.pageProgression),e={item:i,xmldoc:a,instance:S,layoutPositions:[null],pages:[],complete:!1},this.spineItems[t]=e,n.finish(e),s.forEach(N=>{N.schedule(e)})})}),n.result()}removeRenderedPages(){let t=this.spineItems;for(let e of t)e&&e.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let t=this.spineItems;for(let e of t)if(e){let n=e.pages;for(let s of n)if(s.isAutoPageWidth&&s.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(t=>t&&t.pages.length>0)}showTOC(t){let e=this.opf,n=e.toc;if(this.tocAutohide=t,!n)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let s=A("showTOC");this.tocView||(this.tocView=new pc(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore));let i=this.viewport,o=Math.min(344,Math.round(.67*i.width)-16),a=i.height-6,l=i.document.createElement("div");return i.root.appendChild(l),Ps||(l.style.visibility="hidden"),l.style.width=`${o+16}px`,l.style.maxHeight=`${a}px`,l.setAttribute("data-vivliostyle-toc-box","true"),l.setAttribute("role","navigation"),this.tocView.showTOC(l,i,o,a,this.viewport.fontSize).then(c=>{l.style.visibility="visible",l.setAttribute("aria-hidden","false"),s.finish(c)}),s.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}};var lC="data-vivliostyle-viewer-status",Mx="data-vivliostyle-spread-view",jh=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(jh||{}),Cc=class{constructor(t,e,n,s){this.window=t;this.viewportElement=e;this.instanceId=n;this.callbackFn=s;p(this,"fontMapper");p(this,"kick");p(this,"sendCommand");p(this,"resizeListener");p(this,"hyperlinkListener");p(this,"pageRuleStyleElement");p(this,"pageSheetSizeAlreadySet",!1);p(this,"renderTask",null);p(this,"actions");p(this,"readyState");p(this,"packageURL");p(this,"opf");p(this,"touchActive");p(this,"touchX");p(this,"touchY");p(this,"needResize");p(this,"resized");p(this,"needRefresh");p(this,"viewportSize");p(this,"currentPage");p(this,"currentSpread");p(this,"pagePosition");p(this,"fontSize");p(this,"zoom");p(this,"fitToScreen");p(this,"pageViewMode");p(this,"waitForLoading");p(this,"renderAllPages");p(this,"pref");p(this,"pageSizes");p(this,"pixelRatio");p(this,"pixelRatioLimit");p(this,"viewport");p(this,"opfView");let i=e.ownerDocument,o=(a,l)=>{let c=i.getElementById(a);return c||(c=i.createElement("style"),c.id=a,l&&(c.textContent=l),i.head.appendChild(c)),c};o("vivliostyle-viewport-screen-css",Eu),o("vivliostyle-viewport-css",Nu),o("vivliostyle-polyfill-css",Au),e.setAttribute("data-vivliostyle-viewer-viewport",!0),Ps&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(lC,"loading"),this.fontMapper=new jl(i.head,e),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=a=>{},this.pageRuleStyleElement=o("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=zc(),this.pageSizes=[],this.pixelRatioLimit=Hr==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=Lc;F.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),F.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),F.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),F.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){this.readyState!==t&&(this.readyState=t,this.viewportElement.setAttribute(lC,t),this.callback({t:"readystatechange"}))}loadPublication(t){Je.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,i=t.userStyleSheet;this.viewport=null;let o=A("loadPublication");return this.configure(t).then(()=>{let a=new Ir;a.init(s,i).then(()=>{let l=te(Zn(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.render(n).then(()=>{o.finish(!0)})):o.finish(!1)})})}),o.result()}loadXML(t){Je.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,i=t.authorStyleSheet,o=t.userStyleSheet;this.viewport=null;let a=A("loadXML");return this.configure(t).then(()=>{let l=new Ir;l.init(i,o).then(()=>{let c=e.map((u,d)=>({url:te(Zn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new li(l,""),this.opf.initWithChapters(c,n).then(()=>{this.render(s).then(()=>{a.finish(!0)})})})}),a.result()}render(t){this.cancelRenderingTask();let e;return t?e=this.opf.resolveFragment(t).thenAsync(n=>(this.pagePosition=n,T(!0))):e=T(!0),e.thenAsync(()=>(Je.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let i=s[0];if(i==="em"||i==="rem")return e*this.fontSize;let o=Ze[i];if(o)return e*o}return e}configure(t){if(typeof t.autoresize=="boolean"&&(t.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof t.fontSize=="number"){let e=t.fontSize;e>=5&&e<=72&&this.fontSize!=e&&(this.fontSize=e,this.needResize=!0)}if(typeof t.viewport=="object"&&t.viewport){let e=t.viewport,n={marginLeft:this.resolveLength(e["margin-left"])||0,marginRight:this.resolveLength(e["margin-right"])||0,marginTop:this.resolveLength(e["margin-top"])||0,marginBottom:this.resolveLength(e["margin-bottom"])||0,width:this.resolveLength(e.width)||0,height:this.resolveLength(e.height)||0};(n.width>=200||n.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=n,this.needResize=!0)}if(typeof t.hyphenate=="boolean"&&(this.pref.hyphenate=t.hyphenate,this.needResize=!0),typeof t.horizontal=="boolean"&&(this.pref.horizontal=t.horizontal,this.needResize=!0),typeof t.nightMode=="boolean"&&(this.pref.nightMode=t.nightMode,this.needResize=!0),typeof t.lineHeight=="number"&&(this.pref.lineHeight=t.lineHeight,this.needResize=!0),typeof t.columnWidth=="number"&&(this.pref.columnWidth=t.columnWidth,this.needResize=!0),typeof t.fontFamily=="string"&&(this.pref.fontFamily=t.fontFamily,this.needResize=!0),typeof t.load=="boolean"&&(this.waitForLoading=t.load),typeof t.renderAllPages=="boolean"&&(this.renderAllPages=t.renderAllPages),typeof t.userAgentRootURL=="string"&&(Ic(t.userAgentRootURL.replace(/resources\/?$/,"")),Vc(t.userAgentRootURL)),typeof t.rootURL=="string"&&(Ic(t.rootURL),Vc(`${kn}resources/`)),typeof t.pageViewMode=="string"&&t.pageViewMode!==this.pageViewMode&&(this.pageViewMode=t.pageViewMode,this.needResize=!0),typeof t.pageBorder=="number"&&t.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=t.pageBorder,this.needResize=!0),typeof t.zoom=="number"&&t.zoom!==this.zoom&&(this.zoom=t.zoom,this.needRefresh=!0),typeof t.fitToScreen=="boolean"&&t.fitToScreen!==this.fitToScreen&&(this.fitToScreen=t.fitToScreen,this.needRefresh=!0),typeof t.defaultPaperSize=="object"&&typeof t.defaultPaperSize.width=="number"&&typeof t.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=t.defaultPaperSize,this.needResize=!0),typeof t.allowScripts=="boolean"&&t.allowScripts!==cn&&(Zm(t.allowScripts),this.needResize=!0),typeof t.pixelRatio=="number"){let e=Math.min(t.pixelRatio,this.pixelRatioLimit);e!==this.pixelRatio&&(this.pixelRatio=e,this.needResize=!0)}return this.configurePlugins(t),T(!0)}configurePlugins(t){qe("CONFIGURATION").forEach(n=>{let s=n(t);this.needResize=s.needResize||this.needResize,this.needRefresh=s.needRefresh||this.needRefresh})}pageReplacedListener(t){let e=this.currentPage,n=this.currentSpread,s=t.target;n?(n.left===s||n.right===s)&&this.showCurrent(t.newPage):e===t.target&&this.showCurrent(t.newPage)}forCurrentPages(t){let e=[];this.currentPage&&e.push(this.currentPage),this.currentSpread&&(e.push(this.currentSpread.left),e.push(this.currentSpread.right)),e.forEach(n=>{n&&t(n)})}removePageListeners(){this.forCurrentPages(t=>{t.removeEventListener("hyperlink",this.hyperlinkListener,!1),t.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(t=>{w(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),w(t.container,"visibility","visible"),w(t.container,"display","block")}showPage(t){this.hidePages(),this.currentPage=t,t.container.style.marginLeft="",t.container.style.marginRight="",this.showSinglePage(t)}showSpread(t){if(this.hidePages(),this.currentSpread=t,t.left&&t.right){let e=parseFloat(t.left.container.style.width),n=parseFloat(t.right.container.style.width);e&&n&&e!==n&&(e<n?t.left.container.style.marginLeft=`${n-e}px`:t.right.container.style.marginRight=`${e-n}px`)}t.left&&(this.showSinglePage(t.left),t.right?t.left.container.removeAttribute("data-vivliostyle-unpaired-page"):t.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),t.right&&(this.showSinglePage(t.right),t.left?t.right.container.removeAttribute("data-vivliostyle-unpaired-page"):t.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let t=A("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(e=>{let n=this.currentPage;(this.waitForLoading&&n.fetchers.length>0?ns(n.fetchers):T(!0)).then(()=>{this.sendLocationNotification(n,e).thenFinish(t)})}),t.result()}createViewport(){let t=this.viewportElement;if(this.viewportSize){let e=this.viewportSize;return t.style.marginLeft=`${e.marginLeft}px`,t.style.marginRight=`${e.marginRight}px`,t.style.marginTop=`${e.marginTop}px`,t.style.marginBottom=`${e.marginBottom}px`,new Yn(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new Yn(this.window,this.fontSize,this.pixelRatio,t)}resolveSpreadView(t,e){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return t!=null&&(t.width-this.pref.pageBorder)/t.height>=(e?e.width*2/e.height:1.45)&&(!!e||t.width>800)}}updateSpreadView(t){this.pref.spreadView=t,this.viewportElement.setAttribute(Mx,t.toString())}sizeIsGood(){var o;let t=this.createViewport(),e=((o=this.opfView)==null?void 0:o.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&e?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:e?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(t,e,n,s){this.pageSizes[s]=t,this.setPageSizePageRules(e,n,s),s===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,t))}setPageSizePageRules(t,e,n){var i,o;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((i=this.pageSizes[n-1])==null?void 0:i.width)||this.pageSizes[n].height!==((o=this.pageSizes[n-1])==null?void 0:o.height))){let c=function(m){let y=m*.75;return Math.ceil(y)};var s=c;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),u=c(a),d=c(l),h=u*((this.pixelRatio||1)-1)+2,f=d*((this.pixelRatio||1)-1)+2,g=`@page {size: ${u}pt ${d}pt; margin: 0 ${-h}pt ${-f}pt 0;}`;this.pageRuleStyleElement.textContent=g,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new mc(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let n=this.resolveSpreadView(this.viewport,t.dimensions);return n!==this.pref.spreadView&&this.updateSpreadView(n),n?this.opfView.getSpread(this.pagePosition,e).thenAsync(s=>!s.left&&!s.right?T(null):s.left&&s.right&&(!this.resolveSpreadView(this.viewport,s.left.dimensions)||!this.resolveSpreadView(this.viewport,s.right.dimensions))?(this.updateSpreadView(!1),this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null)):(this.showSpread(s),this.setSpreadZoom(s),this.currentPage=t.side==="left"?s.left:s.right,T(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null))}setPageZoom(t){var n;let e=this.getAdjustedZoomFactor(t.dimensions);(n=this.viewport)==null||n.zoom(t.dimensions.width,t.dimensions.height,e)}setSpreadZoom(t){var n;let e=this.getSpreadDimensions(t);(n=this.viewport)==null||n.zoom(e.width,e.height,this.getAdjustedZoomFactor(e))}getAdjustedZoomFactor(t){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(t):this.zoom}getSpreadDimensions(t){let e=0,n=0;return t.left&&(e+=t.left.dimensions.width,n=t.left.dimensions.height),t.right&&(e+=t.right.dimensions.width,n=Math.max(n,t.right.dimensions.height)),t.left&&t.right&&(e+=this.pref.pageBorder*2,e+=Math.abs(t.left.dimensions.width-t.right.dimensions.width)),{width:e,height:n}}queryZoomFactor(t){if(!this.currentPage)throw new Error("no page exists.");switch(t){case"fit inside viewport":{let e;return this.pref.spreadView?(this.currentSpread,e=this.getSpreadDimensions(this.currentSpread)):e=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(e)}default:throw new Error(`unknown zoom type: ${t}`)}}calculateZoomFactorToFitInsideViewPort(t){if(!this.viewport)return this.zoom;let e=this.viewport.width/t.width,n=this.viewport.height/t.height;return Math.min(e,n)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new bc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=xo().getScheduler().run(()=>In("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,Je.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(n=>{if(!n){e.finish(!1);return}this.pagePosition=n.position,this.showCurrent(n.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(s=>{let i={t:"nav",epageCount:s,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)&&(i.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(i)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),Je.registerEndTiming("render (resize)"),cn&&Dh(this.window)?eC(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s))})})})})})},(e,n)=>{if(n instanceof bc)Je.registerEndTiming("render (resize)"),F.debug(n.message);else throw n}));return T(!0)}sendLocationNotification(t,e){let n=A("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:t.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(i=>{s.epage=i,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(t){var s;let e;if(this.readyState!=="complete"&&t.where!=="next"&&this.setReadyState("loading"),typeof t.where=="string"){let i;switch(t.where){case"next":i=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":i=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":i=this.opfView.lastPage;break;case"first":i=this.opfView.firstPage;break;default:return T(!0)}i&&(e=()=>i.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let i=t.epage;e=()=>this.opfView.navigateToEPage(i,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let i=t.url;e=()=>this.opfView.navigateTo(i,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let i=t.position;e=()=>this.opfView.findPage(i,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=A("moveTo");return e.call(this.opfView).then(i=>{let o;if(i){this.pagePosition=i.position;let a=A("moveTo.showCurrent");o=a.result(),this.showCurrent(i.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(a)})}else o=T(!0);o.then(a=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(a)})}),n.result()}showTOC(t){let e=!!t.autohide,n=t.v,s=this.opfView.isTOCVisible(),i=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!i)return T(!0)}else if(n=="hide")return T(!0);if(s&&n!="show")return this.opfView.hideTOC(),T(!0);{let o=A("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(i&&(a.listeners={}),e){let l=()=>{this.opfView.hideTOC()};a.addEventListener("hyperlink",l,!1)}a.addEventListener("hyperlink",this.hyperlinkListener,!1)}o.finish(!0)}),o.result()}}runCommand(t){let e=t.a||"";return In("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(F.error("No such action:",e),n.finish(!0))},(n,s)=>{F.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=cC(t),n=null,s=this;Uf(()=>{let i=A("commandLoop"),o=xo().getScheduler();return s.hyperlinkListener=a=>{let l=a,c=l.href.charAt(0)==="#"||s.packageURL.some(u=>l.href.substr(0,u.length)==u);if(c){a.preventDefault();let u={t:"hyperlink",href:l.href,internal:c};o.run(()=>(s.callback(u),T(!0)))}},i.loopWithFrame(a=>{if(s.needResize)s.resize().then(()=>{a.continueLoop()});else if(s.needRefresh)s.currentPage&&s.showCurrent(s.currentPage,!this.renderAllPages).then(()=>{a.continueLoop()});else if(e){let l=e;e=null,s.runCommand(l).then(()=>{a.continueLoop()})}else{let l=A("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(i),i.result()}),s.kick=()=>{let i=n;i&&(n=null,i.schedule(!0))},s.sendCommand=i=>e?!1:(e=cC(i),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Yh=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Yh||{}),bc=class r extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,r.prototype),this.stack=new Error().stack}};function cC(r){return typeof r=="string"?di(r):r}var uC=ks;function Ux(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function dC(r){let t={};return Object.keys(r).forEach(e=>{let n=r[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var Vr=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");wc(t.debug),this.adaptViewer_=new Cc(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=Ux(),e&&this.setOptions(e),this.eventTarget=new Kn,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},dC(t));this.adaptViewer_.sendCommand(e),Object.assign(this.options,t)}dispatcher(t){let e={type:t.t},n=t;Object.keys(n).forEach(s=>{s!=="t"&&(e[s]=n[s])}),this.eventTarget.dispatchEvent(e)}addListener(t,e){this.eventTarget.addEventListener(t,e,!1)}removeListener(t,e){this.eventTarget.removeEventListener(t,e,!1)}loadDocument(t,e,n){if(!t||(Array.isArray(t)?!t[0]||typeof t[0]!="string"&&!t[0].url:typeof t!="string"&&!t.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(t,null,e,n)}loadPublication(t,e,n){if(!t){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,t,e,n)}loadDocumentOrPublication(t,e,n,s){let i=n||{};function o(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=o(i.authorStyleSheet),l=o(i.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:Hx(t)||e,document:i.documentObject,fragment:i.fragment,authorStyleSheet:a,userStyleSheet:l},dC(this.options));this.initialized?this.adaptViewer_.sendCommand(c):(this.initialized=!0,this.adaptViewer_.initEmbed(c))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(t){switch(t){case"left":return this.getCurrentPageProgression()===uC.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===uC.LTR?"next":"previous";default:return t}}navigateToPage(t,e){t==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:e}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(t)})}navigateToInternalUrl(t){this.adaptViewer_.sendCommand({a:"moveTo",url:t})}navigateToPosition(t){var e,n;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:t.spineIndex,pageIndex:(e=t.pageIndex)!=null?e:-1,offsetInItem:(n=t.offsetInItem)!=null?n:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(t,e){let n=t==null?"toggle":t?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:n,autohide:e})}queryZoomFactor(t){return this.adaptViewer_.queryZoomFactor(t)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var t,e;return(e=(t=this.adaptViewer_.opfView)==null?void 0:t.tocView)==null?void 0:e.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function Hx(r){function t(n){return typeof n=="number"?n:null}function e(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(r)?r.map(e):r?[e(r)]:null}var pC=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(pC||{}),zx=Yh,Gx=jh;Je.forceRegisterEndTiming("load_vivliostyle");var qh=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:i=!0,removeIframe:o=!0}){p(this,"htmlDoc");p(this,"title");p(this,"printCallback");p(this,"errorCallback");p(this,"hideIframe");p(this,"removeIframe");p(this,"iframe");p(this,"iframeWin");p(this,"window");this.htmlDoc=t,this.title=e,this.printCallback=n,this.errorCallback=s,this.hideIframe=i,this.removeIframe=o}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
1799
+ `),n.toString()}},pc=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],i=e.family;if(s){if(s!=i)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=i}filterFontFamily(t){if(t instanceof me){let e=t.values,n=[];for(let s of e){let i=this.familyMap[s.stringValue()];i&&n.push(k(i)),n.push(s)}return new me(n)}else{let e=this.familyMap[t.stringValue()];return e?new me([k(e),t]):t}}},hc=class{constructor(t,e,n){this.head=t;this.body=e;p(this,"srcURLMap",{});p(this,"familyPrefix");p(this,"familyCounter",0);this.familyPrefix=n||"Fnt_"}getViewFontFamily(t,e){let n=t.family,s=e.familyMap[n];return s||(s=this.familyPrefix+ ++this.familyCounter,e.familyMap[n]=s,s)}initFont(t,e,n){let s=A("initFont"),i=t.src,r={};for(let u of Fh(t.properties))r[u]=t.properties[u];let a=this.getViewFontFamily(t,n);r["font-family"]=k(a);let l=new Do(r),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(i,e),this.head.appendChild(c),F.debug("Load font:",i),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n,i=this.srcURLMap[s];return i?i.piggyback(r=>{let a=r;a.traitsEqual(t)?(e.registerFamily(t,a),F.debug("Found already-loaded font:",n)):F.warn("E_FONT_FACE_INCOMPATIBLE",t.src)}):(i=new xn(()=>{let r=A("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?Qs(a,"blob").then(c=>{if(!c.responseBlob){r.finish(null);return}l(c.responseBlob).then(u=>{this.initFont(t,u,e).thenFinish(r)})}):this.initFont(t,null,e).thenFinish(r),r.result()},`loadFont ${n}`),this.srcURLMap[s]=i,i.start()),i}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){F.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return ds(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(i=>{}))}),e===0)return T(!0);let n=A("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?T(!0):T(!1))).thenFinish(n),n.result()}};var Lx=1,hr=class{constructor(t,e,n,s,i){this.name=e;this.pseudoName=n;this.classes=s;this.parent=i;p(this,"specified",{});p(this,"children",[]);p(this,"pageMaster",null);p(this,"index",0);p(this,"key");p(this,"_scope");this._scope=t,this.key=`p${Lx++}`,i&&(this.index=i.children.length,i.children.push(this))}get scope(){return this._scope}createInstance(t){throw new Error("E_UNEXPECTED_CALL")}clone(t){throw new Error("E_UNEXPECTED_CALL")}copySpecified(t){let e=this.specified,n=t.specified;for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}cloneChildren(t){for(let e=0;e<this.children.length;e++)this.children[e].clone({parent:t})}},fc=class extends hr{constructor(t){super(t,null,null,[],null),this.specified.width=new I(rs,0),this.specified.height=new I(os,0)}},gc=class extends Hs{constructor(e,n){super(e,i);this.pageMaster=n;let s=this;function i(r,a){let l=r.match(/^([^.]+)\.([^.]+)$/);if(l){let c=s.pageMaster.keyMap[l[1]];if(c){let d=this.lookupInstance(c);if(d)return a?d.resolveFunc(l[2]):d.resolveName(l[2])}}return null}}},fr=class o extends hr{constructor(e,n,s,i,r,a,l){super(e,n,s,i,r);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof gc||(this._scope=new gc(e,this)),this.pageMaster=this,this.specified.width=new I(rs,0),this.specified.height=new I(os,0),this.specified["wrap-flow"]=new I(b.auto,0),this.specified.position=new I(b.relative,0),this.specified.overflow=new I(b.visible,0)}createInstance(e){return new yi(e,this)}clone(e){let n=new o(this.scope,this.name,e.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(n),this.cloneChildren(n),n}resetScope(){this.scope.pageMaster=this}},mc=class o extends hr{constructor(t,e,n,s,i){super(t,e,n,s,i),this.pageMaster=i.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new I(b.auto,0)}createInstance(t){return new Bh(t,this)}clone(t){let e=new o(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},Vs=class o extends hr{constructor(t,e,n,s,i){super(t,e,n,s,i),this.pageMaster=i.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new Ln(t,this)}clone(t){let e=new o(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function Rx(o,t,e){return!t||X(t)?new he(o,e):t.toExpr(o,o.zero)}function oe(o,t,e){return!t||t===b.auto||X(t)?null:t.toExpr(o,e)}function Ix(o,t,e){return!t||t===b.normal||X(t)?null:t.toExpr(o,e)}function Ct(o,t,e){return!t||t===b.auto||X(t)?o.zero:t.toExpr(o,e)}function Dh(o,t,e){return!t||X(t)?o.zero:t===b.auto?null:t.toExpr(o,e)}function dn(o,t,e,n){return!t||e===b.none||X(t)?o.zero:t.toExpr(o,n)}function gC(o,t,e){return!t||X(t)?e:t===b._true?o._true:t===b._false?o._false:t.toExpr(o,o.zero)}var gr=class{constructor(t,e){this.parentInstance=t;this.pageBox=e;p(this,"cascaded",{});p(this,"style",{});p(this,"autoWidth",null);p(this,"autoHeight",null);p(this,"children",[]);p(this,"isAutoWidth",!1);p(this,"isAutoHeight",!1);p(this,"isTopDependentOnAutoHeight",!1);p(this,"isRightDependentOnAutoWidth",!1);p(this,"calculatedWidth",0);p(this,"calculatedHeight",0);p(this,"pageMasterInstance",null);p(this,"namedValues",{});p(this,"namedFuncs",{});p(this,"vertical",!1);p(this,"rtl",!1);p(this,"suppressEmptyBoxGeneration",!1);p(this,"borderBoxSizing",!1);t&&t.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(t,e){let n=this.resolveName(t),s=this.resolveName(e);if(!n||!s)throw new Error("E_INTERNAL");return $(this.pageBox.scope,n,s)}resolveName(t){let e=this.namedValues[t];if(e)return e;let n=this.style[t];switch(n&&(e=n.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),t){case"margin-left-edge":e=this.resolveName("left");break;case"margin-top-edge":e=this.resolveName("top");break;case"margin-right-edge":e=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":e=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":e=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":e=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":e=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":e=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":e=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":e=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":e=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":e=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":e=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":e=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":e=this.addNamedValues("left-edge","width");break;case"bottom-edge":e=this.addNamedValues("top-edge","height");break}if(!e){let s;if(t=="extent")s=this.vertical?"width":"height";else if(t=="measure")s=this.vertical?"height":"width";else{let i=this.vertical?yp:xp;s=t;for(let r in i)s=s.replace(r,i[r])}s!=t&&(e=this.resolveName(s))}return e&&(this.namedValues[t]=e),e}resolveFunc(t){let e=this.namedFuncs[t];if(e)return e;switch(t){case"columns":{let n=this.pageBox.scope,s=new Li(n,0),i=this.resolveName("column-count"),r=this.resolveName("column-width"),a=this.resolveName("column-gap");e=ee(n,Ri(n,new Fn(n,"min",[s,i]),$(n,r,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=gC(t,e.enabled,t._true),s=oe(t,e.page,t.zero);if(s){let a=new re(t,"page-number");n=ut(t,n,new is(t,s,a))}let i=oe(t,e["min-page-width"],t.zero);i&&(n=ut(t,n,new zs(t,new re(t,"page-width"),i)));let r=oe(t,e["min-page-height"],t.zero);r&&(n=ut(t,n,new zs(t,new re(t,"page-height"),r))),n=this.boxSpecificEnabled(n),e.enabled=new D(n)}boxSpecificEnabled(t){return t}initHorizontal(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=oe(t,e.left,n),i=oe(t,e["margin-left"],n),r=dn(t,e["border-left-width"],e["border-left-style"],n),a=Ct(t,e["padding-left"],n),l=oe(t,e.width,n),c=oe(t,e["max-width"],n),u=Ct(t,e["padding-right"],n),d=dn(t,e["border-right-width"],e["border-right-style"],n),h=oe(t,e["margin-right"],n),f=oe(t,e.right,n),g=$(t,r,a),m=$(t,r,u);if(s&&f&&l){let C=ee(t,n,$(t,l,$(t,$(t,s,g),m)));i?h?f=ee(t,C,h):h=ee(t,C,$(t,f,i)):(C=ee(t,C,f),h?i=ee(t,C,h):(i=Ri(t,C,new he(t,.5)),h=i))}else{i||(i=t.zero),h||(h=t.zero),!s&&!f&&!l&&(s=t.zero),!s&&!l?(l=this.autoWidth,this.isAutoWidth=!0):!s&&!f?s=t.zero:!l&&!f&&(l=this.autoWidth,this.isAutoWidth=!0);let C=ee(t,n,$(t,$(t,i,g),$(t,h,m)));this.isAutoWidth&&(c||(c=ee(t,C,s||f)),!this.vertical&&(oe(t,e["column-width"],null)||oe(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=ee(t,C,$(t,s,l))):l=ee(t,C,$(t,s,f)):s=ee(t,C,$(t,f,l))}let y=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),S=Ct(t,y,n);e.left=new D(s),e["margin-left"]=new D(i),e["border-left-width"]=new D(r),e["padding-left"]=new D(a),e.width=new D(l),e["max-width"]=new D(c||l),e["padding-right"]=new D(u),e["border-right-width"]=new D(d),e["margin-right"]=new D(h),e.right=new D(f),e["snap-width"]=new D(S)}initVertical(){let t=this.pageBox.scope,e=this.style,n=this.parentInstance?this.parentInstance.style.width.toExpr(t,null):null,s=this.parentInstance?this.parentInstance.style.height.toExpr(t,null):null,i=oe(t,e.top,s),r=oe(t,e["margin-top"],n),a=dn(t,e["border-top-width"],e["border-top-style"],n),l=Ct(t,e["padding-top"],n),c=oe(t,e.height,s),u=oe(t,e["max-height"],s),d=Ct(t,e["padding-bottom"],n),h=dn(t,e["border-bottom-width"],e["border-bottom-style"],n),f=oe(t,e["margin-bottom"],n),g=oe(t,e.bottom,s),m=$(t,a,l),y=$(t,h,d);if(i&&g&&c){let x=ee(t,s,$(t,c,$(t,$(t,i,m),y)));r?f?g=ee(t,x,r):f=ee(t,x,$(t,g,r)):(x=ee(t,x,g),f?r=ee(t,x,f):(r=Ri(t,x,new he(t,.5)),f=r))}else{r||(r=t.zero),f||(f=t.zero),!i&&!g&&!c&&(i=t.zero),!i&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!i&&!g?i=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let x=ee(t,s,$(t,$(t,r,m),$(t,f,y)));this.isAutoHeight&&(u||(u=ee(t,x,i||g)),this.vertical&&(oe(t,e["column-width"],null)||oe(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),i?c?g||(g=ee(t,x,$(t,i,c))):c=ee(t,x,$(t,g,i)):i=ee(t,x,$(t,g,c))}let S=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=Ct(t,S,n);e.top=new D(i),e["margin-top"]=new D(r),e["border-top-width"]=new D(a),e["padding-top"]=new D(l),e.height=new D(c),e["max-height"]=new D(u||c),e["padding-bottom"]=new D(d),e["border-bottom-width"]=new D(h),e["margin-bottom"]=new D(f),e.bottom=new D(g),e["snap-height"]=new D(C)}initColumns(){let t=this.pageBox.scope,e=this.style,n=oe(t,e[this.vertical?"height":"width"],null),s=oe(t,e["column-width"],n),i=oe(t,e["column-count"],null),r=Ix(t,e["column-gap"],null);r||(r=new tn(t,1,"em")),s&&!i&&(i=new Fn(t,"floor",[Rr(t,$(t,n,r),$(t,s,r))]),i=new Fn(t,"max",[t.one,i])),i||(i=t.one),s=ee(t,Rr(t,$(t,n,r),i),r),e["column-width"]=new D(s),e["column-count"]=new D(i),e["column-gap"]=new D(r)}depends(t,e,n){return this.style[t].toExpr(this.pageBox.scope,null).depend(e,n)}init(t){var l;t.registerInstance(this.pageBox.key,this);let n=this.pageBox.scope,s=this.style,i=this.parentInstance?this.parentInstance.getActiveRegions(t):null,r=Al(this.cascaded,t,i,!1,null);this.vertical=Pl(r,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=kl(r,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((l=r["box-sizing"])==null?void 0:l.value)===b.border_box;let a=!!(t instanceof Fs&&t.currentLayoutPosition&&new re(n,"left-page").evaluate(t));Ll(r,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new ne(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new ne(n,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(t,e){var s,i;let n=this.style[e];return!n&&As(e)&&this.pageMasterInstance instanceof Rn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new P(t.rootFontSize,"px"):n=(i=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:i.value),n&&(n=ao(t,n,e)),n}getPropAsNumber(t,e){var s,i;let n=this.style[e];if(n){let r=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(i=t.pageAreaWidth)!=null?i:t.pageWidth();n=ao(t,n,e,r)}return Me(n,t)}getSpecial(t,e){let n=Sp(this.cascaded,e);if(n){let s=[];for(let i=0;i<n.length;i++){let r=n[i].evaluate(t,"");r&&r!==H&&s.push(r)}if(s.length)return s}return null}getActiveRegions(t){let e=this.getSpecial(t,"region-id");if(e){let n=[];for(let s=0;s<e.length;s++)n[s]=e[s].toString();return n}return null}propagateProperty(t,e,n,s){this.propagatePropertyToElement(t,e.element,n,s)}propagatePropertyToElement(t,e,n,s){let i=this.getProp(t,n);i&&(i.isNumeric()&&wa(i.unit)&&(i=Aa(i,t)),n==="font-family"&&(i=s.filterFontFamily(i)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),w(e,n,i.toString()))}propagateDelayedProperty(t,e,n,s){let i=this.getProp(t,n);i&&s.push(new Cs(e.element,n,i))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),i=this.getPropAsNumber(t,"padding-left"),r=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),w(e.element,"margin-left",`${s}px`),w(e.element,"padding-left",`${i}px`),w(e.element,"border-left-width",`${r}px`),e.marginLeft=s,e.borderLeft=r,e.paddingLeft=i}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),i=this.getPropAsNumber(t,"margin-right"),r=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(w(e.element,"margin-right",`${i}px`),w(e.element,"padding-right",`${r}px`),w(e.element,"border-right-width",`${a}px`),e.marginRight=i,e.borderRight=a,this.vertical&&s>0){let l=n+e.getInsetRight(),c=l-Math.floor(l/s)*s;c>0&&(e.snapOffsetX=s-c,r+=e.snapOffsetX)}e.paddingRight=r,e.snapWidth=s}assignTopPosition(t,e){let n=this.getPropAsNumber(t,"snap-height"),s=this.getPropAsNumber(t,"top"),i=this.getPropAsNumber(t,"margin-top"),r=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=i,e.borderTop=a,e.snapHeight=n,!this.vertical&&n>0){let l=s+e.getInsetTop(),c=l-Math.floor(l/n)*n;c>0&&(e.snapOffsetY=n-c,r+=e.snapOffsetY)}e.paddingTop=r,w(e.element,"top",`${s}px`),w(e.element,"margin-top",`${i}px`),w(e.element,"padding-top",`${r}px`),w(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),i=this.getPropAsNumber(t,"border-bottom-width"),r=this.getPropAsNumber(t,"height")-e.snapOffsetY;w(e.element,"height",`${r}px`),w(e.element,"margin-bottom",`${n}px`),w(e.element,"padding-bottom",`${s}px`),w(e.element,"border-bottom-width",`${i}px`),e.height=r-e.snapOffsetY,e.marginBottom=n,e.borderBottom=i,e.paddingBottom=s}assignBeforePosition(t,e){this.vertical?this.assignRightPosition(t,e):this.assignTopPosition(t,e)}assignAfterPosition(t,e){this.vertical?this.assignLeftPosition(t,e):this.assignBottomPosition(t,e)}assignStartEndPosition(t,e){this.vertical?(this.assignTopPosition(t,e),this.assignBottomPosition(t,e)):(this.assignRightPosition(t,e),this.assignLeftPosition(t,e))}sizeWithMaxHeight(t,e){w(e.element,"border-top-width","0px");let n=this.getPropAsNumber(t,"max-height");this.isTopDependentOnAutoHeight?e.setVerticalPosition(0,n):(this.assignTopPosition(t,e),n-=e.snapOffsetY,e.height=n,w(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){w(e.element,"border-left-width","0px");let n=this.getPropAsNumber(t,"max-width");if(this.isRightDependentOnAutoWidth)e.setHorizontalPosition(0,n);else{this.assignRightPosition(t,e),n-=e.snapOffsetX,e.width=n;let s=this.getPropAsNumber(t,"right");w(e.element,"right",`${s}px`),w(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,i){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&w(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&w(e.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(t,e):this.sizeWithMaxHeight(t,e):(this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(t,e):this.sizeWithMaxWidth(t,e):this.assignStartEndPosition(t,e);for(let r=0;r<uC.length;r++)this.propagateProperty(t,e,uC[r],s)}transferContentProps(t,e,n,s){for(let i=0;i<pC.length;i++)this.propagateProperty(t,e,pC[i],s);if(this.style["text-overflow"]){let i=e.element.firstElementChild;w(i,"text-overflow","inherit"),w(i,"overflow","inherit")}}transferSingleUriContentProps(t,e,n){let s=()=>{var a,l;let r=(l=(a=this.cascaded.width)!=null?a:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:l.value;return!!r&&r!==b.auto&&!X(r)},i=()=>{var a,l;let r=(l=(a=this.cascaded.height)!=null?a:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:l.value;return!!r&&r!==b.auto&&!X(r)};for(let r=0;r<hC.length;r++){let a=hC[r];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!i())continue;w(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,i,r,a){this.vertical?this.calculatedWidth=e.computedBlockSize+e.snapOffsetX:this.calculatedHeight=e.computedBlockSize+e.snapOffsetY;let l=(this.vertical||!s)&&this.isAutoHeight,c=(!this.vertical||!s)&&this.isAutoWidth,u=null;if(c||l){c&&w(e.element,"width","auto"),l&&w(e.element,"height","auto");let d=s&&Ed(s);d&&qr(s),u=r.getElementClientRect(s?s.element:e.element),d&&Kr(s),c&&(this.calculatedWidth=Math.ceil(u.right-u.left-e.paddingLeft-e.borderLeft-e.paddingRight-e.borderRight),this.vertical&&(this.calculatedWidth+=e.snapOffsetX)),l&&(this.calculatedHeight=u.bottom-u.top-e.paddingTop-e.borderTop-e.paddingBottom-e.borderBottom,this.vertical||(this.calculatedHeight+=e.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(t,e),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(t,e),this.assignAfterPosition(t,e)),i>1){let d=this.getPropAsNumber(t,"column-rule-width"),h=this.getProp(t,"column-rule-style"),f=this.getProp(t,"column-rule-color");if(d>0&&h&&h!=b.none&&f!=b.transparent){let g=this.getPropAsNumber(t,"column-gap"),m=this.vertical?e.height:e.width,y=this.vertical?"border-top":"border-left";for(let S=1;S<i;S++){let C=this.vertical?(m+g)*S/i-g/2+e.paddingTop-d/2:(m+g)*S/i-g/2+e.paddingLeft-d/2,x=this.vertical?e.width+e.paddingLeft+e.paddingRight:e.height+e.paddingTop+e.paddingBottom,v=e.element.ownerDocument.createElement("div");w(v,"position","absolute"),w(v,this.vertical?"left":"top","0px"),w(v,this.vertical?"top":"left",`${C}px`),w(v,this.vertical?"height":"width","0px"),w(v,this.vertical?"width":"height",`${x}px`),w(v,y,`${d}px ${h.toString()}${f?` ${f.toString()}`:""}`),e.element.insertBefore(v,e.element.firstChild)}}}for(let d=0;d<dC.length;d++)this.propagateProperty(t,e,dC[d],a);for(let d=0;d<fC.length;d++)this.propagateDelayedProperty(t,e,fC[d],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let r in s)this instanceof Rn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||ws(r)&&Xn(n,r,de(s,r));if(this.pageBox.pseudoName==_o)for(let r in e)(r.match(/^background-/)||r=="writing-mode")&&(n[r]=e[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in e)!r.match(/^background-/)&&r!="writing-mode"&&(n[r]=e[r]);t.pushRule(this.pageBox.classes,null,n);let i=n.content;i&&(n.content=i.filterValue(new rr(t,null,t.counterResolver))),this.init(t.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(t,e);t.popRule()}resolveAutoSizing(t){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,t)||this.depends("margin-right",this.autoWidth,t)||this.depends("border-right-width",this.autoWidth,t)||this.depends("padding-right",this.autoWidth,t)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,t)||this.depends("margin-top",this.autoHeight,t)||this.depends("border-top-width",this.autoHeight,t)||this.depends("padding-top",this.autoHeight,t));for(let e of this.children)e.resolveAutoSizing(t)}},uC=["border-left-style","border-right-style","border-top-style","border-bottom-style","border-left-color","border-right-color","border-top-color","border-bottom-color","box-sizing","outline-style","outline-color","outline-width","overflow","visibility"],dC=["border-top-left-radius","border-top-right-radius","border-bottom-right-radius","border-bottom-left-radius","border-start-start-radius","border-start-end-radius","border-end-start-radius","border-end-end-radius","border-image-source","border-image-slice","border-image-width","border-image-outset","border-image-repeat","background-attachment","background-color","background-image","background-repeat","background-position","background-clip","background-origin","background-size","box-shadow","opacity","z-index","background-blend-mode","isolation","mix-blend-mode","filter"],pC=["color","font-family","font-size","font-style","font-weight","line-height","letter-spacing","text-align","text-align-last","text-decoration","text-indent","text-transform","white-space","text-wrap","text-wrap-mode","text-wrap-style","word-spacing","font-feature-settings","font-kerning","font-size-adjust","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian","font-stretch","text-combine-upright","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-fill-color","text-orientation","text-shadow","text-stroke-color","text-stroke-width","text-underline-offset","text-underline-position","text-overflow"],hC=["width","height","image-resolution","object-fit","object-position"],fC=["transform","transform-origin"],_o="background-host",Cc=class extends gr{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,i)=>i.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-i.pageBox.index)}},yi=class extends gr{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=ut(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},Bh=class extends gr{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},Ln=class extends gr{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,n){let s=null;if(e instanceof Y&&(s=[e]),e instanceof me&&(s=e.values),s){let i=this.pageBox.scope;for(let r=0;r<s.length;r++)if(s[r]instanceof Y){let a=Lr(s[r].name,"enabled"),l=new re(i,a);n&&(l=new Ft(i,l)),t=ut(i,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=gC(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let i=Rx(e,n["flow-from"],"body"),r=new Fn(e,"has-content",[i]);t=ut(e,t,r)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let i=this.pageMasterInstance.style.enabled,r=i?i.toExpr(e,null):e._true;r=ut(e,r,t),this.pageMasterInstance.style.enabled=new D(r)}return t}prepareContainer(t,e,n,s,i){var r;this.pageBox.pageMaster instanceof Uo||(w(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(t,e,n,s,i)}},Mo=class extends Sn{constructor(e,n,s,i){super(e,n,!1);this.target=s;this.validatorSet=i}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}simpleProperty(e,n,s){this.target.specified[e]=new I(n,s?Ha:za)}},bc=class extends Mo{constructor(t,e,n,s){super(t,e,n,s)}},Oh=class o extends Mo{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new I(gu,0),n.specified.height=new I(gu,0)}startPartitionRule(t,e,n){let s=new Vs(this.scope,t,e,n,this.target),i=new bc(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}startPartitionGroupRule(t,e,n){let s=new mc(this.scope,t,e,n,this.target),i=new o(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}},yc=class extends Mo{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new Vs(this.scope,t,e,n,this.target),i=new bc(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}startPartitionGroupRule(t,e,n){let s=new mc(this.scope,t,e,n,this.target),i=new Oh(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(i)}};function nf(o){var n,s;let t=(n=o["writing-mode"])==null?void 0:n.value,e=(s=o.direction)==null?void 0:s.value;return t===b.vertical_lr||t!==b.vertical_rl&&e!==b.rtl?"ltr":"rtl"}var Vx={a10:{width:new P(26,"mm"),height:new P(37,"mm")},a9:{width:new P(37,"mm"),height:new P(52,"mm")},a8:{width:new P(52,"mm"),height:new P(74,"mm")},a7:{width:new P(74,"mm"),height:new P(105,"mm")},a6:{width:new P(105,"mm"),height:new P(148,"mm")},a5:{width:new P(148,"mm"),height:new P(210,"mm")},a4:{width:new P(210,"mm"),height:new P(297,"mm")},a3:{width:new P(297,"mm"),height:new P(420,"mm")},a2:{width:new P(420,"mm"),height:new P(594,"mm")},a1:{width:new P(594,"mm"),height:new P(841,"mm")},a0:{width:new P(841,"mm"),height:new P(1189,"mm")},b10:{width:new P(31,"mm"),height:new P(44,"mm")},b9:{width:new P(44,"mm"),height:new P(62,"mm")},b8:{width:new P(62,"mm"),height:new P(88,"mm")},b7:{width:new P(88,"mm"),height:new P(125,"mm")},b6:{width:new P(125,"mm"),height:new P(176,"mm")},b5:{width:new P(176,"mm"),height:new P(250,"mm")},b4:{width:new P(250,"mm"),height:new P(353,"mm")},b3:{width:new P(353,"mm"),height:new P(500,"mm")},b2:{width:new P(500,"mm"),height:new P(707,"mm")},b1:{width:new P(707,"mm"),height:new P(1e3,"mm")},b0:{width:new P(1e3,"mm"),height:new P(1414,"mm")},c10:{width:new P(28,"mm"),height:new P(40,"mm")},c9:{width:new P(40,"mm"),height:new P(57,"mm")},c8:{width:new P(57,"mm"),height:new P(81,"mm")},c7:{width:new P(81,"mm"),height:new P(114,"mm")},c6:{width:new P(114,"mm"),height:new P(162,"mm")},c5:{width:new P(162,"mm"),height:new P(229,"mm")},c4:{width:new P(229,"mm"),height:new P(324,"mm")},c3:{width:new P(324,"mm"),height:new P(458,"mm")},c2:{width:new P(458,"mm"),height:new P(648,"mm")},c1:{width:new P(648,"mm"),height:new P(917,"mm")},c0:{width:new P(917,"mm"),height:new P(1297,"mm")},"jis-b10":{width:new P(32,"mm"),height:new P(45,"mm")},"jis-b9":{width:new P(45,"mm"),height:new P(64,"mm")},"jis-b8":{width:new P(64,"mm"),height:new P(91,"mm")},"jis-b7":{width:new P(91,"mm"),height:new P(128,"mm")},"jis-b6":{width:new P(128,"mm"),height:new P(182,"mm")},"jis-b5":{width:new P(182,"mm"),height:new P(257,"mm")},"jis-b4":{width:new P(257,"mm"),height:new P(364,"mm")},"jis-b3":{width:new P(364,"mm"),height:new P(515,"mm")},"jis-b2":{width:new P(515,"mm"),height:new P(728,"mm")},"jis-b1":{width:new P(728,"mm"),height:new P(1030,"mm")},"jis-b0":{width:new P(1030,"mm"),height:new P(1456,"mm")},letter:{width:new P(8.5,"in"),height:new P(11,"in")},legal:{width:new P(8.5,"in"),height:new P(14,"in")},ledger:{width:new P(11,"in"),height:new P(17,"in")}},Fx=new P(.24,"pt"),WE=new P(3,"mm"),Bx=new P(10,"mm"),Ox=new P(13,"mm");function $o(o){let t={width:rs,height:os,bleed:le,bleedOffset:le,cropOffset:le},e=o.size;if(!(!e||e.value===b.auto)){let c=e.value,u,d;if(c.isSpaceList()?(u=c.values[0],d=c.values[1]):(u=c,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let h=u.name&&Vx[u.name.toLowerCase()];h&&(d&&d===b.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=o.marks,s=o.bleed,i=n&&!X(n.value)?n.value:b.none,r=s&&!X(s.value)?s.value:b.auto;if(r===b.auto){if(i!==b.none){let c=!1;i.isSpaceList()?c=i.values.some(u=>u===b.crop):c=i===b.crop,c&&(t.bleed=new P(6,"pt"))}}else r.isNumeric()&&(t.bleed=r);let a=o["crop-offset"],l=a&&!X(a.value)?a.value:b.auto;return l===b.auto?i!==b.none&&(t.bleedOffset=Ox):l.isNumeric()&&(t.cropOffset=l),t}function sf(o,t){let e={},n=Math.max(0,o.bleed.num)*t.queryUnitSize(o.bleed.unit,!1),s=!o.cropOffset.num&&o.bleedOffset.num?o.bleedOffset.num*t.queryUnitSize(o.bleedOffset.unit,!1):Math.max(0,o.cropOffset.num*t.queryUnitSize(o.cropOffset.unit,!1)-n),i=n+s,r=o.width;r===rs?t.pref.defaultPaperSize?e.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):e.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-i*2:e.pageWidth=r.num*t.queryUnitSize(r.unit,!1);let a=o.height;return a===os?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-i*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=i,e}function CC(o,t,e){let n=o.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function Ho(o,t,e,n){n=n||"polyline";let s=o.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===b.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var Mh=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(Mh||{});function Dx(o,t,e,n,s,i,r){let a=s;a<=i+2*Je.mm&&(a=i+s/2);let l=Math.max(s,a),c=i+l+e/2,u=CC(o,c,c),d=[[0,i+s],[s,i+s],[s,i+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[i+l-m[0],m[1]]),h=h.map(m=>[i+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],i+l-m[1]]),h=h.map(m=>[m[0],i+l-m[1]]));let f=Ho(o,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=Ho(o,e,n);return g.setAttribute("points",h.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${r}px`}),u}var zo=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(zo||{});function Mx(o,t,e,n,s,i){let r=s*2,a,l;t==="top"||t==="bottom"?(a=r,l=s):(a=s,l=r);let c=CC(o,a,l),u=Ho(o,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=Ho(o,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=Ho(o,e,n,"circle");h.setAttribute("cx",a/2),h.setAttribute("cy",l/2),h.setAttribute("r",s/4),c.appendChild(h);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(zo).forEach(g=>{let m=zo[g];m===t?c.style[m]=`${i}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function bC(o,t,e,n){let s=!1,i=!1,r=o.marks;if(r){let m=r.value;m instanceof G?m.values.forEach(y=>{y===b.crop?s=!0:y===b.cross&&(i=!0)}):m===b.crop?s=!0:m===b.cross&&(i=!0)}let a=t.bleed;if(!s&&!i)return;let l=e.container,c=l.ownerDocument;let u=Me(Fx,n),d=Math.max(0,t.bleedOffset-Me(Bx,n)),h=t.bleedOffset-d,f=o["crop-marks-line-color"],g=f&&!X(f.value)?f.value:b.auto;s&&Object.keys(Mh).forEach(m=>{let y=Mh[m],S=Dx(c,y,u,g,h,a,d);l.appendChild(S)}),i&&Object.keys(zo).forEach(m=>{let y=zo[m],S=Mx(c,y,u,g,h,d);l.appendChild(S)})}var _h=(()=>{let o=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return o.forEach(e=>{t[`margin-${e}`]=!0,t[`padding-${e}`]=!0,t[`border-${e}-width`]=!0,t[`border-${e}-style`]=!0,t[`border-${e}-color`]=!0}),t})();var rf={"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"}},_x=(()=>{let o=rf;return Object.keys(o).sort((t,e)=>o[t].order-o[e].order)})(),vc="vivliostyle-page-rule-master",Go="_marginBoxes",Uo=class extends fr{constructor(e,n,s){super(e,null,vc,[],n,null,0);p(this,"pageMarginBoxes",{});let i=$o(s),r=new Uh(this.scope,this,s,i);this.createPageMarginBoxes(s),this.applySpecified(s,i)}createPageMarginBoxes(e){let n=e[Go];n&&_x.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new zh(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new I(b.relative,0),this.specified.width=new I(n.width,0),this.specified.height=new I(n.height,0);for(let s in e)!_h[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new Rn(e,this)}},Uh=class extends Vs{constructor(e,n,s,i){super(e,null,null,[],n);this.pageSize=i;let r=new Hh(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new I(b.auto,0),this.specified["z-index"]=new I(new se(0),0),this.specified.position=new I(b.absolute,0),this.specified.overflow=new I(b.visible,0);for(let n in _h)_h.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new Wh(e,this)}},Hh=class extends Vs{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new I(k("body"),0)}createInstance(t){return new Wo(t,this)}},zh=class extends Vs{constructor(e,n,s,i){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(i)}applySpecified(e){let n=e[Go][this.marginBoxName];for(let s in e){let i=e[s],r=n[s];(bp[s]||r&&r.value===b.inherit)&&(this.specified[s]=i)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let i=n[s];i&&i.value!==H&&i.value!==b.inherit&&i.value!==b.unset&&i.value!==b.revert&&(this.specified[s]=i)}}createInstance(e){return new Xo(e,this)}},Rn=class extends yi{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let i in n)if(Object.prototype.hasOwnProperty.call(n,i))switch(i){case"writing-mode":case"direction":s[i]=n[i]}super.applyCascadeAndInit(e,n)}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 n=this.style;n.width=new D(e.borderBoxWidth),n.height=new D(e.borderBoxHeight),n["padding-left"]=new D(e.marginLeft),n["padding-right"]=new D(e.marginRight),n["padding-top"]=new D(e.marginTop),n["padding-bottom"]=new D(e.marginBottom)}adjustPageLayout(e,n,s){let i=n.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},a={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(i.top,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(i.bottom,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(i.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(i.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,i,r){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let E in e){let N=rf[E];if(N){let L=e[E],O=this.pageMarginBoxInstances[E],z=new mr(L,O.style,n,u,r);d[N.positionAlongVariableDimension]=L,h[N.positionAlongVariableDimension]=O,f[N.positionAlongVariableDimension]=z}}let g={start:s.start.evaluate(i),end:s.end.evaluate(i),extent:s.extent.evaluate(i)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),y=!1,S={};Object.keys(d).forEach(E=>{let N=E,L=oe(u,h[N].style[n?"max-width":"max-height"],s.extent);if(L){let O=L.evaluate(i);if(m[N]>O){let z=f[N]=new xc(d[N],h[N].style,n,u,r,O);S[N]=z.getOuterSize(),y=!0}}}),y&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),y=!1,[a,l,c].forEach(E=>{var N;m[E]=(N=S[E])!=null?N:m[E]}));let C={};Object.keys(d).forEach(E=>{let N=E,L=oe(u,h[N].style[n?"min-width":"min-height"],s.extent);if(L){let O=L.evaluate(i);if(m[N]<O){let z=f[N]=new xc(d[N],h[N].style,n,u,r,O);C[N]=z.getOuterSize(),y=!0}}}),y&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(E=>{m[E]=C[E]||m[E]}));let x=g.start+g.extent,v=g.start+(g.start+g.extent);[a,l,c].forEach(E=>{let N=m[E];if(N!=null){let L=d[E],O=0;switch(E){case a:O=n?L.left:L.top;break;case l:O=(v-N)/2;break;case c:O=x-N;break}n?L.setHorizontalPosition(O,N-L.getInsetLeft()-L.getInsetRight()):L.setVerticalPosition(O,N-L.getInsetTop()-L.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,i=e.center,r=e.end,a={};if(i){let c=[s,r],u=new Gh(c),d=this.distributeAutoMarginBoxSizes(i,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:i.getOuterSize(),f=Math.max((n-h)/2,0);s&&(a.start=s.hasAutoSize()?f:s.getOuterSize()),r&&(a.end=r.hasAutoSize()?f:r.getOuterSize())}else{let c=this.distributeAutoMarginBoxSizes(s,r,n);c.xSize!=null&&(a.start=c.xSize),c.ySize!=null&&(a.end=c.ySize)}return a}distributeAutoMarginBoxSizes(e,n,s){let i={xSize:null,ySize:null};if(e instanceof mr&&e.minMaxFitContent&&(i.xSize=e.getOuterSize()),n instanceof mr&&n.minMaxFitContent&&(i.ySize=n.getOuterSize()),e&&n)if(e.hasAutoSize()&&n.hasAutoSize()){let r=e.getOuterMaxContentSize(),a=n.getOuterMaxContentSize();if(r>0&&a>0){let l=r+a;if(l<s)i.xSize=s*r/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?i.xSize=c+(s-d)*(r-c)/(l-d):d>0&&(i.xSize=s*c/d)}i.xSize>0&&(i.ySize=s-i.xSize)}else r>0?i.xSize=s:a>0&&(i.ySize=s)}else e.hasAutoSize()?i.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(i.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(i.xSize=s):n&&n.hasAutoSize()&&(i.ySize=s);return i}prepareContainer(e,n,s,i,r){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,i,r)}},mr=class{constructor(t,e,n,s,i){this.container=t;this.isHorizontal=n;this.clientLayout=i;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let r=e[n?"width":"height"];if(this.hasAutoSize_=!r||r===b.auto||X(r),this.minMaxFitContent=r instanceof Y&&(r.name==="min-content"||r.name==="max-content"||r.name==="fit-content")?r.name:null,this.minMaxFitContent){let a=this.getSize();if(this.isHorizontal){let l=a[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,l)}else{let l=a[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,l)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let t=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=Yi(this.clientLayout,this.container.element,t)}return this.size}getOuterMaxContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let t=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+t["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+t["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},Gh=class{constructor(t){this.params=t}hasAutoSize(){return this.params.some(t=>{var e;return(e=t==null?void 0:t.hasAutoSize())!=null?e:!1})}getOuterMaxContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMaxContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterMinContentSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterMinContentSize())!=null?n:0});return Math.max.apply(null,t)*t.length}getOuterSize(){let t=this.params.map(e=>{var n;return(n=e==null?void 0:e.getOuterSize())!=null?n:0});return Math.max.apply(null,t)*t.length}},xc=class extends mr{constructor(e,n,s,i,r,a){super(e,n,s,i,r);p(this,"fixedSize");this.fixedSize=a}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()}},Wh=class extends Ln{constructor(e,n){super(e,n);p(this,"borderBoxWidth",null);p(this,"borderBoxHeight",null);p(this,"contentBoxWidth",null);p(this,"contentBoxHeight",null);p(this,"marginTop",null);p(this,"marginRight",null);p(this,"marginBottom",null);p(this,"marginLeft",null)}applyCascadeAndInit(e,n){for(let i in n)i.match(/^background-/)&&(this.cascaded[i]=n[i]);super.applyCascadeAndInit(e,n),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let n=this.style,s=this.pageBox.pageSize,i=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=s[l].toExpr(i,null),u=oe(i,n[l],c),d=oe(i,n[`margin-${r}`],c),h=oe(i,n[`margin-${a}`],c),f=Ct(i,n[`padding-${r}`],c),g=Ct(i,n[`padding-${a}`],c),m=dn(i,n[`border-${r}-width`],n[`border-${r}-style`],c),y=dn(i,n[`border-${a}-width`],n[`border-${a}-style`],c),S=$(i,$(i,m,f),$(i,y,g)),C,x,v;return u?(this.borderBoxSizing?(x=u,v=ee(i,x,S)):(v=u,x=$(i,v,S)),C=ee(i,c,x),!d&&!h?(d=Ri(i,C,new he(i,.5)),h=d):d?h=ee(i,C,d):d=ee(i,C,h)):(d||(d=i.zero),h||(h=i.zero),C=$(i,d,h),x=ee(i,c,C),v=ee(i,x,S),u=this.borderBoxSizing?x:v),n[r]=new D(d),n[a]=new D(h),n[`margin-${r}`]=le,n[`margin-${a}`]=le,n[`border-${r}-width`]=new D(m),n[`border-${a}-width`]=new D(y),n[`padding-${r}`]=new D(f),n[`padding-${a}`]=new D(g),n[l]=new D(u),n[`max-${l}`]=new D(u),{borderBoxExtent:x,contentBoxExtent:v,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,i,r){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,i,r)}},Wo=class extends Ln{constructor(t,e){super(t,e)}applyCascadeAndInit(t,e){for(let n in e)n.match(/^column.*$/)&&(this.cascaded[n]=e[n]);super.applyCascadeAndInit(t,{})}initHorizontal(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.left=e["padding-left"],t.width=new D(this.parentInstance.contentBoxWidth),t["margin-left"]=new D(new mn(n,e.left.toExpr(n,null))),t["margin-right"]=new D(new mn(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=b.solid,t["border-right-style"]=b.solid,t["border-left-color"]=b.transparent,t["border-right-color"]=b.transparent}initVertical(){let t=this.style,e=this.parentInstance.style,n=this.pageBox.scope;t.top=e["padding-top"],t.height=new D(this.parentInstance.contentBoxHeight),t["margin-top"]=new D(new mn(n,e.top.toExpr(n,null))),t["margin-bottom"]=new D(new mn(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=b.solid,t["border-bottom-style"]=b.solid,t["border-top-color"]=b.transparent,t["border-bottom-color"]=b.transparent}prepareContainer(t,e,n,s,i){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,i),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},Xo=class extends Ln{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=rf[s];let i=e;i.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,i,r){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,i,r)}applyVerticalAlign(e,n){w(n,"display","flex"),w(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),i=null;s===k("middle")?i="center":s===k("top")?i="flex-start":s===k("bottom")&&(i="flex-end"),i&&w(n,"justify-content",i);let r=this.getProp(e,"content");if(this.vertical||r instanceof ge||r instanceof D&&r.expr instanceof ne&&r.expr.str.startsWith("running-element-")){let a="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?a=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(a=this.vertical||this.rtl?"end":"start")),w(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,i=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=r==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=oe(i,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[r]=new D(h);else if(d){let f=Ct(i,s[`margin-${r}`],u),g=Ct(i,s[`margin-${a}`],u),m=Ct(i,s[`padding-${r}`],u),y=Ct(i,s[`padding-${a}`],u),S=dn(i,s[`border-${r}-width`],s[`border-${r}-style`],u),C=dn(i,s[`border-${a}-width`],s[`border-${a}-style`],u),x=$(i,d,$(i,this.borderBoxSizing?i.zero:$(i,$(i,m,y),$(i,S,C)),$(i,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[r]=new D($(i,h,Rr(i,ee(i,u,x),new he(i,2))));break;case"end":s[r]=new D(ee(i,$(i,h,u),x));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,i=this.pageBox.scope,r=this.borderBoxSizing,a=e.inside,l=e.outside,c=e.extent,u=n[`margin${l.charAt(0).toUpperCase()}${l.substring(1)}`],d=Dh(i,s[`margin-${a}`],u),h=Dh(i,s[`margin-${l}`],u),f=Ct(i,s[`padding-${a}`],u),g=Ct(i,s[`padding-${l}`],u),m=dn(i,s[`border-${a}-width`],s[`border-${a}-style`],u),y=dn(i,s[`border-${l}-width`],s[`border-${l}-style`],u),S=oe(i,s[c],u),C=null;function x(v){if(C)return C;C={extent:S?S.evaluate(v):null,marginInside:d?d.evaluate(v):null,marginOutside:h?h.evaluate(v):null};let E=u.evaluate(v),N=0;return r||[m,f,g,y].forEach(L=>{L&&(N+=L.evaluate(v))}),(C.marginInside===null||C.marginOutside===null)&&N+C.extent+C.marginInside+C.marginOutside>E&&(C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)),C.extent!==null&&C.marginInside!==null&&C.marginOutside!==null&&(C.marginOutside=null),C.extent===null?(C.extent=E-N-C.marginInside-C.marginOutside,C.marginInside===null&&(C.marginInside=0),C.marginOutside===null&&(C.marginOutside=0)):typeof C.extent=="number"&&(C.marginInside===null&&typeof C.marginOutside=="number"?C.marginInside=E-N-C.extent-C.marginOutside:typeof C.marginInside=="number"&&C.marginOutside===null?C.marginOutside=E-N-C.extent-C.marginInside:C.marginInside=C.marginOutside=(E-N-C.extent)/2),C}s[c]=new D(new ne(i,function(){let v=x(this).extent;return v===null?"auto":v},c)),s[`margin-${a}`]=new D(new ne(i,function(){let v=x(this).marginInside;return v===null?"auto":v},`margin-${a}`)),s[`margin-${l}`]=new D(new ne(i,function(){let v=x(this).marginOutside;return v===null?"auto":v},`margin-${l}`)),a==="left"?s.left=new D($(i,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new D($(i,n.marginTop,n.borderBoxHeight)))}initHorizontal(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},n):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},n):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},n)}initVertical(){let n=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},n):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},n):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},n)}finishContainer(e,n,s,i,r,a,l){super.finishContainer(e,n,s,i,r,a,l);let c=s.marginBoxes,u=this.pageBox.marginBoxName,d=this.boxInfo;!d.isInLeftColumn&&!d.isInRightColumn?d.isInTopRow?c.top[u]=n:d.isInBottomRow&&(c.bottom[u]=n):!d.isInTopRow&&!d.isInBottomRow&&(d.isInLeftColumn?c.left[u]=n:d.isInRightColumn&&(c.right[u]=n));let h=this.parentInstance.pageAreaDimension,f=this.getProp(e,"width"),g=f instanceof Y&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),y=this.getPropAsNumber(e,"max-width");if(g||m||y){g&&w(n.element,"width",g),m&&w(n.element,"min-width",`${m}px`),y&&w(n.element,"max-width",`${y}px`);let E=this.getProp(e,"margin-left"),N=this.getProp(e,"margin-right");if(d.isInLeftColumn){let L=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);w(n.element,"right",`${L}px`),(E===b.auto||N!==b.auto)&&w(n.element,"margin-left","auto"),N===b.auto&&w(n.element,"margin-right","auto")}else d.isInRightColumn&&(w(n.element,"right","0"),(N===b.auto||E!==b.auto)&&w(n.element,"margin-right","auto"),E===b.auto&&w(n.element,"margin-left","auto"))}let S=this.getProp(e,"height"),C=S instanceof Y&&(S.name==="min-content"||S.name==="max-content"||S.name==="fit-content")?S.name:null,x=this.getPropAsNumber(e,"min-height"),v=this.getPropAsNumber(e,"max-height");if(C||x||v){C&&w(n.element,"height",C),x&&w(n.element,"min-height",`${x}px`),v&&w(n.element,"max-height",`${v}px`);let E=this.getProp(e,"margin-top"),N=this.getProp(e,"margin-bottom");if(d.isInTopRow){let L=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);w(n.element,"bottom",`${L}px`),(E===b.auto||N!==b.auto)&&w(n.element,"margin-top","auto"),N===b.auto&&w(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(w(n.element,"bottom","0"),(N===b.auto||E!==b.auto)&&w(n.element,"margin-bottom","auto"),E===b.auto&&w(n.element,"margin-top","auto"))}}},Sc=class{constructor(t,e,n,s,i){this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=i;p(this,"pageMasterCache",{});p(this,"pageCascadeInstance");this.pageCascadeInstance=t,this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new re(t,"page-number"),i=new is(t,new Ai(t,s,new he(t,2)),n?t.one:t.zero);t.defineName("recto-page",new Ft(t,i)),t.defineName("verso-page",i),(e.pageProgression||nf(this.docElementStyle))==="ltr"?(t.defineName("left-page",i),t.defineName("right-page",new Ft(t,i))):(t.defineName("left-page",new Ft(t,i)),t.defineName("right-page",i))}getCascadedPageStyle(t){let e={};return this.pageCascadeInstance.pushRule([],t,e),this.pageCascadeInstance.popRule(),e}getPageRulePageMaster(t,e){let n=t.pageBox;if(Object.keys(e).length===0)return n.resetScope(),t;let s=this.makeCacheKey(e,n),i=this.pageMasterCache[s];return i||(n.pseudoName===_o?i=this.generatePageRuleMaster(e):i=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=i),i.pageBox.resetScope(),i}makeCacheKey(t,e){var i;let n=this.makeCascadeValueObjectKey(t),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${e.key}^${n}^${s}`}makeCascadeValueObjectKey(t){let e=[];for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){let s=t[n],i;s instanceof I?i=`${s.value}`:i=this.makeCascadeValueObjectKey(s),e.push(n+i+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new Uo(this.pageScope,this.rootPageBoxInstance.pageBox,t).createInstance(this.rootPageBoxInstance);return n.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),n.resolveAutoSizing(this.context),n}generateCascadedPageMaster(t,e){let n=e.clone({pseudoName:vc}),s=n.specified,i=t.size;if(i&&!X(i.value)){let a=$o(t),l=i.priority;kn(s,"width",new I(a.width,l),this.context),kn(s,"height",new I(a.height,l),this.context)}["counter-reset","counter-increment"].forEach(a=>{s[a]&&(t[a]=s[a])});let r=n.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},Xh=class extends ie{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}},$h=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},jh=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Yh=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Kh=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},qh=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Zh=class extends ie{constructor(e){super();this.scope=e}apply(e){new re(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Qh=class extends An{constructor(e,n,s){super(n,s);this.scope=e;this.a=n;this.b=s}apply(e){let n=e.context,s=n.layoutPositionAtPageStart.page;n.blankPageAtStart&&s--,s&&this.matchANPlusB(s)&&this.chained.apply(e)}getPriority(){return 2}},Jh=class extends An{constructor(e,n,s,i){super(n,s);this.scope=e;this.a=n;this.b=s;this.pageType=i}apply(e){if(e.currentPageType!==this.pageType)return;let n=e.pageTypePageCounts[this.pageType]||0;this.matchANPlusB(n)&&this.chained.apply(e)}getPriority(){return 3}},ef=class extends ui{constructor(t,e){super(t,e,null,null,null)}apply(t){Ux(t.context,t.currentStyle,this.style,this.specificity,t)}};function Ux(o,t,e,n,s){oo(o,t,e,n,null,null,null);let i=e[Go];if(i){let r=di(t,Go);for(let a in i)if(i.hasOwnProperty(a)){let l=r[a];l||(l={},r[a]=l),oo(o,l,i[a],n,null,null,null)}}}var Ec=class extends jn{constructor(e,n,s,i,r){super(e,n,s==null?void 0:s.condition,s,null,i,!1);this.pageProps=r;p(this,"currentPageSelectors",[]);p(this,"currentNamedPageSelector","");p(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,n){this.currentNamedPageSelector=n,n&&(this.chain.push(new Xh(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let s=n[0],i=n[1];if(n.length===3&&typeof n[2]=="string"){let r=n[2];this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${i<0?i:"+"+i} of ${r})`),this.chain.push(new Jh(this.scope,s,i,r)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${i<0?i:"+"+i})`),this.chain.push(new Qh(this.scope,s,i)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${n.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new $h(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new jh(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Yh(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Kh(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new qh(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Zh(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,n,s){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(a=>a.selectors===null))return;super.simpleProperty(e,n,s);let i=de(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(a=>{Xn(r[a],e,i)});else if(e==="size"){let a=r[""];this.currentPageSelectors.forEach(l=>{let c=new I(i.value,i.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=r[u];d?kn(d,e,c):(d=r[u]={},Xn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&Xn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new ef(this.elementStyle,e)}startPageMarginBoxRule(e){let n=di(this.elementStyle,Go),s=n[e];s||(s={},n[e]=s);let i=new tf(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(i)}},tf=class extends Sn{constructor(e,n,s,i){super(e,n,!1);this.validatorSet=s;this.boxStyle=i}property(e,n,s){this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${n.toString()}`)}unknownProperty(e,n){this.report(`E_INVALID_PROPERTY ${e}: ${n.toString()}`)}simpleProperty(e,n,s){let i=s?this.getImportantSpecificity():this.getBaseSpecificity(),r=new I(n,i);Xn(this.boxStyle,e,r)}};var pn=!0;function xC(o){pn=o}var xi=[];function yC(o,t){return o===t||(o.src||t.src?o.src===t.src:o.textContent===t.textContent)}function SC(o){let t=Array.from(o.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(o.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function Nc(o,t,e){if(!pn)return T(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&SC(o.ownerDocument).includes(o))return T(!1);let n=o.textContent,s=o.src,i=o.type==="module",r=s&&s.includes("/MathJax.js");if(r){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return T(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(i||s)&&o.async&&!r,l=(i&&!a||s&&o.defer)&&!r,c=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||l||a);if(of(t)||(t.onload=null),c)return xi.some(d=>yC(d,o))||xi.push(o),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&yC(d,o)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,s&&(u.src=s),u.async=a,u.defer=l,u.setAttribute("data-vivliostyle-scripting","true");for(let d of o.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(F.debug("script:",s),s){let d=ps(u);return t.document.head.appendChild(u),ds([d])}else return t.document.head.appendChild(u),T(!0)}function zx(o,t){var i;let e={},n=r=>{var c;let a=(c=r["font-family"])==null?void 0:c.value;if(a)if(a.values)for(let u of a.values)e[u.stringValue()]=!0;else e[a.stringValue()]=!0;let l=r._marginBoxes;if(l)for(let u of Object.values(l))n(u)},s=r=>{if(r instanceof ui)n(r.style);else if(r instanceof $n||Array.isArray(r))for(let a of Object.values(r))s(a)};for(let r of Object.values(t.cascade.code))for(let a of Object.values(r!=null?r:{}))s(a);for(let r of o.querySelectorAll("[style]"))(i=r.style)!=null&&i.fontFamily&&(e[r.style.fontFamily]=!0);return Object.keys(e).join(",")}function Gx(o,t,e){var s;let n=(s=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?s:t.document.createElement("div");return n.style.position="fixed",n.style.fontSize="0",n.setAttribute("data-vivliostyle-textcontent","true"),n.setAttribute("aria-hidden","true"),n.style.fontFamily=zx(o,e),n.textContent=o.documentElement.textContent,t.document.body.appendChild(n),n}function EC(o,t,e){if(!pn)return T(!1);let n=SC(o);if(n.length===0)return T(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),i=s?Gx(o,t,e):null,r=t.document.fonts,a=t.$,l=!1,c=A("loadScripts");return c.loop(()=>{if(n.length===0)return s?c.sleep(20).thenAsync(()=>{var d,h;return r.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&((h=t.ret)!=null&&h.readyState)&&t.ret.readyState<4?T(!0):T(!1)}):T(!1);let u=n.shift();return Nc(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(xi.push(u),l=!0),n.length===0&&s&&(F.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{i&&i.remove(),c.finish(!0)}),c.result()}function vC(o){if(!pn)return T(!1);let t=A("loadScripts");return t.loop(()=>xi.length===0?T(!1):Nc(xi.shift(),o,{atEnd:!0}).thenReturn(xi.length>0)).then(()=>{F.debug("dispatchEvent: DOMContentLoaded (window)"),o.dispatchEvent(new Event("DOMContentLoaded")),F.debug("dispatchEvent: load (window)"),o.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function of(o){return pn?xi.length>0||!!o.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var NC=(o,t,e)=>o.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${e.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${e.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${e.transformURL(s,t)}`);var Xx={};function $x(o){o.addEventListener("load",()=>{o.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,e){switch(t){case"mouse-events":return!0}return!1}}},!1)}var jo=class jo extends ts{constructor(e,n,s,i,r,a,l,c,u,d,h,f,g){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=i;this.regionIds=r;this.xmldoc=a;this.docFaces=l;this.footnoteStyle=c;this.stylerProducer=u;this.page=d;this.customRenderer=h;this.fallbackMap=f;this.documentURLTransformer=g;p(this,"document");p(this,"exprContentListener");p(this,"nodeContext",null);p(this,"viewRoot",null);p(this,"isFootnote",!1);p(this,"sourceNode",null);p(this,"offsetInNode",0);p(this,"viewNode",null);this.document=s.document,this.exprContentListener=i.counterListener.getExprContentListener()}clone(){return new jo(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(e,n,s,i,r,a,l,c){var m;let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=lr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h;for(let y of Nm){let S;if(y){if(!u[y]||y=="footnote-marker"&&!(n&&this.isFootnote))continue;if(y.match(/^first-/)){let C=i.display;if(!C||C===b.inline)continue;let x=e.firstElementChild;if(x&&Ce(x.previousSibling)){let v=r.getStyle(x,!1);if(v){let E=de(v,"display");if(E!=null&&E.value&&E.value!==b.inline)continue}}}if(y==="before"||y==="after"||y==="marker"){let C=u[y].content;if(!C||!ht(C.value)||y==="marker"&&(!Un(i.display)||((m=de(s,"behavior"))==null?void 0:m.value)===k("toc-node")))continue}d.push(y),S=lr.createElementNS("http://www.w3.org/1999/xhtml","span"),co(S,y)}else S=lr.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(S),y.match(/^first-/)&&(f=S)}if(!d.length)return c;let g=new lo(e,s,r,a,this.exprContentListener);return new si(e,h,null,l,c,Mt.ROOTLESS,g)}getPseudoMap(e,n,s,i,r){let a=Pt(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};ar(u,a[c],r),El(u,r,a[c]),Tp(a[c],n,s,(d,h)=>{ar(u,h,r),Np(h,f=>{ar(u,f,r)})})}return l}createRefShadow(e,n,s,i,r){let a=A("createRefShadow");return this.xmldoc.store.load(e).then(l=>{let c=l;if(c){let u=c.getElement(e);if(u){let d=this.stylerProducer.getStylerForDoc(c);r=new si(s,u,c,i,r,n,d)}}a.finish(r)}),a.result()}createShadows(e,n,s,i,r,a,l){let c=A("createShadows"),u=null,d=i.template,h;if(d instanceof ge||d===b.footnote){let f=d instanceof ge?d.url:te("user-agent.xml#footnote",Jt);h=this.createRefShadow(f,Mt.ROOTLESS,e,l,u)}else h=T(u);return h.then(f=>{let g=null;if(e.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&e.localName=="include"){let y=e.getAttribute("href"),S=null;y?S=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?y=l.owner.getAttribute("href"):y=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),S=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),y&&(y=te(y,S.url),g=this.createRefShadow(y,Mt.ROOTED,e,l,f))}g==null&&(g=T(f));let m=null;g.then(y=>{if(i.display===b.table_cell){let S=te("user-agent.xml#table-cell",Jt);m=this.createRefShadow(S,Mt.ROOTLESS,e,l,y)}else m=T(y);m.then(S=>{S=this.createPseudoelementShadow(e,n,s,i,r,a,l,S),c.finish(S)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,i){var S;let r=this.context,a=Al(s,r,this.regionIds,this.isFootnote,this.nodeContext),l=!((S=this.nodeContext)!=null&&S.parent);l&&(!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 c=e;e=Pl(a,r,e);let u=!l&&e!==c;n=kl(a,r,n);let d=(C,x)=>{let v;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(v=r.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(v=r.pageAreaWidth));let E=x.evaluate(r,C,v,e);return C=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},h=!!new re(r.style.pageScope,"left-page").evaluate(r);if(Ll(a,i,e,n,h,d),u){let C=i[e?"height":"width"];(!C||C===b.auto)&&(i[e?"height":"width"]=b.max_content)}if(jr(i.position))return i.position=b.fixed,i.visibility=b.hidden,e;let f=i.position,g=i.float,m=i.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),y=xd(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(C=>{y[C]&&(i[C]=y[C])}),e}inheritFromSourceParent(e){let n=this.nodeContext.sourceNode,s=[],i=null,r=this.nodeContext.shadowContext,a=-1;for(;n&&n.nodeType==1;){let h=r&&r.root==n;if(!h||r.type==Mt.ROOTLESS){let g=(r?r.styler:this.styler).getStyle(n,!1);s.push(g),i=i||Er(n)}h?(n=r.owner,r=r.parentShadow):(n=n.parentNode,a++)}let l=a===0,c=this.context.queryUnitSize("em",l),u={"font-size":new I(new P(c,"px"),0)};l&&(u["line-height"]=new I(new Re(this.context.pref.lineHeight),0));let d=new fl(u,this.context);for(let h=s.length-1;h>=0;--h){let f=s[h],g=[];for(let S in f)As(S)&&g.push(S);g.sort(mu);let m,y;for(let S of g){d.setPropName(S);let C=de(f,S),x=C;if(!X(C.value)){if(S==="font-size"&&h===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)x=new I(new P(this.context.rootFontSize,"px"),C.priority);else if(S==="line-height"&&h===s.length-1&&this.context.rootLineHeight&&C.value instanceof P&&(C.value.unit==="lh"||C.value.unit==="rlh"))x=new I(new P(this.context.rootLineHeight,"px"),C.priority);else if(h===0&&C.value instanceof P&&C.value.unit==="lh"){let v=this.getLineHeightUnitSize(S,m,y);v!=null&&(x=new I(new P(C.value.num*v,"px"),C.priority))}else Nt(S)||(x=C.filterValue(d));S==="font-size"?m=x.value:S==="line-height"&&(y=x.value),u[S]=x}}}for(let h in e)As(h)||(u[h]=e[h]);return{lang:i,elementStyle:u}}resolveURL(e){return e=te(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=Er(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=rm().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let i in this.nodeContext.parent.inheritedProps)s[i]=this.nodeContext.parent.inheritedProps[i]}n.forEach(i=>{let r=e[i];if(r){if(X(r))r===b.initial&&(s[i]=void 0);else if(r instanceof se)s[i]=r.num;else if(r instanceof Y)s[i]=r.name;else if(r instanceof P){let a=r;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[i]=a.num*Je[a.unit];break;default:s[i]=r}}else s[i]=r;["widows","orphans"].includes(i)||delete e[i]}})}}resolveFormattingContext(e,n,s,i,r,a){let l=Ze("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,i,r,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var S,C;let s=!0,i=A("createElementView"),r=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(r,!1);if(!this.nodeContext.shadowContext){let x=this.xmldoc.getElementOffset(r);Ts.registerFragmentIndex(x,this.nodeContext.fragmentIndex,0)}let c={};if(!this.nodeContext.parent){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}let u=l.position,d=l.float,h=l["float-reference"],f=d&&!X(d.value)&&d.value!==b.none&&h&&!X(h.value)?Wg(h.value.toString()):null;if(this.nodeContext.parent&&(jr(u==null?void 0:u.value)||f&&ys(f))){let x=this.inheritFromSourceParent(l);l=x.elementStyle,this.nodeContext.lang=x.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),f&&ys(f)&&c.display===b.block&&(c.display=b.flow_root),a.processContent(r,c,this.nodeContext),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let g=c["flow-into"];if(g&&g.toString()!=this.flowName)return i.finish(!1),i.result();if(pn&&r.localName==="script"&&r.namespaceURI==="http://www.w3.org/1999/xhtml")return Nc(r,this.viewport.window).thenFinish(i),i.result();let m=c.display;if(X(m)&&(m===b.initial||m===b.unset?m=b.inline:m===b.inherit?m=((S=this.nodeContext.parent)==null?void 0:S.display)&&k((C=this.nodeContext.parent)==null?void 0:C.display):m=null),m===b.none)return i.finish(!1),i.result();let y=this.nodeContext.parent==null;return this.nodeContext.flexContainer=m===b.flex,this.createShadows(r,y,l,c,a,this.context,this.nodeContext.shadowContext).then(x=>{this.nodeContext.nodeShadow=x;let v=c.position,E=c.float,N=c.clear,L=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,O=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:L,z=$g(r),K=c["column-count"],je=c["column-width"],lt=K&&K!==b.auto&&!X(K)||je&&je!==b.auto&&!X(je);this.nodeContext.establishesBFC=Yg(m,v,E,c.overflow,L,O,lt||z),this.nodeContext.containingBlockForAbsolute=Kg(v),this.nodeContext.isInsideBFC()&&E!==b.footnote&&!(f&&ys(f))&&(E=null,N=null);let Ye=E instanceof G||E===b.left||E===b.right||E===b.top||E===b.bottom||E===b.inline_start||E===b.inline_end||E===b.block_start||E===b.block_end||E===b.snap_block||E===b.snap_inline||E===b.inside||E===b.outside||E===b.footnote;E&&(delete c.float,E===b.footnote&&(this.isFootnote?(Ye=!1,c.display=b.block):c.display=b.inline)),N&&(N===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(N=k(this.nodeContext.parent.clearSide)),(N===b.left||N===b.right||N===b.top||N===b.bottom||N===b.inline_start||N===b.inline_end||N===b.block_start||N===b.block_end||N===b.inside||N===b.outside||N===b.both||N===b.all||N===b.same||N===b.column||N===b.region||N===b.page)&&(delete c.clear,c.display&&c.display!=b.inline&&(this.nodeContext.clearSide=N.toString())));let ct=Un(m)&&!!c["ua-list-item-count"],At=c["break-inside"];(Ye||At&&!X(At)&&At!==b.auto)&&this.nodeContext.breakPenalty++,m&&m!==b.inline&&_t(m)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!Ye&&!m||_t(m)||al(m),this.nodeContext.display=m?m.toString():"inline",this.nodeContext.floatSide=Ye?E.toString():null,this.nodeContext.floatReference=f||be.INLINE;let R=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=R&&!X(R)?R:null;let _=this.isInsideNonRootMultiColumn(),B=c["column-span"];if(this.nodeContext.columnSpan=!_&&B&&!X(B)?B:null,!this.nodeContext.inline){let U=c["break-after"];U&&!X(U)&&!(_&&U===b.column)&&(this.nodeContext.breakAfter=U.toString(),Xa[this.nodeContext.breakAfter]&&(c["break-after"]=b.column));let bt=c["break-before"];bt&&!X(bt)&&!(_&&bt===b.column)&&(this.nodeContext.breakBefore=bt.toString(),Xa[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Wt=c.page,yt=Wt&&!X(Wt)&&Wt.toString();!yt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||m===b.table_header_group||m===b.table_footer_group)&&(yt=this.styler.cascade.currentPageType),!yt||yt.toLowerCase()==="auto"?yt=this.nodeContext.pageType:this.nodeContext.pageType=yt,this.styler.cascade.currentPageType!==yt&&!(!yt&&c.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!fs(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),yt!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=yt)}this.nodeContext.verticalAlign=c["vertical-align"]&&c["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let W=c["border-collapse"];if(!W||W===k("separate")){let U=c["border-spacing"],bt,Wt;U&&(U instanceof G?(bt=U.values[0],Wt=U.values[1]):bt=Wt=U,bt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Me(bt,this.context)),Wt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Me(Wt,this.context)))}let q=c["footnote-policy"];this.nodeContext.footnotePolicy=q&&!X(q)?q:null;let fe=c["x-first-pseudo"];if(fe){let U=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Za(U,fe.num)}this.nodeContext.inline||this.processAfterIfcontinues(r,l,a,this.context);let Gt=c["white-space"];if(Gt){let U=tl(Gt.toString());U!==null&&(this.nodeContext.whitespace=U)}let es=c["hyphenate-character"];es&&es instanceof M&&(this.nodeContext.hyphenateCharacter=es.str);let OC=c["word-break"],DC=c["line-break"],yf=c["overflow-wrap"];(OC===b.break_all||DC===b.anywhere||yf===b.break_word||yf===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,m,v,E,y),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(e=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,e)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(c),this.findAndProcessRepeatingElements(r,a));let Os=!1,_c=null,Cr=[],Zt=r.namespaceURI,Z=r.localName,Jo=Z;if(Zt=="http://www.w3.org/1999/xhtml"?(Z=="html"||Z=="body"||Z=="script"||Z=="link"||Z=="meta"?Z="div":Z=="vide_"?Z="video":Z=="audi_"?Z="audio":Z=="object"&&(Os=!!this.customRenderer),r.hasAttribute(Rl)&&r.hasAttribute("src")&&c.content instanceof ge&&(Z="img")):Zt=="http://www.idpf.org/2007/ops"?(Z="span",Zt="http://www.w3.org/1999/xhtml"):Zt=="http://www.pyroxy.com/ns/shadow"?(Zt="http://www.w3.org/1999/xhtml",Z=this.nodeContext.inline?"span":"div"):Os=!!this.customRenderer,ct)m=_t(m)?b.inline:b.block,c.display=m,e?Z="li":Z="div";else if(Z=="body"||Z=="li")Z="div";else if(Z=="q")Z="span";else if(Z=="a"){let U=c["hyperlink-processing"];U&&U.toString()!="normal"&&(Z="span")}c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(Os=!0),r.dataset&&r.getAttribute("data-math-typeset")==="true"&&(Os=!0);let Uc;if(Os){let U=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;Uc=this.customRenderer(r,U,c)}else Uc=T(null);Uc.then(U=>{var Ef,vf,Nf,Tf,wf;if(U)Os&&(s=U.getAttribute("data-adapt-process-children")=="true");else if(c.display===b.none){i.finish(!1);return}else U=this.createElement(Zt,Z);Z!=Jo&&(U.setAttribute("data-vivliostyle-original-tag",Jo),(Jo==="html"||Jo==="body")&&(U.role="presentation")),Z=="a"&&U.addEventListener("click",this.page.hrefHandler,!1),_c&&(this.applyPseudoelementStyle(this.nodeContext,"inner",_c),U.appendChild(_c)),U.localName=="iframe"&&U.namespaceURI=="http://www.w3.org/1999/xhtml"&&$x(U);let bt=this.nodeContext.inheritedProps["image-resolution"],Wt=[],yt=c.width,Hc=c.height,MC=r.getAttribute("width"),_C=r.getAttribute("height"),zc=yt===b.auto||!yt&&!MC,Gc=Hc===b.auto||!Hc&&!_C,xf=r.attributes,UC=xf.length,ea=null,Sf=null;m===b.table_cell&&((Nf=(vf=(Ef=this.nodeContext.parent)==null?void 0:Ef.viewNode)==null?void 0:vf.lastElementChild)==null?void 0:Nf.localName)==="a"&&U.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let We=0;We<UC;We++){let Lt=xf[We],xt=Lt.namespaceURI,pe=Lt.localName,Ee=Lt.nodeValue;if(xt){if(xt=="http://www.w3.org/2000/xmlns/")continue;xt=="http://www.w3.org/1999/xlink"&&pe=="href"&&(Ee=this.documentURLTransformer.transformURL(this.resolveURL(Ee),this.xmldoc.url))}else{if(!pn&&pe.match(/^on/)||pe=="style")continue;if((pe=="id"||pe=="name")&&e){let tt=this.documentURLTransformer.transformFragment(Ee,this.xmldoc.url);U.setAttribute(pe,Ee),U.setAttribute("data-vivliostyle-id",tt);let Rt=U.ownerDocument.createElement("a");Rt.setAttribute(pe,tt),Rt.setAttribute(Tn,"1"),Rt.style.position="absolute",U.appendChild(Rt),this.page.registerElementWithId(U,tt);continue}if(pe=="src"||pe=="href"||pe=="poster")Ee=this.resolveURL(Ee),pe==="href"&&(Ee=this.documentURLTransformer.transformURL(Ee,this.xmldoc.url));else if(pe=="srcset")Ee=Ee.split(",").map(tt=>this.resolveURL(tt.trim())).join(",");else if(pe==="data"&&Os&&Z==="object"&&U.hasAttribute("data"))continue;if(pe==="poster"&&Z==="video"&&Zt==="http://www.w3.org/1999/xhtml"&&zc&&Gc){let tt=new Image,Rt=ps(tt,Ee);Cr.push(Rt),Wt.push({image:tt,element:U,fetcher:Rt})}}if(Zt=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(pe)&&(pe=pe.toLowerCase()),this.isSVGUrlAttribute(pe)&&(Ee=NC(Ee,this.xmldoc.url,this.documentURLTransformer)),xt){let tt=Xx[xt];tt&&(pe=`${tt}:${pe}`)}if(pe=="src"&&!xt&&(Z=="img"||Z=="input")&&Zt=="http://www.w3.org/1999/xhtml")ea=Ee;else if(pe=="alt"&&!xt&&Z=="img"&&Zt=="http://www.w3.org/1999/xhtml")Sf=Ee;else if(pe=="href"&&Z=="image"&&Zt=="http://www.w3.org/2000/svg"&&xt=="http://www.w3.org/1999/xlink")this.page.fetchers.push(ps(U,Ee));else if(xt)U.setAttributeNS(xt,pe,Ee);else try{U.setAttribute(pe,Ee)}catch(tt){F.warn(tt)}}if(ea){let We=Z==="input"?new Image:U,Lt=ps(We,ea,Sf);We!==U&&(U.src=ea);let xt=()=>{var Ee,tt;if(c.position===b.fixed)return!0;for(let Rt=(Ee=this.nodeContext.parent)==null?void 0:Ee.viewNode;Rt&&Rt!==this.viewRoot;Rt=Rt.parentElement)if(((tt=Rt.style)==null?void 0:tt.position)==="fixed")return!0;return!1};!zc&&!Gc&&!(()=>{let Ee=this.nodeContext.vertical?yt:Hc;return Ee instanceof P&&Ee.unit==="%"})()&&!xt()?this.page.fetchers.push(Lt):(zc&&Gc&&bt&&bt!==1&&Wt.push({image:We,element:U,fetcher:Lt}),Cr.push(Lt))}delete c.content;let Wc=c["list-style-image"];if(Wc&&Wc instanceof ge){let We=Wc.url;Cr.push(ps(new Image,We))}if(this.preprocessElementStyle(c),this.applyComputedStyles(U,c),this.nodeContext.inline)e||(Tt(U,"inline-start"),ti(U)&&Tt(U,"clone"));else if(e){if(!il(c.position)){let We=c["margin-break"],Lt=this.getBreakTypeAt(this.nodeContext),xt=Lt!==null,pe=Lt==="auto";(We===b.discard&&xt||We!==b.keep&&pe&&!this.nodeContext.floatSide)&&Wa(U,"block-start")}}else{let We=this.nodeContext.vertical?"width":"height";en(U,We)&&w(U,We,this.nodeContext.display==="table-row"?"0.01px":""),Tt(U,"block-start"),ti(U)&&Tt(U,"clone"),Wa(U,"block-start")}if(ct&&U.setAttribute("value",c["ua-list-item-count"].stringValue()),U.classList.contains("_viv-marker-outside-content")&&Un((wf=(Tf=this.nodeContext.parent)==null?void 0:Tf.parent)==null?void 0:wf.display)){let We=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),Lt=parseFloat(We.borderInlineStartWidth)+parseFloat(We.paddingInlineStart)+parseFloat(We.textIndent);Lt&&(U.style.insetInlineEnd=`${Lt}px`)}this.viewNode=U,Cr.length?ds(Cr).then(()=>{bt>0&&this.modifyElemDimensionWithImageResolution(Wt,bt,c,this.nodeContext.vertical),i.finish(s)}):i.timeSlice().then(()=>{i.finish(s)})})}),i.result()}isAtStartOfPage(){var e,n;for(let s=this.nodeContext;s!=null&&s.parent&&!s.after;s=s.parent){let i=s===this.nodeContext&&!s.viewNode?(e=s.parent.viewNode)==null?void 0:e.lastChild:(n=s.viewNode)==null?void 0:n.previousSibling;for(;i&&(Ce(i,s.parent.whitespace)||Ss(i));)i=i.previousSibling;if(i)return!1}return!0}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&Zr(e))}getBreakTypeAt(e){var s,i,r,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(He(c.breakBefore))return c.breakBefore;if(c.fragmentIndex===1&&!c.parent)return c.sourceNode===c.sourceNode.ownerDocument.documentElement?"page":null;if((s=c.parent)!=null&&s.floatSide)return null;let u=(i=c.parent)==null?void 0:i.viewNode;if(u){let d=this.viewport.window.getComputedStyle(u),h=parseFloat(d.paddingBlockStart),f=parseFloat(d.borderBlockStartWidth);if(h||f)return null;let g=u==null?void 0:u.firstChild;for(;g&&(Ce(g,c.parent.whitespace)||!c.floatSide&&Ss(g));)g=g.nextSibling;if(g&&g!==c.viewNode)return null}}let n=(l=(a=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:a.flowPositions[this.flowName])==null?void 0:l.startBreakType;return He(n)?n:"auto"}isInsideTable(e){for(let n=e;n&&!n.after;n=n.parent)if(n.display&&n.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(e,n,s,i){let r=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,i);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let a=new lo(e,n,s,i,this.exprContentListener);this.nodeContext.afterIfContinues=new Il(e,a)}}isSVGUrlAttribute(e){return jo.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,i){e.forEach(r=>{if(r.fetcher.get().get()==="load"){let a=r.image,l=a.width/n,c=a.height/n,u=r.element;if(l>0&&c>0){if(s["box-sizing"]===b.border_box&&(s["border-left-style"]!==b.none&&(l+=Me(s["border-left-width"],this.context)),s["border-right-style"]!==b.none&&(l+=Me(s["border-right-width"],this.context)),s["border-top-style"]!==b.none&&(c+=Me(s["border-top-width"],this.context)),s["border-bottom-style"]!==b.none&&(c+=Me(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||b.none,h=s["max-height"]||b.none;if(d===b.none&&h===b.none)w(u,"max-width",`${l}px`);else if(d!==b.none&&h===b.none)w(u,"width",`${l}px`);else if(d===b.none&&h!==b.none)w(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?w(u,"max-width",`${Math.min(l,Me(f,this.context))}px`):g.unit!=="%"?w(u,"max-height",`${Math.min(c,Me(g,this.context))}px`):i?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||le,h=s["min-height"]||le;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?w(u,"min-width",`${l}px`):f.num!==0&&g.num===0?w(u,"width",`${l}px`):f.num===0&&g.num!==0?w(u,"height",`${c}px`):f.unit!=="%"?w(u,"min-width",`${Math.max(l,Me(f,this.context))}px`):g.unit!=="%"?w(u,"min-height",`${Math.max(c,Me(g,this.context))}px`):i?w(u,"height",`${c}px`):w(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){Ze("PREPROCESS_ELEMENT_STYLE").forEach(s=>{s(this.nodeContext,e)})}findAndProcessRepeatingElements(e,n){for(let s=e.firstChild;s;s=s.nextSibling){if(s.nodeType!==1)continue;let i={},r=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,i),!this.processRepeatOnBreak(i))continue;if(this.nodeContext.formattingContext instanceof un&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new un(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==b.none&&((n===b.auto||X(n))&&(e.display===b.table_header_group?n=b.header:e.display===b.table_footer_group?n=b.footer:n=b.none),n&&n!==b.none)?n.toString():null}createTextNodeView(){let e=A("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=pd(this.nodeContext.preprocessedTextContent).substr(n);this.viewNode=document.createTextNode(s),e.finish(!0)}),e.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return T(!0);let e,n=e=this.sourceNode.textContent,s=A("preprocessTextContent"),i=Ze("PREPROCESS_TEXT_CONTENT"),r=0;return s.loop(()=>r>=i.length?T(!1):i[r++](this.nodeContext,n).thenAsync(a=>(n=a,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Vg(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=A("createNodeView"),i,r=!0;return this.sourceNode.nodeType==1?i=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,i=T(!0)):i=this.createTextNodeView(),i.then(a=>{var l;if(r=a,this.nodeContext.viewNode=this.viewNode,this.viewNode){let c=(h,f)=>(h==null?void 0:h.nodeType)===1&&pi(h)===f,u=this.nodeContext.parent,d=u?c(this.viewNode,"after")&&c(u.viewNode,"first-letter")&&((l=u.viewNode)!=null&&l.hasChildNodes())?u.parent.viewNode:u.viewNode:this.viewRoot;d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Ce(this.viewNode))&&!d.hasChildNodes()&&od(d).includes("block-start")&&Tt(d,"text-start"),d.appendChild(this.viewNode),Qg(this.viewNode))}s.finish(r)}),s.result()}setCurrent(e,n,s){return this.nodeContext=e,e?(this.sourceNode=e.sourceNode,this.offsetInNode=e.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(n,!!s):T(!0)}processShadowContent(e){if(e.shadowContext==null||e.sourceNode.localName!="content"||e.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return e;let n=e.boxOffset,s=e.shadowContext,i=e.parent,r,a,l=s.subShadow||s.parentShadow;s.subShadow?(r=s.root,a=s.type,a==Mt.ROOTLESS&&(r=r.firstChild)):(r=s.owner.firstChild,a=Mt.ROOTLESS);let c=e.sourceNode.nextSibling;if(c?(e.sourceNode=c,e.resetView()):e.shadowSibling?e=e.shadowSibling:r?e=null:(e=e.parent.modify(),e.after=!0),r){let u=new bs(r,i,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,u}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=Mt.ROOTED){let s=e.sourceNode.nextSibling;if(s)return e=e.modify(),e.boxOffset=n,e.sourceNode=s,e.resetView(),this.processShadowContent(e)}return e.shadowSibling?(e=e.shadowSibling.modify(),e.boxOffset=n,e):(e=e.parent.modify(),e.boxOffset=n,e.after=!0,e)}else{if(e.nodeShadow){let i=e.nodeShadow.root;if(e.nodeShadow.type==Mt.ROOTLESS&&(i=i.firstChild),i){let r=new bs(i,e,n);return r.shadowContext=e.nodeShadow,r.shadowType=e.nodeShadow.type,this.processShadowContent(r)}}let s=e.sourceNode.firstChild;if(s)return this.processShadowContent(new bs(s,e,n));if(e.sourceNode.nodeType!=1){let i=pd(e.preprocessedTextContent);n+=i.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}isTransclusion(e,n,s){let i=de(n,"hyperlink-processing");if(!i)return!1;let r=i.evaluate(this.context,"hyperlink-processing");return r?r.toString()==s:!1}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return T(s);let i=A("nextInTree");return this.setCurrent(s,!0,n).then(r=>{(!s.viewNode||!r)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:s}),i.finish(s)}),i.result()}addImageFetchers(e){if(e instanceof me){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof ge){let n=e.url;this.page.fetchers.push(ps(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let i=n.position===b.relative,r=((u=this.nodeContext)==null?void 0:u.parent)===null&&((d=this.sourceNode)==null?void 0:d.parentElement)===null&&!!((h=this.viewRoot)!=null&&h.parentElement),a=Object.keys(n);a.sort(mu);let l,c;for(let f of a){if(jx[f])continue;let g=n[f];if(!(!g||g===H&&!Nt(f))){if(g=g.visit(new Va(this.xmldoc.url,this.documentURLTransformer)),g instanceof P)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new P(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new P(g.num*m,"px"))}else wa(g.unit)&&(g=Aa(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof P&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new Cn(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),Dg[f]||i&&Mg[f]){this.page.delayedItems.push(new Cs(e,f,g));continue}r&&this.page.pageAreaElement&&As(f)?w(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()):w(e,f,g.toString())}}}parsePlusLayoutUnitAdj(e){if(e.endsWith("px")){let n=parseFloat(e);if(!isNaN(n))return Math.round((n+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(e,n,s){var l,c,u,d,h,f;let i=((u=(c=(l=this.nodeContext)==null?void 0:l.parent)==null?void 0:c.viewNode)==null?void 0:u.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,r=i?this.parsePlusLayoutUnitAdj(i.lineHeight):this.context.rootLineHeight;if(e==="line-height"||e==="font-size")return r;let a=null;if(s)if(s instanceof Re||s instanceof P&&(s.unit==="em"||s.unit==="%"))a=s instanceof P&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof P&&s.unit!=="lh"){let g=this.context.queryUnitSize(s.unit,!1);if(g!=null)return s.num*g}return null}if(a==null)for(let g=(h=(d=this.nodeContext)==null?void 0:d.parent)==null?void 0:h.viewNode;g&&g.nodeType===1;g=g.parentNode){let m=(f=g==null?void 0:g.style)==null?void 0:f.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(a=parseFloat(m));break}}if(a!=null){if(n&&!(n instanceof P))return null;let g=i?this.parsePlusLayoutUnitAdj(i.fontSize):this.context.rootFontSize;if(n instanceof P){let m=Tl(n,g,this.context).num;return typeof m!="number"||isNaN(m)?null:a*m}else return g==null?null:a*g}return r}getEmUnitSize(e,n){var r,a,l;let s=((l=(a=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:a.viewNode)==null?void 0:l.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,i=s?this.parsePlusLayoutUnitAdj(s.fontSize):this.context.rootFontSize;if(e==="font-size"||n==null)return i;if(n instanceof P){let c=Tl(n,i,this.context).num;if(typeof c=="number"&&!isNaN(c))return c}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let i=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(i,!1),l=Pt(a,"_pseudos");if(!l||(a=l[n],!a))return;let c={};e.vertical=this.computeStyle(e.vertical,e.direction==="rtl",a,c);let u=c.content;ht(u)&&(u.visit(new Mn(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=A("peelOff"),i=e.firstPseudo,r=e.offsetInNode,a=e.after;if(n>0){let h=e.viewNode.textContent;e.viewNode.textContent=h.substr(0,n),r+=n}else if(!a&&e.viewNode&&r==0){let h=e.viewNode.parentNode;h&&h.removeChild(e.viewNode)}let l=e.boxOffset+n,c=[];for(;e.firstPseudo===i;)c.push(e),e=e.parent;let u=c.pop(),d=u.shadowSibling;return s.loop(()=>{for(;c.length>0;){u=c.pop(),e=new bs(u.sourceNode,e,l),c.length==0&&(e.offsetInNode=r,e.after=a),e.shadowType=u.shadowType,e.shadowContext=u.shadowContext,e.nodeShadow=u.nodeShadow,e.shadowSibling=u.shadowSibling?u.shadowSibling:d,d=null;let h=this.setCurrent(e,!1);if(h.isPending())return h}return T(!1)}).then(()=>{s.finish(e)}),s.result()}createElement(e,n){return e=="http://www.w3.org/1999/xhtml"?this.document.createElement(n):this.document.createElementNS(e,n)}applyFootnoteStyle(e,n,s){let i={},r=Pt(this.footnoteStyle,"_pseudos");if(e=this.computeStyle(e,n,this.footnoteStyle,i),r&&r.before){let a={},l=this.createElement("http://www.w3.org/1999/xhtml","span");co(l,"before"),s.appendChild(l),this.computeStyle(e,n,r.before,a),delete a.content,this.applyComputedStyles(l,a)}return delete i.content,this.applyComputedStyles(s,i),e}processFragmentedBlockEdge(e){var r,a,l;let n=!e.inline&&e.after?e.parent:e,s=!1;if(e.inline&&e.after&&!e.shadowContext&&((r=e.sourceNode.nextSibling)==null?void 0:r.nodeType)===1){let c=e.sourceNode.nextSibling,u=(a=de(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!_t(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let i=0;for(let c=n;c;c=c.parent){if(((l=c.viewNode)==null?void 0:l.nodeType)!==1)continue;let u=c.viewNode;if(u.style)if(c.inline){if(Tt(u,"inline-end"),ti(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;Tt(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(en(u,d)&&w(u,d,""),Tt(u,"block-end"),!i++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?ad(f,["block-start","text-start","block-end","text-end","justify"]):(Tt(u,"text-end"),Tt(u,"justify")):Tt(u,"text-end")}else Tt(u,"text-end")}ti(u)&&Tt(u,"clone"),Wa(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),i=parseFloat(n.borderInlineEndWidth),r=-(s+i);isNaN(r)||(e.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(e){let n=r=>{let{display:a,position:l,float:c}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||gn[r.localName])return!1;if(r.localName==="br")return!0;if((a==="inline"||a==="contents")&&r.hasChildNodes()){let u=r.lastElementChild;if(u&&(!u.nextSibling||u.nextSibling===r.lastChild&&Ce(u.nextSibling))){let d=n(u);if(d||d===null)return d}for(let d=u==null?void 0:u.previousElementSibling;d;d=d.previousElementSibling){let h=n(d);if(h||h===null)return null}return!1}if(a==="none"||l==="absolute"||l==="fixed"||c&&c!=="none"||r.hasAttribute(Tn)){let u=r.previousElementSibling;return u&&(u.nextSibling===r||u.nextSibling===r.previousSibling&&Ce(u.nextSibling))?n(u):!1}return!(!a||_t(a))},s=null;for(let r=e.lastElementChild;r;r=r.previousElementSibling){let a=n(r);if(a){s=r;break}if(a===null)return null}if(!s)return e;if(s===e.lastElementChild&&(!s.nextSibling||s.nextSibling===e.lastChild&&Ce(s.nextSibling)))return null;let i=e.ownerDocument.createElement("span");i.className="viv-anonymous-block";for(let r=s.nextSibling,a=null;r;r=a)a=r.nextSibling,i.appendChild(r);return e.appendChild(i),i}convertLengthToPx(e,n,s){let i=e.num,r=e.unit;if(Gf(r)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,Nl(e,l,this.context).num}else{let a=this.context.queryUnitSize(r,!1);return a?i*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,i=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&pi(s)===pi(i)}else return e.node===n.node}isSameNodePosition(e,n){return e.offsetInNode===n.offsetInNode&&e.after==n.after&&e.steps.length===n.steps.length&&e.steps.every((s,i)=>{let r=n.steps[i];return this.isSameNodePositionStep(s,r)})}isPseudoelement(e){return!!pi(e)}};p(jo,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var Tc=jo,jx={"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},wc=class{constructor(t){p(this,"layoutBox");p(this,"window");p(this,"pixelRatio");p(this,"scaleRatio");p(this,"layoutUnitPerPixel");this.layoutBox=t.layoutBox,this.window=t.window,this.pixelRatio=t.pixelRatio,this.scaleRatio=t.scaleRatio,this.layoutUnitPerPixel=t.layoutUnitPerPixel}subtractOffsets(t,e){let n=e.left,s=e.top;return{left:t.left-n,top:t.top-s,right:t.right-n,bottom:t.bottom-s,width:t.width,height:t.height}}getRangeClientRects(t){let e=t.getClientRects(),n=this.layoutBox.getBoundingClientRect();return Array.from(e).map(s=>this.subtractOffsets(s,n))}getElementClientRect(t){let n=t.getBoundingClientRect();if(n.left===0&&n.top===0&&n.right===0&&n.bottom===0)return n;let s=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(n,s)}getElementComputedStyle(t){return this.window.getComputedStyle(t,null)}adjustLengthValue(t){return this.layoutUnitPerPixel?Math.floor(t*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:t}},Jn=class{constructor(t,e,n,s,i,r){this.window=t;this.fontSize=e;this.pixelRatio=n;p(this,"document");p(this,"root");p(this,"outerZoomBox");p(this,"contentContainer");p(this,"layoutBox");p(this,"width");p(this,"height");p(this,"scaleRatio",1);p(this,"layoutUnitPerPixel",64);p(this,"layoutUnitAdj",0);if(this.document=t.document,this.root=s||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=i||this.root.clientWidth,this.height=r||this.root.clientHeight;return}let a=this.root.firstElementChild;a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-outer-zoom-box","true"),a.role="presentation",this.root.appendChild(a));let l=a.firstElementChild;switch(l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-spread-container","true"),l.role="presentation",a.appendChild(l)),n>0&&CSS.supports("zoom","8")&&(w(this.root,"--viv-outputPixelRatio",`${n}`),w(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),oa){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||t.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&w(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let c=a.nextElementSibling;c||(c=this.document.createElement("div"),c.setAttribute("data-vivliostyle-layout-box","true"),c.role="presentation",this.root.appendChild(c)),this.outerZoomBox=a,this.contentContainer=l,this.layoutBox=c,this.width=i||parseFloat(t.getComputedStyle(this.root).width)||this.root.offsetWidth||t.innerWidth,this.height=r||parseFloat(t.getComputedStyle(this.root).height)||this.root.offsetHeight||t.innerHeight;let u={width:794,height:1056},d=!t.outerWidth&&!t.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&t.innerWidth===800&&t.innerHeight===600;(!this.width||!i&&d)&&(this.width=u.width),(!this.height||!r&&d)&&(this.height=u.height)}resetZoom(){w(this.outerZoomBox,"width",""),w(this.outerZoomBox,"height",""),w(this.contentContainer,"width",""),w(this.contentContainer,"height",""),w(this.contentContainer,"transform","")}zoom(t,e,n){w(this.root,"--viv-outputScale",`${n}`),w(this.outerZoomBox,"width",`${t*n}px`),w(this.outerZoomBox,"height",`${e*n}px`),w(this.contentContainer,"width",`${t}px`),w(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var Yo=class{constructor(t,e,n){this.store=t;this.url=e;this.document=n;p(this,"lang",null);p(this,"totalOffset",-1);p(this,"root");p(this,"body");p(this,"head");p(this,"last");p(this,"lastOffset",1);p(this,"idMap");this.root=n.documentElement;let s=null,i=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 a=r;if(a.namespaceURI=="http://www.w3.org/1999/xhtml")switch(a.localName){case"head":i=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=i,this.last=this.root,this.last.setAttribute(Qt,"0")}doc(){return new Ac([this.document])}getElementOffset(t){let e=t.getAttribute(Qt);if(e)return parseInt(e,10);let n=this.lastOffset,s=this.last;for(;s!=t;){let i=s.firstChild;if(!i){for(;i=s.nextSibling,!i;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=i,i.nodeType==1?(i.setAttribute(Qt,n.toString()),++n):n+=i.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,i=t,r=null;if(i.nodeType==1){if(!n)return this.getElementOffset(i)}else{if(s=e,r=i.previousSibling,!r)return i=i.parentNode,s+=1,this.getElementOffset(i)+s;i=r}for(;;){for(;i.lastChild;)i=i.lastChild;if(i.nodeType==1)break;if(s+=i.textContent.length,r=i.previousSibling,!r){i=i.parentNode;break}i=r}return s+=1,this.getElementOffset(i)+s}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(t){let e,n=this.root;for(;;){if(e=this.getElementOffset(n),e>=t)return n;let l=n.children;if(!l)break;let c=Vt(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,i=n,r=i.firstChild||i.nextSibling,a=null;for(;;){if(r){if(r.nodeType==1||(i=r,a=i,s+=r.textContent.length,s>t&&!/^\s*$/.test(r.textContent)))break}else if(i=i.parentNode,!i)break;r=i.nextSibling}return r&&a&&/^\s*$/.test(a.textContent)&&(a=r),a||n}buildIdMap(t){let e=t.getAttribute("id");e&&!this.idMap[e]&&(this.idMap[e]=t);let n=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");n&&!this.idMap[n]&&(this.idMap[n]=t);for(let s=t.firstElementChild;s;s=s.nextElementSibling)this.buildIdMap(s)}getElement(t){let e=t.match(/([^#]*)#(.+)$/);if(!e||e[1]&&e[1]!=this.url)return null;let n=e[2],s=this.document.getElementById(n);return!s&&this.document.getElementsByName&&(s=this.document.getElementsByName(n)[0]),s||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),s=this.idMap[n]),s}},lf=(i=>(i.TEXT_HTML="text/html",i.TEXT_XML="text/xml",i.APPLICATION_XML="application/xml",i.APPLICATION_XHTML_XML="application/xhtml+xml",i.IMAGE_SVG_XML="image/svg+xml",i))(lf||{});function kc(o,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(o,t)}catch(i){}if(s){let i=s.documentElement,r="parsererror";if(i.localName===r)return null;for(let a=i.firstElementChild;a;a=a.nextElementSibling)if(a.localName===r)return null}else return null;return s}function Yx(o){let t=o.contentType;if(t){let n=Object.keys(lf);for(let s=0;s<n.length;s++)if(lf[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=o.url.match(/\.([^./#?]+)([#?]|$)/);if(e)switch(e[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 uf(o,t){let e=o.responseXML;if(!e){let s=new DOMParser,i=o.responseText;if(i){let r=Yx(o);if(e=kc(i,r||"application/xml",s),e&&!r){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=kc(i,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=kc(i,"image/svg+xml",s))}e||(e=kc(i,"text/html",s))}}let n=e?new Yo(t,o.url,e):null;return T(n)}function TC(){return new Zs(uf,"document")}var cf=class o{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new o(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new o(n=>{if(!this.check(n))return!1;let s=new Ac([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},df=new cf(o=>!0),Ac=class o{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let e=[];for(let n of this.nodes)t.check(n)&&e.push(n);return new o(e)}forEachNode(t){let e=[],n=s=>{e.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new o(e)}forEach(t){let e=[];for(let n=0;n<this.nodes.length;n++)e.push(t(this.nodes[n]));return e}forEachNonNull(t){let e=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&e.push(s)}return e}child(t){return this.forEachNode((e,n)=>{for(let s=e.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,e)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&e(n)})}attribute(t){return this.forEachNonNull(e=>e.nodeType==1?e.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}};var Kx=new xn(()=>{let o=A("uaStylesheetBase"),t=Vh(),e=te("user-agent-base.css",Jt),n=new jn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),um(n.cascade),Ga(qu,n,e,null,null).thenFinish(o),o.result()},"uaStylesheetBaseFetcher");function qx(){return Kx.get()}var pf=class extends ks{constructor(e,n,s,i,r,a){super(e,n,null,s,i,"counter-style");this.counterStyleName=r;this.counterStyles=a}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||F.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},hf=class{constructor(t,e,n,s,i,r,a,l,c,u,d){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=i;this.fontFaces=r;this.footnoteProps=a;this.flowProps=l;this.viewportProps=c;this.pageProps=u;this.counterStyleStore=d;p(this,"fontDeobfuscator");p(this,"validatorSet");this.fontDeobfuscator=t.fontDeobfuscator,this.validatorSet=t.validatorSet,this.pageScope.defineBuiltIn("has-content",function(h){h=h;let f=this,g=f.currentLayoutPosition,m=g.firstFlowChunkOfFlow(h);return f.matchPageSide(g.startSideOfFlow(h))&&g.hasContent(h,f.lookupOffset)&&!!m&&!f.flowChunkIsAfterParentFlowForcedBreak(m)}),this.pageScope.defineName("page-number",new ne(this.pageScope,function(){let h=this;return h.pageNumberOffset+h.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new ne(this.pageScope,function(){let f=this.currentLayoutPosition;return f==null?void 0:f.isBlankPage},"blank-page"))}sizeViewport(t,e,n,s){if(this.viewportProps.length){let i=new Ti(this.rootScope,t,e,n),r=cm(i,this.viewportProps),a=r.width,l=r.height,c=r["text-zoom"],u=1;if(a&&l||c){let d=Je.em;if((c?c.evaluate(i,"text-zoom"):null)===b.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Me(a.evaluate(i,"width"),i),g=Me(l.evaluate(i,"height"),i);if(f>0&&g>0)return{width:s&&s.spreadView?(f+s.pageBorder)*2:f,height:g,fontSize:n}}}}return{width:t,height:e,fontSize:n}}},Fs=class extends Ti{constructor(e,n,s,i,r,a,l,c,u,d,h,f,g,m){super(e.rootScope,i.width,i.height,i.fontSize);this.style=e;this.xmldoc=n;this.viewport=i;this.clientLayout=r;this.fontMapper=a;this.customRenderer=l;this.fallbackMap=c;this.pageNumberOffset=u;this.documentURLTransformer=d;this.counterStore=h;this.cmykStore=f;p(this,"lang");p(this,"primaryFlows",{body:!0});p(this,"rootPageBoxInstance",null);p(this,"styler",null);p(this,"stylerMap",null);p(this,"currentLayoutPosition",null);p(this,"layoutPositionAtPageStart",null);p(this,"lookupOffset",0);p(this,"faces");p(this,"pageBoxInstances",{});p(this,"pageManager",null);p(this,"rootPageFloatLayoutContext");p(this,"pageBreaks",{});p(this,"pageProgression",null);p(this,"isVersoFirstPage",!1);p(this,"blankPageAtStart",!1);p(this,"pageSheetSize",{});p(this,"pageSheetHeight",0);p(this,"pageSheetWidth",0);this.lang=n.lang||s,this.faces=new pc(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new _n(null,null,null,null,null,null,null),this.pageProgression=g||null,this.isVersoFirstPage=!!m;for(let y in e.flowProps){let S=e.flowProps[y],C=de(S,"flow-consume");C&&(C.evaluate(this,"flow-consume")==b.all?this.primaryFlows[y]=!0:delete this.primaryFlows[y])}}init(){let e=A("StyleInstance.init"),n=this.counterStore.createCounterListener(this.xmldoc.url),s=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Ro(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,n,s,this.style.counterStyleStore,this.cmykStore),s.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let i=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=nf(i)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Cc(r);let a=this.style.cascade.createInstance(this,n,s,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(a,i),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new Sc(a,this.style.pageScope,this.rootPageBoxInstance,this,i);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=lC(u.properties,this),h=new Do(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{EC(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let c=this.style.pageProps;return c[""]||(c[""]={}),Object.keys(c).forEach(u=>{let d=c[u];this.styler.cascade.applyVarFilter([d],this.styler,null),this.styler.cascade.applyCalcFilter(d,this.styler.context),this.styler.cascade.applyCmykFilter(d);let h=sf($o(d),this);this.pageSheetSize[u]={width:h.pageWidth+h.cropOffset*2,height:h.pageHeight+h.cropOffset*2}}),e.result()}matchStartPageSide(e){let n=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),s=this.pageProgression=="ltr";switch(e){case"left":return n!==s;case"right":return n===s;case"recto":return n;case"verso":return!n;default:return!0}}getStylerForDoc(e){let n=this.stylerMap[e.url];if(!n){let s=this.style.store.getStyleForDoc(e),i=new Ti(s.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),a=this.counterStore.createCounterResolver(e.url,s.rootScope,s.pageScope);n=new Ro(e,s.cascade,s.rootScope,i,this.primaryFlows,s.validatorSet,r,a,s.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=n}return n}registerInstance(e,n){this.pageBoxInstances[e]=n}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,n){let s=this.currentLayoutPosition;if(s){s.flows[e.flowName]?n=s.flows[e.flowName]:s.flows[e.flowName]=n;let i=s.flowPositions[e.flowName];i||(i=new Ja,s.flowPositions[e.flowName]=i);let r=zg(e.element),a=new wt(r),l=new Qa(a,e);i.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let i=!0;class r{unknownProperty(d,h){i=!1}invalidPropertyValue(d,h){i=!1}simpleProperty(d,h,f){}}let a=new r,l=En(this.style.rootScope,new Xe(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),i):!1}evalSupportsSelector(e){let n=new Lc(null),s=new Xe(e+"{}",n);return new hs(Ne,s,n,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!n.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let n=Number.POSITIVE_INFINITY;for(let s=0;s<e.positions.length;s++){let i=e.positions[s].chunkPosition.primary,r=i.steps[0].node,a=i.offsetInNode,l=i.after,c=0;for(;r.ownerDocument!=this.xmldoc.document;)c++,r=i.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(r,a,l);u<n&&(n=u)}return n}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let i in this.primaryFlows){let r=e.flowPositions[i];if(!n&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(i),r=this.currentLayoutPosition.flowPositions[i],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[i]=r)),r){let a=this.getConsumedOffset(r);a<s&&(s=a)}}return s}dumpLocation(e){F.debug("Location - page",this.currentLayoutPosition.page),F.debug(" current:",e),F.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i of s.positions)F.debug(" Chunk",`${n}:`,i.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new re(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let n in e.flowPositions){let s=e.flowPositions[n];if(s&&s.positions.length>0){let i=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===i.startOffset){let r=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=ld(ze(a,r))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let i=this.rootPageBoxInstance.children,r;for(let a=0;a<i.length;a++){if(r=i[a],r.pageBox.pseudoName===vc)continue;let l=1;r.pageBox.pseudoName===_o&&!(this.actualPageWidth&&this.actualPageHeight)&&(l=1/0);let c=r.getProp(this,"utilization");c&&c.isNum()&&(l=c.num);let u=this.queryUnitSize("em",!1),d=this.pageWidth()*this.pageHeight(),h=Math.ceil(l*d/(u*u)),f=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(s,h),this.styler.cascade.currentPageType=f,this.updateStartSide(n),this.layoutPositionAtPageStart=n.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let g=r.getProp(this,"enabled");if(!g||g===b._true){if(n.page===1&&this.blankPageAtStart){r.style={};let m=e.size;e={},m&&(e.size=m)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let n=this.layoutPositionAtPageStart.flows,s=n[e.flowName].parentFlowName;if(s){let i=e.startOffset,r=n[s].forcedBreakOffsets;if(!r.length||i<r[0])return!1;let a=Vt(r.length,d=>r[d]>i)-1,l=r[a],c=this.layoutPositionAtPageStart.flowPositions[s],u=this.getConsumedOffset(c);return l<u?!1:u<l?!0:!this.matchPageSide(c.startBreakType)}return!1}setFormattingContextToColumn(e,n){let s=this.currentLayoutPosition.flows[n];s.formattingContext||(s.formattingContext=new er(null)),e.flowRootFormattingContext=s.formattingContext}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),i=c=>{if(c.floatReference!==be.PAGE)return!1;let u=this.layoutPositionAtPageStart.flowPositions.body,d=u&&this.getConsumedOffset(u),h=this.xmldoc.getNodeOffset(c.nodePosition.steps[0].node,0,!1);return h!=null&&d!=null&&h>d},r=A("layoutDeferredPageFloats"),a=!1,l=0;return r.loopWithFrame(c=>{if(l===s.length){c.breakLoop();return}let u=s[l++],d=u.float;if(i(d)){c.breakLoop();return}let h=new cn().findByFloat(d),f=h.findPageFloatFragment(d,n);if(f&&f.hasFloat(d)){c.continueLoop();return}else if(n.isForbidden(d)||n.hasPrecedingFloatsDeferredToNext(d)){n.deferPageFloat(u),c.breakLoop();return}e.layoutPageFloatInner(u,h,null,f).then(g=>{if(!g){c.breakLoop();return}let m=n.parent.isInvalidated();if(m){c.breakLoop();return}else n.isInvalidated()&&!m&&(a=!0,n.validate());c.continueLoop()})}).then(()=>{a&&n.invalidate(),r.finish(!0)}),r.result()}getLastAfterPositionIfDeferredFloatsExists(e,n){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let r;return n?(r=n.clone(),r.primary=e.lastAfterPosition):r=new wt(e.lastAfterPosition),r}else return null;else return null}layoutColumn(e,n){let s=this.currentLayoutPosition.flowPositions[n];if(!s||!this.matchPageSide(s.startBreakType))return T(!0);this.setFormattingContextToColumn(e,n),e.init(),this.primaryFlows[n]&&e.bands.length>0&&(e.forceNonfitting=!1);let i=A("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){i.finish(!0);return}let r=[],a=[],l=!0;i.loopWithFrame(c=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(n)){c.breakLoop();return}for(;s.positions.length-a.length>0;){let u=0;for(;a.includes(u);)u++;let d=s.positions[u];if(d.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(d.flowChunk))break;for(let g=u+1;g<s.positions.length;g++){if(a.includes(g))continue;let m=s.positions[g];if(m.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(m.flowChunk))break;m.flowChunk.isBetter(d.flowChunk)&&(d=m,u=g)}let h=d.flowChunk,f=!0;if(e.layout(d.chunkPosition,l,s.breakAfter).then(g=>{if(e.pageFloatLayoutContext.isInvalidated()){c.breakLoop();return}if(l=!1,d.flowChunk.repeated&&(g===null||h.exclusive)&&r.push(u),h.exclusive){a.push(u),c.breakLoop();return}else{let m=!!g||!!e.pageBreakType,y=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(e.pageBreakType&&y?(d.chunkPosition=y,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||y)&&(d.chunkPosition=g||y,r.push(u)),s.startBreakType=ld(e.pageBreakType)),m){c.breakLoop();return}}e.forceNonfitting=!1,f?f=!1:c.continueLoop()}),f){f=!1;return}}c.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){s.positions=s.positions.filter((u,d)=>r.includes(d)||!a.includes(d)),s.breakAfter==="column"&&(s.breakAfter=null),e.saveDistanceToBlockEndFloats();let c=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(c)}i.finish(!0)})}),i.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new Vl([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,i,r,a,l,c,u,d,h,f,g,m){let y=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,S=r.element,C=new _n(c,be.COLUMN,null,l,null,null,null),x=this.currentLayoutPosition.clone(),v=A("createAndLayoutColumn"),E;return v.loopWithFrame(N=>{let L=this.createLayoutConstraint(C);if(u>1){let O=this.viewport.document.createElement("div");if(w(O,"position","absolute"),S.appendChild(O),E=new fi(O,g,this.clientLayout,L,C),E.forceNonfitting=m,E.vertical=r.vertical,E.rtl=r.rtl,E.snapHeight=r.snapHeight,E.snapWidth=r.snapWidth,r.vertical){let z=(r.rtl?u-a-1:a)*(h+d)+r.paddingTop,K=parseFloat(S.style.width);E.setHorizontalPosition(r.paddingLeft+K-r.width,r.width),E.setVerticalPosition(z,h)}else{let z=(r.rtl?u-a-1:a)*(h+d)+r.paddingLeft;E.setVerticalPosition(r.paddingTop,r.height),E.setHorizontalPosition(z,h)}E.originX=n,E.originY=s}else E=new fi(S,g,this.clientLayout,L,C),E.copyFrom(r);E.exclusions=y?[]:i.concat(),E.innerShape=f,C.setContainer(E),(E.vertical?E.height:E.width)>=0?this.layoutColumn(E,l).then(()=>{C.isInvalidated()||C.finish(),E.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(E.pageFloatLayoutContext.validate(),this.currentLayoutPosition=x.clone(),E.element!==S&&S.removeChild(E.element),N.continueLoop()):N.breakLoop()}):(C.finish(),N.breakLoop())}).then(()=>{v.finish(E)}),v.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof Wo||n instanceof yi&&!(n instanceof Rn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,i){n instanceof Ln;let r=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new _n(e,be.REGION,s,i,null,r,a)}layoutFlowColumnsWithBalancing(e,n,s,i,r,a,l,c,u){let d=this.currentLayoutPosition.clone(),h=this.getRegionPageFloatLayoutContext(a,n,l,c),f=!0,g=()=>(this.currentLayoutPosition=d.clone(),this.layoutFlowColumns(e,n,s,i,r,a,h,l,c,u,f).thenAsync(m=>m?T({columns:m,position:this.currentLayoutPosition}):T(null)));return g().thenAsync(m=>{if(!m)return T(null);if(u<=1)return T(m.columns);let y=n.getProp(this,"column-fill")||b.balance,S=this.currentLayoutPosition.flowPositions[c];let C=Dm(u,y,g,h,l,m.columns,S);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(x=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=x.position,T(x.columns)))):T(m.columns)})}layoutFlowColumns(e,n,s,i,r,a,l,c,u,d,h){let f=A("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=n.getPropAsNumber(this,"column-gap"),y=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,S=n.getActiveRegions(this),C=n.getProp(this,"shape-inside"),x=Fa(C,0,0,c.width,c.height,this),v=new Tc(u,this,this.viewport,this.styler,S,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),E=0,N=null,L=[];return f.loopWithFrame(O=>{this.createAndLayoutColumn(n,s,i,r,c,E++,u,l,d,m,y,x,v,h).then(z=>{if(a.isInvalidated()){L=null,O.breakLoop();return}if((!!z.pageBreakType&&z.pageBreakType!=="column"||E===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){E=0,this.currentLayoutPosition=g.clone(),l.validate(),l.isLocked()?(L=null,O.breakLoop()):O.continueLoop();return}N=z,L[E-1]=N,N.pageBreakType&&N.pageBreakType!="column"&&(E=d,N.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),E<d?O.continueLoop():O.breakLoop()})}).then(()=>{f.finish(L)}),f.result()}layoutContainer(e,n,s,i,r,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==b._true)return T(!0);let u=A("layoutContainer"),h=n.getProp(this,"wrap-flow")===b.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof Xo?"complementary":"presentation";let m=n.getProp(this,"position");w(g,"position",m?m.name:"absolute");let y=n instanceof Rn;n instanceof Ln?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new Qi(g);C.vertical=n.vertical,C.rtl=n.rtl,C.borderBoxSizing=n.borderBoxSizing,C.exclusions=a,n.prepareContainer(this,C,e,this.faces,this.clientLayout),n instanceof Rn&&(C.width<=0||C.height<=0)&&F.warn("Negative or zero page area size"),C.originX=i,C.originY=r,i+=C.left+C.marginLeft+C.borderLeft,r+=C.top+C.marginTop+C.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,C);let x,v=!1;if(!f||!f.isIdent()){let E=n.getProp(this,"content");if(E instanceof D&&E.expr instanceof ne&&E.expr.str.startsWith("running-element-"))E.visit(new Mn(g,this,E,this.counterStore.getExprContentListener()));else if(ht(E)){let N="span";E instanceof ge&&(N="img");let L=this.viewport.document.createElement(N);E.visit(new Mn(L,this,E,this.counterStore.getExprContentListener())),g.appendChild(L),N=="img"&&n.transferSingleUriContentProps(this,L,this.faces),n.transferContentProps(this,C,e,this.faces),N=="span"&&Em(L,n.getProp(this,"text-autospace"),n.getProp(this,"text-spacing-trim"),n.getProp(this,"hanging-punctuation"),this.lang,n.vertical)}else n.suppressEmptyBoxGeneration&&(s.removeChild(g),v=!0);v||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),x=T(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),x=T(!0);else{let E=A("layoutContainer.inner"),N=f.toString(),L=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,i,r,a,l,C,N,L).then(O=>{if(!l.isInvalidated()){let z=O[0];z.element===g&&(C=z),C.computedBlockSize=Math.max.apply(null,O.map(je=>je.computedBlockSize)),n.finishContainer(this,C,e,z,L,this.clientLayout,this.faces);let K=this.currentLayoutPosition.flowPositions[N];K&&K.breakAfter==="region"&&(K.breakAfter=null)}E.finish(!0)}),x=E.result()}return x.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!v&&!h){let N=n.getProp(this,"shape-outside"),L=C.getOuterShape(N,this);a.push(L)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let E=y?0:n.children.length-1;u.loop(()=>{for(;E>=0&&E<n.children.length;){let N=n.children[y?E++:E--],L=this.layoutContainer(e,N,g,i,r,a,l);if(L.isPending())return L.thenAsync(()=>T(!l.isInvalidated()));if(l.isInvalidated())break}return T(!1)}).then(()=>{u.finish(!0)})}),u.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i=s.positions.length-1;i>=0;i--){let r=s.positions[i];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&s.positions.splice(i,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let i=s.positions.length-1;i>=0;i--){let r=s.positions[i];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let n in this.primaryFlows){let s=e.flowPositions[n];if(s&&s.positions.length>0)return!1}return!0}layoutNextPage(e,n){var y;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new el,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let i=1e4;if(n.page>i)throw new Error(`Too many pages generated (over ${i} pages)`);let r=n.startSideOfFlow("body");n.isBlankPage=fs(r)&&this.matchPageSide(r),e.isBlankPage=n.isBlankPage,n.page++;let a=this.styler.cascade.previousPageType;e.pageType==null&&(e.pageType=(y=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?y:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType);let l=this.pageManager.pageCascadeInstance;e.pageType&&(a!==e.pageType&&(l.pageTypePageCounts[e.pageType]=0),l.pageTypePageCounts[e.pageType]=(l.pageTypePageCounts[e.pageType]||0)+1),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let c=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([c],this.styler,null),this.styler.cascade.applyCalcFilter(c,this.styler.context),this.styler.cascade.applyCmykFilter(c),!s){let S=new re(this.style.pageScope,"left-page");e.side=S.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let u=this.selectPageMaster(c);if(!u)return T(null);let d=0;if(!s){e.setAutoPageWidth(u.pageBox.specified.width.value===rs),e.setAutoPageHeight(u.pageBox.specified.height.value===os),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(c,this);let S=sf($o(c),this);this.setPageSizeAndBleed(S,e),bC(c,S,e,this),d=S.bleedOffset+S.bleed}let h=!s&&u.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=h!=b.horizontal_tb;let f=u.getProp(this,"direction")||b.ltr,g=new _n(this.rootPageFloatLayoutContext,be.PAGE,null,null,null,h,f),m=A("layoutNextPage");return m.loopWithFrame(S=>{this.layoutContainer(e,u,e.bleedBox,d,d,[],g).then(()=>{g.isInvalidated()||g.finish(),g.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),g.validate(),S.continueLoop()):S.breakLoop()})}).then(()=>{u.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(C=>{let x=n.flowPositions[C],v=x.breakAfter;v&&(v==="page"||!this.matchPageSide(v))&&(x.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let S=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(S,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),m.finish(n)}),m.result()}setPageSizeAndBleed(e,n){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,n.container.style.width=`${this.pageSheetWidth}px`,n.container.style.height=`${this.pageSheetHeight}px`,n.bleedBox.style.left=`${e.bleedOffset}px`,n.bleedBox.style.right=`${e.bleedOffset}px`,n.bleedBox.style.top=`${e.bleedOffset}px`,n.bleedBox.style.bottom=`${e.bleedOffset}px`,n.bleedBox.style.padding=`${e.bleed}px`}},ff=class o extends jn{constructor(e,n,s,i){super(e.rootScope,e,n,s,i,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let i=new fr(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new yc(i.scope,this.masterHandler,i,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=ut(this.scope,this.condition,n)),this.masterHandler.pushHandler(new o(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Sl(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new ks(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(e){this.masterHandler.pushHandler(new pf(this.scope,this.owner,{},this.masterHandler.validatorSet,e,this.masterHandler.counterStyles))}startFlowRule(e){let n=this.masterHandler.flowProps[e];n||(n={},this.masterHandler.flowProps[e]=n),this.masterHandler.pushHandler(new ks(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new ks(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=di(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new ks(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new Ec(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(jn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",k(e)),this.endRule();let n=new o(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},Lc=class extends Ma{constructor(e){super();this.validatorSet=e;p(this,"rootScope");p(this,"pageScope");p(this,"rootBox");p(this,"cascadeParserHandler");p(this,"regionCount",0);p(this,"fontFaces",[]);p(this,"counterStyles",new Wl);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new Hs(null),this.pageScope=new Hs(this.rootScope),this.rootBox=new fc(this.rootScope),this.cascadeParserHandler=new ff(this,null,null,null),this.slave=this.cascadeParserHandler}};function Zx(o,t){return t.parseOPSResource(o)}var Rc=class extends Zs{constructor(e){super(Zx,"document");this.fontDeobfuscator=e;p(this,"styleByKey",{});p(this,"styleFetcherByKey",{});p(this,"styleByDocURL",{});p(this,"triggersByDocURL",{});p(this,"validatorSet",null);p(this,"styleSheets",[]);p(this,"triggerSingleDocumentPreprocessing",!1)}init(e,n){this.setStyleSheets(e,n);let s=A("OPSDocStore.init");return this.validatorSet=Vh(),qx().then(()=>{this.triggerSingleDocumentPreprocessing=!0,s.finish(!0)}),s.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,n){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),n&&n.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let n=e.url;n&&(n=te(ns(n),In)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=te(ns(n),In)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=A("OPSDocStore.load"),s=e.url,i=s.endsWith("?viv-toc-box");return uf(e,this).then(r=>{var f;if(!r){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=Ze("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](r.document)}catch(y){F.warn("Error during single document preprocessing:",y)}}let a=[],l=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let g=0;g<l.length;g++){let m=l[g],y=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),S=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),x=m.getAttribute("ref");y&&S&&C&&x&&a.push({observer:y,event:S,action:C,ref:x})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:te("user-agent-page.css",Jt),text:Ku,flavor:"UA",classes:null,media:null}),c.push({url:te("user-agent-counter-styles.css",Jt),text:Ju,flavor:"UA",classes:null,media:null}),i)c.push({url:te("user-agent-toc.css",Jt),text:Zu,flavor:"UA",classes:null,media:null});else{let g=r.document.querySelectorAll("style, link, meta");for(let m of g){let y=m.namespaceURI,S=m.localName;if(y=="http://www.w3.org/1999/xhtml")if(S=="style"){let C=m.getAttribute("class"),x=m.getAttribute("media"),v=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:v?C:null,media:x})}else if(S=="link"){let C=m.getAttribute("href"),x=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),v=m.getAttribute("class"),E=m.getAttribute("media");if(C&&(x!=null&&x.includes("stylesheet"))&&(!x.includes("alternate")||v)){let N=te(C,s),L=m.getAttribute("title");c.push({url:N,text:null,classes:L?v:null,media:E,flavor:"Author"})}}else S=="meta"&&m.getAttribute("name")=="viewport"&&c.push({url:s,text:this.processViewportMeta(m),flavor:"Author",classes:null,media:null})}for(let m=0;m<this.styleSheets.length;m++)c.push(this.styleSheets[m])}let u="";for(let g=0;g<c.length;g++)u+=c[g].url,u+="^",c[g].text&&(u+=c[g].text),u+="^";let d=this.styleByKey[u];if(d){this.styleByDocURL[s]=d,n.finish(r);return}let h=this.styleFetcherByKey[u];h||(h=new xn(()=>{let g=A("fetchStylesheet"),m=0,y=new Lc(this.validatorSet);return g.loop(()=>{if(m<c.length){let S=c[m++];return y.startStylesheet(S.flavor),S.text!==null?Ga(S.text,y,S.url,S.classes,S.media).thenReturn(!0):nd(S.url,y,S.classes,S.media)}return T(!1)}).then(()=>{let S=y.cascadeParserHandler.finish();d=new hf(this,y.rootScope,y.pageScope,S,y.rootBox,y.fontFaces,y.footnoteProps,y.flowProps,y.viewportProps,y.pageProps,y.counterStyles),this.styleByKey[u]=d,delete this.styleFetcherByKey[u],g.finish(d)}),g.result()},`FetchStylesheet ${s}`),this.styleFetcherByKey[u]=h,h.start()),h.get().then(g=>{this.styleByDocURL[s]=g,n.finish(r)})}),n.result()}processViewportMeta(e){return""}};var Ko="\u25B8",kC="\u25BE",Qx="\u25B9";function Vc(o){let t=Array.from(o.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(o.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of o.querySelectorAll(e)){if(t.find(i=>i.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 AC(o){let t=Vc(o),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var Ic=class{constructor(t,e,n,s,i,r,a,l,c,u,d){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=i;this.rendererFactory=a;this.fallbackMap=l;this.documentURLTransformer=c;this.counterStore=u;this.cmykStore=d;p(this,"pref");p(this,"page",null);p(this,"instance",null);this.pref=Ta(r),this.pref.spreadView=!1}setAutoHeight(t,e){if(e--!=0){for(let n=t.firstChild;n;n=n.nextSibling)if(n.nodeType==1){let s=n;en(s,"height","auto")!="auto"&&(w(s,"height","auto"),this.setAutoHeight(s,e)),en(s,"position","static")=="absolute"&&(w(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,i)=>{let r=i.behavior;if(r)switch(r.toString()){case"toc-node-anchor":i.color=b.inherit,i["text-decoration"]=b.none;break;case"toc-node":i.display=b.block,i.margin=le,i.padding=le,i["padding-inline-start"]=new P(1.25,"em");break;case"toc-node-first-child":i.display=b.inline_block,i.margin=new P(.2,"em"),i["vertical-align"]=b.top,i.color=b.inherit,i["text-decoration"]=b.none;break;case"toc-container":i.padding=le;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return e(n,s,i);let a=n.firstChild;a&&a.nodeType!==1&&Ce(a)&&n.replaceChild(n.ownerDocument.createComment(a.textContent),a);let l=s.getAttribute("data-adapt-class");if(l=="toc-node"){let u=s.firstChild;u.textContent!=Ko&&(u.textContent=Ko,w(u,"cursor","pointer"),u.addEventListener("click",Jx,!1),u.setAttribute("role","button"),u.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),s.style.height!=="0px"&&(u.tabIndex=0))}let c=s.ownerDocument.createElement("div");if(c.setAttribute("data-adapt-process-children","true"),r.toString()=="toc-node"){let u=s.ownerDocument.createElement("div");if(u.textContent=Qx,w(u,"margin","0.2em 0 0 -1em"),w(u,"margin-inline-start","-1em"),w(u,"margin-inline-end","0"),w(u,"display","inline-block"),w(u,"width","1em"),w(u,"text-align","center"),w(u,"vertical-align","top"),w(u,"cursor","default"),w(u,"font-family","Menlo,sans-serif"),c.appendChild(u),w(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){w(c,"height","0px");let d=n.firstElementChild;d&&d.localName==="a"&&(d.tabIndex=-1)}else s.setAttribute("role","tree")}else l=="toc-node"&&(c.setAttribute("data-adapt-class","toc-container"),c.setAttribute("role","group"),c.setAttribute("aria-hidden","true"));return T(c)}}showTOC(t,e,n,s,i){if(this.page)return T(this.page);let r=A("showTOC"),a=new Zi(t,t);this.page=a;let l=Xt(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of Vc(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,i);e=new Jn(e.window,d.fontSize,0,t,d.width,d.height);let h=this.makeCustomRenderer(c),f=new Fs(u,c,this.lang,e,this.clientLayout,this.fontMapper,h,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=f,f.pref=this.pref,f.init().then(()=>{f.layoutNextPage(a,null).then(()=>{this.setAutoHeight(t,2),r.finish(a)})})}),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 t(s){if(!s)return[];let i=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(i).map(e)}function e(s){let i=new URL(s.href),[,r]=i.hash.match(/^#?(.*)$/),a=s.innerText,l=s.parentElement.querySelector("[role=group]"),c=t(l);return{id:r,title:a,children:c}}let n=this.page.container.querySelector("[role=tree]");return t(n)}};function Jx(o){let t=o.target,e=t.textContent==Ko;t.textContent=e?kC:Ko;let n=t.parentNode;t.setAttribute("aria-expanded",e?"true":"false"),n.setAttribute("aria-expanded",e?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let i=s,r=i.getAttribute("data-adapt-class");if(r==="toc-container"){if(i.setAttribute("aria-hidden",e?"false":"true"),i.firstChild){s=i.firstChild;continue}}else if(r==="toc-node"&&(i.style.height=e?"auto":"0px",i.children.length>=2&&(i.children[1].tabIndex=e?0:-1),i.children.length>=3&&(i.children[0].tabIndex=e?0:-1,!e))){let a=i.children[0];if(a.textContent==kC){a.textContent=Ko,a.setAttribute("aria-expanded","false"),i.setAttribute("aria-expanded","false"),s=i.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}o.stopPropagation()}var Zo=class extends Rc{constructor(){super(null);p(this,"plainXMLStore");p(this,"jsonStore");p(this,"opfByURL",{});p(this,"primaryOPFByEPubURL",{});p(this,"deobfuscators",{});p(this,"documents",{});this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=TC(),this.jsonStore=hg()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,n,s){return this.plainXMLStore.load(e,n,s)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,n,s){return this.jsonStore.load(e,n,s)}loadPubDoc(e){let n=A("loadPubDoc");return Qs(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(i=>{if(i){n.finish(i);return}F.error(`Failed to fetch a source document from ${e} (${s.status}${s.statusText?" "+s.statusText:""})`),n.finish(null)});else if(!s.status&&!s.responseXML&&!s.responseText&&!s.responseBlob&&!s.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),s.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,i,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,r).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),n.finish(null);return}let r=new Si(this,e);r.initWithWebPubManifest(i,void 0,e).then(()=>{n.finish(r)})}):this.loadWebPub(e).then(i=>{if(i){n.finish(i);return}this.loadEPUBDoc(e).then(r=>{if(r){n.finish(r);return}F.error(`Failed to load ${e}.`),n.finish(null)})})}),n.result()}loadEPUBDoc(e){let n=A("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(i=>{if(i){let r=i.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let a of r)if(a){this.loadOPF(e,a).thenFinish(n);return}}n.finish(null)}),n.result()}loadOPF(e,n){let s=e+n,i=this.opfByURL[s];if(i)return T(i);let r=A("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(i=new Si(this,e),this.opfByURL[s]=i,this.primaryOPFByEPubURL[e]=i,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{i.initWithXMLDoc(a,l).then(()=>{r.finish(i)})}):i.initWithXMLDoc(a,null).then(()=>{r.finish(i)})):this.reportLoadError(s)}),r.result()}loadWebPub(e){let n=A("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let i=s.document,r=new Si(this,e),a=i.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=Ni(i.getElementById(l.substr(1)).textContent);r.initWithWebPubManifest(c,i).then(()=>{n.finish(r)})}else{let c=te(a.getAttribute("href"),e);this.loadAsJSON(c,!0,`Failed to fetch Publication Manifest ${c}`).then(u=>{r.initWithWebPubManifest(u,i,c).then(()=>{n.finish(r)})})}}else r.initWithWebPubManifest({},i).then(()=>{r.toc&&r.toc.src===s.url&&Vc(i).length===0&&(r.toc=null),n.finish(r)})}}),n.result()}addDocument(e,n){let s=A("EPUBDocStore.load"),i=Xt(e);return(this.documents[i]=this.parseOPSResource({status:200,statusText:"",url:i,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=i=>i.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let i=n(e);return!(i===n(In)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===i)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?F.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&In.startsWith("https:")?F.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?F.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):F.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=Xt(e),s=this.documents[n];if(s)return s.isPending()?s:T(s.get());{let i=A("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(r=>{r?i.finish(r):this.reportLoadError(n)}),i.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},i;for(;(i=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(i[0].length),s[i[1]]=i[2];let r=s.width-0,a=s.height-0;if(r&&a){let l=!!Object.values(this.primaryOPFByEPubURL).find(c=>c.prePaginated);return`@-epubx-viewport{width:${r}px;height:${a}px;}`+(l?`@page{size:${r}px ${a}px;margin:0;}`:"@page{margin:0;}")}return""}},Bc=class{constructor(){p(this,"id",null);p(this,"src","");p(this,"mediaType",null);p(this,"title",null);p(this,"itemRefElement",null);p(this,"spineIndex",-1);p(this,"compressedSize",0);p(this,"compressed",null);p(this,"epage",0);p(this,"epageCount",0);p(this,"startPage",null);p(this,"skipPagesBefore",null);p(this,"itemProperties");this.itemProperties=If}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=te(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=Bf(n.split(/\s+/)))}initWithParam(t){this.spineIndex=t.index,this.id=`item${t.index+1}`,this.src=t.url,this.startPage=t.startPage,this.skipPagesBefore=t.skipPagesBefore}};function tS(o){return o.id}function nS(o){return t=>{let e=A("deobfuscator");return sS("SHA-1",o).then(n=>{let s=t.slice(0,1040),i=t.slice(1040,t.size);dg(s).then(r=>{let a=new DataView(r);for(let l=0;l<a.byteLength;l++){let c=a.getUint8(l);c^=n[l%20],a.setUint8(l,c)}e.finish(ed([a,i]))})}),e.result()}}function sS(o,t){let e=A("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(o,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var Bs={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"},qo="http://idpf.org/epub/vocab/package/meta/#",Ve={language:`${Bs.dcterms}language`,title:`${Bs.dcterms}title`,creator:`${Bs.dcterms}creator`,layout:`${Bs.rendition}layout`,titleType:`${qo}title-type`,displaySeq:`${qo}display-seq`,alternateScript:`${qo}alternate-script`,role:`${qo}role`};function iS(o,t){let e={};return(n,s)=>{var d,h,f,g,m,y;let i,r,a=n.r||e,l=s.r||e;if(o==Ve.title&&(i=((d=a[Ve.titleType])==null?void 0:d[0].v)=="main",r=((h=l[Ve.titleType])==null?void 0:h[0].v)=="main",i!=r))return i?-1:1;let c=parseInt((f=a[Ve.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[Ve.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:o!=Ve.language&&t&&(i=((m=a[Ve.language]||a[Ve.alternateScript])==null?void 0:m[0].v)==t,r=((y=l[Ve.language]||l[Ve.alternateScript])==null?void 0:y[0].v)==t,i!=r)?i?-1:1:n.o-s.o}}function rS(o,t){let e;if(!t)e=Bs;else{e={};for(let h in Bs)e[h]=Bs[h];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),e[d[1]]=d[2]}let n=d=>{if(d){let h=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(h){let f=h[2]?e[h[2]]:qo;if(f)return f+h[3]}}return null},s=1,i=o.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let h=n(d.getAttribute("property"));if(h)return{name:h,value:d.textContent,id:d.getAttribute("id"),order:s++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:Bs.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),r=la(i,d=>d.refines),a=d=>Of(d,(h,f)=>h.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let y=r[`#${g.id}`]||[];if(y.length||g.lang||g.role){g.lang&&y.push({name:Ve.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&y.push({name:Ve.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let S=la(y,C=>C.name);m.r=a(S)}return m})),l=a(la(i,d=>d.refines?null:d.name)),c=null;l[Ve.language]&&(c=l[Ve.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(iS(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function oS(){let o=window.MathJax;return o?o.Hub:null}var LC={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},gf="viv-id-",Si=class{constructor(t,e){this.store=t;this.pubURL=e;p(this,"opfXML",null);p(this,"encXML",null);p(this,"items",null);p(this,"spine",null);p(this,"itemMap",null);p(this,"itemMapByPath",null);p(this,"uid",null);p(this,"bindings",{});p(this,"lang",null);p(this,"epageCount",0);p(this,"prePaginated",!1);p(this,"epageIsRenderedPage",!0);p(this,"epageCountCallback",null);p(this,"metadata",{});p(this,"toc",null);p(this,"cover",null);p(this,"fallbackMap",{});p(this,"pageProgression",null);p(this,"documentURLTransformer");this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let t=this;class e{transformFragment(s,i){let r=i+(s?`#${s}`:"");return gf+iu(r,":")}transformURL(s,i){let r=s.match(/^([^#]*)#?(.*)$/);if(r){let a=r[1]||i.replace(/\?viv-toc-box$/,""),l=decodeURIComponent(r[2]);if(a&&t.spine.some(c=>c.src===a))return`#${this.transformFragment(l,a)}`}return s}restoreURL(s){s.charAt(0)==="#"&&(s=s.substring(1)),s.indexOf(gf)===0&&(s=s.substring(gf.length));let r=Ff(s,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new e}getMetadata(){return this.metadata}getPathFromURL(t){if(t.startsWith("data:"))return t===this.pubURL?"":t;if(this.pubURL){let e=te("",this.pubURL);return t===e||t+"/"===e?"":(e.charAt(e.length-1)!="/"&&(e+="/"),t.substr(0,e.length)==e?decodeURIComponent(t.substr(e.length)):null)}else return t}initWithXMLDoc(t,e){this.opfXML=t,this.encXML=e;let n=t.doc().child("package"),s=n.attribute("unique-identifier")[0];if(s){let c=t.getElement(`${t.url}#${s}`);c&&(this.uid=c.textContent.replace(/[ \n\r\t]/g,""))}let i={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new Bc,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!LC[u.mediaType]&&(i[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=ru(this.items,tS),this.itemMapByPath=ru(this.items,c=>this.getPathFromURL(c.src));for(let c in i){let u=c;for(;;){let d=this.itemMap[i[u]];if(!d)break;if(LC[d.mediaType]){this.fallbackMap[c]=d.src;break}u=d.src}}this.spine=n.child("spine").child("itemref").asArray().map((c,u)=>{let d=c,h=d.getAttribute("idref"),f=this.itemMap[h];return f&&(f.itemRefElement=d,f.spineIndex=u),f});let r=n.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=jc(r));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(df.withChild("EncryptionMethod",df.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],l=n.child("bindings").child("mediaType").asArray();for(let c=0;c<l.length;c++){let u=l[c].getAttribute("handler"),d=l[c].getAttribute("media-type");d&&u&&this.itemMap[u]&&(this.bindings[d]=this.itemMap[u].src)}if(this.metadata=rS(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[Ve.language]&&(this.lang=this.metadata[Ve.language][0].v),this.metadata[Ve.layout]&&(this.prePaginated=this.metadata[Ve.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=nS(this.uid);for(let u=0;u<a.length;u++)this.store.deobfuscators[this.pubURL+a[u]]=c}return this.prePaginated&&this.assignAutoPages(),T(!0)}assignAutoPages(){let t=0;for(let e of this.spine){let n=this.prePaginated?1:Math.ceil(e.compressedSize/1024);e.epage=t,e.epageCount=n,t+=n}this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(t){this.epageIsRenderedPage=t||this.prePaginated}countEPages(t){if(this.epageCountCallback=t,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),T(!0);let e=0,n=0,s=A("countEPages");return s.loopWithFrame(i=>{if(n===this.spine.length){i.breakLoop();return}let r=this.spine[n++];r.epage=e,this.store.load(r.src).then(a=>{let l=1800,c=a.lang||this.lang;c&&c.match(/^(ja|ko|zh)/)&&(l/=3),r.epageCount=Math.ceil(a.getTotalOffset()/l),e+=r.epageCount,this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount),i.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new Yo(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let i=new Bc;i.initWithParam(s),i.id;let r=n.document.createElement("itemref");r.setAttribute("idref",i.id),n.root.appendChild(r),i.itemRefElement=r,this.itemMap[i.id]=i;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=i,this.items.push(i)}),e?this.store.addDocument(t[0].url,e):T(null)}initWithWebPubManifest(t,e,n){var h,f,g,m;t.readingProgression&&(this.pageProgression=t.readingProgression),this.metadata===void 0&&(this.metadata={});let s=t.name||((h=t.metadata)==null?void 0:h.title)||(e==null?void 0:e.title);s&&(this.metadata[Ve.title]=(Array.isArray(s)?s:[s]).map(y=>{var S;return{v:(S=y.value)!=null?S:y}}));let i=t.author||t.creator||((f=t.metadata)==null?void 0:f.author)||Array.from((g=e==null?void 0:e.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?g:[]).map(y=>y.content);i&&i.length!==0&&(this.metadata[Ve.creator]=(Array.isArray(i)?i:[i]).map(y=>{var S;return{v:(S=y.name)!=null?S:y}}));let r=t.inLanguage||((m=t.metadata)==null?void 0:m.language)||(e==null?void 0:e.documentElement.lang)||(e==null?void 0:e.documentElement.getAttribute("xml:lang"));r&&(this.metadata[Ve.language]=(Array.isArray(r)?r:[r]).map(y=>({v:y})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let y of AC(e)){let S=y.getAttribute("href");if(/^(https?:)?\/\//.test(S)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(S))continue;let C=Xt(te(S,this.pubURL)),x=this.getPathFromURL(C),v=x!==null?encodeURI(x):C;t.readingOrder.indexOf(v)==-1&&t.readingOrder.push(v)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(y=>{y instanceof Array&&y.forEach(S=>{let C=y===t.readingOrder,x=typeof S=="string"?S:S.url||S.href,v=typeof S=="string"?"":S.encodingFormat||S.href&&S.type||"";if(C||v==="text/html"||v==="application/xhtml+xml"||!v&&S.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(x)){let E=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,N={url:te(ns(x),E),index:c++,startPage:null,skipPagesBefore:null};S.rel==="contents"&&u===-1&&(u=N.index),l.push(N)}})});let d=A("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var S,C;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(S=this.items)==null?void 0:S[0]:this.itemMapByPath[a]);let y=(C=t.readingOrder)==null?void 0:C.length;y&&y<this.items.length&&this.items.splice(y),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=A("getCFI");return this.store.load(n.src).then(i=>{let r=i.getNodeByOffset(e),a=null;if(r){let l=i.getNodeOffset(r,0,!1),c=e-l,u=new vr;u.prependPathFromNode(r,c,!1,null),n.itemRefElement&&u.prependPathFromNode(n.itemRefElement,0,!1,null),a=u.toString()}s.finish(a)}),s.result()}resolveFragment(t){return Dn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new vr;n.fromString(t);let s;if(this.opfXML){let i=n.navigate(this.opfXML.document);if(i.node.nodeType!=1||i.after||!i.ref){e.finish(null);return}let r=i.node,a=r.getAttribute("idref");if(r.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=i.ref}else s=this.spine[0];this.store.load(s.src).then(i=>{let r=n.navigate(i.document),a=i.getNodeOffset(r.node,r.offset,r.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Dn("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let i=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);i==-1&&(i=this.spine.length-1);let r=this.spine[i];(!r||r.epageCount==0)&&(r=this.spine[--i]);let a=Math.floor(t-r.epage);e.finish({spineIndex:i,offsetInItem:-1,pageIndex:a});return}let n=Vt(this.spine.length,i=>{let r=this.spine[i];return r.epage+r.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(i=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let r=0;if(t>0){let a=i.getTotalOffset();r=Math.round(a*t/s.epageCount),r==a&&r--}e.finish({spineIndex:n,offsetInItem:r,pageIndex:-1})})},(e,n)=>{F.warn(n,"Cannot resolve epage:",t),e.finish(null)})}getEPageFromPosition(t){let e=this.spine[t.spineIndex];if(this.epageIsRenderedPage){let s=e.epage+t.pageIndex;return T(s)}if(t.offsetInItem<=0)return T(e.epage);let n=A("getEPage");return this.store.load(e.src).then(s=>{let i=s.getTotalOffset(),r=Math.min(i,t.offsetInItem);n.finish(e.epage+r*e.epageCount/i)}),n.result()}},Fc=(o,t)=>({page:o,position:{spineIndex:o.spineIndex,pageIndex:t,offsetInItem:o.offset}}),Oc=class{constructor(t,e,n,s,i){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=i;p(this,"spineItems",[]);p(this,"spineItemLoadingContinuations",[]);p(this,"pref");p(this,"clientLayout");p(this,"counterStore");p(this,"cmykStore");p(this,"tocAutohide",!1);p(this,"tocVisible",!1);p(this,"tocView");this.pref=Ta(s),this.clientLayout=new wc(e),this.counterStore=new Ba(t.documentURLTransformer),this.cmykStore=new Vr}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}waitForPreviousSpines(t,e){if(e||t===0)return T(!0);let n=A("waitForPreviousSpines");return n.loopWithFrame(s=>{let i=!0;for(let r=0;r<t;r++){let a=this.spineItems[r];if(!a||!a.complete){i=!1;break}}i?s.breakLoop():n.sleep(100).then(()=>{s.continueLoop()})}).then(()=>{n.finish(!0)}),n.result()}getCurrentPageProgression(t){if(this.opf.pageProgression)return this.opf.pageProgression;{let e=this.spineItems[t?t.spineIndex:0];return e?e.instance.pageProgression:null}}finishPageContainer(t,e,n){e.container.style.display="none",e.container.style.visibility="visible",e.container.style.position="",e.container.style.top="",e.container.style.left="",e.container.setAttribute("data-vivliostyle-page-side",e.side);let s=t.pages[n];if(e.isFirstPage=t.item.spineIndex==0&&n==0,t.pages[n]=e,this.opf.epageIsRenderedPage){if(n==0&&t.item.spineIndex>0){let i=this.opf.spine[t.item.spineIndex-1];t.item.epage=i.epage+i.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((i,r)=>i+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(s)t.instance.viewport.contentContainer.replaceChild(e.container,s.container),s.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:e});else{let i=null;if(n>0)i=t.pages[n-1].container.nextElementSibling;else for(let r=t.item.spineIndex+1;r<this.spineItems.length;r++){let a=this.spineItems[r];if(a&&a.pages[0]){i=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,i)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}renderSinglePage(t,e){let n=A("renderSinglePage"),s=t.pages[e?e.page:0],i=this.makePage(t,e);return s&&(i.pageType=s.pageType),t.instance.layoutNextPage(i,e).then(r=>{e=r;let a=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,i,a),this.counterStore.finishPage(i.spineIndex,a);let l=null;if(e){let c=t.layoutPositions[e.page];t.layoutPositions[e.page]=e,c&&t.pages[e.page]&&(e.isSamePosition(c)||(l=this.renderSinglePage(t,e)))}l||(l=T(!0)),l.then(()=>{let c=this.counterStore.getUnresolvedRefsToPage(i),u=0;n.loopWithFrame(d=>{if(u++,u>c.length){d.breakLoop();return}let h=c[u-1];if(h.refs=h.refs.filter(f=>!f.isResolved()),h.refs.length===0){d.continueLoop();return}this.getPageViewItem(h.spineIndex).then(f=>{if(!f){d.continueLoop();return}let{currentPageType:g,previousPageType:m}=f.instance.styler.cascade,y=f.instance.scopes;f.instance.scopes={},this.counterStore.pushPageCounters(h.pageCounters),this.counterStore.pushReferencesToSolve(h.refs);let S=f.layoutPositions[h.pageIndex];this.renderSinglePage(f,S).then(C=>{f.instance.styler.cascade.currentPageType=g,f.instance.styler.cascade.previousPageType=m,f.instance.scopes=y,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let x=C.pageAndPosition.position;x.spineIndex===i.spineIndex&&x.pageIndex===a&&(i=C.pageAndPosition.page),d.continueLoop()})})}).then(()=>{i.container.parentElement||(i=t.pages[a]),i.isLastPage=!e&&t.item.spineIndex===this.opf.spine.length-1,i.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),i.container.setAttribute("data-vivliostyle-page-index",a),i.container.setAttribute("data-vivliostyle-spine-index",i.spineIndex),n.finish({pageAndPosition:Fc(i,a),nextLayoutPosition:e})})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let i=Vt(e.layoutPositions.length,r=>e.instance.getPosition(e.layoutPositions[r],!0)>s);i===e.layoutPositions.length?e.complete?n=e.layoutPositions.length-1:n=Number.POSITIVE_INFINITY:n=i-1}else n===Number.POSITIVE_INFINITY&&t.offsetInItem!==-1&&(s=t.offsetInItem);return{spineIndex:t.spineIndex,pageIndex:n,offsetInItem:s}}findPage(t,e){let n=A("findPage");return this.waitForPreviousSpines(t.spineIndex,e).then(()=>{this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let i=null,r;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);r=l.pageIndex,i=s.pages[r],i?a.breakLoop():s.complete?(r=s.layoutPositions.length-1,i=s.pages[r],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(i=c.page,r=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(Fc(i,r))})})}),n.result()}renderPage(t){let e=A("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),i=s.pageIndex,r=s.offsetInItem,a=n.pages[i];if(a){e.finish(Fc(a,i));return}e.loopWithFrame(l=>{if(i<n.layoutPositions.length){l.breakLoop();return}if(n.complete){i=n.layoutPositions.length-1,l.breakLoop();return}let c=n.layoutPositions[n.layoutPositions.length-1];this.renderSinglePage(n,c).then(u=>{let d=u.pageAndPosition.page;if(c=u.nextLayoutPosition,c){if(r>=0&&n.instance.getPosition(c)>r){a=d,i=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,i=u.pageAndPosition.position.pageIndex,n.complete=!0,l.breakLoop()})}).then(()=>{a=a||n.pages[i];let l=n.layoutPositions[i];if(a){e.finish(Fc(a,i));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||(n.complete=!0),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=A("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(e=>{t.loopWithFrame(n=>{this.spineItems.some(s=>s==null?void 0:s.pages.some(i=>i==null?void 0:i.fetchers.some(r=>!r.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=A("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,i=t.pageIndex,r=0;e&&(r=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:r,pageIndex:r===s?i:Number.POSITIVE_INFINITY,offsetInItem:r===s?t.offsetInItem:-1};this.renderPage(c).then(u=>{a=u,++r>s?l.breakLoop():l.continueLoop()})}).then(()=>{n.finish(a)}),n.result()}firstPage(t,e){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},e)}lastPage(t,e){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},e)}nextPage(t,e){let n=t.spineIndex,s=t.pageIndex,i=A("nextPage");return this.getPageViewItem(n).then(r=>{if(!r){i.finish(null);return}if(r.complete&&s==r.layoutPositions.length-1){if(n>=this.opf.spine.length-1){i.finish(null);return}n++,s=0;let a=this.spineItems[n],l=a&&a.pages[0],c=r.pages[r.pages.length-1];l&&c&&l.side==c.side&&(a.pages.forEach(u=>{u.container&&u.container.remove()}),this.spineItems[n]=null,this.spineItemLoadingContinuations[n]=null)}else s++;this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e).thenFinish(i)}),i.result()}previousPage(t,e){let n=t.spineIndex,s=t.pageIndex;if(s==0){if(n==0)return T(null);n--,s=Number.POSITIVE_INFINITY}else s--;return this.findPage({spineIndex:n,pageIndex:s,offsetInItem:-1},e)}isRectoPage(t,e){let n=t.side==="left",s=this.getCurrentPageProgression(e)==="ltr";return!n&&s||n&&!s}getSpread(t,e){let n=this.getPage(t);if(!n)return T({left:null,right:null});let s=A("getSpread"),i=n.side==="left",r;return this.isRectoPage(n,t)?r=this.previousPage(t,e):r=this.nextPage(t,e),r.then(a=>{let l=this.getPage(t),c=a&&a.page;c&&c.side===l.side&&(c=null),i?s.finish({left:l,right:c}):s.finish({left:c,right:l})}),s.result()}nextSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),i=this.nextPage(t,e);return s?i:i.thenAsync(r=>{if(r){if(r.page.side===n.side)return i;let a=this.nextPage(r.position,e);return a.thenAsync(l=>l?a:i)}else return T(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),i=this.previousPage(t,e),r=n.container.previousElementSibling;return s?i.thenAsync(a=>a?a.page.side===n.side||a.page.container!==r?i:this.previousPage(a.position,e):T(null)):i}navigateToEPage(t,e,n){let s=A("navigateToEPage");return this.opf.resolveEPage(t).then(i=>{i?this.findPage(i,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=A("navigateToCFI");return this.opf.resolveFragment(t).then(i=>{i?this.findPage(i,n).thenFinish(s):s.finish(null)}),s.result()}navigateTo(t,e,n){F.debug("Navigate to",t);let s=this.opf.getPathFromURL(Xt(t));if(!s){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))s=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let a=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(s=this.opf.getPathFromURL(a[0]),s==null&&(s=a[0])):s=a[0],t=a[0]+(a[1]?`#${a[1]}`:"")}if(s==null)return T(null)}let i=this.opf.itemMapByPath[s];if(!i){if(this.opf.opfXML&&s==this.opf.getPathFromURL(this.opf.opfXML.url)){let a=t.indexOf("#");if(a>=0)return this.navigateToFragment(t.substr(a+1),e,n)}return T(null)}let r=A("navigateTo");return this.waitForPreviousSpines(i.spineIndex,n).then(()=>{this.getPageViewItem(i.spineIndex).then(a=>{if(!a){r.finish(null);return}let l=a.xmldoc.getElement(t);this.findPage({spineIndex:i.spineIndex,pageIndex:-1,offsetInItem:l?a.xmldoc.getElementOffset(l):0},n).thenFinish(r)})}),r.result()}makePage(t,e){let n=t.instance.viewport,s=n.document.createElement("div");s.setAttribute("data-vivliostyle-page-container","true"),s.role="presentation",Ds||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let i=n.document.createElement("div");i.setAttribute("data-vivliostyle-bleed-box","true"),i.role="presentation",s.appendChild(i);let r=new Zi(s,i);if(r.spineIndex=t.item.spineIndex,r.position=e,r.offset=t.instance.getPosition(e),r.offset===0&&!(t.instance.blankPageAtStart&&t.pages.length===0)){let a=this.opf.documentURLTransformer.transformFragment("",t.item.src);i.setAttribute("id",a),r.registerElementWithId(i,a)}if(n!==this.viewport){let a=cu(this.viewport.width,this.viewport.height,n.width,n.height),l=En(null,new Xe(a,null),"");r.delayedItems.push(new Cs(s,"transform",l))}return r}makeObjectView(t,e,n,s){let i=e.getAttribute("data"),r=null;if(i){i=te(i,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(i);if(l){let c=this.opf.itemMapByPath[l];c&&(a=c.mediaType)}}if(a){let l=this.opf.bindings[a];if(l){r=this.viewport.document.createElement("iframe"),r.style.border="none";let c=nu(i),u=nu(a),d=new st;d.append(l),d.append("?src="),d.append(c),d.append("&type="),d.append(u);for(let g=e.firstChild;g;g=g.nextSibling)if(g.nodeType==1){let m=g;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let y=m.getAttribute("name"),S=m.getAttribute("value");y&&S&&(d.append("&"),d.append(encodeURIComponent(y)),d.append("="),d.append(encodeURIComponent(S)))}}r.setAttribute("src",d.toString());let h=e.getAttribute("width");h&&r.setAttribute("width",h);let f=e.getAttribute("height");f&&r.setAttribute("height",f)}}}return r||(r=this.viewport.document.createElement("object"),i&&r.setAttribute("data",i),r.setAttribute("data-adapt-process-children","true")),T(r)}makeMathJaxView(t,e,n,s){let i=oS();if(i){let r=n.ownerDocument,a=r.createElement("span");n.appendChild(a);let l=r.importNode(e,!0);this.resolveURLsInMathML(l,t),a.appendChild(l);let c=i.queue;c.Push(["Typeset",i,a]);let u=A("makeMathJaxView"),d=u.suspend();return c.Push(()=>{d.schedule(a)}),u.result()}return T(null)}resolveURLsInMathML(t,e){if(t!=null){if(t.nodeType===1&&t.tagName==="mglyph"){let n=Array.from(t.attributes);for(let s of n){if(s.name!=="src")continue;let i=te(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,i):t.setAttribute(s.name,i)}}t.firstChild&&this.resolveURLsInMathML(t.firstChild,e),t.nextSibling&&this.resolveURLsInMathML(t.nextSibling,e)}}makeCustomRenderer(t){return(e,n,s)=>e.localName=="object"&&e.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(t,e,n,s):e.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(t,e,n,s):e.dataset&&e.dataset.mathTypeset=="true"?this.makeMathJaxView(t,e,n,s):T(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return T(null);let e=this.spineItems[t];if(e)return T(e);let n=A("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let i=this.opf.spine[t],r=this.opf.store;return r.load(i.src).then(a=>{var x;let l=i.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),i.title=a.document.title;let c=r.getStyleForDoc(a),u=this.makeCustomRenderer(a),d=this.viewport,h=c.sizeViewport(d.width,d.height,d.fontSize,this.pref);(h.width!=d.width||h.height!=d.height||h.fontSize!=d.fontSize)&&(d=new Jn(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(x=this.spineItems[0])==null?void 0:x.instance.isVersoFirstPage,g=this.spineItems[t-1],m,y;if(i.startPage!==null)m=i.startPage-1,y=m;else{if(t>0&&(!g||!g.complete))m=i.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,y=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let v=this.counterStore.currentPageCounters.page;y=!v||!v.length?m:v[v.length-1]}i.skipPagesBefore!==null&&(m+=i.skipPagesBefore,y+=i.skipPagesBefore)}this.counterStore.forceSetPageCounter(y);let S=new Fs(c,a,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);S.pref=this.pref;let C=this.opf.metadata&&this.opf.metadata[Ve.title];S.pubTitle=C&&C[0]&&C[0].v||"",S.docTitle=i.title||"",S.init().then(()=>{!this.opf.pageProgression&&S.pageProgression&&(this.opf.pageProgression=S.pageProgression),e={item:i,xmldoc:a,instance:S,layoutPositions:[null],pages:[],complete:!1},this.spineItems[t]=e,n.finish(e),s.forEach(v=>{v.schedule(e)})})}),n.result()}removeRenderedPages(){let t=this.spineItems;for(let e of t)e&&e.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let t=this.spineItems;for(let e of t)if(e){let n=e.pages;for(let s of n)if(s.isAutoPageWidth&&s.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(t=>t&&t.pages.length>0)}showTOC(t){let e=this.opf,n=e.toc;if(this.tocAutohide=t,!n)return T(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),T(this.tocView.page);let s=A("showTOC");this.tocView||(this.tocView=new Ic(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore,this.cmykStore));let i=this.viewport,r=Math.min(344,Math.round(.67*i.width)-16),a=i.height-6,l=i.document.createElement("div");return i.root.appendChild(l),Ds||(l.style.visibility="hidden"),l.style.width=`${r+16}px`,l.style.maxHeight=`${a}px`,l.setAttribute("data-vivliostyle-toc-box","true"),l.setAttribute("role","navigation"),this.tocView.showTOC(l,i,r,a,this.viewport.fontSize).then(c=>{l.style.visibility="visible",l.setAttribute("aria-hidden","false"),s.finish(c)}),s.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}};var RC="data-vivliostyle-viewer-status",lS="data-vivliostyle-spread-view",mf=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(mf||{}),Dc=class{constructor(t,e,n,s){this.window=t;this.viewportElement=e;this.instanceId=n;this.callbackFn=s;p(this,"fontMapper");p(this,"kick");p(this,"sendCommand");p(this,"resizeListener");p(this,"hyperlinkListener");p(this,"pageRuleStyleElement");p(this,"pageSheetSizeAlreadySet",!1);p(this,"renderTask",null);p(this,"actions");p(this,"readyState");p(this,"packageURL");p(this,"opf");p(this,"touchActive");p(this,"touchX");p(this,"touchY");p(this,"needResize");p(this,"resized");p(this,"needRefresh");p(this,"viewportSize");p(this,"currentPage");p(this,"currentSpread");p(this,"pagePosition");p(this,"fontSize");p(this,"zoom");p(this,"fitToScreen");p(this,"pageViewMode");p(this,"waitForLoading");p(this,"renderAllPages");p(this,"pref");p(this,"pageSizes");p(this,"pixelRatio");p(this,"pixelRatioLimit");p(this,"viewport");p(this,"opfView");let i=e.ownerDocument,r=(a,l)=>{let c=i.getElementById(a);return c||(c=i.createElement("style"),c.id=a,l&&(c.textContent=l),i.head.appendChild(c)),c};r("vivliostyle-viewport-screen-css",Xu),r("vivliostyle-viewport-css",$u),r("vivliostyle-polyfill-css",Qu),e.setAttribute("data-vivliostyle-viewer-viewport",!0),Ds&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(RC,"loading"),this.fontMapper=new hc(i.head,e),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=a=>{},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=lu(),this.pageSizes=[],this.pixelRatioLimit=oa==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=qc;F.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),F.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),F.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),F.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){this.readyState!==t&&(this.readyState=t,this.viewportElement.setAttribute(RC,t),this.callback({t:"readystatechange"}))}loadPublication(t){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,i=t.userStyleSheet;this.viewport=null;let r=A("loadPublication");return this.configure(t).then(()=>{let a=new Zo;a.init(s,i).then(()=>{let l=te(ns(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.render(n).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(t){nt.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,i=t.authorStyleSheet,r=t.userStyleSheet;this.viewport=null;let a=A("loadXML");return this.configure(t).then(()=>{let l=new Zo;l.init(i,r).then(()=>{let c=e.map((u,d)=>({url:te(ns(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Si(l,""),this.opf.initWithChapters(c,n).then(()=>{this.render(s).then(()=>{a.finish(!0)})})})}),a.result()}render(t){this.cancelRenderingTask();let e;return t?e=this.opf.resolveFragment(t).thenAsync(n=>(this.pagePosition=n,T(!0))):e=T(!0),e.thenAsync(()=>(nt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let i=s[0];if(i==="em"||i==="rem")return e*this.fontSize;let r=Je[i];if(r)return e*r}return e}configure(t){if(typeof t.autoresize=="boolean"&&(t.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof t.fontSize=="number"){let e=t.fontSize;e>=5&&e<=72&&this.fontSize!=e&&(this.fontSize=e,this.needResize=!0)}if(typeof t.viewport=="object"&&t.viewport){let e=t.viewport,n={marginLeft:this.resolveLength(e["margin-left"])||0,marginRight:this.resolveLength(e["margin-right"])||0,marginTop:this.resolveLength(e["margin-top"])||0,marginBottom:this.resolveLength(e["margin-bottom"])||0,width:this.resolveLength(e.width)||0,height:this.resolveLength(e.height)||0};(n.width>=200||n.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=n,this.needResize=!0)}if(typeof t.hyphenate=="boolean"&&(this.pref.hyphenate=t.hyphenate,this.needResize=!0),typeof t.horizontal=="boolean"&&(this.pref.horizontal=t.horizontal,this.needResize=!0),typeof t.nightMode=="boolean"&&(this.pref.nightMode=t.nightMode,this.needResize=!0),typeof t.lineHeight=="number"&&(this.pref.lineHeight=t.lineHeight,this.needResize=!0),typeof t.columnWidth=="number"&&(this.pref.columnWidth=t.columnWidth,this.needResize=!0),typeof t.fontFamily=="string"&&(this.pref.fontFamily=t.fontFamily,this.needResize=!0),typeof t.load=="boolean"&&(this.waitForLoading=t.load),typeof t.renderAllPages=="boolean"&&(this.renderAllPages=t.renderAllPages),typeof t.userAgentRootURL=="string"&&(Qc(t.userAgentRootURL.replace(/resources\/?$/,"")),Jc(t.userAgentRootURL)),typeof t.rootURL=="string"&&(Qc(t.rootURL),Jc(`${In}resources/`)),typeof t.pageViewMode=="string"&&t.pageViewMode!==this.pageViewMode&&(this.pageViewMode=t.pageViewMode,this.needResize=!0),typeof t.pageBorder=="number"&&t.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=t.pageBorder,this.needResize=!0),typeof t.zoom=="number"&&t.zoom!==this.zoom&&(this.zoom=t.zoom,this.needRefresh=!0),typeof t.fitToScreen=="boolean"&&t.fitToScreen!==this.fitToScreen&&(this.fitToScreen=t.fitToScreen,this.needRefresh=!0),typeof t.defaultPaperSize=="object"&&typeof t.defaultPaperSize.width=="number"&&typeof t.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=t.defaultPaperSize,this.needResize=!0),typeof t.allowScripts=="boolean"&&t.allowScripts!==pn&&(xC(t.allowScripts),this.needResize=!0),typeof t.pixelRatio=="number"){let e=Math.min(t.pixelRatio,this.pixelRatioLimit);e!==this.pixelRatio&&(this.pixelRatio=e,this.needResize=!0)}return this.configurePlugins(t),T(!0)}configurePlugins(t){Ze("CONFIGURATION").forEach(n=>{let s=n(t);this.needResize=s.needResize||this.needResize,this.needRefresh=s.needRefresh||this.needRefresh})}pageReplacedListener(t){let e=this.currentPage,n=this.currentSpread,s=t.target;n?(n.left===s||n.right===s)&&this.showCurrent(t.newPage):e===t.target&&this.showCurrent(t.newPage)}forCurrentPages(t){let e=[];this.currentPage&&e.push(this.currentPage),this.currentSpread&&(e.push(this.currentSpread.left),e.push(this.currentSpread.right)),e.forEach(n=>{n&&t(n)})}removePageListeners(){this.forCurrentPages(t=>{t.removeEventListener("hyperlink",this.hyperlinkListener,!1),t.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(t=>{w(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),w(t.container,"visibility","visible"),w(t.container,"display","block")}showPage(t){this.hidePages(),this.currentPage=t,t.container.style.marginLeft="",t.container.style.marginRight="",this.showSinglePage(t)}showSpread(t){if(this.hidePages(),this.currentSpread=t,t.left&&t.right){let e=parseFloat(t.left.container.style.width),n=parseFloat(t.right.container.style.width);e&&n&&e!==n&&(e<n?t.left.container.style.marginLeft=`${n-e}px`:t.right.container.style.marginRight=`${e-n}px`)}t.left&&(this.showSinglePage(t.left),t.right?t.left.container.removeAttribute("data-vivliostyle-unpaired-page"):t.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),t.right&&(this.showSinglePage(t.right),t.left?t.right.container.removeAttribute("data-vivliostyle-unpaired-page"):t.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let t=A("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(e=>{let n=this.currentPage;(this.waitForLoading&&n.fetchers.length>0?ds(n.fetchers):T(!0)).then(()=>{this.sendLocationNotification(n,e).thenFinish(t)})}),t.result()}createViewport(){let t=this.viewportElement;if(this.viewportSize){let e=this.viewportSize;return t.style.marginLeft=`${e.marginLeft}px`,t.style.marginRight=`${e.marginRight}px`,t.style.marginTop=`${e.marginTop}px`,t.style.marginBottom=`${e.marginBottom}px`,new Jn(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new Jn(this.window,this.fontSize,this.pixelRatio,t)}resolveSpreadView(t,e){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return t!=null&&(t.width-this.pref.pageBorder)/t.height>=(e?e.width*2/e.height:1.45)&&(!!e||t.width>800)}}updateSpreadView(t){this.pref.spreadView=t,this.viewportElement.setAttribute(lS,t.toString())}sizeIsGood(){var r;let t=this.createViewport(),e=((r=this.opfView)==null?void 0:r.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&e?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:e?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(t,e,n,s){this.pageSizes[s]=t,this.setPageSizePageRules(e,n,s),s===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,t))}setPageSizePageRules(t,e,n){var i,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((i=this.pageSizes[n-1])==null?void 0:i.width)||this.pageSizes[n].height!==((r=this.pageSizes[n-1])==null?void 0:r.height))){let c=function(m){let y=m*.75;return Math.ceil(y)};var s=c;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),u=c(a),d=c(l),h=u*((this.pixelRatio||1)-1)+2,f=d*((this.pixelRatio||1)-1)+2,g=`@page {size: ${u}pt ${d}pt; margin: 0 ${-h}pt ${-f}pt 0;}`;this.pageRuleStyleElement.textContent=g,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new Oc(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let n=this.resolveSpreadView(this.viewport,t.dimensions);return n!==this.pref.spreadView&&this.updateSpreadView(n),n?this.opfView.getSpread(this.pagePosition,e).thenAsync(s=>!s.left&&!s.right?T(null):s.left&&s.right&&(!this.resolveSpreadView(this.viewport,s.left.dimensions)||!this.resolveSpreadView(this.viewport,s.right.dimensions))?(this.updateSpreadView(!1),this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null)):(this.showSpread(s),this.setSpreadZoom(s),this.currentPage=t.side==="left"?s.left:s.right,T(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,T(null))}setPageZoom(t){var n;let e=this.getAdjustedZoomFactor(t.dimensions);(n=this.viewport)==null||n.zoom(t.dimensions.width,t.dimensions.height,e)}setSpreadZoom(t){var n;let e=this.getSpreadDimensions(t);(n=this.viewport)==null||n.zoom(e.width,e.height,this.getAdjustedZoomFactor(e))}getAdjustedZoomFactor(t){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(t):this.zoom}getSpreadDimensions(t){let e=0,n=0;return t.left&&(e+=t.left.dimensions.width,n=t.left.dimensions.height),t.right&&(e+=t.right.dimensions.width,n=Math.max(n,t.right.dimensions.height)),t.left&&t.right&&(e+=this.pref.pageBorder*2,e+=Math.abs(t.left.dimensions.width-t.right.dimensions.width)),{width:e,height:n}}queryZoomFactor(t){if(!this.currentPage)throw new Error("no page exists.");switch(t){case"fit inside viewport":{let e;return this.pref.spreadView?(this.currentSpread,e=this.getSpreadDimensions(this.currentSpread)):e=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(e)}default:throw new Error(`unknown zoom type: ${t}`)}}calculateZoomFactorToFitInsideViewPort(t){if(!this.viewport)return this.zoom;let e=this.viewport.width/t.width,n=this.viewport.height/t.height;return Math.min(e,n)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Mc),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=Dr().getScheduler().run(()=>Dn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,nt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(n=>{if(!n){e.finish(!1);return}this.pagePosition=n.position,this.showCurrent(n.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(s=>{let i={t:"nav",epageCount:s,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)&&(i.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(i)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),nt.registerEndTiming("render (resize)"),pn&&of(this.window)?vC(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),e.finish(s))})})})})})},(e,n)=>{if(n instanceof Mc)nt.registerEndTiming("render (resize)"),F.debug(n.message);else throw n}));return T(!0)}sendLocationNotification(t,e){let n=A("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:t.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(i=>{s.epage=i,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(t){var s;let e;if(this.readyState!=="complete"&&t.where!=="next"&&this.setReadyState("loading"),typeof t.where=="string"){let i;switch(t.where){case"next":i=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":i=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":i=this.opfView.lastPage;break;case"first":i=this.opfView.firstPage;break;default:return T(!0)}i&&(e=()=>i.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let i=t.epage;e=()=>this.opfView.navigateToEPage(i,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let i=t.url;e=()=>this.opfView.navigateTo(i,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let i=t.position;e=()=>this.opfView.findPage(i,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=A("moveTo");return e.call(this.opfView).then(i=>{let r;if(i){this.pagePosition=i.position;let a=A("moveTo.showCurrent");r=a.result(),this.showCurrent(i.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(a)})}else r=T(!0);r.then(a=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(a)})}),n.result()}showTOC(t){let e=!!t.autohide,n=t.v,s=this.opfView.isTOCVisible(),i=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!i)return T(!0)}else if(n=="hide")return T(!0);if(s&&n!="show")return this.opfView.hideTOC(),T(!0);{let r=A("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(i&&(a.listeners={}),e){let l=()=>{this.opfView.hideTOC()};a.addEventListener("hyperlink",l,!1)}a.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(t){let e=t.a||"";return Dn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(F.error("No such action:",e),n.finish(!0))},(n,s)=>{F.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=IC(t),n=null,s=this;ug(()=>{let i=A("commandLoop"),r=Dr().getScheduler();return s.hyperlinkListener=a=>{let l=a,c=l.href.charAt(0)==="#"||s.packageURL.some(u=>l.href.substr(0,u.length)==u);if(c){a.preventDefault();let u={t:"hyperlink",href:l.href,internal:c};r.run(()=>(s.callback(u),T(!0)))}},i.loopWithFrame(a=>{if(s.needResize)s.resize().then(()=>{a.continueLoop()});else if(s.needRefresh)s.currentPage&&s.showCurrent(s.currentPage,!this.renderAllPages).then(()=>{a.continueLoop()});else if(e){let l=e;e=null,s.runCommand(l).then(()=>{a.continueLoop()})}else{let l=A("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(i),i.result()}),s.kick=()=>{let i=n;i&&(n=null,i.schedule(!0))},s.sendCommand=i=>e?!1:(e=IC(i),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Cf=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Cf||{}),Mc=class o extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,o.prototype),this.stack=new Error().stack}};function IC(o){return typeof o=="string"?Ni(o):o}var VC=Ms;function uS(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function FC(o){let t={};return Object.keys(o).forEach(e=>{let n=o[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var Qo=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");$c(t.debug),this.adaptViewer_=new Dc(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=uS(),e&&this.setOptions(e),this.eventTarget=new ts,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},FC(t));this.adaptViewer_.sendCommand(e),Object.assign(this.options,t)}dispatcher(t){let e={type:t.t},n=t;Object.keys(n).forEach(s=>{s!=="t"&&(e[s]=n[s])}),this.eventTarget.dispatchEvent(e)}addListener(t,e){this.eventTarget.addEventListener(t,e,!1)}removeListener(t,e){this.eventTarget.removeEventListener(t,e,!1)}loadDocument(t,e,n){if(!t||(Array.isArray(t)?!t[0]||typeof t[0]!="string"&&!t[0].url:typeof t!="string"&&!t.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(t,null,e,n)}loadPublication(t,e,n){if(!t){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,t,e,n)}loadDocumentOrPublication(t,e,n,s){let i=n||{};function r(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=r(i.authorStyleSheet),l=r(i.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:dS(t)||e,document:i.documentObject,fragment:i.fragment,authorStyleSheet:a,userStyleSheet:l},FC(this.options));this.initialized?this.adaptViewer_.sendCommand(c):(this.initialized=!0,this.adaptViewer_.initEmbed(c))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(t){switch(t){case"left":return this.getCurrentPageProgression()===VC.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===VC.LTR?"next":"previous";default:return t}}navigateToPage(t,e){t==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:e}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(t)})}navigateToInternalUrl(t){this.adaptViewer_.sendCommand({a:"moveTo",url:t})}navigateToPosition(t){var e,n;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:t.spineIndex,pageIndex:(e=t.pageIndex)!=null?e:-1,offsetInItem:(n=t.offsetInItem)!=null?n:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(t,e){let n=t==null?"toggle":t?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:n,autohide:e})}queryZoomFactor(t){return this.adaptViewer_.queryZoomFactor(t)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var t,e;return(e=(t=this.adaptViewer_.opfView)==null?void 0:t.tocView)==null?void 0:e.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function dS(o){function t(n){return typeof n=="number"?n:null}function e(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(o)?o.map(e):o?[e(o)]:null}var BC=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(BC||{}),pS=Cf,hS=mf;nt.forceRegisterEndTiming("load_vivliostyle");var bf=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:i=!0,removeIframe:r=!0}){p(this,"htmlDoc");p(this,"title");p(this,"printCallback");p(this,"errorCallback");p(this,"hideIframe");p(this,"removeIframe");p(this,"iframe");p(this,"iframeWin");p(this,"window");this.htmlDoc=t,this.title=e,this.printCallback=n,this.errorCallback=s,this.hideIframe=i,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=`
1799
1800
  <!DOCTYPE html>
1800
1801
  <html data-vivliostyle-paginated="true">
1801
1802
  <head>
@@ -1823,6 +1824,6 @@ span[data-viv-leader] {
1823
1824
  <body onload='parent.printInstance.runInIframe(window)'>
1824
1825
  <div id="vivliostyle-viewer-viewport"></div>
1825
1826
  </body>
1826
- </html>`,document.body.appendChild(this.iframe)}runInIframe(t){return this.iframeWin=t,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let t=new Blob([this.htmlDoc],{type:"text/html"}),e=URL.createObjectURL(t),n=new Vr({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(s=>{n.addListener("readystatechange",()=>{n.readyState==="complete"&&s()}),this.errorCallback&&n.addListener("error",i=>{var a,l;let o=(l=(a=i.content.error)==null?void 0:a.toString())!=null?l:i.content.messages.join(`
1827
- `);this.errorCallback(o)}),n.loadDocument({url:e})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function Wx(r,t){new qh(r,t).init()}
1827
+ </html>`,document.body.appendChild(this.iframe)}runInIframe(t){return this.iframeWin=t,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let t=new Blob([this.htmlDoc],{type:"text/html"}),e=URL.createObjectURL(t),n=new Qo({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(s=>{n.addListener("readystatechange",()=>{n.readyState==="complete"&&s()}),this.errorCallback&&n.addListener("error",i=>{var a,l;let r=(l=(a=i.content.error)==null?void 0:a.toString())!=null?l:i.content.messages.join(`
1828
+ `);this.errorCallback(r)}),n.loadDocument({url:e})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function fS(o,t){new bf(o,t).init()}
1828
1829
  //# sourceMappingURL=vivliostyle.js.map