@vivliostyle/core 2.42.0 → 2.42.1

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,12 +1,12 @@
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([`
1
+ "use strict";var iy=Object.create;var jr=Object.defineProperty;var ay=Object.getOwnPropertyDescriptor;var ly=Object.getOwnPropertyNames;var cy=Object.getPrototypeOf,uy=Object.prototype.hasOwnProperty;var yg=i=>{throw TypeError(i)};var dy=(i,t,e)=>t in i?jr(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var py=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),hy=(i,t)=>{for(var e in t)jr(i,e,{get:t[e],enumerable:!0})},Sg=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ly(t))!uy.call(i,s)&&s!==e&&jr(i,s,{get:()=>t[s],enumerable:!(n=ay(t,s))||n.enumerable});return i};var fy=(i,t,e)=>(e=i!=null?iy(cy(i)):{},Sg(t||!i||!i.__esModule?jr(e,"default",{value:i,enumerable:!0}):e,i)),gy=i=>Sg(jr({},"__esModule",{value:!0}),i);var p=(i,t,e)=>dy(i,typeof t!="symbol"?t+"":t,e),Pu=(i,t,e)=>t.has(i)||yg("Cannot "+e);var O=(i,t,e)=>(Pu(i,t,"read from private field"),e?e.call(i):t.get(i)),Z=(i,t,e)=>t.has(i)?yg("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),ke=(i,t,e,n)=>(Pu(i,t,"write to private field"),n?n.call(i,e):t.set(i,e),e),Ce=(i,t,e)=>(Pu(i,t,"access private method"),e);var Km=py((Mv,qm)=>{var qt=-1,Rt=1,st=0;function Si(i,t,e,n,s){if(i===t)return i?[[st,i]]:[];if(e!=null){var o=nx(i,t,e);if(o)return o}var r=Zd(i,t),a=i.substring(0,r);i=i.substring(r),t=t.substring(r),r=Rl(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=YS(i,t);return a&&c.unshift([st,a]),l&&c.push([st,l]),Qd(c,s),n&&ZS(c),c}function YS(i,t){var e;if(!i)return[[Rt,t]];if(!t)return[[qt,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=[[Rt,n.substring(0,o)],[st,s],[Rt,n.substring(o+s.length)]],i.length>t.length&&(e[0][0]=e[2][0]=qt),e;if(s.length===1)return[[qt,i],[Rt,t]];var r=KS(i,t);if(r){var a=r[0],l=r[1],c=r[2],u=r[3],d=r[4],h=Si(a,c),f=Si(l,u);return h.concat([[st,d]],f)}return qS(i,t)}function qS(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 x=-b+h;x<=b-f;x+=2){var C=o+x,v;x===-b||x!==b&&a[C-1]<a[C+1]?v=a[C+1]:v=a[C-1]+1;for(var y=v-x;v<e&&y<n&&i.charAt(v)===t.charAt(y);)v++,y++;if(a[C]=v,v>e)f+=2;else if(y>n)h+=2;else if(d){var N=o+u-x;if(N>=0&&N<r&&l[N]!==-1){var E=e-l[N];if(v>=E)return Um(i,t,v,y)}}}for(var T=-b+g;T<=b-m;T+=2){var N=o+T,E;T===-b||T!==b&&l[N-1]<l[N+1]?E=l[N+1]:E=l[N-1]+1;for(var k=E-T;E<e&&k<n&&i.charAt(e-E-1)===t.charAt(n-k-1);)E++,k++;if(l[N]=E,E>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 v=a[C],y=o+v-C;if(E=e-E,v>=E)return Um(i,t,v,y)}}}}return[[qt,i],[Rt,t]]}function Um(i,t,e,n){var s=i.substring(0,e),o=t.substring(0,n),r=i.substring(e),a=t.substring(n),l=Si(s,o),c=Si(r,a);return l.concat(c)}function Zd(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 $m(i.charCodeAt(s-1))&&s--,s}function Hm(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 Rl(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 Xm(i.charCodeAt(i.length-s))&&s--,s}function KS(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)),x=-1,C="",v,y,N,E;(x=g.indexOf(b,x+1))!==-1;){var T=Zd(f.substring(m),g.substring(x)),k=Rl(f.substring(0,m),g.substring(0,x));C.length<k+T&&(C=g.substring(x-k,x)+g.substring(x,x+T),v=f.substring(0,m-k),y=f.substring(m+T),N=g.substring(0,x-k),E=g.substring(x+T))}return C.length*2>=f.length?[v,y,N,E,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 ZS(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]==st?(e[n++]=o,r=l,a=c,l=0,c=0,s=i[o][1]):(i[o][0]==Rt?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,[qt,s]),i[e[n-1]+1][0]=Rt,n--,n--,o=n>0?e[n-1]:-1,r=0,a=0,l=0,c=0,s=null,t=!0)),o++;for(t&&Qd(i),ex(i),o=1;o<i.length;){if(i[o-1][0]==qt&&i[o][0]==Rt){var u=i[o-1][1],d=i[o][1],h=Hm(u,d),f=Hm(d,u);h>=f?(h>=u.length/2||h>=d.length/2)&&(i.splice(o,0,[st,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,[st,u.substring(0,f)]),i[o-1][0]=Rt,i[o-1][1]=d.substring(0,d.length-f),i[o+1][0]=qt,i[o+1][1]=u.substring(f),o++),o++}o++}}var zm=/[^a-zA-Z0-9]/,Gm=/\s/,Wm=/[\r\n]/,QS=/\n\r?\n$/,JS=/^\r?\n\r?\n/;function ex(i){function t(f,g){if(!f||!g)return 6;var m=f.charAt(f.length-1),b=g.charAt(0),x=m.match(zm),C=b.match(zm),v=x&&m.match(Gm),y=C&&b.match(Gm),N=v&&m.match(Wm),E=y&&b.match(Wm),T=N&&f.match(QS),k=E&&g.match(JS);return T||k?5:N||E?4:x&&!v&&y?3:v||y?2:x||C?1:0}for(var e=1;e<i.length-1;){if(i[e-1][0]==st&&i[e+1][0]==st){var n=i[e-1][1],s=i[e][1],o=i[e+1][1],r=Rl(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 Qd(i,t){i.push([st,""]);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 Rt:s++,r+=i[e][1],e++;break;case qt:n++,o+=i[e][1],e++;break;case st:var l=e-s-n-1;if(t){if(l>=0&&Ym(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]===Rt&&(s++,r=i[u][1]+r,u--),i[u]&&i[u][0]===qt&&(n++,o=i[u][1]+o,u--),l=u}}if(jm(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=Zd(r,o),a!==0&&(l>=0?i[l][1]+=r.substring(0,a):(i.splice(0,0,[st,r.substring(0,a)]),e++),r=r.substring(a),o=o.substring(a)),a=Rl(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,[Rt,r]),e=e-d+1):r.length===0?(i.splice(e-d,d,[qt,o]),e=e-d+1):(i.splice(e-d,d,[qt,o],[Rt,r]),e=e-d+2)}e!==0&&i[e-1][0]===st?(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]===st&&i[e+1][0]===st&&(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&&Qd(i,t)}function $m(i){return i>=55296&&i<=56319}function Xm(i){return i>=56320&&i<=57343}function jm(i){return Xm(i.charCodeAt(0))}function Ym(i){return $m(i.charCodeAt(i.length-1))}function tx(i){for(var t=[],e=0;e<i.length;e++)i[e][1].length>0&&t.push(i[e]);return t}function Kd(i,t,e,n){return Ym(i)||jm(n)?null:tx([[st,i],[qt,t],[Rt,e],[st,n]])}function nx(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 x=l.slice(g),C=h.slice(g);return Kd(m,x,C,c)}e:{if(u!==null&&u!==a)break e;var v=a,h=t.slice(0,v),f=t.slice(v);if(h!==l)break e;var y=Math.min(o-v,r-v),N=c.slice(c.length-y),E=f.slice(f.length-y);if(N!==E)break e;var x=c.slice(0,c.length-y),C=f.slice(0,f.length-y);return Kd(l,x,C,N)}}if(n.length>0&&s&&s.length===0)e:{var m=i.slice(0,n.index),N=i.slice(n.index+n.length),g=m.length,y=N.length;if(r<g+y)break e;var b=t.slice(0,g),E=t.slice(r-y);if(m!==b||N!==E)break e;var x=i.slice(g,o-y),C=t.slice(g,r-y);return Kd(m,x,C,N)}return null}function Ll(i,t,e,n){return Si(i,t,e,n,!0)}Ll.INSERT=Rt;Ll.DELETE=qt;Ll.EQUAL=st;qm.exports=Ll});var fv={};hy(fv,{CoreViewer:()=>Ta,HOOKS:()=>Tt,Navigation:()=>ey,PageProgression:()=>Zs,PageSide:()=>Yr,PageViewMode:()=>pv,Profiler:()=>Fa,ReadyState:()=>Ru,UserAgentBaseCss:()=>Ad,UserAgentCounterStylesCss:()=>Id,UserAgentPageCss:()=>kd,UserAgentTocCss:()=>Rd,UserAgentXml:()=>Pd,ValidationTxt:()=>wd,VivliostylePolyfillCss:()=>Ld,VivliostyleViewportCss:()=>Td,VivliostyleViewportScreenCss:()=>Nd,ZoomType:()=>dv,getHooksForName:()=>nt,isDebug:()=>Ks,pageProgressionOf:()=>Au,plugin:()=>my,printHTML:()=>hv,profile:()=>Sy,profiler:()=>Ct,registerHook:()=>qe,removeHook:()=>xg,setDebug:()=>ku});module.exports=gy(fv);var Ks=!1;function ku(i){Ks=i}var Zs=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Zs||{});function Au(i){switch(i){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${i}`)}}var Yr=(e=>(e.LEFT="left",e.RIGHT="right",e))(Yr||{}),Ru=(n=>(n.LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete",n))(Ru||{});var Iu=(s=>(s[s.DEBUG=1]="DEBUG",s[s.INFO=2]="INFO",s[s.WARN=3]="WARN",s[s.ERROR=4]="ERROR",s))(Iu||{}),Lu=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=Ra(arguments);this.consoleDebug(La(e)),this.triggerListeners(1,e)}info(...t){let e=Ra(arguments);this.consoleInfo(La(e)),this.triggerListeners(2,e)}warn(...t){let e=Ra(arguments);this.consoleWarn(La(e)),this.triggerListeners(3,e)}error(...t){let e=Ra(arguments);this.consoleError(La(e)),this.triggerListeners(4,e)}};function Ra(i){let t=Array.from(i),e=null;return t[0]instanceof Error&&(e=t.shift()),{error:e,messages:t}}function La(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 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}
3
+ `]).concat(e))),n}var D=new Lu;var Tt=(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))(Tt||{}),Ia={};function qe(i,t,e){if(!Tt[i])D.warn(new Error(`Skipping unknown plugin hook '${i}'.`));else{let n=Ia[i];n||(n=Ia[i]=[]),e?n.unshift(t):n.push(t)}}function xg(i,t){if(!Tt[i])D.warn(new Error(`Ignoring unknown plugin hook '${i}'.`));else{let e=Ia[i];if(e){let n=e.indexOf(t);n>=0&&e.splice(n,1)}}}function nt(i){return Ia[i]||[]}var my={registerHook:qe,removeHook:xg};var Fa=class{constructor(t){this.performanceInstance=t;p(this,"timestamps",{});p(this,"registerTiming");p(this,"registerStartTiming");p(this,"registerEndTiming");this.registerTiming=zo,this.registerStartTiming=this.registerStartTiming=zo,this.registerEndTiming=this.registerEndTiming=zo}forceRegisterStartTiming(t,e){Fu.call(this,t,"start",e)}forceRegisterEndTiming(t,e){Fu.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
+ `}}),D.info(e)}disable(){this.registerTiming=zo,this.registerStartTiming=this.registerStartTiming=zo,this.registerEndTiming=this.registerEndTiming=zo}enable(){this.registerTiming=Fu,this.registerStartTiming=this.registerStartTiming=Eg,this.registerEndTiming=this.registerEndTiming=Cy}isEnabled(){return this.registerStartTiming===Eg}};function zo(){}function Fu(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 Eg(i,t){this.registerTiming(i,"start",t)}function Cy(i,t){this.registerTiming(i,"end",t)}var by={now:Date.now},yy=window&&window.performance,Ct=new Fa(yy||by);Ct.forceRegisterStartTiming("load_vivliostyle");var Sy={profiler:{registerStartTiming:Ct.registerStartTiming,registerEndTiming:Ct.registerEndTiming,printTimings:Ct.printTimings,disable:Ct.disable,enable:Ct.enable}};var Wo=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,Xt="data-adapt-eloff",Ng={};function $o(i){return JSON.parse(i)}function wt(i){let t=i.match(/^([^#]*)/);return t?t[1]:i}function Tg(i){let t=i.match(/^([^#?]*)/);return t?t[1]:i}var wn=window.location.href;function Vu(i){wn=i}var un=window.location.href;function Bu(i){un=i}function xy(i){let t=Tg(i).match(/^(https?:\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+)(?:\/|$)/);return t?t[1]:null}function Cs(i){return i.replace(/^(https?:)\/\/raw\.githack\.com\/web-platform-tests\/wpt\/[^/]+\//,"$1//wpt.live/")}function ne(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=xy(t);return r?r+i:(e=t.match(/^(\w{2,}:\/\/[^\/]+)\//),e?e[1]+i:i)}if(i.match(/^\.(\/|$)/)&&(i=i.substr(2)),t=Tg(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 Js(i,t){return i.match(/^#/)&&t?wt(t)+i:ne(i,t)}function Ou(i){return/^about:blank($|[?#])/i.test(i)?"data:text/html,":i}function jn(i){let t;return(i=Ou(i))!==i||((t=/^(https?:)\/\/github\.com\/web-platform-tests\/wpt\/(blob\/|tree\/|raw\/)?(.*)$/.exec(i))?i=`${t[1]}//raw.githack.com/web-platform-tests/wpt/${t[2]?"":"master/"}${t[3]}`:(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))?/\.sub\.[^/]+(?:[?#].*)?$/.test(t[2])||(i=`${t[1]}//raw.githack.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 Du(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}},Mu=["","-webkit-","-moz-"],Go={};function Kr(i,t){return CSS.supports(i+t,"unset")}function Ey(i){let t=Go[i];if(t||t===null)return t;switch(i){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Go[i]=null,null;case"text-combine-upright":if(Kr("-webkit-","text-combine")&&!Kr("","text-combine-upright"))return Go[i]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let e of Mu)if(Kr(e,i))return t=[e+i],Go[i]=t,t;return D.warn("Property not supported by the browser: ",i),Go[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=Ey(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 dn(i,t,e){try{let n=Go[t];return i.style.getPropertyValue(n?n[0]:t)}catch(n){}return e||""}function Zr(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 ut=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 Ba(i){return`\\${i.charCodeAt(0).toString(16)} `}function Pn(i){return i.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Ba)}function eo(i){return i.replace(/[\u0000-\u001F"\\]/g,Ba)}function _u(i){return i.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Uu(i){return!!i.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function vy(i,t){return t=typeof t=="string"?t:"\\u",t+(65536|i.charCodeAt(0)).toString(16).substr(1)}function Hu(i,t){function e(n){return vy(n,t)}return i.replace(/[^-a-zA-Z0-9_]/g,e)}function Yn(i){return Hu(i)}function Ny(i,t){return t=typeof t=="string"?t:"\\u",i.indexOf(t)===0?String.fromCharCode(parseInt(i.substring(t.length),16)):i}function wg(i,t){t=typeof t=="string"?t:"\\u";function e(s){return Ny(s,t)}let n=new RegExp(`${Yn(t)}[0-9a-fA-F]{4}`,"g");return i.replace(n,e)}function Mt(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 Oa(i,t){return i-t}function zu(i,t){let e={};for(let n of i){let s=t(n);s&&!e[s]&&(e[s]=n)}return e}function Pg(i){let t={};for(let e=0;e<i.length;e++)t[i[e]]=!0;return t}function Da(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 kg(i,t){let e={};for(let n in i)e[n]=t(i[n],n);return e}var ms=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)}}},kn={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Gu(){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 Za(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 Ty=Gu(),Ag={PENDING:{}};function Wu(i,t,e,n){let s=Math.min((i-0)/e,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function wy(i){return`"${eo(`${i}`)}"`}function Py(i){return Pn(`${i}`)}function oi(i,t){return i?`${Pn(i)}.${Pn(t)}`:Pn(t)}var Rg=0,to=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${Rg++}`,this.zero=new Pe(this,0),this.one=new Pe(this,1),this._true=new Pe(this,!0),this._false=new Pe(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=Wu,n["css-string"]=wy,n["css-name"]=Py,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 se(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 Lg(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 Ig(i){switch(i==null?void 0:i.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Fg(i){switch(i==null?void 0:i.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var dt={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 Qa(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 Xo=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=Ty}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:dt[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 Pe(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}},_t=class{constructor(t){this.scope=t;p(this,"key");this.scope=t,this.key=`_${Rg++}`}toString(){let t=new ut;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===Ag.PENDING?!1:s;{n[this.key]=Ag.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}},Ma=class extends _t{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)}},jo=class extends _t{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)}},_a=class extends jo{constructor(t,e,n){super(t,e,n)}getPriority(){return 1}},bs=class extends jo{constructor(t,e,n){super(t,e,n)}getPriority(){return 2}},Ua=class extends jo{constructor(t,e,n){super(t,e,n)}getPriority(){return 3}},Qr=class extends jo{constructor(t,e,n){super(t,e,n)}getPriority(){return 4}},jt=class extends Ma{constructor(t,e){super(t,e)}getOp(){return"!"}evalPrefix(t){return!t}},Ha=class extends jt{constructor(t,e){super(t,e)}getOp(){return"not "}},An=class extends Ma{constructor(t,e){super(t,e)}getOp(){return"-"}evalPrefix(t){return-t}},Yo=class extends _a{constructor(t,e,n){super(t,e,n)}getOp(){return"&&"}evaluateCore(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)}},za=class extends Yo{constructor(t,e,n){super(t,e,n)}getOp(){return" and "}},qo=class extends _a{constructor(t,e,n){super(t,e,n)}getOp(){return"||"}evaluateCore(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)}},Ga=class extends qo{constructor(t,e,n){super(t,e,n)}getOp(){return", "}},Wa=class extends qo{constructor(t,e,n){super(t,e,n)}getOp(){return" or "}},$a=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return"<"}evalInfix(t,e){return t<e}},Xa=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return"<="}evalInfix(t,e){return t<=e}},ja=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return">"}evalInfix(t,e){return t>e}},no=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return">="}evalInfix(t,e){return t>=e}},ys=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return"=="}evalInfix(t,e){return t==e}},Ya=class extends bs{constructor(t,e,n){super(t,e,n)}getOp(){return"!="}evalInfix(t,e){return t!=e}},Jr=class extends Ua{constructor(t,e,n){super(t,e,n)}getOp(){return"+"}evalInfix(t,e){return t+e}},ei=class extends Ua{constructor(t,e,n){super(t,e,n)}getOp(){return" - "}evalInfix(t,e){return t-e}},so=class extends Qr{constructor(t,e,n){super(t,e,n)}getOp(){return"*"}evalInfix(t,e){return t*e}},ti=class extends Qr{constructor(t,e,n){super(t,e,n)}getOp(){return"/"}evalInfix(t,e){return t/e}},Ko=class extends Qr{constructor(t,e,n){super(t,e,n)}getOp(){return"%"}evalInfix(t,e){return t%e}},pn=class extends _t{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(Pn(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},xe=class extends _t{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)}},ni=class extends _t{constructor(e,n,s){super(e);this.not=n;this.name=s}appendTo(e,n){this.not&&e.append("not "),e.append(Pn(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},se=class extends _t{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 ky(i,t){i.append("(");for(let e=0;e<t.length;e++)e&&i.append(","),t[e].appendTo(i,0);i.append(")")}function Ay(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 qn=class i extends _t{constructor(e,n,s){super(e);this.qualifiedName=n;this.params=s}appendTo(e,n){e.append(this.qualifiedName),ky(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=Ay(e,this.params,n);return s===this.params?this:new i(this.scope,this.qualifiedName,s)}},qa=class i extends _t{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)}},Pe=class extends _t{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(eo(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},si=class i extends _t{constructor(e,n,s){super(e);this.name=n;this.value=s}appendTo(e,n){e.append("("),e.append(eo(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)}},Ka=class extends _t{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)}},Zo=class extends _t{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 Pt(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 Yo(i,t,e)}function K(i,t,e){return t===i.zero?e:e===i.zero?t:new Jr(i,t,e)}function ae(i,t,e){return t===i.zero?new An(i,e):e===i.zero?t:new ei(i,t,e)}function Qo(i,t,e){return t===i.zero||e===i.zero?i.zero:t===i.one?e:e===i.one?t:new so(i,t,e)}function ri(i,t,e){return t===i.zero?i.zero:e===i.one?t:new ti(i,t,e)}var Ut=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}},nn=class extends Ut{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 j(n)}visitCommaList(e){let n=this.visitValues(e.values);return this.error?$:n===e.values?e:new Te(n)}visitFunc(e){let n=this.visitValues(e.values);return this.error?$:n===e.values?e:new pt(e.name,n)}visitExpr(e){return e}},Ue=class{toString(){let t=new ut;return this.appendTo(t,!0),t.toString()}stringValue(){let t=new ut;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}},Ja=class Ja extends Ue{static get instance(){return this.empty||(this.empty=new Ja),this.empty}constructor(){super()}toExpr(t,e){return new Pe(t,"")}appendTo(t,e){}visit(t){return t.visitEmpty(this)}};p(Ja,"empty");var Xu=Ja,$=Xu.instance,el=class el extends Ue{static get instance(){return this.slash||(this.slash=new el),this.slash}constructor(){super()}toExpr(t,e){return new Pe(t,"/")}appendTo(t,e){t.append("/")}visit(t){return t.visitSlash(this)}};p(el,"slash");var ju=el,Kn=ju.instance,G=class extends Ue{constructor(e){super();this.str=e}toExpr(e,n){return new Pe(e,this.str)}appendTo(e,n){n?(e.append('"'),e.append(eo(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Yu=Object.create(null),Q=class extends Ue{constructor(e){super();this.name=e;if(Yu[e])throw new Error("E_INVALID_CALL");Yu[e]=this}toExpr(e,n){return new Pe(e,this.name)}appendTo(e,n){n?e.append(Pn(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function R(i){let t=Yu[i];return t||(t=new Q(i)),t}var A=class extends Ue{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 so(e,n,new Pe(e,this.num/100)):new pn(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}},He=class extends Ue{constructor(e){super();this.num=e}toExpr(e,n){return this.num==0?e.zero:this.num==1?e.one:new Pe(e,this.num)}appendTo(e,n){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},pe=class extends He{constructor(t){super(t)}visit(t){return t.visitInt(this)}},Jo=class extends Ue{constructor(e){super();this.hex=e}appendTo(e,n){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Ae=class extends Ue{constructor(e){super();this.url=e}appendTo(e,n){e.append('url("'),e.append(eo(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},ii=class extends Ue{constructor(e){super();this.urangeText=e}appendTo(e,n){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function qu(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 j=class extends Ue{constructor(e){super();this.values=e}appendTo(e,n){qu(e,this.values," ",n)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Te=class extends Ue{constructor(e){super();this.values=e}appendTo(e,n){qu(e,this.values,",",n)}visit(e){return e.visitCommaList(this)}},pt=class extends Ue{constructor(e,n){super();this.name=e;this.values=n}appendTo(e,n){e.append(Pn(this.name)),e.append("("),qu(e,this.values,",",n),e.append(")")}visit(e){return e.visitFunc(this)}},_=class extends Ue{constructor(e){super();this.expr=e}toExpr(){return this.expr}appendTo(e,n){this.expr instanceof Pe||this.expr instanceof pn?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}},Rn=class extends Ue{constructor(e){super();this.text=e}appendTo(e,n){e.append(this.text||" ")}};function Ke(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 tl(i,t){return new A(Ke(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")},Ku=new A(100,"%"),Ss=new A(100,"pvw"),xs=new A(100,"pvh"),be=new A(0,"px"),xv=new ii("U+0-10FFFF"),Vg={"font-size":1,"line-height":2,color:3};function X(i){return i===S.inherit||i===S.initial||i===S.revert||i===S.unset}function Zu(i,t){let e=Vg[i]||Number.MAX_VALUE,n=Vg[t]||Number.MAX_VALUE;return e-n}function Ht(i){return(i==null?void 0:i.length)>2&&i.startsWith("--")}var oo,ro,io,hn=class hn{constructor(t,e,n){Z(this,oo);Z(this,ro);Z(this,io);ke(this,oo,Math.round(Math.max(0,Math.min(t,hn.MAX)))),ke(this,ro,Math.round(Math.max(0,Math.min(e,hn.MAX)))),ke(this,io,Math.round(Math.max(0,Math.min(n,hn.MAX))))}static fromInt(t,e,n){return new hn(t,e,n)}offset(t,e,n){return new hn(O(this,oo)+t,O(this,ro)+e,O(this,io)+n)}toKey(){return JSON.stringify([O(this,oo),O(this,ro),O(this,io)])}toColorFunc(t){return new pt("color",[new j([R("srgb"),new He(O(this,oo)/hn.MAX),new He(O(this,ro)/hn.MAX),new He(O(this,io)/hn.MAX),...t!==null?[Kn,new He(t)]:[]])])}};oo=new WeakMap,ro=new WeakMap,io=new WeakMap,p(hn,"MAX",1e4);var gn=hn;function Bg(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 Es,vs,Ns,fn,ht=class ht{constructor(t,e,n,s){Z(this,Es);Z(this,vs);Z(this,Ns);Z(this,fn);ke(this,Es,Math.round(Math.max(0,Math.min(t,ht.MAX)))),ke(this,vs,Math.round(Math.max(0,Math.min(e,ht.MAX)))),ke(this,Ns,Math.round(Math.max(0,Math.min(n,ht.MAX)))),ke(this,fn,Math.round(Math.max(0,Math.min(s,ht.MAX))))}static fromInt(t,e,n,s){return new ht(t,e,n,s)}static fromNumber(t,e,n,s){return new ht(t*ht.MAX,e*ht.MAX,n*ht.MAX,s*ht.MAX)}toSRGB(){let t=ht.MAX-O(this,fn);return gn.fromInt(gn.MAX-Math.min(gn.MAX,Math.round(O(this,Es)*t/ht.MAX)+O(this,fn)),gn.MAX-Math.min(gn.MAX,Math.round(O(this,vs)*t/ht.MAX)+O(this,fn)),gn.MAX-Math.min(gn.MAX,Math.round(O(this,Ns)*t/ht.MAX)+O(this,fn)))}equals(t){return O(this,Es)===O(t,Es)&&O(this,vs)===O(t,vs)&&O(this,Ns)===O(t,Ns)&&O(this,fn)===O(t,fn)}toJSON(){return{c:O(this,Es),m:O(this,vs),y:O(this,Ns),k:O(this,fn)}}};Es=new WeakMap,vs=new WeakMap,Ns=new WeakMap,fn=new WeakMap,p(ht,"MAX",1e4);var nl=ht;function er(i){return i instanceof He?Math.max(0,Math.min(1,i.num)):i instanceof A&&i.unit==="%"?Math.max(0,Math.min(1,i.num/100)):null}function Qu(i){if(i.name!=="device-cmyk"&&i.name!=="cmyk")return null;let t=i.values.length===1&&i.values[0]instanceof j?i.values[0].values:i.values;if(t.length<4||t.length>6)return null;let e=er(t[0]),n=er(t[1]),s=er(t[2]),o=er(t[3]);if(e===null||n===null||s===null||o===null)return null;let r=null;if(t.length>=5){if(t[4]===Kn){if(t.length!==6)return null;r=er(t[5])}else{if(t.length!==5)return null;r=er(t[4])}if(r===null)return null}return{cmyk:nl.fromNumber(e,n,s,o),alpha:r}}function*Ry(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 Zn,or,Og,Dg,ai=class{constructor(){Z(this,or);Z(this,Zn,new Map)}registerDeviceCmyk(t){let e=Qu(t);return e?Ce(this,or,Og).call(this,e.cmyk).toColorFunc(e.alpha):null}registerCmykReserveMap(t){for(let[e,n]of t){let s=gn.fromInt(e.r,e.g,e.b),o=nl.fromInt(n.c,n.m,n.y,n.k);O(this,Zn).set(s.toKey(),o)}}toJSON(){let t={};return O(this,Zn).forEach((e,n)=>{t[n]=e.toJSON()}),t}};Zn=new WeakMap,or=new WeakSet,Og=function(t){let e=t.toSRGB(),n=e.toKey(),s=O(this,Zn).get(n);return s?s.equals(t)?e:Ce(this,or,Dg).call(this,t,e):(O(this,Zn).set(n,t),e)},Dg=function(t,e){for(let n=1;n<=gn.MAX;n++)for(let[s,o,r]of Ry(n)){let a=e.offset(s,o,r),l=a.toKey();if(!O(this,Zn).has(l))return O(this,Zn).set(l,t),a}return D.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(t.toJSON())}`),e};var li,tr,nr,sr=class extends nn{constructor(e){super();Z(this,li);Z(this,tr,new Map);Z(this,nr,!1);ke(this,li,e!=null?e:new ai)}reset(){ke(this,nr,!1)}hadDeviceCmyk(){return O(this,nr)}recordConversion(e,n){O(this,tr).set(e,n)}getConversions(){if(O(this,tr).size===0)return null;let e={};return O(this,tr).forEach((n,s)=>{e[s]=n}),e}visitFunc(e){let n=O(this,li).registerDeviceCmyk(e);return n?(ke(this,nr,!0),n):super.visitFunc(e)}};li=new WeakMap,tr=new WeakMap,nr=new WeakMap;function Ug(i){if(i.nodeType==1){let t=i.getAttribute("id");if(t)return t}return null}function Ly(i){return`^${i}`}function Mg(i){return i.replace(/[\[\]\(\),=;^]/g,Ly)}function Iy(i){return i.substr(1)}function Ju(i){return i&&i.replace(/\^[\[\]\(\),=;^]/g,Iy)}function Fy(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 _g(i){let t={};for(;i;){let e=i.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!e)return t;t[e[1]]=Fy(e[2]),i=i.substr(e[0].length)}return t}var ol=class{appendTo(t){t.append("!")}applyTo(t){return!1}},rl=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:D.warn("E_CFI_ID_MISMATCH:",this.id)}return t.sideBias=this.sideBias,!0}},il=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(Mg(this.textBefore)),t.append(","),this.textAfter&&t.append(Mg(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))}},ci=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=_g(e[4]),o.push(new rl(a,l,Du(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=_g(e[10]),o.push(new il(a,l,c,Du(r.s)));break}case"!":s++,o.push(new ol);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 il(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 rl(u,c,s)),s=null,t=r,r=r.parentNode,n=!1}o.reverse(),this.steps?(o.push(new ol),this.steps=o.concat(this.steps)):this.steps=o}toString(){if(!this.steps)return"";let t=new ut;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 it=class{constructor(t,e,n,s){this.x1=t;this.y1=e;this.x2=n;this.y2=s}},mn=class{constructor(t,e){this.x=t;this.y=e}},ir=class{constructor(t,e,n,s){this.left=t;this.top=e;this.right=n;this.bottom=s}},al=class{constructor(t,e,n,s){this.low=t;this.high=e;this.winding=n;this.shapeId=s}},Cn=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 By(i,t){return i.low.y-t.low.y||i.low.x-t.low.x}var ao=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 al(o,a,1,e):l=new al(a,o,-1,e),t.push(l),o=a}}withOffset(t,e){let n=[];for(let s of this.points)n.push(new mn(s.x+t,s.y+e));return new i(n)}};function ed(i,t,e,n){let o=[];for(let r=0;r<20;r++){let a=r*2*Math.PI/20;o.push(new mn(i+e*Math.sin(a),t+n*Math.cos(a)))}return new ao(o)}function ui(i,t,e,n){return new ao([new mn(i,t),new mn(e,t),new mn(e,n),new mn(i,n)])}var rr=class{constructor(t,e,n,s){this.x=t;this.winding=e;this.shapeId=n;this.lowOrHigh=s}};function Hg(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 Oy(i,t,e,n){let s,o,r,a;t.high.y<e&&D.warn("Error: inconsistent segment (1)"),t.low.y<=e?(s=Hg(t,e),o=t.winding):(s=t.low.x,o=0),t.high.y>=n?(r=Hg(t,n),a=t.winding):(r=t.high.x,a=0),s<r?(i.push(new rr(s,o,t.shapeId,-1)),i.push(new rr(r,a,t.shapeId,1))):(i.push(new rr(r,a,t.shapeId,-1)),i.push(new rr(s,o,t.shapeId,1)))}function Dy(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 My(i,t){return t?Math.ceil(i/t)*t:i}function zg(i,t){return t?Math.floor(i/t)*t:i}function _y(i){return new mn(i.y,-i.x)}function ar(i){return new it(i.y1,-i.x2,i.y2,-i.x1)}function ll(i){return new it(-i.y2,i.x1,-i.y1,i.x2)}function Gg(i){return new ao(i.points.map(t=>_y(t)))}function Wg(i,t,e,n,s,o){o&&(i=ar(i),t=t.map(C=>Gg(C)),e=e.map(C=>Gg(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(By);let g=0;for(;c[g].shapeId>=r;)g++;let m=c[g].low.y;m>i.y1&&l.push(new Cn(i.y1,m,i.x2,i.x2));let b=0,x=[];for(;b<f&&(h=c[b]).low.y<m;)h.high.y>m&&x.push(h),b++;for(;b<f||x.length>0;){let C=i.y2,v=Math.min(My(Math.ceil(m+n),s),i.y2);for(d=0;d<x.length&&C>v;d++)h=x[d],h.low.x==h.high.x?h.high.y<C&&(C=Math.max(zg(h.high.y,s),v)):h.low.x!=h.high.x&&(C=v);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<v)h.low.y==h.high.y&&h.low.y==m||(x.push(h),C=v),b++;else{let E=zg(h.low.y,s);E<C&&(C=E);break}}let y=[];for(d=0;d<x.length;d++)Oy(y,x[d],m,C);y.sort((E,T)=>E.x-T.x||E.lowOrHigh-T.lowOrHigh);let N=Dy(y,r,a);if(N.length==0)l.push(new Cn(m,C,i.x2,i.x2));else{let E=0,T=i.x1;for(d=0;d<N.length;d+=2){let k=Math.max(i.x1,N[d]),L=Math.min(i.x2,N[d+1])-k;L>E&&(E=L,T=k)}E==0?l.push(new Cn(m,C,i.x2,i.x2)):l.push(new Cn(m,C,Math.max(T,i.x1),Math.min(T+E,i.x2)))}if(C==i.y2)break;for(m=C,d=x.length-1;d>=0;d--)x[d].high.y<=C&&x.splice(d,1)}return $g(i,l),l}function $g(i,t){let e=t.length-1,n=new Cn(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 Xg(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 jg(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 it(t.x1,e,t.x2,o)}function Yg(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 it(t.x1,o,t.x2,e)}function qg(i,t,e,n){let s=e.y1,o=e.x2-e.x1,r=e.y2-e.y1,a=Xg(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 Kg(i,t,e,n,s){for(n||(n=[new Cn(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 Cn(r,i.y2,i.x1,i.x2));let a=Xg(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 Cn(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 Cn(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););}$g(i,t)}var td=class extends Ut{constructor(){super();p(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Zg(i){if(i){let t=new td;try{return i.visit(t),t.propSet}catch(e){D.warn(e,"toSet:")}}return{}}var nd=class extends Ut{constructor(e){super();this.value=e}visitInt(e){return this.value=e.num,e}};function rd(i,t){if(i){let e=new nd(t);try{return i.visit(e),e.value}catch(n){D.warn(n,"toInt: ")}}return t}var sd=class extends Ut{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 mn(e+a[c],n+a[c+1]));return new ao(l)}break;case"rectangle":if(a.length==4)return ui(e+a[0],n+a[1],e+a[0]+a[2],n+a[1]+a[3]);break;case"ellipse":if(a.length==4)return ed(e+a[0],n+a[1],a[2],a[3]);break;case"circle":if(a.length==3)return ed(e+a[0],n+a[1],a[2],a[2]);break}}return null}};function dl(i,t,e,n,s,o){if(i){let r=new sd;try{return i.visit(r),r.getShape(t,e,n,s,o)}catch(a){D.warn(a,"toShape:")}}return ui(t,e,t+n,e+s)}var od=class extends Ut{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 Ts(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 od(e,n);try{i.visit(s)}catch(a){D.warn(a,"toCounters:")}return s.counters}var ul=class extends nn{constructor(e,n){super();this.baseUrl=e;this.transformer=n}visitURL(e){return new Ae(Cs(this.transformer.transformURL(e.url,this.baseUrl)))}};function lo(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function Uy(i){return i.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,e,n)=>e?String.fromCodePoint(parseInt(e,16)):n)}function cr(i,t){var e;if(t==="content"){let n=i.cloneNode(!0);return n.querySelectorAll("[data-adapt-pseudo]").forEach(o=>o.remove()),n.textContent||""}else if(t==="marker"){let n=i.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(n)return n.textContent||"";let s=(e=i.style)==null?void 0:e.getPropertyValue("--viv-marker-content");if(s){let o=s.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(r=>Uy(r.substring(1,r.length-1))).join("")}return""}else{let n=i.querySelector(`[data-adapt-pseudo="${t}"]`);return n&&n.textContent||""}}var ld=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}},cd=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()}},ud=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(ne(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 se(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 se(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"?cr(s,e):cr(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 se(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 se(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 se(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 se(this.pageScope,()=>this.getRunningValue(this.namedStringValues,t,e),`named-string-${e}-${t}`)}getRunningElementVal(t,e){return new se(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(Oa),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(`[${Xt}]`)).map(g=>parseInt(g.getAttribute(Xt),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,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{b<c&&(u=b);let C=r.container.querySelector(`[${Xt}="${m}"]`);if(!C)u<0&&(u=m);else{let v=r.container.querySelector(`[${Xt}="${a}"]`);if(v||(v=r.container.querySelector(`[${Xt}="0"]`)),v){for(let y=v;y;y=y.firstElementChild)if(y===C){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)}},pl=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 cd(this,t)}createCounterResolver(t,e,n){return new ud(this,t,e,n)}setCurrentPage(t){this.currentPage=t}setCurrentPageDocCounters(t,e,n){this.previousPageDocCounters=this.currentPageDocCounters?lo(this.currentPageDocCounters):null,this.currentPageDocCounters=t?lo(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=lo(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 x=this.currentPageDocCounters[b],C=x.length?x[x.length-1]:0,v=m[b]||[],y=v.length?v[v.length-1]:0,N=C-y,E=s[b],T=E==="reset"||E==="set";o[b]={delta:N,reset:T,value:C}}}let r=Object.create(null),a,l=t["counter-reset"];if(l){let m=l.evaluate(e);m&&(a=Ts(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=Ts(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=Ts(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=lo(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 x=g[m];x[x.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=lo(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 ld(t,e);this.newReferencesOfCurrentPage.push(n)}}finishPage(t,e){let n=Object.keys(this.currentPage.elementsById);if(n.length>0){let r=lo(this.currentPageCounters),a=this.currentPageDocCounters?lo(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:cr(d,"content"),before:cr(d,"before"),after:cr(d,"after"),marker:cr(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(`[${pi}]`);for(let s of n){let o=s.getAttribute(pi),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(`[${di}]`);for(let l of a){let c=l.getAttribute(di),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 se){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(`[${Xt}="${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(pi,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(ad,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?id:di,t.key),r}else return null}fixPageCounterInRunningElement(t){let e=t.querySelectorAll(`[${di}]`);for(let o of e){let r=o.getAttribute(di),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(`[${pi}]`);for(let o of n)o.setAttribute(Qg,!0);let s=t.querySelectorAll(`[${ad}]`);for(let o of s)o.setAttribute(Jg,!0)}finishLastPage(t){var r;let e=t.root.querySelectorAll(`[${id}]`),n=t.contentContainer.childElementCount;for(let a of e){let l=a.getAttribute(id),c=this.pagesCounterExprs.findIndex(u=>u.expr.key===l);c>=0,a.textContent=this.pagesCounterExprs[c].format([n])}let s=t.root.querySelectorAll(`[${Qg}]`);for(let a of s){let l=a.getAttribute(pi),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(`[${Jg}]`);for(let a of o){let l=a.getAttribute(ad),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 dd(this,t)}},id="data-vivliostyle-pages-counter",di="data-vivliostyle-page-counter",pi="data-vivliostyle-target-counter",ad="data-vivliostyle-target-text",Qg="data-vivliostyle-target-counter-in-running",Jg="data-vivliostyle-target-text-in-running",dd=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 zy=new Set(["before","after","first-line","first-letter"]),em=new Set(["media","supports","-epubx-when"]),tm=new Set([";","}"]),nm=new Set(["{",";","}"]),Gy=new Set([";","{","}"]),Wy=":where(:scope)",$y=":where(:not(*))";function sm(i){let{statements:t,changed:e}=pd(i,0,i.length,null);return e?t.join(`
5
+ `):i}function pd(i,t,e,n){let s=[],o=[],r=!1,a=t,l=()=>{o.length!==0&&(n?s.push(Xy(n,o)):s.push(om(o)),o.length=0)};for(;a<e&&(a=uo(i,a,e),!(a>=e||i[a]==="}"));){if(i[a]==="@"){let d=iS(i,a,e);if(!d)break;if(n&&!em.has(d.name)){o.push(co(i.slice(a,d.end))),a=d.end;continue}if(l(),d.hasBlock&&em.has(d.name)){let h=pd(i,d.blockStart,d.blockEnd,n);r||(r=h.changed||n!=null),s.push(`${d.header} {${jy(h.statements)}}`)}else s.push(co(i.slice(a,d.end)));a=d.end;continue}if(n&&Qy(i,a,e)){let d=tS(i,a,e);if(!d)break;o.push(co(d.text)),a=d.end;continue}l();let c=nS(i,a,e);if(!c){let d=aS(i,a,e);s.push(co(d.text)),a=d.end;continue}if(n&&sS(i,a,c)){let d=rS(i,a,c.end,e);o.push(co(d.text)),a=d.end;continue}let u=n?Yy(n,c.prelude):hd(c.prelude);if(u){r||(r=n!=null);let d=pd(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 Xy(i,t){return`${i} { ${om(t)} }`}function om(i){return i.map(t=>t.endsWith(";")?t:`${t};`).join(" ")}function jy(i){return i.length===0?"":` ${i.join(" ")} `}function Yy(i,t){let e=qy(i);if(!e)return null;let s=im(t,",").map(o=>o.trim()).filter(Boolean).map(o=>{let r=rm(o,e);return r.found?r.text:`${e} ${o}`}).filter(Boolean);return s.length===0?null:s.join(", ")}function hd(i){return rm(i.trim(),Wy).text}function qy(i){let t=im(i,",").map(e=>e.trim()).filter(Boolean).filter(e=>!Ky(e));return t.length===0?null:`:is(${t.join(", ")})`}function Ky(i){let t=0;for(;t<i.length;){let e=hl(i,t);if(e!=null){t=e;continue}let n=po(i,t,i.length);if(n!=null){t=n;continue}if(i[t]===":"){if(i[t+1]===":")return!0;let o=t+1,r=hi(i,o,i.length),a=i.slice(o,r).toLowerCase();if(zy.has(a))return!0;t=r;continue}t++}return!1}function rm(i,t){let e=0,n=!1,s="",o=[],r=Zy(t);for(;e<i.length;){let a=hl(i,e);if(a!=null){s+=i.slice(e,a),e=a;continue}let l=po(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=hi(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")?$y:t,n=!0,e++;continue}s+=c,e++}return{text:s,found:n}}function Zy(i){let t=0;for(;t<i.length;){let e=hl(i,t);if(e!=null){t=e;continue}let n=po(i,t,i.length);if(n!=null){t=n;continue}if(i[t]===":"&&i[t+1]!==":"){let o=t+1,r=hi(i,o,i.length);if(r>o&&i.slice(o,r).toLowerCase()==="has"&&i[r]==="(")return!0;t=r;continue}t++}return!1}function im(i,t){let e=[],n=0,s=0,o=0,r=0;for(;s<i.length;){let a=hl(i,s);if(a!=null){s=a;continue}let l=po(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 Qy(i,t,e){let n=t,s=eS(i,n,e);if(s<=n)return!1;let o=uo(i,s,e);if(o>=e||i[o]!==":")return!1;let r=fi(i,o+1,e,Gy);return(r==null?void 0:r.char)==="{"?!Jy(i,t,s,o,r.index):!0}function Jy(i,t,e,n,s){if(uo(i,e,s)!==n)return!1;let o=uo(i,n+1,s);if(o!==n+1||o>=s)return!1;let r=i[o];return r===":"||r==="\\"||/[A-Za-z_-]/.test(r)}function eS(i,t,e){let n=t;return i[n]==="-"&&(n++,n<e&&i[n]==="-"&&n++),hi(i,n,e)}function hi(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 tS(i,t,e){let n=fi(i,t,e,tm);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 nS(i,t,e){let n=fi(i,t,e,nm);if(!n||n.char!=="{")return null;let s=am(i,n.index,e);return s<0?null:{prelude:co(i.slice(t,n.index)),blockStart:n.index+1,blockEnd:s,end:s+1}}function sS(i,t,e){if(!oS(i,t,e.blockStart-1))return!0;let n=uo(i,e.blockStart,e.blockEnd);return n<e.blockEnd&&i[n]===";"}function oS(i,t,e){let n=uo(i,t,e);if(n>=e)return!1;let s=i[n];return s==="&"||s==="."||s==="#"||s===":"||s==="["||s==="|"||s==="*"||s===">"||s==="+"||s==="~"||s==="\\"||/[A-Za-z_-]/.test(s)}function rS(i,t,e,n){let s=uo(i,e,n),o=s<n&&i[s]===";"?s+1:e;return{text:i.slice(t,o),end:o}}function iS(i,t,e){let n=fi(i,t,e,nm);if(!n)return null;let s=hi(i,t+1,e),o=i.slice(t+1,s).toLowerCase(),r=co(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=am(i,n.index,e);return a<0?null:{name:o,header:r,hasBlock:!0,blockStart:n.index+1,blockEnd:a,end:a+1}}function aS(i,t,e){let n=fi(i,t,e,tm);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 fi(i,t,e,n){let s=t,o=0,r=0,a=0;for(;s<e;){let l=po(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 am(i,t,e){let n=t+1,s=1;for(;n<e;){let o=po(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 uo(i,t,e){let n=t;for(;n<e;){let s=i[n];if(cm(s)){n++;continue}if(s==="/"&&i[n+1]==="*"){n=lm(i,n,e);continue}break}return n}function lm(i,t,e){let n=i.indexOf("*/",t+2);return n<0||n+2>e?e:n+2}function po(i,t,e){let n=i[t];return n==='"'||n==="'"?lS(i,t):n==="/"&&i[t+1]==="*"?lm(i,t,e):null}function hl(i,t){return i[t]!=="\\"?null:t+1>=i.length?i.length:t+2}function lS(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 cm(i){return i===" "||i===`
6
+ `||i==="\r"||i===" "||i==="\f"}function co(i){let t="",e=0,n=!1;for(;e<i.length;){let s=po(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(cm(o)){n=t.length>0,e++;continue}n&&t.length>0&&(t+=" ",n=!1),t+=o,e++}return t}function cS(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 Qn(i){return i.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,cS)}var gd=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 Xe(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 Ln=[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];Ln[NaN]=80;var In=[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];In[NaN]=43;var uS=[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];In[NaN]=43;var dm=[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];dm[NaN]=35;var pm=[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];pm[NaN]=45;var md=[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];md[NaN]=37;var Cd=[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];Cd[NaN]=38;var ho=Xe(35,[61,36]),dS=Xe(35,[58,77]),pS=Xe(35,[61,36,124,50]),hS=Xe(35,[38,51]),fS=Xe(35,[42,54]),gS=Xe(39,[42,55]),mS=Xe(54,[42,55,47,56]),CS=Xe(62,[62,82]),bS=Xe(35,[61,36,33,70]),yS=Xe(62,[45,71]),SS=Xe(63,[45,81]),fd=Xe(76,[10,72,13,72]),xS=Xe(39,[39,46,10,72,13,72,92,48]),ES=Xe(39,[34,46,10,72,13,72,92,49]),vS=Xe(39,[39,47,10,74,13,74,92,48]),NS=Xe(39,[34,47,10,74,13,74,92,49]),um=Xe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),TS=Xe(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]),wS=Xe(39,[39,68,10,74,13,74,92,75,NaN,67]),PS=Xe(39,[34,68,10,74,13,74,92,75,NaN,67]),kS=Xe(72,[9,39,10,39,13,39,32,39,41,69]),AS=15,Ze=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=AS,this.buffer=Array(this.indexMask+1);for(let n=0;n<=this.indexMask;n++)this.buffer[n]=new gd}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=Ln,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:isNaN(m)?(u=o.substring(c,r),l=0):s===Ln&&l===0?(l=54,c=r,u=o.substring(r,r+1),r++):(u=o.substring(c,r),l=54),s=Ln;break;case 1:r++,h=!0;continue;case 2:c=r++,s=md;continue;case 3:l=1,c=r++,s=In;continue;case 4:c=r++,l=31,s=ho;continue;case 33:l=2,c=++r,s=xS;continue;case 34:l=2,c=++r,s=ES;continue;case 6:c=++r,l=7,s=In;continue;case 7:c=r++,l=32,s=ho;continue;case 8:c=r++,l=21;break;case 9:c=r++,l=32,s=hS;continue;case 10:c=r++,l=10;break;case 11:c=r++,l=11;break;case 12:c=r++,l=36,s=ho;continue;case 13:c=r++,l=23;break;case 14:c=r++,l=16;break;case 15:l=24,c=r++,s=dm;continue;case 16:c=r++,s=uS;continue;case 78:c=r++,l=9,s=In;continue;case 17:c=r++,l=19,s=fS;continue;case 18:c=r++,l=18,s=dS;continue;case 77:r++,l=50;break;case 19:c=r++,l=17;break;case 20:c=r++,l=38,s=bS;continue;case 21:c=r++,l=39,s=ho;continue;case 22:c=r++,l=37,s=ho;continue;case 23:c=r++,l=22;break;case 24:c=++r,l=20,s=In;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=fd;continue;case 30:c=r++,l=33,s=ho;continue;case 31:c=r++,l=34,s=pS;continue;case 32:c=r++,l=35,s=ho;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=In;continue;case 41:l=3,d=parseFloat(o.substring(c,r)),u="%",c=r++;break;case 42:r++,s=Cd;continue;case 43:if(u=Qn(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=fd;continue;case 45:u=Qn(o.substring(c,r));break;case 46:u=o.substring(c,r),r++;break;case 47:u=Qn(o.substring(c,r)),r++;break;case 48:g=r,r+=2,s=vS;continue;case 49:g=r,r+=2,s=NS;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=um;continue}l=6}break;case 53:if(u=Qn(o.substring(c,r)),l==1){if(r++,u.toLowerCase()=="url"){s=um;continue}l=6}break;case 54:s=gS,r++;continue;case 55:s=mS,r++;continue;case 56:s=Ln,r++;continue;case 57:s=CS,r++,o[r]!==">"&&(l=1,s=In);continue;case 81:l=51,u=o.substring(c,++r),s=Ln;break;case 82:l=52,u=o.substring(c,++r),s=Ln;break;case 58:l=5,s=md,r++;continue;case 59:l=4,s=Cd,r++;continue;case 60:l=1,s=In,r++;continue;case 61:l=1,s=fd,g=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:c=r++,s=TS;continue;case 65:c=++r,s=wS;continue;case 66:c=++r,s=PS;continue;case 67:l=8,u=Qn(o.substring(c,r)),r++;break;case 69:r++;break;case 70:s=yS,r++;continue;case 71:s=SS,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=Qn(o.substring(c,r)),r++,s=kS;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=Ln;break;case 73:if(r-g<9&&o.substring(g+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,s=In;continue}u=Qn(o.substring(c,r));break;case 75:g=r++;continue;case 76:r++,s=pm;continue;default:if(s!==Ln){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=Ln,h=!1,l=0,c=r,u="",d=0,f=a[t&n]}this.position=r,this.tail=t&n}};var ze=null,bd=null;function mi(){return ze}function I(i){if(!ze)throw new Error("E_TASK_NO_CONTEXT");ze.name||(ze.name=i);let t=ze,e=new dr(t,t.top,i);return t.top=e,e.state=1,e}function RS(i){return new Sd(i||new yd)}function w(i){return new gi(i)}function Jn(i,t,e){let n=I(i);n.handler=e;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function hm(i,t){return(ze?ze.getScheduler():bd||RS()).run(i,t)}var yd=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,bd||(bd=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){D.error(t)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(t,e){let n=new xd(this,e||"");n.top=new dr(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){D.error(a)}};try{t().then(r=>{n.result=r,o()})}catch(r){n.raise(r),o()}});let s=ze;return ze=n,this.schedule(n.top.suspend("bootstrap")),ze=s,n}},fl=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=ze;return ze=t,t.top.finish(this.result),ze=e,!0}return!1}cancel(){this.canceled=!0}},xd=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!==ze&&this.continuation){this.continuation.cancel();let e=new fl(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&&D.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}
7
7
  ---- async ---
8
8
  `:"";for(let n=this.top;n;n=n.parent)e+=" ",e+=n.getName(),e+=`
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=`
9
+ `;t.frameTrace=e}}},gi=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}},Ed=class{constructor(t){this.frame=t}then(t){this.frame.then(t)}thenAsync(t){if(this.isPending()){let e=new dr(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 gi(t)):new gi(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}},dr=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(!ze)throw new Error("F_TASK_NO_CONTEXT");if(this!==ze.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new Ed(this)}finish(t){this.checkEnvironment(),ze&&!ze.exception&&(this.res=t),this.state=2;let e=this.parent;if(ze&&(ze.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()?(D.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=ze;if(!e)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let n;do{let s=new vd(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 fl(this.task);return this.task.continuation=e,ze=null,this.task.waitTarget=t||null,e}},vd=class extends dr{constructor(t,e){super(t,e,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}};var Fn=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=mi().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){D.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}},bn=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 Nd=`
10
10
  @media screen {
11
11
  [data-vivliostyle-viewer-viewport] {
12
12
  background: #aaaaaa;
@@ -75,7 +75,7 @@
75
75
  transform-origin: center top;
76
76
  }
77
77
  }
78
- `,yd=`
78
+ `,Td=`
79
79
  [data-vivliostyle-layout-box] {
80
80
  position: absolute;
81
81
  left: 0;
@@ -198,7 +198,7 @@
198
198
  break-after: page;
199
199
  }
200
200
  }
201
- `,Sd=`
201
+ `,wd=`
202
202
  /*
203
203
  * Copyright 2013 Google, Inc.
204
204
  * Copyright 2015 Daishinsha Inc.
@@ -831,7 +831,7 @@ word-wrap = overflow-wrap;
831
831
  [adapt,webkit]start = inline-start;
832
832
  [adapt,webkit]end = inline-end;
833
833
 
834
- `,xd=`
834
+ `,Pd=`
835
835
  <!DOCTYPE html>
836
836
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
837
837
  <head>
@@ -855,7 +855,7 @@ word-wrap = overflow-wrap;
855
855
  <s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
856
856
 
857
857
  </body>
858
- </html>`,Ed=`
858
+ </html>`,kd=`
859
859
  @namespace "http://www.w3.org/1999/xhtml";
860
860
 
861
861
  :root {
@@ -978,7 +978,7 @@ word-wrap = overflow-wrap;
978
978
  margin: 10%;
979
979
  }
980
980
  }
981
- `,vd=String.raw`
981
+ `,Ad=String.raw`
982
982
  @namespace "http://www.w3.org/1999/xhtml";
983
983
  @namespace m "http://www.w3.org/1998/Math/MathML";
984
984
  @namespace epub "http://www.idpf.org/2007/ops";
@@ -1409,7 +1409,7 @@ epub|case[required-namespace::supported] ~ epub|case {
1409
1409
  epub|case[required-namespace::supported] ~ epub|default {
1410
1410
  display: none;
1411
1411
  }
1412
- `,Nd=`
1412
+ `,Rd=`
1413
1413
  @namespace "http://www.w3.org/1999/xhtml";
1414
1414
 
1415
1415
  *:not([data-vivliostyle-role=doc-toc],
@@ -1439,7 +1439,7 @@ epub|case[required-namespace::supported] ~ epub|default {
1439
1439
  [data-vivliostyle-role=doc-toc]:is(ol,ul) {
1440
1440
  -adapt-behavior: toc-container;
1441
1441
  }
1442
- `,Td=`
1442
+ `,Ld=`
1443
1443
  [data-viv-margin-discard~="block-start"] {
1444
1444
  margin-block-start: 0 !important;
1445
1445
  }
@@ -1611,13 +1611,37 @@ span[data-viv-leader] {
1611
1611
  [style*="--viv-marker-text-combine-upright"]::marker {
1612
1612
  text-combine-upright: var(--viv-marker-text-combine-upright);
1613
1613
  }
1614
+ [style*="--viv-marker-text-orientation"]::marker {
1615
+ text-orientation: var(--viv-marker-text-orientation);
1616
+ }
1617
+ [style*="--viv-marker-hyphens"]::marker {
1618
+ hyphens: var(--viv-marker-hyphens);
1619
+ }
1620
+ [style*="--viv-marker-line-height"]::marker {
1621
+ line-height: var(--viv-marker-line-height);
1622
+ }
1623
+ [style*="--viv-marker-tab-size"]::marker {
1624
+ tab-size: var(--viv-marker-tab-size);
1625
+ }
1626
+ [style*="--viv-marker-text-emphasis-style"]::marker {
1627
+ text-emphasis-style: var(--viv-marker-text-emphasis-style);
1628
+ }
1629
+ [style*="--viv-marker-text-emphasis-color"]::marker {
1630
+ text-emphasis-color: var(--viv-marker-text-emphasis-color);
1631
+ }
1632
+ [style*="--viv-marker-text-emphasis-position"]::marker {
1633
+ text-emphasis-position: var(--viv-marker-text-emphasis-position);
1634
+ }
1635
+ [style*="--viv-marker-text-shadow"]::marker {
1636
+ text-shadow: var(--viv-marker-text-shadow);
1637
+ }
1614
1638
 
1615
1639
  /* initial-letter */
1616
1640
  [style*="--viv-initialLetter"]:has(>[data-adapt-pseudo="first-letter"])::first-letter {
1617
1641
  -webkit-initial-letter: var(--viv-initialLetter);
1618
1642
  initial-letter: var(--viv-initialLetter);
1619
1643
  }
1620
- `,wd=String.raw`
1644
+ `,Id=String.raw`
1621
1645
  @counter-style decimal-leading-zero {
1622
1646
  system: extends decimal;
1623
1647
  pad: 2 '0';
@@ -1841,12 +1865,12 @@ span[data-viv-leader] {
1841
1865
  @counter-style upper-russian {
1842
1866
  system: alphabetic;
1843
1867
  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;
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 {
1868
+ }`;function go(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=Fd([a]):t==="json"?r.responseText=JSON.stringify(a):typeof a=="string"&&(r.responseText=a),o.schedule(r)}).catch(a=>{r.status>=400?D.warn(`Error fetching ${i} (${r.status}${r.statusText?" "+r.statusText:""})`):D.warn(a,`Error fetching ${i}`),o.schedule(r)}),n.result()}function Fd(i,t){let e=t||"application/octet-stream";return new Blob(i,{type:e})}function fm(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 gm(i){return URL.createObjectURL(i)}var fo=class{constructor(t,e){this.parser=t;this.type=e;p(this,"resources",{});p(this,"fetchers",{})}load(t,e,n){t=wt(t);let s=this.resources[t];return typeof s!="undefined"?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=ne("user-agent.xml",un),a=!o&&t===r;return a&&(t=`data:application/xml,${encodeURIComponent(Pd)}`),go(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=wt(t),this.resources[t])return null;let o=this.fetchers[t];return o||(o=new Fn(()=>this.fetchInner(t,e,n),`Fetch ${t}`),this.fetchers[t]=o,o.start()),o}get(t){return this.resources[wt(t)]}delete(t){delete this.resources[wt(t)]}};function LS(i,t){let e=i.responseText;return w(e?$o(e):null)}function mm(){return new fo(LS,"text")}function ft(i,t,e){let n=new Fn(()=>{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);else(i.localName==="img"||i.localName==="embed"||i.localName==="object"||i.localName==="iframe")&&(i.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4));return s.result()},`loadElement ${t||i.localName}`);return n.start(),n}var Cm=0,IS=16777216,Vd=33554432,bl=50331648,yl=67108864,FS=83886080,VS=100663296;var Co=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 Cm;case"User":return VS;default:return FS}}getBaseSpecificity(){switch(this.flavor){case"UA":return Cm;case"User":return IS;default:return Vd}}},gr=class extends Co{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;D.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)}},ml=class extends Co{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()}},on=class extends ml{constructor(t,e,n){super(t,e,n)}report(t){this.error(t,this.getCurrentToken())}reportAndSkip(t){this.report(t),this.owner.pushHandler(new ml(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=[],Cl=[],Se=[],Le=[],sn=[],gt=[],Oe=[],je=[],ye=[],Je=[],yt=[],Ge=[],Be=[];var hr=55,fr=56,gl=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,Cl[1]=46,Cl[0]=200,gt[1]=2,gt[36]=4,gt[7]=6,gt[9]=8,gt[14]=10,gt[18]=14,gt[50]=42,Se[37]=11,Se[23]=12,Se[35]=56,Se[1]=1,Se[36]=3,Se[7]=5,Se[9]=7,Se[14]=9,Se[12]=13,Se[18]=55,Se[50]=58,Se[16]=41,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,sn[1]=2,sn[36]=4,sn[7]=6,sn[9]=8,sn[18]=14,sn[50]=42,sn[14]=10,sn[12]=13,Oe[1]=15,Oe[7]=16,Oe[4]=17,Oe[5]=18,Oe[3]=19,Oe[2]=20,Oe[8]=21,Oe[27]=57,Oe[16]=22,Oe[19]=23,Oe[6]=24,Oe[11]=25,Oe[17]=26,Oe[13]=48,Oe[31]=47,Oe[23]=54,Oe[0]=44,je[1]=31,je[4]=32,je[5]=32,je[3]=33,je[2]=34,je[10]=40,je[6]=38,je[31]=36,je[24]=36,je[32]=35,ye[1]=45,ye[16]=37,ye[37]=37,ye[38]=37,ye[47]=37,ye[48]=37,ye[39]=37,ye[49]=37,ye[41]=37,ye[26]=37,ye[25]=37,ye[23]=37,ye[24]=37,ye[19]=37,ye[21]=37,ye[36]=37,ye[18]=37,ye[22]=37,ye[11]=39,ye[12]=43,ye[17]=49,Je[0]=200,Je[12]=50,Je[13]=51,Je[14]=50,Je[15]=51,Je[10]=50,Je[11]=51,Je[17]=53,yt[0]=200,yt[12]=50,yt[13]=52,yt[14]=50,yt[15]=51,yt[10]=50,yt[11]=51,yt[17]=53,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,Be[11]=0,Be[16]=0,Be[22]=1,Be[18]=1,Be[26]=2,Be[25]=2,Be[38]=3,Be[37]=3,Be[48]=3,Be[47]=3,Be[39]=3,Be[49]=3,Be[41]=3,Be[23]=4,Be[24]=4,Be[36]=5,Be[19]=5,Be[21]=5,Be[0]=6,Be[hr]=2,Be[fr]=2;var ws=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 Rn){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 j(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=yt);let c=new pt(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;(!Ht(u)||u===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${c.toString()}`,e),this.actions=yt)}return c}if(t!=";"||s>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",e),this.actions=yt,null;if(a>1)return new Te(this.extractVals(",",s+1));let l=n[0];return l instanceof Ue?l:l?new Rn(l.toString()):$}exprError(t,e){this.actions=this.propName?yt:Je,D.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 Ga(s.getScope(),c,u);l.unshift(d)}return n.push(new _(l[0])),!0}else if(a=="("){let c=n.pop(),u=n.pop();o=new qn(s.getScope(),oi(u,c),l),t=0;continue}}if(a==10){o.isMediaName()&&(o=new si(s.getScope(),o,null)),t=0;continue}}else if(typeof a=="string"){n.push(a);break}if(a<0)if(a==-31)o=new jt(s.getScope(),o);else if(a==-24)o=new An(s.getScope(),o);else if(a==-gl)o=new Ha(s.getScope(),o);else return this.exprError("F_UNEXPECTED_STATE",e),!1;else{if(Be[t]>Be[a]){n.push(a);break}switch(r=n.pop(),a){case 26:o=new Yo(s.getScope(),r,o);break;case hr:o=new za(s.getScope(),r,o);break;case fr:o=new Wa(s.getScope(),r,o);break;case 25:o=new qo(s.getScope(),r,o);break;case 38:o=new $a(s.getScope(),r,o);break;case 37:o=new ja(s.getScope(),r,o);break;case 48:o=new Xa(s.getScope(),r,o);break;case 47:o=new no(s.getScope(),r,o);break;case 39:case 49:o=new ys(s.getScope(),r,o);break;case 41:o=new Ya(s.getScope(),r,o);break;case 23:o=new Jr(s.getScope(),r,o);break;case 24:o=new ei(s.getScope(),r,o);break;case 36:o=new so(s.getScope(),r,o);break;case 19:o=new ti(s.getScope(),r,o);break;case 21:o=new Ko(s.getScope(),r,o);break;case 18:if(n.length>1)switch(n[n.length-1]){case 22:n.pop(),o=new qa(s.getScope(),n.pop(),r,o);break;case 10:if(r.isMediaName())o=new si(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 Ka(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=Pt(n,e,new jt(n,new xe(n,"pref-horizontal")));break;case"horizontal":e=Pt(n,e,new xe(n,"pref-horizontal"));break;case"day":e=Pt(n,e,new jt(n,new xe(n,"pref-night-mode")));break;case"night":e=Pt(n,e,new xe(n,"pref-night-mode"));break;default:e=n._false}}return e===n._true?null:new _(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,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===Oe&&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 Rn(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=yt):(this.actions=gt,a.startSelectorRule());continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Oe,c.splice(0,c.length);continue;case 46:if(l.nthToken(1).type!=18){this.actions=yt,a.error("E_CSS_COLON_EXPECTED",l.nthToken(1));continue}this.propName=u.text,this.propImportant=!1,l.consume(),l.consume(),this.actions=Oe,c.splice(0,c.length);continue;case 29:this.actions=gt,a.startSelectorRule();continue;case 1:if(!u.precededBySpace){this.actions=Ge,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=Se,l.consume();break;case 36:a.tagSelector(h,null),o?this.actions=Le:this.actions=Se,l.consume();break;default:this.actions=Je,a.error("E_CSS_NAMESPACE",u)}else this.actions=Je,a.error("E_CSS_UNDECLARED_PREFIX",u);else a.tagSelector(this.defaultNamespaceURI,u.text),o?this.actions=Le:this.actions=Se,l.consume();continue;case 3:if(!u.precededBySpace){this.actions=Ge,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=Se,l.consume();break;case 36:a.tagSelector(null,null),o?this.actions=Le:this.actions=Se,l.consume();break;default:this.actions=Je,a.error("E_CSS_NAMESPACE",u)}else a.tagSelector(this.defaultNamespaceURI,null),o?this.actions=Le:this.actions=Se,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=Se,l.consume();continue;case 7:u.precededBySpace&&a.descendantSelector();case 8:a.classSelector(u.text),o?this.actions=Le:this.actions=Se,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=Se;continue;case 6:switch(f=u.text,l.consume(),f){case"is":case"not":case"where":case"has":this.actions=gt,a.startFuncWithSelector(f),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,f==="has")?this.actions=Se:this.actions=Ge;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=gt,a.startFuncWithSelector(f,b),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?o?this.actions=Le:this.actions=Se:this.actions=Ge;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=Se;continue}break}a.error("E_CSS_PSEUDOCLASS_SYNTAX",u),this.actions=Je;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=Se,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=Se,l.consume();continue}break}a.error("E_CSS_PSEUDOELEM_SYNTAX",u),this.actions=Je;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=Ge,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=Ge,a.error("E_CSS_UNDECLARED_PREFIX",u),l.consume();continue}if(l.consume(),u=l.token(),u.type!=1){this.actions=Ge,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=Se,l.consume();continue;default:this.actions=Ge,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=Ge,a.error("E_CSS_ATTR_VAL_EXPECTED",u);continue}if(u.type!=15){this.actions=Ge,a.error("E_CSS_ATTR",u);continue}o?this.actions=Le:this.actions=Se,l.consume();continue;case 11:a.childSelector(),this.actions=sn,l.consume();continue;case 12:a.adjacentSiblingSelector(),this.actions=sn,l.consume();continue;case 56:a.followingSiblingSelector(),this.actions=sn,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=gt,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 He(u.num)),l.consume();continue;case 18:c.push(new pe(u.num)),l.consume();continue;case 19:c.push(new A(u.num,u.text)),l.consume();continue;case 20:c.push(new G(u.text)),l.consume();continue;case 21:c.push(new Ae(ne(u.text,this.baseURL))),l.consume();continue;case 57:c.push(new ii(u.text)),l.consume();continue;case 22:this.valStackReduce(",",u),c.push(","),l.consume();continue;case 23:c.push(Kn),l.consume();continue;case 24:f=u.text.toLowerCase(),f=="-epubx-expr"||f=="env"?(this.actions=je,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 Rn("+")),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?Cl: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 xe(a.getScope(),oi(u.text,d.text))),this.actions=ye),l.consume();else{if(this.exprContext==2||this.exprContext==3)u.text.toLowerCase()=="not"?(l.consume(),c.push(new ni(a.getScope(),!0,d.text))):(u.text.toLowerCase()=="only"&&(l.consume(),u=d),c.push(new ni(a.getScope(),!1,u.text)));else if(this.exprContext===4&&u.text.toLowerCase()==="not"&&c[c.length-1]!==hr&&c[c.length-1]!==fr&&(d.type===10||d.type===6)){c.push(-gl),l.consume();continue}else c.push(new xe(a.getScope(),u.text));this.actions=ye}l.consume();continue;case 38:if(this.exprContext===4){c.push(this.readSupportsTest(u)),this.actions=ye;continue}c.push(null,u.text,"("),l.consume();continue;case 32:c.push(new Pe(a.getScope(),u.num)),l.consume(),this.actions=ye;continue;case 33:f=u.text,f=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?f="vh":f="vw"),c.push(new pn(a.getScope(),u.num,f)),l.consume(),this.actions=ye;continue;case 34:c.push(new Pe(a.getScope(),u.text)),l.consume(),this.actions=ye;continue;case 35:l.consume(),u=l.token(),u.type!=5||u.precededBySpace?this.exprError("E_CSS_SYNTAX",u):(c.push(new Zo(a.getScope(),u.num)),l.consume(),this.actions=ye);continue;case 36:c.push(-u.type),l.consume();continue;case 37:this.actions=je,this.exprStackReduce(u.type,u),c.push(u.type),l.consume();continue;case 45:u.text.toLowerCase()==="and"&&c[c.length-2]!==fr&&c[c.length-2]!==-gl?(this.actions=je,this.exprStackReduce(hr,u),c.push(hr),l.consume()):u.text.toLowerCase()==="or"&&c[c.length-2]!==hr&&c[c.length-2]!==-gl?(this.actions=je,this.exprStackReduce(fr,u),c.push(fr),l.consume()):this.exprError("E_CSS_SYNTAX",u);continue;case 39:this.exprStackReduce(u.type,u)&&(this.actions=Oe),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=ye;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=je,c.push("{");continue}a.error("E_CSS_IMPORT_SYNTAX",u),this.actions=Je;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=Je;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=Je;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=gt;continue;case"page":l.consume(),a.startPageRule(),this.pageRule=!0,this.actions=sn;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=je,c.push("{");continue;case"media":l.consume(),this.propName=null,this.exprContext=2,this.actions=je,c.push("{");continue;case"supports":l.consume(),this.propName=null,this.exprContext=4,this.actions=je,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,v=null,y=[];for(u.type==1&&(C=u.text,l.consume(),u=l.token()),u.type==18&&l.nthToken(1).type==1&&(v=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;)y.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,v,y);break;case"-epubx-partition":a.startPartitionRule(C,v,y);break;case"-epubx-partition-group":a.startPartitionGroupRule(C,v,y);break}this.ruleStack.push(f),a.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":a.error(`E_CSS_UNEXPECTED_AT${f}`,u),this.actions=Ge;continue;default:a.error(`E_CSS_AT_UNKNOWN ${f}`,u),this.actions=Je;continue}a.error(`E_CSS_AT_SYNTAX ${f}`,u),this.actions=Je;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=gt,x=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===Ge)switch(u.type){case 16:this.errorBrackets.length==0&&(a.nextSelector(),x=u.position+1,this.actions=gt),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===gt)a.error("E_CSS_SYNTAX",u);else{let C=l.input.substring(x,u.position);a.pushSelectorText(C),x=u.position+1}if(u.type===16){a.nextSelector(),this.actions=gt,l.consume();continue}else return a.endFuncWithSelector(),l.consume(),!0;case 37:case 23:case 35:if(r){this.actions=Se;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=Ge;continue}if(this.actions!==Je&&this.actions!==Ge&&this.actions!==yt){if(u.type==54)a.error("E_CSS_SYNTAX",u);else if(this.actions===Oe){switch(u.type){case 10:case 12:case 14:this.errorBrackets.push(u.type+1);break}c.push(new Rn(u.toString())),l.consume();continue}else if(u.type===12&&this.actions==je&&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==je)return this.actions=Ie,l.consume(),!1;a.error("E_CSS_SYNTAX",u)}this.isInsidePropertyOnlyRule()?this.actions=yt:this.actions=Ge;continue}l.consume();continue}}return!1}},Ci=class extends Co{constructor(e){super(null);this.scope=e}error(e,n){D.warn(e,n.toString())}getScope(){return this.scope}};function BS(i,t,e,n,s){let o=Sm(t),r=sm(i.input);return r!==i.input?bm(new Ze(r,o),o,e,n,s):bm(i,o,e,n,s)}function bm(i,t,e,n,s){let o=I("parseStylesheet"),r=new ws(Ie,i,t,e),a=null;return s&&(a=Od(new Ze(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=ne(r.importURL,e);r.importCondition&&(t.startMediaRule(r.importCondition),t.startRuleBody());let u=I("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 w(!1)}).then(()=>{a&&t.endRule(),o.finish(!0)}),o.result()}function Sl(i,t,e,n,s){let o=Sm(t);return Jn("parseStylesheetFromText",r=>{let a=new Ze(i,o);BS(a,o,e,n,s).thenFinish(r)},(r,a)=>{D.warn(a,`Failed to parse stylesheet text: ${i}`),r.finish(!1)})}function Sm(i){if(i instanceof gr)return i;if(i instanceof on){if(i.owner)return i.owner;let t=new gr;return t.flavor=i.flavor,t.slave=i,i.owner=t,t}return i}function Bd(i,t,e,n){return Jn("parseStylesheetFromURL",s=>{go(i).then(o=>{o.responseText?Sl(o.responseText,t,i,e,n).then(r=>{r||D.warn(`Failed to parse stylesheet from ${i}`),s.finish(!0)}):s.finish(!0)})},(s,o)=>{D.warn(o,"Exception while fetching and parsing:",i),s.finish(!0)})}function Ps(i,t,e){let n=new ws(Oe,t,new Ci(i),e);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function xm(i,t,e){new ws(Cl,i,t,e).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Od(i,t,e){let n=new ws(je,i,t,e);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var OS={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function DS(i){return!!OS[i]}function Em(i,t,e){if(t instanceof se&&t.str==="viv-leader")return new _(t);if(e==="content"&&t instanceof se)return new _(t);let n=t.evaluate(i);switch(typeof n){case"number":return DS(e)?n==Math.round(n)?new pe(n):new He(n):new A(n,"px");case"string":return n?e==="content"?new G(n):Ps(t.scope,new Ze(n,null),""):$;case"boolean":return n?S._true:S._false;case"undefined":return $}throw new Error("E_UNEXPECTED")}var MS="data-vivliostyle-flow-root";function Nm(i){return i.getAttribute(MS)==="true"}function vm(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 mr(i){return i===S.absolute||i===S.fixed}function yo(i){return i instanceof pt&&i.name==="running"}function Dd(i,t,e,n){return i===S.none||(mr(t)?(e=S.none,i=vm(i)):(e&&e!==S.none&&!X(e)||n)&&(i=vm(i))),{display:i,position:t,float:e}}function xl(i,t,e,n){return Dd(i,t,e,n).display===S.block}function El(i){return i instanceof Q||i instanceof j||typeof i=="string"}function kt(i){if(!El(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 So(i){return El(i)?i.toString().includes("list-item"):!1}function Tm(i){if(!El(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 vl(i){if(!El(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 wm(i,t,e,n,s,o,r){return s=s||o||S.horizontal_tb,!!r||!!e&&e!==S.none&&!X(e)||mr(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&&!X(n)||!!o&&s!==o}function Pm(i){return i===S.relative||i===S.absolute||i===S.fixed}var Vn=1e5;function bi(i){let t=i.element.style;t.columnGap=`${Vn-(i.vertical?i.height:i.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function br(i){let e=("element"in i?i.element:i).style;e.columnWidth="",e.columnCount="",e.columnGap="",e.columnFill=""}function yr(i){return i.element.style.columnCount==="1"}function km(i){i.element.setAttribute("data-vivliostyle-column","true")}function xo(i,t){let e=t?i.bottom:Math.max(Math.abs(i.left),Math.abs(i.right));return Math.round(e/Vn)}function Am(i,t){let e=xo(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/Vn),o=s*Vn,r=e*Vn;return t?(i.top-=o,i.bottom-=r,i.bottom<i.top&&(i.bottom+=Vn),i.right-=o,i.left-=r):i.left<-Vn/2?(i.right+=o,i.left+=r,i.left>i.right&&(i.left-=Vn),i.top+=o,i.bottom+=r):(i.left-=o,i.right-=r,i.right<i.left&&(i.right+=Vn),i.top+=o,i.bottom+=r),i.width=i.right-i.left,i.height=i.bottom-i.top,s}function Tl(i,t){for(let e=0;e<i.length;e++)Am(i[e],t)}function At(i,t,e){let n=i.getElementClientRect(t);if(Am(n,e)>0&&i.getElementComputedStyle(t).display.startsWith("table")&&!Eo(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return br(r),i.getElementClientRect(t)}return n}function Rm(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 Md(i){let t=i.style;return t?!isNaN(parseFloat(t.columnCount))||!isNaN(parseFloat(t.columnWidth)):!1}function Lm(i){if(!i.hasAttribute("data-vivliostyle-column")&&Md(i))return!0;for(let t of i.querySelectorAll("*"))if(!t.hasAttribute("data-vivliostyle-column")&&Md(t))return!0;return!1}function Eo(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(Md(t))return t;if(e.position==="absolute")break}return null}function Im(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=Eo(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=`${Vn}px`)}function Nl(i){let t=i.element.lastElementChild,e=t&&i.clientLayout.getElementClientRect(t);return e?xo(e,i.vertical):0}function _d(i,t){if(i.getAttribute("data-viv-saved-column-fill")!=="auto"||Nl(t))return;let e=t.clientLayout.getElementComputedStyle(i),n=parseFloat(e.blockSize);i.style.columnFill="auto";let s=parseFloat(e.blockSize);if(s<=0||i.parentElement&&Eo(i.parentElement)){i.removeAttribute("data-viv-saved-column-fill");return}let o=NaN;if(i.style.blockSize=`${s}px`,Nl(t)){if(i.style.blockSize=`${n}px`,!Nl(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`,Nl(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 Fm(i){let t=i.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let e of t)_d(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&&kt(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];Tl(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=At(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);Tl(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 yi(i,t,e){let n=yr(t);n&&br(t);let s=t.clientLayout.getElementClientRect(i);n&&bi(t);let o=t.getComputedMargin(i);return e?s.width+o.left+o.right:s.height+o.top+o.bottom}function es(i){for(;i;){if(i.parentNode===i.ownerDocument)return!1;i=i.parentNode}return!0}function wl(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 Bn="data-adapt-spec";function Pl(i){return!!i.getAttribute(Bn)}function St(i){return(i==null?void 0:i.nodeType)!==1?!1:Pl(i)?!0:Ud(i)}function Ud(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 Hd(i){var t;return(i==null?void 0:i.nodeType)!==1?!1:((t=i.style)==null?void 0:t.position)==="fixed"}function ts(i){let t=i==null?void 0:i.viewNode;return(t==null?void 0:t.nodeType)===1&&Pl(t)}function Vm(i){return i!=="inline"&&(kt(i)||vl(i))}function zd(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))&&kt(e.display))return e;return null}function Bm(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 Om(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 Dm(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 Mm={"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"}]}},_S=Om(Mm,!0);function Gd(i,t,e){return Dm(i,t,e||null,_S)}var US=Om(Mm,!1);function Wd(i,t,e){return Dm(i,t,e||null,US)}var HS={"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 _m(i,t){let e=HS[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 Sr(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 As(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 Xd(i){let t=i.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function jd(i,t){i.setAttribute("data-viv-box-break",t.join(" "))}function xt(i,t){let e=Xd(i);e.includes(t)||(e.push(t),jd(i,e))}function GS(i){let t=i.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function WS(i,t){i.setAttribute("data-viv-margin-discard",t.join(" "))}function kl(i,t){let e=GS(i);e.includes(t)||(e.push(t),WS(i,e))}function $S(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 Al={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ee(i){return!!Al[i]}var XS={left:!0,right:!0,recto:!0,verso:!0};function ns(i){return!!XS[i]}function Yd(i){return Ee(i)&&i!=="column"&&i!=="region"}var jS={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function xr(i){return!!jS[i]}function De(i,t){if(i)if(t){if(ns(t))return t;if(ns(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:xr(t)?t:xr(i)?i:t}}else return i;else return t}function qd(i){return Ee(i)?i:"auto"}qe("SIMPLE_PROPERTY",$S);var Er=fy(Km());function Zm(i,t){return(0,Er.default)(i,t,0)}function Jd(i){return i.reduce((t,e)=>e[0]===Er.default.DELETE?t:t+e[1],"")}function Qm(i,t){return eC(i,t,1)}function Jm(i,t){return eC(i,t,-1)}function eC(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 Er.default.INSERT:n++;break;case Er.default.DELETE:n--,s++;break;case Er.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Il;(t=>{function i(e){return e&&e.formattingContextType==="Block"}t.isInstanceOfBlockFormattingContext=i})(Il||(Il={}));var Ls;(t=>{let i;(r=>(r.INLINE="inline",r.COLUMN="column",r.REGION="region",r.PAGE="page"))(i=t.FloatReference||(t.FloatReference={}))})(Ls||(Ls={}));var xi;(t=>{function i(e){return e&&e.flagmentLayoutConstraintType=="AfterIfContinue"}t.isInstanceOfAfterIfContinuesLayoutConstraint=i})(xi||(xi={}));var Dn;(e=>{function i(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||yn.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=i;function t(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||yn.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=t})(Dn||(Dn={}));var yn;(e=>{function i(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=i;function t(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=t})(yn||(yn={}));var rn;(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={}))})(rn||(rn={}));var tC={transform:!0,"transform-origin":!0},nC={top:!0,bottom:!0,left:!0,right:!0},Fs=class{constructor(t,e,n){this.target=t;this.name=e;this.value=n}},sx={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 ox(i,t){let e=sx[t];return e?()=>{for(let n=0;n<i.length;n++)try{e(i[n])}catch(s){}}:null}var Is=class Is extends ms{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(Is.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Is.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(e){this.isAutoPageHeight=e,e?this.container.setAttribute(Is.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Is.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=ox(l,a.action);if(u)for(let d=0;d<c.length;d++)c[d].addEventListener(a.event,u,!1)}}}};p(Is,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),p(Is,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var vr=Is,Et=rn.Whitespace;function _l(i){switch(i){case"normal":case"nowrap":return Et.IGNORE;case"pre-line":return Et.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Et.PRESERVE;default:return null}}function ie(i,t){return i?i.nodeType==1?!1:np(i.textContent,t):!0}function np(i,t){switch(t){case Et.PRESERVE:return i.length==0;case Et.NEWLINE:return!!i.match(/^[ \t]*$/);case Et.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)}},Vl=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 sC(i,t){return i.top-t.top}function oC(i,t){return t.right-i.right}function rC(i,t){var e,n;return i===t?!0:!i||!t?!1:(i.node===t.node||!!i.shadowContext&&!!t.shadowContext&&i.shadowType===rn.ShadowType.ROOTLESS&&t.shadowType===rn.ShadowType.ROOTLESS&&((e=i.node)==null?void 0:e.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&i.shadowType===t.shadowType&&tp(i.shadowContext,t.shadowContext)&&tp(i.nodeShadow,t.nodeShadow)&&rC(i.shadowSibling,t.shadowSibling)}function ss(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(!rC(i.steps[e],t.steps[e]))return!1;return!0}function iC(i){return{steps:[{node:i,shadowType:ot.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function vo(i,t){return{steps:[{node:i.sourceNode,shadowType:ot.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 Tr(i,t){let e=new os(i.node,t,0);return e.shadowType=i.shadowType,e.shadowContext=i.shadowContext,e.nodeShadow=i.nodeShadow,e.shadowSibling=i.shadowSibling?Tr(i.shadowSibling,t.copy()):null,e.formattingContext=i.formattingContext,e.fragmentIndex=i.fragmentIndex+1,e}var ot=rn.ShadowType,Vs=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&&tp(this.parentShadow,t.parentShadow):!1}};function tp(i,t){return i===t||!!i&&!!t&&i.equals(t)}var Bl=class{constructor(t,e){this.outer=t;this.count=e}},os=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=ot.NONE,this.shadowContext=e?e.shadowContext:null,this.breakPenalty=e?e.breakPenalty:0,this.floatReference=Ls.FloatReference.INLINE,this.whitespace=e?e.whitespace:Et.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=Ls.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:Et.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===rn.ShadowType.ROOTLESS&&(t.floatReference!==Ls.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?Jm(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}},Gt=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(!ss(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(!ss(this.floats[e],t.floats[e]))return!1}else if(t.floats)return!1;return!0}},Ol=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))}},Dl=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}},Ml=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&&ns(e)?e:"any"}firstFlowChunkOfFlow(t){let e=this.flowPositions[t];if(!e)return null;let n=e.positions[0];return n?n.flowChunk:null}},Nr=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):ui(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 it(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 it(t,e,t+n,e+s)}getOuterShape(t,e){let n=this.getOuterRect();return dl(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 it(t,e,t+n,e+s)}},Mn=class extends Ut{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 Ae)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 se&&n.str.startsWith("running-element-")&&(s=""),this.visitStrInner(s,o)}return null}};function rt(i){return i!=null&&i!==$&&i!==S.normal&&i!==S.none&&!X(i)}var he=Ls.FloatReference,ix=20;function lC(i){switch(i){case"inline":return he.INLINE;case"column":return he.COLUMN;case"region":return he.REGION;case"page":return he.PAGE;default:throw new Error(`Unknown float-reference: ${i}`)}}function xn(i){switch(i){case he.INLINE:return!1;case he.COLUMN:case he.REGION:case he.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${i}`)}}function Ul(i,t,e,n){let s=t?"vertical-rl":"horizontal-tb";if((i==="top"||i==="bottom")&&(i=Wd(i,s,e)),i==="block-start"&&(i="inline-start"),i==="block-end"&&(i="inline-end"),i==="inline-start"||i==="inline-end"){let o=Gd(i,s,e),r=_m(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"&&(D.warn(`Invalid float value: ${i}. Fallback to left.`),i="left"),i}var vi=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}},sp=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=>ss(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=>ss(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}},Ni=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}},Ti=class{constructor(t,e){this.float=t;this.nodePosition=e}equals(t){return t?this===t?!0:this.float===t.float&&ss(this.nodePosition,t.nodePosition):!1}},_n=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=!X(r)&&r||t&&t.writingMode||S.horizontal_tb,this.direction=!X(a)&&a||t&&t.direction||S.ltr,this.floatStore=t?t.floatStore:new sp;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&&ss(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 Sn().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&&Lm(n)}))}hasMultiColumnFootnoteContext(){return this.hasRootMultiColumnFootnoteContext()||this.hasNonRootMultiColumnFootnoteContext()}trySetFootnoteRetryMaxBlockSize(t){let e=this.footnoteMaxBlockSize!=null?this.footnoteMaxBlockSize/2:t/2;return e<ix?!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===he.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,s=this.findPageFloatFragment(n);if(this.floatReference===he.PAGE&&"footnotePolicy"in n&&n.footnotePolicy===S.line&&this.footnoteAnchorsSeen.has(n.getId())&&!s){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 Wd(t,e,n)}toPhysical(t){let e=this.writingMode.toString(),n=this.direction.toString();return Gd(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,x,C){return b.unit==="%"?C*b.num/100:t.convertLengthToPx(b,x,e)}let d=this.floatFragments;return d.length>0&&(c=d.reduce((b,x)=>{if(n&&!n(x,this))return b;let[C,v]=this.toLogicalFloatSides(x.floatSide);if(v&&(s&&v.includes("block")===s.includes("block")&&v!==s||o&&v.includes("block")===o.includes("block")&&v!==o))return b;let y=x.area,N=x.continuations[0].float.floatMinWrapBlock,E=y.vertical?y.left+y.getInsetLeft()+y.width+y.getInsetRight():y.top+y.getInsetTop()+y.height+y.getInsetBottom(),T=y.vertical?y.top+y.getInsetTop()+y.height+y.getInsetBottom():y.left+y.getInsetLeft()+y.width+y.getInsetRight(),k=b.top,L=b.left,V=b.bottom,W=b.right,J=b.floatMinWrapBlockStart,ee=b.floatMinWrapBlockEnd;switch(C){case"inline-start":y.vertical?k=Math.max(k,T):L=Math.max(L,T);break;case"block-start":y.vertical?(N&&y.left<W&&(J=u(N,y.rootViewNodes[0],l.x2-l.x1)),W=Math.min(W,y.left)):(N&&E>k&&(J=u(N,y.rootViewNodes[0],l.y2-l.y1)),k=Math.max(k,E));break;case"inline-end":y.vertical?V=Math.min(V,y.top):W=Math.min(W,y.left);break;case"block-end":y.vertical?(N&&E>L&&(ee=u(N,y.rootViewNodes[0],l.x2-l.x1)),L=Math.max(L,E)):(N&&y.top<V&&(ee=u(N,y.rootViewNodes[0],l.y2-l.y1)),V=Math.min(V,y.top));break;default:throw new Error(`Unknown logical float side: ${C}`)}return{top:k,left:L,bottom:V,right:W,floatMinWrapBlockStart:J,floatMinWrapBlockEnd:ee}},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(E=>E.includes("inline")&&a[E==="inline-start"?"inline-end":"inline-start"]),u=l.find(E=>E.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 x(E,T){let k=E(t.bands,T);return k?(t.vertical&&(k=ll(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,v,y,N;if(o){let E=t.vertical?ar(new it(h,f,d,g)):new it(f,d,g,h);if((l[0]==="block-start"||l[0]==="snap-block"||l[0]==="inline-start"||l[0]==="snap-inline")&&!x(jg,E)||(l[0]==="block-end"||l[0]==="snap-block"||l[0]==="inline-end"||l[0]==="snap-inline")&&!x(Yg,E)||(t.isFootnote&&s!==null&&isFinite(s)&&l[0]==="block-end"&&(t.vertical?d=Math.min(d,s):d=Math.max(d,s)),y=(h-d)*t.getBoxDir(),t.isFootnote&&this.footnoteMaxBlockSize!=null&&(y=Math.min(y,this.footnoteMaxBlockSize),t.vertical?d=h+y:d=h-y),C=Math.max(0,y-t.getInsetBefore()-t.getInsetAfter()),N=(g-f)*t.getInlineDir(),v=N-t.getInsetStart()-t.getInsetEnd(),!r&&(C<=0||v<=0)))return null}else{let E=t.getContentBlockMarginAfter();C=Math.max(0,t.computedBlockSize+Math.min(0,E)),y=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(),V=this.container.getBoxDir()*(s-(this.container.vertical?L.x2:L.y1)),W=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-s-y);V<=W?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<y)return null;l[0]==="inline-start"||l[0]==="inline-end"||l[1]?v=Sr(t.clientLayout,t.element,["fit-content inline size"])["fit-content inline size"]:t.adjustContentRelativeSize?v=t.getContentInlineSize():v=t.vertical?t.height:t.width,N=v+t.getInsetStart()+t.getInsetEnd();let k=(g-f)*t.getInlineDir();if(!r&&k<N)return null}return d-=m,h-=m,f-=b,g-=b,l.some(E=>E==="inline-start"||E==="snap-inline")||l.length===1&&(l[0]==="block-start"||l[0]==="snap-block")?t.setInlinePosition(f,v):(l.some(E=>E==="inline-end")||l.length===1&&l[0]==="block-end")&&t.setInlinePosition(g-N*t.getInlineDir(),v),l.some(E=>E==="block-start"||E==="snap-block")||l.length===1&&(l[0]==="inline-start"||l[0]==="snap-inline")?t.setBlockPosition(d,C):(l.some(E=>E==="block-end")||l.length===1&&l[0]==="inline-end")&&t.setBlockPosition(h-y*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}},Ei=[],Sn=class{static register(t){Ei.push(t)}findByNodeContext(t){for(let e=Ei.length-1;e>=0;e--){let n=Ei[e];if(n.appliesToNodeContext(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}findByFloat(t){for(let e=Ei.length-1;e>=0;e--){let n=Ei[e];if(n.appliesToFloat(t))return n}throw new Error(`No PageFloatLayoutStrategy found for ${t}`)}},op=class{appliesToNodeContext(t){return xn(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 vi(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 Ni(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){}};Sn.register(new op);var rp="data-vivliostyle-footnote-first-ref",ip="data-vivliostyle-footnote-referenced";function Hl(i,t){return!!(i&&i.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function at(i){if(i.localName!=="aside")return!1;if(Hl(i.getAttribute("role"),"doc-footnote"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Hl(t,"footnote")}function vt(i){if(i.localName!=="a")return!1;if(Hl(i.getAttribute("role"),"doc-noteref"))return!0;let t=i.getAttributeNS("http://www.idpf.org/2007/ops","type")||i.getAttribute("epub:type");return Hl(t,"noteref")}function ap(i,t){if(!vt(i))return null;let e=i.getAttribute("href")||i.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!e)return null;let n=Js(e,t);return n==="#"?null:n}function lp(i,t,e){let n=ap(i,t);if(!n)return null;let s=e(n);return s&&at(s)?s:null}function ax(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=ap(a,t);!l||n.has(l)||n.set(l,e(a))}s.value=!0}function cp(i,t,e,n,s){if(i.localName!=="a"||!vt(i))return!0;let o=ap(i,t);if(!o)return!0;ax(i.ownerDocument,t,e,n,s);let r=n.get(o);return r==null||e(i)===r}function up(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 cC(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)||!vt(a))return t;let l=lp(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=up(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 uC(i,t,e,n,s){var f;if(!((e==null?void 0:e.type)===ot.ROOTED&&at(i)))return t;let o=s.getStyle(i);if(!o)return t;let r={...t},a=up(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 dC(i,t,e){var s,o;let n=(t==null?void 0:t.type)===ot.ROOTED&&at(i)?e.getStyle(i):null;return{sourceStyle:n,footnoteDisplay:((s=up(n,e))==null?void 0:s.value)||null,footnotePolicy:((o=e.getProp(n,"footnote-policy"))==null?void 0:o.value)||null}}function pC(i,t){if(i instanceof _){let e=i.expr.evaluate(t);return typeof e=="string"?new G(e):typeof e=="number"?new G(String(e)):i}return i instanceof j?new j(i.values.map(e=>pC(e,t))):i}function hC(i,t,e){let n=i==null?void 0:i["_footnote-marker-content"];n&&(t["--viv-marker-content"]=pC(n.value,e))}function lx(i){let t=i.getElementsByTagName("a"),e=new Set;for(let n=0;n<t.length;n++){let s=t.item(n);if(!vt(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&&at(r)){let a=s.baseURI.replace(/#.*$/,"")+s.hash;e.has(a)||(e.add(a),s.setAttribute(rp,"true")),r.setAttribute(ip,"true")}}}qe("PREPROCESS_SINGLE_DOCUMENT",lx);var cx=Ni,No=class i extends vi{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 ux(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 zl=class extends cx{constructor(t,e,n,s){super(t,"block-end",null,e,n,s)}getOrder(){return 1/0}shouldBeStashedBefore(t){return t instanceof No?!0:this.getOrder()<t.getOrder()}},dp=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}},pp=class{appliesToNodeContext(t){return t.floatSide==="footnote"}appliesToFloat(t){return t instanceof No}createPageFloat(t,e,n){var h;let s=he.REGION,o=e.getPageFloatLayoutContext(s);e.getPageFloatLayoutContext(he.PAGE).hasSameContainerAs(o)&&(s=he.PAGE);let a=!!e.generatingNodePosition;a&&s!==he.PAGE&&(s=he.PAGE);let l=t.toNodePosition();e.flowName;let c=t.sourceNode,u=(h=t.shadowContext)==null?void 0:h.owner;u instanceof Element&&vt(u)&&(c=u),c=ux(c);let d=new No(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 zl(r.floatReference,t,s,o)}findPageFloatFragment(t,e){let s=e.getPageFloatLayoutContext(t.floatReference).floatFragments.filter(o=>o instanceof zl);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 dp(n);e.addLayoutConstraint(s,n.floatReference);break}}}};Sn.register(new pp);var To=class{calculateOffset(t){return Bs(this.getNodeContext(),t.collectElementsOffset())}breakPositionChosen(t){}getNodeContext(){return null}};function Bs(i,t){return{current:t.reduce((e,n)=>e+n.calculateOffset(i),0),minimum:t.reduce((e,n)=>e+n.calculateMinimumOffset(i),0)}}var Un=class extends To{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(xr(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(!Dn.isInstanceOfRepetitiveElementsOwnerFormattingContext(n))return!1;let s=n.getRepetitiveElements();return s?s.isFirstContentNode(e):!1}};var Os=class{find(t){let e=nt("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()}`)}},Hn=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 Un(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===rn.ShadowType.ROOTLESS&&ts(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;wl(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)}},wr=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){}},ki=new Hn,fC=Il.isInstanceOfBlockFormattingContext;qe("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&&xl(e,n,s,o)?new wr(r?r.formattingContext:null):null});qe("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof wr?ki:null);var Ds=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 gp=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){}},wo=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?ie(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()}},rs=class extends gp{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=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 Wl=[];function mC(){Wl=[]}function bp(i,t,e){return i-=e,t===0?i===0:i%t===0&&i/t>=0}var mp=class{constructor(t){this.matchers=t}matches(){return this.matchers.some(t=>t.matches())}},Cp=class{constructor(t){this.matchers=t}matches(){return this.matchers.every(t=>t.matches())}},Pr=class Pr{constructor(t,e,n){this.elementOffset=t;this.a=e;this.b=n}static registerFragmentIndex(t,e,n){let s=Pr.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:e,priority:n})}static clearFragmentIndices(){Pr.fragmentIndices={}}matches(){let t=Pr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&bp(t.fragmentIndex,this.a,this.b)}};p(Pr,"fragmentIndices",{});var Ms=Pr,Po=class{static buildViewConditionMatcher(t,e){let n=e.split("_");return n[0]=="NFS"?new Ms(t,parseInt(n[1],10),parseInt(n[2],10)):(`${e}`,null)}static buildAllMatcher(t){return new Cp(t)}static buildAnyMatcher(t){return new mp(t)}};var rh={"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},dx=["image-resolution","orphans","widows"];function yC(){return nt("POLYFILLED_INHERITED_PROPS").reduce((t,e)=>t.concat(e()),[].concat(dx))}var px={"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},Ep=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],hx=["max-%","min-%","%"],bC=(()=>{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<Ep.length;e++)for(let n=0;n<i.length;n++){let s=Ep[e].replace("%",i[n]);t[s]=!0}return t})();function Lr(i,t){let e={};for(let n of Ep)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 hx)for(let s in t){let o=n.replace("%",s),r=n.replace("%",t[s]);e[o]=r,e[r]=o}return e}var ih=Lr({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),ah=Lr({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),fx=Lr({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),gx=Lr({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),mx=Lr({inside:"right",outside:"left"},{}),Cx=Lr({inside:"left",outside:"right"},{}),B=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&&Ht(e)?this.value:Oi(t,this.value,e,n,s)}isEnabled(t){return!0}},Ai=class i extends B{constructor(e,n,s){super(e,n);this.condition=s}getBaseValue(){return new B(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){D.warn(n)}return!1}};function vp(i,t,e){return(!t||e.priority>=t.priority)&&e.isEnabled(i)?e.getBaseValue():t}function an(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 SC={"region-id":!0,"fragment-selector-id":!0},Ir="data-viv-footnote-counter";function jl(i){let t=i.getAttribute(Ir);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 xC(i,t,e){let n=jl(i);n[t]=e,i.setAttribute(Ir,JSON.stringify(n))}function bx(i,t){var c,u;if(!vt(i)||i.hasAttribute(rp))return null;let e=jl(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=Js(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=jl(a)[t];return l?(xC(i,t,l),l):null}function yx(i){let t=te(i,"content");return!!t&&rt(t.value)}function Sx(i){return!!SC[i]}function Xl(i){return i.charAt(0)==="_"&&i!=="_viewConditionalStyles"}function _s(i){return i.charAt(0)!=="_"&&!SC[i]}function cs(i){return!!rh[i]||Ht(i)}function te(i,t){return i[t]}function zn(i,t,e){e?i[t]=e:delete i[t]}function lt(i,t){return i[t]}function Kt(i,t){let e=i[t];return e||(e={},i[t]=e),e}var EC=i=>{let t=i._viewConditionalStyles;return t||(t=[],i._viewConditionalStyles=t),t};function lh(i,t){return i[t]}function vC(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=Kt(t,u.styleKey);t=d[u.id],t||(t={},d[u.id]=t)}}),r){let u=EC(t);t={},u.push({styles:t,matcher:r})}for(let u in e)if(!Xl(u))if(Sx(u)){let d=lh(e,u),h=vC(t,u);Array.prototype.push.apply(h,d)}else{let d=te(e,u);if(!d.isEnabled(i))continue;let h=d.increaseSpecificity(n);an(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 B($,h.priority);an(t,g,m,i)}}}function NC(i,t){let e={};for(let n=0;n<t.length;n++)Vi(i,e,t[n],0,null,null,null);return e}function ch(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 Yl=class extends nn{constructor(e,n){super();this.props=e;this.context=n;p(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=te(this.props,"font-size");if(!e.value.isNumeric())return dt.em;let n=e.value;if(!Lg(n.unit))throw new Error("Unexpected state");return n.num*dt[n.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?ac(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ic(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Oi(this.context,e,this.propName).visit(this):e}};function ic(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 ac(i,t,e){i=ic(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 is=class{apply(t){}mergeWith(t){return new Np([this,t])}clone(){return this}},Ar=class extends is{constructor(e){super();this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Np=class i extends is{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))}},Ao=class extends is{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))}},fe=class extends is{constructor(){super();p(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Tp=class extends fe{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}},wp=class extends fe{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}},ql=class extends fe{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}},Pp=class extends fe{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}},kp=class extends fe{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)}}}},Ap=class extends fe{constructor(e){super();this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function lc(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 Kl=class extends fe{constructor(e,n){super();this.ns=e;this.name=n}apply(e){lc(e.currentElement,this.ns,this.name,(n,s,o)=>n.hasAttributeNS(s,o))&&this.chained.apply(e)}},Rp=class extends fe{constructor(e,n,s){super();this.ns=e;this.name=n;this.value=s}apply(e){lc(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}},Lp=class extends fe{constructor(e,n){super();this.ns=e;this.name=n}apply(e){lc(e.currentElement,this.ns,this.name,(n,s,o)=>!!px[n.getAttributeNS(s,o)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},ko=class extends fe{constructor(e,n,s){super();this.ns=e;this.name=n;this.regexp=s}apply(e){lc(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)}},Ip=class extends fe{constructor(e){super();this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Zl=class extends fe{constructor(){super()}apply(t){t.isFirst&&this.chained.apply(t)}getPriority(){return 6}},Fp=class extends fe{constructor(){super()}apply(t){t.isRoot&&this.chained.apply(t)}getPriority(){return 12}},Gn=class extends fe{constructor(e,n){super();this.a=e;this.b=n}matchANPlusB(e){return bp(e,this.a,this.b)}},Vp=class extends Gn{constructor(t,e){super(t,e)}apply(t){this.matchANPlusB(t.currentSiblingOrder)&&this.chained.apply(t)}getPriority(){return 5}},Ri=class extends Gn{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}},Li=class extends Gn{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}},Ii=class extends Gn{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}},Bp=class extends fe{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}},Op=class extends fe{constructor(){super()}apply(t){t.currentElement.disabled===!1&&this.chained.apply(t)}getPriority(){return 5}},Dp=class extends fe{constructor(){super()}apply(t){t.currentElement.disabled===!0&&this.chained.apply(t)}getPriority(){return 5}},Mp=class extends fe{constructor(){super()}apply(t){let e=t.currentElement;(e.selected===!0||e.checked===!0)&&this.chained.apply(t)}getPriority(){return 5}},et=class extends fe{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}},Ql=class i extends is{constructor(){super();p(this,"applied",!1)}apply(e){this.applied=!0}clone(){let e=new i;return e.applied=this.applied,e}},Fi=class extends fe{constructor(e){super();p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Ql;for(let n of e)this.firstActions.push(ch(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 fe?e.getPriority():0))}positive(){return!0}relational(){return!1}},_p=class extends Fi{positive(){return!1}},Up=class extends Fi{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}},Jl=class extends Gn{constructor(e,n,s){super(e,n);p(this,"checkAppliedAction");p(this,"firstActions",[]);this.checkAppliedAction=new Ql;for(let o of s)this.firstActions.push(ch(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}},Hp=class extends Jl{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}},Rr=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)}},zp=class i extends Rr{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}},Gp=class i extends Rr{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)}},Wp=class i extends Rr{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)}},$p=class i extends Rr{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}},Xp=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}},jp=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}},Yp=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}},qp=class extends nn{constructor(e){super();this.element=e}createValueFromString(e,n){switch(n){case"url":return e?new Ae(e):new Ae("about:invalid");case"string":default:return e?new G(e):new G("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let n="string",s=null,o=null;if(e.values[0]instanceof j){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 ec(i,t){if(rt(i)){if(i instanceof G)return i.stringValue();if(i instanceof _&&t){let e=i.expr.evaluate(t);return typeof e=="string"?e:typeof e=="number"?String(e):""}if(i instanceof j)return i.values.map(e=>ec(e,t)).join("")}return""}var as=class extends nn{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=ec(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 G("");case"no-close-quote":return n.quoteDepth>0&&n.quoteDepth--,new G("")}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 ut;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,x,C;let a=typeof r=="string",l=v=>a?this.formatCounterList(v,r,s):this.formatLastValue(v,s),c=v=>{this.pseudoName==="footnote-call"&&this.element&&xC(this.element,n,v)};if(this.pseudoName==="footnote-call"&&this.element){let v=bx(this.element,n);if(v)return l(v)}if(this.pseudoName==="footnote-marker"&&this.element){let y=jl(this.element)[n];if(y)return l(y)}let u;if(n==="pages")return l([]);if(!this.element){let v=((f=e.currentPageCounters)==null?void 0:f[n])||[];if(v.length)return u=v,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 v=((b=e.currentPageDocCounters)==null?void 0:b[n])||[],y=((x=e.currentPageCounters)==null?void 0:x[n])||[],N=y.length?y[y.length-1]:0,E=v.length?v[0]:0,T=d.length?d[0]:0,k=N+(T-E);return u=d.length?[k,...d.slice(1)]:y.length?y:[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 se(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)}let a=this.cascade.counters[n];if(a&&a.length){let c=a&&a.length&&a[a.length-1]||0;return new G(this.format(c,s))}else{let c=new _(this.counterResolver.getPageCounterVal(n,u=>this.format(u||0,s)));return new j([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 se(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 _(g)}let l=this.cascade.counters[n],c=new ut;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 _(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 j([u])}visitFuncTargetCounter(e){let n=e[0],s;n instanceof Ae?s=n.url:s=n.stringValue();let o=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",a=new _(this.counterResolver.getTargetCounterVal(s,o,l=>this.format(l||0,r)));return new j([a])}visitFuncTargetCounters(e){let n=e[0],s;n instanceof Ae?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 _(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 j([l])}visitFuncTargetText(e){let n=e[0],s;n instanceof Ae?s=n.url:s=n.stringValue();let o=e.length>1?e[1].stringValue():"content",r=new _(this.counterResolver.getTargetTextVal(s,o));return new j([r])}visitFuncString(e){let n=e.length>0?e[0].stringValue():"",s=e.length>1?e[1].stringValue():"first";return new _(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 _(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=lt(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 x=(l=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:l.value;s=ec(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,b=(this.evaluateAndGetString(g)||this.element.textContent||this.evaluateAndGetString(m)).match(Qs);s=b?b[0]:""}break}return new G(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 G&&(n=e[0].stringValue());return n.length==0?new G(""):new _(new se(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 Sp(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 xx=(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(H){m==="rtl"?u.textContent=(H.startsWith("\u200F")?"":"\u200F")+H+(H.endsWith("\u200F")?"":"\u200F"):u.textContent=H},W=function(){let H=e.clientLayout.getElementClientRect(d);return g==="vertical-rl"||g==="vertical-lr"?m==="rtl"?H.top-=V:H.bottom+=V:m==="rtl"?H.left-=V:H.right+=V,y.left>H.left||y.right<H.right||y.top>H.top||y.bottom<H.bottom},J=function(){let H,Y,z=f.repeat(1e4);if(x(z),W())H=1,Y=1e4;else return;for(let U=0;U<16;U++){let q="",Ne=Math.floor((H+Y)/2);for(let Ve=0;Ve<Ne;Ve++)q+=f;if(x(q),W())Y=Ne;else{if(H==Ne)return;H=Ne}}x(f)},le=function(H){let Y=0,z=d.parentElement;for(;z&&z!==c.viewNode;)Y+=e.getComputedInsets(z)[H],z=z.parentElement;return Y};var s=x,o=W,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",x(f),d.style.display="inline-block",d.style.textIndent="0";let C=Eo(c.viewNode),v=(C==null?void 0:C.style.columnFill)||null;C&&(C.style.columnFill="auto");let y=e.clientLayout.getElementClientRect(c.viewNode),N=e.clientLayout.getElementClientRect(d),E=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 H=L,{display:Y,float:z,position:U}=e.clientLayout.getElementComputedStyle(H);if(z!=="none"||U==="absolute"||U==="fixed"){L=L.nextSibling;continue}if(kt(Y))T.push(H);else if(Tm(Y))break}else if(L.nodeType===3){let H=L;H.length>0&&T.push(H)}L=L.nextSibling}let V=T.reduce((H,Y)=>H+Sp(Y,e.clientLayout,g),0);if(h!=="after"){let H=Sp(k,e.clientLayout,g),Y=Sp(d,e.clientLayout,g);V+=H-Y}g==="vertical-rl"||g==="vertical-lr"?(m==="rtl"?y.top+=E:y.bottom-=E,y.top=Math.min(N.top,y.top),y.bottom=Math.max(N.bottom,y.bottom)):(m==="rtl"?y.left+=E:y.right-=E,y.left=Math.min(N.left,y.left),y.right=Math.max(N.right,y.right)),J();let ee=e.clientLayout.getElementClientRect(d);m=="rtl"?d.style.float="left":d.style.float="right";let ve=e.clientLayout.getElementClientRect(d),F=0;m=="rtl"?g=="vertical-rl"||g=="vertical-lr"?F=ee.top-ve.top-le("top"):F=ee.left-ve.left-le("left"):g=="vertical-rl"||g=="vertical-lr"?F=ve.bottom-ee.bottom-le("bottom"):F=ve.right-ee.right-le("right"),F-=V,F=Math.max(0,F-.1),d.style.float="",u.style.marginInlineStart=`${F}px`,C&&(v?C.style.columnFill=v:C.style.removeProperty("column-fill"))}};qe("POST_LAYOUT_BLOCK",xx);var uh=1/1048576;function kr(i,t){for(let e in i)t[e]=i[e].clone()}var Kp=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 kr(this.tags,t.tags),kr(this.nstags,t.nstags),kr(this.epubtypes,t.epubtypes),kr(this.classes,t.classes),kr(this.ids,t.ids),kr(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 Zp(this,t,e,n,s,o,r)}nextOrder(){return this.order+=uh}},rc=class rc{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 G("\u201C"),new G("\u201D"),new G("\u2018"),new G("\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=Po.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]:Po.buildAnyMatcher([].concat(o)):null}).filter(s=>s);return n.length<=0?e:e===null?n.length===1?n[0]:Po.buildAllMatcher(n):Po.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=xp,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,x,C,v,y,N;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=Ts(E,{reset:!0}))}let h=t["counter-set"];if(h){let E=h.evaluate(this.context);E&&(u=Ts(E,{defaultValue:0}))}let f=t["counter-increment"];if(f){let E=f.evaluate(this.context);E&&(c=Ts(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),So(s)&&(c||(c=Object.create(null)),c["list-item"]=(b=c["list-item"])!=null?b:1,/^\s*[-+]?\d/.test((C=(x=this.currentElement)==null?void 0:x.getAttribute("value"))!=null?C:"")&&(u||(u=Object.create(null)),u["list-item"]=this.currentElement.value)),((y=(v=this.currentElement)==null?void 0:v.parentNode)==null?void 0:y.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=(N=this.currentStyle["counter-increment"])==null?void 0:N.value;(!E||!(E===S.footnote||E instanceof j&&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 T=this.counters[E];T[T.length-1]+=c[E]}if(u)for(let E in u)if(!this.counters[E])this.defineCounter(E,u[E]);else{let T=this.counters[E];T[T.length-1]=u[E]}if(So(s)){let E=this.counters["list-item"],T=E[E.length-1];t["ua-list-item-count"]=new B(new He(T),0);let k=Kt(t,"_pseudos");k.marker||(k.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 as(this,this.currentElement,this.counterResolver));let n=e.value instanceof Te?e.value.values:[e.value];for(let s of n)if(s instanceof j){let o=s.values[0].stringValue(),r=s.values.slice(1).map(a=>ec(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 pt&&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 as(this,e,this.counterResolver,n))),this.popCounters()}pushElement(t,e,n,s){var N,E,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=xp;let a=e.getAttributeNS("http://www.idpf.org/2007/ops","type");a?this.currentEpubTypes=a.split(/\s+/):this.currentEpubTypes=xp;let l=Zr(e);l&&(this.stack[this.stack.length-1].push(new jp(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 x=n.quotes,C=null;if(x){let k=x.evaluate(this.context);k&&(C=new Yp(this.quotes),k===S.none?this.quotes=[new G(""),new G("")]:k===S.auto||k===S.initial?this.quotes=[new G("\u201C"),new G("\u201D"),new G("\u2018"),new G("\u2019")]:k instanceof j&&(this.quotes=k.values))}this.pushCounters(this.currentStyle);let v=this.currentId||this.currentXmlId||e.getAttribute("name")||"";if(c||v){let k=Object.create(null);Object.keys(this.counters).forEach(L=>{k[L]=Array.from(this.counters[L])}),this.counterListener.countersOfId(v,k)}let y=lt(this.currentStyle,"_pseudos");if(y){let k=!0;for(let L of Ex){L||(k=!1);let V=y[L];if(V){let W=(N=te(this.currentStyle,"float"))==null?void 0:N.value,J=e instanceof Element&&vt(e),ee=e instanceof Element&&at(e),ve=!!te(this.currentStyle,"--viv-semantic-footnote-content"),le=W===S.footnote,F=(L==="before"||L==="after")&&(le||ee||ve)&&!!V.content,H=yx(V),Y=L==="footnote-call"&&J&&H,z=L==="footnote-marker"&&(ee||ve)&&H;if((L==="before"||L==="after")&&!(F||rt((E=V.content)==null?void 0:E.value)||this.hasNonTrivialViewConditionalPseudoContent(V))||L==="marker"&&!So((T=te(this.currentStyle,"display"))==null?void 0:T.value)||(L==="footnote-call"||L==="footnote-marker")&&W!==S.footnote&&!Y&&!z||(L==="footnote-call"||L==="footnote-marker")&&ve&&!H)delete y[L];else if(k){if(this.processPseudoelementProps(V,e,L),L==="marker")this.processMarkerPseudoelementProps(V,e,t),delete y[L];else if(L==="footnote-marker"){if(this.resolvePseudoelementInheritedPropertyValue(V,"list-style-position",t,e)===S.outside){this.processMarkerPseudoelementProps(V,e,t);let q=V.content;q&&(this.currentStyle["_footnote-marker-content"]=q),this.currentStyle.display=new B(R("list-item"),0),this.currentStyle["list-style-position"]=new B(S.outside,0),this.currentStyle["list-style-type"]=new B(S.none,0),this.currentStyle["list-style-image"]=new B(S.none,0),delete y[L]}}else if(L==="first-letter"&&V["initial-letter"]){let q=V["initial-letter"].evaluate(this.context);q!==S.normal&&!X(q)&&(this.currentStyle["--viv-initialLetter"]=new B(q,0)),delete V["initial-letter"]}}else this.stack[this.stack.length-2].push(new Xp(V,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 rt((s=n.styles.content)==null?void 0:s.value)})}processMarkerPseudoelementProps(t,e,n){var r,a,l,c,u;let s=So((r=this.currentStyle.display)==null?void 0:r.value);if(!rt((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 Ae)t.content=new B(new j([h,new G(" ")]),0);else if(d instanceof G)t.content=new B(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 B(new G(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let o=t.content;if(o){let d=o.value;if(rt(d)){let h=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new B(h,0)}}for(let d of rc.markerAllowedProps){let h=t[d];if(h){let f=h.evaluate(this.context,d);f&&!X(f)&&(this.currentStyle[`--viv-marker-${d}`]=new B(f,0))}}if(!kt((u=te(this.currentStyle,"display"))==null?void 0:u.value)){let d=this.getInheritedPropertyValue("list-style-position",n,e);d&&d!==S.outside&&!X(d)&&(this.currentStyle["list-style-position"]=new B(d,0))}}resolveMarkerContentVal(t){if(t instanceof _){let e=t.expr.evaluate(this.context);return typeof e=="string"?new G(e):typeof e=="number"?new G(String(e)):t}if(t instanceof j){let e=t.values.map(n=>this.resolveMarkerContentVal(n));return new j(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)_s(n)&&!Ht(n)&&(e[n]=e[n].filterValue(t))}applyAttrFilter(t){let e=new qp(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 oh(t,e,n),r=32,a={};for(let d in s)if(Xl(d)){let h=lt(s,d);for(let f in h)this.applyVarFilter([h[f],...t],e,n)}else if(_s(d)){let h=te(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(X(f)){for(let b of m.propList){let x=new B(f,h.priority),C=te(s,b);zn(a,b,vp(this.context,C,x))}delete s[d]}else{let b=Ps(e.scope,new Ze(f.toString(),null),"");if(b&&(b.visit(m),!m.error)){for(let x of m.propList){let C=new B((u=(c=m.values[x])!=null?c:g.defaultValues[x])!=null?u:S.initial,h.priority),v=te(s,x);zn(a,x,vp(this.context,v,C))}delete s[d]}}else s[d]=new B(f,h.priority)}if(a[d]){let g=te(s,d);g&&g.value!==$&&an(a,d,g,this.context)}}for(let d in a)s[d]=a[d]}applyCalcFilter(t,e){let n=new oc(e);for(let s in t)if(Xl(s)){let o=lt(t,s);for(let r in o)this.applyCalcFilter(o[r],e)}else if(_s(s)&&!Ht(s)){let o=te(t,s),r=o.value.visit(n);r!==o.value&&(t[s]=new B(r,o.priority))}}applyCmykFilter(t,e){let n=new sr(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(Xl(s)){let o=lt(t,s);for(let r in o)this.applyCmykFilterInternal(o[r],e,`::${r}:`)}else if(_s(s)&&!Ht(s)){let o=te(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 B(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(rc,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","hyphens","line-height","tab-size","text-combine-upright","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-orientation","text-shadow","text-transform","unicode-bidi","direction","white-space"]);var Zp=rc,xp=[],Ex=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"];var Qp=null;function TC(i){Qp=i}var ls=class extends on{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:Qp?Qp.clone():new Kp,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let n=ch(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 Pp(e,n.toLowerCase())):n?this.chain.push(new ql(n.toLowerCase())):this.chain.push(new Ap(e)))}invalidSelector(e){D.warn(e),this.chain.push(new et("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Us;e=e.parent)e.parent.invalid=!0}classSelector(e){this.invalidContinuationAfterPseudoelement(`.${e}`)||(this.specificity+=256,this.chain.push(new Tp(e)))}pseudoclassSelector(e,n){if(!this.invalidContinuationAfterPseudoelement(`:${e}`)){switch(e.toLowerCase()){case"enabled":this.chain.push(new Op);break;case"disabled":this.chain.push(new Dp);break;case"checked":this.chain.push(new Mp);break;case"root":case"scope":this.chain.push(new Fp);break;case"link":this.chain.push(new ql("a")),this.chain.push(new Kl("","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)${Yn(s)}($|\\s)`),r=n[1];this.chain.push(new kp(o,r,e==="href-role-type"))}else this.chain.push(new et(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new et(""));break;case"lang":if(n&&n.length==1&&typeof n[0]=="string"){let s=n[0];this.chain.push(new Ip(new RegExp(`^${Yn(s.toLowerCase())}($|-)`)))}else this.chain.push(new et(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let s=vx[e.toLowerCase()];n&&n.length==2?this.chain.push(new s(n[0],n[1])):this.chain.push(new et(""));break}case"first-child":this.chain.push(new Zl);break;case"last-child":this.chain.push(new Li(0,1));break;case"first-of-type":this.chain.push(new Ri(0,1));break;case"last-of-type":this.chain.push(new Ii(0,1));break;case"only-child":this.chain.push(new Zl),this.chain.push(new Li(0,1));break;case"only-of-type":this.chain.push(new Ri(0,1)),this.chain.push(new Ii(0,1));break;case"empty":this.chain.push(new Bp);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 et(""));break;case"nth-fragment":n&&n.length==2?this.viewConditionId=`NFS_${n[0]}_${n[1]}`:this.chain.push(new et(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}}idSelector(e){this.invalidContinuationAfterPseudoelement(`#${e}`)||(this.specificity+=65536,this.chain.push(new wp(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 Kl(e,n);break;case 39:r=new Rp(e,n,o);break;case 45:!o||o.match(/\s/)?r=new et(""):r=new ko(e,n,new RegExp(`(^|\\s)${Yn(o)}($|\\s)`));break;case 44:r=new ko(e,n,new RegExp(`^${Yn(o)}($|-)`));break;case 43:o?r=new ko(e,n,new RegExp(`^${Yn(o)}`)):r=new et("");break;case 42:o?r=new ko(e,n,new RegExp(`${Yn(o)}$`)):r=new et("");break;case 46:o?r=new ko(e,n,new RegExp(Yn(o))):r=new et("");break;case 50:if(o=="supported")r=new Lp(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${$l++}`;this.processChain(new Ar(new zp(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}childSelector(){if(this.invalidContinuationAfterPseudoelement("child selector"))return;let e=`c${$l++}`;this.processChain(new Ar(new Gp(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}adjacentSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("adjacent sibling selector"))return;let e=`a${$l++}`;this.processChain(new Ar(new Wp(e,this.viewConditionId,null))),this.chain=[new et(e)],this.viewConditionId=null}followingSiblingSelector(){if(this.invalidContinuationAfterPseudoelement("following sibling selector"))return;let e=`f${$l++}`;this.processChain(new Ar(new $p(e,this.viewConditionId,null))),this.chain=[new et(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 Ao(this.elementStyle,e,this.pseudoelement,n,this.viewConditionId)}special(e,n){let s;this.condition?s=new Ai(n,0,this.condition):s=new B(n,0),vC(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 j([S.exclusive,S._static]),s),this.simpleProperty("flow-into",n,s),n=S.block),nt("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 Ai(n,a,this.condition):new B(n,a);an(this.elementStyle,e,l)}finish(){return this.cascade}startFuncWithSelector(e,n){let s;switch(e){case"is":s=new Us(this);break;case"not":s=new Jp(this);break;case"where":s=new eh(this);break;case"has":s=new th(this);break;case"nth-child":n&&n.length>=2&&(s=new tc(this,n[0],n[1]));break;case"nth-last-child":n&&n.length>=2&&(s=new nh(this,n[0],n[1]));break}s&&(s.startSelectorRule(),this.owner.pushHandler(s))}},vx={"nth-child":Vp,"nth-of-type":Ri,"nth-last-child":Li,"nth-last-of-type":Ii},$l=0,Us=class i extends ls{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 Up(this.selectorTexts):this.positive()?new Fi(this.chains):new _p(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity),(e=this.parent).selectorFunctionContainsPseudoelement||(e.selectorFunctionContainsPseudoelement=this.containsPseudoelementSelector)):this.parentChain.push(new et("")),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}},Jp=class extends Us{positive(){return!1}forgiving(){return!1}},eh=class extends Us{increasingSpecificity(){return!1}},th=class extends Us{relational(){return!0}},tc=class extends Us{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 Jl(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}forgiving(){return!0}},nh=class extends tc{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Hp(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new et("")),this.owner.popHandler()}},nc=class extends on{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 pn(this.scope,100,s);this.scope.defineName(t,e.toExpr(this.scope,o))}}},Ro=class extends on{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?D.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,n,s,this)}invalidPropertyValue(e,n){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){D.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?this.getImportantSpecificity():this.getBaseSpecificity();o+=this.order,this.order+=uh;let r=this.condition?new Ai(n,o,this.condition):new B(n,o);an(this.elementStyle,e,r)}},sh=class extends Ci{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){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,n.toString())}unknownProperty(e,n){D.warn("E_INVALID_PROPERTY",`${e}:`,n.toString())}simpleProperty(e,n,s){let o=s?yl:bl;o+=this.order,this.order+=uh;let r=new B(n,o);an(this.elementStyle,e,r)}};function dh(i,t){let e=EC(i);e&&e.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function sc(i,t,e){dh(e,n=>{Fr(i,n,t)})}function wC(i,t,e,n){let s=new sh(i,t),o=new Ze(n,s);try{xm(o,s,e)}catch(r){D.warn(r,"Style attribute parse error:")}return s.elementStyle}function cc(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 uc(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 Bi(i,t,e,n,s){let o={};for(let r in i)_s(r)&&(o[r]=te(i,r));return sc(o,t,i),ph(i,e,n,(r,a)=>{Fr(o,a,t),sc(o,t,a)}),o}function ph(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 Fr(i,t,e){for(let n in t)if(_s(n)){let s=te(t,n),o=i[n];i[n]=vp(e,o,s)}}var dc=(i,t,e,n,s,o)=>{var l,c;let r=e?n?fx:ih:n?gx:ah,a=s?mx:Cx;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=bC[h]?h:bC[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===S.inside||d.value===S.outside)&&(d=new B(s===(d.value===S.inside)?S.right:S.left,d.priority));t[m]=o(u,d)}},oh=class extends nn{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||!Ht(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 Te(e.values.slice(1)))}},oc=class extends nn{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=Ps(this.context.rootScope,new Ze(s,null),"");if(o instanceof _)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 He(r)))}catch(r){D.warn(r)}return n}visitNumeric(e){return this.resolveViewportUnit&&$u(e.unit)||this.context.rootFontSize!=null&&Fg(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 Oi(i,t,e,n,s){try{if(t instanceof _)return t.expr instanceof se&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Em(i,t.expr,e);if(t instanceof A||t instanceof pt||t instanceof j||t instanceof Te)return t.visit(new oc(i,!0,n,s))}catch(o){return D.warn(o),$}return t}var PC={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function kC(i){let t=i instanceof Ue?i:typeof i=="string"?R(i):S.none;if(t===S.none)return PC;let e=t instanceof j?t.values:[t],n=Object.create(PC);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 AC(i){return!i.first&&!i.last&&!i.forceEnd&&!i.allowEnd}var Nx={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},RC={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},LC={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function IC(i){let t=i instanceof Ue?i:typeof i=="string"?R(i):S.normal;if(t===S.normal)return RC;if(t===S.auto)return LC;let e=t instanceof j?t.values:[t],n=Object.create(RC);for(let s of e)if(s instanceof Q)switch(s.name){case"trim-both":case"trim-auto":return LC;case"space-all":return Nx;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 hh={ideographAlpha:!1,ideographNumeric:!1},Tx={ideographAlpha:!0,ideographNumeric:!0};function FC(i){let t=i instanceof Ue?i:typeof i=="string"?R(i):S.normal;if(t===S.normal||t===S.auto)return Tx;if(t===S.none)return hh;let e=t instanceof j?t.values:[t],n=Object.create(hh);for(let s of e)if(s instanceof Q)switch(s.name){case"no-autospace":return hh;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function VC(i,t){return!i.ideographAlpha&&!i.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function BC(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 fh=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=BC(o);let a=FC(e),l=IC(n),c=kC(s);if(AC(c)&&VC(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),x=!f||/^\n/.test(f.textContent),C=!f;this.processTextSpacing(g,m||b,m,b,x,C,h,f,a,l,c,o,r),h=g}t.style.whiteSpace=u}postLayoutBlock(t,e){var d,h,f,g,m,b,x,C;let n=!t||t.fragmentIndex===1&&r(),s=n||a();function o(v){var T;if((v==null?void 0:v.nodeType)!==1)return!1;let y=v;if(y.hasAttribute(Bn))return!0;let{position:N,float:E}=(T=y.style)!=null?T:{};return N==="absolute"||N==="fixed"||E&&E!=="none"}function r(){let v=e[0];for(let y=v;;y=y.parent)if(!y||!y.inline){if((y==null?void 0:y.fragmentIndex)!==1)return!1;break}if(!v.inline)return!0;for(let y=v.viewNode.previousSibling;y;y=y.previousSibling)if(!ie(y,v.whitespace)&&!o(y))return!1;return!0}function a(){var N,E;let v=e[0],y;for(;v&&v.inline&&(y=(N=v.viewNode)==null?void 0:N.previousSibling,!(y&&(y.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(y.textContent)&&v.whitespace!==Et.PRESERVE&&(y=y.previousSibling),y)));)v=v.parent;for(;y;){if(y.nodeType===Node.ELEMENT_NODE){if(y.localName==="br")return!0;let T=(E=y.style)==null?void 0:E.display;if(T&&T!=="inline")return!/^(inline|ruby)\b/.test(T)}else if(y.nodeType===Node.TEXT_NODE){if(v.whitespace===Et.PRESERVE){if(/\n$/.test(y.textContent))return!0}else if(v.whitespace===Et.NEWLINE&&/\n[ \t\r\n\f]*$/.test(y.textContent))return!0}y=y.lastChild}return!1}let l=-1;for(let v=0;v<e.length;v++){let y=e[v];if(!y.after&&y.inline&&!y.display&&y.parent&&y.viewNode.parentNode&&y.viewNode.nodeType===Node.TEXT_NODE&&!ie(y.viewNode,y.whitespace)){let F=function(z){var U,q,Ne;if(((U=z.viewNode)==null?void 0:U.nodeType)===Node.ELEMENT_NODE)return z.viewNode.localName==="br";if(((q=z.viewNode)==null?void 0:q.nodeType)===Node.TEXT_NODE){let Ve=z.viewNode;if(z.whitespace===Et.PRESERVE){if(/\n$/.test(Ve.textContent))return!0}else if(z.whitespace===Et.NEWLINE&&/\n[ \t\r\n\f]*$/.test(Ve.textContent))return!0;if(((Ne=Ve.previousElementSibling)==null?void 0:Ne.localName)==="br")return ie(Ve,z.whitespace)}return!1},H=function(z){var U,q,Ne;if(((U=z.viewNode)==null?void 0:U.nodeType)===Node.ELEMENT_NODE)return z.viewNode.localName==="br";if(((q=z.viewNode)==null?void 0:q.nodeType)===Node.TEXT_NODE){let Ve=z.viewNode;if(z.whitespace===Et.PRESERVE){if(/^\n/.test(Ve.textContent))return!0}else if(z.whitespace===Et.NEWLINE&&/^[ \t\r\n\f]*\n/.test(Ve.textContent))return!0;if(((Ne=Ve.nextElementSibling)==null?void 0:Ne.localName)==="br")return ie(Ve,z.whitespace)}return!1};var c=F,u=H;l<0&&(l=v);let N=BC((g=(h=(d=y.lang)!=null?d:y.parent.lang)!=null?h:t==null?void 0:t.lang)!=null?g:(f=t==null?void 0:t.parent)==null?void 0:f.lang),E=FC(y.inheritedProps["text-autospace"]),T=IC(y.inheritedProps["text-spacing-trim"]),k=kC(y.inheritedProps["hanging-punctuation"]);if(AC(k)&&VC(E,T)||/\b(flex|grid)\b/.test(y.parent.display))continue;let L=null,V=null,W=v===l,J=v===l&&n,ee=v===l&&s,ve=!1,le=!1;for(let z=v-1;z>=0;z--){let U=e[z];if(F(U)){ee=!0;break}if(!U.display&&U.viewNode.nodeType===Node.TEXT_NODE&&U.viewNode.textContent.length>0){L=U.viewNode;break}if(((m=U.viewNode)==null?void 0:m.nodeType)===Node.ELEMENT_NODE&&Zt(U.viewNode)==="footnote-call"){if(U.viewNode.contains(y.viewNode))continue;let q=Bm(U.viewNode);if(q){L=q;break}}if(U.display&&!/^(inline|ruby)\b/.test(U.display)||((b=U.viewNode)==null?void 0:b.nodeType)===Node.ELEMENT_NODE&&(U.viewNode.localName==="br"||kn[U.viewNode.localName]))break;z===0&&(W=!0,n&&(J=!0,ee=!0))}for(let z=v+1;z<e.length;z++){let U=e[z];if(H(U)){ve=!0;break}if(U.viewNode!==y.viewNode&&!U.display&&U.viewNode.nodeType===Node.TEXT_NODE&&U.viewNode.textContent.length>0){V=U.viewNode;break}if(U.display&&!/^(inline|ruby)\b/.test(U.display)||((x=U.viewNode)==null?void 0:x.nodeType)===Node.ELEMENT_NODE&&(U.viewNode.localName==="br"||kn[U.viewNode.localName])){z===e.length-1&&o(U.viewNode)&&(le=!0);break}if(z===e.length-1){ve=!0,le=!0;for(let q=U.viewNode.nextSibling;q;q=q.nextSibling)if(!o(q)){le=!1;break}}}if(((C=y.parent)==null?void 0:C.display)==="inline-block"){if(!J){let z=y.parent.viewNode.firstChild;for(;ie(z,y.whitespace);)z=z.nextSibling;y.viewNode===z&&(J=!0)}if(!le){let z=y.parent.viewNode.lastChild;for(;ie(z,y.whitespace);)z=z.previousSibling;y.viewNode===z&&(le=!0)}}if(this.processTextSpacing(y.viewNode,W,J,ee,ve,le,L,V,E,T,k,N,y.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,x,C,v;function y(){if(e)return!0;if(!a)return!1;x||(x=m.createRange(),x.selectNode(t));let F=x.getClientRects()[0];if(!F)return!1;C||(C=m.createRange(),C.selectNode(a));let H=C.getClientRects(),Y=H[H.length-1];return Y?(b||(b=xo(Y,f)),f?F.top<Y.top+Y.height-F.width||F.left+F.width<Y.left+F.width/10||F.left>Y.left+Y.width-F.width/10:F.left<Y.left+Y.width-F.height||F.top>Y.top+Y.height-F.height/10||F.top+F.height<Y.top+F.height/10):!1}function N(){if(!l)return!1;x||(x=m.createRange(),x.selectNode(t));let F=x.getClientRects()[0];if(!F)return!1;b||(b=xo(F,f)),v||(v=m.createRange(),v.selectNode(l));let H=v.getClientRects()[0];return H?f?F.top+F.height>H.top+F.width||F.left>H.left+H.width-F.width/10||F.left+F.width<H.left+F.width/10:F.left+F.width>H.left+F.height||F.top+F.height<H.top+F.height/10||F.top>H.top+H.height-F.height/10:!1}let E=!1,T=!1,k=!1,L=!1,V;if(n&&d.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(g)?(V="viv-ts-open",E=!0,T=!0):r&&d.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(g)?(V="viv-ts-close",E=!0,k=!0):(d.forceEnd||d.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(g)?(V="viv-ts-close",E=!0,L=!0):(u.trimStart||u.spaceFirst||u.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(g)?(V="viv-ts-open",E=!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))&&(V="viv-ts-close",E=!0),E){let Y=function(q){let Ve=parseFloat(m.defaultView.getComputedStyle(q).fontSize)*.7;return(f?q.offsetHeight:q.offsetWidth)>Ve},U=function(){return f?F.offsetLeft:F.offsetTop};var ve=Y,le=U;if(t.parentElement.localName==="viv-ts-inner")return 0;let F=m.createElement(V),H=m.createElement("viv-ts-inner");F.appendChild(H),t.parentNode.insertBefore(F,t),H.appendChild(t);let z=Y(H);if(z||T||k||L){if(V==="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)&&y())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"&&Y(a.parentElement)))F.className="viv-ts-trim";else if((u.trimStart||u.spaceFirst)&&y()){let q=U();F.className="viv-ts-auto",q===U()&&!y()&&(F.className="viv-ts-trim")}}else if(V==="viv-ts-close"){if(k)F.className=z?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||o){let q=U();L?(F.className=z?d.allowEnd&&u.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",d.allowEnd&&q===U()&&(u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-hang-end",q===U()&&(F.className="")):F.className="viv-ts-space")):u.trimEnd?F.className="viv-ts-trim":u.allowEnd?(F.className="viv-ts-auto",q===U()&&(F.className="")):F.className="viv-ts-space"}else if(l&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(l.textContent))z&&u.trimAdjacent&&(F.className="viv-ts-trim");else if(L){let q=N(),Ne=q&&d.allowEnd;Ne||(F.className=z?"viv-hang-end":"viv-hang-end viv-hang-hw"),z?Ne&&u.trimEnd?F.className="viv-ts-auto":!Ne&&!N()?F.className="":!q&&d.allowEnd&&(u.trimEnd?(F.className="viv-ts-auto",N()||(F.className="viv-hang-end")):(F.className="viv-ts-space",N()||(u.allowEnd?(F.className="viv-ts-auto",N()||(F.className="viv-hang-end")):F.className="viv-hang-end"))):!q&&!N()&&(F.className="")}else if(u.trimEnd||u.allowEnd)if(N())u.allowEnd?F.className="viv-ts-space":F.className="viv-ts-auto";else{let q=U();F.className="viv-ts-auto",q===U()&&(F.className="")}}}}let W=!1;function J(F){var Y;let H=(Y=F==null?void 0:F.ownerDocument.defaultView)==null?void 0:Y.getComputedStyle(F);return!!H&&(H.textOrientation==="upright"||H.textCombineUpright==="all"||H["-webkit-text-combine"]==="horizontal")}function ee(F,H){if(F.nodeType===Node.ELEMENT_NODE){let U=m.defaultView.getComputedStyle(F);if(parseFloat(U.marginInlineEnd)||parseFloat(U.borderInlineEndWidth)||parseFloat(U.paddingInlineEnd))return!0}let Y=F.parentElement;if(Y&&!Y.contains(H))return ee(Y,H);if(H.nodeType===Node.ELEMENT_NODE){let U=m.defaultView.getComputedStyle(H);if(parseFloat(U.marginInlineStart)||parseFloat(U.borderInlineStartWidth)||parseFloat(U.paddingInlineStart))return!0}let z=H.parentElement;return z&&!z.contains(F)?ee(F,z):!1}return(c.ideographAlpha||c.ideographNumeric)&&(a&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(g)&&(c.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(a.textContent)||c.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(a.textContent))&&!(f&&J(a.parentElement))&&!ee(a,t)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t),W=!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))&&!ee(t,l)&&(t.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),t.nextSibling),W=!0)),b}registerHooks(){qe("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),qe("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),qe("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},gh=new fh;gh.registerHooks();function OC(i){gh.preprocessForTextSpacing(i)}function DC(i,t,e,n,s,o){gh.processGeneratedContent(i,t,e,n,s,o)}var Lo=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),_C=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","footnote-call","","after"],pc="data-adapt-pseudo";function Zt(i){return i.getAttribute(pc)||""}function Io(i,t){i.setAttribute(pc,t)}var Vr=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=Zt(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 B(new pe(r),0)}return o}processContent(t,e,n){let s=Zt(t);if(!this.contentProcessed[s]){this.contentProcessed[s]=!0;let o=e.content;rt(o)&&(o.visit(new Mn(t,this.context,o,this.exprContentListener)),OC(t))}}};var gN=xi.isInstanceOfAfterIfContinuesLayoutConstraint,HC=Ms.registerFragmentIndex,mN=Ms.clearFragmentIndices,hc=class{constructor(t,e){this.sourceNode=t;this.styler=e}createElement(t,e){let s=e.viewNode.ownerDocument.createElement("div"),o=new Vo(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=Lo.createElementNS("http://www.w3.org/1999/xhtml","div");Io(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 Gt(s)}createShadowContext(t){return new Vs(this.sourceNode,t,null,null,null,rn.ShadowType.ROOTED,this.styler)}},Ch=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 bh(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof i?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},bh=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 zC(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=Px(i,t,n);return t.fragmentLayoutConstraints.push(new Ch(i,e,s)),w(i)})}function Eh(i,t){return i.thenAsync(e=>zC(e,t))}function wx(i,t){let e=I("processAfterIfContinuesOfAncestors"),n=i;return e.loop(()=>{if(n!==null){let s=zC(n,t);return n=n.parent,s.thenReturn(!0)}else return w(!1)}).then(()=>{e.finish(!0)}),e.result()}function Px(i,t,e){let n=i.viewNode;n.appendChild(e);let s=yi(e,t,i.vertical);return n.removeChild(e),s}var fc=class{constructor(t){this.constraints=t}allowLayout(t){return this.constraints.every(e=>e.allowLayout(t))}},Hs=class extends To{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 Fo=class extends Nr{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);km(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=this.clientLayout.pixelRatio===0?.5:1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-n)<s}getFloatLayoutUnit(){return this.clientLayout.pixelRatio===0?0:1/(this.clientLayout.pixelRatio||1)}getFloatLayoutTolerance(e){return e||1}isOverflown(e){let n=1.5/(this.clientLayout.pixelRatio||1);return this.almostEquals(e,this.footnoteEdge,n)?!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=Tr(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?Qm(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&&!ts(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(xo(u,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(l=>{let c=l;c!==e&&(e=c,ts(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)&&(xn(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 Eh(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&&!ts(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}ts(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)&&(xn(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,c=1.5/(this.clientLayout.pixelRatio||1);for(let g of n){let b=Math.abs(g.x1-s)<c&&Math.abs(g.x2-o)<c?c:void 0;this.almostEquals(g.x1,s,b)?g.x1=s:this.almostEquals(g.x1,o,b)&&(g.x1=o),this.almostEquals(g.x2,o,b)?g.x2=o:this.almostEquals(g.x2,s,b)&&(g.x2=s),this.almostEquals(g.y1,r,b)?g.y1=r:this.almostEquals(g.y1,a,b)&&(g.y1=a),this.almostEquals(g.y2,a,b)?g.y2=a:this.almostEquals(g.y2,r,b)&&(g.y2=r)}let u=this.getFloatLayoutUnit(),d=Wo==="webkit"?Math.floor:Math.round,h=n.map(g=>u>0?(d(g.y2/u)-d(g.y1/u))*u:g.y2-g.y1),f=.01;for(let g=0;g<n.length;g++){let m=g<n.length-1?n[g+1].x1:s,b=g<n.length-1?n[g+1].x2:o,x=m-n[g].x1,C=n[g].x2-b,v=0,y=0;x>f?v=1:x<-f&&(v=-1),C>f?y=1:C<-f&&(y=-1);let N=v!==0&&y!==0?v===y?v:0:v||y;if(u>0&&N!==0){let E=N*u;h[g]+E>=0&&(g>=n.length-1||h[g+1]-E>=0)&&(h[g]+=E,g<n.length-1&&(h[g+1]-=E))}}for(let g=0;g<n.length;g++){let m=n[g];m.left=this.createFloat(e,"left",m.x1-s,h[g]),m.right=this.createFloat(e,"right",o-m.x2,h[g]),m.x1<o&&m.x2>s?l=m:l||P(m.right,"float","none")}if(l){let g=n[n.length-1],m=1.5/(this.clientLayout.pixelRatio||1);if(l!==g&&(g.y2>=a||this.almostEquals(g.y2,a,m))&&(this.footnoteEdge=this.vertical?-l.y2:l.y2,l.x1===s&&l.x2===o))for(let b=n.indexOf(l);b<n.length;b++){let x=n[b];this.element.removeChild(x.left),this.element.removeChild(x.right),x.left=null,x.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var o;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(o=this.element.parentElement)!=null&&o.hasAttribute("data-vivliostyle-in-column-balancing"))return;let e=this.vertical?this.width:this.height,n=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge),s=1.5/(this.clientLayout.pixelRatio||1);if(n>0&&n<e&&!this.almostEquals(n,e,s)){let r=this.vertical?"width":"height";if(P(this.element,r,`${n}px`),this.vertical){let a=this.left+(e-n);P(this.element,"left",`${a}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,n,s,o){let r;if(e&&es(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 ir(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 ir(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 ir(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=Ul(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=At(this.clientLayout,s,this.vertical),l=this.getComputedMargin(s),c=new it(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 T=At(this.clientLayout,E,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(E);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 it(u,this.getBoxDir()*this.beforeEdge,d,this.getBoxDir()*this.afterEdge),g=c;this.vertical&&(g=ar(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)?Ul(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?o:e.clearSide,T=this.beforeEdge;E!=="right"&&(T=m*Math.max(T*m,this.leftFloatEdge*m)),E!=="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+=this.getFloatLayoutUnit(),qg(f,this.bands,g,o),this.vertical&&(c=ll(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 x,C=null;if(h&&(h.containingBlockForAbsolute?C=h:C=h.getContainingBlockForAbsolute()),C){let E=C.viewNode.ownerDocument.createElement("div");E.style.position="absolute",C.vertical?E.style.right="0":E.style.left="0",E.style.top="0",C.viewNode.appendChild(E),x=At(this.clientLayout,E,this.vertical),C.viewNode.removeChild(E)}else x={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};if(C?C.vertical:this.vertical){let E=Math.max(0,x.right-c.x2);P(s,"right",`${E}px`)}else{let E=Math.max(0,c.x1-x.left);P(s,"left",`${E}px`)}let v=Math.max(0,c.y1-x.top);P(s,"top",`${v}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let y=this.vertical?c.x1:c.y2,N=this.vertical?c.x2:c.y1;!this.isOverflown(y)||this.breakPositions.length==0?(this.killFloats(),f=new it(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(f=ar(f)),Kg(f,this.bands,g,null,o),this.createFloats(),o=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=N,this.updateMaxReachedAfterEdge(y),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 _n(null,he.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);c.setOuterContext(this.pageFloatLayoutContext);let u=l.getContainer(),d=new xh(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,x=0;g.loopWithFrame(C=>{if(x>=e.length){C.breakLoop();return}let v=e[x],y=new Gt(v.nodePosition),N=m.breakPositions?m.breakPositions.length:0;m.layout(y,!0).then(E=>{if(f.newPosition=E,!E||o){if(E&&m.isFootnote&&m.breakPositions&&!(m.breakPositions.length>N&&m.breakPositions.slice(N).some(k=>k instanceof Hs))){b=!0,C.breakLoop();return}x++,C.continueLoop()}else 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(v=>{g.finish(v)});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 v=r.createPageFloatFragment(e,C,s,m,!!f.newPosition);c.addPageFloatFragment(v,!0),f.pageFloatFragment=v}}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(x=>x.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 No,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 x=!!r.generatingNodePosition;if(r.addPageFloatFragment(g,x),r.discardStashedFragments(a.floatReference),m){let C=new Ti(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 Sn().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&&Zt(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(Bn,"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(he.REGION);return r.getContainer().width<a.getContainer().width&&e===he.COLUMN?n===S.auto?this.buildDeepElementView(s.copy()).then(c=>{let u=c.viewNode,d=Sr(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(he.REGION):o.finish(e)}):n===S.all?o.finish(he.REGION):o.finish(e):o.finish(e),o.result()}layoutPageFloat(e){let n=this.pageFloatLayoutContext,s=new Sn().findByNodeContext(e),o,r=n.findPageFloatByNodePosition(e.toNodePosition());return r?o=w(r):o=s.createPageFloat(e,n,this),o.thenAsync(a=>{let l=vo(e,0),c=this.setFloatAnchorViewNode(e);n.markPageFloatAnchorSeen(a);let u=s.findPageFloatFragment(a,n),d=new Ti(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=g=>{if(!g||g.nodeType!==1)return NaN;let m=At(this.clientLayout,g,this.vertical);return m.right>=m.left&&m.bottom>=m.top?this.vertical?m.left:m.bottom:NaN},f=ks(c,this.clientLayout,0,this.vertical);if(e.floatSide==="footnote"){let g=a;if(g.footnotePolicy===S.line||isNaN(f)){let m=c;for(;m;){if((m.shadowContext?m.shadowContext.owner:m.sourceNode)===g.policyAnchorNode){let x=h(m.viewNode);isNaN(x)||(f=x);break}m=m.parent}}}return isNaN(f)&&e.floatSide==="footnote"&&(f=h(c.viewNode)),this.isOverflown(f)?w(c):this.layoutPageFloatInner(d,s,f,u).thenAsync(g=>g?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==null?void 0: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&&kn[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||!es(o.viewNode)){let d=Bs(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){nt("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=zd(r);if(d){if(((c=this.breakPositions)==null?void 0:c[0])instanceof Hs&&(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&&(ie(h,r.parent.whitespace)||St(h));)h=h.previousSibling;if(h)break;r=r.parent}}}return this.clearOverflownViewNodes(r,!1),r}resolveTextNodeBreaker(e){return nt("RESOLVE_TEXT_NODE_BREAKER").reduce((s,o)=>o(e)||s,Br.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:Pl(f)?d=!c:!f.firstChild||kn[f.localName]||/^r(uby|[bt]c?)$/.test(f.localName)||Vm(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);Tl(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?oC:sC);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(Oa),this.vertical&&o.reverse(),o}calculateClonedPaddingBorder(e){let n=0;for(let s=e;s;s=s.parent)if(!s.inline&&As(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=Bs(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=Mt(d.length,y=>{let N=d[y];return this.vertical?N<h||N<=m.edge:N>h||N>=m.edge}),x=b<=0;x&&(b=Mt(d.length,y=>this.vertical?d[y]<h:d[y]>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 v;if(x?v=m.checkPoint:v=this.findAcceptableBreakInside(e.checkPoints,h,n),v){let y=this.getAfterEdgeOfBlockContainer(v);if(!isNaN(y)&&f*(h-y)>0&&(h=y),this.computedBlockSize=f*(h-this.beforeEdge)+g,d.length>=2){let N=Math.max(1,Math.min(b-1,d.length-1));this.lastLineStride=Math.abs(d[N]-d[N-1])}}return v}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 Os().find(e.formattingContext).finishBreak(this,e,n,s);return r||(r=ki.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 D.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(St(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(!yr(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||As(o))continue;let r=this.clientLayout.getElementComputedStyle(o);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let a=o.getAttribute("data-viv-box-break");xt(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(St(l.viewNode))return!1;if(es(e.viewNode))return!1;let s=this.suppressOpenAncestorBlockEndInset(e),o=ks(e,this.clientLayout,0,this.vertical);s();let r=Bs(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||es(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!==he.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=At(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)?Ul(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=this.getFloatLayoutUnit(),g=this.leftFloatEdge*a>this.beforeEdge*a||this.rightFloatEdge*a>this.beforeEdge*a;if(f>0&&g){let b=d*a>h*a;d=a*(Math.ceil(d*a/f)+(b?1:0))*f}let m=this.getFloatLayoutTolerance(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=At(this.clientLayout,s,this.vertical);let x=this.getAfterEdge(o);if(!e.floatSide)if(this.vertical){let C=x-n.right-d;C>0==n.right>=0&&(C+=n.right),s.style.marginLeft=`${C}px`}else{let C=d-(x+n.top);C>0==n.top>=0&&(C+=n.top),s.style.marginBottom=`${C}px`}return e.clearSpacer=s,!0}}isBFC(e){return!!(fC(e)||Dn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let n=e;n;n=n.parent)if(Hd(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(T){var k,L;if(!(!n||a.isNonFirstColumn||s||!Yd(c))){for(let V=T;V;V=V.parent)if(V.breakBefore==="column"&&(V.breakBefore=null),((k=V.viewNode)==null?void 0:k.nodeType)===1){let W=V.viewNode;((L=W.style)==null?void 0:L.breakBefore)==="column"&&(W.style.breakBefore="")}}}function m(T){var k,L;if(!(!n||!a.isNonFirstColumn||s||c!=="column")){for(let V=T;V;V=V.parent)if(V.breakBefore==="column"&&(V.breakBefore=null),((k=V.viewNode)==null?void 0:k.nodeType)===1){let W=V.viewNode;((L=W.style)==null?void 0:L.breakBefore)==="column"&&(W.style.breakBefore="")}c=null}}function b(T){var k,L;if(!(s||!Yd(c))){for(let V=T;V;V=V.parent)if(V.breakAfter==="column"&&(V.breakAfter=null),((k=V.viewNode)==null?void 0:k.nodeType)===1){let W=V.viewNode;((L=W.style)==null?void 0:L.breakAfter)==="column"&&(W.style.breakAfter="")}}}function x(T){c=De(c,T)}function C(){return s?!0:Ee(c)?n?a.isNonFirstColumn&&c!=="column"&&c!=="region":!v()&&!y():!1}function v(){var T;if(!u||!e||e.floatSide)return!1;for(let k=u;k!=null&&k.parent;k=k.parent){if(k.parent.viewNode&&St(k.parent.viewNode))continue;let L=k.after?k.viewNode:(T=k.viewNode)==null?void 0:T.previousSibling;for(;L&&(ie(L,k.parent.whitespace)||St(L));)L=L.previousSibling;if(L)return!1}return!0}function y(){var k,L;if(u||!(e!=null&&e.viewNode)||e.shadowContext||e.after||e.floatSide||!((k=e.parent)!=null&&k.viewNode)||St(e.parent.viewNode))return!1;let T=!1;for(let V=e;V!=null&&V.parent&&!V.after;V=V.parent){if(V!==e&&St(V.viewNode))return!1;let W=(L=V.viewNode)==null?void 0:L.previousSibling;for(;W&&(ie(W,V.parent.whitespace)||St(W));)St(W)&&(T=!0),W=W.previousSibling;if(W)return!1}return T}let N=()=>{e=d[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=c};return r.loopWithFrame(T=>{var k;for(;e;){e.formattingContext;let L=new Os().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(ie(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){C()?N():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),T.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=xr(c)?c:null),L&&L.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?zd(u):this.breakPositions[this.breakPositions.length-1]instanceof Hs||!n&&d.length===0)&&this.saveEdgeBreakPosition(e.copy(),c,!1),!this.isBFC(e.formattingContext)||Dn.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&ie(e.sourceNode.firstChild,e.whitespace)){d.push(e.copy()),x(e.breakBefore),g(e),m(e),C()?N():(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),T.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let W=e.viewNode,J=W.style;if(e.after){_d(W,this),e.floatSide&&(c=c!=null?c:this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let ee=e.sourceNode;if(ee.localName==="svg"||ee.localName==="math"||ee.getAttribute("data-math-typeset")==="true"){f=!1,u=e.copy(),h.push(u),c=null,x(e.breakAfter),b(e),this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c);break}if(e.inline||L&&L.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(f){if(Hd(e.viewNode))break;if(C()){N(),T.breakLoop();return}d=[],n=!1,l=!1,c=null}f=!1,Ud(e.viewNode)||(u=e.copy(),h.push(u)),x(e.breakAfter),b(e),J&&!St(e.viewNode)&&this.hasNonZeroBlockEndInset(J)&&(h=u?[u]:[])}else{if(d.push(e.copy()),x(e.breakBefore),g(e),m(e),u&&Ee(c)&&Rm(u.viewNode,e.viewNode),(e.pageType!=((k=e.parent)==null?void 0:k.pageType)||!Ee(c))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!this.stopAtOverflow,c),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){T.breakLoop();return}let ee=e.viewNode.localName;if(kn[ee]){C()?N():this.checkOverflowAndSaveEdgeAndBreakPosition(u,null,!0,c)&&(e=(this.stopAtOverflow&&u||e).modify(),e.overflow=!0),T.breakLoop();return}J&&this.hasNonZeroBlockStartInset(J)&&(l=!1,h=[]),f=!0}}while(!1);let V=this.nextInTree(e,l);if(V.isPending()){V.then(W=>{e=W,T.continueLoop()});return}else e=V.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(u,h,!this.stopAtOverflow,c)?u&&this.stopAtOverflow&&(e=u.modify(),e.overflow=!0):Ee(c)&&(this.pageBreakType=c),T.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(ie(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=De(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=De(o,e.breakAfter)}else{o=De(o,e.breakBefore);let u=e.viewNode.localName;if(kn[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(xn(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=he.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 Os().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 Os().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 it(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=Wg(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 Os().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 Hs(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);bi(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 yh(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(yr(this)&&(Fm(this),br(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 Gt(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(Dn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}if(xi.isInstanceOfAfterIfContinuesLayoutConstraint(s)){let o=s.getRepetitiveElements();e.push(o)}yn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(this).forEach(o=>{e.push(o)})});return e}},Vo=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 Fo.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 Un(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 ss(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(!np(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(!ie(r,t.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Br=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+UC(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&&Uu(o)&&Uu(r)?UC(s):""),n}updateNodeContext(t,e,n){return t=t.modify(),t.offsetInNode+=e,t.breakBefore=null,t}};p(Br,"instance");Br.instance=new Br;function UC(i){return i.hyphenateCharacter||i.parent&&i.parent.hyphenateCharacter||"-"}var yh=class extends Ds{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 Sh(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,n){n.fragmentLayoutConstraints=[],n.pseudoParent||mC()}clearNodes(e){super.clearNodes(e);let n=e;for(;n;){let s=n.viewNode;s&&wl(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}},Sh=class{constructor(t,e,n){this.leadingEdge=t;this.breakAfter=e;this.context=n}doLayout(t,e){let n=I("DefaultLayoutMode.doLayout");return wx(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}},xh=class extends Fo{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=dn(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=>{dn(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=dn(n,"height");r!==""&&r!=="auto"&&P(n,"margin-top","auto")}}else if(s==="block-end"||s==="bottom"){let r=dn(n,"width");r!==""&&r!=="auto"&&P(n,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,n)=>{let s=At(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,v,y,N;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(Xt);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=(y=(v=te(m,"footnote-display"))==null?void 0:v.value)==null?void 0:y.toString(),x=!!((N=te(m,"--viv-marker-content"))!=null&&N.value);return b==="compact"&&!x});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=At(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=>Zt(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&&at(r)),o=s?this.getFootnoteAfterPseudo(s):null;return!!o&&!o.hasAttribute("data-vivliostyle-default-footnote-separator")}createDefaultFootnoteAfterPseudo(e){let n=e.ownerDocument.createElement("span");Io(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 En=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;Wl.some(n=>n.root===this.rootSourceNode?(this.repetitiveElements=n.elements,!0):!1)||(this.repetitiveElements=new vh(t,this.rootSourceNode),Wl.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(t){}},vh=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=vo(t,0),this.headerSourceNode=t.sourceNode,this.headerViewNode=t.viewNode)}setFooterNodeContext(t){this.footerNodePosition||(this.footerNodePosition=vo(t,0),this.footerSourceNode=t.sourceNode,this.footerViewNode=t.viewNode)}updateHeight(t){this.headerViewNode&&(this.headerHeight=yi(this.headerViewNode,t,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=yi(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 Vo(s,a,e),c=l.getColumn().pageBreakType;return l.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,l.layout(new Gt(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(Bn,"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}},Di=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}},Mi=class{constructor(t){this.formattingContext=t}accept(t,e){return!0}postLayout(t,e,n,s){return s}},Nh=class extends Di{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}accept(e,n){return!1}},Th=class extends Mi{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return!e.belongsTo(this.formattingContext)&&!e.after&&n.fragmentLayoutConstraints.unshift(new Or(e)),this.processor.doLayout(e,n)}},Or=class i{constructor(t){p(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner");p(this,"nodeContext");let e=us(t.formattingContext);this.nodeContext=e.getRootNodeContext(t)}allowLayout(t,e,n){let s=this.getRepetitiveElements();return!s||es(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:e&&!t||t&&t.overflow?!Rh(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=us(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return w(!0);let o=this.nodeContext;return Ax(n,o,e).thenAsync(()=>Rx(n,o,e).thenAsync(()=>(s.prepareLayoutFragment(),w(!0))))}getRepetitiveElements(){return us(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof i?us(this.nodeContext.formattingContext)===us(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},wh=class extends Ds{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 Nh(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&n&&n.preventSkippingHeader(),new Th(this.formattingContext,this.processor))}},Ph=class extends rs{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 rs.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):rs.prototype.afterNonInlineElementNode.call(this,e)}};var kh=class extends Hn{layout(t,e,n){if(e.isFloatNodeContext(t))return e.layoutFloatOrFootnote(t);let s=us(t.formattingContext);return s.getRootViewNode(t)?(n&&Ah(t.parent,e),t.belongsTo(s)?Hn.prototype.layout.call(this,t,e,n):new wh(s,this).layout(t,e)):e.buildDeepElementView(t)}startNonInlineElementNode(t){let n=Lx(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=us(t.formattingContext),s=I("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(t,e).thenFinish(s),s.result()}layoutEntireBlock(t,e){let n=us(t.formattingContext),s=new Ph(n,e);return new wo(s,e.layoutContext).iterate(t)}doLayout(t,e){let n=us(t.formattingContext),s=I("doLayout"),o=e.layoutContext.nextInTree(t,!1);return Eh(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 Hn.prototype.finishBreak.call(this,t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Hn.prototype.clearOverflownViewNodes(t,e,n,s)}};function kx(i,t){for(let e=i;e;e=e.parent){let n=e.formattingContext;n&&n instanceof En&&!e.belongsTo(n)&&t(n,e)}}function Ah(i,t){i&&kx(i.after?i.parent:i,(e,n)=>{yn.isInstanceOfTableFormattingContext(e)||t.fragmentLayoutConstraints.push(new Or(n))})}function Ax(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 Rx(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 Rh(i,t,e){let n=e.ownerSourceNode,s=i||t;return!s||n.contains(s.sourceNode)}function Lx(i){let t=i.formattingContext;return!t||!(t instanceof En)?null:t}function us(i){return i instanceof En,i}var Ix=new kh;qe("RESOLVE_LAYOUT_PROCESSOR",i=>i instanceof En&&!yn.isInstanceOfTableFormattingContext(i)?Ix:null);var mc=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}},Fh=class{constructor(t,e,n){this.rowIndex=t;this.columnIndex=e;this.cell=n}},Vh=class{constructor(t,e,n){this.column=t;this.cellNodeContext=n;p(this,"pseudoColumn");p(this,"empty",!1);this.pseudoColumn=new Vo(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}},Bh=class{constructor(t,e){this.viewNode=t;this.side=e}},Oh=class extends Un{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 To{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 Hs&&r[c].cellNodeContext.sourceNode.rowSpan>1);return o.forEach((l,c)=>{let u=l.breakPosition.getMinBreakPenalty();a&&l.breakPosition instanceof Un&&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)}},zs=class extends En{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":{let o=this.findRowIndexBySourceNode(e.sourceNode);return this.cellBreakPositions.every(r=>this.isPreviousFragmentRowSpanningCellBreakPosition(r,o))&&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 mc(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 Fh(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)}isPreviousFragmentRowSpanningCellBreakPosition(e,n){let s=e.cell;return n>=0&&s.rowIndex<n&&s.rowIndex+s.rowSpan>n}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=At(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 Mh(e.map(n=>n.elements))]}collectElementsOffsetFromColumn(e,n){e.fragmentLayoutConstraints.forEach(s=>{if(Dn.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(s)){let o=s.getRepetitiveElements();n.push(o)}yn.isInstanceOfTableRowLayoutConstraint(s)&&s.getElementsOffsetsForTableCell(null).forEach(o=>{n.push(o)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Mh=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=Bs(t,s);n=Math.max(n,e(o))}),n}};function ln(i){return i instanceof zs,i}function Fx(i){return i==="table-row-group"||i==="table-header-group"||i==="table-footer-group"}function Vx(i){return i==="table"||i==="inline-table"}function WC(i){return Fx(i)||Vx(i)}function $C(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 zs)){for(let l=n.parent;l;l=l.parent)if(l.formattingContext instanceof zs){r=l.formattingContext===t;break}}return r||s==="table-row"&&!WC(o)||s==="table-cell"&&o!=="table-row"&&!WC(o)||n.formattingContext instanceof zs&&n.formattingContext!==t?e.buildDeepElementView(n).thenAsync(l=>(i.nodeContext=l,w(!0))):null}function XC(i,t){let e=t.nodeContext;return!(e!=null&&e.floatSide)||!(xn(e.floatReference)||e.floatSide==="footnote")?null:i.layoutFloatOrFootnote(e).thenAsync(n=>(n&&(t.nodeContext=n),w(!0)))}var _h=class extends rs{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=$C(e,n,this.column);if(s)return s;this.postLayoutBlockContents(e);let o=XC(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 Bh(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 mc(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 Ih(this.rowIndex,this.columnIndex,a)),this.columnIndex++,jC(a);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&&!ts(n)&&this.checkPoints.push(n.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},bc=class bc extends rs{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");p(this,"didExtractRowSpanningCellBreakPositions",!1);this.originalStopAtOverflow=n.stopAtOverflow,n.stopAtOverflow=!1}startNonInlineElementNode(e){let n=XC(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 Vh(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).thenAsync(()=>(jC(l),w(!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(){if(this.didExtractRowSpanningCellBreakPositions)return[];let e=this.formattingContext.cellBreakPositions;if(e.length===0)return[];let n=[];return e.forEach(s=>{let o=s.cell,r=o.rowIndex;if(r<this.currentRowIndex&&r+o.rowSpan>this.currentRowIndex){let a=n[r];a||(a=n[r]=[]),a.push(s)}}),this.didExtractRowSpanningCellBreakPositions=n.length>0,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=Tr(h[0].cellNodePosition.steps[1],a.parent);return r.setCurrent(f,!1).thenAsync(()=>{let g=w(!0),m=0;function b(x){for(;m<x;){if(!d.includes(m)){let C=f.viewNode.ownerDocument.createElement("td");P(C,"padding","0"),f.viewNode.appendChild(C)}m++}}return h.forEach(x=>{g=g.thenAsync(()=>{let C=x.cell;b(C.anchorSlot.columnIndex);let v=x.cellNodePosition,y=Tr(v.steps[0],f);return y.offsetInNode=v.offsetInNode,y.after=v.after,y.fragmentIndex=v.steps[0].fragmentIndex+1,r.setCurrent(y,!1).thenAsync(()=>{let N=x.breakChunkPosition;for(let E=0;E<C.colSpan;E++)d.push(m+E);return m+=C.colSpan,this.layoutCell(C,y,N).thenAsync(()=>(y.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&&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,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);HC(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=vo(c,0);return w(new Gt(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=$C(e,ln(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 Dh(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&&bc.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 if(o==="table-row"&&!this.inHeader&&!this.inFooter){let r=super.afterNonInlineElementNode(e);return(r&&r.isPending()?r:w(!0)).thenAsync(()=>{if(!e.break){let l=this.column.checkOverflowAndSaveEdge(n,null),c=this.formattingContext.getRepetitiveElements(),u=this.column.nodeContextOverflowingDueToRepetitiveElements===n,d=!l&&u&&!!(c!=null&&c.isFooterRegistered());(l||u)&&!d&&this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex).length===0&&(this.resetColumn(),n.overflow=!0,e.break=!0)}return w(!0)})}else return super.afterNonInlineElementNode(e);return w(!0)}};p(bc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Uh=bc,_i=[];function Bx(i){let t=_i.findIndex(n=>n.root===i),e=_i[t];return e?e.tableLayoutOption:null}function Ox(i){let t=_i.findIndex(e=>e.root===i);t>=0&&_i.splice(t,1)}var Cc=class{layoutEntireTable(t,e){let n=ln(t.formattingContext),s=new _h(n,e);return new wo(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=At(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=ln(t.formattingContext);n.vertical=t.vertical,n.initializeRepetitiveElements(t.vertical),t.sourceNode;let s=Bx(t.sourceNode);Ox(t.sourceNode);let o=I("TableLayoutProcessor.doInitialLayout"),r=t.copy();return this.layoutEntireTable(t,e).then(a=>{var h;let l=a.viewNode,c=n.rows[0];if(c&&Ee(c.breakBefore)&&this.hasInFlowContentBefore(l,e)){(h=l.parentNode)==null||h.removeChild(l),e.pageBreakType=c.breakBefore,o.finish(r);return}let u=At(e.clientLayout,l,e.vertical),d=e.vertical?u.left:u.bottom;if(d+=(e.vertical?-1:1)*Bs(t,e.collectElementsOffset()).current,!e.isOverflown(d)&&(!s||!s.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(n)){e.breakPositions.push(new Gh(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}hasInFlowContentBefore(t,e){let n=t;for(;n&&n!==e.element;){let s=n.previousSibling;for(;s;){if(s.nodeType===1&&!St(s)||s.nodeType===3&&!ie(s))return!0;s=s.previousSibling}n=n.parentNode}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=ln(t.formattingContext),s=n.getRootViewNode(t),o=s.firstChild;this.addCaptions(n,s,o),this.addColGroups(n,s,o);let r=new Uh(n,e),a=new wo(r,e.layoutContext),l=I("TableFormattingContext.doLayout");return a.iterate(t).thenFinish(l),l.result()}layout(t,e,n){let s=ln(t.formattingContext);return s.getRootViewNode(t)?(n&&Ah(t.parent,e),new Hh(s,this).layout(t,e)):e.buildDeepElementView(t)}createEdgeBreakPosition(t,e,n,s){return new Oh(t,e,n,s)}startNonInlineElementNode(t){return!1}afterNonInlineElementNode(t,e){return Lh(t),!1}finishBreak(t,e,n,s){let o=ln(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 Gt(f.toNodePosition());o.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:b,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(()=>{Dx(h,o,f),u.continueLoop()})}).then(()=>{t.clearOverflownViewNodes(e,!1),t.layoutContext.processFragmentedBlockEdge(e),Lh(e),o.finishFragment(),l.finish(!0)}),l.result()}}return Lh(e),o.finishFragment(),ki.finishBreak(t,e,n,s)}clearOverflownViewNodes(t,e,n,s){Hn.prototype.clearOverflownViewNodes(t,e,n,s)}};function Dx(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=At(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 jC(i){let t=i.matches("td, th")?i:i.closest("td, th");if(!t||t.style.verticalAlign!=="baseline")return;let n=t.querySelector(".-vivliostyle-table-cell-container");if(!n)return;let s=n.children;if(s.length!==0){for(let o=0;o<s.length;o++){let r=s[o].style.position;if(r!=="absolute"&&r!=="fixed")return}P(n,"display","contents")}}function Lh(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 Hh=class extends Ds{constructor(e,n){super();this.tableFormattingContext=e;this.processor=n}resolveLayoutMode(e){let n=this.tableFormattingContext.getRepetitiveElements();return!n||!n.doneInitialLayout?new zh(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&n&&n.preventSkippingHeader(),new $h(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()}},zh=class extends Di{constructor(e,n){super(e);this.processor=n}doLayout(e,n){return this.processor.doInitialLayout(e,n)}},Gh=class extends Un{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 Wh(this.position.sourceNode))}},Wh=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,_i.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}},$h=class extends Mi{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 Or{constructor(e){super(e);p(this,"flagmentLayoutConstraintType","TableRow");p(this,"cellFragmentLayoutConstraints",[])}allowLayout(e,n,s){let o=this.getRepetitiveElements();return!o||s.pseudoParent||es(this.nodeContext.viewNode)||!o.isEnableToUpdateState()?!0:n&&!e||e&&e.overflow?!Rh(e,n,o):!0}nextCandidate(e){let n=ln(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=ln(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 Cc().removeColGroups(r,a),this.removeDummyRowNodes(s)}super.postLayout(e,n,s,o)}finishBreak(e,n){let s=ln(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=ln(this.nodeContext.formattingContext),s=n.findCellFromColumn(e);return s?n.collectElementsOffsetOfUpperCells(s):n.collectElementsOffsetOfHighestColumn()}equalsTo(e){return e instanceof i?ln(this.nodeContext.formattingContext)===ln(e.nodeContext.formattingContext):!1}},Mx=new Cc;function _x(i,t,e,n,s,o){if(!t)return null;if(e===S.table){let r=i.parent;return new zs(r?r.formattingContext:null,i.sourceNode)}return null}function Ux(i){return i instanceof zs?Mx:null}qe("RESOLVE_FORMATTING_CONTEXT",_x);qe("RESOLVE_LAYOUT_PROCESSOR",Ux);function YC(i){return i.reduce((t,e)=>t+e,0)/i.length}function qC(i){let t=YC(i);return YC(i.map(e=>{let n=e-t;return n*n}))}var jh=class{constructor(t,e){this.layoutResult=t;this.penalty=e}};function Ui(i){return i.vertical?i.width:i.height}function Hi(i,t){i.vertical?i.width=t:i.height=t}var yc=class{constructor(t,e,n){this.layoutContainer=t;this.columnGenerator=e;this.regionPageFloatLayoutContext=n;p(this,"originalContainerBlockSize");this.originalContainerBlockSize=Ui(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 jh(t,e)}preBalance(t){}postBalance(){Hi(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)}},Yh=1;function ZC(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+Yh}function QC(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+Yh))-Yh;s<Ui(t)?Hi(t,s):Hi(t,Ui(t)-1)}var qh=class extends yc{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);Hi(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 KC(n)?1/0:Math.max.apply(null,n.map(s=>s.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return ZC(e);{let n=e[e.length-1];return this.checkPosition(n.layoutResult.position)&&!KC(n.layoutResult.columns)?(this.foundUpperBound=!0,!0):Ui(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)QC(e,this.layoutContainer);else{let n=Math.min(this.originalContainerBlockSize,Ui(this.layoutContainer)+this.originalContainerBlockSize*.1);Hi(this.layoutContainer,n)}}};function KC(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 Kh=class extends yc{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 qC(e)}hasNextCandidate(t){return ZC(t)}updateCondition(t){QC(t,this.layoutContainer)}};function JC(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 qh(e,n,s,i):t===S.balance_all?new Kh(e,n,s):(S.balance,null)}}var Gx=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Wx=new Set(Gx);function $x(i){return!(i.toLowerCase()==="none"||Wx.has(i))}var Xx=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],jx=new Set(Xx),Yx=["fixed","extends"],qx=new Set(Yx),FN=Symbol();function ta(i){return i instanceof Q&&i.name.toLowerCase()!=="none"}function tb(i){return i.name}function Kx(i){if(i instanceof Q)return jx.has(i.name);if(i instanceof j&&i.values.length===2){let t=i.values[0],e=i.values[1];if(t instanceof Q){let n=t.name;return qx.has(n)&&(n==="fixed"&&e instanceof pe||n==="extends"&&ta(e))}}return!1}function Zx(i){let t=Nt(i,"system");return t instanceof Q&&t.name==="cyclic"}function Qx(i){let t=Nt(i,"system");if(t instanceof Q&&t.name==="fixed")return!0;if(t instanceof j&&t.values.length===2){let[e,n]=t.values;return e instanceof Q&&e.name==="fixed"&&n instanceof pe}return!1}function Jx(i){let t=Nt(i,"system");return t instanceof Q?1:t.values[1].num}function eE(i){let t=Nt(i,"system");return t instanceof Q&&t.name==="alphabetic"}function tE(i){let t=Nt(i,"system");return t instanceof Q&&t.name==="numeric"}function nE(i){let t=Nt(i,"system");return t instanceof Q&&t.name==="additive"}function sE(i){let t=Nt(i,"system");if(t instanceof j&&t.values.length===2){let[e,n]=t.values;return e instanceof Q&&e.name==="extends"&&ta(n)}return!1}function oE(i){let t=Nt(i,"system");return tb(t.values[1])}function cn(i){return i instanceof G||i instanceof Q}function ps(i){return i instanceof G?i.str:i.name}function nb(i){if(cn(i))return!0;if(i instanceof j&&i.values.length===2){let t=i.values[0],e=i.values[1];return cn(t)&&cn(e)}return!1}function rE(i){if(cn(i))return{prefix:ps(i),suffix:null};{let t=i.values[0],e=i.values[1];return{prefix:ps(t),suffix:ps(e)}}}function eb(i){return i instanceof pe||i instanceof Q&&i.name==="infinite"}function Sc(i,t){return i instanceof pe?i.num:t?-1/0:1/0}var VN=Symbol();function Zh(i){if(!(i instanceof j&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];if(!(eb(t)&&eb(e)))return!1;let n=Sc(t,!0),s=Sc(e,!1);return!(n>s)}function iE(i){return{lower:Sc(i.values[0],!0),upper:Sc(i.values[1],!1)}}function sb(i){return i instanceof Q&&i.name==="auto"||Zh(i)||i instanceof Te&&i.values.length>=1&&i.values.every(t=>Zh(t))}function aE(i){return i instanceof Q?null:(Zh(i)?[i]:i.values).map(e=>iE(e))}var BN=Symbol();function xc(i){if(!(i instanceof j&&i.values.length===2))return!1;let t=i.values[0],e=i.values[1];return t instanceof pe&&t.num>=0&&cn(e)||cn(t)&&e instanceof pe&&e.num>=0}function Ec(i){let[t,e]=i.values;return t instanceof pe?[t.num,ps(e)]:[e.num,ps(t)]}function ob(i){return xc(i)}function lE(i){let[t,e]=Ec(i);return{minLength:t,symbol:e}}function rb(i){return cn(i)||i instanceof j&&i.values.length>=1&&i.values.every(t=>cn(t))}function cE(i){return cn(i)?[ps(i)]:i.values.map(t=>ps(t))}var ON=Symbol();function ib(i){if(xc(i))return!0;if(i instanceof Te&&i.values.length>=1){let t=1/0;for(let e of i.values){if(!xc(e))return!1;let[n]=Ec(e);if(n>=t)return!1;t=n}return!0}return!1}function uE(i){if(xc(i)){let[t,e]=Ec(i);return[{weight:t,symbol:e}]}else return i.values.map(t=>{let[e,n]=Ec(t);return{weight:e,symbol:n}})}var dE=["auto","bullets","numbers","words","spell-out"],pE=new Set(dE);function hE(i){return i instanceof Q&&pE.has(i.name)||ta(i)}function ab(i,t){switch(i){case"system":return Kx(t);case"negative":return nb(t);case"prefix":case"suffix":return cn(t);case"range":return sb(t);case"pad":return ob(t);case"fallback":return ta(t);case"symbols":return rb(t);case"additive-symbols":return ib(t);case"speak-as":return hE(t);default:return!0}}function Nt(i,t){var n;let e=(n=i[t])==null?void 0:n.value;return e==null?null:e}function fE(i,t){return t.some(({lower:e,upper:n})=>i>=e&&i<=n)}function Mr(i){let t=i.get("decimal");return t||(t=oe.createDecimal(i),i.set("decimal",t)),t}var Gi,Wi,$i,Xi,ji,Yi,qi,Ki,wc,Pc,kc,Ac,Rc,Lc,Ic,Me,Qh,lb,cb,ub,db,Jh,pb,zi,It=class It{constructor(t,e){Z(this,Me);p(this,"_store");Z(this,Gi);Z(this,Wi);Z(this,$i);Z(this,Xi);Z(this,ji);Z(this,Yi);Z(this,qi);Z(this,Ki);this._store=t;let n=Nt(e,"negative");ke(this,Gi,n&&nb(n)?rE(n):null);let s=Nt(e,"prefix");ke(this,Wi,s&&cn(s)?ps(s):null);let o=Nt(e,"suffix");ke(this,$i,o&&cn(o)?ps(o):null);let r=Nt(e,"range");ke(this,Xi,r&&sb(r)?aE(r):null);let a=Nt(e,"pad");ke(this,ji,a&&ob(a)?lE(a):null);let l=Nt(e,"fallback");ke(this,Yi,l&&ta(l)?tb(l):null);let c=Nt(e,"symbols");ke(this,qi,c&&rb(c)?cE(c):null);let u=Nt(e,"additive-symbols");ke(this,Ki,u&&ib(u)?uE(u):null)}static create(t,e){return Zx(e)?new ds(t,e):Qx(e)?new ef(t,e):eE(e)?new nf(t,e):tE(e)?new vc(t,e):nE(e)?new sf(t,e):sE(e)?new of(t,e):new tf(t,e)}static createDecimal(t){return new vc(t,O(It,wc))}static createDisc(t){return new ds(t,O(It,Pc))}static createSquare(t){return new ds(t,O(It,kc))}static createCircle(t){return new ds(t,O(It,Ac))}static createDisclosureOpen(t){return new ds(t,O(It,Rc))}static createDisclosureClosed(t){return new ds(t,O(this,Lc))}static createNone(t){return new ds(t,O(It,Ic))}static get CHINESE_LONGHAND_NAMES(){return Nc.NAMES}static createChineseLonghand(t,e){return new Nc(t,e)}static createEthiopicNumeric(t){return new rf(t)}_getNegative(){return O(this,Gi)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return O(this,Wi)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return O(this,$i)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return O(this,Xi)}static _getRangeFrom(t){return t._getRange()}_getPad(){return O(this,ji)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(O(this,Yi)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return O(this,qi)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return O(this,Ki)}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 Ce(this,Me,zi).call(this,t,new Set)}formatMarker(t){return Ce(this,Me,lb).call(this)+this.format(t)+Ce(this,Me,cb).call(this)}};Gi=new WeakMap,Wi=new WeakMap,$i=new WeakMap,Xi=new WeakMap,ji=new WeakMap,Yi=new WeakMap,qi=new WeakMap,Ki=new WeakMap,wc=new WeakMap,Pc=new WeakMap,kc=new WeakMap,Ac=new WeakMap,Rc=new WeakMap,Lc=new WeakMap,Ic=new WeakMap,Me=new WeakSet,Qh=function(){var t;return(t=this._getNegative())!=null?t:{prefix:"-",suffix:null}},lb=function(){var t;return(t=this._getPrefix())!=null?t:""},cb=function(){var t;return(t=this._getSuffix())!=null?t:". "},ub=function(){var t;return(t=this._getRange())!=null?t:this._getAutoRange()},db=function(){var t;return(t=this._getPad())!=null?t:{minLength:0,symbol:""}},Jh=function(){var t;return(t=this._getFallback())!=null?t:Mr(this._store)},pb=function(t,e){let{minLength:n,symbol:s}=Ce(this,Me,db).call(this);if(n===0||s==="")return t;let{prefix:o,suffix:r}=Ce(this,Me,Qh).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},zi=function(t,e){var a,l,c;if(e.has(this))return Ce(a=Mr(this._store),Me,zi).call(a,t,new Set);if(e.add(this),!fE(t,Ce(this,Me,ub).call(this))){let u=Ce(this,Me,Jh).call(this);return Ce(l=u,Me,zi).call(l,t,e)}let n=this._usesNegativeSign(t),s=n?Math.abs(t):t,o=this._generateInitialRepresentation(s);if(o===null){let u=Ce(this,Me,Jh).call(this);return Ce(c=u,Me,zi).call(c,t,e)}let r=Ce(this,Me,pb).call(this,o,n);if(n){let{prefix:u,suffix:d}=Ce(this,Me,Qh).call(this);r=u+r+(d!=null?d:"")}return r},Z(It,wc,{system:new B(R("numeric"),0),symbols:new B(new j([new G("0"),new G("1"),new G("2"),new G("3"),new G("4"),new G("5"),new G("6"),new G("7"),new G("8"),new G("9")]),0)}),Z(It,Pc,{system:new B(R("cyclic"),0),symbols:new B(new G("\u2022"),0),suffix:new B(new G(" "),0)}),Z(It,kc,{system:new B(R("cyclic"),0),symbols:new B(new G("\u25AA"),0),suffix:new B(new G(" "),0)}),Z(It,Ac,{system:new B(R("cyclic"),0),symbols:new B(new G("\u25E6"),0),suffix:new B(new G(" "),0)}),Z(It,Rc,{system:new B(R("cyclic"),0),symbols:new B(new G("\u25BE"),0),suffix:new B(new G(" "),0)}),Z(It,Lc,{system:new B(R("cyclic"),0),symbols:new B(new G("\u25B8"),0),suffix:new B(new G(" "),0)}),Z(It,Ic,{system:new B(R("cyclic"),0),symbols:new B(new G(""),0),suffix:new B(new G(""),0)});var oe=It,ds=class extends oe{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]}},Zi,ef=class extends oe{constructor(e,n){super(e,n);Z(this,Zi);ke(this,Zi,Jx(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,Zi);return(o=n[s])!=null?o:null}};Zi=new WeakMap;var tf=class extends oe{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)}},nf=class extends oe{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}},vc=class extends oe{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}},sf=class extends oe{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}},Dr,Ft,Qt,af=class af extends oe{constructor(e,n){super(e,n);Z(this,Ft);Z(this,Dr);let s=oE(n),o=s.toLowerCase();o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed"?ke(this,Dr,o):ke(this,Dr,s)}_getNegative(){var e;return(e=super._getNegative())!=null?e:oe._getNegativeFrom(Ce(this,Ft,Qt).call(this))}_getPrefix(){var e;return(e=super._getPrefix())!=null?e:oe._getPrefixFrom(Ce(this,Ft,Qt).call(this))}_getSuffix(){var e;return(e=super._getSuffix())!=null?e:oe._getSuffixFrom(Ce(this,Ft,Qt).call(this))}_getAutoRange(){return oe._getAutoRangeFrom(Ce(this,Ft,Qt).call(this))}_getRange(){var e;return(e=super._getRange())!=null?e:oe._getRangeFrom(Ce(this,Ft,Qt).call(this))}_getPad(){var e;return(e=super._getPad())!=null?e:oe._getPadFrom(Ce(this,Ft,Qt).call(this))}_getFallback(){var e;return(e=super._getFallback())!=null?e:oe._getFallbackFrom(Ce(this,Ft,Qt).call(this))}_getSymbols(){var e;return(e=super._getSymbols())!=null?e:oe._getSymbolsFrom(Ce(this,Ft,Qt).call(this))}_getAdditiveSymbols(){var e;return(e=super._getAdditiveSymbols())!=null?e:oe._getAdditiveSymbolsFrom(Ce(this,Ft,Qt).call(this))}_usesNegativeSign(e){return oe._useNegativeSignFrom(Ce(this,Ft,Qt).call(this),e)}_generateInitialRepresentation(e){return super._getSymbols()||super._getAdditiveSymbols()?null:oe._generateInitialRepresentationFrom(Ce(this,Ft,Qt).call(this),e)}};Dr=new WeakMap,Ft=new WeakSet,Qt=function(e=new Set){var s;if(e.has(this))return Mr(this._store);e.add(this);let n=this._store.get(O(this,Dr));return n?n instanceof af?Ce(s=n,Ft,Qt).call(s,e):n:Mr(this._store)};var of=af,gE=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Fc,Vc,Qi,Bc,Oc,Ji,Wt=class Wt extends oe{constructor(e,n){let{chars:s,descriptors:o}=O(Wt,Oc).get(n);super(e,o);Z(this,Ji);ke(this,Ji,s)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let n=O(this,Ji);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}};Fc=new WeakMap,Vc=new WeakMap,Qi=new WeakMap,Bc=new WeakMap,Oc=new WeakMap,Ji=new WeakMap,Z(Wt,Fc,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new B(new G("\u3001"),0),fallback:new B(R("cjk-decimal"),0),range:new B(new j([new pe(-9999),new pe(9999)]),0),negative:new B(new G("\u8D1F"),0)}}),Z(Wt,Vc,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new B(new G("\u3001"),0),fallback:new B(R("cjk-decimal"),0),range:new B(new j([new pe(-9999),new pe(9999)]),0),negative:new B(new G("\u8D1F"),0)}}),Z(Wt,Qi,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new B(new G("\u3001"),0),fallback:new B(R("cjk-decimal"),0),range:new B(new j([new pe(-9999),new pe(9999)]),0),negative:new B(new G("\u8CA0"),0)}}),Z(Wt,Bc,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new B(new G("\u3001"),0),fallback:new B(R("cjk-decimal"),0),range:new B(new j([new pe(-9999),new pe(9999)]),0),negative:new B(new G("\u8CA0"),0)}}),p(Wt,"NAMES",new Set(gE)),Z(Wt,Oc,new Map([["simp-chinese-informal",O(Wt,Fc)],["simp-chinese-formal",O(Wt,Vc)],["trad-chinese-informal",O(Wt,Qi)],["trad-chinese-formal",O(Wt,Bc)],["cjk-ideographic",O(Wt,Qi)]]));var Nc=Wt,Dc,Mc,ea,_c,Uc,Jt=class Jt extends oe{constructor(t){super(t,O(Jt,Dc))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return O(Jt,ea)[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(Jt,Mc)[d]+O(Jt,ea)[h]}l?a!==0&&(o+=O(Jt,_c)):r!==0&&(o+=O(Jt,Uc))}return o}};Dc=new WeakMap,Mc=new WeakMap,ea=new WeakMap,_c=new WeakMap,Uc=new WeakMap,Z(Jt,Dc,{range:new B(new j([new pe(1),R("infinite")]),0),suffix:new B(new G("/ "),0)}),Z(Jt,Mc,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),Z(Jt,ea,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),Z(Jt,_c,"\u137B"),Z(Jt,Uc,"\u137C");var rf=Jt,we,Tc=class{constructor(){Z(this,we);ke(this,we,new Map),O(this,we).set("none",oe.createNone(O(this,we))),O(this,we).set("decimal",oe.createDecimal(O(this,we))),O(this,we).set("disc",oe.createDisc(O(this,we))),O(this,we).set("square",oe.createSquare(O(this,we))),O(this,we).set("circle",oe.createCircle(O(this,we))),O(this,we).set("disclosure-open",oe.createDisclosureOpen(O(this,we))),O(this,we).set("disclosure-closed",oe.createDisclosureClosed(O(this,we)));for(let t of oe.CHINESE_LONGHAND_NAMES)O(this,we).set(t,oe.createChineseLonghand(O(this,we),t));O(this,we).set("ethiopic-numeric",oe.createEthiopicNumeric(O(this,we)))}define(t,e){if(!$x(t))return null;let n=oe.create(O(this,we),e);return O(this,we).set(t,n),n}getStyle(t){var e;return(e=O(this,we).get(t))!=null?e:null}format(t,e){var n;return((n=this.getStyle(t))!=null?n:Mr(O(this,we))).format(e)}formatMarker(t,e){var n;return((n=this.getStyle(t))!=null?n:Mr(O(this,we))).formatMarker(e)}};we=new WeakMap;var na=class{constructor(t,e,n){p(this,"endStuckFixed");p(this,"endFixed");p(this,"endSlipped");this.endStuckFixed=t,this.endFixed=e,this.endSlipped=n}},lf=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 na(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 na(t,t,n))}}addSlippedRange(t){this.map.length==0?this.map.push(new na(t,0,0)):this.map[this.map.length-1].endFixed=t}slippedByFixed(t){let e=Mt(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=Mt(this.map.length,s=>t<=this.map[s].endSlipped),n=this.map[e];return n.endStuckFixed-(n.endSlipped-t)}};function mE(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}var cf=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");rt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=De(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ee(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");rt(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=xl(t,e,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==S.none&&!yo(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}},uf=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 cf(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=_l(n);s&&!ie(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!")}},sa=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 lf;let d=t.getElementOffset(this.root);this.lastOffset=d,this.boxStack=new uf(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 B(o,Vd))}}}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)cs(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&&!X(s)||o&&!X(o))&&(this.transferPropsToRoot(t,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let s=0;s<fb.length;s++)if(this.hasProp(t,this.validatorSet.layoutProps,fb[s])){this.transferPropsToRoot(t,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!e){let s=t["font-size"],o=!0;if(s&&!X(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*dt.lh/dt.em;break;default:{let u=dt[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&&!X(a.value)){let l=a.evaluate(this.context);if(l instanceof He)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=dt[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 wC(this.scope,this.validatorSet,this.xmldoc.url,e)}return{}}recordCounterSnapshot(t,e,n=[],s){let o={offset:t,counters:mE(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=Mt(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&&!X(u.value)&&u.value.toString();d&&d.toLowerCase()!=="auto"&&(this.cascade.firstPageType=d)}let a=te(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=Zg(u.evaluate(this.context,"flow-options"));a=!!b.exclusive,l=!!b.static,c=!!b.last}let d=e["flow-linger"];d&&(r=rd(d.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let h=e["flow-priority"];h&&(o=rd(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 Fl(t,b)}let m=new Vl(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]=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(;this.last;){let r=this.last.firstChild;if(r==null)for(;this.last;){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.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&&!X(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)}}return Number.POSITIVE_INFINITY}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){}},fb=["column-count","column-width","column-fill"];var Gs=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)}},hs=class{constructor(t,e){this.where=t;this.success=e;p(this,"what",-1)}};var Oo=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 Gs(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 hs(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 Gs(gb);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 hs(s,!0),a=new hs(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 Gs(gb);e.markAsStartAlternate(t),this.nodes.push(e);let n=new hs(0,!0),s=new hs(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 Gs(t));let n=new hs(e,!0),s=new hs(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]}},bE=1,Cb=2,bb=4,Bo=8,Hc=16,df=32,zc=64,yb=128,oa=256,ra=512,pf=1024,Sb=2048,xb=4096,Eb=8192,Gc=class extends Ut{constructor(){super()}validateForShorthand(t,e){let n=t[e].visit(this);return n?[n]:null}},Fe=class i extends Gc{constructor(e,n,s){super();this.allowed=e;this.idents=n;this.units=s}visitEmpty(e){return this.allowed&bE?e:null}visitSlash(e){return this.allowed&Sb?e:null}visitStr(e){return this.allowed&Cb?e:null}visitIdent(e){let n=this.idents[e.name.toLowerCase()];return n||(this.allowed&bb||this.allowed&zc&&CSS.supports("color",e.name)?e:null)}visitNumeric(e){return e.num==0&&!(this.allowed&ra)?e.unit=="%"&&this.allowed&pf?e:null:e.num<0&&!(this.allowed&oa)?null:this.units[e.unit]?e:null}visitNum(e){return e.num==0?this.allowed&ra?e:null:e.num<=0&&!(this.allowed&oa)?null:this.allowed&Hc?e:null}visitInt(e){if(e.num==0)return this.allowed&ra?e:null;if(e.num<=0&&!(this.allowed&oa))return null;if(this.allowed&(df|Hc))return e;let n=this.idents[`${e.num}`];return n||null}visitHexColor(e){return this.allowed&zc&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(e.hex)?e:null}visitURL(e){return this.allowed&yb?e:null}visitURange(e){return this.allowed&xb?e:null}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){if(this.allowed&zc){if(e.name==="device-cmyk"||e.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Qu(e)!==null?e:null;if(CSS.supports("color",e.toString()))return e}if(this.allowed&Eb){let n=e.visit(new sr);if(CSS.supports("background-image",n.toString()))return e}return e.name==="calc"&&this.allowed&(Bo|Hc|df|oa|ra|pf)?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)}},re=Object.create(null),gb=new Fe(0,re,re),ia=class extends Gc{constructor(e){super();p(this,"successTerminal");p(this,"failureTerminal");p(this,"first");this.successTerminal=new Gs(null),this.failureTerminal=new Gs(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 Do&&this instanceof Do){if(d=new j(e).visit(r.validator),d){a=e.length,r=r.success;continue}}else if(a==0&&!n&&r.validator instanceof aa&&this instanceof Do){if(d=new Te(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=this.validateList([e],!1,0);return n?n[0]:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Do=class extends ia{constructor(t){super(t)}visitSpaceList(t){let e=this.validateList(t.values,!1,0);return e===t.values?t:e?new j(e):null}visitCommaList(t){let e=this.first,n=!1;for(;e;){if(e.validator instanceof aa){n=!0;break}e=e.failure}if(n){let s=this.validateList(t.values,!1,0);return s===t.values?t:s?new Te(s):null}return null}validateForShorthand(t,e){return this.validateList(t,!0,e)}},aa=class extends ia{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 Te(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}},hf=class extends ia{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 pt(e.name,n):null}},Wc=class{tryParse(t,e,n){return e}success(t,e){}},$c=class extends Wc{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 j(o):o[0];return this.success(a,s),n+r}return n}success(e,n){n.values[this.name]=e}},ff=class extends $c{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}},gf=class extends Wc{constructor(e,n){super();this.nodes=e;this.slash=n}tryParse(e,n,s){let o=n;if(this.slash)if(e[n]==Kn){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}},la=class extends Ut{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 $c(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)}},Ws=class extends la{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}},Xc=class extends la{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 ff(this.validatorSet,this.propList)}},mf=class extends la{constructor(){super()}validateList(t){let e=t.length;for(let n=0;n<t.length;n++)if(t[n]===Kn){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}},Cf=class extends Ws{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 Te?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 Te(e[n]);return null}},bf=class extends Ws{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"])){let a=this.values["font-weight"],l=a instanceof pt&&a.name==="calc"?t.indexOf(a):-1;if(l>=0&&t[l].visit(o["font-size"]))delete this.values["font-weight"],e=l;else return this.error=!0,e}if(this.values["font-size"]=t[e++],t[e]===Kn){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 j(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 Te(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}},yf=class extends Ws{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)}},yE=["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"],Sf=class extends Ws{constructor(){super()}init(t,e){super.init(t,e);for(let n in this.validatorSet.validators)yE.includes(n)||this.propList.push(n)}validateList(t){return this.error=!0,0}},mb={SIMPLE:Ws,INSETS:Xc,INSETS_SLASH:mf,COMMA:Cf,FONT:bf,TEXT_SPACING:yf,ALL:Sf},SE=["initial-letter"],xf=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 Oo;if(t=="||"){for(let o=0;o<e.length;o++){let r=new Oo;r.startClause(o),r.addGroup(e[o],1),r.endClause(o),n.addGroup(r,o==0?1:4)}let s=new Oo;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 Oo;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 Oo;return e.addPrimitive(t),e}newFunc(t,e){let n;switch(t){case"COMMA":n=new aa(e);break;case"SPACE":n=new Do(e);break;default:n=new hf(t.toLowerCase(),e);break}return this.primitive(n)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Fe(zc,re,re)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Fe(Eb,re,re)),this.namedValidators.POS_INT=this.primitive(new Fe(df,re,re)),this.namedValidators.POS_NUM=this.primitive(new Fe(Hc,re,re)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Fe(Bo,re,{"%":$})),this.namedValidators.NEGATIVE=this.primitive(new Fe(oa,re,re)),this.namedValidators.ZERO=this.primitive(new Fe(ra,re,re)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Fe(pf,re,re)),this.namedValidators.POS_LENGTH=this.primitive(new Fe(Bo,re,{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(Bo,re,{deg:$,grad:$,rad:$,turn:$})),this.namedValidators.POS_TIME=this.primitive(new Fe(Bo,re,{s:$,ms:$})),this.namedValidators.FREQUENCY=this.primitive(new Fe(Bo,re,{Hz:$,kHz:$})),this.namedValidators.RESOLUTION=this.primitive(new Fe(Bo,re,{dpi:$,dpcm:$,dppx:$})),this.namedValidators.URI=this.primitive(new Fe(yb,re,re)),this.namedValidators.URANGE=this.primitive(new Fe(xb,re,re)),this.namedValidators.IDENT=this.primitive(new Fe(bb,re,re)),this.namedValidators.STRING=this.primitive(new Fe(Cb,re,re)),this.namedValidators.SLASH=this.primitive(new Fe(Sb,re,re));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,re)))}a=!1;break;case 5:{let h={};h[`${d.num}`]=new pe(d.num),n.push(this.primitive(new Fe(0,h,re))),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 Do(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 He(s.num));break;case 5:n.push(new pe(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 j(n):n[0]}}parseShorthands(t){for(;;){let e=this.readNameAndPrefixes(t,3);if(!e)return;let n=t.nthToken(1),s;n.type==1&&mb[n.text]?(s=new mb[n.text],t.consume()):s=new Ws,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 Xc){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 gf(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 Ze(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(Ht(t)||o==="font-face"||xE(e)){s.simpleProperty(t,e,n);return}if(o==="counter-style"){ab(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&&!Mu.includes(`-${r}-`)||s.unknownProperty(a,e);return}else if(SE.includes(t)&&!Object.keys(c).some(d=>Kr(d?`-${d}-`:"",t))){s.unknownProperty(a,e);return}let u=this.validators[t];if(u){let d=X(e)||e.isExpr()?e:e.visit(u);d?s.simpleProperty(t,d,n):!r&&CSS.supports(t,e.toString())?s.simpleProperty(t,e,n):s.invalidPropertyValue(a,e)}else{let d=this.shorthands[t].clone();X(e)?d.propagateDefaultingValue(e,n,s):(e.visit(d),d.finish(n,s)||s.invalidPropertyValue(a,e))}}};function vf(){let i=new xf;return i.initBuiltInValidators(),i.parse(wd),i}var Ef=class extends Ut{constructor(){super(...arguments);p(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function xE(i){let t=new Ef;return i.visit(t),t.varFound}var zN=`OTTO${new Date().valueOf()}`;function Nf(i){return Object.keys(i).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function vE(i){let t=new ut;for(let e of Nf(i))t.append(`${e}:${i[e].toString()};`);return t.toString()}function Nb(i,t){let e={};for(let n in i)e[n]=te(i,n).evaluate(t,n);return e}var ca=class{constructor(t){this.properties=t;p(this,"fontTraitKey");p(this,"src");p(this,"blobURLs",[]);p(this,"blobs",[]);p(this,"family");this.fontTraitKey=vE(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 ut;n.append(`@font-face {
1845
1869
  font-family: `),n.append(this.family),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(`;
1870
+ `);for(let s of Nf(this.properties))n.append(s),n.append(": "),this.properties[s].appendTo(n,!0),n.append(`;
1871
+ `);if(e){n.append('src: url("');let s=gm(e);n.append(s),this.blobURLs.push(s),this.blobs.push(e),n.append('")')}else n.append("src: "),n.append(t);return n.append(`;
1848
1872
  }
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=`
1873
+ `),n.toString()}},jc=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 Te){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 Te(n)}else{let e=this.familyMap[t.stringValue()];return e?new Te([R(e),t]):t}}},Yc=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 Nf(t.properties))r[u]=t.properties[u];let a=this.getViewFontFamily(t,n);r["font-family"]=R(a);let l=new ca(r),c=this.head.ownerDocument.createElement("style");return c.textContent=l.makeAtRule(o,e),this.head.appendChild(c),D.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),D.debug("Found already-loaded font:",n)}):(o=new Fn(()=>{let r=I("loadFont"),a=n.replace(/^url\("([^"]+)"\).*$/,"$1"),l=e.deobfuscator?e.deobfuscator(a):null;return l?go(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){D.warn("E_FONT_FACE_INVALID");continue}n.push(this.loadFont(s,e))}return bn(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 vn=!0;function Pb(i){vn=i}var Mo=[];function wb(i,t){return i===t||(i.src||t.src?i.src===t.src:i.textContent===t.textContent)}function kb(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 qc(i,t,e){if(!vn)return w(!1);if(!(e!=null&&e.inHead)&&!(e!=null&&e.atEnd)&&kb(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(Tf(t)||(t.onload=null),c)return Mo.some(d=>wb(d,i))||Mo.push(i),w(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&wb(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(D.debug("script:",s),s){let d=ft(u);return t.document.head.appendChild(u),bn([d])}else return t.document.head.appendChild(u),w(!0)}function NE(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 Ao)n(r.style);else if(r instanceof is||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 TE(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=NE(i,e),n.textContent=i.documentElement.textContent,t.document.body.appendChild(n),n}function Ab(i,t,e){if(!vn)return w(!1);let n=kb(i);if(n.length===0)return w(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),o=s?TE(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 qc(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Mo.push(u),l=!0),n.length===0&&s&&(D.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),w(!0)))}).then(()=>{o&&o.remove(),c.finish(!0)}),c.result()}function Rb(i){if(!vn)return w(!1);let t=I("loadScripts");return t.loop(()=>Mo.length===0?w(!1):qc(Mo.shift(),i,{atEnd:!0}).thenReturn(Mo.length>0)).then(()=>{D.debug("dispatchEvent: DOMContentLoaded (window)"),i.dispatchEvent(new Event("DOMContentLoaded")),D.debug("dispatchEvent: load (window)"),i.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Tf(i){return vn?Mo.length>0||!!i.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var wE=i=>String(i).replace(/[\u0000-\u001F"\\\u2028\u2029]/g,Ba),PE=i=>`"${wE(i)}"`,Pf=(i,t,e)=>PE(e.transformURL(Qn(String(i)),t)),Lb=(i,t,e)=>i.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url(${Pf(s,t,e)}`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url(${Pf(s,t,e)}`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${Pf(s,t,e)}`);var AE={},RE=new Set(["base","body","head","html","link","meta","script","style","title"]);function LE(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 ms{constructor(e,n,s,o,r,a,l,c,u,d,h,f,g,m,b,x=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=x;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"||!vt(e)||!cp(e,this.xmldoc.url,o=>this.xmldoc.getElementOffset(o),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized))return;let n=e.getAttribute(Ir);if(!n)return;let s=lp(e,this.xmldoc.url,o=>this.xmldoc.getElement(o));s&&s.setAttribute(Ir,n)}createPseudoelementShadow(e,n,s,o,r,a,l,c){var x,C;let u=this.getPseudoMap(s,this.regionIds,this.isFootnote,this.nodeContext,a);if(!u)return c;let d=[],h=Lo.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=h,g=vt(e)&&!!u["footnote-call"]&&rt((x=u["footnote-call"].content)==null?void 0:x.value);for(let v of _C){let y;if(v){if(!u[v])continue;let N=at(e),E=e.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&e.localName==="include"&&e.classList.contains("-vivliostyle-footnote-content");if(v=="footnote-call"&&!vt(e)||v=="footnote-marker"&&!(N||E||n&&this.isFootnote)&&!((C=this.nodeContext)!=null&&C.pluginProps.nestedFootnoteDetached))continue;if(v.match(/^first-/)){let T=o.display;if(!T||T===S.inline)continue;let k=e.firstElementChild;if(k&&ie(k.previousSibling)){let L=r.getStyle(k,!1);if(L){let V=te(L,"display");if(V!=null&&V.value&&V.value!==S.inline)continue}}}if(v==="before"||v==="after"||v==="footnote-call"||v==="footnote-marker"){let T=u[v].content,k=(v==="before"||v==="after")&&(o.float===S.footnote||N||E)&&!!T;if(!T||!rt(T.value)&&!k)continue}d.push(v),y=Lo.createElementNS("http://www.w3.org/1999/xhtml","span"),Io(y,v)}else{if(g)continue;y=Lo.createElementNS("http://www.pyroxy.com/ns/shadow","content")}f.appendChild(y),v.match(/^first-/)&&(f=y)}if(!d.length)return c;let m=new Vr(e,s,r,a,this.exprContentListener),b=new Vs(e,h,null,l,c,ot.ROOTLESS,m);return c||b}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]={};Fr(u,a[c],r),sc(u,r,a[c]),ph(a[c],n,s,(d,h)=>{Fr(u,h,r),dh(h,f=>{Fr(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 Vs(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 Ae||d===S.footnote)if(d!==S.footnote||cp(e,this.xmldoc.url,f=>this.xmldoc.getElementOffset(f),this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)){let f=d instanceof Ae?d.url:ne("user-agent.xml#footnote",un);h=this.createRefShadow(f,ot.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"),x=null;b?x=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"),x=l.parentShadow?l.parentShadow.xmldoc:this.xmldoc),b&&(b=Js(b,x.url),g=this.createRefShadow(b,ot.ROOTED,e,l,f))}g==null&&(g=w(f));let m=null;g.then(b=>{if(o.display===S.table_cell){let x=ne("user-agent.xml#table-cell",un);m=this.createRefShadow(x,ot.ROOTLESS,e,l,b)}else m=w(b);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=Bi(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=cc(a,r,e);let u=!l&&e!==c;n=uc(a,r,n);let d=(C,v)=>{let y;u&&(e?/^(min-|max-)?(height|inline-size)$/.test(C)&&(y=r.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(C)&&(y=r.pageAreaWidth));let N=v.evaluate(r,C,y,e);return C=="font-family"&&(N=this.docFaces.filterFontFamily(N)),N},h=!!new xe(r.style.pageScope,"left-page").evaluate(r);if(dc(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(yo(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=Dd(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 x=l==null?void 0:l.owner;if(x instanceof Element&&vt(x)){let C=x.getAttribute("href")||x.getAttributeNS("http://www.w3.org/1999/xlink","href");if(C){let v=Js(C,this.xmldoc.url),y=this.xmldoc.getElement(v);y&&at(y)&&((b=y.parentNode)==null?void 0:b.nodeType)===1&&(n=y.parentNode,l=null)}}}let c=-1;for(;n&&n.nodeType==1;){let x=l&&l.root==n,C=!!x&&l.type==ot.ROOTED&&at(n);if(!x||l.type==ot.ROOTLESS||C){let y=(l?l.styler:this.styler).getStyle(n,!1);s.push(y),o=o||Zr(n)}x&&!C?(n=l.owner,l=l.parentShadow):(n=n.parentNode,c++)}let u=new Set;if(s.length>0){let x=s[0],C=Bi(x,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let v in C){if(!cs(v))continue;let y=C[v].evaluate(this.context,v);y&&y!==S.inherit&&y!==S.unset&&y!==S.revert&&y!==$&&u.add(v)}}let d=c===0,h=this.context.queryUnitSize("em",d),f={"font-size":new B(new A(h,"px"),0)};d&&(f["line-height"]=new B(new He(this.context.pref.lineHeight),0));let g=new Yl(f,this.context);for(let x=s.length-1;x>=0;--x){let C=s[x],v=[];for(let E in C)cs(E)&&v.push(E);v.sort(Zu);let y,N;for(let E of v){if(x>0&&a&&E.startsWith("--viv-marker-")||x>0&&u.has(E))continue;g.setPropName(E);let T=te(C,E),k=T;if(T.value===S.initial)delete f[E];else if(!X(T.value)){if(E==="font-size"&&x===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)k=new B(new A(this.context.rootFontSize,"px"),T.priority);else if(E==="line-height"&&x===s.length-1&&this.context.rootLineHeight&&T.value instanceof A&&(T.value.unit==="lh"||T.value.unit==="rlh"))k=new B(new A(this.context.rootLineHeight,"px"),T.priority);else if(x===0&&T.value instanceof A&&T.value.unit==="lh"){let L=this.getLineHeightUnitSize(E,y,N);L!=null&&(k=new B(new A(T.value.num*L,"px"),T.priority))}else Ht(E)||(k=T.filterValue(g));E==="font-size"?y=k.value:E==="line-height"&&(N=k.value),f[E]=k}}}for(let x in e)cs(x)||(f[x]=e[x]);return{lang:o,elementStyle:f}}resolveURL(e){return e=ne(e,this.xmldoc.url),this.fallbackMap[e]||e}inheritLangAttribute(){this.nodeContext.lang=Zr(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(e){let n=yC().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(X(r))r===S.initial&&(s[o]=void 0);else if(r instanceof pe)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*dt[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=nt("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 v,y;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 N=this.xmldoc.getElementOffset(r);Ms.registerFragmentIndex(N,this.nodeContext.fragmentIndex,0)}let c={},u={getStyle:N=>this.styler.getStyle(N,!1),getProp:(N,E)=>N?te(N,E):null,getStyleMap:(N,E)=>lt(N,E),getMutableStyleMap:(N,E)=>Kt(N,E),createCascadeValue:(N,E)=>new B(N,E),filterFootnoteMarkerContent:(N,E)=>N.filterValue(new as(this.styler.cascade,E,this.styler.cascade.counterResolver,"footnote-marker")).value};if(!this.nodeContext.parent){let N=this.inheritFromSourceParent(l);l=N.elementStyle,this.nodeContext.lang=N.lang}let d=l.position,h=l.float,f=l["float-reference"],g=h&&!X(h.value)&&h.value!==S.none&&f&&!X(f.value)?lC(f.value.toString()):null,m=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===ot.ROOTED&&at(r);if(this.nodeContext.parent&&(yo(d==null?void 0:d.value)||g&&xn(g)||m)){let N=this.inheritFromSourceParent(l);l=N.elementStyle,this.nodeContext.lang=N.lang}l=cC(r,l,this.nodeContext.shadowContext,this.xmldoc.url,N=>this.xmldoc.getElement(N),Ir,u),l=uC(r,l,this.nodeContext.shadowContext,this.context,u),this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,c),g&&xn(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 qc(r,this.viewport.window).thenFinish(o),o.result();let x=c.display;if(at(r)&&!m&&r.hasAttribute(ip)&&(x=c.display=S.none),X(x)&&(x===S.initial||x===S.unset?x=S.inline:x===S.inherit?x=((v=this.nodeContext.parent)==null?void 0:v.display)&&R((y=this.nodeContext.parent)==null?void 0:y.display):x=null),x===S.none)return o.finish(!1),o.result();let C=this.nodeContext.parent==null;return this.nodeContext.flexContainer=x===S.flex,this.createShadows(r,C,l,c,a,this.context,this.nodeContext.shadowContext).then(N=>{var ug;this.nodeContext.nodeShadow=N;let E=c.position,T=c.float,k=c.clear,L=this.nodeContext.vertical?S.vertical_rl:S.horizontal_tb,V=this.nodeContext.parent?this.nodeContext.parent.vertical?S.vertical_rl:S.horizontal_tb:L,W=Nm(r),J=c["column-count"],ee=c["column-width"],ve=J&&J!==S.auto&&!X(J)||ee&&ee!==S.auto&&!X(ee);this.nodeContext.establishesBFC=wm(x,E,T,c.overflow,L,V,ve||W),this.nodeContext.containingBlockForAbsolute=Pm(E),this.nodeContext.isInsideBFC()&&T!==S.footnote&&!(g&&xn(g))&&(T=null,k=null);let le=null,F=!1,H=this.isFootnote&&(!((ug=this.nodeContext)!=null&&ug.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached||m),Y=dC(r,this.nodeContext.shadowContext,u);hC(Y.sourceStyle,c,this.context),le=Y.footnoteDisplay;let z=T instanceof j||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"],H){z=!1;let M=le==null?void 0:le.toString();M&&(c["--viv-footnote-display"]=R(M)),x=F?R("list-item"):M==="inline"||M==="compact"?S.inline:S.block,c.display=x}else c.display=S.inline;if(H&&at(r)){F=F||!!c["--viv-marker-content"];let M=le==null?void 0:le.toString();M&&(c["--viv-footnote-display"]=R(M)),F&&(x=c.display=R("list-item")),!F&&(M==="inline"||M==="compact")&&(x=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,(z||c.display&&c.display!=S.inline)&&(this.nodeContext.clearSide=k.toString())));let U=So(x)&&!!(c["ua-list-item-count"]||c["--viv-marker-content"]),q=c["break-inside"];(z||q&&!X(q)&&q!==S.auto)&&this.nodeContext.breakPenalty++,x&&x!==S.inline&&kt(x)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!z&&!x||kt(x)||vl(x),this.nodeContext.display=x?x.toString():"inline",this.nodeContext.floatSide=z?T.toString():null,this.nodeContext.floatReference=g||he.INLINE;let Ne=c["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=Ne&&!X(Ne)?Ne:null;let Ve=this.isInsideNonRootMultiColumn(),Ho=c["column-span"];if(this.nodeContext.columnSpan=!Ve&&Ho&&!X(Ho)?Ho:null,!this.nodeContext.inline){let M=c["break-after"];M&&!X(M)&&!(Ve&&M===S.column)&&(this.nodeContext.breakAfter=M.toString(),Al[this.nodeContext.breakAfter]&&(c["break-after"]=S.column));let Bt=c["break-before"];Bt&&!X(Bt)&&!(Ve&&Bt===S.column)&&(this.nodeContext.breakBefore=Bt.toString(),Al[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete c["break-before"]:c["break-before"]=S.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let en=c.page,Ot=en&&!X(en)&&en.toString();!Ot&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||x===S.table_header_group||x===S.table_footer_group)&&(Ot=this.styler.cascade.currentPageType),!Ot||Ot.toLowerCase()==="auto"?Ot=this.nodeContext.pageType:this.nodeContext.pageType=Ot,this.styler.cascade.currentPageType!==Ot&&!(!Ot&&c.position===S.fixed)&&(this.nodeContext.fragmentIndex===1&&!ns(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),Ot!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=Ot)}this.nodeContext.captionSide=c["caption-side"]&&c["caption-side"].toString()||"top";let Wr=c["border-collapse"];if(!Wr||Wr===R("separate")){let M=c["border-spacing"],Bt,en;M&&(M instanceof j?(Bt=M.values[0],en=M.values[1]):Bt=en=M,Bt.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Ke(Bt,this.context)),en.isNumeric()&&(this.nodeContext.blockBorderSpacing=Ke(en,this.context)))}let gs=c["footnote-policy"]||Y.footnotePolicy;gs&&!X(gs)&&(c["--viv-footnote-policy"]=gs),this.nodeContext.footnotePolicy=gs&&!X(gs)?gs:null;let wa=c["x-first-pseudo"];if(wa){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Bl(M,wa.num)}this.nodeContext.inline||this.processAfterIfcontinues(r,l,a,this.context);let Tn=c["white-space"];if(Tn){let M=_l(Tn.toString());M!==null&&(this.nodeContext.whitespace=M)}let xu=c["hyphenate-character"];xu&&xu instanceof G&&(this.nodeContext.hyphenateCharacter=xu.str);let ty=c["word-break"],ny=c["line-break"],cg=c["overflow-wrap"];(ty===S.break_all||ny===S.anywhere||cg===S.break_word||cg===S.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,e,x,E,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 qs=!1,Eu=null,$r=[],$t=r.namespaceURI,ge=r.localName,Pa=ge;$t=="http://www.w3.org/1999/xhtml"?(RE.has(ge)?ge="div":ge=="vide_"?ge="video":ge=="audi_"?ge="audio":ge=="object"&&(qs=!!this.customRenderer),r.hasAttribute(pc)&&r.hasAttribute("src")&&c.content instanceof Ae&&(ge="img")):$t=="http://www.idpf.org/2007/ops"?(ge="span",$t="http://www.w3.org/1999/xhtml"):$t=="http://www.pyroxy.com/ns/shadow"?($t="http://www.w3.org/1999/xhtml",ge=this.nodeContext.inline?"span":"div"):qs=!!this.customRenderer,U?e?(ge="li",c["--viv-marker-content"]&&(c["list-style-type"]=S.none,c["list-style-image"]=S.none)):(x=kt(x)?S.inline:S.block,c.display=x,ge="div"):ge=="body"||ge=="li"?ge="div":ge=="q"&&(ge="span"),c.behavior&&c.behavior.toString()!="none"&&this.customRenderer&&(qs=!0),r.dataset&&r.getAttribute("data-math-typeset")==="true"&&(qs=!0);let vu;if(qs){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;vu=this.customRenderer(r,M,c)}else vu=w(null);vu.then(M=>{var hg,fg,gg,mg,Cg;if(M)qs&&(s=M.getAttribute("data-adapt-process-children")=="true");else if(c.display===S.none){o.finish(!1);return}else M=this.createElement($t,ge);if(!C&&ve&&c["column-fill"]===S.auto){let _e=this.nodeContext.vertical?c.width:c.height;(!_e||_e===S.auto||X(_e))&&(M.setAttribute("data-viv-saved-column-fill","auto"),c["column-fill"]=S.balance)}ge!=Pa&&(M.setAttribute("data-vivliostyle-original-tag",Pa),(Pa==="html"||Pa==="body")&&(M.role="presentation")),ge=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),Eu&&(this.applyPseudoelementStyle(this.nodeContext,"inner",Eu),M.appendChild(Eu)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&LE(M);let Bt=this.nodeContext.inheritedProps["image-resolution"],en=[],Ot=c.width,Nu=c.height,sy=r.getAttribute("width"),oy=r.getAttribute("height"),Tu=Ot===S.auto||!Ot&&!sy,wu=Nu===S.auto||!Nu&&!oy,dg=r.attributes,ry=dg.length,Xr=null,pg=null;x===S.table_cell&&((gg=(fg=(hg=this.nodeContext.parent)==null?void 0:hg.viewNode)==null?void 0:fg.lastElementChild)==null?void 0:gg.localName)==="a"&&M.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let _e=0;_e<ry;_e++){let Dt=dg[_e],mt=Dt.namespaceURI,ce=Dt.localName,ue=Dt.nodeValue;if(mt){if(mt=="http://www.w3.org/2000/xmlns/")continue;mt=="http://www.w3.org/1999/xlink"&&ce=="href"&&(ue=this.documentURLTransformer.transformURL(this.resolveURL(ue),this.xmldoc.url))}else{if(!vn&&ce.match(/^on/)||ce=="style")continue;if(ce==="media"&&ge==="source"&&$t==="http://www.w3.org/1999/xhtml"&&((mg=r.parentElement)==null?void 0:mg.localName)==="picture")try{let tt=this.context.rootScope,$e=new Co(tt),Aa=new Ze(ue,$e),bg=Od(Aa,$e,"");if(bg){if(bg.toExpr().evaluate(this.context))continue;ue="not all"}}catch(tt){}if((ce=="id"||ce=="name")&&e){let tt=this.documentURLTransformer.transformFragment(ue,this.xmldoc.url);M.setAttribute(ce,ue),M.setAttribute("data-vivliostyle-id",tt);let $e=M.ownerDocument.createElement("a");$e.setAttribute(ce,tt),$e.setAttribute(Bn,"1"),$e.style.position="absolute",M.appendChild($e),this.page.registerElementWithId(M,tt);continue}if(ce=="src"||ce=="href"||ce=="poster")ue=this.resolveURL(ue),ce==="href"?ue=this.documentURLTransformer.transformURL(ue,this.xmldoc.url):ue=Cs(ue),ce==="src"&&(ue=Ou(ue));else if(ce=="srcset")ue=ue.split(",").map(tt=>{let $e=tt.trim().split(/\s+/),Aa=Cs(this.resolveURL($e[0]));return $e.length>1?`${Aa} ${$e.slice(1).join(" ")}`:Aa}).join(",");else if(ce==="data"&&qs&&ge==="object"&&M.hasAttribute("data"))continue;if(ce==="poster"&&ge==="video"&&$t==="http://www.w3.org/1999/xhtml"){let tt=new Image,$e=ft(tt,ue);Tu&&wu?($r.push($e),en.push({image:tt,element:M,fetcher:$e})):this.page.fetchers.push($e)}}if($t=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ce)&&(ce=ce.toLowerCase()),this.isSVGUrlAttribute(ce)&&(ue=Lb(ue,this.xmldoc.url,this.documentURLTransformer)),mt){let tt=AE[mt];tt&&(ce=`${tt}:${ce}`)}if(ce=="src"&&!mt&&(ge=="img"||ge=="input")&&$t=="http://www.w3.org/1999/xhtml")Xr=ue;else if(ce=="alt"&&!mt&&ge=="img"&&$t=="http://www.w3.org/1999/xhtml")pg=ue;else if(ce=="href"&&ge=="image"&&$t=="http://www.w3.org/2000/svg"&&(mt=="http://www.w3.org/1999/xlink"||!mt))mt||M.setAttribute(ce,ue),this.page.fetchers.push(ft(M,ue));else if(mt)M.setAttributeNS(mt,ce,ue);else try{M.setAttribute(ce,ue)}catch(tt){D.warn(tt)}}if(Xr){let _e=ge==="input"?new Image:M,Dt=ft(_e,Xr,pg);_e!==M&&(M.src=Xr);let mt=()=>{var ue,tt;if(c.position===S.fixed)return!0;for(let $e=(ue=this.nodeContext.parent)==null?void 0:ue.viewNode;$e&&$e!==this.viewRoot;$e=$e.parentElement)if(((tt=$e.style)==null?void 0:tt.position)==="fixed")return!0;return!1};!Tu&&!wu&&!(()=>{let ue=this.nodeContext.vertical?Ot:Nu;return ue instanceof A&&ue.unit==="%"})()&&!mt()?this.page.fetchers.push(Dt):(Tu&&wu&&Bt&&Bt!==1&&en.push({image:_e,element:M,fetcher:Dt}),$r.push(Dt))}else!Xr&&ge==="img"&&$t==="http://www.w3.org/1999/xhtml"&&(M.srcset||((Cg=r.parentElement)==null?void 0:Cg.localName)==="picture")&&this.page.fetchers.push(ft(M));delete c.content;let ka=c["--viv-marker-content"];if(ka){let _e=ka instanceof j?ka.values:[ka];for(let Dt of _e)Dt instanceof Ae&&Dt.url&&$r.push(ft(new Image,Dt.url))}if(M.localName==="object"&&M.namespaceURI==="http://www.w3.org/1999/xhtml"&&M.hasAttribute("data")&&this.page.fetchers.push(ft(M)),M.localName==="embed"&&M.namespaceURI==="http://www.w3.org/1999/xhtml"&&M.hasAttribute("src")&&this.page.fetchers.push(ft(M)),M.localName==="iframe"&&M.namespaceURI==="http://www.w3.org/1999/xhtml"&&M.hasAttribute("src")){let _e=M;_e.loading==="lazy"&&(_e.loading="eager"),this.page.fetchers.push(ft(M))}if(this.preprocessElementStyle(c),this.applyComputedStyles(M,c),this.nodeContext.inline)e||(xt(M,"inline-start"),As(M)&&xt(M,"clone"));else if(e){if(!mr(c.position)){let _e=c["margin-break"],Dt=this.getBreakTypeAt(this.nodeContext),mt=Dt!==null,ce=Dt==="auto";(_e===S.discard&&mt||_e!==S.keep&&ce&&!this.nodeContext.floatSide)&&kl(M,"block-start")}}else{let _e=this.nodeContext.vertical?"width":"height";dn(M,_e)&&P(M,_e,this.nodeContext.display==="table-row"?"0.01px":""),xt(M,"block-start"),As(M)&&xt(M,"clone"),kl(M,"block-start")}U&&c["ua-list-item-count"]&&M.setAttribute("value",c["ua-list-item-count"].stringValue()),this.viewNode=M,$r.length?bn($r).then(()=>{Bt>0&&this.modifyElemDimensionWithImageResolution(en,Bt,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&&(ie(o,s.parent.whitespace)||St(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&&Eo(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&&(ie(g,c.parent.whitespace)||!c.floatSide&&St(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 Vr(e,n,s,o,this.exprContentListener);this.nodeContext.afterIfContinues=new hc(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+=Ke(s["border-left-width"],this.context)),s["border-right-style"]!==S.none&&(l+=Ke(s["border-right-width"],this.context)),s["border-top-style"]!==S.none&&(c+=Ke(s["border-top-width"],this.context)),s["border-bottom-style"]!==S.none&&(c+=Ke(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,Ke(f,this.context))}px`):g.unit!=="%"?P(u,"max-height",`${Math.min(c,Ke(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}else if(n<1){let d=s["min-width"]||be,h=s["min-height"]||be;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,Ke(f,this.context))}px`):g.unit!=="%"?P(u,"min-height",`${Math.max(c,Ke(g,this.context))}px`):o?P(u,"height",`${c}px`):P(u,"width",`${l}px`)}}}})}preprocessElementStyle(e){nt("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 En&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let l=this.nodeContext.parent,c=l&&l.formattingContext;this.nodeContext.formattingContext=new En(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||X(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=Jd(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=nt("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=Zm(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&&Zt(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&&ie(this.viewNode))&&!d.hasChildNodes()&&Xd(d).includes("block-start")&&xt(d,"text-start"),d.appendChild(this.viewNode),Im(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==ot.ROOTLESS&&(r=r.firstChild)):(r=s.owner.firstChild,a=ot.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 os(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!=ot.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==ot.ROOTLESS&&(o=o.firstChild),o){let r=new os(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 os(s,e,n));if(e.sourceNode.nodeType!=1){let o=Jd(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 Zt(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&&at(n)}insertFootnoteCall(e){var l,c;let n=I("insertFootnoteCall"),s=Lo.createElementNS("http://www.w3.org/1999/xhtml","span");Io(s,"footnote-call");let o=this.xmldoc.getElementOffset(e.sourceNode);s.setAttribute($s.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let r=new os(s,e.parent,e.boxOffset);r.inline=!0;let a=new Vr(e.sourceNode,this.styler.getStyle(e.sourceNode,!1),this.styler,this.context,this.exprContentListener);return r.shadowContext=new Vs(e.sourceNode,s,null,((l=e.parent)==null?void 0:l.shadowContext)||null,null,ot.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){_r(e,this.page)}applyComputedStyles(e,n){var x,C,v;let s=n["background-image"];s&&this.addImageFetchers(s);let o=n["border-image-source"];o&&this.addImageFetchers(o);let r=n["list-style-image"];r&&this.addImageFetchers(r);let a=n["mask-image"];a&&this.addImageFetchers(a);let l=n["clip-path"];l&&this.addImageFetchers(l);let c=n.filter;c&&this.addImageFetchers(c);let u=n["shape-outside"];u&&this.addImageFetchers(u);let d=n["--viv-marker-content"];d&&this.addImageFetchers(d);let h=n.position===S.relative,f=((x=this.nodeContext)==null?void 0:x.parent)===null&&((C=this.sourceNode)==null?void 0:C.parentElement)===null&&!!((v=this.viewRoot)!=null&&v.parentElement),g=Object.keys(n);g.sort(Zu);let m,b;for(let y of g){if(IE[y])continue;let N=n[y];if(!(!N||N===$&&!Ht(y))){if(N=N.visit(new ul(this.xmldoc.url,this.documentURLTransformer)),N instanceof A)if(N.unit==="em"){let E=this.getEmUnitSize(y,m);E!=null&&(N=new A(N.num*E,"px"))}else if(N.unit==="lh"){let E=this.getLineHeightUnitSize(y,m,b);E!=null&&(N=new A(N.num*E,"px"))}else Qa(N.unit)&&(N=tl(N,this.context));if((y==="font-size"||y==="line-height")&&(y==="font-size"?m=N:b=N,this.viewport.layoutUnitAdj&&N instanceof A&&N.unit!=="%"&&N.unit!=="em"&&N.unit!=="lh"&&(N=new Rn(`calc(${N.toString()} - var(--viv-layoutUnitAdj))`))),tC[y]||h&&nC[y]){this.page.delayedItems.push(new Fs(e,y,N));continue}f&&this.page.pageAreaElement&&cs(y)?(P(this.page.pageAreaElement.parentElement.parentElement,y,N.toString()),y!=="writing-mode"&&y!=="direction"&&P(this.viewport.layoutBox,y,N.toString())):P(e,y,N.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 He||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=ac(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=ac(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=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;rt(u)&&(u.visit(new Mn(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&&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 os(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=lt(this.cascadedPageStyle,ua);f&&f.area&&(a=f.area)}let l=lt(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=!!te(g,"display"),b={},x=this.createElement("http://www.w3.org/1999/xhtml","span");Io(x,"before"),s.appendChild(x),this.computeStyle(e,n,g,b),m||(b.display=S.block);let C=te(g,"content");if(C){let y=((h=this.sourceNode)==null?void 0:h.nodeType)===1?this.sourceNode:this.xmldoc.root;b.content=C.filterValue(new as(this.styler.cascade,y,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let v=b.content;if(rt(v)){v.visit(new Mn(x,this.context,v,this.exprContentListener));let y=x.querySelectorAll("img[src]");for(let E=0;E<y.length;E++){let T=y[E],k=T.getAttribute("src");if(!k)continue;let L=ft(T,k);r.push(L),this.page.fetchers.push(L)}let N=x.getAttribute("src");if(N){let E=x.querySelector("img");E||(E=this.document.createElement("img"),E.setAttribute("src",N),x.appendChild(E));let T=ft(E,N);r.push(T),this.page.fetchers.push(T)}}delete b.content,this.applyComputedStyles(x,b)}}finally{this.computedStyleParentFontSizeOverride=u,this.computedStyleParentLineHeightOverride=d}return r.length?bn(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=te(this.styler.getStyle(c,!1),"display"))==null?void 0:a.value.toString();s=u&&!kt(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(xt(u,"inline-end"),As(u)){let d=c.vertical?u.offsetWidth:u.offsetHeight;xt(u,"clone"),(c.vertical?u.offsetWidth:u.offsetHeight)>d&&this.fixClonedBoxDecorationOverflow(u)}}else{let d=this.nodeContext.vertical?"width":"height";if(dn(u,d)&&P(u,d,""),xt(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?jd(f,["block-start","text-start","block-end","text-end","justify"]):(xt(u,"text-end"),xt(u,"justify")):xt(u,"text-end")}else xt(u,"text-end")}As(u)&&xt(u,"clone"),kl(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"||kn[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&&ie(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(Bn)){let u=r.previousElementSibling;return u&&(u.nextSibling===r||u.nextSibling===r.previousSibling&&ie(u.nextSibling))?n(u):!1}return!(!a||kt(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&&ie(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(Ig(r)){let a=n;for(;a&&a.nodeType!==1;)a=a.parentNode;let l=parseFloat(s.getElementComputedStyle(a)["font-size"]);return this.context,ic(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&&Zt(s)===Zt(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!!Zt(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 Kc=$s,IE={"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},Zc=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}},fs=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),Wo){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)}};function _r(i,t){if(i instanceof Te)for(let e of i.values)_r(e,t);else if(i instanceof Ae){let e=Cs(i.url);t.fetchers.push(ft(new Image,e))}else if(i instanceof pt)for(let e of i.values)_r(e,t);else if(i instanceof j)for(let e of i.values)_r(e,t)}var FE=1,Ur=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${FE++}`,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})}},Jc=class extends Ur{constructor(t){super(t,null,null,[],null),this.specified.width=new B(Ss,0),this.specified.height=new B(xs,0)}},eu=class extends to{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}}},Hr=class i extends Ur{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 eu||(this._scope=new eu(e,this)),this.pageMaster=this,this.specified.width=new B(Ss,0),this.specified.height=new B(xs,0),this.specified["wrap-flow"]=new B(S.auto,0),this.specified.position=new B(S.relative,0),this.specified.overflow=new B(S.visible,0)}createInstance(e){return new _o(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}},tu=class i extends Ur{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 B(S.auto,0)}createInstance(t){return new kf(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}},Xs=class i extends Ur{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 VE(i,t,e){return!t||X(t)?new Pe(i,e):t.toExpr(i,i.zero)}function me(i,t,e){return!t||t===S.auto||X(t)?null:t.toExpr(i,e)}function BE(i,t,e){return!t||t===S.normal||X(t)?null:t.toExpr(i,e)}function Vt(i,t,e){return!t||t===S.auto||X(t)?i.zero:t.toExpr(i,e)}function Rf(i,t,e){return!t||X(t)?i.zero:t===S.auto?null:t.toExpr(i,e)}function Nn(i,t,e,n){return!t||e===S.none||X(t)?i.zero:t.toExpr(i,n)}function Mb(i,t,e){return!t||X(t)?e:t===S._true?i._true:t===S._false?i._false:t.toExpr(i,i.zero)}var zr=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?ih:ah;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 Zo(n,0),o=this.resolveName("column-count"),r=this.resolveName("column-width"),a=this.resolveName("column-gap");e=ae(n,Qo(n,new qn(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=Mb(t,e.enabled,t._true),s=me(t,e.page,t.zero);if(s){let a=new xe(t,"page-number");n=Pt(t,n,new ys(t,s,a))}let o=me(t,e["min-page-width"],t.zero);o&&(n=Pt(t,n,new no(t,new xe(t,"page-width"),o)));let r=me(t,e["min-page-height"],t.zero);r&&(n=Pt(t,n,new no(t,new xe(t,"page-height"),r))),n=this.boxSpecificEnabled(n),e.enabled=new _(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=me(t,e.left,n),o=me(t,e["margin-left"],n),r=Nn(t,e["border-left-width"],e["border-left-style"],n),a=Vt(t,e["padding-left"],n),l=me(t,e.width,n),c=me(t,e["max-width"],n),u=Vt(t,e["padding-right"],n),d=Nn(t,e["border-right-width"],e["border-right-style"],n),h=me(t,e["margin-right"],n),f=me(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=Qo(t,C,new Pe(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&&(me(t,e["column-width"],null)||me(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),x=Vt(t,b,n);e.left=new _(s),e["margin-left"]=new _(o),e["border-left-width"]=new _(r),e["padding-left"]=new _(a),e.width=new _(l),e["max-width"]=new _(c||l),e["padding-right"]=new _(u),e["border-right-width"]=new _(d),e["margin-right"]=new _(h),e.right=new _(f),e["snap-width"]=new _(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=me(t,e.top,s),r=me(t,e["margin-top"],n),a=Nn(t,e["border-top-width"],e["border-top-style"],n),l=Vt(t,e["padding-top"],n),c=me(t,e.height,s),u=me(t,e["max-height"],s),d=Vt(t,e["padding-bottom"],n),h=Nn(t,e["border-bottom-width"],e["border-bottom-style"],n),f=me(t,e["margin-bottom"],n),g=me(t,e.bottom,s),m=K(t,a,l),b=K(t,h,d);if(o&&g&&c){let v=ae(t,s,K(t,c,K(t,K(t,o,m),b)));r?f?g=ae(t,v,r):f=ae(t,v,K(t,g,r)):(v=ae(t,v,g),f?r=ae(t,v,f):(r=Qo(t,v,new Pe(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 v=ae(t,s,K(t,K(t,r,m),K(t,f,b)));this.isAutoHeight&&(u||(u=ae(t,v,o||g)),this.vertical&&(me(t,e["column-width"],null)||me(t,e["column-count"],null))&&(c=u,this.isAutoHeight=!1)),o?c?g||(g=ae(t,v,K(t,o,c))):c=ae(t,v,K(t,g,o)):o=ae(t,v,K(t,g,c))}let x=e["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),C=Vt(t,x,n);e.top=new _(o),e["margin-top"]=new _(r),e["border-top-width"]=new _(a),e["padding-top"]=new _(l),e.height=new _(c),e["max-height"]=new _(u||c),e["padding-bottom"]=new _(d),e["border-bottom-width"]=new _(h),e["margin-bottom"]=new _(f),e.bottom=new _(g),e["snap-height"]=new _(C)}initColumns(){let t=this.pageBox.scope,e=this.style,n=me(t,e[this.vertical?"height":"width"],null),s=me(t,e["column-width"],n),o=me(t,e["column-count"],null),r=BE(t,e["column-gap"],null);r||(r=new pn(t,1,"em")),s&&!o&&(o=new qn(t,"floor",[ri(t,K(t,n,r),K(t,s,r))]),o=new qn(t,"max",[t.one,o])),o||(o=t.one),s=ae(t,ri(t,K(t,n,r),o),r),e["column-width"]=new _(s),e["column-count"]=new _(o),e["column-gap"]=new _(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=Bi(this.cascaded,t,o,!1,null);this.vertical=cc(r,t,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=uc(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 js&&t.currentLayoutPosition&&new xe(n,"left-page").evaluate(t));dc(r,s,this.vertical,this.rtl,a,(c,u)=>u.value),this.autoWidth=new se(n,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new se(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&&cs(e)&&this.pageMasterInstance instanceof Xn&&(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=Oi(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=Oi(t,n,e,r)}return Ke(n,t)}getSpecial(t,e){let n=lh(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()&&Qa(o.unit)&&(o=tl(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 Fs(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<Fb.length;r++)this.propagateProperty(t,e,Fb[r],s)}transferContentProps(t,e,n,s){for(let o=0;o<Bb.length;o++)this.propagateProperty(t,e,Bb[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&&!X(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&&!X(r)};for(let r=0;r<Ob.length;r++){let a=Ob[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,x,C,v,y;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 N=s&&yr(s);N&&br(s),u=r.getElementClientRect(s?s.element:e.element),N&&bi(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 N=this.getPropAsNumber(t,"column-rule-width"),E=this.getProp(t,"column-rule-style"),T=this.getProp(t,"column-rule-color");if(N>0&&E&&E!=S.none&&T!=S.transparent){let k=this.getPropAsNumber(t,"column-gap"),L=this.vertical?e.height:e.width,V=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:""),W=e.getPaddingRect(),J=s,ee=this.vertical?"border-top":"border-left";for(let ve=1;ve<o;ve++){let le=this.vertical?(L+k)*ve/o-k/2+e.paddingTop-N/2:(L+k)*ve/o-k/2+e.paddingLeft-N/2,F=this.vertical?W.y1+le+N/2:W.x1+le+N/2,H=(m=(g=(f=J.pageFloatLayoutContext)==null?void 0:f.parent)==null?void 0:g.getBlockEndEdgeOfBlockStartFloats)==null?void 0:m.call(g,F),Y=(C=(x=(b=J.pageFloatLayoutContext)==null?void 0:b.parent)==null?void 0:x.getBlockStartEdgeOfBlockEndFloats)==null?void 0:C.call(x,F),z=isFinite(H)?this.vertical?H-W.x1:H-W.y1:NaN,U=isFinite(Y)?this.vertical?Y-W.x1:Y-W.y1:NaN,q=parseFloat(this.vertical?(v=s==null?void 0:s.element.style.width)!=null?v:"":(y=s==null?void 0:s.element.style.height)!=null?y:""),Ne=q>0?q:this.vertical?s.width:s.height,Ve=Math.max(V>0?V:0,0),Ho=Ve+Ne,Wr=Math.max(Ve,isFinite(this.vertical?U:z)?Math.max(0,this.vertical?U:z):0),gs=Math.min(Ho,isFinite(this.vertical?z:U)?Math.max(0,this.vertical?z:U):Ho),wa=Math.max(0,gs-Wr),Tn=e.element.ownerDocument.createElement("div");P(Tn,"position","absolute"),P(Tn,this.vertical?"left":"top",`${Wr}px`),P(Tn,this.vertical?"top":"left",`${le}px`),P(Tn,this.vertical?"height":"width","0px"),P(Tn,this.vertical?"width":"height",`${wa}px`),P(Tn,ee,`${N}px ${E.toString()}${T?` ${T.toString()}`:""}`),e.element.insertBefore(Tn,e.element.firstChild)}}}for(let N=0;N<Vb.length;N++)this.propagateProperty(t,e,Vb[N],a);for(let N of OE){let E=this.getProp(t,N);E&&_r(E,n)}for(let N=0;N<Db.length;N++)this.propagateDelayedProperty(t,e,Db[N],n.delayedItems)}applyCascadeAndInit(t,e){let n=this.cascaded,s=this.pageBox.specified;for(let r in s)this instanceof Xn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||_s(r)&&zn(n,r,te(s,r));if(this.pageBox.pseudoName==pa)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 as(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)}},Fb=["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"],Vb=["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"],OE=["background-image","border-image-source","filter"],Bb=["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"],Ob=["width","height","image-resolution","object-fit","object-position"],Db=["transform","transform-origin"],pa="background-host",nu=class extends zr{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)}},_o=class extends zr{constructor(t,e){super(t,e),this.pageMasterInstance=this}boxSpecificEnabled(t){let e=this.pageBox.pageMaster;return e.condition&&(t=Pt(e.scope,t,e.condition)),t}adjustPageLayout(t,e,n){}},kf=class extends zr{constructor(t,e){super(t,e),this.pageMasterInstance=t.pageMasterInstance}},$n=class extends zr{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 Te&&(s=e.values),s){let o=this.pageBox.scope;for(let r=0;r<s.length;r++)if(s[r]instanceof Q){let a=oi(s[r].name,"enabled"),l=new xe(o,a);n&&(l=new jt(o,l)),t=Pt(o,t,l)}}return t}boxSpecificEnabled(t){let e=this.pageBox.scope,n=this.style,s=Mb(e,n.required,e._false)!==e._false;if(s||this.isAutoHeight){let o=VE(e,n["flow-from"],"body"),r=new qn(e,"has-content",[o]);t=Pt(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=Pt(e,r,t),this.pageMasterInstance.style.enabled=new _(r)}return t}prepareContainer(t,e,n,s,o){var r;this.pageBox.pageMaster instanceof ha||(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)}},da=class extends on{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 B(n,s?bl:yl)}},su=class extends da{constructor(t,e,n,s){super(t,e,n,s)}},Af=class i extends da{constructor(t,e,n,s){super(t,e,n,s),n.specified.width=new B(Ku,0),n.specified.height=new B(Ku,0)}startPartitionRule(t,e,n){let s=new Xs(this.scope,t,e,n,this.target),o=new su(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new tu(this.scope,t,e,n,this.target),o=new i(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}},ou=class extends da{constructor(t,e,n,s){super(t,e,n,s)}startPartitionRule(t,e,n){let s=new Xs(this.scope,t,e,n,this.target),o=new su(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}startPartitionGroupRule(t,e,n){let s=new tu(this.scope,t,e,n,this.target),o=new Af(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(o)}};function qf(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 DE={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")}},ME=new A(.24,"pt"),KN=new A(3,"mm"),_E=new A(10,"mm"),UE=new A(13,"mm");function Sa(i){let t={width:Ss,height:xs,bleed:be,bleedOffset:be,cropOffset:be},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&&DE[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&&!X(n.value)?n.value:S.none,r=s&&!X(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&&!X(a.value)?a.value:S.auto;return l===S.auto?o!==S.none&&(t.bleedOffset=UE):l.isNumeric()&&(t.cropOffset=l),t}function Kf(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===Ss?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===xs?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 Ub(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 fa(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 Lf=(s=>(s.TOP_LEFT="top left",s.TOP_RIGHT="top right",s.BOTTOM_LEFT="bottom left",s.BOTTOM_RIGHT="bottom right",s))(Lf||{});function HE(i,t,e,n,s,o,r){let a=s;a<=o+2*dt.mm&&(a=o+s/2);let l=Math.max(s,a),c=o+l+e/2,u=Ub(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=fa(i,e,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=fa(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 ga=(s=>(s.TOP="top",s.BOTTOM="bottom",s.LEFT="left",s.RIGHT="right",s))(ga||{});function zE(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=Ub(i,a,l),u=fa(i,e,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),c.appendChild(u);let d=fa(i,e,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),c.appendChild(d);let h=fa(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(ga).forEach(g=>{let m=ga[g];m===t?c.style[m]=`${o}px`:m!==f&&(c.style[m]="0",c.style[`margin-${m}`]="auto")}),c}function Hb(i,t,e,n){let s=!1,o=!1,r=i.marks;if(r){let m=r.value;m instanceof j?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=Ke(ME,n),d=Math.max(0,t.bleedOffset-Ke(_E,n)),h=t.bleedOffset-d,f=i["crop-marks-line-color"],g=f&&!X(f.value)?f.value:S.auto;s&&Object.keys(Lf).forEach(m=>{let b=Lf[m],x=HE(c,b,u,g,h,a,d);l.appendChild(x)}),o&&Object.keys(ga).forEach(m=>{let b=ga[m],x=zE(c,b,u,g,h,d);l.appendChild(x)})}var If=(()=>{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 Zf={"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"}},GE=(()=>{let i=Zf;return Object.keys(i).sort((t,e)=>i[t].order-i[e].order)})(),lu="vivliostyle-page-rule-master",ma="_marginBoxes",ua="_footnoteArea",ha=class extends Hr{constructor(e,n,s){super(e,null,lu,[],n,null,0);p(this,"pageMarginBoxes",{});let o=Sa(s),r=new Ff(this.scope,this,s,o);this.createPageMarginBoxes(s),this.applySpecified(s,o)}createPageMarginBoxes(e){let n=e[ma];n&&GE.forEach(s=>{n[s]&&(this.pageMarginBoxes[s]=new Bf(this.scope,this,s,e))})}applySpecified(e,n){this.specified.position=new B(S.relative,0),this.specified.width=new B(n.width,0),this.specified.height=new B(n.height,0);for(let s in e)!If[s]&&s!=="background-clip"&&(this.specified[s]=e[s])}createInstance(e){return new Xn(e,this)}},Ff=class extends Xs{constructor(e,n,s,o){super(e,null,null,[],n);this.pageSize=o;let r=new Vf(this.scope,this);this.applySpecified(s)}applySpecified(e){this.specified["wrap-flow"]=new B(S.auto,0),this.specified["z-index"]=new B(new pe(0),0),this.specified.position=new B(S.absolute,0),this.specified.overflow=new B(S.visible,0);for(let n in If)If.hasOwnProperty(n)&&(this.specified[n]=e[n])}createInstance(e){return new Df(e,this)}},Vf=class extends Xs{constructor(t,e){super(t,null,null,[],e),this.specified["flow-from"]=new B(R("body"),0)}createInstance(t){return new Ca(t,this)}},Bf=class extends Xs{constructor(e,n,s,o){super(e,null,null,[],n);this.marginBoxName=s;this.applySpecified(o)}applySpecified(e){let n=e[ma][this.marginBoxName];for(let s in e){let o=e[s],r=n[s];(rh[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 ba(e,this)}},Xn=class extends _o{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=be,e["margin-left"]=be,e["border-left-width"]=be,e["padding-left"]=be,e["padding-right"]=be,e["border-right-width"]=be,e["margin-right"]=be,e.right=be}initVertical(){let e=this.style;e.top=be,e["margin-top"]=be,e["border-top-width"]=be,e["padding-top"]=be,e["padding-bottom"]=be,e["border-bottom-width"]=be,e["margin-bottom"]=be,e.bottom=be}setPageAreaDimension(e){this.pageAreaDimension=e;let n=this.style;n.width=new _(e.borderBoxWidth),n.height=new _(e.borderBoxHeight),n["padding-left"]=new _(e.marginLeft),n["padding-right"]=new _(e.marginRight),n["padding-top"]=new _(e.marginTop),n["padding-bottom"]=new _(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 N in e){let E=Zf[N];if(E){let T=e[N],k=this.pageMarginBoxInstances[N],L=new Gr(T,k.style,n,u,r);d[E.positionAlongVariableDimension]=T,h[E.positionAlongVariableDimension]=k,f[E.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,x={};Object.keys(d).forEach(N=>{let E=N,T=me(u,h[E].style[n?"max-width":"max-height"],s.extent);if(T){let k=T.evaluate(o);if(m[E]>k){let L=f[E]=new ru(d[E],h[E].style,n,u,r,k);x[E]=L.getOuterSize(),b=!0}}}),b&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),b=!1,[a,l,c].forEach(N=>{var E;m[N]=(E=x[N])!=null?E:m[N]}));let C={};Object.keys(d).forEach(N=>{let E=N,T=me(u,h[E].style[n?"min-width":"min-height"],s.extent);if(T){let k=T.evaluate(o);if(m[E]<k){let L=f[E]=new ru(d[E],h[E].style,n,u,r,k);C[E]=L.getOuterSize(),b=!0}}}),b&&(m=this.getSizesOfMarginBoxesAlongVariableDimension(f,g.extent),[a,l,c].forEach(N=>{m[N]=C[N]||m[N]}));let v=g.start+g.extent,y=g.start+(g.start+g.extent);[a,l,c].forEach(N=>{let E=m[N];if(E!=null){let T=d[N],k=0;switch(N){case a:k=n?T.left:T.top;break;case l:k=(y-E)/2;break;case c:k=v-E;break}n?T.setHorizontalPosition(k,E-T.getInsetLeft()-T.getInsetRight()):T.setVerticalPosition(k,E-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 Of(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 Gr&&e.minMaxFitContent&&(o.xSize=e.getOuterSize()),n instanceof Gr&&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)}},Gr=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||X(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=Sr(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()}},Of=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}},ru=class extends Gr{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()}},Df=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=me(o,n[l],c),d=me(o,n[`margin-${r}`],c),h=me(o,n[`margin-${a}`],c),f=Vt(o,n[`padding-${r}`],c),g=Vt(o,n[`padding-${a}`],c),m=Nn(o,n[`border-${r}-width`],n[`border-${r}-style`],c),b=Nn(o,n[`border-${a}-width`],n[`border-${a}-style`],c),x=K(o,K(o,m,f),K(o,b,g)),C,v,y;return u?(this.borderBoxSizing?(v=u,y=ae(o,v,x)):(y=u,v=K(o,y,x)),C=ae(o,c,v),!d&&!h?(d=Qo(o,C,new Pe(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),v=ae(o,c,C),y=ae(o,v,x),u=this.borderBoxSizing?v:y),n[r]=new _(d),n[a]=new _(h),n[`margin-${r}`]=be,n[`margin-${a}`]=be,n[`border-${r}-width`]=new _(m),n[`border-${a}-width`]=new _(b),n[`padding-${r}`]=new _(f),n[`padding-${a}`]=new _(g),n[l]=new _(u),n[`max-${l}`]=new _(u),{borderBoxExtent:v,contentBoxExtent:y,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)}},Ca=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 _(this.parentInstance.contentBoxWidth),t["margin-left"]=new _(new An(n,e.left.toExpr(n,null))),t["margin-right"]=new _(new An(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 _(this.parentInstance.contentBoxHeight),t["margin-top"]=new _(new An(n,e.top.toExpr(n,null))),t["margin-bottom"]=new _(new An(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}},ba=class extends $n{constructor(e,n){super(e,n);p(this,"boxInfo");p(this,"suppressEmptyBoxGeneration",!0);let s=n.marginBoxName;this.boxInfo=Zf[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 Ae||r instanceof _&&r.expr instanceof se&&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=me(o,s[l],u),h=c?n.marginLeft:n.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")s[r]=new _(h);else if(d){let f=Vt(o,s[`margin-${r}`],u),g=Vt(o,s[`margin-${a}`],u),m=Vt(o,s[`padding-${r}`],u),b=Vt(o,s[`padding-${a}`],u),x=Nn(o,s[`border-${r}-width`],s[`border-${r}-style`],u),C=Nn(o,s[`border-${a}-width`],s[`border-${a}-style`],u),v=K(o,d,K(o,this.borderBoxSizing?o.zero:K(o,K(o,m,b),K(o,x,C)),K(o,f,g)));switch(this.boxInfo.positionAlongVariableDimension){case"center":s[r]=new _(K(o,h,ri(o,ae(o,u,v),new Pe(o,2))));break;case"end":s[r]=new _(ae(o,K(o,h,u),v));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=Rf(o,s[`margin-${a}`],u),h=Rf(o,s[`margin-${l}`],u),f=Vt(o,s[`padding-${a}`],u),g=Vt(o,s[`padding-${l}`],u),m=Nn(o,s[`border-${a}-width`],s[`border-${a}-style`],u),b=Nn(o,s[`border-${l}-width`],s[`border-${l}-style`],u),x=me(o,s[c],u),C=null;function v(y){if(C)return C;C={extent:x?x.evaluate(y):null,marginInside:d?d.evaluate(y):null,marginOutside:h?h.evaluate(y):null};let N=u.evaluate(y),E=0;return r||[m,f,g,b].forEach(T=>{T&&(E+=T.evaluate(y))}),(C.marginInside===null||C.marginOutside===null)&&E+C.extent+C.marginInside+C.marginOutside>N&&(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=N-E-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=N-E-C.extent-C.marginOutside:typeof C.marginInside=="number"&&C.marginOutside===null?C.marginOutside=N-E-C.extent-C.marginInside:C.marginInside=C.marginOutside=(N-E-C.extent)/2),C}s[c]=new _(new se(o,function(){let y=v(this).extent;return y===null?"auto":y},c)),s[`margin-${a}`]=new _(new se(o,function(){let y=v(this).marginInside;return y===null?"auto":y},`margin-${a}`)),s[`margin-${l}`]=new _(new se(o,function(){let y=v(this).marginOutside;return y===null?"auto":y},`margin-${l}`)),a==="left"?s.left=new _(K(o,n.marginLeft,n.borderBoxWidth)):a==="top"&&(s.top=new _(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 N=this.getProp(e,"margin-left"),E=this.getProp(e,"margin-right");if(d.isInLeftColumn){let T=h.borderBoxWidth.evaluate(e)+h.marginRight.evaluate(e);P(n.element,"right",`${T}px`),(N===S.auto||E!==S.auto)&&P(n.element,"margin-left","auto"),E===S.auto&&P(n.element,"margin-right","auto")}else d.isInRightColumn&&(P(n.element,"right","0"),(E===S.auto||N!==S.auto)&&P(n.element,"margin-right","auto"),N===S.auto&&P(n.element,"margin-left","auto"))}let x=this.getProp(e,"height"),C=x instanceof Q&&(x.name==="min-content"||x.name==="max-content"||x.name==="fit-content")?x.name:null,v=this.getPropAsNumber(e,"min-height"),y=this.getPropAsNumber(e,"max-height");if(C||v||y){C&&P(n.element,"height",C),v&&P(n.element,"min-height",`${v}px`),y&&P(n.element,"max-height",`${y}px`);let N=this.getProp(e,"margin-top"),E=this.getProp(e,"margin-bottom");if(d.isInTopRow){let T=h.borderBoxHeight.evaluate(e)+h.marginBottom.evaluate(e);P(n.element,"bottom",`${T}px`),(N===S.auto||E!==S.auto)&&P(n.element,"margin-top","auto"),E===S.auto&&P(n.element,"margin-bottom","auto")}else d.isInBottomRow&&(P(n.element,"bottom","0"),(E===S.auto||N!==S.auto)&&P(n.element,"margin-bottom","auto"),N===S.auto&&P(n.element,"margin-top","auto"))}}},iu=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 xe(t,"page-number"),o=new ys(t,new Ko(t,s,new Pe(t,2)),n?t.one:t.zero);t.defineName("recto-page",new jt(t,o)),t.defineName("verso-page",o),(e.pageProgression||qf(this.docElementStyle))==="ltr"?(t.defineName("left-page",o),t.defineName("right-page",new jt(t,o))):(t.defineName("left-page",new jt(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===pa?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 B?o=`${s.value}`:o=this.makeCascadeValueObjectKey(s),e.push(n+o+(s.priority||""))}return e.sort().join("^")}generatePageRuleMaster(t){let n=new ha(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:lu}),s=n.specified,o=t.size;if(o&&!X(o.value)){let a=Sa(t),l=o.priority;an(s,"width",new B(a.width,l),this.context),an(s,"height",new B(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}},Mf=class extends fe{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}},_f=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Uf=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Hf=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},zf=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Gf=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Wf=class extends fe{constructor(e){super();this.scope=e}apply(e){new xe(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},$f=class extends Gn{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}},Xf=class extends Gn{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}},jf=class extends Ao{constructor(t,e){super(t,e,null,null,null)}apply(t){WE(t.context,t.currentStyle,this.style,this.specificity,t)}};function WE(i,t,e,n,s){Vi(i,t,e,n,null,null,null);let o=e[ma];if(o){let a=Kt(t,ma);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[ua];if(r){let a=Kt(t,ua);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 B&&an(c,h,f)}let d=lt(u,"_pseudos");if(d){let h=Kt(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 x=m[b];x instanceof B&&an(g,b,x)}}}}}}var au=class extends ls{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 Mf(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 Xf(this.scope,s,o,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${s}n${o<0?o:"+"+o})`),this.chain.push(new $f(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 _f(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Uf(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Hf(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new zf(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Gf(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Wf(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=te(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(a=>{zn(r[a],e,o)});else if(e==="size"){let a=r[""];this.currentPageSelectors.forEach(l=>{let c=new B(o.value,o.priority+l.specificity),u=l.selectors?l.selectors.join(""):"",d=r[u];d?an(d,e,c):(d=r[u]={},zn(d,e,c),a&&["bleed","marks"].forEach(h=>{a[h]&&zn(d,h,a[h])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new jf(this.elementStyle,e)}startFootnoteRule(e){let n=Kt(this.elementStyle,ua),s=n.area;if(s||(s={},n.area=s),e){let r=Kt(s,"_pseudos"),a=r[e];a||(a={},r[e]=a),s=a}let o=new ya(this.scope,this.owner,this.validatorSet,s);this.owner.pushHandler(o)}startPageMarginBoxRule(e){let n=Kt(this.elementStyle,ma),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 on{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 B(n,o);zn(this.boxStyle,e,r)}},ya=class extends on{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 B(n,o);zn(this.areaStyle,e,r)}};var xa=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(Xt,"0")}doc(){return new uu([this.document])}getElementOffset(t){let e=t.getAttribute(Xt);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(Xt,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=Mt(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}},Qf=(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))(Qf||{});function cu(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 $E(i){let t=i.contentType;if(t){let n=Object.keys(Qf);for(let s=0;s<n.length;s++)if(Qf[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 eg(i,t){let e=i.responseXML;if(!e){let s=new DOMParser,o=i.responseText;if(o!=null){let r=$E(i);if(e=cu(o,r||"application/xml",s),e&&!r){let a=e.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?e=cu(o,"text/html",s):a.localName.toLowerCase()==="svg"&&e.contentType!=="image/svg+xml"&&(e=cu(o,"image/svg+xml",s))}e||(e=cu(o,"text/html",s))}}let n=e?new xa(t,i.url,e):null;return w(n)}function zb(){return new fo(eg,"document")}var Jf=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 uu([n]);return s=s.child(t),e&&(s=s.predicate(e)),s.size()>0})}},tg=new Jf(i=>!0),uu=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 XE=new Fn(()=>{let i=I("uaStylesheetBase"),t=vf(),e=ne("user-agent-base.css",un),n=new ls(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),TC(n.cascade),Sl(Ad,n,e,null,null).thenFinish(i),i.result()},"uaStylesheetBaseFetcher");function jE(){return XE.get()}var ng=class extends Ro{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)||D.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},sg=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 se(this.pageScope,function(){let h=this;return h.pageNumberOffset+h.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new se(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 Xo(this.rootScope,t,e,n),r=NC(o,this.viewportProps),a=r.width,l=r.height,c=r["text-zoom"],u=1;if(a&&l||c){let d=dt.em;if((c?c.evaluate(o,"text-zoom"):null)===S.scale&&(u=d/n,n=d,t*=u,e*=u),a&&l){let f=Ke(a.evaluate(o,"width"),o),g=Ke(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 Wb(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 $b(i){for(let[t,e]of i)e!==void 0&&t.restoreState(e)}var js=class extends Xo{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 jc(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new _n(null,null,null,null,null,null,null),this.pageProgression=g||null,this.isVersoFirstPage=!!m;for(let b in e.flowProps){let x=e.flowProps[b],C=te(x,"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 sa(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=qf(o)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new nu(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 iu(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=Nb(u.properties,this),h=new ca(d);l.push(h)}this.fontMapper.findOrLoadFonts(l,this.faces).then(()=>{Ab(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=Kf(Sa(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 Xo(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 sa(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 Dl,s.flowPositions[e.flowName]=o);let r=iC(e.element),a=new Gt(r),l=new Ol(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=Ps(this.style.rootScope,new Ze(n,null),"");return l?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,l,!1,a),o):!1}evalSupportsSelector(e){class n extends du{errorMsg(...c){}}let s=new n(null),o=hd(e),r=new Ze(o+"{}",s);return new ws(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 Ee(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let n=te(e,"break-before");if(!n)return!1;let s=n.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(s)}getExplicitPageType(e){let n=te(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=ns(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 x=this.pageGroupPageCounts[b]||(this.pageGroupPageCounts[b]=new Map),C=x.get(m)||0;(C>0||c&&(g||this.shouldStartPageGroup(m,b,u)))&&(C+=1,x.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(!ie(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&&!X(o)?o:S.static;if(yo(r)||mr(r))return!1;let a=(u=n==null?void 0:n.float)==null?void 0:u.evaluate(this.styler.context,"float");return(a&&!X(a)?a:S.none)===S.none}isInlineLevelElement(e){return kt(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&&!X(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){D.debug("Location - page",this.currentLayoutPosition.page),D.debug(" current:",e),D.debug(" lookup:",this.lookupOffset);for(let n in this.currentLayoutPosition.flowPositions){let s=this.currentLayoutPosition.flowPositions[n];for(let o of s.positions)D.debug(" Chunk",`${n}:`,o.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new xe(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=qd(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===lu)continue;let l=1;r.pageBox.pseudoName===pa&&!(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=Mt(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 wr(null)),e.flowRootFormattingContext=s.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new _n(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!==he.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 Sn().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 Gt(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=qd(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),x=C=>C!==""&&C!=="none";return x(b.getPropertyValue("max-block-size"))||x(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 fc([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.isAutoHeight&&e.isTopDependentOnAutoHeight||e.isAutoWidth,x=r.element,C=new _n(c,he.COLUMN,null,l,null,null,null),v=this.currentLayoutPosition.clone(),y=I("createAndLayoutColumn"),N;return y.loopWithFrame(E=>{let T=this.createLayoutConstraint(C);if(u>1){let k=this.viewport.document.createElement("div");if(P(k,"position","absolute"),x.appendChild(k),N=new Fo(k,g,this.clientLayout,T,C),N.isNonFirstColumn=a>0,N.forceNonfitting=m,N.vertical=r.vertical,N.rtl=r.rtl,N.snapHeight=r.snapHeight,N.snapWidth=r.snapWidth,r.vertical){let L=(r.rtl?u-a-1:a)*(h+d)+r.paddingTop,V=parseFloat(x.style.width);N.setHorizontalPosition(r.paddingLeft+V-r.width,r.width),N.setVerticalPosition(L,h)}else{let L=(r.rtl?u-a-1:a)*(h+d)+r.paddingLeft;N.setVerticalPosition(r.paddingTop,r.height),N.setHorizontalPosition(L,h)}N.originX=n,N.originY=s}else N=new Fo(x,g,this.clientLayout,T,C),N.isNonFirstColumn=!1,N.copyFrom(r);N.exclusions=b?[]:o.concat(),N.innerShape=f,C.setContainer(N),(N.vertical?N.height:N.width)>=0?this.layoutColumn(N,l).then(()=>{C.isInvalidated()||C.finish(),N.pageFloatLayoutContext.isInvalidated()&&!c.isInvalidated()?(N.pageFloatLayoutContext.validate(),this.currentLayoutPosition=v.clone(),N.element!==x&&x.removeChild(N.element),E.continueLoop()):E.breakLoop()}):(C.finish(),E.breakLoop())}).then(()=>{y.finish(N)}),y.result()}setPagePageFloatLayoutContextContainer(e,n,s){(n instanceof Ca||n instanceof _o&&!(n instanceof Xn))&&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 _n(e,he.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,x=this.currentLayoutPosition.flowPositions[c];let C=JC(u,b,g,h,l,m.columns,x);return C?(f=!1,a.lock(),h.lock(),C.balanceColumns(m).thenAsync(v=>(a.unlock(),a.validate(),h.unlock(),this.currentLayoutPosition=v.position,w(v.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=Wb(this.currentLayoutPosition),b=n.getPropAsNumber(this,"column-gap"),x=d>1?n.getPropAsNumber(this,"column-width"):c.vertical?c.height:c.width,C=n.getActiveRegions(this),v=n.getProp(this,"shape-inside"),y=dl(v,0,0,c.width,c.height,this),N=new Kc(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),E=0,T=null,k=[];return f.loopWithFrame(L=>{this.createAndLayoutColumn(n,s,o,r,c,E++,u,l,d,b,x,y,N,h).then(V=>{if(a.isInvalidated()){k=null,L.breakLoop();return}if((!!V.pageBreakType&&V.pageBreakType!=="column"||E===d)&&!l.isInvalidated()&&l.finish(),l.isInvalidated()){E=0,this.currentLayoutPosition=g.clone(),$b(m),l.validate(),l.isLocked()?(k=null,L.breakLoop()):L.continueLoop();return}T=V,k[E-1]=T,T.pageBreakType&&T.pageBreakType!="column"&&(E=d,T.pageBreakType!="region"&&(this.pageBreaks[u]=!0)),E<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 ba?"complementary":"presentation";let m=n.getProp(this,"position");P(g,"position",m?m.name:"absolute");let b=n instanceof Xn;n instanceof $n?s.appendChild(g):s.insertBefore(g,s.firstChild);let C=new Nr(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 Xn&&(C.width<=0||C.height<=0)&&D.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 v,y=!1;if(!f||!f.isIdent()){let N=[],E=n.getProp(this,"content");if(E instanceof _&&E.expr instanceof se&&E.expr.str.startsWith("running-element-"))E.visit(new Mn(g,this,E,this.counterStore.getExprContentListener()));else if(rt(E)){let T="span";E instanceof Ae&&(T="img");let k=this.viewport.document.createElement(T);E.visit(new Mn(k,this,E,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 W=0;W<L.length;W++){let J=L[W],ee=J.getAttribute("src");if(!ee)continue;let ve=ft(J,ee);N.push(ve),e.fetchers.push(ve)}let V=k.getAttribute("src");if(V){let W=k.querySelector("img");W||(W=k);let J=ft(W,V);N.push(J),e.fetchers.push(J)}T=="span"&&DC(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),y=!0);y||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),v=N.length?bn(N).thenReturn(!0):w(!0)}else if(this.pageBreaks[f.toString()])l.isInvalidated()||n.finishContainer(this,C,e,null,1,this.clientLayout,this.faces),v=w(!0);else{let N=I("layoutContainer.inner"),E=f.toString(),T=n.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,n,o,r,a,l,C,E,T).then(k=>{if(!l.isInvalidated()){let L=k[0];L.element===g&&(C=L),C.computedBlockSize=Math.max.apply(null,k.map(W=>W.computedBlockSize)),n.finishContainer(this,C,e,L,T,this.clientLayout,this.faces);let V=this.currentLayoutPosition.flowPositions[E];V&&V.breakAfter==="region"&&(V.breakAfter=null)}N.finish(!0)}),v=N.result()}return v.then(()=>{if(l.isInvalidated()){u.finish(!0);return}if(!n.isAutoHeight||Math.floor(C.computedBlockSize)>0){if(!y&&!h){let E=n.getProp(this,"shape-outside"),T=C.getOuterShape(E,this);a.push(T)}}else if(n.children.length==0){s.removeChild(g),u.finish(!0);return}let N=b?0:n.children.length-1;u.loop(()=>{for(;N>=0&&N<n.children.length;){let E=n.children[b?N++:N--],T=this.layoutContainer(e,E,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,x,C;let s=e.container===e.bleedBox;this.pageBreaks={},n?(this.currentLayoutPosition=n.clone(),this.styler.replayFlowElementsFromOffset(n.highestSeenOffset)):(this.currentLayoutPosition=new Ml,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=ns(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=Wb(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 v=new xe(this.style.pageScope,"left-page");e.side=v.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===Ss),e.setAutoPageHeight(c.pageBox.specified.height.value===xs);let{counterOffset:v,changeOffset:y}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(v)||(v=this.lookupOffset,y=this.lookupOffset),isFinite(v)&&this.styler.styleUntil(v,0);let N=this.styler.getCounterSnapshotAtOffset(v),E=y===v?N:this.styler.getCounterSnapshotAtOffset(y);N||(N=this.styler.getLastCounterSnapshot()),E||(E=N),this.counterStore.setCurrentPageDocCounters((x=N==null?void 0:N.counters)!=null?x:null,(C=E==null?void 0:E.changes)!=null?C:null,E==null?void 0:E.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let T=Kf(Sa(l),this);this.setPageSizeAndBleed(T,e),Hb(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 _n(this.rootPageFloatLayoutContext,he.PAGE,null,null,null,d,h),g=I("layoutNextPage");return g.loopWithFrame(v=>{this.layoutContainer(e,c,e.bleedBox,u,u,[],f).then(()=>{if(f.isInvalidated()||f.finish(),f.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),$b(a),f.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);v.continueLoop()}else v.breakLoop()})}).then(()=>{c.adjustPageLayout(this,e,this.clientLayout),s||(this.processLinger(),n=this.currentLayoutPosition,Object.keys(n.flowPositions).forEach(y=>{let N=n.flowPositions[y],E=N.breakAfter;E&&(E==="page"||!this.matchPageSide(E))&&(N.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,n.highestSeenOffset=this.styler.getReachedOffset();let v=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(v,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`}},og=class i extends ls{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 Hr(this.masterHandler.pageScope,e,n,s,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new ou(o.scope,this.masterHandler,o,this.validatorSet))}startWhenRule(e){let n=e.expr;this.condition!=null&&(n=Pt(this.scope,this.condition,n)),this.masterHandler.pushHandler(new i(this.masterHandler,n,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new nc(this.scope,this.owner))}startFontFaceRule(){let e={};this.masterHandler.fontFaces.push({properties:e,condition:this.condition}),this.masterHandler.pushHandler(new Ro(this.scope,this.owner,null,e,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(e){this.masterHandler.pushHandler(new ng(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 Ro(this.scope,this.owner,null,n,this.masterHandler.validatorSet))}startViewportRule(){let e={};this.masterHandler.viewportProps.push(e),this.masterHandler.pushHandler(new Ro(this.scope,this.owner,this.condition,e,this.masterHandler.validatorSet))}startFootnoteRule(e){let n=this.masterHandler.footnoteProps;if(e){let s=Kt(n,"_pseudos");n=s[e],n||(n={},s[e]=n)}this.masterHandler.pushHandler(new ya(this.scope,this.owner,this.masterHandler.validatorSet,n))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let e=new au(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(e),e.startPageRule()}startRuleBody(){if(ls.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()}}},du=class extends gr{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 Tc);p(this,"footnoteProps",{});p(this,"flowProps",{});p(this,"viewportProps",[]);p(this,"pageProps",{});this.rootScope=new to(null),this.pageScope=new to(this.rootScope),this.rootBox=new Jc(this.rootScope),this.cascadeParserHandler=new og(this,null,null,null),this.slave=this.cascadeParserHandler}};function YE(i,t){return t.parseOPSResource(i)}var pu=class extends fo{constructor(e){super(YE,"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=vf(),jE().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=ne(jn(n),wn)),this.styleSheets.push({url:n,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let n=e.url;n&&(n=ne(jn(n),wn)),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 eg(e,this).then(r=>{var f;if(!r){n.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let g=nt("PREPROCESS_SINGLE_DOCUMENT");for(let m=0;m<g.length;m++)try{g[m](r.document)}catch(b){D.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"),x=m.getAttributeNS("http://www.w3.org/2001/xml-events","event"),C=m.getAttribute("action"),v=m.getAttribute("ref");b&&x&&C&&v&&a.push({observer:b,event:x,action:C,ref:v})}this.triggersByDocURL[s]=a;let c=[];if(c.push({url:ne("user-agent-page.css",un),text:kd,flavor:"UA",classes:null,media:null}),c.push({url:ne("user-agent-counter-styles.css",un),text:Id,flavor:"UA",classes:null,media:null}),o)c.push({url:ne("user-agent-toc.css",un),text:Rd,flavor:"UA",classes:null,media:null});else{let g=r.document.querySelectorAll("style, link, meta");for(let m of g){let b=m.namespaceURI,x=m.localName;if(b=="http://www.w3.org/1999/xhtml")if(x=="style"){let C=m.getAttribute("class"),v=m.getAttribute("media"),y=m.getAttribute("title");c.push({url:s,text:m.textContent,flavor:"Author",classes:y?C:null,media:v})}else if(x=="link"){let C=m.getAttribute("href"),v=(f=m.getAttribute("rel"))==null?void 0:f.split(/\s+/),y=m.getAttribute("class"),N=m.getAttribute("media");if(C&&(v!=null&&v.includes("stylesheet"))&&(!v.includes("alternate")||y)){let E=ne(C,s),T=m.getAttribute("title");c.push({url:E,text:null,classes:T?y:null,media:N,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 Fn(()=>{let g=I("fetchStylesheet"),m=0,b=new du(this.validatorSet);return g.loop(()=>{if(m<c.length){let x=c[m++];return b.startStylesheet(x.flavor),x.text!==null?Sl(x.text,b,x.url,x.classes,x.media).thenReturn(!0):Bd(x.url,b,x.classes,x.media)}return w(!1)}).then(()=>{let x=b.cascadeParserHandler.finish();d=new sg(this,b.rootScope,b.pageScope,x,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 Ea="\u25B8",jb="\u25BE",qE="\u25B9";function fu(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 Yb(i){let t=fu(i),e=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))e.push(s);return e}var hu=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=Za(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;dn(s,"height","auto")!="auto"&&(P(s,"height","auto"),this.setAutoHeight(s,e)),dn(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=be,o.padding=be,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=be;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return e(n,s,o);let a=n.firstChild;a&&a.nodeType!==1&&ie(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!=Ea&&(u.textContent=Ea,P(u,"cursor","pointer"),u.addEventListener("click",KE,!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=qE,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 vr(t,t);this.page=a;let l=wt(this.url)+"?viv-toc-box";return this.store.load(l).then(c=>{for(let g of fu(c.document))g.setAttribute("data-vivliostyle-role","doc-toc");let u=this.store.getStyleForDoc(c),d=u.sizeViewport(n,1e5,o);e=new fs(e.window,d.fontSize,0,t,d.width,d.height);let h=this.makeCustomRenderer(c),f=new js(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 KE(i){let t=i.target,e=t.textContent==Ea;t.textContent=e?jb:Ea;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==jb){a.textContent=Ea,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 gu(i){let t={};return Object.keys(i).forEach(e=>{t[e]=Array.from(i[e])}),t}function QE(i){let t=Object.create(null);return Object.keys(i).forEach(e=>{t[e]=new Map(i[e])}),t}function JE(i){return/\.(x?html?|xht|svg)(?:[#?]|$)/i.test(i)||/^(?:about:|data:|blob:)/i.test(wt(i))}var Na=class extends pu{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=zb(),this.jsonStore=mm()}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 Uo(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):JE(e)?this.loadWebPub(e).then(s=>{if(s){n.finish(s);return}this.reportLoadError(e),n.finish(null)}):go(e,null,"HEAD").then(s=>{if(s.status>=400)this.loadEPUBDoc(e).then(o=>{if(o){n.finish(o);return}D.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 Uo(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 Uo(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=ne(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&&fu(o).length===0&&(r.toc=null),n.finish(r)})}}),n.result()}addDocument(e,n){let s=I("EPUBDocStore.load"),o=wt(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(wn)||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:")?D.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&wn.startsWith("https:")&&!/^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(?:[/?#]|$)/.test(e)?D.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):s()?D.error(`Failed to load ${e}. This may be caused by network error, incorrect URL, or the server not allowing cross-origin resource sharing (CORS).`):D.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let n=wt(e),s=this.documents[n];if(s)return s.isPending()?s: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""}},Cu=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=Ng}initWithElement(t,e){this.id=t.getAttribute("id"),this.src=ne(t.getAttribute("href"),e),this.mediaType=t.getAttribute("media-type");let n=t.getAttribute("properties");n&&(this.itemProperties=Pg(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 ev(i){return i.id}function tv(i){return t=>{let e=I("deobfuscator");return nv("SHA-1",i).then(n=>{let s=t.slice(0,1040),o=t.slice(1040,t.size);fm(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(Fd([a,o]))})}),e.result()}}function nv(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 Ys={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"},va="http://idpf.org/epub/vocab/package/meta/#",We={language:`${Ys.dcterms}language`,title:`${Ys.dcterms}title`,creator:`${Ys.dcterms}creator`,layout:`${Ys.rendition}layout`,titleType:`${va}title-type`,displaySeq:`${va}display-seq`,alternateScript:`${va}alternate-script`,role:`${va}role`};function sv(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==We.title&&(o=((d=a[We.titleType])==null?void 0:d[0].v)=="main",r=((h=l[We.titleType])==null?void 0:h[0].v)=="main",o!=r))return o?-1:1;let c=parseInt((f=a[We.displaySeq])==null?void 0:f[0].v,10);isNaN(c)&&(c=Number.MAX_VALUE);let u=parseInt((g=l[We.displaySeq])==null?void 0:g[0].v,10);return isNaN(u)&&(u=Number.MAX_VALUE),c!=u?c-u:i!=We.language&&t&&(o=((m=a[We.language]||a[We.alternateScript])==null?void 0:m[0].v)==t,r=((b=l[We.language]||l[We.alternateScript])==null?void 0:b[0].v)==t,o!=r)?o?-1:1:n.o-s.o}}function ov(i,t){let e;if(!t)e=Ys;else{e={};for(let h in Ys)e[h]=Ys[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]]:va;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:Ys.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=Da(o,d=>d.refines),a=d=>kg(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:We.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&b.push({name:We.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let x=Da(b,C=>C.name);m.r=a(x)}return m})),l=a(Da(o,d=>d.refines?null:d.name)),c=null;l[We.language]&&(c=l[We.language][0].v);let u=d=>{for(let h in d){let f=d[h];f.sort(sv(h,c));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(l),l}function rv(){let i=window.MathJax;return i?i.Hub:null}var qb={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},rg="viv-id-",Uo=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 rg+Hu(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(rg)===0&&(s=s.substring(rg.length));let r=wg(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=ne("",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 Cu,d=c;u.initWithElement(d,t.url);let h=d.getAttribute("fallback");return h&&!qb[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=zu(this.items,ev),this.itemMapByPath=zu(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(qb[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=Au(r));let a=e?e.doc().child("encryption").child("EncryptedData").predicate(tg.withChild("EncryptionMethod",tg.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=ov(n.child("metadata"),n.attribute("prefix")[0]),this.metadata[We.language]&&(this.lang=this.metadata[We.language][0].v),this.metadata[We.layout]&&(this.prePaginated=this.metadata[We.layout][0].v==="pre-paginated"),a.length>0&&this.uid){let c=tv(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 xa(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return t.forEach(s=>{let o=new Cu;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 g,m,b,x;t.readingProgression&&(this.pageProgression=t.readingProgression),this.metadata===void 0&&(this.metadata={});let s=t.name||((g=t.metadata)==null?void 0:g.title)||(e==null?void 0:e.title);s&&(this.metadata[We.title]=(Array.isArray(s)?s:[s]).map(C=>{var v;return{v:(v=C.value)!=null?v:C}}));let o=t.author||t.creator||((m=t.metadata)==null?void 0:m.author)||Array.from((b=e==null?void 0:e.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?b:[]).map(C=>C.content);o&&o.length!==0&&(this.metadata[We.creator]=(Array.isArray(o)?o:[o]).map(C=>{var v;return{v:(v=C.name)!=null?v:C}}));let r=t.inLanguage||((x=t.metadata)==null?void 0:x.language)||(e==null?void 0:e.documentElement.lang)||(e==null?void 0:e.documentElement.getAttribute("xml:lang"));r&&(this.metadata[We.language]=(Array.isArray(r)?r:[r]).map(C=>({v:C})));let a=wt(this.pubURL),l=this.getPathFromURL(a),c=l!==null?encodeURI(l):/^(?:about:|blob:)/i.test(a)?a:null;if(!t.readingOrder&&e&&c!==null){t.readingOrder=[c];for(let C of Yb(e)){let v=C.getAttribute("href");if(/^(https?:)?\/\//.test(v)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(v))continue;let y=wt(ne(v,this.pubURL)),N=this.getPathFromURL(y),E=N!==null?encodeURI(N):y;t.readingOrder.indexOf(E)==-1&&t.readingOrder.push(E)}}let u=[],d=0,h=-1;[t.readingOrder,t.resources].forEach(C=>{C instanceof Array&&C.forEach(v=>{let y=C===t.readingOrder,N=typeof v=="string"?v:v.url||v.href,E=typeof v=="string"?"":v.encodingFormat||v.href&&v.type||"";if(y||E==="text/html"||E==="application/xhtml+xml"||!E&&v.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(N)){let T=n?n.replace(/\/[^/]+$/,"/"):this.pubURL,k={url:ne(jn(N),T),index:d++,startPage:null,skipPagesBefore:null};v.rel==="contents"&&h===-1&&(h=k.index),u.push(k)}})});let f=I("initWithWebPubManifest");return this.initWithChapters(u).then(()=>{var v,y;h!==-1&&(this.toc=this.items[h]),this.toc||(this.toc=n?(v=this.items)==null?void 0:v[0]:this.itemMapByPath[l]);let C=(y=t.readingOrder)==null?void 0:y.length;C&&C<this.items.length&&this.items.splice(C),f.finish(!0)}),f.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 ci;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 Jn("resolveFragment",e=>{if(!t){e.finish(null);return}let n=new ci;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)=>{D.warn(n,"Cannot resolve fragment:",t),e.finish(null)})}resolveEPage(t){return Jn("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=Mt(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)=>{D.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()}},mu=(i,t)=>({page:i,position:{spineIndex:i.spineIndex,pageIndex:t,offsetInItem:i.offset}}),bu=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=Za(s),this.clientLayout=new Zc(e),this.counterStore=new pl(t.documentURLTransformer),this.cmykStore=new ai,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=nt("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){D.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=gu(s));let o=gu(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},x=QE(h.instance.pageGroupPageCounts),C=h.instance.currentPageGroupDocument,v=h.instance.scopes;h.instance.scopes={};let y=d.pageIndex<h.pages.length-1,N=!!h.pages[d.pageIndex]&&y,E=N?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=>{N&&h.instance.endIsolatedRootPageFloatLayoutContext(E);let L=f.currentPageType;f.currentPageType=m.currentPageType,f.previousPageType=m.previousPageType,g.currentPageType=b.currentPageType,g.previousPageType=b.previousPageType,h.instance.pageGroupPageCounts=x,h.instance.currentPageGroupDocument=C,h.instance.scopes=v;let V=gu(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,ee=h.pages.length,ve=h.layoutPositions[ee],le=h.instance.hasActiveRootPageFloatLayoutContext();if(ve&&!le){let F=J?gu(this.counterStore.currentPageCounters):null;J&&(this.counterStore.currentPageCounters=V);let H=ee;this.renderSinglePage(h,ve).then(()=>{J&&this.markSpineItemCompleteIfReady(h);let Y=h.pages.length-H;if(J&&Y>0){this.counterStore.adjustPageCountersOfLaterSpines(h.item.spineIndex,Y),this.counterStore.updateTargetCounterNodesInPages(h.pages);let z=h.item.spineIndex;for(let U=z+1;U<this.spineItems.length;U++){let q=this.spineItems[U];if(q){q.item.epage+=Y;for(let Ne of q.pageCounterStarts)Ne!=null&&Ne.page&&(Ne.page=Ne.page.map(Ve=>Ve+Y));this.counterStore.updatePageCounterNodesInPages(q.pages,q.pageCounterStarts)}}if(F){let U=F.page;U&&(F.page=U.map(q=>q+Y))}}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:mu(h,d),nextLayoutPosition:e})})}),n.result()}normalizeSeekPosition(t,e){let n=t.pageIndex,s=-1;if(n<0){s=t.offsetInItem;let o=Mt(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(mu(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(mu(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(mu(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(!at(e))return null;let n=e.getAttribute("id");if(!n)return null;let s=ne(`#${n}`,t.xmldoc.url),o=t.xmldoc.document.getElementsByTagName("a");for(let r=0;r<o.length;r++){let a=o.item(r);if(!vt(a))continue;let l=a.getAttribute("href")||a.getAttributeNS("http://www.w3.org/1999/xlink","href");if(l&&ne(l,t.xmldoc.url)===s)return t.xmldoc.getElementOffset(a)}return null}navigateTo(t,e,n){D.debug("Navigate to",t);let s=this.opf.getPathFromURL(wt(t));if(!s){if(this.opf.opfXML&&t.match(/^#epubcfi\(/))s=this.opf.getPathFromURL(this.opf.opfXML.url);else if(t.charAt(0)==="#"){let a=this.opf.documentURLTransformer.restoreURL(t);this.opf.opfXML?(s=this.opf.getPathFromURL(a[0]),s==null&&(s=a[0])):s=a[0],t=a[0]+(a[1]?`#${a[1]}`:"")}if(s==null)return 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",Ks||(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 vr(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=Wu(this.viewport.width,this.viewport.height,n.width,n.height),l=Ps(null,new Ze(a,null),"");r.delayedItems.push(new Fs(s,"transform",l))}return r}makeObjectView(t,e,n,s){let o=e.getAttribute("data"),r=null;if(o){o=ne(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=_u(o),u=_u(a),d=new ut;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"),x=m.getAttribute("value");b&&x&&(d.append("&"),d.append(encodeURIComponent(b)),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",Cs(o)),r.setAttribute("data-adapt-process-children","true")),w(r)}makeMathJaxView(t,e,n,s){let o=rv();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=ne(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 v;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 fs(d.window,h.fontSize,d.pixelRatio,d.root,h.width,h.height));let f=(v=this.spineItems[0])==null?void 0:v.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 y=g&&g.pageCounterStarts[g.pages.length-1],N=y&&y.page;if(N&&N.length)b=N[N.length-1]+1;else{let E=this.counterStore.currentPageCounters.page;b=!E||!E.length?m:E[E.length-1]}}o.skipPagesBefore!==null&&(m+=o.skipPagesBefore,b+=o.skipPagesBefore)}this.counterStore.forceSetPageCounter(b);let x=new js(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 C=this.opf.metadata&&this.opf.metadata[We.title];x.pubTitle=C&&C[0]&&C[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(y=>{y.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 hu(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),Ks||(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 Kb="data-vivliostyle-viewer-status",av="data-vivliostyle-spread-view",ig=(n=>(n.SINGLE_PAGE="singlePage",n.SPREAD="spread",n.AUTO_SPREAD="autoSpread",n))(ig||{}),yu=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",Nd),r("vivliostyle-viewport-css",Td),r("vivliostyle-polyfill-css",Ld),e.setAttribute("data-vivliostyle-viewer-viewport",!0),Ks&&e.setAttribute("data-vivliostyle-debug",!0),e.setAttribute(Kb,"loading"),this.fontMapper=new Yc(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=Gu(),this.pageSizes=[],this.pixelRatioLimit=Wo==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let t=Iu;D.addListener(t.DEBUG,e=>{this.callback({t:"debug",content:e})}),D.addListener(t.INFO,e=>{this.callback({t:"info",content:e})}),D.addListener(t.WARN,e=>{this.callback({t:"warn",content:e})}),D.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(Kb,t);let e=this.getCurrentPageProgression();e&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",e),this.callback({t:"readystatechange"})}}loadPublication(t){Ct.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 Na;a.init(s,o).then(()=>{let l=ne(jn(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){Ct.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 Na;l.init(o,r).then(()=>{let c=e.map((u,d)=>({url:ne(jn(u.url),this.window.location.href),index:d,startPage:u.startPage,skipPagesBefore:u.skipPagesBefore}));this.packageURL=c.map(u=>u.url),this.opf=new Uo(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(()=>(Ct.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=dt[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"&&(Vu(t.userAgentRootURL.replace(/resources\/?$/,"")),Bu(t.userAgentRootURL)),typeof t.rootURL=="string"&&(Vu(t.rootURL),Bu(`${wn}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&&(Pb(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){nt("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?bn(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 fs(this.window,this.fontSize,this.pixelRatio,t,e.width,e.height)}else return new fs(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(av,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=ne(jn(this.cmykReserveMapUrl),wn),n=I("loadCmykReserveMap");return t.loadAsJSON(e).then(s=>{Bg(s)?this.cmykReserveMap=s:(D.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 bu(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 Su),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return w(!0);this.setReadyState("loading"),this.cancelRenderingTask();let t=mi().getScheduler().run(()=>Jn("resize",e=>{if(!this.opf){e.finish(!1);return}this.renderTask=t,Ct.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),Ct.registerEndTiming("render (resize)"),vn&&Tf(this.window)?Rb(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 Su)Ct.registerEndTiming("render (resize)"),D.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 Jn("runCommand",n=>{let s=this.actions[e];s?s.call(this,t).then(()=>{this.callback({t:"done",a:e}),n.finish(!0)}):(D.error("No such action:",e),n.finish(!0))},(n,s)=>{D.error(s,"Error during action:",e),n.finish(!0)})}initEmbed(t){let e=Zb(t),n=null,s=this;hm(()=>{let o=I("commandLoop"),r=mi().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=Zb(o),s.kick(),!0),this.window.adapt_command=s.sendCommand}},ag=(t=>(t.FIT_INSIDE_VIEWPORT="fit inside viewport",t))(ag||{}),Su=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 Zb(i){return typeof i=="string"?$o(i):i}var Qb=Zs;function cv(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Jb(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 Ta=class{constructor(t,e){this.settings=t;p(this,"initialized",!1);p(this,"adaptViewer_");p(this,"options");p(this,"eventTarget");p(this,"readyState");ku(t.debug),this.adaptViewer_=new yu(t.window||window,t.viewportElement,"main",this.dispatcher.bind(this)),this.options=cv(),e&&this.setOptions(e),this.eventTarget=new ms,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(t){let e=Object.assign({a:"configure"},Jb(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:uv(t)||e,document:o.documentObject,fragment:o.fragment,authorStyleSheet:a,userStyleSheet:l,cmykReserveMapUrl:o.cmykReserveMapUrl},Jb(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()===Qb.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Qb.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 uv(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 ey=(a=>(a.PREVIOUS="previous",a.NEXT="next",a.LEFT="left",a.RIGHT="right",a.FIRST="first",a.LAST="last",a.EPAGE="epage",a))(ey||{}),dv=ag,pv=ig;Ct.forceRegisterEndTiming("load_vivliostyle");var lg=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=`
1850
1874
  <!DOCTYPE html>
1851
1875
  <html data-vivliostyle-paginated="true">
1852
1876
  <head>
@@ -1874,6 +1898,6 @@ span[data-viv-leader] {
1874
1898
  <body onload='parent.printInstance.runInIframe(window)'>
1875
1899
  <div id="vivliostyle-viewer-viewport"></div>
1876
1900
  </body>
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()}
1901
+ </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 Ta({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(`
1902
+ `);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 hv(i,t){new lg(i,t).init()}
1879
1903
  //# sourceMappingURL=vivliostyle.js.map