@vivliostyle/core 2.41.0 → 2.42.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,12 @@
1
- "use strict";var pb=Object.create;var Br=Object.defineProperty;var hb=Object.getOwnPropertyDescriptor;var fb=Object.getOwnPropertyNames;var gb=Object.getPrototypeOf,mb=Object.prototype.hasOwnProperty;var Gf=i=>{throw TypeError(i)};var Cb=(i,t,e)=>t in i?Br(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var bb=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),yb=(i,t)=>{for(var e in t)Br(i,e,{get:t[e],enumerable:!0})},Wf=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of fb(t))!mb.call(i,s)&&s!==e&&Br(i,s,{get:()=>t[s],enumerable:!(n=hb(t,s))||n.enumerable});return i};var xb=(i,t,e)=>(e=i!=null?pb(gb(i)):{},Wf(t||!i||!i.__esModule?Br(e,"default",{value:i,enumerable:!0}):e,i)),Sb=i=>Wf(Br({},"__esModule",{value:!0}),i);var p=(i,t,e)=>Cb(i,typeof t!="symbol"?t+"":t,e),hu=(i,t,e)=>t.has(i)||Gf("Cannot "+e);var B=(i,t,e)=>(hu(i,t,"read from private field"),e?e.call(i):t.get(i)),Z=(i,t,e)=>t.has(i)?Gf("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),we=(i,t,e,n)=>(hu(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),pe=(i,t,e)=>(hu(i,t,"access private method"),e);var qg=bb((pE,Yg)=>{var $t=-1,xt=1,et=0;function ai(i,t,e,n,s){if(i===t)return i?[[et,i]]:[];if(e!=null){var o=Hy(i,t,e);if(o)return o}var r=Pd(i,t),a=i.substring(0,r);i=i.substring(r),t=t.substring(r),r=dl(i,t);var l=i.substring(i.length-r);i=i.substring(0,i.length-r),t=t.substring(0,t.length-r);var c=Fy(i,t);return a&&c.unshift([et,a]),l&&c.push([et,l]),kd(c,s),n&&Oy(c),c}function Fy(i,t){var e;if(!i)return[[xt,t]];if(!t)return[[$t,i]];var n=i.length>t.length?i:t,s=i.length>t.length?t:i,o=n.indexOf(s);if(o!==-1)return e=[[xt,n.substring(0,o)],[et,s],[xt,n.substring(o+s.length)]],i.length>t.length&&(e[0][0]=e[2][0]=$t),e;if(s.length===1)return[[$t,i],[xt,t]];var r=By(i,t);if(r){var a=r[0],l=r[1],c=r[2],u=r[3],d=r[4],h=ai(a,c),f=ai(l,u);return h.concat([[et,d]],f)}return Vy(i,t)}function Vy(i,t){for(var e=i.length,n=t.length,s=Math.ceil((e+n)/2),o=s,r=2*s,a=new Array(r),l=new Array(r),c=0;c<r;c++)a[c]=-1,l[c]=-1;a[o+1]=0,l[o+1]=0;for(var u=e-n,d=u%2!==0,h=0,f=0,g=0,m=0,C=0;C<s;C++){for(var x=-C+h;x<=C-f;x+=2){var b=o+x,N;x===-C||x!==C&&a[b-1]<a[b+1]?N=a[b+1]:N=a[b-1]+1;for(var S=N-x;N<e&&S<n&&i.charAt(N)===t.charAt(S);)N++,S++;if(a[b]=N,N>e)f+=2;else if(S>n)h+=2;else if(d){var E=o+u-x;if(E>=0&&E<r&&l[E]!==-1){var v=e-l[E];if(N>=v)return _g(i,t,N,S)}}}for(var w=-C+g;w<=C-m;w+=2){var E=o+w,v;w===-C||w!==C&&l[E-1]<l[E+1]?v=l[E+1]:v=l[E-1]+1;for(var A=v-w;v<e&&A<n&&i.charAt(e-v-1)===t.charAt(n-A-1);)v++,A++;if(l[E]=v,v>e)m+=2;else if(A>n)g+=2;else if(!d){var b=o+u-w;if(b>=0&&b<r&&a[b]!==-1){var N=a[b],S=o+N-b;if(v=e-v,N>=v)return _g(i,t,N,S)}}}}return[[$t,i],[xt,t]]}function _g(i,t,e,n){var s=i.substring(0,e),o=t.substring(0,n),r=i.substring(e),a=t.substring(n),l=ai(s,o),c=ai(r,a);return l.concat(c)}function Pd(i,t){if(!i||!t||i.charAt(0)!==t.charAt(0))return 0;for(var e=0,n=Math.min(i.length,t.length),s=n,o=0;e<s;)i.substring(o,s)==t.substring(o,s)?(e=s,o=e):n=s,s=Math.floor((n-e)/2+e);return Wg(i.charCodeAt(s-1))&&s--,s}function Ug(i,t){var e=i.length,n=t.length;if(e==0||n==0)return 0;e>n?i=i.substring(e-n):e<n&&(t=t.substring(0,e));var s=Math.min(e,n);if(i==t)return s;for(var o=0,r=1;;){var a=i.substring(s-r),l=t.indexOf(a);if(l==-1)return o;r+=l,(l==0||i.substring(s-r)==t.substring(0,r))&&(o=r,r++)}}function dl(i,t){if(!i||!t||i.slice(-1)!==t.slice(-1))return 0;for(var e=0,n=Math.min(i.length,t.length),s=n,o=0;e<s;)i.substring(i.length-s,i.length-o)==t.substring(t.length-s,t.length-o)?(e=s,o=e):n=s,s=Math.floor((n-e)/2+e);return $g(i.charCodeAt(i.length-s))&&s--,s}function By(i,t){var e=i.length>t.length?i:t,n=i.length>t.length?t:i;if(e.length<4||n.length*2<e.length)return null;function s(f,g,m){for(var C=f.substring(m,m+Math.floor(f.length/4)),x=-1,b="",N,S,E,v;(x=g.indexOf(C,x+1))!==-1;){var w=Pd(f.substring(m),g.substring(x)),A=dl(f.substring(0,m),g.substring(0,x));b.length<A+w&&(b=g.substring(x-A,x)+g.substring(x,x+w),N=f.substring(0,m-A),S=f.substring(m+w),E=g.substring(0,x-A),v=g.substring(x+w))}return b.length*2>=f.length?[N,S,E,v,b]:null}var o=s(e,n,Math.ceil(e.length/4)),r=s(e,n,Math.ceil(e.length/2)),a;if(!o&&!r)return null;r?o?a=o[4].length>r[4].length?o:r:a=r:a=o;var l,c,u,d;i.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 Oy(i){for(var t=!1,e=[],n=0,s=null,o=0,r=0,a=0,l=0,c=0;o<i.length;)i[o][0]==et?(e[n++]=o,r=l,a=c,l=0,c=0,s=i[o][1]):(i[o][0]==xt?l+=i[o][1].length:c+=i[o][1].length,s&&s.length<=Math.max(r,a)&&s.length<=Math.max(l,c)&&(i.splice(e[n-1],0,[$t,s]),i[e[n-1]+1][0]=xt,n--,n--,o=n>0?e[n-1]:-1,r=0,a=0,l=0,c=0,s=null,t=!0)),o++;for(t&&kd(i),_y(i),o=1;o<i.length;){if(i[o-1][0]==$t&&i[o][0]==xt){var u=i[o-1][1],d=i[o][1],h=Ug(u,d),f=Ug(d,u);h>=f?(h>=u.length/2||h>=d.length/2)&&(i.splice(o,0,[et,d.substring(0,h)]),i[o-1][1]=u.substring(0,u.length-h),i[o+1][1]=d.substring(h),o++):(f>=u.length/2||f>=d.length/2)&&(i.splice(o,0,[et,u.substring(0,f)]),i[o-1][0]=xt,i[o-1][1]=d.substring(0,d.length-f),i[o+1][0]=$t,i[o+1][1]=u.substring(f),o++),o++}o++}}var Hg=/[^a-zA-Z0-9]/,zg=/\s/,Gg=/[\r\n]/,Dy=/\n\r?\n$/,My=/^\r?\n\r?\n/;function _y(i){function t(f,g){if(!f||!g)return 6;var m=f.charAt(f.length-1),C=g.charAt(0),x=m.match(Hg),b=C.match(Hg),N=x&&m.match(zg),S=b&&C.match(zg),E=N&&m.match(Gg),v=S&&C.match(Gg),w=E&&f.match(Dy),A=v&&g.match(My);return w||A?5:E||v?4:x&&!N&&S?3:N||S?2:x||b?1:0}for(var e=1;e<i.length-1;){if(i[e-1][0]==et&&i[e+1][0]==et){var n=i[e-1][1],s=i[e][1],o=i[e+1][1],r=dl(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),o=a+o}for(var l=n,c=s,u=o,d=t(n,s)+t(s,o);s.charAt(0)===o.charAt(0);){n+=s.charAt(0),s=s.substring(1)+o.charAt(0),o=o.substring(1);var h=t(n,s)+t(s,o);h>=d&&(d=h,l=n,c=s,u=o)}i[e-1][1]!=l&&(l?i[e-1][1]=l:(i.splice(e-1,1),e--),i[e][1]=c,u?i[e+1][1]=u:(i.splice(e+1,1),e--))}e++}}function kd(i,t){i.push([et,""]);for(var e=0,n=0,s=0,o="",r="",a;e<i.length;){if(e<i.length-1&&!i[e][1]){i.splice(e,1);continue}switch(i[e][0]){case xt:s++,r+=i[e][1],e++;break;case $t:n++,o+=i[e][1],e++;break;case et:var l=e-s-n-1;if(t){if(l>=0&&jg(i[l][1])){var c=i[l][1].slice(-1);if(i[l][1]=i[l][1].slice(0,-1),o=c+o,r=c+r,!i[l][1]){i.splice(l,1),e--;var u=l-1;i[u]&&i[u][0]===xt&&(s++,r=i[u][1]+r,u--),i[u]&&i[u][0]===$t&&(n++,o=i[u][1]+o,u--),l=u}}if(Xg(i[e][1])){var c=i[e][1].charAt(0);i[e][1]=i[e][1].slice(1),o+=c,r+=c}}if(e<i.length-1&&!i[e][1]){i.splice(e,1);break}if(o.length>0||r.length>0){o.length>0&&r.length>0&&(a=Pd(r,o),a!==0&&(l>=0?i[l][1]+=r.substring(0,a):(i.splice(0,0,[et,r.substring(0,a)]),e++),r=r.substring(a),o=o.substring(a)),a=dl(r,o),a!==0&&(i[e][1]=r.substring(r.length-a)+i[e][1],r=r.substring(0,r.length-a),o=o.substring(0,o.length-a)));var d=s+n;o.length===0&&r.length===0?(i.splice(e-d,d),e=e-d):o.length===0?(i.splice(e-d,d,[xt,r]),e=e-d+1):r.length===0?(i.splice(e-d,d,[$t,o]),e=e-d+1):(i.splice(e-d,d,[$t,o],[xt,r]),e=e-d+2)}e!==0&&i[e-1][0]===et?(i[e-1][1]+=i[e][1],i.splice(e,1)):e++,s=0,n=0,o="",r="";break}}i[i.length-1][1]===""&&i.pop();var h=!1;for(e=1;e<i.length-1;)i[e-1][0]===et&&i[e+1][0]===et&&(i[e][1].substring(i[e][1].length-i[e-1][1].length)===i[e-1][1]?(i[e][1]=i[e-1][1]+i[e][1].substring(0,i[e][1].length-i[e-1][1].length),i[e+1][1]=i[e-1][1]+i[e+1][1],i.splice(e-1,1),h=!0):i[e][1].substring(0,i[e+1][1].length)==i[e+1][1]&&(i[e-1][1]+=i[e+1][1],i[e][1]=i[e][1].substring(i[e+1][1].length)+i[e+1][1],i.splice(e+1,1),h=!0)),e++;h&&kd(i,t)}function Wg(i){return i>=55296&&i<=56319}function $g(i){return i>=56320&&i<=57343}function Xg(i){return $g(i.charCodeAt(0))}function jg(i){return Wg(i.charCodeAt(i.length-1))}function Uy(i){for(var t=[],e=0;e<i.length;e++)i[e][1].length>0&&t.push(i[e]);return t}function wd(i,t,e,n){return jg(i)||Xg(n)?null:Uy([[et,i],[$t,t],[xt,e],[et,n]])}function Hy(i,t,e){var n=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,o=i.length,r=t.length;if(n.length===0&&(s===null||s.length===0)){var a=n.index,l=i.slice(0,a),c=i.slice(a),u=s?s.index:null;e:{var d=a+r-o;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),C=h.slice(0,g);if(m!==C)break e;var x=l.slice(g),b=h.slice(g);return wd(m,x,b,c)}e:{if(u!==null&&u!==a)break e;var N=a,h=t.slice(0,N),f=t.slice(N);if(h!==l)break e;var S=Math.min(o-N,r-N),E=c.slice(c.length-S),v=f.slice(f.length-S);if(E!==v)break e;var x=c.slice(0,c.length-S),b=f.slice(0,f.length-S);return wd(l,x,b,E)}}if(n.length>0&&s&&s.length===0)e:{var m=i.slice(0,n.index),E=i.slice(n.index+n.length),g=m.length,S=E.length;if(r<g+S)break e;var C=t.slice(0,g),v=t.slice(r-S);if(m!==C||E!==v)break e;var x=i.slice(g,o-S),b=t.slice(g,r-S);return wd(m,x,b,E)}return null}function pl(i,t,e,n){return ai(i,t,e,n,!0)}pl.INSERT=xt;pl.DELETE=$t;pl.EQUAL=et;Yg.exports=pl});var $S={};yb($S,{CoreViewer:()=>fa,HOOKS:()=>Ct,Navigation:()=>ab,PageProgression:()=>Xs,PageSide:()=>Or,PageViewMode:()=>GS,Profiler:()=>Ea,ReadyState:()=>mu,UserAgentBaseCss:()=>pd,UserAgentCounterStylesCss:()=>gd,UserAgentPageCss:()=>dd,UserAgentTocCss:()=>hd,UserAgentXml:()=>ud,ValidationTxt:()=>cd,VivliostylePolyfillCss:()=>fd,VivliostyleViewportCss:()=>ld,VivliostyleViewportScreenCss:()=>ad,ZoomType:()=>zS,getHooksForName:()=>Je,isDebug:()=>$s,pageProgressionOf:()=>gu,plugin:()=>Eb,printHTML:()=>WS,profile:()=>wb,profiler:()=>ut,registerHook:()=>je,removeHook:()=>$f,setDebug:()=>fu});module.exports=Sb($S);var $s=!1;function fu(i){$s=i}var Xs=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Xs||{});function gu(i){switch(i){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${i}`)}}var Or=(e=>(e.LEFT="left",e.RIGHT="right",e))(Or||{}),mu=(n=>(n.LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete",n))(mu||{});var bu=(s=>(s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s))(bu||{}),Cu=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=ya(arguments);this.consoleDebug(xa(e)),this.triggerListeners(1,e)}info(...t){let e=ya(arguments);this.consoleInfo(xa(e)),this.triggerListeners(2,e)}warn(...t){let e=ya(arguments);this.consoleWarn(xa(e)),this.triggerListeners(3,e)}error(...t){let e=ya(arguments);this.consoleError(xa(e)),this.triggerListeners(4,e)}};function ya(i){let t=Array.from(i),e=null;return t[0]instanceof Error&&(e=t.shift()),{error:e,messages:t}}function xa(i){let t=i.error,e=t&&(t.frameTrace||t.stack),n=[].concat(i.messages);return t&&(n.length>0&&(n=n.concat([`
1
+ "use strict";var qb=Object.create;var Ur=Object.defineProperty;var Kb=Object.getOwnPropertyDescriptor;var Zb=Object.getOwnPropertyNames;var Qb=Object.getPrototypeOf,Jb=Object.prototype.hasOwnProperty;var lg=i=>{throw TypeError(i)};var ey=(i,t,e)=>t in i?Ur(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var ty=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),ny=(i,t)=>{for(var e in t)Ur(i,e,{get:t[e],enumerable:!0})},cg=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Zb(t))!Jb.call(i,s)&&s!==e&&Ur(i,s,{get:()=>t[s],enumerable:!(n=Kb(t,s))||n.enumerable});return i};var sy=(i,t,e)=>(e=i!=null?qb(Qb(i)):{},cg(t||!i||!i.__esModule?Ur(e,"default",{value:i,enumerable:!0}):e,i)),oy=i=>cg(Ur({},"__esModule",{value:!0}),i);var p=(i,t,e)=>ey(i,typeof t!="symbol"?t+"":t,e),Eu=(i,t,e)=>t.has(i)||lg("Cannot "+e);var O=(i,t,e)=>(Eu(i,t,"read from private field"),e?e.call(i):t.get(i)),Z=(i,t,e)=>t.has(i)?lg("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),Pe=(i,t,e,n)=>(Eu(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),fe=(i,t,e)=>(Eu(i,t,"access private method"),e);var Um=ty((yv,_m)=>{var jt=-1,Nt=1,et=0;function mi(i,t,e,n,s){if(i===t)return i?[[et,i]]:[];if(e!=null){var o=GS(i,t,e);if(o)return o}var r=$d(i,t),a=i.substring(0,r);i=i.substring(r),t=t.substring(r),r=Tl(i,t);var l=i.substring(i.length-r);i=i.substring(0,i.length-r),t=t.substring(0,t.length-r);var c=OS(i,t);return a&&c.unshift([et,a]),l&&c.push([et,l]),Wd(c,s),n&&MS(c),c}function OS(i,t){var e;if(!i)return[[Nt,t]];if(!t)return[[jt,i]];var n=i.length>t.length?i:t,s=i.length>t.length?t:i,o=n.indexOf(s);if(o!==-1)return e=[[Nt,n.substring(0,o)],[et,s],[Nt,n.substring(o+s.length)]],i.length>t.length&&(e[0][0]=e[2][0]=jt),e;if(s.length===1)return[[jt,i],[Nt,t]];var r=DS(i,t);if(r){var a=r[0],l=r[1],c=r[2],u=r[3],d=r[4],h=mi(a,c),f=mi(l,u);return h.concat([[et,d]],f)}return BS(i,t)}function BS(i,t){for(var e=i.length,n=t.length,s=Math.ceil((e+n)/2),o=s,r=2*s,a=new Array(r),l=new Array(r),c=0;c<r;c++)a[c]=-1,l[c]=-1;a[o+1]=0,l[o+1]=0;for(var u=e-n,d=u%2!==0,h=0,f=0,g=0,m=0,b=0;b<s;b++){for(var y=-b+h;y<=b-f;y+=2){var C=o+y,N;y===-b||y!==b&&a[C-1]<a[C+1]?N=a[C+1]:N=a[C-1]+1;for(var x=N-y;N<e&&x<n&&i.charAt(N)===t.charAt(x);)N++,x++;if(a[C]=N,N>e)f+=2;else if(x>n)h+=2;else if(d){var E=o+u-y;if(E>=0&&E<r&&l[E]!==-1){var v=e-l[E];if(N>=v)return Rm(i,t,N,x)}}}for(var T=-b+g;T<=b-m;T+=2){var E=o+T,v;T===-b||T!==b&&l[E-1]<l[E+1]?v=l[E+1]:v=l[E-1]+1;for(var k=v-T;v<e&&k<n&&i.charAt(e-v-1)===t.charAt(n-k-1);)v++,k++;if(l[E]=v,v>e)m+=2;else if(k>n)g+=2;else if(!d){var C=o+u-T;if(C>=0&&C<r&&a[C]!==-1){var N=a[C],x=o+N-C;if(v=e-v,N>=v)return Rm(i,t,N,x)}}}}return[[jt,i],[Nt,t]]}function Rm(i,t,e,n){var s=i.substring(0,e),o=t.substring(0,n),r=i.substring(e),a=t.substring(n),l=mi(s,o),c=mi(r,a);return l.concat(c)}function $d(i,t){if(!i||!t||i.charAt(0)!==t.charAt(0))return 0;for(var e=0,n=Math.min(i.length,t.length),s=n,o=0;e<s;)i.substring(o,s)==t.substring(o,s)?(e=s,o=e):n=s,s=Math.floor((n-e)/2+e);return Om(i.charCodeAt(s-1))&&s--,s}function Lm(i,t){var e=i.length,n=t.length;if(e==0||n==0)return 0;e>n?i=i.substring(e-n):e<n&&(t=t.substring(0,e));var s=Math.min(e,n);if(i==t)return s;for(var o=0,r=1;;){var a=i.substring(s-r),l=t.indexOf(a);if(l==-1)return o;r+=l,(l==0||i.substring(s-r)==t.substring(0,r))&&(o=r,r++)}}function Tl(i,t){if(!i||!t||i.slice(-1)!==t.slice(-1))return 0;for(var e=0,n=Math.min(i.length,t.length),s=n,o=0;e<s;)i.substring(i.length-s,i.length-o)==t.substring(t.length-s,t.length-o)?(e=s,o=e):n=s,s=Math.floor((n-e)/2+e);return Bm(i.charCodeAt(i.length-s))&&s--,s}function DS(i,t){var e=i.length>t.length?i:t,n=i.length>t.length?t:i;if(e.length<4||n.length*2<e.length)return null;function s(f,g,m){for(var b=f.substring(m,m+Math.floor(f.length/4)),y=-1,C="",N,x,E,v;(y=g.indexOf(b,y+1))!==-1;){var T=$d(f.substring(m),g.substring(y)),k=Tl(f.substring(0,m),g.substring(0,y));C.length<k+T&&(C=g.substring(y-k,y)+g.substring(y,y+T),N=f.substring(0,m-k),x=f.substring(m+T),E=g.substring(0,y-k),v=g.substring(y+T))}return C.length*2>=f.length?[N,x,E,v,C]:null}var o=s(e,n,Math.ceil(e.length/4)),r=s(e,n,Math.ceil(e.length/2)),a;if(!o&&!r)return null;r?o?a=o[4].length>r[4].length?o:r:a=r:a=o;var l,c,u,d;i.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 MS(i){for(var t=!1,e=[],n=0,s=null,o=0,r=0,a=0,l=0,c=0;o<i.length;)i[o][0]==et?(e[n++]=o,r=l,a=c,l=0,c=0,s=i[o][1]):(i[o][0]==Nt?l+=i[o][1].length:c+=i[o][1].length,s&&s.length<=Math.max(r,a)&&s.length<=Math.max(l,c)&&(i.splice(e[n-1],0,[jt,s]),i[e[n-1]+1][0]=Nt,n--,n--,o=n>0?e[n-1]:-1,r=0,a=0,l=0,c=0,s=null,t=!0)),o++;for(t&&Wd(i),HS(i),o=1;o<i.length;){if(i[o-1][0]==jt&&i[o][0]==Nt){var u=i[o-1][1],d=i[o][1],h=Lm(u,d),f=Lm(d,u);h>=f?(h>=u.length/2||h>=d.length/2)&&(i.splice(o,0,[et,d.substring(0,h)]),i[o-1][1]=u.substring(0,u.length-h),i[o+1][1]=d.substring(h),o++):(f>=u.length/2||f>=d.length/2)&&(i.splice(o,0,[et,u.substring(0,f)]),i[o-1][0]=Nt,i[o-1][1]=d.substring(0,d.length-f),i[o+1][0]=jt,i[o+1][1]=u.substring(f),o++),o++}o++}}var Im=/[^a-zA-Z0-9]/,Fm=/\s/,Vm=/[\r\n]/,_S=/\n\r?\n$/,US=/^\r?\n\r?\n/;function HS(i){function t(f,g){if(!f||!g)return 6;var m=f.charAt(f.length-1),b=g.charAt(0),y=m.match(Im),C=b.match(Im),N=y&&m.match(Fm),x=C&&b.match(Fm),E=N&&m.match(Vm),v=x&&b.match(Vm),T=E&&f.match(_S),k=v&&g.match(US);return T||k?5:E||v?4:y&&!N&&x?3:N||x?2:y||C?1:0}for(var e=1;e<i.length-1;){if(i[e-1][0]==et&&i[e+1][0]==et){var n=i[e-1][1],s=i[e][1],o=i[e+1][1],r=Tl(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),o=a+o}for(var l=n,c=s,u=o,d=t(n,s)+t(s,o);s.charAt(0)===o.charAt(0);){n+=s.charAt(0),s=s.substring(1)+o.charAt(0),o=o.substring(1);var h=t(n,s)+t(s,o);h>=d&&(d=h,l=n,c=s,u=o)}i[e-1][1]!=l&&(l?i[e-1][1]=l:(i.splice(e-1,1),e--),i[e][1]=c,u?i[e+1][1]=u:(i.splice(e+1,1),e--))}e++}}function Wd(i,t){i.push([et,""]);for(var e=0,n=0,s=0,o="",r="",a;e<i.length;){if(e<i.length-1&&!i[e][1]){i.splice(e,1);continue}switch(i[e][0]){case Nt:s++,r+=i[e][1],e++;break;case jt:n++,o+=i[e][1],e++;break;case et:var l=e-s-n-1;if(t){if(l>=0&&Mm(i[l][1])){var c=i[l][1].slice(-1);if(i[l][1]=i[l][1].slice(0,-1),o=c+o,r=c+r,!i[l][1]){i.splice(l,1),e--;var u=l-1;i[u]&&i[u][0]===Nt&&(s++,r=i[u][1]+r,u--),i[u]&&i[u][0]===jt&&(n++,o=i[u][1]+o,u--),l=u}}if(Dm(i[e][1])){var c=i[e][1].charAt(0);i[e][1]=i[e][1].slice(1),o+=c,r+=c}}if(e<i.length-1&&!i[e][1]){i.splice(e,1);break}if(o.length>0||r.length>0){o.length>0&&r.length>0&&(a=$d(r,o),a!==0&&(l>=0?i[l][1]+=r.substring(0,a):(i.splice(0,0,[et,r.substring(0,a)]),e++),r=r.substring(a),o=o.substring(a)),a=Tl(r,o),a!==0&&(i[e][1]=r.substring(r.length-a)+i[e][1],r=r.substring(0,r.length-a),o=o.substring(0,o.length-a)));var d=s+n;o.length===0&&r.length===0?(i.splice(e-d,d),e=e-d):o.length===0?(i.splice(e-d,d,[Nt,r]),e=e-d+1):r.length===0?(i.splice(e-d,d,[jt,o]),e=e-d+1):(i.splice(e-d,d,[jt,o],[Nt,r]),e=e-d+2)}e!==0&&i[e-1][0]===et?(i[e-1][1]+=i[e][1],i.splice(e,1)):e++,s=0,n=0,o="",r="";break}}i[i.length-1][1]===""&&i.pop();var h=!1;for(e=1;e<i.length-1;)i[e-1][0]===et&&i[e+1][0]===et&&(i[e][1].substring(i[e][1].length-i[e-1][1].length)===i[e-1][1]?(i[e][1]=i[e-1][1]+i[e][1].substring(0,i[e][1].length-i[e-1][1].length),i[e+1][1]=i[e-1][1]+i[e+1][1],i.splice(e-1,1),h=!0):i[e][1].substring(0,i[e+1][1].length)==i[e+1][1]&&(i[e-1][1]+=i[e+1][1],i[e][1]=i[e][1].substring(i[e+1][1].length)+i[e+1][1],i.splice(e+1,1),h=!0)),e++;h&&Wd(i,t)}function Om(i){return i>=55296&&i<=56319}function Bm(i){return i>=56320&&i<=57343}function Dm(i){return Bm(i.charCodeAt(0))}function Mm(i){return Om(i.charCodeAt(i.length-1))}function zS(i){for(var t=[],e=0;e<i.length;e++)i[e][1].length>0&&t.push(i[e]);return t}function Gd(i,t,e,n){return Mm(i)||Dm(n)?null:zS([[et,i],[jt,t],[Nt,e],[et,n]])}function GS(i,t,e){var n=typeof e=="number"?{index:e,length:0}:e.oldRange,s=typeof e=="number"?null:e.newRange,o=i.length,r=t.length;if(n.length===0&&(s===null||s.length===0)){var a=n.index,l=i.slice(0,a),c=i.slice(a),u=s?s.index:null;e:{var d=a+r-o;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),b=h.slice(0,g);if(m!==b)break e;var y=l.slice(g),C=h.slice(g);return Gd(m,y,C,c)}e:{if(u!==null&&u!==a)break e;var N=a,h=t.slice(0,N),f=t.slice(N);if(h!==l)break e;var x=Math.min(o-N,r-N),E=c.slice(c.length-x),v=f.slice(f.length-x);if(E!==v)break e;var y=c.slice(0,c.length-x),C=f.slice(0,f.length-x);return Gd(l,y,C,E)}}if(n.length>0&&s&&s.length===0)e:{var m=i.slice(0,n.index),E=i.slice(n.index+n.length),g=m.length,x=E.length;if(r<g+x)break e;var b=t.slice(0,g),v=t.slice(r-x);if(m!==b||E!==v)break e;var y=i.slice(g,o-x),C=t.slice(g,r-x);return Gd(m,y,C,E)}return null}function wl(i,t,e,n){return mi(i,t,e,n,!0)}wl.INSERT=Nt;wl.DELETE=jt;wl.EQUAL=et;_m.exports=wl});var KE={};ny(KE,{CoreViewer:()=>xa,HOOKS:()=>St,Navigation:()=>Gb,PageProgression:()=>Ys,PageSide:()=>Hr,PageViewMode:()=>YE,Profiler:()=>Aa,ReadyState:()=>Tu,UserAgentBaseCss:()=>vd,UserAgentCounterStylesCss:()=>wd,UserAgentPageCss:()=>Ed,UserAgentTocCss:()=>Nd,UserAgentXml:()=>xd,ValidationTxt:()=>Sd,VivliostylePolyfillCss:()=>Td,VivliostyleViewportCss:()=>yd,VivliostyleViewportScreenCss:()=>bd,ZoomType:()=>jE,getHooksForName:()=>Je,isDebug:()=>js,pageProgressionOf:()=>Nu,plugin:()=>ry,printHTML:()=>qE,profile:()=>cy,profiler:()=>ht,registerHook:()=>je,removeHook:()=>ug,setDebug:()=>vu});module.exports=oy(KE);var js=!1;function vu(i){js=i}var Ys=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Ys||{});function Nu(i){switch(i){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${i}`)}}var Hr=(e=>(e.LEFT="left",e.RIGHT="right",e))(Hr||{}),Tu=(n=>(n.LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete",n))(Tu||{});var Pu=(s=>(s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s))(Pu||{}),wu=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=wa(arguments);this.consoleDebug(Pa(e)),this.triggerListeners(1,e)}info(...t){let e=wa(arguments);this.consoleInfo(Pa(e)),this.triggerListeners(2,e)}warn(...t){let e=wa(arguments);this.consoleWarn(Pa(e)),this.triggerListeners(3,e)}error(...t){let e=wa(arguments);this.consoleError(Pa(e)),this.triggerListeners(4,e)}};function wa(i){let t=Array.from(i),e=null;return t[0]instanceof Error&&(e=t.shift()),{error:e,messages:t}}function Pa(i){let t=i.error,e=t&&(t.frameTrace||t.stack),n=[].concat(i.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 O=new Cu;var Ct=(d=>(d.SIMPLE_PROPERTY="SIMPLE_PROPERTY",d.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",d.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",d.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",d.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",d.CONFIGURATION="CONFIGURATION",d.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",d.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",d.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",d.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",d.PAGINATION_PROGRESS="PAGINATION_PROGRESS",d))(Ct||{}),Sa={};function je(i,t,e){if(!Ct[i])O.warn(new Error(`Skipping unknown plugin hook '${i}'.`));else{let n=Sa[i];n||(n=Sa[i]=[]),e?n.unshift(t):n.push(t)}}function $f(i,t){if(!Ct[i])O.warn(new Error(`Ignoring unknown plugin hook '${i}'.`));else{let e=Sa[i];if(e){let n=e.indexOf(t);n>=0&&e.splice(n,1)}}}function Je(i){return Sa[i]||[]}var Eb={registerHook:je,removeHook:$f};var Ea=class{constructor(t){this.performanceInstance=t;p(this,"timestamps",{});p(this,"registerTiming");p(this,"registerStartTiming");p(this,"registerEndTiming");this.registerTiming=Lo,this.registerStartTiming=this.registerStartTiming=Lo,this.registerEndTiming=this.registerEndTiming=Lo}forceRegisterStartTiming(t,e){yu.call(this,t,"start",e)}forceRegisterEndTiming(t,e){yu.call(this,t,"end",e)}printTimings(){let t=this.timestamps,e="";Object.keys(t).forEach(n=>{let s=t[n],o=s.length;for(let r=0;r<o;r++){let a=s[r];e+=n,o>1&&(e+=`(${r})`),e+=` => start: ${a.start}, end: ${a.end}, duration: ${a.end-a.start}
4
- `}}),O.info(e)}disable(){this.registerTiming=Lo,this.registerStartTiming=this.registerStartTiming=Lo,this.registerEndTiming=this.registerEndTiming=Lo}enable(){this.registerTiming=yu,this.registerStartTiming=this.registerStartTiming=Xf,this.registerEndTiming=this.registerEndTiming=vb}isEnabled(){return this.registerStartTiming===Xf}};function Lo(){}function yu(i,t,e){e||(e=this.performanceInstance.now());let n=this.timestamps[i];n||(n=this.timestamps[i]=[]);let s,o=n.length;for(let r=o-1;r>=0&&(s=n[r],!(s&&!s[t]));r--)s=null;s||(s={},n.push(s)),s[t]=e}function Xf(i,t){this.registerTiming(i,"start",t)}function vb(i,t){this.registerTiming(i,"end",t)}var Nb={now:Date.now},Tb=window&&window.performance,ut=new Ea(Tb||Nb);ut.forceRegisterStartTiming("load_vivliostyle");var wb={profiler:{registerStartTiming:ut.registerStartTiming,registerEndTiming:ut.registerEndTiming,printTimings:ut.printTimings,disable:ut.disable,enable:ut.enable}};var Fo=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",js=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Ut="data-adapt-eloff",Yf={};function Vo(i){return JSON.parse(i)}function Ht(i){let t=i.match(/^([^#]*)/);return t?t[1]:i}function Pb(i){let t=i.match(/^([^#?]*)/);return t?t[1]:i}var vn=window.location.href;function xu(i){vn=i}var on=window.location.href;function Su(i){on=i}function ee(i,t){if(/^data:/i.test(t))return i||t;if(!t||i.match(/^\w{2,}:/))return i.toLowerCase().match("^javascript:")?"#":(i.match(/^\w{2,}:\/\/[^\/]+$/)&&(i=`${i}/`),i);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let e;if(i.match(/^\/\//))return e=t.match(/^(\w{2,}:)\/\//),e?e[1]+i:i;if(i.match(/^\//))return e=t.match(/^(\w{2,}:\/\/[^\/]+)\//),e?e[1]+i:i;if(i.match(/^\.(\/|$)/)&&(i=i.substr(2)),t=Pb(t),i.match(/^#/))return t+i;let n=t.lastIndexOf("/");if(n<0)return i;let s=t.substr(0,n+1)+i,o="";for(e=s.match(/^([^?#]*)([?#].*)$/),e&&(s=e[1],o=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,"/")+o}function _r(i,t){return i.match(/^#/)&&t?Ht(t)+i:ee(i,t)}function Wn(i){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(i))?i=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(i))?i=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(i))?i=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(i))?i=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(i))&&(i=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),i}function Eu(i){return i==null?i:i.toString()}var va=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 o=s*2;if(o>=n)break;if(this.queue[o].compare(e)>0)o+1<n&&this.queue[o+1].compare(this.queue[o])>0&&o++;else if(o+1<n&&this.queue[o+1].compare(e)>0)o++;else break;this.queue[s]=this.queue[o],s=o}this.queue[s]=e}return t}},vu=["","-webkit-","-moz-"],Io={};function Mr(i,t){return CSS.supports(i+t,"unset")}function kb(i){let t=Io[i];if(t||t===null)return t;switch(i){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Io[i]=null,null;case"text-combine-upright":if(Mr("-webkit-","text-combine")&&!Mr("","text-combine-upright"))return Io[i]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let e of vu)if(Mr(e,i))return t=[e+i],Io[i]=t,t;return O.warn("Property not supported by the browser: ",i),Io[i]=null,null}function P(i,t,e){let n=i==null?void 0:i.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,e||" ");return}let s=kb(t);if(s)for(let o of s){switch(o){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(o,e)}}function rn(i,t,e){try{let n=Io[t];return i.style.getPropertyValue(n?n[0]:t)}catch(n){}return e||""}function Ur(i){let t=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&i.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=i.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 qf(i){return`\\${i.charCodeAt(0).toString(16)} `}function Nn(i){return i.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,qf)}function Ys(i){return i.replace(/[\u0000-\u001F"\\]/g,qf)}function Nu(i){return i.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Tu(i){return!!i.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Ab(i,t){return t=typeof t=="string"?t:"\\u",t+(65536|i.charCodeAt(0)).toString(16).substr(1)}function wu(i,t){function e(n){return Ab(n,t)}return i.replace(/[^-a-zA-Z0-9_]/g,e)}function $n(i){return wu(i)}function Rb(i,t){return t=typeof t=="string"?t:"\\u",i.indexOf(t)===0?String.fromCharCode(parseInt(i.substring(t.length),16)):i}function Kf(i,t){t=typeof t=="string"?t:"\\u";function e(s){return Rb(s,t)}let n=new RegExp(`${$n(t)}[0-9a-fA-F]{4}`,"g");return i.replace(n,e)}function Rt(i,t){let e=0,n=i;for(;;){if(e<=n,e==0||t(e-1),n==i||t(n),e==n)return e;let s=e+n>>1;t(s)?n=s:e=s+1}}function Na(i,t){return i-t}function Pu(i,t){let e={};for(let n of i){let s=t(n);s&&!e[s]&&(e[s]=n)}return e}function Zf(i){let t={};for(let e=0;e<i.length;e++)t[i[e]]=!0;return t}function Ta(i,t){let e={};for(let n of i){let s=t(n);s&&(e[s]?e[s].push(n):e[s]=[n])}return e}function Qf(i,t){let e={};for(let n in i)e[n]=t(i[n],n);return e}var ds=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 o=s.indexOf(e);o>=0&&s.splice(o,1)}}},Tn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function ku(){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 _a(i){return{fontFamily:i.fontFamily,lineHeight:i.lineHeight,margin:i.margin,hyphenate:i.hyphenate,columnWidth:i.columnWidth,horizontal:i.horizontal,nightMode:i.nightMode,spreadView:i.spreadView,pageBorder:i.pageBorder,enabledMediaTypes:Object.assign({},i.enabledMediaTypes),defaultPaperSize:i.defaultPaperSize?Object.assign({},i.defaultPaperSize):void 0}}var Lb=ku(),Jf={PENDING:{}};function Au(i,t,e,n){let s=Math.min((i-0)/e,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function Ib(i){return`"${Ys(`${i}`)}"`}function Fb(i){return Nn(`${i}`)}function jr(i,t){return i?`${Nn(i)}.${Nn(t)}`:Nn(t)}var eg=0,qs=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${eg++}`,this.zero=new Ne(this,0),this.one=new Ne(this,1),this._true=new Ne(this,!0),this._false=new Ne(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=Au,n["css-string"]=Ib,n["css-name"]=Fb,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 this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(t,e){this.values[t]=new te(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 tg(i){switch(i==null?void 0:i.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Ru(i){switch(i==null?void 0:i.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 ng(i){switch(i==null?void 0:i.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function sg(i){switch(i==null?void 0:i.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var ot={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 Ua(i){switch(i){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 Bo=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=Lb}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(Ru(t)){let s=this.pageWidth()/100,o=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:s,a=this.pageAreaHeight!=null?this.pageAreaHeight/100:o,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 o;case"pvi":return l?o:s;case"pvb":return l?s:o;case"pvmin":return s<o?s:o;case"pvmax":return s>o?s:o}}return t=="em"||t=="rem"?e?this.initialFontSize:this.fontSize():t=="lh"||t=="rlh"?this.rootLineHeight:ot[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 o=t.funcs[e];if(o||t.resolver&&(o=t.resolver.call(this,e,!0),o))return o;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 Ne(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 o=null,r=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(o=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&&o!=null)switch(n){case"min":return r>=Number(o);case"max":return r<=Number(o);default:return r==o}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}},Lt=class{constructor(t){this.scope=t;p(this,"key");this.scope=t,this.key=`_${eg++}`}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===Jf.PENDING?!1:s;{n[this.key]=Jf.PENDING;let o=this.dependCore(t,e,n);return n[this.key]=o,o}}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}},wa=class extends Lt{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)}},Oo=class extends Lt{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),o=this.rhs.expand(e,n);return s===this.lhs&&o===this.rhs?this:new this.constructor(this.scope,s,o)}},Pa=class extends Oo{constructor(t,e,n){super(t,e,n)}getPriority(){return 1}},ps=class extends Oo{constructor(t,e,n){super(t,e,n)}getPriority(){return 2}},ka=class extends Oo{constructor(t,e,n){super(t,e,n)}getPriority(){return 3}},Hr=class extends Oo{constructor(t,e,n){super(t,e,n)}getPriority(){return 4}},zt=class extends wa{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},Aa=class extends zt{constructor(t,e){super(t,e)}getOp(){return"not "}},wn=class extends wa{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},Do=class extends Pa{constructor(t,e,n){super(t,e,n)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},Ra=class extends Do{constructor(t,e,n){super(t,e,n)}getOp(){return" and "}},Mo=class extends Pa{constructor(t,e,n){super(t,e,n)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},La=class extends Mo{constructor(t,e,n){super(t,e,n)}getOp(){return", "}},Ia=class extends Mo{constructor(t,e,n){super(t,e,n)}getOp(){return" or "}},Fa=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return"<"}evalInfix(t,e){return t<e}},Va=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return"<="}evalInfix(t,e){return t<=e}},Ba=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return">"}evalInfix(t,e){return t>e}},Ks=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return">="}evalInfix(t,e){return t>=e}},hs=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return"=="}evalInfix(t,e){return t==e}},Oa=class extends ps{constructor(t,e,n){super(t,e,n)}getOp(){return"!="}evalInfix(t,e){return t!=e}},zr=class extends ka{constructor(t,e,n){super(t,e,n)}getOp(){return"+"}evalInfix(t,e){return t+e}},Gr=class extends ka{constructor(t,e,n){super(t,e,n)}getOp(){return" - "}evalInfix(t,e){return t-e}},Zs=class extends Hr{constructor(t,e,n){super(t,e,n)}getOp(){return"*"}evalInfix(t,e){return t*e}},Wr=class extends Hr{constructor(t,e,n){super(t,e,n)}getOp(){return"/"}evalInfix(t,e){return t/e}},_o=class extends Hr{constructor(t,e,n){super(t,e,n)}getOp(){return"%"}evalInfix(t,e){return t%e}},an=class extends Lt{constructor(e,n,s){var o;super(e);this.num=n;p(this,"unit");this.unit=(o=s==null?void 0:s.toLowerCase())!=null?o:""}appendTo(e,n){e.append(this.num.toString()),e.append(Nn(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},ye=class extends Lt{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)}},$r=class extends Lt{constructor(e,n,s){super(e);this.not=n;this.name=s}appendTo(e,n){this.not&&e.append("not "),e.append(Nn(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},te=class extends Lt{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 Vb(i,t){i.append("(");for(let e=0;e<t.length;e++)e&&i.append(","),t[e].appendTo(i,0);i.append(")")}function Bb(i,t,e){let n=t;for(let s=0;s<t.length;s++){let o=t[s].expand(i,e);if(t!==n)n[s]=o;else if(o!==t[s]){n=Array(t.length);for(let r=0;r<s;r++)n[r]=t[r];n[s]=o}}return n}var Xn=class i extends Lt{constructor(e,n,s){super(e);this.qualifiedName=n;this.params=s}appendTo(e,n){e.append(this.qualifiedName),Vb(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=Bb(e,this.params,n);return s===this.params?this:new i(this.scope,this.qualifiedName,s)}},Da=class i extends Lt{constructor(e,n,s,o){super(e);this.cond=n;this.ifTrue=s;this.ifFalse=o}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),o=this.ifTrue.expand(e,n),r=this.ifFalse.expand(e,n);return s===this.cond&&o===this.ifTrue&&r===this.ifFalse?this:new i(this.scope,s,o,r)}},Ne=class extends Lt{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(Ys(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Xr=class i extends Lt{constructor(e,n,s){super(e);this.name=n;this.value=s}appendTo(e,n){e.append("("),e.append(Ys(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 i(this.scope,this.name,s)}},Ma=class extends Lt{constructor(e,n,s,o){super(e);this.name=n;this.value=s;this.isFunc=o}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)}},Uo=class extends Lt{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 bt(i,t,e){return t===i._false||t===i.zero||e==i._false||e==i.zero?i._false:t===i._true||t===i.one?e:e===i._true||e===i.one?t:new Do(i,t,e)}function K(i,t,e){return t===i.zero?e:e===i.zero?t:new zr(i,t,e)}function ie(i,t,e){return t===i.zero?new wn(i,e):e===i.zero?t:new Gr(i,t,e)}function Ho(i,t,e){return t===i.zero||e===i.zero?i.zero:t===i.one?e:e===i.one?t:new Zs(i,t,e)}function Yr(i,t,e){return t===i.zero?i.zero:e===i.one?t:new Wr(i,t,e)}var It=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}},Kt=class extends It{constructor(){super();p(this,"error",!1)}visitValues(e){let n=null;for(let s=0;s<e.length;s++){let o=e[s],r=o.visit(this);if(this.error)return[];if(n)n[s]=r;else if(o!==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?G:n===e.values?e:new X(n)}visitCommaList(e){let n=this.visitValues(e.values);return this.error?G:n===e.values?e:new Se(n)}visitFunc(e){let n=this.visitValues(e.values);return this.error?G:n===e.values?e:new Ft(e.name,n)}visitExpr(e){return e}},_e=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}},Ha=class Ha extends _e{static get instance(){return this.empty||(this.empty=new Ha),this.empty}constructor(){super()}toExpr(t,e){return new Ne(t,"")}appendTo(t,e){}visit(t){return t.visitEmpty(this)}};p(Ha,"empty");var Lu=Ha,G=Lu.instance,za=class za extends _e{static get instance(){return this.slash||(this.slash=new za),this.slash}constructor(){super()}toExpr(t,e){return new Ne(t,"/")}appendTo(t,e){t.append("/")}visit(t){return t.visitSlash(this)}};p(za,"slash");var Iu=za,jn=Iu.instance,z=class extends _e{constructor(e){super();this.str=e}toExpr(e,n){return new Ne(e,this.str)}appendTo(e,n){n?(e.append('"'),e.append(Ys(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Fu=Object.create(null),J=class extends _e{constructor(e){super();this.name=e;if(Fu[e])throw new Error("E_INVALID_CALL");Fu[e]=this}toExpr(e,n){return new Ne(e,this.name)}appendTo(e,n){n?e.append(Nn(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function R(i){let t=Fu[i];return t||(t=new J(i)),t}var k=class extends _e{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 Zs(e,n,new Ne(e,this.num/100)):new an(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}},Ue=class extends _e{constructor(e){super();this.num=e}toExpr(e,n){return this.num==0?e.zero:this.num==1?e.one:new Ne(e,this.num)}appendTo(e,n){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},ae=class extends Ue{constructor(t){super(t)}visit(t){return t.visitInt(this)}},zo=class extends _e{constructor(e){super();this.hex=e}appendTo(e,n){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Pe=class extends _e{constructor(e){super();this.url=e}appendTo(e,n){e.append('url("'),e.append(Ys(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},qr=class extends _e{constructor(e){super();this.urangeText=e}appendTo(e,n){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Vu(i,t,e,n){var o,r;let s=t.length;if(s>0){(o=t[0])==null||o.appendTo(i,n);for(let a=1;a<s;a++)i.append(e),(r=t[a])==null||r.appendTo(i,n)}}var X=class extends _e{constructor(e){super();this.values=e}appendTo(e,n){Vu(e,this.values," ",n)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Se=class extends _e{constructor(e){super();this.values=e}appendTo(e,n){Vu(e,this.values,",",n)}visit(e){return e.visitCommaList(this)}},Ft=class extends _e{constructor(e,n){super();this.name=e;this.values=n}appendTo(e,n){e.append(Nn(this.name)),e.append("("),Vu(e,this.values,",",n),e.append(")")}visit(e){return e.visitFunc(this)}},D=class extends _e{constructor(e){super();this.expr=e}toExpr(){return this.expr}appendTo(e,n){this.expr instanceof Ne||this.expr instanceof an?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},Pn=class extends _e{constructor(e){super();this.text=e}appendTo(e,n){e.append(this.text||" ")}};function Ye(i,t){if(i){if(i.isNumeric()){let e=i;return t.queryUnitSize(e.unit,!1)*e.num}if(i.isNum())return i.num}return 0}function Ga(i,t){return new k(Ye(i,t),"px")}var y={absolute:R("absolute"),all:R("all"),always:R("always"),anywhere:R("anywhere"),auto:R("auto"),avoid:R("avoid"),balance:R("balance"),balance_all:R("balance-all"),block:R("block"),block_end:R("block-end"),block_start:R("block-start"),both:R("both"),bottom:R("bottom"),border_box:R("border-box"),break_all:R("break-all"),break_word:R("break-word"),clip:R("clip"),crop:R("crop"),cross:R("cross"),column:R("column"),discard:R("discard"),exclusive:R("exclusive"),_false:R("false"),fixed:R("fixed"),flex:R("flex"),flow_root:R("flow-root"),footnote:R("footnote"),footer:R("footer"),grid:R("grid"),header:R("header"),hidden:R("hidden"),horizontal_tb:R("horizontal-tb"),inherit:R("inherit"),initial:R("initial"),inline:R("inline"),inline_block:R("inline-block"),inline_end:R("inline-end"),inline_start:R("inline-start"),inside:R("inside"),keep:R("keep"),landscape:R("landscape"),left:R("left"),line:R("line"),list_item:R("list-item"),ltr:R("ltr"),manual:R("manual"),max_content:R("max-content"),min_content:R("min-content"),none:R("none"),normal:R("normal"),oeb_page_foot:R("oeb-page-foot"),oeb_page_head:R("oeb-page-head"),outside:R("outside"),padding_box:R("padding-box"),page:R("page"),relative:R("relative"),revert:R("revert"),right:R("right"),same:R("same"),scale:R("scale"),snap_block:R("snap-block"),snap_inline:R("snap-inline"),solid:R("solid"),spread:R("spread"),_static:R("static"),rtl:R("rtl"),table:R("table"),table_caption:R("table-caption"),table_cell:R("table-cell"),table_footer_group:R("table-footer-group"),table_header_group:R("table-header-group"),table_row:R("table-row"),top:R("top"),transparent:R("transparent"),unset:R("unset"),vertical_lr:R("vertical-lr"),vertical_rl:R("vertical-rl"),visible:R("visible"),_true:R("true")},Bu=new k(100,"%"),fs=new k(100,"pvw"),gs=new k(100,"pvh"),he=new k(0,"px"),ZS=new qr("U+0-10FFFF"),og={"font-size":1,"line-height":2,color:3};function W(i){return i===y.inherit||i===y.initial||i===y.revert||i===y.unset}function Ou(i,t){let e=og[i]||Number.MAX_VALUE,n=og[t]||Number.MAX_VALUE;return e-n}function Vt(i){return(i==null?void 0:i.length)>2&&i.startsWith("--")}var Qs,Js,eo,ln=class ln{constructor(t,e,n){Z(this,Qs);Z(this,Js);Z(this,eo);we(this,Qs,Math.round(Math.max(0,Math.min(t,ln.MAX)))),we(this,Js,Math.round(Math.max(0,Math.min(e,ln.MAX)))),we(this,eo,Math.round(Math.max(0,Math.min(n,ln.MAX))))}static fromInt(t,e,n){return new ln(t,e,n)}offset(t,e,n){return new ln(B(this,Qs)+t,B(this,Js)+e,B(this,eo)+n)}toKey(){return JSON.stringify([B(this,Qs),B(this,Js),B(this,eo)])}toColorFunc(t){return new Ft("color",[new X([R("srgb"),new Ue(B(this,Qs)/ln.MAX),new Ue(B(this,Js)/ln.MAX),new Ue(B(this,eo)/ln.MAX),...t!==null?[jn,new Ue(t)]:[]])])}};Qs=new WeakMap,Js=new WeakMap,eo=new WeakMap,p(ln,"MAX",1e4);var un=ln;function rg(i){return Array.isArray(i)?i.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[e,n]=t;if(!e||typeof e!="object"||Array.isArray(e)||!n||typeof n!="object"||Array.isArray(n))return!1;let s=e,o=n;return Number.isFinite(s.r)&&Number.isFinite(s.g)&&Number.isFinite(s.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var ms,Cs,bs,cn,rt=class rt{constructor(t,e,n,s){Z(this,ms);Z(this,Cs);Z(this,bs);Z(this,cn);we(this,ms,Math.round(Math.max(0,Math.min(t,rt.MAX)))),we(this,Cs,Math.round(Math.max(0,Math.min(e,rt.MAX)))),we(this,bs,Math.round(Math.max(0,Math.min(n,rt.MAX)))),we(this,cn,Math.round(Math.max(0,Math.min(s,rt.MAX))))}static fromInt(t,e,n,s){return new rt(t,e,n,s)}static fromNumber(t,e,n,s){return new rt(t*rt.MAX,e*rt.MAX,n*rt.MAX,s*rt.MAX)}toSRGB(){let t=rt.MAX-B(this,cn);return un.fromInt(un.MAX-Math.min(un.MAX,Math.round(B(this,ms)*t/rt.MAX)+B(this,cn)),un.MAX-Math.min(un.MAX,Math.round(B(this,Cs)*t/rt.MAX)+B(this,cn)),un.MAX-Math.min(un.MAX,Math.round(B(this,bs)*t/rt.MAX)+B(this,cn)))}equals(t){return B(this,ms)===B(t,ms)&&B(this,Cs)===B(t,Cs)&&B(this,bs)===B(t,bs)&&B(this,cn)===B(t,cn)}toJSON(){return{c:B(this,ms),m:B(this,Cs),y:B(this,bs),k:B(this,cn)}}};ms=new WeakMap,Cs=new WeakMap,bs=new WeakMap,cn=new WeakMap,p(rt,"MAX",1e4);var Wa=rt;function Go(i){return i instanceof Ue?Math.max(0,Math.min(1,i.num)):i instanceof k&&i.unit==="%"?Math.max(0,Math.min(1,i.num/100)):null}function Du(i){if(i.name!=="device-cmyk"&&i.name!=="cmyk")return null;let t=i.values.length===1&&i.values[0]instanceof X?i.values[0].values:i.values;if(t.length<4||t.length>6)return null;let e=Go(t[0]),n=Go(t[1]),s=Go(t[2]),o=Go(t[3]);if(e===null||n===null||s===null||o===null)return null;let r=null;if(t.length>=5){if(t[4]===jn){if(t.length!==6)return null;r=Go(t[5])}else{if(t.length!==5)return null;r=Go(t[4])}if(r===null)return null}return{cmyk:Wa.fromNumber(e,n,s,o),alpha:r}}function*Ob(i){for(let t=-i;t<=i;t++)for(let e=-i;e<=i;e++)for(let n=-i;n<=i;n++)Math.abs(t)+Math.abs(e)+Math.abs(n)===i&&(yield[t,e,n])}var Yn,jo,ig,ag,Kr=class{constructor(){Z(this,jo);Z(this,Yn,new Map)}registerDeviceCmyk(t){let e=Du(t);return e?pe(this,jo,ig).call(this,e.cmyk).toColorFunc(e.alpha):null}registerCmykReserveMap(t){for(let[e,n]of t){let s=un.fromInt(e.r,e.g,e.b),o=Wa.fromInt(n.c,n.m,n.y,n.k);B(this,Yn).set(s.toKey(),o)}}toJSON(){let t={};return B(this,Yn).forEach((e,n)=>{t[n]=e.toJSON()}),t}};Yn=new WeakMap,jo=new WeakSet,ig=function(t){let e=t.toSRGB(),n=e.toKey(),s=B(this,Yn).get(n);return s?s.equals(t)?e:pe(this,jo,ag).call(this,t,e):(B(this,Yn).set(n,t),e)},ag=function(t,e){for(let n=1;n<=un.MAX;n++)for(let[s,o,r]of Ob(n)){let a=e.offset(s,o,r),l=a.toKey();if(!B(this,Yn).has(l))return B(this,Yn).set(l,t),a}return O.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(t.toJSON())}`),e};var Zr,Wo,$o,Xo=class extends Kt{constructor(e){super();Z(this,Zr);Z(this,Wo,new Map);Z(this,$o,!1);we(this,Zr,e!=null?e:new Kr)}reset(){we(this,$o,!1)}hadDeviceCmyk(){return B(this,$o)}recordConversion(e,n){B(this,Wo).set(e,n)}getConversions(){if(B(this,Wo).size===0)return null;let e={};return B(this,Wo).forEach((n,s)=>{e[s]=n}),e}visitFunc(e){let n=B(this,Zr).registerDeviceCmyk(e);return n?(we(this,$o,!0),n):super.visitFunc(e)}};Zr=new WeakMap,Wo=new WeakMap,$o=new WeakMap;function ug(i){if(i.nodeType==1){let t=i.getAttribute("id");if(t)return t}return null}function Db(i){return`^${i}`}function lg(i){return i.replace(/[\[\]\(\),=;^]/g,Db)}function Mb(i){return i.substr(1)}function Mu(i){return i&&i.replace(/\^[\[\]\(\),=;^]/g,Mb)}function _b(i){let t=[];do{let e=i.match(/^(\^,|[^,])*/),n=Mu(e[0]);if(i=i.substr(e[0].length+1),!i&&!t.length)return n;t.push(n)}while(i);return t}function cg(i){let t={};for(;i;){let e=i.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!e)return t;t[e[1]]=_b(e[2]),i=i.substr(e[0].length)}return t}var Xa=class{appendTo(t){t.append("!")}applyTo(t){return!1}},ja=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,o,r=Math.floor(this.index/2)-1;if(r<0||s==0)o=e.firstChild,t.node=o||e;else{if(o=n[Math.min(r,s-1)],this.index&1){let a=o.nextSibling;!a||a.nodeType==1?t.after=!0:o=a}t.node=o}if(this.id&&(t.after||this.id!=ug(t.node))){let a=e.ownerDocument.getElementById(this.id);a?t.node=a:O.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},Ya=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 o=n.nextSibling;if(3<=s&&s<=5){let r=n.textContent.length;if(e<=r)break;if(!o){e=r;break}e-=r}if(!o){e=0;break}n=o}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(lg(this.textBefore)),t.append(","),this.textAfter&&t.append(lg(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},Qr=class i{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,o=[];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=cg(e[4]),o.push(new ja(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=Mu(l));let c=e[7];c&&(c=Mu(c)),r=cg(e[10]),o.push(new Ya(a,l,c,Eu(r.s)));break}case"!":s++,o.push(new Xa);break;case"~":case"@":case"":this.steps=o;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 i,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 o=[],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),o.push(new Ya(e,a,l,s)),s=null);r&&!(!r||r.nodeType==9);){let c=n?null:ug(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new ja(u,c,s)),s=null,t=r,r=r.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Xa),this.steps=o.concat(this.steps)):this.steps=o}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")}};var tt=class{constructor(t,e,n,s){this.x1=t;this.y1=e;this.x2=n;this.y2=s}},dn=class{constructor(t,e){this.x=t;this.y=e}},qo=class{constructor(t,e,n,s){this.left=t;this.top=e;this.right=n;this.bottom=s}},qa=class{constructor(t,e,n,s){this.low=t;this.high=e;this.winding=n;this.shapeId=s}},pn=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 Hb(i,t){return i.low.y-t.low.y||i.low.x-t.low.x}var to=class i{constructor(t){this.points=t}addSegments(t,e){let n=this.points,s=n.length,o=n[s-1];for(let r=0;r<s;r++){let a=n[r],l;o.y<a.y?l=new qa(o,a,1,e):l=new qa(a,o,-1,e),t.push(l),o=a}}withOffset(t,e){let n=[];for(let s of this.points)n.push(new dn(s.x+t,s.y+e));return new i(n)}};function _u(i,t,e,n){let o=[];for(let r=0;r<20;r++){let a=r*2*Math.PI/20;o.push(new dn(i+e*Math.sin(a),t+n*Math.cos(a)))}return new to(o)}function Jr(i,t,e,n){return new to([new dn(i,t),new dn(e,t),new dn(e,n),new dn(i,n)])}var Yo=class{constructor(t,e,n,s){this.x=t;this.winding=e;this.shapeId=n;this.lowOrHigh=s}};function dg(i,t){let e=i.low.x+(i.high.x-i.low.x)*(t-i.low.y)/(i.high.y-i.low.y);if(isNaN(e))throw new Error("Bad intersection");return e}function zb(i,t,e,n){let s,o,r,a;t.high.y<e&&O.warn("Error: inconsistent segment (1)"),t.low.y<=e?(s=dg(t,e),o=t.winding):(s=t.low.x,o=0),t.high.y>=n?(r=dg(t,n),a=t.winding):(r=t.high.x,a=0),s<r?(i.push(new Yo(s,o,t.shapeId,-1)),i.push(new Yo(r,a,t.shapeId,1))):(i.push(new Yo(r,a,t.shapeId,-1)),i.push(new Yo(s,o,t.shapeId,1)))}function Gb(i,t,e){let n=t+e,s=Array(n),o=Array(n),r;for(r=0;r<=n;r++)s[r]=0,o[r]=0;let a=[],l=!1,c=i.length;for(let u=0;u<c;u++){let d=i[u];s[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let h=!1;for(r=0;r<t;r++)if(s[r]&&!o[r]){h=!0;break}if(h){for(r=t;r<=n;r++)if(s[r]||o[r]){h=!1;break}}l!=h&&(a.push(d.x),l=h)}return a}function Wb(i,t){return t?Math.ceil(i/t)*t:i}function pg(i,t){return t?Math.floor(i/t)*t:i}function $b(i){return new dn(i.y,-i.x)}function Ko(i){return new tt(i.y1,-i.x2,i.y2,-i.x1)}function Ka(i){return new tt(-i.y2,i.x1,-i.y1,i.x2)}function hg(i){return new to(i.points.map(t=>$b(t)))}function fg(i,t,e,n,s,o){o&&(i=Ko(i),t=t.map(b=>hg(b)),e=e.map(b=>hg(b)));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(Hb);let g=0;for(;c[g].shapeId>=r;)g++;let m=c[g].low.y;m>i.y1&&l.push(new pn(i.y1,m,i.x2,i.x2));let C=0,x=[];for(;C<f&&(h=c[C]).low.y<m;)h.high.y>m&&x.push(h),C++;for(;C<f||x.length>0;){let b=i.y2,N=Math.min(Wb(Math.ceil(m+n),s),i.y2);for(d=0;d<x.length&&b>N;d++)h=x[d],h.low.x==h.high.x?h.high.y<b&&(b=Math.max(pg(h.high.y,s),N)):h.low.x!=h.high.x&&(b=N);for(b>i.y2&&(b=i.y2);C<f&&(h=c[C]).low.y<b;){if(h.high.y<m){C++;continue}if(h.low.y<N)h.low.y==h.high.y&&h.low.y==m||(x.push(h),b=N),C++;else{let v=pg(h.low.y,s);v<b&&(b=v);break}}let S=[];for(d=0;d<x.length;d++)zb(S,x[d],m,b);S.sort((v,w)=>v.x-w.x||v.lowOrHigh-w.lowOrHigh);let E=Gb(S,r,a);if(E.length==0)l.push(new pn(m,b,i.x2,i.x2));else{let v=0,w=i.x1;for(d=0;d<E.length;d+=2){let A=Math.max(i.x1,E[d]),I=Math.min(i.x2,E[d+1])-A;I>v&&(v=I,w=A)}v==0?l.push(new pn(m,b,i.x2,i.x2)):l.push(new pn(m,b,Math.max(w,i.x1),Math.min(w+v,i.x2)))}if(b==i.y2)break;for(m=b,d=x.length-1;d>=0;d--)x[d].high.y<=b&&x.splice(d,1)}return gg(i,l),l}function gg(i,t){let e=t.length-1,n=new pn(i.y2,i.y2,i.x1,i.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 mg(i,t){let e=0,n=i.length;for(;e<n;){let s=Math.floor((e+n)/2);t>=i[s].y2?e=s+1:n=s}return e}function Cg(i,t){if(!i.length)return t;let e=t.y1,n,s;for(s=0;s<i.length&&(n=i[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)e=Math.max(e,n.y2);let o=e;for(;s<i.length&&(n=i[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)o=n.y2;return s===i.length?o=t.y2:o=Math.min(o,t.y2),o<=e?null:new tt(t.x1,e,t.x2,o)}function bg(i,t){if(!i.length)return t;let e=t.y2,n,s;for(s=i.length-1;s>=0&&(n=i[s],!(s===i.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 o=Math.min(e,n.y2);for(;s>=0&&(n=i[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)o=n.y1;return o=Math.max(o,t.y1),e<=o?null:new tt(t.x1,o,t.x2,e)}function yg(i,t,e,n){let s=e.y1,o=e.x2-e.x1,r=e.y2-e.y1,a=mg(t,s);for(;;){let l=s+r;if(l>i.y2)return!1;let c=i.x1,u=i.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+o<=u||a>=t.length)return n=="left"?(e.x1=c,e.x2=c+o):(e.x1=u-o,e.x2=u),e.y2+=s-e.y1,e.y1=s,!0;s=t[a].y2,a++}}function xg(i,t,e,n,s){for(n||(n=[new pn(e.y1,e.y2,e.x1,e.x2)]);n.length>0&&n[0].y2<=i.y1;)n.shift();if(n.length==0)return;n[0].y1<i.y1&&(n[0].y1=i.y1);let o,r=t.length==0?i.y1:t[t.length-1].y2;r<i.y2&&t.push(new pn(r,i.y2,i.x1,i.x2));let a=mg(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(o=t[a],a++,t.splice(a,0,new pn(l.y1,o.y2,o.x1,o.x2)),o.y2=l.y1);a<t.length&&(o=t[a++],o.y2>l.y2&&(t.splice(a,0,new pn(l.y2,o.y2,o.x1,o.x2)),o.y2=l.y2),l.x1!=l.x2&&(s=="left"?o.x1=Math.min(l.x2,i.x2):o.x2=Math.max(l.x1,i.x1)),o.y2!=l.y2););}gg(i,t)}var Uu=class extends It{constructor(){super();p(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Sg(i){if(i){let t=new Uu;try{return i.visit(t),t.propSet}catch(e){O.warn(e,"toSet:")}}return{}}var Hu=class extends It{constructor(e){super();this.value=e}visitInt(e){return this.value=e.num,e}};function Wu(i,t){if(i){let e=new Hu(t);try{return i.visit(e),e.value}catch(n){O.warn(n,"toInt: ")}}return t}var zu=class extends It{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 k(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,o,r){if(this.coords.length>0){let a=[];switch(this.coords.forEach((l,c)=>{if(l.unit=="%"){let u=c%2==0?s:o;c==3&&this.name=="circle"&&(u=Math.sqrt((s*s+o*o)/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 dn(e+a[c],n+a[c+1]));return new to(l)}break;case"rectangle":if(a.length==4)return Jr(e+a[0],n+a[1],e+a[0]+a[2],n+a[1]+a[3]);break;case"ellipse":if(a.length==4)return _u(e+a[0],n+a[1],a[2],a[3]);break;case"circle":if(a.length==3)return _u(e+a[0],n+a[1],a[2],a[2]);break}}return null}};function Ja(i,t,e,n,s,o){if(i){let r=new zu;try{return i.visit(r),r.getShape(t,e,n,s,o)}catch(a){O.warn(a,"toShape:")}}return Jr(t,e,t+n,e+s)}var Gu=class extends It{constructor(e,n){super();this.reset=e;this.defaultValue=n;p(this,"counters",Object.create(null));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)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function ys(i,t){var o,r;let e=(o=t==null?void 0:t.reset)!=null?o:!1,n=(r=t==null?void 0:t.defaultValue)!=null?r:e?0:1,s=new Gu(e,n);try{i.visit(s)}catch(a){O.warn(a,"toCounters:")}return s.counters}var Qa=class extends Kt{constructor(e,n){super();this.baseUrl=e;this.transformer=n}visitURL(e){return new Pe(this.transformer.transformURL(e.url,this.baseUrl))}};function no(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function Xb(i){return i.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,e,n)=>e?String.fromCodePoint(parseInt(e,16)):n)}function Qo(i,t){var e,n;if(t==="content"){let s=i.cloneNode(!0);return s.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),s.textContent||""}else if(t==="marker"){let s=i.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(s)return s.textContent||"";let o=(n=(e=i.ownerDocument.defaultView)==null?void 0:e.getComputedStyle(i))==null?void 0:n.getPropertyValue("--viv-marker-content");if(o){let r=o.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(r&&r.length>0)return r.map(a=>Xb(a.substring(1,a.length-1))).join("")}return""}else{let s=i.querySelector(`[data-adapt-pseudo="${t}"]`);return s&&s.textContent||""}}var ju=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}},Yu=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()}},qu=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",Object.create(null));p(this,"runningElements",Object.create(null))}setStyler(t){this.styler=t}getFragment(t){let e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null}getTransformedId(t){let e=this.counterStore.documentURLTransformer.transformURL(ee(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 te(this.pageScope,()=>e(n()),`page-counter-${t}`),o=r=>e(r[r.length-1]);return this.counterStore.registerPageCounterExpr(t,o,s),s}getPageCountersVal(t,e){let n=()=>this.counterStore.currentPageCounters[t]||[],s=new te(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}getTargetPageDocCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[t]||null}adjustCountersForCrossScope(t,e,n,s){if(!this.counterStore.isPageControlledCounter(t)||!n)return e;let o=n[t]||[],r=o.length?o[o.length-1]:0,a=(s==null?void 0:s[t])||[],l=a.length?a[0]:0;return e.length?[r+(e[0]-l),...e.slice(1)]:[r]}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"?Qo(s,e):Qo(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),o=this.getTransformedId(t),r=new te(this.pageScope,()=>{let a=this.getTargetCounters(s,o,!0);if(a)if(a[e]){let l=a[e],c=this.getTargetPageCounters(o),u=this.getTargetPageDocCounters(o),d=this.adjustCountersForCrossScope(e,l,c,u);return c&&this.counterStore.resolveReference(o),n(d[d.length-1]||null)}else{let l=this.getTargetPageCounters(o);if(l)if(this.counterStore.resolveReference(o),l[e]){let c=l[e];return n(c[c.length-1]||null)}else return n(0);else return this.counterStore.saveReferenceOfCurrentPage(o,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(o,!1),"??"},`target-counter-${e}-of-${t}`);return this.counterStore.registerTargetCounterExpr(e,n,r,o),r}getTargetCountersVal(t,e,n){let s=this.getFragment(t),o=this.getTransformedId(t);return new te(this.pageScope,()=>{let r=this.getTargetPageCounters(o);if(r){this.counterStore.resolveReference(o);let a=this.getTargetCounters(s,o,!0),l=(a==null?void 0:a[e])||[],c=this.getTargetPageDocCounters(o),u=this.adjustCountersForCrossScope(e,l,r,c);if(u.length)return n(u);let d=r[e]||[];return n(d)}else return this.counterStore.saveReferenceOfCurrentPage(o,!1),"??"},`target-counters-${e}-of-${t}`)}getTargetTextVal(t,e){let n=this.getTransformedId(t),s=new te(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(js);return u?u[0]:""}let o=this.getTargetPageText(n,e);return o!==null?(this.counterStore.resolveReference(n),o):(this.counterStore.saveReferenceOfCurrentPage(n,!1),"??")},`target-text-${e}-of-${t}`);return this.counterStore.registerTargetTextExpr(e,s,n),s}getNamedStringVal(t,e){return new te(this.pageScope,()=>this.getRunningValue(this.namedStringValues,t,e),`named-string-${e}-${t}`)}getRunningElementVal(t,e){return new te(this.pageScope,()=>this.getRunningValue(this.runningElements,t,e),`running-element-${e}-${t}`)}getRunningValue(t,e,n){let s=t[e];if(!s)return"";let o=Object.keys(s).map(g=>parseInt(g,10)).sort(Na),r=this.counterStore.currentPage;if(!r)return"";let a=r.isBlankPage?r.offset-1:r.offset,l=r.isBlankPage?a:Math.max(a,...Array.from(r.container.querySelectorAll(`[${Ut}]`)).map(g=>parseInt(g.getAttribute(Ut),10))),c=-1,u=-1,d=-1,h=-1;for(let g=0;g<o.length;g++){let m=o[g],C=g>0?o[g-1]:-1,x=g<o.length-1?o[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{C<c&&(u=C);let b=r.container.querySelector(`[${Ut}="${m}"]`);if(!b)u<0&&(u=m);else{let N=r.container.querySelector(`[${Ut}="${a}"]`);if(N||(N=r.container.querySelector(`[${Ut}="0"]`)),N){for(let S=N;S;S=S.firstElementChild)if(S===b){u=m;break}}}}d=m}else(x>l||x<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]=Object.create(null));s[n]=e}setRunningElement(t,e){let n=this.runningElements[t]||(this.runningElements[t]=Object.create(null));n[e]=String(e)}},el=class{constructor(t){this.documentURLTransformer=t;p(this,"countersById",Object.create(null));p(this,"pageCountersById",Object.create(null));p(this,"pageDocCountersById",Object.create(null));p(this,"pageTextById",Object.create(null));p(this,"currentPageDocCounters",null);p(this,"previousPageDocCounters",null);p(this,"currentPageDocCounterChanges",Object.create(null));p(this,"currentPageDocCounterChangeTypes",Object.create(null));p(this,"currentPageCounters",Object.create(null));p(this,"previousPageCounters",Object.create(null));p(this,"currentPageCountersStack",[]);p(this,"pageIndicesById",Object.create(null));p(this,"currentPage",null);p(this,"newReferencesOfCurrentPage",[]);p(this,"referencesToSolve",[]);p(this,"referencesToSolveStack",[]);p(this,"unresolvedReferences",Object.create(null));p(this,"resolvedReferences",Object.create(null));p(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0}));p(this,"pagesCounterExprs",[]);p(this,"pageCounterExprs",[]);p(this,"targetCounterExprs",[]);p(this,"targetTextExprs",[]);this.currentPageCounters.page=[0]}createCounterListener(t){return new Yu(this,t)}createCounterResolver(t,e,n){return new qu(this,t,e,n)}setCurrentPage(t){this.currentPage=t}setCurrentPageDocCounters(t,e,n){this.previousPageDocCounters=this.currentPageDocCounters?no(this.currentPageDocCounters):null,this.currentPageDocCounters=t?no(t):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=n?{...n}:Object.create(null),e&&e.forEach(s=>{this.currentPageDocCounterChanges[s]=!0})}setPageControlledCounterNames(t){let e=Object.assign(Object.create(null),{page:!0});t.forEach(n=>{e[n]=!0}),this.pageControlledCounterNames=e}isPageControlledCounter(t){return!!this.pageControlledCounterNames[t]}definePageCounter(t,e){this.currentPageCounters[t]?this.currentPageCounters[t].push(e):this.currentPageCounters[t]=[e]}forceSetPageCounter(t){let e=this.currentPageCounters.page;!e||!e.length?this.currentPageCounters.page=[t]:e[e.length-1]=t}updatePageCounters(t,e){this.previousPageCounters=no(this.currentPageCounters);let n=this.currentPageDocCounterChanges||{},s=this.currentPageDocCounterChangeTypes||{},o=Object.create(null);if(this.currentPageDocCounters){let m=this.previousPageDocCounters||{};for(let C in this.currentPageDocCounters){if(!n[C])continue;let x=this.currentPageDocCounters[C],b=x.length?x[x.length-1]:0,N=m[C]||[],S=N.length?N[N.length-1]:0,E=b-S,v=s[C],w=v==="reset"||v==="set";o[C]={delta:E,reset:w,value:b}}}let r=Object.create(null),a,l=t["counter-reset"];if(l){let m=l.evaluate(e);m&&(a=ys(m,{reset:!0}))}a&&"pages"in a&&delete a.pages;let c,u=t["counter-set"];if(u){let m=u.evaluate(e);m&&(c=ys(m,{defaultValue:0}))}c&&"pages"in c&&delete c.pages;let d=[];if(a)for(let m in a)d.push(m);if(c)for(let m in c)d.push(m);let h,f=t["counter-increment"];if(f){let m=f.evaluate(e);m&&(h=ys(m))}h&&"pages"in h&&delete h.pages,h?!("page"in h)&&!(o.page&&o.page.reset)&&(h.page=1):(h=Object.create(null),o.page&&o.page.reset||(h.page=1));for(let m in h)d.push(m);this.setPageControlledCounterNames(d);let g=no(this.previousPageCounters);if(this.currentPageDocCounters)for(let m in this.currentPageDocCounters){if(this.isPageControlledCounter(m)){let C=o[m];if(C){if(C.reset)g[m]=[C.value],r[m]=!0;else if(C.delta!==0){g[m]||(g[m]=[0]);let x=g[m];x[x.length-1]+=C.delta}}continue}g[m]=Array.from(this.currentPageDocCounters[m])}if(this.currentPageCounters=g,a)for(let m in a)this.definePageCounter(m,a[m]);if(c)for(let m in c)if(!this.currentPageCounters[m])this.definePageCounter(m,c[m]);else{let C=this.currentPageCounters[m];C[C.length-1]=c[m]}for(let m in h){if(r[m])continue;this.currentPageCounters[m]||this.definePageCounter(m,0);let C=this.currentPageCounters[m];C[C.length-1]+=h[m]}}pushPageCounters(t){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=no(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 o=0;o<this.referencesToSolve.length;){let r=this.referencesToSolve[o];if(r.targetId===t){if(r.resolve(),this.referencesToSolve.splice(o,1),e){let a=e.indexOf(r);a>=0&&e.splice(a,1)}n.push(r),s=!0}else o++}s||this.saveReferenceOfCurrentPage(t,!0)}saveReferenceOfCurrentPage(t,e){if(!this.newReferencesOfCurrentPage.some(n=>n.targetId===t)){let n=new ju(t,e);this.newReferencesOfCurrentPage.push(n)}}finishPage(t,e){let n=Object.keys(this.currentPage.elementsById);if(n.length>0){let r=no(this.currentPageCounters),a=this.currentPageDocCounters?no(this.currentPageDocCounters):null;n.forEach(l=>{this.pageCountersById[l]=r,a&&(this.pageDocCountersById[l]=a);let c=this.currentPage.elementsById[l];if(c&&c.length>0){let d=c[0];this.pageTextById[l]={content:Qo(d,"content"),before:Qo(d,"before"),after:Qo(d,"after"),marker:Qo(d,"marker")}}let u=this.pageIndicesById[l];if(u&&u.pageIndex<e){let d=this.resolvedReferences[l];if(d){let h=this.unresolvedReferences[l];h||(h=this.unresolvedReferences[l]=[]);let f;for(;f=d.shift();)f.unresolve(),h.push(f)}}this.pageIndicesById[l]={spineIndex:t,pageIndex:e}})}let s=this.previousPageCounters,o;for(;o=this.newReferencesOfCurrentPage.shift();){o.pageCounters=s,o.spineIndex=t,o.pageIndex=e;let r;o.isResolved()?(r=this.resolvedReferences[o.targetId],r||(r=this.resolvedReferences[o.targetId]=[])):(r=this.unresolvedReferences[o.targetId],r||(r=this.unresolvedReferences[o.targetId]=[])),r.every(a=>!o.equals(a))&&r.push(o)}this.currentPage=null}adjustPageCountersOfLaterSpines(t,e){if(e<=0)return;let n=new Set;for(let s of Object.keys(this.pageIndicesById))if(this.pageIndicesById[s].spineIndex>t){let r=this.pageCountersById[s];r&&r.page&&!n.has(r)&&(n.add(r),r.page=r.page.map(a=>a+e))}}updateTargetCounterNodesInPages(t){for(let e of t){if(!e||!e.container)continue;let n=e.container.querySelectorAll(`[${ti}]`);for(let s of n){let o=s.getAttribute(ti),r=this.targetCounterExprs.find(a=>a.expr.key===o);if(r&&r.transformedId){let a=this.pageCountersById[r.transformedId];if(a){let l=a[r.name];l&&(s.textContent=r.format(l[l.length-1]))}}}}}getPageCountersForPage(t,e){let n=Object.keys(t.elementsById);for(let s of n){let o=this.pageCountersById[s];if(o)return o}return e||null}updatePageCounterNodesInPages(t,e){var n;for(let s=0;s<t.length;s++){let o=t[s];if(!(o!=null&&o.container))continue;let r=this.getPageCountersForPage(o,e==null?void 0:e[s]);if(!r)continue;let a=o.container.querySelectorAll(`[${ei}]`);for(let l of a){let c=l.getAttribute(ei),u=this.pageCounterExprs.find(g=>g.expr.key===c);if(!u)continue;let d=(n=u.expr)==null?void 0:n.str,h=d==null?void 0:d.replace(/^page-counters?-/,""),f=r[h];f&&(l.textContent=u.format(f))}}}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=[],o=null;return e.forEach(r=>{!o||o.spineIndex!==r.spineIndex||o.pageIndex!==r.pageIndex?(o={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},s.push(o)):o.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 te){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(`[${Ut}="${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(ti,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(Xu,t.key),r}}let s=this.pagesCounterExprs.findIndex(r=>r.expr===t)>=0,o=!s&&this.pageCounterExprs.findIndex(r=>r.expr===t)>=0;if(s||o){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute(s?$u:ei,t.key),r}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${ei}]`);for(let o of e){let r=o.getAttribute(ei),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&&(o.textContent=a.format(u))}let n=t.querySelectorAll(`[${ti}]`);for(let o of n)o.setAttribute(Eg,!0);let s=t.querySelectorAll(`[${Xu}]`);for(let o of s)o.setAttribute(vg,!0)}finishLastPage(t){var r;let e=t.root.querySelectorAll(`[${$u}]`),n=t.contentContainer.childElementCount;for(let a of e){let l=a.getAttribute($u),c=this.pagesCounterExprs.findIndex(u=>u.expr.key===l);c>=0,a.textContent=this.pagesCounterExprs[c].format([n])}let s=t.root.querySelectorAll(`[${Eg}]`);for(let a of s){let l=a.getAttribute(ti),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 o=t.root.querySelectorAll(`[${vg}]`);for(let a of o){let l=a.getAttribute(Xu),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 Ku(this,t)}},$u="data-vivliostyle-pages-counter",ei="data-vivliostyle-page-counter",ti="data-vivliostyle-target-counter",Xu="data-vivliostyle-target-text",Eg="data-vivliostyle-target-counter-in-running",vg="data-vivliostyle-target-text-in-running",Ku=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 Yb(i){if(i=i.substr(1),i.match(/^[^0-9a-fA-F\n\r]$/))return i;let t=parseInt(i,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function so(i){return i.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Yb)}var Qu=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 Ge(i,t){let e=Array(128),n;for(n=0;n<128;n++)e[n]=i;for(e[NaN]=i==35?35:72,n=0;n<t.length;n+=2)e[t[n]]=t[n+1];return e}var qn=[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];qn[NaN]=80;var kn=[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];kn[NaN]=43;var qb=[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];kn[NaN]=43;var Tg=[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];Tg[NaN]=35;var wg=[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];wg[NaN]=45;var Ju=[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];Ju[NaN]=37;var ed=[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];ed[NaN]=38;var oo=Ge(35,[61,36]),Kb=Ge(35,[58,77]),Zb=Ge(35,[61,36,124,50]),Qb=Ge(35,[38,51]),Jb=Ge(35,[42,54]),ey=Ge(39,[42,55]),ty=Ge(54,[42,55,47,56]),ny=Ge(62,[62,82]),sy=Ge(35,[61,36,33,70]),oy=Ge(62,[45,71]),ry=Ge(63,[45,81]),Zu=Ge(76,[10,72,13,72]),iy=Ge(39,[39,46,10,72,13,72,92,48]),ay=Ge(39,[34,46,10,72,13,72,92,49]),ly=Ge(39,[39,47,10,74,13,74,92,48]),cy=Ge(39,[34,47,10,74,13,74,92,49]),Ng=Ge(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),uy=Ge(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),dy=Ge(39,[39,68,10,74,13,74,92,75,NaN,67]),py=Ge(39,[34,68,10,74,13,74,92,75,NaN,67]),hy=Ge(72,[9,39,10,39,13,39,32,39,41,69]),fy=15,it=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=fy,this.buffer=Array(this.indexMask+1);for(let n=0;n<=this.indexMask;n++)this.buffer[n]=new Qu}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=qn,o=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=o.charCodeAt(r);switch(s[m]||s[65]){case 72:u=o.substring(c,r),isNaN(m)?l=0:l=54,s=qn;break;case 1:r++,h=!0;continue;case 2:c=r++,s=Ju;continue;case 3:l=1,c=r++,s=kn;continue;case 4:c=r++,l=31,s=oo;continue;case 33:l=2,c=++r,s=iy;continue;case 34:l=2,c=++r,s=ay;continue;case 6:c=++r,l=7,s=kn;continue;case 7:c=r++,l=32,s=oo;continue;case 8:c=r++,l=21;break;case 9:c=r++,l=32,s=Qb;continue;case 10:c=r++,l=10;break;case 11:c=r++,l=11;break;case 12:c=r++,l=36,s=oo;continue;case 13:c=r++,l=23;break;case 14:c=r++,l=16;break;case 15:l=24,c=r++,s=Tg;continue;case 16:c=r++,s=qb;continue;case 78:c=r++,l=9,s=kn;continue;case 17:c=r++,l=19,s=Jb;continue;case 18:c=r++,l=18,s=Kb;continue;case 77:r++,l=50;break;case 19:c=r++,l=17;break;case 20:c=r++,l=38,s=sy;continue;case 21:c=r++,l=39,s=oo;continue;case 22:c=r++,l=37,s=oo;continue;case 23:c=r++,l=22;break;case 24:c=++r,l=20,s=kn;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=Zu;continue;case 30:c=r++,l=33,s=oo;continue;case 31:c=r++,l=34,s=Zb;continue;case 32:c=r++,l=35,s=oo;continue;case 35:break;case 36:r++,l=l+41-31;break;case 37:l=5,d=parseInt(o.substring(c,r),10);break;case 38:l=4,d=parseFloat(o.substring(c,r));break;case 39:r++;continue;case 40:l=3,d=parseFloat(o.substring(c,r)),c=r++,s=kn;continue;case 41:l=3,d=parseFloat(o.substring(c,r)),u="%",c=r++;break;case 42:r++,s=ed;continue;case 43:if(u=so(o.substring(c,r)),l===27&&m===63||l===1&&u.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(o.substring(r-1))){l=27,r++;continue}break;case 44:g=r++,s=Zu;continue;case 45:u=so(o.substring(c,r));break;case 46:u=o.substring(c,r),r++;break;case 47:u=so(o.substring(c,r)),r++;break;case 48:g=r,r+=2,s=ly;continue;case 49:g=r,r+=2,s=cy;continue;case 50:r++,l=25;break;case 51:r++,l=26;break;case 52:if(u=o.substring(c,r),l==1){if(r++,u.toLowerCase()=="url"){s=Ng;continue}l=6}break;case 53:if(u=so(o.substring(c,r)),l==1){if(r++,u.toLowerCase()=="url"){s=Ng;continue}l=6}break;case 54:s=ey,r++;continue;case 55:s=ty,r++;continue;case 56:s=qn,r++;continue;case 57:s=ny,r++,o[r]!==">"&&(l=1,s=kn);continue;case 81:l=51,u=o.substring(c,++r),s=qn;break;case 82:l=52,u=o.substring(c,++r),s=qn;break;case 58:l=5,s=Ju,r++;continue;case 59:l=4,s=ed,r++;continue;case 60:l=1,s=kn,r++;continue;case 61:l=1,s=Zu,g=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:c=r++,s=uy;continue;case 65:c=++r,s=dy;continue;case 66:c=++r,s=py;continue;case 67:l=8,u=so(o.substring(c,r)),r++;break;case 69:r++;break;case 70:s=oy,r++;continue;case 71:s=ry,r++;continue;case 79:if(r-g<8&&o.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:l=8,u=so(o.substring(c,r)),r++,s=hy;continue;case 74:if(r++,r-g<9&&o.substring(g+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;l=54,u="E_CSS_UNEXPECTED_NEWLINE",s=qn;break;case 73:if(r-g<9&&o.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,s=kn;continue}u=so(o.substring(c,r));break;case 75:g=r++;continue;case 76:r++,s=wg;continue;default:if(s!==qn){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=qn,h=!1,f=a[t&n]}this.position=r,this.tail=t&n}};var He=null,td=null;function oi(){return He}function L(i){if(!He)throw new Error("E_TASK_NO_CONTEXT");He.name||(He.name=i);let t=He,e=new Jo(t,t.top,i);return t.top=e,e.state=1,e}function gy(i){return new sd(i||new nd)}function T(i){return new si(i)}function Kn(i,t,e){let n=L(i);n.handler=e;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function Pg(i,t){return(He?He.getScheduler():td||gy()).run(i,t)}var nd=class{currentTime(){return new Date().valueOf()}setTimeout(t,e){return setTimeout(t,e)}clearTimeout(t){clearTimeout(t)}},sd=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 va,td||(td=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){O.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let n=new od(this,e||"");n.top=new Jo(n,null,"bootstrap"),n.top.state=1,n.top.then(()=>{let o=()=>{n.running=!1;for(let r of n.callbacks)try{r()}catch(a){O.error(a)}};try{t().then(r=>{n.result=r,o()})}catch(r){n.raise(r),o()}});let s=He;return He=n,this.schedule(n.top.suspend("bootstrap")),He=s,n}},tl=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=He;return He=t,t.top.finish(this.result),He=e,!0}return!1}cancel(){this.canceled=!0}},od=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!==He&&this.continuation){this.continuation.cancel();let e=new tl(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=L("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&&O.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 B=new wu;var St=(d=>(d.SIMPLE_PROPERTY="SIMPLE_PROPERTY",d.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",d.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",d.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",d.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",d.CONFIGURATION="CONFIGURATION",d.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",d.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",d.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",d.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",d.PAGINATION_PROGRESS="PAGINATION_PROGRESS",d))(St||{}),ka={};function je(i,t,e){if(!St[i])B.warn(new Error(`Skipping unknown plugin hook '${i}'.`));else{let n=ka[i];n||(n=ka[i]=[]),e?n.unshift(t):n.push(t)}}function ug(i,t){if(!St[i])B.warn(new Error(`Ignoring unknown plugin hook '${i}'.`));else{let e=ka[i];if(e){let n=e.indexOf(t);n>=0&&e.splice(n,1)}}}function Je(i){return ka[i]||[]}var ry={registerHook:je,removeHook:ug};var Aa=class{constructor(t){this.performanceInstance=t;p(this,"timestamps",{});p(this,"registerTiming");p(this,"registerStartTiming");p(this,"registerEndTiming");this.registerTiming=Bo,this.registerStartTiming=this.registerStartTiming=Bo,this.registerEndTiming=this.registerEndTiming=Bo}forceRegisterStartTiming(t,e){ku.call(this,t,"start",e)}forceRegisterEndTiming(t,e){ku.call(this,t,"end",e)}printTimings(){let t=this.timestamps,e="";Object.keys(t).forEach(n=>{let s=t[n],o=s.length;for(let r=0;r<o;r++){let a=s[r];e+=n,o>1&&(e+=`(${r})`),e+=` => start: ${a.start}, end: ${a.end}, duration: ${a.end-a.start}
4
+ `}}),B.info(e)}disable(){this.registerTiming=Bo,this.registerStartTiming=this.registerStartTiming=Bo,this.registerEndTiming=this.registerEndTiming=Bo}enable(){this.registerTiming=ku,this.registerStartTiming=this.registerStartTiming=dg,this.registerEndTiming=this.registerEndTiming=iy}isEnabled(){return this.registerStartTiming===dg}};function Bo(){}function ku(i,t,e){e||(e=this.performanceInstance.now());let n=this.timestamps[i];n||(n=this.timestamps[i]=[]);let s,o=n.length;for(let r=o-1;r>=0&&(s=n[r],!(s&&!s[t]));r--)s=null;s||(s={},n.push(s)),s[t]=e}function dg(i,t){this.registerTiming(i,"start",t)}function iy(i,t){this.registerTiming(i,"end",t)}var ay={now:Date.now},ly=window&&window.performance,ht=new Aa(ly||ay);ht.forceRegisterStartTiming("load_vivliostyle");var cy={profiler:{registerStartTiming:ht.registerStartTiming,registerEndTiming:ht.registerEndTiming,printTimings:ht.printTimings,disable:ht.disable,enable:ht.enable}};var Mo=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",qs=/^[\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",hg={};function _o(i){return JSON.parse(i)}function Gt(i){let t=i.match(/^([^#]*)/);return t?t[1]:i}function fg(i){let t=i.match(/^([^#?]*)/);return t?t[1]:i}var Tn=window.location.href;function Au(i){Tn=i}var cn=window.location.href;function Ru(i){cn=i}function uy(i){let t=fg(i).match(/^(https?:\/\/raw\.githubusercontent\.com\/web-platform-tests\/wpt\/master)(?:\/|$)/);return t?t[1]:null}function te(i,t){if(/^data:/i.test(t))return i||t;if(!t||i.match(/^\w{2,}:/))return i.toLowerCase().match("^javascript:")?"#":(i.match(/^\w{2,}:\/\/[^\/]+$/)&&(i=`${i}/`),i);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let e;if(i.match(/^\/\//))return e=t.match(/^(\w{2,}:)\/\//),e?e[1]+i:i;if(i.match(/^\//)){let r=uy(t);return r?r+i:(e=t.match(/^(\w{2,}:\/\/[^\/]+)\//),e?e[1]+i:i)}if(i.match(/^\.(\/|$)/)&&(i=i.substr(2)),t=fg(t),i.match(/^#/))return t+i;let n=t.lastIndexOf("/");if(n<0)return i;let s=t.substr(0,n+1)+i,o="";for(e=s.match(/^([^?#]*)([?#].*)$/),e&&(s=e[1],o=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,"/")+o}function Ks(i,t){return i.match(/^#/)&&t?Gt(t)+i:te(i,t)}function Xn(i){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(i))?i=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/wpt\.live\/(.*)$/.exec(i))?i=`${t[1]}//raw.githubusercontent.com/web-platform-tests/wpt/master/${t[2]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(i))?i=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(i))?i=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(i))?i=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(i))&&(i=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),i}function Lu(i){return i==null?i:i.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 o=s*2;if(o>=n)break;if(this.queue[o].compare(e)>0)o+1<n&&this.queue[o+1].compare(this.queue[o])>0&&o++;else if(o+1<n&&this.queue[o+1].compare(e)>0)o++;else break;this.queue[s]=this.queue[o],s=o}this.queue[s]=e}return t}},Iu=["","-webkit-","-moz-"],Do={};function Gr(i,t){return CSS.supports(i+t,"unset")}function dy(i){let t=Do[i];if(t||t===null)return t;switch(i){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Do[i]=null,null;case"text-combine-upright":if(Gr("-webkit-","text-combine")&&!Gr("","text-combine-upright"))return Do[i]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let e of Iu)if(Gr(e,i))return t=[e+i],Do[i]=t,t;return B.warn("Property not supported by the browser: ",i),Do[i]=null,null}function P(i,t,e){let n=i==null?void 0:i.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,e||" ");return}let s=dy(t);if(s)for(let o of s){switch(o){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(o,e)}}function un(i,t,e){try{let n=Do[t];return i.style.getPropertyValue(n?n[0]:t)}catch(n){}return e||""}function $r(i){let t=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&i.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=i.getAttribute("lang")),t}var lt=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 gg(i){return`\\${i.charCodeAt(0).toString(16)} `}function wn(i){return i.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,gg)}function Zs(i){return i.replace(/[\u0000-\u001F"\\]/g,gg)}function Fu(i){return i.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Vu(i){return!!i.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function py(i,t){return t=typeof t=="string"?t:"\\u",t+(65536|i.charCodeAt(0)).toString(16).substr(1)}function Ou(i,t){function e(n){return py(n,t)}return i.replace(/[^-a-zA-Z0-9_]/g,e)}function jn(i){return Ou(i)}function hy(i,t){return t=typeof t=="string"?t:"\\u",i.indexOf(t)===0?String.fromCharCode(parseInt(i.substring(t.length),16)):i}function mg(i,t){t=typeof t=="string"?t:"\\u";function e(s){return hy(s,t)}let n=new RegExp(`${jn(t)}[0-9a-fA-F]{4}`,"g");return i.replace(n,e)}function Ft(i,t){let e=0,n=i;for(;;){if(e<=n,e==0||t(e-1),n==i||t(n),e==n)return e;let s=e+n>>1;t(s)?n=s:e=s+1}}function La(i,t){return i-t}function Bu(i,t){let e={};for(let n of i){let s=t(n);s&&!e[s]&&(e[s]=n)}return e}function Cg(i){let t={};for(let e=0;e<i.length;e++)t[i[e]]=!0;return t}function Ia(i,t){let e={};for(let n of i){let s=t(n);s&&(e[s]?e[s].push(n):e[s]=[n])}return e}function bg(i,t){let e={};for(let n in i)e[n]=t(i[n],n);return e}var gs=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 o=s.indexOf(e);o>=0&&s.splice(o,1)}}},Pn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Du(){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 Xa(i){return{fontFamily:i.fontFamily,lineHeight:i.lineHeight,margin:i.margin,hyphenate:i.hyphenate,columnWidth:i.columnWidth,horizontal:i.horizontal,nightMode:i.nightMode,spreadView:i.spreadView,pageBorder:i.pageBorder,enabledMediaTypes:Object.assign({},i.enabledMediaTypes),defaultPaperSize:i.defaultPaperSize?Object.assign({},i.defaultPaperSize):void 0}}var fy=Du(),yg={PENDING:{}};function Mu(i,t,e,n){let s=Math.min((i-0)/e,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function gy(i){return`"${Zs(`${i}`)}"`}function my(i){return wn(`${i}`)}function Zr(i,t){return i?`${wn(i)}.${wn(t)}`:wn(t)}var Sg=0,Qs=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${Sg++}`,this.zero=new we(this,0),this.one=new we(this,1),this._true=new we(this,!0),this._false=new we(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=Mu,n["css-string"]=gy,n["css-name"]=my,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 this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return 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 xg(i){switch(i==null?void 0:i.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function _u(i){switch(i==null?void 0:i.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 Eg(i){switch(i==null?void 0:i.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function vg(i){switch(i==null?void 0:i.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var ct={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 ja(i){switch(i){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 Uo=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=fy}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(_u(t)){let s=this.pageWidth()/100,o=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:s,a=this.pageAreaHeight!=null?this.pageAreaHeight/100:o,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 o;case"pvi":return l?o:s;case"pvb":return l?s:o;case"pvmin":return s<o?s:o;case"pvmax":return s>o?s:o}}return t=="em"||t=="rem"?e?this.initialFontSize:this.fontSize():t=="lh"||t=="rlh"?this.rootLineHeight:ct[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 o=t.funcs[e];if(o||t.resolver&&(o=t.resolver.call(this,e,!0),o))return o;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 we(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 o=null,r=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(o=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&&o!=null)switch(n){case"min":return r>=Number(o);case"max":return r<=Number(o);default:return r==o}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}},Vt=class{constructor(t){this.scope=t;p(this,"key");this.scope=t,this.key=`_${Sg++}`}toString(){let t=new lt;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===yg.PENDING?!1:s;{n[this.key]=yg.PENDING;let o=this.dependCore(t,e,n);return n[this.key]=o,o}}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}},Fa=class extends Vt{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)}},Ho=class extends Vt{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),o=this.rhs.expand(e,n);return s===this.lhs&&o===this.rhs?this:new this.constructor(this.scope,s,o)}},Va=class extends Ho{constructor(t,e,n){super(t,e,n)}getPriority(){return 1}},ms=class extends Ho{constructor(t,e,n){super(t,e,n)}getPriority(){return 2}},Oa=class extends Ho{constructor(t,e,n){super(t,e,n)}getPriority(){return 3}},Wr=class extends Ho{constructor(t,e,n){super(t,e,n)}getPriority(){return 4}},$t=class extends Fa{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},Ba=class extends $t{constructor(t,e){super(t,e)}getOp(){return"not "}},kn=class extends Fa{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},zo=class extends Va{constructor(t,e,n){super(t,e,n)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},Da=class extends zo{constructor(t,e,n){super(t,e,n)}getOp(){return" and "}},Go=class extends Va{constructor(t,e,n){super(t,e,n)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},Ma=class extends Go{constructor(t,e,n){super(t,e,n)}getOp(){return", "}},_a=class extends Go{constructor(t,e,n){super(t,e,n)}getOp(){return" or "}},Ua=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return"<"}evalInfix(t,e){return t<e}},Ha=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return"<="}evalInfix(t,e){return t<=e}},za=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return">"}evalInfix(t,e){return t>e}},Js=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return">="}evalInfix(t,e){return t>=e}},Cs=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return"=="}evalInfix(t,e){return t==e}},Ga=class extends ms{constructor(t,e,n){super(t,e,n)}getOp(){return"!="}evalInfix(t,e){return t!=e}},Xr=class extends Oa{constructor(t,e,n){super(t,e,n)}getOp(){return"+"}evalInfix(t,e){return t+e}},jr=class extends Oa{constructor(t,e,n){super(t,e,n)}getOp(){return" - "}evalInfix(t,e){return t-e}},eo=class extends Wr{constructor(t,e,n){super(t,e,n)}getOp(){return"*"}evalInfix(t,e){return t*e}},Yr=class extends Wr{constructor(t,e,n){super(t,e,n)}getOp(){return"/"}evalInfix(t,e){return t/e}},$o=class extends Wr{constructor(t,e,n){super(t,e,n)}getOp(){return"%"}evalInfix(t,e){return t%e}},dn=class extends Vt{constructor(e,n,s){var o;super(e);this.num=n;p(this,"unit");this.unit=(o=s==null?void 0:s.toLowerCase())!=null?o:""}appendTo(e,n){e.append(this.num.toString()),e.append(wn(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},Se=class extends Vt{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)}},qr=class extends Vt{constructor(e,n,s){super(e);this.not=n;this.name=s}appendTo(e,n){this.not&&e.append("not "),e.append(wn(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},ne=class extends Vt{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 Cy(i,t){i.append("(");for(let e=0;e<t.length;e++)e&&i.append(","),t[e].appendTo(i,0);i.append(")")}function by(i,t,e){let n=t;for(let s=0;s<t.length;s++){let o=t[s].expand(i,e);if(t!==n)n[s]=o;else if(o!==t[s]){n=Array(t.length);for(let r=0;r<s;r++)n[r]=t[r];n[s]=o}}return n}var Yn=class i extends Vt{constructor(e,n,s){super(e);this.qualifiedName=n;this.params=s}appendTo(e,n){e.append(this.qualifiedName),Cy(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=by(e,this.params,n);return s===this.params?this:new i(this.scope,this.qualifiedName,s)}},$a=class i extends Vt{constructor(e,n,s,o){super(e);this.cond=n;this.ifTrue=s;this.ifFalse=o}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),o=this.ifTrue.expand(e,n),r=this.ifFalse.expand(e,n);return s===this.cond&&o===this.ifTrue&&r===this.ifFalse?this:new i(this.scope,s,o,r)}},we=class extends Vt{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(Zs(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Kr=class i extends Vt{constructor(e,n,s){super(e);this.name=n;this.value=s}appendTo(e,n){e.append("("),e.append(Zs(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 i(this.scope,this.name,s)}},Wa=class extends Vt{constructor(e,n,s,o){super(e);this.name=n;this.value=s;this.isFunc=o}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)}},Wo=class extends Vt{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 xt(i,t,e){return t===i._false||t===i.zero||e==i._false||e==i.zero?i._false:t===i._true||t===i.one?e:e===i._true||e===i.one?t:new zo(i,t,e)}function K(i,t,e){return t===i.zero?e:e===i.zero?t:new Xr(i,t,e)}function ae(i,t,e){return t===i.zero?new kn(i,e):e===i.zero?t:new jr(i,t,e)}function Xo(i,t,e){return t===i.zero||e===i.zero?i.zero:t===i.one?e:e===i.one?t:new eo(i,t,e)}function Qr(i,t,e){return t===i.zero?i.zero:e===i.one?t:new Yr(i,t,e)}var Ot=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}},en=class extends Ot{constructor(){super();p(this,"error",!1)}visitValues(e){let n=null;for(let s=0;s<e.length;s++){let o=e[s],r=o.visit(this);if(this.error)return[];if(n)n[s]=r;else if(o!==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?$:n===e.values?e:new X(n)}visitCommaList(e){let n=this.visitValues(e.values);return this.error?$:n===e.values?e:new ve(n)}visitFunc(e){let n=this.visitValues(e.values);return this.error?$:n===e.values?e:new Bt(e.name,n)}visitExpr(e){return e}},_e=class{toString(){let t=new lt;return this.appendTo(t,!0),t.toString()}stringValue(){let t=new lt;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}},Ya=class Ya extends _e{static get instance(){return this.empty||(this.empty=new Ya),this.empty}constructor(){super()}toExpr(t,e){return new we(t,"")}appendTo(t,e){}visit(t){return t.visitEmpty(this)}};p(Ya,"empty");var Uu=Ya,$=Uu.instance,qa=class qa extends _e{static get instance(){return this.slash||(this.slash=new qa),this.slash}constructor(){super()}toExpr(t,e){return new we(t,"/")}appendTo(t,e){t.append("/")}visit(t){return t.visitSlash(this)}};p(qa,"slash");var Hu=qa,qn=Hu.instance,z=class extends _e{constructor(e){super();this.str=e}toExpr(e,n){return new we(e,this.str)}appendTo(e,n){n?(e.append('"'),e.append(Zs(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},zu=Object.create(null),Q=class extends _e{constructor(e){super();this.name=e;if(zu[e])throw new Error("E_INVALID_CALL");zu[e]=this}toExpr(e,n){return new we(e,this.name)}appendTo(e,n){n?e.append(wn(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function R(i){let t=zu[i];return t||(t=new Q(i)),t}var A=class extends _e{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 eo(e,n,new we(e,this.num/100)):new dn(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}},Ue=class extends _e{constructor(e){super();this.num=e}toExpr(e,n){return this.num==0?e.zero:this.num==1?e.one:new we(e,this.num)}appendTo(e,n){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},ce=class extends Ue{constructor(t){super(t)}visit(t){return t.visitInt(this)}},jo=class extends _e{constructor(e){super();this.hex=e}appendTo(e,n){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ke=class extends _e{constructor(e){super();this.url=e}appendTo(e,n){e.append('url("'),e.append(Zs(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Jr=class extends _e{constructor(e){super();this.urangeText=e}appendTo(e,n){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Gu(i,t,e,n){var o,r;let s=t.length;if(s>0){(o=t[0])==null||o.appendTo(i,n);for(let a=1;a<s;a++)i.append(e),(r=t[a])==null||r.appendTo(i,n)}}var X=class extends _e{constructor(e){super();this.values=e}appendTo(e,n){Gu(e,this.values," ",n)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},ve=class extends _e{constructor(e){super();this.values=e}appendTo(e,n){Gu(e,this.values,",",n)}visit(e){return e.visitCommaList(this)}},Bt=class extends _e{constructor(e,n){super();this.name=e;this.values=n}appendTo(e,n){e.append(wn(this.name)),e.append("("),Gu(e,this.values,",",n),e.append(")")}visit(e){return e.visitFunc(this)}},D=class extends _e{constructor(e){super();this.expr=e}toExpr(){return this.expr}appendTo(e,n){this.expr instanceof we||this.expr instanceof dn?this.expr.appendTo(e,0):(e.append("-epubx-expr("),this.expr.appendTo(e,0),e.append(")"))}visit(e){return e.visitExpr(this)}isExpr(){return!0}},An=class extends _e{constructor(e){super();this.text=e}appendTo(e,n){e.append(this.text||" ")}};function Ye(i,t){if(i){if(i.isNumeric()){let e=i;return t.queryUnitSize(e.unit,!1)*e.num}if(i.isNum())return i.num}return 0}function Ka(i,t){return new A(Ye(i,t),"px")}var S={absolute:R("absolute"),all:R("all"),always:R("always"),anywhere:R("anywhere"),auto:R("auto"),avoid:R("avoid"),balance:R("balance"),balance_all:R("balance-all"),block:R("block"),block_end:R("block-end"),block_start:R("block-start"),both:R("both"),bottom:R("bottom"),border_box:R("border-box"),break_all:R("break-all"),break_word:R("break-word"),clip:R("clip"),crop:R("crop"),cross:R("cross"),column:R("column"),discard:R("discard"),exclusive:R("exclusive"),_false:R("false"),fixed:R("fixed"),flex:R("flex"),flow_root:R("flow-root"),footnote:R("footnote"),footer:R("footer"),grid:R("grid"),header:R("header"),hidden:R("hidden"),horizontal_tb:R("horizontal-tb"),inherit:R("inherit"),initial:R("initial"),inline:R("inline"),inline_block:R("inline-block"),inline_end:R("inline-end"),inline_start:R("inline-start"),inside:R("inside"),keep:R("keep"),landscape:R("landscape"),left:R("left"),line:R("line"),list_item:R("list-item"),ltr:R("ltr"),manual:R("manual"),max_content:R("max-content"),min_content:R("min-content"),none:R("none"),normal:R("normal"),oeb_page_foot:R("oeb-page-foot"),oeb_page_head:R("oeb-page-head"),outside:R("outside"),padding_box:R("padding-box"),page:R("page"),relative:R("relative"),revert:R("revert"),right:R("right"),same:R("same"),scale:R("scale"),snap_block:R("snap-block"),snap_inline:R("snap-inline"),solid:R("solid"),spread:R("spread"),_static:R("static"),rtl:R("rtl"),table:R("table"),table_caption:R("table-caption"),table_cell:R("table-cell"),table_footer_group:R("table-footer-group"),table_header_group:R("table-header-group"),table_row:R("table-row"),top:R("top"),transparent:R("transparent"),unset:R("unset"),vertical_lr:R("vertical-lr"),vertical_rl:R("vertical-rl"),visible:R("visible"),_true:R("true")},$u=new A(100,"%"),bs=new A(100,"pvw"),ys=new A(100,"pvh"),me=new A(0,"px"),nv=new Jr("U+0-10FFFF"),Ng={"font-size":1,"line-height":2,color:3};function W(i){return i===S.inherit||i===S.initial||i===S.revert||i===S.unset}function Wu(i,t){let e=Ng[i]||Number.MAX_VALUE,n=Ng[t]||Number.MAX_VALUE;return e-n}function Dt(i){return(i==null?void 0:i.length)>2&&i.startsWith("--")}var to,no,so,pn=class pn{constructor(t,e,n){Z(this,to);Z(this,no);Z(this,so);Pe(this,to,Math.round(Math.max(0,Math.min(t,pn.MAX)))),Pe(this,no,Math.round(Math.max(0,Math.min(e,pn.MAX)))),Pe(this,so,Math.round(Math.max(0,Math.min(n,pn.MAX))))}static fromInt(t,e,n){return new pn(t,e,n)}offset(t,e,n){return new pn(O(this,to)+t,O(this,no)+e,O(this,so)+n)}toKey(){return JSON.stringify([O(this,to),O(this,no),O(this,so)])}toColorFunc(t){return new Bt("color",[new X([R("srgb"),new Ue(O(this,to)/pn.MAX),new Ue(O(this,no)/pn.MAX),new Ue(O(this,so)/pn.MAX),...t!==null?[qn,new Ue(t)]:[]])])}};to=new WeakMap,no=new WeakMap,so=new WeakMap,p(pn,"MAX",1e4);var fn=pn;function Tg(i){return Array.isArray(i)?i.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[e,n]=t;if(!e||typeof e!="object"||Array.isArray(e)||!n||typeof n!="object"||Array.isArray(n))return!1;let s=e,o=n;return Number.isFinite(s.r)&&Number.isFinite(s.g)&&Number.isFinite(s.b)&&Number.isFinite(o.c)&&Number.isFinite(o.m)&&Number.isFinite(o.y)&&Number.isFinite(o.k)}):!1}var Ss,xs,Es,hn,ut=class ut{constructor(t,e,n,s){Z(this,Ss);Z(this,xs);Z(this,Es);Z(this,hn);Pe(this,Ss,Math.round(Math.max(0,Math.min(t,ut.MAX)))),Pe(this,xs,Math.round(Math.max(0,Math.min(e,ut.MAX)))),Pe(this,Es,Math.round(Math.max(0,Math.min(n,ut.MAX)))),Pe(this,hn,Math.round(Math.max(0,Math.min(s,ut.MAX))))}static fromInt(t,e,n,s){return new ut(t,e,n,s)}static fromNumber(t,e,n,s){return new ut(t*ut.MAX,e*ut.MAX,n*ut.MAX,s*ut.MAX)}toSRGB(){let t=ut.MAX-O(this,hn);return fn.fromInt(fn.MAX-Math.min(fn.MAX,Math.round(O(this,Ss)*t/ut.MAX)+O(this,hn)),fn.MAX-Math.min(fn.MAX,Math.round(O(this,xs)*t/ut.MAX)+O(this,hn)),fn.MAX-Math.min(fn.MAX,Math.round(O(this,Es)*t/ut.MAX)+O(this,hn)))}equals(t){return O(this,Ss)===O(t,Ss)&&O(this,xs)===O(t,xs)&&O(this,Es)===O(t,Es)&&O(this,hn)===O(t,hn)}toJSON(){return{c:O(this,Ss),m:O(this,xs),y:O(this,Es),k:O(this,hn)}}};Ss=new WeakMap,xs=new WeakMap,Es=new WeakMap,hn=new WeakMap,p(ut,"MAX",1e4);var Za=ut;function Yo(i){return i instanceof Ue?Math.max(0,Math.min(1,i.num)):i instanceof A&&i.unit==="%"?Math.max(0,Math.min(1,i.num/100)):null}function Xu(i){if(i.name!=="device-cmyk"&&i.name!=="cmyk")return null;let t=i.values.length===1&&i.values[0]instanceof X?i.values[0].values:i.values;if(t.length<4||t.length>6)return null;let e=Yo(t[0]),n=Yo(t[1]),s=Yo(t[2]),o=Yo(t[3]);if(e===null||n===null||s===null||o===null)return null;let r=null;if(t.length>=5){if(t[4]===qn){if(t.length!==6)return null;r=Yo(t[5])}else{if(t.length!==5)return null;r=Yo(t[4])}if(r===null)return null}return{cmyk:Za.fromNumber(e,n,s,o),alpha:r}}function*yy(i){for(let t=-i;t<=i;t++)for(let e=-i;e<=i;e++)for(let n=-i;n<=i;n++)Math.abs(t)+Math.abs(e)+Math.abs(n)===i&&(yield[t,e,n])}var Kn,Qo,wg,Pg,ei=class{constructor(){Z(this,Qo);Z(this,Kn,new Map)}registerDeviceCmyk(t){let e=Xu(t);return e?fe(this,Qo,wg).call(this,e.cmyk).toColorFunc(e.alpha):null}registerCmykReserveMap(t){for(let[e,n]of t){let s=fn.fromInt(e.r,e.g,e.b),o=Za.fromInt(n.c,n.m,n.y,n.k);O(this,Kn).set(s.toKey(),o)}}toJSON(){let t={};return O(this,Kn).forEach((e,n)=>{t[n]=e.toJSON()}),t}};Kn=new WeakMap,Qo=new WeakSet,wg=function(t){let e=t.toSRGB(),n=e.toKey(),s=O(this,Kn).get(n);return s?s.equals(t)?e:fe(this,Qo,Pg).call(this,t,e):(O(this,Kn).set(n,t),e)},Pg=function(t,e){for(let n=1;n<=fn.MAX;n++)for(let[s,o,r]of yy(n)){let a=e.offset(s,o,r),l=a.toKey();if(!O(this,Kn).has(l))return O(this,Kn).set(l,t),a}return B.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(t.toJSON())}`),e};var ti,qo,Ko,Zo=class extends en{constructor(e){super();Z(this,ti);Z(this,qo,new Map);Z(this,Ko,!1);Pe(this,ti,e!=null?e:new ei)}reset(){Pe(this,Ko,!1)}hadDeviceCmyk(){return O(this,Ko)}recordConversion(e,n){O(this,qo).set(e,n)}getConversions(){if(O(this,qo).size===0)return null;let e={};return O(this,qo).forEach((n,s)=>{e[s]=n}),e}visitFunc(e){let n=O(this,ti).registerDeviceCmyk(e);return n?(Pe(this,Ko,!0),n):super.visitFunc(e)}};ti=new WeakMap,qo=new WeakMap,Ko=new WeakMap;function Rg(i){if(i.nodeType==1){let t=i.getAttribute("id");if(t)return t}return null}function Sy(i){return`^${i}`}function kg(i){return i.replace(/[\[\]\(\),=;^]/g,Sy)}function xy(i){return i.substr(1)}function ju(i){return i&&i.replace(/\^[\[\]\(\),=;^]/g,xy)}function Ey(i){let t=[];do{let e=i.match(/^(\^,|[^,])*/),n=ju(e[0]);if(i=i.substr(e[0].length+1),!i&&!t.length)return n;t.push(n)}while(i);return t}function Ag(i){let t={};for(;i;){let e=i.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!e)return t;t[e[1]]=Ey(e[2]),i=i.substr(e[0].length)}return t}var Ja=class{appendTo(t){t.append("!")}applyTo(t){return!1}},el=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,o,r=Math.floor(this.index/2)-1;if(r<0||s==0)o=e.firstChild,t.node=o||e;else{if(o=n[Math.min(r,s-1)],this.index&1){let a=o.nextSibling;!a||a.nodeType==1?t.after=!0:o=a}t.node=o}if(this.id&&(t.after||this.id!=Rg(t.node))){let a=e.ownerDocument.getElementById(this.id);a?t.node=a:B.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},tl=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 o=n.nextSibling;if(3<=s&&s<=5){let r=n.textContent.length;if(e<=r)break;if(!o){e=r;break}e-=r}if(!o){e=0;break}n=o}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(kg(this.textBefore)),t.append(","),this.textAfter&&t.append(kg(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},ni=class i{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,o=[];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=Ag(e[4]),o.push(new el(a,l,Lu(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=ju(l));let c=e[7];c&&(c=ju(c)),r=Ag(e[10]),o.push(new tl(a,l,c,Lu(r.s)));break}case"!":s++,o.push(new Ja);break;case"~":case"@":case"":this.steps=o;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 i,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 o=[],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),o.push(new tl(e,a,l,s)),s=null);r&&!(!r||r.nodeType==9);){let c=n?null:Rg(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;o.push(new el(u,c,s)),s=null,t=r,r=r.parentNode,n=!1}o.reverse(),this.steps?(o.push(new Ja),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new lt;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")}};var st=class{constructor(t,e,n,s){this.x1=t;this.y1=e;this.x2=n;this.y2=s}},gn=class{constructor(t,e){this.x=t;this.y=e}},er=class{constructor(t,e,n,s){this.left=t;this.top=e;this.right=n;this.bottom=s}},nl=class{constructor(t,e,n,s){this.low=t;this.high=e;this.winding=n;this.shapeId=s}},mn=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 Ny(i,t){return i.low.y-t.low.y||i.low.x-t.low.x}var oo=class i{constructor(t){this.points=t}addSegments(t,e){let n=this.points,s=n.length,o=n[s-1];for(let r=0;r<s;r++){let a=n[r],l;o.y<a.y?l=new nl(o,a,1,e):l=new nl(a,o,-1,e),t.push(l),o=a}}withOffset(t,e){let n=[];for(let s of this.points)n.push(new gn(s.x+t,s.y+e));return new i(n)}};function Yu(i,t,e,n){let o=[];for(let r=0;r<20;r++){let a=r*2*Math.PI/20;o.push(new gn(i+e*Math.sin(a),t+n*Math.cos(a)))}return new oo(o)}function si(i,t,e,n){return new oo([new gn(i,t),new gn(e,t),new gn(e,n),new gn(i,n)])}var Jo=class{constructor(t,e,n,s){this.x=t;this.winding=e;this.shapeId=n;this.lowOrHigh=s}};function Lg(i,t){let e=i.low.x+(i.high.x-i.low.x)*(t-i.low.y)/(i.high.y-i.low.y);if(isNaN(e))throw new Error("Bad intersection");return e}function Ty(i,t,e,n){let s,o,r,a;t.high.y<e&&B.warn("Error: inconsistent segment (1)"),t.low.y<=e?(s=Lg(t,e),o=t.winding):(s=t.low.x,o=0),t.high.y>=n?(r=Lg(t,n),a=t.winding):(r=t.high.x,a=0),s<r?(i.push(new Jo(s,o,t.shapeId,-1)),i.push(new Jo(r,a,t.shapeId,1))):(i.push(new Jo(r,a,t.shapeId,-1)),i.push(new Jo(s,o,t.shapeId,1)))}function wy(i,t,e){let n=t+e,s=Array(n),o=Array(n),r;for(r=0;r<=n;r++)s[r]=0,o[r]=0;let a=[],l=!1,c=i.length;for(let u=0;u<c;u++){let d=i[u];s[d.shapeId]+=d.winding,o[d.shapeId]+=d.lowOrHigh;let h=!1;for(r=0;r<t;r++)if(s[r]&&!o[r]){h=!0;break}if(h){for(r=t;r<=n;r++)if(s[r]||o[r]){h=!1;break}}l!=h&&(a.push(d.x),l=h)}return a}function Py(i,t){return t?Math.ceil(i/t)*t:i}function Ig(i,t){return t?Math.floor(i/t)*t:i}function ky(i){return new gn(i.y,-i.x)}function tr(i){return new st(i.y1,-i.x2,i.y2,-i.x1)}function sl(i){return new st(-i.y2,i.x1,-i.y1,i.x2)}function Fg(i){return new oo(i.points.map(t=>ky(t)))}function Vg(i,t,e,n,s,o){o&&(i=tr(i),t=t.map(C=>Fg(C)),e=e.map(C=>Fg(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(Ny);let g=0;for(;c[g].shapeId>=r;)g++;let m=c[g].low.y;m>i.y1&&l.push(new mn(i.y1,m,i.x2,i.x2));let b=0,y=[];for(;b<f&&(h=c[b]).low.y<m;)h.high.y>m&&y.push(h),b++;for(;b<f||y.length>0;){let C=i.y2,N=Math.min(Py(Math.ceil(m+n),s),i.y2);for(d=0;d<y.length&&C>N;d++)h=y[d],h.low.x==h.high.x?h.high.y<C&&(C=Math.max(Ig(h.high.y,s),N)):h.low.x!=h.high.x&&(C=N);for(C>i.y2&&(C=i.y2);b<f&&(h=c[b]).low.y<C;){if(h.high.y<m){b++;continue}if(h.low.y<N)h.low.y==h.high.y&&h.low.y==m||(y.push(h),C=N),b++;else{let v=Ig(h.low.y,s);v<C&&(C=v);break}}let x=[];for(d=0;d<y.length;d++)Ty(x,y[d],m,C);x.sort((v,T)=>v.x-T.x||v.lowOrHigh-T.lowOrHigh);let E=wy(x,r,a);if(E.length==0)l.push(new mn(m,C,i.x2,i.x2));else{let v=0,T=i.x1;for(d=0;d<E.length;d+=2){let k=Math.max(i.x1,E[d]),L=Math.min(i.x2,E[d+1])-k;L>v&&(v=L,T=k)}v==0?l.push(new mn(m,C,i.x2,i.x2)):l.push(new mn(m,C,Math.max(T,i.x1),Math.min(T+v,i.x2)))}if(C==i.y2)break;for(m=C,d=y.length-1;d>=0;d--)y[d].high.y<=C&&y.splice(d,1)}return Og(i,l),l}function Og(i,t){let e=t.length-1,n=new mn(i.y2,i.y2,i.x1,i.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 Bg(i,t){let e=0,n=i.length;for(;e<n;){let s=Math.floor((e+n)/2);t>=i[s].y2?e=s+1:n=s}return e}function Dg(i,t){if(!i.length)return t;let e=t.y1,n,s;for(s=0;s<i.length&&(n=i[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)e=Math.max(e,n.y2);let o=e;for(;s<i.length&&(n=i[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)o=n.y2;return s===i.length?o=t.y2:o=Math.min(o,t.y2),o<=e?null:new st(t.x1,e,t.x2,o)}function Mg(i,t){if(!i.length)return t;let e=t.y2,n,s;for(s=i.length-1;s>=0&&(n=i[s],!(s===i.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 o=Math.min(e,n.y2);for(;s>=0&&(n=i[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)o=n.y1;return o=Math.max(o,t.y1),e<=o?null:new st(t.x1,o,t.x2,e)}function _g(i,t,e,n){let s=e.y1,o=e.x2-e.x1,r=e.y2-e.y1,a=Bg(t,s);for(;;){let l=s+r;if(l>i.y2)return!1;let c=i.x1,u=i.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+o<=u||a>=t.length)return n=="left"?(e.x1=c,e.x2=c+o):(e.x1=u-o,e.x2=u),e.y2+=s-e.y1,e.y1=s,!0;s=t[a].y2,a++}}function Ug(i,t,e,n,s){for(n||(n=[new mn(e.y1,e.y2,e.x1,e.x2)]);n.length>0&&n[0].y2<=i.y1;)n.shift();if(n.length==0)return;n[0].y1<i.y1&&(n[0].y1=i.y1);let o,r=t.length==0?i.y1:t[t.length-1].y2;r<i.y2&&t.push(new mn(r,i.y2,i.x1,i.x2));let a=Bg(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(o=t[a],a++,t.splice(a,0,new mn(l.y1,o.y2,o.x1,o.x2)),o.y2=l.y1);a<t.length&&(o=t[a++],o.y2>l.y2&&(t.splice(a,0,new mn(l.y2,o.y2,o.x1,o.x2)),o.y2=l.y2),l.x1!=l.x2&&(s=="left"?o.x1=Math.min(l.x2,i.x2):o.x2=Math.max(l.x1,i.x1)),o.y2!=l.y2););}Og(i,t)}var qu=class extends Ot{constructor(){super();p(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Hg(i){if(i){let t=new qu;try{return i.visit(t),t.propSet}catch(e){B.warn(e,"toSet:")}}return{}}var Ku=class extends Ot{constructor(e){super();this.value=e}visitInt(e){return this.value=e.num,e}};function Ju(i,t){if(i){let e=new Ku(t);try{return i.visit(e),e.value}catch(n){B.warn(n,"toInt: ")}}return t}var Zu=class extends Ot{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 A(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,o,r){if(this.coords.length>0){let a=[];switch(this.coords.forEach((l,c)=>{if(l.unit=="%"){let u=c%2==0?s:o;c==3&&this.name=="circle"&&(u=Math.sqrt((s*s+o*o)/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 gn(e+a[c],n+a[c+1]));return new oo(l)}break;case"rectangle":if(a.length==4)return si(e+a[0],n+a[1],e+a[0]+a[2],n+a[1]+a[3]);break;case"ellipse":if(a.length==4)return Yu(e+a[0],n+a[1],a[2],a[3]);break;case"circle":if(a.length==3)return Yu(e+a[0],n+a[1],a[2],a[2]);break}}return null}};function il(i,t,e,n,s,o){if(i){let r=new Zu;try{return i.visit(r),r.getShape(t,e,n,s,o)}catch(a){B.warn(a,"toShape:")}}return si(t,e,t+n,e+s)}var Qu=class extends Ot{constructor(e,n){super();this.reset=e;this.defaultValue=n;p(this,"counters",Object.create(null));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)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function vs(i,t){var o,r;let e=(o=t==null?void 0:t.reset)!=null?o:!1,n=(r=t==null?void 0:t.defaultValue)!=null?r:e?0:1,s=new Qu(e,n);try{i.visit(s)}catch(a){B.warn(a,"toCounters:")}return s.counters}var rl=class extends en{constructor(e,n){super();this.baseUrl=e;this.transformer=n}visitURL(e){return new ke(this.transformer.transformURL(e.url,this.baseUrl))}};function ro(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function Ay(i){return i.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,e,n)=>e?String.fromCodePoint(parseInt(e,16)):n)}function sr(i,t){var e,n;if(t==="content"){let s=i.cloneNode(!0);return s.querySelectorAll("[data-adapt-pseudo]").forEach(r=>r.remove()),s.textContent||""}else if(t==="marker"){let s=i.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(s)return s.textContent||"";let o=(n=(e=i.ownerDocument.defaultView)==null?void 0:e.getComputedStyle(i))==null?void 0:n.getPropertyValue("--viv-marker-content");if(o){let r=o.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(r&&r.length>0)return r.map(a=>Ay(a.substring(1,a.length-1))).join("")}return""}else{let s=i.querySelector(`[data-adapt-pseudo="${t}"]`);return s&&s.textContent||""}}var nd=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}},sd=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()}},od=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",Object.create(null));p(this,"runningElements",Object.create(null))}setStyler(t){this.styler=t}getFragment(t){let e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null}getTransformedId(t){let e=this.counterStore.documentURLTransformer.transformURL(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}`),o=r=>e(r[r.length-1]);return this.counterStore.registerPageCounterExpr(t,o,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}getTargetPageDocCounters(t){return this.counterStore.currentPage.elementsById[t]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[t]||null}adjustCountersForCrossScope(t,e,n,s){if(!this.counterStore.isPageControlledCounter(t)||!n)return e;let o=n[t]||[],r=o.length?o[o.length-1]:0,a=(s==null?void 0:s[t])||[],l=a.length?a[0]:0;return e.length?[r+(e[0]-l),...e.slice(1)]:[r]}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"?sr(s,e):sr(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),o=this.getTransformedId(t),r=new ne(this.pageScope,()=>{let a=this.getTargetCounters(s,o,!0);if(a)if(a[e]){let l=a[e],c=this.getTargetPageCounters(o),u=this.getTargetPageDocCounters(o),d=this.adjustCountersForCrossScope(e,l,c,u);return c&&this.counterStore.resolveReference(o),n(d[d.length-1]||null)}else{let l=this.getTargetPageCounters(o);if(l)if(this.counterStore.resolveReference(o),l[e]){let c=l[e];return n(c[c.length-1]||null)}else return n(0);else return this.counterStore.saveReferenceOfCurrentPage(o,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(o,!1),"??"},`target-counter-${e}-of-${t}`);return this.counterStore.registerTargetCounterExpr(e,n,r,o),r}getTargetCountersVal(t,e,n){let s=this.getFragment(t),o=this.getTransformedId(t);return new ne(this.pageScope,()=>{let r=this.getTargetPageCounters(o);if(r){this.counterStore.resolveReference(o);let a=this.getTargetCounters(s,o,!0),l=(a==null?void 0:a[e])||[],c=this.getTargetPageDocCounters(o),u=this.adjustCountersForCrossScope(e,l,r,c);if(u.length)return n(u);let d=r[e]||[];return n(d)}else return this.counterStore.saveReferenceOfCurrentPage(o,!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(qs);return u?u[0]:""}let o=this.getTargetPageText(n,e);return o!==null?(this.counterStore.resolveReference(n),o):(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 o=Object.keys(s).map(g=>parseInt(g,10)).sort(La),r=this.counterStore.currentPage;if(!r)return"";let a=r.isBlankPage?r.offset-1:r.offset,l=r.isBlankPage?a:Math.max(a,...Array.from(r.container.querySelectorAll(`[${zt}]`)).map(g=>parseInt(g.getAttribute(zt),10))),c=-1,u=-1,d=-1,h=-1;for(let g=0;g<o.length;g++){let m=o[g],b=g>0?o[g-1]:-1,y=g<o.length-1?o[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{b<c&&(u=b);let C=r.container.querySelector(`[${zt}="${m}"]`);if(!C)u<0&&(u=m);else{let N=r.container.querySelector(`[${zt}="${a}"]`);if(N||(N=r.container.querySelector(`[${zt}="0"]`)),N){for(let x=N;x;x=x.firstElementChild)if(x===C){u=m;break}}}}d=m}else(y>l||y<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]=Object.create(null));s[n]=e}setRunningElement(t,e){let n=this.runningElements[t]||(this.runningElements[t]=Object.create(null));n[e]=String(e)}},al=class{constructor(t){this.documentURLTransformer=t;p(this,"countersById",Object.create(null));p(this,"pageCountersById",Object.create(null));p(this,"pageDocCountersById",Object.create(null));p(this,"pageTextById",Object.create(null));p(this,"currentPageDocCounters",null);p(this,"previousPageDocCounters",null);p(this,"currentPageDocCounterChanges",Object.create(null));p(this,"currentPageDocCounterChangeTypes",Object.create(null));p(this,"currentPageCounters",Object.create(null));p(this,"previousPageCounters",Object.create(null));p(this,"currentPageCountersStack",[]);p(this,"pageIndicesById",Object.create(null));p(this,"currentPage",null);p(this,"newReferencesOfCurrentPage",[]);p(this,"referencesToSolve",[]);p(this,"referencesToSolveStack",[]);p(this,"unresolvedReferences",Object.create(null));p(this,"resolvedReferences",Object.create(null));p(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0}));p(this,"pagesCounterExprs",[]);p(this,"pageCounterExprs",[]);p(this,"targetCounterExprs",[]);p(this,"targetTextExprs",[]);this.currentPageCounters.page=[0]}createCounterListener(t){return new sd(this,t)}createCounterResolver(t,e,n){return new od(this,t,e,n)}setCurrentPage(t){this.currentPage=t}setCurrentPageDocCounters(t,e,n){this.previousPageDocCounters=this.currentPageDocCounters?ro(this.currentPageDocCounters):null,this.currentPageDocCounters=t?ro(t):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=n?{...n}:Object.create(null),e&&e.forEach(s=>{this.currentPageDocCounterChanges[s]=!0})}setPageControlledCounterNames(t){let e=Object.assign(Object.create(null),{page:!0});t.forEach(n=>{e[n]=!0}),this.pageControlledCounterNames=e}isPageControlledCounter(t){return!!this.pageControlledCounterNames[t]}definePageCounter(t,e){this.currentPageCounters[t]?this.currentPageCounters[t].push(e):this.currentPageCounters[t]=[e]}forceSetPageCounter(t){let e=this.currentPageCounters.page;!e||!e.length?this.currentPageCounters.page=[t]:e[e.length-1]=t}updatePageCounters(t,e){this.previousPageCounters=ro(this.currentPageCounters);let n=this.currentPageDocCounterChanges||{},s=this.currentPageDocCounterChangeTypes||{},o=Object.create(null);if(this.currentPageDocCounters){let m=this.previousPageDocCounters||{};for(let b in this.currentPageDocCounters){if(!n[b])continue;let y=this.currentPageDocCounters[b],C=y.length?y[y.length-1]:0,N=m[b]||[],x=N.length?N[N.length-1]:0,E=C-x,v=s[b],T=v==="reset"||v==="set";o[b]={delta:E,reset:T,value:C}}}let r=Object.create(null),a,l=t["counter-reset"];if(l){let m=l.evaluate(e);m&&(a=vs(m,{reset:!0}))}a&&"pages"in a&&delete a.pages;let c,u=t["counter-set"];if(u){let m=u.evaluate(e);m&&(c=vs(m,{defaultValue:0}))}c&&"pages"in c&&delete c.pages;let d=[];if(a)for(let m in a)d.push(m);if(c)for(let m in c)d.push(m);let h,f=t["counter-increment"];if(f){let m=f.evaluate(e);m&&(h=vs(m))}h&&"pages"in h&&delete h.pages,h?!("page"in h)&&!(o.page&&o.page.reset)&&(h.page=1):(h=Object.create(null),o.page&&o.page.reset||(h.page=1));for(let m in h)d.push(m);this.setPageControlledCounterNames(d);let g=ro(this.previousPageCounters);if(this.currentPageDocCounters)for(let m in this.currentPageDocCounters){if(this.isPageControlledCounter(m)){let b=o[m];if(b){if(b.reset)g[m]=[b.value],r[m]=!0;else if(b.delta!==0){g[m]||(g[m]=[0]);let y=g[m];y[y.length-1]+=b.delta}}continue}g[m]=Array.from(this.currentPageDocCounters[m])}if(this.currentPageCounters=g,a)for(let m in a)this.definePageCounter(m,a[m]);if(c)for(let m in c)if(!this.currentPageCounters[m])this.definePageCounter(m,c[m]);else{let b=this.currentPageCounters[m];b[b.length-1]=c[m]}for(let m in h){if(r[m])continue;this.currentPageCounters[m]||this.definePageCounter(m,0);let b=this.currentPageCounters[m];b[b.length-1]+=h[m]}}pushPageCounters(t){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=ro(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 o=0;o<this.referencesToSolve.length;){let r=this.referencesToSolve[o];if(r.targetId===t){if(r.resolve(),this.referencesToSolve.splice(o,1),e){let a=e.indexOf(r);a>=0&&e.splice(a,1)}n.push(r),s=!0}else o++}s||this.saveReferenceOfCurrentPage(t,!0)}saveReferenceOfCurrentPage(t,e){if(!this.newReferencesOfCurrentPage.some(n=>n.targetId===t)){let n=new nd(t,e);this.newReferencesOfCurrentPage.push(n)}}finishPage(t,e){let n=Object.keys(this.currentPage.elementsById);if(n.length>0){let r=ro(this.currentPageCounters),a=this.currentPageDocCounters?ro(this.currentPageDocCounters):null;n.forEach(l=>{this.pageCountersById[l]=r,a&&(this.pageDocCountersById[l]=a);let c=this.currentPage.elementsById[l];if(c&&c.length>0){let d=c[0];this.pageTextById[l]={content:sr(d,"content"),before:sr(d,"before"),after:sr(d,"after"),marker:sr(d,"marker")}}let u=this.pageIndicesById[l];if(u&&u.pageIndex<e){let d=this.resolvedReferences[l];if(d){let h=this.unresolvedReferences[l];h||(h=this.unresolvedReferences[l]=[]);let f;for(;f=d.shift();)f.unresolve(),h.push(f)}}this.pageIndicesById[l]={spineIndex:t,pageIndex:e}})}let s=this.previousPageCounters,o;for(;o=this.newReferencesOfCurrentPage.shift();){o.pageCounters=s,o.spineIndex=t,o.pageIndex=e;let r;o.isResolved()?(r=this.resolvedReferences[o.targetId],r||(r=this.resolvedReferences[o.targetId]=[])):(r=this.unresolvedReferences[o.targetId],r||(r=this.unresolvedReferences[o.targetId]=[])),r.every(a=>!o.equals(a))&&r.push(o)}this.currentPage=null}adjustPageCountersOfLaterSpines(t,e){if(e<=0)return;let n=new Set;for(let s of Object.keys(this.pageIndicesById))if(this.pageIndicesById[s].spineIndex>t){let r=this.pageCountersById[s];r&&r.page&&!n.has(r)&&(n.add(r),r.page=r.page.map(a=>a+e))}}updateTargetCounterNodesInPages(t){for(let e of t){if(!e||!e.container)continue;let n=e.container.querySelectorAll(`[${ri}]`);for(let s of n){let o=s.getAttribute(ri),r=this.targetCounterExprs.find(a=>a.expr.key===o);if(r&&r.transformedId){let a=this.pageCountersById[r.transformedId];if(a){let l=a[r.name];l&&(s.textContent=r.format(l[l.length-1]))}}}}}getPageCountersForPage(t,e){let n=Object.keys(t.elementsById);for(let s of n){let o=this.pageCountersById[s];if(o)return o}return e||null}updatePageCounterNodesInPages(t,e){var n;for(let s=0;s<t.length;s++){let o=t[s];if(!(o!=null&&o.container))continue;let r=this.getPageCountersForPage(o,e==null?void 0:e[s]);if(!r)continue;let a=o.container.querySelectorAll(`[${oi}]`);for(let l of a){let c=l.getAttribute(oi),u=this.pageCounterExprs.find(g=>g.expr.key===c);if(!u)continue;let d=(n=u.expr)==null?void 0:n.str,h=d==null?void 0:d.replace(/^page-counters?-/,""),f=r[h];f&&(l.textContent=u.format(f))}}}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=[],o=null;return e.forEach(r=>{!o||o.spineIndex!==r.spineIndex||o.pageIndex!==r.pageIndex?(o={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},s.push(o)):o.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(`[${zt}="${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(ri,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(td,t.key),r}}let s=this.pagesCounterExprs.findIndex(r=>r.expr===t)>=0,o=!s&&this.pageCounterExprs.findIndex(r=>r.expr===t)>=0;if(s||o){let r=n.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=e,r.setAttribute(s?ed:oi,t.key),r}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${oi}]`);for(let o of e){let r=o.getAttribute(oi),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&&(o.textContent=a.format(u))}let n=t.querySelectorAll(`[${ri}]`);for(let o of n)o.setAttribute(zg,!0);let s=t.querySelectorAll(`[${td}]`);for(let o of s)o.setAttribute(Gg,!0)}finishLastPage(t){var r;let e=t.root.querySelectorAll(`[${ed}]`),n=t.contentContainer.childElementCount;for(let a of e){let l=a.getAttribute(ed),c=this.pagesCounterExprs.findIndex(u=>u.expr.key===l);c>=0,a.textContent=this.pagesCounterExprs[c].format([n])}let s=t.root.querySelectorAll(`[${zg}]`);for(let a of s){let l=a.getAttribute(ri),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 o=t.root.querySelectorAll(`[${Gg}]`);for(let a of o){let l=a.getAttribute(td),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 rd(this,t)}},ed="data-vivliostyle-pages-counter",oi="data-vivliostyle-page-counter",ri="data-vivliostyle-target-counter",td="data-vivliostyle-target-text",zg="data-vivliostyle-target-counter-in-running",Gg="data-vivliostyle-target-text-in-running",rd=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}};var Ly=new Set(["before","after","first-line","first-letter"]),Iy=new Set(["media","supports","-epubx-when"]),$g=new Set([";","}"]),Wg=new Set(["{",";","}"]),Fy=new Set([";","{","}"]),Vy=":where(:scope)",Oy=":where(:not(*))";function Xg(i){let{statements:t,changed:e}=id(i,0,i.length,null);return e?t.join(`
5
+ `):i}function id(i,t,e,n){let s=[],o=[],r=!1,a=t,l=()=>{o.length!==0&&(n?s.push(By(n,o)):s.push(jg(o)),o.length=0)};for(;a<e&&(a=Zg(i,a,e),!(a>=e||i[a]==="}"));){if(i[a]==="@"){l();let d=Xy(i,a,e);if(!d)break;if(d.hasBlock&&Iy.has(d.name)){let h=id(i,d.blockStart,d.blockEnd,n);r||(r=h.changed||n!=null),s.push(`${d.header} {${Dy(h.statements)}}`)}else s.push(ii(i.slice(a,d.end)));a=d.end;continue}if(n&&zy(i,a,e)){let d=$y(i,a,e);if(!d)break;o.push(ii(d.text)),a=d.end;continue}l();let c=Wy(i,a,e);if(!c){let d=jy(i,a,e);s.push(ii(d.text)),a=d.end;continue}let u=n?My(n,c.prelude):ad(c.prelude);if(u){r||(r=n!=null);let d=id(i,c.blockStart,c.blockEnd,u);r||(r=d.changed),d.statements.length===0?s.push(`${u} {}`):s.push(...d.statements)}a=c.end}return l(),{statements:s,changed:r}}function By(i,t){return`${i} { ${jg(t)} }`}function jg(i){return i.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function Dy(i){return i.length===0?"":` ${i.join(" ")} `}function My(i,t){let e=_y(i);if(!e)return null;let s=qg(t,",").map(o=>o.trim()).filter(Boolean).map(o=>{let r=Yg(o,e);return r.found?r.text:`${e} ${o}`}).filter(Boolean);return s.length===0?null:s.join(", ")}function ad(i){return Yg(i.trim(),Vy).text}function _y(i){let t=qg(i,",").map(e=>e.trim()).filter(Boolean).filter(e=>!Uy(e));return t.length===0?null:`:is(${t.join(", ")})`}function Uy(i){let t=0;for(;t<i.length;){let e=ll(i,t);if(e!=null){t=e;continue}let n=io(i,t,i.length);if(n!=null){t=n;continue}if(i[t]===":"){if(i[t+1]===":")return!0;let o=t+1,r=ai(i,o,i.length),a=i.slice(o,r).toLowerCase();if(Ly.has(a))return!0;t=r;continue}t++}return!1}function Yg(i,t){let e=0,n=!1,s="",o=[],r=Hy(t);for(;e<i.length;){let a=ll(i,e);if(a!=null){s+=i.slice(e,a),e=a;continue}let l=io(i,e,i.length);if(l!=null){s+=i.slice(e,l),e=l;continue}let c=i[e];if(c===":"&&i[e+1]!==":"){let u=e+1,d=ai(i,u,i.length);if(d>u&&i[d]==="("){o.push(i.slice(u,d).toLowerCase()),s+=i.slice(e,d+1),e=d+1;continue}}if(c==="("){o.push(""),s+=c,e++;continue}if(c===")"){o.pop(),s+=c,e++;continue}if(c==="&"){s+=r&&o.includes("has")?Oy:t,n=!0,e++;continue}s+=c,e++}return{text:s,found:n}}function Hy(i){let t=0;for(;t<i.length;){let e=ll(i,t);if(e!=null){t=e;continue}let n=io(i,t,i.length);if(n!=null){t=n;continue}if(i[t]===":"&&i[t+1]!==":"){let o=t+1,r=ai(i,o,i.length);if(r>o&&i.slice(o,r).toLowerCase()==="has"&&i[r]==="(")return!0;t=r;continue}t++}return!1}function qg(i,t){let e=[],n=0,s=0,o=0,r=0;for(;s<i.length;){let a=ll(i,s);if(a!=null){s=a;continue}let l=io(i,s,i.length);if(l!=null){s=l;continue}let c=i[s];switch(c){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":r++;break;case"]":r=Math.max(0,r-1);break;default:o===0&&r===0&&c===t&&(e.push(i.slice(n,s)),n=s+1);break}s++}return e.push(i.slice(n)),e}function zy(i,t,e){let n=t,s=Gy(i,n,e);if(s<=n)return!1;let o=Zg(i,s,e);if(o>=e||i[o]!==":")return!1;if(i[t]==="-"&&i[t+1]==="-")return!0;let r=li(i,o+1,e,Fy);return!r||r.char!=="{"}function Gy(i,t,e){let n=t;return i[n]==="-"&&(n++,n<e&&i[n]==="-"&&n++),ai(i,n,e)}function ai(i,t,e){let n=t;for(;n<e;){let s=i[n];if(s==="\\"){n+=2;continue}if(!/[0-9A-Za-z_-]/.test(s))break;n++}return n}function $y(i,t,e){let n=li(i,t,e,$g);if(!n){let o=i.slice(t,e).trim();return o?{text:o,end:e}:null}let s=n.char===";"?n.index+1:n.index;return{text:i.slice(t,s).trim(),end:s}}function Wy(i,t,e){let n=li(i,t,e,Wg);if(!n||n.char!=="{")return null;let s=Kg(i,n.index,e);return s<0?null:{prelude:ii(i.slice(t,n.index)),blockStart:n.index+1,blockEnd:s,end:s+1}}function Xy(i,t,e){let n=li(i,t,e,Wg);if(!n)return null;let s=ai(i,t+1,e),o=i.slice(t+1,s).toLowerCase(),r=ii(i.slice(t,n.index));if(n.char!=="{")return{name:o,header:r,hasBlock:!1,blockStart:-1,blockEnd:-1,end:n.index+(n.char===";"?1:0)};let a=Kg(i,n.index,e);return a<0?null:{name:o,header:r,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function jy(i,t,e){let n=li(i,t,e,$g);if(!n)return{text:i.slice(t,e),end:e};let s=n.char===";"?n.index+1:n.index;return{text:i.slice(t,s),end:s}}function li(i,t,e,n){let s=t,o=0,r=0,a=0;for(;s<e;){let l=io(i,s,e);if(l!=null){s=l;continue}let c=i[s];switch(c){case"(":o++;break;case")":o=Math.max(0,o-1);break;case"[":r++;break;case"]":r=Math.max(0,r-1);break;case"{":if(o===0&&r===0&&a===0&&n.has(c))return{index:s,char:c};a++;break;case"}":if(o===0&&r===0&&a===0&&n.has(c))return{index:s,char:c};a=Math.max(0,a-1);break;default:if(o===0&&r===0&&a===0&&n.has(c))return{index:s,char:c};break}s++}return null}function Kg(i,t,e){let n=t+1,s=1;for(;n<e;){let o=io(i,n,e);if(o!=null){n=o;continue}let r=i[n];if(r==="{")s++;else if(r==="}"&&(s--,s===0))return n;n++}return-1}function Zg(i,t,e){let n=t;for(;n<e;){let s=i[n];if(Jg(s)){n++;continue}if(s==="/"&&i[n+1]==="*"){n=Qg(i,n,e);continue}break}return n}function Qg(i,t,e){let n=i.indexOf("*/",t+2);return n<0||n+2>e?e:n+2}function io(i,t,e){let n=i[t];return n==='"'||n==="'"?Yy(i,t):n==="/"&&i[t+1]==="*"?Qg(i,t,e):null}function ll(i,t){return i[t]!=="\\"?null:t+1>=i.length?i.length:t+2}function Yy(i,t){let e=i[t],n=t+1;for(;n<i.length;){let s=i[n];if(s==="\\"){n+=2;continue}if(s===e)return n+1;n++}return i.length}function Jg(i){return i===" "||i===`
6
+ `||i==="\r"||i===" "||i==="\f"}function ii(i){let t="",e=0,n=!1;for(;e<i.length;){let s=io(i,e,i.length);if(s!=null&&i[e]!=="/"){n&&t.length>0&&(t+=" ",n=!1),t+=i.slice(e,s),e=s;continue}if(s!=null){n=t.length>0,e=s;continue}let o=i[e];if(Jg(o)){n=t.length>0,e++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,e++}return t}function qy(i){if(i=i.substr(1),i.match(/^[^0-9a-fA-F\n\r]$/))return i;let t=parseInt(i,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function ao(i){return i.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,qy)}var cd=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 $e(i,t){let e=Array(128),n;for(n=0;n<128;n++)e[n]=i;for(e[NaN]=i==35?35:72,n=0;n<t.length;n+=2)e[t[n]]=t[n+1];return e}var Zn=[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];Zn[NaN]=80;var Rn=[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];Rn[NaN]=43;var Ky=[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];Rn[NaN]=43;var tm=[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];tm[NaN]=35;var nm=[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];nm[NaN]=45;var ud=[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];ud[NaN]=37;var dd=[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];dd[NaN]=38;var lo=$e(35,[61,36]),Zy=$e(35,[58,77]),Qy=$e(35,[61,36,124,50]),Jy=$e(35,[38,51]),eS=$e(35,[42,54]),tS=$e(39,[42,55]),nS=$e(54,[42,55,47,56]),sS=$e(62,[62,82]),oS=$e(35,[61,36,33,70]),rS=$e(62,[45,71]),iS=$e(63,[45,81]),ld=$e(76,[10,72,13,72]),aS=$e(39,[39,46,10,72,13,72,92,48]),lS=$e(39,[34,46,10,72,13,72,92,49]),cS=$e(39,[39,47,10,74,13,74,92,48]),uS=$e(39,[34,47,10,74,13,74,92,49]),em=$e(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),dS=$e(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]),pS=$e(39,[39,68,10,74,13,74,92,75,NaN,67]),hS=$e(39,[34,68,10,74,13,74,92,75,NaN,67]),fS=$e(72,[9,39,10,39,13,39,32,39,41,69]),gS=15,ot=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=gS,this.buffer=Array(this.indexMask+1);for(let n=0;n<=this.indexMask;n++)this.buffer[n]=new cd}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=Zn,o=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=o.charCodeAt(r);switch(s[m]||s[65]){case 72:u=o.substring(c,r),isNaN(m)?l=0:l=54,s=Zn;break;case 1:r++,h=!0;continue;case 2:c=r++,s=ud;continue;case 3:l=1,c=r++,s=Rn;continue;case 4:c=r++,l=31,s=lo;continue;case 33:l=2,c=++r,s=aS;continue;case 34:l=2,c=++r,s=lS;continue;case 6:c=++r,l=7,s=Rn;continue;case 7:c=r++,l=32,s=lo;continue;case 8:c=r++,l=21;break;case 9:c=r++,l=32,s=Jy;continue;case 10:c=r++,l=10;break;case 11:c=r++,l=11;break;case 12:c=r++,l=36,s=lo;continue;case 13:c=r++,l=23;break;case 14:c=r++,l=16;break;case 15:l=24,c=r++,s=tm;continue;case 16:c=r++,s=Ky;continue;case 78:c=r++,l=9,s=Rn;continue;case 17:c=r++,l=19,s=eS;continue;case 18:c=r++,l=18,s=Zy;continue;case 77:r++,l=50;break;case 19:c=r++,l=17;break;case 20:c=r++,l=38,s=oS;continue;case 21:c=r++,l=39,s=lo;continue;case 22:c=r++,l=37,s=lo;continue;case 23:c=r++,l=22;break;case 24:c=++r,l=20,s=Rn;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=ld;continue;case 30:c=r++,l=33,s=lo;continue;case 31:c=r++,l=34,s=Qy;continue;case 32:c=r++,l=35,s=lo;continue;case 35:break;case 36:r++,l=l+41-31;break;case 37:l=5,d=parseInt(o.substring(c,r),10);break;case 38:l=4,d=parseFloat(o.substring(c,r));break;case 39:r++;continue;case 40:l=3,d=parseFloat(o.substring(c,r)),c=r++,s=Rn;continue;case 41:l=3,d=parseFloat(o.substring(c,r)),u="%",c=r++;break;case 42:r++,s=dd;continue;case 43:if(u=ao(o.substring(c,r)),l===27&&m===63||l===1&&u.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(o.substring(r-1))){l=27,r++;continue}break;case 44:g=r++,s=ld;continue;case 45:u=ao(o.substring(c,r));break;case 46:u=o.substring(c,r),r++;break;case 47:u=ao(o.substring(c,r)),r++;break;case 48:g=r,r+=2,s=cS;continue;case 49:g=r,r+=2,s=uS;continue;case 50:r++,l=25;break;case 51:r++,l=26;break;case 52:if(u=o.substring(c,r),l==1){if(r++,u.toLowerCase()=="url"){s=em;continue}l=6}break;case 53:if(u=ao(o.substring(c,r)),l==1){if(r++,u.toLowerCase()=="url"){s=em;continue}l=6}break;case 54:s=tS,r++;continue;case 55:s=nS,r++;continue;case 56:s=Zn,r++;continue;case 57:s=sS,r++,o[r]!==">"&&(l=1,s=Rn);continue;case 81:l=51,u=o.substring(c,++r),s=Zn;break;case 82:l=52,u=o.substring(c,++r),s=Zn;break;case 58:l=5,s=ud,r++;continue;case 59:l=4,s=dd,r++;continue;case 60:l=1,s=Rn,r++;continue;case 61:l=1,s=ld,g=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:c=r++,s=dS;continue;case 65:c=++r,s=pS;continue;case 66:c=++r,s=hS;continue;case 67:l=8,u=ao(o.substring(c,r)),r++;break;case 69:r++;break;case 70:s=rS,r++;continue;case 71:s=iS,r++;continue;case 79:if(r-g<8&&o.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:l=8,u=ao(o.substring(c,r)),r++,s=fS;continue;case 74:if(r++,r-g<9&&o.substring(g+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;l=54,u="E_CSS_UNEXPECTED_NEWLINE",s=Zn;break;case 73:if(r-g<9&&o.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,s=Rn;continue}u=ao(o.substring(c,r));break;case 75:g=r++;continue;case 76:r++,s=nm;continue;default:if(s!==Zn){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=Zn,h=!1,f=a[t&n]}this.position=r,this.tail=t&n}};var He=null,pd=null;function di(){return He}function I(i){if(!He)throw new Error("E_TASK_NO_CONTEXT");He.name||(He.name=i);let t=He,e=new or(t,t.top,i);return t.top=e,e.state=1,e}function mS(i){return new fd(i||new hd)}function w(i){return new ui(i)}function Qn(i,t,e){let n=I(i);n.handler=e;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function sm(i,t){return(He?He.getScheduler():pd||mS()).run(i,t)}var hd=class{currentTime(){return new Date().valueOf()}setTimeout(t,e){return setTimeout(t,e)}clearTimeout(t){clearTimeout(t)}},fd=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,pd||(pd=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){B.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let n=new gd(this,e||"");n.top=new or(n,null,"bootstrap"),n.top.state=1,n.top.then(()=>{let o=()=>{n.running=!1;for(let r of n.callbacks)try{r()}catch(a){B.error(a)}};try{t().then(r=>{n.result=r,o()})}catch(r){n.raise(r),o()}});let s=He;return He=n,this.schedule(n.top.suspend("bootstrap")),He=s,n}},cl=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=He;return He=t,t.top.finish(this.result),He=e,!0}return!1}cancel(){this.canceled=!0}},gd=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!==He&&this.continuation){this.continuation.cancel();let e=new cl(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=I("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&&B.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
7
  ---- async ---
6
8
  `:"";for(let n=this.top;n;n=n.parent)e+=" ",e+=n.getName(),e+=`
7
- `;t.frameTrace=e}}},si=class i{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new i(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},rd=class{constructor(t){this.frame=t}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new Jo(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 si(t)):new si(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}},Jo=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(!He)throw new Error("F_TASK_NO_CONTEXT");if(this!==He.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new rd(this)}finish(t){this.checkEnvironment(),He&&!He.exception&&(this.res=t),this.state=2;let e=this.parent;if(He&&(He.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=L("Frame.timeSlice");return t.getScheduler().isTimeSliceOver()?(O.debug("-- time slice --"),t.suspend().schedule(!0)):t.finish(!0),t.result()}sleep(t){let e=L("Frame.sleep");return e.suspend().schedule(!0,t),e.result()}loop(t){let e=L("Frame.loop"),n=s=>{try{for(;s;){let o=t();if(o.isPending()){o.then(n);return}else o.then(r=>{s=r})}e.finish(!0)}catch(o){e.task.raise(o,e)}};return n(!0),e.result()}loopWithFrame(t){let e=He;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let n;do{let s=new id(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 tl(this.task);return this.task.continuation=e,He=null,this.task.waitTarget=t||null,e}},id=class extends Jo{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}};var An=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=oi().getScheduler().run(()=>{let t=L("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(o){O.error(o,"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}},hn=i=>{if(i.length==0)return T(!0);if(i.length==1)return i[0].get().thenReturn(!0);let t=L("waitForFetches"),e=0;return t.loop(()=>{for(;e<i.length;){let n=i[e++];if(!n.hasArrived())return n.get().thenReturn(!0)}return T(!1)}).then(()=>{t.finish(!0)}),t.result()};var ad=`
9
+ `;t.frameTrace=e}}},ui=class i{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new i(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},md=class{constructor(t){this.frame=t}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new or(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 ui(t)):new ui(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}},or=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(!He)throw new Error("F_TASK_NO_CONTEXT");if(this!==He.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new md(this)}finish(t){this.checkEnvironment(),He&&!He.exception&&(this.res=t),this.state=2;let e=this.parent;if(He&&(He.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=I("Frame.timeSlice");return t.getScheduler().isTimeSliceOver()?(B.debug("-- time slice --"),t.suspend().schedule(!0)):t.finish(!0),t.result()}sleep(t){let e=I("Frame.sleep");return e.suspend().schedule(!0,t),e.result()}loop(t){let e=I("Frame.loop"),n=s=>{try{for(;s;){let o=t();if(o.isPending()){o.then(n);return}else o.then(r=>{s=r})}e.finish(!0)}catch(o){e.task.raise(o,e)}};return n(!0),e.result()}loopWithFrame(t){let e=He;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let n;do{let s=new Cd(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 cl(this.task);return this.task.continuation=e,He=null,this.task.waitTarget=t||null,e}},Cd=class extends or{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}};var Ln=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=di().getScheduler().run(()=>{let t=I("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(o){B.error(o,"Error:")}t.finish(e)}),t.result()},this.name))}piggyback(t){this.arrived?t(this.resource):this.piggybacks.push(t)}get(){return this.arrived?w(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},Cn=i=>{if(i.length==0)return w(!0);if(i.length==1)return i[0].get().thenReturn(!0);let t=I("waitForFetches"),e=0;return t.loop(()=>{for(;e<i.length;){let n=i[e++];if(!n.hasArrived())return n.get().thenReturn(!0)}return w(!1)}).then(()=>{t.finish(!0)}),t.result()};var bd=`
8
10
  @media screen {
9
11
  [data-vivliostyle-viewer-viewport] {
10
12
  background: #aaaaaa;
@@ -73,7 +75,7 @@
73
75
  transform-origin: center top;
74
76
  }
75
77
  }
76
- `,ld=`
78
+ `,yd=`
77
79
  [data-vivliostyle-layout-box] {
78
80
  position: absolute;
79
81
  left: 0;
@@ -196,7 +198,7 @@
196
198
  break-after: page;
197
199
  }
198
200
  }
199
- `,cd=`
201
+ `,Sd=`
200
202
  /*
201
203
  * Copyright 2013 Google, Inc.
202
204
  * Copyright 2015 Daishinsha Inc.
@@ -829,7 +831,7 @@ word-wrap = overflow-wrap;
829
831
  [adapt,webkit]start = inline-start;
830
832
  [adapt,webkit]end = inline-end;
831
833
 
832
- `,ud=`
834
+ `,xd=`
833
835
  <!DOCTYPE html>
834
836
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
835
837
  <head>
@@ -837,6 +839,7 @@ word-wrap = overflow-wrap;
837
839
 
838
840
  .-vivliostyle-footnote-content {
839
841
  float: footnote;
842
+ --viv-semantic-footnote-content: 1;
840
843
  }
841
844
 
842
845
  .-vivliostyle-table-cell-container {
@@ -852,7 +855,7 @@ word-wrap = overflow-wrap;
852
855
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
853
856
 
854
857
  </body>
855
- </html>`,dd=`
858
+ </html>`,Ed=`
856
859
  @namespace "http://www.w3.org/1999/xhtml";
857
860
 
858
861
  :root {
@@ -975,7 +978,7 @@ word-wrap = overflow-wrap;
975
978
  margin: 10%;
976
979
  }
977
980
  }
978
- `,pd=String.raw`
981
+ `,vd=String.raw`
979
982
  @namespace "http://www.w3.org/1999/xhtml";
980
983
  @namespace m "http://www.w3.org/1998/Math/MathML";
981
984
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1323,10 +1326,13 @@ m|math[display="block"] {
1323
1326
 
1324
1327
  /* CSS GCPM footnotes */
1325
1328
  ::footnote-marker {
1326
- content: counter(footnote) ". ";
1327
1329
  list-style-position: inside;
1328
1330
  }
1329
- ::footnote-call {
1331
+ /* Semantic DPUB/EPUB footnotes provide their own default call/marker path. */
1332
+ :not(aside[epub|type~="footnote"], aside[epub\:type~="footnote"], aside[role~="doc-footnote"])::footnote-marker {
1333
+ content: counter(footnote) ". ";
1334
+ }
1335
+ :not(a[epub|type~="noteref"], a[epub\:type~="noteref"], a[role~="doc-noteref"])::footnote-call {
1330
1336
  content: counter(footnote);
1331
1337
  font-size: 0.75em;
1332
1338
  vertical-align: super;
@@ -1335,23 +1341,18 @@ m|math[display="block"] {
1335
1341
 
1336
1342
  /* EPUB/DPUB footnotes */
1337
1343
 
1338
- a[epub|type="noteref"],
1339
- a[epub\:type="noteref"],
1340
- a[role="doc-noteref"] {
1344
+ a[epub|type="noteref"]:not(sup > *, :has(> sup)),
1345
+ a[epub\:type="noteref"]:not(sup > *, :has(> sup)),
1346
+ a[role="doc-noteref"]:not(sup > *, :has(> sup)) {
1341
1347
  font-size: 0.75em;
1342
1348
  vertical-align: super;
1343
1349
  line-height: 0;
1344
1350
  }
1345
1351
 
1346
- sup > a[epub|type="noteref"],
1347
- a[epub|type="noteref"] > sup,
1348
- sup > a[epub\:type="noteref"],
1349
- a[epub\:type="noteref"] > sup,
1350
- sup > a[role="doc-noteref"],
1351
- a[role="doc-noteref"] > sup {
1352
- font-size: unset;
1353
- vertical-align: unset;
1354
- line-height: unset;
1352
+ a[epub|type="noteref"][data-vivliostyle-footnote-first-ref],
1353
+ a[epub\:type="noteref"][data-vivliostyle-footnote-first-ref],
1354
+ a[role="doc-noteref"][data-vivliostyle-footnote-first-ref] {
1355
+ counter-increment: footnote;
1355
1356
  }
1356
1357
 
1357
1358
  a[epub|type="noteref"]:href-epub-type(footnote, aside),
@@ -1408,7 +1409,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1408
1409
  epub|case[required-namespace::supported] ~ epub|default {
1409
1410
  display: none;
1410
1411
  }
1411
- `,hd=`
1412
+ `,Nd=`
1412
1413
  @namespace "http://www.w3.org/1999/xhtml";
1413
1414
 
1414
1415
  *:not([data-vivliostyle-role=doc-toc],
@@ -1438,7 +1439,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1438
1439
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1439
1440
  -adapt-behavior: toc-container;
1440
1441
  }
1441
- `,fd=`
1442
+ `,Td=`
1442
1443
  [data-viv-margin-discard~="block-start"] {
1443
1444
  margin-block-start: 0 !important;
1444
1445
  }
@@ -1574,10 +1575,6 @@ span[data-viv-leader] {
1574
1575
  white-space: pre;
1575
1576
  text-transform: none;
1576
1577
  }
1577
- [style*="--viv-footnote-inline-separator"]::after {
1578
- content: var(--viv-footnote-inline-separator);
1579
- white-space: normal;
1580
- }
1581
1578
  [style*="--viv-footnote-white-space"] {
1582
1579
  white-space: var(--viv-footnote-white-space);
1583
1580
  }
@@ -1620,7 +1617,7 @@ span[data-viv-leader] {
1620
1617
  -webkit-initial-letter: var(--viv-initialLetter);
1621
1618
  initial-letter: var(--viv-initialLetter);
1622
1619
  }
1623
- `,gd=String.raw`
1620
+ `,wd=String.raw`
1624
1621
  @counter-style decimal-leading-zero {
1625
1622
  system: extends decimal;
1626
1623
  pad: 2 '0';
@@ -1844,12 +1841,12 @@ span[data-viv-leader] {
1844
1841
  @counter-style upper-russian {
1845
1842
  system: alphabetic;
1846
1843
  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;
1847
- }`;function io(i,t,e){let n=L("fetchFromURL"),s={method:e||"GET",mode:"cors"},o=n.suspend(),r={status:0,statusText:"",url:i,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(i,s).then(a=>{var l;if(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)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(i)?(r.contentType="text/html",a.arrayBuffer().then(c=>new TextDecoder("Shift_JIS").decode(c))):(/^data:,(<|%3c)/i.test(i)&&(r.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?r.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?r.responseBlob=md([a]):t==="json"?r.responseText=JSON.stringify(a):typeof a=="string"&&(r.responseText=a),o.schedule(r)}).catch(a=>{r.status>=400?O.warn(`Error fetching ${i} (${r.status}${r.statusText?" "+r.statusText:""})`):O.warn(a,`Error fetching ${i}`),o.schedule(r)}),n.result()}function md(i,t){let e=t||"application/octet-stream";return new Blob(i,{type:e})}function kg(i){let t=L("readBlob"),e=new FileReader,n=t.suspend(e);return e.addEventListener("load",()=>{n.schedule(e.result)},!1),e.readAsArrayBuffer(i),t.result()}function Ag(i){return URL.createObjectURL(i)}var ro=class{constructor(t,e){this.parser=t;this.type=e;p(this,"resources",{});p(this,"fetchers",{})}load(t,e,n){t=Ht(t);let s=this.resources[t];return typeof s!="undefined"?T(s):this.fetch(t,e,n).get()}fetchInner(t,e,n){let s=L("fetch"),o=t.endsWith("?viv-toc-box");o&&(t=t.replace("?viv-toc-box",""));let r=ee("user-agent.xml",on),a=!o&&t===r;return a&&(t=`data:application/xml,${encodeURIComponent(ud)}`),io(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:""})`);o?(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=Ht(t),this.resources[t])return null;let o=this.fetchers[t];return o||(o=new An(()=>this.fetchInner(t,e,n),`Fetch ${t}`),this.fetchers[t]=o,o.start()),o}get(t){return this.resources[Ht(t)]}delete(t){delete this.resources[Ht(t)]}};function my(i,t){let e=i.responseText;return T(e?Vo(e):null)}function Rg(){return new ro(my,"text")}function Wt(i,t,e){let n=new An(()=>{let s=L("loadElement"),o=s.suspend(i),r=!1,a=null,l=c=>{r||(r=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(c?c.type:"timeout"))};if(i.addEventListener("load",l,!1),i.addEventListener("error",l,!1),i.addEventListener("abort",l,!1),i.namespaceURI=="http://www.w3.org/2000/svg")t&&i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(i.localName==="script")a=setTimeout(l,3e3);else if(t)if(i.localName==="img"){let c=i;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 i.src=t,e&&(i.alt=e);return s.result()},`loadElement ${t||i.localName}`);return n.start(),n}var Lg=0,Cy=16777216,Cd=33554432,il=50331648,al=67108864,by=83886080,yy=100663296;var ri=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 Lg;case"User":return yy;default:return by}}getBaseSpecificity(){switch(this.flavor){case"UA":return Lg;case"User":return Cy;default:return Cd}}},sl=class extends ri{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;O.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,o){this.slave.attributeSelector(e,n,s,o)}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)}},ol=class extends ri{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()}},fn=class extends ol{constructor(t,e,n){super(t,e,n)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.pushHandler(new ol(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())}},Re=[],rl=[],ge=[],Ae=[],Zt=[],yt=[],Ve=[],$e=[],fe=[],Ke=[],pt=[],We=[],Fe=[];var tr=55,nr=56,nl=57;Re[1]=28,Re[36]=29,Re[7]=29,Re[9]=29,Re[14]=29,Re[18]=29,Re[50]=29,Re[20]=30,Re[13]=27,Re[0]=200,rl[1]=46,rl[0]=200,yt[1]=2,yt[36]=4,yt[7]=6,yt[9]=8,yt[14]=10,yt[18]=14,yt[50]=42,ge[37]=11,ge[23]=12,ge[35]=56,ge[1]=1,ge[36]=3,ge[7]=5,ge[9]=7,ge[14]=9,ge[12]=13,ge[18]=55,ge[50]=58,ge[16]=41,Ae[37]=11,Ae[23]=12,Ae[35]=56,Ae[1]=1,Ae[36]=3,Ae[7]=5,Ae[9]=7,Ae[14]=9,Ae[18]=55,Zt[1]=2,Zt[36]=4,Zt[7]=6,Zt[9]=8,Zt[18]=14,Zt[50]=42,Zt[14]=10,Zt[12]=13,Ve[1]=15,Ve[7]=16,Ve[4]=17,Ve[5]=18,Ve[3]=19,Ve[2]=20,Ve[8]=21,Ve[27]=57,Ve[16]=22,Ve[19]=23,Ve[6]=24,Ve[11]=25,Ve[17]=26,Ve[13]=48,Ve[31]=47,Ve[23]=54,Ve[0]=44,$e[1]=31,$e[4]=32,$e[5]=32,$e[3]=33,$e[2]=34,$e[10]=40,$e[6]=38,$e[31]=36,$e[24]=36,$e[32]=35,fe[1]=45,fe[16]=37,fe[37]=37,fe[38]=37,fe[47]=37,fe[48]=37,fe[39]=37,fe[49]=37,fe[41]=37,fe[26]=37,fe[25]=37,fe[23]=37,fe[24]=37,fe[19]=37,fe[21]=37,fe[36]=37,fe[18]=37,fe[22]=37,fe[11]=39,fe[12]=43,fe[17]=49,Ke[0]=200,Ke[12]=50,Ke[13]=51,Ke[14]=50,Ke[15]=51,Ke[10]=50,Ke[11]=51,Ke[17]=53,pt[0]=200,pt[12]=50,pt[13]=52,pt[14]=50,pt[15]=51,pt[10]=50,pt[11]=51,pt[17]=53,We[0]=200,We[12]=50,We[13]=51,We[14]=50,We[15]=51,We[10]=50,We[11]=51,Fe[11]=0,Fe[16]=0,Fe[22]=1,Fe[18]=1,Fe[26]=2,Fe[25]=2,Fe[38]=3,Fe[37]=3,Fe[48]=3,Fe[47]=3,Fe[39]=3,Fe[49]=3,Fe[41]=3,Fe[23]=4,Fe[24]=4,Fe[36]=5,Fe[19]=5,Fe[21]=5,Fe[0]=6,Fe[tr]=2,Fe[nr]=2;var xs=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(G)}return n}valStackReduce(t,e){let n=this.valStack,s=n.length,o=0,r;do if(r=n[--s],t===")"&&r instanceof Pn){if(r.text===")")o++;else if(r.text==="("){if(o===0)return null;o--}}while(typeof r!="undefined"&&typeof r!="string");let a=n.length-(s+1);if(a>1&&n.splice(s+1,a,new X(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=pt);let c=new Ft(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;(!Vt(u)||u===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${c.toString()}`,e),this.actions=pt)}return c}if(t!=";"||s>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=pt,null;if(a>1)return new Se(this.extractVals(",",s+1));let l=n[0];return l instanceof _e?l:l?new Pn(l.toString()):G}exprError(t,e){this.actions=this.propName?pt:Ke,O.warn(t,e.toString())}exprStackReduce(t,e){let n=this.valStack,s=this.handler,o=n.pop(),r;for(;;){let a=n.pop();if(t==11){let l=[o];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 La(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();o=new Xn(s.getScope(),jr(u,c),l),t=0;continue}}if(a==10){o.isMediaName()&&(o=new Xr(s.getScope(),o,null)),t=0;continue}}else if(typeof a=="string"){n.push(a);break}if(a<0)if(a==-31)o=new zt(s.getScope(),o);else if(a==-24)o=new wn(s.getScope(),o);else if(a==-nl)o=new Aa(s.getScope(),o);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if(Fe[t]>Fe[a]){n.push(a);break}switch(r=n.pop(),a){case 26:o=new Do(s.getScope(),r,o);break;case tr:o=new Ra(s.getScope(),r,o);break;case nr:o=new Ia(s.getScope(),r,o);break;case 25:o=new Mo(s.getScope(),r,o);break;case 38:o=new Fa(s.getScope(),r,o);break;case 37:o=new Ba(s.getScope(),r,o);break;case 48:o=new Va(s.getScope(),r,o);break;case 47:o=new Ks(s.getScope(),r,o);break;case 39:case 49:o=new hs(s.getScope(),r,o);break;case 41:o=new Oa(s.getScope(),r,o);break;case 23:o=new zr(s.getScope(),r,o);break;case 24:o=new Gr(s.getScope(),r,o);break;case 36:o=new Zs(s.getScope(),r,o);break;case 19:o=new Wr(s.getScope(),r,o);break;case 21:o=new _o(s.getScope(),r,o);break;case 18:if(n.length>1)switch(n[n.length-1]){case 22:n.pop(),o=new Da(s.getScope(),n.pop(),r,o);break;case 10:if(r.isMediaName())o=new Xr(s.getScope(),r,o);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(o),!1;default:return this.exprError("F_UNEXPECTED_STATE",e),!1}}}return n.push(o),!1}readSupportsTest(t){let e=t.type===6,n=this.tokenizer,s,o;if(e)o=t.text,s=t.position+o.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(),o=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&&o==="selector"&&l>0?"":n.input.substring(s,c).trim();return new Ma(this.handler.getScope(),o,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 o=e.type===24,r=e.type===23||o;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,o&&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 o of s)switch(o){case"vertical":e=bt(n,e,new zt(n,new ye(n,"pref-horizontal")));break;case"horizontal":e=bt(n,e,new ye(n,"pref-horizontal"));break;case"day":e=bt(n,e,new zt(n,new ye(n,"pref-night-mode")));break;case"night":e=bt(n,e,new ye(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":case"footnote":return!0}return!1}runParser(t,e,n,s,o,r){let a=this.handler,l=this.tokenizer,c=this.valStack,u,d,h,f,g,m,C,x=null;for(n&&(this.inStyleDeclaration=!0),s&&(this.exprContext=2,this.valStack.push("{"));t>0;--t){if(u=l.token(),o&&x===null&&(x=u.position-1,l.input[x]==="("&&x++),this.actions===Ve&&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 Pn(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=pt):(this.actions=yt,a.startSelectorRule());continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Ve,c.splice(0,c.length);continue;case 46:if(l.nthToken(1).type!=18){this.actions=pt,a.error("E_CSS_COLON_EXPECTED",l.nthToken(1));continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Ve,c.splice(0,c.length);continue;case 29:this.actions=yt,a.startSelectorRule();continue;case 1:if(!u.precededBySpace){this.actions=We,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),o?this.actions=Ae:this.actions=ge,l.consume();break;case 36:a.tagSelector(h,null),o?this.actions=Ae:this.actions=ge,l.consume();break;default:this.actions=Ke,a.error("E_CSS_NAMESPACE",u)}else this.actions=Ke,a.error("E_CSS_UNDECLARED_PREFIX",u);else a.tagSelector(this.defaultNamespaceURI,u.text),o?this.actions=Ae:this.actions=ge,l.consume();continue;case 3:if(!u.precededBySpace){this.actions=We,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),o?this.actions=Ae:this.actions=ge,l.consume();break;case 36:a.tagSelector(null,null),o?this.actions=Ae:this.actions=ge,l.consume();break;default:this.actions=Ke,a.error("E_CSS_NAMESPACE",u)}else a.tagSelector(this.defaultNamespaceURI,null),o?this.actions=Ae:this.actions=ge,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),o?this.actions=Ae:this.actions=ge,l.consume();continue;case 7:u.precededBySpace&&a.descendantSelector();case 8:a.classSelector(u.text),o?this.actions=Ae:this.actions=ge,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(),o?this.actions=Ae:this.actions=ge;continue;case 6:switch(f=u.text,l.consume(),f){case"is":case"not":case"where":case"has":this.actions=yt,a.startFuncWithSelector(f),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,f==="has")?this.actions=ge:this.actions=We;continue;case"lang":case"href-epub-type":case"href-role-type":if(u=l.token(),u.type===1){C=[u.text],l.consume(),(f==="href-epub-type"||f==="href-role-type")&&l.token().type===16&&(l.consume(),u=l.token(),u.type===1&&(C.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(C=this.readNthPseudoParams(),C)if(f==="nth-child"||f==="nth-last-child"){if(d=l.nthToken(0),d.type===1&&d.text==="of"){l.consume(),this.actions=yt,a.startFuncWithSelector(f,C),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?o?this.actions=Ae:this.actions=ge:this.actions=We;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)C.push(d.text),l.consume();else break e;break}else break;else break e;default:C=this.readPseudoParams()}if(u=l.token(),u.type==11){a.pseudoclassSelector(f,C),l.consume(),o?this.actions=Ae:this.actions=ge;continue}break}a.error("E_CSS_PSEUDOCLASS_SYNTAX",u),this.actions=Ke;continue;case 58:u.precededBySpace&&a.descendantSelector();case 42:switch(l.consume(),u=l.token(),u.type){case 1:a.pseudoelementSelector(u.text,null),o?this.actions=Ae:this.actions=ge,l.consume();continue;case 6:if(f=u.text,l.consume(),f=="nth-fragment"){if(C=this.readNthPseudoParams(),C===null)break}else C=this.readPseudoParams();if(u=l.token(),u.type==11){a.pseudoelementSelector(f,C),o?this.actions=Ae:this.actions=ge,l.consume();continue}break}a.error("E_CSS_PSEUDOELEM_SYNTAX",u),this.actions=Ke;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=We,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=We,a.error("E_CSS_UNDECLARED_PREFIX",u),l.consume();continue}if(l.consume(),u=l.token(),u.type!=1){this.actions=We,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),o?this.actions=Ae:this.actions=ge,l.consume();continue;default:this.actions=We,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=We,a.error("E_CSS_ATTR_VAL_EXPECTED",u);continue}if(u.type!=15){this.actions=We,a.error("E_CSS_ATTR",u);continue}o?this.actions=Ae:this.actions=ge,l.consume();continue;case 11:a.childSelector(),this.actions=Zt,l.consume();continue;case 12:a.adjacentSiblingSelector(),this.actions=Zt,l.consume();continue;case 56:a.followingSiblingSelector(),this.actions=Zt,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=Re,l.consume();continue;case 41:a.nextSelector(),this.actions=yt,l.consume();continue;case 15:c.push(R(u.text)),l.consume();continue;case 16:g=parseInt(u.text,16),c.push(new zo(u.text)),l.consume();continue;case 17:c.push(new Ue(u.num)),l.consume();continue;case 18:c.push(new ae(u.num)),l.consume();continue;case 19:c.push(new k(u.num,u.text)),l.consume();continue;case 20:c.push(new z(u.text)),l.consume();continue;case 21:c.push(new Pe(ee(u.text,this.baseURL))),l.consume();continue;case 57:c.push(new qr(u.text)),l.consume();continue;case 22:this.valStackReduce(",",u),c.push(","),l.consume();continue;case 23:c.push(jn),l.consume();continue;case 24:f=u.text.toLowerCase(),f=="-epubx-expr"||f=="env"?(this.actions=$e,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 Pn("+")),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?rl:Re;continue;case 44:for(l.consume();c.length>0;){let b=c.length;if(m=this.valStackReduce(";",u),!m||c.length===b)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 ye(a.getScope(),jr(u.text,d.text))),this.actions=fe),l.consume();else{if(this.exprContext==2||this.exprContext==3)u.text.toLowerCase()=="not"?(l.consume(),c.push(new $r(a.getScope(),!0,d.text))):(u.text.toLowerCase()=="only"&&(l.consume(),u=d),c.push(new $r(a.getScope(),!1,u.text)));else if(this.exprContext===4&&u.text.toLowerCase()==="not"&&c[c.length-1]!==tr&&c[c.length-1]!==nr&&(d.type===10||d.type===6)){c.push(-nl),l.consume();continue}else c.push(new ye(a.getScope(),u.text));this.actions=fe}l.consume();continue;case 38:if(this.exprContext===4){c.push(this.readSupportsTest(u)),this.actions=fe;continue}c.push(null,u.text,"("),l.consume();continue;case 32:c.push(new Ne(a.getScope(),u.num)),l.consume(),this.actions=fe;continue;case 33:f=u.text,f=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?f="vh":f="vw"),c.push(new an(a.getScope(),u.num,f)),l.consume(),this.actions=fe;continue;case 34:c.push(new Ne(a.getScope(),u.text)),l.consume(),this.actions=fe;continue;case 35:l.consume(),u=l.token(),u.type!=5||u.precededBySpace?this.exprError("E_CSS_SYNTAX",u):(c.push(new Uo(a.getScope(),u.num)),l.consume(),this.actions=fe);continue;case 36:c.push(-u.type),l.consume();continue;case 37:this.actions=$e,this.exprStackReduce(u.type,u),c.push(u.type),l.consume();continue;case 45:u.text.toLowerCase()==="and"&&c[c.length-2]!==nr&&c[c.length-2]!==-nl?(this.actions=$e,this.exprStackReduce(tr,u),c.push(tr),l.consume()):u.text.toLowerCase()==="or"&&c[c.length-2]!==tr&&c[c.length-2]!==-nl?(this.actions=$e,this.exprStackReduce(nr,u),c.push(nr),l.consume()):this.exprError("E_CSS_SYNTAX",u);continue;case 39:this.exprStackReduce(u.type,u)&&(this.actions=Ve),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=Re)),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=Re,l.consume(),!1):(this.importCondition=c.pop(),this.importReady=!0,this.actions=Re,l.consume(),!1);l.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(u);if(b){c.push(b),this.actions=fe;continue}}c.push(u.type),l.consume();continue;case 27:if(this.actions=Re,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=$e,c.push("{");continue}a.error("E_CSS_IMPORT_SYNTAX",u),this.actions=Ke;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=Ke;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=Ke;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"-epubx-region":l.consume(),a.startRegionRule(),this.regionRule=!0,this.actions=yt;continue;case"page":l.consume(),a.startPageRule(),this.pageRule=!0,this.actions=Zt;continue;case"-adapt-footnote-area":case"footnote":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){let b=u.text;l.consume(),l.consume(),a.startFootnoteRule(b),this.ruleStack.push(f==="footnote"?"footnote":"-adapt-footnote-area"),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(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=$e,c.push("{");continue;case"media":l.consume(),this.propName=null,this.exprContext=2,this.actions=$e,c.push("{");continue;case"supports":l.consume(),this.propName=null,this.exprContext=4,this.actions=$e,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 b=null,N=null,S=[];for(u.type==1&&(b=u.text,l.consume(),u=l.token()),u.type==18&&l.nthToken(1).type==1&&(N=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;)S.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(b,N,S);break;case"-epubx-partition":a.startPartitionRule(b,N,S);break;case"-epubx-partition-group":a.startPartitionGroupRule(b,N,S);break}this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":a.error(`E_CSS_UNEXPECTED_AT${f}`,u),this.actions=We;continue;default:a.error(`E_CSS_AT_UNKNOWN ${f}`,u),this.actions=Ke;continue}a.error(`E_CSS_AT_SYNTAX ${f}`,u),this.actions=Ke;continue;case 50:this.errorBrackets.push(u.type+1),l.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Re;continue}case 51:if(o&&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=Re),l.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Re),l.consume();continue;case 200:return!0;default:if(s)return this.exprStackReduce(11,u)?(this.result=c.pop(),!0):!1;if(o){switch(u.type){case 16:case 11:if(this.actions===yt)a.error("E_CSS_SYNTAX",u);else{let b=l.input.substring(x,u.position);a.pushSelectorText(b),x=u.position+1}if(u.type===16){a.nextSelector(),this.actions=yt,l.consume();continue}else return a.endFuncWithSelector(),l.consume(),!0;case 37:case 23:case 35:if(r){this.actions=ge;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=We;continue}if(this.actions!==Ke&&this.actions!==We&&this.actions!==pt){if(u.type==54)a.error("E_CSS_SYNTAX",u);else if(this.actions===Ve){switch(u.type){case 10:case 12:case 14:this.errorBrackets.push(u.type+1);break}c.push(new Pn(u.toString())),l.consume();continue}else if(u.type===12&&this.actions==$e&&c.length>0){a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Re,l.consume();continue}else{if(u.type===17&&this.actions==$e)return this.actions=Re,l.consume(),!1;a.error("E_CSS_SYNTAX",u)}this.isInsidePropertyOnlyRule()?this.actions=pt:this.actions=We;continue}l.consume();continue}}return!1}},ii=class extends ri{constructor(e){super(null);this.scope=e}error(e,n){O.warn(e,n.toString())}getScope(){return this.scope}};function xy(i,t,e,n,s){let o=L("parseStylesheet"),r=new xs(Re,i,t,e),a=null;return s&&(a=Sy(new it(s,t),t,e)),a=r.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.loop(()=>{for(;!r.runParser(100,!1,!1,!1,!1);){if(r.importReady){let c=ee(r.importURL,e);r.importCondition&&(t.startMediaRule(r.importCondition),t.startRuleBody());let u=L("parseStylesheet.import");return bd(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=o.timeSlice();if(l.isPending)return l}return T(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function ll(i,t,e,n,s){return Kn("parseStylesheetFromText",o=>{let r=new it(i,t);xy(r,t,e,n,s).thenFinish(o)},(o,r)=>{O.warn(r,`Failed to parse stylesheet text: ${i}`),o.finish(!1)})}function bd(i,t,e,n){return Kn("parseStylesheetFromURL",s=>{io(i).then(o=>{o.responseText?ll(o.responseText,t,i,e,n).then(r=>{r||O.warn(`Failed to parse stylesheet from ${i}`),s.finish(!0)}):s.finish(!0)})},(s,o)=>{O.warn(o,"Exception while fetching and parsing:",i),s.finish(!0)})}function Ss(i,t,e){let n=new xs(Ve,t,new ii(i),e);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Fg(i,t,e){new xs(rl,i,t,e).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Sy(i,t,e){let n=new xs($e,i,t,e);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Ey={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function vy(i){return!!Ey[i]}function Vg(i,t,e){if(t instanceof te&&t.str==="viv-leader")return new D(t);if(e==="content"&&t instanceof te)return new D(t);let n=t.evaluate(i);switch(typeof n){case"number":return vy(e)?n==Math.round(n)?new ae(n):new Ue(n):new k(n,"px");case"string":return n?e==="content"?new z(n):Ss(t.scope,new it(n,null),""):G;case"boolean":return n?y._true:y._false;case"undefined":return G}throw new Error("E_UNEXPECTED")}function Bg(i,t){let e={};return Object.keys(i).forEach(n=>{let s=e[n]={},o=i[n];Object.keys(o).forEach(r=>{s[r]=o[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 Og(i,t,e,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let o=s[e||"ltr"];if(!o)throw new Error(`unknown direction: ${e}`);for(let r of o){let a=i.replace(r.regexp,r.to);if(a!==i)return a}return i}var Dg={"horizontal-tb":{ltr:[{logical:"inline-start",physical:"left"},{logical:"inline-end",physical:"right"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}],rtl:[{logical:"inline-start",physical:"right"},{logical:"inline-end",physical:"left"},{logical:"block-start",physical:"top"},{logical:"block-end",physical:"bottom"},{logical:"inline-size",physical:"width"},{logical:"block-size",physical:"height"}]},"vertical-rl":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"right"},{logical:"block-end",physical:"left"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]},"vertical-lr":{ltr:[{logical:"inline-start",physical:"top"},{logical:"inline-end",physical:"bottom"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}],rtl:[{logical:"inline-start",physical:"bottom"},{logical:"inline-end",physical:"top"},{logical:"block-start",physical:"left"},{logical:"block-end",physical:"right"},{logical:"inline-size",physical:"height"},{logical:"block-size",physical:"width"}]}},Ny=Bg(Dg,!0);function yd(i,t,e){return Og(i,t,e||null,Ny)}var Ty=Bg(Dg,!1);function xd(i,t,e){return Og(i,t,e||null,Ty)}var wy={"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 Mg(i,t){let e=wy[t];if(!e)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<e.length;n++)if(e[n].physical===i)return e[n].logical;return i}function or(i,t,e){var h;let n=t,s={width:n.style.width,height:n.style.height};function o(f){return i.getElementComputedStyle(t).getPropertyValue(f)}let a=o("writing-mode")!=="horizontal-tb",l=a?"height":"width",c=a?"width":"height";function u(f,g){n.style[f]=g;let m=o(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 Es(i){var t,e;return((t=i==null?void 0:i.style)==null?void 0:t["box-decoration-break"])==="clone"||((e=i==null?void 0:i.style)==null?void 0:e["-webkit-box-decoration-break"])==="clone"}function Ed(i){let t=i.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function vd(i,t){i.setAttribute("data-viv-box-break",t.join(" "))}function ht(i,t){let e=Ed(i);e.includes(t)||(e.push(t),vd(i,e))}function ky(i){let t=i.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function Ay(i,t){i.setAttribute("data-viv-margin-discard",t.join(" "))}function cl(i,t){let e=ky(i);e.includes(t)||(e.push(t),Ay(i,e))}function Ry(i){let t=i.name,e=i.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:e===y.always?y.page:e,important:i.important};default:return i}}var ul={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ee(i){return!!ul[i]}var Ly={left:!0,right:!0,recto:!0,verso:!0};function Zn(i){return!!Ly[i]}function Nd(i){return Ee(i)&&i!=="column"&&i!=="region"}var Iy={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function rr(i){return!!Iy[i]}function Be(i,t){if(i)if(t){if(Zn(t))return t;if(Zn(i))return i;{let e=Ee(i),n=Ee(t);if(e&&n)switch(t){case"column":return i;case"region":return i==="column"?t:i;default:return t}else return n?t:e?i:rr(t)?t:rr(i)?i:t}}else return i;else return t}function Td(i){return Ee(i)?i:"auto"}je("SIMPLE_PROPERTY",Ry);var ir=xb(qg());function Kg(i,t){return(0,ir.default)(i,t,0)}function Ad(i){return i.reduce((t,e)=>e[0]===ir.default.DELETE?t:t+e[1],"")}function Zg(i,t){return Jg(i,t,1)}function Qg(i,t){return Jg(i,t,-1)}function Jg(i,t,e){let n=0,s=0;return i.some(o=>{for(let r=0;r<o[1].length;r++){switch(o[0]*e){case ir.default.INSERT:n++;break;case ir.default.DELETE:n--,s++;break;case ir.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var hl;(t=>{function i(e){return e&&e.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=i})(hl||(hl={}));var Ns;(t=>{let i;(r=>(r.INLINE="inline",r.COLUMN="column",r.REGION="region",r.PAGE="page"))(i=t.FloatReference||(t.FloatReference={}))})(Ns||(Ns={}));var li;(t=>{function i(e){return e&&e.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=i})(li||(li={}));var Rn;(e=>{function i(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||gn.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=i;function t(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||gn.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=t})(Rn||(Rn={}));var gn;(e=>{function i(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=i;function t(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=t})(gn||(gn={}));var Qt;(e=>{let i;(r=>(r[r.IGNORE=0]="IGNORE",r[r.NEWLINE=1]="NEWLINE",r[r.PRESERVE=2]="PRESERVE"))(i=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={}))})(Qt||(Qt={}));var em={transform:!0,"transform-origin":!0},tm={top:!0,bottom:!0,left:!0,right:!0},ws=class{constructor(t,e,n){this.target=t;this.name=e;this.value=n}},zy={show:function(i){i.style.visibility="visible"},hide:function(i){i.style.visibility="hidden"},play:function(i){i.currentTime=0,i.play()},pause:function(i){i.pause()},resume:function(i){i.play()},mute:function(i){i.muted=!0},unmute:function(i){i.muted=!1}};function Gy(i,t){let e=zy[t];return e?()=>{for(let n=0;n<i.length;n++)try{e(i[n])}catch(s){}}:null}var Ts=class Ts extends ds{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 o=s.currentTarget,r=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let a={type:"hyperlink",target:null,currentTarget:null,anchorElement:o,href:r,preventDefault(){s.preventDefault()}};this.dispatchEvent(a)}}}setAutoPageWidth(e){this.isAutoPageWidth=e,e?this.container.setAttribute(Ts.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Ts.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(Ts.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Ts.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||P(a.target,a.name,a.value.toString())}let o=n.getElementClientRect(this.container);this.dimensions.width=o.width,this.dimensions.height=o.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=Gy(l,a.action);if(u)for(let d=0;d<c.length;d++)c[d].addEventListener(a.event,u,!1)}}}};p(Ts,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),p(Ts,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var ar=Ts,ft=Qt.Whitespace;function xl(i){switch(i){case"normal":case"nowrap":return ft.IGNORE;case"pre-line":return ft.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ft.PRESERVE;default:return null}}function ce(i,t){return i?i.nodeType==1?!1:Id(i.textContent,t):!0}function Id(i,t){switch(t){case ft.PRESERVE:return i.length==0;case ft.NEWLINE:return!!i.match(/^[ \t]*$/);case ft.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var fl=class{constructor(t,e){this.flowName=t;this.parentFlowName=e;p(this,"forcedBreakOffsets",[]);p(this,"formattingContext",null)}},gl=class{constructor(t,e,n,s,o,r,a,l,c){this.flowName=t;this.element=e;this.startOffset=n;this.priority=s;this.linger=o;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 nm(i,t){return i.top-t.top}function sm(i,t){return t.right-i.right}function om(i,t){var e,n;return i===t?!0:!i||!t?!1:(i.node===t.node||!!i.shadowContext&&!!t.shadowContext&&i.shadowType===Qt.ShadowType.ROOTLESS&&t.shadowType===Qt.ShadowType.ROOTLESS&&((e=i.node)==null?void 0:e.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&i.shadowType===t.shadowType&&Ld(i.shadowContext,t.shadowContext)&&Ld(i.nodeShadow,t.nodeShadow)&&om(i.shadowSibling,t.shadowSibling)}function mn(i,t){if(i===t)return!0;if(!i||!t||i.offsetInNode!==t.offsetInNode||i.after!==t.after||i.steps.length!==t.steps.length)return!1;for(let e=0;e<i.steps.length;e++)if(!om(i.steps[e],t.steps[e]))return!1;return!0}function rm(i){return{steps:[{node:i,shadowType:gt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function lo(i,t){return{steps:[{node:i.sourceNode,shadowType:gt.NONE,shadowContext:i.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:i.formattingContext,fragmentIndex:t!=null?t:i.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:i.preprocessedTextContent}}function cr(i,t){let e=new Qn(i.node,t,0);return e.shadowType=i.shadowType,e.shadowContext=i.shadowContext,e.nodeShadow=i.nodeShadow,e.shadowSibling=i.shadowSibling?cr(i.shadowSibling,t.copy()):null,e.formattingContext=i.formattingContext,e.fragmentIndex=i.fragmentIndex+1,e}var gt=Qt.ShadowType,Ps=class{constructor(t,e,n,s,o,r,a){this.owner=t;this.root=e;this.xmldoc=n;this.parentShadow=s;this.type=r;this.styler=a;p(this,"subShadow",null);o&&(o.subShadow=this)}equals(t){return t?this.owner===t.owner&&this.xmldoc===t.xmldoc&&this.type===t.type&&Ld(this.parentShadow,t.parentShadow):!1}};function Ld(i,t){return i===t||!!i&&!!t&&i.equals(t)}var ml=class{constructor(t,e){this.outer=t;this.count=e}},Qn=class i{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,"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=gt.NONE,this.shadowContext=e?e.shadowContext:null,this.breakPenalty=e?e.breakPenalty:0,this.floatReference=Ns.FloatReference.INLINE,this.whitespace=e?e.whitespace:ft.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=Ns.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:ft.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 i(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),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,o,r;let t=this,e=[];t.shadowType===Qt.ShadowType.ROOTLESS&&(t.floatReference!==Ns.FloatReference.INLINE||t.floatSide==="footnote")&&((r=(o=(s=t.shadowContext)==null?void 0:s.styler)==null?void 0:o.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?Qg(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}},Ot=class i{constructor(t){this.primary=t;p(this,"floats",null)}clone(){let t=new i(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(!mn(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(!mn(this.floats[e],t.floats[e]))return!1}else if(t.floats)return!1;return!0}},Cl=class i{constructor(t,e){this.chunkPosition=t;this.flowChunk=e}clone(){return new i(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},bl=class i{constructor(){p(this,"positions",[]);p(this,"startBreakType",null);p(this,"breakAfter",null)}clone(){let t=new i,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}},yl=class i{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 i;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&&Zn(e)?e:"any"}firstFlowChunkOfFlow(t){let e=this.flowPositions[t];if(!e)return null;let n=e.positions[0];return n?n.flowChunk:null}},lr=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,P(this.element,"top",`${t}px`),P(this.element,"height",`${e}px`)}setHorizontalPosition(t,e){this.left=t,this.width=e,P(this.element,"left",`${t}px`),P(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):Jr(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 tt(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 tt(t,e,t+n,e+s)}getOuterShape(t,e){let n=this.getOuterRect();return Ja(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 tt(t,e,t+n,e+s)}},Ln=class extends It{constructor(e,n,s,o){super();this.elem=e;this.context=n;this.rootContentValue=s;this.exprContentListener=o}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 Pe)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"){this.elem.ownerDocument;let o=this.exprContentListener(n,s,this.elem.ownerDocument);!o&&s&&n instanceof te&&n.str.startsWith("running-element-")&&(s=""),this.visitStrInner(s,o)}return null}};function at(i){return i!=null&&i!==G&&i!==y.normal&&i!==y.none&&!W(i)}var ue=Ns.FloatReference;function am(i){switch(i){case"inline":return ue.INLINE;case"column":return ue.COLUMN;case"region":return ue.REGION;case"page":return ue.PAGE;default:throw new Error(`Unknown float-reference: ${i}`)}}function bn(i){switch(i){case ue.INLINE:return!1;case ue.COLUMN:case ue.REGION:case ue.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${i}`)}}function Sl(i,t,e,n){let s=t?"vertical-rl":"horizontal-tb";if((i==="top"||i==="bottom")&&(i=xd(i,s,e)),i==="block-start"&&(i="inline-start"),i==="block-end"&&(i="inline-end"),i==="inline-start"||i==="inline-end"){let o=yd(i,s,e),r=Mg(o,s);r==="line-left"?i="left":r==="line-right"&&(i="right")}else i==="inside"?i=n==="left"?"right":"left":i==="outside"&&(i=n==="left"?"left":"right");return i!=="left"&&i!=="right"&&(O.warn(`Invalid float value: ${i}. Fallback to left.`),i="left"),i}var ui=class{constructor(t,e,n,s,o,r){this.nodePosition=t;this.floatReference=e;this.floatSide=n;this.clearSide=s;this.flowName=o;this.floatMinWrapBlock=r;p(this,"order",null);p(this,"id",null);p(this,"insidePageFloatArea",!1);p(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(t){return t.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!t.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(t){return!1}},Fd=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=>mn(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(s=>mn(s.nodePosition,t));if(e>=0)return this.floats[e];let n=t==null?void 0:t.steps;if(n!=null&&n.length){let s=this.floats.findIndex(o=>{let r=o.nodePosition.steps;if(!(r!=null&&r.length)||r.length===n.length||o.nodePosition.offsetInNode!==t.offsetInNode||o.nodePosition.after!==t.after)return!1;let a=Math.min(r.length,n.length);for(let l=0;l<a;l++)if(r[l].node!==n[l].node)return!1;return!0});if(s>=0)return this.floats[s]}return null}findPageFloatById(t){let e=this.floats.findIndex(n=>n.id===t);return e>=0?this.floats[e]:null}},di=class{constructor(t,e,n,s,o,r){this.floatReference=t;this.floatSide=e;this.clearSide=n;this.continuations=s;this.area=o;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}},pi=class{constructor(t,e){this.float=t;this.nodePosition=e}equals(t){return t?this===t?!0:this.float===t.float&&mn(this.nodePosition,t.nodePosition):!1}},In=class{constructor(t,e,n,s,o,r,a){this.parent=t;this.floatReference=e;this.container=n;this.flowName=s;this.generatingNodePosition=o;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);p(this,"outerContext",null);t&&t.children.push(this),this.writingMode=!W(r)&&r||t&&t.writingMode||y.horizontal_tb,this.direction=!W(a)&&a||t&&t.direction||y.ltr,this.floatStore=t?t.floatStore:new Fd;let l=this.getPreviousSibling();this.floatsDeferredFromPrevious=l?[].concat(l.floatsDeferredToNext):[]}get effectiveParent(){var t;return(t=this.parent)!=null?t:this.outerContext}getParent(t){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${t}`)}setOuterContext(t){this.outerContext=t,this.floatStore=t.floatStore}getPreviousSiblingOf(t,e,n,s){let o=this.children.indexOf(t);o<0&&(o=this.children.length);for(let r=o-1;r>=0;r--){let a=this.children[r];if(a.floatReference===e&&a.flowName===n&&mn(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,o)=>s.getOrder()-o.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 o=this.floatFragments.splice(s,1)[0],r=o.area&&o.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(o=>o.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(o=>o.float.getOrder()<n&&!t.isAllowedToPrecede(o.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(o=>{let r=o.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(o=>o.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===ue.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let t=this.getFloatsDeferredToNextInChildContexts(),e=this.floatFragments.reduce((n,s)=>n.concat(s.continuations.map(o=>o.float)),[]);e.sort((n,s)=>s.getOrder()-n.getOrder());for(let n of e){let s=n.getOrder();if(t.some(o=>!n.isAllowedToPrecede(o)&&s>o.getOrder())){if(this.locked)this.invalidate();else{this.forbid(n);let o=this.findPageFloatFragment(n);this.removePageFloatFragment(o)}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 xd(t,e,n)}toPhysical(t){let e=this.writingMode.toString(),n=this.direction.toString();return yd(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=[],o=!1,r=!1;for(let a=0;a<n.length;a++){let l=n[a];l.includes("block")?o||(n.slice(a+1).some(c=>c.includes("block"))?(s.push("snap-block"),o=!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 o=this.floatFragments[s],r=this.toLogicalFloatSides(o.floatSide)[0];(r===n||n==="snap-block"&&r==="block-end"||n==="snap-inline"&&r==="inline-end")&&o.shouldBeStashedBefore(t)?(this.stashedFloatFragments.push(o),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,o,r=!0){this.container;let a=this.toLogical(t),l=this.toPhysical(t),c=e&&this.toLogical(e),u=e&&this.toPhysical(e),d=this.getLimitValueInner(a,c,n,s,o);if(r&&this.parent&&this.parent.container){let h=this.parent.getLimitValue(l,u,n,s,o,r);switch(l){case"top":return Math.max(d,h);case"left":return Math.max(d,h);case"bottom":return Math.min(d,h);case"right":return Math.min(d,h);default:}}return d}getLimitValueInner(t,e,n,s,o){this.container;let r=this.getLimitValuesInner(n,s,o,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,o){var h,f,g,m;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};if(this.container.vertical){let C=parseFloat((f=(h=this.container.element)==null?void 0:h.style)==null?void 0:f.width);isFinite(C)&&C>this.container.width&&(c.right+=C-this.container.width)}else{let C=parseFloat((m=(g=this.container.element)==null?void 0:g.style)==null?void 0:m.height);isFinite(C)&&C>this.container.height&&(c.bottom+=C-this.container.height)}function u(C,x,b){return C.unit==="%"?b*C.num/100:t.convertLengthToPx(C,x,e)}let d=this.floatFragments;return d.length>0&&(c=d.reduce((C,x)=>{if(n&&!n(x,this))return C;let[b,N]=this.toLogicalFloatSides(x.floatSide);if(N&&(s&&N.includes("block")===s.includes("block")&&N!==s||o&&N.includes("block")===o.includes("block")&&N!==o))return C;let S=x.area,E=x.continuations[0].float.floatMinWrapBlock,v=S.vertical?S.left+S.getInsetLeft()+S.width+S.getInsetRight():S.top+S.getInsetTop()+S.height+S.getInsetBottom(),w=S.vertical?S.top+S.getInsetTop()+S.height+S.getInsetBottom():S.left+S.getInsetLeft()+S.width+S.getInsetRight(),A=C.top,I=C.left,_=C.bottom,Y=C.right,Q=C.floatMinWrapBlockStart,me=C.floatMinWrapBlockEnd;switch(b){case"inline-start":S.vertical?A=Math.max(A,w):I=Math.max(I,w);break;case"block-start":S.vertical?(E&&S.left<Y&&(Q=u(E,S.rootViewNodes[0],l.x2-l.x1)),Y=Math.min(Y,S.left)):(E&&v>A&&(Q=u(E,S.rootViewNodes[0],l.y2-l.y1)),A=Math.max(A,v));break;case"inline-end":S.vertical?_=Math.min(_,S.top):Y=Math.min(Y,S.left);break;case"block-end":S.vertical?(E&&v>I&&(me=u(E,S.rootViewNodes[0],l.x2-l.x1)),I=Math.max(I,v)):(E&&S.top<_&&(me=u(E,S.rootViewNodes[0],l.y2-l.y1)),_=Math.min(_,S.top));break;default:throw new Error(`Unknown logical float side: ${b}`)}return{top:A,left:I,bottom:_,right:Y,floatMinWrapBlockStart:Q,floatMinWrapBlockEnd:me}},c)),c.left+=r,c.right+=r,c.top+=a,c.bottom+=a,c}setFloatAreaDimensions(t,e,n,s,o,r,a){if(e!==this.floatReference)return this.getParent(e).setFloatAreaDimensions(t,e,n,s,o,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(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,C=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 x(v,w){let A=v(t.bands,w);return A?(t.vertical&&(A=Ka(A)),d=t.vertical?Math.min(d,A.x2):Math.max(d,A.y1),h=t.vertical?Math.max(h,A.x1):Math.min(h,A.y2),!0):r}let b,N,S,E;if(o){let v=t.vertical?Ko(new tt(h,f,d,g)):new tt(f,d,g,h);if((l[0]==="block-start"||l[0]==="snap-block"||l[0]==="inline-start"||l[0]==="snap-inline")&&!x(Cg,v)||(l[0]==="block-end"||l[0]==="snap-block"||l[0]==="inline-end"||l[0]==="snap-inline")&&!x(bg,v)||(S=(h-d)*t.getBoxDir(),b=S-t.getInsetBefore()-t.getInsetAfter(),E=(g-f)*t.getInlineDir(),N=E-t.getInsetStart()-t.getInsetEnd(),!r&&(b<=0||N<=0)))return null}else{let v=t.getContentBlockMarginAfter();b=Math.max(0,t.computedBlockSize+Math.min(0,v)),S=b+t.getInsetBefore()+t.getInsetAfter();let w=(h-d)*t.getBoxDir();if(l[0]==="snap-block"){if(s===null)l[0]="block-start";else{let I=this.container.getPaddingRect(),_=this.container.getBoxDir()*(s-(this.container.vertical?I.x2:I.y1)),Y=this.container.getBoxDir()*((this.container.vertical?I.x1:I.y2)-s-S);_<=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(!r&&w<S)return null;l[0]==="inline-start"||l[0]==="inline-end"||l[1]?N=or(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?N=t.getContentInlineSize():N=t.vertical?t.height:t.width,E=N+t.getInsetStart()+t.getInsetEnd();let A=(g-f)*t.getInlineDir();if(!r&&A<E)return null}return d-=m,h-=m,f-=C,g-=C,l.some(v=>v==="inline-start"||v==="snap-inline")||l.length===1&&(l[0]==="block-start"||l[0]==="snap-block")?t.setInlinePosition(f,N):(l.some(v=>v==="inline-end")||l.length===1&&l[0]==="block-end")&&t.setInlinePosition(g-E*t.getInlineDir(),N),l.some(v=>v==="block-start"||v==="snap-block")||l.length===1&&(l[0]==="inline-start"||l[0]==="snap-inline")?t.setBlockPosition(d,b):(l.some(v=>v==="block-end")||l.length===1&&l[0]==="inline-end")&&t.setBlockPosition(h-S*t.getBoxDir(),b),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)}getBlockEndEdgeOfBlockStartFloats(t){let e=this,n=null;for(;e&&!n;)n=e.container,e=e.parent;let s=!!(n!=null&&n.vertical),o=NaN;if(this.floatFragments.filter(r=>r.floatSide.includes("block-start")).filter(r=>{if(!isFinite(t))return!0;let a=r.getOuterRect();return s?a.y1<=t&&t<=a.y2:a.x1<=t&&t<=a.x2}).forEach(r=>{let a=r.getOuterRect(),l=s?a.x1:a.y2;o=isFinite(o)?s?Math.min(o,l):Math.max(o,l):l}),this.parent){let r=this.parent.getBlockEndEdgeOfBlockStartFloats(t);isFinite(r)&&(o=isFinite(o)?s?Math.min(o,r):Math.max(o,r):r)}return o}getBlockStartEdgeOfBlockEndFloats(t){let e=this,n=null;for(;e&&!n;)n=e.container,e=e.parent;let s=!!(n!=null&&n.vertical),o=NaN;if(this.floatFragments.filter(r=>r.floatSide.includes("block-end")).filter(r=>{if(!isFinite(t))return!0;let a=r.getOuterRect();return s?a.y1<=t&&t<=a.y2:a.x1<=t&&t<=a.x2}).forEach(r=>{let a=r.getOuterRect(),l=s?a.x2:a.y1;o=isFinite(o)?s?Math.max(o,l):Math.min(o,l):l}),this.parent){let r=this.parent.getBlockStartEdgeOfBlockEndFloats(t);isFinite(r)&&(o=isFinite(o)?s?Math.max(o,r):Math.min(o,r):r)}return o}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 o=e.getPaddingRect(),r=e.vertical?o.x1:o.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 o=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"?o==="snap-block"?a=["block-start","block-end"]:a=[o]: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,o=null;for(;s&&s.container;){let l=s.getLimitValuesInner(e,n);o?t.vertical?(l.right<o.right&&(o.right=l.right,o.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.left>o.left&&(o.left=l.left,o.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):(l.top>o.top&&(o.top=l.top,o.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.bottom<o.bottom&&(o.bottom=l.bottom,o.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):o=l,s=s.parent}let r=Math.max(o.floatMinWrapBlockStart,o.floatMinWrapBlockEnd);return(t.vertical?o.right-o.left:o.bottom-o.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}},ci=[],Cn=class{static register(t){ci.push(t)}findByNodeContext(t){for(let e=ci.length-1;e>=0;e--){let n=ci[e];if(n.appliesToNodeContext(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=ci.length-1;e>=0;e--){let n=ci[e];if(n.appliesToFloat(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},Vd=class{appliesToNodeContext(t){return bn(t.floatReference)}appliesToFloat(t){return!0}createPageFloat(t,e,n){let s=t.floatReference;t.floatSide;let o=t.floatSide,r=t.toNodePosition(),a=!!e.generatingNodePosition;return n.resolveFloatReferenceFromColumnSpan(s,t.columnSpan,t).thenAsync(l=>{s=l,e.flowName;let c=new ui(r,s,o,t.clearSide,e.flowName,t.floatMinWrapBlock);if(c.insidePageFloatArea=a,a){let u=e.generatingNodePosition;u&&(c.parentPageFloat=e.findPageFloatByNodePosition(u))}return e.addPageFloat(c),T(c)})}createPageFloatFragment(t,e,n,s,o){let r=t[0].float;return new di(r.floatReference,e,n,t,s,o)}findPageFloatFragment(t,e){return e.findPageFloatFragment(t)}adjustPageFloatArea(t,e,n){return T(void 0)}forbid(t,e){}};Cn.register(new Vd);var $y=di,fi=class i extends ui{constructor(e,n,s,o,r){super(e,n,"block-end",null,s,r);this.footnotePolicy=o}isAllowedToPrecede(e){return!(e instanceof i)}},El=class extends $y{constructor(t,e,n,s){super(t,"block-end",null,e,n,s)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof fi?!0:this.getOrder()<t.getOrder()}},Bd=class{constructor(t){this.footnote=t}allowLayout(t){let e=t.toNodePosition();return!mn(e,this.footnote.nodePosition)}},Od=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof fi}createPageFloat(t,e,n){let s=ue.REGION,o=e.getPageFloatLayoutContext(s);e.getPageFloatLayoutContext(ue.PAGE).hasSameContainerAs(o)&&(s=ue.PAGE);let a=!!e.generatingNodePosition;a&&s!==ue.PAGE&&(s=ue.PAGE);let l=t.toNodePosition();e.flowName;let c=new fi(l,s,e.flowName,t.footnotePolicy,t.floatMinWrapBlock);if(c.insidePageFloatArea=a,a){let u=e.generatingNodePosition;u&&(c.parentPageFloat=e.findPageFloatByNodePosition(u))}return e.addPageFloat(c),T(c)}createPageFloatFragment(t,e,n,s,o){let r=t[0].float;return new El(r.floatReference,t,s,o)}findPageFloatFragment(t,e){let s=e.getPageFloatLayoutContext(t.floatReference).floatFragments.filter(o=>o instanceof El);return s.length<=1,s[0]||null}adjustPageFloatArea(t,e,n){t.isFootnote=!0,t.adjustContentRelativeSize=!1;let s=t.element;return n.layoutContext.applyFootnoteStyle(e.vertical,n.layoutContext.nodeContext&&n.layoutContext.nodeContext.direction==="rtl",s).thenAsync(o=>(t.vertical=o,t.convertPercentageSizesToPx(s),n.setComputedInsets(s,t),n.setComputedWidthAndHeight(s,t),T(void 0)))}forbid(t,e){let n=t;switch(n.footnotePolicy){case y.line:{let s=new Bd(n);e.addLayoutConstraint(s,n.floatReference);break}}}};Cn.register(new Od);var Xy="data-vivliostyle-flow-root";function cm(i){return i.getAttribute(Xy)==="true"}function lm(i){let t=(i==null?void 0:i.toString())||"block",e;switch(t){case"inline-flex":e="flex";break;case"inline-grid":e="grid";break;case"inline-table":e="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":e="block";break;default:e=t}return R(e)}function ur(i){return i===y.absolute||i===y.fixed}function co(i){return i instanceof Ft&&i.name==="running"}function Dd(i,t,e,n){return i===y.none||(ur(t)?(e=y.none,i=lm(i)):(e&&e!==y.none&&!W(e)||n)&&(i=lm(i))),{display:i,position:t,float:e}}function vl(i,t,e,n){return Dd(i,t,e,n).display===y.block}function Nl(i){return i instanceof J||i instanceof X||typeof i=="string"}function Et(i){if(!Nl(i))return!1;let t=i.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 uo(i){return Nl(i)?i.toString().includes("list-item"):!1}function um(i){if(!Nl(i))return!1;switch(i.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Tl(i){if(!Nl(i))return!1;switch(i.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function dm(i,t,e,n,s,o,r){return s=s||o||y.horizontal_tb,!!r||!!e&&e!==y.none&&!W(e)||ur(t)||i===y.inline_block||i===y.table_cell||i===y.table_caption||i==y.flex||i==y.grid||i==y.flow_root||(i===y.block||i===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!W(n)||!!o&&s!==o}function pm(i){return i===y.relative||i===y.absolute||i===y.fixed}var Fn=1e5;function gi(i){let t=i.element.style;t.columnGap=`${Fn-(i.vertical?i.height:i.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function pr(i){let e=("element"in i?i.element:i).style;e.columnWidth="",e.columnCount="",e.columnGap="",e.columnFill=""}function hr(i){return i.element.style.columnCount==="1"}function hm(i){i.element.setAttribute("data-vivliostyle-column","true")}function po(i,t){let e=t?i.bottom:Math.max(Math.abs(i.left),Math.abs(i.right));return Math.round(e/Fn)}function fm(i,t){let e=po(i,t);if(e===0)return 0;let n=t?i.top:Math.min(Math.abs(i.left),Math.abs(i.right)),s=Math.round(n/Fn),o=s*Fn,r=e*Fn;return t?(i.top-=o,i.bottom-=r,i.bottom<i.top&&(i.bottom+=Fn),i.right-=o,i.left-=r):i.left<-Fn/2?(i.right+=o,i.left+=r,i.left>i.right&&(i.left-=Fn),i.top+=o,i.bottom+=r):(i.left-=o,i.right-=r,i.right<i.left&&(i.right+=Fn),i.top+=o,i.bottom+=r),i.width=i.right-i.left,i.height=i.bottom-i.top,s}function Pl(i,t){for(let e=0;e<i.length;e++)fm(i[e],t)}function Dt(i,t,e){let n=i.getElementClientRect(t);if(fm(n,e)>0&&i.getElementComputedStyle(t).display.startsWith("table")&&!fr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return pr(r),i.getElementClientRect(t)}return n}function gm(i,t){var e,n;if(i.nodeType===1){let s=i;((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 fr(i){for(let t=i.nodeType===1?i:i.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 mm(i){var b;if(i.nodeType!==1)return;let t=i,e=t.style,n=(e==null?void 0:e.breakBefore)==="column",s=t.previousElementSibling,o=s&&((b=s.style)==null?void 0:b.breakAfter)==="column";if(!n&&!o)return;let r=fr(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(),C=t.getBoundingClientRect();(h?C.top>m.bottom+g:f?C.right<m.left-g:C.left>m.right+g)&&(n&&(e.breakBefore=""),o&&s&&(s.style.breakAfter=""),e.marginBlockStart=`${Fn}px`)}function wl(i){let t=i.element.lastElementChild,e=t&&i.clientLayout.getElementClientRect(t);return e?po(e,i.vertical):0}function Md(i,t){if(i.getAttribute("data-viv-saved-column-fill")!=="auto"||wl(t))return;let e=t.clientLayout.getElementComputedStyle(i),n=parseFloat(e.blockSize);i.style.columnFill="auto";let s=parseFloat(e.blockSize),o=NaN;if(i.style.blockSize=`${s}px`,wl(t)){if(i.style.blockSize=`${n}px`,!wl(t)){let r=1/(t.clientLayout.pixelRatio||1),a=n,l=s;for(;l-a>r;){let c=(a+l)/2;i.style.blockSize=`${c}px`,wl(t)?l=c:a=c}o=a,i.style.blockSize=`${o}px`}}else if(o=parseFloat(e.blockSize),o<s){let r=1/t.clientLayout.layoutUnitPerPixel;o=s+r,i.style.blockSize=`${o}px`}if(isNaN(o)){i.style.blockSize="",i.style.columnFill="balance";return}i.removeAttribute("data-viv-saved-column-fill")}function Cm(i){let t=i.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let e of t)Md(e,i)}function ks(i,t,e,n){let s=i.viewNode;if(!s)return NaN;let o=s.nodeType===1?s:s.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let r=o.style;if(o.localName==="wbr"||r&&Et(r.display)&&/^([\d\.]|super|(text-)?top)/.test(r.verticalAlign))return NaN}if(s===o){if(o.localName==="br"){let a=o.ownerDocument.createElement("span");o.parentNode.insertBefore(a,o);let l=t.getElementClientRect(a);if(a.remove(),l){let c=[l];Pl(c,n);let u=c[0],d=n?u.left:u.bottom;if(!isNaN(d)&&d!==0)return d}return NaN}if(i.after||!i.inline){if(i.after&&!i.inline&&o.querySelector("ruby")){let a=o.parentNode,l=o.nextSibling;a.removeChild(o),a.insertBefore(o,l)}let r=Dt(t,o,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 i.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;i.after&&(e+=l),e>=l&&(e=l-1),a.setStart(s,e),a.setEnd(s,e+1);let c=t.getRangeClientRects(a);Pl(c,n);let u=c.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)c=u;else{let d=o?t.getElementComputedStyle(o).whiteSpace:"";c=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?c.filter(f=>n?f.right>f.left:f.bottom>f.top):[]}return c.length?(n?r=Math.min.apply(null,c.map(d=>d.left)):r=Math.max.apply(null,c.map(d=>d.bottom)),r):NaN}}function mi(i,t,e){let n=hr(t);n&&pr(t);let s=t.clientLayout.getElementClientRect(i);n&&gi(t);let o=t.getComputedMargin(i);return e?s.width+o.left+o.right:s.height+o.top+o.bottom}function Jn(i){for(;i;){if(i.parentNode===i.ownerDocument)return!1;i=i.parentNode}return!0}function kl(i,t){var e;if(i)for(let n=i.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")&&i.removeChild(n)}var Vn="data-adapt-spec";function Al(i){return!!i.getAttribute(Vn)}function Bn(i){return(i==null?void 0:i.nodeType)!==1?!1:Al(i)?!0:_d(i)}function _d(i){var s,o;if((i==null?void 0:i.nodeType)!==1)return!1;let t=i,e=(s=t.style)==null?void 0:s.position;if(e==="absolute"||e==="fixed")return!0;let n=(o=t.style)==null?void 0:o.float;return n==="left"||n==="right"||n==="inline-start"||n==="inline-end"}function Ud(i){var t;return(i==null?void 0:i.nodeType)!==1?!1:((t=i.style)==null?void 0:t.position)==="fixed"}function es(i){let t=i==null?void 0:i.viewNode;return(t==null?void 0:t.nodeType)===1&&Al(t)}function bm(i){return i!=="inline"&&(Et(i)||Tl(i))}function Hd(i){var t;for(let e=i.parent;e;e=e.parent)if((e.display!=="inline"||e.vertical!==((t=e.parent)==null?void 0:t.vertical))&&Et(e.display))return e;return null}function ym(i){let t=i;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===i||!t)return null;t=(t==null?void 0:t.previousSibling)||null}}return null}var ho=class{calculateOffset(t){return As(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function As(i,t){return{current:t.reduce((e,n)=>e+n.calculateOffset(i),0),minimum:t.reduce((e,n)=>e+n.calculateMinimumOffset(i),0)}}var On=class extends ho{constructor(e,n,s,o){super();this.position=e;this.breakOnEdge=n;this.overflows=s;this.computedBlockSize=o;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(rr(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=ks(this.position,e.clientLayout,0,e.vertical)+n,!this.position.after&&!this.position.inline){let o=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*o}else if(this.position.after&&((s=this.position.shadowContext)==null?void 0:s.root.id)==="table-cell"){let o=e.element.parentElement,r=o==null?void 0:o.closest("table, [style*='display: table;']");if(r){let a=r.style.borderCollapse==="collapse",l=0,c=0;for(let u=o;u;u=u.parentElement){let d=e.clientLayout.getElementComputedStyle(u);if((u===o||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===o||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(!Rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(n))return!1;let s=n.getRepetitiveElements();return s?s.isFirstContentNode(e):!1}};var Rs=class{find(t){let e=Je("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()}`)}},Dn=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 On(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===Qt.ShadowType.ROOTLESS&&es(n))return;let o=n.viewNode;((a=o.parentElement)==null?void 0:a.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let r=o.parentNode;kl(r,o),s&&r.removeChild(o)}finishBreak(t,e,n,s){let o=n||e.viewNode!=null&&e.viewNode.nodeType==1&&!e.after;return t.clearOverflownViewNodes(e,o),s&&t.layoutContext.processFragmentedBlockEdge(e),T(!0)}},gr=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){}},Ci=new Dn,xm=hl.isInstanceOfBlockFormattingContext;je("RESOLVE_FORMATTING_CONTEXT",(i,t,e,n,s,o)=>{let r=i.parent;return!r&&i.formattingContext||r&&i.formattingContext!==r.formattingContext?null:i.establishesBFC||!i.formattingContext&&vl(e,n,s,o)?new gr(r?r.formattingContext:null):null});je("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof gr?Ci:null);var Ls=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=L("AbstractLayoutRetryer.tryLayout");this.saveState(t,e);let s=this.resolveLayoutMode(t);return s.doLayout(t,e).then(o=>{let r=s.accept(o,e);r=s.postLayout(o,this.initialPosition,e,r),r?n.finish(o):(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 Wd=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){}},fo=class{constructor(t,e){this.strategy=t;this.layoutContext=e}iterate(t){let e=this.strategy,n=e.initialState(t),s=L("LayoutIterator");return s.loopWithFrame(o=>{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?o.breakLoop():(n.nodeContext=c,o.continueLoop())});return}else if(n.break){o.breakLoop();return}else n.nodeContext=l.get()}e.finish(n),o.breakLoop()}).then(()=>{s.finish(n.nodeContext)}),s.result()}},ns=class extends Wd{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&&Ee(e.breakAtTheEdge);if(s){let o=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;o.viewNode.parentNode.removeChild(o.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 o=e.nodeContext,r=!n.allowLayout(o);return r&&(s.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),o=e.nodeContext=o.modify(),o.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=Be(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=Be(e.breakAtTheEdge,e.nodeContext.breakAfter)),T(!0)))}};var Ll=[];function Em(){Ll=[]}function jd(i,t,e){return i-=e,t===0?i===0:i%t===0&&i/t>=0}var $d=class{constructor(t){this.matchers=t}matches(){return this.matchers.some(t=>t.matches())}},Xd=class{constructor(t){this.matchers=t}matches(){return this.matchers.every(t=>t.matches())}},mr=class mr{constructor(t,e,n){this.elementOffset=t;this.a=e;this.b=n}static registerFragmentIndex(t,e,n){let s=mr.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:e,priority:n})}static clearFragmentIndices(){mr.fragmentIndices={}}matches(){let t=mr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&jd(t.fragmentIndex,this.a,this.b)}};p(mr,"fragmentIndices",{});var Is=mr,go=class{static buildViewConditionMatcher(t,e){let n=e.split("_");return n[0]=="NFS"?new Is(t,parseInt(n[1],10),parseInt(n[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new Xd(t)}static buildAnyMatcher(t){return new $d(t)}};var Vp={"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},jy=["image-resolution","orphans","widows"];function Tm(){return Je("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(jy))}var Yy={"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},Zd=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],qy=["max-%","min-%","%"],Nm=(()=>{let i=["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<Zd.length;e++)for(let n=0;n<i.length;n++){let s=Zd[e].replace("%",i[n]);t[s]=!0}return t})();function xr(i,t){let e={};for(let n of Zd)for(let s in i){let o=n.replace("%",s),r=n.replace("%",i[s]);e[o]=r,e[r]=o}for(let n of qy)for(let s in t){let o=n.replace("%",s),r=n.replace("%",t[s]);e[o]=r,e[r]=o}return e}var Bp=xr({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Op=xr({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Ky=xr({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Zy=xr({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Qy=xr({inside:"right",outside:"left"},{}),Jy=xr({inside:"left",outside:"right"},{}),V=class i{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 i(e,this.priority)}increaseSpecificity(t){return t==0?this:new i(this.value,this.priority+t)}evaluate(t,e,n,s){return e&&Vt(e)?this.value:Ti(t,this.value,e,n,s)}isEnabled(t){return!0}},bi=class i extends V{constructor(e,n,s){super(e,n);this.condition=s}getBaseValue(){return new V(this.value,this.priority)}filterValue(e){let n=this.value.visit(e);return n===this.value?this:new i(n,this.priority,this.condition)}increaseSpecificity(e){return e==0?this:new i(this.value,this.priority+e,this.condition)}isEnabled(e){try{return!!this.condition.evaluate(e)}catch(n){O.warn(n)}return!1}};function Qd(i,t,e){return(!t||e.priority>=t.priority)&&e.isEnabled(i)?e.getBaseValue():t}function Jt(i,t,e,n){if(i)if(!e)delete i[t];else{let s=i[t];(!s||e.priority>=s.priority)&&(n?e.isEnabled(n)&&(i[t]=e.getBaseValue()):i[t]=e)}}var wm={"region-id":!0,"fragment-selector-id":!0},Pm="data-viv-footnote-counter";function km(i){let t=i.getAttribute(Pm);if(!t)return Object.create(null);let e;try{e=JSON.parse(t)}catch(s){return Object.create(null)}if(!e||typeof e!="object"||Array.isArray(e))return Object.create(null);let n=Object.create(null);return Object.entries(e).forEach(([s,o])=>{if(Array.isArray(o)){let r=o.filter(a=>typeof a=="number"&&isFinite(a));n[s]=r}else typeof o=="number"&&isFinite(o)&&(n[s]=[o])}),n}function ex(i,t,e){let n=km(i);n[t]=e,i.setAttribute(Pm,JSON.stringify(n))}function tx(i){return!!wm[i]}function Fl(i){return i.charAt(0)==="_"&&i!=="_viewConditionalStyles"}function Fs(i){return i.charAt(0)!=="_"&&!wm[i]}function rs(i){return!!Vp[i]||Vt(i)}function ne(i,t){return i[t]}function Mn(i,t,e){e?i[t]=e:delete i[t]}function lt(i,t){return i[t]}function yn(i,t){let e=i[t];return e||(e={},i[t]=e),e}var Am=i=>{let t=i._viewConditionalStyles;return t||(t=[],i._viewConditionalStyles=t),t};function Dp(i,t){return i[t]}function Rm(i,t){let e=i[t];return e||(e=[],i[t]=e),e}function vi(i,t,e,n,s,o,r){var l,c;if([{id:s,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(u=>{if(u.id){let d=yn(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(!Fl(u))if(tx(u)){let d=Dp(e,u),h=Rm(t,u);Array.prototype.push.apply(h,d)}else{let d=ne(e,u);if(!d.isEnabled(i))continue;let h=d.increaseSpecificity(n);Jt(t,u,h,i);let f=(c=(l=i.style)==null?void 0:l.validatorSet.shorthands[u])==null?void 0:c.propList;if(f)for(let g of f){let m=new V(G,h.priority);Jt(t,g,m,i)}}}function Lm(i,t){let e={};for(let n=0;n<t.length;n++)vi(i,e,t[n],0,null,null,null);return e}function Mp(i,t){if(i.length>0){i.sort((n,s)=>s.getPriority()-n.getPriority());let e=null;for(let n=i.length-1;n>=0;n--)e=i[n],e.chained=t,t=e;return e}return t}var Vl=class extends Kt{constructor(e,n){super();this.props=e;this.context=n;p(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ne(this.props,"font-size");if(!e.value.isNumeric())return ot.em;let n=e.value;if(!tg(n.unit))throw new Error("Unexpected state");return n.num*ot[n.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?jl(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Xl(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Ti(this.context,e,this.propName).visit(this):e}};function Xl(i,t,e){let n=i.unit,s=i.num;return n==="em"?new k(s*t,"px"):n==="rem"?new k(s*e.fontSize(),"px"):n==="rlh"?new k(s*e.rootLineHeight,"px"):i}function jl(i,t,e){i=Xl(i,t,e);let n=i.unit,s=i.num;return n==="px"?i:n==="%"?new k(s/100*t,"px"):new k(s*e.queryUnitSize(n,!1),"px")}var ss=class{apply(t){}mergeWith(t){return new Jd([this,t])}clone(){return this}},br=class extends ss{constructor(e){super();this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Jd=class i extends ss{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 i([].concat(this.list))}},Co=class extends ss{constructor(e,n,s,o,r){super();this.style=e;this.specificity=n;this.pseudoelement=s;this.regionId=o;this.viewConditionId=r}apply(e){vi(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},le=class extends ss{constructor(){super();p(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},ep=class extends le{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}},tp=class extends le{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}},Bl=class extends le{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}},np=class extends le{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}},sp=class extends le{constructor(e,n,s=!1){super();this.epubTypePatt=e;this.targetLocalName=n;this.useRoleAttr=s}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),o=n.ownerDocument.getElementById(s);if(o&&(!this.targetLocalName||o.localName==this.targetLocalName)){let r=this.useRoleAttr?o.getAttribute("role"):o.getAttributeNS("http://www.idpf.org/2007/ops","type")||o.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},op=class extends le{constructor(e){super();this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Yl(i,t,e,n){if(!i)return!1;if(t!==null)return n(i,t,e);for(let s of i.getAttributeNames())if((s===e||s.endsWith(`:${e}`))&&n(i,s===e?"":i.lookupNamespaceURI(s.split(":")[0]),e))return!0;return!1}var Ol=class extends le{constructor(e,n){super();this.ns=e;this.name=n}apply(e){Yl(e.currentElement,this.ns,this.name,(n,s,o)=>n.hasAttributeNS(s,o))&&this.chained.apply(e)}},rp=class extends le{constructor(e,n,s){super();this.ns=e;this.name=n;this.value=s}apply(e){Yl(e.currentElement,this.ns,this.name,(n,s,o)=>n.getAttributeNS(s,o)==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}},ip=class extends le{constructor(e,n){super();this.ns=e;this.name=n}apply(e){Yl(e.currentElement,this.ns,this.name,(n,s,o)=>!!Yy[n.getAttributeNS(s,o)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},mo=class extends le{constructor(e,n,s){super();this.ns=e;this.name=n;this.regexp=s}apply(e){Yl(e.currentElement,this.ns,this.name,(n,s,o)=>{var r;return!!((r=n.getAttributeNS(s,o))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},ap=class extends le{constructor(e){super();this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Dl=class extends le{constructor(){super()}apply(t){t.isFirst&&this.chained.apply(t)}getPriority(){return 6}},lp=class extends le{constructor(){super()}apply(t){t.isRoot&&this.chained.apply(t)}getPriority(){return 12}},_n=class extends le{constructor(e,n){super();this.a=e;this.b=n}matchANPlusB(e){return jd(e,this.a,this.b)}},cp=class extends _n{constructor(t,e){super(t,e)}apply(t){this.matchANPlusB(t.currentSiblingOrder)&&this.chained.apply(t)}getPriority(){return 5}},yi=class extends _n{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}},xi=class extends _n{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}},Si=class extends _n{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,o=n.localName,r=e[s];r||(r=e[s]={}),r[o]=(r[o]||0)+1}while(n=n.nextElementSibling)}this.matchANPlusB(e[t.currentNamespace][t.currentLocalName])&&this.chained.apply(t)}getPriority(){return 4}},up=class extends le{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}},dp=class extends le{constructor(){super()}apply(t){t.currentElement.disabled===!1&&this.chained.apply(t)}getPriority(){return 5}},pp=class extends le{constructor(){super()}apply(t){t.currentElement.disabled===!0&&this.chained.apply(t)}getPriority(){return 5}},hp=class extends le{constructor(){super()}apply(t){let e=t.currentElement;(e.selected===!0||e.checked===!0)&&this.chained.apply(t)}getPriority(){return 5}},Ze=class extends le{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}},Ml=class i extends ss{constructor(){super();p(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new i;return e.applied=this.applied,e}},Ei=class extends le{constructor(e){super();p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Ml;for(let n of e)this.firstActions.push(Mp(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 le?e.getPriority():0))}positive(){return!0}relational(){return!1}},fp=class extends Ei{positive(){return!1}},gp=class extends Ei{constructor(e){super([]);this.selectorTexts=e}apply(e){for(let n of this.selectorTexts){let s,o;/^\s*[+~]/.test(n)?(o=e.currentElement.parentNode,s=`:scope > :nth-child(${Array.from(o.children).indexOf(e.currentElement)+1}) ${n}`):(o=e.currentElement,s=`:scope ${n}`);try{if(o.querySelector(s)){this.checkAppliedAction.apply(e);break}}catch(r){}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},_l=class extends _n{constructor(e,n,s){super(e,n);p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Ml;for(let o of s)this.firstActions.push(Mp(o,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,o=n.previousElementSibling;for(;o;)this.matchesSelector(o,e)&&s++,o=o.previousElementSibling;this.matchANPlusB(s)&&this.chained.apply(e)}matchesSelector(e,n){let s=n.currentElement,o=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=o,n.currentLocalName=r,n.currentId=a,n.currentClassNames=l,n.currentSiblingOrder=c,h}getPriority(){return 5}},mp=class extends _l{constructor(t,e,n){super(t,e,n)}apply(t){for(let o of this.firstActions)if(o.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}},yr=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)}},Cp=class i extends yr{constructor(t,e,n){super(t,e,n)}fresh(t){return new i(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}},bp=class i extends yr{constructor(t,e,n){super(t,e,n)}fresh(t){return new i(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)}},yp=class i extends yr{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new i(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)}},xp=class i extends yr{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new i(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}},Sp=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}},Ep=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}},vp=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}},Np=class extends Kt{constructor(e){super();this.element=e}createValueFromString(e,n){switch(n){case"url":return e?new Pe(e):new Pe("about:invalid");case"string":default:return e?new z(e):new z("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let n="string",s=null,o=null;if(e.values[0]instanceof X){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?o=this.createValueFromString(e.values[1].stringValue(),n):o=this.createValueFromString(null,n),this.element&&this.element.hasAttribute(s)?this.createValueFromString(this.element.getAttribute(s),n):o}};function Ul(i,t){if(at(i)){if(i instanceof z)return i.stringValue();if(i instanceof D&&t){let e=i.expr.evaluate(t);return typeof e=="string"?e:typeof e=="number"?String(e):""}if(i instanceof X)return i.values.map(e=>Ul(e,t)).join("")}return""}var Vs=class extends Kt{constructor(e,n,s,o){super();this.cascade=e;this.element=n;this.counterResolver=s;this.pseudoName=o}getCounterStore(){var e,n;return(n=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?n:null}getPageScope(){var e,n;return(n=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:n.pageScope}evaluateAndGetString(e){if(!e)return"";let n=this.cascade.quoteDepth,s=e.visit(this),o=Ul(s,this.cascade.context);return this.cascade.quoteDepth=n,o}visitIdent(e){let n=this.cascade,s=n.quotes,o=Math.floor(s.length/2)-1;switch(e.name){case"open-quote":{let r=s[2*Math.min(o,n.quoteDepth)];return n.quoteDepth++,r}case"close-quote":return n.quoteDepth>0&&n.quoteDepth--,s[2*Math.min(o,n.quoteDepth)+1];case"no-open-quote":return n.quoteDepth++,new z("");case"no-close-quote":return n.quoteDepth>0&&n.quoteDepth--,new z("")}return e}format(e,n){return this.cascade.counterStyleStore.format(n,e)}formatCounterList(e,n,s){if(!e.length)return this.format(0,s);let o=new st;for(let r=0;r<e.length;r++)r>0&&o.append(n),o.append(this.format(e[r],s));return o.toString()}formatLastValue(e,n){let s=e.length?e[e.length-1]:0;return this.format(s,n)}buildCounterText(e,n,s,o,r){var f,g,m,C,x,b;let a=typeof r=="string",l=N=>a?this.formatCounterList(N,r,s):this.formatLastValue(N,s),c=N=>{this.pseudoName==="footnote-call"&&this.element&&ex(this.element,n,N)};if(this.pseudoName==="footnote-marker"&&this.element){let S=km(this.element)[n];if(S)return l(S)}let u;if(n==="pages")return l([]);if(!this.element){let N=((f=e.currentPageCounters)==null?void 0:f[n])||[];if(N.length)return u=N,c(u),l(u)}let d=this.element?o:((g=e.currentPageDocCounters)==null?void 0:g[n])||o;if((m=e.isPageControlledCounter)!=null&&m.call(e,n)){let N=((C=e.currentPageDocCounters)==null?void 0:C[n])||[],S=((x=e.currentPageCounters)==null?void 0:x[n])||[],E=S.length?S[S.length-1]:0,v=N.length?N[0]:0,w=d.length?d[0]:0,A=E+(w-v);return u=d.length?[A,...d.slice(1)]:S.length?S:[0],c(u),l(u)}return d.length?(u=d,c(u),l(u)):(u=((b=e.currentPageCounters)==null?void 0:b[n])||[],c(u),l(u))}visitFuncCounter(e){var l;let n=e[0].toString(),s=e.length>1?e[1].stringValue():"decimal",o=(this.cascade.counters[n]||[]).slice(),r=this.getCounterStore();if(r){let c=n==="pages"||((l=r==null?void 0:r.isPageControlledCounter)==null?void 0:l.call(r,n)),u=this.getPageScope(),d=new te(u,()=>this.buildCounterText(r,n,s,o),c?`page-counter-${n}`:`counter-${n}`);if(c&&(r!=null&&r.registerPageCounterExpr)){let h=f=>this.formatLastValue(f,s);r.registerPageCounterExpr(n,h,d)}return new D(d)}let a=this.cascade.counters[n];if(a&&a.length){let c=a&&a.length&&a[a.length-1]||0;return new z(this.format(c,s))}else{let c=new D(this.counterResolver.getPageCounterVal(n,u=>this.format(u||0,s)));return new X([c])}}visitFuncCounters(e){var d;let n=e[0].toString(),s=e[1].stringValue(),o=e.length>2?e[2].stringValue():"decimal",r=(this.cascade.counters[n]||[]).slice(),a=this.getCounterStore();if(a){let h=n==="pages"||((d=a==null?void 0:a.isPageControlledCounter)==null?void 0:d.call(a,n)),f=this.getPageScope(),g=new te(f,()=>this.buildCounterText(a,n,o,r,s),h?`page-counters-${n}`:`counters-${n}`);return h&&(a!=null&&a.registerPageCounterExpr)&&a.registerPageCounterExpr(n,m=>this.formatCounterList(m,s,o),g),new D(g)}let l=this.cascade.counters[n],c=new st;if(l&&l.length)for(let h=0;h<l.length;h++)h>0&&c.append(s),c.append(this.format(l[h],o));let u=new D(this.counterResolver.getPageCountersVal(n,h=>{let f=[];if(h.length)for(let m=0;m<h.length;m++)f.push(this.format(h[m],o));let g=c.toString();return g.length&&f.push(g),f.length?f.join(s):this.format(0,o)}));return new X([u])}visitFuncTargetCounter(e){let n=e[0],s;n instanceof Pe?s=n.url:s=n.stringValue();let o=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",a=new D(this.counterResolver.getTargetCounterVal(s,o,l=>this.format(l||0,r)));return new X([a])}visitFuncTargetCounters(e){let n=e[0],s;n instanceof Pe?s=n.url:s=n.stringValue();let o=e[1].toString(),r=e[2].stringValue(),a=e.length>3?e[3].stringValue():"decimal",l=new D(this.counterResolver.getTargetCountersVal(s,o,c=>{let u=c.map(d=>this.format(d,a));return u.length?u.join(r):this.format(0,a)}));return new X([l])}visitFuncTargetText(e){let n=e[0],s;n instanceof Pe?s=n.url:s=n.stringValue();let o=e.length>1?e[1].stringValue():"content",r=new D(this.counterResolver.getTargetTextVal(s,o));return new X([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 o,r,a,l,c,u,d,h;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 f=(o=this.element)==null?void 0:o.querySelectorAll(`[data-adapt-pseudo="${n}"]`),g=null;if(f&&this.element)for(let m=0;m<f.length;m++){let C=f[m];if(C.parentElement===this.element){g=C;break}}if(g)s=g.textContent||"";else{let m=lt(this.cascade.currentStyle,"_pseudos"),C=(a=(r=m==null?void 0:m[n])==null?void 0:r.content)==null?void 0:a.value;if(C)s=this.evaluateAndGetString(C);else if(n==="marker"){let x=(l=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:l.value;s=Ul(x,this.cascade.context)}}}break;case"first-letter":{let f=lt(this.cascade.currentStyle,"_pseudos"),g=(u=(c=f==null?void 0:f.before)==null?void 0:c.content)==null?void 0:u.value,m=(h=(d=f==null?void 0:f.after)==null?void 0:d.content)==null?void 0:h.value,C=(this.evaluateAndGetString(g)||this.element.textContent||this.evaluateAndGetString(m)).match(js);s=C?C[0]:""}break}return new z(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 z&&(n=e[0].stringValue());return n.length==0?new z(""):new D(new te(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 qd(i,t,e){let n;if(i.nodeType===1)n=Array.from(i.getClientRects());else{let o=i.ownerDocument.createRange();o.selectNodeContents(i),n=t.getRangeClientRects(o)}return n.reduce((o,r)=>o+(e==="vertical-rl"||e==="vertical-lr"?r.height:r.width),0)}var nx=(i,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 x=function(U){m==="rtl"?u.textContent=(U.startsWith("\u200F")?"":"\u200F")+U+(U.endsWith("\u200F")?"":"\u200F"):u.textContent=U},Y=function(){let U=e.clientLayout.getElementClientRect(d);return g==="vertical-rl"||g==="vertical-lr"?m==="rtl"?U.top-=_:U.bottom+=_:m==="rtl"?U.left-=_:U.right+=_,S.left>U.left||S.right<U.right||S.top>U.top||S.bottom<U.bottom},Q=function(){let U,j,H=f.repeat(1e4);if(x(H),Y())U=1,j=1e4;else return;for(let M=0;M<16;M++){let q="",xe=Math.floor((U+j)/2);for(let Me=0;Me<xe;Me++)q+=f;if(x(q),Y())j=xe;else{if(U==xe)return;U=xe}}x(f)},De=function(U){let j=0,H=d.parentElement;for(;H&&H!==c.viewNode;)j+=e.getComputedInsets(H)[U],H=H.parentElement;return j};var s=x,o=Y,r=Q,a=De;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:C}=e.clientLayout.getElementComputedStyle(d);u.style.marginInlineStart="1px",x(f),d.style.display="inline-block",d.style.textIndent="0";let b=fr(c.viewNode),N=(b==null?void 0:b.style.columnFill)||null;b&&(b.style.columnFill="auto");let S=e.clientLayout.getElementClientRect(c.viewNode),E=e.clientLayout.getElementClientRect(d),v=e.parseComputedLength(C),w=[],A=d.parentElement;for(;A.parentElement&&A.parentElement!==c.viewNode;)A=A.parentElement;let I=A.nextSibling;for(;I;){if(I.nodeType===1){let U=I,{display:j,float:H,position:M}=e.clientLayout.getElementComputedStyle(U);if(H!=="none"||M==="absolute"||M==="fixed"){I=I.nextSibling;continue}if(Et(j))w.push(U);else if(um(j))break}else if(I.nodeType===3){let U=I;U.length>0&&w.push(U)}I=I.nextSibling}let _=w.reduce((U,j)=>U+qd(j,e.clientLayout,g),0);if(h!=="after"){let U=qd(A,e.clientLayout,g),j=qd(d,e.clientLayout,g);_+=U-j}g==="vertical-rl"||g==="vertical-lr"?(m==="rtl"?S.top+=v:S.bottom-=v,S.top=Math.min(E.top,S.top),S.bottom=Math.max(E.bottom,S.bottom)):(m==="rtl"?S.left+=v:S.right-=v,S.left=Math.min(E.left,S.left),S.right=Math.max(E.right,S.right)),Q();let me=e.clientLayout.getElementClientRect(d);m=="rtl"?d.style.float="left":d.style.float="right";let Te=e.clientLayout.getElementClientRect(d),F=0;m=="rtl"?g=="vertical-rl"||g=="vertical-lr"?F=me.top-Te.top-De("top"):F=me.left-Te.left-De("left"):g=="vertical-rl"||g=="vertical-lr"?F=Te.bottom-me.bottom-De("bottom"):F=Te.right-me.right-De("right"),F-=_,F=Math.max(0,F-.1),d.style.float="",u.style.marginInlineStart=`${F}px`,b&&(N?b.style.columnFill=N:b.style.removeProperty("column-fill"))}};je("POST_LAYOUT_BLOCK",nx);var _p=1/1048576;function Cr(i,t){for(let e in i)t[e]=i[e].clone()}var Tp=class i{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 i;t.nsCount=this.nsCount;for(let e in this.nsPrefix)t.nsPrefix[e]=this.nsPrefix[e];return Cr(this.tags,t.tags),Cr(this.nstags,t.nstags),Cr(this.epubtypes,t.epubtypes),Cr(this.classes,t.classes),Cr(this.ids,t.ids),Cr(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,o,r){return new wp(this,t,e,n,s,o,r)}nextOrder(){return this.order+=_p}},$l=class $l{constructor(t,e,n,s,o,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",Object.create(null));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,"pageTypePageIndices",Object.create(null));p(this,"isFirst",!0);p(this,"isRoot",!0);p(this,"counters",Object.create(null));p(this,"lastCounterChanges",[]);p(this,"lastCounterChangeTypes",Object.create(null));p(this,"counterScoping",[Object.create(null)]);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",Object.create(null));p(this,"dependentConditions",[]);p(this,"elementStack");this.code=t,this.quotes=[new z("\u201C"),new z("\u201D"),new z("\u2018"),new z("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,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=go.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(s=>{let o=this.viewConditions[s];return o&&o.length>0?o.length===1?o[0]:go.buildAnyMatcher([].concat(o)):null}).filter(s=>s);return n.length<=0?e:e===null?n.length===1?n[0]:go.buildAllMatcher(n):go.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=Kd,this.currentPageType=e,this.applyActions()}defineCounter(t,e){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(e)):this.counters[t]=[e],n[t]=!0}pushCounters(t){var g,m,C,x,b,N,S;let e=new Set,n=Object.create(null),s=y.inline,o=t.display;if(o&&(s=o.evaluate(this.context)),s===y.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let r=y.inline,a=t.float;a&&(r=a.evaluate(this.context));let l=null,c=null,u=null,d=t["counter-reset"];if(d){let E=d.evaluate(this.context);E&&(l=ys(E,{reset:!0}))}let h=t["counter-set"];if(h){let E=h.evaluate(this.context);E&&(u=ys(E,{defaultValue:0}))}let f=t["counter-increment"];if(f){let E=f.evaluate(this.context);E&&(c=ys(E))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(l||(l=Object.create(null)),l["list-item"]=((m=(g=this.currentElement)==null?void 0:g.start)!=null?m:1)-1),uo(s)&&(c||(c=Object.create(null)),c["list-item"]=(C=c["list-item"])!=null?C:1,/^\s*[-+]?\d/.test((b=(x=this.currentElement)==null?void 0:x.getAttribute("value"))!=null?b:"")&&(u||(u=Object.create(null)),u["list-item"]=this.currentElement.value)),((N=this.currentElement)==null?void 0:N.parentNode.nodeType)===Node.DOCUMENT_NODE&&(l||(l=Object.create(null)),l.footnote===void 0&&(l.footnote=0)),r===y.footnote&&(c||(c=Object.create(null)),c.footnote===void 0)){let E=(S=this.currentStyle["counter-increment"])==null?void 0:S.value;(!E||!(E===y.footnote||E instanceof X&&E.values.includes(y.footnote)))&&(c.footnote=1)}if(l)for(let E in l)e.add(E),n[E]="reset";if(c)for(let E in c)e.add(E),n[E]||(n[E]="increment");if(u)for(let E in u)e.add(E),n[E]="set";if(this.lastCounterChanges=Array.from(e),this.lastCounterChangeTypes=n,l)for(let E in l)this.defineCounter(E,l[E]);if(c)for(let E in c){this.counters[E]||this.defineCounter(E,0);let v=this.counters[E];v[v.length-1]+=c[E]}if(u)for(let E in u)if(!this.counters[E])this.defineCounter(E,u[E]);else{let v=this.counters[E];v[v.length-1]=u[E]}if(uo(s)){let E=this.counters["list-item"],v=E[E.length-1];t["ua-list-item-count"]=new V(new Ue(v),0);let w=yn(t,"_pseudos");w.marker||(w.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 Vs(this,this.currentElement,this.counterResolver));let n=e.value instanceof Se?e.value.values:[e.value];for(let s of n)if(s instanceof X){let o=s.values[0].stringValue(),r=s.values.slice(1).map(a=>Ul(a,this.context)).join("");this.counterResolver.setNamedString(o,r,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let e=t.position;if((e==null?void 0:e.value)instanceof Ft&&e.value.name==="running"){let n=e.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,e,n){this.pushCounters(t);let s=t.content;s&&(t.content=s.filterValue(new Vs(this,e,this.counterResolver,n))),this.popCounters()}pushElement(t,e,n,s){var E,v,w;this.currentPageType=null,this.currentElement=e,this.currentElementOffset=s,this.currentStyle=n,this.currentNamespace=e.namespaceURI,this.currentLocalName=e.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+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=Kd;let a=e.getAttributeNS("http://www.idpf.org/2007/ops","type");a?this.currentEpubTypes=a.split(/\s+/):this.currentEpubTypes=Kd;let l=Ur(e);l&&(this.stack[this.stack.length-1].push(new Ep(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,C=this.currentFollowingSiblingTypeCounts=m[m.length-1];C&&C[this.currentNamespace]&&C[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 x=n.quotes,b=null;if(x){let A=x.evaluate(this.context);A&&(b=new vp(this.quotes),A===y.none?this.quotes=[new z(""),new z("")]:A===y.auto||A===y.initial?this.quotes=[new z("\u201C"),new z("\u201D"),new z("\u2018"),new z("\u2019")]:A instanceof X&&(this.quotes=A.values))}this.pushCounters(this.currentStyle);let N=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(c||N){let A=Object.create(null);Object.keys(this.counters).forEach(I=>{A[I]=Array.from(this.counters[I])}),this.counterListener.countersOfId(N,A)}let S=lt(this.currentStyle,"_pseudos");if(S){let A=!0;for(let I of sx){I||(A=!1);let _=S[I];if(_)if((I==="before"||I==="after")&&!(at((E=_.content)==null?void 0:E.value)||this.hasNonTrivialViewConditionalPseudoContent(_))||I==="marker"&&!uo((v=ne(this.currentStyle,"display"))==null?void 0:v.value)||(I==="footnote-call"||I==="footnote-marker")&&((w=ne(this.currentStyle,"float"))==null?void 0:w.value)!==y.footnote)delete S[I];else if(A){if(this.processPseudoelementProps(_,e,I),I==="marker")this.processMarkerPseudoelementProps(_,e,t),delete S[I];else if(I==="footnote-marker")this.resolvePseudoelementInheritedPropertyValue(_,"list-style-position",t,e)===y.outside&&(this.processMarkerPseudoelementProps(_,e,t),this.currentStyle.display=new V(R("list-item"),0),this.currentStyle["list-style-position"]=new V(y.outside,0),this.currentStyle["list-style-type"]=new V(y.none,0),this.currentStyle["list-style-image"]=new V(y.none,0),delete S[I]);else if(I==="first-letter"&&_["initial-letter"]){let Q=_["initial-letter"].evaluate(this.context);Q!==y.normal&&!W(Q)&&(this.currentStyle["--viv-initialLetter"]=new V(Q,0)),delete _["initial-letter"]}}else this.stack[this.stack.length-2].push(new Sp(_,e))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),b&&this.stack[this.stack.length-2].push(b)}hasNonTrivialViewConditionalPseudoContent(t){let e=t._viewConditionalStyles;return!e||e.length<=0?!1:e.some(n=>{var s;return at((s=n.styles.content)==null?void 0:s.value)})}processMarkerPseudoelementProps(t,e,n){var r,a,l,c,u;let s=uo((r=this.currentStyle.display)==null?void 0:r.value);if(!at((a=t.content)==null?void 0:a.value)&&s){let d=this.getInheritedPropertyValue("list-style-type",n,e),h=this.getInheritedPropertyValue("list-style-image",n,e);if(h instanceof Pe)t.content=new V(new X([h,new z(" ")]),0);else if(d instanceof z)t.content=new V(d,0);else if(d instanceof J&&d!==y.none){let f=(c=(l=this.currentStyle["ua-list-item-count"])==null?void 0:l.value)==null?void 0:c.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new z(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let o=t.content;if(o){let d=o.value;if(at(d)){let h=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new V(h,0)}}for(let d of $l.markerAllowedProps){let h=t[d];if(h){let f=h.evaluate(this.context,d);f&&!W(f)&&(this.currentStyle[`--viv-marker-${d}`]=new V(f,0))}}if(!Et((u=ne(this.currentStyle,"display"))==null?void 0:u.value)){let d=this.getInheritedPropertyValue("list-style-position",n,e);d&&d!==y.outside&&!W(d)&&(this.currentStyle["list-style-position"]=new V(d,0))}}resolveMarkerContentVal(t){if(t instanceof D){let e=t.expr.evaluate(this.context);return typeof e=="string"?new z(e):typeof e=="number"?new z(String(e)):t}if(t instanceof X){let e=t.values.map(n=>this.resolveMarkerContentVal(n));return new X(e)}return t}getInheritedPropertyValue(t,e,n){var o;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===y.inherit||c===y.unset||c===y.revert)continue;if(c===y.initial)break;return c}}let s=e.validatorSet;return(o=s==null?void 0:s.defaultValues[t])!=null?o:null}resolvePseudoelementInheritedPropertyValue(t,e,n,s){var r;let o=t[e];if(o){let a=o.evaluate(this.context,e);if(a!==y.inherit&&a!==y.unset&&a!==y.revert){if(a===y.initial){let l=n.validatorSet;return(r=l==null?void 0:l.defaultValues[e])!=null?r:null}return a}}return this.getInheritedPropertyValue(e,n,s)}applyAttrFilterInner(t,e){for(let n in e)Fs(n)&&!Vt(n)&&(e[n]=e[n].filterValue(t))}applyAttrFilter(t){let e=new Np(t),n=this.currentStyle,s=lt(n,"_pseudos");for(let o in s)this.applyAttrFilterInner(e,s[o]);this.applyAttrFilterInner(e,n)}applyVarFilter(t,e,n){var l,c,u;let s=t[0],o=new Fp(t,e,n),r=32,a={};for(let d in s)if(Fl(d)){let h=lt(s,d);for(let f in h)this.applyVarFilter([h[f],...t],e,n)}else if(Fs(d)){let h=ne(s,d),f=h.value;for(let g=0;;g++){if(g>=r){f=G;break}let m=f.visit(o);if(o.error){f=G,o.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(W(f)){for(let C of m.propList){let x=new V(f,h.priority),b=ne(s,C);Mn(a,C,Qd(this.context,b,x))}delete s[d]}else{let C=Ss(e.scope,new it(f.toString(),null),"");if(C&&(C.visit(m),!m.error)){for(let x of m.propList){let b=new V((u=(c=m.values[x])!=null?c:g.defaultValues[x])!=null?u:y.initial,h.priority),N=ne(s,x);Mn(a,x,Qd(this.context,N,b))}delete s[d]}}else s[d]=new V(f,h.priority)}if(a[d]){let g=ne(s,d);g&&g.value!==G&&Jt(a,d,g,this.context)}}for(let d in a)s[d]=a[d]}applyCalcFilter(t,e){let n=new Wl(e);for(let s in t)if(Fl(s)){let o=lt(t,s);for(let r in o)this.applyCalcFilter(o[r],e)}else if(Fs(s)&&!Vt(s)){let o=ne(t,s),r=o.value.visit(n);r!==o.value&&(t[s]=new V(r,o.priority))}}applyCmykFilter(t,e){let n=new Xo(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(Fl(s)){let o=lt(t,s);for(let r in o)this.applyCmykFilterInternal(o[r],e,`::${r}:`)}else if(Fs(s)&&!Vt(s)){let o=ne(t,s),r=o.value.toString();e.reset();let a=o.value.visit(e);a!==o.value&&(e.hadDeviceCmyk()&&e.recordConversion(n+s,r),t[s]=new V(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let 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()}};p($l,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var wp=$l,Kd=[],sx=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"];var Pp=null;function Im(i){Pp=i}var os=class extends fn{constructor(e,n,s,o,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=o?o.cascade:Pp?Pp.clone():new Tp,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let n=Mp(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 np(e,n.toLowerCase())):n?this.chain.push(new Bl(n.toLowerCase())):this.chain.push(new op(e)))}invalidSelector(e){O.warn(e),this.chain.push(new Ze("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Bs;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 ep(e))}pseudoclassSelector(e,n){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new dp);break;case"disabled":this.chain.push(new pp);break;case"checked":this.chain.push(new hp);break;case"root":case"scope":this.chain.push(new lp);break;case"link":this.chain.push(new Bl("a")),this.chain.push(new Ol("","href"));break;case"href-epub-type":case"href-role-type":if(n&&n.length>=1&&typeof n[0]=="string"){let s=n[0],o=new RegExp(`(^|\\s)${$n(s)}($|\\s)`),r=n[1];this.chain.push(new sp(o,r,e==="href-role-type"))}else this.chain.push(new Ze(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ze(""));break;case"lang":if(n&&n.length==1&&typeof n[0]=="string"){let s=n[0];this.chain.push(new ap(new RegExp(`^${$n(s.toLowerCase())}($|-)`)))}else this.chain.push(new Ze(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let s=ox[e.toLowerCase()];n&&n.length==2?this.chain.push(new s(n[0],n[1])):this.chain.push(new Ze(""));break}case"first-child":this.chain.push(new Dl);break;case"last-child":this.chain.push(new xi(0,1));break;case"first-of-type":this.chain.push(new yi(0,1));break;case"last-of-type":this.chain.push(new Si(0,1));break;case"only-child":this.chain.push(new Dl),this.chain.push(new xi(0,1));break;case"only-of-type":this.chain.push(new yi(0,1)),this.chain.push(new Si(0,1));break;case"empty":this.chain.push(new up);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 Ze(""));break;case"nth-fragment":n&&n.length==2?this.viewConditionId=`NFS_${n[0]}_${n[1]}`:this.chain.push(new Ze(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new tp(e))}attributeSelector(e,n,s,o){this.specificity+=256,n=n.toLowerCase(),o=o||"";let r;switch(s){case 0:r=new Ol(e,n);break;case 39:r=new rp(e,n,o);break;case 45:!o||o.match(/\s/)?r=new Ze(""):r=new mo(e,n,new RegExp(`(^|\\s)${$n(o)}($|\\s)`));break;case 44:r=new mo(e,n,new RegExp(`^${$n(o)}($|-)`));break;case 43:o?r=new mo(e,n,new RegExp(`^${$n(o)}`)):r=new Ze("");break;case 42:o?r=new mo(e,n,new RegExp(`${$n(o)}$`)):r=new Ze("");break;case 46:o?r=new mo(e,n,new RegExp($n(o))):r=new Ze("");break;case 50:if(o=="supported")r=new ip(e,n);else{this.invalidSelector(`Unsupported :: attr selector op: ${o}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${s}`);return}this.chain.push(r)}descendantSelector(){let e=`d${Il++}`;this.processChain(new br(new Cp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}childSelector(){let e=`c${Il++}`;this.processChain(new br(new bp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Il++}`;this.processChain(new br(new yp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Il++}`;this.processChain(new br(new xp(e,this.viewConditionId,null))),this.chain=[new Ze(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 Co(this.elementStyle,e,this.pseudoelement,n,this.viewConditionId)}special(e,n){let s;this.condition?s=new bi(n,0,this.condition):s=new V(n,0),Rm(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===y.oeb_page_head||n===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new X([y.exclusive,y._static]),s),this.simpleProperty("flow-into",n,s),n=y.block),Je("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 bi(n,a,this.condition):new V(n,a);Jt(this.elementStyle,e,l)}finish(){return this.cascade}startFuncWithSelector(e,n){let s;switch(e){case"is":s=new Bs(this);break;case"not":s=new kp(this);break;case"where":s=new Ap(this);break;case"has":s=new Rp(this);break;case"nth-child":n&&n.length>=2&&(s=new Hl(this,n[0],n[1]));break;case"nth-last-child":n&&n.length>=2&&(s=new Lp(this,n[0],n[1]));break}s&&(s.startSelectorRule(),this.owner.pushHandler(s))}},ox={"nth-child":cp,"nth-of-type":yi,"nth-last-child":xi,"nth-last-of-type":Si},Il=0,Bs=class i extends os{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 gp(this.selectorTexts):this.positive()?new Ei(this.chains):new fp(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ze("")),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 o=this;o instanceof i;o=o.parent)if(o.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}},kp=class extends Bs{positive(){return!1}forgiving(){return!1}},Ap=class extends Bs{increasingSpecificity(){return!1}},Rp=class extends Bs{relational(){return!0}},Hl=class extends Bs{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 _l(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ze("")),this.owner.popHandler()}forgiving(){return!0}},Lp=class extends Hl{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new mp(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ze("")),this.owner.popHandler()}},zl=class extends fn{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",o=new an(this.scope,100,s);this.scope.defineName(t,e.toExpr(this.scope,o))}}},bo=class extends fn{constructor(e,n,s,o,r,a){super(e,n,!1);this.condition=s;this.elementStyle=o;this.validatorSet=r;this.ruleType=a;p(this,"order");this.order=0}property(e,n,s){s?O.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){O.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){O.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?this.getImportantSpecificity():this.getBaseSpecificity();o+=this.order,this.order+=_p;let r=this.condition?new bi(n,o,this.condition):new V(n,o);Jt(this.elementStyle,e,r)}},Ip=class extends ii{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){O.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){O.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?al:il;o+=this.order,this.order+=_p;let r=new V(n,o);Jt(this.elementStyle,e,r)}};function Up(i,t){let e=Am(i);e&&e.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Gl(i,t,e){Up(e,n=>{Sr(i,n,t)})}function Fm(i,t,e,n){let s=new Ip(i,t),o=new it(n,s);try{Fg(o,s,e)}catch(r){O.warn(r,"Style attribute parse error:")}return s.elementStyle}function ql(i,t,e){let n=i["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.vertical_rl}return e}function Kl(i,t,e){let n=i.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.rtl}return e}function Ni(i,t,e,n,s){let o={};for(let r in i)Fs(r)&&(o[r]=ne(i,r));return Gl(o,t,i),Hp(i,e,n,(r,a)=>{Sr(o,a,t),Gl(o,t,a)}),o}function Hp(i,t,e,n){let s=lt(i,"_regions");if((t||e)&&s){if(e){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let r=s[o];r&&n(o,r)}}}function Sr(i,t,e){for(let n in t)if(Fs(n)){let s=ne(t,n),o=i[n];i[n]=Qd(e,o,s)}}var Zl=(i,t,e,n,s,o)=>{var l,c;let r=e?n?Ky:Bp:n?Zy:Op,a=s?Qy:Jy;for(let u in i){let d=i[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 C=i[g];if(C&&C.priority>d.priority||h&&f&&h!==f&&(g=f,C=i[g],C&&C.priority>d.priority))continue;m=Nm[h]?h:Nm[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===y.inside||d.value===y.outside)&&(d=new V(s===(d.value===y.inside)?y.right:y.left,d.priority));t[m]=o(u,d)}},Fp=class extends Kt{constructor(e,n,s){super();this.elementStyles=e;this.styler=n;this.element=s}getVarValue(e){var s,o,r,a,l;let n=(s=this.element)!=null?s:this.styler.root;if((o=this.elementStyles)!=null&&o.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 J&&e.values[0].name;if(!n||!Vt(n))return this.error=!0,G;let s=this.getVarValue(n);return s||(e.values.length<2?(this.error=!0,G):e.values.length===2?e.values[1]:new Se(e.values.slice(1)))}},Wl=class extends Kt{constructor(e,n,s,o){super();this.context=e;this.resolveViewportUnit=n;this.percentRef=s;this.vertical=o}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 o=Ss(this.context.rootScope,new it(s,null),"");if(o instanceof D)try{let r=o.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 k(r,"px"):/\d[a-z]/i.test(s)||(n=new Ue(r)))}catch(r){O.warn(r)}return n}visitNumeric(e){return this.resolveViewportUnit&&Ru(e.unit)||this.context.rootFontSize!=null&&sg(e.unit)?new k(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new k(e.num*this.percentRef/100,"px"):e}};function Ti(i,t,e,n,s){try{if(t instanceof D)return t.expr instanceof te&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Vg(i,t.expr,e);if(t instanceof k||t instanceof Ft||t instanceof X||t instanceof Se)return t.visit(new Wl(i,!0,n,s))}catch(o){return O.warn(o),G}return t}var Vm={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Bm(i){let t=i instanceof _e?i:typeof i=="string"?R(i):y.none;if(t===y.none)return Vm;let e=t instanceof X?t.values:[t],n=Object.create(Vm);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 Om(i){return!i.first&&!i.last&&!i.forceEnd&&!i.allowEnd}var rx={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Dm={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Mm={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function _m(i){let t=i instanceof _e?i:typeof i=="string"?R(i):y.normal;if(t===y.normal)return Dm;if(t===y.auto)return Mm;let e=t instanceof X?t.values:[t],n=Object.create(Dm);for(let s of e)if(s instanceof J)switch(s.name){case"trim-both":case"trim-auto":return Mm;case"space-all":return rx;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 zp={ideographAlpha:!1,ideographNumeric:!1},ix={ideographAlpha:!0,ideographNumeric:!0};function Um(i){let t=i instanceof _e?i:typeof i=="string"?R(i):y.normal;if(t===y.normal||t===y.auto)return ix;if(t===y.none)return zp;let e=t instanceof X?t.values:[t],n=Object.create(zp);for(let s of e)if(s instanceof J)switch(s.name){case"no-autospace":return zp;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Hm(i,t){return!i.ideographAlpha&&!i.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function zm(i){return i?(i=i.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(i)?"zh-hant":/^zh\b/.test(i)?"zh-hans":/^ja\b/.test(i)?"ja":/^ko\b/.test(i)?"ko":i):null}var Gp=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 o=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(o.length>1){let r=o.length-1;for(let a=0;a<r;a++)s.parentNode.insertBefore(document.createTextNode(o[a]),s);s.textContent=o[r]}}}processGeneratedContent(t,e,n,s,o,r){o=zm(o);let a=Um(e),l=_m(n),c=Bm(s);if(Om(c)&&Hm(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,C=!h||/\n$/.test(h.textContent),x=!f||/^\n/.test(f.textContent),b=!f;this.processTextSpacing(g,m||C,m,C,x,b,h,f,a,l,c,o,r),h=g}t.style.whiteSpace=u}postLayoutBlock(t,e){var d,h,f,g,m,C,x,b;let n=!t||t.fragmentIndex===1&&r(),s=n||a();function o(N){var w;if((N==null?void 0:N.nodeType)!==1)return!1;let S=N;if(S.hasAttribute(Vn))return!0;let{position:E,float:v}=(w=S.style)!=null?w:{};return E==="absolute"||E==="fixed"||v&&v!=="none"}function r(){let N=e[0];for(let S=N;;S=S.parent)if(!S||!S.inline){if((S==null?void 0:S.fragmentIndex)!==1)return!1;break}if(!N.inline)return!0;for(let S=N.viewNode.previousSibling;S;S=S.previousSibling)if(!ce(S,N.whitespace)&&!o(S))return!1;return!0}function a(){var E,v;let N=e[0],S;for(;N&&N.inline&&(S=(E=N.viewNode)==null?void 0:E.previousSibling,!(S&&(S.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(S.textContent)&&N.whitespace!==ft.PRESERVE&&(S=S.previousSibling),S)));)N=N.parent;for(;S;){if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let w=(v=S.style)==null?void 0:v.display;if(w&&w!=="inline")return!/^(inline|ruby)\b/.test(w)}else if(S.nodeType===Node.TEXT_NODE){if(N.whitespace===ft.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(N.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}S=S.lastChild}return!1}let l=-1;for(let N=0;N<e.length;N++){let S=e[N];if(!S.after&&S.inline&&!S.display&&S.parent&&S.viewNode.parentNode&&S.viewNode.nodeType===Node.TEXT_NODE&&!ce(S.viewNode,S.whitespace)){let F=function(H){var M,q,xe;if(((M=H.viewNode)==null?void 0:M.nodeType)===Node.ELEMENT_NODE)return H.viewNode.localName==="br";if(((q=H.viewNode)==null?void 0:q.nodeType)===Node.TEXT_NODE){let Me=H.viewNode;if(H.whitespace===ft.PRESERVE){if(/\n$/.test(Me.textContent))return!0}else if(H.whitespace===ft.NEWLINE&&/\n[ \t\r\n\f]*$/.test(Me.textContent))return!0;if(((xe=Me.previousElementSibling)==null?void 0:xe.localName)==="br")return ce(Me,H.whitespace)}return!1},U=function(H){var M,q,xe;if(((M=H.viewNode)==null?void 0:M.nodeType)===Node.ELEMENT_NODE)return H.viewNode.localName==="br";if(((q=H.viewNode)==null?void 0:q.nodeType)===Node.TEXT_NODE){let Me=H.viewNode;if(H.whitespace===ft.PRESERVE){if(/^\n/.test(Me.textContent))return!0}else if(H.whitespace===ft.NEWLINE&&/^[ \t\r\n\f]*\n/.test(Me.textContent))return!0;if(((xe=Me.nextElementSibling)==null?void 0:xe.localName)==="br")return ce(Me,H.whitespace)}return!1};var c=F,u=U;l<0&&(l=N);let E=zm((g=(h=(d=S.lang)!=null?d:S.parent.lang)!=null?h:t==null?void 0:t.lang)!=null?g:(f=t==null?void 0:t.parent)==null?void 0:f.lang),v=Um(S.inheritedProps["text-autospace"]),w=_m(S.inheritedProps["text-spacing-trim"]),A=Bm(S.inheritedProps["hanging-punctuation"]);if(Om(A)&&Hm(v,w)||/\b(flex|grid)\b/.test(S.parent.display))continue;let I=null,_=null,Y=N===l,Q=N===l&&n,me=N===l&&s,Te=!1,De=!1;for(let H=N-1;H>=0;H--){let M=e[H];if(F(M)){me=!0;break}if(!M.display&&M.viewNode.nodeType===Node.TEXT_NODE&&M.viewNode.textContent.length>0){I=M.viewNode;break}if(((m=M.viewNode)==null?void 0:m.nodeType)===Node.ELEMENT_NODE&&en(M.viewNode)==="footnote-call"){if(M.viewNode.contains(S.viewNode))continue;let q=ym(M.viewNode);if(q){I=q;break}}if(M.display&&!/^(inline|ruby)\b/.test(M.display)||((C=M.viewNode)==null?void 0:C.nodeType)===Node.ELEMENT_NODE&&(M.viewNode.localName==="br"||Tn[M.viewNode.localName]))break;H===0&&(Y=!0,n&&(Q=!0,me=!0))}for(let H=N+1;H<e.length;H++){let M=e[H];if(U(M)){Te=!0;break}if(M.viewNode!==S.viewNode&&!M.display&&M.viewNode.nodeType===Node.TEXT_NODE&&M.viewNode.textContent.length>0){_=M.viewNode;break}if(M.display&&!/^(inline|ruby)\b/.test(M.display)||((x=M.viewNode)==null?void 0:x.nodeType)===Node.ELEMENT_NODE&&(M.viewNode.localName==="br"||Tn[M.viewNode.localName])){H===e.length-1&&o(M.viewNode)&&(De=!0);break}if(H===e.length-1){Te=!0,De=!0;for(let q=M.viewNode.nextSibling;q;q=q.nextSibling)if(!o(q)){De=!1;break}}}if(((b=S.parent)==null?void 0:b.display)==="inline-block"){if(!Q){let H=S.parent.viewNode.firstChild;for(;ce(H,S.whitespace);)H=H.nextSibling;S.viewNode===H&&(Q=!0)}if(!De){let H=S.parent.viewNode.lastChild;for(;ce(H,S.whitespace);)H=H.previousSibling;S.viewNode===H&&(De=!0)}}if(this.processTextSpacing(S.viewNode,Y,Q,me,Te,De,I,_,v,w,A,E,S.vertical)>0)break}}}processTextSpacing(t,e,n,s,o,r,a,l,c,u,d,h,f){let g=t.textContent,m=t.ownerDocument,C=0,x,b,N;function S(){if(e)return!0;if(!a)return!1;x||(x=m.createRange(),x.selectNode(t));let F=x.getClientRects()[0];if(!F)return!1;b||(b=m.createRange(),b.selectNode(a));let U=b.getClientRects(),j=U[U.length-1];return j?(C||(C=po(j,f)),f?F.top<j.top+j.height-F.width||F.left+F.width<j.left+F.width/10||F.left>j.left+j.width-F.width/10:F.left<j.left+j.width-F.height||F.top>j.top+j.height-F.height/10||F.top+F.height<j.top+F.height/10):!1}function E(){if(!l)return!1;x||(x=m.createRange(),x.selectNode(t));let F=x.getClientRects()[0];if(!F)return!1;C||(C=po(F,f)),N||(N=m.createRange(),N.selectNode(l));let U=N.getClientRects()[0];return U?f?F.top+F.height>U.top+F.width||F.left>U.left+U.width-F.width/10||F.left+F.width<U.left+F.width/10:F.left+F.width>U.left+F.height||F.top+F.height<U.top+F.height/10||F.top>U.top+U.height-F.height/10:!1}let v=!1,w=!1,A=!1,I=!1,_;if(n&&d.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(g)?(_="viv-ts-open",v=!0,w=!0):r&&d.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(g)?(_="viv-ts-close",v=!0,A=!0):(d.forceEnd||d.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(g)?(_="viv-ts-close",v=!0,I=!0):(u.trimStart||u.spaceFirst||u.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(g)?(_="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))&&(_="viv-ts-close",v=!0),v){let j=function(q){let Me=parseFloat(m.defaultView.getComputedStyle(q).fontSize)*.7;return(f?q.offsetHeight:q.offsetWidth)>Me},M=function(){return f?F.offsetLeft:F.offsetTop};var Te=j,De=M;if(t.parentElement.localName==="viv-ts-inner")return 0;let F=m.createElement(_),U=m.createElement("viv-ts-inner");F.appendChild(U),t.parentNode.insertBefore(F,t),U.appendChild(t);let H=j(U);if(H||w||A||I){if(_==="viv-ts-open"){if(w)F.className="viv-hang-first";else if(n||s)u.trimStart?F.className="viv-ts-trim":F.className="viv-ts-space";else if(!(u.trimStart||u.spaceFirst)&&S())F.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"&&j(a.parentElement)))F.className="viv-ts-trim";else if((u.trimStart||u.spaceFirst)&&S()){let q=M();F.className="viv-ts-auto",q===M()&&!S()&&(F.className="viv-ts-trim")}}else if(_==="viv-ts-close"){if(A)F.className=H?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||o){let q=M();I?(F.className=H?d.allowEnd&&u.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",d.allowEnd&&q===M()&&(u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-hang-end",q===M()&&(F.className="")):F.className="viv-ts-space")):u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-ts-auto",q===M()&&(F.className="")):F.className="viv-ts-space"}else if(l&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(l.textContent))H&&u.trimAdjacent&&(F.className="viv-ts-trim");else if(I){let q=E(),xe=q&&d.allowEnd;xe||(F.className=H?"viv-hang-end":"viv-hang-end viv-hang-hw"),H?xe&&u.trimEnd?F.className="viv-ts-auto":!xe&&!E()?F.className="":!q&&d.allowEnd&&(u.trimEnd?(F.className="viv-ts-auto",E()||(F.className="viv-hang-end")):(F.className="viv-ts-space",E()||(u.allowEnd?(F.className="viv-ts-auto",E()||(F.className="viv-hang-end")):F.className="viv-hang-end"))):!q&&!E()&&(F.className="")}else if(u.trimEnd||u.allowEnd)if(E())u.allowEnd?F.className="viv-ts-space":F.className="viv-ts-auto";else{let q=M();F.className="viv-ts-auto",q===M()&&(F.className="")}}}}let Y=!1;function Q(F){var j;let U=(j=F==null?void 0:F.ownerDocument.defaultView)==null?void 0:j.getComputedStyle(F);return!!U&&(U.textOrientation==="upright"||U.textCombineUpright==="all"||U["-webkit-text-combine"]==="horizontal")}function me(F,U){if(F.nodeType===Node.ELEMENT_NODE){let M=m.defaultView.getComputedStyle(F);if(parseFloat(M.marginInlineEnd)||parseFloat(M.borderInlineEndWidth)||parseFloat(M.paddingInlineEnd))return!0}let j=F.parentElement;if(j&&!j.contains(U))return me(j,U);if(U.nodeType===Node.ELEMENT_NODE){let M=m.defaultView.getComputedStyle(U);if(parseFloat(M.marginInlineStart)||parseFloat(M.borderInlineStartWidth)||parseFloat(M.paddingInlineStart))return!0}let H=U.parentElement;return H&&!H.contains(F)?me(F,H):!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&&Q(a.parentElement))&&!me(a,t)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t),Y=!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&&Q(l.parentElement))&&!me(t,l)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t.nextSibling),Y=!0)),C}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)}},Wp=new Gp;Wp.registerHooks();function Gm(i){Wp.preprocessForTextSpacing(i)}function Wm(i,t,e,n,s,o){Wp.processGeneratedContent(i,t,e,n,s,o)}var yo=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Xm=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],Ql="data-adapt-pseudo";function en(i){return i.getAttribute(Ql)||""}function vr(i,t){i.setAttribute(Ql,t)}var Er=class{constructor(t,e,n,s,o){this.element=t;this.style=e;this.styler=n;this.context=s;this.exprContentListener=o;p(this,"contentProcessed",{})}getStyle(t,e){let n=en(t);this.styler&&n&&n.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let s=lt(this.style,"_pseudos"),o=(s==null?void 0:s[n])||{};if(n.match(/^first-/)&&!o["x-first-pseudo"]){let r=1,a;n=="first-letter"?r=0:(a=n.match(/^first-([0-9]+)-lines$/))!=null&&(r=a[1]-0),o["x-first-pseudo"]=new V(new ae(r),0)}return o}processContent(t,e,n){let s=en(t);if(!this.contentProcessed[s]){this.contentProcessed[s]=!0;let o=e.content;at(o)&&(o.visit(new Ln(t,this.context,o,this.exprContentListener)),Gm(t))}}};var zE=li.isInstanceOfAfterIfContinuesLayoutConstraint,Ym=Is.registerFragmentIndex,GE=Is.clearFragmentIndices,Jl=class{constructor(t,e){this.sourceNode=t;this.styler=e}createElement(t,e){let s=e.viewNode.ownerDocument.createElement("div"),o=new Eo(t,s,e),r=o.getColumn().pageBreakType;return o.getColumn().pageBreakType=null,o.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,o.getColumn().pageBreakType=r;let a=s.firstChild;return P(a,"display","block"),T(a)})}createNodePositionForPseudoElement(){let t=yo.createElementNS("http://www.w3.org/1999/xhtml","div");vr(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 Ot(s)}createShadowContext(t){return new Ps(this.sourceNode,t,null,null,null,Qt.ShadowType.ROOTED,this.styler)}},Xp=class i{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 jp(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof i?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},jp=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 qm(i,t){if(!i||!i.afterIfContinues||i.after||t.isFloatNodeContext(i))return T(i);let e=i.afterIfContinues;return e.createElement(t,i).thenAsync(n=>{let s=lx(i,t,n);return t.fragmentLayoutConstraints.push(new Xp(i,e,s)),T(i)})}function Zp(i,t){return i.thenAsync(e=>qm(e,t))}function ax(i,t){let e=L("processAfterIfContinuesOfAncestors"),n=i;return e.loop(()=>{if(n!==null){let s=qm(n,t);return n=n.parent,s.thenReturn(!0)}else return T(!1)}).then(()=>{e.finish(!0)}),e.result()}function lx(i,t,e){let n=i.viewNode;n.appendChild(e);let s=mi(e,t,i.vertical);return n.removeChild(e),s}var ec=class{constructor(t){this.constraints=t}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},xo=class extends ho{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 So=class extends lr{constructor(e,n,s,o,r){super(e);this.layoutContext=n;this.clientLayout=s;this.layoutConstraint=o;this.pageFloatLayoutContext=r;p(this,"last");p(this,"viewDocument");p(this,"flowRootFormattingContext",null);p(this,"isNonFirstColumn",!1);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,"lastLineStride",0);p(this,"breakAtTheEdgeBeforeFloat",null);hm(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,n,s=1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-n)<s}isOverflown(e){return this.almostEquals(e,this.footnoteEdge)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let n=L("openAllViews"),s=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let o=s.length-1,r=null;return n.loop(()=>{for(;o>=0;){let a=r,l=s[o];if(r=cr(l,a),o===s.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),o==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let c=this.layoutContext.setCurrent(r,o==0&&r.offsetInNode==0);if(o--,c.isPending())return c}return T(!1)}).then(()=>{n.finish(r)}),n.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?Zg(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,n){var s,o;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,a=r.match(js),l=a?a[0].length:0;if(!a&&((s=e.sourceNode)==null?void 0:s.nodeType)===3&&((o=e.sourceNode.nextSibling)==null?void 0:o.nodeType)===3&&r===e.sourceNode.textContent){let c=r+e.sourceNode.nextSibling.textContent,u=c.match(js);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,o=L("buildViewToNextBlockEdge");return o.loopWithFrame(r=>{var a;if(e.viewNode&&!es(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(po(u,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(l=>{let c=l;c!==e&&(e=c,es(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)&&(bn(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(()=>{o.finish(e)}),o.result()}nextInTree(e,n){let s=this.layoutContext.nextInTree(e,n);return Zp(s,this)}buildDeepElementView(e){if(!e.viewNode)return T(e);let n=[],s=e.sourceNode,o=L("buildDeepElementView");return o.loopWithFrame(r=>{e.viewNode&&e.inline&&!es(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}es(l)||n.push(l.copy())}this.nextInTree(l).then(c=>{if(e=c,!e||e.sourceNode==s){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(bn(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(u=>{if(e=u,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{n.length>0&&this.postLayoutBlock(e,n),o.finish(e)}),o.result()}createFloat(e,n,s,o){let r=this.viewDocument.createElement("div");return this.vertical?(o>=this.height&&(o-=.1),o<1&&(o=0),P(r,"height",`${s}px`),P(r,"width",`${o}px`)):(s>=this.width&&(s-=.1),s<1&&(s=0),P(r,"width",`${s}px`),P(r,"height",`${o}px`)),P(r,"float",n),P(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,o=s.style.cssFloat;if(o=="left"||o=="right"||o==="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(),o=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),a=this.vertical?-this.getLeftEdge():this.getBottomEdge(),l=null;for(let f of n)this.almostEquals(f.x1,s)?f.x1=s:this.almostEquals(f.x1,o)&&(f.x1=o),this.almostEquals(f.x2,o)?f.x2=o:this.almostEquals(f.x2,s)&&(f.x2=s),this.almostEquals(f.y1,r)?f.y1=r:this.almostEquals(f.y1,a)&&(f.y1=a),this.almostEquals(f.y2,a)?f.y2=a:this.almostEquals(f.y2,r)&&(f.y2=r);let c=1/(this.clientLayout.pixelRatio||1),u=Fo==="webkit"?Math.floor:Math.round,d=n.map(f=>(u(f.y2/c)-u(f.y1/c))*c),h=.01;for(let f=0;f<n.length;f++){let g=f<n.length-1?n[f+1].x1:s,m=f<n.length-1?n[f+1].x2:o,C=g-n[f].x1,x=n[f].x2-m,b=0,N=0;C>h?b=1:C<-h&&(b=-1),x>h?N=1:x<-h&&(N=-1);let S=b!==0&&N!==0?b===N?b:0:b||N;if(S!==0){let E=S*c;d[f]+E>=0&&(f>=n.length-1||d[f+1]-E>=0)&&(d[f]+=E,f<n.length-1&&(d[f+1]-=E))}}for(let f=0;f<n.length;f++){let g=n[f];g.left=this.createFloat(e,"left",g.x1-s,d[f]),g.right=this.createFloat(e,"right",o-g.x2,d[f]),g.x1<o&&g.x2>s?l=g:l||P(g.right,"float","none")}if(l){let f=n[n.length-1];if(l!==f&&f.y2>=a&&(this.footnoteEdge=this.vertical?-l.y2:l.y2,l.x1===s&&l.x2===o))for(let g=n.indexOf(l);g<n.length;g++){let m=n[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var s;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(s=this.element.parentElement)!=null&&s.hasAttribute("data-vivliostyle-in-column-balancing"))return;let e=this.vertical?this.width:this.height,n=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge);if(n>0&&n<e&&!this.almostEquals(n,e)){let o=this.vertical?"width":"height";if(P(this.element,o,`${n}px`),this.vertical){let r=this.left+(e-n);P(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,n,s,o){let r;if(e&&Jn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=ks(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=n[s];let a=o-e.boxOffset;for(;;){if(r=ks(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 qo(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 qo(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 qo(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=L("layoutFloat"),s=e.viewNode,o=Sl(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return P(s,"float","none"),P(s,"display","inline-block"),P(s,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let a=Dt(this.clientLayout,s,this.vertical),l=this.getComputedMargin(s),c=new tt(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=Dt(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 w=this.vertical?c.y2-c.y1:c.x2-c.x1;o=="left"?d=Math.max(d,u+w):u=Math.min(u,d-w),h!==e.parent&&!e.firstPseudo&&(h.viewNode.appendChild(s),s.setAttribute("data-vivliostyle-float-box-moved","true"))}let f=new tt(u,this.getBoxDir()*this.beforeEdge,d,this.getBoxDir()*this.afterEdge),g=c;this.vertical&&(g=Ko(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(e.clearSide){let E=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?Sl(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?o:e.clearSide,v=this.beforeEdge;E!=="right"&&(v=m*Math.max(v*m,this.leftFloatEdge*m)),E!=="left"&&(v=m*Math.max(v*m,this.rightFloatEdge*m));let w=v*m;if(g.y1<w){let A=g.y2-g.y1;g.y1=w,g.y2=g.y1+A}}f.y2+=1/(this.clientLayout.pixelRatio||1),yg(f,this.bands,g,o),this.vertical&&(c=Ka(g));let C=this.getComputedInsets(s);P(s,"width",`${c.x2-c.x1-C.left-C.right}px`),P(s,"height",`${c.y2-c.y1-C.top-C.bottom}px`),P(s,"position","absolute"),e.display,P(s,"display",e.display);let x,b=null;if(h&&(h.containingBlockForAbsolute?b=h:b=h.getContainingBlockForAbsolute()),b){let E=b.viewNode.ownerDocument.createElement("div");E.style.position="absolute",b.vertical?E.style.right="0":E.style.left="0",E.style.top="0",b.viewNode.appendChild(E),x=Dt(this.clientLayout,E,this.vertical),b.viewNode.removeChild(E)}else x={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(b?b.vertical:this.vertical)?P(s,"right",`${x.right-c.x2}px`):P(s,"left",`${c.x1-x.left}px`),P(s,"top",`${c.y1-x.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let N=this.vertical?c.x1:c.y2,S=this.vertical?c.x2:c.y1;!this.isOverflown(N)||this.breakPositions.length==0?(this.killFloats(),f=new tt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(f=Ko(f)),xg(f,this.bands,g,null,o),this.createFloats(),o=="left"?this.leftFloatEdge=N:this.rightFloatEdge=N,this.bottommostFloatTop=S,this.updateMaxReachedAfterEdge(N),n.finish(r)):(e=e.modify(),e.overflow=!0,n.finish(e))}),n.result()}setupFloatArea(e,n,s,o,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();return 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).thenAsync(()=>{e.init();let h=!!l.setFloatAreaDimensions(e,n,s,o,!0,!l.hasFloatFragments(),a);return h?(e.killFloats(),e.init()):c.element.parentNode.removeChild(u),T(h)})}createPageFloatArea(e,n,s,o,r){let a=this.element.ownerDocument.createElement("div");P(a,"position","absolute");let l=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),c=new In(null,ue.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);c.setOuterContext(this.pageFloatLayoutContext);let u=l.getContainer(),d=new Kp(n,a,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,c,u);return c.setContainer(d),this.setupFloatArea(d,e.floatReference,n,s,o,r).thenAsync(h=>h?T(d):T(null))}layoutSinglePageFloatFragment(e,n,s,o,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={floatArea:null,pageFloatFragment:null,newPosition:null},g=L("layoutSinglePageFloatFragment");return this.createPageFloatArea(d,n,a,r,h).then(m=>{if(f.floatArea=m,!m){g.finish(f);return}let C=!1,x=0;g.loopWithFrame(b=>{if(x>=e.length){b.breakLoop();return}let N=e[x],S=new Ot(N.nodePosition);m.layout(S,!0).then(E=>{f.newPosition=E,!E||o?(x++,b.continueLoop()):(C=!0,b.breakLoop())})}).then(()=>{if(!C){m.isFootnote&&m.applyCompactFootnoteDisplay();let b=c.setFloatAreaDimensions(m,d.floatReference,n,a,!1,o,h);if(!b)C=!0;else{let N=r.createPageFloatFragment(e,b,s,m,!!f.newPosition);c.addPageFloatFragment(N,!0),f.pageFloatFragment=N}}g.finish(f)})}),g.result()}layoutPageFloatInner(e,n,s,o){let r=this.pageFloatLayoutContext,a=e.float,l=new Set;for(let d=r;d;d=d.effectiveParent)for(let h of d.floatFragments)h.continuations.some(f=>f.float.insidePageFloatArea)&&l.add(h);r.stashEndFloatFragments(a);function c(d,h){h?r.removePageFloatFragment(h,!0):d&&d.element.parentNode.removeChild(d.element);let f=[];for(let g=r;g;g=g.effectiveParent)for(let m of g.floatFragments)!l.has(m)&&m.continuations.some(C=>C.float.insidePageFloatArea)&&f.push(m);for(let g of f)r.removePageFloatFragment(g,!0);r.restoreStashedFragments(a.floatReference),r.deferPageFloat(e)}let u=L("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],a.floatSide,a.clearSide,!r.hasFloatFragments(),n,s,o).then(d=>{let h=d.floatArea,f=d.pageFloatFragment,g=d.newPosition;f?this.layoutStashedPageFloats(a.floatReference,[o]).then(m=>{if(m){let C=!!r.generatingNodePosition;if(r.addPageFloatFragment(f,C),r.discardStashedFragments(a.floatReference),g){let x=new pi(a,g.primary);r.deferPageFloat(x)}u.finish(!0)}else c(h,f),u.finish(!1)}):(c(h,f),u.finish(!1))}),u.result()}layoutStashedPageFloats(e,n){let s=this.pageFloatLayoutContext,o=s.getStashedFloatFragments(e),r=[],a=[],l=!1,c=L("layoutStashedPageFloats"),u=0;return c.loopWithFrame(d=>{if(u>=o.length){d.breakLoop();return}let h=o[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 C=g.pageFloatFragment;C?(a.push(C),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)})):o.forEach(d=>{let h=d.area.element;h&&h.parentNode&&h.parentNode.removeChild(h)}),c.finish(!l)}),c.result()}findFootnoteCallElement(e){let n=e.previousSibling;for(;n;){if(n.nodeType===Node.ELEMENT_NODE&&en(n)==="footnote-call")return n;n=n.previousSibling}return null}setFloatAnchorViewNode(e){let n=e.viewNode.parentNode,s=n.ownerDocument.createElement("span");if(s.setAttribute(Vn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?s=r:n.insertBefore(s,e.viewNode)}else n.appendChild(s);n.removeChild(e.viewNode);let o=e.modify();return o.after=!0,o.viewNode=s,e.floatSide==="footnote"&&(o.display="inline"),o}resolveFloatReferenceFromColumnSpan(e,n,s){let o=L("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,a=r.getPageFloatLayoutContext(ue.REGION);return r.getContainer().width<a.getContainer().width&&e===ue.COLUMN?n===y.auto?this.buildDeepElementView(s.copy()).then(c=>{let u=c.viewNode,d=or(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?o.finish(ue.REGION):o.finish(e)}):n===y.all?o.finish(ue.REGION):o.finish(e):o.finish(e),o.result()}layoutPageFloat(e){let n=this.pageFloatLayoutContext,s=new Cn().findByNodeContext(e),o,r=n.findPageFloatByNodePosition(e.toNodePosition());return r?o=T(r):o=s.createPageFloat(e,n,this),o.thenAsync(a=>{let l=lo(e,0),c=this.setFloatAnchorViewNode(e),u=s.findPageFloatFragment(a,n),d=new pi(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=ks(c,this.clientLayout,0,this.vertical);return this.isOverflown(h)?T(c):this.layoutPageFloatInner(d,s,h,u).thenAsync(f=>f?e.floatSide==="footnote"?T(c):n.generatingNodePosition?T(c):T(null):(n.registerPageFloatAnchor(a,c.viewNode),T(c)))}})}processLineStyling(e,n,s){let o=L("processLineStyling"),r=s.concat([]);s.splice(0,s.length);let a=0,l=e.firstPseudo;return l.count==0&&(l=l.outer),o.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),o.finish(n)}),o.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Tn[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let n=0,s=0;for(let o=e.length-1;o>=0;o--){let r=e[o];if(!r||!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=L("layoutBreakableBlock"),s=[];return this.buildViewToNextBlockEdge(e,s).then(o=>{let r=s.length-1;if(r<0){n.finish(o);return}this.postLayoutBlock(o,s);let a=this.suppressOpenAncestorBlockEndInset(o!=null?o:e),l=this.calculateEdge(o,s,r,s[r].boxOffset);a();let c=!1;if(!o||!Jn(o.viewNode)){let d=As(o,this.collectElementsOffset());c=this.isOverflown(l+(this.vertical?-1:1)*d.minimum),this.isOverflown(l+(this.vertical?-1:1)*d.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=o)}o==null&&(l+=this.getTrailingMarginEdgeAdjustment(s)),this.updateMaxReachedAfterEdge(l);let u;e.firstPseudo?u=this.processLineStyling(e,o,s):u=T(o),u.then(d=>{s.length>0&&(this.saveBoxBreakPosition(s),c&&!this.isLoneImage(s)&&d&&(d=d.modify(),d.overflow=!0)),n.finish(d)})}),n.result()}postLayoutBlock(e,n){Je("POST_LAYOUT_BLOCK").forEach(o=>{o(e,n,this)})}findEndOfLine(e,n,s){let o=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<=o:f>=o){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 o=this.findEndOfLine(n,e,!0),r=o.nodeContext;if(o.checkPointIndex===0&&o.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,o.index,e,o.checkPointIndex,s)}else{let d=Hd(r);if(d){if(((c=this.breakPositions)==null?void 0:c[0])instanceof xo&&(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)||Bn(h));)h=h.previousSibling;if(h)break;r=r.parent}}}return this.clearOverflownViewNodes(r,!1),r}resolveTextNodeBreaker(e){return Je("RESOLVE_TEXT_NODE_BREAKER").reduce((s,o)=>o(e)||s,Nr.instance)}getRangeBoxes(e,n){let s=[],o=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:Al(f)?d=!c:!f.firstChild||Tn[f.localName]||/^r(uby|[bt]c?)$/.test(f.localName)||bm(this.clientLayout.getElementComputedStyle(f).display)?(d=!c,d?(f.localName==="ruby"&&a.firstChild&&(a=a.firstChild),o.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:(o.setStartBefore(a),c=!0)),l=a),h||(h=a.nextSibling,h||(r=!0,h=a.parentNode)),a=h}while(d&&u);if(c){o.setEndAfter(l);let h=this.clientLayout.getRangeClientRects(o);Pl(h,this.vertical);for(let f=0;f<h.length;f++)s.push(h[f]);c=!1}}return s}findLinePositions(e){let o=[],r=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);r.sort(this.vertical?sm:nm);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&&(o.push(l),u=0),d>=r.length)break}return o.sort(Na),this.vertical&&o.reverse(),o}calculateClonedPaddingBorder(e){let n=0;for(let s=e;s;s=s.parent)if(!s.inline&&Es(s.viewNode)){let o=this.getComputedPaddingBorder(s.viewNode);n+=s.vertical?-o.left:o.bottom,s.display==="table"&&(n+=(s.vertical?-1:1)*s.blockBorderSpacing)}return n}getOffsetByRepetitiveElements(e){let n;return e?n=e.calculateOffset(this):n=As(null,this.collectElementsOffset()),n.current}findBoxBreakPosition(e,n){let s=this.element.parentNode,o=this.element.nextSibling;s.removeChild(this.element),s.insertBefore(this.element,o);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 C=Rt(d.length,S=>{let E=d[S];return this.vertical?E<h||E<=m.edge:E>h||E>=m.edge}),x=C<=0;x&&(C=Rt(d.length,S=>this.vertical?d[S]<h:d[S]>h));let b=r[r.length-1].viewNode;if((b==null?void 0:b.parentElement.localName)==="viv-ts-inner"&&(b=b.parentElement.parentElement),(C===d.length&&b.nextSibling||C>=d.length-1&&b.parentElement.querySelector(".MJXc-display"))&&(l=0,c=1),C=Math.min(d.length-l,C),C<c)return null;h=d[C-1];let N;if(x?N=m.checkPoint:N=this.findAcceptableBreakInside(e.checkPoints,h,n),N){let S=this.getAfterEdgeOfBlockContainer(N);if(!isNaN(S)&&f*(h-S)>0&&(h=S),this.computedBlockSize=f*(h-this.beforeEdge)+g,d.length>=2){let E=Math.max(1,Math.min(C-1,d.length-1));this.lastLineStride=Math.abs(d[E]-d[E-1])}}return N}getAfterEdgeOfBlockContainer(e){let n=e;do n=n.parent;while(n&&n.inline);return n?(n=n.copy().modify(),n.after=!0,ks(n,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let n=e.findIndex(o=>o.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 Rs().find(e.formattingContext).finishBreak(this,e,n,s);return r||(r=Ci.finishBreak(this,e,n,s)),r}findAcceptableBreakPosition(){let e=null,n=null,s=0,o=0;do{s=o,o=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&&(o=Math.min(o,a))}}while(o>s&&!n&&this.forceNonfitting);return{breakPosition:n?e:null,nodeContext:n}}doFinishBreak(e,n,s,o){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!n)return T(e);let r=L("doFinishBreak"),a=!1;if(!e){if(this.forceNonfitting)return O.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=o}return this.finishBreak(e,a,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let n=e;n;n=n.parent)if(Bn(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}isZeroLength(e){let n=e.trim();return n===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(n)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!hr(this))return()=>{};let n=[];for(let s=e==null?void 0:e.parent;s;s=s.parent){if(s.after||s.inline)continue;let o=s.viewNode;if(!o||o.nodeType!==1||Es(o))continue;let r=this.clientLayout.getElementComputedStyle(o);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let a=o.getAttribute("data-viv-box-break");ht(o,"block-end"),n.push({element:o,original:a})}return()=>{for(let{element:s,original:o}of n)o===null?s.removeAttribute("data-viv-box-break"):s.setAttribute("data-viv-box-break",o)}}checkOverflowAndSaveEdge(e,n){if(!e)return!1;for(let l=e;l;l=l.parent)if(Bn(l.viewNode))return!1;if(Jn(e.viewNode))return!1;let s=this.suppressOpenAncestorBlockEndInset(e),o=ks(e,this.clientLayout,0,this.vertical);s();let r=As(e,this.collectElementsOffset()),a=this.isOverflown(o+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(o+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(n){let l=o+this.getTrailingMarginEdgeAdjustment(n),c=this.footnoteEdge-this.getBoxDir()*r.current;o=this.vertical?Math.min(o,Math.max(l,c)):Math.max(o,Math.min(l,c))}return this.updateMaxReachedAfterEdge(o),a}checkOverflowAndSaveEdgeAndBreakPosition(e,n,s,o){if(!e||Jn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,n);return(s||!r)&&this.saveEdgeBreakPosition(e,o,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==ue.INLINE||e.floatSide)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 o=Dt(this.clientLayout,s,this.vertical),r=this.getBeforeEdge(o),a=this.getBoxDir(),l=e.clearSide==="same"?e.floatSide:e.clearSide,c=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(l)?Sl(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),h=d;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 f=1/(this.clientLayout.pixelRatio||1),g=d*a>h*a;d=a*(Math.ceil(d*a/f)+(g?1:0))*f;let m=f;if(r*a+m>d*a)return e.viewNode.parentNode.removeChild(s),!1;{let C=Math.max(1,(d-r)*a);this.vertical?s.style.width=`${C}px`:s.style.height=`${C}px`,o=Dt(this.clientLayout,s,this.vertical);let x=this.getAfterEdge(o);if(!e.floatSide)if(this.vertical){let b=x-n.right-d;b>0==n.right>=0&&(b+=n.right),s.style.marginLeft=`${b}px`}else{let b=d-(x+n.top);b>0==n.top>=0&&(b+=n.top),s.style.marginBottom=`${b}px`}return e.clearSpacer=s,!0}}isBFC(e){return!!(xm(e)||Rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let n=e;n;n=n.parent)if(Ud(n.viewNode))return!0;return!1}skipEdges(e,n,s){var E;let o=e.after?(E=e.parent)==null?void 0:E.formattingContext:e.formattingContext;if(o&&!this.isBFC(o))return T(e);let r=L("skipEdges"),a=this,l=!s&&n&&e&&e.after,c=s,u=null,d=[],h=[],f=!1;function g(v){var w,A;if(!(!n||a.isNonFirstColumn||s||!Nd(c))){for(let I=v;I;I=I.parent)if(I.breakBefore==="column"&&(I.breakBefore=null),((w=I.viewNode)==null?void 0:w.nodeType)===1){let _=I.viewNode;((A=_.style)==null?void 0:A.breakBefore)==="column"&&(_.style.breakBefore="")}}}function m(v){var w,A;if(!(!n||!a.isNonFirstColumn||s||c!=="column")){for(let I=v;I;I=I.parent)if(I.breakBefore==="column"&&(I.breakBefore=null),((w=I.viewNode)==null?void 0:w.nodeType)===1){let _=I.viewNode;((A=_.style)==null?void 0:A.breakBefore)==="column"&&(_.style.breakBefore="")}c=null}}function C(v){var w,A;if(!(s||!Nd(c))){for(let I=v;I;I=I.parent)if(I.breakAfter==="column"&&(I.breakAfter=null),((w=I.viewNode)==null?void 0:w.nodeType)===1){let _=I.viewNode;((A=_.style)==null?void 0:A.breakAfter)==="column"&&(_.style.breakAfter="")}}}function x(v){c=Be(c,v)}function b(){return s?!0:Ee(c)?n?a.isNonFirstColumn&&c!=="column"&&c!=="region":!N():!1}function N(){var v;if(!u||!e||e.floatSide)return!1;for(let w=u;w!=null&&w.parent;w=w.parent){if(w.parent.viewNode&&Bn(w.parent.viewNode))continue;let A=w.after?w.viewNode:(v=w.viewNode)==null?void 0:v.previousSibling;for(;A&&(ce(A,w.parent.whitespace)||Bn(A));)A=A.previousSibling;if(A)return!1}return!0}let S=()=>{e=d[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=c};return r.loopWithFrame(v=>{var w;for(;e;){e.formattingContext;let A=new Rs().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(ce(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){b()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)?(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0):(!u&&!n&&d.length===0&&this.saveEdgeBreakPosition(e,c,!1),e=e.modify(),e.breakBefore=c),v.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=rr(c)?c:null),A&&A.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&n&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),c,!1),!e.inline&&!e.repeatOnBreak&&(u?Hd(u):this.breakPositions[this.breakPositions.length-1]instanceof xo||!n&&d.length===0)&&this.saveEdgeBreakPosition(e.copy(),c,!1),!this.isBFC(e.formattingContext)||Rn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&ce(e.sourceNode.firstChild,e.whitespace)){d.push(e.copy()),x(e.breakBefore),g(e),m(e),b()?S():(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),v.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let _=e.viewNode,Y=_.style;if(e.after){Md(_,this),e.floatSide&&(c=c!=null?c:this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let Q=e.sourceNode;if(Q.localName==="svg"||Q.localName==="math"||Q.getAttribute("data-math-typeset")==="true"){f=!1,u=e.copy(),h.push(u),c=null,x(e.breakAfter),C(e),this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c);break}if(e.inline||A&&A.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(f){if(Ud(e.viewNode))break;if(b()){S(),v.breakLoop();return}d=[],n=!1,l=!1,c=null}f=!1,_d(e.viewNode)||(u=e.copy(),h.push(u)),x(e.breakAfter),C(e),Y&&!Bn(e.viewNode)&&this.hasNonZeroBlockEndInset(Y)&&(h=u?[u]:[])}else{if(d.push(e.copy()),x(e.breakBefore),g(e),m(e),u&&Ee(c)&&gm(u.viewNode,e.viewNode),(e.pageType!=((w=e.parent)==null?void 0:w.pageType)||!Ee(c))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){v.breakLoop();return}let Q=e.viewNode.localName;if(Tn[Q]){b()?S():this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),v.breakLoop();return}Y&&this.hasNonZeroBlockStartInset(Y)&&(l=!1,h=[]),f=!0}}while(!1);let I=this.nextInTree(e,l);if(I.isPending()){I.then(_=>{e=_,v.continueLoop()});return}else e=I.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(u,h,!this.stopAtOverflow,c)?u&&this.stopAtOverflow&&(e=u.modify(),e.overflow=!0):Ee(c)&&(this.pageBreakType=c),v.breakLoop()}).then(()=>{u&&(this.lastAfterPosition=u.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let n=e.copy(),s=L("skipEdges"),o=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){Ee(o)&&(this.pageBreakType=o),a.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){o=Be(o,e.breakBefore),Ee(o)&&(this.pageBreakType=o),a.breakLoop();return}if(e.viewNode.nodeType!=1)break;let c=e.viewNode.style;if(e.after){if(r){if(Ee(o)){this.pageBreakType=o,a.breakLoop();return}o=null}r=!1,o=Be(o,e.breakAfter)}else{o=Be(o,e.breakBefore);let u=e.viewNode.localName;if(Tn[u]){Ee(o)&&(this.pageBreakType=o),a.breakLoop();return}if(c&&this.hasNonZeroBlockStartInset(c)){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){if(bn(e.floatReference)||e.floatSide==="footnote"){let n=this.pageFloatLayoutContext.generatingNodePosition;if(n&&e.sourceNode===n.steps[0].node){let s=e.modify();return s.floatSide=null,s.floatReference=ue.INLINE,s.clearSide=null,this.isBreakable(s)?this.layoutBreakableBlock(s):this.layoutUnbreakable(s)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,n,s){let o=L("layoutNext");return this.skipEdges(e,n,s||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))o.finish(e);else{let a=e.formattingContext;new Rs().find(a).layout(e,this,n).thenFinish(o)}}),o.result()}clearOverflownViewNodes(e,n){if(e)for(let s=e.parent;e;e=s,s=s?s.parent:null){let o=(s||e).formattingContext;new Rs().find(o).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(),o=this.originY+this.top+this.getInsetTop();this.box=new tt(s,o,s+this.width,o+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=fg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],P(this.element,"width",`${this.width}px`),P(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,n,s){e.formattingContext;let o=e.copy(),r=new Rs().find(e.formattingContext),a=this.calculateClonedPaddingBorder(o),l=r.createEdgeBreakPosition(o,n,s,this.computedBlockSize+a);this.breakPositions.push(l)}saveBoxBreakPosition(e){let n=e[0].breakPenalty;if(n){let o=e[0];for(;o.parent&&o.inline;)o=o.parent;n=o.breakPenalty}let s=new xo(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);gi(this);let o=L("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 Yp(n,s);l.layout(r,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(hr(this)&&(Cm(this),pr(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(P(this.element,"width",`${this.width}px`),P(this.element,"left",`${this.left}px`)):P(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){o.finish(null);return}if(!u)o.finish(null);else{this.overflown=!0;let h=new Ot(u.toNodePosition());o.finish(h)}})})})}),o.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let n=L("doFinishBreakOfFragmentLayoutConstraints"),s=[].concat(this.fragmentLayoutConstraints);s.sort((r,a)=>r.getPriorityOfFinishBreak()-a.getPriorityOfFinishBreak());let o=0;return n.loop(()=>o<s.length?s[o++].finishBreak(e,this).thenReturn(!0):T(!1)).then(()=>{n.finish(!0)}),n.result()}doLayout(e,n,s){let o=L("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,o.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(()=>{o.finish({nodeContext:e,overflownNodeContext:r})}),o.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=L("redoLayout"),o=0,r=null,a=!0;return s.loopWithFrame(l=>{if(o<e.length){let c=e[o++];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(Rn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}if(li.isInstanceOfAfterIfContinuesLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}gn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(this).forEach(o=>{e.push(o)})});return e}},Eo=class{constructor(t,e,n){p(this,"startNodeContexts",[]);p(this,"column");p(this,"flowRootSourceNode");this.flowRootSourceNode=n.sourceNode,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 o=this;this.column.openAllViews=function(r){return So.prototype.openAllViews.call(this,r).thenAsync(a=>(o.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 On(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 mn(t.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(t)}isEffectivelyLastAfterNodeContext(t){var s;let e=this.flowRootSourceNode,n=t.sourceNode;if(!e||!n||!t.after||e!==n&&!((s=e.contains)!=null&&s.call(e,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let o=n;if(t.offsetInNode<o.length){let r=o.data.slice(t.offsetInNode);if(!Id(r,t.whitespace))return!1}}for(let o=n;o&&o!==e;o=o.parentNode)for(let r=o.nextSibling;r;r=r.nextSibling)if(!ce(r,t.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Nr=class{breakTextNode(t,e,n,s,o,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+jm(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 o=e.charAt(n);n++;let r=e.charAt(n);return t.replaceData(n,e.length-n,!s.breakWord&&Tu(o)&&Tu(r)?jm(s):""),n}updateNodeContext(t,e,n){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};p(Nr,"instance");Nr.instance=new Nr;function jm(i){return i.hyphenateCharacter||i.parent&&i.parent.hyphenateCharacter||"-"}var Yp=class extends Ls{constructor(e,n){super();this.leadingEdge=e;p(this,"breakAfter");p(this,"initialPageBreakType",null);p(this,"initialComputedBlockSize",0);p(this,"initialOverflown",!1);p(this,"initialLastLineStride",0);p(this,"context",{overflownNodeContext:null});this.breakAfter=n||null}resolveLayoutMode(e){return new qp(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,n){n.fragmentLayoutConstraints=[],n.pseudoParent||Em()}clearNodes(e){super.clearNodes(e);let n=e;for(;n;){let s=n.viewNode;s&&kl(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,this.initialLastLineStride=n.lastLineStride}restoreState(e,n){super.restoreState(e,n),n.pageBreakType=this.initialPageBreakType,n.computedBlockSize=this.initialComputedBlockSize,n.overflown=this.initialOverflown,n.lastLineStride=this.initialLastLineStride}},qp=class{constructor(t,e,n){this.leadingEdge=t;this.breakAfter=e;this.context=n}doLayout(t,e){let n=L("DefaultLayoutMode.doLayout");return ax(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(o=>{o.postLayout(s,t,e,n)}),s}},Kp=class extends So{constructor(e,n,s,o,r,a,l){super(n,s,o,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,o=n.y2-n.y1;function r(a,l){a.forEach(c=>{let u=rn(e,c);if(u&&u.charAt(u.length-1)==="%"){let d=parseFloat(u),h=l*d/100;P(e,c,`${h}px`)}})}r(["width","max-width","min-width"],s),r(["height","max-height","min-height"],o),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?o:s),["margin-top","margin-right","margin-bottom","margin-left"].forEach(a=>{rn(e,a)==="auto"&&P(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=rn(n,"height");r!==""&&r!=="auto"&&P(n,"margin-top","auto")}}else if(s==="block-end"||s==="bottom"){let r=rn(n,"width");r!==""&&r!=="auto"&&P(n,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=Dt(this.clientLayout,e,this.vertical),o=this.floatMargins[n];return this.vertical?o.top+s.height+o.bottom:o.left+s.width+o.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=this.floatMargins[n];return this.vertical?s.left:s.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,n=e==null?void 0:e.styler,s=e==null?void 0:e.xmldoc,o=this.rootViewNodes.filter(u=>{var C,x,b;let d=u.getAttribute(Ut);if(!d||!n||!s)return!1;let h=s.getNodeByOffset(parseInt(d,10));if(!h||h.nodeType!==Node.ELEMENT_NODE)return!1;let f=n.getStyle(h,!1),g=(x=(C=ne(f,"footnote-display"))==null?void 0:C.value)==null?void 0:x.toString(),m=!!((b=ne(f,"--viv-marker-content"))!=null&&b.value);return g==="compact"&&!m});if(o.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),a=this.vertical?r.height:r.width;o.forEach(u=>{P(u,"display","inline"),u.style.setProperty("--viv-footnote-white-space","nowrap")});let l=1.5/(this.clientLayout.pixelRatio||1),c=u=>{let d=u.cloneNode(!0);d.style.removeProperty("--viv-footnote-inline-separator"),P(d,"display","inline-block"),P(d,"position","absolute"),P(d,"visibility","hidden"),P(d,"white-space","nowrap"),P(d,"max-width","none"),P(d,"left","0"),P(d,"top","0"),this.element.appendChild(d);let h=d.getBoundingClientRect();return this.element.removeChild(d),this.vertical?h.height:h.width};o.forEach(u=>{c(u)>a+l&&(P(u,"display","block"),u.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(n=>{let s=Dt(this.clientLayout,n,this.vertical),o=this.getComputedMargin(n),r=this.vertical?o.left:o.bottom;return e*(this.getAfterEdge(s)-this.beforeEdge)+Math.max(0,r)}))}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,n)=>{var l,c;let s=e,o=(l=s.ownerDocument.defaultView)==null?void 0:l.getComputedStyle(s).display,r=this.rootViewNodes[n+1],a=(c=r==null?void 0:r.ownerDocument.defaultView)==null?void 0:c.getComputedStyle(r).display;o==="inline"&&a==="inline"?s.style.setProperty("--viv-footnote-inline-separator",'" "'):s.style.removeProperty("--viv-footnote-inline-separator")})}};var xn=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;Ll.some(n=>n.root===this.rootSourceNode?(this.repetitiveElements=n.elements,!0):!1)||(this.repetitiveElements=new Qp(t,this.rootSourceNode),Ll.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},Qp=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=lo(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=lo(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=mi(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=mi(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 o=e.viewNode.ownerDocument,r=e.viewNode,a=o.createElement("div");r.appendChild(a);let l=new Eo(s,a,e),c=l.getColumn().pageBreakType;return l.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,l.layout(new Ot(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(Vn,"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(o=>o.nodeContext.sourceNode===t.sourceNode&&o.nodeContext.after===t.after);if(s.length>0)return s[0].result;{let o=n(t);return e.push({nodeContext:t,result:o}),o}}isAfterNodeContextOf(t,e,n){let s=[];for(let o=t;o;o=o.parentNode){if(e.sourceNode===o)return e.after;s.push(o)}for(let o=e.sourceNode;o;o=o.parentNode){let r=s.indexOf(o);if(r>=0)return n?r===0:!1;for(let a=o;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}},wi=class{constructor(t){this.formattingContext=t}accept(t,e){return!!t}postLayout(t,e,n,s){let o=this.formattingContext.getRepetitiveElements();return o&&(n.clientLayout,o.doneInitialLayout||(o.updateHeight(n),o.doneInitialLayout=!0)),s}},Pi=class{constructor(t){this.formattingContext=t}accept(t,e){return!0}postLayout(t,e,n,s){return s}},Jp=class extends wi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}accept(e,n){return!1}},eh=class extends Pi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return!e.belongsTo(this.formattingContext)&&!e.after&&n.fragmentLayoutConstraints.unshift(new Tr(e)),this.processor.doLayout(e,n)}},Tr=class i{constructor(t){p(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner");p(this,"nodeContext");let e=is(t.formattingContext);this.nodeContext=e.getRootNodeContext(t)}allowLayout(t,e,n){let s=this.getRepetitiveElements();return!s||Jn(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 o=this.getRepetitiveElements();o&&t&&s.stopAtOverflow&&(e==null||o.isAfterLastContent(e))&&o.preventSkippingFooter()}finishBreak(t,e){let n=is(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return T(!0);let o=this.nodeContext;return ux(n,o,e).thenAsync(()=>dx(n,o,e).thenAsync(()=>(s.prepareLayoutFragment(),T(!0))))}getRepetitiveElements(){return is(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof i?is(this.nodeContext.formattingContext)===is(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},th=class extends Ls{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 Jp(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&n&&n.preventSkippingHeader(),new eh(this.formattingContext,this.processor))}},nh=class extends ns{constructor(e,n){super();this.formattingContext=e;this.column=n}startNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,o=n.getRepetitiveElements();if(s.parent&&n.rootSourceNode===s.parent.sourceNode){switch(s.repeatOnBreak){case"header":if(o.isHeaderRegistered())s.repeatOnBreak="none";else return o.setHeaderNodeContext(s),T(!0);break;case"footer":if(o.isFooterRegistered())s.repeatOnBreak="none";else return o.setFooterNodeContext(s),T(!0);break}o.firstContentSourceNode||(o.firstContentSourceNode=s.sourceNode)}return ns.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):ns.prototype.afterNonInlineElementNode.call(this,e)}};var sh=class extends Dn{layout(t,e,n){if(e.isFloatNodeContext(t))return e.layoutFloatOrFootnote(t);let s=is(t.formattingContext);return s.getRootViewNode(t)?(n&&oh(t.parent,e),t.belongsTo(s)?Dn.prototype.layout.call(this,t,e,n):new th(s,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let n=px(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=is(t.formattingContext),s=L("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(s),s.result()}layoutEntireBlock(t,e){let n=is(t.formattingContext),s=new nh(n,e);return new fo(s,e.layoutContext).iterate(t)}doLayout(t,e){let n=is(t.formattingContext),s=L("doLayout"),o=e.layoutContext.nextInTree(t,!1);return Zp(o,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 Dn.prototype.finishBreak.call(this,t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Dn.prototype.clearOverflownViewNodes(t,e,n,s)}};function cx(i,t){for(let e=i;e;e=e.parent){let n=e.formattingContext;n&&n instanceof xn&&!e.belongsTo(n)&&t(n,e)}}function oh(i,t){i&&cx(i.after?i.parent:i,(e,n)=>{gn.isInstanceOfTableFormattingContext(e)||t.fragmentLayoutConstraints.push(new Tr(n))})}function ux(i,t,e){let n=i.getRepetitiveElements();if(n){let s=i.getRootNodeContext(t);if(s.viewNode){let o=s.viewNode.firstChild;return n.appendHeaderToFragment(s,o,e)}}return T(!0)}function dx(i,t,e){let n=i.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=i.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,e)}return T(!0)}function px(i){let t=i.formattingContext;return!t||!(t instanceof xn)?null:t}function is(i){return i instanceof xn,i}var hx=new sh;je("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof xn&&!gn.isInstanceOfTableFormattingContext(i)?hx:null);var nc=class{constructor(t,e){this.rowIndex=t;this.sourceNode=e;p(this,"cells",[]);p(this,"breakBefore",null);p(this,"breakAfter",null)}addCell(t){this.cells.push(t)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(t=>t.height))}},ih=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}},ah=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;this.cell=n}},lh=class{constructor(t,e,n){this.column=t;this.cellNodeContext=n;p(this,"pseudoColumn");p(this,"empty",!1);this.pseudoColumn=new Eo(t,e,n)}findAcceptableBreakPosition(){let t=this.cellNodeContext.viewNode,{verticalAlign:e,alignContent:n}=t.style;e!=="top"&&e!=="baseline"&&P(t,"vertical-align","top"),n&&n!=="normal"&&P(t,"align-content","normal");let s=this.pseudoColumn.findAcceptableBreakPosition(!0);return P(t,"vertical-align",e),n&&n!=="normal"&&P(t,"align-content",n),s}},ch=class{constructor(t,e){this.viewNode=t;this.side=e}},uh=class extends On{constructor(e,n,s,o){super(e,n,s,o);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)?this.hasUnfinishedCells()?null:s:null}hasUnfinishedCells(){let e=this.getRowIndex(),n=this.formattingContext.getCellsFallingOnRow(e);for(let s of n){if(s.rowIndex+s.rowSpan-1>e)continue;let o=this.formattingContext.getCellFragmentOfCell(s);if(o){let r=o.findAcceptableBreakPosition();if(r.nodeContext&&!o.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}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)}},dh=class extends ho{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(),o=this.getAcceptableCellBreakPositions(),r=o.every(a=>!!a.nodeContext)&&o.some((a,l)=>{let c=s[l].pseudoColumn,u=a.nodeContext;return!c.isStartNodeContext(u)&&!c.isLastAfterNodeContext(u)});return this.beforeNodeContext.overflow=o.some(a=>a.nodeContext&&a.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let n=this.formattingContext.getRowByIndex(this.rowIndex),s=this.beforeNodeContext.breakPenalty,o=this.getAcceptableCellBreakPositions(),r=this.getCellFragments();s+=Math.max(0,...r.map(l=>l.cellNodeContext.breakPenalty));let a=o.some((l,c)=>l.breakPosition instanceof xo&&r[c].cellNodeContext.sourceNode.rowSpan>1);return o.forEach((l,c)=>{let u=l.breakPosition.getMinBreakPenalty();a&&l.breakPosition instanceof On&&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)}},Os=class extends xn{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){var s;if(!n)return n;switch(e.display){case"table-row":return this.cellBreakPositions.length===0&&e.fragmentIndex<=1;case"table-cell":return e.fragmentIndex>1||((s=e.parent)==null?void 0:s.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(o=>o.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 nc(e,null)),s=this.rows[e]),s.addCell(n);let o=e+n.rowSpan,r=this.getRowSlots(e),a=0;for(;r[a];)a++;for(;e<o;e++){r=this.getRowSlots(e);for(let l=a;l<a+n.colSpan;l++){let c=r[l]=new ah(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 o=this.cellFragments[e];o||(o=this.cellFragments[e]=[]),o[n]=s}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((s,o)=>o.cell!==s[s.length-1]?s.concat(o.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 o=Dt(e,s.viewElement,this.vertical);s.viewElement=null,s.setHeight(this.vertical?o.width:o.height)})})}findCellFromColumn(e){if(!e)return null;let n=null,s=0,o=0;e:for(s=0;s<this.cellFragments.length;s++)if(this.cellFragments[s]){for(o=0;o<this.cellFragments[s].length;o++)if(this.cellFragments[s][o]&&e===this.cellFragments[s][o].pseudoColumn.getColumn()){n=this.rows[s].cells[o];break e}}if(!n)return null;for(;s<this.slots.length;s++)for(;o<this.slots[s].length;o++){let r=this.slots[s][o];if(r.cell===n)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let n=[];return this.slots.reduce((s,o,r)=>{if(r>=e.rowIndex)return s;let a=o[e.columnIndex]&&this.getCellFragmentOfCell(o[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,o)=>{e[o]||(e[o]={collected:[],elements:[]});let r=e[o],a=this.getCellFragmentOfCell(s);!a||r.collected.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),r.elements),r.collected.push(a))})}),[new ph(e.map(n=>n.elements))]}collectElementsOffsetFromColumn(e,n){e.fragmentLayoutConstraints.forEach(s=>{if(Rn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();n.push(o)}gn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(null).forEach(o=>{n.push(o)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},ph=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 o=As(t,s);n=Math.max(n,e(o))}),n}};function tn(i){return i instanceof Os,i}function fx(i){return i==="table-row-group"||i==="table-header-group"||i==="table-footer-group"}function gx(i){return i==="table"||i==="inline-table"}function Zm(i){return fx(i)||gx(i)}function Qm(i,t,e){let n=i.nodeContext,s=n.display,o=n.parent?n.parent.display:null,r=!1;if(o==="inline-table"&&!(n.formattingContext instanceof Os)){for(let l=n.parent;l;l=l.parent)if(l.formattingContext instanceof Os){r=l.formattingContext===t;break}}return r||s==="table-row"&&!Zm(o)||s==="table-cell"&&o!=="table-row"&&!Zm(o)||n.formattingContext instanceof Os&&n.formattingContext!==t?e.buildDeepElementView(n).thenAsync(l=>(i.nodeContext=l,T(!0))):null}function Jm(i,t){let e=t.nodeContext;return!(e!=null&&e.floatSide)||!(bn(e.floatReference)||e.floatSide==="footnote")?null:i.layoutFloatOrFootnote(e).thenAsync(n=>(n&&(t.nodeContext=n),T(!0)))}var hh=class extends ns{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=Qm(e,n,this.column);if(s)return s;this.postLayoutBlockContents(e);let o=Jm(this.column,e);if(o)return o;let r=e.nodeContext,a=r.display,l=n.getRepetitiveElements();switch(a){case"table":n.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let c=new ch(r.viewNode,r.captionSide);n.captions.push(c);break}case"table-header-group":return l.isHeaderRegistered()||(this.inHeaderOrFooter=!0,l.setHeaderNodeContext(r)),T(!0);case"table-footer-group":return l.isFooterRegistered()||(this.inHeaderOrFooter=!0,l.setFooterNodeContext(r)),T(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,n.addRow(this.rowIndex,new nc(this.rowIndex,r.sourceNode)),r.breakBefore&&(n.rows[this.rowIndex].breakBefore=r.breakBefore),l.firstContentSourceNode||(l.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,o=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(o){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,T(!0);break;case"table-row":if(!this.inHeaderOrFooter){n.lastRowViewNode=s.viewNode,this.inRow=!1;let a=n.rows[this.rowIndex];a&&s.breakAfter&&(a.breakAfter=Be(a.breakAfter,s.breakAfter))}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 ih(this.rowIndex,this.columnIndex,a)),this.columnIndex++;let l=n.rows[this.rowIndex];l&&(s.breakBefore&&(l.breakBefore=Be(l.breakBefore,s.breakBefore)),s.breakAfter&&(l.breakAfter=Be(l.breakAfter,s.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let n=e.nodeContext;n&&n.viewNode&&!es(n)&&this.checkPoints.push(n.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},oc=class oc extends ns{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}startNonInlineElementNode(e){let n=Jm(this.column,e);return n||super.startNonInlineElementNode(e)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(e){let n=this.formattingContext.colWidths;let s=0;for(let o=0;o<e.colSpan;o++)s+=n[e.anchorSlot.columnIndex+o];return s+=this.formattingContext.inlineBorderSpacing*(e.colSpan-1),s}layoutCell(e,n,s){let o=e.rowIndex,r=e.columnIndex,a=e.colSpan,l=n.viewNode;a>1&&(P(l,"box-sizing","border-box"),P(l,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(e)}px`));let c=l.ownerDocument.createElement("div");l.appendChild(c);let u=new lh(this.column,c,n);return this.formattingContext.addCellFragment(o,r,u),s.primary.steps.length===1&&s.primary.after&&(u.empty=!0),u.pseudoColumn.layout(s,!0).thenReturn(!0)}findBrokenCellAtSlot(e,n){let s=this.formattingContext.cellBreakPositions;for(let o=0;o<s.length;o++){let r=s[o];if(r.cell.anchorSlot.columnIndex===e&&r.cellNodePosition.steps[0].node===n)return{position:r,index:o}}return null}extractRowSpanningCellBreakPositions(){let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let n=[],s=0;do{let o=e[s],r=o.cell,a=r.rowIndex;if(a<this.currentRowIndex&&a+r.rowSpan>this.currentRowIndex){let l=n[a];l||(l=n[a]=[]),l.push(o),e.splice(s,1)}else s++}while(s<e.length);return n}layoutRowSpanningCellsFromPreviousFragment(e){let n=this.formattingContext,s=this.extractRowSpanningCellBreakPositions(),o=s.reduce(h=>h+1,0);if(o===0)return T(!0);let r=this.column.layoutContext,a=e.nodeContext;a.viewNode.parentNode.removeChild(a.viewNode);let l=L("layoutRowSpanningCellsFromPreviousFragment"),c=T(!0),u=0,d=[];return s.forEach(h=>{c=c.thenAsync(()=>{let f=cr(h[0].cellNodePosition.steps[1],a.parent);return r.setCurrent(f,!1).thenAsync(()=>{let g=T(!0),m=0;function C(x){for(;m<x;){if(!d.includes(m)){let b=f.viewNode.ownerDocument.createElement("td");P(b,"padding","0"),f.viewNode.appendChild(b)}m++}}return h.forEach(x=>{g=g.thenAsync(()=>{let b=x.cell;C(b.anchorSlot.columnIndex);let N=x.cellNodePosition,S=cr(N.steps[0],f);return S.offsetInNode=N.offsetInNode,S.after=N.after,S.fragmentIndex=N.steps[0].fragmentIndex+1,r.setCurrent(S,!1).thenAsync(()=>{let E=x.breakChunkPosition;for(let v=0;v<b.colSpan;v++)d.push(m+v);return m+=b.colSpan,this.layoutCell(b,S,E).thenAsync(()=>(S.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+o-u,T(!0)))})})}),g.thenAsync(()=>(C(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(()=>{var l;this.registerCellFragmentIndex();let o=e.breakAtTheEdge;if(this.currentRowIndex>0){let c=s.rows[this.currentRowIndex-1];c!=null&&c.breakAfter&&(o=Be(o,c.breakAfter))}let r=s.rows[this.currentRowIndex];return r!=null&&r.breakBefore&&(o=Be(o,r.breakBefore)),!e.leadingEdge&&Ee(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o),(l=n.viewNode)!=null&&l.parentNode&&n.viewNode.parentNode.removeChild(n.viewNode),e.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(e.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),e.break=!0,T(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o)&&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.find(o=>o.cell===n);if(s){let o=s.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(o.node);Ym(r,o.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 o=n.copy().modify();o.after=!0,e.nodeContext=o;let r=L("startTableCell"),a,l=this.findBrokenCellAtSlot(s.anchorSlot.columnIndex,n.sourceNode);if(l){let c=l.position;this.formattingContext.cellBreakPositions.splice(l.index,1),n.fragmentIndex=c.cellNodePosition.steps[0].fragmentIndex+1,a=T(c.breakChunkPosition)}else a=this.column.nextInTree(n,e.atUnforcedBreak).thenAsync(c=>{c.viewNode&&n.viewNode.removeChild(c.viewNode);let u=lo(c,0);return T(new Ot(u))});return a.then(c=>{this.layoutCell(s,n,c).then(()=>{this.afterNonInlineElementNode(e),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(e){let n=Qm(e,tn(this.formattingContext),this.column);if(n)return n;let s=e.nodeContext,o=this.formattingContext.getRepetitiveElements(),r=s.display;return r==="table-header-group"&&o&&o.isHeaderSourceNode(s.sourceNode)?(this.inHeader=!0,T(!0)):r==="table-footer-group"&&o&&o.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 o=n.copy().modify();o.after=!1;let r=new dh(this.currentRowIndex,o,this.formattingContext);this.column.breakPositions.push(r)}return T(!0)}afterNonInlineElementNode(e){let n=e.nodeContext,s=this.formattingContext.getRepetitiveElements(),o=n.display;if(o==="table-header-group"?s&&!s.allowInsertRepeatitiveElements&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!1,n.viewNode.parentNode.removeChild(n.viewNode)):P(n.viewNode,"display","table-row-group"):o==="table-footer-group"&&(s&&!s.allowInsertRepeatitiveElements&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!1,n.viewNode.parentNode.removeChild(n.viewNode)):P(n.viewNode,"display","table-row-group")),o&&oc.ignoreList[o])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(oc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var fh=oc,ki=[];function mx(i){let t=ki.findIndex(n=>n.root===i),e=ki[t];return e?e.tableLayoutOption:null}function Cx(i){let t=ki.findIndex(e=>e.root===i);t>=0&&ki.splice(t,1)}var sc=class{layoutEntireTable(t,e){let n=tn(t.formattingContext),s=new hh(n,e);return new fo(s,e.layoutContext).iterate(t)}getColumnWidths(t,e,n,s){let o=t.ownerDocument,r=o.createElement("tr"),a=[];for(let c=0;c<e;c++){let u=o.createElement("td");r.appendChild(u),a.push(u)}t.parentNode.insertBefore(r,t.nextSibling);let l=a.map(c=>{let u=Dt(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 o=n.firstElementChild;for(;o;){if(o.localName==="col"){let r=o.span;for(o.removeAttribute("span"),s-=r;r-- >1;){let a=o.cloneNode(!0);n.insertBefore(a,o),e.push(a)}e.push(o)}o=o.nextElementSibling}for(;s-- >0;)o=n.ownerDocument.createElement("col"),n.appendChild(o),e.push(o)}),e}addMissingColElements(t,e,n,s){if(t.length<n){let o=s.ownerDocument.createElement("colgroup");e.push(o);for(let r=t.length;r<n;r++){let a=s.ownerDocument.createElement("col");o.appendChild(a),t.push(a)}}}normalizeColGroups(t,e,n){let s=t.vertical,o=t.lastRowViewNode;if(!o)return;t.lastRowViewNode=null;let a=o.ownerDocument.createDocumentFragment(),l=t.getColumnCount();if(!(l>0)){t.colGroups=a;return}let c=t.colWidths=this.getColumnWidths(o,l,s,n.clientLayout),u=this.getColGroupElements(e),d=this.normalizeAndGetColElements(u);this.addMissingColElements(d,u,l,e),d.forEach((h,f)=>{P(h,s?"height":"width",`${c[f]}px`)}),u.forEach(h=>{a.appendChild(h.cloneNode(!0))}),t.colGroups=a}doInitialLayout(t,e){let n=tn(t.formattingContext);n.vertical=t.vertical,n.initializeRepetitiveElements(t.vertical),t.sourceNode;let s=mx(t.sourceNode);Cx(t.sourceNode);let o=L("TableLayoutProcessor.doInitialLayout"),r=t.copy();return this.layoutEntireTable(t,e).then(a=>{let l=a.viewNode,c=Dt(e.clientLayout,l,e.vertical),u=e.vertical?c.left:c.bottom;if(u+=(e.vertical?-1:1)*As(t,e.collectElementsOffset()).current,!e.isOverflown(u)&&(!s||!s.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(n)){e.breakPositions.push(new Ch(r)),o.finish(a);return}this.normalizeColGroups(n,l,e),n.updateCellSizes(e.clientLayout),o.finish(null)}),o.result()}hasForcedBreakInRows(t){for(let e=0;e<t.rows.length;e++){let n=t.rows[e];if(n&&(e>0&&Ee(n.breakBefore)||e<t.rows.length-1&&Ee(n.breakAfter)))return!0}return!1}addCaptions(t,e,n){let s=t.captions;s.forEach((o,r)=>{o&&(e.insertBefore(o.viewNode,n),o.side==="top"&&(s[r]=null))})}addColGroups(t,e,n){t.colGroups&&this.getColGroupElements(e).length===0&&(e.insertBefore(t.colGroups.cloneNode(!0),n),P(e,"table-layout","fixed"),P(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=tn(t.formattingContext),s=n.getRootViewNode(t),o=s.firstChild;this.addCaptions(n,s,o),this.addColGroups(n,s,o);let r=new fh(n,e),a=new fo(r,e.layoutContext),l=L("TableFormattingContext.doLayout");return a.iterate(t).thenFinish(l),l.result()}layout(t,e,n){let s=tn(t.formattingContext);return s.getRootViewNode(t)?(n&&oh(t.parent,e),new gh(s,this).layout(t,e)):e.buildDeepElementView(t)}createEdgeBreakPosition(t,e,n,s){return new uh(t,e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return rh(t),!1}finishBreak(t,e,n,s){let o=tn(e.formattingContext);if(e.display==="table-row"){e.sourceNode;let r=o.findRowIndexBySourceNode(e.sourceNode),a;if(e.after?a=o.getRowSpanningCellsOverflowingTheRow(r):a=o.getCellsFallingOnRow(r),o.cellBreakPositions=o.cellBreakPositions.filter(l=>!a.includes(l.cell)),a.length){let l=L("TableLayoutProcessor.finishBreak"),c=0;return l.loopWithFrame(u=>{if(c===a.length){u.breakLoop();return}let d=a[c++],h=o.getCellFragmentOfCell(d),f=h.findAcceptableBreakPosition().nodeContext;let g=h.cellNodeContext,m=g.toNodePosition(),C=new Ot(f.toNodePosition());o.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:C,cell:d});let x=g.viewNode;h.column.layoutContext.processFragmentedBlockEdge(h.cellNodeContext),r<d.rowIndex+d.rowSpan-1&&(x.rowSpan=r-d.rowIndex+1),h.empty?u.continueLoop():h.pseudoColumn.finishBreak(f,!1,!0).then(()=>{bx(h,o,f),u.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),rh(e),o.finishFragment(),l.finish(!0)}),l.result()}}return rh(e),o.finishFragment(),Ci.finishBreak(t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Dn.prototype.clearOverflownViewNodes(t,e,n,s)}};function bx(i,t,e){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,o=i.column,r=i.pseudoColumn.getColumnElement(),a=i.cellNodeContext.viewNode,l=Dt(o.clientLayout,a,s),c=o.getComputedPaddingBorder(a);if(s){let u=l.right-o.footnoteEdge-n.calculateOffset(e)-c.right;P(r,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(e)-l.top-c.top;P(r,"max-height",`${u}px`)}}function rh(i){let t=i.display==="table-row"?i.viewNode.parentElement:i.display==="table"?i.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=i.vertical?f.width:f.height;return d+g},0),s=e[e.length-1],o=Array.from(t.children).indexOf(s),r=Array.from(s.children).reduce((d,h)=>{let f=h.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(d,f):d},0),a=r?t.children[o+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=i.vertical?l.width:l.height,u=n+c;P(a,i.vertical?"width":"height",`${u}px`)}var gh=class extends Ls{constructor(e,n){super();this.tableFormattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.tableFormattingContext.getRepetitiveElements();return!n||!n.doneInitialLayout?new mh(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&n&&n.preventSkippingHeader(),new yh(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()}},mh=class extends wi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}},Ch=class extends On{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 bh(this.position.sourceNode))}},bh=class i{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,ki.push({root:e.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,e){return T(!0)}equalsTo(t){return t instanceof i&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},yh=class extends Pi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){let s=this.formattingContext.getRepetitiveElements();if(s&&!s.isAfterLastContent(e)){let o=new xh(e);n.fragmentLayoutConstraints.some(r=>o.equalsTo(r))||n.fragmentLayoutConstraints.unshift(o)}return this.processor.doLayout(e,n)}},xh=class i extends Tr{constructor(e){super(e);p(this,"flagmentLayoutConstraintType","TableRow");p(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,n,s){let o=this.getRepetitiveElements();return!o||s.pseudoParent||Jn(this.nodeContext.viewNode)||!o.isEnableToUpdateState()?!0:!(n&&!e||e&&e.overflow)}nextCandidate(e){let n=tn(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(e,n).some(o=>o.constraints.some(r=>r.nextCandidate(e)))?!0:super.nextCandidate(e)}postLayout(e,n,s,o){let r=tn(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(n,r),this.cellFragmentLayoutConstraints.forEach(a=>{a.constraints.forEach(l=>{l.postLayout(e,a.breakPosition,s,o)})}),!e){let a=r.getRootViewNode(this.nodeContext);new sc().removeColGroups(r,a),this.removeDummyRowNodes(s)}super.postLayout(e,n,s,o)}finishBreak(e,n){let s=tn(this.nodeContext.formattingContext),o=L("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((l,c)=>l.concat(c.constraints.map(u=>({constraint:u,breakPosition:c.breakPosition}))),[]),a=0;return o.loop(()=>{if(a<r.length){let l=r[a++];return l.constraint.finishBreak(l.breakPosition,n).thenReturn(!0)}else return T(!1)}).then(()=>{o.finish(!0)}),o.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 o=[];for(let r=0;r<s;r++)n.cellFragments[r]&&n.cellFragments[r].forEach(a=>{a&&o.push({fragment:a,breakPosition:a.findAcceptableBreakPosition().nodeContext})});return o}getElementsOffsetsForTableCell(e){let n=tn(this.nodeContext.formattingContext),s=n.findCellFromColumn(e);return s?n.collectElementsOffsetOfUpperCells(s):n.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof i?tn(this.nodeContext.formattingContext)===tn(e.nodeContext.formattingContext):!1}},yx=new sc;function xx(i,t,e,n,s,o){if(!t)return null;if(e===y.table){let r=i.parent;return new Os(r?r.formattingContext:null,i.sourceNode)}return null}function Sx(i){return i instanceof Os?yx:null}je("RESOLVE_FORMATTING_CONTEXT",xx);je("RESOLVE_LAYOUT_PROCESSOR",Sx);function eC(i){return i.reduce((t,e)=>t+e,0)/i.length}function tC(i){let t=eC(i);return eC(i.map(e=>{let n=e-t;return n*n}))}var Sh=class{constructor(t,e){this.layoutResult=t;this.penalty=e}};function Ai(i){return i.vertical?i.width:i.height}function Ri(i,t){i.vertical?i.width=t:i.height=t}var rc=class{constructor(t,e,n){this.layoutContainer=t;this.columnGenerator=e;this.regionPageFloatLayoutContext=n;p(this,"originalContainerBlockSize");this.originalContainerBlockSize=Ai(t)}balanceColumns(t){let e=L("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),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(o=>{if(this.savePageFloatLayoutContexts(o),this.layoutContainer.clear(),!o){s.breakLoop();return}n.push(this.createTrialResult(o)),s.continueLoop()})}).then(()=>{let s=n.reduce((o,r)=>r.penalty<o.penalty?r:o,n[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(s.layoutResult),this.tightenColumnBlockSizes(s.layoutResult.columns),this.postBalance(),e.finish(s.layoutResult)}),e.result()}createTrialResult(t){let e=this.calculatePenalty(t);return new Sh(t,e)}preBalance(t){}postBalance(){Ri(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(t){if(t.length<=1)return;let e=Math.max.apply(null,t.map(n=>n.computedBlockSize));if(!(e<=0))for(let n of t)if(n.vertical){let s=parseFloat(n.element.style.width),o=parseFloat(n.element.style.left);if(isFinite(s)&&isFinite(o)&&s>e){let a=o+s-e;P(n.element,"width",`${e}px`),P(n.element,"left",`${a}px`),n.width=e,n.left=a}}else{let s=parseFloat(n.element.style.height);isFinite(s)&&s>e&&(P(n.element,"height",`${e}px`),n.height=e)}}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)}},Eh=1;function sC(i){let t=i[i.length-1];if(t.penalty===0)return!1;let e=i[i.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)),o=Math.max.apply(null,n.map(r=>r.getMaxBlockSizeOfPageFloats()));return s>o+Eh}function oC(i,t){let e=i[i.length-1].layoutResult.columns,s=Math.max.apply(null,e.map(o=>isNaN(o.blockDistanceToBlockEndFloats)?o.computedBlockSize:o.computedBlockSize-o.blockDistanceToBlockEndFloats+Eh))-Eh;s<Ai(t)?Ri(t,s):Ri(t,Ai(t)-1)}var vh=class extends rc{constructor(e,n,s,o){super(s,e,n);this.columnCount=o;p(this,"originalPosition",null);p(this,"foundUpperBound",!1)}preBalance(e){let s=e.columns.reduce((o,r)=>o+r.computedBlockSize,0);Ri(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 nC(n)?1/0:Math.max.apply(null,n.map(s=>s.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return sC(e);{let n=e[e.length-1];return this.checkPosition(n.layoutResult.position)&&!nC(n.layoutResult.columns)?(this.foundUpperBound=!0,!0):Ai(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)oC(e,this.layoutContainer);else{let n=Math.min(this.originalContainerBlockSize,Ai(this.layoutContainer)+this.originalContainerBlockSize*.1);Ri(this.layoutContainer,n)}}};function nC(i){if(i.length<=1)return!1;let t=i[i.length-1].computedBlockSize,e=i.slice(0,i.length-1),n=Math.max(...i.map(o=>o.lastLineStride||0)),s=n>0?n/2:6;return e.every(o=>t>o.computedBlockSize+s)}var Nh=class extends rc{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 tC(e)}hasNextCandidate(t){return sC(t)}updateCondition(t){oC(t,this.layoutContainer)}};function rC(i,t,e,n,s,o,r){if(t===y.auto)return null;{let a=r.positions.length===0,l=o[o.length-1],c=!!(l&&l.pageBreakType);return a||c?new vh(e,n,s,i):t===y.balance_all?new Nh(e,n,s):(y.balance,null)}}var Nx=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Tx=new Set(Nx);function wx(i){return!(i.toLowerCase()==="none"||Tx.has(i))}var Px=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],kx=new Set(Px),Ax=["fixed","extends"],Rx=new Set(Ax),iv=Symbol();function Wi(i){return i instanceof J&&i.name.toLowerCase()!=="none"}function aC(i){return i.name}function Lx(i){if(i instanceof J)return kx.has(i.name);if(i instanceof X&&i.values.length===2){let t=i.values[0],e=i.values[1];if(t instanceof J){let n=t.name;return Rx.has(n)&&(n==="fixed"&&e instanceof ae||n==="extends"&&Wi(e))}}return!1}function Ix(i){let t=mt(i,"system");return t instanceof J&&t.name==="cyclic"}function Fx(i){let t=mt(i,"system");if(t instanceof J&&t.name==="fixed")return!0;if(t instanceof X&&t.values.length===2){let[e,n]=t.values;return e instanceof J&&e.name==="fixed"&&n instanceof ae}return!1}function Vx(i){let t=mt(i,"system");return t instanceof J?1:t.values[1].num}function Bx(i){let t=mt(i,"system");return t instanceof J&&t.name==="alphabetic"}function Ox(i){let t=mt(i,"system");return t instanceof J&&t.name==="numeric"}function Dx(i){let t=mt(i,"system");return t instanceof J&&t.name==="additive"}function Mx(i){let t=mt(i,"system");if(t instanceof X&&t.values.length===2){let[e,n]=t.values;return e instanceof J&&e.name==="extends"&&Wi(n)}return!1}function _x(i){let t=mt(i,"system");return aC(t.values[1])}function nn(i){return i instanceof z||i instanceof J}function ls(i){return i instanceof z?i.str:i.name}function lC(i){if(nn(i))return!0;if(i instanceof X&&i.values.length===2){let t=i.values[0],e=i.values[1];return nn(t)&&nn(e)}return!1}function Ux(i){if(nn(i))return{prefix:ls(i),suffix:null};{let t=i.values[0],e=i.values[1];return{prefix:ls(t),suffix:ls(e)}}}function iC(i){return i instanceof ae||i instanceof J&&i.name==="infinite"}function ic(i,t){return i instanceof ae?i.num:t?-1/0:1/0}var av=Symbol();function Th(i){if(!(i instanceof X&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];if(!(iC(t)&&iC(e)))return!1;let n=ic(t,!0),s=ic(e,!1);return!(n>s)}function Hx(i){return{lower:ic(i.values[0],!0),upper:ic(i.values[1],!1)}}function cC(i){return i instanceof J&&i.name==="auto"||Th(i)||i instanceof Se&&i.values.length>=1&&i.values.every(t=>Th(t))}function zx(i){return i instanceof J?null:(Th(i)?[i]:i.values).map(e=>Hx(e))}var lv=Symbol();function ac(i){if(!(i instanceof X&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];return t instanceof ae&&t.num>=0&&nn(e)||nn(t)&&e instanceof ae&&e.num>=0}function lc(i){let[t,e]=i.values;return t instanceof ae?[t.num,ls(e)]:[e.num,ls(t)]}function uC(i){return ac(i)}function Gx(i){let[t,e]=lc(i);return{minLength:t,symbol:e}}function dC(i){return nn(i)||i instanceof X&&i.values.length>=1&&i.values.every(t=>nn(t))}function Wx(i){return nn(i)?[ls(i)]:i.values.map(t=>ls(t))}var cv=Symbol();function pC(i){if(ac(i))return!0;if(i instanceof Se&&i.values.length>=1){let t=1/0;for(let e of i.values){if(!ac(e))return!1;let[n]=lc(e);if(n>=t)return!1;t=n}return!0}return!1}function $x(i){if(ac(i)){let[t,e]=lc(i);return[{weight:t,symbol:e}]}else return i.values.map(t=>{let[e,n]=lc(t);return{weight:e,symbol:n}})}var Xx=["auto","bullets","numbers","words","spell-out"],jx=new Set(Xx);function Yx(i){return i instanceof J&&jx.has(i.name)||Wi(i)}function hC(i,t){switch(i){case"system":return Lx(t);case"negative":return lC(t);case"prefix":case"suffix":return nn(t);case"range":return cC(t);case"pad":return uC(t);case"fallback":return Wi(t);case"symbols":return dC(t);case"additive-symbols":return pC(t);case"speak-as":return Yx(t);default:return!0}}function mt(i,t){var n;let e=(n=i[t])==null?void 0:n.value;return e==null?null:e}function qx(i,t){return t.some(({lower:e,upper:n})=>i>=e&&i<=n)}function Pr(i){let t=i.get("decimal");return t||(t=se.createDecimal(i),i.set("decimal",t)),t}var Ii,Fi,Vi,Bi,Oi,Di,Mi,_i,pc,hc,fc,gc,mc,Cc,bc,Oe,wh,fC,gC,mC,CC,Ph,bC,Li,vt=class vt{constructor(t,e){Z(this,Oe);p(this,"_store");Z(this,Ii);Z(this,Fi);Z(this,Vi);Z(this,Bi);Z(this,Oi);Z(this,Di);Z(this,Mi);Z(this,_i);this._store=t;let n=mt(e,"negative");we(this,Ii,n&&lC(n)?Ux(n):null);let s=mt(e,"prefix");we(this,Fi,s&&nn(s)?ls(s):null);let o=mt(e,"suffix");we(this,Vi,o&&nn(o)?ls(o):null);let r=mt(e,"range");we(this,Bi,r&&cC(r)?zx(r):null);let a=mt(e,"pad");we(this,Oi,a&&uC(a)?Gx(a):null);let l=mt(e,"fallback");we(this,Di,l&&Wi(l)?aC(l):null);let c=mt(e,"symbols");we(this,Mi,c&&dC(c)?Wx(c):null);let u=mt(e,"additive-symbols");we(this,_i,u&&pC(u)?$x(u):null)}static create(t,e){return Ix(e)?new as(t,e):Fx(e)?new kh(t,e):Bx(e)?new Rh(t,e):Ox(e)?new cc(t,e):Dx(e)?new Lh(t,e):Mx(e)?new Ih(t,e):new Ah(t,e)}static createDecimal(t){return new cc(t,B(vt,pc))}static createDisc(t){return new as(t,B(vt,hc))}static createSquare(t){return new as(t,B(vt,fc))}static createCircle(t){return new as(t,B(vt,gc))}static createDisclosureOpen(t){return new as(t,B(vt,mc))}static createDisclosureClosed(t){return new as(t,B(this,Cc))}static createNone(t){return new as(t,B(vt,bc))}static get CHINESE_LONGHAND_NAMES(){return uc.NAMES}static createChineseLonghand(t,e){return new uc(t,e)}static createEthiopicNumeric(t){return new Fh(t)}_getNegative(){return B(this,Ii)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return B(this,Fi)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return B(this,Vi)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return B(this,Bi)}static _getRangeFrom(t){return t._getRange()}_getPad(){return B(this,Oi)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(B(this,Di)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return B(this,Mi)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return B(this,_i)}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 pe(this,Oe,Li).call(this,t,new Set)}formatMarker(t){return pe(this,Oe,fC).call(this)+this.format(t)+pe(this,Oe,gC).call(this)}};Ii=new WeakMap,Fi=new WeakMap,Vi=new WeakMap,Bi=new WeakMap,Oi=new WeakMap,Di=new WeakMap,Mi=new WeakMap,_i=new WeakMap,pc=new WeakMap,hc=new WeakMap,fc=new WeakMap,gc=new WeakMap,mc=new WeakMap,Cc=new WeakMap,bc=new WeakMap,Oe=new WeakSet,wh=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},fC=function(){var t;return(t=this._getPrefix())!=null?t:""},gC=function(){var t;return(t=this._getSuffix())!=null?t:". "},mC=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},CC=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},Ph=function(){var t;return(t=this._getFallback())!=null?t:Pr(this._store)},bC=function(t,e){let{minLength:n,symbol:s}=pe(this,Oe,CC).call(this);if(n===0||s==="")return t;let{prefix:o,suffix:r}=pe(this,Oe,wh).call(this),a=e?[...o].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},Li=function(t,e){var a,l,c;if(e.has(this))return pe(a=Pr(this._store),Oe,Li).call(a,t,new Set);if(e.add(this),!qx(t,pe(this,Oe,mC).call(this))){let u=pe(this,Oe,Ph).call(this);return pe(l=u,Oe,Li).call(l,t,e)}let n=this._usesNegativeSign(t),s=n?Math.abs(t):t,o=this._generateInitialRepresentation(s);if(o===null){let u=pe(this,Oe,Ph).call(this);return pe(c=u,Oe,Li).call(c,t,e)}let r=pe(this,Oe,bC).call(this,o,n);if(n){let{prefix:u,suffix:d}=pe(this,Oe,wh).call(this);r=u+r+(d!=null?d:"")}return r},Z(vt,pc,{system:new V(R("numeric"),0),symbols:new V(new X([new z("0"),new z("1"),new z("2"),new z("3"),new z("4"),new z("5"),new z("6"),new z("7"),new z("8"),new z("9")]),0)}),Z(vt,hc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u2022"),0),suffix:new V(new z(" "),0)}),Z(vt,fc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25AA"),0),suffix:new V(new z(" "),0)}),Z(vt,gc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25E6"),0),suffix:new V(new z(" "),0)}),Z(vt,mc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25BE"),0),suffix:new V(new z(" "),0)}),Z(vt,Cc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25B8"),0),suffix:new V(new z(" "),0)}),Z(vt,bc,{system:new V(R("cyclic"),0),symbols:new V(new z(""),0),suffix:new V(new z(""),0)});var se=vt,as=class extends se{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]}},Ui,kh=class extends se{constructor(e,n){super(e,n);Z(this,Ui);we(this,Ui,Vx(n))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var o;let n=this._getSymbols();if(!n||n.length===0)return null;let s=e-B(this,Ui);return(o=n[s])!=null?o:null}};Ui=new WeakMap;var Ah=class extends se{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],o=Math.ceil(t/n);return s.repeat(o)}},Rh=class extends se{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="",o=t;for(;o!==0;)o=o-1,s=e[o%n]+s,o=Math.floor(o/n);return s}},cc=class extends se{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="",o=t;for(;o!==0;)s=e[o%n]+s,o=Math.floor(o/n);return s}},Lh=class extends se{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 o=e.find(r=>r.weight===0);return o?o.symbol:null}let s=t;for(let o of e){let{weight:r,symbol:a}=o;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}},wr,Nt,Xt,Vh=class Vh extends se{constructor(e,n){super(e,n);Z(this,Nt);Z(this,wr);let s=_x(n),o=s.toLowerCase();o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed"?we(this,wr,o):we(this,wr,s)}_getNegative(){var e;return(e=super._getNegative())!=null?e:se._getNegativeFrom(pe(this,Nt,Xt).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:se._getPrefixFrom(pe(this,Nt,Xt).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:se._getSuffixFrom(pe(this,Nt,Xt).call(this))}_getAutoRange(){return se._getAutoRangeFrom(pe(this,Nt,Xt).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:se._getRangeFrom(pe(this,Nt,Xt).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:se._getPadFrom(pe(this,Nt,Xt).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:se._getFallbackFrom(pe(this,Nt,Xt).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:se._getSymbolsFrom(pe(this,Nt,Xt).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:se._getAdditiveSymbolsFrom(pe(this,Nt,Xt).call(this))}_usesNegativeSign(e){return se._useNegativeSignFrom(pe(this,Nt,Xt).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:se._generateInitialRepresentationFrom(pe(this,Nt,Xt).call(this),e)}};wr=new WeakMap,Nt=new WeakSet,Xt=function(e=new Set){var s;if(e.has(this))return Pr(this._store);e.add(this);let n=this._store.get(B(this,wr));return n?n instanceof Vh?pe(s=n,Nt,Xt).call(s,e):n:Pr(this._store)};var Ih=Vh,Kx=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],yc,xc,Hi,Sc,Ec,zi,Mt=class Mt extends se{constructor(e,n){let{chars:s,descriptors:o}=B(Mt,Ec).get(n);super(e,o);Z(this,zi);we(this,zi,s)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let n=B(this,zi);if(e===0)return n.digits[0];let s=[],o=0,r=e;for(;r>0;)s.unshift({digit:r%10,position:o}),r=Math.floor(r/10),o++;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}};yc=new WeakMap,xc=new WeakMap,Hi=new WeakMap,Sc=new WeakMap,Ec=new WeakMap,zi=new WeakMap,Z(Mt,yc,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ae(-9999),new ae(9999)]),0),negative:new V(new z("\u8D1F"),0)}}),Z(Mt,xc,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ae(-9999),new ae(9999)]),0),negative:new V(new z("\u8D1F"),0)}}),Z(Mt,Hi,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ae(-9999),new ae(9999)]),0),negative:new V(new z("\u8CA0"),0)}}),Z(Mt,Sc,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ae(-9999),new ae(9999)]),0),negative:new V(new z("\u8CA0"),0)}}),p(Mt,"NAMES",new Set(Kx)),Z(Mt,Ec,new Map([["simp-chinese-informal",B(Mt,yc)],["simp-chinese-formal",B(Mt,xc)],["trad-chinese-informal",B(Mt,Hi)],["trad-chinese-formal",B(Mt,Sc)],["cjk-ideographic",B(Mt,Hi)]]));var uc=Mt,vc,Nc,Gi,Tc,wc,jt=class jt extends se{constructor(t){super(t,B(jt,vc))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return B(jt,Gi)[1];let e=[],n=t;for(;n>0;)e.push(n%100),n=Math.floor(n/100);let s=e.length,o="";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;o+=B(jt,Nc)[d]+B(jt,Gi)[h]}l?a!==0&&(o+=B(jt,Tc)):r!==0&&(o+=B(jt,wc))}return o}};vc=new WeakMap,Nc=new WeakMap,Gi=new WeakMap,Tc=new WeakMap,wc=new WeakMap,Z(jt,vc,{range:new V(new X([new ae(1),R("infinite")]),0),suffix:new V(new z("/ "),0)}),Z(jt,Nc,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),Z(jt,Gi,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),Z(jt,Tc,"\u137B"),Z(jt,wc,"\u137C");var Fh=jt,ve,dc=class{constructor(){Z(this,ve);we(this,ve,new Map),B(this,ve).set("none",se.createNone(B(this,ve))),B(this,ve).set("decimal",se.createDecimal(B(this,ve))),B(this,ve).set("disc",se.createDisc(B(this,ve))),B(this,ve).set("square",se.createSquare(B(this,ve))),B(this,ve).set("circle",se.createCircle(B(this,ve))),B(this,ve).set("disclosure-open",se.createDisclosureOpen(B(this,ve))),B(this,ve).set("disclosure-closed",se.createDisclosureClosed(B(this,ve)));for(let t of se.CHINESE_LONGHAND_NAMES)B(this,ve).set(t,se.createChineseLonghand(B(this,ve),t));B(this,ve).set("ethiopic-numeric",se.createEthiopicNumeric(B(this,ve)))}define(t,e){if(!wx(t))return null;let n=se.create(B(this,ve),e);return B(this,ve).set(t,n),n}getStyle(t){var e;return(e=B(this,ve).get(t))!=null?e:null}format(t,e){var n;return((n=this.getStyle(t))!=null?n:Pr(B(this,ve))).format(e)}formatMarker(t,e){var n;return((n=this.getStyle(t))!=null?n:Pr(B(this,ve))).formatMarker(e)}};ve=new WeakMap;var $i=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 $i(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 $i(t,t,n))}}addSlippedRange(t){this.map.length==0?this.map.push(new $i(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=Rt(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=Rt(this.map.length,s=>t<=this.map[s].endSlipped),n=this.map[e];return n.endStuckFixed-(n.endSlipped-t)}};function Zx(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}var Oh=class i{constructor(t,e,n,s,o,r,a,l){this.context=t;this.style=e;this.offset=n;this.isRoot=s;this.flowChunk=o;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=o.flowName,this.hasBox()){let c=e._pseudos;if(c&&c.before){let u=new i(t,c.before,n,!1,o,this.isBlock(),a,!0),d=u.styleValue("content");at(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=Be(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ee(this.breakBefore)&&(o.breakBefore=Be(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,e,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let o=new i(this.context,s.after,t,!1,this.flowChunk,e,n,!0),r=o.styleValue("content");at(r)&&(this.afterBox=o)}}}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",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),e=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=vl(t,e,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!co(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}},Dh=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()!==y.none)}push(t,e,n,s){let o=this.lastBox();s&&o&&s.flowName!==o.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=s||o.flowChunk,a=this.atFlowStart||!!s,l=this.isCurrentBoxDisplayed(),c=new Oh(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",y.normal).toString(),s=xl(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=Be(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!")}},Xi=class{constructor(t,e,n,s,o,r,a,l,c,u){this.xmldoc=t;this.scope=n;this.context=s;this.primaryFlows=o;this.validatorSet=r;this.counterListener=a;p(this,"root");p(this,"cascadeHolder");p(this,"last");p(this,"rootStyle",{});p(this,"styleMap",{});p(this,"counterSnapshots",[]);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 Dh(s),this.offsetMap.addStuckRange(d);let h=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,h,d),this.recordCounterSnapshot(d,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),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 o=e[n];o&&(this.rootStyle[n]=new V(o,Cd))}}}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)rs(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,o=this.hasProp(t,this.validatorSet.backgroundProps,"background-image")?t["background-image"].evaluate(this.context):null;(s&&!W(s)||o&&!W(o))&&(this.transferPropsToRoot(t,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let s=0;s<xC.length;s++)if(this.hasProp(t,this.validatorSet.layoutProps,xC[s])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!e){let s=t["font-size"],o=!0;if(s&&!W(s.value)){let l=s.evaluate(this.context);if(l instanceof k){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*ot.lh/ot.em;break;default:{let u=ot[l.unit];u&&(c*=u),o=!1}}this.context.rootFontSize=c,this.context.isRelativeRootFontSize=o}}let r=(n=this.context.rootFontSize)!=null?n:this.context.initialFontSize,a=t["line-height"];if(a&&!W(a.value)){let l=a.evaluate(this.context);if(l instanceof Ue)this.context.rootLineHeight=l.num*r;else if(l instanceof k){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=ot[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 Fm(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}recordCounterSnapshot(t,e,n=[],s){let o={offset:t,counters:Zx(e),changes:Array.from(n||[]),changeTypes:s?{...s}:void 0},r=this.counterSnapshots[this.counterSnapshots.length-1];if(r&&r.offset===t){this.counterSnapshots[this.counterSnapshots.length-1]=o;return}this.counterSnapshots.push(o)}getCounterSnapshotAtOffset(t){if(!this.counterSnapshots.length)return null;let e=Rt(this.counterSnapshots.length,s=>t<this.counterSnapshots[s].offset),n=e===0?0:e-1;return this.counterSnapshots[n]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(t){if(t>=this.lastOffset)return;let e=this.context,n=this.xmldoc.getElementOffset(this.root);if(t<n){let r=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let u=r.page,d=u&&!W(u.value)&&u.value.toString();d&&d.toLowerCase()!=="auto"&&(this.cascade.firstPageType=d)}let a=ne(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),o=this.xmldoc.getNodeOffset(s,0,!1);if(!(o>=this.lastOffset))for(;;){if(s.nodeType!=1)o+=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,o)}o++}if(o>=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 o=0,r=Number.POSITIVE_INFINITY,a=!1,l=!1,c=!1,u=e["flow-options"];if(u){let C=Sg(u.evaluate(this.context,"flow-options"));a=!!C.exclusive,l=!!C.static,c=!!C.last}let d=e["flow-linger"];d&&(r=Wu(d.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let h=e["flow-priority"];h&&(o=Wu(h.evaluate(this.context,"flow-priority"),0));let f=this.breakBeforeValues[s]||null,g=this.flows[t];if(!g){let C=this.boxStack.lastFlowName();g=this.flows[t]=new fl(t,C)}let m=new gl(t,n,s,o,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(Ee(t)){let o=this.flows[n].forcedBreakOffsets;(o.length===0||o[o.length-1]<e)&&o.push(e)}let s=this.breakBeforeValues[e];this.breakBeforeValues[e]=Be(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 o=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=Be(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),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);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(o,"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=Be(u.flowChunk.breakBefore,u.breakBefore));let h=this.boxStack.nearestBlockStartOffset(u);if(h===0||a===this.xmldoc.body){let f=l.page,g=f&&!W(f.value)&&f.value.toString();!this.cascade.firstPageType&&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()===y.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){}},xC=["column-count","column-width","column-fill"];var Ds=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)}},cs=class{constructor(t,e){this.where=t;this.success=e;p(this,"what",-1)}};var No=class i{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 i;for(let e=0;e<this.nodes.length;e++){let n=this.nodes[e],s=new Ds(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 cs(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,o=new Ds(SC);n>=0?e?o.markAsStartAlternate(n):o.markAsEndAlternate(n):e?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,s);let r=new cs(s,!0),a=new cs(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 Ds(SC);e.markAsStartAlternate(t),this.nodes.push(e);let n=new cs(0,!0),s=new cs(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 Ds(t));let n=new cs(e,!0),s=new cs(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 Le}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 o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);e==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let o=0;o<t.connections.length;o++){let r=t.connections[o];r.where+=n,r.what>=0&&(r.what+=n),this.connections.push(r)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+s);if(e==3&&this.connect(this.match,n),e==2||e==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+s);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+s);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+s);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+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]}},Jx=1,vC=2,NC=4,vo=8,Pc=16,Mh=32,kc=64,TC=128,ji=256,Yi=512,_h=1024,wC=2048,PC=4096,kC=8192,Ac=class extends It{constructor(){super()}validateForShorthand(t,e){let n=t[e].visit(this);return n?[n]:null}},Le=class i extends Ac{constructor(e,n,s){super();this.allowed=e;this.idents=n;this.units=s}visitEmpty(e){return this.allowed&Jx?e:null}visitSlash(e){return this.allowed&wC?e:null}visitStr(e){return this.allowed&vC?e:null}visitIdent(e){let n=this.idents[e.name.toLowerCase()];return n||(this.allowed&NC||this.allowed&kc&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&Yi)?e.unit=="%"&&this.allowed&_h?e:null:e.num<0&&!(this.allowed&ji)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&Yi?e:null:e.num<=0&&!(this.allowed&ji)?null:this.allowed&Pc?e:null}visitInt(e){if(e.num==0)return this.allowed&Yi?e:null;if(e.num<=0&&!(this.allowed&ji))return null;if(this.allowed&(Mh|Pc))return e;let n=this.idents[`${e.num}`];return n||null}visitHexColor(e){return this.allowed&kc&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&TC?e:null}visitURange(e){return this.allowed&PC?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){if(this.allowed&kc){if(e.name==="device-cmyk"||e.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Du(e)!==null?e:null;if(CSS.supports("color",e.toString()))return e}if(this.allowed&kC){let n=e.visit(new Xo);if(CSS.supports("background-image",n.toString()))return e}return e.name==="calc"&&this.allowed&(vo|Pc|Mh|ji|Yi|_h)?e:null}visitExpr(e){return this.allowed&2046?e:null}combine(e){let n={},s={};for(let o in this.idents)n[o]=this.idents[o];for(let o in e.idents)n[o]=e.idents[o];for(let o in this.units)s[o]=this.units[o];for(let o in e.units)s[o]=e.units[o];return new i(this.allowed|e.allowed,n,s)}},oe=Object.create(null),SC=new Le(0,oe,oe),qi=class extends Ac{constructor(e){super();p(this,"successTerminal");p(this,"failureTerminal");p(this,"first");this.successTerminal=new Ds(null),this.failureTerminal=new Ds(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,n,s){let o=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 To&&this instanceof To){if(d=new X(e).visit(r.validator),d){a=e.length,r=r.success;continue}}else if(a==0&&!n&&r.validator instanceof Ki&&this instanceof To){if(d=new Se(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===o){o=[];for(let h=0;h<a;h++)o[h]=e[h]}e!==o&&(o[a-s]=d),a++,r=r.success}}return r===this.successTerminal&&(n?o.length>0:a==e.length)?o: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}},To=class extends qi{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new X(e):null}visitCommaList(t){let e=this.first,n=!1;for(;e;){if(e.validator instanceof Ki){n=!0;break}e=e.failure}if(n){let s=this.validateList(t.values,!1,0);return s===t.values?t:s?new Se(s):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},Ki=class extends qi{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 Se(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}},Uh=class extends qi{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 Ft(e.name,n):null}},Rc=class{tryParse(t,e,n){return e}success(t,e){}},Lc=class extends Rc{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 o=this.validator.validateForShorthand(e,n);if(o){let r=o.length,a=r>1?new X(o):o[0];return this.success(a,s),n+r}return n}success(e,n){n.values[this.name]=e}},Hh=class extends Lc{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}},zh=class extends Rc{constructor(e,n){super();this.nodes=e;this.slash=n}tryParse(e,n,s){let o=n;if(this.slash)if(e[n]==jn){if(++n==e.length)return o}else return o;let r=this.nodes[0].tryParse(e,n,s);if(r==n)return o;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}},Zi=class extends It{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 Lc(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,o;if(!this.error){for(let r of this.propList)n.simpleProperty(r,(o=(s=this.values[r])!=null?s:this.validatorSet.defaultValues[r])!=null?o:y.initial,e);return!0}return!1}propagateDefaultingValue(e,n,s){for(let o of this.propList)s.simpleProperty(o,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)}},Ms=class extends Zi{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}},Ic=class extends Zi{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 Hh(this.validatorSet,this.propList)}},Gh=class extends Zi{constructor(){super()}validateList(t){let e=t.length;for(let n=0;n<t.length;n++)if(t[n]===jn){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 o;if(e+1<t.length)for(o=e+n+1;o>=t.length;)o=o-(o==e+2?1:2);else o=s;let r=[t[s],t[o]];if(this.syntax[n].tryParse(r,0,this)!=2)return this.error=!0,0}return t.length}},Wh=class extends Ms{constructor(){super()}mergeIn(t,e){var n,s;for(let o of this.propList){let r=(s=(n=e[o])!=null?n:this.validatorSet.defaultValues[o])!=null?s:y.initial,a=t[o];a||(a=[],t[o]=a),a.push(r)}}visitCommaList(t){let e={};for(let n=0;n<t.values.length;n++)if(this.values={},t.values[n]instanceof Se?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 Se(e[n]);return null}},$h=class extends Ms{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 o=this.validatorSet.validators;if(!t[e].visit(o["font-size"]))return this.error=!0,e;if(this.values["font-size"]=t[e++],t[e]===jn){if(e++,e+2>t.length)return this.error=!0,e;if(!t[e].visit(o["line-height"]))return this.error=!0,e;this.values["line-height"]=t[e++]}let r=e==t.length-1?t[e]:new X(t.slice(e,t.length));return r.visit(o["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 Se(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}},Xh=class extends Ms{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=[y.auto,y.auto];break;case"none":t=[R("no-autospace"),R("space-all")];break}return super.validateList(t)}},eS=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],jh=class extends Ms{constructor(){super()}init(t,e){super.init(t,e);for(let n in this.validatorSet.validators)eS.includes(n)||this.propList.push(n)}validateList(t){return this.error=!0,0}},EC={SIMPLE:Ms,INSETS:Ic,INSETS_SLASH:Gh,COMMA:Wh,FONT:$h,TEXT_SPACING:Xh,ALL:jh},tS=["initial-letter"],Yh=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 k(e.num,e.text);else if(e.type==7)n=new zo(e.text);else if(e.type==1)n=R(e.text);else throw new Error("unexpected replacement");if(t.isPrimitive()){let o=t.nodes[0].validator.idents;for(let r in o)o[r]=n;return t}throw new Error("unexpected replacement")}newGroup(t,e){let n=new No;if(t=="||"){for(let o=0;o<e.length;o++){let r=new No;r.startClause(o),r.addGroup(e[o],1),r.endClause(o),n.addGroup(r,o==0?1:4)}let s=new No;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 o=0;o<e.length;o++)n.addGroup(e[o],o==0?1:s);return n}}addCounts(t,e,n){let s=new No;for(let o=0;o<e;o++)s.addGroup(t.clone(),1);if(n==Number.POSITIVE_INFINITY)s.addGroup(t,3);else for(let o=e;o<n;o++)s.addGroup(t.clone(),2);return s}primitive(t){let e=new No;return e.addPrimitive(t),e}newFunc(t,e){let n;switch(t){case"COMMA":n=new Ki(e);break;case"SPACE":n=new To(e);break;default:n=new Uh(t.toLowerCase(),e);break}return this.primitive(n)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Le(kc,oe,oe)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Le(kC,oe,oe)),this.namedValidators.POS_INT=this.primitive(new Le(Mh,oe,oe)),this.namedValidators.POS_NUM=this.primitive(new Le(Pc,oe,oe)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Le(vo,oe,{"%":G})),this.namedValidators.NEGATIVE=this.primitive(new Le(ji,oe,oe)),this.namedValidators.ZERO=this.primitive(new Le(Yi,oe,oe)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Le(_h,oe,oe)),this.namedValidators.POS_LENGTH=this.primitive(new Le(vo,oe,{em:G,ex:G,ch:G,rem:G,lh:G,rlh:G,vw:G,vh:G,vi:G,vb:G,vmin:G,vmax:G,pvw:G,pvh:G,pvi:G,pvb:G,pvmin:G,pvmax:G,cm:G,mm:G,in:G,px:G,pt:G,pc:G,q:G})),this.namedValidators.POS_ANGLE=this.primitive(new Le(vo,oe,{deg:G,grad:G,rad:G,turn:G})),this.namedValidators.POS_TIME=this.primitive(new Le(vo,oe,{s:G,ms:G})),this.namedValidators.FREQUENCY=this.primitive(new Le(vo,oe,{Hz:G,kHz:G})),this.namedValidators.RESOLUTION=this.primitive(new Le(vo,oe,{dpi:G,dpcm:G,dppx:G})),this.namedValidators.URI=this.primitive(new Le(TC,oe,oe)),this.namedValidators.URANGE=this.primitive(new Le(PC,oe,oe)),this.namedValidators.IDENT=this.primitive(new Le(NC,oe,oe)),this.namedValidators.STRING=this.primitive(new Le(vC,oe,oe)),this.namedValidators.SLASH=this.primitive(new Le(wC,oe,oe));let t={"font-family":R("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 o=n.text;if(t.consume(),e!=2){if(t.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(o)||(this.prefixes[o]=s)}else if(t.token().type!=18)throw new Error("':' expected");return o}parseValidators(t){for(;;){let e=this.readNameAndPrefixes(t,1);if(!e)return;let n=[],s=[],o="",r,a=!0,l=()=>{if(n.length==0)throw new Error("No values");return n.length==1?n[0]:this.newGroup(o,n)},c=d=>{if(a)throw new Error(`'${d}': unexpected`);if(o&&o!=d)throw new Error(`mixed operators: '${d}' and '${o}'`);o=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()]=R(d.text),n.push(this.primitive(new Le(0,h,oe)))}a=!1;break;case 5:{let h={};h[`${d.num}`]=new ae(d.num),n.push(this.primitive(new Le(0,h,oe))),a=!1;break}case 34:c("|");break;case 25:c("||");break;case 14:a||c(" "),s.push({vals:n,op:o,b:"["}),o="",n=[],a=!0;break;case 6:a||c(" "),s.push({vals:n,op:o,b:"(",fn:d.text}),o="",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),o=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)),o=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 To(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(R(s.text));break;case 4:n.push(new Ue(s.num));break;case 5:n.push(new ae(s.num));break;case 3:n.push(new k(s.num,s.text));break;default:throw new Error("unexpected token")}}this.defaultValues[e]=n.length>1?new X(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 Ms,s.setOwner(this);let o=!1,r=[],a=!1,l=[],c=[];for(;!o;)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 Ic){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 zh(r,a),d=l.pop();r=d.syntax,a=d.slash,r.push(u);break}case 17:o=!0,t.consume();break;default:throw new Error("unexpected token")}s.init(r,c),this.shorthands[e]=s}}parse(t){let e=new it(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 o=this.shorthands[s],r=o?o.propList:[s];for(let a of r)e[a]=(n=this.defaultValues[a])!=null?n:y.initial}return e}validatePropertyAndHandleShorthand(t,e,n,s){let o=s.ruleType;if(Vt(t)||o==="font-face"||nS(e)){s.simpleProperty(t,e,n);return}if(o==="counter-style"){hC(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&&!vu.includes(`-${r}-`)||s.unknownProperty(a,e);return}else if(tS.includes(t)&&!Object.keys(c).some(d=>Mr(d?`-${d}-`:"",t))){s.unknownProperty(a,e);return}let u=this.validators[t];if(u){let d=W(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();W(e)?d.propagateDefaultingValue(e,n,s):(e.visit(d),d.finish(n,s)||s.invalidPropertyValue(a,e))}}};function Kh(){let i=new Yh;return i.initBuiltInValidators(),i.parse(cd),i}var qh=class extends It{constructor(){super(...arguments);p(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function nS(i){let t=new qh;return i.visit(t),t.varFound}var gv=`OTTO${new Date().valueOf()}`;function Zh(i){return Object.keys(i).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function oS(i){let t=new st;for(let e of Zh(i))t.append(`${e}:${i[e].toString()};`);return t.toString()}function RC(i,t){let e={};for(let n in i)e[n]=ne(i,n).evaluate(t,n);return e}var Qi=class{constructor(t){this.properties=t;p(this,"fontTraitKey");p(this,"src");p(this,"blobURLs",[]);p(this,"blobs",[]);p(this,"family");this.fontTraitKey=oS(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 {
1844
+ }`;function uo(i,t,e){let n=I("fetchFromURL"),s={method:e||"GET",mode:"cors"},o=n.suspend(),r={status:0,statusText:"",url:i,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(i,s).then(a=>{var l;if(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)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(i)?(r.contentType="text/html",a.arrayBuffer().then(c=>new TextDecoder("Shift_JIS").decode(c))):(/^data:,(<|%3c)/i.test(i)&&(r.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?r.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?r.responseBlob=Pd([a]):t==="json"?r.responseText=JSON.stringify(a):typeof a=="string"&&(r.responseText=a),o.schedule(r)}).catch(a=>{r.status>=400?B.warn(`Error fetching ${i} (${r.status}${r.statusText?" "+r.statusText:""})`):B.warn(a,`Error fetching ${i}`),o.schedule(r)}),n.result()}function Pd(i,t){let e=t||"application/octet-stream";return new Blob(i,{type:e})}function om(i){let t=I("readBlob"),e=new FileReader,n=t.suspend(e);return e.addEventListener("load",()=>{n.schedule(e.result)},!1),e.readAsArrayBuffer(i),t.result()}function rm(i){return URL.createObjectURL(i)}var co=class{constructor(t,e){this.parser=t;this.type=e;p(this,"resources",{});p(this,"fetchers",{})}load(t,e,n){t=Gt(t);let s=this.resources[t];return typeof s!="undefined"?w(s):this.fetch(t,e,n).get()}fetchInner(t,e,n){let s=I("fetch"),o=t.endsWith("?viv-toc-box");o&&(t=t.replace("?viv-toc-box",""));let r=te("user-agent.xml",cn),a=!o&&t===r;return a&&(t=`data:application/xml,${encodeURIComponent(xd)}`),uo(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:""})`);o?(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=Gt(t),this.resources[t])return null;let o=this.fetchers[t];return o||(o=new Ln(()=>this.fetchInner(t,e,n),`Fetch ${t}`),this.fetchers[t]=o,o.start()),o}get(t){return this.resources[Gt(t)]}delete(t){delete this.resources[Gt(t)]}};function CS(i,t){let e=i.responseText;return w(e?_o(e):null)}function im(){return new co(CS,"text")}function Xt(i,t,e){let n=new Ln(()=>{let s=I("loadElement"),o=s.suspend(i),r=!1,a=null,l=c=>{r||(r=!0,a!==null&&(clearTimeout(a),a=null),o.schedule(c?c.type:"timeout"))};if(i.addEventListener("load",l,!1),i.addEventListener("error",l,!1),i.addEventListener("abort",l,!1),i.namespaceURI=="http://www.w3.org/2000/svg")t&&i.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(i.localName==="script")a=setTimeout(l,3e3);else if(t)if(i.localName==="img"){let c=i;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 i.src=t,e&&(i.alt=e);return s.result()},`loadElement ${t||i.localName}`);return n.start(),n}var am=0,bS=16777216,kd=33554432,hl=50331648,fl=67108864,yS=83886080,SS=100663296;var pi=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 am;case"User":return SS;default:return yS}}getBaseSpecificity(){switch(this.flavor){case"UA":return am;case"User":return bS;default:return kd}}},lr=class extends pi{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;B.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,o){this.slave.attributeSelector(e,n,s,o)}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)}},dl=class extends pi{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()}},nn=class extends dl{constructor(t,e,n){super(t,e,n)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.pushHandler(new dl(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())}},Ie=[],pl=[],be=[],Le=[],tn=[],dt=[],Be=[],We=[],Ce=[],Ke=[],gt=[],ze=[],Oe=[];var ir=55,ar=56,ul=57;Ie[1]=28,Ie[36]=29,Ie[7]=29,Ie[9]=29,Ie[14]=29,Ie[18]=29,Ie[50]=29,Ie[20]=30,Ie[13]=27,Ie[0]=200,pl[1]=46,pl[0]=200,dt[1]=2,dt[36]=4,dt[7]=6,dt[9]=8,dt[14]=10,dt[18]=14,dt[50]=42,be[37]=11,be[23]=12,be[35]=56,be[1]=1,be[36]=3,be[7]=5,be[9]=7,be[14]=9,be[12]=13,be[18]=55,be[50]=58,be[16]=41,Le[37]=11,Le[23]=12,Le[35]=56,Le[1]=1,Le[36]=3,Le[7]=5,Le[9]=7,Le[14]=9,Le[18]=55,tn[1]=2,tn[36]=4,tn[7]=6,tn[9]=8,tn[18]=14,tn[50]=42,tn[14]=10,tn[12]=13,Be[1]=15,Be[7]=16,Be[4]=17,Be[5]=18,Be[3]=19,Be[2]=20,Be[8]=21,Be[27]=57,Be[16]=22,Be[19]=23,Be[6]=24,Be[11]=25,Be[17]=26,Be[13]=48,Be[31]=47,Be[23]=54,Be[0]=44,We[1]=31,We[4]=32,We[5]=32,We[3]=33,We[2]=34,We[10]=40,We[6]=38,We[31]=36,We[24]=36,We[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,Ke[0]=200,Ke[12]=50,Ke[13]=51,Ke[14]=50,Ke[15]=51,Ke[10]=50,Ke[11]=51,Ke[17]=53,gt[0]=200,gt[12]=50,gt[13]=52,gt[14]=50,gt[15]=51,gt[10]=50,gt[11]=51,gt[17]=53,ze[0]=200,ze[12]=50,ze[13]=51,ze[14]=50,ze[15]=51,ze[10]=50,ze[11]=51,Oe[11]=0,Oe[16]=0,Oe[22]=1,Oe[18]=1,Oe[26]=2,Oe[25]=2,Oe[38]=3,Oe[37]=3,Oe[48]=3,Oe[47]=3,Oe[39]=3,Oe[49]=3,Oe[41]=3,Oe[23]=4,Oe[24]=4,Oe[36]=5,Oe[19]=5,Oe[21]=5,Oe[0]=6,Oe[ir]=2,Oe[ar]=2;var Ns=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($)}return n}valStackReduce(t,e){let n=this.valStack,s=n.length,o=0,r;do if(r=n[--s],t===")"&&r instanceof An){if(r.text===")")o++;else if(r.text==="("){if(o===0)return null;o--}}while(typeof r!="undefined"&&typeof r!="string");let a=n.length-(s+1);if(a>1&&n.splice(s+1,a,new X(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=gt);let c=new Bt(n[s-1],this.extractVals(",",s+1));if(n.splice(s-1,a+2,c),c.name==="var"){let u=c.values[0]instanceof Q&&c.values[0].name;(!Dt(u)||u===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${c.toString()}`,e),this.actions=gt)}return c}if(t!=";"||s>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=gt,null;if(a>1)return new ve(this.extractVals(",",s+1));let l=n[0];return l instanceof _e?l:l?new An(l.toString()):$}exprError(t,e){this.actions=this.propName?gt:Ke,B.warn(t,e.toString())}exprStackReduce(t,e){let n=this.valStack,s=this.handler,o=n.pop(),r;for(;;){let a=n.pop();if(t==11){let l=[o];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 Ma(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();o=new Yn(s.getScope(),Zr(u,c),l),t=0;continue}}if(a==10){o.isMediaName()&&(o=new Kr(s.getScope(),o,null)),t=0;continue}}else if(typeof a=="string"){n.push(a);break}if(a<0)if(a==-31)o=new $t(s.getScope(),o);else if(a==-24)o=new kn(s.getScope(),o);else if(a==-ul)o=new Ba(s.getScope(),o);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if(Oe[t]>Oe[a]){n.push(a);break}switch(r=n.pop(),a){case 26:o=new zo(s.getScope(),r,o);break;case ir:o=new Da(s.getScope(),r,o);break;case ar:o=new _a(s.getScope(),r,o);break;case 25:o=new Go(s.getScope(),r,o);break;case 38:o=new Ua(s.getScope(),r,o);break;case 37:o=new za(s.getScope(),r,o);break;case 48:o=new Ha(s.getScope(),r,o);break;case 47:o=new Js(s.getScope(),r,o);break;case 39:case 49:o=new Cs(s.getScope(),r,o);break;case 41:o=new Ga(s.getScope(),r,o);break;case 23:o=new Xr(s.getScope(),r,o);break;case 24:o=new jr(s.getScope(),r,o);break;case 36:o=new eo(s.getScope(),r,o);break;case 19:o=new Yr(s.getScope(),r,o);break;case 21:o=new $o(s.getScope(),r,o);break;case 18:if(n.length>1)switch(n[n.length-1]){case 22:n.pop(),o=new $a(s.getScope(),n.pop(),r,o);break;case 10:if(r.isMediaName())o=new Kr(s.getScope(),r,o);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(o),!1;default:return this.exprError("F_UNEXPECTED_STATE",e),!1}}}return n.push(o),!1}readSupportsTest(t){let e=t.type===6,n=this.tokenizer,s,o;if(e)o=t.text,s=t.position+o.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(),o=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&&o==="selector"&&l>0?"":n.input.substring(s,c).trim();return new Wa(this.handler.getScope(),o,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()}}skipPseudoFunctionContents(){let t=0;for(;;){switch(this.tokenizer.token().type){case 0:return!1;case 11:if(t===0)return!0;t--;break;case 10:case 6:t++;break}this.tokenizer.consume()}}readNthPseudoParams(){let t=!1,e=this.tokenizer.token();if(e.type===23)t=!0,this.tokenizer.consume(),e=this.tokenizer.token();else if(e.type===1&&(e.text==="even"||e.text==="odd"))return this.tokenizer.consume(),[2,e.text==="odd"?1:0];switch(e.type){case 3:if(t&&e.num<0)return null;case 1:if(t&&e.text.charAt(0)==="-")return null;if(e.text==="n"||e.text==="-n"){if(t&&e.precededBySpace)return null;let n=e.text==="-n"?-1:1;e.type===3&&(n=e.num);let s=0;this.tokenizer.consume(),e=this.tokenizer.token();let o=e.type===24,r=e.type===23||o;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,o&&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 o of s)switch(o){case"vertical":e=xt(n,e,new $t(n,new Se(n,"pref-horizontal")));break;case"horizontal":e=xt(n,e,new Se(n,"pref-horizontal"));break;case"day":e=xt(n,e,new $t(n,new Se(n,"pref-night-mode")));break;case"night":e=xt(n,e,new Se(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":case"footnote":return!0}return!1}runParser(t,e,n,s,o,r){let a=this.handler,l=this.tokenizer,c=this.valStack,u,d,h,f,g,m,b,y=null;for(n&&(this.inStyleDeclaration=!0),s&&(this.exprContext=2,this.valStack.push("{"));t>0;--t){if(u=l.token(),o&&y===null&&(y=u.position-1,l.input[y]==="("&&y++),this.actions===Be&&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 An(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=gt):(this.actions=dt,a.startSelectorRule());continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Be,c.splice(0,c.length);continue;case 46:if(l.nthToken(1).type!=18){this.actions=gt,a.error("E_CSS_COLON_EXPECTED",l.nthToken(1));continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Be,c.splice(0,c.length);continue;case 29:this.actions=dt,a.startSelectorRule();continue;case 1:if(!u.precededBySpace){this.actions=ze,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),o?this.actions=Le:this.actions=be,l.consume();break;case 36:a.tagSelector(h,null),o?this.actions=Le:this.actions=be,l.consume();break;default:this.actions=Ke,a.error("E_CSS_NAMESPACE",u)}else this.actions=Ke,a.error("E_CSS_UNDECLARED_PREFIX",u);else a.tagSelector(this.defaultNamespaceURI,u.text),o?this.actions=Le:this.actions=be,l.consume();continue;case 3:if(!u.precededBySpace){this.actions=ze,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),o?this.actions=Le:this.actions=be,l.consume();break;case 36:a.tagSelector(null,null),o?this.actions=Le:this.actions=be,l.consume();break;default:this.actions=Ke,a.error("E_CSS_NAMESPACE",u)}else a.tagSelector(this.defaultNamespaceURI,null),o?this.actions=Le:this.actions=be,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),o?this.actions=Le:this.actions=be,l.consume();continue;case 7:u.precededBySpace&&a.descendantSelector();case 8:a.classSelector(u.text),o?this.actions=Le:this.actions=be,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(),o?this.actions=Le:this.actions=be;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=be:this.actions=ze;continue;case"lang":case"href-epub-type":case"href-role-type":if(u=l.token(),u.type===1){b=[u.text],l.consume(),(f==="href-epub-type"||f==="href-role-type")&&l.token().type===16&&(l.consume(),u=l.token(),u.type===1&&(b.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(b=this.readNthPseudoParams(),b)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,b),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?o?this.actions=Le:this.actions=be:this.actions=ze;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)b.push(d.text),l.consume();else break e;break}else break;else break e;default:if(b=[],!this.skipPseudoFunctionContents())break e}if(u=l.token(),u.type==11){a.pseudoclassSelector(f,b),l.consume(),o?this.actions=Le:this.actions=be;continue}break}a.error("E_CSS_PSEUDOCLASS_SYNTAX",u),this.actions=Ke;continue;case 58:u.precededBySpace&&a.descendantSelector();case 42:switch(l.consume(),u=l.token(),u.type){case 1:a.pseudoelementSelector(u.text,null),o?this.actions=Le:this.actions=be,l.consume();continue;case 6:if(f=u.text,l.consume(),f=="nth-fragment"){if(b=this.readNthPseudoParams(),b===null)break}else b=this.readPseudoParams();if(u=l.token(),u.type==11){a.pseudoelementSelector(f,b),o?this.actions=Le:this.actions=be,l.consume();continue}break}a.error("E_CSS_PSEUDOELEM_SYNTAX",u),this.actions=Ke;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=ze,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=ze,a.error("E_CSS_UNDECLARED_PREFIX",u),l.consume();continue}if(l.consume(),u=l.token(),u.type!=1){this.actions=ze,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),o?this.actions=Le:this.actions=be,l.consume();continue;default:this.actions=ze,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=ze,a.error("E_CSS_ATTR_VAL_EXPECTED",u);continue}if(u.type!=15){this.actions=ze,a.error("E_CSS_ATTR",u);continue}o?this.actions=Le:this.actions=be,l.consume();continue;case 11:a.childSelector(),this.actions=tn,l.consume();continue;case 12:a.adjacentSiblingSelector(),this.actions=tn,l.consume();continue;case 56:a.followingSiblingSelector(),this.actions=tn,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=Ie,l.consume();continue;case 41:a.nextSelector(),this.actions=dt,l.consume();continue;case 15:c.push(R(u.text)),l.consume();continue;case 16:g=parseInt(u.text,16),c.push(new jo(u.text)),l.consume();continue;case 17:c.push(new Ue(u.num)),l.consume();continue;case 18:c.push(new ce(u.num)),l.consume();continue;case 19:c.push(new A(u.num,u.text)),l.consume();continue;case 20:c.push(new z(u.text)),l.consume();continue;case 21:c.push(new ke(te(u.text,this.baseURL))),l.consume();continue;case 57:c.push(new Jr(u.text)),l.consume();continue;case 22:this.valStackReduce(",",u),c.push(","),l.consume();continue;case 23:c.push(qn),l.consume();continue;case 24:f=u.text.toLowerCase(),f=="-epubx-expr"||f=="env"?(this.actions=We,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 An("+")),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?pl:Ie;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 Se(a.getScope(),Zr(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 qr(a.getScope(),!0,d.text))):(u.text.toLowerCase()=="only"&&(l.consume(),u=d),c.push(new qr(a.getScope(),!1,u.text)));else if(this.exprContext===4&&u.text.toLowerCase()==="not"&&c[c.length-1]!==ir&&c[c.length-1]!==ar&&(d.type===10||d.type===6)){c.push(-ul),l.consume();continue}else c.push(new Se(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 we(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 dn(a.getScope(),u.num,f)),l.consume(),this.actions=Ce;continue;case 34:c.push(new we(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 Wo(a.getScope(),u.num)),l.consume(),this.actions=Ce);continue;case 36:c.push(-u.type),l.consume();continue;case 37:this.actions=We,this.exprStackReduce(u.type,u),c.push(u.type),l.consume();continue;case 45:u.text.toLowerCase()==="and"&&c[c.length-2]!==ar&&c[c.length-2]!==-ul?(this.actions=We,this.exprStackReduce(ir,u),c.push(ir),l.consume()):u.text.toLowerCase()==="or"&&c[c.length-2]!==ir&&c[c.length-2]!==-ul?(this.actions=We,this.exprStackReduce(ar,u),c.push(ar),l.consume()):this.exprError("E_CSS_SYNTAX",u);continue;case 39:this.exprStackReduce(u.type,u)&&(this.actions=Be),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=Ie)),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=Ie,l.consume(),!1):(this.importCondition=c.pop(),this.importReady=!0,this.actions=Ie,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=Ie,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=We,c.push("{");continue}a.error("E_CSS_IMPORT_SYNTAX",u),this.actions=Ke;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=Ke;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=Ke;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"-epubx-region":l.consume(),a.startRegionRule(),this.regionRule=!0,this.actions=dt;continue;case"page":l.consume(),a.startPageRule(),this.pageRule=!0,this.actions=tn;continue;case"-adapt-footnote-area":case"footnote":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){let C=u.text;l.consume(),l.consume(),a.startFootnoteRule(C),this.ruleStack.push(f==="footnote"?"footnote":"-adapt-footnote-area"),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(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=We,c.push("{");continue;case"media":l.consume(),this.propName=null,this.exprContext=2,this.actions=We,c.push("{");continue;case"supports":l.consume(),this.propName=null,this.exprContext=4,this.actions=We,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,N=null,x=[];for(u.type==1&&(C=u.text,l.consume(),u=l.token()),u.type==18&&l.nthToken(1).type==1&&(N=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;)x.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,N,x);break;case"-epubx-partition":a.startPartitionRule(C,N,x);break;case"-epubx-partition-group":a.startPartitionGroupRule(C,N,x);break}this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":a.error(`E_CSS_UNEXPECTED_AT${f}`,u),this.actions=ze;continue;default:a.error(`E_CSS_AT_UNKNOWN ${f}`,u),this.actions=Ke;continue}a.error(`E_CSS_AT_SYNTAX ${f}`,u),this.actions=Ke;continue;case 50:this.errorBrackets.push(u.type+1),l.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ie;continue}case 51:if(o&&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=Ie),l.consume();continue;case 53:if(o&&this.errorBrackets.length==0&&u.type==16){a.nextSelector(),this.actions=dt,y=u.position+1,l.consume();continue}this.errorBrackets.length==0&&(this.actions=Ie),l.consume();continue;case 200:return!0;default:if(s)return this.exprStackReduce(11,u)?(this.result=c.pop(),!0):!1;if(o){if(this.actions===ze)switch(u.type){case 16:this.errorBrackets.length==0&&(a.nextSelector(),y=u.position+1,this.actions=dt),l.consume();continue;case 11:if(this.errorBrackets.length==0)return a.endFuncWithSelector(),l.consume(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==u.type&&this.errorBrackets.pop(),l.consume();continue;case 12:case 14:case 10:this.errorBrackets.push(u.type+1),l.consume();continue;case 6:this.errorBrackets.push(11),l.consume();continue;case 13:case 15:this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==u.type&&this.errorBrackets.pop(),l.consume();continue;default:l.consume();continue}switch(u.type){case 16:case 11:if(this.actions===dt)a.error("E_CSS_SYNTAX",u);else{let C=l.input.substring(y,u.position);a.pushSelectorText(C),y=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=be;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=ze;continue}if(this.actions!==Ke&&this.actions!==ze&&this.actions!==gt){if(u.type==54)a.error("E_CSS_SYNTAX",u);else if(this.actions===Be){switch(u.type){case 10:case 12:case 14:this.errorBrackets.push(u.type+1);break}c.push(new An(u.toString())),l.consume();continue}else if(u.type===12&&this.actions==We&&c.length>0){a.startMediaRule(c.pop()),this.ruleStack.push("media"),a.startRuleBody(),this.actions=Ie,l.consume();continue}else{if(u.type===17&&this.actions==We)return this.actions=Ie,l.consume(),!1;a.error("E_CSS_SYNTAX",u)}this.isInsidePropertyOnlyRule()?this.actions=gt:this.actions=ze;continue}l.consume();continue}}return!1}},hi=class extends pi{constructor(e){super(null);this.scope=e}error(e,n){B.warn(e,n.toString())}getScope(){return this.scope}};function xS(i,t,e,n,s){let o=um(t),r=Xg(i.input);return r!==i.input?lm(new ot(r,o),o,e,n,s):lm(i,o,e,n,s)}function lm(i,t,e,n,s){let o=I("parseStylesheet"),r=new Ns(Ie,i,t,e),a=null;return s&&(a=ES(new ot(s,t),t,e)),a=r.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),o.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=I("parseStylesheet.import");return Ad(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=o.timeSlice();if(l.isPending)return l}return w(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function gl(i,t,e,n,s){let o=um(t);return Qn("parseStylesheetFromText",r=>{let a=new ot(i,o);xS(a,o,e,n,s).thenFinish(r)},(r,a)=>{B.warn(a,`Failed to parse stylesheet text: ${i}`),r.finish(!1)})}function um(i){if(i instanceof lr)return i;if(i instanceof nn){if(i.owner)return i.owner;let t=new lr;return t.flavor=i.flavor,t.slave=i,i.owner=t,t}return i}function Ad(i,t,e,n){return Qn("parseStylesheetFromURL",s=>{uo(i).then(o=>{o.responseText?gl(o.responseText,t,i,e,n).then(r=>{r||B.warn(`Failed to parse stylesheet from ${i}`),s.finish(!0)}):s.finish(!0)})},(s,o)=>{B.warn(o,"Exception while fetching and parsing:",i),s.finish(!0)})}function Ts(i,t,e){let n=new Ns(Be,t,new hi(i),e);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function dm(i,t,e){new Ns(pl,i,t,e).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function ES(i,t,e){let n=new Ns(We,i,t,e);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var vS={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function NS(i){return!!vS[i]}function pm(i,t,e){if(t instanceof ne&&t.str==="viv-leader")return new D(t);if(e==="content"&&t instanceof ne)return new D(t);let n=t.evaluate(i);switch(typeof n){case"number":return NS(e)?n==Math.round(n)?new ce(n):new Ue(n):new A(n,"px");case"string":return n?e==="content"?new z(n):Ts(t.scope,new ot(n,null),""):$;case"boolean":return n?S._true:S._false;case"undefined":return $}throw new Error("E_UNEXPECTED")}var TS="data-vivliostyle-flow-root";function fm(i){return i.getAttribute(TS)==="true"}function hm(i){let t=(i==null?void 0:i.toString())||"block",e;switch(t){case"inline-flex":e="flex";break;case"inline-grid":e="grid";break;case"inline-table":e="table";break;case"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":e="block";break;default:e=t}return R(e)}function ur(i){return i===S.absolute||i===S.fixed}function ho(i){return i instanceof Bt&&i.name==="running"}function Rd(i,t,e,n){return i===S.none||(ur(t)?(e=S.none,i=hm(i)):(e&&e!==S.none&&!W(e)||n)&&(i=hm(i))),{display:i,position:t,float:e}}function ml(i,t,e,n){return Rd(i,t,e,n).display===S.block}function Cl(i){return i instanceof Q||i instanceof X||typeof i=="string"}function Et(i){if(!Cl(i))return!1;let t=i.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 fo(i){return Cl(i)?i.toString().includes("list-item"):!1}function gm(i){if(!Cl(i))return!1;switch(i.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function bl(i){if(!Cl(i))return!1;switch(i.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function mm(i,t,e,n,s,o,r){return s=s||o||S.horizontal_tb,!!r||!!e&&e!==S.none&&!W(e)||ur(t)||i===S.inline_block||i===S.table_cell||i===S.table_caption||i==S.flex||i==S.grid||i==S.flow_root||(i===S.block||i===S.list_item)&&!!n&&n!==S.visible&&n!==S.clip&&!W(n)||!!o&&s!==o}function Cm(i){return i===S.relative||i===S.absolute||i===S.fixed}var In=1e5;function fi(i){let t=i.element.style;t.columnGap=`${In-(i.vertical?i.height:i.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function pr(i){let e=("element"in i?i.element:i).style;e.columnWidth="",e.columnCount="",e.columnGap="",e.columnFill=""}function hr(i){return i.element.style.columnCount==="1"}function bm(i){i.element.setAttribute("data-vivliostyle-column","true")}function go(i,t){let e=t?i.bottom:Math.max(Math.abs(i.left),Math.abs(i.right));return Math.round(e/In)}function ym(i,t){let e=go(i,t);if(e===0)return 0;let n=t?i.top:Math.min(Math.abs(i.left),Math.abs(i.right)),s=Math.round(n/In),o=s*In,r=e*In;return t?(i.top-=o,i.bottom-=r,i.bottom<i.top&&(i.bottom+=In),i.right-=o,i.left-=r):i.left<-In/2?(i.right+=o,i.left+=r,i.left>i.right&&(i.left-=In),i.top+=o,i.bottom+=r):(i.left-=o,i.right-=r,i.right<i.left&&(i.right+=In),i.top+=o,i.bottom+=r),i.width=i.right-i.left,i.height=i.bottom-i.top,s}function Sl(i,t){for(let e=0;e<i.length;e++)ym(i[e],t)}function vt(i,t,e){let n=i.getElementClientRect(t);if(ym(n,e)>0&&i.getElementComputedStyle(t).display.startsWith("table")&&!fr(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return pr(r),i.getElementClientRect(t)}return n}function Sm(i,t){var e,n;if(i.nodeType===1){let s=i;((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 Ld(i){let t=i.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function xm(i){if(!i.hasAttribute("data-vivliostyle-column")&&Ld(i))return!0;for(let t of i.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Ld(t))return!0;return!1}function fr(i){for(let t=i.nodeType===1?i:i.parentElement;t;t=t.parentElement){let e=t.style;if(!e||t.hasAttribute("data-vivliostyle-column"))break;if(Ld(t))return t;if(e.position==="absolute")break}return null}function Em(i){var C;if(i.nodeType!==1)return;let t=i,e=t.style,n=(e==null?void 0:e.breakBefore)==="column",s=t.previousElementSibling,o=s&&((C=s.style)==null?void 0:C.breakAfter)==="column";if(!n&&!o)return;let r=fr(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(),b=t.getBoundingClientRect();(h?b.top>m.bottom+g:f?b.right<m.left-g:b.left>m.right+g)&&(n&&(e.breakBefore=""),o&&s&&(s.style.breakAfter=""),e.marginBlockStart=`${In}px`)}function yl(i){let t=i.element.lastElementChild,e=t&&i.clientLayout.getElementClientRect(t);return e?go(e,i.vertical):0}function Id(i,t){if(i.getAttribute("data-viv-saved-column-fill")!=="auto"||yl(t))return;let e=t.clientLayout.getElementComputedStyle(i),n=parseFloat(e.blockSize);i.style.columnFill="auto";let s=parseFloat(e.blockSize),o=NaN;if(i.style.blockSize=`${s}px`,yl(t)){if(i.style.blockSize=`${n}px`,!yl(t)){let r=1/(t.clientLayout.pixelRatio||1),a=n,l=s;for(;l-a>r;){let c=(a+l)/2;i.style.blockSize=`${c}px`,yl(t)?l=c:a=c}o=a,i.style.blockSize=`${o}px`}}else if(o=parseFloat(e.blockSize),o<s){let r=1/t.clientLayout.layoutUnitPerPixel;o=s+r,i.style.blockSize=`${o}px`}if(isNaN(o)){i.style.blockSize="",i.style.columnFill="balance";return}i.removeAttribute("data-viv-saved-column-fill")}function vm(i){let t=i.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let e of t)Id(e,i)}function ws(i,t,e,n){let s=i.viewNode;if(!s)return NaN;let o=s.nodeType===1?s:s.parentElement;if(o&&o.namespaceURI==="http://www.w3.org/1999/xhtml"){let r=o.style;if(o.localName==="wbr"||r&&Et(r.display)&&/^([\d\.]|super|(text-)?top)/.test(r.verticalAlign))return NaN}if(s===o){if(o.localName==="br"){let a=o.ownerDocument.createElement("span");o.parentNode.insertBefore(a,o);let l=t.getElementClientRect(a);if(a.remove(),l){let c=[l];Sl(c,n);let u=c[0],d=n?u.left:u.bottom;if(!isNaN(d)&&d!==0)return d}return NaN}if(i.after||!i.inline){if(i.after&&!i.inline&&o.querySelector("ruby")){let a=o.parentNode,l=o.nextSibling;a.removeChild(o),a.insertBefore(o,l)}let r=vt(t,o,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 i.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;i.after&&(e+=l),e>=l&&(e=l-1),a.setStart(s,e),a.setEnd(s,e+1);let c=t.getRangeClientRects(a);Sl(c,n);let u=c.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)c=u;else{let d=o?t.getElementComputedStyle(o).whiteSpace:"";c=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?c.filter(f=>n?f.right>f.left:f.bottom>f.top):[]}return c.length?(n?r=Math.min.apply(null,c.map(d=>d.left)):r=Math.max.apply(null,c.map(d=>d.bottom)),r):NaN}}function gi(i,t,e){let n=hr(t);n&&pr(t);let s=t.clientLayout.getElementClientRect(i);n&&fi(t);let o=t.getComputedMargin(i);return e?s.width+o.left+o.right:s.height+o.top+o.bottom}function Jn(i){for(;i;){if(i.parentNode===i.ownerDocument)return!1;i=i.parentNode}return!0}function xl(i,t){var e;if(i)for(let n=i.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")&&i.removeChild(n)}var Fn="data-adapt-spec";function El(i){return!!i.getAttribute(Fn)}function Vn(i){return(i==null?void 0:i.nodeType)!==1?!1:El(i)?!0:Fd(i)}function Fd(i){var s,o;if((i==null?void 0:i.nodeType)!==1)return!1;let t=i,e=(s=t.style)==null?void 0:s.position;if(e==="absolute"||e==="fixed")return!0;let n=(o=t.style)==null?void 0:o.float;return n==="left"||n==="right"||n==="inline-start"||n==="inline-end"}function Vd(i){var t;return(i==null?void 0:i.nodeType)!==1?!1:((t=i.style)==null?void 0:t.position)==="fixed"}function es(i){let t=i==null?void 0:i.viewNode;return(t==null?void 0:t.nodeType)===1&&El(t)}function Nm(i){return i!=="inline"&&(Et(i)||bl(i))}function Od(i){var t;for(let e=i.parent;e;e=e.parent)if((e.display!=="inline"||e.vertical!==((t=e.parent)==null?void 0:t.vertical))&&Et(e.display))return e;return null}function Tm(i){let t=i;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===i||!t)return null;t=(t==null?void 0:t.previousSibling)||null}}return null}function wm(i,t){let e={};return Object.keys(i).forEach(n=>{let s=e[n]={},o=i[n];Object.keys(o).forEach(r=>{s[r]=o[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 Pm(i,t,e,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let o=s[e||"ltr"];if(!o)throw new Error(`unknown direction: ${e}`);for(let r of o){let a=i.replace(r.regexp,r.to);if(a!==i)return a}return i}var km={"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"}]}},wS=wm(km,!0);function Bd(i,t,e){return Pm(i,t,e||null,wS)}var PS=wm(km,!1);function Dd(i,t,e){return Pm(i,t,e||null,PS)}var kS={"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 Am(i,t){let e=kS[t];if(!e)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<e.length;n++)if(e[n].physical===i)return e[n].logical;return i}function gr(i,t,e){var h;let n=t,s={width:n.style.width,height:n.style.height};function o(f){return i.getElementComputedStyle(t).getPropertyValue(f)}let a=o("writing-mode")!=="horizontal-tb",l=a?"height":"width",c=a?"width":"height";function u(f,g){n.style[f]=g;let m=o(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 Ps(i){var t,e;return((t=i==null?void 0:i.style)==null?void 0:t["box-decoration-break"])==="clone"||((e=i==null?void 0:i.style)==null?void 0:e["-webkit-box-decoration-break"])==="clone"}function _d(i){let t=i.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Ud(i,t){i.setAttribute("data-viv-box-break",t.join(" "))}function mt(i,t){let e=_d(i);e.includes(t)||(e.push(t),Ud(i,e))}function RS(i){let t=i.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function LS(i,t){i.setAttribute("data-viv-margin-discard",t.join(" "))}function vl(i,t){let e=RS(i);e.includes(t)||(e.push(t),LS(i,e))}function IS(i){let t=i.name,e=i.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:e===S.always?S.page:e,important:i.important};default:return i}}var Nl={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ne(i){return!!Nl[i]}var FS={left:!0,right:!0,recto:!0,verso:!0};function ts(i){return!!FS[i]}function Hd(i){return Ne(i)&&i!=="column"&&i!=="region"}var VS={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function mr(i){return!!VS[i]}function De(i,t){if(i)if(t){if(ts(t))return t;if(ts(i))return i;{let e=Ne(i),n=Ne(t);if(e&&n)switch(t){case"column":return i;case"region":return i==="column"?t:i;default:return t}else return n?t:e?i:mr(t)?t:mr(i)?i:t}}else return i;else return t}function zd(i){return Ne(i)?i:"auto"}je("SIMPLE_PROPERTY",IS);var Cr=sy(Um());function Hm(i,t){return(0,Cr.default)(i,t,0)}function Xd(i){return i.reduce((t,e)=>e[0]===Cr.default.DELETE?t:t+e[1],"")}function zm(i,t){return $m(i,t,1)}function Gm(i,t){return $m(i,t,-1)}function $m(i,t,e){let n=0,s=0;return i.some(o=>{for(let r=0;r<o[1].length;r++){switch(o[0]*e){case Cr.default.INSERT:n++;break;case Cr.default.DELETE:n--,s++;break;case Cr.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Pl;(t=>{function i(e){return e&&e.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=i})(Pl||(Pl={}));var As;(t=>{let i;(r=>(r.INLINE="inline",r.COLUMN="column",r.REGION="region",r.PAGE="page"))(i=t.FloatReference||(t.FloatReference={}))})(As||(As={}));var Ci;(t=>{function i(e){return e&&e.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=i})(Ci||(Ci={}));var Bn;(e=>{function i(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||bn.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=i;function t(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||bn.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=t})(Bn||(Bn={}));var bn;(e=>{function i(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=i;function t(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=t})(bn||(bn={}));var sn;(e=>{let i;(r=>(r[r.IGNORE=0]="IGNORE",r[r.NEWLINE=1]="NEWLINE",r[r.PRESERVE=2]="PRESERVE"))(i=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={}))})(sn||(sn={}));var Wm={transform:!0,"transform-origin":!0},Xm={top:!0,bottom:!0,left:!0,right:!0},Ls=class{constructor(t,e,n){this.target=t;this.name=e;this.value=n}},$S={show:function(i){i.style.visibility="visible"},hide:function(i){i.style.visibility="hidden"},play:function(i){i.currentTime=0,i.play()},pause:function(i){i.pause()},resume:function(i){i.play()},mute:function(i){i.muted=!0},unmute:function(i){i.muted=!1}};function WS(i,t){let e=$S[t];return e?()=>{for(let n=0;n<i.length;n++)try{e(i[n])}catch(s){}}:null}var Rs=class Rs extends gs{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 o=s.currentTarget,r=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let a={type:"hyperlink",target:null,currentTarget:null,anchorElement:o,href:r,preventDefault(){s.preventDefault()}};this.dispatchEvent(a)}}}setAutoPageWidth(e){this.isAutoPageWidth=e,e?this.container.setAttribute(Rs.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Rs.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(Rs.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Rs.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||P(a.target,a.name,a.value.toString())}let o=n.getElementClientRect(this.container);this.dimensions.width=o.width,this.dimensions.height=o.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=WS(l,a.action);if(u)for(let d=0;d<c.length;d++)c[d].addEventListener(a.event,u,!1)}}}};p(Rs,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),p(Rs,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var br=Rs,Ct=sn.Whitespace;function Vl(i){switch(i){case"normal":case"nowrap":return Ct.IGNORE;case"pre-line":return Ct.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Ct.PRESERVE;default:return null}}function pe(i,t){return i?i.nodeType==1?!1:qd(i.textContent,t):!0}function qd(i,t){switch(t){case Ct.PRESERVE:return i.length==0;case Ct.NEWLINE:return!!i.match(/^[ \t]*$/);case Ct.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var kl=class{constructor(t,e){this.flowName=t;this.parentFlowName=e;p(this,"forcedBreakOffsets",[]);p(this,"formattingContext",null)}},Al=class{constructor(t,e,n,s,o,r,a,l,c){this.flowName=t;this.element=e;this.startOffset=n;this.priority=s;this.linger=o;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 jm(i,t){return i.top-t.top}function Ym(i,t){return t.right-i.right}function qm(i,t){var e,n;return i===t?!0:!i||!t?!1:(i.node===t.node||!!i.shadowContext&&!!t.shadowContext&&i.shadowType===sn.ShadowType.ROOTLESS&&t.shadowType===sn.ShadowType.ROOTLESS&&((e=i.node)==null?void 0:e.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&i.shadowType===t.shadowType&&Yd(i.shadowContext,t.shadowContext)&&Yd(i.nodeShadow,t.nodeShadow)&&qm(i.shadowSibling,t.shadowSibling)}function ns(i,t){if(i===t)return!0;if(!i||!t||i.offsetInNode!==t.offsetInNode||i.after!==t.after||i.steps.length!==t.steps.length)return!1;for(let e=0;e<i.steps.length;e++)if(!qm(i.steps[e],t.steps[e]))return!1;return!0}function Km(i){return{steps:[{node:i,shadowType:tt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function mo(i,t){return{steps:[{node:i.sourceNode,shadowType:tt.NONE,shadowContext:i.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:i.formattingContext,fragmentIndex:t!=null?t:i.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:i.preprocessedTextContent}}function Sr(i,t){let e=new ss(i.node,t,0);return e.shadowType=i.shadowType,e.shadowContext=i.shadowContext,e.nodeShadow=i.nodeShadow,e.shadowSibling=i.shadowSibling?Sr(i.shadowSibling,t.copy()):null,e.formattingContext=i.formattingContext,e.fragmentIndex=i.fragmentIndex+1,e}var tt=sn.ShadowType,Is=class{constructor(t,e,n,s,o,r,a){this.owner=t;this.root=e;this.xmldoc=n;this.parentShadow=s;this.type=r;this.styler=a;p(this,"subShadow",null);o&&(o.subShadow=this)}equals(t){return t?this.owner===t.owner&&this.xmldoc===t.xmldoc&&this.type===t.type&&Yd(this.parentShadow,t.parentShadow):!1}};function Yd(i,t){return i===t||!!i&&!!t&&i.equals(t)}var Rl=class{constructor(t,e){this.outer=t;this.count=e}},ss=class i{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,"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=tt.NONE,this.shadowContext=e?e.shadowContext:null,this.breakPenalty=e?e.breakPenalty:0,this.floatReference=As.FloatReference.INLINE,this.whitespace=e?e.whitespace:Ct.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=As.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:Ct.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 i(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),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,o,r;let t=this,e=[];t.shadowType===sn.ShadowType.ROOTLESS&&(t.floatReference!==As.FloatReference.INLINE||t.floatSide==="footnote")&&((r=(o=(s=t.shadowContext)==null?void 0:s.styler)==null?void 0:o.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?Gm(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}},_t=class i{constructor(t){this.primary=t;p(this,"floats",null)}clone(){let t=new i(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(!ns(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(!ns(this.floats[e],t.floats[e]))return!1}else if(t.floats)return!1;return!0}},Ll=class i{constructor(t,e){this.chunkPosition=t;this.flowChunk=e}clone(){return new i(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Il=class i{constructor(){p(this,"positions",[]);p(this,"startBreakType",null);p(this,"breakAfter",null)}clone(){let t=new i,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}},Fl=class i{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 i;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&&ts(e)?e:"any"}firstFlowChunkOfFlow(t){let e=this.flowPositions[t];if(!e)return null;let n=e.positions[0];return n?n.flowChunk:null}},yr=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,P(this.element,"top",`${t}px`),P(this.element,"height",`${e}px`)}setHorizontalPosition(t,e){this.left=t,this.width=e,P(this.element,"left",`${t}px`),P(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):si(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 st(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 st(t,e,t+n,e+s)}getOuterShape(t,e){let n=this.getOuterRect();return il(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 st(t,e,t+n,e+s)}},Dn=class extends Ot{constructor(e,n,s,o){super();this.elem=e;this.context=n;this.rootContentValue=s;this.exprContentListener=o}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 ke)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"){this.elem.ownerDocument;let o=this.exprContentListener(n,s,this.elem.ownerDocument);!o&&s&&n instanceof ne&&n.str.startsWith("running-element-")&&(s=""),this.visitStrInner(s,o)}return null}};function nt(i){return i!=null&&i!==$&&i!==S.normal&&i!==S.none&&!W(i)}var ue=As.FloatReference,jS=20;function Qm(i){switch(i){case"inline":return ue.INLINE;case"column":return ue.COLUMN;case"region":return ue.REGION;case"page":return ue.PAGE;default:throw new Error(`Unknown float-reference: ${i}`)}}function Sn(i){switch(i){case ue.INLINE:return!1;case ue.COLUMN:case ue.REGION:case ue.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${i}`)}}function Ol(i,t,e,n){let s=t?"vertical-rl":"horizontal-tb";if((i==="top"||i==="bottom")&&(i=Dd(i,s,e)),i==="block-start"&&(i="inline-start"),i==="block-end"&&(i="inline-end"),i==="inline-start"||i==="inline-end"){let o=Bd(i,s,e),r=Am(o,s);r==="line-left"?i="left":r==="line-right"&&(i="right")}else i==="inside"?i=n==="left"?"right":"left":i==="outside"&&(i=n==="left"?"left":"right");return i!=="left"&&i!=="right"&&(B.warn(`Invalid float value: ${i}. Fallback to left.`),i="left"),i}var yi=class{constructor(t,e,n,s,o,r){this.nodePosition=t;this.floatReference=e;this.floatSide=n;this.clearSide=s;this.flowName=o;this.floatMinWrapBlock=r;p(this,"order",null);p(this,"id",null);p(this,"insidePageFloatArea",!1);p(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(t){return t.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!t.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(t){return!1}},Kd=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=>ns(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(s=>ns(s.nodePosition,t));if(e>=0)return this.floats[e];let n=t==null?void 0:t.steps;if(n!=null&&n.length){let s=this.floats.findIndex(o=>{let r=o.nodePosition.steps;if(!(r!=null&&r.length)||r.length===n.length||o.nodePosition.offsetInNode!==t.offsetInNode||o.nodePosition.after!==t.after)return!1;let a=Math.min(r.length,n.length);for(let l=0;l<a;l++)if(r[l].node!==n[l].node)return!1;return!0});if(s>=0)return this.floats[s]}return null}findPageFloatById(t){let e=this.floats.findIndex(n=>n.id===t);return e>=0?this.floats[e]:null}},Si=class{constructor(t,e,n,s,o,r){this.floatReference=t;this.floatSide=e;this.clearSide=n;this.continuations=s;this.area=o;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}},xi=class{constructor(t,e){this.float=t;this.nodePosition=e}equals(t){return t?this===t?!0:this.float===t.float&&ns(this.nodePosition,t.nodePosition):!1}},Mn=class{constructor(t,e,n,s,o,r,a){this.parent=t;this.floatReference=e;this.container=n;this.flowName=s;this.generatingNodePosition=o;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);p(this,"footnoteMaxBlockSize",null);p(this,"ignoreFootnoteAreaMaxHeight",!1);p(this,"footnoteAnchorsSeen",new Set);p(this,"outerContext",null);t&&t.children.push(this),this.writingMode=!W(r)&&r||t&&t.writingMode||S.horizontal_tb,this.direction=!W(a)&&a||t&&t.direction||S.ltr,this.floatStore=t?t.floatStore:new Kd;let l=this.getPreviousSibling();this.floatsDeferredFromPrevious=l?[].concat(l.floatsDeferredToNext):[]}get effectiveParent(){var t;return(t=this.parent)!=null?t:this.outerContext}getParent(t){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${t}`)}setOuterContext(t){this.outerContext=t,this.floatStore=t.floatStore}getPreviousSiblingOf(t,e,n,s){let o=this.children.indexOf(t);o<0&&(o=this.children.length);for(let r=o-1;r>=0;r--){let a=this.children[r];if(a.floatReference===e&&a.flowName===n&&ns(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 yn().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,o)=>s.getOrder()-o.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 o=this.floatFragments.splice(s,1)[0],r=o.area&&o.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&&e.floatSide!=="block-end")}markPageFloatAnchorSeen(t){var n;if(!("footnotePolicy"in t))return;let e=this;for(;e;)e.footnoteAnchorsSeen.add(t.getId()),e=(n=e.parent)!=null?n:e.outerContext}registerPageFloatAnchor(t,e){this.floatAnchors[t.getId()]=e,this.markPageFloatAnchorSeen(t)}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(o=>o.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)}removeFloatDeferredToNext(t){let e=this.floatsDeferredToNext.findIndex(n=>n.float===t);e>=0&&this.floatsDeferredToNext.splice(e,1)}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(o=>o.float.getOrder()<n&&!t.isAllowedToPrecede(o.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(o=>{let r=o.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(o=>o.float)),t=t.concat(s.getFloatsDeferredToNextInChildContexts()))}return t}hasRootMultiColumnFootnoteContext(){return this.children.some(t=>{let e=0;for(let n of t.children)if(!n.generatingNodePosition&&(e+=1,e>1))return!0;return!1})}hasNonRootMultiColumnFootnoteContext(){return this.children.some(t=>t.children.some(e=>{var s;let n=(s=e.getContainer())==null?void 0:s.element;return n!=null&&xm(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(t){let e=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:t/2;return e<jS?!1:(this.footnoteMaxBlockSize=e,!0)}initFootnoteRetryFromEmptyFragment(t,e){if(!("footnotePolicy"in t&&this.footnoteMaxBlockSize==null&&this.footnoteAnchorsSeen.has(t.getId())&&this.hasMultiColumnFootnoteContext()))return!1;let n=(e.vertical?e.width:e.height)+e.getInsetBefore()+e.getInsetAfter();return this.trySetFootnoteRetryMaxBlockSize(n)}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){let s=e.area&&"isFootnote"in e.area&&e.area.isFootnote;if(this.locked)this.invalidate();else{if(s&&this.footnoteAnchorsSeen.has(n.getId())&&this.hasMultiColumnFootnoteContext()){let r=e.area.computedBlockSize+e.area.getInsetBefore()+e.area.getInsetAfter();if(this.trySetFootnoteRetryMaxBlockSize(r))return this.removePageFloatFragment(e),this.removeEndFloatFragments(e.floatSide),!0}this.removePageFloatFragment(e),this.forbid(n),this.removeEndFloatFragments(e.floatSide)}return!0}}return this.floatReference===ue.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let t=this.getFloatsDeferredToNextInChildContexts(),e=this.floatFragments.reduce((n,s)=>n.concat(s.continuations.map(o=>o.float)),[]);e.sort((n,s)=>s.getOrder()-n.getOrder());for(let n of e){let s=n.getOrder();if(t.some(o=>!n.isAllowedToPrecede(o)&&s>o.getOrder())){if(this.locked)this.invalidate();else{this.forbid(n);let o=this.findPageFloatFragment(n);this.removePageFloatFragment(o)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let t=this.floatsDeferredToNext.length-1;t>=0;t--){let n=this.floatsDeferredToNext[t].float;if(this.floatReference===ue.PAGE&&"footnotePolicy"in n&&n.footnotePolicy===S.line&&this.footnoteAnchorsSeen.has(n.getId())){if(this.locked){this.invalidate();return}this.removeFloatDeferredToNext(n),this.forbid(n),this.invalidate();return}}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 Dd(t,e,n)}toPhysical(t){let e=this.writingMode.toString(),n=this.direction.toString();return Bd(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=[],o=!1,r=!1;for(let a=0;a<n.length;a++){let l=n[a];l.includes("block")?o||(n.slice(a+1).some(c=>c.includes("block"))?(s.push("snap-block"),o=!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 o=this.floatFragments[s],r=this.toLogicalFloatSides(o.floatSide)[0];(r===n||n==="snap-block"&&r==="block-end"||n==="snap-inline"&&r==="inline-end")&&o.shouldBeStashedBefore(t)?(this.stashedFloatFragments.push(o),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,o,r=!0){this.container;let a=this.toLogical(t),l=this.toPhysical(t),c=e&&this.toLogical(e),u=e&&this.toPhysical(e),d=this.getLimitValueInner(a,c,n,s,o);if(r&&this.parent&&this.parent.container){let h=this.parent.getLimitValue(l,u,n,s,o,r);switch(l){case"top":return Math.max(d,h);case"left":return Math.max(d,h);case"bottom":return Math.min(d,h);case"right":return Math.min(d,h);default:}}return d}getLimitValueInner(t,e,n,s,o){this.container;let r=this.getLimitValuesInner(n,s,o,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,o){var h,f,g,m;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};if(this.container.vertical){let b=parseFloat((f=(h=this.container.element)==null?void 0:h.style)==null?void 0:f.width);isFinite(b)&&b>this.container.width&&(c.right+=b-this.container.width)}else{let b=parseFloat((m=(g=this.container.element)==null?void 0:g.style)==null?void 0:m.height);isFinite(b)&&b>this.container.height&&(c.bottom+=b-this.container.height)}function u(b,y,C){return b.unit==="%"?C*b.num/100:t.convertLengthToPx(b,y,e)}let d=this.floatFragments;return d.length>0&&(c=d.reduce((b,y)=>{if(n&&!n(y,this))return b;let[C,N]=this.toLogicalFloatSides(y.floatSide);if(N&&(s&&N.includes("block")===s.includes("block")&&N!==s||o&&N.includes("block")===o.includes("block")&&N!==o))return b;let x=y.area,E=y.continuations[0].float.floatMinWrapBlock,v=x.vertical?x.left+x.getInsetLeft()+x.width+x.getInsetRight():x.top+x.getInsetTop()+x.height+x.getInsetBottom(),T=x.vertical?x.top+x.getInsetTop()+x.height+x.getInsetBottom():x.left+x.getInsetLeft()+x.width+x.getInsetRight(),k=b.top,L=b.left,M=b.bottom,q=b.right,J=b.floatMinWrapBlockStart,re=b.floatMinWrapBlockEnd;switch(C){case"inline-start":x.vertical?k=Math.max(k,T):L=Math.max(L,T);break;case"block-start":x.vertical?(E&&x.left<q&&(J=u(E,x.rootViewNodes[0],l.x2-l.x1)),q=Math.min(q,x.left)):(E&&v>k&&(J=u(E,x.rootViewNodes[0],l.y2-l.y1)),k=Math.max(k,v));break;case"inline-end":x.vertical?M=Math.min(M,x.top):q=Math.min(q,x.left);break;case"block-end":x.vertical?(E&&v>L&&(re=u(E,x.rootViewNodes[0],l.x2-l.x1)),L=Math.max(L,v)):(E&&x.top<M&&(re=u(E,x.rootViewNodes[0],l.y2-l.y1)),M=Math.min(M,x.top));break;default:throw new Error(`Unknown logical float side: ${C}`)}return{top:k,left:L,bottom:M,right:q,floatMinWrapBlockStart:J,floatMinWrapBlockEnd:re}},c)),c.left+=r,c.right+=r,c.top+=a,c.bottom+=a,c}setFloatAreaDimensions(t,e,n,s,o,r,a){if(e!==this.floatReference)return this.getParent(e).setFloatAreaDimensions(t,e,n,s,o,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(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,b=t.vertical?t.originY:t.originX;t.isFootnote||(d=t.vertical?Math.min(d,t.left+t.getInsetLeft()+t.width+t.getInsetRight()+m):Math.max(d,t.top+m),h=t.vertical?Math.max(h,t.left+m):Math.min(h,t.top+t.getInsetTop()+t.height+t.getInsetBottom()+m));function y(v,T){let k=v(t.bands,T);return k?(t.vertical&&(k=sl(k)),d=t.vertical?Math.min(d,k.x2):Math.max(d,k.y1),h=t.vertical?Math.max(h,k.x1):Math.min(h,k.y2),!0):r}let C,N,x,E;if(o){let v=t.vertical?tr(new st(h,f,d,g)):new st(f,d,g,h);if((l[0]==="block-start"||l[0]==="snap-block"||l[0]==="inline-start"||l[0]==="snap-inline")&&!y(Dg,v)||(l[0]==="block-end"||l[0]==="snap-block"||l[0]==="inline-end"||l[0]==="snap-inline")&&!y(Mg,v)||(t.isFootnote&&s!==null&&isFinite(s)&&l[0]==="block-end"&&(t.vertical?d=Math.min(d,s):d=Math.max(d,s)),x=(h-d)*t.getBoxDir(),t.isFootnote&&this.footnoteMaxBlockSize!=null&&(x=Math.min(x,this.footnoteMaxBlockSize),t.vertical?d=h+x:d=h-x),C=Math.max(0,x-t.getInsetBefore()-t.getInsetAfter()),E=(g-f)*t.getInlineDir(),N=E-t.getInsetStart()-t.getInsetEnd(),!r&&(C<=0||N<=0)))return null}else{let v=t.getContentBlockMarginAfter();C=Math.max(0,t.computedBlockSize+Math.min(0,v)),x=C+t.getInsetBefore()+t.getInsetAfter();let T=(h-d)*t.getBoxDir();if(l[0]==="snap-block"){if(s===null)l[0]="block-start";else{let L=this.container.getPaddingRect(),M=this.container.getBoxDir()*(s-(this.container.vertical?L.x2:L.y1)),q=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-s-x);M<=q?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&&T<x)return null;l[0]==="inline-start"||l[0]==="inline-end"||l[1]?N=gr(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?N=t.getContentInlineSize():N=t.vertical?t.height:t.width,E=N+t.getInsetStart()+t.getInsetEnd();let k=(g-f)*t.getInlineDir();if(!r&&k<E)return null}return d-=m,h-=m,f-=b,g-=b,l.some(v=>v==="inline-start"||v==="snap-inline")||l.length===1&&(l[0]==="block-start"||l[0]==="snap-block")?t.setInlinePosition(f,N):(l.some(v=>v==="inline-end")||l.length===1&&l[0]==="block-end")&&t.setInlinePosition(g-E*t.getInlineDir(),N),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-x*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)}getBlockEndEdgeOfBlockStartFloats(t){let e=this,n=null;for(;e&&!n;)n=e.container,e=e.parent;let s=!!(n!=null&&n.vertical),o=NaN;if(this.floatFragments.filter(r=>r.floatSide.includes("block-start")).filter(r=>{if(!isFinite(t))return!0;let a=r.getOuterRect();return s?a.y1<=t&&t<=a.y2:a.x1<=t&&t<=a.x2}).forEach(r=>{let a=r.getOuterRect(),l=s?a.x1:a.y2;o=isFinite(o)?s?Math.min(o,l):Math.max(o,l):l}),this.parent){let r=this.parent.getBlockEndEdgeOfBlockStartFloats(t);isFinite(r)&&(o=isFinite(o)?s?Math.min(o,r):Math.max(o,r):r)}return o}getBlockStartEdgeOfBlockEndFloats(t){let e=this,n=null;for(;e&&!n;)n=e.container,e=e.parent;let s=!!(n!=null&&n.vertical),o=NaN;if(this.floatFragments.filter(r=>r.floatSide.includes("block-end")).filter(r=>{if(!isFinite(t))return!0;let a=r.getOuterRect();return s?a.y1<=t&&t<=a.y2:a.x1<=t&&t<=a.x2}).forEach(r=>{let a=r.getOuterRect(),l=s?a.x2:a.y1;o=isFinite(o)?s?Math.max(o,l):Math.min(o,l):l}),this.parent){let r=this.parent.getBlockStartEdgeOfBlockEndFloats(t);isFinite(r)&&(o=isFinite(o)?s?Math.max(o,r):Math.min(o,r):r)}return o}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 o=e.getPaddingRect(),r=e.vertical?o.x1:o.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 o=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"?o==="snap-block"?a=["block-start","block-end"]:a=[o]: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,o=null;for(;s&&s.container;){let l=s.getLimitValuesInner(e,n);o?t.vertical?(l.right<o.right&&(o.right=l.right,o.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.left>o.left&&(o.left=l.left,o.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):(l.top>o.top&&(o.top=l.top,o.floatMinWrapBlockStart=l.floatMinWrapBlockStart),l.bottom<o.bottom&&(o.bottom=l.bottom,o.floatMinWrapBlockEnd=l.floatMinWrapBlockEnd)):o=l,s=s.parent}let r=Math.max(o.floatMinWrapBlockStart,o.floatMinWrapBlockEnd);return(t.vertical?o.right-o.left:o.bottom-o.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}},bi=[],yn=class{static register(t){bi.push(t)}findByNodeContext(t){for(let e=bi.length-1;e>=0;e--){let n=bi[e];if(n.appliesToNodeContext(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=bi.length-1;e>=0;e--){let n=bi[e];if(n.appliesToFloat(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},Zd=class{appliesToNodeContext(t){return Sn(t.floatReference)}appliesToFloat(t){return!0}createPageFloat(t,e,n){let s=t.floatReference;t.floatSide;let o=t.floatSide,r=t.toNodePosition(),a=!!e.generatingNodePosition;return n.resolveFloatReferenceFromColumnSpan(s,t.columnSpan,t).thenAsync(l=>{s=l,e.flowName;let c=new yi(r,s,o,t.clearSide,e.flowName,t.floatMinWrapBlock);if(c.insidePageFloatArea=a,a){let u=e.generatingNodePosition;u&&(c.parentPageFloat=e.findPageFloatByNodePosition(u))}return e.addPageFloat(c),w(c)})}createPageFloatFragment(t,e,n,s,o){let r=t[0].float;return new Si(r.floatReference,e,n,t,s,o)}findPageFloatFragment(t,e){return e.findPageFloatFragment(t)}adjustPageFloatArea(t,e,n){return w(void 0)}forbid(t,e){}};yn.register(new Zd);var Qd="data-vivliostyle-footnote-first-ref",Jd="data-vivliostyle-footnote-referenced";function Bl(i,t){return!!(i&&i.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function rt(i){if(i.localName!=="aside")return!1;if(Bl(i.getAttribute("role"),"doc-footnote"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Bl(t,"footnote")}function bt(i){if(i.localName!=="a")return!1;if(Bl(i.getAttribute("role"),"doc-noteref"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Bl(t,"noteref")}function ep(i,t){if(!bt(i))return null;let e=i.getAttribute("href")||i.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!e)return null;let n=Ks(e,t);return n==="#"?null:n}function tp(i,t,e){let n=ep(i,t);if(!n)return null;let s=e(n);return s&&rt(s)?s:null}function YS(i,t,e,n,s){if(s.value)return;let o=i.getElementsByTagName("a");for(let r=0;r<o.length;r++){let a=o.item(r),l=ep(a,t);!l||n.has(l)||n.set(l,e(a))}s.value=!0}function np(i,t,e,n,s){if(i.localName!=="a"||!bt(i))return!0;let o=ep(i,t);if(!o)return!0;YS(i.ownerDocument,t,e,n,s);let r=n.get(o);return r==null||e(i)===r}function sp(i,t){let e=t.getProp(i,"footnote-display");if(e)return e;let n=t.getProp(i,"display");return(n==null?void 0:n.value)===S.inline?t.createCascadeValue(S.inline,n.priority):null}function Jm(i,t,e,n,s,o,r){if(i.namespaceURI!=="http://www.pyroxy.com/ns/shadow"||i.localName!=="include"||!i.classList.contains("-vivliostyle-footnote-content"))return t;let a=e==null?void 0:e.owner;if(!(a instanceof Element)||!bt(a))return t;let l=tp(a,n,s);if(!l)return t;let c=a.getAttribute(o);c?(i.setAttribute(o,c),l.setAttribute(o,c)):(i.removeAttribute(o),l.removeAttribute(o));let u=r.getStyle(l);if(!u)return t;let d={...t},h=sp(u,r),f=r.getProp(u,"footnote-policy"),g=r.getStyleMap(u,"_pseudos"),m=g==null?void 0:g.after;if(h&&(d["footnote-display"]=h),f&&(d["footnote-policy"]=f),m){let b=r.getMutableStyleMap(d,"_pseudos");b.after={...m}}return d}function eC(i,t,e,n,s){var f;if(!((e==null?void 0:e.type)===tt.ROOTED&&rt(i)))return t;let o=s.getStyle(i);if(!o)return t;let r={...t},a=sp(o,s),l=s.getProp(o,"footnote-policy"),c=s.getStyleMap(o,"_pseudos"),u=c==null?void 0:c["footnote-marker"],d=s.getProp(u,"content"),h=s.getProp(u,"list-style-position");if(a&&(r["footnote-display"]=a),l&&(r["footnote-policy"]=l),d&&((f=h==null?void 0:h.evaluate)==null?void 0:f.call(h,n,"list-style-position"))===S.outside){let g=s.filterFootnoteMarkerContent(d,i);r["--viv-marker-content"]=s.createCascadeValue(g,0),r.display=s.createCascadeValue(R("list-item"),0),r["list-style-position"]=s.createCascadeValue(S.outside,0),r["list-style-type"]=s.createCascadeValue(S.none,0),r["list-style-image"]=s.createCascadeValue(S.none,0)}return r}function tC(i,t,e){var s,o;let n=(t==null?void 0:t.type)===tt.ROOTED&&rt(i)?e.getStyle(i):null;return{sourceStyle:n,footnoteDisplay:((s=sp(n,e))==null?void 0:s.value)||null,footnotePolicy:((o=e.getProp(n,"footnote-policy"))==null?void 0:o.value)||null}}function nC(i,t){if(i instanceof D){let e=i.expr.evaluate(t);return typeof e=="string"?new z(e):typeof e=="number"?new z(String(e)):i}return i instanceof X?new X(i.values.map(e=>nC(e,t))):i}function sC(i,t,e){let n=i==null?void 0:i["_footnote-marker-content"];n&&(t["--viv-marker-content"]=nC(n.value,e))}function qS(i){let t=i.getElementsByTagName("a"),e=new Set;for(let n=0;n<t.length;n++){let s=t.item(n);if(!bt(s)||!(s instanceof HTMLAnchorElement)||!s.hash||s.href!==s.baseURI.replace(/#.*$/,"")+s.hash)continue;let o=s.hash.substring(1),r=i.getElementById(o);if(r&&rt(r)){let a=s.baseURI.replace(/#.*$/,"")+s.hash;e.has(a)||(e.add(a),s.setAttribute(Qd,"true")),r.setAttribute(Jd,"true")}}}je("PREPROCESS_SINGLE_DOCUMENT",qS);var KS=Si,Co=class i extends yi{constructor(e,n,s,o,r,a){super(e,n,"block-end",null,s,r);this.footnotePolicy=o;this.policyAnchorNode=a}isAllowedToPrecede(e){return!(e instanceof i)}};function ZS(i){let t=i.nodeType===Node.ELEMENT_NODE?i:i.parentElement;for(;t;){if(/^(p|li|dd|dt|td|th|blockquote)$/i.test(t.localName)&&!t.querySelector("br"))return t;t=t.parentElement}return i}var Dl=class extends KS{constructor(t,e,n,s){super(t,"block-end",null,e,n,s)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof Co?!0:this.getOrder()<t.getOrder()}},op=class{constructor(t){this.footnote=t}allowLayout(t){let e=t.shadowContext?t.shadowContext.owner:t.sourceNode;for(;e;){if(e===this.footnote.policyAnchorNode)return!1;e=e.parentNode}return!0}},rp=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof Co}createPageFloat(t,e,n){var h;let s=ue.REGION,o=e.getPageFloatLayoutContext(s);e.getPageFloatLayoutContext(ue.PAGE).hasSameContainerAs(o)&&(s=ue.PAGE);let a=!!e.generatingNodePosition;a&&s!==ue.PAGE&&(s=ue.PAGE);let l=t.toNodePosition();e.flowName;let c=t.sourceNode,u=(h=t.shadowContext)==null?void 0:h.owner;u instanceof Element&&bt(u)&&(c=u),c=ZS(c);let d=new Co(l,s,e.flowName,t.footnotePolicy,t.floatMinWrapBlock,c);if(d.insidePageFloatArea=a,a){let f=e.generatingNodePosition;f&&(d.parentPageFloat=e.findPageFloatByNodePosition(f))}return e.addPageFloat(d),w(d)}createPageFloatFragment(t,e,n,s,o){let r=t[0].float;return new Dl(r.floatReference,t,s,o)}findPageFloatFragment(t,e){let s=e.getPageFloatLayoutContext(t.floatReference).floatFragments.filter(o=>o instanceof Dl);return s.length<=1,s[0]||null}adjustPageFloatArea(t,e,n){t.isFootnote=!0,t.adjustContentRelativeSize=!1;let s=t.element;return n.layoutContext.applyFootnoteStyle(e.vertical,n.layoutContext.nodeContext&&n.layoutContext.nodeContext.direction==="rtl",s).thenAsync(o=>{var l,c;if(t.vertical=o,t.convertPercentageSizesToPx(s),n.setComputedInsets(s,t),n.setComputedWidthAndHeight(s,t),((l=n.clientLayout.getElementComputedStyle(s))==null?void 0:l.boxSizing)==="border-box"){let u=t.vertical?t.paddingLeft+t.paddingRight+t.borderLeft+t.borderRight:t.paddingTop+t.paddingBottom+t.borderTop+t.borderBottom,d=t.vertical?["max-width","min-width","width"]:["max-height","min-height","height"],h=getComputedStyle(s);for(let f of d){let g=h.getPropertyValue(f);if(g&&g!=="none"){let m=parseFloat(g);isNaN(m)||P(s,f,`${Math.max(0,m-u)}px`)}}P(s,"box-sizing","content-box")}let a=n.pageFloatLayoutContext;for(;a;){if(a.ignoreFootnoteAreaMaxHeight){P(s,"max-block-size",""),P(s,t.vertical?"max-width":"max-height","");break}a=(c=a.parent)!=null?c:null}return w(void 0)})}forbid(t,e){let n=t;switch(n.footnotePolicy){case S.line:{let s=new op(n);e.addLayoutConstraint(s,n.floatReference);break}}}};yn.register(new rp);var bo=class{calculateOffset(t){return Fs(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function Fs(i,t){return{current:t.reduce((e,n)=>e+n.calculateOffset(i),0),minimum:t.reduce((e,n)=>e+n.calculateMinimumOffset(i),0)}}var _n=class extends bo{constructor(e,n,s,o){super();this.position=e;this.breakOnEdge=n;this.overflows=s;this.computedBlockSize=o;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(mr(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=ws(this.position,e.clientLayout,0,e.vertical)+n,!this.position.after&&!this.position.inline){let o=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*o}else if(this.position.after&&((s=this.position.shadowContext)==null?void 0:s.root.id)==="table-cell"){let o=e.element.parentElement,r=o==null?void 0:o.closest("table, [style*='display: table;']");if(r){let a=r.style.borderCollapse==="collapse",l=0,c=0;for(let u=o;u;u=u.parentElement){let d=e.clientLayout.getElementComputedStyle(u);if((u===o||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===o||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(!Bn.isInstanceOfRepetitiveElementsOwnerFormattingContext(n))return!1;let s=n.getRepetitiveElements();return s?s.isFirstContentNode(e):!1}};var Vs=class{find(t){let e=Je("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()}`)}},Un=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 _n(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===sn.ShadowType.ROOTLESS&&es(n))return;let o=n.viewNode;((a=o.parentElement)==null?void 0:a.localName)==="viv-ts-inner"&&(o=o.parentElement.parentElement);let r=o.parentNode;xl(r,o),s&&r.removeChild(o)}finishBreak(t,e,n,s){let o=n||e.viewNode!=null&&e.viewNode.nodeType==1&&!e.after;return t.clearOverflownViewNodes(e,o),s&&t.layoutContext.processFragmentedBlockEdge(e),w(!0)}},xr=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){}},Ni=new Un,oC=Pl.isInstanceOfBlockFormattingContext;je("RESOLVE_FORMATTING_CONTEXT",(i,t,e,n,s,o)=>{let r=i.parent;return!r&&i.formattingContext||r&&i.formattingContext!==r.formattingContext?null:i.establishesBFC||!i.formattingContext&&ml(e,n,s,o)?new xr(r?r.formattingContext:null):null});je("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof xr?Ni:null);var Os=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=I("AbstractLayoutRetryer.tryLayout");this.saveState(t,e);let s=this.resolveLayoutMode(t);return s.doLayout(t,e).then(o=>{let r=s.accept(o,e);r=s.postLayout(o,this.initialPosition,e,r),r?n.finish(o):(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 lp=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){}},yo=class{constructor(t,e){this.strategy=t;this.layoutContext=e}iterate(t){let e=this.strategy,n=e.initialState(t),s=I("LayoutIterator");return s.loopWithFrame(o=>{let r;for(;n.nodeContext;){n.nodeContext.viewNode?n.nodeContext.viewNode.nodeType!==1?pe(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:w(!0)).thenAsync(()=>n.break?w(null):this.layoutContext.nextInTree(n.nodeContext,n.atUnforcedBreak));if(l.isPending()){l.then(c=>{n.break?o.breakLoop():(n.nodeContext=c,o.continueLoop())});return}else if(n.break){o.breakLoop();return}else n.nodeContext=l.get()}e.finish(n),o.breakLoop()}).then(()=>{s.finish(n.nodeContext)}),s.result()}},os=class extends lp{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&&Ne(e.breakAtTheEdge);if(s){let o=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;o.viewNode.parentNode.removeChild(o.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 o=e.nodeContext,r=!n.allowLayout(o);return r&&(s.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),o=e.nodeContext=o.modify(),o.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=De(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:w(!0),s=s.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),w(!0)))):(n=this.endNonInlineBox(e),s=n&&n.isPending()?n:w(!0)),s.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=De(e.breakAtTheEdge,e.nodeContext.breakAfter)),w(!0)))}};var _l=[];function iC(){_l=[]}function dp(i,t,e){return i-=e,t===0?i===0:i%t===0&&i/t>=0}var cp=class{constructor(t){this.matchers=t}matches(){return this.matchers.some(t=>t.matches())}},up=class{constructor(t){this.matchers=t}matches(){return this.matchers.every(t=>t.matches())}},Er=class Er{constructor(t,e,n){this.elementOffset=t;this.a=e;this.b=n}static registerFragmentIndex(t,e,n){let s=Er.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:e,priority:n})}static clearFragmentIndices(){Er.fragmentIndices={}}matches(){let t=Er.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&dp(t.fragmentIndex,this.a,this.b)}};p(Er,"fragmentIndices",{});var Bs=Er,So=class{static buildViewConditionMatcher(t,e){let n=e.split("_");return n[0]=="NFS"?new Bs(t,parseInt(n[1],10),parseInt(n[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new up(t)}static buildAnyMatcher(t){return new cp(t)}};var Qp={"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},QS=["image-resolution","orphans","widows"];function cC(){return Je("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(QS))}var JS={"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},gp=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],ex=["max-%","min-%","%"],lC=(()=>{let i=["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<gp.length;e++)for(let n=0;n<i.length;n++){let s=gp[e].replace("%",i[n]);t[s]=!0}return t})();function wr(i,t){let e={};for(let n of gp)for(let s in i){let o=n.replace("%",s),r=n.replace("%",i[s]);e[o]=r,e[r]=o}for(let n of ex)for(let s in t){let o=n.replace("%",s),r=n.replace("%",t[s]);e[o]=r,e[r]=o}return e}var Jp=wr({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),eh=wr({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),tx=wr({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),nx=wr({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),sx=wr({inside:"right",outside:"left"},{}),ox=wr({inside:"left",outside:"right"},{}),V=class i{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 i(e,this.priority)}increaseSpecificity(t){return t==0?this:new i(this.value,this.priority+t)}evaluate(t,e,n,s){return e&&Dt(e)?this.value:Ii(t,this.value,e,n,s)}isEnabled(t){return!0}},Ti=class i extends V{constructor(e,n,s){super(e,n);this.condition=s}getBaseValue(){return new V(this.value,this.priority)}filterValue(e){let n=this.value.visit(e);return n===this.value?this:new i(n,this.priority,this.condition)}increaseSpecificity(e){return e==0?this:new i(this.value,this.priority+e,this.condition)}isEnabled(e){try{return!!this.condition.evaluate(e)}catch(n){B.warn(n)}return!1}};function mp(i,t,e){return(!t||e.priority>=t.priority)&&e.isEnabled(i)?e.getBaseValue():t}function on(i,t,e,n){if(i)if(!e)delete i[t];else{let s=i[t];(!s||e.priority>=s.priority)&&(n?e.isEnabled(n)&&(i[t]=e.getBaseValue()):i[t]=e)}}var uC={"region-id":!0,"fragment-selector-id":!0},Pr="data-viv-footnote-counter";function zl(i){let t=i.getAttribute(Pr);if(!t)return Object.create(null);let e;try{e=JSON.parse(t)}catch(s){return Object.create(null)}if(!e||typeof e!="object"||Array.isArray(e))return Object.create(null);let n=Object.create(null);return Object.entries(e).forEach(([s,o])=>{if(Array.isArray(o)){let r=o.filter(a=>typeof a=="number"&&isFinite(a));n[s]=r}else typeof o=="number"&&isFinite(o)&&(n[s]=[o])}),n}function dC(i,t,e){let n=zl(i);n[t]=e,i.setAttribute(Pr,JSON.stringify(n))}function rx(i,t){var c,u;if(!bt(i)||i.hasAttribute(Qd))return null;let e=zl(i)[t];if(e)return e;let n=i.getAttribute("href")||i.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!n)return null;let s=i.baseURI||((c=i.ownerDocument)==null?void 0:c.baseURI)||"",o=Ks(n,s);if(o==="#"||o.replace(/#.*$/,"")!==s.replace(/#.*$/,""))return null;let r=o.indexOf("#");if(r<0||r===o.length-1)return null;let a=(u=i.ownerDocument)==null?void 0:u.getElementById(o.substring(r+1));if(!(a instanceof Element))return null;let l=zl(a)[t];return l?(dC(i,t,l),l):null}function ix(i){let t=ee(i,"content");return!!t&&nt(t.value)}function ax(i){return!!uC[i]}function Hl(i){return i.charAt(0)==="_"&&i!=="_viewConditionalStyles"}function Ds(i){return i.charAt(0)!=="_"&&!uC[i]}function ls(i){return!!Qp[i]||Dt(i)}function ee(i,t){return i[t]}function Hn(i,t,e){e?i[t]=e:delete i[t]}function it(i,t){return i[t]}function Yt(i,t){let e=i[t];return e||(e={},i[t]=e),e}var pC=i=>{let t=i._viewConditionalStyles;return t||(t=[],i._viewConditionalStyles=t),t};function th(i,t){return i[t]}function hC(i,t){let e=i[t];return e||(e=[],i[t]=e),e}function Ri(i,t,e,n,s,o,r){var l,c;if([{id:s,styleKey:"_pseudos"},{id:o,styleKey:"_regions"}].forEach(u=>{if(u.id){let d=Yt(t,u.styleKey);t=d[u.id],t||(t={},d[u.id]=t)}}),r){let u=pC(t);t={},u.push({styles:t,matcher:r})}for(let u in e)if(!Hl(u))if(ax(u)){let d=th(e,u),h=hC(t,u);Array.prototype.push.apply(h,d)}else{let d=ee(e,u);if(!d.isEnabled(i))continue;let h=d.increaseSpecificity(n);on(t,u,h,i);let f=(c=(l=i.style)==null?void 0:l.validatorSet.shorthands[u])==null?void 0:c.propList;if(f)for(let g of f){let m=new V($,h.priority);on(t,g,m,i)}}}function fC(i,t){let e={};for(let n=0;n<t.length;n++)Ri(i,e,t[n],0,null,null,null);return e}function nh(i,t){if(i.length>0){i.sort((n,s)=>s.getPriority()-n.getPriority());let e=null;for(let n=i.length-1;n>=0;n--)e=i[n],e.chained=t,t=e;return e}return t}var Gl=class extends en{constructor(e,n){super();this.props=e;this.context=n;p(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ee(this.props,"font-size");if(!e.value.isNumeric())return ct.em;let n=e.value;if(!xg(n.unit))throw new Error("Unexpected state");return n.num*ct[n.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?nc(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?tc(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Ii(this.context,e,this.propName).visit(this):e}};function tc(i,t,e){let n=i.unit,s=i.num;return n==="em"?new A(s*t,"px"):n==="rem"?new A(s*e.fontSize(),"px"):n==="rlh"?new A(s*e.rootLineHeight,"px"):i}function nc(i,t,e){i=tc(i,t,e);let n=i.unit,s=i.num;return n==="px"?i:n==="%"?new A(s/100*t,"px"):new A(s*e.queryUnitSize(n,!1),"px")}var rs=class{apply(t){}mergeWith(t){return new Cp([this,t])}clone(){return this}},Nr=class extends rs{constructor(e){super();this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Cp=class i extends rs{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 i([].concat(this.list))}},Eo=class extends rs{constructor(e,n,s,o,r){super();this.style=e;this.specificity=n;this.pseudoelement=s;this.regionId=o;this.viewConditionId=r}apply(e){Ri(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},de=class extends rs{constructor(){super();p(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},bp=class extends de{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}},yp=class extends de{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}},$l=class extends de{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}},Sp=class extends de{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}},xp=class extends de{constructor(e,n,s=!1){super();this.epubTypePatt=e;this.targetLocalName=n;this.useRoleAttr=s}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),o=n.ownerDocument.getElementById(s);if(o&&(!this.targetLocalName||o.localName==this.targetLocalName)){let r=this.useRoleAttr?o.getAttribute("role"):o.getAttributeNS("http://www.idpf.org/2007/ops","type")||o.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Ep=class extends de{constructor(e){super();this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function sc(i,t,e,n){if(!i)return!1;if(t!==null)return n(i,t,e);for(let s of i.getAttributeNames())if((s===e||s.endsWith(`:${e}`))&&n(i,s===e?"":i.lookupNamespaceURI(s.split(":")[0]),e))return!0;return!1}var Wl=class extends de{constructor(e,n){super();this.ns=e;this.name=n}apply(e){sc(e.currentElement,this.ns,this.name,(n,s,o)=>n.hasAttributeNS(s,o))&&this.chained.apply(e)}},vp=class extends de{constructor(e,n,s){super();this.ns=e;this.name=n;this.value=s}apply(e){sc(e.currentElement,this.ns,this.name,(n,s,o)=>n.getAttributeNS(s,o)==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}},Np=class extends de{constructor(e,n){super();this.ns=e;this.name=n}apply(e){sc(e.currentElement,this.ns,this.name,(n,s,o)=>!!JS[n.getAttributeNS(s,o)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},xo=class extends de{constructor(e,n,s){super();this.ns=e;this.name=n;this.regexp=s}apply(e){sc(e.currentElement,this.ns,this.name,(n,s,o)=>{var r;return!!((r=n.getAttributeNS(s,o))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},Tp=class extends de{constructor(e){super();this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Xl=class extends de{constructor(){super()}apply(t){t.isFirst&&this.chained.apply(t)}getPriority(){return 6}},wp=class extends de{constructor(){super()}apply(t){t.isRoot&&this.chained.apply(t)}getPriority(){return 12}},zn=class extends de{constructor(e,n){super();this.a=e;this.b=n}matchANPlusB(e){return dp(e,this.a,this.b)}},Pp=class extends zn{constructor(t,e){super(t,e)}apply(t){this.matchANPlusB(t.currentSiblingOrder)&&this.chained.apply(t)}getPriority(){return 5}},wi=class extends zn{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}},Pi=class extends zn{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}},ki=class extends zn{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,o=n.localName,r=e[s];r||(r=e[s]={}),r[o]=(r[o]||0)+1}while(n=n.nextElementSibling)}this.matchANPlusB(e[t.currentNamespace][t.currentLocalName])&&this.chained.apply(t)}getPriority(){return 4}},kp=class extends de{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}},Ap=class extends de{constructor(){super()}apply(t){t.currentElement.disabled===!1&&this.chained.apply(t)}getPriority(){return 5}},Rp=class extends de{constructor(){super()}apply(t){t.currentElement.disabled===!0&&this.chained.apply(t)}getPriority(){return 5}},Lp=class extends de{constructor(){super()}apply(t){let e=t.currentElement;(e.selected===!0||e.checked===!0)&&this.chained.apply(t)}getPriority(){return 5}},Ze=class extends de{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}},jl=class i extends rs{constructor(){super();p(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new i;return e.applied=this.applied,e}},Ai=class extends de{constructor(e){super();p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new jl;for(let n of e)this.firstActions.push(nh(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 de?e.getPriority():0))}positive(){return!0}relational(){return!1}},Ip=class extends Ai{positive(){return!1}},Fp=class extends Ai{constructor(e){super([]);this.selectorTexts=e}apply(e){for(let n of this.selectorTexts){let s,o;/^\s*[+~]/.test(n)?(o=e.currentElement.parentNode,s=`:scope > :nth-child(${Array.from(o.children).indexOf(e.currentElement)+1}) ${n}`):(o=e.currentElement,s=`:scope ${n}`);try{if(o.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 zn{constructor(e,n,s){super(e,n);p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new jl;for(let o of s)this.firstActions.push(nh(o,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,o=n.previousElementSibling;for(;o;)this.matchesSelector(o,e)&&s++,o=o.previousElementSibling;this.matchANPlusB(s)&&this.chained.apply(e)}matchesSelector(e,n){let s=n.currentElement,o=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=o,n.currentLocalName=r,n.currentId=a,n.currentClassNames=l,n.currentSiblingOrder=c,h}getPriority(){return 5}},Vp=class extends Yl{constructor(t,e,n){super(t,e,n)}apply(t){for(let o of this.firstActions)if(o.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}},Tr=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)}},Op=class i extends Tr{constructor(t,e,n){super(t,e,n)}fresh(t){return new i(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}},Bp=class i extends Tr{constructor(t,e,n){super(t,e,n)}fresh(t){return new i(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)}},Dp=class i extends Tr{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new i(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)}},Mp=class i extends Tr{constructor(e,n,s){super(e,n,s);p(this,"fired",!1)}fresh(e){return new i(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}},_p=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}},Up=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}},Hp=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}},zp=class extends en{constructor(e){super();this.element=e}createValueFromString(e,n){switch(n){case"url":return e?new ke(e):new ke("about:invalid");case"string":default:return e?new z(e):new z("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let n="string",s=null,o=null;if(e.values[0]instanceof X){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?o=this.createValueFromString(e.values[1].stringValue(),n):o=this.createValueFromString(null,n),this.element&&this.element.hasAttribute(s)?this.createValueFromString(this.element.getAttribute(s),n):o}};function ql(i,t){if(nt(i)){if(i instanceof z)return i.stringValue();if(i instanceof D&&t){let e=i.expr.evaluate(t);return typeof e=="string"?e:typeof e=="number"?String(e):""}if(i instanceof X)return i.values.map(e=>ql(e,t)).join("")}return""}var is=class extends en{constructor(e,n,s,o){super();this.cascade=e;this.element=n;this.counterResolver=s;this.pseudoName=o}getCounterStore(){var e,n;return(n=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?n:null}getPageScope(){var e,n;return(n=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:n.pageScope}evaluateAndGetString(e){if(!e)return"";let n=this.cascade.quoteDepth,s=e.visit(this),o=ql(s,this.cascade.context);return this.cascade.quoteDepth=n,o}visitIdent(e){let n=this.cascade,s=n.quotes,o=Math.floor(s.length/2)-1;switch(e.name){case"open-quote":{let r=s[2*Math.min(o,n.quoteDepth)];return n.quoteDepth++,r}case"close-quote":return n.quoteDepth>0&&n.quoteDepth--,s[2*Math.min(o,n.quoteDepth)+1];case"no-open-quote":return n.quoteDepth++,new z("");case"no-close-quote":return n.quoteDepth>0&&n.quoteDepth--,new z("")}return e}format(e,n){return this.cascade.counterStyleStore.format(n,e)}formatCounterList(e,n,s){if(!e.length)return this.format(0,s);let o=new lt;for(let r=0;r<e.length;r++)r>0&&o.append(n),o.append(this.format(e[r],s));return o.toString()}formatLastValue(e,n){let s=e.length?e[e.length-1]:0;return this.format(s,n)}buildCounterText(e,n,s,o,r){var f,g,m,b,y,C;let a=typeof r=="string",l=N=>a?this.formatCounterList(N,r,s):this.formatLastValue(N,s),c=N=>{this.pseudoName==="footnote-call"&&this.element&&dC(this.element,n,N)};if(this.pseudoName==="footnote-call"&&this.element){let N=rx(this.element,n);if(N)return l(N)}if(this.pseudoName==="footnote-marker"&&this.element){let x=zl(this.element)[n];if(x)return l(x)}let u;if(n==="pages")return l([]);if(!this.element){let N=((f=e.currentPageCounters)==null?void 0:f[n])||[];if(N.length)return u=N,c(u),l(u)}let d=this.element?o:((g=e.currentPageDocCounters)==null?void 0:g[n])||o;if((m=e.isPageControlledCounter)!=null&&m.call(e,n)){let N=((b=e.currentPageDocCounters)==null?void 0:b[n])||[],x=((y=e.currentPageCounters)==null?void 0:y[n])||[],E=x.length?x[x.length-1]:0,v=N.length?N[0]:0,T=d.length?d[0]:0,k=E+(T-v);return u=d.length?[k,...d.slice(1)]:x.length?x:[0],c(u),l(u)}return d.length?(u=d,c(u),l(u)):(u=((C=e.currentPageCounters)==null?void 0:C[n])||[],c(u),l(u))}visitFuncCounter(e){var l;let n=e[0].toString(),s=e.length>1?e[1].stringValue():"decimal",o=(this.cascade.counters[n]||[]).slice(),r=this.getCounterStore();if(r){let c=n==="pages"||((l=r==null?void 0:r.isPageControlledCounter)==null?void 0:l.call(r,n)),u=this.getPageScope(),d=new ne(u,()=>this.buildCounterText(r,n,s,o),c?`page-counter-${n}`:`counter-${n}`);if(c&&(r!=null&&r.registerPageCounterExpr)){let h=f=>this.formatLastValue(f,s);r.registerPageCounterExpr(n,h,d)}return new D(d)}let a=this.cascade.counters[n];if(a&&a.length){let c=a&&a.length&&a[a.length-1]||0;return new z(this.format(c,s))}else{let c=new D(this.counterResolver.getPageCounterVal(n,u=>this.format(u||0,s)));return new X([c])}}visitFuncCounters(e){var d;let n=e[0].toString(),s=e[1].stringValue(),o=e.length>2?e[2].stringValue():"decimal",r=(this.cascade.counters[n]||[]).slice(),a=this.getCounterStore();if(a){let h=n==="pages"||((d=a==null?void 0:a.isPageControlledCounter)==null?void 0:d.call(a,n)),f=this.getPageScope(),g=new ne(f,()=>this.buildCounterText(a,n,o,r,s),h?`page-counters-${n}`:`counters-${n}`);return h&&(a!=null&&a.registerPageCounterExpr)&&a.registerPageCounterExpr(n,m=>this.formatCounterList(m,s,o),g),new D(g)}let l=this.cascade.counters[n],c=new lt;if(l&&l.length)for(let h=0;h<l.length;h++)h>0&&c.append(s),c.append(this.format(l[h],o));let u=new D(this.counterResolver.getPageCountersVal(n,h=>{let f=[];if(h.length)for(let m=0;m<h.length;m++)f.push(this.format(h[m],o));let g=c.toString();return g.length&&f.push(g),f.length?f.join(s):this.format(0,o)}));return new X([u])}visitFuncTargetCounter(e){let n=e[0],s;n instanceof ke?s=n.url:s=n.stringValue();let o=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",a=new D(this.counterResolver.getTargetCounterVal(s,o,l=>this.format(l||0,r)));return new X([a])}visitFuncTargetCounters(e){let n=e[0],s;n instanceof ke?s=n.url:s=n.stringValue();let o=e[1].toString(),r=e[2].stringValue(),a=e.length>3?e[3].stringValue():"decimal",l=new D(this.counterResolver.getTargetCountersVal(s,o,c=>{let u=c.map(d=>this.format(d,a));return u.length?u.join(r):this.format(0,a)}));return new X([l])}visitFuncTargetText(e){let n=e[0],s;n instanceof ke?s=n.url:s=n.stringValue();let o=e.length>1?e[1].stringValue():"content",r=new D(this.counterResolver.getTargetTextVal(s,o));return new X([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 o,r,a,l,c,u,d,h;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 f=(o=this.element)==null?void 0:o.querySelectorAll(`[data-adapt-pseudo="${n}"]`),g=null;if(f&&this.element)for(let m=0;m<f.length;m++){let b=f[m];if(b.parentElement===this.element){g=b;break}}if(g)s=g.textContent||"";else{let m=it(this.cascade.currentStyle,"_pseudos"),b=(a=(r=m==null?void 0:m[n])==null?void 0:r.content)==null?void 0:a.value;if(b)s=this.evaluateAndGetString(b);else if(n==="marker"){let y=(l=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:l.value;s=ql(y,this.cascade.context)}}}break;case"first-letter":{let f=it(this.cascade.currentStyle,"_pseudos"),g=(u=(c=f==null?void 0:f.before)==null?void 0:c.content)==null?void 0:u.value,m=(h=(d=f==null?void 0:f.after)==null?void 0:d.content)==null?void 0:h.value,b=(this.evaluateAndGetString(g)||this.element.textContent||this.evaluateAndGetString(m)).match(qs);s=b?b[0]:""}break}return new z(s)}visitFuncLeader(e){let n="";if(e[0]instanceof Q)switch(e[0].stringValue()){case"dotted":n=".";break;case"solid":n="_";break;case"space":n=" ";break}else e[0]instanceof z&&(n=e[0].stringValue());return n.length==0?new z(""):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 hp(i,t,e){let n;if(i.nodeType===1)n=Array.from(i.getClientRects());else{let o=i.ownerDocument.createRange();o.selectNodeContents(i),n=t.getRangeClientRects(o)}return n.reduce((o,r)=>o+(e==="vertical-rl"||e==="vertical-lr"?r.height:r.width),0)}var lx=(i,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 y=function(U){m==="rtl"?u.textContent=(U.startsWith("\u200F")?"":"\u200F")+U+(U.endsWith("\u200F")?"":"\u200F"):u.textContent=U},q=function(){let U=e.clientLayout.getElementClientRect(d);return g==="vertical-rl"||g==="vertical-lr"?m==="rtl"?U.top-=M:U.bottom+=M:m==="rtl"?U.left-=M:U.right+=M,x.left>U.left||x.right<U.right||x.top>U.top||x.bottom<U.bottom},J=function(){let U,j,H=f.repeat(1e4);if(y(H),q())U=1,j=1e4;else return;for(let _=0;_<16;_++){let Y="",Ee=Math.floor((U+j)/2);for(let Ve=0;Ve<Ee;Ve++)Y+=f;if(y(Y),q())j=Ee;else{if(U==Ee)return;U=Ee}}y(f)},le=function(U){let j=0,H=d.parentElement;for(;H&&H!==c.viewNode;)j+=e.getComputedInsets(H)[U],H=H.parentElement;return j};var s=y,o=q,r=J,a=le;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:b}=e.clientLayout.getElementComputedStyle(d);u.style.marginInlineStart="1px",y(f),d.style.display="inline-block",d.style.textIndent="0";let C=fr(c.viewNode),N=(C==null?void 0:C.style.columnFill)||null;C&&(C.style.columnFill="auto");let x=e.clientLayout.getElementClientRect(c.viewNode),E=e.clientLayout.getElementClientRect(d),v=e.parseComputedLength(b),T=[],k=d.parentElement;for(;k.parentElement&&k.parentElement!==c.viewNode;)k=k.parentElement;let L=k.nextSibling;for(;L;){if(L.nodeType===1){let U=L,{display:j,float:H,position:_}=e.clientLayout.getElementComputedStyle(U);if(H!=="none"||_==="absolute"||_==="fixed"){L=L.nextSibling;continue}if(Et(j))T.push(U);else if(gm(j))break}else if(L.nodeType===3){let U=L;U.length>0&&T.push(U)}L=L.nextSibling}let M=T.reduce((U,j)=>U+hp(j,e.clientLayout,g),0);if(h!=="after"){let U=hp(k,e.clientLayout,g),j=hp(d,e.clientLayout,g);M+=U-j}g==="vertical-rl"||g==="vertical-lr"?(m==="rtl"?x.top+=v:x.bottom-=v,x.top=Math.min(E.top,x.top),x.bottom=Math.max(E.bottom,x.bottom)):(m==="rtl"?x.left+=v:x.right-=v,x.left=Math.min(E.left,x.left),x.right=Math.max(E.right,x.right)),J();let re=e.clientLayout.getElementClientRect(d);m=="rtl"?d.style.float="left":d.style.float="right";let xe=e.clientLayout.getElementClientRect(d),F=0;m=="rtl"?g=="vertical-rl"||g=="vertical-lr"?F=re.top-xe.top-le("top"):F=re.left-xe.left-le("left"):g=="vertical-rl"||g=="vertical-lr"?F=xe.bottom-re.bottom-le("bottom"):F=xe.right-re.right-le("right"),F-=M,F=Math.max(0,F-.1),d.style.float="",u.style.marginInlineStart=`${F}px`,C&&(N?C.style.columnFill=N:C.style.removeProperty("column-fill"))}};je("POST_LAYOUT_BLOCK",lx);var sh=1/1048576;function vr(i,t){for(let e in i)t[e]=i[e].clone()}var Gp=class i{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 i;t.nsCount=this.nsCount;for(let e in this.nsPrefix)t.nsPrefix[e]=this.nsPrefix[e];return vr(this.tags,t.tags),vr(this.nstags,t.nstags),vr(this.epubtypes,t.epubtypes),vr(this.classes,t.classes),vr(this.ids,t.ids),vr(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,o,r){return new $p(this,t,e,n,s,o,r)}nextOrder(){return this.order+=sh}},ec=class ec{constructor(t,e,n,s,o,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",Object.create(null));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,"pageTypePageIndices",Object.create(null));p(this,"isFirst",!0);p(this,"isRoot",!0);p(this,"counters",Object.create(null));p(this,"lastCounterChanges",[]);p(this,"lastCounterChangeTypes",Object.create(null));p(this,"counterScoping",[Object.create(null)]);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",Object.create(null));p(this,"dependentConditions",[]);p(this,"elementStack");this.code=t,this.quotes=[new z("\u201C"),new z("\u201D"),new z("\u2018"),new z("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(t){this.stack[this.stack.length-1].push(t)}increment(t,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=So.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(s=>{let o=this.viewConditions[s];return o&&o.length>0?o.length===1?o[0]:So.buildAnyMatcher([].concat(o)):null}).filter(s=>s);return n.length<=0?e:e===null?n.length===1?n[0]:So.buildAllMatcher(n):So.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=fp,this.currentPageType=e,this.applyActions()}defineCounter(t,e){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(e)):this.counters[t]=[e],n[t]=!0}pushCounters(t){var g,m,b,y,C,N,x;let e=new Set,n=Object.create(null),s=S.inline,o=t.display;if(o&&(s=o.evaluate(this.context)),s===S.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let r=S.inline,a=t.float;a&&(r=a.evaluate(this.context));let l=null,c=null,u=null,d=t["counter-reset"];if(d){let E=d.evaluate(this.context);E&&(l=vs(E,{reset:!0}))}let h=t["counter-set"];if(h){let E=h.evaluate(this.context);E&&(u=vs(E,{defaultValue:0}))}let f=t["counter-increment"];if(f){let E=f.evaluate(this.context);E&&(c=vs(E))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(l||(l=Object.create(null)),l["list-item"]=((m=(g=this.currentElement)==null?void 0:g.start)!=null?m:1)-1),fo(s)&&(c||(c=Object.create(null)),c["list-item"]=(b=c["list-item"])!=null?b:1,/^\s*[-+]?\d/.test((C=(y=this.currentElement)==null?void 0:y.getAttribute("value"))!=null?C:"")&&(u||(u=Object.create(null)),u["list-item"]=this.currentElement.value)),((N=this.currentElement)==null?void 0:N.parentNode.nodeType)===Node.DOCUMENT_NODE&&(l||(l=Object.create(null)),l.footnote===void 0&&(l.footnote=0)),r===S.footnote&&!this.currentStyle["--viv-semantic-footnote-content"]&&(c||(c=Object.create(null)),c.footnote===void 0)){let E=(x=this.currentStyle["counter-increment"])==null?void 0:x.value;(!E||!(E===S.footnote||E instanceof X&&E.values.includes(S.footnote)))&&(c.footnote=1)}if(l)for(let E in l)e.add(E),n[E]="reset";if(c)for(let E in c)e.add(E),n[E]||(n[E]="increment");if(u)for(let E in u)e.add(E),n[E]="set";if(this.lastCounterChanges=Array.from(e),this.lastCounterChangeTypes=n,l)for(let E in l)this.defineCounter(E,l[E]);if(c)for(let E in c){this.counters[E]||this.defineCounter(E,0);let v=this.counters[E];v[v.length-1]+=c[E]}if(u)for(let E in u)if(!this.counters[E])this.defineCounter(E,u[E]);else{let v=this.counters[E];v[v.length-1]=u[E]}if(fo(s)){let E=this.counters["list-item"],v=E[E.length-1];t["ua-list-item-count"]=new V(new Ue(v),0);let T=Yt(t,"_pseudos");T.marker||(T.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 is(this,this.currentElement,this.counterResolver));let n=e.value instanceof ve?e.value.values:[e.value];for(let s of n)if(s instanceof X){let o=s.values[0].stringValue(),r=s.values.slice(1).map(a=>ql(a,this.context)).join("");this.counterResolver.setNamedString(o,r,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let e=t.position;if((e==null?void 0:e.value)instanceof Bt&&e.value.name==="running"){let n=e.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,e,n){this.pushCounters(t);let s=t.content;s&&(t.content=s.filterValue(new is(this,e,this.counterResolver,n))),this.popCounters()}pushElement(t,e,n,s){var E,v,T;this.currentPageType=null,this.currentElement=e,this.currentElementOffset=s,this.currentStyle=n,this.currentNamespace=e.namespaceURI,this.currentLocalName=e.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+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=fp;let a=e.getAttributeNS("http://www.idpf.org/2007/ops","type");a?this.currentEpubTypes=a.split(/\s+/):this.currentEpubTypes=fp;let l=$r(e);l&&(this.stack[this.stack.length-1].push(new Up(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,b=this.currentFollowingSiblingTypeCounts=m[m.length-1];b&&b[this.currentNamespace]&&b[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 y=n.quotes,C=null;if(y){let k=y.evaluate(this.context);k&&(C=new Hp(this.quotes),k===S.none?this.quotes=[new z(""),new z("")]:k===S.auto||k===S.initial?this.quotes=[new z("\u201C"),new z("\u201D"),new z("\u2018"),new z("\u2019")]:k instanceof X&&(this.quotes=k.values))}this.pushCounters(this.currentStyle);let N=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(c||N){let k=Object.create(null);Object.keys(this.counters).forEach(L=>{k[L]=Array.from(this.counters[L])}),this.counterListener.countersOfId(N,k)}let x=it(this.currentStyle,"_pseudos");if(x){let k=!0;for(let L of cx){L||(k=!1);let M=x[L];if(M){let q=(E=ee(this.currentStyle,"float"))==null?void 0:E.value,J=e instanceof Element&&bt(e),re=e instanceof Element&&rt(e),xe=!!ee(this.currentStyle,"--viv-semantic-footnote-content"),le=q===S.footnote,F=(L==="before"||L==="after")&&(le||re||xe)&&!!M.content,U=ix(M),j=L==="footnote-call"&&J&&U,H=L==="footnote-marker"&&(re||xe)&&U;if((L==="before"||L==="after")&&!(F||nt((v=M.content)==null?void 0:v.value)||this.hasNonTrivialViewConditionalPseudoContent(M))||L==="marker"&&!fo((T=ee(this.currentStyle,"display"))==null?void 0:T.value)||(L==="footnote-call"||L==="footnote-marker")&&q!==S.footnote&&!j&&!H||(L==="footnote-call"||L==="footnote-marker")&&xe&&!U)delete x[L];else if(k){if(this.processPseudoelementProps(M,e,L),L==="marker")this.processMarkerPseudoelementProps(M,e,t),delete x[L];else if(L==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(M,"list-style-position",t,e)===S.outside){this.processMarkerPseudoelementProps(M,e,t);let Y=M.content;Y&&(this.currentStyle["_footnote-marker-content"]=Y),this.currentStyle.display=new V(R("list-item"),0),this.currentStyle["list-style-position"]=new V(S.outside,0),this.currentStyle["list-style-type"]=new V(S.none,0),this.currentStyle["list-style-image"]=new V(S.none,0),delete x[L]}}else if(L==="first-letter"&&M["initial-letter"]){let Y=M["initial-letter"].evaluate(this.context);Y!==S.normal&&!W(Y)&&(this.currentStyle["--viv-initialLetter"]=new V(Y,0)),delete M["initial-letter"]}}else this.stack[this.stack.length-2].push(new _p(M,e))}}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),C&&this.stack[this.stack.length-2].push(C)}hasNonTrivialViewConditionalPseudoContent(t){let e=t._viewConditionalStyles;return!e||e.length<=0?!1:e.some(n=>{var s;return nt((s=n.styles.content)==null?void 0:s.value)})}processMarkerPseudoelementProps(t,e,n){var r,a,l,c,u;let s=fo((r=this.currentStyle.display)==null?void 0:r.value);if(!nt((a=t.content)==null?void 0:a.value)&&s){let d=this.getInheritedPropertyValue("list-style-type",n,e),h=this.getInheritedPropertyValue("list-style-image",n,e);if(h instanceof ke)t.content=new V(new X([h,new z(" ")]),0);else if(d instanceof z)t.content=new V(d,0);else if(d instanceof Q&&d!==S.none){let f=(c=(l=this.currentStyle["ua-list-item-count"])==null?void 0:l.value)==null?void 0:c.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new V(new z(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let o=t.content;if(o){let d=o.value;if(nt(d)){let h=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new V(h,0)}}for(let d of ec.markerAllowedProps){let h=t[d];if(h){let f=h.evaluate(this.context,d);f&&!W(f)&&(this.currentStyle[`--viv-marker-${d}`]=new V(f,0))}}if(!Et((u=ee(this.currentStyle,"display"))==null?void 0:u.value)){let d=this.getInheritedPropertyValue("list-style-position",n,e);d&&d!==S.outside&&!W(d)&&(this.currentStyle["list-style-position"]=new V(d,0))}}resolveMarkerContentVal(t){if(t instanceof D){let e=t.expr.evaluate(this.context);return typeof e=="string"?new z(e):typeof e=="number"?new z(String(e)):t}if(t instanceof X){let e=t.values.map(n=>this.resolveMarkerContentVal(n));return new X(e)}return t}getInheritedPropertyValue(t,e,n){var o;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===S.inherit||c===S.unset||c===S.revert)continue;if(c===S.initial)break;return c}}let s=e.validatorSet;return(o=s==null?void 0:s.defaultValues[t])!=null?o:null}resolvePseudoelementInheritedPropertyValue(t,e,n,s){var r;let o=t[e];if(o){let a=o.evaluate(this.context,e);if(a!==S.inherit&&a!==S.unset&&a!==S.revert){if(a===S.initial){let l=n.validatorSet;return(r=l==null?void 0:l.defaultValues[e])!=null?r:null}return a}}return this.getInheritedPropertyValue(e,n,s)}applyAttrFilterInner(t,e){for(let n in e)Ds(n)&&!Dt(n)&&(e[n]=e[n].filterValue(t))}applyAttrFilter(t){let e=new zp(t),n=this.currentStyle,s=it(n,"_pseudos");for(let o in s)this.applyAttrFilterInner(e,s[o]);this.applyAttrFilterInner(e,n)}applyVarFilter(t,e,n){var l,c,u;let s=t[0],o=new Zp(t,e,n),r=32,a={};for(let d in s)if(Hl(d)){let h=it(s,d);for(let f in h)this.applyVarFilter([h[f],...t],e,n)}else if(Ds(d)){let h=ee(s,d),f=h.value;for(let g=0;;g++){if(g>=r){f=$;break}let m=f.visit(o);if(o.error){f=$,o.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(W(f)){for(let b of m.propList){let y=new V(f,h.priority),C=ee(s,b);Hn(a,b,mp(this.context,C,y))}delete s[d]}else{let b=Ts(e.scope,new ot(f.toString(),null),"");if(b&&(b.visit(m),!m.error)){for(let y of m.propList){let C=new V((u=(c=m.values[y])!=null?c:g.defaultValues[y])!=null?u:S.initial,h.priority),N=ee(s,y);Hn(a,y,mp(this.context,N,C))}delete s[d]}}else s[d]=new V(f,h.priority)}if(a[d]){let g=ee(s,d);g&&g.value!==$&&on(a,d,g,this.context)}}for(let d in a)s[d]=a[d]}applyCalcFilter(t,e){let n=new Jl(e);for(let s in t)if(Hl(s)){let o=it(t,s);for(let r in o)this.applyCalcFilter(o[r],e)}else if(Ds(s)&&!Dt(s)){let o=ee(t,s),r=o.value.visit(n);r!==o.value&&(t[s]=new V(r,o.priority))}}applyCmykFilter(t,e){let n=new Zo(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 o=it(t,s);for(let r in o)this.applyCmykFilterInternal(o[r],e,`::${r}:`)}else if(Ds(s)&&!Dt(s)){let o=ee(t,s),r=o.value.toString();e.reset();let a=o.value.visit(e);a!==o.value&&(e.hadDeviceCmyk()&&e.recordConversion(n+s,r),t[s]=new V(a,o.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let 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()}};p(ec,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var $p=ec,fp=[],cx=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"];var Wp=null;function gC(i){Wp=i}var as=class extends nn{constructor(e,n,s,o,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,"selectorFunctionContainsPseudoelement",!1);p(this,"footnoteContent",!1);p(this,"cascade");p(this,"state");p(this,"viewConditionId",null);p(this,"insideSelectorRule");p(this,"invalid",!1);this.cascade=o?o.cascade:Wp?Wp.clone():new Gp,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let n=nh(this.chain,e);n!==e&&n.makePrimary(this.cascade)||this.insertNonPrimary(n)}invalidContinuationAfterPseudoelement(e){return this.pseudoelement?(this.invalidSelector(`::${this.pseudoelement} followed by ${e}`),!0):this.selectorFunctionContainsPseudoelement?(this.invalidSelector(`Selector containing pseudo-element followed by ${e}`),!0):!1}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,n){!n&&!e||this.invalidContinuationAfterPseudoelement(n||"*")||(n&&(this.specificity+=1),n&&e?this.chain.push(new Sp(e,n.toLowerCase())):n?this.chain.push(new $l(n.toLowerCase())):this.chain.push(new Ep(e)))}invalidSelector(e){B.warn(e),this.chain.push(new Ze("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Ms;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new bp(e)))}pseudoclassSelector(e,n){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Ap);break;case"disabled":this.chain.push(new Rp);break;case"checked":this.chain.push(new Lp);break;case"root":case"scope":this.chain.push(new wp);break;case"link":this.chain.push(new $l("a")),this.chain.push(new Wl("","href"));break;case"href-epub-type":case"href-role-type":if(n&&n.length>=1&&typeof n[0]=="string"){let s=n[0],o=new RegExp(`(^|\\s)${jn(s)}($|\\s)`),r=n[1];this.chain.push(new xp(o,r,e==="href-role-type"))}else this.chain.push(new Ze(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ze(""));break;case"lang":if(n&&n.length==1&&typeof n[0]=="string"){let s=n[0];this.chain.push(new Tp(new RegExp(`^${jn(s.toLowerCase())}($|-)`)))}else this.chain.push(new Ze(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let s=ux[e.toLowerCase()];n&&n.length==2?this.chain.push(new s(n[0],n[1])):this.chain.push(new Ze(""));break}case"first-child":this.chain.push(new Xl);break;case"last-child":this.chain.push(new Pi(0,1));break;case"first-of-type":this.chain.push(new wi(0,1));break;case"last-of-type":this.chain.push(new ki(0,1));break;case"only-child":this.chain.push(new Xl),this.chain.push(new Pi(0,1));break;case"only-of-type":this.chain.push(new wi(0,1)),this.chain.push(new ki(0,1));break;case"empty":this.chain.push(new kp);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){if(!this.invalidContinuationAfterPseudoelement(`::${e}`)){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(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 Ze(""));break;case"nth-fragment":n&&n.length==2?this.viewConditionId=`NFS_${n[0]}_${n[1]}`:this.chain.push(new Ze(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new yp(e)))}attributeSelector(e,n,s,o){if(this.invalidContinuationAfterPseudoelement(`[${n}]`))return;this.specificity+=256,n=n.toLowerCase(),o=o||"";let r;switch(s){case 0:r=new Wl(e,n);break;case 39:r=new vp(e,n,o);break;case 45:!o||o.match(/\s/)?r=new Ze(""):r=new xo(e,n,new RegExp(`(^|\\s)${jn(o)}($|\\s)`));break;case 44:r=new xo(e,n,new RegExp(`^${jn(o)}($|-)`));break;case 43:o?r=new xo(e,n,new RegExp(`^${jn(o)}`)):r=new Ze("");break;case 42:o?r=new xo(e,n,new RegExp(`${jn(o)}$`)):r=new Ze("");break;case 46:o?r=new xo(e,n,new RegExp(jn(o))):r=new Ze("");break;case 50:if(o=="supported")r=new Np(e,n);else{this.invalidSelector(`Unsupported :: attr selector op: ${o}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${s}`);return}this.chain.push(r)}descendantSelector(){if(this.invalidContinuationAfterPseudoelement("descendant selector"))return;let e=`d${Ul++}`;this.processChain(new Nr(new Op(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${Ul++}`;this.processChain(new Nr(new Bp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${Ul++}`;this.processChain(new Nr(new Dp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${Ul++}`;this.processChain(new Nr(new Mp(e,this.viewConditionId,null))),this.chain=[new Ze(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.selectorFunctionContainsPseudoelement=!1,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,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.selectorFunctionContainsPseudoelement=!1,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 Eo(this.elementStyle,e,this.pseudoelement,n,this.viewConditionId)}special(e,n){let s;this.condition?s=new Ti(n,0,this.condition):s=new V(n,0),hC(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===S.oeb_page_head||n===S.oeb_page_foot)&&(this.simpleProperty("flow-options",new X([S.exclusive,S._static]),s),this.simpleProperty("flow-into",n,s),n=S.block),Je("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 Ti(n,a,this.condition):new V(n,a);on(this.elementStyle,e,l)}finish(){return this.cascade}startFuncWithSelector(e,n){let s;switch(e){case"is":s=new Ms(this);break;case"not":s=new Xp(this);break;case"where":s=new jp(this);break;case"has":s=new Yp(this);break;case"nth-child":n&&n.length>=2&&(s=new Kl(this,n[0],n[1]));break;case"nth-last-child":n&&n.length>=2&&(s=new qp(this,n[0],n[1]));break}s&&(s.startSelectorRule(),this.owner.pushHandler(s))}},ux={"nth-child":Pp,"nth-of-type":wi,"nth-last-child":Pi,"nth-last-of-type":ki},Ul=0,Ms=class i extends as{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",[]);p(this,"containsPseudoelementSelector",!1);this.parentChain=e.chain}nextSelector(){this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){var e;this.containsPseudoelementSelector||(this.containsPseudoelementSelector=!!this.pseudoelement),this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Fp(this.selectorTexts):this.positive()?new Ai(this.chains):new Ip(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(e=this.parent).selectorFunctionContainsPseudoelement||(e.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new Ze("")),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 o=this;o instanceof i;o=o.parent)if(o.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}},Xp=class extends Ms{positive(){return!1}forgiving(){return!1}},jp=class extends Ms{increasingSpecificity(){return!1}},Yp=class extends Ms{relational(){return!0}},Kl=class extends Ms{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 Ze("")),this.owner.popHandler()}forgiving(){return!0}},qp=class extends Kl{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Vp(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ze("")),this.owner.popHandler()}},Zl=class extends nn{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",o=new dn(this.scope,100,s);this.scope.defineName(t,e.toExpr(this.scope,o))}}},vo=class extends nn{constructor(e,n,s,o,r,a){super(e,n,!1);this.condition=s;this.elementStyle=o;this.validatorSet=r;this.ruleType=a;p(this,"order");this.order=0}property(e,n,s){s?B.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){B.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){B.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?this.getImportantSpecificity():this.getBaseSpecificity();o+=this.order,this.order+=sh;let r=this.condition?new Ti(n,o,this.condition):new V(n,o);on(this.elementStyle,e,r)}},Kp=class extends hi{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){B.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){B.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?fl:hl;o+=this.order,this.order+=sh;let r=new V(n,o);on(this.elementStyle,e,r)}};function oh(i,t){let e=pC(i);e&&e.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Ql(i,t,e){oh(e,n=>{kr(i,n,t)})}function mC(i,t,e,n){let s=new Kp(i,t),o=new ot(n,s);try{dm(o,s,e)}catch(r){B.warn(r,"Style attribute parse error:")}return s.elementStyle}function oc(i,t,e){let n=i["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==S.inherit&&s!==S.revert&&s!==S.unset)return s===S.vertical_rl}return e}function rc(i,t,e){let n=i.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==S.inherit&&s!==S.revert&&s!==S.unset)return s===S.rtl}return e}function Li(i,t,e,n,s){let o={};for(let r in i)Ds(r)&&(o[r]=ee(i,r));return Ql(o,t,i),rh(i,e,n,(r,a)=>{kr(o,a,t),Ql(o,t,a)}),o}function rh(i,t,e,n){let s=it(i,"_regions");if((t||e)&&s){if(e){let o=["footnote"];t?t=t.concat(o):t=o}for(let o of t){let r=s[o];r&&n(o,r)}}}function kr(i,t,e){for(let n in t)if(Ds(n)){let s=ee(t,n),o=i[n];i[n]=mp(e,o,s)}}var ic=(i,t,e,n,s,o)=>{var l,c;let r=e?n?tx:Jp:n?nx:eh,a=s?sx:ox;for(let u in i){let d=i[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 b=i[g];if(b&&b.priority>d.priority||h&&f&&h!==f&&(g=f,b=i[g],b&&b.priority>d.priority))continue;m=lC[h]?h:lC[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===S.inside||d.value===S.outside)&&(d=new V(s===(d.value===S.inside)?S.right:S.left,d.priority));t[m]=o(u,d)}},Zp=class extends en{constructor(e,n,s){super();this.elementStyles=e;this.styler=n;this.element=s}getVarValue(e){var s,o,r,a,l;let n=(s=this.element)!=null?s:this.styler.root;if((o=this.elementStyles)!=null&&o.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 Q&&e.values[0].name;if(!n||!Dt(n))return this.error=!0,$;let s=this.getVarValue(n);return s||(e.values.length<2?(this.error=!0,$):e.values.length===2?e.values[1]:new ve(e.values.slice(1)))}},Jl=class extends en{constructor(e,n,s,o){super();this.context=e;this.resolveViewportUnit=n;this.percentRef=s;this.vertical=o}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 o=Ts(this.context.rootScope,new ot(s,null),"");if(o instanceof D)try{let r=o.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 A(r,"px"):/\d[a-z]/i.test(s)||(n=new Ue(r)))}catch(r){B.warn(r)}return n}visitNumeric(e){return this.resolveViewportUnit&&_u(e.unit)||this.context.rootFontSize!=null&&vg(e.unit)?new A(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new A(e.num*this.percentRef/100,"px"):e}};function Ii(i,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:pm(i,t.expr,e);if(t instanceof A||t instanceof Bt||t instanceof X||t instanceof ve)return t.visit(new Jl(i,!0,n,s))}catch(o){return B.warn(o),$}return t}var CC={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function bC(i){let t=i instanceof _e?i:typeof i=="string"?R(i):S.none;if(t===S.none)return CC;let e=t instanceof X?t.values:[t],n=Object.create(CC);for(let s of e)if(s instanceof Q)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 yC(i){return!i.first&&!i.last&&!i.forceEnd&&!i.allowEnd}var dx={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},SC={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},xC={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function EC(i){let t=i instanceof _e?i:typeof i=="string"?R(i):S.normal;if(t===S.normal)return SC;if(t===S.auto)return xC;let e=t instanceof X?t.values:[t],n=Object.create(SC);for(let s of e)if(s instanceof Q)switch(s.name){case"trim-both":case"trim-auto":return xC;case"space-all":return dx;case"trim-start":n.trimStart=!0,n.spaceFirst=!1;break;case"space-start":n.trimStart=!1,n.spaceFirst=!1;break;case"space-first":n.trimStart=!1,n.spaceFirst=!0;break;case"trim-end":n.trimEnd=!0,n.allowEnd=!1;break;case"space-end":n.trimEnd=!1,n.allowEnd=!1;break;case"allow-end":n.trimEnd=!1,n.allowEnd=!0;break;case"trim-adjacent":n.trimAdjacent=!0;break;case"space-adjacent":n.trimAdjacent=!1;break}return n}var ih={ideographAlpha:!1,ideographNumeric:!1},px={ideographAlpha:!0,ideographNumeric:!0};function vC(i){let t=i instanceof _e?i:typeof i=="string"?R(i):S.normal;if(t===S.normal||t===S.auto)return px;if(t===S.none)return ih;let e=t instanceof X?t.values:[t],n=Object.create(ih);for(let s of e)if(s instanceof Q)switch(s.name){case"no-autospace":return ih;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function NC(i,t){return!i.ideographAlpha&&!i.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function TC(i){return i?(i=i.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(i)?"zh-hant":/^zh\b/.test(i)?"zh-hans":/^ja\b/.test(i)?"ja":/^ko\b/.test(i)?"ko":i):null}var ah=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 o=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(o.length>1){let r=o.length-1;for(let a=0;a<r;a++)s.parentNode.insertBefore(document.createTextNode(o[a]),s);s.textContent=o[r]}}}processGeneratedContent(t,e,n,s,o,r){o=TC(o);let a=vC(e),l=EC(n),c=bC(s);if(yC(c)&&NC(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,b=!h||/\n$/.test(h.textContent),y=!f||/^\n/.test(f.textContent),C=!f;this.processTextSpacing(g,m||b,m,b,y,C,h,f,a,l,c,o,r),h=g}t.style.whiteSpace=u}postLayoutBlock(t,e){var d,h,f,g,m,b,y,C;let n=!t||t.fragmentIndex===1&&r(),s=n||a();function o(N){var T;if((N==null?void 0:N.nodeType)!==1)return!1;let x=N;if(x.hasAttribute(Fn))return!0;let{position:E,float:v}=(T=x.style)!=null?T:{};return E==="absolute"||E==="fixed"||v&&v!=="none"}function r(){let N=e[0];for(let x=N;;x=x.parent)if(!x||!x.inline){if((x==null?void 0:x.fragmentIndex)!==1)return!1;break}if(!N.inline)return!0;for(let x=N.viewNode.previousSibling;x;x=x.previousSibling)if(!pe(x,N.whitespace)&&!o(x))return!1;return!0}function a(){var E,v;let N=e[0],x;for(;N&&N.inline&&(x=(E=N.viewNode)==null?void 0:E.previousSibling,!(x&&(x.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(x.textContent)&&N.whitespace!==Ct.PRESERVE&&(x=x.previousSibling),x)));)N=N.parent;for(;x;){if(x.nodeType===Node.ELEMENT_NODE){if(x.localName==="br")return!0;let T=(v=x.style)==null?void 0:v.display;if(T&&T!=="inline")return!/^(inline|ruby)\b/.test(T)}else if(x.nodeType===Node.TEXT_NODE){if(N.whitespace===Ct.PRESERVE){if(/\n$/.test(x.textContent))return!0}else if(N.whitespace===Ct.NEWLINE&&/\n[ \t\r\n\f]*$/.test(x.textContent))return!0}x=x.lastChild}return!1}let l=-1;for(let N=0;N<e.length;N++){let x=e[N];if(!x.after&&x.inline&&!x.display&&x.parent&&x.viewNode.parentNode&&x.viewNode.nodeType===Node.TEXT_NODE&&!pe(x.viewNode,x.whitespace)){let F=function(H){var _,Y,Ee;if(((_=H.viewNode)==null?void 0:_.nodeType)===Node.ELEMENT_NODE)return H.viewNode.localName==="br";if(((Y=H.viewNode)==null?void 0:Y.nodeType)===Node.TEXT_NODE){let Ve=H.viewNode;if(H.whitespace===Ct.PRESERVE){if(/\n$/.test(Ve.textContent))return!0}else if(H.whitespace===Ct.NEWLINE&&/\n[ \t\r\n\f]*$/.test(Ve.textContent))return!0;if(((Ee=Ve.previousElementSibling)==null?void 0:Ee.localName)==="br")return pe(Ve,H.whitespace)}return!1},U=function(H){var _,Y,Ee;if(((_=H.viewNode)==null?void 0:_.nodeType)===Node.ELEMENT_NODE)return H.viewNode.localName==="br";if(((Y=H.viewNode)==null?void 0:Y.nodeType)===Node.TEXT_NODE){let Ve=H.viewNode;if(H.whitespace===Ct.PRESERVE){if(/^\n/.test(Ve.textContent))return!0}else if(H.whitespace===Ct.NEWLINE&&/^[ \t\r\n\f]*\n/.test(Ve.textContent))return!0;if(((Ee=Ve.nextElementSibling)==null?void 0:Ee.localName)==="br")return pe(Ve,H.whitespace)}return!1};var c=F,u=U;l<0&&(l=N);let E=TC((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),v=vC(x.inheritedProps["text-autospace"]),T=EC(x.inheritedProps["text-spacing-trim"]),k=bC(x.inheritedProps["hanging-punctuation"]);if(yC(k)&&NC(v,T)||/\b(flex|grid)\b/.test(x.parent.display))continue;let L=null,M=null,q=N===l,J=N===l&&n,re=N===l&&s,xe=!1,le=!1;for(let H=N-1;H>=0;H--){let _=e[H];if(F(_)){re=!0;break}if(!_.display&&_.viewNode.nodeType===Node.TEXT_NODE&&_.viewNode.textContent.length>0){L=_.viewNode;break}if(((m=_.viewNode)==null?void 0:m.nodeType)===Node.ELEMENT_NODE&&qt(_.viewNode)==="footnote-call"){if(_.viewNode.contains(x.viewNode))continue;let Y=Tm(_.viewNode);if(Y){L=Y;break}}if(_.display&&!/^(inline|ruby)\b/.test(_.display)||((b=_.viewNode)==null?void 0:b.nodeType)===Node.ELEMENT_NODE&&(_.viewNode.localName==="br"||Pn[_.viewNode.localName]))break;H===0&&(q=!0,n&&(J=!0,re=!0))}for(let H=N+1;H<e.length;H++){let _=e[H];if(U(_)){xe=!0;break}if(_.viewNode!==x.viewNode&&!_.display&&_.viewNode.nodeType===Node.TEXT_NODE&&_.viewNode.textContent.length>0){M=_.viewNode;break}if(_.display&&!/^(inline|ruby)\b/.test(_.display)||((y=_.viewNode)==null?void 0:y.nodeType)===Node.ELEMENT_NODE&&(_.viewNode.localName==="br"||Pn[_.viewNode.localName])){H===e.length-1&&o(_.viewNode)&&(le=!0);break}if(H===e.length-1){xe=!0,le=!0;for(let Y=_.viewNode.nextSibling;Y;Y=Y.nextSibling)if(!o(Y)){le=!1;break}}}if(((C=x.parent)==null?void 0:C.display)==="inline-block"){if(!J){let H=x.parent.viewNode.firstChild;for(;pe(H,x.whitespace);)H=H.nextSibling;x.viewNode===H&&(J=!0)}if(!le){let H=x.parent.viewNode.lastChild;for(;pe(H,x.whitespace);)H=H.previousSibling;x.viewNode===H&&(le=!0)}}if(this.processTextSpacing(x.viewNode,q,J,re,xe,le,L,M,v,T,k,E,x.vertical)>0)break}}}processTextSpacing(t,e,n,s,o,r,a,l,c,u,d,h,f){let g=t.textContent,m=t.ownerDocument,b=0,y,C,N;function x(){if(e)return!0;if(!a)return!1;y||(y=m.createRange(),y.selectNode(t));let F=y.getClientRects()[0];if(!F)return!1;C||(C=m.createRange(),C.selectNode(a));let U=C.getClientRects(),j=U[U.length-1];return j?(b||(b=go(j,f)),f?F.top<j.top+j.height-F.width||F.left+F.width<j.left+F.width/10||F.left>j.left+j.width-F.width/10:F.left<j.left+j.width-F.height||F.top>j.top+j.height-F.height/10||F.top+F.height<j.top+F.height/10):!1}function E(){if(!l)return!1;y||(y=m.createRange(),y.selectNode(t));let F=y.getClientRects()[0];if(!F)return!1;b||(b=go(F,f)),N||(N=m.createRange(),N.selectNode(l));let U=N.getClientRects()[0];return U?f?F.top+F.height>U.top+F.width||F.left>U.left+U.width-F.width/10||F.left+F.width<U.left+F.width/10:F.left+F.width>U.left+F.height||F.top+F.height<U.top+F.height/10||F.top>U.top+U.height-F.height/10:!1}let v=!1,T=!1,k=!1,L=!1,M;if(n&&d.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(g)?(M="viv-ts-open",v=!0,T=!0):r&&d.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(g)?(M="viv-ts-close",v=!0,k=!0):(d.forceEnd||d.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(g)?(M="viv-ts-close",v=!0,L=!0):(u.trimStart||u.spaceFirst||u.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(g)?(M="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))&&(M="viv-ts-close",v=!0),v){let j=function(Y){let Ve=parseFloat(m.defaultView.getComputedStyle(Y).fontSize)*.7;return(f?Y.offsetHeight:Y.offsetWidth)>Ve},_=function(){return f?F.offsetLeft:F.offsetTop};var xe=j,le=_;if(t.parentElement.localName==="viv-ts-inner")return 0;let F=m.createElement(M),U=m.createElement("viv-ts-inner");F.appendChild(U),t.parentNode.insertBefore(F,t),U.appendChild(t);let H=j(U);if(H||T||k||L){if(M==="viv-ts-open"){if(T)F.className="viv-hang-first";else if(n||s)u.trimStart?F.className="viv-ts-trim":F.className="viv-ts-space";else if(!(u.trimStart||u.spaceFirst)&&x())F.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"&&j(a.parentElement)))F.className="viv-ts-trim";else if((u.trimStart||u.spaceFirst)&&x()){let Y=_();F.className="viv-ts-auto",Y===_()&&!x()&&(F.className="viv-ts-trim")}}else if(M==="viv-ts-close"){if(k)F.className=H?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||o){let Y=_();L?(F.className=H?d.allowEnd&&u.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",d.allowEnd&&Y===_()&&(u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-hang-end",Y===_()&&(F.className="")):F.className="viv-ts-space")):u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-ts-auto",Y===_()&&(F.className="")):F.className="viv-ts-space"}else if(l&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(l.textContent))H&&u.trimAdjacent&&(F.className="viv-ts-trim");else if(L){let Y=E(),Ee=Y&&d.allowEnd;Ee||(F.className=H?"viv-hang-end":"viv-hang-end viv-hang-hw"),H?Ee&&u.trimEnd?F.className="viv-ts-auto":!Ee&&!E()?F.className="":!Y&&d.allowEnd&&(u.trimEnd?(F.className="viv-ts-auto",E()||(F.className="viv-hang-end")):(F.className="viv-ts-space",E()||(u.allowEnd?(F.className="viv-ts-auto",E()||(F.className="viv-hang-end")):F.className="viv-hang-end"))):!Y&&!E()&&(F.className="")}else if(u.trimEnd||u.allowEnd)if(E())u.allowEnd?F.className="viv-ts-space":F.className="viv-ts-auto";else{let Y=_();F.className="viv-ts-auto",Y===_()&&(F.className="")}}}}let q=!1;function J(F){var j;let U=(j=F==null?void 0:F.ownerDocument.defaultView)==null?void 0:j.getComputedStyle(F);return!!U&&(U.textOrientation==="upright"||U.textCombineUpright==="all"||U["-webkit-text-combine"]==="horizontal")}function re(F,U){if(F.nodeType===Node.ELEMENT_NODE){let _=m.defaultView.getComputedStyle(F);if(parseFloat(_.marginInlineEnd)||parseFloat(_.borderInlineEndWidth)||parseFloat(_.paddingInlineEnd))return!0}let j=F.parentElement;if(j&&!j.contains(U))return re(j,U);if(U.nodeType===Node.ELEMENT_NODE){let _=m.defaultView.getComputedStyle(U);if(parseFloat(_.marginInlineStart)||parseFloat(_.borderInlineStartWidth)||parseFloat(_.paddingInlineStart))return!0}let H=U.parentElement;return H&&!H.contains(F)?re(F,H):!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&&J(a.parentElement))&&!re(a,t)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t),q=!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&&J(l.parentElement))&&!re(t,l)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t.nextSibling),q=!0)),b}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)}},lh=new ah;lh.registerHooks();function wC(i){lh.preprocessForTextSpacing(i)}function PC(i,t,e,n,s,o){lh.processGeneratedContent(i,t,e,n,s,o)}var No=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),AC=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],ac="data-adapt-pseudo";function qt(i){return i.getAttribute(ac)||""}function To(i,t){i.setAttribute(ac,t)}var Ar=class{constructor(t,e,n,s,o){this.element=t;this.style=e;this.styler=n;this.context=s;this.exprContentListener=o;p(this,"contentProcessed",{})}getStyle(t,e){let n=qt(t);this.styler&&n&&n.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let s=it(this.style,"_pseudos"),o=(s==null?void 0:s[n])||{};if(n.match(/^first-/)&&!o["x-first-pseudo"]){let r=1,a;n=="first-letter"?r=0:(a=n.match(/^first-([0-9]+)-lines$/))!=null&&(r=a[1]-0),o["x-first-pseudo"]=new V(new ce(r),0)}return o}processContent(t,e,n){let s=qt(t);if(!this.contentProcessed[s]){this.contentProcessed[s]=!0;let o=e.content;nt(o)&&(o.visit(new Dn(t,this.context,o,this.exprContentListener)),wC(t))}}};var Kv=Ci.isInstanceOfAfterIfContinuesLayoutConstraint,LC=Bs.registerFragmentIndex,Zv=Bs.clearFragmentIndices,lc=class{constructor(t,e){this.sourceNode=t;this.styler=e}createElement(t,e){let s=e.viewNode.ownerDocument.createElement("div"),o=new ko(t,s,e),r=o.getColumn().pageBreakType;return o.getColumn().pageBreakType=null,o.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,o.getColumn().pageBreakType=r;let a=s.firstChild;return P(a,"display","block"),w(a)})}createNodePositionForPseudoElement(){let t=No.createElementNS("http://www.w3.org/1999/xhtml","div");To(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 _t(s)}createShadowContext(t){return new Is(this.sourceNode,t,null,null,null,sn.ShadowType.ROOTED,this.styler)}},uh=class i{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),w(!0))):w(!0)}getRepetitiveElements(){return new dh(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof i?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},dh=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 IC(i,t){if(!i||!i.afterIfContinues||i.after||t.isFloatNodeContext(i))return w(i);let e=i.afterIfContinues;return e.createElement(t,i).thenAsync(n=>{let s=fx(i,t,n);return t.fragmentLayoutConstraints.push(new uh(i,e,s)),w(i)})}function gh(i,t){return i.thenAsync(e=>IC(e,t))}function hx(i,t){let e=I("processAfterIfContinuesOfAncestors"),n=i;return e.loop(()=>{if(n!==null){let s=IC(n,t);return n=n.parent,s.thenReturn(!0)}else return w(!1)}).then(()=>{e.finish(!0)}),e.result()}function fx(i,t,e){let n=i.viewNode;n.appendChild(e);let s=gi(e,t,i.vertical);return n.removeChild(e),s}var cc=class{constructor(t){this.constraints=t}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},wo=class extends bo{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 Po=class extends yr{constructor(e,n,s,o,r){super(e);this.layoutContext=n;this.clientLayout=s;this.layoutConstraint=o;this.pageFloatLayoutContext=r;p(this,"last");p(this,"viewDocument");p(this,"flowRootFormattingContext",null);p(this,"isNonFirstColumn",!1);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,"lastLineStride",0);p(this,"breakAtTheEdgeBeforeFloat",null);bm(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,n,s=1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-n)<s}isOverflown(e){return this.almostEquals(e,this.footnoteEdge)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let n=I("openAllViews"),s=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let o=s.length-1,r=null;return n.loop(()=>{for(;o>=0;){let a=r,l=s[o];if(r=Sr(l,a),o===s.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),o==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let c=this.layoutContext.setCurrent(r,o==0&&r.offsetInNode==0);if(o--,c.isPending())return c}return w(!1)}).then(()=>{n.finish(r)}),n.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?zm(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,n){var s,o;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,a=r.match(qs),l=a?a[0].length:0;if(!a&&((s=e.sourceNode)==null?void 0:s.nodeType)===3&&((o=e.sourceNode.nextSibling)==null?void 0:o.nodeType)===3&&r===e.sourceNode.textContent){let c=r+e.sourceNode.nextSibling.textContent,u=c.match(qs);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 w(e)}buildViewToNextBlockEdge(e,n){let s=!1,o=I("buildViewToNextBlockEdge");return o.loopWithFrame(r=>{var a;if(e.viewNode&&!es(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(go(u,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(l=>{let c=l;c!==e&&(e=c,es(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)&&(Sn(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(()=>{o.finish(e)}),o.result()}nextInTree(e,n){let s=this.layoutContext.nextInTree(e,n);return gh(s,this)}buildDeepElementView(e){if(!e.viewNode)return w(e);let n=[],s=e.sourceNode,o=I("buildDeepElementView");return o.loopWithFrame(r=>{e.viewNode&&e.inline&&!es(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}es(l)||n.push(l.copy())}this.nextInTree(l).then(c=>{if(e=c,!e||e.sourceNode==s){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(Sn(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(u=>{if(e=u,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{n.length>0&&this.postLayoutBlock(e,n),o.finish(e)}),o.result()}createFloat(e,n,s,o){let r=this.viewDocument.createElement("div");return this.vertical?(o>=this.height&&(o-=.1),o<1&&(o=0),P(r,"height",`${s}px`),P(r,"width",`${o}px`)):(s>=this.width&&(s-=.1),s<1&&(s=0),P(r,"width",`${s}px`),P(r,"height",`${o}px`)),P(r,"float",n),P(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,o=s.style.cssFloat;if(o=="left"||o=="right"||o==="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(),o=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),a=this.vertical?-this.getLeftEdge():this.getBottomEdge(),l=null;for(let f of n)this.almostEquals(f.x1,s)?f.x1=s:this.almostEquals(f.x1,o)&&(f.x1=o),this.almostEquals(f.x2,o)?f.x2=o:this.almostEquals(f.x2,s)&&(f.x2=s),this.almostEquals(f.y1,r)?f.y1=r:this.almostEquals(f.y1,a)&&(f.y1=a),this.almostEquals(f.y2,a)?f.y2=a:this.almostEquals(f.y2,r)&&(f.y2=r);let c=1/(this.clientLayout.pixelRatio||1),u=Mo==="webkit"?Math.floor:Math.round,d=n.map(f=>(u(f.y2/c)-u(f.y1/c))*c),h=.01;for(let f=0;f<n.length;f++){let g=f<n.length-1?n[f+1].x1:s,m=f<n.length-1?n[f+1].x2:o,b=g-n[f].x1,y=n[f].x2-m,C=0,N=0;b>h?C=1:b<-h&&(C=-1),y>h?N=1:y<-h&&(N=-1);let x=C!==0&&N!==0?C===N?C:0:C||N;if(x!==0){let E=x*c;d[f]+E>=0&&(f>=n.length-1||d[f+1]-E>=0)&&(d[f]+=E,f<n.length-1&&(d[f+1]-=E))}}for(let f=0;f<n.length;f++){let g=n[f];g.left=this.createFloat(e,"left",g.x1-s,d[f]),g.right=this.createFloat(e,"right",o-g.x2,d[f]),g.x1<o&&g.x2>s?l=g:l||P(g.right,"float","none")}if(l){let f=n[n.length-1];if(l!==f&&f.y2>=a&&(this.footnoteEdge=this.vertical?-l.y2:l.y2,l.x1===s&&l.x2===o))for(let g=n.indexOf(l);g<n.length;g++){let m=n[g];this.element.removeChild(m.left),this.element.removeChild(m.right),m.left=null,m.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var s;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(s=this.element.parentElement)!=null&&s.hasAttribute("data-vivliostyle-in-column-balancing"))return;let e=this.vertical?this.width:this.height,n=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge);if(n>0&&n<e&&!this.almostEquals(n,e)){let o=this.vertical?"width":"height";if(P(this.element,o,`${n}px`),this.vertical){let r=this.left+(e-n);P(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,n,s,o){let r;if(e&&Jn(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=ws(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=n[s];let a=o-e.boxOffset;for(;;){if(r=ws(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 er(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 er(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 er(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=I("layoutFloat"),s=e.viewNode,o=Ol(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return P(s,"float","none"),P(s,"display","inline-block"),P(s,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let a=vt(this.clientLayout,s,this.vertical),l=this.getComputedMargin(s),c=new st(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 v=h.viewNode.ownerDocument.createElement("div");v.style.left="0px",v.style.top="0px",this.vertical?(v.style.bottom="0px",v.style.width="1px"):(v.style.right="0px",v.style.height="1px"),h.viewNode.appendChild(v);let T=vt(this.clientLayout,v,this.vertical);u=Math.max(this.rtl?this.getEndEdge(T):this.getStartEdge(T),u),d=Math.min(this.rtl?this.getStartEdge(T):this.getEndEdge(T),d),h.viewNode.removeChild(v);let k=this.vertical?c.y2-c.y1:c.x2-c.x1;o=="left"?d=Math.max(d,u+k):u=Math.min(u,d-k),h!==e.parent&&!e.firstPseudo&&(h.viewNode.appendChild(s),s.setAttribute("data-vivliostyle-float-box-moved","true"))}let f=new st(u,this.getBoxDir()*this.beforeEdge,d,this.getBoxDir()*this.afterEdge),g=c;this.vertical&&(g=tr(c));let m=this.getBoxDir();if(g.y1<this.bottommostFloatTop*m){let v=g.y2-g.y1;g.y1=this.bottommostFloatTop*m,g.y2=g.y1+v}if(e.clearSide){let v=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?Ol(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?o:e.clearSide,T=this.beforeEdge;v!=="right"&&(T=m*Math.max(T*m,this.leftFloatEdge*m)),v!=="left"&&(T=m*Math.max(T*m,this.rightFloatEdge*m));let k=T*m;if(g.y1<k){let L=g.y2-g.y1;g.y1=k,g.y2=g.y1+L}}f.y2+=1/(this.clientLayout.pixelRatio||1),_g(f,this.bands,g,o),this.vertical&&(c=sl(g));let b=this.getComputedInsets(s);P(s,"width",`${c.x2-c.x1-b.left-b.right}px`),P(s,"height",`${c.y2-c.y1-b.top-b.bottom}px`),P(s,"position","absolute"),e.display,P(s,"display",e.display);let y,C=null;if(h&&(h.containingBlockForAbsolute?C=h:C=h.getContainingBlockForAbsolute()),C){let v=C.viewNode.ownerDocument.createElement("div");v.style.position="absolute",C.vertical?v.style.right="0":v.style.left="0",v.style.top="0",C.viewNode.appendChild(v),y=vt(this.clientLayout,v,this.vertical),C.viewNode.removeChild(v)}else y={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(C?C.vertical:this.vertical){let v=Math.max(0,y.right-c.x2);P(s,"right",`${v}px`)}else{let v=Math.max(0,c.x1-y.left);P(s,"left",`${v}px`)}let N=Math.max(0,c.y1-y.top);P(s,"top",`${N}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let x=this.vertical?c.x1:c.y2,E=this.vertical?c.x2:c.y1;!this.isOverflown(x)||this.breakPositions.length==0?(this.killFloats(),f=new st(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(f=tr(f)),Ug(f,this.bands,g,null,o),this.createFloats(),o=="left"?this.leftFloatEdge=x:this.rightFloatEdge=x,this.bottommostFloatTop=E,this.updateMaxReachedAfterEdge(x),n.finish(r)):(e=e.modify(),e.overflow=!0,n.finish(e))}),n.result()}setupFloatArea(e,n,s,o,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();return 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).thenAsync(()=>{e.init();let h=!!l.setFloatAreaDimensions(e,n,s,o,!0,e.isFootnote||!l.hasFloatFragments(),a);if(h){if(e.isFootnote){let f=getComputedStyle(e.element);if(e.vertical){let g=parseFloat(f.maxWidth);!isNaN(g)&&e.width>g&&(e.width=g,P(e.element,"width",`${g}px`))}else{let g=parseFloat(f.maxHeight);!isNaN(g)&&e.height>g&&(e.height=g,P(e.element,"height",`${g}px`))}}e.killFloats(),e.init()}else c.element.parentNode.removeChild(u);return w(h)})}createPageFloatArea(e,n,s,o,r){let a=this.element.ownerDocument.createElement("div");P(a,"position","absolute");let l=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),c=new Mn(null,ue.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);c.setOuterContext(this.pageFloatLayoutContext);let u=l.getContainer(),d=new fh(n,a,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,c,u);return c.setContainer(d),this.setupFloatArea(d,e.floatReference,n,s,o,r).thenAsync(h=>h?w(d):w(null))}layoutSinglePageFloatFragment(e,n,s,o,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={floatArea:null,pageFloatFragment:null,newPosition:null},g=I("layoutSinglePageFloatFragment");return this.createPageFloatArea(d,n,a,r,h).then(m=>{if(f.floatArea=m,!m){g.finish(f);return}let b=!1,y=0;g.loopWithFrame(C=>{if(y>=e.length){C.breakLoop();return}let N=e[y],x=new _t(N.nodePosition);m.layout(x,!0).then(E=>{f.newPosition=E,!E||o?(y++,C.continueLoop()):(b=!0,C.breakLoop())})}).then(()=>{if(!b&&m.isFootnote&&m.computedBlockSize<=0&&f.newPosition){let C=c.getPageFloatLayoutContext(d.floatReference);if(C.footnoteMaxBlockSize==null){if(C.initFootnoteRetryFromEmptyFragment(d,m)){m.element.parentNode&&m.element.parentNode.removeChild(m.element),this.layoutSinglePageFloatFragment(e,n,s,o,r,a,l).then(N=>{g.finish(N)});return}b=!0}}if(!b){m.isFootnote&&m.applyCompactFootnoteDisplay();let C=c.setFloatAreaDimensions(m,d.floatReference,n,a,!1,o,h);if(!C)b=!0;else{let N=r.createPageFloatFragment(e,C,s,m,!!f.newPosition);c.addPageFloatFragment(N,!0),f.pageFloatFragment=N}}g.finish(f)})}),g.result()}layoutPageFloatInner(e,n,s,o){let r=this.pageFloatLayoutContext,a=e.float,l=new Set;for(let h=r;h;h=h.effectiveParent)for(let f of h.floatFragments)f.continuations.some(g=>g.float.insidePageFloatArea)&&l.add(f);r.stashEndFloatFragments(a);function c(h,f){f?r.removePageFloatFragment(f,!0):h&&h.element.parentNode.removeChild(h.element);let g=[];for(let m=r;m;m=m.effectiveParent)for(let b of m.floatFragments)!l.has(b)&&b.continuations.some(y=>y.float.insidePageFloatArea)&&g.push(b);for(let m of g)r.removePageFloatFragment(m,!0);r.restoreStashedFragments(a.floatReference),r.deferPageFloat(e)}let u=a instanceof Co,d=I("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],a.floatSide,a.clearSide,u||!r.hasFloatFragments(),n,s,o).then(h=>{let f=h.floatArea,g=h.pageFloatFragment,m=h.newPosition;g?this.layoutStashedPageFloats(a.floatReference,[o]).then(b=>{if(b){let y=!!r.generatingNodePosition;if(r.addPageFloatFragment(g,y),r.discardStashedFragments(a.floatReference),m){let C=new xi(a,m.primary);r.deferPageFloat(C)}d.finish(!0)}else c(f,g),d.finish(!1)}):(c(f,g),d.finish(!1))}),d.result()}layoutStashedPageFloats(e,n){let s=this.pageFloatLayoutContext,o=s.getStashedFloatFragments(e),r=[],a=[],l=!1,c=I("layoutStashedPageFloats"),u=0;return c.loopWithFrame(d=>{if(u>=o.length){d.breakLoop();return}let h=o[u];if(n.includes(h)){u++,d.continueLoop();return}let f=new yn().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 b=g.pageFloatFragment;b?(a.push(b),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)})):o.forEach(d=>{let h=d.area.element;h&&h.parentNode&&h.parentNode.removeChild(h)}),c.finish(!l)}),c.result()}findFootnoteCallElement(e){let n=e.previousSibling;for(;n;){if(n.nodeType===Node.ELEMENT_NODE&&qt(n)==="footnote-call")return n;n=n.previousSibling}return null}setFloatAnchorViewNode(e){let n=e.viewNode.parentNode,s=n.ownerDocument.createElement("span");if(s.setAttribute(Fn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?s=r:n.insertBefore(s,e.viewNode)}else n.appendChild(s);n.removeChild(e.viewNode);let o=e.modify();return o.after=!0,o.viewNode=s,e.floatSide==="footnote"&&(o.display="inline"),o}resolveFloatReferenceFromColumnSpan(e,n,s){let o=I("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,a=r.getPageFloatLayoutContext(ue.REGION);return r.getContainer().width<a.getContainer().width&&e===ue.COLUMN?n===S.auto?this.buildDeepElementView(s.copy()).then(c=>{let u=c.viewNode,d=gr(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?o.finish(ue.REGION):o.finish(e)}):n===S.all?o.finish(ue.REGION):o.finish(e):o.finish(e),o.result()}layoutPageFloat(e){let n=this.pageFloatLayoutContext,s=new yn().findByNodeContext(e),o,r=n.findPageFloatByNodePosition(e.toNodePosition());return r?o=w(r):o=s.createPageFloat(e,n,this),o.thenAsync(a=>{let l=mo(e,0),c=this.setFloatAnchorViewNode(e);n.markPageFloatAnchorSeen(a);let u=s.findPageFloatFragment(a,n),d=new xi(a,l);if(u&&u.hasFloat(a))return n.registerPageFloatAnchor(a,c.viewNode),w(c);if(n.isForbidden(a)||n.hasPrecedingFloatsDeferredToNext(a))return n.deferPageFloat(d),n.registerPageFloatAnchor(a,c.viewNode),w(c);if(this.nodeContextOverflowingDueToRepetitiveElements)return w(null);{let h=ws(c,this.clientLayout,0,this.vertical);if(isNaN(h)&&e.floatSide==="footnote"){let f=c.viewNode;if(f&&f.nodeType===1){let g=vt(this.clientLayout,f,this.vertical);g.right>=g.left&&g.bottom>=g.top&&(h=this.vertical?g.left:g.bottom)}}return this.isOverflown(h)?w(c):this.layoutPageFloatInner(d,s,h,u).thenAsync(f=>f?e.floatSide==="footnote"?w(c):n.generatingNodePosition?w(c):w(null):(n.registerPageFloatAnchor(a,c.viewNode),w(c)))}})}processLineStyling(e,n,s){let o=I("processLineStyling"),r=s.concat([]);s.splice(0,s.length);let a=0,l=e.firstPseudo;return l.count==0&&(l=l.outer),o.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),o.finish(n)}),o.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 o=e.length-1;o>=0;o--){let r=e[o];if(!r||!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=I("layoutBreakableBlock"),s=[];return this.buildViewToNextBlockEdge(e,s).then(o=>{let r=s.length-1;if(r<0){n.finish(o);return}this.postLayoutBlock(o,s);let a=this.suppressOpenAncestorBlockEndInset(o!=null?o:e),l=this.calculateEdge(o,s,r,s[r].boxOffset);a();let c=!1;if(!o||!Jn(o.viewNode)){let d=Fs(o,this.collectElementsOffset());c=this.isOverflown(l+(this.vertical?-1:1)*d.minimum),this.isOverflown(l+(this.vertical?-1:1)*d.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=o)}o==null&&(l+=this.getTrailingMarginEdgeAdjustment(s)),this.updateMaxReachedAfterEdge(l);let u;e.firstPseudo?u=this.processLineStyling(e,o,s):u=w(o),u.then(d=>{s.length>0&&(this.saveBoxBreakPosition(s),c&&!this.isLoneImage(s)&&d&&(d=d.modify(),d.overflow=!0)),n.finish(d)})}),n.result()}postLayoutBlock(e,n){Je("POST_LAYOUT_BLOCK").forEach(o=>{o(e,n,this)})}findEndOfLine(e,n,s){let o=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<=o:f>=o){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 o=this.findEndOfLine(n,e,!0),r=o.nodeContext;if(o.checkPointIndex===0&&o.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,o.index,e,o.checkPointIndex,s)}else{let d=Od(r);if(d){if(((c=this.breakPositions)==null?void 0:c[0])instanceof wo&&(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&&(pe(h,r.parent.whitespace)||Vn(h));)h=h.previousSibling;if(h)break;r=r.parent}}}return this.clearOverflownViewNodes(r,!1),r}resolveTextNodeBreaker(e){return Je("RESOLVE_TEXT_NODE_BREAKER").reduce((s,o)=>o(e)||s,Rr.instance)}getRangeBoxes(e,n){let s=[],o=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:El(f)?d=!c:!f.firstChild||Pn[f.localName]||/^r(uby|[bt]c?)$/.test(f.localName)||Nm(this.clientLayout.getElementComputedStyle(f).display)?(d=!c,d?(f.localName==="ruby"&&a.firstChild&&(a=a.firstChild),o.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:(o.setStartBefore(a),c=!0)),l=a),h||(h=a.nextSibling,h||(r=!0,h=a.parentNode)),a=h}while(d&&u);if(c){o.setEndAfter(l);let h=this.clientLayout.getRangeClientRects(o);Sl(h,this.vertical);for(let f=0;f<h.length;f++)s.push(h[f]);c=!1}}return s}findLinePositions(e){let o=[],r=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);r.sort(this.vertical?Ym:jm);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&&(o.push(l),u=0),d>=r.length)break}return o.sort(La),this.vertical&&o.reverse(),o}calculateClonedPaddingBorder(e){let n=0;for(let s=e;s;s=s.parent)if(!s.inline&&Ps(s.viewNode)){let o=this.getComputedPaddingBorder(s.viewNode);n+=s.vertical?-o.left:o.bottom,s.display==="table"&&(n+=(s.vertical?-1:1)*s.blockBorderSpacing)}return n}getOffsetByRepetitiveElements(e){let n;return e?n=e.calculateOffset(this):n=Fs(null,this.collectElementsOffset()),n.current}findBoxBreakPosition(e,n){let s=this.element.parentNode,o=this.element.nextSibling;s.removeChild(this.element),s.insertBefore(this.element,o);let r=e.checkPoints,a=r[0];for(;a.parent&&a.inline;)a=a.parent;let l,c;n&&!this.isFootnote?(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 b=Ft(d.length,x=>{let E=d[x];return this.vertical?E<h||E<=m.edge:E>h||E>=m.edge}),y=b<=0;y&&(b=Ft(d.length,x=>this.vertical?d[x]<h:d[x]>h));let C=r[r.length-1].viewNode;if((C==null?void 0:C.parentElement.localName)==="viv-ts-inner"&&(C=C.parentElement.parentElement),(b===d.length&&C.nextSibling||b>=d.length-1&&C.parentElement.querySelector(".MJXc-display"))&&(l=0,c=1),b=Math.min(d.length-l,b),b<c)return null;h=d[b-1];let N;if(y?N=m.checkPoint:N=this.findAcceptableBreakInside(e.checkPoints,h,n),N){let x=this.getAfterEdgeOfBlockContainer(N);if(!isNaN(x)&&f*(h-x)>0&&(h=x),this.computedBlockSize=f*(h-this.beforeEdge)+g,d.length>=2){let E=Math.max(1,Math.min(b-1,d.length-1));this.lastLineStride=Math.abs(d[E]-d[E-1])}}return N}getAfterEdgeOfBlockContainer(e){let n=e;do n=n.parent;while(n&&n.inline);return n?(n=n.copy().modify(),n.after=!0,ws(n,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let n=e.findIndex(o=>o.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=Ni.finishBreak(this,e,n,s)),r}findAcceptableBreakPosition(){let e=null,n=null,s=0,o=0;do{s=o,o=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&&(o=Math.min(o,a))}}while(o>s&&!n&&this.forceNonfitting);return{breakPosition:n?e:null,nodeContext:n}}doFinishBreak(e,n,s,o){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!n)return w(e);let r=I("doFinishBreak"),a=!1;if(!e){if(this.forceNonfitting&&!this.isFootnote)return B.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=o}return this.finishBreak(e,a,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let n=e;n;n=n.parent)if(Vn(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}isZeroLength(e){let n=e.trim();return n===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(n)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!hr(this))return()=>{};let n=[];for(let s=e==null?void 0:e.parent;s;s=s.parent){if(s.after||s.inline)continue;let o=s.viewNode;if(!o||o.nodeType!==1||Ps(o))continue;let r=this.clientLayout.getElementComputedStyle(o);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let a=o.getAttribute("data-viv-box-break");mt(o,"block-end"),n.push({element:o,original:a})}return()=>{for(let{element:s,original:o}of n)o===null?s.removeAttribute("data-viv-box-break"):s.setAttribute("data-viv-box-break",o)}}checkOverflowAndSaveEdge(e,n){if(!e)return!1;for(let l=e;l;l=l.parent)if(Vn(l.viewNode))return!1;if(Jn(e.viewNode))return!1;let s=this.suppressOpenAncestorBlockEndInset(e),o=ws(e,this.clientLayout,0,this.vertical);s();let r=Fs(e,this.collectElementsOffset()),a=this.isOverflown(o+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(o+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(n){let l=o+this.getTrailingMarginEdgeAdjustment(n),c=this.footnoteEdge-this.getBoxDir()*r.current;o=this.vertical?Math.min(o,Math.max(l,c)):Math.max(o,Math.min(l,c))}return this.updateMaxReachedAfterEdge(o),a}checkOverflowAndSaveEdgeAndBreakPosition(e,n,s,o){if(!e||Jn(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,n);return(s||!r)&&this.saveEdgeBreakPosition(e,o,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==ue.INLINE||e.floatSide)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 o=vt(this.clientLayout,s,this.vertical),r=this.getBeforeEdge(o),a=this.getBoxDir(),l=e.clearSide==="same"?e.floatSide:e.clearSide,c=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(l)?Ol(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),h=d;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 f=1/(this.clientLayout.pixelRatio||1),g=d*a>h*a;d=a*(Math.ceil(d*a/f)+(g?1:0))*f;let m=f;if(r*a+m>d*a)return e.viewNode.parentNode.removeChild(s),!1;{let b=Math.max(1,(d-r)*a);this.vertical?s.style.width=`${b}px`:s.style.height=`${b}px`,o=vt(this.clientLayout,s,this.vertical);let y=this.getAfterEdge(o);if(!e.floatSide)if(this.vertical){let C=y-n.right-d;C>0==n.right>=0&&(C+=n.right),s.style.marginLeft=`${C}px`}else{let C=d-(y+n.top);C>0==n.top>=0&&(C+=n.top),s.style.marginBottom=`${C}px`}return e.clearSpacer=s,!0}}isBFC(e){return!!(oC(e)||Bn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let n=e;n;n=n.parent)if(Vd(n.viewNode))return!0;return!1}skipEdges(e,n,s){var E;let o=e.after?(E=e.parent)==null?void 0:E.formattingContext:e.formattingContext;if(o&&!this.isBFC(o))return w(e);let r=I("skipEdges"),a=this,l=!s&&n&&e&&e.after,c=s,u=null,d=[],h=[],f=!1;function g(v){var T,k;if(!(!n||a.isNonFirstColumn||s||!Hd(c))){for(let L=v;L;L=L.parent)if(L.breakBefore==="column"&&(L.breakBefore=null),((T=L.viewNode)==null?void 0:T.nodeType)===1){let M=L.viewNode;((k=M.style)==null?void 0:k.breakBefore)==="column"&&(M.style.breakBefore="")}}}function m(v){var T,k;if(!(!n||!a.isNonFirstColumn||s||c!=="column")){for(let L=v;L;L=L.parent)if(L.breakBefore==="column"&&(L.breakBefore=null),((T=L.viewNode)==null?void 0:T.nodeType)===1){let M=L.viewNode;((k=M.style)==null?void 0:k.breakBefore)==="column"&&(M.style.breakBefore="")}c=null}}function b(v){var T,k;if(!(s||!Hd(c))){for(let L=v;L;L=L.parent)if(L.breakAfter==="column"&&(L.breakAfter=null),((T=L.viewNode)==null?void 0:T.nodeType)===1){let M=L.viewNode;((k=M.style)==null?void 0:k.breakAfter)==="column"&&(M.style.breakAfter="")}}}function y(v){c=De(c,v)}function C(){return s?!0:Ne(c)?n?a.isNonFirstColumn&&c!=="column"&&c!=="region":!N():!1}function N(){var v;if(!u||!e||e.floatSide)return!1;for(let T=u;T!=null&&T.parent;T=T.parent){if(T.parent.viewNode&&Vn(T.parent.viewNode))continue;let k=T.after?T.viewNode:(v=T.viewNode)==null?void 0:v.previousSibling;for(;k&&(pe(k,T.parent.whitespace)||Vn(k));)k=k.previousSibling;if(k)return!1}return!0}let x=()=>{e=d[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=c};return r.loopWithFrame(v=>{var T;for(;e;){e.formattingContext;let k=new Vs().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(pe(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){C()?x():this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)?(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0):(!u&&!n&&d.length===0&&this.saveEdgeBreakPosition(e,c,!1),e=e.modify(),e.breakBefore=c),v.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=mr(c)?c:null),k&&k.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&n&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),c,!1),!e.inline&&!e.repeatOnBreak&&(u?Od(u):this.breakPositions[this.breakPositions.length-1]instanceof wo||!n&&d.length===0)&&this.saveEdgeBreakPosition(e.copy(),c,!1),!this.isBFC(e.formattingContext)||Bn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&pe(e.sourceNode.firstChild,e.whitespace)){d.push(e.copy()),y(e.breakBefore),g(e),m(e),C()?x():(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),v.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let M=e.viewNode,q=M.style;if(e.after){Id(M,this),e.floatSide&&(c=c!=null?c:this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let J=e.sourceNode;if(J.localName==="svg"||J.localName==="math"||J.getAttribute("data-math-typeset")==="true"){f=!1,u=e.copy(),h.push(u),c=null,y(e.breakAfter),b(e),this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c);break}if(e.inline||k&&k.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(f){if(Vd(e.viewNode))break;if(C()){x(),v.breakLoop();return}d=[],n=!1,l=!1,c=null}f=!1,Fd(e.viewNode)||(u=e.copy(),h.push(u)),y(e.breakAfter),b(e),q&&!Vn(e.viewNode)&&this.hasNonZeroBlockEndInset(q)&&(h=u?[u]:[])}else{if(d.push(e.copy()),y(e.breakBefore),g(e),m(e),u&&Ne(c)&&Sm(u.viewNode,e.viewNode),(e.pageType!=((T=e.parent)==null?void 0:T.pageType)||!Ne(c))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){v.breakLoop();return}let J=e.viewNode.localName;if(Pn[J]){C()?x():this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),v.breakLoop();return}q&&this.hasNonZeroBlockStartInset(q)&&(l=!1,h=[]),f=!0}}while(!1);let L=this.nextInTree(e,l);if(L.isPending()){L.then(M=>{e=M,v.continueLoop()});return}else e=L.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(u,h,!this.stopAtOverflow,c)?u&&this.stopAtOverflow&&(e=u.modify(),e.overflow=!0):Ne(c)&&(this.pageBreakType=c),v.breakLoop()}).then(()=>{u&&(this.lastAfterPosition=u.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let n=e.copy(),s=I("skipEdges"),o=null,r=!1;return s.loopWithFrame(a=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(pe(e.viewNode,e.whitespace))break;if(!e.after){Ne(o)&&(this.pageBreakType=o),a.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){o=De(o,e.breakBefore),Ne(o)&&(this.pageBreakType=o),a.breakLoop();return}if(e.viewNode.nodeType!=1)break;let c=e.viewNode.style;if(e.after){if(r){if(Ne(o)){this.pageBreakType=o,a.breakLoop();return}o=null}r=!1,o=De(o,e.breakAfter)}else{o=De(o,e.breakBefore);let u=e.viewNode.localName;if(Pn[u]){Ne(o)&&(this.pageBreakType=o),a.breakLoop();return}if(c&&this.hasNonZeroBlockStartInset(c)){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){if(Sn(e.floatReference)||e.floatSide==="footnote"){let n=this.pageFloatLayoutContext.generatingNodePosition;if(n&&e.sourceNode===n.steps[0].node){let s=e.modify();return s.floatSide=null,s.floatReference=ue.INLINE,s.clearSide=null,this.isBreakable(s)?this.layoutBreakableBlock(s):this.layoutUnbreakable(s)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,n,s){let o=I("layoutNext");return this.skipEdges(e,n,s||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))o.finish(e);else{let a=e.formattingContext;new Vs().find(a).layout(e,this,n).thenFinish(o)}}),o.result()}clearOverflownViewNodes(e,n){if(e)for(let s=e.parent;e;e=s,s=s?s.parent:null){let o=(s||e).formattingContext;new Vs().find(o).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(),o=this.originY+this.top+this.getInsetTop();this.box=new st(s,o,s+this.width,o+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=Vg(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],P(this.element,"width",`${this.width}px`),P(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,n,s){e.formattingContext;let o=e.copy(),r=new Vs().find(e.formattingContext),a=this.calculateClonedPaddingBorder(o),l=r.createEdgeBreakPosition(o,n,s,this.computedBlockSize+a);this.breakPositions.push(l)}saveBoxBreakPosition(e){let n=e[0].breakPenalty;if(n){let o=e[0];for(;o.parent&&o.inline;)o=o.parent;n=o.breakPenalty}let s=new wo(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 w(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?w(null):w(e);fi(this);let o=I("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 ph(n,s);l.layout(r,this).then(c=>{this.doFinishBreak(c,l.context.overflownNodeContext,a,l.initialComputedBlockSize).then(u=>{let d=null;this.pseudoParent?d=w(null):d=this.doFinishBreakOfFragmentLayoutConstraints(u),d.then(()=>{if(hr(this)&&(vm(this),pr(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(P(this.element,"width",`${this.width}px`),P(this.element,"left",`${this.left}px`)):P(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){o.finish(null);return}if(!u)o.finish(null);else{this.overflown=!0;let h=new _t(u.toNodePosition());o.finish(h)}})})})}),o.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let n=I("doFinishBreakOfFragmentLayoutConstraints"),s=[].concat(this.fragmentLayoutConstraints);s.sort((r,a)=>r.getPriorityOfFinishBreak()-a.getPriorityOfFinishBreak());let o=0;return n.loop(()=>o<s.length?s[o++].finishBreak(e,this).thenReturn(!0):w(!1)).then(()=>{n.finish(!0)}),n.result()}doLayout(e,n,s){let o=I("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,o.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(()=>{o.finish({nodeContext:e,overflownNodeContext:r})}),o.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=I("redoLayout"),o=0,r=null,a=!0;return s.loopWithFrame(l=>{if(o<e.length){let c=e[o++];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(Bn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}if(Ci.isInstanceOfAfterIfContinuesLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}bn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(this).forEach(o=>{e.push(o)})});return e}},ko=class{constructor(t,e,n){p(this,"startNodeContexts",[]);p(this,"column");p(this,"flowRootSourceNode");this.flowRootSourceNode=n.sourceNode,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 o=this;this.column.openAllViews=function(r){return Po.prototype.openAllViews.call(this,r).thenAsync(a=>(o.startNodeContexts.push(a.copy()),w(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 _n(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 ns(t.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(t)}isEffectivelyLastAfterNodeContext(t){var s;let e=this.flowRootSourceNode,n=t.sourceNode;if(!e||!n||!t.after||e!==n&&!((s=e.contains)!=null&&s.call(e,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let o=n;if(t.offsetInNode<o.length){let r=o.data.slice(t.offsetInNode);if(!qd(r,t.whitespace))return!1}}for(let o=n;o&&o!==e;o=o.parentNode)for(let r=o.nextSibling;r;r=r.nextSibling)if(!pe(r,t.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Rr=class{breakTextNode(t,e,n,s,o,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+RC(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 o=e.charAt(n);n++;let r=e.charAt(n);return t.replaceData(n,e.length-n,!s.breakWord&&Vu(o)&&Vu(r)?RC(s):""),n}updateNodeContext(t,e,n){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};p(Rr,"instance");Rr.instance=new Rr;function RC(i){return i.hyphenateCharacter||i.parent&&i.parent.hyphenateCharacter||"-"}var ph=class extends Os{constructor(e,n){super();this.leadingEdge=e;p(this,"breakAfter");p(this,"initialPageBreakType",null);p(this,"initialComputedBlockSize",0);p(this,"initialOverflown",!1);p(this,"initialLastLineStride",0);p(this,"context",{overflownNodeContext:null});this.breakAfter=n||null}resolveLayoutMode(e){return new hh(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,n){n.fragmentLayoutConstraints=[],n.pseudoParent||iC()}clearNodes(e){super.clearNodes(e);let n=e;for(;n;){let s=n.viewNode;s&&xl(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,this.initialLastLineStride=n.lastLineStride}restoreState(e,n){super.restoreState(e,n),n.pageBreakType=this.initialPageBreakType,n.computedBlockSize=this.initialComputedBlockSize,n.overflown=this.initialOverflown,n.lastLineStride=this.initialLastLineStride}},hh=class{constructor(t,e,n){this.leadingEdge=t;this.breakAfter=e;this.context=n}doLayout(t,e){let n=I("DefaultLayoutMode.doLayout");return hx(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(o=>{o.postLayout(s,t,e,n)}),s}},fh=class extends Po{constructor(e,n,s,o,r,a,l){super(n,s,o,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),w(n)))}convertPercentageSizesToPx(e){let n=this.parentContainer.getPaddingRect(),s=n.x2-n.x1,o=n.y2-n.y1;function r(a,l){a.forEach(c=>{let u=un(e,c);if(u&&u.charAt(u.length-1)==="%"){let d=parseFloat(u),h=l*d/100;P(e,c,`${h}px`)}})}r(["width","max-width","min-width"],s),r(["height","max-height","min-height"],o),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?o:s),["margin-top","margin-right","margin-bottom","margin-left"].forEach(a=>{un(e,a)==="auto"&&P(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=un(n,"height");r!==""&&r!=="auto"&&P(n,"margin-top","auto")}}else if(s==="block-end"||s==="bottom"){let r=un(n,"width");r!==""&&r!=="auto"&&P(n,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=vt(this.clientLayout,e,this.vertical),o=this.floatMargins[n];return this.vertical?o.top+s.height+o.bottom:o.left+s.width+o.right}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=this.floatMargins[n];return this.vertical?s.left:s.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,n=e==null?void 0:e.styler,s=e==null?void 0:e.xmldoc,o=this.rootViewNodes.filter(u=>{var C,N,x,E;let d=(C=u.ownerDocument.defaultView)==null?void 0:C.getComputedStyle(u);if(((d==null?void 0:d.getPropertyValue("--viv-footnote-display").trim())||"")==="compact")return!((d==null?void 0:d.display)==="list-item"&&d.getPropertyValue("list-style-position").trim()==="outside");let f=u.getAttribute(zt);if(!f||!n||!s)return!1;let g=s.getNodeByOffset(parseInt(f,10));if(!g||g.nodeType!==Node.ELEMENT_NODE)return!1;let m=n.getStyle(g,!1),b=(x=(N=ee(m,"footnote-display"))==null?void 0:N.value)==null?void 0:x.toString(),y=!!((E=ee(m,"--viv-marker-content"))!=null&&E.value);return b==="compact"&&!y});if(o.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),a=this.vertical?r.height:r.width;o.forEach(u=>{P(u,"display","inline"),u.style.setProperty("--viv-footnote-white-space","nowrap")});let l=1.5/(this.clientLayout.pixelRatio||1),c=u=>{let d=u.cloneNode(!0);P(d,"display","inline-block"),P(d,"position","absolute"),P(d,"visibility","hidden"),P(d,"white-space","nowrap"),P(d,"max-width","none"),P(d,"left","0"),P(d,"top","0"),this.element.appendChild(d);let h=d.getBoundingClientRect();return this.element.removeChild(d),this.vertical?h.height:h.width};o.forEach(u=>{c(u)>a+l&&(P(u,"display","block"),u.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(n=>{let s=vt(this.clientLayout,n,this.vertical),o=this.getComputedMargin(n),r=this.vertical?o.left:o.bottom;return e*(this.getAfterEdge(s)-this.beforeEdge)+Math.max(0,r)}))}getFootnoteAfterPseudo(e){return Array.from(e.children).find(n=>qt(n)==="after")}hasAuthorFootnoteAfterPseudo(e){let n=this.getFootnoteAfterPseudo(e);if(n&&!n.hasAttribute("data-vivliostyle-default-footnote-separator"))return!0;let s=Array.from(e.children).find(r=>r instanceof Element&&rt(r)),o=s?this.getFootnoteAfterPseudo(s):null;return!!o&&!o.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let n=e.ownerDocument.createElement("span");To(n,"after"),n.setAttribute("data-vivliostyle-default-footnote-separator","1"),n.style.whiteSpace="normal",n.textContent=" ",e.appendChild(n)}getFootnoteBreakOpportunity(e){let n=e.nextElementSibling;return n!=null&&n.hasAttribute("data-vivliostyle-footnote-break")?n:null}createFootnoteBreakOpportunity(e){let n=e.ownerDocument.createElement("wbr");n.setAttribute("data-vivliostyle-footnote-break","1"),e.insertAdjacentElement("afterend",n)}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,n)=>{var h,f;let s=e,o=(h=s.ownerDocument.defaultView)==null?void 0:h.getComputedStyle(s).display,r=this.rootViewNodes[n+1],a=(f=r==null?void 0:r.ownerDocument.defaultView)==null?void 0:f.getComputedStyle(r).display,l=this.getFootnoteAfterPseudo(s),c=this.hasAuthorFootnoteAfterPseudo(s),u=!!(l!=null&&l.hasAttribute("data-vivliostyle-default-footnote-separator")),d=this.getFootnoteBreakOpportunity(s);if(o==="inline"&&a==="inline"){let g=!l&&!c;g&&this.createDefaultFootnoteAfterPseudo(s),!g&&!d?this.createFootnoteBreakOpportunity(s):g&&(d==null||d.remove())}else u&&l.remove(),d==null||d.remove()})}};var xn=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;_l.some(n=>n.root===this.rootSourceNode?(this.repetitiveElements=n.elements,!0):!1)||(this.repetitiveElements=new mh(t,this.rootSourceNode),_l.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},mh=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=mo(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=mo(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=gi(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=gi(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?w(!0):this.appendElementToFragment(this.headerNodePosition,t,e,n)}appendFooterToFragment(t,e,n){return!this.footerNodePosition||this.isSkipFooter?w(!0):this.appendElementToFragment(this.footerNodePosition,t,e,n)}appendElementToFragment(t,e,n,s){let o=e.viewNode.ownerDocument,r=e.viewNode,a=o.createElement("div");r.appendChild(a);let l=new ko(s,a,e),c=l.getColumn().pageBreakType;return l.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,l.layout(new _t(t),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(a),this.moveChildren(a,r,n),l.getColumn().pageBreakType=c,w(!0)))}moveChildren(t,e,n){if(e)for(;t.firstChild;){let s=t.firstChild;t.removeChild(s),s.setAttribute(Fn,"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(o=>o.nodeContext.sourceNode===t.sourceNode&&o.nodeContext.after===t.after);if(s.length>0)return s[0].result;{let o=n(t);return e.push({nodeContext:t,result:o}),o}}isAfterNodeContextOf(t,e,n){let s=[];for(let o=t;o;o=o.parentNode){if(e.sourceNode===o)return e.after;s.push(o)}for(let o=e.sourceNode;o;o=o.parentNode){let r=s.indexOf(o);if(r>=0)return n?r===0:!1;for(let a=o;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}},Fi=class{constructor(t){this.formattingContext=t}accept(t,e){return!!t}postLayout(t,e,n,s){let o=this.formattingContext.getRepetitiveElements();return o&&(n.clientLayout,o.doneInitialLayout||(o.updateHeight(n),o.doneInitialLayout=!0)),s}},Vi=class{constructor(t){this.formattingContext=t}accept(t,e){return!0}postLayout(t,e,n,s){return s}},Ch=class extends Fi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}accept(e,n){return!1}},bh=class extends Vi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return!e.belongsTo(this.formattingContext)&&!e.after&&n.fragmentLayoutConstraints.unshift(new Lr(e)),this.processor.doLayout(e,n)}},Lr=class i{constructor(t){p(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner");p(this,"nodeContext");let e=cs(t.formattingContext);this.nodeContext=e.getRootNodeContext(t)}allowLayout(t,e,n){let s=this.getRepetitiveElements();return!s||Jn(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:e&&!t||t&&t.overflow?!vh(t,e,s):!0}nextCandidate(t){let e=this.getRepetitiveElements();return e&&e.isEnableToUpdateState()?(e.updateState(),!0):!1}postLayout(t,e,n,s){let o=this.getRepetitiveElements();o&&t&&s.stopAtOverflow&&(e==null||o.isAfterLastContent(e))&&o.preventSkippingFooter()}finishBreak(t,e){let n=cs(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return w(!0);let o=this.nodeContext;return mx(n,o,e).thenAsync(()=>Cx(n,o,e).thenAsync(()=>(s.prepareLayoutFragment(),w(!0))))}getRepetitiveElements(){return cs(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof i?cs(this.nodeContext.formattingContext)===cs(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},yh=class extends Os{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 Ch(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&n&&n.preventSkippingHeader(),new bh(this.formattingContext,this.processor))}},Sh=class extends os{constructor(e,n){super();this.formattingContext=e;this.column=n}startNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,o=n.getRepetitiveElements();if(s.parent&&n.rootSourceNode===s.parent.sourceNode){switch(s.repeatOnBreak){case"header":if(o.isHeaderRegistered())s.repeatOnBreak="none";else return o.setHeaderNodeContext(s),w(!0);break;case"footer":if(o.isFooterRegistered())s.repeatOnBreak="none";else return o.setFooterNodeContext(s),w(!0);break}o.firstContentSourceNode||(o.firstContentSourceNode=s.sourceNode)}return os.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"?w(!0):os.prototype.afterNonInlineElementNode.call(this,e)}};var xh=class extends Un{layout(t,e,n){if(e.isFloatNodeContext(t))return e.layoutFloatOrFootnote(t);let s=cs(t.formattingContext);return s.getRootViewNode(t)?(n&&Eh(t.parent,e),t.belongsTo(s)?Un.prototype.layout.call(this,t,e,n):new yh(s,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let n=bx(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=cs(t.formattingContext),s=I("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(s),s.result()}layoutEntireBlock(t,e){let n=cs(t.formattingContext),s=new Sh(n,e);return new yo(s,e.layoutContext).iterate(t)}doLayout(t,e){let n=cs(t.formattingContext),s=I("doLayout"),o=e.layoutContext.nextInTree(t,!1);return gh(o,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 Un.prototype.finishBreak.call(this,t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Un.prototype.clearOverflownViewNodes(t,e,n,s)}};function gx(i,t){for(let e=i;e;e=e.parent){let n=e.formattingContext;n&&n instanceof xn&&!e.belongsTo(n)&&t(n,e)}}function Eh(i,t){i&&gx(i.after?i.parent:i,(e,n)=>{bn.isInstanceOfTableFormattingContext(e)||t.fragmentLayoutConstraints.push(new Lr(n))})}function mx(i,t,e){let n=i.getRepetitiveElements();if(n){let s=i.getRootNodeContext(t);if(s.viewNode){let o=s.viewNode.firstChild;return n.appendHeaderToFragment(s,o,e)}}return w(!0)}function Cx(i,t,e){let n=i.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=i.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,e)}return w(!0)}function vh(i,t,e){let n=e.ownerSourceNode,s=i||t;return!s||n.contains(s.sourceNode)}function bx(i){let t=i.formattingContext;return!t||!(t instanceof xn)?null:t}function cs(i){return i instanceof xn,i}var yx=new xh;je("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof xn&&!bn.isInstanceOfTableFormattingContext(i)?yx:null);var dc=class{constructor(t,e){this.rowIndex=t;this.sourceNode=e;p(this,"cells",[]);p(this,"breakBefore",null);p(this,"breakAfter",null)}addCell(t){this.cells.push(t)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(t=>t.height))}},Th=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}},wh=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;this.cell=n}},Ph=class{constructor(t,e,n){this.column=t;this.cellNodeContext=n;p(this,"pseudoColumn");p(this,"empty",!1);this.pseudoColumn=new ko(t,e,n)}findAcceptableBreakPosition(){let t=this.cellNodeContext.viewNode,{verticalAlign:e,alignContent:n}=t.style;e!=="top"&&e!=="baseline"&&P(t,"vertical-align","top"),n&&n!=="normal"&&P(t,"align-content","normal");let s=this.pseudoColumn.findAcceptableBreakPosition(!0);return P(t,"vertical-align",e),n&&n!=="normal"&&P(t,"align-content",n),s}},kh=class{constructor(t,e){this.viewNode=t;this.side=e}},Ah=class extends _n{constructor(e,n,s,o){super(e,n,s,o);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)?this.hasUnfinishedCells()?null:s:null}hasUnfinishedCells(){let e=this.getRowIndex(),n=this.formattingContext.getCellsFallingOnRow(e);for(let s of n){if(s.rowIndex+s.rowSpan-1>e)continue;let o=this.formattingContext.getCellFragmentOfCell(s);if(o){let r=o.findAcceptableBreakPosition();if(r.nodeContext&&!o.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}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)}},Rh=class extends bo{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(),o=this.getAcceptableCellBreakPositions(),r=o.every(a=>!!a.nodeContext)&&o.some((a,l)=>{let c=s[l].pseudoColumn,u=a.nodeContext;return!c.isStartNodeContext(u)&&!c.isLastAfterNodeContext(u)});return this.beforeNodeContext.overflow=o.some(a=>a.nodeContext&&a.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let n=this.formattingContext.getRowByIndex(this.rowIndex),s=this.beforeNodeContext.breakPenalty,o=this.getAcceptableCellBreakPositions(),r=this.getCellFragments();s+=Math.max(0,...r.map(l=>l.cellNodeContext.breakPenalty));let a=o.some((l,c)=>l.breakPosition instanceof wo&&r[c].cellNodeContext.sourceNode.rowSpan>1);return o.forEach((l,c)=>{let u=l.breakPosition.getMinBreakPenalty();a&&l.breakPosition instanceof _n&&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)}},_s=class extends xn{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){var s;if(!n)return n;switch(e.display){case"table-row":return this.cellBreakPositions.length===0&&e.fragmentIndex<=1;case"table-cell":return e.fragmentIndex>1||((s=e.parent)==null?void 0:s.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(o=>o.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 dc(e,null)),s=this.rows[e]),s.addCell(n);let o=e+n.rowSpan,r=this.getRowSlots(e),a=0;for(;r[a];)a++;for(;e<o;e++){r=this.getRowSlots(e);for(let l=a;l<a+n.colSpan;l++){let c=r[l]=new wh(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 o=this.cellFragments[e];o||(o=this.cellFragments[e]=[]),o[n]=s}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((s,o)=>o.cell!==s[s.length-1]?s.concat(o.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 o=vt(e,s.viewElement,this.vertical);s.viewElement=null,s.setHeight(this.vertical?o.width:o.height)})})}findCellFromColumn(e){if(!e)return null;let n=null,s=0,o=0;e:for(s=0;s<this.cellFragments.length;s++)if(this.cellFragments[s]){for(o=0;o<this.cellFragments[s].length;o++)if(this.cellFragments[s][o]&&e===this.cellFragments[s][o].pseudoColumn.getColumn()){n=this.rows[s].cells[o];break e}}if(!n)return null;for(;s<this.slots.length;s++)for(;o<this.slots[s].length;o++){let r=this.slots[s][o];if(r.cell===n)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let n=[];return this.slots.reduce((s,o,r)=>{if(r>=e.rowIndex)return s;let a=o[e.columnIndex]&&this.getCellFragmentOfCell(o[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,o)=>{e[o]||(e[o]={collected:[],elements:[]});let r=e[o],a=this.getCellFragmentOfCell(s);!a||r.collected.includes(a)||(this.collectElementsOffsetFromColumn(a.pseudoColumn.getColumn(),r.elements),r.collected.push(a))})}),[new Lh(e.map(n=>n.elements))]}collectElementsOffsetFromColumn(e,n){e.fragmentLayoutConstraints.forEach(s=>{if(Bn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();n.push(o)}bn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(null).forEach(o=>{n.push(o)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Lh=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 o=Fs(t,s);n=Math.max(n,e(o))}),n}};function rn(i){return i instanceof _s,i}function Sx(i){return i==="table-row-group"||i==="table-header-group"||i==="table-footer-group"}function xx(i){return i==="table"||i==="inline-table"}function VC(i){return Sx(i)||xx(i)}function OC(i,t,e){let n=i.nodeContext,s=n.display,o=n.parent?n.parent.display:null,r=!1;if(o==="inline-table"&&!(n.formattingContext instanceof _s)){for(let l=n.parent;l;l=l.parent)if(l.formattingContext instanceof _s){r=l.formattingContext===t;break}}return r||s==="table-row"&&!VC(o)||s==="table-cell"&&o!=="table-row"&&!VC(o)||n.formattingContext instanceof _s&&n.formattingContext!==t?e.buildDeepElementView(n).thenAsync(l=>(i.nodeContext=l,w(!0))):null}function BC(i,t){let e=t.nodeContext;return!(e!=null&&e.floatSide)||!(Sn(e.floatReference)||e.floatSide==="footnote")?null:i.layoutFloatOrFootnote(e).thenAsync(n=>(n&&(t.nodeContext=n),w(!0)))}var Ih=class extends os{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=OC(e,n,this.column);if(s)return s;this.postLayoutBlockContents(e);let o=BC(this.column,e);if(o)return o;let r=e.nodeContext,a=r.display,l=n.getRepetitiveElements();switch(a){case"table":n.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let c=new kh(r.viewNode,r.captionSide);n.captions.push(c);break}case"table-header-group":return l.isHeaderRegistered()||(this.inHeaderOrFooter=!0,l.setHeaderNodeContext(r)),w(!0);case"table-footer-group":return l.isFooterRegistered()||(this.inHeaderOrFooter=!0,l.setFooterNodeContext(r)),w(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,n.addRow(this.rowIndex,new dc(this.rowIndex,r.sourceNode)),r.breakBefore&&(n.rows[this.rowIndex].breakBefore=r.breakBefore),l.firstContentSourceNode||(l.firstContentSourceNode=r.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let n=this.formattingContext,s=e.nodeContext,o=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(o){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,w(!0);break;case"table-row":if(!this.inHeaderOrFooter){n.lastRowViewNode=s.viewNode,this.inRow=!1;let a=n.rows[this.rowIndex];a&&s.breakAfter&&(a.breakAfter=De(a.breakAfter,s.breakAfter))}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 Th(this.rowIndex,this.columnIndex,a)),this.columnIndex++;let l=n.rows[this.rowIndex];l&&(s.breakBefore&&(l.breakBefore=De(l.breakBefore,s.breakBefore)),s.breakAfter&&(l.breakAfter=De(l.breakAfter,s.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let n=e.nodeContext;n&&n.viewNode&&!es(n)&&this.checkPoints.push(n.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},hc=class hc extends os{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}startNonInlineElementNode(e){let n=BC(this.column,e);return n||super.startNonInlineElementNode(e)}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(e){let n=this.formattingContext.colWidths;let s=0;for(let o=0;o<e.colSpan;o++)s+=n[e.anchorSlot.columnIndex+o];return s+=this.formattingContext.inlineBorderSpacing*(e.colSpan-1),s}layoutCell(e,n,s){let o=e.rowIndex,r=e.columnIndex,a=e.colSpan,l=n.viewNode;a>1&&(P(l,"box-sizing","border-box"),P(l,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(e)}px`));let c=l.ownerDocument.createElement("div");l.appendChild(c);let u=new Ph(this.column,c,n);return this.formattingContext.addCellFragment(o,r,u),s.primary.steps.length===1&&s.primary.after&&(u.empty=!0),u.pseudoColumn.layout(s,!0).thenReturn(!0)}findBrokenCellAtSlot(e,n){let s=this.formattingContext.cellBreakPositions;for(let o=0;o<s.length;o++){let r=s[o];if(r.cell.anchorSlot.columnIndex===e&&r.cellNodePosition.steps[0].node===n)return{position:r,index:o}}return null}extractRowSpanningCellBreakPositions(){let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let n=[],s=0;do{let o=e[s],r=o.cell,a=r.rowIndex;if(a<this.currentRowIndex&&a+r.rowSpan>this.currentRowIndex){let l=n[a];l||(l=n[a]=[]),l.push(o),e.splice(s,1)}else s++}while(s<e.length);return n}layoutRowSpanningCellsFromPreviousFragment(e){let n=this.formattingContext,s=this.extractRowSpanningCellBreakPositions(),o=s.reduce(h=>h+1,0);if(o===0)return w(!0);let r=this.column.layoutContext,a=e.nodeContext;a.viewNode.parentNode.removeChild(a.viewNode);let l=I("layoutRowSpanningCellsFromPreviousFragment"),c=w(!0),u=0,d=[];return s.forEach(h=>{c=c.thenAsync(()=>{let f=Sr(h[0].cellNodePosition.steps[1],a.parent);return r.setCurrent(f,!1).thenAsync(()=>{let g=w(!0),m=0;function b(y){for(;m<y;){if(!d.includes(m)){let C=f.viewNode.ownerDocument.createElement("td");P(C,"padding","0"),f.viewNode.appendChild(C)}m++}}return h.forEach(y=>{g=g.thenAsync(()=>{let C=y.cell;b(C.anchorSlot.columnIndex);let N=y.cellNodePosition,x=Sr(N.steps[0],f);return x.offsetInNode=N.offsetInNode,x.after=N.after,x.fragmentIndex=N.steps[0].fragmentIndex+1,r.setCurrent(x,!1).thenAsync(()=>{let E=y.breakChunkPosition;for(let v=0;v<C.colSpan;v++)d.push(m+v);return m+=C.colSpan,this.layoutCell(C,x,E).thenAsync(()=>(x.viewNode.rowSpan=C.rowIndex+C.rowSpan-this.currentRowIndex+o-u,w(!0)))})})}),g.thenAsync(()=>(b(n.getColumnCount()),u++,w(!0)))})})}),c.then(()=>{r.setCurrent(a,!0,e.atUnforcedBreak).then(()=>{l.finish(!0)})}),l.result()}startTableRow(e){if(this.inHeader||this.inFooter)return w(!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(()=>{var l;this.registerCellFragmentIndex();let o=e.breakAtTheEdge;if(this.currentRowIndex>0){let c=s.rows[this.currentRowIndex-1];c!=null&&c.breakAfter&&(o=De(o,c.breakAfter))}let r=s.rows[this.currentRowIndex];return r!=null&&r.breakBefore&&(o=De(o,r.breakBefore)),!e.leadingEdge&&Ne(o)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o),(l=n.viewNode)!=null&&l.parentNode&&n.viewNode.parentNode.removeChild(n.viewNode),e.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(e.lastAfterNodeContext),this.column.pageBreakType=o,this.resetColumn(),e.break=!0,w(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,o)&&s.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),n.overflow=!0,e.break=!0),w(!0))})}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(n=>{let s=this.formattingContext.cellBreakPositions.find(o=>o.cell===n);if(s){let o=s.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(o.node);LC(r,o.fragmentIndex+1,1)}})}startTableCell(e){if(this.inHeader||this.inFooter)return w(!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,w(!0);let o=n.copy().modify();o.after=!0,e.nodeContext=o;let r=I("startTableCell"),a,l=this.findBrokenCellAtSlot(s.anchorSlot.columnIndex,n.sourceNode);if(l){let c=l.position;this.formattingContext.cellBreakPositions.splice(l.index,1),n.fragmentIndex=c.cellNodePosition.steps[0].fragmentIndex+1,a=w(c.breakChunkPosition)}else a=this.column.nextInTree(n,e.atUnforcedBreak).thenAsync(c=>{c.viewNode&&n.viewNode.removeChild(c.viewNode);let u=mo(c,0);return w(new _t(u))});return a.then(c=>{this.layoutCell(s,n,c).then(()=>{this.afterNonInlineElementNode(e),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(e){let n=OC(e,rn(this.formattingContext),this.column);if(n)return n;let s=e.nodeContext,o=this.formattingContext.getRepetitiveElements(),r=s.display;return r==="table-header-group"&&o&&o.isHeaderSourceNode(s.sourceNode)?(this.inHeader=!0,w(!0)):r==="table-footer-group"&&o&&o.isFooterSourceNode(s.sourceNode)?(this.inFooter=!0,w(!0)):r==="table-row"?this.startTableRow(e):r==="table-cell"?this.startTableCell(e):w(!0)}endNonInlineBox(e){let n=e.nodeContext;if(n.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let o=n.copy().modify();o.after=!1;let r=new Rh(this.currentRowIndex,o,this.formattingContext);this.column.breakPositions.push(r)}return w(!0)}afterNonInlineElementNode(e){let n=e.nodeContext,s=this.formattingContext.getRepetitiveElements(),o=n.display;if(o==="table-header-group"?s&&!s.allowInsertRepeatitiveElements&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!1,n.viewNode.parentNode.removeChild(n.viewNode)):P(n.viewNode,"display","table-row-group"):o==="table-footer-group"&&(s&&!s.allowInsertRepeatitiveElements&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!1,n.viewNode.parentNode.removeChild(n.viewNode)):P(n.viewNode,"display","table-row-group")),o&&hc.ignoreList[o])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 w(!0)}};p(hc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Fh=hc,Oi=[];function Ex(i){let t=Oi.findIndex(n=>n.root===i),e=Oi[t];return e?e.tableLayoutOption:null}function vx(i){let t=Oi.findIndex(e=>e.root===i);t>=0&&Oi.splice(t,1)}var pc=class{layoutEntireTable(t,e){let n=rn(t.formattingContext),s=new Ih(n,e);return new yo(s,e.layoutContext).iterate(t)}getColumnWidths(t,e,n,s){let o=t.ownerDocument,r=o.createElement("tr"),a=[];for(let c=0;c<e;c++){let u=o.createElement("td");r.appendChild(u),a.push(u)}t.parentNode.insertBefore(r,t.nextSibling);let l=a.map(c=>{let u=vt(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 o=n.firstElementChild;for(;o;){if(o.localName==="col"){let r=o.span;for(o.removeAttribute("span"),s-=r;r-- >1;){let a=o.cloneNode(!0);n.insertBefore(a,o),e.push(a)}e.push(o)}o=o.nextElementSibling}for(;s-- >0;)o=n.ownerDocument.createElement("col"),n.appendChild(o),e.push(o)}),e}addMissingColElements(t,e,n,s){if(t.length<n){let o=s.ownerDocument.createElement("colgroup");e.push(o);for(let r=t.length;r<n;r++){let a=s.ownerDocument.createElement("col");o.appendChild(a),t.push(a)}}}normalizeColGroups(t,e,n){let s=t.vertical,o=t.lastRowViewNode;if(!o)return;t.lastRowViewNode=null;let a=o.ownerDocument.createDocumentFragment(),l=t.getColumnCount();if(!(l>0)){t.colGroups=a;return}let c=t.colWidths=this.getColumnWidths(o,l,s,n.clientLayout),u=this.getColGroupElements(e),d=this.normalizeAndGetColElements(u);this.addMissingColElements(d,u,l,e),d.forEach((h,f)=>{P(h,s?"height":"width",`${c[f]}px`)}),u.forEach(h=>{a.appendChild(h.cloneNode(!0))}),t.colGroups=a}doInitialLayout(t,e){let n=rn(t.formattingContext);n.vertical=t.vertical,n.initializeRepetitiveElements(t.vertical),t.sourceNode;let s=Ex(t.sourceNode);vx(t.sourceNode);let o=I("TableLayoutProcessor.doInitialLayout"),r=t.copy();return this.layoutEntireTable(t,e).then(a=>{let l=a.viewNode,c=vt(e.clientLayout,l,e.vertical),u=e.vertical?c.left:c.bottom;if(u+=(e.vertical?-1:1)*Fs(t,e.collectElementsOffset()).current,!e.isOverflown(u)&&(!s||!s.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(n)){e.breakPositions.push(new Bh(r)),o.finish(a);return}this.normalizeColGroups(n,l,e),n.updateCellSizes(e.clientLayout),o.finish(null)}),o.result()}hasForcedBreakInRows(t){for(let e=0;e<t.rows.length;e++){let n=t.rows[e];if(n&&(e>0&&Ne(n.breakBefore)||e<t.rows.length-1&&Ne(n.breakAfter)))return!0}return!1}addCaptions(t,e,n){let s=t.captions;s.forEach((o,r)=>{o&&(e.insertBefore(o.viewNode,n),o.side==="top"&&(s[r]=null))})}addColGroups(t,e,n){t.colGroups&&this.getColGroupElements(e).length===0&&(e.insertBefore(t.colGroups.cloneNode(!0),n),P(e,"table-layout","fixed"),P(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=rn(t.formattingContext),s=n.getRootViewNode(t),o=s.firstChild;this.addCaptions(n,s,o),this.addColGroups(n,s,o);let r=new Fh(n,e),a=new yo(r,e.layoutContext),l=I("TableFormattingContext.doLayout");return a.iterate(t).thenFinish(l),l.result()}layout(t,e,n){let s=rn(t.formattingContext);return s.getRootViewNode(t)?(n&&Eh(t.parent,e),new Vh(s,this).layout(t,e)):e.buildDeepElementView(t)}createEdgeBreakPosition(t,e,n,s){return new Ah(t,e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return Nh(t),!1}finishBreak(t,e,n,s){let o=rn(e.formattingContext);if(e.display==="table-row"){e.sourceNode;let r=o.findRowIndexBySourceNode(e.sourceNode),a;if(e.after?a=o.getRowSpanningCellsOverflowingTheRow(r):a=o.getCellsFallingOnRow(r),o.cellBreakPositions=o.cellBreakPositions.filter(l=>!a.includes(l.cell)),a.length){let l=I("TableLayoutProcessor.finishBreak"),c=0;return l.loopWithFrame(u=>{if(c===a.length){u.breakLoop();return}let d=a[c++],h=o.getCellFragmentOfCell(d),f=h.findAcceptableBreakPosition().nodeContext;let g=h.cellNodeContext,m=g.toNodePosition(),b=new _t(f.toNodePosition());o.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:b,cell:d});let y=g.viewNode;h.column.layoutContext.processFragmentedBlockEdge(h.cellNodeContext),r<d.rowIndex+d.rowSpan-1&&(y.rowSpan=r-d.rowIndex+1),h.empty?u.continueLoop():h.pseudoColumn.finishBreak(f,!1,!0).then(()=>{Nx(h,o,f),u.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),Nh(e),o.finishFragment(),l.finish(!0)}),l.result()}}return Nh(e),o.finishFragment(),Ni.finishBreak(t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Un.prototype.clearOverflownViewNodes(t,e,n,s)}};function Nx(i,t,e){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,o=i.column,r=i.pseudoColumn.getColumnElement(),a=i.cellNodeContext.viewNode,l=vt(o.clientLayout,a,s),c=o.getComputedPaddingBorder(a);if(s){let u=l.right-o.footnoteEdge-n.calculateOffset(e)-c.right;P(r,"max-width",`${u}px`)}else{let u=o.footnoteEdge-n.calculateOffset(e)-l.top-c.top;P(r,"max-height",`${u}px`)}}function Nh(i){let t=i.display==="table-row"?i.viewNode.parentElement:i.display==="table"?i.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=i.vertical?f.width:f.height;return d+g},0),s=e[e.length-1],o=Array.from(t.children).indexOf(s),r=Array.from(s.children).reduce((d,h)=>{let f=h.rowSpan;return f>1&&o+f<t.childElementCount?Math.max(d,f):d},0),a=r?t.children[o+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=i.vertical?l.width:l.height,u=n+c;P(a,i.vertical?"width":"height",`${u}px`)}var Vh=class extends Os{constructor(e,n){super();this.tableFormattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.tableFormattingContext.getRepetitiveElements();return!n||!n.doneInitialLayout?new Oh(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&n&&n.preventSkippingHeader(),new Mh(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()}},Oh=class extends Fi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}},Bh=class extends _n{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 Dh(this.position.sourceNode))}},Dh=class i{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,Oi.push({root:e.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,e){return w(!0)}equalsTo(t){return t instanceof i&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Mh=class extends Vi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){let s=this.formattingContext.getRepetitiveElements();if(s&&!s.isAfterLastContent(e)){let o=new _h(e);n.fragmentLayoutConstraints.some(r=>o.equalsTo(r))||n.fragmentLayoutConstraints.unshift(o)}return this.processor.doLayout(e,n)}},_h=class i extends Lr{constructor(e){super(e);p(this,"flagmentLayoutConstraintType","TableRow");p(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,n,s){let o=this.getRepetitiveElements();return!o||s.pseudoParent||Jn(this.nodeContext.viewNode)||!o.isEnableToUpdateState()?!0:n&&!e||e&&e.overflow?!vh(e,n,o):!0}nextCandidate(e){let n=rn(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(e,n).some(o=>o.constraints.some(r=>r.nextCandidate(e)))?!0:super.nextCandidate(e)}postLayout(e,n,s,o){let r=rn(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(n,r),this.cellFragmentLayoutConstraints.forEach(a=>{a.constraints.forEach(l=>{l.postLayout(e,a.breakPosition,s,o)})}),!e){let a=r.getRootViewNode(this.nodeContext);new pc().removeColGroups(r,a),this.removeDummyRowNodes(s)}super.postLayout(e,n,s,o)}finishBreak(e,n){let s=rn(this.nodeContext.formattingContext),o=I("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((l,c)=>l.concat(c.constraints.map(u=>({constraint:u,breakPosition:c.breakPosition}))),[]),a=0;return o.loop(()=>{if(a<r.length){let l=r[a++];return l.constraint.finishBreak(l.breakPosition,n).thenReturn(!0)}else return w(!1)}).then(()=>{o.finish(!0)}),o.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 o=[];for(let r=0;r<s;r++)n.cellFragments[r]&&n.cellFragments[r].forEach(a=>{a&&o.push({fragment:a,breakPosition:a.findAcceptableBreakPosition().nodeContext})});return o}getElementsOffsetsForTableCell(e){let n=rn(this.nodeContext.formattingContext),s=n.findCellFromColumn(e);return s?n.collectElementsOffsetOfUpperCells(s):n.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof i?rn(this.nodeContext.formattingContext)===rn(e.nodeContext.formattingContext):!1}},Tx=new pc;function wx(i,t,e,n,s,o){if(!t)return null;if(e===S.table){let r=i.parent;return new _s(r?r.formattingContext:null,i.sourceNode)}return null}function Px(i){return i instanceof _s?Tx:null}je("RESOLVE_FORMATTING_CONTEXT",wx);je("RESOLVE_LAYOUT_PROCESSOR",Px);function DC(i){return i.reduce((t,e)=>t+e,0)/i.length}function MC(i){let t=DC(i);return DC(i.map(e=>{let n=e-t;return n*n}))}var Uh=class{constructor(t,e){this.layoutResult=t;this.penalty=e}};function Bi(i){return i.vertical?i.width:i.height}function Di(i,t){i.vertical?i.width=t:i.height=t}var fc=class{constructor(t,e,n){this.layoutContainer=t;this.columnGenerator=e;this.regionPageFloatLayoutContext=n;p(this,"originalContainerBlockSize");this.originalContainerBlockSize=Bi(t)}balanceColumns(t){let e=I("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),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(o=>{if(this.savePageFloatLayoutContexts(o),this.layoutContainer.clear(),!o){s.breakLoop();return}n.push(this.createTrialResult(o)),s.continueLoop()})}).then(()=>{let s=n.reduce((o,r)=>r.penalty<o.penalty?r:o,n[0]);this.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(s.layoutResult),this.tightenColumnBlockSizes(s.layoutResult.columns),this.postBalance(),e.finish(s.layoutResult)}),e.result()}createTrialResult(t){let e=this.calculatePenalty(t);return new Uh(t,e)}preBalance(t){}postBalance(){Di(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(t){if(t.length<=1)return;let e=Math.max.apply(null,t.map(n=>n.computedBlockSize));if(!(e<=0))for(let n of t)if(n.vertical){let s=parseFloat(n.element.style.width),o=parseFloat(n.element.style.left);if(isFinite(s)&&isFinite(o)&&s>e){let a=o+s-e;P(n.element,"width",`${e}px`),P(n.element,"left",`${a}px`),n.width=e,n.left=a}}else{let s=parseFloat(n.element.style.height);isFinite(s)&&s>e&&(P(n.element,"height",`${e}px`),n.height=e)}}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)}},Hh=1;function UC(i){let t=i[i.length-1];if(t.penalty===0)return!1;let e=i[i.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)),o=Math.max.apply(null,n.map(r=>r.getMaxBlockSizeOfPageFloats()));return s>o+Hh}function HC(i,t){let e=i[i.length-1].layoutResult.columns,s=Math.max.apply(null,e.map(o=>isNaN(o.blockDistanceToBlockEndFloats)?o.computedBlockSize:o.computedBlockSize-o.blockDistanceToBlockEndFloats+Hh))-Hh;s<Bi(t)?Di(t,s):Di(t,Bi(t)-1)}var zh=class extends fc{constructor(e,n,s,o){super(s,e,n);this.columnCount=o;p(this,"originalPosition",null);p(this,"foundUpperBound",!1)}preBalance(e){let s=e.columns.reduce((o,r)=>o+r.computedBlockSize,0);Di(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 _C(n)?1/0:Math.max.apply(null,n.map(s=>s.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return UC(e);{let n=e[e.length-1];return this.checkPosition(n.layoutResult.position)&&!_C(n.layoutResult.columns)?(this.foundUpperBound=!0,!0):Bi(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)HC(e,this.layoutContainer);else{let n=Math.min(this.originalContainerBlockSize,Bi(this.layoutContainer)+this.originalContainerBlockSize*.1);Di(this.layoutContainer,n)}}};function _C(i){if(i.length<=1)return!1;let t=i[i.length-1].computedBlockSize,e=i.slice(0,i.length-1),n=Math.max(...i.map(o=>o.lastLineStride||0)),s=n>0?n/2:6;return e.every(o=>t>o.computedBlockSize+s)}var Gh=class extends fc{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 MC(e)}hasNextCandidate(t){return UC(t)}updateCondition(t){HC(t,this.layoutContainer)}};function zC(i,t,e,n,s,o,r){if(t===S.auto)return null;{let a=r.positions.length===0,l=o[o.length-1],c=!!(l&&l.pageBreakType);return a||c?new zh(e,n,s,i):t===S.balance_all?new Gh(e,n,s):(S.balance,null)}}var Rx=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Lx=new Set(Rx);function Ix(i){return!(i.toLowerCase()==="none"||Lx.has(i))}var Fx=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Vx=new Set(Fx),Ox=["fixed","extends"],Bx=new Set(Ox),fN=Symbol();function Zi(i){return i instanceof Q&&i.name.toLowerCase()!=="none"}function $C(i){return i.name}function Dx(i){if(i instanceof Q)return Vx.has(i.name);if(i instanceof X&&i.values.length===2){let t=i.values[0],e=i.values[1];if(t instanceof Q){let n=t.name;return Bx.has(n)&&(n==="fixed"&&e instanceof ce||n==="extends"&&Zi(e))}}return!1}function Mx(i){let t=yt(i,"system");return t instanceof Q&&t.name==="cyclic"}function _x(i){let t=yt(i,"system");if(t instanceof Q&&t.name==="fixed")return!0;if(t instanceof X&&t.values.length===2){let[e,n]=t.values;return e instanceof Q&&e.name==="fixed"&&n instanceof ce}return!1}function Ux(i){let t=yt(i,"system");return t instanceof Q?1:t.values[1].num}function Hx(i){let t=yt(i,"system");return t instanceof Q&&t.name==="alphabetic"}function zx(i){let t=yt(i,"system");return t instanceof Q&&t.name==="numeric"}function Gx(i){let t=yt(i,"system");return t instanceof Q&&t.name==="additive"}function $x(i){let t=yt(i,"system");if(t instanceof X&&t.values.length===2){let[e,n]=t.values;return e instanceof Q&&e.name==="extends"&&Zi(n)}return!1}function Wx(i){let t=yt(i,"system");return $C(t.values[1])}function an(i){return i instanceof z||i instanceof Q}function ds(i){return i instanceof z?i.str:i.name}function WC(i){if(an(i))return!0;if(i instanceof X&&i.values.length===2){let t=i.values[0],e=i.values[1];return an(t)&&an(e)}return!1}function Xx(i){if(an(i))return{prefix:ds(i),suffix:null};{let t=i.values[0],e=i.values[1];return{prefix:ds(t),suffix:ds(e)}}}function GC(i){return i instanceof ce||i instanceof Q&&i.name==="infinite"}function gc(i,t){return i instanceof ce?i.num:t?-1/0:1/0}var gN=Symbol();function $h(i){if(!(i instanceof X&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];if(!(GC(t)&&GC(e)))return!1;let n=gc(t,!0),s=gc(e,!1);return!(n>s)}function jx(i){return{lower:gc(i.values[0],!0),upper:gc(i.values[1],!1)}}function XC(i){return i instanceof Q&&i.name==="auto"||$h(i)||i instanceof ve&&i.values.length>=1&&i.values.every(t=>$h(t))}function Yx(i){return i instanceof Q?null:($h(i)?[i]:i.values).map(e=>jx(e))}var mN=Symbol();function mc(i){if(!(i instanceof X&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];return t instanceof ce&&t.num>=0&&an(e)||an(t)&&e instanceof ce&&e.num>=0}function Cc(i){let[t,e]=i.values;return t instanceof ce?[t.num,ds(e)]:[e.num,ds(t)]}function jC(i){return mc(i)}function qx(i){let[t,e]=Cc(i);return{minLength:t,symbol:e}}function YC(i){return an(i)||i instanceof X&&i.values.length>=1&&i.values.every(t=>an(t))}function Kx(i){return an(i)?[ds(i)]:i.values.map(t=>ds(t))}var CN=Symbol();function qC(i){if(mc(i))return!0;if(i instanceof ve&&i.values.length>=1){let t=1/0;for(let e of i.values){if(!mc(e))return!1;let[n]=Cc(e);if(n>=t)return!1;t=n}return!0}return!1}function Zx(i){if(mc(i)){let[t,e]=Cc(i);return[{weight:t,symbol:e}]}else return i.values.map(t=>{let[e,n]=Cc(t);return{weight:e,symbol:n}})}var Qx=["auto","bullets","numbers","words","spell-out"],Jx=new Set(Qx);function eE(i){return i instanceof Q&&Jx.has(i.name)||Zi(i)}function KC(i,t){switch(i){case"system":return Dx(t);case"negative":return WC(t);case"prefix":case"suffix":return an(t);case"range":return XC(t);case"pad":return jC(t);case"fallback":return Zi(t);case"symbols":return YC(t);case"additive-symbols":return qC(t);case"speak-as":return eE(t);default:return!0}}function yt(i,t){var n;let e=(n=i[t])==null?void 0:n.value;return e==null?null:e}function tE(i,t){return t.some(({lower:e,upper:n})=>i>=e&&i<=n)}function Fr(i){let t=i.get("decimal");return t||(t=se.createDecimal(i),i.set("decimal",t)),t}var _i,Ui,Hi,zi,Gi,$i,Wi,Xi,xc,Ec,vc,Nc,Tc,wc,Pc,Me,Wh,ZC,QC,JC,eb,Xh,tb,Mi,wt=class wt{constructor(t,e){Z(this,Me);p(this,"_store");Z(this,_i);Z(this,Ui);Z(this,Hi);Z(this,zi);Z(this,Gi);Z(this,$i);Z(this,Wi);Z(this,Xi);this._store=t;let n=yt(e,"negative");Pe(this,_i,n&&WC(n)?Xx(n):null);let s=yt(e,"prefix");Pe(this,Ui,s&&an(s)?ds(s):null);let o=yt(e,"suffix");Pe(this,Hi,o&&an(o)?ds(o):null);let r=yt(e,"range");Pe(this,zi,r&&XC(r)?Yx(r):null);let a=yt(e,"pad");Pe(this,Gi,a&&jC(a)?qx(a):null);let l=yt(e,"fallback");Pe(this,$i,l&&Zi(l)?$C(l):null);let c=yt(e,"symbols");Pe(this,Wi,c&&YC(c)?Kx(c):null);let u=yt(e,"additive-symbols");Pe(this,Xi,u&&qC(u)?Zx(u):null)}static create(t,e){return Mx(e)?new us(t,e):_x(e)?new jh(t,e):Hx(e)?new qh(t,e):zx(e)?new bc(t,e):Gx(e)?new Kh(t,e):$x(e)?new Zh(t,e):new Yh(t,e)}static createDecimal(t){return new bc(t,O(wt,xc))}static createDisc(t){return new us(t,O(wt,Ec))}static createSquare(t){return new us(t,O(wt,vc))}static createCircle(t){return new us(t,O(wt,Nc))}static createDisclosureOpen(t){return new us(t,O(wt,Tc))}static createDisclosureClosed(t){return new us(t,O(this,wc))}static createNone(t){return new us(t,O(wt,Pc))}static get CHINESE_LONGHAND_NAMES(){return yc.NAMES}static createChineseLonghand(t,e){return new yc(t,e)}static createEthiopicNumeric(t){return new Qh(t)}_getNegative(){return O(this,_i)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return O(this,Ui)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return O(this,Hi)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return O(this,zi)}static _getRangeFrom(t){return t._getRange()}_getPad(){return O(this,Gi)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(O(this,$i)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return O(this,Wi)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return O(this,Xi)}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 fe(this,Me,Mi).call(this,t,new Set)}formatMarker(t){return fe(this,Me,ZC).call(this)+this.format(t)+fe(this,Me,QC).call(this)}};_i=new WeakMap,Ui=new WeakMap,Hi=new WeakMap,zi=new WeakMap,Gi=new WeakMap,$i=new WeakMap,Wi=new WeakMap,Xi=new WeakMap,xc=new WeakMap,Ec=new WeakMap,vc=new WeakMap,Nc=new WeakMap,Tc=new WeakMap,wc=new WeakMap,Pc=new WeakMap,Me=new WeakSet,Wh=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},ZC=function(){var t;return(t=this._getPrefix())!=null?t:""},QC=function(){var t;return(t=this._getSuffix())!=null?t:". "},JC=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},eb=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},Xh=function(){var t;return(t=this._getFallback())!=null?t:Fr(this._store)},tb=function(t,e){let{minLength:n,symbol:s}=fe(this,Me,eb).call(this);if(n===0||s==="")return t;let{prefix:o,suffix:r}=fe(this,Me,Wh).call(this),a=e?[...o].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},Mi=function(t,e){var a,l,c;if(e.has(this))return fe(a=Fr(this._store),Me,Mi).call(a,t,new Set);if(e.add(this),!tE(t,fe(this,Me,JC).call(this))){let u=fe(this,Me,Xh).call(this);return fe(l=u,Me,Mi).call(l,t,e)}let n=this._usesNegativeSign(t),s=n?Math.abs(t):t,o=this._generateInitialRepresentation(s);if(o===null){let u=fe(this,Me,Xh).call(this);return fe(c=u,Me,Mi).call(c,t,e)}let r=fe(this,Me,tb).call(this,o,n);if(n){let{prefix:u,suffix:d}=fe(this,Me,Wh).call(this);r=u+r+(d!=null?d:"")}return r},Z(wt,xc,{system:new V(R("numeric"),0),symbols:new V(new X([new z("0"),new z("1"),new z("2"),new z("3"),new z("4"),new z("5"),new z("6"),new z("7"),new z("8"),new z("9")]),0)}),Z(wt,Ec,{system:new V(R("cyclic"),0),symbols:new V(new z("\u2022"),0),suffix:new V(new z(" "),0)}),Z(wt,vc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25AA"),0),suffix:new V(new z(" "),0)}),Z(wt,Nc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25E6"),0),suffix:new V(new z(" "),0)}),Z(wt,Tc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25BE"),0),suffix:new V(new z(" "),0)}),Z(wt,wc,{system:new V(R("cyclic"),0),symbols:new V(new z("\u25B8"),0),suffix:new V(new z(" "),0)}),Z(wt,Pc,{system:new V(R("cyclic"),0),symbols:new V(new z(""),0),suffix:new V(new z(""),0)});var se=wt,us=class extends se{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]}},ji,jh=class extends se{constructor(e,n){super(e,n);Z(this,ji);Pe(this,ji,Ux(n))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var o;let n=this._getSymbols();if(!n||n.length===0)return null;let s=e-O(this,ji);return(o=n[s])!=null?o:null}};ji=new WeakMap;var Yh=class extends se{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],o=Math.ceil(t/n);return s.repeat(o)}},qh=class extends se{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="",o=t;for(;o!==0;)o=o-1,s=e[o%n]+s,o=Math.floor(o/n);return s}},bc=class extends se{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="",o=t;for(;o!==0;)s=e[o%n]+s,o=Math.floor(o/n);return s}},Kh=class extends se{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 o=e.find(r=>r.weight===0);return o?o.symbol:null}let s=t;for(let o of e){let{weight:r,symbol:a}=o;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}},Ir,Pt,Kt,Jh=class Jh extends se{constructor(e,n){super(e,n);Z(this,Pt);Z(this,Ir);let s=Wx(n),o=s.toLowerCase();o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed"?Pe(this,Ir,o):Pe(this,Ir,s)}_getNegative(){var e;return(e=super._getNegative())!=null?e:se._getNegativeFrom(fe(this,Pt,Kt).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:se._getPrefixFrom(fe(this,Pt,Kt).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:se._getSuffixFrom(fe(this,Pt,Kt).call(this))}_getAutoRange(){return se._getAutoRangeFrom(fe(this,Pt,Kt).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:se._getRangeFrom(fe(this,Pt,Kt).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:se._getPadFrom(fe(this,Pt,Kt).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:se._getFallbackFrom(fe(this,Pt,Kt).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:se._getSymbolsFrom(fe(this,Pt,Kt).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:se._getAdditiveSymbolsFrom(fe(this,Pt,Kt).call(this))}_usesNegativeSign(e){return se._useNegativeSignFrom(fe(this,Pt,Kt).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:se._generateInitialRepresentationFrom(fe(this,Pt,Kt).call(this),e)}};Ir=new WeakMap,Pt=new WeakSet,Kt=function(e=new Set){var s;if(e.has(this))return Fr(this._store);e.add(this);let n=this._store.get(O(this,Ir));return n?n instanceof Jh?fe(s=n,Pt,Kt).call(s,e):n:Fr(this._store)};var Zh=Jh,nE=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],kc,Ac,Yi,Rc,Lc,qi,Ut=class Ut extends se{constructor(e,n){let{chars:s,descriptors:o}=O(Ut,Lc).get(n);super(e,o);Z(this,qi);Pe(this,qi,s)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let n=O(this,qi);if(e===0)return n.digits[0];let s=[],o=0,r=e;for(;r>0;)s.unshift({digit:r%10,position:o}),r=Math.floor(r/10),o++;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}};kc=new WeakMap,Ac=new WeakMap,Yi=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,qi=new WeakMap,Z(Ut,kc,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ce(-9999),new ce(9999)]),0),negative:new V(new z("\u8D1F"),0)}}),Z(Ut,Ac,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ce(-9999),new ce(9999)]),0),negative:new V(new z("\u8D1F"),0)}}),Z(Ut,Yi,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ce(-9999),new ce(9999)]),0),negative:new V(new z("\u8CA0"),0)}}),Z(Ut,Rc,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new V(new z("\u3001"),0),fallback:new V(R("cjk-decimal"),0),range:new V(new X([new ce(-9999),new ce(9999)]),0),negative:new V(new z("\u8CA0"),0)}}),p(Ut,"NAMES",new Set(nE)),Z(Ut,Lc,new Map([["simp-chinese-informal",O(Ut,kc)],["simp-chinese-formal",O(Ut,Ac)],["trad-chinese-informal",O(Ut,Yi)],["trad-chinese-formal",O(Ut,Rc)],["cjk-ideographic",O(Ut,Yi)]]));var yc=Ut,Ic,Fc,Ki,Vc,Oc,Zt=class Zt extends se{constructor(t){super(t,O(Zt,Ic))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return O(Zt,Ki)[1];let e=[],n=t;for(;n>0;)e.push(n%100),n=Math.floor(n/100);let s=e.length,o="";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;o+=O(Zt,Fc)[d]+O(Zt,Ki)[h]}l?a!==0&&(o+=O(Zt,Vc)):r!==0&&(o+=O(Zt,Oc))}return o}};Ic=new WeakMap,Fc=new WeakMap,Ki=new WeakMap,Vc=new WeakMap,Oc=new WeakMap,Z(Zt,Ic,{range:new V(new X([new ce(1),R("infinite")]),0),suffix:new V(new z("/ "),0)}),Z(Zt,Fc,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),Z(Zt,Ki,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),Z(Zt,Vc,"\u137B"),Z(Zt,Oc,"\u137C");var Qh=Zt,Te,Sc=class{constructor(){Z(this,Te);Pe(this,Te,new Map),O(this,Te).set("none",se.createNone(O(this,Te))),O(this,Te).set("decimal",se.createDecimal(O(this,Te))),O(this,Te).set("disc",se.createDisc(O(this,Te))),O(this,Te).set("square",se.createSquare(O(this,Te))),O(this,Te).set("circle",se.createCircle(O(this,Te))),O(this,Te).set("disclosure-open",se.createDisclosureOpen(O(this,Te))),O(this,Te).set("disclosure-closed",se.createDisclosureClosed(O(this,Te)));for(let t of se.CHINESE_LONGHAND_NAMES)O(this,Te).set(t,se.createChineseLonghand(O(this,Te),t));O(this,Te).set("ethiopic-numeric",se.createEthiopicNumeric(O(this,Te)))}define(t,e){if(!Ix(t))return null;let n=se.create(O(this,Te),e);return O(this,Te).set(t,n),n}getStyle(t){var e;return(e=O(this,Te).get(t))!=null?e:null}format(t,e){var n;return((n=this.getStyle(t))!=null?n:Fr(O(this,Te))).format(e)}formatMarker(t,e){var n;return((n=this.getStyle(t))!=null?n:Fr(O(this,Te))).formatMarker(e)}};Te=new WeakMap;var Qi=class{constructor(t,e,n){p(this,"endStuckFixed");p(this,"endFixed");p(this,"endSlipped");this.endStuckFixed=t,this.endFixed=e,this.endSlipped=n}},ef=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 Qi(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 Qi(t,t,n))}}addSlippedRange(t){this.map.length==0?this.map.push(new Qi(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=Ft(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=Ft(this.map.length,s=>t<=this.map[s].endSlipped),n=this.map[e];return n.endStuckFixed-(n.endSlipped-t)}};function sE(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}var tf=class i{constructor(t,e,n,s,o,r,a,l){this.context=t;this.style=e;this.offset=n;this.isRoot=s;this.flowChunk=o;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=o.flowName,this.hasBox()){let c=e._pseudos;if(c&&c.before){let u=new i(t,c.before,n,!1,o,this.isBlock(),a,!0),d=u.styleValue("content");nt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=De(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ne(this.breakBefore)&&(o.breakBefore=De(o.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,e,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let o=new i(this.context,s.after,t,!1,this.flowChunk,e,n,!0),r=o.styleValue("content");nt(r)&&(this.afterBox=o)}}}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",S.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),e=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=ml(t,e,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==S.none&&!ho(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}},nf=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()!==S.none)}push(t,e,n,s){let o=this.lastBox();s&&o&&s.flowName!==o.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=s||o.flowChunk,a=this.atFlowStart||!!s,l=this.isCurrentBoxDisplayed(),c=new tf(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",S.normal).toString(),s=Vl(n);s&&!pe(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=De(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!")}},Ji=class{constructor(t,e,n,s,o,r,a,l,c,u){this.xmldoc=t;this.scope=n;this.context=s;this.primaryFlows=o;this.validatorSet=r;this.counterListener=a;p(this,"root");p(this,"cascadeHolder");p(this,"last");p(this,"rootStyle",{});p(this,"styleMap",{});p(this,"counterSnapshots",[]);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 ef;let d=t.getElementOffset(this.root);this.lastOffset=d,this.boxStack=new nf(s),this.offsetMap.addStuckRange(d);let h=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,h,d),this.recordCounterSnapshot(d,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),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 o=e[n];o&&(this.rootStyle[n]=new V(o,kd))}}}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)ls(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,o=this.hasProp(t,this.validatorSet.backgroundProps,"background-image")?t["background-image"].evaluate(this.context):null;(s&&!W(s)||o&&!W(o))&&(this.transferPropsToRoot(t,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let s=0;s<sb.length;s++)if(this.hasProp(t,this.validatorSet.layoutProps,sb[s])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!e){let s=t["font-size"],o=!0;if(s&&!W(s.value)){let l=s.evaluate(this.context);if(l instanceof A){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*ct.lh/ct.em;break;default:{let u=ct[l.unit];u&&(c*=u),o=!1}}this.context.rootFontSize=c,this.context.isRelativeRootFontSize=o}}let r=(n=this.context.rootFontSize)!=null?n:this.context.initialFontSize,a=t["line-height"];if(a&&!W(a.value)){let l=a.evaluate(this.context);if(l instanceof Ue)this.context.rootLineHeight=l.num*r;else if(l instanceof A){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=ct[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 mC(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}recordCounterSnapshot(t,e,n=[],s){let o={offset:t,counters:sE(e),changes:Array.from(n||[]),changeTypes:s?{...s}:void 0},r=this.counterSnapshots[this.counterSnapshots.length-1];if(r&&r.offset===t){this.counterSnapshots[this.counterSnapshots.length-1]=o;return}this.counterSnapshots.push(o)}getCounterSnapshotAtOffset(t){if(!this.counterSnapshots.length)return null;let e=Ft(this.counterSnapshots.length,s=>t<this.counterSnapshots[s].offset),n=e===0?0:e-1;return this.counterSnapshots[n]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(t){if(t>=this.lastOffset)return;let e=this.context,n=this.xmldoc.getElementOffset(this.root);if(t<n){let r=this.getStyle(this.root,!1);if(!this.cascade.firstPageType){let u=r.page,d=u&&!W(u.value)&&u.value.toString();d&&d.toLowerCase()!=="auto"&&(this.cascade.firstPageType=d)}let a=ee(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),o=this.xmldoc.getNodeOffset(s,0,!1);if(!(o>=this.lastOffset))for(;;){if(s.nodeType!=1)o+=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,o)}o++}if(o>=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 o=0,r=Number.POSITIVE_INFINITY,a=!1,l=!1,c=!1,u=e["flow-options"];if(u){let b=Hg(u.evaluate(this.context,"flow-options"));a=!!b.exclusive,l=!!b.static,c=!!b.last}let d=e["flow-linger"];d&&(r=Ju(d.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let h=e["flow-priority"];h&&(o=Ju(h.evaluate(this.context,"flow-priority"),0));let f=this.breakBeforeValues[s]||null,g=this.flows[t];if(!g){let b=this.boxStack.lastFlowName();g=this.flows[t]=new kl(t,b)}let m=new Al(t,n,s,o,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(Ne(t)){let o=this.flows[n].forcedBreakOffsets;(o.length===0||o[o.length-1]<e)&&o.push(e)}let s=this.breakBeforeValues[e];this.breakBeforeValues[e]=De(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 o=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=De(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),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);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(o,"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=De(u.flowChunk.breakBefore,u.breakBefore));let h=this.boxStack.nearestBlockStartOffset(u);if(h===0||a===this.xmldoc.body){let f=l.page,g=f&&!W(f.value)&&f.value.toString();!this.cascade.firstPageType&&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()===S.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){}},sb=["column-count","column-width","column-fill"];var Us=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)}},ps=class{constructor(t,e){this.where=t;this.success=e;p(this,"what",-1)}};var Ro=class i{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 i;for(let e=0;e<this.nodes.length;e++){let n=this.nodes[e],s=new Us(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 ps(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,o=new Us(ob);n>=0?e?o.markAsStartAlternate(n):o.markAsEndAlternate(n):e?o.markAsStartGroup():o.markAsEndGroup(),this.nodes.push(o),this.connect(t,s);let r=new ps(s,!0),a=new ps(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 Us(ob);e.markAsStartAlternate(t),this.nodes.push(e);let n=new ps(0,!0),s=new ps(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 Us(t));let n=new ps(e,!0),s=new ps(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 Fe}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 o=0;o<t.nodes.length;o++)this.nodes.push(t.nodes[o]);e==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let o=0;o<t.connections.length;o++){let r=t.connections[o];r.where+=n,r.what>=0&&(r.what+=n),this.connections.push(r)}for(let o=0;o<t.match.length;o++)this.match.push(t.match[o]+s);if(e==3&&this.connect(this.match,n),e==2||e==3)for(let o=0;o<t.nomatch.length;o++)this.match.push(t.nomatch[o]+s);else if(this.emptyHead){for(let o=0;o<t.nomatch.length;o++)this.nomatch.push(t.nomatch[o]+s);this.emptyHead=t.emptyHead}else for(let o=0;o<t.nomatch.length;o++)this.error.push(t.nomatch[o]+s);for(let o=0;o<t.error.length;o++)this.error.push(t.error[o]+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]}},rE=1,ib=2,ab=4,Ao=8,Bc=16,sf=32,Dc=64,lb=128,ea=256,ta=512,of=1024,cb=2048,ub=4096,db=8192,Mc=class extends Ot{constructor(){super()}validateForShorthand(t,e){let n=t[e].visit(this);return n?[n]:null}},Fe=class i extends Mc{constructor(e,n,s){super();this.allowed=e;this.idents=n;this.units=s}visitEmpty(e){return this.allowed&rE?e:null}visitSlash(e){return this.allowed&cb?e:null}visitStr(e){return this.allowed&ib?e:null}visitIdent(e){let n=this.idents[e.name.toLowerCase()];return n||(this.allowed&ab||this.allowed&Dc&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&ta)?e.unit=="%"&&this.allowed&of?e:null:e.num<0&&!(this.allowed&ea)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&ta?e:null:e.num<=0&&!(this.allowed&ea)?null:this.allowed&Bc?e:null}visitInt(e){if(e.num==0)return this.allowed&ta?e:null;if(e.num<=0&&!(this.allowed&ea))return null;if(this.allowed&(sf|Bc))return e;let n=this.idents[`${e.num}`];return n||null}visitHexColor(e){return this.allowed&Dc&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&lb?e:null}visitURange(e){return this.allowed&ub?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){if(this.allowed&Dc){if(e.name==="device-cmyk"||e.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Xu(e)!==null?e:null;if(CSS.supports("color",e.toString()))return e}if(this.allowed&db){let n=e.visit(new Zo);if(CSS.supports("background-image",n.toString()))return e}return e.name==="calc"&&this.allowed&(Ao|Bc|sf|ea|ta|of)?e:null}visitExpr(e){return this.allowed&2046?e:null}combine(e){let n={},s={};for(let o in this.idents)n[o]=this.idents[o];for(let o in e.idents)n[o]=e.idents[o];for(let o in this.units)s[o]=this.units[o];for(let o in e.units)s[o]=e.units[o];return new i(this.allowed|e.allowed,n,s)}},oe=Object.create(null),ob=new Fe(0,oe,oe),na=class extends Mc{constructor(e){super();p(this,"successTerminal");p(this,"failureTerminal");p(this,"first");this.successTerminal=new Us(null),this.failureTerminal=new Us(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,n,s){let o=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 Lo&&this instanceof Lo){if(d=new X(e).visit(r.validator),d){a=e.length,r=r.success;continue}}else if(a==0&&!n&&r.validator instanceof sa&&this instanceof Lo){if(d=new ve(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===o){o=[];for(let h=0;h<a;h++)o[h]=e[h]}e!==o&&(o[a-s]=d),a++,r=r.success}}return r===this.successTerminal&&(n?o.length>0:a==e.length)?o: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}},Lo=class extends na{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new X(e):null}visitCommaList(t){let e=this.first,n=!1;for(;e;){if(e.validator instanceof sa){n=!0;break}e=e.failure}if(n){let s=this.validateList(t.values,!1,0);return s===t.values?t:s?new ve(s):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},sa=class extends na{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 ve(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}},rf=class extends na{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 Bt(e.name,n):null}},_c=class{tryParse(t,e,n){return e}success(t,e){}},Uc=class extends _c{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 o=this.validator.validateForShorthand(e,n);if(o){let r=o.length,a=r>1?new X(o):o[0];return this.success(a,s),n+r}return n}success(e,n){n.values[this.name]=e}},af=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}},lf=class extends _c{constructor(e,n){super();this.nodes=e;this.slash=n}tryParse(e,n,s){let o=n;if(this.slash)if(e[n]==qn){if(++n==e.length)return o}else return o;let r=this.nodes[0].tryParse(e,n,s);if(r==n)return o;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}},oa=class extends Ot{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,o;if(!this.error){for(let r of this.propList)n.simpleProperty(r,(o=(s=this.values[r])!=null?s:this.validatorSet.defaultValues[r])!=null?o:S.initial,e);return!0}return!1}propagateDefaultingValue(e,n,s){for(let o of this.propList)s.simpleProperty(o,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)}},Hs=class extends oa{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}},Hc=class extends oa{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 af(this.validatorSet,this.propList)}},cf=class extends oa{constructor(){super()}validateList(t){let e=t.length;for(let n=0;n<t.length;n++)if(t[n]===qn){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 o;if(e+1<t.length)for(o=e+n+1;o>=t.length;)o=o-(o==e+2?1:2);else o=s;let r=[t[s],t[o]];if(this.syntax[n].tryParse(r,0,this)!=2)return this.error=!0,0}return t.length}},uf=class extends Hs{constructor(){super()}mergeIn(t,e){var n,s;for(let o of this.propList){let r=(s=(n=e[o])!=null?n:this.validatorSet.defaultValues[o])!=null?s:S.initial,a=t[o];a||(a=[],t[o]=a),a.push(r)}}visitCommaList(t){let e={};for(let n=0;n<t.values.length;n++)if(this.values={},t.values[n]instanceof ve?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 ve(e[n]);return null}},df=class extends Hs{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 o=this.validatorSet.validators;if(!t[e].visit(o["font-size"]))return this.error=!0,e;if(this.values["font-size"]=t[e++],t[e]===qn){if(e++,e+2>t.length)return this.error=!0,e;if(!t[e].visit(o["line-height"]))return this.error=!0,e;this.values["line-height"]=t[e++]}let r=e==t.length-1?t[e]:new X(t.slice(e,t.length));return r.visit(o["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 ve(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}},pf=class extends Hs{validateList(t){if(t.length===1&&t[0]instanceof Q)switch(t[0].name.toLowerCase()){case"normal":t=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":t=[S.auto,S.auto];break;case"none":t=[R("no-autospace"),R("space-all")];break}return super.validateList(t)}},iE=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],hf=class extends Hs{constructor(){super()}init(t,e){super.init(t,e);for(let n in this.validatorSet.validators)iE.includes(n)||this.propList.push(n)}validateList(t){return this.error=!0,0}},rb={SIMPLE:Hs,INSETS:Hc,INSETS_SLASH:cf,COMMA:uf,FONT:df,TEXT_SPACING:pf,ALL:hf},aE=["initial-letter"],ff=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 A(e.num,e.text);else if(e.type==7)n=new jo(e.text);else if(e.type==1)n=R(e.text);else throw new Error("unexpected replacement");if(t.isPrimitive()){let o=t.nodes[0].validator.idents;for(let r in o)o[r]=n;return t}throw new Error("unexpected replacement")}newGroup(t,e){let n=new Ro;if(t=="||"){for(let o=0;o<e.length;o++){let r=new Ro;r.startClause(o),r.addGroup(e[o],1),r.endClause(o),n.addGroup(r,o==0?1:4)}let s=new Ro;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 o=0;o<e.length;o++)n.addGroup(e[o],o==0?1:s);return n}}addCounts(t,e,n){let s=new Ro;for(let o=0;o<e;o++)s.addGroup(t.clone(),1);if(n==Number.POSITIVE_INFINITY)s.addGroup(t,3);else for(let o=e;o<n;o++)s.addGroup(t.clone(),2);return s}primitive(t){let e=new Ro;return e.addPrimitive(t),e}newFunc(t,e){let n;switch(t){case"COMMA":n=new sa(e);break;case"SPACE":n=new Lo(e);break;default:n=new rf(t.toLowerCase(),e);break}return this.primitive(n)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Fe(Dc,oe,oe)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Fe(db,oe,oe)),this.namedValidators.POS_INT=this.primitive(new Fe(sf,oe,oe)),this.namedValidators.POS_NUM=this.primitive(new Fe(Bc,oe,oe)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Fe(Ao,oe,{"%":$})),this.namedValidators.NEGATIVE=this.primitive(new Fe(ea,oe,oe)),this.namedValidators.ZERO=this.primitive(new Fe(ta,oe,oe)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Fe(of,oe,oe)),this.namedValidators.POS_LENGTH=this.primitive(new Fe(Ao,oe,{em:$,ex:$,ch:$,rem:$,lh:$,rlh:$,vw:$,vh:$,vi:$,vb:$,vmin:$,vmax:$,pvw:$,pvh:$,pvi:$,pvb:$,pvmin:$,pvmax:$,cm:$,mm:$,in:$,px:$,pt:$,pc:$,q:$})),this.namedValidators.POS_ANGLE=this.primitive(new Fe(Ao,oe,{deg:$,grad:$,rad:$,turn:$})),this.namedValidators.POS_TIME=this.primitive(new Fe(Ao,oe,{s:$,ms:$})),this.namedValidators.FREQUENCY=this.primitive(new Fe(Ao,oe,{Hz:$,kHz:$})),this.namedValidators.RESOLUTION=this.primitive(new Fe(Ao,oe,{dpi:$,dpcm:$,dppx:$})),this.namedValidators.URI=this.primitive(new Fe(lb,oe,oe)),this.namedValidators.URANGE=this.primitive(new Fe(ub,oe,oe)),this.namedValidators.IDENT=this.primitive(new Fe(ab,oe,oe)),this.namedValidators.STRING=this.primitive(new Fe(ib,oe,oe)),this.namedValidators.SLASH=this.primitive(new Fe(cb,oe,oe));let t={"font-family":R("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 o=n.text;if(t.consume(),e!=2){if(t.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(o)||(this.prefixes[o]=s)}else if(t.token().type!=18)throw new Error("':' expected");return o}parseValidators(t){for(;;){let e=this.readNameAndPrefixes(t,1);if(!e)return;let n=[],s=[],o="",r,a=!0,l=()=>{if(n.length==0)throw new Error("No values");return n.length==1?n[0]:this.newGroup(o,n)},c=d=>{if(a)throw new Error(`'${d}': unexpected`);if(o&&o!=d)throw new Error(`mixed operators: '${d}' and '${o}'`);o=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()]=R(d.text),n.push(this.primitive(new Fe(0,h,oe)))}a=!1;break;case 5:{let h={};h[`${d.num}`]=new ce(d.num),n.push(this.primitive(new Fe(0,h,oe))),a=!1;break}case 34:c("|");break;case 25:c("||");break;case 14:a||c(" "),s.push({vals:n,op:o,b:"["}),o="",n=[],a=!0;break;case 6:a||c(" "),s.push({vals:n,op:o,b:"(",fn:d.text}),o="",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),o=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)),o=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 Lo(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(R(s.text));break;case 4:n.push(new Ue(s.num));break;case 5:n.push(new ce(s.num));break;case 3:n.push(new A(s.num,s.text));break;default:throw new Error("unexpected token")}}this.defaultValues[e]=n.length>1?new X(n):n[0]}}parseShorthands(t){for(;;){let e=this.readNameAndPrefixes(t,3);if(!e)return;let n=t.nthToken(1),s;n.type==1&&rb[n.text]?(s=new rb[n.text],t.consume()):s=new Hs,s.setOwner(this);let o=!1,r=[],a=!1,l=[],c=[];for(;!o;)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 Hc){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 lf(r,a),d=l.pop();r=d.syntax,a=d.slash,r.push(u);break}case 17:o=!0,t.consume();break;default:throw new Error("unexpected token")}s.init(r,c),this.shorthands[e]=s}}parse(t){let e=new ot(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 o=this.shorthands[s],r=o?o.propList:[s];for(let a of r)e[a]=(n=this.defaultValues[a])!=null?n:S.initial}return e}validatePropertyAndHandleShorthand(t,e,n,s){let o=s.ruleType;if(Dt(t)||o==="font-face"||lE(e)){s.simpleProperty(t,e,n);return}if(o==="counter-style"){KC(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&&!Iu.includes(`-${r}-`)||s.unknownProperty(a,e);return}else if(aE.includes(t)&&!Object.keys(c).some(d=>Gr(d?`-${d}-`:"",t))){s.unknownProperty(a,e);return}let u=this.validators[t];if(u){let d=W(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();W(e)?d.propagateDefaultingValue(e,n,s):(e.visit(d),d.finish(n,s)||s.invalidPropertyValue(a,e))}}};function mf(){let i=new ff;return i.initBuiltInValidators(),i.parse(Sd),i}var gf=class extends Ot{constructor(){super(...arguments);p(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function lE(i){let t=new gf;return i.visit(t),t.varFound}var vN=`OTTO${new Date().valueOf()}`;function Cf(i){return Object.keys(i).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function uE(i){let t=new lt;for(let e of Cf(i))t.append(`${e}:${i[e].toString()};`);return t.toString()}function hb(i,t){let e={};for(let n in i)e[n]=ee(i,n).evaluate(t,n);return e}var ra=class{constructor(t){this.properties=t;p(this,"fontTraitKey");p(this,"src");p(this,"blobURLs",[]);p(this,"blobs",[]);p(this,"family");this.fontTraitKey=uE(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 lt;n.append(`@font-face {
1848
1845
  font-family: `),n.append(this.family),n.append(`;
1849
- `);for(let s of Zh(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
1850
- `);if(e){n.append('src: url("');let s=Ag(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
1846
+ `);for(let s of Cf(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
1847
+ `);if(e){n.append('src: url("');let s=rm(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
1851
1848
  }
1852
- `),n.toString()}},Fc=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],o=e.family;if(s){if(s!=o)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=o}filterFontFamily(t){if(t instanceof Se){let e=t.values,n=[];for(let s of e){let o=this.familyMap[s.stringValue()];o&&n.push(R(o)),n.push(s)}return new Se(n)}else{let e=this.familyMap[t.stringValue()];return e?new Se([R(e),t]):t}}},Vc=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=L("initFont"),o=t.src,r={};for(let u of Zh(t.properties))r[u]=t.properties[u];let a=this.getViewFontFamily(t,n);r["font-family"]=R(a);let l=new Qi(r),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(o,e),this.head.appendChild(c),O.debug("Load font:",o),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n+";"+t.fontTraitKey,o=this.srcURLMap[s];return o?o.piggyback(r=>{e.registerFamily(t,r),O.debug("Found already-loaded font:",n)}):(o=new An(()=>{let r=L("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?io(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]=o,o.start()),o}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){O.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return hn(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(o=>{}))}),e===0)return T(!0);let n=L("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?T(!0):T(!1))).thenFinish(n),n.result()}};var rS=1,kr=class{constructor(t,e,n,s,o){this.name=e;this.pseudoName=n;this.classes=s;this.parent=o;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${rS++}`,o&&(this.index=o.children.length,o.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})}},Bc=class extends kr{constructor(t){super(t,null,null,[],null),this.specified.width=new V(fs,0),this.specified.height=new V(gs,0)}},Oc=class extends qs{constructor(e,n){super(e,o);this.pageMaster=n;let s=this;function o(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}}},Ar=class i extends kr{constructor(e,n,s,o,r,a,l){super(e,n,s,o,r);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof Oc||(this._scope=new Oc(e,this)),this.pageMaster=this,this.specified.width=new V(fs,0),this.specified.height=new V(gs,0),this.specified["wrap-flow"]=new V(y.auto,0),this.specified.position=new V(y.relative,0),this.specified.overflow=new V(y.visible,0)}createInstance(e){return new wo(e,this)}clone(e){let n=new i(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}},Dc=class i extends kr{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new V(y.auto,0)}createInstance(t){return new Qh(t,this)}clone(t){let e=new i(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},_s=class i extends kr{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new Hn(t,this)}clone(t){let e=new i(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function iS(i,t,e){return!t||W(t)?new Ne(i,e):t.toExpr(i,i.zero)}function de(i,t,e){return!t||t===y.auto||W(t)?null:t.toExpr(i,e)}function aS(i,t,e){return!t||t===y.normal||W(t)?null:t.toExpr(i,e)}function Tt(i,t,e){return!t||t===y.auto||W(t)?i.zero:t.toExpr(i,e)}function ef(i,t,e){return!t||W(t)?i.zero:t===y.auto?null:t.toExpr(i,e)}function Sn(i,t,e,n){return!t||e===y.none||W(t)?i.zero:t.toExpr(i,n)}function DC(i,t,e){return!t||W(t)?e:t===y._true?i._true:t===y._false?i._false:t.toExpr(i,i.zero)}var Rr=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 K(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 o=this.vertical?Bp:Op;s=t;for(let r in o)s=s.replace(r,o[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 Uo(n,0),o=this.resolveName("column-count"),r=this.resolveName("column-width"),a=this.resolveName("column-gap");e=ie(n,Ho(n,new Xn(n,"min",[s,o]),K(n,r,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=DC(t,e.enabled,t._true),s=de(t,e.page,t.zero);if(s){let a=new ye(t,"page-number");n=bt(t,n,new hs(t,s,a))}let o=de(t,e["min-page-width"],t.zero);o&&(n=bt(t,n,new Ks(t,new ye(t,"page-width"),o)));let r=de(t,e["min-page-height"],t.zero);r&&(n=bt(t,n,new Ks(t,new ye(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=de(t,e.left,n),o=de(t,e["margin-left"],n),r=Sn(t,e["border-left-width"],e["border-left-style"],n),a=Tt(t,e["padding-left"],n),l=de(t,e.width,n),c=de(t,e["max-width"],n),u=Tt(t,e["padding-right"],n),d=Sn(t,e["border-right-width"],e["border-right-style"],n),h=de(t,e["margin-right"],n),f=de(t,e.right,n),g=K(t,r,a),m=K(t,r,u);if(s&&f&&l){let b=ie(t,n,K(t,l,K(t,K(t,s,g),m)));o?h?f=ie(t,b,h):h=ie(t,b,K(t,f,o)):(b=ie(t,b,f),h?o=ie(t,b,h):(o=Ho(t,b,new Ne(t,.5)),h=o))}else{o||(o=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 b=ie(t,n,K(t,K(t,o,g),K(t,h,m)));this.isAutoWidth&&(c||(c=ie(t,b,s||f)),!this.vertical&&(de(t,e["column-width"],null)||de(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=ie(t,b,K(t,s,l))):l=ie(t,b,K(t,s,f)):s=ie(t,b,K(t,f,l))}let C=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),x=Tt(t,C,n);e.left=new D(s),e["margin-left"]=new D(o),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(x)}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,o=de(t,e.top,s),r=de(t,e["margin-top"],n),a=Sn(t,e["border-top-width"],e["border-top-style"],n),l=Tt(t,e["padding-top"],n),c=de(t,e.height,s),u=de(t,e["max-height"],s),d=Tt(t,e["padding-bottom"],n),h=Sn(t,e["border-bottom-width"],e["border-bottom-style"],n),f=de(t,e["margin-bottom"],n),g=de(t,e.bottom,s),m=K(t,a,l),C=K(t,h,d);if(o&&g&&c){let N=ie(t,s,K(t,c,K(t,K(t,o,m),C)));r?f?g=ie(t,N,r):f=ie(t,N,K(t,g,r)):(N=ie(t,N,g),f?r=ie(t,N,f):(r=Ho(t,N,new Ne(t,.5)),f=r))}else{r||(r=t.zero),f||(f=t.zero),!o&&!g&&!c&&(o=t.zero),!o&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!o&&!g?o=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let N=ie(t,s,K(t,K(t,r,m),K(t,f,C)));this.isAutoHeight&&(u||(u=ie(t,N,o||g)),this.vertical&&(de(t,e["column-width"],null)||de(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),o?c?g||(g=ie(t,N,K(t,o,c))):c=ie(t,N,K(t,g,o)):o=ie(t,N,K(t,g,c))}let x=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=Tt(t,x,n);e.top=new D(o),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(b)}initColumns(){let t=this.pageBox.scope,e=this.style,n=de(t,e[this.vertical?"height":"width"],null),s=de(t,e["column-width"],n),o=de(t,e["column-count"],null),r=aS(t,e["column-gap"],null);r||(r=new an(t,1,"em")),s&&!o&&(o=new Xn(t,"floor",[Yr(t,K(t,n,r),K(t,s,r))]),o=new Xn(t,"max",[t.one,o])),o||(o=t.one),s=ie(t,Yr(t,K(t,n,r),o),r),e["column-width"]=new D(s),e["column-count"]=new D(o),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,o=this.parentInstance?this.parentInstance.getActiveRegions(t):null,r=Ni(this.cascaded,t,o,!1,null);this.vertical=ql(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)===y.border_box;let a=!!(t instanceof Us&&t.currentLayoutPosition&&new ye(n,"left-page").evaluate(t));Zl(r,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new te(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new te(n,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(t,e){var s,o;let n=this.style[e];return!n&&rs(e)&&this.pageMasterInstance instanceof zn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new k(t.rootFontSize,"px"):n=(o=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:o.value),n&&(n=Ti(t,n,e)),n}getPropAsNumber(t,e){var s,o;let n=this.style[e];if(n){let r=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(o=t.pageAreaWidth)!=null?o:t.pageWidth();n=Ti(t,n,e,r)}return Ye(n,t)}getSpecial(t,e){let n=Dp(this.cascaded,e);if(n){let s=[];for(let o=0;o<n.length;o++){let r=n[o].evaluate(t,"");r&&r!==G&&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 o=this.getProp(t,n);o&&(o.isNumeric()&&Ua(o.unit)&&(o=Ga(o,t)),n==="font-family"&&(o=s.filterFontFamily(o)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),P(e,n,o.toString()))}propagateDelayedProperty(t,e,n,s){let o=this.getProp(t,n);o&&s.push(new ws(e.element,n,o))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),o=this.getPropAsNumber(t,"padding-left"),r=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),P(e.element,"margin-left",`${s}px`),P(e.element,"padding-left",`${o}px`),P(e.element,"border-left-width",`${r}px`),e.marginLeft=s,e.borderLeft=r,e.paddingLeft=o}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),o=this.getPropAsNumber(t,"margin-right"),r=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(P(e.element,"margin-right",`${o}px`),P(e.element,"padding-right",`${r}px`),P(e.element,"border-right-width",`${a}px`),e.marginRight=o,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"),o=this.getPropAsNumber(t,"margin-top"),r=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=o,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,P(e.element,"top",`${s}px`),P(e.element,"margin-top",`${o}px`),P(e.element,"padding-top",`${r}px`),P(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),o=this.getPropAsNumber(t,"border-bottom-width"),r=this.getPropAsNumber(t,"height")-e.snapOffsetY;P(e.element,"height",`${r}px`),P(e.element,"margin-bottom",`${n}px`),P(e.element,"padding-bottom",`${s}px`),P(e.element,"border-bottom-width",`${o}px`),e.height=r-e.snapOffsetY,e.marginBottom=n,e.borderBottom=o,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){P(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,P(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){P(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");P(e.element,"right",`${s}px`),P(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,o){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&P(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&P(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<IC.length;r++)this.propagateProperty(t,e,IC[r],s)}transferContentProps(t,e,n,s){for(let o=0;o<VC.length;o++)this.propagateProperty(t,e,VC[o],s);if(this.style["text-overflow"]){let o=e.element.firstElementChild;P(o,"text-overflow","inherit"),P(o,"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!==y.auto&&!W(r)},o=()=>{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!==y.auto&&!W(r)};for(let r=0;r<BC.length;r++){let a=BC[r];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!o())continue;P(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,o,r,a){var d,h,f,g,m,C,x,b,N,S;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&&P(e.element,"width","auto"),l&&P(e.element,"height","auto");let E=s&&hr(s);E&&pr(s),u=r.getElementClientRect(s?s.element:e.element),E&&gi(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)),o>1){let E=this.getPropAsNumber(t,"column-rule-width"),v=this.getProp(t,"column-rule-style"),w=this.getProp(t,"column-rule-color");if(E>0&&v&&v!=y.none&&w!=y.transparent){let A=this.getPropAsNumber(t,"column-gap"),I=this.vertical?e.height:e.width,_=parseFloat(this.vertical?(d=s==null?void 0:s.element.style.left)!=null?d:"":(h=s==null?void 0:s.element.style.top)!=null?h:""),Y=e.getPaddingRect(),Q=s,me=this.vertical?"border-top":"border-left";for(let Te=1;Te<o;Te++){let De=this.vertical?(I+A)*Te/o-A/2+e.paddingTop-E/2:(I+A)*Te/o-A/2+e.paddingLeft-E/2,F=this.vertical?Y.y1+De+E/2:Y.x1+De+E/2,U=(m=(g=(f=Q.pageFloatLayoutContext)==null?void 0:f.parent)==null?void 0:g.getBlockEndEdgeOfBlockStartFloats)==null?void 0:m.call(g,F),j=(b=(x=(C=Q.pageFloatLayoutContext)==null?void 0:C.parent)==null?void 0:x.getBlockStartEdgeOfBlockEndFloats)==null?void 0:b.call(x,F),H=isFinite(U)?this.vertical?U-Y.x1:U-Y.y1:NaN,M=isFinite(j)?this.vertical?j-Y.x1:j-Y.y1:NaN,q=parseFloat(this.vertical?(N=s==null?void 0:s.element.style.width)!=null?N:"":(S=s==null?void 0:s.element.style.height)!=null?S:""),xe=q>0?q:this.vertical?s.width:s.height,Me=Math.max(_>0?_:0,0),Ro=Me+xe,Ir=Math.max(Me,isFinite(this.vertical?M:H)?Math.max(0,this.vertical?M:H):0),ga=Math.min(Ro,isFinite(this.vertical?H:M)?Math.max(0,this.vertical?H:M):Ro),Fr=Math.max(0,ga-Ir),Gn=e.element.ownerDocument.createElement("div");P(Gn,"position","absolute"),P(Gn,this.vertical?"left":"top",`${Ir}px`),P(Gn,this.vertical?"top":"left",`${De}px`),P(Gn,this.vertical?"height":"width","0px"),P(Gn,this.vertical?"width":"height",`${Fr}px`),P(Gn,me,`${E}px ${v.toString()}${w?` ${w.toString()}`:""}`),e.element.insertBefore(Gn,e.element.firstChild)}}}for(let E=0;E<FC.length;E++)this.propagateProperty(t,e,FC[E],a);for(let E=0;E<OC.length;E++)this.propagateDelayedProperty(t,e,OC[E],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let r in s)this instanceof zn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Fs(r)&&Mn(n,r,ne(s,r));if(this.pageBox.pseudoName==ea)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 o=n.content;o&&(n.content=o.filterValue(new Vs(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)}},IC=["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"],FC=["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"],VC=["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"],BC=["width","height","image-resolution","object-fit","object-position"],OC=["transform","transform-origin"],ea="background-host",Mc=class extends Rr{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,o)=>o.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-o.pageBox.index)}},wo=class extends Rr{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=bt(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},Qh=class extends Rr{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},Hn=class extends Rr{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 Se&&(s=e.values),s){let o=this.pageBox.scope;for(let r=0;r<s.length;r++)if(s[r]instanceof J){let a=jr(s[r].name,"enabled"),l=new ye(o,a);n&&(l=new zt(o,l)),t=bt(o,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=DC(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let o=iS(e,n["flow-from"],"body"),r=new Xn(e,"has-content",[o]);t=bt(e,t,r)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let o=this.pageMasterInstance.style.enabled,r=o?o.toExpr(e,null):e._true;r=bt(e,r,t),this.pageMasterInstance.style.enabled=new D(r)}return t}prepareContainer(t,e,n,s,o){var r;this.pageBox.pageMaster instanceof ta||(P(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(t,e,n,s,o)}},Ji=class extends fn{constructor(e,n,s,o){super(e,n,!1);this.target=s;this.validatorSet=o}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 V(n,s?il:al)}},_c=class extends Ji{constructor(t,e,n,s){super(t,e,n,s)}},Jh=class i extends Ji{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new V(Bu,0),n.specified.height=new V(Bu,0)}startPartitionRule(t,e,n){let s=new _s(this.scope,t,e,n,this.target),o=new _c(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new Dc(this.scope,t,e,n,this.target),o=new i(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},Uc=class extends Ji{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new _s(this.scope,t,e,n,this.target),o=new _c(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new Dc(this.scope,t,e,n,this.target),o=new Jh(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}};function xf(i){var n,s;let t=(n=i["writing-mode"])==null?void 0:n.value,e=(s=i.direction)==null?void 0:s.value;return t===y.vertical_lr||t!==y.vertical_rl&&e!==y.rtl?"ltr":"rtl"}var lS={a10:{width:new k(26,"mm"),height:new k(37,"mm")},a9:{width:new k(37,"mm"),height:new k(52,"mm")},a8:{width:new k(52,"mm"),height:new k(74,"mm")},a7:{width:new k(74,"mm"),height:new k(105,"mm")},a6:{width:new k(105,"mm"),height:new k(148,"mm")},a5:{width:new k(148,"mm"),height:new k(210,"mm")},a4:{width:new k(210,"mm"),height:new k(297,"mm")},a3:{width:new k(297,"mm"),height:new k(420,"mm")},a2:{width:new k(420,"mm"),height:new k(594,"mm")},a1:{width:new k(594,"mm"),height:new k(841,"mm")},a0:{width:new k(841,"mm"),height:new k(1189,"mm")},b10:{width:new k(31,"mm"),height:new k(44,"mm")},b9:{width:new k(44,"mm"),height:new k(62,"mm")},b8:{width:new k(62,"mm"),height:new k(88,"mm")},b7:{width:new k(88,"mm"),height:new k(125,"mm")},b6:{width:new k(125,"mm"),height:new k(176,"mm")},b5:{width:new k(176,"mm"),height:new k(250,"mm")},b4:{width:new k(250,"mm"),height:new k(353,"mm")},b3:{width:new k(353,"mm"),height:new k(500,"mm")},b2:{width:new k(500,"mm"),height:new k(707,"mm")},b1:{width:new k(707,"mm"),height:new k(1e3,"mm")},b0:{width:new k(1e3,"mm"),height:new k(1414,"mm")},c10:{width:new k(28,"mm"),height:new k(40,"mm")},c9:{width:new k(40,"mm"),height:new k(57,"mm")},c8:{width:new k(57,"mm"),height:new k(81,"mm")},c7:{width:new k(81,"mm"),height:new k(114,"mm")},c6:{width:new k(114,"mm"),height:new k(162,"mm")},c5:{width:new k(162,"mm"),height:new k(229,"mm")},c4:{width:new k(229,"mm"),height:new k(324,"mm")},c3:{width:new k(324,"mm"),height:new k(458,"mm")},c2:{width:new k(458,"mm"),height:new k(648,"mm")},c1:{width:new k(648,"mm"),height:new k(917,"mm")},c0:{width:new k(917,"mm"),height:new k(1297,"mm")},"jis-b10":{width:new k(32,"mm"),height:new k(45,"mm")},"jis-b9":{width:new k(45,"mm"),height:new k(64,"mm")},"jis-b8":{width:new k(64,"mm"),height:new k(91,"mm")},"jis-b7":{width:new k(91,"mm"),height:new k(128,"mm")},"jis-b6":{width:new k(128,"mm"),height:new k(182,"mm")},"jis-b5":{width:new k(182,"mm"),height:new k(257,"mm")},"jis-b4":{width:new k(257,"mm"),height:new k(364,"mm")},"jis-b3":{width:new k(364,"mm"),height:new k(515,"mm")},"jis-b2":{width:new k(515,"mm"),height:new k(728,"mm")},"jis-b1":{width:new k(728,"mm"),height:new k(1030,"mm")},"jis-b0":{width:new k(1030,"mm"),height:new k(1456,"mm")},letter:{width:new k(8.5,"in"),height:new k(11,"in")},legal:{width:new k(8.5,"in"),height:new k(14,"in")},ledger:{width:new k(11,"in"),height:new k(17,"in")}},cS=new k(.24,"pt"),xv=new k(3,"mm"),uS=new k(10,"mm"),dS=new k(13,"mm");function ca(i){let t={width:fs,height:gs,bleed:he,bleedOffset:he,cropOffset:he},e=i.size;if(!(!e||e.value===y.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&&lS[u.name.toLowerCase()];h&&(d&&d===y.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=i.marks,s=i.bleed,o=n&&!W(n.value)?n.value:y.none,r=s&&!W(s.value)?s.value:y.auto;if(r===y.auto){if(o!==y.none){let c=!1;o.isSpaceList()?c=o.values.some(u=>u===y.crop):c=o===y.crop,c&&(t.bleed=new k(6,"pt"))}}else r.isNumeric()&&(t.bleed=r);let a=i["crop-offset"],l=a&&!W(a.value)?a.value:y.auto;return l===y.auto?o!==y.none&&(t.bleedOffset=dS):l.isNumeric()&&(t.cropOffset=l),t}function Sf(i,t){let e={},n=Math.max(0,i.bleed.num)*t.queryUnitSize(i.bleed.unit,!1),s=!i.cropOffset.num&&i.bleedOffset.num?i.bleedOffset.num*t.queryUnitSize(i.bleedOffset.unit,!1):Math.max(0,i.cropOffset.num*t.queryUnitSize(i.cropOffset.unit,!1)-n),o=n+s,r=i.width;r===fs?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)-o*2:e.pageWidth=r.num*t.queryUnitSize(r.unit,!1);let a=i.height;return a===gs?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-o*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=o,e}function _C(i,t,e){let n=i.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function na(i,t,e,n){n=n||"polyline";let s=i.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===y.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var tf=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(tf||{});function pS(i,t,e,n,s,o,r){let a=s;a<=o+2*ot.mm&&(a=o+s/2);let l=Math.max(s,a),c=o+l+e/2,u=_C(i,c,c),d=[[0,o+s],[s,o+s],[s,o+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+l-m[0],m[1]]),h=h.map(m=>[o+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+l-m[1]]),h=h.map(m=>[m[0],o+l-m[1]]));let f=na(i,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=na(i,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 sa=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(sa||{});function hS(i,t,e,n,s,o){let r=s*2,a,l;t==="top"||t==="bottom"?(a=r,l=s):(a=s,l=r);let c=_C(i,a,l),u=na(i,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=na(i,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=na(i,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(sa).forEach(g=>{let m=sa[g];m===t?c.style[m]=`${o}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function UC(i,t,e,n){let s=!1,o=!1,r=i.marks;if(r){let m=r.value;m instanceof X?m.values.forEach(C=>{C===y.crop?s=!0:C===y.cross&&(o=!0)}):m===y.crop?s=!0:m===y.cross&&(o=!0)}let a=t.bleed;if(!s&&!o)return;let l=e.container,c=l.ownerDocument;let u=Ye(cS,n),d=Math.max(0,t.bleedOffset-Ye(uS,n)),h=t.bleedOffset-d,f=i["crop-marks-line-color"],g=f&&!W(f.value)?f.value:y.auto;s&&Object.keys(tf).forEach(m=>{let C=tf[m],x=pS(c,C,u,g,h,a,d);l.appendChild(x)}),o&&Object.keys(sa).forEach(m=>{let C=sa[m],x=hS(c,C,u,g,h,d);l.appendChild(x)})}var nf=(()=>{let i=["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 i.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 Ef={"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"}},fS=(()=>{let i=Ef;return Object.keys(i).sort((t,e)=>i[t].order-i[e].order)})(),Wc="vivliostyle-page-rule-master",oa="_marginBoxes",ra="_footnoteArea",ta=class extends Ar{constructor(e,n,s){super(e,null,Wc,[],n,null,0);p(this,"pageMarginBoxes",{});let o=ca(s),r=new sf(this.scope,this,s,o);this.createPageMarginBoxes(s),this.applySpecified(s,o)}createPageMarginBoxes(e){let n=e[oa];n&&fS.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new rf(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new V(y.relative,0),this.specified.width=new V(n.width,0),this.specified.height=new V(n.height,0);for(let s in e)!nf[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new zn(e,this)}},sf=class extends _s{constructor(e,n,s,o){super(e,null,null,[],n);this.pageSize=o;let r=new of(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new V(y.auto,0),this.specified["z-index"]=new V(new ae(0),0),this.specified.position=new V(y.absolute,0),this.specified.overflow=new V(y.visible,0);for(let n in nf)nf.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new lf(e,this)}},of=class extends _s{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new V(R("body"),0)}createInstance(t){return new ia(t,this)}},rf=class extends _s{constructor(e,n,s,o){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(o)}applySpecified(e){let n=e[oa][this.marginBoxName];for(let s in e){let o=e[s],r=n[s];(Vp[s]||r&&r.value===y.inherit)&&(this.specified[s]=o)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let o=n[s];o&&o.value!==G&&o.value!==y.inherit&&o.value!==y.unset&&o.value!==y.revert&&(this.specified[s]=o)}}createInstance(e){return new aa(e,this)}},zn=class extends wo{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o))switch(o){case"writing-mode":case"direction":s[o]=n[o]}super.applyCascadeAndInit(e,n)}initHorizontal(){let e=this.style;e.left=he,e["margin-left"]=he,e["border-left-width"]=he,e["padding-left"]=he,e["padding-right"]=he,e["border-right-width"]=he,e["margin-right"]=he,e.right=he}initVertical(){let e=this.style;e.top=he,e["margin-top"]=he,e["border-top-width"]=he,e["padding-top"]=he,e["padding-bottom"]=he,e["border-bottom-width"]=he,e["margin-bottom"]=he,e.bottom=he}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 o=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(o.top,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(o.bottom,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(o.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(o.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,o,r){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let E in e){let v=Ef[E];if(v){let w=e[E],A=this.pageMarginBoxInstances[E],I=new Lr(w,A.style,n,u,r);d[v.positionAlongVariableDimension]=w,h[v.positionAlongVariableDimension]=A,f[v.positionAlongVariableDimension]=I}}let g={start:s.start.evaluate(o),end:s.end.evaluate(o),extent:s.extent.evaluate(o)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),C=!1,x={};Object.keys(d).forEach(E=>{let v=E,w=de(u,h[v].style[n?"max-width":"max-height"],s.extent);if(w){let A=w.evaluate(o);if(m[v]>A){let I=f[v]=new Hc(d[v],h[v].style,n,u,r,A);x[v]=I.getOuterSize(),C=!0}}}),C&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),C=!1,[a,l,c].forEach(E=>{var v;m[E]=(v=x[E])!=null?v:m[E]}));let b={};Object.keys(d).forEach(E=>{let v=E,w=de(u,h[v].style[n?"min-width":"min-height"],s.extent);if(w){let A=w.evaluate(o);if(m[v]<A){let I=f[v]=new Hc(d[v],h[v].style,n,u,r,A);b[v]=I.getOuterSize(),C=!0}}}),C&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(E=>{m[E]=b[E]||m[E]}));let N=g.start+g.extent,S=g.start+(g.start+g.extent);[a,l,c].forEach(E=>{let v=m[E];if(v!=null){let w=d[E],A=0;switch(E){case a:A=n?w.left:w.top;break;case l:A=(S-v)/2;break;case c:A=N-v;break}n?w.setHorizontalPosition(A,v-w.getInsetLeft()-w.getInsetRight()):w.setVerticalPosition(A,v-w.getInsetTop()-w.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,o=e.center,r=e.end,a={};if(o){let c=[s,r],u=new af(c),d=this.distributeAutoMarginBoxSizes(o,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:o.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 o={xSize:null,ySize:null};if(e instanceof Lr&&e.minMaxFitContent&&(o.xSize=e.getOuterSize()),n instanceof Lr&&n.minMaxFitContent&&(o.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)o.xSize=s*r/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?o.xSize=c+(s-d)*(r-c)/(l-d):d>0&&(o.xSize=s*c/d)}o.xSize>0&&(o.ySize=s-o.xSize)}else r>0?o.xSize=s:a>0&&(o.ySize=s)}else e.hasAutoSize()?o.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(o.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(o.xSize=s):n&&n.hasAutoSize()&&(o.ySize=s);return o}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,o,r)}},Lr=class{constructor(t,e,n,s,o){this.container=t;this.isHorizontal=n;this.clientLayout=o;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let r=e[n?"width":"height"];if(this.hasAutoSize_=!r||r===y.auto||W(r),this.minMaxFitContent=r instanceof J&&(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=or(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()}},af=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}},Hc=class extends Lr{constructor(e,n,s,o,r,a){super(e,n,s,o,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()}},lf=class extends Hn{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 o in n)o.match(/^background-/)&&(this.cascaded[o]=n[o]);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,o=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=s[l].toExpr(o,null),u=de(o,n[l],c),d=de(o,n[`margin-${r}`],c),h=de(o,n[`margin-${a}`],c),f=Tt(o,n[`padding-${r}`],c),g=Tt(o,n[`padding-${a}`],c),m=Sn(o,n[`border-${r}-width`],n[`border-${r}-style`],c),C=Sn(o,n[`border-${a}-width`],n[`border-${a}-style`],c),x=K(o,K(o,m,f),K(o,C,g)),b,N,S;return u?(this.borderBoxSizing?(N=u,S=ie(o,N,x)):(S=u,N=K(o,S,x)),b=ie(o,c,N),!d&&!h?(d=Ho(o,b,new Ne(o,.5)),h=d):d?h=ie(o,b,d):d=ie(o,b,h)):(d||(d=o.zero),h||(h=o.zero),b=K(o,d,h),N=ie(o,c,b),S=ie(o,N,x),u=this.borderBoxSizing?N:S),n[r]=new D(d),n[a]=new D(h),n[`margin-${r}`]=he,n[`margin-${a}`]=he,n[`border-${r}-width`]=new D(m),n[`border-${a}-width`]=new D(C),n[`padding-${r}`]=new D(f),n[`padding-${a}`]=new D(g),n[l]=new D(u),n[`max-${l}`]=new D(u),{borderBoxExtent:N,contentBoxExtent:S,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,o,r)}},ia=class extends Hn{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 wn(n,e.left.toExpr(n,null))),t["margin-right"]=new D(new wn(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=y.solid,t["border-right-style"]=y.solid,t["border-left-color"]=y.transparent,t["border-right-color"]=y.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 wn(n,e.top.toExpr(n,null))),t["margin-bottom"]=new D(new wn(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=y.solid,t["border-bottom-style"]=y.solid,t["border-top-color"]=y.transparent,t["border-bottom-color"]=y.transparent}prepareContainer(t,e,n,s,o){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,o),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},aa=class extends Hn{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=Ef[s];let o=e;o.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,o,r)}applyVerticalAlign(e,n){P(n,"display","flex"),P(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),o=null;s===R("middle")?o="center":s===R("top")?o="flex-start":s===R("bottom")&&(o="flex-end"),o&&P(n,"justify-content",o);let r=this.getProp(e,"content");if(this.vertical||r instanceof Pe||r instanceof D&&r.expr instanceof te&&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")),P(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,o=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=r==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=de(o,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[r]=new D(h);else if(d){let f=Tt(o,s[`margin-${r}`],u),g=Tt(o,s[`margin-${a}`],u),m=Tt(o,s[`padding-${r}`],u),C=Tt(o,s[`padding-${a}`],u),x=Sn(o,s[`border-${r}-width`],s[`border-${r}-style`],u),b=Sn(o,s[`border-${a}-width`],s[`border-${a}-style`],u),N=K(o,d,K(o,this.borderBoxSizing?o.zero:K(o,K(o,m,C),K(o,x,b)),K(o,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[r]=new D(K(o,h,Yr(o,ie(o,u,N),new Ne(o,2))));break;case"end":s[r]=new D(ie(o,K(o,h,u),N));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,o=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=ef(o,s[`margin-${a}`],u),h=ef(o,s[`margin-${l}`],u),f=Tt(o,s[`padding-${a}`],u),g=Tt(o,s[`padding-${l}`],u),m=Sn(o,s[`border-${a}-width`],s[`border-${a}-style`],u),C=Sn(o,s[`border-${l}-width`],s[`border-${l}-style`],u),x=de(o,s[c],u),b=null;function N(S){if(b)return b;b={extent:x?x.evaluate(S):null,marginInside:d?d.evaluate(S):null,marginOutside:h?h.evaluate(S):null};let E=u.evaluate(S),v=0;return r||[m,f,g,C].forEach(w=>{w&&(v+=w.evaluate(S))}),(b.marginInside===null||b.marginOutside===null)&&v+b.extent+b.marginInside+b.marginOutside>E&&(b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)),b.extent!==null&&b.marginInside!==null&&b.marginOutside!==null&&(b.marginOutside=null),b.extent===null?(b.extent=E-v-b.marginInside-b.marginOutside,b.marginInside===null&&(b.marginInside=0),b.marginOutside===null&&(b.marginOutside=0)):typeof b.extent=="number"&&(b.marginInside===null&&typeof b.marginOutside=="number"?b.marginInside=E-v-b.extent-b.marginOutside:typeof b.marginInside=="number"&&b.marginOutside===null?b.marginOutside=E-v-b.extent-b.marginInside:b.marginInside=b.marginOutside=(E-v-b.extent)/2),b}s[c]=new D(new te(o,function(){let S=N(this).extent;return S===null?"auto":S},c)),s[`margin-${a}`]=new D(new te(o,function(){let S=N(this).marginInside;return S===null?"auto":S},`margin-${a}`)),s[`margin-${l}`]=new D(new te(o,function(){let S=N(this).marginOutside;return S===null?"auto":S},`margin-${l}`)),a==="left"?s.left=new D(K(o,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new D(K(o,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,o,r,a,l){super.finishContainer(e,n,s,o,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 J&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),C=this.getPropAsNumber(e,"max-width");if(g||m||C){g&&P(n.element,"width",g),m&&P(n.element,"min-width",`${m}px`),C&&P(n.element,"max-width",`${C}px`);let E=this.getProp(e,"margin-left"),v=this.getProp(e,"margin-right");if(d.isInLeftColumn){let w=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);P(n.element,"right",`${w}px`),(E===y.auto||v!==y.auto)&&P(n.element,"margin-left","auto"),v===y.auto&&P(n.element,"margin-right","auto")}else d.isInRightColumn&&(P(n.element,"right","0"),(v===y.auto||E!==y.auto)&&P(n.element,"margin-right","auto"),E===y.auto&&P(n.element,"margin-left","auto"))}let x=this.getProp(e,"height"),b=x instanceof J&&(x.name==="min-content"||x.name==="max-content"||x.name==="fit-content")?x.name:null,N=this.getPropAsNumber(e,"min-height"),S=this.getPropAsNumber(e,"max-height");if(b||N||S){b&&P(n.element,"height",b),N&&P(n.element,"min-height",`${N}px`),S&&P(n.element,"max-height",`${S}px`);let E=this.getProp(e,"margin-top"),v=this.getProp(e,"margin-bottom");if(d.isInTopRow){let w=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);P(n.element,"bottom",`${w}px`),(E===y.auto||v!==y.auto)&&P(n.element,"margin-top","auto"),v===y.auto&&P(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(P(n.element,"bottom","0"),(v===y.auto||E!==y.auto)&&P(n.element,"margin-bottom","auto"),E===y.auto&&P(n.element,"margin-top","auto"))}}},zc=class{constructor(t,e,n,s,o){this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=o;p(this,"pageMasterCache",{});p(this,"pageCascadeInstance");this.pageCascadeInstance=t,this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new ye(t,"page-number"),o=new hs(t,new _o(t,s,new Ne(t,2)),n?t.one:t.zero);t.defineName("recto-page",new zt(t,o)),t.defineName("verso-page",o),(e.pageProgression||xf(this.docElementStyle))==="ltr"?(t.defineName("left-page",o),t.defineName("right-page",new zt(t,o))):(t.defineName("left-page",new zt(t,o)),t.defineName("right-page",o))}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),o=this.pageMasterCache[s];return o||(n.pseudoName===ea?o=this.generatePageRuleMaster(e):o=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=o),o.pageBox.resetScope(),o}makeCacheKey(t,e){var o;let n=this.makeCascadeValueObjectKey(t),s=((o=this.context.currentLayoutPosition)==null?void 0:o.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],o;s instanceof V?o=`${s.value}`:o=this.makeCascadeValueObjectKey(s),e.push(n+o+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new ta(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:Wc}),s=n.specified,o=t.size;if(o&&!W(o.value)){let a=ca(t),l=o.priority;Jt(s,"width",new V(a.width,l),this.context),Jt(s,"height",new V(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}},cf=class extends le{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}},uf=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},df=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},pf=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},hf=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},ff=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},gf=class extends le{constructor(e){super();this.scope=e}apply(e){new ye(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},mf=class extends _n{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}},Cf=class extends _n{constructor(e,n,s,o){super(n,s);this.scope=e;this.a=n;this.b=s;this.pageType=o}apply(e){let n=e.pageTypePageIndices[this.pageType];if(n){for(let s of n)if(this.matchANPlusB(s)){this.chained.apply(e);return}}}getPriority(){return 3}},bf=class extends Co{constructor(t,e){super(t,e,null,null,null)}apply(t){gS(t.context,t.currentStyle,this.style,this.specificity,t)}};function gS(i,t,e,n,s){vi(i,t,e,n,null,null,null);let o=e[oa];if(o){let a=yn(t,oa);for(let l in o)if(o.hasOwnProperty(l)){let c=a[l];c||(c={},a[l]=c),vi(i,c,o[l],n,null,null,null)}}let r=e[ra];if(r){let a=yn(t,ra);for(let l in r)if(r.hasOwnProperty(l)){let c=a[l];c||(c={},a[l]=c);let u=r[l];for(let h in u)if(u.hasOwnProperty(h)&&h!=="_pseudos"){let f=u[h];f instanceof V&&Jt(c,h,f)}let d=lt(u,"_pseudos");if(d){let h=yn(c,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=h[f];g||(g={},h[f]=g);let m=d[f];for(let C in m)if(m.hasOwnProperty(C)){let x=m[C];x instanceof V&&Jt(g,C,x)}}}}}}var Gc=class extends os{constructor(e,n,s,o,r){super(e,n,s==null?void 0:s.condition,s,null,o,!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 cf(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let s=n[0],o=n[1];if(n.length===3&&typeof n[2]=="string"){let r=n[2];this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o} of ${r})`),this.chain.push(new Cf(this.scope,s,o,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o})`),this.chain.push(new mf(this.scope,s,o)),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 uf(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new df(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new pf(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new hf(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new ff(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new gf(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 o=ne(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(a=>{Mn(r[a],e,o)});else if(e==="size"){let a=r[""];this.currentPageSelectors.forEach(l=>{let c=new V(o.value,o.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=r[u];d?Jt(d,e,c):(d=r[u]={},Mn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&Mn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new bf(this.elementStyle,e)}startFootnoteRule(e){let n=yn(this.elementStyle,ra),s=n.area;if(s||(s={},n.area=s),e){let r=yn(s,"_pseudos"),a=r[e];a||(a={},r[e]=a),s=a}let o=new la(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}startPageMarginBoxRule(e){let n=yn(this.elementStyle,oa),s=n[e];s||(s={},n[e]=s);let o=new yf(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}},yf=class extends fn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.boxStyle=o}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 o=s?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(n,o);Mn(this.boxStyle,e,r)}},la=class extends fn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.areaStyle=o}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 o=s?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(n,o);Mn(this.areaStyle,e,r)}};var En=!0;function GC(i){En=i}var Po=[];function zC(i,t){return i===t||(i.src||t.src?i.src===t.src:i.textContent===t.textContent)}function WC(i){let t=Array.from(i.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(i.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function $c(i,t,e){if(!En)return T(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&WC(i.ownerDocument).includes(i))return T(!1);let n=i.textContent,s=i.src,o=i.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=(o||s)&&i.async&&!r,l=(o&&!a||s&&i.defer)&&!r,c=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||l||a);if(vf(t)||(t.onload=null),c)return Po.some(d=>zC(d,i))||Po.push(i),T(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&zC(d,i)&&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 i.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(O.debug("script:",s),s){let d=Wt(u);return t.document.head.appendChild(u),hn([d])}else return t.document.head.appendChild(u),T(!0)}function mS(i,t){var o;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 Co)n(r.style);else if(r instanceof ss||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 i.querySelectorAll("[style]"))(o=r.style)!=null&&o.fontFamily&&(e[r.style.fontFamily]=!0);return Object.keys(e).join(",")}function CS(i,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=mS(i,e),n.textContent=i.documentElement.textContent,t.document.body.appendChild(n),n}function $C(i,t,e){if(!En)return T(!1);let n=WC(i);if(n.length===0)return T(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),o=s?CS(i,t,e):null,r=t.document.fonts,a=t.$,l=!1,c=L("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 $c(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Po.push(u),l=!0),n.length===0&&s&&(O.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),T(!0)))}).then(()=>{o&&o.remove(),c.finish(!0)}),c.result()}function XC(i){if(!En)return T(!1);let t=L("loadScripts");return t.loop(()=>Po.length===0?T(!1):$c(Po.shift(),i,{atEnd:!0}).thenReturn(Po.length>0)).then(()=>{O.debug("dispatchEvent: DOMContentLoaded (window)"),i.dispatchEvent(new Event("DOMContentLoaded")),O.debug("dispatchEvent: load (window)"),i.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function vf(i){return En?Po.length>0||!!i.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}function Xc(i,t){return!!(i&&i.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function Hs(i){if(i.localName!=="aside")return!1;if(Xc(i.getAttribute("role"),"doc-footnote"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Xc(t,"footnote")}function ko(i){if(i.localName!=="a")return!1;if(Xc(i.getAttribute("role"),"doc-noteref"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Xc(t,"noteref")}function bS(i){let t=i.getElementsByTagName("a");for(let e=0;e<t.length;e++){let n=t.item(e);if(!ko(n)||!(n instanceof HTMLAnchorElement)||!n.hash||n.href!==n.baseURI.replace(/#.*$/,"")+n.hash)continue;let s=n.hash.substring(1),o=i.getElementById(s);o&&Hs(o)&&o.setAttribute("data-vivliostyle-footnote-referenced","true")}}je("PREPROCESS_SINGLE_DOCUMENT",bS);var YC=(i,t,e)=>i.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 xS={};function SS(i){i.addEventListener("load",()=>{i.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 zs=class zs extends ds{constructor(e,n,s,o,r,a,l,c,u,d,h,f,g,m,C,x=new Map,b={value:!1}){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=o;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;this.pageProps=m;this.cascadedPageStyle=C;this.semanticFootnoteFirstRefOffsets=x;this.semanticFootnoteFirstRefOffsetsInitialized=b;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=o.counterListener.getExprContentListener()}clone(){return new zs(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}initializeSemanticFootnoteFirstRefOffsets(e){if(this.semanticFootnoteFirstRefOffsetsInitialized.value)return;let n=e.getElementsByTagName("a");for(let s=0;s<n.length;s++){let o=n.item(s);if(!ko(o))continue;let r=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!r)continue;let a=_r(r,this.xmldoc.url);a!=="#"&&(this.semanticFootnoteFirstRefOffsets.has(a)||this.semanticFootnoteFirstRefOffsets.set(a,this.xmldoc.getElementOffset(o)))}this.semanticFootnoteFirstRefOffsetsInitialized.value=!0}shouldGenerateSemanticFootnote(e){if(e.localName!=="a"||!ko(e))return!0;let n=e.getAttribute("href")||e.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!n)return!0;let s=_r(n,this.xmldoc.url);if(s==="#")return!0;this.initializeSemanticFootnoteFirstRefOffsets(e.ownerDocument);let o=this.semanticFootnoteFirstRefOffsets.get(s);return o==null?!0:this.xmldoc.getElementOffset(e)===o}createPseudoelementShadow(e,n,s,o,r,a,l,c){var C;let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=yo.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h;for(let x of Xm){let b;if(x){if(!u[x]||x=="footnote-marker"&&!(n&&this.isFootnote)&&!((C=this.nodeContext)!=null&&C.pluginProps.nestedFootnoteDetached))continue;if(x.match(/^first-/)){let N=o.display;if(!N||N===y.inline)continue;let S=e.firstElementChild;if(S&&ce(S.previousSibling)){let E=r.getStyle(S,!1);if(E){let v=ne(E,"display");if(v!=null&&v.value&&v.value!==y.inline)continue}}}if(x==="before"||x==="after"||x==="footnote-marker"){let N=u[x].content;if(!N||!at(N.value))continue}d.push(x),b=yo.createElementNS("http://www.w3.org/1999/xhtml","span"),vr(b,x)}else b=yo.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(b),x.match(/^first-/)&&(f=b)}if(!d.length)return c;let g=new Er(e,s,r,a,this.exprContentListener),m=new Ps(e,h,null,l,c,gt.ROOTLESS,g);return c||m}getPseudoMap(e,n,s,o,r){let a=lt(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};Sr(u,a[c],r),Gl(u,r,a[c]),Hp(a[c],n,s,(d,h)=>{Sr(u,h,r),Up(h,f=>{Sr(u,f,r)})})}return l}createRefShadow(e,n,s,o,r){let a=L("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 Ps(s,u,c,o,r,n,d)}}a.finish(r)}),a.result()}createShadows(e,n,s,o,r,a,l){let c=L("createShadows"),u=null,d=o.template,h;if(d instanceof Pe||d===y.footnote)if(d!==y.footnote||this.shouldGenerateSemanticFootnote(e)){let f=d instanceof Pe?d.url:ee("user-agent.xml#footnote",on);h=this.createRefShadow(f,gt.ROOTLESS,e,l,u)}else h=T(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 C=e.getAttribute("href"),x=null;C?x=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?C=l.owner.getAttribute("href"):C=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),x=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),C&&(C=_r(C,x.url),g=this.createRefShadow(C,gt.ROOTED,e,l,f))}g==null&&(g=T(f));let m=null;g.then(C=>{if(o.display===y.table_cell){let x=ee("user-agent.xml#table-cell",on);m=this.createRefShadow(x,gt.ROOTLESS,e,l,C)}else m=T(C);m.then(x=>{x=this.createPseudoelementShadow(e,n,s,o,r,a,l,x),c.finish(x)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,o){var x;let r=this.context,a=Ni(s,r,this.regionIds,this.isFootnote,this.nodeContext),l=!((x=this.nodeContext)!=null&&x.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=ql(a,r,e);let u=!l&&e!==c;n=Kl(a,r,n);let d=(b,N)=>{let S;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(b)&&(S=r.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(b)&&(S=r.pageAreaWidth));let E=N.evaluate(r,b,S,e);return b=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},h=!!new ye(r.style.pageScope,"left-page").evaluate(r);if(Zl(a,o,e,n,h,d),u){let b=o[e?"height":"width"];(!b||b===y.auto)&&(o[e?"height":"width"]=y.max_content)}if(co(o.position))return o.position=y.fixed,o.visibility=y.hidden,e;let f=o.position,g=o.float,m=o.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),C=Dd(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(b=>{C[b]&&(o[b]=C[b])}),e}inheritFromSourceParent(e){var m,C;let n=this.nodeContext.sourceNode,s=[],o=null,r=n instanceof Element&&n.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&n.localName==="include"&&n.classList.contains("-vivliostyle-footnote-content"),a=this.isFootnote&&(!((m=this.nodeContext)!=null&&m.parent)||r),l=this.nodeContext.shadowContext;if(n instanceof Element&&n.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&n.localName==="include"&&n.classList.contains("-vivliostyle-footnote-content")){let x=l==null?void 0:l.owner;if(x instanceof Element&&ko(x)){let b=x.getAttribute("href")||x.getAttributeNS("http://www.w3.org/1999/xlink","href");if(b){let N=_r(b,this.xmldoc.url),S=this.xmldoc.getElement(N);S&&Hs(S)&&((C=S.parentNode)==null?void 0:C.nodeType)===1&&(n=S.parentNode,l=null)}}}let c=-1;for(;n&&n.nodeType==1;){let x=l&&l.root==n,b=!!x&&l.type==gt.ROOTED&&Hs(n);if(!x||l.type==gt.ROOTLESS||b){let S=(l?l.styler:this.styler).getStyle(n,!1);s.push(S),o=o||Ur(n)}x&&!b?(n=l.owner,l=l.parentShadow):(n=n.parentNode,c++)}let u=new Set;if(s.length>0){let x=s[0],b=Ni(x,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let N in b){if(!rs(N))continue;let S=b[N].evaluate(this.context,N);S&&S!==y.inherit&&S!==y.unset&&S!==y.revert&&S!==G&&u.add(N)}}let d=c===0,h=this.context.queryUnitSize("em",d),f={"font-size":new V(new k(h,"px"),0)};d&&(f["line-height"]=new V(new Ue(this.context.pref.lineHeight),0));let g=new Vl(f,this.context);for(let x=s.length-1;x>=0;--x){let b=s[x],N=[];for(let v in b)rs(v)&&N.push(v);N.sort(Ou);let S,E;for(let v of N){if(x>0&&a&&v.startsWith("--viv-marker-")||x>0&&u.has(v))continue;g.setPropName(v);let w=ne(b,v),A=w;if(w.value===y.initial)delete f[v];else if(!W(w.value)){if(v==="font-size"&&x===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)A=new V(new k(this.context.rootFontSize,"px"),w.priority);else if(v==="line-height"&&x===s.length-1&&this.context.rootLineHeight&&w.value instanceof k&&(w.value.unit==="lh"||w.value.unit==="rlh"))A=new V(new k(this.context.rootLineHeight,"px"),w.priority);else if(x===0&&w.value instanceof k&&w.value.unit==="lh"){let I=this.getLineHeightUnitSize(v,S,E);I!=null&&(A=new V(new k(w.value.num*I,"px"),w.priority))}else Vt(v)||(A=w.filterValue(g));v==="font-size"?S=A.value:v==="line-height"&&(E=A.value),f[v]=A}}}for(let x in e)rs(x)||(f[x]=e[x]);return{lang:o,elementStyle:f}}resolveURL(e){return e=ee(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=Ur(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=Tm().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let o in this.nodeContext.parent.inheritedProps)s[o]=this.nodeContext.parent.inheritedProps[o]}n.forEach(o=>{let r=e[o];if(r){if(W(r))r===y.initial&&(s[o]=void 0);else if(r instanceof ae)s[o]=r.num;else if(r instanceof J)s[o]=r.name;else if(r instanceof k){let a=r;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[o]=a.num*ot[a.unit];break;default:s[o]=r}}else s[o]=r;["widows","orphans"].includes(o)||delete e[o]}})}}resolveFormattingContext(e,n,s,o,r,a){let l=Je("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,o,r,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var b,N;let s=!0,o=L("createElementView"),r=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(r,!1);if(!this.nodeContext.shadowContext){let S=this.xmldoc.getElementOffset(r);Is.registerFragmentIndex(S,this.nodeContext.fragmentIndex,0)}let c={};if(!this.nodeContext.parent){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}let u=l.position,d=l.float,h=l["float-reference"],f=d&&!W(d.value)&&d.value!==y.none&&h&&!W(h.value)?am(h.value.toString()):null,g=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===gt.ROOTED&&Hs(r);if(this.nodeContext.parent&&(co(u==null?void 0:u.value)||f&&bn(f)||g)){let S=this.inheritFromSourceParent(l);l=S.elementStyle,this.nodeContext.lang=S.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),f&&bn(f)&&c.display===y.block&&(c.display=y.flow_root),a.processContent(r,c,this.nodeContext),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let m=c["flow-into"];if(m&&m.toString()!=this.flowName)return o.finish(!1),o.result();if(En&&r.localName==="script"&&r.namespaceURI==="http://www.w3.org/1999/xhtml")return $c(r,this.viewport.window).thenFinish(o),o.result();let C=c.display;if(W(C)&&(C===y.initial||C===y.unset?C=y.inline:C===y.inherit?C=((b=this.nodeContext.parent)==null?void 0:b.display)&&R((N=this.nodeContext.parent)==null?void 0:N.display):C=null),C===y.none)return o.finish(!1),o.result();let x=this.nodeContext.parent==null;return this.nodeContext.flexContainer=C===y.flex,this.createShadows(r,x,l,c,a,this.context,this.nodeContext.shadowContext).then(S=>{var Df;this.nodeContext.nodeShadow=S;let E=c.position,v=c.float,w=c.clear,A=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,I=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:A,_=cm(r),Y=c["column-count"],Q=c["column-width"],me=Y&&Y!==y.auto&&!W(Y)||Q&&Q!==y.auto&&!W(Q);this.nodeContext.establishesBFC=dm(C,E,v,c.overflow,A,I,me||_),this.nodeContext.containingBlockForAbsolute=pm(E),this.nodeContext.isInsideBFC()&&v!==y.footnote&&!(f&&bn(f))&&(v=null,w=null);let Te=null,De=!1,F=this.isFootnote&&(!((Df=this.nodeContext)!=null&&Df.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached),U=v instanceof X||v===y.left||v===y.right||v===y.top||v===y.bottom||v===y.inline_start||v===y.inline_end||v===y.block_start||v===y.block_end||v===y.snap_block||v===y.snap_inline||v===y.inside||v===y.outside||v===y.footnote;if(v&&(delete c.float,v===y.footnote))if(Te=c["footnote-display"],De=!!c["--viv-marker-content"],F){U=!1;let $=Te==null?void 0:Te.toString();C=De?R("list-item"):$==="inline"?y.inline:y.block,c.display=C}else c.display=y.inline;w&&(w===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(w=R(this.nodeContext.parent.clearSide)),(w===y.left||w===y.right||w===y.top||w===y.bottom||w===y.inline_start||w===y.inline_end||w===y.block_start||w===y.block_end||w===y.inside||w===y.outside||w===y.both||w===y.all||w===y.same||w===y.column||w===y.region||w===y.page)&&(delete c.clear,(U||c.display&&c.display!=y.inline)&&(this.nodeContext.clearSide=w.toString())));let j=uo(C)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),H=c["break-inside"];(U||H&&!W(H)&&H!==y.auto)&&this.nodeContext.breakPenalty++,C&&C!==y.inline&&Et(C)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!U&&!C||Et(C)||Tl(C),this.nodeContext.display=C?C.toString():"inline",this.nodeContext.floatSide=U?v.toString():null,this.nodeContext.floatReference=f||ue.INLINE;let M=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=M&&!W(M)?M:null;let q=this.isInsideNonRootMultiColumn(),xe=c["column-span"];if(this.nodeContext.columnSpan=!q&&xe&&!W(xe)?xe:null,!this.nodeContext.inline){let $=c["break-after"];$&&!W($)&&!(q&&$===y.column)&&(this.nodeContext.breakAfter=$.toString(),ul[this.nodeContext.breakAfter]&&(c["break-after"]=y.column));let wt=c["break-before"];wt&&!W(wt)&&!(q&&wt===y.column)&&(this.nodeContext.breakBefore=wt.toString(),ul[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Yt=c.page,Pt=Yt&&!W(Yt)&&Yt.toString();!Pt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||C===y.table_header_group||C===y.table_footer_group)&&(Pt=this.styler.cascade.currentPageType),!Pt||Pt.toLowerCase()==="auto"?Pt=this.nodeContext.pageType:this.nodeContext.pageType=Pt,this.styler.cascade.currentPageType!==Pt&&!(!Pt&&c.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!Zn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Pt!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Pt)}this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let Me=c["border-collapse"];if(!Me||Me===R("separate")){let $=c["border-spacing"],wt,Yt;$&&($ instanceof X?(wt=$.values[0],Yt=$.values[1]):wt=Yt=$,wt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Ye(wt,this.context)),Yt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Ye(Yt,this.context)))}let Ro=c["footnote-policy"];this.nodeContext.footnotePolicy=Ro&&!W(Ro)?Ro:null;let Ir=c["x-first-pseudo"];if(Ir){let $=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new ml($,Ir.num)}this.nodeContext.inline||this.processAfterIfcontinues(r,l,a,this.context);let ga=c["white-space"];if(ga){let $=xl(ga.toString());$!==null&&(this.nodeContext.whitespace=$)}let Fr=c["hyphenate-character"];Fr&&Fr instanceof z&&(this.nodeContext.hyphenateCharacter=Fr.str);let Gn=c["word-break"],lb=c["line-break"],Of=c["overflow-wrap"];(Gn===y.break_all||lb===y.anywhere||Of===y.break_word||Of===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,C,E,v,x),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 Ws=!1,lu=null,Vr=[],sn=r.namespaceURI,re=r.localName,ma=re;sn=="http://www.w3.org/1999/xhtml"?(re=="html"||re=="body"||re=="script"||re=="link"||re=="meta"?re="div":re=="vide_"?re="video":re=="audi_"?re="audio":re=="object"&&(Ws=!!this.customRenderer),r.hasAttribute(Ql)&&r.hasAttribute("src")&&c.content instanceof Pe&&(re="img")):sn=="http://www.idpf.org/2007/ops"?(re="span",sn="http://www.w3.org/1999/xhtml"):sn=="http://www.pyroxy.com/ns/shadow"?(sn="http://www.w3.org/1999/xhtml",re=this.nodeContext.inline?"span":"div"):Ws=!!this.customRenderer,j?e?(re="li",c["--viv-marker-content"]&&(c["list-style-type"]=y.none,c["list-style-image"]=y.none)):(C=Et(C)?y.inline:y.block,c.display=C,re="div"):re=="body"||re=="li"?re="div":re=="q"&&(re="span"),c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(Ws=!0),r.dataset&&r.getAttribute("data-math-typeset")==="true"&&(Ws=!0);let cu;if(Ws){let $=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;cu=this.customRenderer(r,$,c)}else cu=T(null);cu.then($=>{var Uf,Hf,zf;if($)Ws&&(s=$.getAttribute("data-adapt-process-children")=="true");else if(c.display===y.none){o.finish(!1);return}else $=this.createElement(sn,re);if(!x&&me&&c["column-fill"]===y.auto){let Qe=this.nodeContext.vertical?c.width:c.height;(!Qe||Qe===y.auto||W(Qe))&&($.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=y.balance)}re!=ma&&($.setAttribute("data-vivliostyle-original-tag",ma),(ma==="html"||ma==="body")&&($.role="presentation")),re=="a"&&$.addEventListener("click",this.page.hrefHandler,!1),lu&&(this.applyPseudoelementStyle(this.nodeContext,"inner",lu),$.appendChild(lu)),$.localName=="iframe"&&$.namespaceURI=="http://www.w3.org/1999/xhtml"&&SS($);let wt=this.nodeContext.inheritedProps["image-resolution"],Yt=[],Pt=c.width,uu=c.height,cb=r.getAttribute("width"),ub=r.getAttribute("height"),du=Pt===y.auto||!Pt&&!cb,pu=uu===y.auto||!uu&&!ub,Mf=r.attributes,db=Mf.length,Ca=null,_f=null;C===y.table_cell&&((zf=(Hf=(Uf=this.nodeContext.parent)==null?void 0:Uf.viewNode)==null?void 0:Hf.lastElementChild)==null?void 0:zf.localName)==="a"&&$.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Qe=0;Qe<db;Qe++){let kt=Mf[Qe],At=kt.namespaceURI,Ce=kt.localName,ke=kt.nodeValue;if(At){if(At=="http://www.w3.org/2000/xmlns/")continue;At=="http://www.w3.org/1999/xlink"&&Ce=="href"&&(ke=this.documentURLTransformer.transformURL(this.resolveURL(ke),this.xmldoc.url))}else{if(!En&&Ce.match(/^on/)||Ce=="style")continue;if((Ce=="id"||Ce=="name")&&e){let ct=this.documentURLTransformer.transformFragment(ke,this.xmldoc.url);$.setAttribute(Ce,ke),$.setAttribute("data-vivliostyle-id",ct);let _t=$.ownerDocument.createElement("a");_t.setAttribute(Ce,ct),_t.setAttribute(Vn,"1"),_t.style.position="absolute",$.appendChild(_t),this.page.registerElementWithId($,ct);continue}if(Ce=="src"||Ce=="href"||Ce=="poster")ke=this.resolveURL(ke),Ce==="href"&&(ke=this.documentURLTransformer.transformURL(ke,this.xmldoc.url));else if(Ce=="srcset")ke=ke.split(",").map(ct=>this.resolveURL(ct.trim())).join(",");else if(Ce==="data"&&Ws&&re==="object"&&$.hasAttribute("data"))continue;if(Ce==="poster"&&re==="video"&&sn==="http://www.w3.org/1999/xhtml"&&du&&pu){let ct=new Image,_t=Wt(ct,ke);Vr.push(_t),Yt.push({image:ct,element:$,fetcher:_t})}}if(sn=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(Ce)&&(Ce=Ce.toLowerCase()),this.isSVGUrlAttribute(Ce)&&(ke=YC(ke,this.xmldoc.url,this.documentURLTransformer)),At){let ct=xS[At];ct&&(Ce=`${ct}:${Ce}`)}if(Ce=="src"&&!At&&(re=="img"||re=="input")&&sn=="http://www.w3.org/1999/xhtml")Ca=ke;else if(Ce=="alt"&&!At&&re=="img"&&sn=="http://www.w3.org/1999/xhtml")_f=ke;else if(Ce=="href"&&re=="image"&&sn=="http://www.w3.org/2000/svg"&&At=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Wt($,ke));else if(At)$.setAttributeNS(At,Ce,ke);else try{$.setAttribute(Ce,ke)}catch(ct){O.warn(ct)}}if(Ca){let Qe=re==="input"?new Image:$,kt=Wt(Qe,Ca,_f);Qe!==$&&($.src=Ca);let At=()=>{var ke,ct;if(c.position===y.fixed)return!0;for(let _t=(ke=this.nodeContext.parent)==null?void 0:ke.viewNode;_t&&_t!==this.viewRoot;_t=_t.parentElement)if(((ct=_t.style)==null?void 0:ct.position)==="fixed")return!0;return!1};!du&&!pu&&!(()=>{let ke=this.nodeContext.vertical?Pt:uu;return ke instanceof k&&ke.unit==="%"})()&&!At()?this.page.fetchers.push(kt):(du&&pu&&wt&&wt!==1&&Yt.push({image:Qe,element:$,fetcher:kt}),Vr.push(kt))}delete c.content;let ba=c["--viv-marker-content"];if(ba){let Qe=ba instanceof X?ba.values:[ba];for(let kt of Qe)kt instanceof Pe&&kt.url&&Vr.push(Wt(new Image,kt.url))}if(this.preprocessElementStyle(c),this.applyComputedStyles($,c),this.nodeContext.inline)e||(ht($,"inline-start"),Es($)&&ht($,"clone"));else if(e){if(!ur(c.position)){let Qe=c["margin-break"],kt=this.getBreakTypeAt(this.nodeContext),At=kt!==null,Ce=kt==="auto";(Qe===y.discard&&At||Qe!==y.keep&&Ce&&!this.nodeContext.floatSide)&&cl($,"block-start")}}else{let Qe=this.nodeContext.vertical?"width":"height";rn($,Qe)&&P($,Qe,this.nodeContext.display==="table-row"?"0.01px":""),ht($,"block-start"),Es($)&&ht($,"clone"),cl($,"block-start")}j&&c["ua-list-item-count"]&&$.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=$,Vr.length?hn(Vr).then(()=>{wt>0&&this.modifyElemDimensionWithImageResolution(Yt,wt,c,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var e,n;for(let s=this.nodeContext;s!=null&&s.parent&&!s.after;s=s.parent){let o=s===this.nodeContext&&!s.viewNode?(e=s.parent.viewNode)==null?void 0:e.lastChild:(n=s.viewNode)==null?void 0:n.previousSibling;for(;o&&(ce(o,s.parent.whitespace)||Bn(o));)o=o.previousSibling;if(o)return!1}return!0}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&fr(e))}getBreakTypeAt(e){var s,o,r,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(Ee(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=(o=c.parent)==null?void 0:o.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&&Bn(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 Ee(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,o){let r=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let a=new Er(e,n,s,o,this.exprContentListener);this.nodeContext.afterIfContinues=new Jl(e,a)}}isSVGUrlAttribute(e){return zs.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,o){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"]===y.border_box&&(s["border-left-style"]!==y.none&&(l+=Ye(s["border-left-width"],this.context)),s["border-right-style"]!==y.none&&(l+=Ye(s["border-right-width"],this.context)),s["border-top-style"]!==y.none&&(c+=Ye(s["border-top-width"],this.context)),s["border-bottom-style"]!==y.none&&(c+=Ye(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||y.none,h=s["max-height"]||y.none;if(d===y.none&&h===y.none)P(u,"max-width",`${l}px`);else if(d!==y.none&&h===y.none)P(u,"width",`${l}px`);else if(d===y.none&&h!==y.none)P(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?P(u,"max-width",`${Math.min(l,Ye(f,this.context))}px`):g.unit!=="%"?P(u,"max-height",`${Math.min(c,Ye(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||he,h=s["min-height"]||he;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?P(u,"min-width",`${l}px`):f.num!==0&&g.num===0?P(u,"width",`${l}px`):f.num===0&&g.num!==0?P(u,"height",`${c}px`):f.unit!=="%"?P(u,"min-width",`${Math.max(l,Ye(f,this.context))}px`):g.unit!=="%"?P(u,"min-height",`${Math.max(c,Ye(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){Je("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 o={},r=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,o),!this.processRepeatOnBreak(o))continue;if(this.nodeContext.formattingContext instanceof xn&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new xn(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==y.none&&((n===y.auto||W(n))&&(e.display===y.table_header_group?n=y.header:e.display===y.table_footer_group?n=y.footer:n=y.none),n&&n!==y.none)?n.toString():null}createTextNodeView(){let e=L("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=Ad(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=L("preprocessTextContent"),o=Je("PREPROCESS_TEXT_CONTENT"),r=0;return s.loop(()=>r>=o.length?T(!1):o[r++](this.nodeContext,n).thenAsync(a=>(n=a,T(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Kg(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=L("createNodeView"),o,r=!0;return this.sourceNode.nodeType==1?o=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,o=T(!0)):o=this.createTextNodeView(),o.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&&en(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;this.nodeContext.pluginProps.nestedFootnoteDetached&&(d=this.viewRoot),d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&ce(this.viewNode))&&!d.hasChildNodes()&&Ed(d).includes("block-start")&&ht(d,"text-start"),d.appendChild(this.viewNode),mm(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,o=e.parent,r,a,l=s.subShadow||s.parentShadow;s.subShadow?(r=s.subShadow.root,a=s.subShadow.type,a==gt.ROOTLESS&&(r=r.firstChild)):(r=s.owner.firstChild,a=gt.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 Qn(r,o,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,this.processShadowContent(u)}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=gt.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 o=e.nodeShadow.root;if(e.nodeShadow.type==gt.ROOTLESS&&(o=o.firstChild),o){let r=new Qn(o,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 Qn(s,e,n));if(e.sourceNode.nodeType!=1){let o=Ad(e.preprocessedTextContent);n+=o.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}findImmediateFootnoteCallSibling(e){let n=this.xmldoc.getElementOffset(e.sourceNode),s=e.viewNode;if(!s)return null;let o=s.previousSibling;for(;o;){if(o.nodeType===Node.TEXT_NODE){if(o.textContent.trim().length===0){o=o.previousSibling;continue}return null}if(o.nodeType===Node.ELEMENT_NODE){let r=o;return en(r)==="footnote-call"&&r.getAttribute(zs.FOOTNOTE_CALL_OWNER_ATTR)===n.toString()?r:null}return null}return null}isSemanticFootnoteElement(e){let n=e.sourceNode;return n instanceof Element&&Hs(n)}insertFootnoteCall(e){var l,c;let n=L("insertFootnoteCall"),s=yo.createElementNS("http://www.w3.org/1999/xhtml","span");vr(s,"footnote-call");let o=this.xmldoc.getElementOffset(e.sourceNode);s.setAttribute(zs.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let r=new Qn(s,e.parent,e.boxOffset);r.inline=!0;let a=new Er(e.sourceNode,this.styler.getStyle(e.sourceNode,!1),this.styler,this.context,this.exprContentListener);return r.shadowContext=new Ps(e.sourceNode,s,null,((l=e.parent)==null?void 0:l.shadowContext)||null,null,gt.ROOTLESS,a),r.shadowSibling=e,e.boxOffset++,(c=e.viewNode)!=null&&c.parentNode&&e.viewNode.parentNode.removeChild(e.viewNode),this.setCurrent(r,!0,!1).then(u=>{if(u&&s.hasChildNodes())n.finish(r);else{let d=r.modify();d.after=!0,r.viewNode||(d.inline=!0),n.finish(d)}}),n.result()}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return T(s);let o=L("nextInTree");return this.setCurrent(s,!0,n).then(r=>{if((!s.viewNode||!r)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),s.floatSide==="footnote"&&!(this.isFootnote&&!s.parent)&&!s.after&&!s.pluginProps.footnoteCallProcessed&&!s.shadowContext&&!this.isSemanticFootnoteElement(s)){let a=this.findImmediateFootnoteCallSibling(s);a!=null&&a.parentNode&&a.parentNode.removeChild(a),this.isFootnote&&s.parent&&(s.pluginProps.nestedFootnoteDetached=1),s.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(s).then(l=>{this.dispatchEvent({type:"nextInTree",nodeContext:l}),o.finish(l)});return}this.dispatchEvent({type:"nextInTree",nodeContext:s}),o.finish(s)}),o.result()}addImageFetchers(e){if(e instanceof Se){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof Pe){let n=e.url;this.page.fetchers.push(Wt(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let o=n.position===y.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(Ou);let l,c;for(let f of a){if(ES[f])continue;let g=n[f];if(!(!g||g===G&&!Vt(f))){if(g=g.visit(new Qa(this.xmldoc.url,this.documentURLTransformer)),g instanceof k)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new k(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new k(g.num*m,"px"))}else Ua(g.unit)&&(g=Ga(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof k&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new Pn(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),em[f]||o&&tm[f]){this.page.delayedItems.push(new ws(e,f,g));continue}r&&this.page.pageAreaElement&&rs(f)?(P(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()),f!=="writing-mode"&&f!=="direction"&&P(this.viewport.layoutBox,f,g.toString())):P(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 o=((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=o?this.parsePlusLayoutUnitAdj(o.lineHeight):this.context.rootLineHeight;if(e==="line-height"||e==="font-size")return r;let a=null;if(s)if(s instanceof Ue||s instanceof k&&(s.unit==="em"||s.unit==="%"))a=s instanceof k&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof k&&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 k))return null;let g=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(n instanceof k){let m=jl(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,o=s?this.parsePlusLayoutUnitAdj(s.fontSize):this.context.rootFontSize;if(e==="font-size"||n==null)return o;if(n instanceof k){let c=jl(n,o,this.context).num;if(typeof c=="number"&&!isNaN(c))return c}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let o=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(o,!1),l=lt(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;at(u)&&(u.visit(new Ln(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=L("peelOff"),o=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===o;)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 Qn(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){var c;let o={},r=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let u=lt(this.cascadedPageStyle,ra);u&&u.area&&(a=u.area)}let l=lt(a,"_pseudos");if(e=this.computeStyle(e,n,a,o),l&&l.before){let u=l.before,d=!!ne(u,"display"),h={},f=this.createElement("http://www.w3.org/1999/xhtml","span");vr(f,"before"),s.appendChild(f),this.computeStyle(e,n,u,h),d||(h.display=y.block);let g=ne(u,"content");if(g){let C=((c=this.sourceNode)==null?void 0:c.nodeType)===1?this.sourceNode:this.xmldoc.root;h.content=g.filterValue(new Vs(this.styler.cascade,C,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let m=h.content;if(at(m)){m.visit(new Ln(f,this.context,m,this.exprContentListener));let C=f.querySelectorAll("img[src]");for(let b=0;b<C.length;b++){let N=C[b],S=N.getAttribute("src");if(!S)continue;let E=Wt(N,S);r.push(E),this.page.fetchers.push(E)}let x=f.getAttribute("src");if(x){let b=f.querySelector("img");b||(b=this.document.createElement("img"),b.setAttribute("src",x),f.appendChild(b));let N=Wt(b,x);r.push(N),this.page.fetchers.push(N)}}delete h.content,this.applyComputedStyles(f,h)}return delete o.content,this.applyComputedStyles(s,o),r.length?hn(r).thenReturn(e):T(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=ne(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!Et(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let o=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(ht(u,"inline-end"),Es(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;ht(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(rn(u,d)&&P(u,d,""),ht(u,"block-end"),!o++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?vd(f,["block-start","text-start","block-end","text-end","justify"]):(ht(u,"text-end"),ht(u,"justify")):ht(u,"text-end")}else ht(u,"text-end")}Es(u)&&ht(u,"clone"),cl(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),o=parseFloat(n.borderInlineEndWidth),r=-(s+o);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"||Tn[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(Vn)){let u=r.previousElementSibling;return u&&(u.nextSibling===r||u.nextSibling===r.previousSibling&&ce(u.nextSibling))?n(u):!1}return!(!a||Et(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 o=e.ownerDocument.createElement("span");o.className="viv-anonymous-block";for(let r=s.nextSibling,a=null;r;r=a)a=r.nextSibling,o.appendChild(r);return e.appendChild(o),o}convertLengthToPx(e,n,s){let o=e.num,r=e.unit;if(ng(r)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,Xl(e,l,this.context).num}else{let a=this.context.queryUnitSize(r,!1);return a?o*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,o=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&en(s)===en(o)}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,o)=>{let r=n.steps[o];return this.isSameNodePositionStep(s,r)})}isPseudoelement(e){return!!en(e)}};p(zs,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),p(zs,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var jc=zs,ES={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},Yc=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}},us=class{constructor(t,e,n,s,o,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=o||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")&&(P(this.root,"--viv-outputPixelRatio",`${n}`),P(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),Fo){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&&P(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=o||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||!o&&d)&&(this.width=u.width),(!this.height||!r&&d)&&(this.height=u.height)}resetZoom(){P(this.outerZoomBox,"width",""),P(this.outerZoomBox,"height",""),P(this.contentContainer,"width",""),P(this.contentContainer,"height",""),P(this.contentContainer,"transform","")}zoom(t,e,n){P(this.root,"--viv-outputScale",`${n}`),P(this.outerZoomBox,"width",`${t*n}px`),P(this.outerZoomBox,"height",`${e*n}px`),P(this.contentContainer,"width",`${t}px`),P(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var ua=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,o=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":o=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=o,this.last=this.root,this.last.setAttribute(Ut,"0")}doc(){return new Zc([this.document])}getElementOffset(t){let e=t.getAttribute(Ut);if(e)return parseInt(e,10);let n=this.lastOffset,s=this.last;for(;s!=t;){let o=s.firstChild;if(!o){for(;o=s.nextSibling,!o;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=o,o.nodeType==1?(o.setAttribute(Ut,n.toString()),++n):n+=o.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,o=t,r=null;if(o.nodeType==1){if(!n)return this.getElementOffset(o)}else{if(s=e,r=o.previousSibling,!r)return o=o.parentNode,s+=1,this.getElementOffset(o)+s;o=r}for(;;){for(;o.lastChild;)o=o.lastChild;if(o.nodeType==1)break;if(s+=o.textContent.length,r=o.previousSibling,!r){o=o.parentNode;break}o=r}return s+=1,this.getElementOffset(o)+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=Rt(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,o=n,r=o.firstChild||o.nextSibling,a=null;for(;;){if(r){if(r.nodeType==1||(o=r,a=o,s+=r.textContent.length,s>t&&!/^\s*$/.test(r.textContent)))break}else if(o=o.parentNode,!o)break;r=o.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}},Tf=(o=>(o.TEXT_HTML="text/html",o.TEXT_XML="text/xml",o.APPLICATION_XML="application/xml",o.APPLICATION_XHTML_XML="application/xhtml+xml",o.IMAGE_SVG_XML="image/svg+xml",o))(Tf||{});function Kc(i,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(i,t)}catch(o){}if(s){let o=s.documentElement,r="parsererror";if(o.localName===r)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===r)return null}else return null;return s}function vS(i){let t=i.contentType;if(t){let n=Object.keys(Tf);for(let s=0;s<n.length;s++)if(Tf[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=i.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 Pf(i,t){let e=i.responseXML;if(!e){let s=new DOMParser,o=i.responseText;if(o){let r=vS(i);if(e=Kc(o,r||"application/xml",s),e&&!r){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=Kc(o,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=Kc(o,"image/svg+xml",s))}e||(e=Kc(o,"text/html",s))}}let n=e?new ua(t,i.url,e):null;return T(n)}function qC(){return new ro(Pf,"document")}var wf=class i{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new i(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new i(n=>{if(!this.check(n))return!1;let s=new Zc([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},kf=new wf(i=>!0),Zc=class i{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 i(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 i(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 NS=new An(()=>{let i=L("uaStylesheetBase"),t=Kh(),e=ee("user-agent-base.css",on),n=new os(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Im(n.cascade),ll(pd,n,e,null,null).thenFinish(i),i.result()},"uaStylesheetBaseFetcher");function TS(){return NS.get()}var Af=class extends bo{constructor(e,n,s,o,r,a){super(e,n,null,s,o,"counter-style");this.counterStyleName=r;this.counterStyles=a}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||O.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Rf=class{constructor(t,e,n,s,o,r,a,l,c,u,d){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=o;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 te(this.pageScope,function(){let h=this;return h.pageNumberOffset+h.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new te(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 o=new Bo(this.rootScope,t,e,n),r=Lm(o,this.viewportProps),a=r.width,l=r.height,c=r["text-zoom"],u=1;if(a&&l||c){let d=ot.em;if((c?c.evaluate(o,"text-zoom"):null)===y.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Ye(a.evaluate(o,"width"),o),g=Ye(l.evaluate(o,"height"),o);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}}};function ZC(i){let t=new Map,e=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&e(n.shadowSibling)};for(let n in i.flowPositions){let s=i.flowPositions[n];for(let o of s.positions){let r=o.chunkPosition.primary;for(let a of r.steps)e(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let l of a.steps)e(l)}}return t}function QC(i){for(let[t,e]of i)e!==void 0&&t.restoreState(e)}var Us=class extends Bo{constructor(e,n,s,o,r,a,l,c,u,d,h,f,g,m){super(e.rootScope,o.width,o.height,o.fontSize);this.style=e;this.xmldoc=n;this.viewport=o;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,"currentCascadedPageStyle",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);p(this,"semanticFootnoteFirstRefOffsets",new Map);p(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1});p(this,"pageGroupPageCounts",Object.create(null));p(this,"currentPageGroupDocument",null);this.lang=n.lang||s,this.faces=new Fc(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new In(null,null,null,null,null,null,null),this.pageProgression=g||null,this.isVersoFirstPage=!!m;for(let C in e.flowProps){let x=e.flowProps[C],b=ne(x,"flow-consume");b&&(b.evaluate(this,"flow-consume")==y.all?this.primaryFlows[C]=!0:delete this.primaryFlows[C])}}init(){let e=L("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 Xi(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 o=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=xf(o)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Mc(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,o),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new zc(a,this.style.pageScope,this.rootPageBoxInstance,this,o);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=RC(u.properties,this),h=new Qi(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{$C(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(ca(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),o=new Bo(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 Xi(e,s.cascade,s.rootScope,o,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 o=s.flowPositions[e.flowName];o||(o=new bl,s.flowPositions[e.flowName]=o);let r=rm(e.element),a=new Ot(r),l=new Cl(a,e);o.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let o=!0;class r{unknownProperty(d,h){o=!1}invalidPropertyValue(d,h){o=!1}simpleProperty(d,h,f){}}let a=new r,l=Ss(this.style.rootScope,new it(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),o):!1}evalSupportsSelector(e){let n=new Qc(null),s=new it(e+"{}",n);return new xs(Re,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 o=e.positions[s].chunkPosition.primary,r=o.steps[0].node,a=o.offsetInNode,l=o.after,c=0;for(;r.ownerDocument!=this.xmldoc.document;)c++,r=o.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(r,a,l);u<n&&(n=u)}return n}getNodePositionOffset(e){let n=e.steps[0].node,s=e.offsetInNode,o=e.after,r=0;for(;n.ownerDocument!=this.xmldoc.document;)r++,n=e.steps[r].node,o=!1,s=0;return this.xmldoc.getNodeOffset(n,s,o)}getPageStartOffset(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let r=e.flowPositions[o];if(!n&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),r=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[o]=r)),r)for(let a=0;a<r.positions.length;a++){let l=r.positions[a].chunkPosition.primary,c=this.getNodePositionOffset(l);c<s&&(s=c)}}return s}getPageStartCounterOffsets(e){let n=this.getPageStartOffset(e);if(!isFinite(n))return{counterOffset:n,changeOffset:n};let s=this.xmldoc.body||this.xmldoc.root,o=s?this.getFirstInFlowElementAtOrAfter(s,n):null,r=s?this.xmldoc.getElementOffset(s):n,a=n<=r,l=o===s&&a?this.getFirstInFlowChildElement(s):o;if(!l)return{counterOffset:n,changeOffset:n};let c=this.xmldoc.getElementOffset(l),u=n;return a&&c!==n&&(u=c),c===n&&(this.isInlineLevelElement(l)?u=Math.max(0,n-1):u=this.getDeepestFirstInFlowChildOffset(l)),{counterOffset:u,changeOffset:c}}getPageStartElement(e,n=this.getPageStartOffset(e)){if(!isFinite(n))return null;let s=this.xmldoc.body||this.xmldoc.root;if(!s)return null;let o=this.getFirstInFlowElementAtOrAfter(s,n),r=this.xmldoc.getElementOffset(s),a=n<=r;return o===s&&a?this.getFirstInFlowChildElement(s):o}isForcedPageBreakValue(e){return Ee(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let n=ne(e,"break-before");if(!n)return!1;let s=n.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(s)}getExplicitPageType(e){let n=ne(e,"page");if(!n)return null;let s=n.evaluate(this,"page").toString();return!s||s.toLowerCase()==="auto"?null:s}getPageGroupPageType(e){let n=this.styler.getStyle(e,!1);return n?this.getExplicitPageType(n):null}getPreviousInFlowSibling(e){let n=e.previousElementSibling;for(;n;){if(this.isNormalFlowElement(n))return n;n=n.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let n=this.xmldoc.getElementOffset(e),s=this.getFirstInFlowElementAtOrAfter(e,n);return s===e?this.getFirstInFlowChildElement(e):s}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,n,s){let o=this.styler.getStyle(e,!1);if(!o)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),a=this.xmldoc.body||this.xmldoc.root,l=this.xmldoc.getElementOffset(a);if(s<=l&&e===a||!this.getPreviousInFlowSibling(e)&&s===r)return!0;if(r!==s)return!1;if(this.hasForcedPageBreakBefore(o))return!0;let u=this.getPreviousInFlowSibling(e);if(!u)return!1;let d=this.styler.getStyle(u,!1);return d?this.getExplicitPageType(d)!==n:!1}updatePageGroupPageIndices(e){let n=this.pageManager.pageCascadeInstance;n.pageTypePageIndices=Object.create(null);let s=e.startSideOfFlow("body"),o=e.flowPositions.body,r=!!(o&&o.positions.length),a=Zn(s)&&!this.matchPageSide(s)&&!r,c=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!a,u=this.getPageStartOffset(e),d=this.getPageStartElement(e,u);if(!d)return;let h=d.ownerDocument,g=this.currentPageGroupDocument!==h&&c;g&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=h);let m=d;for(;m;){let C=this.getPageGroupPageType(m);if(C){let x=this.pageGroupPageCounts[C]||(this.pageGroupPageCounts[C]=new Map),b=x.get(m)||0;(b>0||c&&(g||this.shouldStartPageGroup(m,C,u)))&&(b+=1,x.set(m,b),(n.pageTypePageIndices[C]||(n.pageTypePageIndices[C]=[])).push(b))}if(m===this.xmldoc.root)break;m=m.parentElement}}getFirstInFlowElementAtOrAfter(e,n){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=n)return e;let o=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{let a=r;return this.isNormalFlowElement(a)?this.xmldoc.getElementOffset(a)<n?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return o!=null?o:null}getDeepestFirstInFlowChildOffset(e){let n=e;for(;;){let s=this.getFirstInFlowChildElement(n);if(!s)return this.xmldoc.getElementOffset(n);n=s}}getFirstInFlowChildElement(e){let n=e.firstChild;for(;n;){if(n.nodeType===Node.TEXT_NODE){if(!ce(n))return null;n=n.nextSibling;continue}if(n.nodeType!==Node.ELEMENT_NODE){n=n.nextSibling;continue}let s=n;if(this.isNormalFlowElement(s))return s;n=n.nextSibling}return null}isNormalFlowElement(e){var c,u;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===y.none)return!1;let o=(c=n==null?void 0:n.position)==null?void 0:c.evaluate(this.styler.context,"position"),r=o&&!W(o)?o:y.static;if(co(r)||ur(r))return!1;let a=(u=n==null?void 0:n.float)==null?void 0:u.evaluate(this.styler.context,"float");return(a&&!W(a)?a:y.none)===y.none}isInlineLevelElement(e){return Et(this.getDisplayValue(e))}getDisplayValue(e){var o;let n=this.styler.getStyle(e,!1),s=(o=n==null?void 0:n.display)==null?void 0:o.evaluate(this.styler.context,"display");return s&&!W(s)?s:y.inline}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let r=e.flowPositions[o];if(!n&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),r=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[o]=r)),r){let a=this.getConsumedOffset(r);a<s&&(s=a)}}return s}dumpLocation(e){O.debug("Location - page",this.currentLayoutPosition.page),O.debug(" current:",e),O.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o of s.positions)O.debug(" Chunk",`${n}:`,o.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new ye(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 o=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===o.startOffset){let r=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=Td(Be(a,r))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let o=this.rootPageBoxInstance.children,r;for(let a=0;a<o.length;a++){if(r=o[a],r.pageBox.pseudoName===Wc)continue;let l=1;r.pageBox.pseudoName===ea&&!(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===y._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 o=e.startOffset,r=n[s].forcedBreakOffsets;if(!r.length||o<r[0])return!1;let a=Rt(r.length,d=>r[d]>o)-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 gr(null)),e.flowRootFormattingContext=s.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new In(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),o=this.counterStore.currentPageCountersStack.length>0,r=u=>{var m,C;if(!o||u.floatReference!==ue.PAGE)return!1;let d=((C=(m=this.layoutPositionAtPageStart)==null?void 0:m.flowPositions)==null?void 0:C.body)||null,h=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(h)?h:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(u.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},a=L("layoutDeferredPageFloats"),l=!1,c=0;return a.loopWithFrame(u=>{if(c===s.length){u.breakLoop();return}let d=s[c++],h=d.float;if(r(h)){u.breakLoop();return}let f=new Cn().findByFloat(h),g=f.findPageFloatFragment(h,n);if(g&&g.hasFloat(h)){u.continueLoop();return}else if(n.isForbidden(h)||n.hasPrecedingFloatsDeferredToNext(h)){n.deferPageFloat(d),u.breakLoop();return}e.layoutPageFloatInner(d,f,null,g).then(m=>{if(!m){u.breakLoop();return}let C=n.parent.isInvalidated();if(C){u.breakLoop();return}else n.isInvalidated()&&!C&&(l=!0,n.validate());u.continueLoop()})}).then(()=>{l&&n.invalidate(),a.finish(!0)}),a.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 Ot(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 o=L("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){o.finish(!0);return}let r=[],a=[],l=!0;o.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,C=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(e.pageBreakType&&C?(d.chunkPosition=C,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||C)&&(d.chunkPosition=g||C,r.push(u)),s.startBreakType=Td(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)}o.finish(!0)})}),o.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new ec([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,o,r,a,l,c,u,d,h,f,g,m){let C=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,x=r.element,b=new In(c,ue.COLUMN,null,l,null,null,null),N=this.currentLayoutPosition.clone(),S=L("createAndLayoutColumn"),E;return S.loopWithFrame(v=>{let w=this.createLayoutConstraint(b);if(u>1){let A=this.viewport.document.createElement("div");if(P(A,"position","absolute"),x.appendChild(A),E=new So(A,g,this.clientLayout,w,b),E.isNonFirstColumn=a>0,E.forceNonfitting=m,E.vertical=r.vertical,E.rtl=r.rtl,E.snapHeight=r.snapHeight,E.snapWidth=r.snapWidth,r.vertical){let I=(r.rtl?u-a-1:a)*(h+d)+r.paddingTop,_=parseFloat(x.style.width);E.setHorizontalPosition(r.paddingLeft+_-r.width,r.width),E.setVerticalPosition(I,h)}else{let I=(r.rtl?u-a-1:a)*(h+d)+r.paddingLeft;E.setVerticalPosition(r.paddingTop,r.height),E.setHorizontalPosition(I,h)}E.originX=n,E.originY=s}else E=new So(x,g,this.clientLayout,w,b),E.isNonFirstColumn=!1,E.copyFrom(r);E.exclusions=C?[]:o.concat(),E.innerShape=f,b.setContainer(E),(E.vertical?E.height:E.width)>=0?this.layoutColumn(E,l).then(()=>{b.isInvalidated()||b.finish(),E.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(E.pageFloatLayoutContext.validate(),this.currentLayoutPosition=N.clone(),E.element!==x&&x.removeChild(E.element),v.continueLoop()):v.breakLoop()}):(b.finish(),v.breakLoop())}).then(()=>{S.finish(E)}),S.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof ia||n instanceof wo&&!(n instanceof zn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,o){n instanceof Hn;let r=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new In(e,ue.REGION,s,o,null,r,a)}layoutFlowColumnsWithBalancing(e,n,s,o,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,o,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 C=n.getProp(this,"column-fill")||y.balance,x=this.currentLayoutPosition.flowPositions[c];let b=rC(u,C,g,h,l,m.columns,x);return b?(f=!1,a.lock(),h.lock(),b.balanceColumns(m).thenAsync(N=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=N.position,T(N.columns)))):T(m.columns)})}layoutFlowColumns(e,n,s,o,r,a,l,c,u,d,h){let f=L("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=ZC(this.currentLayoutPosition),C=n.getPropAsNumber(this,"column-gap"),x=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,b=n.getActiveRegions(this),N=n.getProp(this,"shape-inside"),S=Ja(N,0,0,c.width,c.height,this),E=new jc(u,this,this.viewport,this.styler,b,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),v=0,w=null,A=[];return f.loopWithFrame(I=>{this.createAndLayoutColumn(n,s,o,r,c,v++,u,l,d,C,x,S,E,h).then(_=>{if(a.isInvalidated()){A=null,I.breakLoop();return}if((!!_.pageBreakType&&_.pageBreakType!=="column"||v===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){v=0,this.currentLayoutPosition=g.clone(),QC(m),l.validate(),l.isLocked()?(A=null,I.breakLoop()):I.continueLoop();return}w=_,A[v-1]=w,w.pageBreakType&&w.pageBreakType!="column"&&(v=d,w.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),v<d?I.continueLoop():I.breakLoop()})}).then(()=>{f.finish(A)}),f.result()}layoutContainer(e,n,s,o,r,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==y._true)return T(!0);let u=L("layoutContainer"),h=n.getProp(this,"wrap-flow")===y.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof aa?"complementary":"presentation";let m=n.getProp(this,"position");P(g,"position",m?m.name:"absolute");let C=n instanceof zn;n instanceof Hn?s.appendChild(g):s.insertBefore(g,s.firstChild);let b=new lr(g);b.vertical=n.vertical,b.rtl=n.rtl,b.borderBoxSizing=n.borderBoxSizing,b.exclusions=a,n.prepareContainer(this,b,e,this.faces,this.clientLayout),n instanceof zn&&(b.width<=0||b.height<=0)&&O.warn("Negative or zero page area size"),b.originX=o,b.originY=r,o+=b.left+b.marginLeft+b.borderLeft,r+=b.top+b.marginTop+b.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,b);let N,S=!1;if(!f||!f.isIdent()){let E=[],v=n.getProp(this,"content");if(v instanceof D&&v.expr instanceof te&&v.expr.str.startsWith("running-element-"))v.visit(new Ln(g,this,v,this.counterStore.getExprContentListener()));else if(at(v)){let w="span";v instanceof Pe&&(w="img");let A=this.viewport.document.createElement(w);v.visit(new Ln(A,this,v,this.counterStore.getExprContentListener())),g.appendChild(A),w=="img"&&n.transferSingleUriContentProps(this,A,this.faces),n.transferContentProps(this,b,e,this.faces);let I=A.querySelectorAll("img[src]");for(let Y=0;Y<I.length;Y++){let Q=I[Y],me=Q.getAttribute("src");if(!me)continue;let Te=Wt(Q,me);E.push(Te),e.fetchers.push(Te)}let _=A.getAttribute("src");if(_){let Y=A.querySelector("img");Y||(Y=A);let Q=Wt(Y,_);E.push(Q),e.fetchers.push(Q)}w=="span"&&Wm(A,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),S=!0);S||n.finishContainer(this,b,e,null,1,this.clientLayout,this.faces),N=E.length?hn(E).thenReturn(!0):T(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,b,e,null,1,this.clientLayout,this.faces),N=T(!0);else{let E=L("layoutContainer.inner"),v=f.toString(),w=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,o,r,a,l,b,v,w).then(A=>{if(!l.isInvalidated()){let I=A[0];I.element===g&&(b=I),b.computedBlockSize=Math.max.apply(null,A.map(Y=>Y.computedBlockSize)),n.finishContainer(this,b,e,I,w,this.clientLayout,this.faces);let _=this.currentLayoutPosition.flowPositions[v];_&&_.breakAfter==="region"&&(_.breakAfter=null)}E.finish(!0)}),N=E.result()}return N.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(b.computedBlockSize)>0){if(!S&&!h){let v=n.getProp(this,"shape-outside"),w=b.getOuterShape(v,this);a.push(w)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let E=C?0:n.children.length-1;u.loop(()=>{for(;E>=0&&E<n.children.length;){let v=n.children[C?E++:E--],w=this.layoutContainer(e,v,g,o,r,a,l);if(w.isPending())return w.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 o=s.positions.length-1;o>=0;o--){let r=s.positions[o];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&s.positions.splice(o,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let r=s.positions[o];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 m,C,x,b;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new yl,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let o=1e4;if(n.page>o)throw new Error(`Too many pages generated (over ${o} pages)`);let r=n.startSideOfFlow("body");n.isBlankPage=Zn(r)&&this.matchPageSide(r),e.isBlankPage=n.isBlankPage,n.page++,e.pageType==null&&(e.pageType=(C=(m=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?m:n.page===1?this.resolveFirstPageType():null)!=null?C:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(n),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let a=ZC(n),l=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=l,this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!s){let N=new ye(this.style.pageScope,"left-page");e.side=N.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(l);if(!c)return T(null);let u=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===fs),e.setAutoPageHeight(c.pageBox.specified.height.value===gs);let{counterOffset:N,changeOffset:S}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(N)||(N=this.lookupOffset,S=this.lookupOffset),isFinite(N)&&this.styler.styleUntil(N,0);let E=this.styler.getCounterSnapshotAtOffset(N),v=S===N?E:this.styler.getCounterSnapshotAtOffset(S);E||(E=this.styler.getLastCounterSnapshot()),v||(v=E),this.counterStore.setCurrentPageDocCounters((x=E==null?void 0:E.counters)!=null?x:null,(b=v==null?void 0:v.changes)!=null?b:null,v==null?void 0:v.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let w=Sf(ca(l),this);this.setPageSizeAndBleed(w,e),UC(l,w,e,this),u=w.bleedOffset+w.bleed}let d=!s&&c.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=d!=y.horizontal_tb;let h=c.getProp(this,"direction")||y.ltr,f=new In(this.rootPageFloatLayoutContext,ue.PAGE,null,null,null,d,h),g=L("layoutNextPage");return g.loopWithFrame(N=>{this.layoutContainer(e,c,e.bleedBox,u,u,[],f).then(()=>{if(f.isInvalidated()||f.finish(),f.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),QC(a),f.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);N.continueLoop()}else N.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(S=>{let E=n.flowPositions[S],v=E.breakAfter;v&&(v==="page"||!this.matchPageSide(v))&&(E.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let N=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(N,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),g.finish(n)}),g.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`}},Lf=class i extends os{constructor(e,n,s,o){super(e.rootScope,e,n,s,o,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let o=new Ar(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Uc(o.scope,this.masterHandler,o,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=bt(this.scope,this.condition,n)),this.masterHandler.pushHandler(new i(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new zl(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new bo(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(e){this.masterHandler.pushHandler(new Af(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 bo(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new bo(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=yn(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new la(this.scope,this.owner,this.masterHandler.validatorSet,n))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new Gc(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(os.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",R(e)),this.endRule();let n=new i(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},Qc=class extends sl{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 dc);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new qs(null),this.pageScope=new qs(this.rootScope),this.rootBox=new Bc(this.rootScope),this.cascadeParserHandler=new Lf(this,null,null,null),this.slave=this.cascadeParserHandler}};function wS(i,t){return t.parseOPSResource(i)}var Jc=class extends ro{constructor(e){super(wS,"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=L("OPSDocStore.init");return this.validatorSet=Kh(),TS().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=ee(Wn(n),vn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=ee(Wn(n),vn)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=L("OPSDocStore.load"),s=e.url,o=s.endsWith("?viv-toc-box");return Pf(e,this).then(r=>{var f;if(!r){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=Je("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](r.document)}catch(C){O.warn("Error during single document preprocessing:",C)}}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],C=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),x=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),b=m.getAttribute("action"),N=m.getAttribute("ref");C&&x&&b&&N&&a.push({observer:C,event:x,action:b,ref:N})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:ee("user-agent-page.css",on),text:dd,flavor:"UA",classes:null,media:null}),c.push({url:ee("user-agent-counter-styles.css",on),text:gd,flavor:"UA",classes:null,media:null}),o)c.push({url:ee("user-agent-toc.css",on),text:hd,flavor:"UA",classes:null,media:null});else{let g=r.document.querySelectorAll("style, link, meta");for(let m of g){let C=m.namespaceURI,x=m.localName;if(C=="http://www.w3.org/1999/xhtml")if(x=="style"){let b=m.getAttribute("class"),N=m.getAttribute("media"),S=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:S?b:null,media:N})}else if(x=="link"){let b=m.getAttribute("href"),N=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),S=m.getAttribute("class"),E=m.getAttribute("media");if(b&&(N!=null&&N.includes("stylesheet"))&&(!N.includes("alternate")||S)){let v=ee(b,s),w=m.getAttribute("title");c.push({url:v,text:null,classes:w?S:null,media:E,flavor:"Author"})}}else x=="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 An(()=>{let g=L("fetchStylesheet"),m=0,C=new Qc(this.validatorSet);return g.loop(()=>{if(m<c.length){let x=c[m++];return C.startStylesheet(x.flavor),x.text!==null?ll(x.text,C,x.url,x.classes,x.media).thenReturn(!0):bd(x.url,C,x.classes,x.media)}return T(!1)}).then(()=>{let x=C.cascadeParserHandler.finish();d=new Rf(this,C.rootScope,C.pageScope,x,C.rootBox,C.fontFaces,C.footnoteProps,C.flowProps,C.viewportProps,C.pageProps,C.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 da="\u25B8",eb="\u25BE",PS="\u25B9";function tu(i){let t=Array.from(i.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(i.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of i.querySelectorAll(e)){if(t.find(o=>o.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 tb(i){let t=tu(i),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var eu=class{constructor(t,e,n,s,o,r,a,l,c,u,d){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=o;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=_a(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;rn(s,"height","auto")!="auto"&&(P(s,"height","auto"),this.setAutoHeight(s,e)),rn(s,"position","static")=="absolute"&&(P(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,o)=>{let r=o.behavior;if(r)switch(r.toString()){case"toc-node-anchor":o.color=y.inherit,o["text-decoration"]=y.none;break;case"toc-node":o.display=y.block,o.margin=he,o.padding=he,o["padding-inline-start"]=new k(1.25,"em");break;case"toc-node-first-child":o.display=y.inline_block,o.margin=new k(.2,"em"),o["vertical-align"]=y.top,o.color=y.inherit,o["text-decoration"]=y.none;break;case"toc-container":o.padding=he;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return e(n,s,o);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!=da&&(u.textContent=da,P(u,"cursor","pointer"),u.addEventListener("click",kS,!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=PS,P(u,"margin","0.2em 0 0 -1em"),P(u,"margin-inline-start","-1em"),P(u,"margin-inline-end","0"),P(u,"display","inline-block"),P(u,"width","1em"),P(u,"text-align","center"),P(u,"vertical-align","top"),P(u,"cursor","default"),P(u,"font-family","Menlo,sans-serif"),c.appendChild(u),P(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){P(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,o){if(this.page)return T(this.page);let r=L("showTOC"),a=new ar(t,t);this.page=a;let l=Ht(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of tu(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,o);e=new us(e.window,d.fontSize,0,t,d.width,d.height);let h=this.makeCustomRenderer(c),f=new Us(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 o=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(o).map(e)}function e(s){let o=new URL(s.href),[,r]=o.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 kS(i){let t=i.target,e=t.textContent==da;t.textContent=e?eb:da;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 o=s,r=o.getAttribute("data-adapt-class");if(r==="toc-container"){if(o.setAttribute("aria-hidden",e?"false":"true"),o.firstChild){s=o.firstChild;continue}}else if(r==="toc-node"&&(o.style.height=e?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=e?0:-1),o.children.length>=3&&(o.children[0].tabIndex=e?0:-1,!e))){let a=o.children[0];if(a.textContent==eb){a.textContent=da,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),s=o.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}i.stopPropagation()}function nu(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function RS(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=new Map(i[e])}),t}var ha=class extends Jc{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=qC(),this.jsonStore=Rg()}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)}loadWebPubManifest(e,n){this.loadAsJSON(e,!0).then(s=>{if(!s){this.reportLoadError(e),n.finish(null);return}let o=new Ao(this,e);o.initWithWebPubManifest(s,void 0,e).then(()=>{n.finish(o)})})}loadPubDoc(e){let n=L("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,s,o]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(s,o).thenFinish(n)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,n):/\.(x?html?|xht)(?:[#?]|$)/i.test(e)?this.loadWebPub(e).then(s=>{if(s){n.finish(s);return}this.reportLoadError(e),n.finish(null)}):io(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}O.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"){let[,o,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(o,r).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"?this.loadWebPubManifest(e,n):this.loadWebPub(e).then(o=>{if(o){n.finish(o);return}this.loadEPUBDoc(e).then(r=>{if(r){n.finish(r);return}this.reportLoadError(e),n.finish(null)})})});return n.result()}loadEPUBDoc(e){let n=L("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(o=>{if(o){let r=o.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,o=this.opfByURL[s];if(o)return T(o);let r=L("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(o=new Ao(this,e),this.opfByURL[s]=o,this.primaryOPFByEPubURL[e]=o,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{o.initWithXMLDoc(a,l).then(()=>{r.finish(o)})}):o.initWithXMLDoc(a,null).then(()=>{r.finish(o)})):this.reportLoadError(s)}),r.result()}loadWebPub(e){let n=L("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e),n.finish(null);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let o=s.document,r=new Ao(this,e),a=o.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=Vo(o.getElementById(l.substr(1)).textContent);r.initWithWebPubManifest(c,o).then(()=>{n.finish(r)})}else{let c=ee(a.getAttribute("href"),e);this.loadAsJSON(c,!0,`Failed to fetch Publication Manifest ${c}`).then(u=>{r.initWithWebPubManifest(u,o,c).then(()=>{n.finish(r)})})}}else r.initWithWebPubManifest({},o).then(()=>{r.toc&&r.toc.src===s.url&&tu(o).length===0&&(r.toc=null),n.finish(r)})}}),n.result()}addDocument(e,n){let s=L("EPUBDocStore.load"),o=Ht(e);return(this.documents[o]=this.parseOPSResource({status:200,statusText:"",url:o,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=o=>o.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let o=n(e);return!(o===n(vn)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===o)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?O.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&vn.startsWith("https:")?O.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?O.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):O.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=Ht(e),s=this.documents[n];if(s)return s.isPending()?s:T(s.get());{let o=L("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(r=>{r?o.finish(r):this.reportLoadError(n)}),o.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},o;for(;(o=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(o[0].length),s[o[1]]=o[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""}},ou=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=Yf}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=ee(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=Zf(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 LS(i){return i.id}function IS(i){return t=>{let e=L("deobfuscator");return FS("SHA-1",i).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);kg(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(md([a,o]))})}),e.result()}}function FS(i,t){let e=L("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(i,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var Gs={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"},pa="http://idpf.org/epub/vocab/package/meta/#",ze={language:`${Gs.dcterms}language`,title:`${Gs.dcterms}title`,creator:`${Gs.dcterms}creator`,layout:`${Gs.rendition}layout`,titleType:`${pa}title-type`,displaySeq:`${pa}display-seq`,alternateScript:`${pa}alternate-script`,role:`${pa}role`};function VS(i,t){let e={};return(n,s)=>{var d,h,f,g,m,C;let o,r,a=n.r||e,l=s.r||e;if(i==ze.title&&(o=((d=a[ze.titleType])==null?void 0:d[0].v)=="main",r=((h=l[ze.titleType])==null?void 0:h[0].v)=="main",o!=r))return o?-1:1;let c=parseInt((f=a[ze.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[ze.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:i!=ze.language&&t&&(o=((m=a[ze.language]||a[ze.alternateScript])==null?void 0:m[0].v)==t,r=((C=l[ze.language]||l[ze.alternateScript])==null?void 0:C[0].v)==t,o!=r)?o?-1:1:n.o-s.o}}function BS(i,t){let e;if(!t)e=Gs;else{e={};for(let h in Gs)e[h]=Gs[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]]:pa;if(f)return f+h[3]}}return null},s=1,o=i.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:Gs.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=Ta(o,d=>d.refines),a=d=>Qf(d,(h,f)=>h.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let C=r[`#${g.id}`]||[];if(C.length||g.lang||g.role){g.lang&&C.push({name:ze.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&C.push({name:ze.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=Ta(C,b=>b.name);m.r=a(x)}return m})),l=a(Ta(o,d=>d.refines?null:d.name)),c=null;l[ze.language]&&(c=l[ze.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(VS(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 i=window.MathJax;return i?i.Hub:null}var nb={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},If="viv-id-",Ao=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,o){let r=o+(s?`#${s}`:"");return If+wu(r,":")}transformURL(s,o){let r=s.match(/^([^#]*)#?(.*)$/);if(r){let a=r[1]||o.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(If)===0&&(s=s.substring(If.length));let r=Kf(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=ee("",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 o={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new ou,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!nb[u.mediaType]&&(o[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=Pu(this.items,LS),this.itemMapByPath=Pu(this.items,c=>this.getPathFromURL(c.src));for(let c in o){let u=c;for(;;){let d=this.itemMap[o[u]];if(!d)break;if(nb[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=gu(r));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(kf.withChild("EncryptionMethod",kf.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=BS(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[ze.language]&&(this.lang=this.metadata[ze.language][0].v),this.metadata[ze.layout]&&(this.prePaginated=this.metadata[ze.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=IS(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=L("countEPages");return s.loopWithFrame(o=>{if(n===this.spine.length){o.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),o.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new ua(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let o=new ou;o.initWithParam(s),o.id;let r=n.document.createElement("itemref");r.setAttribute("idref",o.id),n.root.appendChild(r),o.itemRefElement=r,this.itemMap[o.id]=o;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=o,this.items.push(o)}),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[ze.title]=(Array.isArray(s)?s:[s]).map(C=>{var x;return{v:(x=C.value)!=null?x:C}}));let o=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(C=>C.content);o&&o.length!==0&&(this.metadata[ze.creator]=(Array.isArray(o)?o:[o]).map(C=>{var x;return{v:(x=C.name)!=null?x:C}}));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[ze.language]=(Array.isArray(r)?r:[r]).map(C=>({v:C})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let C of tb(e)){let x=C.getAttribute("href");if(/^(https?:)?\/\//.test(x)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(x))continue;let b=Ht(ee(x,this.pubURL)),N=this.getPathFromURL(b),S=N!==null?encodeURI(N):b;t.readingOrder.indexOf(S)==-1&&t.readingOrder.push(S)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(C=>{C instanceof Array&&C.forEach(x=>{let b=C===t.readingOrder,N=typeof x=="string"?x:x.url||x.href,S=typeof x=="string"?"":x.encodingFormat||x.href&&x.type||"";if(b||S==="text/html"||S==="application/xhtml+xml"||!S&&x.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(N)){let E=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,v={url:ee(Wn(N),E),index:c++,startPage:null,skipPagesBefore:null};x.rel==="contents"&&u===-1&&(u=v.index),l.push(v)}})});let d=L("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var x,b;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(x=this.items)==null?void 0:x[0]:this.itemMapByPath[a]);let C=(b=t.readingOrder)==null?void 0:b.length;C&&C<this.items.length&&this.items.splice(C),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=L("getCFI");return this.store.load(n.src).then(o=>{let r=o.getNodeByOffset(e),a=null;if(r){let l=o.getNodeOffset(r,0,!1),c=e-l,u=new Qr;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 Kn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new Qr;n.fromString(t);let s;if(this.opfXML){let o=n.navigate(this.opfXML.document);if(o.node.nodeType!=1||o.after||!o.ref){e.finish(null);return}let r=o.node,a=r.getAttribute("idref");if(r.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=o.ref}else s=this.spine[0];this.store.load(s.src).then(o=>{let r=n.navigate(o.document),a=o.getNodeOffset(r.node,r.offset,r.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{O.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Kn("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let o=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);o==-1&&(o=this.spine.length-1);let r=this.spine[o];(!r||r.epageCount==0)&&(r=this.spine[--o]);let a=Math.floor(t-r.epage);e.finish({spineIndex:o,offsetInItem:-1,pageIndex:a});return}let n=Rt(this.spine.length,o=>{let r=this.spine[o];return r.epage+r.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(o=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let r=0;if(t>0){let a=o.getTotalOffset();r=Math.round(a*t/s.epageCount),r==a&&r--}e.finish({spineIndex:n,offsetInItem:r,pageIndex:-1})})},(e,n)=>{O.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=L("getEPage");return this.store.load(e.src).then(s=>{let o=s.getTotalOffset(),r=Math.min(o,t.offsetInItem);n.finish(e.epage+r*e.epageCount/o)}),n.result()}},su=(i,t)=>({page:i,position:{spineIndex:i.spineIndex,pageIndex:t,offsetInItem:i.offset}}),ru=class{constructor(t,e,n,s,o,r){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=o;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");p(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0});this.pref=_a(s),this.clientLayout=new Yc(e),this.counterStore=new el(t.documentURLTransformer),this.cmykStore=new Kr,r!=null&&r.length&&this.cmykStore.registerCmykReserveMap(r)}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=L("waitForPreviousSpines");return n.loopWithFrame(s=>{let o=!0;for(let r=0;r<t;r++){let a=this.spineItems[r];if(!a||!a.complete){o=!1;break}}o?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 o=this.opf.spine[t.item.spineIndex-1];t.item.epage=o.epage+o.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((o,r)=>o+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 o=null;if(n>0)o=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]){o=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,o)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}getRenderedPageCount(){let t=0;for(let e of this.spineItems)e&&(t+=e.pages.length);return t}markSpineItemCompleteIfReady(t){t.complete=t.layoutPositions.length===t.pages.length,t.complete&&t.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(t){let e=t.item.spineIndex,n=this.paginationProgress.totalOffsetsBySpine[e];return n==null&&(n=t.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[e]=n),n}getTotalOffsetAll(){let t=0;for(let e of this.spineItems)e&&(t+=this.getTotalOffsetForViewItem(e));return t}getRenderedOffsetAll(){var s;let t=0,e=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let a=(s=n[o])!=null?s:0;t+=Math.min(r,a)}return t}reportPaginationProgress(t,e){let n=Je("PAGINATION_PROGRESS");if(!n.length)return;let s=t.item.spineIndex,o=this.getTotalOffsetForViewItem(t),r=o;e&&(r=t.instance.getPosition(e,!0)),r<0&&(r=0),r>o&&(r=o);let a=this.paginationProgress.renderedOffsetsBySpine[s];a!=null&&r<a&&(r=a),this.paginationProgress.renderedOffsetsBySpine[s]=r;let l=this.getRenderedPageCount(),c=this.getTotalOffsetAll(),u=this.getRenderedOffsetAll(),d=c>0?u/c:0;d<this.paginationProgress.lastReportedFraction?d=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=d,l>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=l);let h={fraction:d,pages:this.paginationProgress.lastReportedPages};for(let f of n)try{f(h)}catch(g){O.warn(g)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(t){return!!(t!=null&&t.pageType)&&t.pageType!==""}hasPageTypeBoundaryBetween(t,e){return(t==null?void 0:t.pageType)!=null&&(e==null?void 0:e.pageType)!=null&&t.pageType!==e.pageType}resolvePageTypeForRenderSlot(t,e,n,s,o,r,a){let l=!1;if(s){let u=this.hasPageTypeBoundaryBetween(o,s),d=(r==null?void 0:r.pageType)===s.pageType,h=s.offset!==e.offset,f=a&&!h&&n>0&&u&&d;if(l=s.pageType!=null&&(f||n===0||s.pageType===(o==null?void 0:o.pageType)),e.pageType=l?s.pageType:null,!a&&!l){let m=n>1&&u&&d?o.pageType:null;t.instance.styler.cascade.currentPageType=m,t.instance.pageManager.pageCascadeInstance.currentPageType=m}}!a&&this.hasNonEmptyPageType(o)&&this.hasNonEmptyPageType(r)&&o.pageType!==r.pageType&&(!s||s.pageType==null)&&(e.pageType=o.pageType)}evaluateNextPageRelayout(t,e,n,s,o){if(!t||e&&!n)return{needsRelayout:!1,shouldCascade:!1};let r=!!e&&(t.pageType===e.pageType||!e.pageType);return!!e&&s&&(!o||r)&&(e.pageType==null||t.pageType==null||t.pageType!==e.pageType)&&(e.pageType=null),{needsRelayout:!0,shouldCascade:!!e||!o}}preparePageCountersForRender(t,e){let n=t.pages[e],s=t.pageCounterStarts[e];n&&s&&(this.counterStore.currentPageCounters=nu(s));let o=nu(this.counterStore.currentPageCounters);return(!s||!n)&&(t.pageCounterStarts[e]=o),n}maybeRelayoutFollowingPage(t,e,n,s){if(!e)return T(!0);let o=t.layoutPositions[e.page];t.layoutPositions[e.page]=e;let r=t.pages[e.page],a=!!n&&s.offset!==n.offset,l=!o||!e.isSamePosition(o)||e.highestSeenOffset!==o.highestSeenOffset||a,c=this.isInCounterResolveScope(),u=this.evaluateNextPageRelayout(n,r,l,a,c);return u.needsRelayout?(t.complete=!1,u.shouldCascade?this.renderSinglePage(t,e):T(!0)):T(!0)}resolveUnresolvedReferencesForPage(t,e,n,s){let o=L("resolveUnresolvedReferencesForPage"),a=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(e),l=0,c=e;return o.loopWithFrame(u=>{if(l++,l>a.length){u.breakLoop();return}let d=a[l-1];if(d.refs=d.refs.filter(h=>!h.isResolved()),d.refs.length===0){u.continueLoop();return}this.getPageViewItem(d.spineIndex).then(h=>{if(!h){u.continueLoop();return}let f=h.instance.styler.cascade,g=h.instance.pageManager.pageCascadeInstance,m={currentPageType:f.currentPageType,previousPageType:f.previousPageType},C={currentPageType:g.currentPageType,previousPageType:g.previousPageType},x=RS(h.instance.pageGroupPageCounts),b=h.instance.currentPageGroupDocument,N=h.instance.scopes;h.instance.scopes={};let S=d.pageIndex<h.pages.length-1,E=!!h.pages[d.pageIndex]&&S,v=E?h.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(d.pageCounters),this.counterStore.pushReferencesToSolve(d.refs);let w=h.layoutPositions[d.pageIndex];this.renderSinglePage(h,w).then(A=>{E&&h.instance.endIsolatedRootPageFloatLayoutContext(v);let I=f.currentPageType;f.currentPageType=m.currentPageType,f.previousPageType=m.previousPageType,g.currentPageType=C.currentPageType,g.previousPageType=C.previousPageType,h.instance.pageGroupPageCounts=x,h.instance.currentPageGroupDocument=b,h.instance.scopes=N;let _=nu(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),A.pageAndPosition.position.spineIndex===c.spineIndex&&A.pageAndPosition.position.pageIndex===n&&(c=A.pageAndPosition.page),!!c.pageType&&c.pageType!==m.currentPageType&&I!==A.pageAndPosition.page.pageType&&(f.currentPageType=c.pageType);let Q=h!==t,me=h.pages.length,Te=h.layoutPositions[me],De=h.instance.hasActiveRootPageFloatLayoutContext();if(Te&&!De){let F=Q?nu(this.counterStore.currentPageCounters):null;Q&&(this.counterStore.currentPageCounters=_);let U=me;this.renderSinglePage(h,Te).then(()=>{Q&&this.markSpineItemCompleteIfReady(h);let j=h.pages.length-U;if(Q&&j>0){this.counterStore.adjustPageCountersOfLaterSpines(h.item.spineIndex,j),this.counterStore.updateTargetCounterNodesInPages(h.pages);let H=h.item.spineIndex;for(let M=H+1;M<this.spineItems.length;M++){let q=this.spineItems[M];if(q){q.item.epage+=j;for(let xe of q.pageCounterStarts)xe!=null&&xe.page&&(xe.page=xe.page.map(Me=>Me+j));this.counterStore.updatePageCounterNodesInPages(q.pages,q.pageCounterStarts)}}if(F){let M=F.page;M&&(F.page=M.map(q=>q+j))}}F&&(this.counterStore.currentPageCounters=F),u.continueLoop()});return}Q&&this.markSpineItemCompleteIfReady(h),u.continueLoop()})})}).then(()=>{c.container.parentElement||(c=t.pages[n]),c.isLastPage=!s&&t.item.spineIndex===this.opf.spine.length-1,c.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),c.container.setAttribute("data-vivliostyle-page-index",n),c.container.setAttribute("data-vivliostyle-spine-index",c.spineIndex),o.finish(c)}),o.result()}renderSinglePage(t,e){let n=L("renderSinglePage"),s=e?Math.max(e.page,0):0,o=this.isInCounterResolveScope(),r=this.preparePageCountersForRender(t,s),a=s>0?t.pages[s-1]:null,l=t.pages[s+1],c=this.makePage(t,e);return this.resolvePageTypeForRenderSlot(t,c,s,r,a,l,o),t.instance.layoutNextPage(c,e).then(u=>{e=u;let d=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,c,d),this.counterStore.finishPage(c.spineIndex,d),this.reportPaginationProgress(t,e),this.maybeRelayoutFollowingPage(t,e,r,c).thenAsync(()=>this.resolveUnresolvedReferencesForPage(t,c,d,e)).then(h=>{n.finish({pageAndPosition:su(h,d),nextLayoutPosition:e})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let o=Rt(e.layoutPositions.length,r=>e.instance.getPosition(e.layoutPositions[r],!0)>s);o===e.layoutPositions.length?e.complete?n=e.pages.length-1:n=Number.POSITIVE_INFINITY:n=o-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=L("findPage");return this.waitForPreviousSpines(t.spineIndex,e).then(()=>{this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let o=null,r;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);r=l.pageIndex,o=s.pages[r],o?a.breakLoop():s.complete?(r=s.pages.length-1,o=s.pages[r],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(o=c.page,r=c.position.pageIndex),a.breakLoop()}):r<s.layoutPositions.length&&!s.pages[r]?this.renderPage(l).then(c=>{c&&(o=c.page,r=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(su(o,r))})})}),n.result()}renderPage(t){let e=L("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),o=s.pageIndex,r=s.offsetInItem,a=n.pages[o];if(a){e.finish(su(a,o));return}e.loopWithFrame(l=>{if(o<n.layoutPositions.length){l.breakLoop();return}if(n.complete){o=n.pages.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,o=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,o=u.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(n),l.breakLoop()})}).then(()=>{a=a||n.pages[o];let l=n.layoutPositions[o];if(a){e.finish(su(a,o));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||this.markSpineItemCompleteIfReady(n),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=L("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(o=>o==null?void 0:o.fetchers.some(r=>!r.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=L("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,o=t.pageIndex,r=0;e&&(r=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:r,pageIndex:r===s?o: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,o=L("nextPage");return this.getPageViewItem(n).then(r=>{if(!r){o.finish(null);return}if(r.complete&&s==r.pages.length-1){if(n>=this.opf.spine.length-1){o.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(o)}),o.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=L("getSpread"),o=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),o?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),o=this.nextPage(t,e);return s?o:o.thenAsync(r=>{if(r){if(r.page.side===n.side)return o;let a=this.nextPage(r.position,e);return a.thenAsync(l=>l?a:o)}else return T(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return T(null);let s=this.isRectoPage(n,t),o=this.previousPage(t,e),r=n.container.previousElementSibling;return s?o.thenAsync(a=>a?a.page.side===n.side||a.page.container!==r?o:this.previousPage(a.position,e):T(null)):o}navigateToEPage(t,e,n){let s=L("navigateToEPage");return this.opf.resolveEPage(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=L("navigateToCFI");return this.opf.resolveFragment(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}resolveSemanticFootnoteNavigationOffset(t,e){if(!Hs(e))return null;let n=e.getAttribute("id");if(!n)return null;let s=ee(`#${n}`,t.xmldoc.url),o=t.xmldoc.document.getElementsByTagName("a");for(let r=0;r<o.length;r++){let a=o.item(r);if(!ko(a))continue;let l=a.getAttribute("href")||a.getAttributeNS("http://www.w3.org/1999/xlink","href");if(l&&ee(l,t.xmldoc.url)===s)return t.xmldoc.getElementOffset(a)}return null}navigateTo(t,e,n){O.debug("Navigate to",t);let s=this.opf.getPathFromURL(Ht(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 o=this.opf.itemMapByPath[s];if(!o){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=L("navigateTo");return this.waitForPreviousSpines(o.spineIndex,n).then(()=>{this.getPageViewItem(o.spineIndex).then(a=>{if(!a){r.finish(null);return}let l=a.xmldoc.getElement(t),c=l&&this.resolveSemanticFootnoteNavigationOffset(a,l),u=c!=null?c:l?a.xmldoc.getElementOffset(l):0;this.findPage({spineIndex:o.spineIndex,pageIndex:-1,offsetInItem:u},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",$s||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let o=n.document.createElement("div");o.setAttribute("data-vivliostyle-bleed-box","true"),o.role="presentation",s.appendChild(o);let r=new ar(s,o);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);o.setAttribute("id",a),r.registerElementWithId(o,a)}if(n!==this.viewport){let a=Au(this.viewport.width,this.viewport.height,n.width,n.height),l=Ss(null,new it(a,null),"");r.delayedItems.push(new ws(s,"transform",l))}return r}makeObjectView(t,e,n,s){let o=e.getAttribute("data"),r=null;if(o){o=ee(o,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(o);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(o),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 C=m.getAttribute("name"),x=m.getAttribute("value");C&&x&&(d.append("&"),d.append(encodeURIComponent(C)),d.append("="),d.append(encodeURIComponent(x)))}}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"),o&&r.setAttribute("data",o),r.setAttribute("data-adapt-process-children","true")),T(r)}makeMathJaxView(t,e,n,s){let o=OS();if(o){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=o.queue;c.Push(["Typeset",o,a]);let u=L("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 o=ee(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,o):t.setAttribute(s.name,o)}}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=L("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let o=this.opf.spine[t],r=this.opf.store;return r.load(o.src).then(a=>{var N;let l=o.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),o.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 us(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(N=this.spineItems[0])==null?void 0:N.instance.isVersoFirstPage,g=this.spineItems[t-1],m,C;if(o.startPage!==null)m=o.startPage-1,C=m;else{if(t>0&&(!g||!g.complete))m=o.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,C=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let S=g&&g.pageCounterStarts[g.pages.length-1],E=S&&S.page;if(E&&E.length)C=E[E.length-1]+1;else{let v=this.counterStore.currentPageCounters.page;C=!v||!v.length?m:v[v.length-1]}}o.skipPagesBefore!==null&&(m+=o.skipPagesBefore,C+=o.skipPagesBefore)}this.counterStore.forceSetPageCounter(C);let x=new Us(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);x.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[ze.title];x.pubTitle=b&&b[0]&&b[0].v||"",x.docTitle=o.title||"",x.init().then(()=>{!this.opf.pageProgression&&x.pageProgression&&(this.opf.pageProgression=x.pageProgression),e={item:o,xmldoc:a,instance:x,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[t]=e,n.finish(e),s.forEach(S=>{S.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=L("showTOC");this.tocView||(this.tocView=new eu(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore,this.cmykStore));let o=this.viewport,r=Math.min(344,Math.round(.67*o.width)-16),a=o.height-6,l=o.document.createElement("div");return o.root.appendChild(l),$s||(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,o,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 sb="data-vivliostyle-viewer-status",MS="data-vivliostyle-spread-view",Ff=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(Ff||{}),iu=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");p(this,"cmykReserveMap");p(this,"cmykReserveMapUrl");let o=e.ownerDocument,r=(a,l)=>{let c=o.getElementById(a);return c||(c=o.createElement("style"),c.id=a,l&&(c.textContent=l),o.head.appendChild(c)),c};r("vivliostyle-viewport-screen-css",ad),r("vivliostyle-viewport-css",ld),r("vivliostyle-polyfill-css",fd),e.setAttribute("data-vivliostyle-viewer-viewport",!0),$s&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(sb,"loading"),this.fontMapper=new Vc(o.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=ku(),this.pageSizes=[],this.pixelRatioLimit=Fo==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=bu;O.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),O.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),O.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),O.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){if(this.readyState!==t){this.readyState=t,this.viewportElement.setAttribute(sb,t);let e=this.getCurrentPageProgression();e&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",e),this.callback({t:"readystatechange"})}}loadPublication(t){ut.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,o=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let r=L("loadPublication");return this.configure(t).then(()=>{let a=new ha;a.init(s,o).then(()=>{let l=ee(Wn(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{r.finish(!0)})})):r.finish(!1)})})}),r.result()}loadXML(t){ut.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,o=t.authorStyleSheet,r=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let a=L("loadXML");return this.configure(t).then(()=>{let l=new ha;l.init(o,r).then(()=>{let c=e.map((u,d)=>({url:ee(Wn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Ao(l,""),this.opf.initWithChapters(c,n).then(()=>{this.loadCmykReserveMap(l).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(()=>(ut.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let o=s[0];if(o==="em"||o==="rem")return e*this.fontSize;let r=ot[o];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"&&(xu(t.userAgentRootURL.replace(/resources\/?$/,"")),Su(t.userAgentRootURL)),typeof t.rootURL=="string"&&(xu(t.rootURL),Su(`${vn}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!==En&&(GC(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){Je("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=>{P(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),P(t.container,"visibility","visible"),P(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=L("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?hn(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 us(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new us(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(MS,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 o,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((o=this.pageSizes[n-1])==null?void 0:o.width)||this.pageSizes[n].height!==((r=this.pageSizes[n-1])==null?void 0:r.height))){let c=function(m){let C=m*.75;return Math.ceil(C)};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)}loadCmykReserveMap(t){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,T(!0);let e=ee(Wn(this.cmykReserveMapUrl),vn),n=L("loadCmykReserveMap");return t.loadAsJSON(e).then(s=>{rg(s)?this.cmykReserveMap=s:(O.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),n.finish(!0)}),n.result()}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new ru(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let 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 au),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return T(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=oi().getScheduler().run(()=>Kn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,ut.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 o={t:"nav",epageCount:s,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(o.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(o)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():T(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),ut.registerEndTiming("render (resize)"),En&&vf(this.window)?XC(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 au)ut.registerEndTiming("render (resize)"),O.debug(n.message);else throw n}));return T(!0)}sendLocationNotification(t,e){let n=L("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:this.isLastPageForNotification(t),metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(o=>{s.epage=o,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}isLastPageForNotification(t){if(!this.opfView||!this.pagePosition)return t.isLastPage;let e=this.opfView.spineItems[this.pagePosition.spineIndex];if(!e||!e.complete)return!1;let n=e.item.spineIndex===this.opf.spine.length-1,s=this.pagePosition.pageIndex===e.pages.length-1;return n&&s}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 o;switch(t.where){case"next":o=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":o=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":o=this.opfView.lastPage;break;case"first":o=this.opfView.firstPage;break;default:return T(!0)}o&&(e=()=>o.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let o=t.epage;e=()=>this.opfView.navigateToEPage(o,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let o=t.url;e=()=>this.opfView.navigateTo(o,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let o=t.position;e=()=>this.opfView.findPage(o,!this.renderAllPages)}else return T(!0);if(!this.opfView)return T(!0);let n=L("moveTo");return e.call(this.opfView).then(o=>{let r;if(o){this.pagePosition=o.position;let a=L("moveTo.showCurrent");r=a.result(),this.showCurrent(o.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(),o=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!o)return T(!0)}else if(n=="hide")return T(!0);if(s&&n!="show")return this.opfView.hideTOC(),T(!0);{let r=L("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(o&&(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 Kn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(O.error("No such action:",e),n.finish(!0))},(n,s)=>{O.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=ob(t),n=null,s=this;Pg(()=>{let o=L("commandLoop"),r=oi().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)))}},o.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=L("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(o),o.result()}),s.kick=()=>{let o=n;o&&(n=null,o.schedule(!0))},s.sendCommand=o=>e?!1:(e=ob(o),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Vf=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Vf||{}),au=class i extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,i.prototype),this.stack=new Error().stack}};function ob(i){return typeof i=="string"?Vo(i):i}var rb=Xs;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 ib(i){let t={};return Object.keys(i).forEach(e=>{let n=i[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var fa=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");fu(t.debug),this.adaptViewer_=new iu(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=US(),e&&this.setOptions(e),this.eventTarget=new ds,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},ib(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 o=n||{};function r(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=r(o.authorStyleSheet),l=r(o.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:HS(t)||e,document:o.documentObject,fragment:o.fragment,authorStyleSheet:a,userStyleSheet:l,cmykReserveMapUrl:o.cmykReserveMapUrl},ib(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()===rb.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===rb.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 HS(i){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(i)?i.map(e):i?[e(i)]:null}var ab=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(ab||{}),zS=Vf,GS=Ff;ut.forceRegisterEndTiming("load_vivliostyle");var Bf=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:o=!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=o,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=`
1849
+ `),n.toString()}},zc=class{constructor(t){this.deobfuscator=t;p(this,"familyMap",{})}registerFamily(t,e){let n=t.family,s=this.familyMap[n],o=e.family;if(s){if(s!=o)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${t.family}`)}else this.familyMap[n]=o}filterFontFamily(t){if(t instanceof ve){let e=t.values,n=[];for(let s of e){let o=this.familyMap[s.stringValue()];o&&n.push(R(o)),n.push(s)}return new ve(n)}else{let e=this.familyMap[t.stringValue()];return e?new ve([R(e),t]):t}}},Gc=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=I("initFont"),o=t.src,r={};for(let u of Cf(t.properties))r[u]=t.properties[u];let a=this.getViewFontFamily(t,n);r["font-family"]=R(a);let l=new ra(r),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(o,e),this.head.appendChild(c),B.debug("Load font:",o),s.finish(l),s.result()}loadFont(t,e){let n=t.src,s=t.family+";"+n+";"+t.fontTraitKey,o=this.srcURLMap[s];return o?o.piggyback(r=>{e.registerFamily(t,r),B.debug("Found already-loaded font:",n)}):(o=new Ln(()=>{let r=I("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?uo(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]=o,o.start()),o}findOrLoadFonts(t,e){let n=[];for(let s of t){if(!s.src||!s.family){B.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return Cn(n).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let t=this.head.ownerDocument.fonts,e=0;if(t.forEach(s=>{s.status==="unloaded"&&(e++,s.load().catch(o=>{}))}),e===0)return w(!0);let n=I("waitFontLoading");return n.loop(()=>n.sleep(20).thenAsync(()=>t.status==="loading"?w(!0):w(!1))).thenFinish(n),n.result()}};var dE=1,Vr=class{constructor(t,e,n,s,o){this.name=e;this.pseudoName=n;this.classes=s;this.parent=o;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${dE++}`,o&&(this.index=o.children.length,o.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})}},$c=class extends Vr{constructor(t){super(t,null,null,[],null),this.specified.width=new V(bs,0),this.specified.height=new V(ys,0)}},Wc=class extends Qs{constructor(e,n){super(e,o);this.pageMaster=n;let s=this;function o(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}}},Or=class i extends Vr{constructor(e,n,s,o,r,a,l){super(e,n,s,o,r);this.condition=a;this.specificity=l;p(this,"keyMap",{});e instanceof Wc||(this._scope=new Wc(e,this)),this.pageMaster=this,this.specified.width=new V(bs,0),this.specified.height=new V(ys,0),this.specified["wrap-flow"]=new V(S.auto,0),this.specified.position=new V(S.relative,0),this.specified.overflow=new V(S.visible,0)}createInstance(e){return new Io(e,this)}clone(e){let n=new i(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}},Xc=class i extends Vr{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key),this.specified["wrap-flow"]=new V(S.auto,0)}createInstance(t){return new bf(t,this)}clone(t){let e=new i(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}},zs=class i extends Vr{constructor(t,e,n,s,o){super(t,e,n,s,o),this.pageMaster=o.pageMaster,e&&(this.pageMaster.keyMap[e]=this.key)}createInstance(t){return new $n(t,this)}clone(t){let e=new i(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(e),this.cloneChildren(e),e}};function pE(i,t,e){return!t||W(t)?new we(i,e):t.toExpr(i,i.zero)}function he(i,t,e){return!t||t===S.auto||W(t)?null:t.toExpr(i,e)}function hE(i,t,e){return!t||t===S.normal||W(t)?null:t.toExpr(i,e)}function kt(i,t,e){return!t||t===S.auto||W(t)?i.zero:t.toExpr(i,e)}function Sf(i,t,e){return!t||W(t)?i.zero:t===S.auto?null:t.toExpr(i,e)}function En(i,t,e,n){return!t||e===S.none||W(t)?i.zero:t.toExpr(i,n)}function Sb(i,t,e){return!t||W(t)?e:t===S._true?i._true:t===S._false?i._false:t.toExpr(i,i.zero)}var Br=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 K(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 o=this.vertical?Jp:eh;s=t;for(let r in o)s=s.replace(r,o[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 Wo(n,0),o=this.resolveName("column-count"),r=this.resolveName("column-width"),a=this.resolveName("column-gap");e=ae(n,Xo(n,new Yn(n,"min",[s,o]),K(n,r,a)),a);break}}return e&&(this.namedFuncs[t]=e),e}initEnabled(){let t=this.pageBox.scope,e=this.style,n=Sb(t,e.enabled,t._true),s=he(t,e.page,t.zero);if(s){let a=new Se(t,"page-number");n=xt(t,n,new Cs(t,s,a))}let o=he(t,e["min-page-width"],t.zero);o&&(n=xt(t,n,new Js(t,new Se(t,"page-width"),o)));let r=he(t,e["min-page-height"],t.zero);r&&(n=xt(t,n,new Js(t,new Se(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=he(t,e.left,n),o=he(t,e["margin-left"],n),r=En(t,e["border-left-width"],e["border-left-style"],n),a=kt(t,e["padding-left"],n),l=he(t,e.width,n),c=he(t,e["max-width"],n),u=kt(t,e["padding-right"],n),d=En(t,e["border-right-width"],e["border-right-style"],n),h=he(t,e["margin-right"],n),f=he(t,e.right,n),g=K(t,r,a),m=K(t,r,u);if(s&&f&&l){let C=ae(t,n,K(t,l,K(t,K(t,s,g),m)));o?h?f=ae(t,C,h):h=ae(t,C,K(t,f,o)):(C=ae(t,C,f),h?o=ae(t,C,h):(o=Xo(t,C,new we(t,.5)),h=o))}else{o||(o=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=ae(t,n,K(t,K(t,o,g),K(t,h,m)));this.isAutoWidth&&(c||(c=ae(t,C,s||f)),!this.vertical&&(he(t,e["column-width"],null)||he(t,e["column-count"],null))&&(l=c,this.isAutoWidth=!1)),s?l?f||(f=ae(t,C,K(t,s,l))):l=ae(t,C,K(t,s,f)):s=ae(t,C,K(t,f,l))}let b=e["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),y=kt(t,b,n);e.left=new D(s),e["margin-left"]=new D(o),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(y)}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,o=he(t,e.top,s),r=he(t,e["margin-top"],n),a=En(t,e["border-top-width"],e["border-top-style"],n),l=kt(t,e["padding-top"],n),c=he(t,e.height,s),u=he(t,e["max-height"],s),d=kt(t,e["padding-bottom"],n),h=En(t,e["border-bottom-width"],e["border-bottom-style"],n),f=he(t,e["margin-bottom"],n),g=he(t,e.bottom,s),m=K(t,a,l),b=K(t,h,d);if(o&&g&&c){let N=ae(t,s,K(t,c,K(t,K(t,o,m),b)));r?f?g=ae(t,N,r):f=ae(t,N,K(t,g,r)):(N=ae(t,N,g),f?r=ae(t,N,f):(r=Xo(t,N,new we(t,.5)),f=r))}else{r||(r=t.zero),f||(f=t.zero),!o&&!g&&!c&&(o=t.zero),!o&&!c?(c=this.autoHeight,this.isAutoHeight=!0):!o&&!g?o=t.zero:!c&&!g&&(c=this.autoHeight,this.isAutoHeight=!0);let N=ae(t,s,K(t,K(t,r,m),K(t,f,b)));this.isAutoHeight&&(u||(u=ae(t,N,o||g)),this.vertical&&(he(t,e["column-width"],null)||he(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),o?c?g||(g=ae(t,N,K(t,o,c))):c=ae(t,N,K(t,g,o)):o=ae(t,N,K(t,g,c))}let y=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=kt(t,y,n);e.top=new D(o),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=he(t,e[this.vertical?"height":"width"],null),s=he(t,e["column-width"],n),o=he(t,e["column-count"],null),r=hE(t,e["column-gap"],null);r||(r=new dn(t,1,"em")),s&&!o&&(o=new Yn(t,"floor",[Qr(t,K(t,n,r),K(t,s,r))]),o=new Yn(t,"max",[t.one,o])),o||(o=t.one),s=ae(t,Qr(t,K(t,n,r),o),r),e["column-width"]=new D(s),e["column-count"]=new D(o),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,o=this.parentInstance?this.parentInstance.getActiveRegions(t):null,r=Li(this.cascaded,t,o,!1,null);this.vertical=oc(r,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=rc(r,t,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((l=r["box-sizing"])==null?void 0:l.value)===S.border_box;let a=!!(t instanceof Gs&&t.currentLayoutPosition&&new Se(n,"left-page").evaluate(t));ic(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,o;let n=this.style[e];return!n&&ls(e)&&this.pageMasterInstance instanceof Wn&&(e==="font-size"&&t.isRelativeRootFontSize&&t.rootFontSize?n=new A(t.rootFontSize,"px"):n=(o=((s=t.styler)==null?void 0:s.rootStyle)[e])==null?void 0:o.value),n&&(n=Ii(t,n,e)),n}getPropAsNumber(t,e){var s,o;let n=this.style[e];if(n){let r=/\b(height|top|bottom)\b/.test(e)?(s=t.pageAreaHeight)!=null?s:t.pageHeight():(o=t.pageAreaWidth)!=null?o:t.pageWidth();n=Ii(t,n,e,r)}return Ye(n,t)}getSpecial(t,e){let n=th(this.cascaded,e);if(n){let s=[];for(let o=0;o<n.length;o++){let r=n[o].evaluate(t,"");r&&r!==$&&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 o=this.getProp(t,n);o&&(o.isNumeric()&&ja(o.unit)&&(o=Ka(o,t)),n==="font-family"&&(o=s.filterFontFamily(o)),(n.startsWith("background")||n==="z-index")&&e.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(e=e.parentElement),P(e,n,o.toString()))}propagateDelayedProperty(t,e,n,s){let o=this.getProp(t,n);o&&s.push(new Ls(e.element,n,o))}assignLeftPosition(t,e){let n=this.getPropAsNumber(t,"left"),s=this.getPropAsNumber(t,"margin-left"),o=this.getPropAsNumber(t,"padding-left"),r=this.getPropAsNumber(t,"border-left-width"),a=this.getPropAsNumber(t,"width");e.setHorizontalPosition(n,a),P(e.element,"margin-left",`${s}px`),P(e.element,"padding-left",`${o}px`),P(e.element,"border-left-width",`${r}px`),e.marginLeft=s,e.borderLeft=r,e.paddingLeft=o}assignRightPosition(t,e){let n=this.getPropAsNumber(t,"right"),s=this.getPropAsNumber(t,"snap-height"),o=this.getPropAsNumber(t,"margin-right"),r=this.getPropAsNumber(t,"padding-right"),a=this.getPropAsNumber(t,"border-right-width");if(P(e.element,"margin-right",`${o}px`),P(e.element,"padding-right",`${r}px`),P(e.element,"border-right-width",`${a}px`),e.marginRight=o,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"),o=this.getPropAsNumber(t,"margin-top"),r=this.getPropAsNumber(t,"padding-top"),a=this.getPropAsNumber(t,"border-top-width");if(e.top=s,e.marginTop=o,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,P(e.element,"top",`${s}px`),P(e.element,"margin-top",`${o}px`),P(e.element,"padding-top",`${r}px`),P(e.element,"border-top-width",`${a}px`)}assignBottomPosition(t,e){let n=this.getPropAsNumber(t,"margin-bottom"),s=this.getPropAsNumber(t,"padding-bottom"),o=this.getPropAsNumber(t,"border-bottom-width"),r=this.getPropAsNumber(t,"height")-e.snapOffsetY;P(e.element,"height",`${r}px`),P(e.element,"margin-bottom",`${n}px`),P(e.element,"padding-bottom",`${s}px`),P(e.element,"border-bottom-width",`${o}px`),e.height=r-e.snapOffsetY,e.marginBottom=n,e.borderBottom=o,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){P(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,P(e.element,"height",`${n}px`))}sizeWithMaxWidth(t,e){P(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");P(e.element,"right",`${s}px`),P(e.element,"width",`${n}px`)}}prepareContainer(t,e,n,s,o){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&P(e.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&P(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<gb.length;r++)this.propagateProperty(t,e,gb[r],s)}transferContentProps(t,e,n,s){for(let o=0;o<Cb.length;o++)this.propagateProperty(t,e,Cb[o],s);if(this.style["text-overflow"]){let o=e.element.firstElementChild;P(o,"text-overflow","inherit"),P(o,"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!==S.auto&&!W(r)},o=()=>{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!==S.auto&&!W(r)};for(let r=0;r<bb.length;r++){let a=bb[r];if(a==="width"||a==="height"){if(a==="width"&&!s()||a==="height"&&!o())continue;P(e,a,"100%");continue}this.propagatePropertyToElement(t,e,a,n)}}finishContainer(t,e,n,s,o,r,a){var d,h,f,g,m,b,y,C,N,x;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&&P(e.element,"width","auto"),l&&P(e.element,"height","auto");let E=s&&hr(s);E&&pr(s),u=r.getElementClientRect(s?s.element:e.element),E&&fi(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)),o>1){let E=this.getPropAsNumber(t,"column-rule-width"),v=this.getProp(t,"column-rule-style"),T=this.getProp(t,"column-rule-color");if(E>0&&v&&v!=S.none&&T!=S.transparent){let k=this.getPropAsNumber(t,"column-gap"),L=this.vertical?e.height:e.width,M=parseFloat(this.vertical?(d=s==null?void 0:s.element.style.left)!=null?d:"":(h=s==null?void 0:s.element.style.top)!=null?h:""),q=e.getPaddingRect(),J=s,re=this.vertical?"border-top":"border-left";for(let xe=1;xe<o;xe++){let le=this.vertical?(L+k)*xe/o-k/2+e.paddingTop-E/2:(L+k)*xe/o-k/2+e.paddingLeft-E/2,F=this.vertical?q.y1+le+E/2:q.x1+le+E/2,U=(m=(g=(f=J.pageFloatLayoutContext)==null?void 0:f.parent)==null?void 0:g.getBlockEndEdgeOfBlockStartFloats)==null?void 0:m.call(g,F),j=(C=(y=(b=J.pageFloatLayoutContext)==null?void 0:b.parent)==null?void 0:y.getBlockStartEdgeOfBlockEndFloats)==null?void 0:C.call(y,F),H=isFinite(U)?this.vertical?U-q.x1:U-q.y1:NaN,_=isFinite(j)?this.vertical?j-q.x1:j-q.y1:NaN,Y=parseFloat(this.vertical?(N=s==null?void 0:s.element.style.width)!=null?N:"":(x=s==null?void 0:s.element.style.height)!=null?x:""),Ee=Y>0?Y:this.vertical?s.width:s.height,Ve=Math.max(M>0?M:0,0),Oo=Ve+Ee,Mr=Math.max(Ve,isFinite(this.vertical?_:H)?Math.max(0,this.vertical?_:H):0),fs=Math.min(Oo,isFinite(this.vertical?H:_)?Math.max(0,this.vertical?H:_):Oo),Ea=Math.max(0,fs-Mr),Nn=e.element.ownerDocument.createElement("div");P(Nn,"position","absolute"),P(Nn,this.vertical?"left":"top",`${Mr}px`),P(Nn,this.vertical?"top":"left",`${le}px`),P(Nn,this.vertical?"height":"width","0px"),P(Nn,this.vertical?"width":"height",`${Ea}px`),P(Nn,re,`${E}px ${v.toString()}${T?` ${T.toString()}`:""}`),e.element.insertBefore(Nn,e.element.firstChild)}}}for(let E=0;E<mb.length;E++)this.propagateProperty(t,e,mb[E],a);for(let E=0;E<yb.length;E++)this.propagateDelayedProperty(t,e,yb[E],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let r in s)this instanceof Wn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Ds(r)&&Hn(n,r,ee(s,r));if(this.pageBox.pseudoName==aa)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 o=n.content;o&&(n.content=o.filterValue(new is(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)}},gb=["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"],mb=["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"],Cb=["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"],bb=["width","height","image-resolution","object-fit","object-position"],yb=["transform","transform-origin"],aa="background-host",jc=class extends Br{constructor(t){super(null,t)}applyCascadeAndInit(t,e){super.applyCascadeAndInit(t,e),this.children.sort((s,o)=>o.pageBox.specificity-s.pageBox.specificity||s.pageBox.index-o.pageBox.index)}},Io=class extends Br{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=xt(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},bf=class extends Br{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},$n=class extends Br{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}processPartitionList(t,e,n){let s=null;if(e instanceof Q&&(s=[e]),e instanceof ve&&(s=e.values),s){let o=this.pageBox.scope;for(let r=0;r<s.length;r++)if(s[r]instanceof Q){let a=Zr(s[r].name,"enabled"),l=new Se(o,a);n&&(l=new $t(o,l)),t=xt(o,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=Sb(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let o=pE(e,n["flow-from"],"body"),r=new Yn(e,"has-content",[o]);t=xt(e,t,r)}if(t=this.processPartitionList(t,n["required-partitions"],!1),t=this.processPartitionList(t,n["conflicting-partitions"],!0),s){let o=this.pageMasterInstance.style.enabled,r=o?o.toExpr(e,null):e._true;r=xt(e,r,t),this.pageMasterInstance.style.enabled=new D(r)}return t}prepareContainer(t,e,n,s,o){var r;this.pageBox.pageMaster instanceof la||(P(e.element,"overflow","hidden"),e.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(t,e,n,s,o)}},ia=class extends nn{constructor(e,n,s,o){super(e,n,!1);this.target=s;this.validatorSet=o}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 V(n,s?hl:fl)}},Yc=class extends ia{constructor(t,e,n,s){super(t,e,n,s)}},yf=class i extends ia{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new V($u,0),n.specified.height=new V($u,0)}startPartitionRule(t,e,n){let s=new zs(this.scope,t,e,n,this.target),o=new Yc(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new Xc(this.scope,t,e,n,this.target),o=new i(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},qc=class extends ia{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new zs(this.scope,t,e,n,this.target),o=new Yc(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new Xc(this.scope,t,e,n,this.target),o=new yf(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}};function _f(i){var n,s;let t=(n=i["writing-mode"])==null?void 0:n.value,e=(s=i.direction)==null?void 0:s.value;return t===S.vertical_lr||t!==S.vertical_rl&&e!==S.rtl?"ltr":"rtl"}var fE={a10:{width:new A(26,"mm"),height:new A(37,"mm")},a9:{width:new A(37,"mm"),height:new A(52,"mm")},a8:{width:new A(52,"mm"),height:new A(74,"mm")},a7:{width:new A(74,"mm"),height:new A(105,"mm")},a6:{width:new A(105,"mm"),height:new A(148,"mm")},a5:{width:new A(148,"mm"),height:new A(210,"mm")},a4:{width:new A(210,"mm"),height:new A(297,"mm")},a3:{width:new A(297,"mm"),height:new A(420,"mm")},a2:{width:new A(420,"mm"),height:new A(594,"mm")},a1:{width:new A(594,"mm"),height:new A(841,"mm")},a0:{width:new A(841,"mm"),height:new A(1189,"mm")},b10:{width:new A(31,"mm"),height:new A(44,"mm")},b9:{width:new A(44,"mm"),height:new A(62,"mm")},b8:{width:new A(62,"mm"),height:new A(88,"mm")},b7:{width:new A(88,"mm"),height:new A(125,"mm")},b6:{width:new A(125,"mm"),height:new A(176,"mm")},b5:{width:new A(176,"mm"),height:new A(250,"mm")},b4:{width:new A(250,"mm"),height:new A(353,"mm")},b3:{width:new A(353,"mm"),height:new A(500,"mm")},b2:{width:new A(500,"mm"),height:new A(707,"mm")},b1:{width:new A(707,"mm"),height:new A(1e3,"mm")},b0:{width:new A(1e3,"mm"),height:new A(1414,"mm")},c10:{width:new A(28,"mm"),height:new A(40,"mm")},c9:{width:new A(40,"mm"),height:new A(57,"mm")},c8:{width:new A(57,"mm"),height:new A(81,"mm")},c7:{width:new A(81,"mm"),height:new A(114,"mm")},c6:{width:new A(114,"mm"),height:new A(162,"mm")},c5:{width:new A(162,"mm"),height:new A(229,"mm")},c4:{width:new A(229,"mm"),height:new A(324,"mm")},c3:{width:new A(324,"mm"),height:new A(458,"mm")},c2:{width:new A(458,"mm"),height:new A(648,"mm")},c1:{width:new A(648,"mm"),height:new A(917,"mm")},c0:{width:new A(917,"mm"),height:new A(1297,"mm")},"jis-b10":{width:new A(32,"mm"),height:new A(45,"mm")},"jis-b9":{width:new A(45,"mm"),height:new A(64,"mm")},"jis-b8":{width:new A(64,"mm"),height:new A(91,"mm")},"jis-b7":{width:new A(91,"mm"),height:new A(128,"mm")},"jis-b6":{width:new A(128,"mm"),height:new A(182,"mm")},"jis-b5":{width:new A(182,"mm"),height:new A(257,"mm")},"jis-b4":{width:new A(257,"mm"),height:new A(364,"mm")},"jis-b3":{width:new A(364,"mm"),height:new A(515,"mm")},"jis-b2":{width:new A(515,"mm"),height:new A(728,"mm")},"jis-b1":{width:new A(728,"mm"),height:new A(1030,"mm")},"jis-b0":{width:new A(1030,"mm"),height:new A(1456,"mm")},letter:{width:new A(8.5,"in"),height:new A(11,"in")},legal:{width:new A(8.5,"in"),height:new A(14,"in")},ledger:{width:new A(11,"in"),height:new A(17,"in")}},gE=new A(.24,"pt"),kN=new A(3,"mm"),mE=new A(10,"mm"),CE=new A(13,"mm");function ma(i){let t={width:bs,height:ys,bleed:me,bleedOffset:me,cropOffset:me},e=i.size;if(!(!e||e.value===S.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&&fE[u.name.toLowerCase()];h&&(d&&d===S.landscape?(t.width=h.height,t.height=h.width):(t.width=h.width,t.height=h.height))}}let n=i.marks,s=i.bleed,o=n&&!W(n.value)?n.value:S.none,r=s&&!W(s.value)?s.value:S.auto;if(r===S.auto){if(o!==S.none){let c=!1;o.isSpaceList()?c=o.values.some(u=>u===S.crop):c=o===S.crop,c&&(t.bleed=new A(6,"pt"))}}else r.isNumeric()&&(t.bleed=r);let a=i["crop-offset"],l=a&&!W(a.value)?a.value:S.auto;return l===S.auto?o!==S.none&&(t.bleedOffset=CE):l.isNumeric()&&(t.cropOffset=l),t}function Uf(i,t){let e={},n=Math.max(0,i.bleed.num)*t.queryUnitSize(i.bleed.unit,!1),s=!i.cropOffset.num&&i.bleedOffset.num?i.bleedOffset.num*t.queryUnitSize(i.bleedOffset.unit,!1):Math.max(0,i.cropOffset.num*t.queryUnitSize(i.cropOffset.unit,!1)-n),o=n+s,r=i.width;r===bs?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)-o*2:e.pageWidth=r.num*t.queryUnitSize(r.unit,!1);let a=i.height;return a===ys?t.pref.defaultPaperSize?e.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):e.pageHeight=t.viewportHeight-o*2:e.pageHeight=a.num*t.queryUnitSize(a.unit,!1),e.bleed=n,e.bleedOffset=s,e.cropOffset=o,e}function Eb(i,t,e){let n=i.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",e),n.style.position="absolute",n}function ca(i,t,e,n){n=n||"polyline";let s=i.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",e===S.auto?"#010101":e.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var xf=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(xf||{});function bE(i,t,e,n,s,o,r){let a=s;a<=o+2*ct.mm&&(a=o+s/2);let l=Math.max(s,a),c=o+l+e/2,u=Eb(i,c,c),d=[[0,o+s],[s,o+s],[s,o+s-a]],h=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[o+l-m[0],m[1]]),h=h.map(m=>[o+l-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],o+l-m[1]]),h=h.map(m=>[m[0],o+l-m[1]]));let f=ca(i,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=ca(i,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 ua=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(ua||{});function yE(i,t,e,n,s,o){let r=s*2,a,l;t==="top"||t==="bottom"?(a=r,l=s):(a=s,l=r);let c=Eb(i,a,l),u=ca(i,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=ca(i,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=ca(i,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(ua).forEach(g=>{let m=ua[g];m===t?c.style[m]=`${o}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function vb(i,t,e,n){let s=!1,o=!1,r=i.marks;if(r){let m=r.value;m instanceof X?m.values.forEach(b=>{b===S.crop?s=!0:b===S.cross&&(o=!0)}):m===S.crop?s=!0:m===S.cross&&(o=!0)}let a=t.bleed;if(!s&&!o)return;let l=e.container,c=l.ownerDocument;let u=Ye(gE,n),d=Math.max(0,t.bleedOffset-Ye(mE,n)),h=t.bleedOffset-d,f=i["crop-marks-line-color"],g=f&&!W(f.value)?f.value:S.auto;s&&Object.keys(xf).forEach(m=>{let b=xf[m],y=bE(c,b,u,g,h,a,d);l.appendChild(y)}),o&&Object.keys(ua).forEach(m=>{let b=ua[m],y=yE(c,b,u,g,h,d);l.appendChild(y)})}var Ef=(()=>{let i=["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 i.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 Hf={"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"}},SE=(()=>{let i=Hf;return Object.keys(i).sort((t,e)=>i[t].order-i[e].order)})(),Jc="vivliostyle-page-rule-master",da="_marginBoxes",pa="_footnoteArea",la=class extends Or{constructor(e,n,s){super(e,null,Jc,[],n,null,0);p(this,"pageMarginBoxes",{});let o=ma(s),r=new vf(this.scope,this,s,o);this.createPageMarginBoxes(s),this.applySpecified(s,o)}createPageMarginBoxes(e){let n=e[da];n&&SE.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new Tf(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new V(S.relative,0),this.specified.width=new V(n.width,0),this.specified.height=new V(n.height,0);for(let s in e)!Ef[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new Wn(e,this)}},vf=class extends zs{constructor(e,n,s,o){super(e,null,null,[],n);this.pageSize=o;let r=new Nf(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new V(S.auto,0),this.specified["z-index"]=new V(new ce(0),0),this.specified.position=new V(S.absolute,0),this.specified.overflow=new V(S.visible,0);for(let n in Ef)Ef.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new Pf(e,this)}},Nf=class extends zs{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new V(R("body"),0)}createInstance(t){return new ha(t,this)}},Tf=class extends zs{constructor(e,n,s,o){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(o)}applySpecified(e){let n=e[da][this.marginBoxName];for(let s in e){let o=e[s],r=n[s];(Qp[s]||r&&r.value===S.inherit)&&(this.specified[s]=o)}for(let s in n)if(Object.prototype.hasOwnProperty.call(n,s)){let o=n[s];o&&o.value!==$&&o.value!==S.inherit&&o.value!==S.unset&&o.value!==S.revert&&(this.specified[s]=o)}}createInstance(e){return new fa(e,this)}},Wn=class extends Io{constructor(e,n){super(e,n);p(this,"pageAreaDimension",null);p(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,n){let s=this.cascaded;for(let o in n)if(Object.prototype.hasOwnProperty.call(n,o))switch(o){case"writing-mode":case"direction":s[o]=n[o]}super.applyCascadeAndInit(e,n)}initHorizontal(){let e=this.style;e.left=me,e["margin-left"]=me,e["border-left-width"]=me,e["padding-left"]=me,e["padding-right"]=me,e["border-right-width"]=me,e["margin-right"]=me,e.right=me}initVertical(){let e=this.style;e.top=me,e["margin-top"]=me,e["border-top-width"]=me,e["padding-top"]=me,e["padding-bottom"]=me,e["border-bottom-width"]=me,e["margin-bottom"]=me,e.bottom=me}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 o=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(o.top,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(o.bottom,!0,r,e,s),this.sizeMarginBoxesAlongVariableDimension(o.left,!1,a,e,s),this.sizeMarginBoxesAlongVariableDimension(o.right,!1,a,e,s)}sizeMarginBoxesAlongVariableDimension(e,n,s,o,r){let a="start",l="center",c="end",u=this.pageBox.scope,d={},h={},f={};for(let E in e){let v=Hf[E];if(v){let T=e[E],k=this.pageMarginBoxInstances[E],L=new Dr(T,k.style,n,u,r);d[v.positionAlongVariableDimension]=T,h[v.positionAlongVariableDimension]=k,f[v.positionAlongVariableDimension]=L}}let g={start:s.start.evaluate(o),end:s.end.evaluate(o),extent:s.extent.evaluate(o)},m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),b=!1,y={};Object.keys(d).forEach(E=>{let v=E,T=he(u,h[v].style[n?"max-width":"max-height"],s.extent);if(T){let k=T.evaluate(o);if(m[v]>k){let L=f[v]=new Kc(d[v],h[v].style,n,u,r,k);y[v]=L.getOuterSize(),b=!0}}}),b&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),b=!1,[a,l,c].forEach(E=>{var v;m[E]=(v=y[E])!=null?v:m[E]}));let C={};Object.keys(d).forEach(E=>{let v=E,T=he(u,h[v].style[n?"min-width":"min-height"],s.extent);if(T){let k=T.evaluate(o);if(m[v]<k){let L=f[v]=new Kc(d[v],h[v].style,n,u,r,k);C[v]=L.getOuterSize(),b=!0}}}),b&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(E=>{m[E]=C[E]||m[E]}));let N=g.start+g.extent,x=g.start+(g.start+g.extent);[a,l,c].forEach(E=>{let v=m[E];if(v!=null){let T=d[E],k=0;switch(E){case a:k=n?T.left:T.top;break;case l:k=(x-v)/2;break;case c:k=N-v;break}n?T.setHorizontalPosition(k,v-T.getInsetLeft()-T.getInsetRight()):T.setVerticalPosition(k,v-T.getInsetTop()-T.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,n){var l;let s=e.start,o=e.center,r=e.end,a={};if(o){let c=[s,r],u=new wf(c),d=this.distributeAutoMarginBoxSizes(o,u,n);d.xSize!=null&&(a.center=d.xSize);let h=(l=d.xSize)!=null?l:o.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 o={xSize:null,ySize:null};if(e instanceof Dr&&e.minMaxFitContent&&(o.xSize=e.getOuterSize()),n instanceof Dr&&n.minMaxFitContent&&(o.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)o.xSize=s*r/l;else{let c=e.getOuterMinContentSize(),u=n.getOuterMinContentSize(),d=c+u;d<s?o.xSize=c+(s-d)*(r-c)/(l-d):d>0&&(o.xSize=s*c/d)}o.xSize>0&&(o.ySize=s-o.xSize)}else r>0?o.xSize=s:a>0&&(o.ySize=s)}else e.hasAutoSize()?o.xSize=Math.max(s-n.getOuterSize(),0):n.hasAutoSize()&&(o.ySize=Math.max(s-e.getOuterSize(),0));else e?e.hasAutoSize()&&(o.xSize=s):n&&n.hasAutoSize()&&(o.ySize=s);return o}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,n,s,o,r)}},Dr=class{constructor(t,e,n,s,o){this.container=t;this.isHorizontal=n;this.clientLayout=o;p(this,"hasAutoSize_");p(this,"size",null);p(this,"minMaxFitContent",null);let r=e[n?"width":"height"];if(this.hasAutoSize_=!r||r===S.auto||W(r),this.minMaxFitContent=r instanceof Q&&(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=gr(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()}},wf=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}},Kc=class extends Dr{constructor(e,n,s,o,r,a){super(e,n,s,o,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()}},Pf=class extends $n{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 o in n)o.match(/^background-/)&&(this.cascaded[o]=n[o]);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,o=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=s[l].toExpr(o,null),u=he(o,n[l],c),d=he(o,n[`margin-${r}`],c),h=he(o,n[`margin-${a}`],c),f=kt(o,n[`padding-${r}`],c),g=kt(o,n[`padding-${a}`],c),m=En(o,n[`border-${r}-width`],n[`border-${r}-style`],c),b=En(o,n[`border-${a}-width`],n[`border-${a}-style`],c),y=K(o,K(o,m,f),K(o,b,g)),C,N,x;return u?(this.borderBoxSizing?(N=u,x=ae(o,N,y)):(x=u,N=K(o,x,y)),C=ae(o,c,N),!d&&!h?(d=Xo(o,C,new we(o,.5)),h=d):d?h=ae(o,C,d):d=ae(o,C,h)):(d||(d=o.zero),h||(h=o.zero),C=K(o,d,h),N=ae(o,c,C),x=ae(o,N,y),u=this.borderBoxSizing?N:x),n[r]=new D(d),n[a]=new D(h),n[`margin-${r}`]=me,n[`margin-${a}`]=me,n[`border-${r}-width`]=new D(m),n[`border-${a}-width`]=new D(b),n[`padding-${r}`]=new D(f),n[`padding-${a}`]=new D(g),n[l]=new D(u),n[`max-${l}`]=new D(u),{borderBoxExtent:N,contentBoxExtent:x,marginStart:d,marginEnd:h}}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,n,s,o,r)}},ha=class extends $n{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 kn(n,e.left.toExpr(n,null))),t["margin-right"]=new D(new kn(n,e.right.toExpr(n,null))),t["border-left-width"]=e.left,t["border-right-width"]=e.right,t["border-left-style"]=S.solid,t["border-right-style"]=S.solid,t["border-left-color"]=S.transparent,t["border-right-color"]=S.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 kn(n,e.top.toExpr(n,null))),t["margin-bottom"]=new D(new kn(n,e.bottom.toExpr(n,null))),t["border-top-width"]=e.top,t["border-bottom-width"]=e.bottom,t["border-top-style"]=S.solid,t["border-bottom-style"]=S.solid,t["border-top-color"]=S.transparent,t["border-bottom-color"]=S.transparent}prepareContainer(t,e,n,s,o){e.element.setAttribute("data-vivliostyle-page-area",!0),n.pageAreaElement=e.element,super.prepareContainer(t,e,n,s,o),t.pageAreaWidth=e.width,t.pageAreaHeight=e.height}},fa=class extends $n{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=Hf[s];let o=e;o.pageMarginBoxInstances[s]=this}prepareContainer(e,n,s,o,r){n.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,n.element),super.prepareContainer(e,n,s,o,r)}applyVerticalAlign(e,n){P(n,"display","flex"),P(n,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let s=this.getProp(e,"vertical-align"),o=null;s===R("middle")?o="center":s===R("top")?o="flex-start":s===R("bottom")&&(o="flex-end"),o&&P(n,"justify-content",o);let r=this.getProp(e,"content");if(this.vertical||r instanceof ke||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")),P(n,"align-items",a)}}positionAlongVariableDimension(e,n){let s=this.style,o=this.pageBox.scope,r=e.start,a=e.end,l=e.extent,c=r==="left",u=c?n.borderBoxWidth:n.borderBoxHeight,d=he(o,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[r]=new D(h);else if(d){let f=kt(o,s[`margin-${r}`],u),g=kt(o,s[`margin-${a}`],u),m=kt(o,s[`padding-${r}`],u),b=kt(o,s[`padding-${a}`],u),y=En(o,s[`border-${r}-width`],s[`border-${r}-style`],u),C=En(o,s[`border-${a}-width`],s[`border-${a}-style`],u),N=K(o,d,K(o,this.borderBoxSizing?o.zero:K(o,K(o,m,b),K(o,y,C)),K(o,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[r]=new D(K(o,h,Qr(o,ae(o,u,N),new we(o,2))));break;case"end":s[r]=new D(ae(o,K(o,h,u),N));break}}}positionAndSizeAlongFixedDimension(e,n){let s=this.style,o=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=Sf(o,s[`margin-${a}`],u),h=Sf(o,s[`margin-${l}`],u),f=kt(o,s[`padding-${a}`],u),g=kt(o,s[`padding-${l}`],u),m=En(o,s[`border-${a}-width`],s[`border-${a}-style`],u),b=En(o,s[`border-${l}-width`],s[`border-${l}-style`],u),y=he(o,s[c],u),C=null;function N(x){if(C)return C;C={extent:y?y.evaluate(x):null,marginInside:d?d.evaluate(x):null,marginOutside:h?h.evaluate(x):null};let E=u.evaluate(x),v=0;return r||[m,f,g,b].forEach(T=>{T&&(v+=T.evaluate(x))}),(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 D(new ne(o,function(){let x=N(this).extent;return x===null?"auto":x},c)),s[`margin-${a}`]=new D(new ne(o,function(){let x=N(this).marginInside;return x===null?"auto":x},`margin-${a}`)),s[`margin-${l}`]=new D(new ne(o,function(){let x=N(this).marginOutside;return x===null?"auto":x},`margin-${l}`)),a==="left"?s.left=new D(K(o,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new D(K(o,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,o,r,a,l){super.finishContainer(e,n,s,o,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 Q&&(f.name==="min-content"||f.name==="max-content"||f.name==="fit-content")?f.name:null,m=this.getPropAsNumber(e,"min-width"),b=this.getPropAsNumber(e,"max-width");if(g||m||b){g&&P(n.element,"width",g),m&&P(n.element,"min-width",`${m}px`),b&&P(n.element,"max-width",`${b}px`);let E=this.getProp(e,"margin-left"),v=this.getProp(e,"margin-right");if(d.isInLeftColumn){let T=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);P(n.element,"right",`${T}px`),(E===S.auto||v!==S.auto)&&P(n.element,"margin-left","auto"),v===S.auto&&P(n.element,"margin-right","auto")}else d.isInRightColumn&&(P(n.element,"right","0"),(v===S.auto||E!==S.auto)&&P(n.element,"margin-right","auto"),E===S.auto&&P(n.element,"margin-left","auto"))}let y=this.getProp(e,"height"),C=y instanceof Q&&(y.name==="min-content"||y.name==="max-content"||y.name==="fit-content")?y.name:null,N=this.getPropAsNumber(e,"min-height"),x=this.getPropAsNumber(e,"max-height");if(C||N||x){C&&P(n.element,"height",C),N&&P(n.element,"min-height",`${N}px`),x&&P(n.element,"max-height",`${x}px`);let E=this.getProp(e,"margin-top"),v=this.getProp(e,"margin-bottom");if(d.isInTopRow){let T=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);P(n.element,"bottom",`${T}px`),(E===S.auto||v!==S.auto)&&P(n.element,"margin-top","auto"),v===S.auto&&P(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(P(n.element,"bottom","0"),(v===S.auto||E!==S.auto)&&P(n.element,"margin-bottom","auto"),E===S.auto&&P(n.element,"margin-top","auto"))}}},Zc=class{constructor(t,e,n,s,o){this.pageScope=e;this.rootPageBoxInstance=n;this.context=s;this.docElementStyle=o;p(this,"pageMasterCache",{});p(this,"pageCascadeInstance");this.pageCascadeInstance=t,this.definePageProgression()}definePageProgression(){let t=this.pageScope,e=this.context,n=e.isVersoFirstPage,s=new Se(t,"page-number"),o=new Cs(t,new $o(t,s,new we(t,2)),n?t.one:t.zero);t.defineName("recto-page",new $t(t,o)),t.defineName("verso-page",o),(e.pageProgression||_f(this.docElementStyle))==="ltr"?(t.defineName("left-page",o),t.defineName("right-page",new $t(t,o))):(t.defineName("left-page",new $t(t,o)),t.defineName("right-page",o))}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),o=this.pageMasterCache[s];return o||(n.pseudoName===aa?o=this.generatePageRuleMaster(e):o=this.generateCascadedPageMaster(e,n),this.pageMasterCache[s]=o),o.pageBox.resetScope(),o}makeCacheKey(t,e){var o;let n=this.makeCascadeValueObjectKey(t),s=((o=this.context.currentLayoutPosition)==null?void 0:o.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],o;s instanceof V?o=`${s.value}`:o=this.makeCascadeValueObjectKey(s),e.push(n+o+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new la(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:Jc}),s=n.specified,o=t.size;if(o&&!W(o.value)){let a=ma(t),l=o.priority;on(s,"width",new V(a.width,l),this.context),on(s,"height",new V(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}},kf=class extends de{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}},Af=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Rf=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Lf=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},If=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ff=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Vf=class extends de{constructor(e){super();this.scope=e}apply(e){new Se(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Of=class extends zn{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}},Bf=class extends zn{constructor(e,n,s,o){super(n,s);this.scope=e;this.a=n;this.b=s;this.pageType=o}apply(e){let n=e.pageTypePageIndices[this.pageType];if(n){for(let s of n)if(this.matchANPlusB(s)){this.chained.apply(e);return}}}getPriority(){return 3}},Df=class extends Eo{constructor(t,e){super(t,e,null,null,null)}apply(t){xE(t.context,t.currentStyle,this.style,this.specificity,t)}};function xE(i,t,e,n,s){Ri(i,t,e,n,null,null,null);let o=e[da];if(o){let a=Yt(t,da);for(let l in o)if(o.hasOwnProperty(l)){let c=a[l];c||(c={},a[l]=c),Ri(i,c,o[l],n,null,null,null)}}let r=e[pa];if(r){let a=Yt(t,pa);for(let l in r)if(r.hasOwnProperty(l)){let c=a[l];c||(c={},a[l]=c);let u=r[l];for(let h in u)if(u.hasOwnProperty(h)&&h!=="_pseudos"){let f=u[h];f instanceof V&&on(c,h,f)}let d=it(u,"_pseudos");if(d){let h=Yt(c,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=h[f];g||(g={},h[f]=g);let m=d[f];for(let b in m)if(m.hasOwnProperty(b)){let y=m[b];y instanceof V&&on(g,b,y)}}}}}}var Qc=class extends as{constructor(e,n,s,o,r){super(e,n,s==null?void 0:s.condition,s,null,o,!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 kf(n)),this.specificity+=65536)}pseudoclassSelector(e,n){if(e=e.toLowerCase(),n)switch(e){case"nth":{let s=n[0],o=n[1];if(n.length===3&&typeof n[2]=="string"){let r=n[2];this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o} of ${r})`),this.chain.push(new Bf(this.scope,s,o,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o})`),this.chain.push(new Of(this.scope,s,o)),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 Af(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Rf(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Lf(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new If(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Ff(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Vf(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 o=ee(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(a=>{Hn(r[a],e,o)});else if(e==="size"){let a=r[""];this.currentPageSelectors.forEach(l=>{let c=new V(o.value,o.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=r[u];d?on(d,e,c):(d=r[u]={},Hn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&Hn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Df(this.elementStyle,e)}startFootnoteRule(e){let n=Yt(this.elementStyle,pa),s=n.area;if(s||(s={},n.area=s),e){let r=Yt(s,"_pseudos"),a=r[e];a||(a={},r[e]=a),s=a}let o=new ga(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}startPageMarginBoxRule(e){let n=Yt(this.elementStyle,da),s=n[e];s||(s={},n[e]=s);let o=new Mf(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}},Mf=class extends nn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.boxStyle=o}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 o=s?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(n,o);Hn(this.boxStyle,e,r)}},ga=class extends nn{constructor(e,n,s,o){super(e,n,!1);this.validatorSet=s;this.areaStyle=o}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 o=s?this.getImportantSpecificity():this.getBaseSpecificity(),r=new V(n,o);Hn(this.areaStyle,e,r)}};var vn=!0;function wb(i){vn=i}var Fo=[];function Tb(i,t){return i===t||(i.src||t.src?i.src===t.src:i.textContent===t.textContent)}function Pb(i){let t=Array.from(i.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(i.querySelectorAll("head > script, body > script")).filter(e=>!t.includes(e))}function eu(i,t,e){if(!vn)return w(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&Pb(i.ownerDocument).includes(i))return w(!1);let n=i.textContent,s=i.src,o=i.type==="module",r=s&&s.includes("/MathJax.js");if(r){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return w(!0);t.MathJax||(t.MathJax={MathML:{extensions:["content-mathml.js"]},showProcessingMessages:!1,messageStyle:"none",skipStartupTypeset:!0,CommonHTML:{linebreaks:{automatic:!0}},"fast-preview":{disabled:!0},AuthorInit:function(){t.MathJax.Hub.processSectionDelay=0}})}let a=(o||s)&&i.async&&!r,l=(o&&!a||s&&i.defer)&&!r,c=!(e!=null&&e.atEnd)&&((e==null?void 0:e.forceDefer)||l||a);if(zf(t)||(t.onload=null),c)return Fo.some(d=>Tb(d,i))||Fo.push(i),w(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Tb(d,i)&&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 i.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(B.debug("script:",s),s){let d=Xt(u);return t.document.head.appendChild(u),Cn([d])}else return t.document.head.appendChild(u),w(!0)}function EE(i,t){var o;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 Eo)n(r.style);else if(r instanceof rs||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 i.querySelectorAll("[style]"))(o=r.style)!=null&&o.fontFamily&&(e[r.style.fontFamily]=!0);return Object.keys(e).join(",")}function vE(i,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=EE(i,e),n.textContent=i.documentElement.textContent,t.document.body.appendChild(n),n}function kb(i,t,e){if(!vn)return w(!1);let n=Pb(i);if(n.length===0)return w(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),o=s?vE(i,t,e):null,r=t.document.fonts,a=t.$,l=!1,c=I("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?w(!0):w(!1)}):w(!1);let u=n.shift();return eu(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Fo.push(u),l=!0),n.length===0&&s&&(B.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),w(!0)))}).then(()=>{o&&o.remove(),c.finish(!0)}),c.result()}function Ab(i){if(!vn)return w(!1);let t=I("loadScripts");return t.loop(()=>Fo.length===0?w(!1):eu(Fo.shift(),i,{atEnd:!0}).thenReturn(Fo.length>0)).then(()=>{B.debug("dispatchEvent: DOMContentLoaded (window)"),i.dispatchEvent(new Event("DOMContentLoaded")),B.debug("dispatchEvent: load (window)"),i.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function zf(i){return vn?Fo.length>0||!!i.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Rb=(i,t,e)=>i.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 TE={};function wE(i){i.addEventListener("load",()=>{i.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 $s=class $s extends gs{constructor(e,n,s,o,r,a,l,c,u,d,h,f,g,m,b,y=new Map,C={value:!1}){super();this.flowName=e;this.context=n;this.viewport=s;this.styler=o;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;this.pageProps=m;this.cascadedPageStyle=b;this.semanticFootnoteFirstRefOffsets=y;this.semanticFootnoteFirstRefOffsetsInitialized=C;p(this,"document");p(this,"exprContentListener");p(this,"computedStyleParentFontSizeOverride",null);p(this,"computedStyleParentLineHeightOverride",null);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=o.counterListener.getExprContentListener()}clone(){return new $s(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}syncSemanticFootnoteCounterToTarget(e){if(e.localName!=="a"||!bt(e)||!np(e,this.xmldoc.url,o=>this.xmldoc.getElementOffset(o),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let n=e.getAttribute(Pr);if(!n)return;let s=tp(e,this.xmldoc.url,o=>this.xmldoc.getElement(o));s&&s.setAttribute(Pr,n)}createPseudoelementShadow(e,n,s,o,r,a,l,c){var y,C;let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=No.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h,g=bt(e)&&!!u["footnote-call"]&&nt((y=u["footnote-call"].content)==null?void 0:y.value);for(let N of AC){let x;if(N){if(!u[N])continue;let E=rt(e),v=e.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&e.localName==="include"&&e.classList.contains("-vivliostyle-footnote-content");if(N=="footnote-call"&&!bt(e)||N=="footnote-marker"&&!(E||v||n&&this.isFootnote)&&!((C=this.nodeContext)!=null&&C.pluginProps.nestedFootnoteDetached))continue;if(N.match(/^first-/)){let T=o.display;if(!T||T===S.inline)continue;let k=e.firstElementChild;if(k&&pe(k.previousSibling)){let L=r.getStyle(k,!1);if(L){let M=ee(L,"display");if(M!=null&&M.value&&M.value!==S.inline)continue}}}if(N==="before"||N==="after"||N==="footnote-call"||N==="footnote-marker"){let T=u[N].content,k=(N==="before"||N==="after")&&(o.float===S.footnote||E||v)&&!!T;if(!T||!nt(T.value)&&!k)continue}d.push(N),x=No.createElementNS("http://www.w3.org/1999/xhtml","span"),To(x,N)}else{if(g)continue;x=No.createElementNS("http://www.pyroxy.com/ns/shadow","content")}f.appendChild(x),N.match(/^first-/)&&(f=x)}if(!d.length)return c;let m=new Ar(e,s,r,a,this.exprContentListener),b=new Is(e,h,null,l,c,tt.ROOTLESS,m);return c||b}getPseudoMap(e,n,s,o,r){let a=it(e,"_pseudos");if(!a)return null;let l={};for(let c in a){let u=l[c]={};kr(u,a[c],r),Ql(u,r,a[c]),rh(a[c],n,s,(d,h)=>{kr(u,h,r),oh(h,f=>{kr(u,f,r)})})}return l}createRefShadow(e,n,s,o,r){let a=I("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 Is(s,u,c,o,r,n,d)}}a.finish(r)}),a.result()}createShadows(e,n,s,o,r,a,l){let c=I("createShadows"),u=null,d=o.template,h;if(d instanceof ke||d===S.footnote)if(d!==S.footnote||np(e,this.xmldoc.url,f=>this.xmldoc.getElementOffset(f),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let f=d instanceof ke?d.url:te("user-agent.xml#footnote",cn);h=this.createRefShadow(f,tt.ROOTLESS,e,l,u)}else h=w(u);else h=w(u);return h.then(f=>{let g=null;if(e.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&e.localName=="include"){let b=e.getAttribute("href"),y=null;b?y=l?l.xmldoc:this.xmldoc:l&&(l.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?b=l.owner.getAttribute("href"):b=l.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),y=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),b&&(b=Ks(b,y.url),g=this.createRefShadow(b,tt.ROOTED,e,l,f))}g==null&&(g=w(f));let m=null;g.then(b=>{if(o.display===S.table_cell){let y=te("user-agent.xml#table-cell",cn);m=this.createRefShadow(y,tt.ROOTLESS,e,l,b)}else m=w(b);m.then(y=>{y=this.createPseudoelementShadow(e,n,s,o,r,a,l,y),c.finish(y)})})}),c.result()}setViewRoot(e,n){this.viewRoot=e,this.isFootnote=n}computeStyle(e,n,s,o){var y;let r=this.context,a=Li(s,r,this.regionIds,this.isFootnote,this.nodeContext),l=!((y=this.nodeContext)!=null&&y.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=oc(a,r,e);let u=!l&&e!==c;n=rc(a,r,n);let d=(C,N)=>{let x;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(x=r.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(x=r.pageAreaWidth));let E=N.evaluate(r,C,x,e);return C=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},h=!!new Se(r.style.pageScope,"left-page").evaluate(r);if(ic(a,o,e,n,h,d),u){let C=o[e?"height":"width"];(!C||C===S.auto)&&(o[e?"height":"width"]=S.max_content)}if(ho(o.position))return o.position=S.fixed,o.visibility=S.hidden,e;let f=o.position,g=o.float,m=o.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?S.inline:void 0),b=Rd(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(C=>{b[C]&&(o[C]=b[C])}),e}inheritFromSourceParent(e){var m,b;let n=this.nodeContext.sourceNode,s=[],o=null,r=n instanceof Element&&n.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&n.localName==="include"&&n.classList.contains("-vivliostyle-footnote-content"),a=this.isFootnote&&(!((m=this.nodeContext)!=null&&m.parent)||r),l=this.nodeContext.shadowContext;if(n instanceof Element&&n.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&n.localName==="include"&&n.classList.contains("-vivliostyle-footnote-content")){let y=l==null?void 0:l.owner;if(y instanceof Element&&bt(y)){let C=y.getAttribute("href")||y.getAttributeNS("http://www.w3.org/1999/xlink","href");if(C){let N=Ks(C,this.xmldoc.url),x=this.xmldoc.getElement(N);x&&rt(x)&&((b=x.parentNode)==null?void 0:b.nodeType)===1&&(n=x.parentNode,l=null)}}}let c=-1;for(;n&&n.nodeType==1;){let y=l&&l.root==n,C=!!y&&l.type==tt.ROOTED&&rt(n);if(!y||l.type==tt.ROOTLESS||C){let x=(l?l.styler:this.styler).getStyle(n,!1);s.push(x),o=o||$r(n)}y&&!C?(n=l.owner,l=l.parentShadow):(n=n.parentNode,c++)}let u=new Set;if(s.length>0){let y=s[0],C=Li(y,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let N in C){if(!ls(N))continue;let x=C[N].evaluate(this.context,N);x&&x!==S.inherit&&x!==S.unset&&x!==S.revert&&x!==$&&u.add(N)}}let d=c===0,h=this.context.queryUnitSize("em",d),f={"font-size":new V(new A(h,"px"),0)};d&&(f["line-height"]=new V(new Ue(this.context.pref.lineHeight),0));let g=new Gl(f,this.context);for(let y=s.length-1;y>=0;--y){let C=s[y],N=[];for(let v in C)ls(v)&&N.push(v);N.sort(Wu);let x,E;for(let v of N){if(y>0&&a&&v.startsWith("--viv-marker-")||y>0&&u.has(v))continue;g.setPropName(v);let T=ee(C,v),k=T;if(T.value===S.initial)delete f[v];else if(!W(T.value)){if(v==="font-size"&&y===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)k=new V(new A(this.context.rootFontSize,"px"),T.priority);else if(v==="line-height"&&y===s.length-1&&this.context.rootLineHeight&&T.value instanceof A&&(T.value.unit==="lh"||T.value.unit==="rlh"))k=new V(new A(this.context.rootLineHeight,"px"),T.priority);else if(y===0&&T.value instanceof A&&T.value.unit==="lh"){let L=this.getLineHeightUnitSize(v,x,E);L!=null&&(k=new V(new A(T.value.num*L,"px"),T.priority))}else Dt(v)||(k=T.filterValue(g));v==="font-size"?x=k.value:v==="line-height"&&(E=k.value),f[v]=k}}}for(let y in e)ls(y)||(f[y]=e[y]);return{lang:o,elementStyle:f}}resolveURL(e){return e=te(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=$r(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=cC().filter(s=>e[s]);if(n.length){let s=this.nodeContext.inheritedProps;if(this.nodeContext.parent){s=this.nodeContext.inheritedProps={};for(let o in this.nodeContext.parent.inheritedProps)s[o]=this.nodeContext.parent.inheritedProps[o]}n.forEach(o=>{let r=e[o];if(r){if(W(r))r===S.initial&&(s[o]=void 0);else if(r instanceof ce)s[o]=r.num;else if(r instanceof Q)s[o]=r.name;else if(r instanceof A){let a=r;switch(a.unit){case"dpi":case"dpcm":case"dppx":s[o]=a.num*ct[a.unit];break;default:s[o]=r}}else s[o]=r;["widows","orphans"].includes(o)||delete e[o]}})}}resolveFormattingContext(e,n,s,o,r,a){let l=Je("RESOLVE_FORMATTING_CONTEXT");for(let c=0;c<l.length;c++){let u=l[c](e,n,s,o,r,a);if(u){e.formattingContext=u;return}}}createElementView(e,n){var N,x;let s=!0,o=I("createElementView"),r=this.sourceNode,a=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=a.getStyle(r,!1);if(this.syncSemanticFootnoteCounterToTarget(r),!this.nodeContext.shadowContext){let E=this.xmldoc.getElementOffset(r);Bs.registerFragmentIndex(E,this.nodeContext.fragmentIndex,0)}let c={},u={getStyle:E=>this.styler.getStyle(E,!1),getProp:(E,v)=>E?ee(E,v):null,getStyleMap:(E,v)=>it(E,v),getMutableStyleMap:(E,v)=>Yt(E,v),createCascadeValue:(E,v)=>new V(E,v),filterFootnoteMarkerContent:(E,v)=>E.filterValue(new is(this.styler.cascade,v,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let E=this.inheritFromSourceParent(l);l=E.elementStyle,this.nodeContext.lang=E.lang}let d=l.position,h=l.float,f=l["float-reference"],g=h&&!W(h.value)&&h.value!==S.none&&f&&!W(f.value)?Qm(f.value.toString()):null,m=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===tt.ROOTED&&rt(r);if(this.nodeContext.parent&&(ho(d==null?void 0:d.value)||g&&Sn(g)||m)){let E=this.inheritFromSourceParent(l);l=E.elementStyle,this.nodeContext.lang=E.lang}l=Jm(r,l,this.nodeContext.shadowContext,this.xmldoc.url,E=>this.xmldoc.getElement(E),Pr,u),l=eC(r,l,this.nodeContext.shadowContext,this.context,u),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),g&&Sn(g)&&c.display===S.block&&(c.display=S.flow_root),a.processContent(r,c,this.nodeContext),this.transferPolyfilledInheritedProps(c),this.inheritLangAttribute(),c.direction&&(this.nodeContext.direction=c.direction.toString());let b=c["flow-into"];if(b&&b.toString()!=this.flowName)return o.finish(!1),o.result();if(vn&&r.localName==="script"&&r.namespaceURI==="http://www.w3.org/1999/xhtml")return eu(r,this.viewport.window).thenFinish(o),o.result();let y=c.display;if(rt(r)&&!m&&r.hasAttribute(Jd)&&(y=c.display=S.none),W(y)&&(y===S.initial||y===S.unset?y=S.inline:y===S.inherit?y=((N=this.nodeContext.parent)==null?void 0:N.display)&&R((x=this.nodeContext.parent)==null?void 0:x.display):y=null),y===S.none)return o.finish(!1),o.result();let C=this.nodeContext.parent==null;return this.nodeContext.flexContainer=y===S.flex,this.createShadows(r,C,l,c,a,this.context,this.nodeContext.shadowContext).then(E=>{var ng;this.nodeContext.nodeShadow=E;let v=c.position,T=c.float,k=c.clear,L=this.nodeContext.vertical?S.vertical_rl:S.horizontal_tb,M=this.nodeContext.parent?this.nodeContext.parent.vertical?S.vertical_rl:S.horizontal_tb:L,q=fm(r),J=c["column-count"],re=c["column-width"],xe=J&&J!==S.auto&&!W(J)||re&&re!==S.auto&&!W(re);this.nodeContext.establishesBFC=mm(y,v,T,c.overflow,L,M,xe||q),this.nodeContext.containingBlockForAbsolute=Cm(v),this.nodeContext.isInsideBFC()&&T!==S.footnote&&!(g&&Sn(g))&&(T=null,k=null);let le=null,F=!1,U=this.isFootnote&&(!((ng=this.nodeContext)!=null&&ng.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||m),j=tC(r,this.nodeContext.shadowContext,u);sC(j.sourceStyle,c,this.context),le=j.footnoteDisplay;let H=T instanceof X||T===S.left||T===S.right||T===S.top||T===S.bottom||T===S.inline_start||T===S.inline_end||T===S.block_start||T===S.block_end||T===S.snap_block||T===S.snap_inline||T===S.inside||T===S.outside||T===S.footnote;if(T&&(delete c.float,T===S.footnote))if(le=c["footnote-display"]||le,F=!!c["--viv-marker-content"],U){H=!1;let G=le==null?void 0:le.toString();G&&(c["--viv-footnote-display"]=R(G)),y=F?R("list-item"):G==="inline"||G==="compact"?S.inline:S.block,c.display=y}else c.display=S.inline;if(U&&rt(r)){F=F||!!c["--viv-marker-content"];let G=le==null?void 0:le.toString();G&&(c["--viv-footnote-display"]=R(G)),F&&(y=c.display=R("list-item")),!F&&(G==="inline"||G==="compact")&&(y=c.display=S.inline)}k&&(k===S.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(k=R(this.nodeContext.parent.clearSide)),(k===S.left||k===S.right||k===S.top||k===S.bottom||k===S.inline_start||k===S.inline_end||k===S.block_start||k===S.block_end||k===S.inside||k===S.outside||k===S.both||k===S.all||k===S.same||k===S.column||k===S.region||k===S.page)&&(delete c.clear,(H||c.display&&c.display!=S.inline)&&(this.nodeContext.clearSide=k.toString())));let _=fo(y)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),Y=c["break-inside"];(H||Y&&!W(Y)&&Y!==S.auto)&&this.nodeContext.breakPenalty++,y&&y!==S.inline&&Et(y)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!H&&!y||Et(y)||bl(y),this.nodeContext.display=y?y.toString():"inline",this.nodeContext.floatSide=H?T.toString():null,this.nodeContext.floatReference=g||ue.INLINE;let Ee=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=Ee&&!W(Ee)?Ee:null;let Ve=this.isInsideNonRootMultiColumn(),Oo=c["column-span"];if(this.nodeContext.columnSpan=!Ve&&Oo&&!W(Oo)?Oo:null,!this.nodeContext.inline){let G=c["break-after"];G&&!W(G)&&!(Ve&&G===S.column)&&(this.nodeContext.breakAfter=G.toString(),Nl[this.nodeContext.breakAfter]&&(c["break-after"]=S.column));let At=c["break-before"];At&&!W(At)&&!(Ve&&At===S.column)&&(this.nodeContext.breakBefore=At.toString(),Nl[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=S.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Qt=c.page,Rt=Qt&&!W(Qt)&&Qt.toString();!Rt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||y===S.table_header_group||y===S.table_footer_group)&&(Rt=this.styler.cascade.currentPageType),!Rt||Rt.toLowerCase()==="auto"?Rt=this.nodeContext.pageType:this.nodeContext.pageType=Rt,this.styler.cascade.currentPageType!==Rt&&!(!Rt&&c.position===S.fixed)&&(this.nodeContext.fragmentIndex===1&&!ts(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Rt!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Rt)}this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let Mr=c["border-collapse"];if(!Mr||Mr===R("separate")){let G=c["border-spacing"],At,Qt;G&&(G instanceof X?(At=G.values[0],Qt=G.values[1]):At=Qt=G,At.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Ye(At,this.context)),Qt.isNumeric()&&(this.nodeContext.blockBorderSpacing=Ye(Qt,this.context)))}let fs=c["footnote-policy"]||j.footnotePolicy;fs&&!W(fs)&&(c["--viv-footnote-policy"]=fs),this.nodeContext.footnotePolicy=fs&&!W(fs)?fs:null;let Ea=c["x-first-pseudo"];if(Ea){let G=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Rl(G,Ea.num)}this.nodeContext.inline||this.processAfterIfcontinues(r,l,a,this.context);let Nn=c["white-space"];if(Nn){let G=Vl(Nn.toString());G!==null&&(this.nodeContext.whitespace=G)}let mu=c["hyphenate-character"];mu&&mu instanceof z&&(this.nodeContext.hyphenateCharacter=mu.str);let $b=c["word-break"],Wb=c["line-break"],tg=c["overflow-wrap"];($b===S.break_all||Wb===S.anywhere||tg===S.break_word||tg===S.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,y,v,T,C),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 Xs=!1,Cu=null,_r=[],ln=r.namespaceURI,ie=r.localName,va=ie;ln=="http://www.w3.org/1999/xhtml"?(ie=="html"||ie=="body"||ie=="script"||ie=="link"||ie=="meta"?ie="div":ie=="vide_"?ie="video":ie=="audi_"?ie="audio":ie=="object"&&(Xs=!!this.customRenderer),r.hasAttribute(ac)&&r.hasAttribute("src")&&c.content instanceof ke&&(ie="img")):ln=="http://www.idpf.org/2007/ops"?(ie="span",ln="http://www.w3.org/1999/xhtml"):ln=="http://www.pyroxy.com/ns/shadow"?(ln="http://www.w3.org/1999/xhtml",ie=this.nodeContext.inline?"span":"div"):Xs=!!this.customRenderer,_?e?(ie="li",c["--viv-marker-content"]&&(c["list-style-type"]=S.none,c["list-style-image"]=S.none)):(y=Et(y)?S.inline:S.block,c.display=y,ie="div"):ie=="body"||ie=="li"?ie="div":ie=="q"&&(ie="span"),c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(Xs=!0),r.dataset&&r.getAttribute("data-math-typeset")==="true"&&(Xs=!0);let bu;if(Xs){let G=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;bu=this.customRenderer(r,G,c)}else bu=w(null);bu.then(G=>{var rg,ig,ag;if(G)Xs&&(s=G.getAttribute("data-adapt-process-children")=="true");else if(c.display===S.none){o.finish(!1);return}else G=this.createElement(ln,ie);if(!C&&xe&&c["column-fill"]===S.auto){let Qe=this.nodeContext.vertical?c.width:c.height;(!Qe||Qe===S.auto||W(Qe))&&(G.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=S.balance)}ie!=va&&(G.setAttribute("data-vivliostyle-original-tag",va),(va==="html"||va==="body")&&(G.role="presentation")),ie=="a"&&G.addEventListener("click",this.page.hrefHandler,!1),Cu&&(this.applyPseudoelementStyle(this.nodeContext,"inner",Cu),G.appendChild(Cu)),G.localName=="iframe"&&G.namespaceURI=="http://www.w3.org/1999/xhtml"&&wE(G);let At=this.nodeContext.inheritedProps["image-resolution"],Qt=[],Rt=c.width,yu=c.height,Xb=r.getAttribute("width"),jb=r.getAttribute("height"),Su=Rt===S.auto||!Rt&&!Xb,xu=yu===S.auto||!yu&&!jb,sg=r.attributes,Yb=sg.length,Na=null,og=null;y===S.table_cell&&((ag=(ig=(rg=this.nodeContext.parent)==null?void 0:rg.viewNode)==null?void 0:ig.lastElementChild)==null?void 0:ag.localName)==="a"&&G.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Qe=0;Qe<Yb;Qe++){let Lt=sg[Qe],It=Lt.namespaceURI,ye=Lt.localName,Ae=Lt.nodeValue;if(It){if(It=="http://www.w3.org/2000/xmlns/")continue;It=="http://www.w3.org/1999/xlink"&&ye=="href"&&(Ae=this.documentURLTransformer.transformURL(this.resolveURL(Ae),this.xmldoc.url))}else{if(!vn&&ye.match(/^on/)||ye=="style")continue;if((ye=="id"||ye=="name")&&e){let pt=this.documentURLTransformer.transformFragment(Ae,this.xmldoc.url);G.setAttribute(ye,Ae),G.setAttribute("data-vivliostyle-id",pt);let Ht=G.ownerDocument.createElement("a");Ht.setAttribute(ye,pt),Ht.setAttribute(Fn,"1"),Ht.style.position="absolute",G.appendChild(Ht),this.page.registerElementWithId(G,pt);continue}if(ye=="src"||ye=="href"||ye=="poster")Ae=this.resolveURL(Ae),ye==="href"&&(Ae=this.documentURLTransformer.transformURL(Ae,this.xmldoc.url));else if(ye=="srcset")Ae=Ae.split(",").map(pt=>this.resolveURL(pt.trim())).join(",");else if(ye==="data"&&Xs&&ie==="object"&&G.hasAttribute("data"))continue;if(ye==="poster"&&ie==="video"&&ln==="http://www.w3.org/1999/xhtml"&&Su&&xu){let pt=new Image,Ht=Xt(pt,Ae);_r.push(Ht),Qt.push({image:pt,element:G,fetcher:Ht})}}if(ln=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ye)&&(ye=ye.toLowerCase()),this.isSVGUrlAttribute(ye)&&(Ae=Rb(Ae,this.xmldoc.url,this.documentURLTransformer)),It){let pt=TE[It];pt&&(ye=`${pt}:${ye}`)}if(ye=="src"&&!It&&(ie=="img"||ie=="input")&&ln=="http://www.w3.org/1999/xhtml")Na=Ae;else if(ye=="alt"&&!It&&ie=="img"&&ln=="http://www.w3.org/1999/xhtml")og=Ae;else if(ye=="href"&&ie=="image"&&ln=="http://www.w3.org/2000/svg"&&It=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Xt(G,Ae));else if(It)G.setAttributeNS(It,ye,Ae);else try{G.setAttribute(ye,Ae)}catch(pt){B.warn(pt)}}if(Na){let Qe=ie==="input"?new Image:G,Lt=Xt(Qe,Na,og);Qe!==G&&(G.src=Na);let It=()=>{var Ae,pt;if(c.position===S.fixed)return!0;for(let Ht=(Ae=this.nodeContext.parent)==null?void 0:Ae.viewNode;Ht&&Ht!==this.viewRoot;Ht=Ht.parentElement)if(((pt=Ht.style)==null?void 0:pt.position)==="fixed")return!0;return!1};!Su&&!xu&&!(()=>{let Ae=this.nodeContext.vertical?Rt:yu;return Ae instanceof A&&Ae.unit==="%"})()&&!It()?this.page.fetchers.push(Lt):(Su&&xu&&At&&At!==1&&Qt.push({image:Qe,element:G,fetcher:Lt}),_r.push(Lt))}delete c.content;let Ta=c["--viv-marker-content"];if(Ta){let Qe=Ta instanceof X?Ta.values:[Ta];for(let Lt of Qe)Lt instanceof ke&&Lt.url&&_r.push(Xt(new Image,Lt.url))}if(this.preprocessElementStyle(c),this.applyComputedStyles(G,c),this.nodeContext.inline)e||(mt(G,"inline-start"),Ps(G)&&mt(G,"clone"));else if(e){if(!ur(c.position)){let Qe=c["margin-break"],Lt=this.getBreakTypeAt(this.nodeContext),It=Lt!==null,ye=Lt==="auto";(Qe===S.discard&&It||Qe!==S.keep&&ye&&!this.nodeContext.floatSide)&&vl(G,"block-start")}}else{let Qe=this.nodeContext.vertical?"width":"height";un(G,Qe)&&P(G,Qe,this.nodeContext.display==="table-row"?"0.01px":""),mt(G,"block-start"),Ps(G)&&mt(G,"clone"),vl(G,"block-start")}_&&c["ua-list-item-count"]&&G.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=G,_r.length?Cn(_r).then(()=>{At>0&&this.modifyElemDimensionWithImageResolution(Qt,At,c,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var e,n;for(let s=this.nodeContext;s!=null&&s.parent&&!s.after;s=s.parent){let o=s===this.nodeContext&&!s.viewNode?(e=s.parent.viewNode)==null?void 0:e.lastChild:(n=s.viewNode)==null?void 0:n.previousSibling;for(;o&&(pe(o,s.parent.whitespace)||Vn(o));)o=o.previousSibling;if(o)return!1}return!0}isInsideNonRootMultiColumn(){var n;let e=(n=this.nodeContext.parent)==null?void 0:n.viewNode;return!!(e&&fr(e))}getBreakTypeAt(e){var s,o,r,a,l;if(this.isInsideTable(e))return null;for(let c=e;c&&!c.after;c=c.parent){if(Ne(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=(o=c.parent)==null?void 0:o.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&&(pe(g,c.parent.whitespace)||!c.floatSide&&Vn(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 Ne(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,o){let r=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let a=new Ar(e,n,s,o,this.exprContentListener);this.nodeContext.afterIfContinues=new lc(e,a)}}isSVGUrlAttribute(e){return $s.SVG_URL_ATTRIBUTES.includes(e.toLowerCase())}modifyElemDimensionWithImageResolution(e,n,s,o){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"]===S.border_box&&(s["border-left-style"]!==S.none&&(l+=Ye(s["border-left-width"],this.context)),s["border-right-style"]!==S.none&&(l+=Ye(s["border-right-width"],this.context)),s["border-top-style"]!==S.none&&(c+=Ye(s["border-top-width"],this.context)),s["border-bottom-style"]!==S.none&&(c+=Ye(s["border-bottom-width"],this.context))),n>1){let d=s["max-width"]||S.none,h=s["max-height"]||S.none;if(d===S.none&&h===S.none)P(u,"max-width",`${l}px`);else if(d!==S.none&&h===S.none)P(u,"width",`${l}px`);else if(d===S.none&&h!==S.none)P(u,"height",`${c}px`);else{d.isNumeric(),h.isNumeric();let f=d,g=h;f.unit!=="%"?P(u,"max-width",`${Math.min(l,Ye(f,this.context))}px`):g.unit!=="%"?P(u,"max-height",`${Math.min(c,Ye(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||me,h=s["min-height"]||me;d.isNumeric(),d.isNumeric();let f=d,g=h;f.num===0&&g.num===0?P(u,"min-width",`${l}px`):f.num!==0&&g.num===0?P(u,"width",`${l}px`):f.num===0&&g.num!==0?P(u,"height",`${c}px`):f.unit!=="%"?P(u,"min-width",`${Math.max(l,Ye(f,this.context))}px`):g.unit!=="%"?P(u,"min-height",`${Math.max(c,Ye(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){Je("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 o={},r=n.getStyle(s,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,o),!this.processRepeatOnBreak(o))continue;if(this.nodeContext.formattingContext instanceof xn&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new xn(c,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(e){let n=e["repeat-on-break"];return n!==S.none&&((n===S.auto||W(n))&&(e.display===S.table_header_group?n=S.header:e.display===S.table_footer_group?n=S.footer:n=S.none),n&&n!==S.none)?n.toString():null}createTextNodeView(){let e=I("createTextNodeView");return this.preprocessTextContent().then(()=>{let n=this.offsetInNode||0,s=Xd(this.nodeContext.preprocessedTextContent).substr(n);this.viewNode=document.createTextNode(s),e.finish(!0)}),e.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return w(!0);let e,n=e=this.sourceNode.textContent,s=I("preprocessTextContent"),o=Je("PREPROCESS_TEXT_CONTENT"),r=0;return s.loop(()=>r>=o.length?w(!1):o[r++](this.nodeContext,n).thenAsync(a=>(n=a,w(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Hm(e,n),s.finish(!0)}),s.result()}createNodeView(e,n){let s=I("createNodeView"),o,r=!0;return this.sourceNode.nodeType==1?o=this.createElementView(e,n):this.sourceNode.nodeType==8?(this.viewNode=null,o=w(!0)):o=this.createTextNodeView(),o.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&&qt(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;this.nodeContext.pluginProps.nestedFootnoteDetached&&(d=this.viewRoot),d&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&pe(this.viewNode))&&!d.hasChildNodes()&&_d(d).includes("block-start")&&mt(d,"text-start"),d.appendChild(this.viewNode),Em(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):w(!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,o=e.parent,r,a,l=s.subShadow||s.parentShadow;s.subShadow?(r=s.subShadow.root,a=s.subShadow.type,a==tt.ROOTLESS&&(r=r.firstChild)):(r=s.owner.firstChild,a=tt.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 ss(r,o,n);return u.shadowContext=l,u.shadowType=a,u.shadowSibling=e,this.processShadowContent(u)}return e.boxOffset=n,e}nextPositionInTree(e){let n=e.boxOffset+1;if(e.after){if(!e.parent)return null;if(e.shadowType!=tt.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 o=e.nodeShadow.root;if(e.nodeShadow.type==tt.ROOTLESS&&(o=o.firstChild),o){let r=new ss(o,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 ss(s,e,n));if(e.sourceNode.nodeType!=1){let o=Xd(e.preprocessedTextContent);n+=o.length-1-e.offsetInNode}return e=e.modify(),e.boxOffset=n,e.after=!0,e}}findImmediateFootnoteCallSibling(e){let n=this.xmldoc.getElementOffset(e.sourceNode),s=e.viewNode;if(!s)return null;let o=s.previousSibling;for(;o;){if(o.nodeType===Node.TEXT_NODE){if(o.textContent.trim().length===0){o=o.previousSibling;continue}return null}if(o.nodeType===Node.ELEMENT_NODE){let r=o;return qt(r)==="footnote-call"&&r.getAttribute($s.FOOTNOTE_CALL_OWNER_ATTR)===n.toString()?r:null}return null}return null}isSemanticFootnoteElement(e){let n=e.sourceNode;return n instanceof Element&&rt(n)}insertFootnoteCall(e){var l,c;let n=I("insertFootnoteCall"),s=No.createElementNS("http://www.w3.org/1999/xhtml","span");To(s,"footnote-call");let o=this.xmldoc.getElementOffset(e.sourceNode);s.setAttribute($s.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let r=new ss(s,e.parent,e.boxOffset);r.inline=!0;let a=new Ar(e.sourceNode,this.styler.getStyle(e.sourceNode,!1),this.styler,this.context,this.exprContentListener);return r.shadowContext=new Is(e.sourceNode,s,null,((l=e.parent)==null?void 0:l.shadowContext)||null,null,tt.ROOTLESS,a),r.shadowSibling=e,e.boxOffset++,(c=e.viewNode)!=null&&c.parentNode&&e.viewNode.parentNode.removeChild(e.viewNode),this.setCurrent(r,!0,!1).then(u=>{if(u&&s.hasChildNodes())n.finish(r);else{let d=r.modify();d.after=!0,r.viewNode||(d.inline=!0),n.finish(d)}}),n.result()}nextInTree(e,n){let s=this.nextPositionInTree(e);if(!s||s.after)return w(s);let o=I("nextInTree");return this.setCurrent(s,!0,n).then(r=>{if((!s.viewNode||!r)&&(s=s.modify(),s.after=!0,s.viewNode||(s.inline=!0)),s.floatSide==="footnote"&&!(this.isFootnote&&!s.parent)&&!s.after&&!s.pluginProps.footnoteCallProcessed&&!s.shadowContext&&!this.isSemanticFootnoteElement(s)){let a=this.findImmediateFootnoteCallSibling(s);a!=null&&a.parentNode&&a.parentNode.removeChild(a),this.isFootnote&&s.parent&&(s.pluginProps.nestedFootnoteDetached=1),s.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(s).then(l=>{this.dispatchEvent({type:"nextInTree",nodeContext:l}),o.finish(l)});return}this.dispatchEvent({type:"nextInTree",nodeContext:s}),o.finish(s)}),o.result()}addImageFetchers(e){if(e instanceof ve){let n=e.values;for(let s=0;s<n.length;s++)this.addImageFetchers(n[s])}else if(e instanceof ke){let n=e.url;this.page.fetchers.push(Xt(new Image,n))}}applyComputedStyles(e,n){var u,d,h;let s=n["background-image"];s&&this.addImageFetchers(s);let o=n.position===S.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(Wu);let l,c;for(let f of a){if(PE[f])continue;let g=n[f];if(!(!g||g===$&&!Dt(f))){if(g=g.visit(new rl(this.xmldoc.url,this.documentURLTransformer)),g instanceof A)if(g.unit==="em"){let m=this.getEmUnitSize(f,l);m!=null&&(g=new A(g.num*m,"px"))}else if(g.unit==="lh"){let m=this.getLineHeightUnitSize(f,l,c);m!=null&&(g=new A(g.num*m,"px"))}else ja(g.unit)&&(g=Ka(g,this.context));if((f==="font-size"||f==="line-height")&&(f==="font-size"?l=g:c=g,this.viewport.layoutUnitAdj&&g instanceof A&&g.unit!=="%"&&g.unit!=="em"&&g.unit!=="lh"&&(g=new An(`calc(${g.toString()} - var(--viv-layoutUnitAdj))`))),Wm[f]||o&&Xm[f]){this.page.delayedItems.push(new Ls(e,f,g));continue}r&&this.page.pageAreaElement&&ls(f)?(P(this.page.pageAreaElement.parentElement.parentElement,f,g.toString()),f!=="writing-mode"&&f!=="direction"&&P(this.viewport.layoutBox,f,g.toString())):P(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}getFootnoteAreaInheritedMetrics(){var r,a;let e=(a=(r=this.page.pageAreaElement)==null?void 0:r.parentElement)==null?void 0:a.parentElement,n=e?this.viewport.window.getComputedStyle(e):null,s=n&&this.parsePlusLayoutUnitAdj(n.fontSize)||this.context.rootFontSize||this.context.initialFontSize,o=n&&this.parsePlusLayoutUnitAdj(n.lineHeight)||this.context.rootLineHeight||s*this.context.pref.lineHeight;return{fontSize:s,lineHeight:o}}getComputedFontMetrics(e,n){var a,l,c;let s=this.viewport.window.getComputedStyle(e),o=(a=this.parsePlusLayoutUnitAdj(s.fontSize))!=null?a:n.fontSize,r=(c=(l=this.parsePlusLayoutUnitAdj(s.lineHeight))!=null?l:n.lineHeight)!=null?c:o!=null?o*this.context.pref.lineHeight:null;return{fontSize:o,lineHeight:r}}getParentViewStyle(){var e,n,s;return((s=(n=(e=this.nodeContext)==null?void 0:e.parent)==null?void 0:n.viewNode)==null?void 0:s.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null}getParentComputedMetrics(e){var n,s;return{fontSize:(n=this.computedStyleParentFontSizeOverride)!=null?n:e?this.parsePlusLayoutUnitAdj(e.fontSize):this.context.rootFontSize,lineHeight:(s=this.computedStyleParentLineHeightOverride)!=null?s:e?this.parsePlusLayoutUnitAdj(e.lineHeight):this.context.rootLineHeight}}getLineHeightUnitSize(e,n,s){var c,u,d;let o=this.getParentViewStyle(),r=this.getParentComputedMetrics(o),a=r.lineHeight;if(e==="line-height"||e==="font-size")return a;let l=null;if(s)if(s instanceof Ue||s instanceof A&&(s.unit==="em"||s.unit==="%"))l=s instanceof A&&s.unit==="%"?s.num/100:s.num;else{if(s instanceof A&&s.unit!=="lh"){let h=this.context.queryUnitSize(s.unit,!1);if(h!=null)return s.num*h}return null}if(l==null)for(let h=(u=(c=this.nodeContext)==null?void 0:c.parent)==null?void 0:u.viewNode;h&&h.nodeType===1;h=h.parentNode){let f=(d=h==null?void 0:h.style)==null?void 0:d.lineHeight;if(f){/^[0-9.]+$/.test(f)&&(l=parseFloat(f));break}}if(l!=null){if(n&&!(n instanceof A))return null;let h=r.fontSize;if(n instanceof A){let f=nc(n,h,this.context).num;return typeof f!="number"||isNaN(f)?null:l*f}else return h==null?null:l*h}return a}getEmUnitSize(e,n){let s=this.getParentViewStyle(),o=this.getParentComputedMetrics(s).fontSize;if(e==="font-size"||n==null)return o;if(n instanceof A){let r=nc(n,o,this.context).num;if(typeof r=="number"&&!isNaN(r))return r}return null}applyPseudoelementStyle(e,n,s){if(e.after)return;let o=this.sourceNode,a=(e.shadowContext?e.shadowContext.styler:this.styler).getStyle(o,!1),l=it(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;nt(u)&&(u.visit(new Dn(s,this.context,u,this.exprContentListener)),delete c.content),this.applyComputedStyles(s,c)}peelOff(e,n){let s=I("peelOff"),o=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===o;)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 ss(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 w(!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){var h;let o={},r=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let f=it(this.cascadedPageStyle,pa);f&&f.area&&(a=f.area)}let l=it(a,"_pseudos");e=this.computeStyle(e,n,a,o);let c=this.getFootnoteAreaInheritedMetrics();!o["font-size"]&&c.fontSize!=null&&(o["font-size"]=new A(c.fontSize,"px")),delete o.content;let u=this.computedStyleParentFontSizeOverride,d=this.computedStyleParentLineHeightOverride;this.computedStyleParentFontSizeOverride=c.fontSize,this.computedStyleParentLineHeightOverride=c.lineHeight;try{this.applyComputedStyles(s,o);let f=this.getComputedFontMetrics(s,c);if(this.computedStyleParentFontSizeOverride=f.fontSize,this.computedStyleParentLineHeightOverride=f.lineHeight,l&&l.before){let g=l.before,m=!!ee(g,"display"),b={},y=this.createElement("http://www.w3.org/1999/xhtml","span");To(y,"before"),s.appendChild(y),this.computeStyle(e,n,g,b),m||(b.display=S.block);let C=ee(g,"content");if(C){let x=((h=this.sourceNode)==null?void 0:h.nodeType)===1?this.sourceNode:this.xmldoc.root;b.content=C.filterValue(new is(this.styler.cascade,x,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let N=b.content;if(nt(N)){N.visit(new Dn(y,this.context,N,this.exprContentListener));let x=y.querySelectorAll("img[src]");for(let v=0;v<x.length;v++){let T=x[v],k=T.getAttribute("src");if(!k)continue;let L=Xt(T,k);r.push(L),this.page.fetchers.push(L)}let E=y.getAttribute("src");if(E){let v=y.querySelector("img");v||(v=this.document.createElement("img"),v.setAttribute("src",E),y.appendChild(v));let T=Xt(v,E);r.push(T),this.page.fetchers.push(T)}}delete b.content,this.applyComputedStyles(y,b)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=d}return r.length?Cn(r).thenReturn(e):w(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=ee(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!Et(u)||c.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(c.textContent)}let o=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(mt(u,"inline-end"),Ps(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;mt(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(un(u,d)&&P(u,d,""),mt(u,"block-end"),!o++&&c!==n){let{textAlign:h}=this.viewport.window.getComputedStyle(u);if(h==="justify"&&!s){let f=this.createChildAnonymousBlockIfNeeded(u);f?f!==u?Ud(f,["block-start","text-start","block-end","text-end","justify"]):(mt(u,"text-end"),mt(u,"justify")):mt(u,"text-end")}else mt(u,"text-end")}Ps(u)&&mt(u,"clone"),vl(u,"block-end")}}}fixClonedBoxDecorationOverflow(e){let n=this.viewport.window.getComputedStyle(e),s=parseFloat(n.paddingInlineEnd),o=parseFloat(n.borderInlineEndWidth),r=-(s+o);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"||Pn[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&&pe(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(Fn)){let u=r.previousElementSibling;return u&&(u.nextSibling===r||u.nextSibling===r.previousSibling&&pe(u.nextSibling))?n(u):!1}return!(!a||Et(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&&pe(s.nextSibling)))return null;let o=e.ownerDocument.createElement("span");o.className="viv-anonymous-block";for(let r=s.nextSibling,a=null;r;r=a)a=r.nextSibling,o.appendChild(r);return e.appendChild(o),o}convertLengthToPx(e,n,s){let o=e.num,r=e.unit;if(Eg(r)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,tc(e,l,this.context).num}else{let a=this.context.queryUnitSize(r,!1);return a?o*a:e}}isSameNodePositionStep(e,n){if(e.shadowContext){if(!n.shadowContext)return!1;let s=e.node.nodeType===1?e.node:e.node.parentElement,o=n.node.nodeType===1?n.node:n.node.parentElement;return e.shadowContext.owner===n.shadowContext.owner&&qt(s)===qt(o)}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,o)=>{let r=n.steps[o];return this.isSameNodePositionStep(s,r)})}isPseudoelement(e){return!!qt(e)}};p($s,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),p($s,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var tu=$s,PE={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},nu=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}},hs=class{constructor(t,e,n,s,o,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=o||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")&&(P(this.root,"--viv-outputPixelRatio",`${n}`),P(this.root,"--viv-devicePixelRatio",`${t.devicePixelRatio}`),this.scaleRatio=n/t.devicePixelRatio),Mo){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&&P(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=o||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||!o&&d)&&(this.width=u.width),(!this.height||!r&&d)&&(this.height=u.height)}resetZoom(){P(this.outerZoomBox,"width",""),P(this.outerZoomBox,"height",""),P(this.contentContainer,"width",""),P(this.contentContainer,"height",""),P(this.contentContainer,"transform","")}zoom(t,e,n){P(this.root,"--viv-outputScale",`${n}`),P(this.outerZoomBox,"width",`${t*n}px`),P(this.outerZoomBox,"height",`${e*n}px`),P(this.contentContainer,"width",`${t}px`),P(this.contentContainer,"height",`${e}px`)}clear(){let t=this.root;for(;t.lastChild;)t.removeChild(t.lastChild)}};var Ca=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,o=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":o=a;break;case"body":s=a;break}}this.lang=this.root.getAttribute("lang")}this.body=s,this.head=o,this.last=this.root,this.last.setAttribute(zt,"0")}doc(){return new ru([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 o=s.firstChild;if(!o){for(;o=s.nextSibling,!o;)if(s=s.parentNode,s==null)throw new Error("Internal error")}s=o,o.nodeType==1?(o.setAttribute(zt,n.toString()),++n):n+=o.textContent.length}return this.lastOffset=n,this.last=t,n-1}getNodeOffset(t,e,n){let s=0,o=t,r=null;if(o.nodeType==1){if(!n)return this.getElementOffset(o)}else{if(s=e,r=o.previousSibling,!r)return o=o.parentNode,s+=1,this.getElementOffset(o)+s;o=r}for(;;){for(;o.lastChild;)o=o.lastChild;if(o.nodeType==1)break;if(s+=o.textContent.length,r=o.previousSibling,!r){o=o.parentNode;break}o=r}return s+=1,this.getElementOffset(o)+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=Ft(l.length,u=>{let d=l[u];return this.getElementOffset(d)>t});if(c==0)break;n=l[c-1]}let s=e+1,o=n,r=o.firstChild||o.nextSibling,a=null;for(;;){if(r){if(r.nodeType==1||(o=r,a=o,s+=r.textContent.length,s>t&&!/^\s*$/.test(r.textContent)))break}else if(o=o.parentNode,!o)break;r=o.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}},$f=(o=>(o.TEXT_HTML="text/html",o.TEXT_XML="text/xml",o.APPLICATION_XML="application/xml",o.APPLICATION_XHTML_XML="application/xhtml+xml",o.IMAGE_SVG_XML="image/svg+xml",o))($f||{});function ou(i,t,e){let n=e||new DOMParser,s;try{s=n.parseFromString(i,t)}catch(o){}if(s){let o=s.documentElement,r="parsererror";if(o.localName===r)return null;for(let a=o.firstElementChild;a;a=a.nextElementSibling)if(a.localName===r)return null}else return null;return s}function kE(i){let t=i.contentType;if(t){let n=Object.keys($f);for(let s=0;s<n.length;s++)if($f[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let e=i.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 Xf(i,t){let e=i.responseXML;if(!e){let s=new DOMParser,o=i.responseText;if(o!=null){let r=kE(i);if(e=ou(o,r||"application/xml",s),e&&!r){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=ou(o,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=ou(o,"image/svg+xml",s))}e||(e=ou(o,"text/html",s))}}let n=e?new Ca(t,i.url,e):null;return w(n)}function Lb(){return new co(Xf,"document")}var Wf=class i{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,e){return new i(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==e)}withChild(t,e){return new i(n=>{if(!this.check(n))return!1;let s=new ru([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},jf=new Wf(i=>!0),ru=class i{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 i(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 i(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 AE=new Ln(()=>{let i=I("uaStylesheetBase"),t=mf(),e=te("user-agent-base.css",cn),n=new as(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),gC(n.cascade),gl(vd,n,e,null,null).thenFinish(i),i.result()},"uaStylesheetBaseFetcher");function RE(){return AE.get()}var Yf=class extends vo{constructor(e,n,s,o,r,a){super(e,n,null,s,o,"counter-style");this.counterStyleName=r;this.counterStyles=a}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||B.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},qf=class{constructor(t,e,n,s,o,r,a,l,c,u,d){this.store=t;this.rootScope=e;this.pageScope=n;this.cascade=s;this.rootBox=o;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 o=new Uo(this.rootScope,t,e,n),r=fC(o,this.viewportProps),a=r.width,l=r.height,c=r["text-zoom"],u=1;if(a&&l||c){let d=ct.em;if((c?c.evaluate(o,"text-zoom"):null)===S.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Ye(a.evaluate(o,"width"),o),g=Ye(l.evaluate(o,"height"),o);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}}};function Fb(i){let t=new Map,e=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&e(n.shadowSibling)};for(let n in i.flowPositions){let s=i.flowPositions[n];for(let o of s.positions){let r=o.chunkPosition.primary;for(let a of r.steps)e(a);if(o.chunkPosition.floats)for(let a of o.chunkPosition.floats)for(let l of a.steps)e(l)}}return t}function Vb(i){for(let[t,e]of i)e!==void 0&&t.restoreState(e)}var Gs=class extends Uo{constructor(e,n,s,o,r,a,l,c,u,d,h,f,g,m){super(e.rootScope,o.width,o.height,o.fontSize);this.style=e;this.xmldoc=n;this.viewport=o;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,"currentCascadedPageStyle",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);p(this,"semanticFootnoteFirstRefOffsets",new Map);p(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1});p(this,"pageGroupPageCounts",Object.create(null));p(this,"currentPageGroupDocument",null);this.lang=n.lang||s,this.faces=new zc(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Mn(null,null,null,null,null,null,null),this.pageProgression=g||null,this.isVersoFirstPage=!!m;for(let b in e.flowProps){let y=e.flowProps[b],C=ee(y,"flow-consume");C&&(C.evaluate(this,"flow-consume")==S.all?this.primaryFlows[b]=!0:delete this.primaryFlows[b])}}init(){let e=I("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 Ji(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 o=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=_f(o)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new jc(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,o),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new Zc(a,this.style.pageScope,this.rootPageBoxInstance,this,o);let l=[];for(let u of this.style.fontFaces){if(u.condition&&!u.condition.evaluate(this))continue;let d=hb(u.properties,this),h=new ra(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{kb(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=Uf(ma(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),o=new Uo(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 Ji(e,s.cascade,s.rootScope,o,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 o=s.flowPositions[e.flowName];o||(o=new Il,s.flowPositions[e.flowName]=o);let r=Km(e.element),a=new _t(r),l=new Ll(a,e);o.positions.push(l)}}evalSupportsTest(e,n,s){if(s)return e==="selector"?this.evalSupportsSelector(n):!1;if(!e)return!1;let o=!0;class r{unknownProperty(d,h){o=!1}invalidPropertyValue(d,h){o=!1}simpleProperty(d,h,f){}}let a=new r,l=Ts(this.style.rootScope,new ot(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),o):!1}evalSupportsSelector(e){class n extends iu{errorMsg(...c){}}let s=new n(null),o=ad(e),r=new ot(o+"{}",s);return new Ns(Ie,r,s,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!s.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let n=Number.POSITIVE_INFINITY;for(let s=0;s<e.positions.length;s++){let o=e.positions[s].chunkPosition.primary,r=o.steps[0].node,a=o.offsetInNode,l=o.after,c=0;for(;r.ownerDocument!=this.xmldoc.document;)c++,r=o.steps[c].node,l=!1,a=0;let u=this.xmldoc.getNodeOffset(r,a,l);u<n&&(n=u)}return n}getNodePositionOffset(e){let n=e.steps[0].node,s=e.offsetInNode,o=e.after,r=0;for(;n.ownerDocument!=this.xmldoc.document;)r++,n=e.steps[r].node,o=!1,s=0;return this.xmldoc.getNodeOffset(n,s,o)}getPageStartOffset(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let r=e.flowPositions[o];if(!n&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),r=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[o]=r)),r)for(let a=0;a<r.positions.length;a++){let l=r.positions[a].chunkPosition.primary,c=this.getNodePositionOffset(l);c<s&&(s=c)}}return s}getPageStartCounterOffsets(e){let n=this.getPageStartOffset(e);if(!isFinite(n))return{counterOffset:n,changeOffset:n};let s=this.xmldoc.body||this.xmldoc.root,o=s?this.getFirstInFlowElementAtOrAfter(s,n):null,r=s?this.xmldoc.getElementOffset(s):n,a=n<=r,l=o===s&&a?this.getFirstInFlowChildElement(s):o;if(!l)return{counterOffset:n,changeOffset:n};let c=this.xmldoc.getElementOffset(l),u=n;return a&&c!==n&&(u=c),c===n&&(this.isInlineLevelElement(l)?u=Math.max(0,n-1):u=this.getDeepestFirstInFlowChildOffset(l)),{counterOffset:u,changeOffset:c}}getPageStartElement(e,n=this.getPageStartOffset(e)){if(!isFinite(n))return null;let s=this.xmldoc.body||this.xmldoc.root;if(!s)return null;let o=this.getFirstInFlowElementAtOrAfter(s,n),r=this.xmldoc.getElementOffset(s),a=n<=r;return o===s&&a?this.getFirstInFlowChildElement(s):o}isForcedPageBreakValue(e){return Ne(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let n=ee(e,"break-before");if(!n)return!1;let s=n.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(s)}getExplicitPageType(e){let n=ee(e,"page");if(!n)return null;let s=n.evaluate(this,"page").toString();return!s||s.toLowerCase()==="auto"?null:s}getPageGroupPageType(e){let n=this.styler.getStyle(e,!1);return n?this.getExplicitPageType(n):null}getPreviousInFlowSibling(e){let n=e.previousElementSibling;for(;n;){if(this.isNormalFlowElement(n))return n;n=n.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let n=this.xmldoc.getElementOffset(e),s=this.getFirstInFlowElementAtOrAfter(e,n);return s===e?this.getFirstInFlowChildElement(e):s}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,n,s){let o=this.styler.getStyle(e,!1);if(!o)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),a=this.xmldoc.body||this.xmldoc.root,l=this.xmldoc.getElementOffset(a);if(s<=l&&e===a||!this.getPreviousInFlowSibling(e)&&s===r)return!0;if(r!==s)return!1;if(this.hasForcedPageBreakBefore(o))return!0;let u=this.getPreviousInFlowSibling(e);if(!u)return!1;let d=this.styler.getStyle(u,!1);return d?this.getExplicitPageType(d)!==n:!1}updatePageGroupPageIndices(e){let n=this.pageManager.pageCascadeInstance;n.pageTypePageIndices=Object.create(null);let s=e.startSideOfFlow("body"),o=e.flowPositions.body,r=!!(o&&o.positions.length),a=ts(s)&&!this.matchPageSide(s)&&!r,c=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!a,u=this.getPageStartOffset(e),d=this.getPageStartElement(e,u);if(!d)return;let h=d.ownerDocument,g=this.currentPageGroupDocument!==h&&c;g&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=h);let m=d;for(;m;){let b=this.getPageGroupPageType(m);if(b){let y=this.pageGroupPageCounts[b]||(this.pageGroupPageCounts[b]=new Map),C=y.get(m)||0;(C>0||c&&(g||this.shouldStartPageGroup(m,b,u)))&&(C+=1,y.set(m,C),(n.pageTypePageIndices[b]||(n.pageTypePageIndices[b]=[])).push(C))}if(m===this.xmldoc.root)break;m=m.parentElement}}getFirstInFlowElementAtOrAfter(e,n){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=n)return e;let o=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{let a=r;return this.isNormalFlowElement(a)?this.xmldoc.getElementOffset(a)<n?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return o!=null?o:null}getDeepestFirstInFlowChildOffset(e){let n=e;for(;;){let s=this.getFirstInFlowChildElement(n);if(!s)return this.xmldoc.getElementOffset(n);n=s}}getFirstInFlowChildElement(e){let n=e.firstChild;for(;n;){if(n.nodeType===Node.TEXT_NODE){if(!pe(n))return null;n=n.nextSibling;continue}if(n.nodeType!==Node.ELEMENT_NODE){n=n.nextSibling;continue}let s=n;if(this.isNormalFlowElement(s))return s;n=n.nextSibling}return null}isNormalFlowElement(e){var c,u;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===S.none)return!1;let o=(c=n==null?void 0:n.position)==null?void 0:c.evaluate(this.styler.context,"position"),r=o&&!W(o)?o:S.static;if(ho(r)||ur(r))return!1;let a=(u=n==null?void 0:n.float)==null?void 0:u.evaluate(this.styler.context,"float");return(a&&!W(a)?a:S.none)===S.none}isInlineLevelElement(e){return Et(this.getDisplayValue(e))}getDisplayValue(e){var o;let n=this.styler.getStyle(e,!1),s=(o=n==null?void 0:n.display)==null?void 0:o.evaluate(this.styler.context,"display");return s&&!W(s)?s:S.inline}getPosition(e,n){if(!e)return 0;let s=Number.POSITIVE_INFINITY;for(let o in this.primaryFlows){let r=e.flowPositions[o];if(!n&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(o),r=this.currentLayoutPosition.flowPositions[o],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[o]=r)),r){let a=this.getConsumedOffset(r);a<s&&(s=a)}}return s}dumpLocation(e){B.debug("Location - page",this.currentLayoutPosition.page),B.debug(" current:",e),B.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o of s.positions)B.debug(" Chunk",`${n}:`,o.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new Se(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 o=s.positions[0].flowChunk;if(this.getConsumedOffset(s)===o.startOffset){let r=s.positions[0].flowChunk.breakBefore,a=s.startBreakType;s.startBreakType=zd(De(a,r))}}}}selectPageMaster(e){let n=this.currentLayoutPosition,s=this.getPosition(n);if(s==Number.POSITIVE_INFINITY)return null;let o=this.rootPageBoxInstance.children,r;for(let a=0;a<o.length;a++){if(r=o[a],r.pageBox.pseudoName===Jc)continue;let l=1;r.pageBox.pseudoName===aa&&!(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===S._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 o=e.startOffset,r=n[s].forcedBreakOffsets;if(!r.length||o<r[0])return!1;let a=Ft(r.length,d=>r[d]>o)-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 xr(null)),e.flowRootFormattingContext=s.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new Mn(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let n=e.pageFloatLayoutContext,s=n.getDeferredPageFloatContinuations(),o=this.counterStore.currentPageCountersStack.length>0,r=u=>{var m,b;if(!o||u.floatReference!==ue.PAGE)return!1;let d=((b=(m=this.layoutPositionAtPageStart)==null?void 0:m.flowPositions)==null?void 0:b.body)||null,h=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(h)?h:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(u.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},a=I("layoutDeferredPageFloats"),l=!1,c=0;return a.loopWithFrame(u=>{if(c===s.length){u.breakLoop();return}let d=s[c++],h=d.float;if(r(h)){u.breakLoop();return}let f=new yn().findByFloat(h),g=f.findPageFloatFragment(h,n);if(g&&g.hasFloat(h)){u.continueLoop();return}else if(n.isForbidden(h)||n.hasPrecedingFloatsDeferredToNext(h)){n.deferPageFloat(d),u.breakLoop();return}e.layoutPageFloatInner(d,f,null,g).then(m=>{if(!m){u.breakLoop();return}let b=n.parent.isInvalidated();if(b){u.breakLoop();return}else n.isInvalidated()&&!b&&(l=!0,n.validate());u.continueLoop()})}).then(()=>{l&&n.invalidate(),a.finish(!0)}),a.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 _t(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 s?(this.setFormattingContextToColumn(e,n),e.init(),this.layoutDeferredPageFloats(e)):w(!0);this.setFormattingContextToColumn(e,n),e.init(),this.primaryFlows[n]&&e.bands.length>0&&(e.forceNonfitting=!1);let o=I("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){o.finish(!0);return}let r=[],a=[],l=!0;o.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,b=this.getLastAfterPositionIfDeferredFloatsExists(e,g);if(!g&&e.pageBreakType&&s.positions.length-a.length-1<=0&&(e.pageBreakType=null),e.pageBreakType&&b?(d.chunkPosition=b,s.breakAfter=e.pageBreakType,e.pageBreakType=null):(a.push(u),(g||b)&&(d.chunkPosition=g||b,r.push(u)),s.startBreakType=zd(e.pageBreakType)),m){c.breakLoop();return}}e.forceNonfitting=!1,f?f=!1:c.continueLoop()}),f){f=!1;return}}c.breakLoop()}).then(()=>{var c;if(!e.pageFloatLayoutContext.isInvalidated()){s.positions=s.positions.filter((d,h)=>r.includes(h)||!a.includes(h)),s.breakAfter==="column"&&(s.breakAfter=null),e.saveDistanceToBlockEndFloats();let u=e.pageFloatLayoutContext.getMaxReachedAfterEdge();if(e.updateMaxReachedAfterEdge(u),e.computedBlockSize===0){let d=e.pageFloatLayoutContext,h=d;for(;h;){let f=h.floatFragments.filter(g=>"isFootnote"in g.area&&g.area.isFootnote);if(f.length>0&&!h.ignoreFootnoteAreaMaxHeight&&f.some(m=>{let b=getComputedStyle(m.area.element),y=C=>C!==""&&C!=="none";return y(b.getPropertyValue("max-block-size"))||y(m.area.vertical?b.maxWidth:b.maxHeight)})){h.ignoreFootnoteAreaMaxHeight=!0;for(let m of f){d.removePageFloatFragment(m,!0);let b=(c=m.continuations[0])==null?void 0:c.float;b&&h.removeFloatDeferredToNext(b)}d.invalidate();break}h=h.parent}}}o.finish(!0)})}),o.result()}createLayoutConstraint(e){let n=this.currentLayoutPosition.page-1,s=this.counterStore.createLayoutConstraint(n);return new cc([s].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,n,s,o,r,a,l,c,u,d,h,f,g,m){let b=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,y=r.element,C=new Mn(c,ue.COLUMN,null,l,null,null,null),N=this.currentLayoutPosition.clone(),x=I("createAndLayoutColumn"),E;return x.loopWithFrame(v=>{let T=this.createLayoutConstraint(C);if(u>1){let k=this.viewport.document.createElement("div");if(P(k,"position","absolute"),y.appendChild(k),E=new Po(k,g,this.clientLayout,T,C),E.isNonFirstColumn=a>0,E.forceNonfitting=m,E.vertical=r.vertical,E.rtl=r.rtl,E.snapHeight=r.snapHeight,E.snapWidth=r.snapWidth,r.vertical){let L=(r.rtl?u-a-1:a)*(h+d)+r.paddingTop,M=parseFloat(y.style.width);E.setHorizontalPosition(r.paddingLeft+M-r.width,r.width),E.setVerticalPosition(L,h)}else{let L=(r.rtl?u-a-1:a)*(h+d)+r.paddingLeft;E.setVerticalPosition(r.paddingTop,r.height),E.setHorizontalPosition(L,h)}E.originX=n,E.originY=s}else E=new Po(y,g,this.clientLayout,T,C),E.isNonFirstColumn=!1,E.copyFrom(r);E.exclusions=b?[]:o.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=N.clone(),E.element!==y&&y.removeChild(E.element),v.continueLoop()):v.breakLoop()}):(C.finish(),v.breakLoop())}).then(()=>{x.finish(E)}),x.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof ha||n instanceof Io&&!(n instanceof Wn))&&e.setContainer(s)}getRegionPageFloatLayoutContext(e,n,s,o){n instanceof $n;let r=n.getProp(this,"writing-mode")||null,a=n.getProp(this,"direction")||null;return new Mn(e,ue.REGION,s,o,null,r,a)}layoutFlowColumnsWithBalancing(e,n,s,o,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,o,r,a,h,l,c,u,f).thenAsync(m=>m?w({columns:m,position:this.currentLayoutPosition}):w(null)));return g().thenAsync(m=>{if(!m)return w(null);if(u<=1)return w(m.columns);let b=n.getProp(this,"column-fill")||S.balance,y=this.currentLayoutPosition.flowPositions[c];let C=zC(u,b,g,h,l,m.columns,y);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(N=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=N.position,w(N.columns)))):w(m.columns)})}layoutFlowColumns(e,n,s,o,r,a,l,c,u,d,h){let f=I("layoutFlowColumns"),g=this.currentLayoutPosition.clone(),m=Fb(this.currentLayoutPosition),b=n.getPropAsNumber(this,"column-gap"),y=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,C=n.getActiveRegions(this),N=n.getProp(this,"shape-inside"),x=il(N,0,0,c.width,c.height,this),E=new tu(u,this,this.viewport,this.styler,C,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),v=0,T=null,k=[];return f.loopWithFrame(L=>{this.createAndLayoutColumn(n,s,o,r,c,v++,u,l,d,b,y,x,E,h).then(M=>{if(a.isInvalidated()){k=null,L.breakLoop();return}if((!!M.pageBreakType&&M.pageBreakType!=="column"||v===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){v=0,this.currentLayoutPosition=g.clone(),Vb(m),l.validate(),l.isLocked()?(k=null,L.breakLoop()):L.continueLoop();return}T=M,k[v-1]=T,T.pageBreakType&&T.pageBreakType!="column"&&(v=d,T.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),v<d?L.continueLoop():L.breakLoop()})}).then(()=>{f.finish(k)}),f.result()}layoutContainer(e,n,s,o,r,a,l){n.reset();let c=n.getProp(this,"enabled");if(c&&c!==S._true)return w(!0);let u=I("layoutContainer"),h=n.getProp(this,"wrap-flow")===S.auto,f=n.getProp(this,"flow-from"),g=this.viewport.document.createElement("div");g.role=n instanceof fa?"complementary":"presentation";let m=n.getProp(this,"position");P(g,"position",m?m.name:"absolute");let b=n instanceof Wn;n instanceof $n?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new yr(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 Wn&&(C.width<=0||C.height<=0)&&B.warn("Negative or zero page area size"),C.originX=o,C.originY=r,o+=C.left+C.marginLeft+C.borderLeft,r+=C.top+C.marginTop+C.borderTop,this.setPagePageFloatLayoutContextContainer(l,n,C);let N,x=!1;if(!f||!f.isIdent()){let E=[],v=n.getProp(this,"content");if(v instanceof D&&v.expr instanceof ne&&v.expr.str.startsWith("running-element-"))v.visit(new Dn(g,this,v,this.counterStore.getExprContentListener()));else if(nt(v)){let T="span";v instanceof ke&&(T="img");let k=this.viewport.document.createElement(T);v.visit(new Dn(k,this,v,this.counterStore.getExprContentListener())),g.appendChild(k),T=="img"&&n.transferSingleUriContentProps(this,k,this.faces),n.transferContentProps(this,C,e,this.faces);let L=k.querySelectorAll("img[src]");for(let q=0;q<L.length;q++){let J=L[q],re=J.getAttribute("src");if(!re)continue;let xe=Xt(J,re);E.push(xe),e.fetchers.push(xe)}let M=k.getAttribute("src");if(M){let q=k.querySelector("img");q||(q=k);let J=Xt(q,M);E.push(J),e.fetchers.push(J)}T=="span"&&PC(k,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),x=!0);x||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),N=E.length?Cn(E).thenReturn(!0):w(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),N=w(!0);else{let E=I("layoutContainer.inner"),v=f.toString(),T=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,o,r,a,l,C,v,T).then(k=>{if(!l.isInvalidated()){let L=k[0];L.element===g&&(C=L),C.computedBlockSize=Math.max.apply(null,k.map(q=>q.computedBlockSize)),n.finishContainer(this,C,e,L,T,this.clientLayout,this.faces);let M=this.currentLayoutPosition.flowPositions[v];M&&M.breakAfter==="region"&&(M.breakAfter=null)}E.finish(!0)}),N=E.result()}return N.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!x&&!h){let v=n.getProp(this,"shape-outside"),T=C.getOuterShape(v,this);a.push(T)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let E=b?0:n.children.length-1;u.loop(()=>{for(;E>=0&&E<n.children.length;){let v=n.children[b?E++:E--],T=this.layoutContainer(e,v,g,o,r,a,l);if(T.isPending())return T.thenAsync(()=>w(!l.isInvalidated()));if(l.isInvalidated())break}return w(!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 o=s.positions.length-1;o>=0;o--){let r=s.positions[o];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&s.positions.splice(o,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o=s.positions.length-1;o>=0;o--){let r=s.positions[o];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 m,b,y,C;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new Fl,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),n=this.currentLayoutPosition;let o=1e4;if(n.page>o)throw new Error(`Too many pages generated (over ${o} pages)`);let r=n.startSideOfFlow("body");n.isBlankPage=ts(r)&&this.matchPageSide(r),e.isBlankPage=n.isBlankPage,n.page++,e.pageType==null&&(e.pageType=(b=(m=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?m:n.page===1?this.resolveFirstPageType():null)!=null?b:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(n),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=n.clone();let a=Fb(n),l=s?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=l,this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!s){let N=new Se(this.style.pageScope,"left-page");e.side=N.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let c=this.selectPageMaster(l);if(!c)return w(null);let u=0;if(!s){e.setAutoPageWidth(c.pageBox.specified.width.value===bs),e.setAutoPageHeight(c.pageBox.specified.height.value===ys);let{counterOffset:N,changeOffset:x}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(N)||(N=this.lookupOffset,x=this.lookupOffset),isFinite(N)&&this.styler.styleUntil(N,0);let E=this.styler.getCounterSnapshotAtOffset(N),v=x===N?E:this.styler.getCounterSnapshotAtOffset(x);E||(E=this.styler.getLastCounterSnapshot()),v||(v=E),this.counterStore.setCurrentPageDocCounters((y=E==null?void 0:E.counters)!=null?y:null,(C=v==null?void 0:v.changes)!=null?C:null,v==null?void 0:v.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let T=Uf(ma(l),this);this.setPageSizeAndBleed(T,e),vb(l,T,e,this),u=T.bleedOffset+T.bleed}let d=!s&&c.getProp(this,"writing-mode")||S.horizontal_tb;this.pageVertical=d!=S.horizontal_tb;let h=c.getProp(this,"direction")||S.ltr,f=new Mn(this.rootPageFloatLayoutContext,ue.PAGE,null,null,null,d,h),g=I("layoutNextPage");return g.loopWithFrame(N=>{this.layoutContainer(e,c,e.bleedBox,u,u,[],f).then(()=>{if(f.isInvalidated()||f.finish(),f.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Vb(a),f.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);N.continueLoop()}else N.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(x=>{let E=n.flowPositions[x],v=E.breakAfter;v&&(v==="page"||!this.matchPageSide(v))&&(E.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let N=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(N,this.clientLayout),this.noMorePrimaryFlows(n)&&(n=null),g.finish(n)}),g.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`}},Kf=class i extends as{constructor(e,n,s,o){super(e.rootScope,e,n,s,o,e.validatorSet,!s);this.masterHandler=e;p(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(e,n,s){let o=new Or(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new qc(o.scope,this.masterHandler,o,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=xt(this.scope,this.condition,n)),this.masterHandler.pushHandler(new i(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Zl(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new vo(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(e){this.masterHandler.pushHandler(new Yf(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 vo(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new vo(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=Yt(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new ga(this.scope,this.owner,this.masterHandler.validatorSet,n))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new Qc(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(as.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let e=`R${this.masterHandler.regionCount++}`;this.special("region-id",R(e)),this.endRule();let n=new i(this.masterHandler,this.condition,this,e);this.masterHandler.pushHandler(n),n.startRuleBody()}}},iu=class extends lr{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 Sc);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new Qs(null),this.pageScope=new Qs(this.rootScope),this.rootBox=new $c(this.rootScope),this.cascadeParserHandler=new Kf(this,null,null,null),this.slave=this.cascadeParserHandler}};function LE(i,t){return t.parseOPSResource(i)}var au=class extends co{constructor(e){super(LE,"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=I("OPSDocStore.init");return this.validatorSet=mf(),RE().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(Xn(n),Tn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=te(Xn(n),Tn)),this.styleSheets.push({url:n,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let n=I("OPSDocStore.load"),s=e.url,o=s.endsWith("?viv-toc-box");return Xf(e,this).then(r=>{var f;if(!r){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=Je("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](r.document)}catch(b){B.warn("Error during single document preprocessing:",b)}}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],b=m.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),y=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),N=m.getAttribute("ref");b&&y&&C&&N&&a.push({observer:b,event:y,action:C,ref:N})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:te("user-agent-page.css",cn),text:Ed,flavor:"UA",classes:null,media:null}),c.push({url:te("user-agent-counter-styles.css",cn),text:wd,flavor:"UA",classes:null,media:null}),o)c.push({url:te("user-agent-toc.css",cn),text:Nd,flavor:"UA",classes:null,media:null});else{let g=r.document.querySelectorAll("style, link, meta");for(let m of g){let b=m.namespaceURI,y=m.localName;if(b=="http://www.w3.org/1999/xhtml")if(y=="style"){let C=m.getAttribute("class"),N=m.getAttribute("media"),x=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:x?C:null,media:N})}else if(y=="link"){let C=m.getAttribute("href"),N=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),x=m.getAttribute("class"),E=m.getAttribute("media");if(C&&(N!=null&&N.includes("stylesheet"))&&(!N.includes("alternate")||x)){let v=te(C,s),T=m.getAttribute("title");c.push({url:v,text:null,classes:T?x:null,media:E,flavor:"Author"})}}else y=="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 Ln(()=>{let g=I("fetchStylesheet"),m=0,b=new iu(this.validatorSet);return g.loop(()=>{if(m<c.length){let y=c[m++];return b.startStylesheet(y.flavor),y.text!==null?gl(y.text,b,y.url,y.classes,y.media).thenReturn(!0):Ad(y.url,b,y.classes,y.media)}return w(!1)}).then(()=>{let y=b.cascadeParserHandler.finish();d=new qf(this,b.rootScope,b.pageScope,y,b.rootBox,b.fontFaces,b.footnoteProps,b.flowProps,b.viewportProps,b.pageProps,b.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 ba="\u25B8",Bb="\u25BE",IE="\u25B9";function cu(i){let t=Array.from(i.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(i.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let e="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of i.querySelectorAll(e)){if(t.find(o=>o.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 Db(i){let t=cu(i),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var lu=class{constructor(t,e,n,s,o,r,a,l,c,u,d){this.store=t;this.url=e;this.lang=n;this.clientLayout=s;this.fontMapper=o;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=Xa(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;un(s,"height","auto")!="auto"&&(P(s,"height","auto"),this.setAutoHeight(s,e)),un(s,"position","static")=="absolute"&&(P(s,"position","relative"),this.setAutoHeight(s,e))}}}makeCustomRenderer(t){let e=this.rendererFactory.makeCustomRenderer(t);return(n,s,o)=>{let r=o.behavior;if(r)switch(r.toString()){case"toc-node-anchor":o.color=S.inherit,o["text-decoration"]=S.none;break;case"toc-node":o.display=S.block,o.margin=me,o.padding=me,o["padding-inline-start"]=new A(1.25,"em");break;case"toc-node-first-child":o.display=S.inline_block,o.margin=new A(.2,"em"),o["vertical-align"]=S.top,o.color=S.inherit,o["text-decoration"]=S.none;break;case"toc-container":o.padding=me;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return e(n,s,o);let a=n.firstChild;a&&a.nodeType!==1&&pe(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!=ba&&(u.textContent=ba,P(u,"cursor","pointer"),u.addEventListener("click",FE,!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=IE,P(u,"margin","0.2em 0 0 -1em"),P(u,"margin-inline-start","-1em"),P(u,"margin-inline-end","0"),P(u,"display","inline-block"),P(u,"width","1em"),P(u,"text-align","center"),P(u,"vertical-align","top"),P(u,"cursor","default"),P(u,"font-family","Menlo,sans-serif"),c.appendChild(u),P(c,"overflow","hidden"),c.setAttribute("data-adapt-class","toc-node"),c.setAttribute("role","treeitem"),l=="toc-node"||l=="toc-container"){P(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 w(c)}}showTOC(t,e,n,s,o){if(this.page)return w(this.page);let r=I("showTOC"),a=new br(t,t);this.page=a;let l=Gt(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of cu(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,o);e=new hs(e.window,d.fontSize,0,t,d.width,d.height);let h=this.makeCustomRenderer(c),f=new Gs(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 o=s.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(o).map(e)}function e(s){let o=new URL(s.href),[,r]=o.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 FE(i){let t=i.target,e=t.textContent==ba;t.textContent=e?Bb:ba;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 o=s,r=o.getAttribute("data-adapt-class");if(r==="toc-container"){if(o.setAttribute("aria-hidden",e?"false":"true"),o.firstChild){s=o.firstChild;continue}}else if(r==="toc-node"&&(o.style.height=e?"auto":"0px",o.children.length>=2&&(o.children[1].tabIndex=e?0:-1),o.children.length>=3&&(o.children[0].tabIndex=e?0:-1,!e))){let a=o.children[0];if(a.textContent==Bb){a.textContent=ba,a.setAttribute("aria-expanded","false"),o.setAttribute("aria-expanded","false"),s=o.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}i.stopPropagation()}function uu(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function OE(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=new Map(i[e])}),t}var Sa=class extends au{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=Lb(),this.jsonStore=im()}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)}loadWebPubManifest(e,n){this.loadAsJSON(e,!0).then(s=>{if(!s){this.reportLoadError(e),n.finish(null);return}let o=new Vo(this,e);o.initWithWebPubManifest(s,void 0,e).then(()=>{n.finish(o)})})}loadPubDoc(e){let n=I("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,s,o]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(s,o).thenFinish(n)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,n):/\.(x?html?|xht)(?:[#?]|$)/i.test(e)?this.loadWebPub(e).then(s=>{if(s){n.finish(s);return}this.reportLoadError(e),n.finish(null)}):uo(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}B.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"){let[,o,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(o,r).thenFinish(n)}else s.contentType=="application/ld+json"||s.contentType=="application/webpub+json"||s.contentType=="application/audiobook+json"||s.contentType=="application/json"?this.loadWebPubManifest(e,n):this.loadWebPub(e).then(o=>{if(o){n.finish(o);return}this.loadEPUBDoc(e).then(r=>{if(r){n.finish(r);return}this.reportLoadError(e),n.finish(null)})})});return n.result()}loadEPUBDoc(e){let n=I("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let s=e+"META-INF/container.xml";return this.loadAsPlainXML(s).then(o=>{if(o){let r=o.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,o=this.opfByURL[s];if(o)return w(o);let r=I("loadOPF");return this.loadAsPlainXML(s,!0,`Failed to fetch EPUB OPF ${s}`).then(a=>{a?(o=new Vo(this,e),this.opfByURL[s]=o,this.primaryOPFByEPubURL[e]=o,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(l=>{o.initWithXMLDoc(a,l).then(()=>{r.finish(o)})}):o.initWithXMLDoc(a,null).then(()=>{r.finish(o)})):this.reportLoadError(s)}),r.result()}loadWebPub(e){let n=I("loadWebPub");return this.load(e).then(s=>{if(!s)this.reportLoadError(e),n.finish(null);else if(s.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))n.finish(null);else{let o=s.document,r=new Vo(this,e),a=o.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(a){let l=a.getAttribute("href");if(/^#/.test(l)){let c=_o(o.getElementById(l.substr(1)).textContent);r.initWithWebPubManifest(c,o).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,o,c).then(()=>{n.finish(r)})})}}else r.initWithWebPubManifest({},o).then(()=>{r.toc&&r.toc.src===s.url&&cu(o).length===0&&(r.toc=null),n.finish(r)})}}),n.result()}addDocument(e,n){let s=I("EPUBDocStore.load"),o=Gt(e);return(this.documents[o]=this.parseOPSResource({status:200,statusText:"",url:o,contentType:n.contentType,responseText:null,responseXML:n,responseBlob:null})).thenFinish(s),s.result()}reportLoadError(e){let n=o=>o.replace(/([^:/?#]|^)[/?#].*/,"$1"),s=()=>{let o=n(e);return!(o===n(Tn)||Object.keys(this.resources).find(a=>this.resources[a]&&n(a)===o)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?B.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Tn.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?B.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?B.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):B.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=Gt(e),s=this.documents[n];if(s)return s.isPending()?s:w(s.get());{let o=I("EPUBDocStore.load");return s=super.load(n,!0,`Failed to fetch a source document from ${n}`),s.then(r=>{r?o.finish(r):this.reportLoadError(n)}),o.result()}}processViewportMeta(e){let n=e.getAttribute("content");if(!n)return"";let s={},o;for(;(o=n.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)n=n.substr(o[0].length),s[o[1]]=o[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""}},pu=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=hg}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=Cg(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 BE(i){return i.id}function DE(i){return t=>{let e=I("deobfuscator");return ME("SHA-1",i).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);om(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(Pd([a,o]))})}),e.result()}}function ME(i,t){let e=I("makeDigest"),n=e.suspend();return window.crypto.subtle.digest(i,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),e.result()}var Ws={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"},ya="http://idpf.org/epub/vocab/package/meta/#",Ge={language:`${Ws.dcterms}language`,title:`${Ws.dcterms}title`,creator:`${Ws.dcterms}creator`,layout:`${Ws.rendition}layout`,titleType:`${ya}title-type`,displaySeq:`${ya}display-seq`,alternateScript:`${ya}alternate-script`,role:`${ya}role`};function _E(i,t){let e={};return(n,s)=>{var d,h,f,g,m,b;let o,r,a=n.r||e,l=s.r||e;if(i==Ge.title&&(o=((d=a[Ge.titleType])==null?void 0:d[0].v)=="main",r=((h=l[Ge.titleType])==null?void 0:h[0].v)=="main",o!=r))return o?-1:1;let c=parseInt((f=a[Ge.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[Ge.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:i!=Ge.language&&t&&(o=((m=a[Ge.language]||a[Ge.alternateScript])==null?void 0:m[0].v)==t,r=((b=l[Ge.language]||l[Ge.alternateScript])==null?void 0:b[0].v)==t,o!=r)?o?-1:1:n.o-s.o}}function UE(i,t){let e;if(!t)e=Ws;else{e={};for(let h in Ws)e[h]=Ws[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]]:ya;if(f)return f+h[3]}}return null},s=1,o=i.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:Ws.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=Ia(o,d=>d.refines),a=d=>bg(d,(h,f)=>h.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let b=r[`#${g.id}`]||[];if(b.length||g.lang||g.role){g.lang&&b.push({name:Ge.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&b.push({name:Ge.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let y=Ia(b,C=>C.name);m.r=a(y)}return m})),l=a(Ia(o,d=>d.refines?null:d.name)),c=null;l[Ge.language]&&(c=l[Ge.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(_E(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function HE(){let i=window.MathJax;return i?i.Hub:null}var Mb={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Zf="viv-id-",Vo=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,o){let r=o+(s?`#${s}`:"");return Zf+Ou(r,":")}transformURL(s,o){let r=s.match(/^([^#]*)#?(.*)$/);if(r){let a=r[1]||o.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(Zf)===0&&(s=s.substring(Zf.length));let r=mg(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 o={};this.items=n.child("manifest").child("item").asArray().map(c=>{let u=new pu,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!Mb[u.mediaType]&&(o[u.src]=h),!this.toc&&u.itemProperties.nav&&(this.toc=u),!this.cover&&u.itemProperties["cover-image"]&&(this.cover=u),u}),this.itemMap=Bu(this.items,BE),this.itemMapByPath=Bu(this.items,c=>this.getPathFromURL(c.src));for(let c in o){let u=c;for(;;){let d=this.itemMap[o[u]];if(!d)break;if(Mb[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=Nu(r));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(jf.withChild("EncryptionMethod",jf.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=UE(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[Ge.language]&&(this.lang=this.metadata[Ge.language][0].v),this.metadata[Ge.layout]&&(this.prePaginated=this.metadata[Ge.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=DE(this.uid);for(let u=0;u<a.length;u++)this.store.deobfuscators[this.pubURL+a[u]]=c}return this.prePaginated&&this.assignAutoPages(),w(!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(),w(!0);let e=0,n=0,s=I("countEPages");return s.loopWithFrame(o=>{if(n===this.spine.length){o.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),o.continueLoop()})}).thenFinish(s),s.result()}initWithChapters(t,e){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let n=this.opfXML=new Ca(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let o=new pu;o.initWithParam(s),o.id;let r=n.document.createElement("itemref");r.setAttribute("idref",o.id),n.root.appendChild(r),o.itemRefElement=r,this.itemMap[o.id]=o;let a=this.getPathFromURL(s.url);a==null&&(a=s.url),this.itemMapByPath[a]=o,this.items.push(o)}),e?this.store.addDocument(t[0].url,e):w(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[Ge.title]=(Array.isArray(s)?s:[s]).map(b=>{var y;return{v:(y=b.value)!=null?y:b}}));let o=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(b=>b.content);o&&o.length!==0&&(this.metadata[Ge.creator]=(Array.isArray(o)?o:[o]).map(b=>{var y;return{v:(y=b.name)!=null?y:b}}));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[Ge.language]=(Array.isArray(r)?r:[r]).map(b=>({v:b})));let a=this.getPathFromURL(this.pubURL);if(!t.readingOrder&&e&&a!==null){t.readingOrder=[encodeURI(a)];for(let b of Db(e)){let y=b.getAttribute("href");if(/^(https?:)?\/\//.test(y)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(y))continue;let C=Gt(te(y,this.pubURL)),N=this.getPathFromURL(C),x=N!==null?encodeURI(N):C;t.readingOrder.indexOf(x)==-1&&t.readingOrder.push(x)}}let l=[],c=0,u=-1;[t.readingOrder,t.resources].forEach(b=>{b instanceof Array&&b.forEach(y=>{let C=b===t.readingOrder,N=typeof y=="string"?y:y.url||y.href,x=typeof y=="string"?"":y.encodingFormat||y.href&&y.type||"";if(C||x==="text/html"||x==="application/xhtml+xml"||!x&&y.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(N)){let E=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,v={url:te(Xn(N),E),index:c++,startPage:null,skipPagesBefore:null};y.rel==="contents"&&u===-1&&(u=v.index),l.push(v)}})});let d=I("initWithWebPubManifest");return this.initWithChapters(l).then(()=>{var y,C;u!==-1&&(this.toc=this.items[u]),this.toc||(this.toc=n?(y=this.items)==null?void 0:y[0]:this.itemMapByPath[a]);let b=(C=t.readingOrder)==null?void 0:C.length;b&&b<this.items.length&&this.items.splice(b),d.finish(!0)}),d.result()}getCFI(t,e){let n=this.spine[t],s=I("getCFI");return this.store.load(n.src).then(o=>{let r=o.getNodeByOffset(e),a=null;if(r){let l=o.getNodeOffset(r,0,!1),c=e-l,u=new ni;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 Qn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new ni;n.fromString(t);let s;if(this.opfXML){let o=n.navigate(this.opfXML.document);if(o.node.nodeType!=1||o.after||!o.ref){e.finish(null);return}let r=o.node,a=r.getAttribute("idref");if(r.localName!="itemref"||!a||!this.itemMap[a]){e.finish(null);return}s=this.itemMap[a],n=o.ref}else s=this.spine[0];this.store.load(s.src).then(o=>{let r=n.navigate(o.document),a=o.getNodeOffset(r.node,r.offset,r.after);e.finish({spineIndex:s.spineIndex,offsetInItem:a,pageIndex:-1})})},(e,n)=>{B.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Qn("resolveEPage",e=>{if(t<=0){e.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let o=this.spine.findIndex(l=>l.epage==0&&l.epageCount==0||l.epage<=t&&l.epage+l.epageCount>t);o==-1&&(o=this.spine.length-1);let r=this.spine[o];(!r||r.epageCount==0)&&(r=this.spine[--o]);let a=Math.floor(t-r.epage);e.finish({spineIndex:o,offsetInItem:-1,pageIndex:a});return}let n=Ft(this.spine.length,o=>{let r=this.spine[o];return r.epage+r.epageCount>t});n==this.spine.length&&n--;let s=this.spine[n];this.store.load(s.src).then(o=>{t-=s.epage,t>s.epageCount&&(t=s.epageCount);let r=0;if(t>0){let a=o.getTotalOffset();r=Math.round(a*t/s.epageCount),r==a&&r--}e.finish({spineIndex:n,offsetInItem:r,pageIndex:-1})})},(e,n)=>{B.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 w(s)}if(t.offsetInItem<=0)return w(e.epage);let n=I("getEPage");return this.store.load(e.src).then(s=>{let o=s.getTotalOffset(),r=Math.min(o,t.offsetInItem);n.finish(e.epage+r*e.epageCount/o)}),n.result()}},du=(i,t)=>({page:i,position:{spineIndex:i.spineIndex,pageIndex:t,offsetInItem:i.offset}}),hu=class{constructor(t,e,n,s,o,r){this.opf=t;this.viewport=e;this.fontMapper=n;this.pageSheetSizeReporter=o;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");p(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0});this.pref=Xa(s),this.clientLayout=new nu(e),this.counterStore=new al(t.documentURLTransformer),this.cmykStore=new ei,r!=null&&r.length&&this.cmykStore.registerCmykReserveMap(r)}getPage(t){let e=this.spineItems[t.spineIndex];return e?e.pages[t.pageIndex]:null}waitForPreviousSpines(t,e){if(e||t===0)return w(!0);let n=I("waitForPreviousSpines");return n.loopWithFrame(s=>{let o=!0;for(let r=0;r<t;r++){let a=this.spineItems[r];if(!a||!a.complete){o=!1;break}}o?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 o=this.opf.spine[t.item.spineIndex-1];t.item.epage=o.epage+o.epageCount}t.item.epageCount=t.pages.length,this.opf.epageCount=this.opf.spine.reduce((o,r)=>o+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 o=null;if(n>0)o=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]){o=a.pages[0].container;break}}t.instance.viewport.contentContainer.insertBefore(e.container,o)}this.pageSheetSizeReporter({width:t.instance.pageSheetWidth,height:t.instance.pageSheetHeight},t.instance.pageSheetSize,t.item.spineIndex,t.instance.pageNumberOffset+n)}getRenderedPageCount(){let t=0;for(let e of this.spineItems)e&&(t+=e.pages.length);return t}markSpineItemCompleteIfReady(t){t.complete=t.layoutPositions.length===t.pages.length,t.complete&&t.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(t){let e=t.item.spineIndex,n=this.paginationProgress.totalOffsetsBySpine[e];return n==null&&(n=t.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[e]=n),n}getTotalOffsetAll(){let t=0;for(let e of this.spineItems)e&&(t+=this.getTotalOffsetForViewItem(e));return t}getRenderedOffsetAll(){var s;let t=0,e=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let o=0;o<e.length;o++){let r=e[o];if(!r)continue;let a=(s=n[o])!=null?s:0;t+=Math.min(r,a)}return t}reportPaginationProgress(t,e){let n=Je("PAGINATION_PROGRESS");if(!n.length)return;let s=t.item.spineIndex,o=this.getTotalOffsetForViewItem(t),r=o;e&&(r=t.instance.getPosition(e,!0)),r<0&&(r=0),r>o&&(r=o);let a=this.paginationProgress.renderedOffsetsBySpine[s];a!=null&&r<a&&(r=a),this.paginationProgress.renderedOffsetsBySpine[s]=r;let l=this.getRenderedPageCount(),c=this.getTotalOffsetAll(),u=this.getRenderedOffsetAll(),d=c>0?u/c:0;d<this.paginationProgress.lastReportedFraction?d=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=d,l>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=l);let h={fraction:d,pages:this.paginationProgress.lastReportedPages};for(let f of n)try{f(h)}catch(g){B.warn(g)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(t){return!!(t!=null&&t.pageType)&&t.pageType!==""}hasPageTypeBoundaryBetween(t,e){return(t==null?void 0:t.pageType)!=null&&(e==null?void 0:e.pageType)!=null&&t.pageType!==e.pageType}resolvePageTypeForRenderSlot(t,e,n,s,o,r,a){let l=!1;if(s){let u=this.hasPageTypeBoundaryBetween(o,s),d=(r==null?void 0:r.pageType)===s.pageType,h=s.offset!==e.offset,f=a&&!h&&n>0&&u&&d;if(l=s.pageType!=null&&(f||n===0||s.pageType===(o==null?void 0:o.pageType)),e.pageType=l?s.pageType:null,!a&&!l){let m=n>1&&u&&d?o.pageType:null;t.instance.styler.cascade.currentPageType=m,t.instance.pageManager.pageCascadeInstance.currentPageType=m}}!a&&this.hasNonEmptyPageType(o)&&this.hasNonEmptyPageType(r)&&o.pageType!==r.pageType&&(!s||s.pageType==null)&&(e.pageType=o.pageType)}evaluateNextPageRelayout(t,e,n,s,o){if(!t||e&&!n)return{needsRelayout:!1,shouldCascade:!1};let r=!!e&&(t.pageType===e.pageType||!e.pageType);return!!e&&s&&(!o||r)&&(e.pageType==null||t.pageType==null||t.pageType!==e.pageType)&&(e.pageType=null),{needsRelayout:!0,shouldCascade:!!e||!o}}preparePageCountersForRender(t,e){let n=t.pages[e],s=t.pageCounterStarts[e];n&&s&&(this.counterStore.currentPageCounters=uu(s));let o=uu(this.counterStore.currentPageCounters);return(!s||!n)&&(t.pageCounterStarts[e]=o),n}maybeRelayoutFollowingPage(t,e,n,s){if(!e)return w(!0);let o=t.layoutPositions[e.page];t.layoutPositions[e.page]=e;let r=t.pages[e.page],a=!!n&&s.offset!==n.offset,l=!o||!e.isSamePosition(o)||e.highestSeenOffset!==o.highestSeenOffset||a,c=this.isInCounterResolveScope(),u=this.evaluateNextPageRelayout(n,r,l,a,c);return u.needsRelayout?(t.complete=!1,u.shouldCascade?this.renderSinglePage(t,e):w(!0)):w(!0)}resolveUnresolvedReferencesForPage(t,e,n,s){let o=I("resolveUnresolvedReferencesForPage"),a=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(e),l=0,c=e;return o.loopWithFrame(u=>{if(l++,l>a.length){u.breakLoop();return}let d=a[l-1];if(d.refs=d.refs.filter(h=>!h.isResolved()),d.refs.length===0){u.continueLoop();return}this.getPageViewItem(d.spineIndex).then(h=>{if(!h){u.continueLoop();return}let f=h.instance.styler.cascade,g=h.instance.pageManager.pageCascadeInstance,m={currentPageType:f.currentPageType,previousPageType:f.previousPageType},b={currentPageType:g.currentPageType,previousPageType:g.previousPageType},y=OE(h.instance.pageGroupPageCounts),C=h.instance.currentPageGroupDocument,N=h.instance.scopes;h.instance.scopes={};let x=d.pageIndex<h.pages.length-1,E=!!h.pages[d.pageIndex]&&x,v=E?h.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(d.pageCounters),this.counterStore.pushReferencesToSolve(d.refs);let T=h.layoutPositions[d.pageIndex];this.renderSinglePage(h,T).then(k=>{E&&h.instance.endIsolatedRootPageFloatLayoutContext(v);let L=f.currentPageType;f.currentPageType=m.currentPageType,f.previousPageType=m.previousPageType,g.currentPageType=b.currentPageType,g.previousPageType=b.previousPageType,h.instance.pageGroupPageCounts=y,h.instance.currentPageGroupDocument=C,h.instance.scopes=N;let M=uu(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),k.pageAndPosition.position.spineIndex===c.spineIndex&&k.pageAndPosition.position.pageIndex===n&&(c=k.pageAndPosition.page),!!c.pageType&&c.pageType!==m.currentPageType&&L!==k.pageAndPosition.page.pageType&&(f.currentPageType=c.pageType);let J=h!==t,re=h.pages.length,xe=h.layoutPositions[re],le=h.instance.hasActiveRootPageFloatLayoutContext();if(xe&&!le){let F=J?uu(this.counterStore.currentPageCounters):null;J&&(this.counterStore.currentPageCounters=M);let U=re;this.renderSinglePage(h,xe).then(()=>{J&&this.markSpineItemCompleteIfReady(h);let j=h.pages.length-U;if(J&&j>0){this.counterStore.adjustPageCountersOfLaterSpines(h.item.spineIndex,j),this.counterStore.updateTargetCounterNodesInPages(h.pages);let H=h.item.spineIndex;for(let _=H+1;_<this.spineItems.length;_++){let Y=this.spineItems[_];if(Y){Y.item.epage+=j;for(let Ee of Y.pageCounterStarts)Ee!=null&&Ee.page&&(Ee.page=Ee.page.map(Ve=>Ve+j));this.counterStore.updatePageCounterNodesInPages(Y.pages,Y.pageCounterStarts)}}if(F){let _=F.page;_&&(F.page=_.map(Y=>Y+j))}}F&&(this.counterStore.currentPageCounters=F),u.continueLoop()});return}J&&this.markSpineItemCompleteIfReady(h),u.continueLoop()})})}).then(()=>{c.container.parentElement||(c=t.pages[n]),c.isLastPage=!s&&t.item.spineIndex===this.opf.spine.length-1,c.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),c.container.setAttribute("data-vivliostyle-page-index",n),c.container.setAttribute("data-vivliostyle-spine-index",c.spineIndex),o.finish(c)}),o.result()}renderSinglePage(t,e){let n=I("renderSinglePage"),s=e?Math.max(e.page,0):0,o=this.isInCounterResolveScope(),r=this.preparePageCountersForRender(t,s),a=s>0?t.pages[s-1]:null,l=t.pages[s+1],c=this.makePage(t,e);return this.resolvePageTypeForRenderSlot(t,c,s,r,a,l,o),t.instance.layoutNextPage(c,e).then(u=>{e=u;let d=e?e.page-1:t.layoutPositions.length-1;this.finishPageContainer(t,c,d),this.counterStore.finishPage(c.spineIndex,d),this.reportPaginationProgress(t,e),this.maybeRelayoutFollowingPage(t,e,r,c).thenAsync(()=>this.resolveUnresolvedReferencesForPage(t,c,d,e)).then(h=>{n.finish({pageAndPosition:du(h,d),nextLayoutPosition:e})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let o=Ft(e.layoutPositions.length,r=>e.instance.getPosition(e.layoutPositions[r],!0)>s);o===e.layoutPositions.length?e.complete?n=e.pages.length-1:n=Number.POSITIVE_INFINITY:n=o-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=I("findPage");return this.waitForPreviousSpines(t.spineIndex,e).then(()=>{this.getPageViewItem(t.spineIndex).then(s=>{if(!s){n.finish(null);return}let o=null,r;n.loopWithFrame(a=>{let l=this.normalizeSeekPosition(t,s);r=l.pageIndex,o=s.pages[r],o?a.breakLoop():s.complete?(r=s.pages.length-1,o=s.pages[r],a.breakLoop()):e?this.renderPage(l).then(c=>{c&&(o=c.page,r=c.position.pageIndex),a.breakLoop()}):r<s.layoutPositions.length&&!s.pages[r]?this.renderPage(l).then(c=>{c&&(o=c.page,r=c.position.pageIndex),a.breakLoop()}):n.sleep(100).then(()=>{a.continueLoop()})}).then(()=>{n.finish(du(o,r))})})}),n.result()}renderPage(t){let e=I("renderPage");return this.getPageViewItem(t.spineIndex).then(n=>{if(!n){e.finish(null);return}let s=this.normalizeSeekPosition(t,n),o=s.pageIndex,r=s.offsetInItem,a=n.pages[o];if(a){e.finish(du(a,o));return}e.loopWithFrame(l=>{if(o<n.layoutPositions.length){l.breakLoop();return}if(n.complete){o=n.pages.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,o=n.layoutPositions.length-2,l.breakLoop();return}l.continueLoop()}else a=d,o=u.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(n),l.breakLoop()})}).then(()=>{a=a||n.pages[o];let l=n.layoutPositions[o];if(a){e.finish(du(a,o));return}this.renderSinglePage(n,l).then(c=>{c.nextLayoutPosition||this.markSpineItemCompleteIfReady(n),e.finish(c.pageAndPosition)})})}),e.result()}renderAllPages(){let t=I("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(o=>o==null?void 0:o.fetchers.some(r=>!r.arrived)))?t.sleep(100).then(()=>{n.continueLoop()}):n.breakLoop()}).then(()=>{t.finish(e)})}),t.result()}renderPagesUpto(t,e){let n=I("renderPagesUpto");t||(t={spineIndex:0,pageIndex:0,offsetInItem:0});let s=t.spineIndex,o=t.pageIndex,r=0;e&&(r=s);let a;return n.loopWithFrame(l=>{let c={spineIndex:r,pageIndex:r===s?o: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,o=I("nextPage");return this.getPageViewItem(n).then(r=>{if(!r){o.finish(null);return}if(r.complete&&s==r.pages.length-1){if(n>=this.opf.spine.length-1){o.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(o)}),o.result()}previousPage(t,e){let n=t.spineIndex,s=t.pageIndex;if(s==0){if(n==0)return w(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 w({left:null,right:null});let s=I("getSpread"),o=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),o?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 w(null);let s=this.isRectoPage(n,t),o=this.nextPage(t,e);return s?o:o.thenAsync(r=>{if(r){if(r.page.side===n.side)return o;let a=this.nextPage(r.position,e);return a.thenAsync(l=>l?a:o)}else return w(null)})}previousSpread(t,e){let n=this.getPage(t);if(!n)return w(null);let s=this.isRectoPage(n,t),o=this.previousPage(t,e),r=n.container.previousElementSibling;return s?o.thenAsync(a=>a?a.page.side===n.side||a.page.container!==r?o:this.previousPage(a.position,e):w(null)):o}navigateToEPage(t,e,n){let s=I("navigateToEPage");return this.opf.resolveEPage(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}navigateToFragment(t,e,n){let s=I("navigateToCFI");return this.opf.resolveFragment(t).then(o=>{o?this.findPage(o,n).thenFinish(s):s.finish(null)}),s.result()}resolveSemanticFootnoteNavigationOffset(t,e){if(!rt(e))return null;let n=e.getAttribute("id");if(!n)return null;let s=te(`#${n}`,t.xmldoc.url),o=t.xmldoc.document.getElementsByTagName("a");for(let r=0;r<o.length;r++){let a=o.item(r);if(!bt(a))continue;let l=a.getAttribute("href")||a.getAttributeNS("http://www.w3.org/1999/xlink","href");if(l&&te(l,t.xmldoc.url)===s)return t.xmldoc.getElementOffset(a)}return null}navigateTo(t,e,n){B.debug("Navigate to",t);let s=this.opf.getPathFromURL(Gt(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 w(null)}let o=this.opf.itemMapByPath[s];if(!o){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 w(null)}let r=I("navigateTo");return this.waitForPreviousSpines(o.spineIndex,n).then(()=>{this.getPageViewItem(o.spineIndex).then(a=>{if(!a){r.finish(null);return}let l=a.xmldoc.getElement(t),c=l&&this.resolveSemanticFootnoteNavigationOffset(a,l),u=c!=null?c:l?a.xmldoc.getElementOffset(l):0;this.findPage({spineIndex:o.spineIndex,pageIndex:-1,offsetInItem:u},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",js||(s.style.visibility="hidden"),n.layoutBox.appendChild(s);let o=n.document.createElement("div");o.setAttribute("data-vivliostyle-bleed-box","true"),o.role="presentation",s.appendChild(o);let r=new br(s,o);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);o.setAttribute("id",a),r.registerElementWithId(o,a)}if(n!==this.viewport){let a=Mu(this.viewport.width,this.viewport.height,n.width,n.height),l=Ts(null,new ot(a,null),"");r.delayedItems.push(new Ls(s,"transform",l))}return r}makeObjectView(t,e,n,s){let o=e.getAttribute("data"),r=null;if(o){o=te(o,t.url);let a=e.getAttribute("media-type");if(!a){let l=this.opf.getPathFromURL(o);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=Fu(o),u=Fu(a),d=new lt;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 b=m.getAttribute("name"),y=m.getAttribute("value");b&&y&&(d.append("&"),d.append(encodeURIComponent(b)),d.append("="),d.append(encodeURIComponent(y)))}}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"),o&&r.setAttribute("data",o),r.setAttribute("data-adapt-process-children","true")),w(r)}makeMathJaxView(t,e,n,s){let o=HE();if(o){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=o.queue;c.Push(["Typeset",o,a]);let u=I("makeMathJaxView"),d=u.suspend();return c.Push(()=>{d.schedule(a)}),u.result()}return w(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 o=te(s.nodeValue,e.url);s.namespaceURI?t.setAttributeNS(s.namespaceURI,s.name,o):t.setAttribute(s.name,o)}}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):w(null)}getPageViewItem(t){if(t===-1||t>=this.opf.spine.length)return w(null);let e=this.spineItems[t];if(e)return w(e);let n=I("getPageViewItem"),s=this.spineItemLoadingContinuations[t];if(s){let a=n.suspend();return s.push(a),n.result()}else s=this.spineItemLoadingContinuations[t]=[];let o=this.opf.spine[t],r=this.opf.store;return r.load(o.src).then(a=>{var N;let l=o.itemRefElement.getAttribute("properties");l&&a.root.setAttribute("data-vivliostyle-epub-spine-properties",l),o.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 hs(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(N=this.spineItems[0])==null?void 0:N.instance.isVersoFirstPage,g=this.spineItems[t-1],m,b;if(o.startPage!==null)m=o.startPage-1,b=m;else{if(t>0&&(!g||!g.complete))m=o.epage||t,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,b=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let x=g&&g.pageCounterStarts[g.pages.length-1],E=x&&x.page;if(E&&E.length)b=E[E.length-1]+1;else{let v=this.counterStore.currentPageCounters.page;b=!v||!v.length?m:v[v.length-1]}}o.skipPagesBefore!==null&&(m+=o.skipPagesBefore,b+=o.skipPagesBefore)}this.counterStore.forceSetPageCounter(b);let y=new Gs(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);y.pref=this.pref;let C=this.opf.metadata&&this.opf.metadata[Ge.title];y.pubTitle=C&&C[0]&&C[0].v||"",y.docTitle=o.title||"",y.init().then(()=>{!this.opf.pageProgression&&y.pageProgression&&(this.opf.pageProgression=y.pageProgression),e={item:o,xmldoc:a,instance:y,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[t]=e,n.finish(e),s.forEach(x=>{x.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 w(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"),w(this.tocView.page);let s=I("showTOC");this.tocView||(this.tocView=new lu(e.store,n.src,e.lang,this.clientLayout,this.fontMapper,this.pref,this,e.fallbackMap,e.documentURLTransformer,this.counterStore,this.cmykStore));let o=this.viewport,r=Math.min(344,Math.round(.67*o.width)-16),a=o.height-6,l=o.document.createElement("div");return o.root.appendChild(l),js||(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,o,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 _b="data-vivliostyle-viewer-status",GE="data-vivliostyle-spread-view",Qf=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(Qf||{}),fu=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");p(this,"cmykReserveMap");p(this,"cmykReserveMapUrl");let o=e.ownerDocument,r=(a,l)=>{let c=o.getElementById(a);return c||(c=o.createElement("style"),c.id=a,l&&(c.textContent=l),o.head.appendChild(c)),c};r("vivliostyle-viewport-screen-css",bd),r("vivliostyle-viewport-css",yd),r("vivliostyle-polyfill-css",Td),e.setAttribute("data-vivliostyle-viewer-viewport",!0),js&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(_b,"loading"),this.fontMapper=new Gc(o.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=Du(),this.pageSizes=[],this.pixelRatioLimit=Mo==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=Pu;B.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),B.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),B.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),B.addListener(t.ERROR,e=>{this.callback({t:"error",content:e})})}callback(t){t.i=this.instanceId,this.callbackFn(t)}setReadyState(t){if(this.readyState!==t){this.readyState=t,this.viewportElement.setAttribute(_b,t);let e=this.getCurrentPageProgression();e&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",e),this.callback({t:"readystatechange"})}}loadPublication(t){ht.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.fragment,s=t.authorStyleSheet,o=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let r=I("loadPublication");return this.configure(t).then(()=>{let a=new Sa;a.init(s,o).then(()=>{let l=te(Xn(e),this.window.location.href);this.packageURL=[l],a.loadPubDoc(l).then(c=>{c?(this.opf=c,this.loadCmykReserveMap(a).then(()=>{this.render(n).then(()=>{r.finish(!0)})})):r.finish(!1)})})}),r.result()}loadXML(t){ht.registerStartTiming("beforeRender"),this.setReadyState("loading");let e=t.url,n=t.document,s=t.fragment,o=t.authorStyleSheet,r=t.userStyleSheet;this.cmykReserveMapUrl=t.cmykReserveMapUrl,this.viewport=null;let a=I("loadXML");return this.configure(t).then(()=>{let l=new Sa;l.init(o,r).then(()=>{let c=e.map((u,d)=>({url:te(Xn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Vo(l,""),this.opf.initWithChapters(c,n).then(()=>{this.loadCmykReserveMap(l).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,w(!0))):e=w(!0),e.thenAsync(()=>(ht.registerEndTiming("beforeRender"),this.resize()))}resolveLength(t){let e=parseFloat(t),n=/[a-z]+$/,s;if(typeof t=="string"&&(s=t.match(n))){let o=s[0];if(o==="em"||o==="rem")return e*this.fontSize;let r=ct[o];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"&&(Au(t.userAgentRootURL.replace(/resources\/?$/,"")),Ru(t.userAgentRootURL)),typeof t.rootURL=="string"&&(Au(t.rootURL),Ru(`${Tn}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!==vn&&(wb(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),w(!0)}configurePlugins(t){Je("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=>{P(t.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(t){t.addEventListener("hyperlink",this.hyperlinkListener,!1),t.addEventListener("replaced",this.pageReplacedListener,!1),P(t.container,"visibility","visible"),P(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=I("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?Cn(n.fetchers):w(!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 hs(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new hs(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(GE,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 o,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[n].width!==((o=this.pageSizes[n-1])==null?void 0:o.width)||this.pageSizes[n].height!==((r=this.pageSizes[n-1])==null?void 0:r.height))){let c=function(m){let b=m*.75;return Math.ceil(b)};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)}loadCmykReserveMap(t){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,w(!0);let e=te(Xn(this.cmykReserveMapUrl),Tn),n=I("loadCmykReserveMap");return t.loadAsJSON(e).then(s=>{Tg(s)?this.cmykReserveMap=s:(B.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),n.finish(!0)}),n.result()}reset(){let t=!1,e=!1;this.opfView&&(t=this.opfView.tocVisible,e=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new hu(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),t&&this.sendCommand({a:"toc",v:"show",autohide:e})}showCurrent(t,e){this.needRefresh=!1,this.removePageListeners();let 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?w(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,w(null)):(this.showSpread(s),this.setSpreadZoom(s),this.currentPage=t.side==="left"?s.left:s.right,w(null))):(this.showPage(t),this.setPageZoom(t),this.currentPage=t,w(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 gu),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return w(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=di().getScheduler().run(()=>Qn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,ht.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 o={t:"nav",epageCount:s,first:this.currentPage.isFirstPage,last:this.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(o.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(o)}).then(()=>{this.reportPosition().then(s=>{(this.renderAllPages?this.opfView.renderAllPages():w(null)).then(()=>{this.renderTask===t&&(this.renderTask=null),ht.registerEndTiming("render (resize)"),vn&&zf(this.window)?Ab(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 gu)ht.registerEndTiming("render (resize)"),B.debug(n.message);else throw n}));return w(!0)}sendLocationNotification(t,e){let n=I("sendLocationNotification"),s={t:"nav",first:t.isFirstPage,last:this.isLastPageForNotification(t),metadata:this.opf.metadata,docTitle:this.opf.spine[t.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(o=>{s.epage=o,s.epageCount=this.opf.epageCount,e&&(s.cfi=e),this.callback(s),n.finish(!0)}),n.result()}isLastPageForNotification(t){if(!this.opfView||!this.pagePosition)return t.isLastPage;let e=this.opfView.spineItems[this.pagePosition.spineIndex];if(!e||!e.complete)return!1;let n=e.item.spineIndex===this.opf.spine.length-1,s=this.pagePosition.pageIndex===e.pages.length-1;return n&&s}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 o;switch(t.where){case"next":o=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":o=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":o=this.opfView.lastPage;break;case"first":o=this.opfView.firstPage;break;default:return w(!0)}o&&(e=()=>o.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof t.epage=="number"){let o=t.epage;e=()=>this.opfView.navigateToEPage(o,this.pagePosition,!this.renderAllPages)}else if(typeof t.url=="string"){let o=t.url;e=()=>this.opfView.navigateTo(o,this.pagePosition,!this.renderAllPages)}else if(typeof((s=t.position)==null?void 0:s.spineIndex)=="number"){let o=t.position;e=()=>this.opfView.findPage(o,!this.renderAllPages)}else return w(!0);if(!this.opfView)return w(!0);let n=I("moveTo");return e.call(this.opfView).then(o=>{let r;if(o){this.pagePosition=o.position;let a=I("moveTo.showCurrent");r=a.result(),this.showCurrent(o.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(a)})}else r=w(!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(),o=e!=this.opfView.tocAutohide&&n!="hide";if(s){if(n=="show"&&!o)return w(!0)}else if(n=="hide")return w(!0);if(s&&n!="show")return this.opfView.hideTOC(),w(!0);{let r=I("showTOC");return this.opfView.showTOC(e).then(a=>{if(a){if(o&&(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 Qn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(B.error("No such action:",e),n.finish(!0))},(n,s)=>{B.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=Ub(t),n=null,s=this;sm(()=>{let o=I("commandLoop"),r=di().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),w(!0)))}},o.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=I("waitForCommand");n=l.suspend(this),l.result().then(()=>{a.continueLoop()})}}).thenFinish(o),o.result()}),s.kick=()=>{let o=n;o&&(n=null,o.schedule(!0))},s.sendCommand=o=>e?!1:(e=Ub(o),s.kick(),!0),this.window.adapt_command=s.sendCommand}},Jf=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(Jf||{}),gu=class i extends Error{constructor(){super();p(this,"name","RenderingCanceledError");p(this,"message","Page rendering has been canceled");p(this,"stack");Object.setPrototypeOf(this,i.prototype),this.stack=new Error().stack}};function Ub(i){return typeof i=="string"?_o(i):i}var Hb=Ys;function WE(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function zb(i){let t={};return Object.keys(i).forEach(e=>{let n=i[e];switch(e){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[e]=n}}),t}var xa=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");vu(t.debug),this.adaptViewer_=new fu(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=WE(),e&&this.setOptions(e),this.eventTarget=new gs,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},zb(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 o=n||{};function r(u){if(u)return u.map(d=>({url:d.url||null,text:d.text||null}))}let a=r(o.authorStyleSheet),l=r(o.userStyleSheet);s&&Object.assign(this.options,s);let c=Object.assign({a:t?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:XE(t)||e,document:o.documentObject,fragment:o.fragment,authorStyleSheet:a,userStyleSheet:l,cmykReserveMapUrl:o.cmykReserveMapUrl},zb(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()===Hb.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Hb.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 XE(i){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(i)?i.map(e):i?[e(i)]:null}var Gb=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(Gb||{}),jE=Jf,YE=Qf;ht.forceRegisterEndTiming("load_vivliostyle");var eg=class{constructor(t,{title:e="",printCallback:n=a=>a.print(),errorCallback:s=null,hideIframe:o=!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=o,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=`
1853
1850
  <!DOCTYPE html>
1854
1851
  <html data-vivliostyle-paginated="true">
1855
1852
  <head>
@@ -1877,6 +1874,6 @@ span[data-viv-leader] {
1877
1874
  <body onload='parent.printInstance.runInIframe(window)'>
1878
1875
  <div id="vivliostyle-viewer-viewport"></div>
1879
1876
  </body>
1880
- </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 fa({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",o=>{var a,l;let r=(l=(a=o.content.error)==null?void 0:a.toString())!=null?l:o.content.messages.join(`
1881
- `);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 WS(i,t){new Bf(i,t).init()}
1877
+ </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 xa({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",o=>{var a,l;let r=(l=(a=o.content.error)==null?void 0:a.toString())!=null?l:o.content.messages.join(`
1878
+ `);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 qE(i,t){new eg(i,t).init()}
1882
1879
  //# sourceMappingURL=vivliostyle.js.map