@vivliostyle/print 2.39.1 → 2.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +23 -22
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.es6.js +23 -22
- package/dist/index.es6.js.map +4 -4
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var Xd=Object.create;var Qn=Object.defineProperty;var qd=Object.getOwnPropertyDescriptor;var Yd=Object.getOwnPropertyNames;var Kd=Object.getPrototypeOf,Zd=Object.prototype.hasOwnProperty;var Jd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Qd=(e,t)=>{for(var i in t)Qn(e,i,{get:t[i],enumerable:!0})},Da=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Yd(t))!Zd.call(e,s)&&s!==i&&Qn(e,s,{get:()=>t[s],enumerable:!(n=qd(t,s))||n.enumerable});return e};var ep=(e,t,i)=>(i=e!=null?Xd(Kd(e)):{},Da(t||!e||!e.__esModule?Qn(i,"default",{value:e,enumerable:!0}):i,e)),tp=e=>Da(Qn({},"__esModule",{value:!0}),e);var Hd=Jd((F0,Ud)=>{"use strict";var ip=Object.create,Dn=Object.defineProperty,np=Object.getOwnPropertyDescriptor,sp=Object.getOwnPropertyNames,rp=Object.getPrototypeOf,op=Object.prototype.hasOwnProperty,wh=e=>{throw TypeError(e)},ap=(e,t,i)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,lp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hp=(e,t)=>{for(var i in t)Dn(e,i,{get:t[i],enumerable:!0})},bh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of sp(t))!op.call(e,s)&&s!==i&&Dn(e,s,{get:()=>t[s],enumerable:!(n=np(t,s))||n.enumerable});return e},up=(e,t,i)=>(i=e!=null?ip(rp(e)):{},bh(t||!e||!e.__esModule?Dn(i,"default",{value:e,enumerable:!0}):i,e)),cp=e=>bh(Dn({},"__esModule",{value:!0}),e),c=(e,t,i)=>ap(e,typeof t!="symbol"?t+"":t,i),Go=(e,t,i)=>t.has(e)||wh("Cannot "+i),X=(e,t,i)=>(Go(e,t,"read from private field"),i?i.call(e):t.get(e)),ue=(e,t,i)=>t.has(e)?wh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),mt=(e,t,i,n)=>(Go(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ee=(e,t,i)=>(Go(e,t,"access private method"),i),dp=lp((e,t)=>{var i=-1,n=1,s=0;function r(x,O,S,P,k){if(x===O)return x?[[s,x]]:[];if(S!=null){var R=at(x,O,S);if(R)return R}var L=h(x,O),z=x.substring(0,L);x=x.substring(L),O=O.substring(L),L=d(x,O);var $=x.substring(x.length-L);x=x.substring(0,x.length-L),O=O.substring(0,O.length-L);var q=o(x,O);return z&&q.unshift([s,z]),$&&q.push([s,$]),E(q,k),P&&f(q),q}function o(x,O){var S;if(!x)return[[n,O]];if(!O)return[[i,x]];var P=x.length>O.length?x:O,k=x.length>O.length?O:x,R=P.indexOf(k);if(R!==-1)return S=[[n,P.substring(0,R)],[s,k],[n,P.substring(R+k.length)]],x.length>O.length&&(S[0][0]=S[2][0]=i),S;if(k.length===1)return[[i,x],[n,O]];var L=p(x,O);if(L){var z=L[0],$=L[1],q=L[2],Z=L[3],J=L[4],we=r(z,q),ee=r($,Z);return we.concat([[s,J]],ee)}return a(x,O)}function a(x,O){for(var S=x.length,P=O.length,k=Math.ceil((S+P)/2),R=k,L=2*k,z=new Array(L),$=new Array(L),q=0;q<L;q++)z[q]=-1,$[q]=-1;z[R+1]=0,$[R+1]=0;for(var Z=S-P,J=Z%2!==0,we=0,ee=0,be=0,Se=0,le=0;le<k;le++){for(var W=-le+we;W<=le-ee;W+=2){var ce=R+W,de;W===-le||W!==le&&z[ce-1]<z[ce+1]?de=z[ce+1]:de=z[ce-1]+1;for(var M=de-W;de<S&&M<P&&x.charAt(de)===O.charAt(M);)de++,M++;if(z[ce]=de,de>S)ee+=2;else if(M>P)we+=2;else if(J){var ne=R+Z-W;if(ne>=0&&ne<L&&$[ne]!==-1){var se=S-$[ne];if(de>=se)return l(x,O,de,M)}}}for(var ye=-le+be;ye<=le-Se;ye+=2){var ne=R+ye,se;ye===-le||ye!==le&&$[ne-1]<$[ne+1]?se=$[ne+1]:se=$[ne-1]+1;for(var lt=se-ye;se<S&<<P&&x.charAt(S-se-1)===O.charAt(P-lt-1);)se++,lt++;if($[ne]=se,se>S)Se+=2;else if(lt>P)be+=2;else if(!J){var ce=R+Z-ye;if(ce>=0&&ce<L&&z[ce]!==-1){var de=z[ce],M=R+de-ce;if(se=S-se,de>=se)return l(x,O,de,M)}}}}return[[i,x],[n,O]]}function l(x,O,S,P){var k=x.substring(0,S),R=O.substring(0,P),L=x.substring(S),z=O.substring(P),$=r(k,R),q=r(L,z);return $.concat(q)}function h(x,O){if(!x||!O||x.charAt(0)!==O.charAt(0))return 0;for(var S=0,P=Math.min(x.length,O.length),k=P,R=0;S<k;)x.substring(R,k)==O.substring(R,k)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return A(x.charCodeAt(k-1))&&k--,k}function u(x,O){var S=x.length,P=O.length;if(S==0||P==0)return 0;S>P?x=x.substring(S-P):S<P&&(O=O.substring(0,S));var k=Math.min(S,P);if(x==O)return k;for(var R=0,L=1;;){var z=x.substring(k-L),$=O.indexOf(z);if($==-1)return R;L+=$,($==0||x.substring(k-L)==O.substring(0,L))&&(R=L,L++)}}function d(x,O){if(!x||!O||x.slice(-1)!==O.slice(-1))return 0;for(var S=0,P=Math.min(x.length,O.length),k=P,R=0;S<k;)x.substring(x.length-k,x.length-R)==O.substring(O.length-k,O.length-R)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return V(x.charCodeAt(x.length-k))&&k--,k}function p(x,O){var S=x.length>O.length?x:O,P=x.length>O.length?O:x;if(S.length<4||P.length*2<S.length)return null;function k(ee,be,Se){for(var le=ee.substring(Se,Se+Math.floor(ee.length/4)),W=-1,ce="",de,M,ne,se;(W=be.indexOf(le,W+1))!==-1;){var ye=h(ee.substring(Se),be.substring(W)),lt=d(ee.substring(0,Se),be.substring(0,W));ce.length<lt+ye&&(ce=be.substring(W-lt,W)+be.substring(W,W+ye),de=ee.substring(0,Se-lt),M=ee.substring(Se+ye),ne=be.substring(0,W-lt),se=be.substring(W+ye))}return ce.length*2>=ee.length?[de,M,ne,se,ce]:null}var R=k(S,P,Math.ceil(S.length/4)),L=k(S,P,Math.ceil(S.length/2)),z;if(!R&&!L)return null;L?R?z=R[4].length>L[4].length?R:L:z=L:z=R;var $,q,Z,J;x.length>O.length?($=z[0],q=z[1],Z=z[2],J=z[3]):(Z=z[0],J=z[1],$=z[2],q=z[3]);var we=z[4];return[$,q,Z,J,we]}function f(x){for(var O=!1,S=[],P=0,k=null,R=0,L=0,z=0,$=0,q=0;R<x.length;)x[R][0]==s?(S[P++]=R,L=$,z=q,$=0,q=0,k=x[R][1]):(x[R][0]==n?$+=x[R][1].length:q+=x[R][1].length,k&&k.length<=Math.max(L,z)&&k.length<=Math.max($,q)&&(x.splice(S[P-1],0,[i,k]),x[S[P-1]+1][0]=n,P--,P--,R=P>0?S[P-1]:-1,L=0,z=0,$=0,q=0,k=null,O=!0)),R++;for(O&&E(x),C(x),R=1;R<x.length;){if(x[R-1][0]==i&&x[R][0]==n){var Z=x[R-1][1],J=x[R][1],we=u(Z,J),ee=u(J,Z);we>=ee?(we>=Z.length/2||we>=J.length/2)&&(x.splice(R,0,[s,J.substring(0,we)]),x[R-1][1]=Z.substring(0,Z.length-we),x[R+1][1]=J.substring(we),R++):(ee>=Z.length/2||ee>=J.length/2)&&(x.splice(R,0,[s,Z.substring(0,ee)]),x[R-1][0]=n,x[R-1][1]=J.substring(0,J.length-ee),x[R+1][0]=i,x[R+1][1]=Z.substring(ee),R++),R++}R++}}var m=/[^a-zA-Z0-9]/,g=/\s/,w=/[\r\n]/,v=/\n\r?\n$/,b=/^\r?\n\r?\n/;function C(x){function O(ee,be){if(!ee||!be)return 6;var Se=ee.charAt(ee.length-1),le=be.charAt(0),W=Se.match(m),ce=le.match(m),de=W&&Se.match(g),M=ce&&le.match(g),ne=de&&Se.match(w),se=M&&le.match(w),ye=ne&&ee.match(v),lt=se&&be.match(b);return ye||lt?5:ne||se?4:W&&!de&&M?3:de||M?2:W||ce?1:0}for(var S=1;S<x.length-1;){if(x[S-1][0]==s&&x[S+1][0]==s){var P=x[S-1][1],k=x[S][1],R=x[S+1][1],L=d(P,k);if(L){var z=k.substring(k.length-L);P=P.substring(0,P.length-L),k=z+k.substring(0,k.length-L),R=z+R}for(var $=P,q=k,Z=R,J=O(P,k)+O(k,R);k.charAt(0)===R.charAt(0);){P+=k.charAt(0),k=k.substring(1)+R.charAt(0),R=R.substring(1);var we=O(P,k)+O(k,R);we>=J&&(J=we,$=P,q=k,Z=R)}x[S-1][1]!=$&&($?x[S-1][1]=$:(x.splice(S-1,1),S--),x[S][1]=q,Z?x[S+1][1]=Z:(x.splice(S+1,1),S--))}S++}}function E(x,O){x.push([s,""]);for(var S=0,P=0,k=0,R="",L="",z;S<x.length;){if(S<x.length-1&&!x[S][1]){x.splice(S,1);continue}switch(x[S][0]){case n:k++,L+=x[S][1],S++;break;case i:P++,R+=x[S][1],S++;break;case s:var $=S-k-P-1;if(O){if($>=0&&te(x[$][1])){var q=x[$][1].slice(-1);if(x[$][1]=x[$][1].slice(0,-1),R=q+R,L=q+L,!x[$][1]){x.splice($,1),S--;var Z=$-1;x[Z]&&x[Z][0]===n&&(k++,L=x[Z][1]+L,Z--),x[Z]&&x[Z][0]===i&&(P++,R=x[Z][1]+R,Z--),$=Z}}if(D(x[S][1])){var q=x[S][1].charAt(0);x[S][1]=x[S][1].slice(1),R+=q,L+=q}}if(S<x.length-1&&!x[S][1]){x.splice(S,1);break}if(R.length>0||L.length>0){R.length>0&&L.length>0&&(z=h(L,R),z!==0&&($>=0?x[$][1]+=L.substring(0,z):(x.splice(0,0,[s,L.substring(0,z)]),S++),L=L.substring(z),R=R.substring(z)),z=d(L,R),z!==0&&(x[S][1]=L.substring(L.length-z)+x[S][1],L=L.substring(0,L.length-z),R=R.substring(0,R.length-z)));var J=k+P;R.length===0&&L.length===0?(x.splice(S-J,J),S=S-J):R.length===0?(x.splice(S-J,J,[n,L]),S=S-J+1):L.length===0?(x.splice(S-J,J,[i,R]),S=S-J+1):(x.splice(S-J,J,[i,R],[n,L]),S=S-J+2)}S!==0&&x[S-1][0]===s?(x[S-1][1]+=x[S][1],x.splice(S,1)):S++,k=0,P=0,R="",L="";break}}x[x.length-1][1]===""&&x.pop();var we=!1;for(S=1;S<x.length-1;)x[S-1][0]===s&&x[S+1][0]===s&&(x[S][1].substring(x[S][1].length-x[S-1][1].length)===x[S-1][1]?(x[S][1]=x[S-1][1]+x[S][1].substring(0,x[S][1].length-x[S-1][1].length),x[S+1][1]=x[S-1][1]+x[S+1][1],x.splice(S-1,1),we=!0):x[S][1].substring(0,x[S+1][1].length)==x[S+1][1]&&(x[S-1][1]+=x[S+1][1],x[S][1]=x[S][1].substring(x[S+1][1].length)+x[S+1][1],x.splice(S+1,1),we=!0)),S++;we&&E(x,O)}function A(x){return x>=55296&&x<=56319}function V(x){return x>=56320&&x<=57343}function D(x){return V(x.charCodeAt(0))}function te(x){return A(x.charCodeAt(x.length-1))}function ie(x){for(var O=[],S=0;S<x.length;S++)x[S][1].length>0&&O.push(x[S]);return O}function je(x,O,S,P){return te(x)||D(P)?null:ie([[s,x],[i,O],[n,S],[s,P]])}function at(x,O,S){var P=typeof S=="number"?{index:S,length:0}:S.oldRange,k=typeof S=="number"?null:S.newRange,R=x.length,L=O.length;if(P.length===0&&(k===null||k.length===0)){var z=P.index,$=x.slice(0,z),q=x.slice(z),Z=k?k.index:null;e:{var J=z+L-R;if(Z!==null&&Z!==J||J<0||J>L)break e;var we=O.slice(0,J),ee=O.slice(J);if(ee!==q)break e;var be=Math.min(z,J),Se=$.slice(0,be),le=we.slice(0,be);if(Se!==le)break e;var W=$.slice(be),ce=we.slice(be);return je(Se,W,ce,q)}e:{if(Z!==null&&Z!==z)break e;var de=z,we=O.slice(0,de),ee=O.slice(de);if(we!==$)break e;var M=Math.min(R-de,L-de),ne=q.slice(q.length-M),se=ee.slice(ee.length-M);if(ne!==se)break e;var W=q.slice(0,q.length-M),ce=ee.slice(0,ee.length-M);return je($,W,ce,ne)}}if(P.length>0&&k&&k.length===0)e:{var Se=x.slice(0,P.index),ne=x.slice(P.index+P.length),be=Se.length,M=ne.length;if(L<be+M)break e;var le=O.slice(0,be),se=O.slice(L-M);if(Se!==le||ne!==se)break e;var W=x.slice(be,R-M),ce=O.slice(be,L-M);return je(Se,W,ce,ne)}return null}function xe(x,O,S,P){return r(x,O,S,P,!0)}xe.INSERT=n,xe.DELETE=i,xe.EQUAL=s,t.exports=xe}),yh={};hp(yh,{CoreViewer:()=>Dd,HOOKS:()=>Ys,Navigation:()=>Vd,PageProgression:()=>jo,PageSide:()=>Sh,PageViewMode:()=>w0,Profiler:()=>Nh,ReadyState:()=>Ch,UserAgentBaseCss:()=>bu,UserAgentCounterStylesCss:()=>xu,UserAgentPageCss:()=>wu,UserAgentTocCss:()=>yu,UserAgentXml:()=>mu,ValidationTxt:()=>gu,VivliostylePolyfillCss:()=>vu,VivliostyleViewportCss:()=>fu,VivliostyleViewportScreenCss:()=>pu,ZoomType:()=>m0,getHooksForName:()=>It,isDebug:()=>An,pageProgressionOf:()=>xh,plugin:()=>fp,printHTML:()=>y0,profile:()=>bp,profiler:()=>ct,registerHook:()=>Ct,removeHook:()=>Eh,setDebug:()=>vh});Ud.exports=cp(yh);var An=!1;function vh(e){An=e}var jo=(e=>(e.LTR="ltr",e.RTL="rtl",e))(jo||{});function xh(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Sh=(e=>(e.LEFT="left",e.RIGHT="right",e))(Sh||{}),Ch=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Ch||{}),kh=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(kh||{}),pp=class{constructor(e){this.opt_console=e,c(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=es(arguments);this.consoleDebug(ts(t)),this.triggerListeners(1,t)}info(...e){let t=es(arguments);this.consoleInfo(ts(t)),this.triggerListeners(2,t)}warn(...e){let t=es(arguments);this.consoleWarn(ts(t)),this.triggerListeners(3,t)}error(...e){let t=es(arguments);this.consoleError(ts(t)),this.triggerListeners(4,t)}};function es(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function ts(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
|
|
1
|
+
var wp=Object.create;var gr=Object.defineProperty;var yp=Object.getOwnPropertyDescriptor;var bp=Object.getOwnPropertyNames;var vp=Object.getPrototypeOf,xp=Object.prototype.hasOwnProperty;var Sp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Cp=(e,t)=>{for(var i in t)gr(e,i,{get:t[i],enumerable:!0})},il=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of bp(t))!xp.call(e,r)&&r!==i&&gr(e,r,{get:()=>t[r],enumerable:!(n=yp(t,r))||n.enumerable});return e};var kp=(e,t,i)=>(i=e!=null?wp(vp(e)):{},il(t||!e||!e.__esModule?gr(i,"default",{value:e,enumerable:!0}):i,e)),Ep=e=>il(gr({},"__esModule",{value:!0}),e);var dp=Sp((nv,cp)=>{"use strict";var Np=Object.create,tr=Object.defineProperty,Pp=Object.getOwnPropertyDescriptor,Tp=Object.getOwnPropertyNames,Ip=Object.getPrototypeOf,Ap=Object.prototype.hasOwnProperty,Mh=e=>{throw TypeError(e)},Rp=(e,t,i)=>t in e?tr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Fp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Lp=(e,t)=>{for(var i in t)tr(e,i,{get:t[i],enumerable:!0})},_h=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Tp(t))!Ap.call(e,r)&&r!==i&&tr(e,r,{get:()=>t[r],enumerable:!(n=Pp(t,r))||n.enumerable});return e},Op=(e,t,i)=>(i=e!=null?Np(Ip(e)):{},_h(t||!e||!e.__esModule?tr(i,"default",{value:e,enumerable:!0}):i,e)),Bp=e=>_h(tr({},"__esModule",{value:!0}),e),c=(e,t,i)=>Rp(e,typeof t!="symbol"?t+"":t,i),aa=(e,t,i)=>t.has(e)||Mh("Cannot "+i),M=(e,t,i)=>(aa(e,t,"read from private field"),i?i.call(e):t.get(e)),Z=(e,t,i)=>t.has(e)?Mh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Fe=(e,t,i,n)=>(aa(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Se=(e,t,i)=>(aa(e,t,"access private method"),i),Mp=Fp((e,t)=>{var i=-1,n=1,r=0;function s(x,B,S,P,k){if(x===B)return x?[[r,x]]:[];if(S!=null){var R=ht(x,B,S);if(R)return R}var L=h(x,B),D=x.substring(0,L);x=x.substring(L),B=B.substring(L),L=d(x,B);var W=x.substring(x.length-L);x=x.substring(0,x.length-L),B=B.substring(0,B.length-L);var q=o(x,B);return D&&q.unshift([r,D]),W&&q.push([r,W]),E(q,k),P&&f(q),q}function o(x,B){var S;if(!x)return[[n,B]];if(!B)return[[i,x]];var P=x.length>B.length?x:B,k=x.length>B.length?B:x,R=P.indexOf(k);if(R!==-1)return S=[[n,P.substring(0,R)],[r,k],[n,P.substring(R+k.length)]],x.length>B.length&&(S[0][0]=S[2][0]=i),S;if(k.length===1)return[[i,x],[n,B]];var L=p(x,B);if(L){var D=L[0],W=L[1],q=L[2],Q=L[3],ee=L[4],we=s(D,q),te=s(W,Q);return we.concat([[r,ee]],te)}return a(x,B)}function a(x,B){for(var S=x.length,P=B.length,k=Math.ceil((S+P)/2),R=k,L=2*k,D=new Array(L),W=new Array(L),q=0;q<L;q++)D[q]=-1,W[q]=-1;D[R+1]=0,W[R+1]=0;for(var Q=S-P,ee=Q%2!==0,we=0,te=0,ye=0,Ce=0,he=0;he<k;he++){for(var G=-he+we;G<=he-te;G+=2){var ce=R+G,de;G===-he||G!==he&&D[ce-1]<D[ce+1]?de=D[ce+1]:de=D[ce-1]+1;for(var z=de-G;de<S&&z<P&&x.charAt(de)===B.charAt(z);)de++,z++;if(D[ce]=de,de>S)te+=2;else if(z>P)we+=2;else if(ee){var re=R+Q-G;if(re>=0&&re<L&&W[re]!==-1){var se=S-W[re];if(de>=se)return l(x,B,de,z)}}}for(var be=-he+ye;be<=he-Ce;be+=2){var re=R+be,se;be===-he||be!==he&&W[re-1]<W[re+1]?se=W[re+1]:se=W[re-1]+1;for(var ut=se-be;se<S&&ut<P&&x.charAt(S-se-1)===B.charAt(P-ut-1);)se++,ut++;if(W[re]=se,se>S)Ce+=2;else if(ut>P)ye+=2;else if(!ee){var ce=R+Q-be;if(ce>=0&&ce<L&&D[ce]!==-1){var de=D[ce],z=R+de-ce;if(se=S-se,de>=se)return l(x,B,de,z)}}}}return[[i,x],[n,B]]}function l(x,B,S,P){var k=x.substring(0,S),R=B.substring(0,P),L=x.substring(S),D=B.substring(P),W=s(k,R),q=s(L,D);return W.concat(q)}function h(x,B){if(!x||!B||x.charAt(0)!==B.charAt(0))return 0;for(var S=0,P=Math.min(x.length,B.length),k=P,R=0;S<k;)x.substring(R,k)==B.substring(R,k)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return A(x.charCodeAt(k-1))&&k--,k}function u(x,B){var S=x.length,P=B.length;if(S==0||P==0)return 0;S>P?x=x.substring(S-P):S<P&&(B=B.substring(0,S));var k=Math.min(S,P);if(x==B)return k;for(var R=0,L=1;;){var D=x.substring(k-L),W=B.indexOf(D);if(W==-1)return R;L+=W,(W==0||x.substring(k-L)==B.substring(0,L))&&(R=L,L++)}}function d(x,B){if(!x||!B||x.slice(-1)!==B.slice(-1))return 0;for(var S=0,P=Math.min(x.length,B.length),k=P,R=0;S<k;)x.substring(x.length-k,x.length-R)==B.substring(B.length-k,B.length-R)?(S=k,R=S):P=k,k=Math.floor((P-S)/2+S);return H(x.charCodeAt(x.length-k))&&k--,k}function p(x,B){var S=x.length>B.length?x:B,P=x.length>B.length?B:x;if(S.length<4||P.length*2<S.length)return null;function k(te,ye,Ce){for(var he=te.substring(Ce,Ce+Math.floor(te.length/4)),G=-1,ce="",de,z,re,se;(G=ye.indexOf(he,G+1))!==-1;){var be=h(te.substring(Ce),ye.substring(G)),ut=d(te.substring(0,Ce),ye.substring(0,G));ce.length<ut+be&&(ce=ye.substring(G-ut,G)+ye.substring(G,G+be),de=te.substring(0,Ce-ut),z=te.substring(Ce+be),re=ye.substring(0,G-ut),se=ye.substring(G+be))}return ce.length*2>=te.length?[de,z,re,se,ce]:null}var R=k(S,P,Math.ceil(S.length/4)),L=k(S,P,Math.ceil(S.length/2)),D;if(!R&&!L)return null;L?R?D=R[4].length>L[4].length?R:L:D=L:D=R;var W,q,Q,ee;x.length>B.length?(W=D[0],q=D[1],Q=D[2],ee=D[3]):(Q=D[0],ee=D[1],W=D[2],q=D[3]);var we=D[4];return[W,q,Q,ee,we]}function f(x){for(var B=!1,S=[],P=0,k=null,R=0,L=0,D=0,W=0,q=0;R<x.length;)x[R][0]==r?(S[P++]=R,L=W,D=q,W=0,q=0,k=x[R][1]):(x[R][0]==n?W+=x[R][1].length:q+=x[R][1].length,k&&k.length<=Math.max(L,D)&&k.length<=Math.max(W,q)&&(x.splice(S[P-1],0,[i,k]),x[S[P-1]+1][0]=n,P--,P--,R=P>0?S[P-1]:-1,L=0,D=0,W=0,q=0,k=null,B=!0)),R++;for(B&&E(x),C(x),R=1;R<x.length;){if(x[R-1][0]==i&&x[R][0]==n){var Q=x[R-1][1],ee=x[R][1],we=u(Q,ee),te=u(ee,Q);we>=te?(we>=Q.length/2||we>=ee.length/2)&&(x.splice(R,0,[r,ee.substring(0,we)]),x[R-1][1]=Q.substring(0,Q.length-we),x[R+1][1]=ee.substring(we),R++):(te>=Q.length/2||te>=ee.length/2)&&(x.splice(R,0,[r,Q.substring(0,te)]),x[R-1][0]=n,x[R-1][1]=ee.substring(0,ee.length-te),x[R+1][0]=i,x[R+1][1]=Q.substring(te),R++),R++}R++}}var m=/[^a-zA-Z0-9]/,g=/\s/,w=/[\r\n]/,v=/\n\r?\n$/,y=/^\r?\n\r?\n/;function C(x){function B(te,ye){if(!te||!ye)return 6;var Ce=te.charAt(te.length-1),he=ye.charAt(0),G=Ce.match(m),ce=he.match(m),de=G&&Ce.match(g),z=ce&&he.match(g),re=de&&Ce.match(w),se=z&&he.match(w),be=re&&te.match(v),ut=se&&ye.match(y);return be||ut?5:re||se?4:G&&!de&&z?3:de||z?2:G||ce?1:0}for(var S=1;S<x.length-1;){if(x[S-1][0]==r&&x[S+1][0]==r){var P=x[S-1][1],k=x[S][1],R=x[S+1][1],L=d(P,k);if(L){var D=k.substring(k.length-L);P=P.substring(0,P.length-L),k=D+k.substring(0,k.length-L),R=D+R}for(var W=P,q=k,Q=R,ee=B(P,k)+B(k,R);k.charAt(0)===R.charAt(0);){P+=k.charAt(0),k=k.substring(1)+R.charAt(0),R=R.substring(1);var we=B(P,k)+B(k,R);we>=ee&&(ee=we,W=P,q=k,Q=R)}x[S-1][1]!=W&&(W?x[S-1][1]=W:(x.splice(S-1,1),S--),x[S][1]=q,Q?x[S+1][1]=Q:(x.splice(S+1,1),S--))}S++}}function E(x,B){x.push([r,""]);for(var S=0,P=0,k=0,R="",L="",D;S<x.length;){if(S<x.length-1&&!x[S][1]){x.splice(S,1);continue}switch(x[S][0]){case n:k++,L+=x[S][1],S++;break;case i:P++,R+=x[S][1],S++;break;case r:var W=S-k-P-1;if(B){if(W>=0&&ie(x[W][1])){var q=x[W][1].slice(-1);if(x[W][1]=x[W][1].slice(0,-1),R=q+R,L=q+L,!x[W][1]){x.splice(W,1),S--;var Q=W-1;x[Q]&&x[Q][0]===n&&(k++,L=x[Q][1]+L,Q--),x[Q]&&x[Q][0]===i&&(P++,R=x[Q][1]+R,Q--),W=Q}}if(V(x[S][1])){var q=x[S][1].charAt(0);x[S][1]=x[S][1].slice(1),R+=q,L+=q}}if(S<x.length-1&&!x[S][1]){x.splice(S,1);break}if(R.length>0||L.length>0){R.length>0&&L.length>0&&(D=h(L,R),D!==0&&(W>=0?x[W][1]+=L.substring(0,D):(x.splice(0,0,[r,L.substring(0,D)]),S++),L=L.substring(D),R=R.substring(D)),D=d(L,R),D!==0&&(x[S][1]=L.substring(L.length-D)+x[S][1],L=L.substring(0,L.length-D),R=R.substring(0,R.length-D)));var ee=k+P;R.length===0&&L.length===0?(x.splice(S-ee,ee),S=S-ee):R.length===0?(x.splice(S-ee,ee,[n,L]),S=S-ee+1):L.length===0?(x.splice(S-ee,ee,[i,R]),S=S-ee+1):(x.splice(S-ee,ee,[i,R],[n,L]),S=S-ee+2)}S!==0&&x[S-1][0]===r?(x[S-1][1]+=x[S][1],x.splice(S,1)):S++,k=0,P=0,R="",L="";break}}x[x.length-1][1]===""&&x.pop();var we=!1;for(S=1;S<x.length-1;)x[S-1][0]===r&&x[S+1][0]===r&&(x[S][1].substring(x[S][1].length-x[S-1][1].length)===x[S-1][1]?(x[S][1]=x[S-1][1]+x[S][1].substring(0,x[S][1].length-x[S-1][1].length),x[S+1][1]=x[S-1][1]+x[S+1][1],x.splice(S-1,1),we=!0):x[S][1].substring(0,x[S+1][1].length)==x[S+1][1]&&(x[S-1][1]+=x[S+1][1],x[S][1]=x[S][1].substring(x[S+1][1].length)+x[S+1][1],x.splice(S+1,1),we=!0)),S++;we&&E(x,B)}function A(x){return x>=55296&&x<=56319}function H(x){return x>=56320&&x<=57343}function V(x){return H(x.charCodeAt(0))}function ie(x){return A(x.charCodeAt(x.length-1))}function ne(x){for(var B=[],S=0;S<x.length;S++)x[S][1].length>0&&B.push(x[S]);return B}function Xe(x,B,S,P){return ie(x)||V(P)?null:ne([[r,x],[i,B],[n,S],[r,P]])}function ht(x,B,S){var P=typeof S=="number"?{index:S,length:0}:S.oldRange,k=typeof S=="number"?null:S.newRange,R=x.length,L=B.length;if(P.length===0&&(k===null||k.length===0)){var D=P.index,W=x.slice(0,D),q=x.slice(D),Q=k?k.index:null;e:{var ee=D+L-R;if(Q!==null&&Q!==ee||ee<0||ee>L)break e;var we=B.slice(0,ee),te=B.slice(ee);if(te!==q)break e;var ye=Math.min(D,ee),Ce=W.slice(0,ye),he=we.slice(0,ye);if(Ce!==he)break e;var G=W.slice(ye),ce=we.slice(ye);return Xe(Ce,G,ce,q)}e:{if(Q!==null&&Q!==D)break e;var de=D,we=B.slice(0,de),te=B.slice(de);if(we!==W)break e;var z=Math.min(R-de,L-de),re=q.slice(q.length-z),se=te.slice(te.length-z);if(re!==se)break e;var G=q.slice(0,q.length-z),ce=te.slice(0,te.length-z);return Xe(W,G,ce,re)}}if(P.length>0&&k&&k.length===0)e:{var Ce=x.slice(0,P.index),re=x.slice(P.index+P.length),ye=Ce.length,z=re.length;if(L<ye+z)break e;var he=B.slice(0,ye),se=B.slice(L-z);if(Ce!==he||re!==se)break e;var G=x.slice(ye,R-z),ce=B.slice(ye,L-z);return Xe(Ce,G,ce,re)}return null}function xe(x,B,S,P){return s(x,B,S,P,!0)}xe.INSERT=n,xe.DELETE=i,xe.EQUAL=r,t.exports=xe}),zh={};Lp(zh,{CoreViewer:()=>hp,HOOKS:()=>ps,Navigation:()=>up,PageProgression:()=>la,PageSide:()=>Hh,PageViewMode:()=>U0,Profiler:()=>Gh,ReadyState:()=>Uh,UserAgentBaseCss:()=>$u,UserAgentCounterStylesCss:()=>ju,UserAgentPageCss:()=>Uu,UserAgentTocCss:()=>Wu,UserAgentXml:()=>Hu,ValidationTxt:()=>Vu,VivliostylePolyfillCss:()=>Gu,VivliostyleViewportCss:()=>Du,VivliostyleViewportScreenCss:()=>zu,ZoomType:()=>H0,getHooksForName:()=>Rt,isDebug:()=>Gn,pageProgressionOf:()=>Vh,plugin:()=>zp,printHTML:()=>W0,profile:()=>Up,profiler:()=>pt,registerHook:()=>Nt,removeHook:()=>Wh,setDebug:()=>Dh});cp.exports=Bp(zh);var Gn=!1;function Dh(e){Gn=e}var la=(e=>(e.LTR="ltr",e.RTL="rtl",e))(la||{});function Vh(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var Hh=(e=>(e.LEFT="left",e.RIGHT="right",e))(Hh||{}),Uh=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Uh||{}),$h=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))($h||{}),_p=class{constructor(e){this.opt_console=e,c(this,"listeners",{})}consoleDebug(e){this.opt_console?this.opt_console.debug?this.opt_console.debug(...e):this.opt_console.log(...e):console.debug(...e)}consoleInfo(e){this.opt_console?this.opt_console.info?this.opt_console.info(...e):this.opt_console.log(...e):console.info(...e)}consoleWarn(e){this.opt_console?this.opt_console.warn?this.opt_console.warn(...e):this.opt_console.log(...e):console.warn(...e)}consoleError(e){this.opt_console?this.opt_console.error?this.opt_console.error(...e):this.opt_console.log(...e):console.error(...e)}triggerListeners(e,t){let i=this.listeners[e];i&&i(t)}addListener(e,t){this.listeners[e]=t}debug(...e){let t=mr(arguments);this.consoleDebug(wr(t)),this.triggerListeners(1,t)}info(...e){let t=mr(arguments);this.consoleInfo(wr(t)),this.triggerListeners(2,t)}warn(...e){let t=mr(arguments);this.consoleWarn(wr(t)),this.triggerListeners(3,t)}error(...e){let t=mr(arguments);this.consoleError(wr(t)),this.triggerListeners(4,t)}};function mr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function wr(e){let t=e.error,i=t&&(t.frameTrace||t.stack),n=[].concat(e.messages);return t&&(n.length>0&&(n=n.concat([`
|
|
2
2
|
`])),n=n.concat([t.toString()]),i&&(n=n.concat([`
|
|
3
|
-
`]).concat(i))),n}var
|
|
4
|
-
`}}),H.info(t)}disable(){this.registerTiming=Si,this.registerStartTiming=this.registerStartTiming=Si,this.registerEndTiming=this.registerEndTiming=Si}enable(){this.registerTiming=fr,this.registerStartTiming=this.registerStartTiming=Va,this.registerEndTiming=this.registerEndTiming=gp}isEnabled(){return this.registerStartTiming===Va}};function Si(){}function fr(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let s,r=n.length;for(let o=r-1;o>=0&&(s=n[o],!(s&&!s[t]));o--)s=null;s||(s={},n.push(s)),s[t]=i}function Va(e,t){this.registerTiming(e,"start",t)}function gp(e,t){this.registerTiming(e,"end",t)}var mp={now:Date.now},wp=window&&window.performance,ct=new Nh(wp||mp);ct.forceRegisterStartTiming("load_vivliostyle");var bp={profiler:{registerStartTiming:ct.registerStartTiming,registerEndTiming:ct.registerEndTiming,printTimings:ct.printTimings,disable:ct.disable,enable:ct.enable}},Ph=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",As=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Mt="data-adapt-eloff",yp={};function Xo(e){return JSON.parse(e)}function Dt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function vp(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Gi=window.location.href;function Ua(e){Gi=e}var Qt=window.location.href;function Ha(e){Qt=e}function Pe(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=vp(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let s=t.substr(0,n+1)+e,r="";for(i=s.match(/^([^?#]*)([?#].*)$/),i&&(s=i[1],r=i[2]);n=s.indexOf("/../"),!(n<=0);){let o=s.lastIndexOf("/",n-1);if(o<=0)break;s=s.substr(0,o)+s.substr(n+3)}return s.replace(/\/(\.\/)+/g,"/")+r}function Rn(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function $a(e){return e==null?e:e.toString()}var xp=class{constructor(){c(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let s=n*2;if(s>=i)break;if(this.queue[s].compare(t)>0)s+1<i&&this.queue[s+1].compare(this.queue[s])>0&&s++;else if(s+1<i&&this.queue[s+1].compare(t)>0)s++;else break;this.queue[n]=this.queue[s],n=s}this.queue[n]=t}return e}},Th=["","-webkit-","-moz-"],ki={};function us(e,t){return CSS.supports(e+t,"unset")}function Sp(e){let t=ki[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return ki[e]=null,null;case"text-combine-upright":if(us("-webkit-","text-combine")&&!us("","text-combine-upright"))return ki[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Th)if(us(i,e))return t=[i+e],ki[e]=t,t;return H.warn("Property not supported by the browser: ",e),ki[e]=null,null}function T(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let s=Sp(t);if(s)for(let r of s){switch(r){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(r,i)}}function Kt(e,t,i){try{let n=ki[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function _r(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var ii=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function Ih(e){return`\\${e.charCodeAt(0).toString(16)} `}function ei(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Ih)}function Vn(e){return e.replace(/[\u0000-\u001F"\\]/g,Ih)}function Wa(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Ga(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Cp(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Ah(e,t){function i(n){return Cp(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function qt(e){return Ah(e)}function kp(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Ep(e,t){t=typeof t=="string"?t:"\\u";function i(s){return kp(s,t)}let n=new RegExp(`${qt(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ni(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let s=i+n>>1;t(s)?n=s:i=s+1}}function Rh(e,t){return e-t}function ja(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function Np(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function gr(e,t){let i={};for(let n of e){let s=t(n);s&&(i[s]?i[s].push(n):i[s]=[n])}return i}function Pp(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var qo=class{constructor(){c(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let s=n.indexOf(t);s>=0&&n.splice(s,1)}}},gi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Fh(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Tp(e){return`^${e}`}function Xa(e){return e.replace(/[\[\]\(\),=;^]/g,Tp)}function Ip(e){return e.substr(1)}function Mr(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Ip)}function Ap(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=Mr(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function qa(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Ap(i[2]),e=e.substr(i[0].length)}return t}var Ya=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Ka=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,s,r=Math.floor(this.index/2)-1;if(r<0||n==0)s=t.firstChild,e.node=s||t;else{if(s=i[Math.min(r,n-1)],this.index&1){let o=s.nextSibling;!o||o.nodeType==1?e.after=!0:s=o}e.node=s}if(this.id&&(e.after||this.id!=Fh(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:H.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Za=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let s=i.nextSibling;if(3<=n&&n<=5){let r=i.textContent.length;if(t<=r)break;if(!s){t=r;break}t-=r}if(!s){t=0;break}i=s}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(Xa(this.textBefore)),e.append(","),this.textAfter&&e.append(Xa(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Ja=class Lh{constructor(){c(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),s=0,r=[];for(;;){let o;switch(n.charAt(s)){case"/":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),l=i[3];o=qa(i[4]),r.push(new Ka(a,l,$a(o.s)));break}case":":{if(s++,i=n.substr(s).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");s+=i[0].length;let a=parseInt(i[1],10),l=i[4];l&&(l=Mr(l));let h=i[7];h&&(h=Mr(h)),o=qa(i[10]),r.push(new Za(a,l,h,$a(o.s)));break}case"!":s++,r.push(new Ya);break;case"~":case"@":case"":this.steps=r;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new Lh,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,s){let r=[],o=t.parentNode,a="",l="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let h=t.textContent,u=h.length;n?(i+=u,a||(a=h)):(i>u&&(i=u),n=!0,a=h.substr(0,i),l=h.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||l)&&(a=this.trim(a,!1),l=this.trim(l,!0),r.push(new Za(i,a,l,s)),s=null);o&&!(!o||o.nodeType==9);){let h=n?null:Fh(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;r.push(new Ka(u,h,s)),s=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new Ya),this.steps=r.concat(this.steps)):this.steps=r}toString(){if(!this.steps)return"";let t=new ii;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function Bh(){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 Oh(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var Rp=Bh(),Qa={PENDING:{}};function _h(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function mr(e){return`"${Vn(`${e}`)}"`}function Fp(e){return ei(`${e}`)}function zr(e,t){return e?`${ei(e)}.${ei(t)}`:ei(t)}var Mh=0,Dr=class{constructor(e,t){if(this.parent=e,this.resolver=t,c(this,"scopeKey"),c(this,"children",[]),c(this,"zero"),c(this,"one"),c(this,"_true"),c(this,"_false"),c(this,"values",{}),c(this,"funcs",{}),c(this,"builtIns",{}),this.scopeKey=`S${Mh++}`,this.zero=new $e(this,0),this.one=new $e(this,1),this._true=new $e(this,!0),this._false=new $e(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=_h,i["css-string"]=mr,i["css-name"]=Fp,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return mr(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return mr(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new Me(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function Lp(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function zh(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function Bp(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Op(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var Pt={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 Dh(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var Vr=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,c(this,"actualPageWidth",null),c(this,"pageWidth"),c(this,"actualPageHeight",null),c(this,"pageHeight"),c(this,"initialFontSize"),c(this,"rootFontSize",null),c(this,"isRelativeRootFontSize",null),c(this,"fontSize"),c(this,"rootLineHeight",null),c(this,"pref"),c(this,"scopes",{}),c(this,"pageAreaWidth",null),c(this,"pageAreaHeight",null),c(this,"pageVertical",null),c(this,"pubTitle",null),c(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=Rp}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(zh(e)){let n=this.pageWidth()/100,s=this.pageHeight()/100,r=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:s,a=i??this.pageVertical;switch(e){case"vw":return r;case"vh":return o;case"vi":return a?o:r;case"vb":return a?r:o;case"vmin":return r<o?r:o;case"vmax":return r>o?r:o;case"pvw":return n;case"pvh":return s;case"pvi":return a?s:n;case"pvb":return a?n:s;case"pvmin":return n<s?n:s;case"pvmax":return n>s?n:s}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:Pt[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let s=e.funcs[t];if(s||e.resolver&&(s=e.resolver.call(this,t,!0),s))return s;let r=e.builtIns[t];if(r){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new $e(e,r.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let s=null,r=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(s=t.evaluate(this));break}switch(e){case"width":r=this.pageWidth();break;case"height":r=this.pageHeight();break;case"device-width":r=window.screen.availWidth;break;case"device-height":r=window.screen.availHeight;break;case"color":r=window.screen.pixelDepth;break}if(r!=null&&s!=null)switch(i){case"min":return r>=Number(s);case"max":return r<=Number(s);default:return r==s}else if(r!=null&&t==null)return r!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Et=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${Mh++}`}toString(){let e=new ii;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===Qa.PENDING?!1:n;{i[this.key]=Qa.PENDING;let s=this.dependCore(e,t,i);return i[this.key]=s,s}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},Vh=class extends Et{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},Ks=class extends Et{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},Uh=class extends Ks{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ji=class extends Ks{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Hh=class extends Ks{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Yo=class extends Ks{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},ti=class extends Vh{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},_p=class extends ti{constructor(e,t){super(e,t)}getOp(){return"not "}},Ri=class extends Vh{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Ko=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Mp=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Zo=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},zp=class extends Zo{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},Dp=class extends Zo{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Vp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},Up=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Hp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Ur=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Jo=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},$p=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},$h=class extends Hh{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},Wh=class extends Hh{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Qo=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Gh=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},jh=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},Un=class extends Et{constructor(e,t,i){var n;super(e),this.num=t,c(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(ei(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},ze=class extends Et{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},el=class extends Et{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(ei(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Me=class extends Et{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function Wp(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function Gp(e,t,i){let n=t;for(let s=0;s<t.length;s++){let r=t[s].expand(e,i);if(t!==n)n[s]=r;else if(r!==t[s]){n=Array(t.length);for(let o=0;o<s;o++)n[o]=t[o];n[s]=r}}return n}var yn=class Xh extends Et{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Wp(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let s=0;s<this.params.length;s++)if(this.params[s].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=Gp(t,this.params,i);return n===this.params?this:new Xh(this.scope,this.qualifiedName,n)}},jp=class qh extends Et{constructor(t,i,n,s){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=s}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),s=this.ifTrue.expand(t,i),r=this.ifFalse.expand(t,i);return n===this.cond&&s===this.ifTrue&&r===this.ifFalse?this:new qh(this.scope,n,s,r)}},$e=class extends Et{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(Vn(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},tl=class Yh extends Et{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(Vn(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new Yh(this.scope,this.name,n)}},Xp=class extends Et{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},Kh=class extends Et{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function St(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new Ko(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new $h(e,t,i)}function pe(e,t,i){return t===e.zero?new Ri(e,i):i===e.zero?t:new Wh(e,t,i)}function cs(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Qo(e,t,i)}function Hr(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Gh(e,t,i)}var Xt=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Qi=class extends Xt{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],s=n.visit(this);if(this.error)return[];if(t)t[i]=s;else if(n!==s){t=new Array(e.length);for(let r=0;r<i;r++)t[r]=e[r];t[i]=s}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?j:t===e.values?e:new Q(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?j:t===e.values?e:new Ke(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?j:t===e.values?e:new en(e.name,t)}visitExpr(e){return e}},Ze=class{toString(){let e=new ii;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new ii;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},Zh=class Jh extends Ze{static get instance(){return this.empty||(this.empty=new Jh),this.empty}constructor(){super()}toExpr(t,i){return new $e(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(Zh,"empty");var qp=Zh,j=qp.instance,Qh=class eu extends Ze{static get instance(){return this.slash||(this.slash=new eu),this.slash}constructor(){super()}toExpr(t,i){return new $e(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(Qh,"slash");var Yp=Qh,Zs=Yp.instance,G=class extends Ze{constructor(e){super(),this.str=e}toExpr(e,t){return new $e(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(Vn(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},$r={},ae=class extends Ze{constructor(e){if(super(),this.name=e,$r[e])throw new Error("E_INVALID_CALL");$r[e]=this}toExpr(e,t){return new $e(e,this.name)}appendTo(e,t){t?e.append(ei(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function F(e){let t=$r[e];return t||(t=new ae(e)),t}var I=class extends Ze{constructor(e,t){var i;super(),this.num=e,c(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new Qo(e,t,new $e(e,this.num/100)):new Un(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},Ht=class extends Ze{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new $e(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Re=class extends Ht{constructor(e){super(e)}visit(e){return e.visitInt(this)}},tu=class extends Ze{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Je=class extends Ze{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(Vn(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},iu=class extends Ze{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ea(e,t,i,n){var s,r;let o=t.length;if(o>0){(s=t[0])==null||s.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(r=t[a])==null||r.appendTo(e,n)}}var Q=class extends Ze{constructor(e){super(),this.values=e}appendTo(e,t){ea(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Ke=class extends Ze{constructor(e){super(),this.values=e}appendTo(e,t){ea(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},en=class extends Ze{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(ei(this.name)),e.append("("),ea(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},U=class extends Ze{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof $e||this.expr instanceof Un?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}},Ei=class extends Ze{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function Qe(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function nu(e,t){return new I(Qe(e,t),"px")}var y={absolute:F("absolute"),all:F("all"),always:F("always"),anywhere:F("anywhere"),auto:F("auto"),avoid:F("avoid"),balance:F("balance"),balance_all:F("balance-all"),block:F("block"),block_end:F("block-end"),block_start:F("block-start"),both:F("both"),bottom:F("bottom"),border_box:F("border-box"),break_all:F("break-all"),break_word:F("break-word"),clip:F("clip"),crop:F("crop"),cross:F("cross"),column:F("column"),discard:F("discard"),exclusive:F("exclusive"),_false:F("false"),fixed:F("fixed"),flex:F("flex"),flow_root:F("flow-root"),footnote:F("footnote"),footer:F("footer"),grid:F("grid"),header:F("header"),hidden:F("hidden"),horizontal_tb:F("horizontal-tb"),inherit:F("inherit"),initial:F("initial"),inline:F("inline"),inline_block:F("inline-block"),inline_end:F("inline-end"),inline_start:F("inline-start"),inside:F("inside"),keep:F("keep"),landscape:F("landscape"),left:F("left"),line:F("line"),list_item:F("list-item"),ltr:F("ltr"),manual:F("manual"),max_content:F("max-content"),min_content:F("min-content"),none:F("none"),normal:F("normal"),oeb_page_foot:F("oeb-page-foot"),oeb_page_head:F("oeb-page-head"),outside:F("outside"),padding_box:F("padding-box"),page:F("page"),relative:F("relative"),revert:F("revert"),right:F("right"),same:F("same"),scale:F("scale"),snap_block:F("snap-block"),snap_inline:F("snap-inline"),solid:F("solid"),spread:F("spread"),_static:F("static"),rtl:F("rtl"),table:F("table"),table_caption:F("table-caption"),table_cell:F("table-cell"),table_footer_group:F("table-footer-group"),table_header_group:F("table-header-group"),table_row:F("table-row"),top:F("top"),transparent:F("transparent"),unset:F("unset"),vertical_lr:F("vertical-lr"),vertical_rl:F("vertical-rl"),visible:F("visible"),_true:F("true")},il=new I(100,"%"),Hn=new I(100,"pvw"),$n=new I(100,"pvh"),ke=new I(0,"px"),S0=new iu("U+0-10FFFF"),nl={"font-size":1,"line-height":2,color:3};function K(e){return e===y.inherit||e===y.initial||e===y.revert||e===y.unset}function sl(e,t){let i=nl[e]||Number.MAX_VALUE,n=nl[t]||Number.MAX_VALUE;return i-n}function $t(e){return e?.length>2&&e.startsWith("--")}var wt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},Zt=class{constructor(e,t){this.x=e,this.y=t}},wr=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},rl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Vt=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,c(this,"left",null),c(this,"right",null)}};function Kp(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Js=class su{constructor(t){this.points=t}addSegments(t,i){let n=this.points,s=n.length,r=n[s-1];for(let o=0;o<s;o++){let a=n[o],l;r.y<a.y?l=new rl(r,a,1,i):l=new rl(a,r,-1,i),t.push(l),r=a}}withOffset(t,i){let n=[];for(let s of this.points)n.push(new Zt(s.x+t,s.y+i));return new su(n)}};function ol(e,t,i,n){let s=[];for(let r=0;r<20;r++){let o=r*2*Math.PI/20;s.push(new Zt(e+i*Math.sin(o),t+n*Math.cos(o)))}return new Js(s)}function ta(e,t,i,n){return new Js([new Zt(e,t),new Zt(i,t),new Zt(i,n),new Zt(e,n)])}var is=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function al(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function Zp(e,t,i,n){let s,r,o,a;t.high.y<i&&H.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=al(t,i),r=t.winding):(s=t.low.x,r=0),t.high.y>=n?(o=al(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(e.push(new is(s,r,t.shapeId,-1)),e.push(new is(o,a,t.shapeId,1))):(e.push(new is(o,a,t.shapeId,-1)),e.push(new is(s,r,t.shapeId,1)))}function Jp(e,t,i){let n=t+i,s=Array(n),r=Array(n),o;for(o=0;o<=n;o++)s[o]=0,r[o]=0;let a=[],l=!1,h=e.length;for(let u=0;u<h;u++){let d=e[u];s[d.shapeId]+=d.winding,r[d.shapeId]+=d.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(s[o]&&!r[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(s[o]||r[o]){p=!1;break}}l!=p&&(a.push(d.x),l=p)}return a}function Qp(e,t){return t?Math.ceil(e/t)*t:e}function ll(e,t){return t?Math.floor(e/t)*t:e}function ef(e){return new Zt(e.y,-e.x)}function Rs(e){return new wt(e.y1,-e.x2,e.y2,-e.x1)}function ru(e){return new wt(-e.y2,e.x1,-e.y1,e.x2)}function hl(e){return new Js(e.points.map(t=>ef(t)))}function tf(e,t,i,n,s,r){r&&(e=Rs(e),t=t.map(b=>hl(b)),i=i.map(b=>hl(b)));let o=t.length,a=i?i.length:0,l=[],h=[],u,d,p;for(u=0;u<o;u++)t[u].addSegments(h,u);for(u=0;u<a;u++)i[u].addSegments(h,u+o);let f=h.length;h.sort(Kp);let m=0;for(;h[m].shapeId>=o;)m++;let g=h[m].low.y;g>e.y1&&l.push(new Vt(e.y1,g,e.x2,e.x2));let w=0,v=[];for(;w<f&&(p=h[w]).low.y<g;)p.high.y>g&&v.push(p),w++;for(;w<f||v.length>0;){let b=e.y2,C=Math.min(Qp(Math.ceil(g+n),s),e.y2);for(d=0;d<v.length&&b>C;d++)p=v[d],p.low.x==p.high.x?p.high.y<b&&(b=Math.max(ll(p.high.y,s),C)):p.low.x!=p.high.x&&(b=C);for(b>e.y2&&(b=e.y2);w<f&&(p=h[w]).low.y<b;){if(p.high.y<g){w++;continue}if(p.low.y<C)p.low.y==p.high.y&&p.low.y==g||(v.push(p),b=C),w++;else{let V=ll(p.low.y,s);V<b&&(b=V);break}}let E=[];for(d=0;d<v.length;d++)Zp(E,v[d],g,b);E.sort((V,D)=>V.x-D.x||V.lowOrHigh-D.lowOrHigh);let A=Jp(E,o,a);if(A.length==0)l.push(new Vt(g,b,e.x2,e.x2));else{let V=0,D=e.x1;for(d=0;d<A.length;d+=2){let te=Math.max(e.x1,A[d]),ie=Math.min(e.x2,A[d+1])-te;ie>V&&(V=ie,D=te)}V==0?l.push(new Vt(g,b,e.x2,e.x2)):l.push(new Vt(g,b,Math.max(D,e.x1),Math.min(D+V,e.x2)))}if(b==e.y2)break;for(g=b,d=v.length-1;d>=0;d--)v[d].high.y<=b&&v.splice(d,1)}return ou(e,l),l}function ou(e,t){let i=t.length-1,n=new Vt(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let s=n;n=t[i],(n.y2-n.y1<1||n.x1==s.x1&&n.x2==s.x2)&&(s.y1=n.y1,t.splice(i,1),n=s),i--}}function au(e,t){let i=0,n=e.length;for(;i<n;){let s=Math.floor((i+n)/2);t>=e[s].y2?i=s+1:n=s}return i}function nf(e,t){if(!e.length)return t;let i=t.y1,n,s;for(s=0;s<e.length&&(n=e[s],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));s++)i=Math.max(i,n.y2);let r=i;for(;s<e.length&&(n=e[s],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));s++)r=n.y2;return s===e.length?r=t.y2:r=Math.min(r,t.y2),r<=i?null:new wt(t.x1,i,t.x2,r)}function sf(e,t){if(!e.length)return t;let i=t.y2,n,s;for(s=e.length-1;s>=0&&(n=e[s],!(s===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);s--)i=Math.min(i,n.y1);let r=Math.min(i,n.y2);for(;s>=0&&(n=e[s],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));s--)r=n.y1;return r=Math.max(r,t.y1),i<=r?null:new wt(t.x1,r,t.x2,i)}function rf(e,t,i,n){let s=i.y1,r=i.x2-i.x1,o=i.y2-i.y1,a=au(t,s);for(;;){let l=s+o;if(l>e.y2)return!1;let h=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<l;d++){let p=t[d];p.x1>h&&(h=p.x1),p.x2<u&&(u=p.x2)}if(h+r<=u||a>=t.length)return n=="left"?(i.x1=h,i.x2=h+r):(i.x1=u-r,i.x2=u),i.y2+=s-i.y1,i.y1=s,!0;s=t[a].y2,a++}}function of(e,t,i,n,s){for(n||(n=[new Vt(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let r,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Vt(o,e.y2,e.x1,e.x2));let a=au(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(r=t[a],a++,t.splice(a,0,new Vt(l.y1,r.y2,r.x1,r.x2)),r.y2=l.y1);a<t.length&&(r=t[a++],r.y2>l.y2&&(t.splice(a,0,new Vt(l.y2,r.y2,r.x1,r.x2)),r.y2=l.y2),l.x1!=l.x2&&(s=="left"?r.x1=Math.min(l.x2,e.x2):r.x2=Math.max(l.x1,e.x1)),r.y2!=l.y2););}ou(e,t)}var af=class extends Xt{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function lf(e){if(e){let t=new af;try{return e.visit(t),t.propSet}catch(i){H.warn(i,"toSet:")}}return{}}var hf=class extends Xt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function ul(e,t){if(e){let i=new hf(t);try{return e.visit(i),i.value}catch(n){H.warn(n,"toInt: ")}}return t}var uf=class extends Xt{constructor(){super(),c(this,"collect",!1),c(this,"coords",[]),c(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 I(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,s){if(this.coords.length>0){let r=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let l=a%2==0?i:n;a==3&&this.name=="circle"&&(l=Math.sqrt((i*i+n*n)/2)),r.push(o.num*l/100)}else r.push(o.num*s.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(r.length%2==0){let o=[];for(let a=0;a<r.length;a+=2)o.push(new Zt(e+r[a],t+r[a+1]));return new Js(o)}break;case"rectangle":if(r.length==4)return ta(e+r[0],t+r[1],e+r[0]+r[2],t+r[1]+r[3]);break;case"ellipse":if(r.length==4)return ol(e+r[0],t+r[1],r[2],r[3]);break;case"circle":if(r.length==3)return ol(e+r[0],t+r[1],r[2],r[2]);break}}return null}};function lu(e,t,i,n,s,r){if(e){let o=new uf;try{return e.visit(o),o.getShape(t,i,n,s,r)}catch(a){H.warn(a,"toShape:")}}return ta(t,i,t+n,i+s)}var cf=class extends Xt{constructor(e){super(),this.reset=e,c(this,"counters",{}),c(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+1,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:1)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function vn(e,t){let i=new cf(t);try{e.visit(i)}catch(n){H.warn(n,"toCounters:")}return i.counters}var df=class extends Qi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new Je(this.transformer.transformURL(e.url,this.baseUrl))}};function br(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Fi(e,t){if(t==="content"){let i=e.cloneNode(!0);return i.querySelectorAll("[data-adapt-pseudo]").forEach(n=>n.remove()),i.textContent||""}else{let i=e.querySelector(`[data-adapt-pseudo="${t}"]`);return i&&i.textContent||""}}var pf=class{constructor(e,t){this.targetId=e,this.resolved=t,c(this,"pageCounters",null),c(this,"spineIndex",-1),c(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},ff=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},gf=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,c(this,"styler",null),c(this,"namedStringValues",{}),c(this,"runningElements",{})}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Pe(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let r=this.counterStore.currentPageCounters[e];return r&&r.length?r[r.length-1]:null},n=new Me(this.pageScope,()=>t(i()),`page-counter-${e}`),s=r=>t(r[r.length-1]);return this.counterStore.registerPageCounterExpr(e,s,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new Me(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?Fi(n,t):Fi(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e),r=this.getTargetCounters(n,s,!1);if(r&&r[t]){let a=r[t];return new $e(this.rootScope,i(a[a.length-1]||null))}let o=new Me(this.pageScope,()=>{if(r=this.getTargetCounters(n,s,!0),r)if(r[t]){let a=r[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(s);if(a)if(this.counterStore.resolveReference(s),a[t]){let l=a[t];return i(l[l.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,s),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),s=this.getTransformedId(e);return new Me(this.pageScope,()=>{let r=this.getTargetPageCounters(s);if(r){this.counterStore.resolveReference(s);let o=r[t]||[],a=this.getTargetCounters(n,s,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(s,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Me(this.pageScope,()=>{if(t==="first-letter"){let r=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(r===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let l=(r??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let h=l.match(As);return h?h[0]:""}let s=this.getTargetPageText(i,t);return s!==null?(this.counterStore.resolveReference(i),s):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new Me(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Me(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let s=Object.keys(n).map(p=>parseInt(p,10)).sort(Rh),r=this.counterStore.currentPage,o=r.isBlankPage?r.offset-1:r.offset,a=r.isBlankPage?o:Math.max(o,...Array.from(r.container.querySelectorAll(`[${Mt}]`)).map(p=>parseInt(p.getAttribute(Mt),10))),l=-1,h=-1,u=-1,d=-1;for(let p=0;p<s.length;p++){let f=s[p],m=p>0?s[p-1]:-1,g=p<s.length-1?s[p+1]:-1;if(f>a)break;if(f>=o){if(l<0&&(l=f,d=-1),h<0)if(f===o)h=f;else{m<l&&(h=m);let w=r.container.querySelector(`[${Mt}="${f}"]`);if(!w)h<0&&(h=f);else{let v=r.container.querySelector(`[${Mt}="${o}"]`);if(v||(v=r.container.querySelector(`[${Mt}="0"]`)),v){for(let b=v;b;b=b.firstElementChild)if(b===w){h=f;break}}}}u=f}else(g>a||g<0)&&(l=h=u=d=f)}return n[{first:l,start:h,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]={});n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]={});i[t]=String(t)}},mf=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",{}),c(this,"pageCountersById",{}),c(this,"pageTextById",{}),c(this,"currentPageCounters",{}),c(this,"previousPageCounters",{}),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",{}),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",{}),c(this,"resolvedReferences",{}),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new ff(this,e)}createCounterResolver(e,t,i){return new gf(this,e,t,i)}setCurrentPage(e){this.currentPage=e}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=br(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let o=n.evaluate(t);o&&(i=vn(o,!0))}if(i)for(let o in i)this.definePageCounter(o,i[o]);let s,r=e["counter-increment"];if(r){let o=r.evaluate(t);o&&(s=vn(o,!1))}s?"page"in s||(s.page=1):(s={},s.page=1);for(let o in s){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=s[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=br(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let s=0;s<this.referencesToSolve.length;){let r=this.referencesToSolve[s];if(r.targetId===e){if(r.resolve(),this.referencesToSolve.splice(s,1),t){let o=t.indexOf(r);o>=0&&t.splice(o,1)}i.push(r),n=!0}else s++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new pf(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let r=br(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=r;let a=this.currentPage.elementsById[o];if(a&&a.length>0){let h=a[0];this.pageTextById[o]={content:Fi(h,"content"),before:Fi(h,"before"),after:Fi(h,"after"),marker:Fi(h,"marker")}}let l=this.pageIndicesById[o];if(l&&l.pageIndex<t){let h=this.resolvedReferences[o];if(h){let u=this.unresolvedReferences[o];u||(u=this.unresolvedReferences[o]=[]);let d;for(;d=h.shift();)d.unresolve(),u.push(d)}}this.pageIndicesById[o]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,s;for(;s=this.newReferencesOfCurrentPage.shift();){s.pageCounters=n,s.spineIndex=e,s.pageIndex=t;let r;s.isResolved()?(r=this.resolvedReferences[s.targetId],r||(r=this.resolvedReferences[s.targetId]=[])):(r=this.unresolvedReferences[s.targetId],r||(r=this.unresolvedReferences[s.targetId]=[])),r.every(o=>!s.equals(o))&&r.push(s)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(s=>{let r=this.unresolvedReferences[s];r&&(t=t.concat(r))}),t.sort((s,r)=>s.spineIndex-r.spineIndex||s.pageIndex-r.pageIndex);let i=[],n=null;return t.forEach(s=>{!n||n.spineIndex!==s.spineIndex||n.pageIndex!==s.pageIndex?(n={spineIndex:s.spineIndex,pageIndex:s.pageIndex,pageCounters:s.pageCounters,refs:[s]},i.push(n)):n.refs.push(s)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof Me){if(e.str=="viv-leader"){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute("data-viv-leader",e.key),r.setAttribute("data-viv-leader-value",t),r}else if(e.str.startsWith("running-element-")){let r=t&&i.querySelectorAll(`[${Mt}="${t}"]`);if(!r||r.length===0)return null;let o=r[r.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(xr,e.key),r}else if(e.str.startsWith("target-text-")){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(Sr,e.key),r}}let n=this.pagesCounterExprs.findIndex(r=>r.expr===e)>=0,s=!n&&this.pageCounterExprs.findIndex(r=>r.expr===e)>=0;if(n||s){let r=i.createElementNS("http://www.w3.org/1999/xhtml","span");return r.textContent=t,r.setAttribute(n?yr:vr,e.key),r}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${vr}]`);for(let s of t){let r=s.getAttribute(vr),o=this.pageCounterExprs.find(u=>u.expr.key===r),a=(o?.expr).str,l=a?.replace(/^page-counters?-/,""),h=this.currentPageCounters[l];h&&(s.textContent=o.format(h))}let i=e.querySelectorAll(`[${xr}]`);for(let s of i)s.setAttribute(cl,!0);let n=e.querySelectorAll(`[${Sr}]`);for(let s of n)s.setAttribute(dl,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${yr}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(yr),l=this.pagesCounterExprs.findIndex(h=>h.expr.key===a);l>=0,o.textContent=this.pagesCounterExprs[l].format([n])}let s=e.root.querySelectorAll(`[${cl}]`);for(let o of s){let a=o.getAttribute(xr),l=this.targetCounterExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageCountersById[l.transformedId];if(h){let u=h[l.name];u&&(o.textContent=l.format(u[u.length-1]))}}}let r=e.root.querySelectorAll(`[${dl}]`);for(let o of r){let a=o.getAttribute(Sr),l=this.targetTextExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageTextById[l.transformedId];h&&(o.textContent=(t=h[l.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new wf(this,e)}},yr="data-vivliostyle-pages-counter",vr="data-vivliostyle-page-counter",xr="data-vivliostyle-target-counter",Sr="data-vivliostyle-target-text",cl="data-vivliostyle-target-counter-in-running",dl="data-vivliostyle-target-text-in-running",wf=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}};function bf(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function li(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,bf)}var yf=class{constructor(){c(this,"type"),c(this,"precededBySpace",!1),c(this,"num",0),c(this,"text",""),c(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 We(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var _t=[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];_t[NaN]=80;var Rt=[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];Rt[NaN]=43;var vf=[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];Rt[NaN]=43;var hu=[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];hu[NaN]=35;var uu=[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];uu[NaN]=45;var Wr=[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];Wr[NaN]=37;var Gr=[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];Gr[NaN]=38;var hi=We(35,[61,36]),xf=We(35,[58,77]),Sf=We(35,[61,36,124,50]),Cf=We(35,[38,51]),kf=We(35,[42,54]),Ef=We(39,[42,55]),Nf=We(54,[42,55,47,56]),Pf=We(62,[62,82]),Tf=We(35,[61,36,33,70]),If=We(62,[45,71]),Af=We(63,[45,81]),Cr=We(76,[10,72,13,72]),Rf=We(39,[39,46,10,72,13,72,92,48]),Ff=We(39,[34,46,10,72,13,72,92,49]),Lf=We(39,[39,47,10,74,13,74,92,48]),Bf=We(39,[34,47,10,74,13,74,92,49]),pl=We(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Of=We(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]),_f=We(39,[39,68,10,74,13,74,92,75,NaN,67]),Mf=We(39,[34,68,10,74,13,74,92,75,NaN,67]),zf=We(72,[9,39,10,39,13,39,32,39,41,69]),Df=15,At=class{constructor(e,t){this.input=e,this.handler=t,c(this,"indexMask"),c(this,"buffer"),c(this,"tail",0),c(this,"curr",0),c(this,"position",0),this.indexMask=Df,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new yf}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=_t,s=this.input,r=this.position,o=this.buffer,a=0,l=0,h="",u=0,d=!1,p=o[e],f=-9;for(;;){let m=s.charCodeAt(r);switch(n[m]||n[65]){case 72:h=s.substring(l,r),isNaN(m)?a=0:a=54,n=_t;break;case 1:r++,d=!0;continue;case 2:l=r++,n=Wr;continue;case 3:a=1,l=r++,n=Rt;continue;case 4:l=r++,a=31,n=hi;continue;case 33:a=2,l=++r,n=Rf;continue;case 34:a=2,l=++r,n=Ff;continue;case 6:l=++r,a=7,n=Rt;continue;case 7:l=r++,a=32,n=hi;continue;case 8:l=r++,a=21;break;case 9:l=r++,a=32,n=Cf;continue;case 10:l=r++,a=10;break;case 11:l=r++,a=11;break;case 12:l=r++,a=36,n=hi;continue;case 13:l=r++,a=23;break;case 14:l=r++,a=16;break;case 15:a=24,l=r++,n=hu;continue;case 16:l=r++,n=vf;continue;case 78:l=r++,a=9,n=Rt;continue;case 17:l=r++,a=19,n=kf;continue;case 18:l=r++,a=18,n=xf;continue;case 77:r++,a=50;break;case 19:l=r++,a=17;break;case 20:l=r++,a=38,n=Tf;continue;case 21:l=r++,a=39,n=hi;continue;case 22:l=r++,a=37,n=hi;continue;case 23:l=r++,a=22;break;case 24:l=++r,a=20,n=Rt;continue;case 25:l=r++,a=14;break;case 26:l=r++,a=15;break;case 27:l=r++,a=12;break;case 28:l=r++,a=13;break;case 29:l=r++,f=l,a=1,n=Cr;continue;case 30:l=r++,a=33,n=hi;continue;case 31:l=r++,a=34,n=Sf;continue;case 32:l=r++,a=35,n=hi;continue;case 35:break;case 36:r++,a=a+41-31;break;case 37:a=5,u=parseInt(s.substring(l,r),10);break;case 38:a=4,u=parseFloat(s.substring(l,r));break;case 39:r++;continue;case 40:a=3,u=parseFloat(s.substring(l,r)),l=r++,n=Rt;continue;case 41:a=3,u=parseFloat(s.substring(l,r)),h="%",l=r++;break;case 42:r++,n=Gr;continue;case 43:if(h=li(s.substring(l,r)),a===27&&m===63||a===1&&h.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(s.substring(r-1))){a=27,r++;continue}break;case 44:f=r++,n=Cr;continue;case 45:h=li(s.substring(l,r));break;case 46:h=s.substring(l,r),r++;break;case 47:h=li(s.substring(l,r)),r++;break;case 48:f=r,r+=2,n=Lf;continue;case 49:f=r,r+=2,n=Bf;continue;case 50:r++,a=25;break;case 51:r++,a=26;break;case 52:if(h=s.substring(l,r),a==1){if(r++,h.toLowerCase()=="url"){n=pl;continue}a=6}break;case 53:if(h=li(s.substring(l,r)),a==1){if(r++,h.toLowerCase()=="url"){n=pl;continue}a=6}break;case 54:n=Ef,r++;continue;case 55:n=Nf,r++;continue;case 56:n=_t,r++;continue;case 57:n=Pf,r++,s[r]!==">"&&(a=1,n=Rt);continue;case 81:a=51,h=s.substring(l,++r),n=_t;break;case 82:a=52,h=s.substring(l,++r),n=_t;break;case 58:a=5,n=Wr,r++;continue;case 59:a=4,n=Gr,r++;continue;case 60:a=1,n=Rt,r++;continue;case 61:a=1,n=Cr,f=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:l=r++,n=Of;continue;case 65:l=++r,n=_f;continue;case 66:l=++r,n=Mf;continue;case 67:a=8,h=li(s.substring(l,r)),r++;break;case 69:r++;break;case 70:n=If,r++;continue;case 71:n=Af,r++;continue;case 79:if(r-f<8&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){r++;continue}case 68:a=8,h=li(s.substring(l,r)),r++,n=zf;continue;case 74:if(r++,r-f<9&&s.substring(f+1,r).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,h="E_CSS_UNEXPECTED_NEWLINE",n=_t;break;case 73:if(r-f<9&&s.substring(f+1,r+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){r++,n=Rt;continue}h=li(s.substring(l,r));break;case 75:f=r++;continue;case 76:r++,n=uu;continue;default:if(n!==_t){a=54,h="E_CSS_UNEXPECTED_STATE";break}l=r,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=h,p.position=l,e++,e>=t)break;n=_t,d=!1,p=o[e&i]}this.position=r,this.tail=e&i}},Oe=null,jr=null;function Xr(){return Oe}function B(e){if(!Oe)throw new Error("E_TASK_NO_CONTEXT");Oe.name||(Oe.name=e);let t=Oe,i=new Qs(t,t.top,e);return t.top=i,i.state=1,i}function Vf(e){return new $f(e||new Hf)}function N(e){return new qr(e)}function ji(e,t,i){let n=B(e);n.handler=i;try{t(n)}catch(s){n.task.raise(s,n)}return n.result()}function Uf(e,t){return(Oe?Oe.getScheduler():jr||Vf()).run(e,t)}var Hf=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},$f=class{constructor(e){this.timer=e,c(this,"timeout",1),c(this,"slice",25),c(this,"sliceOverTime",0),c(this,"queue"),c(this,"wakeupTime",null),c(this,"timeoutToken",null),c(this,"inTimeSlice",!1),c(this,"order",0),this.queue=new xp,jr||(jr=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){H.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Wf(this,t||"");i.top=new Qs(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let s=()=>{i.running=!1;for(let r of i.callbacks)try{r()}catch(o){H.error(o)}};try{e().then(r=>{i.result=r,s()})}catch(r){i.raise(r),s()}});let n=Oe;return Oe=i,this.schedule(i.top.suspend("bootstrap")),Oe=n,i}},cu=class{constructor(e){this.task=e,c(this,"scheduledTime",0),c(this,"order",0),c(this,"result",null),c(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=Oe;return Oe=e,e.top.finish(this.result),Oe=t,!0}return!1}cancel(){this.canceled=!0}},Wf=class{constructor(e,t){this.scheduler=e,this.name=t,c(this,"callbacks",[]),c(this,"exception",null),c(this,"running",!0),c(this,"result",null),c(this,"waitTarget",null),c(this,"top",null),c(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==Oe&&this.continuation){this.continuation.cancel();let t=new cu(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=B("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&H.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
|
|
3
|
+
`]).concat(i))),n}var $=new _p,ps=(e=>(e.SIMPLE_PROPERTY="SIMPLE_PROPERTY",e.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",e.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",e.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",e.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",e.CONFIGURATION="CONFIGURATION",e.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",e.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",e.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",e.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK",e))(ps||{}),Xr={};function Nt(e,t,i){if(!ps[e])$.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=Xr[e];n||(n=Xr[e]=[]),i?n.unshift(t):n.push(t)}}function Wh(e,t){if(!ps[e])$.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=Xr[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Rt(e){return Xr[e]||[]}var zp={registerHook:Nt,removeHook:Wh},Gh=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=Li,this.registerStartTiming=this.registerStartTiming=Li,this.registerEndTiming=this.registerEndTiming=Li}forceRegisterStartTiming(e,t){Rs.call(this,e,"start",t)}forceRegisterEndTiming(e,t){Rs.call(this,e,"end",t)}printTimings(){let e=this.timestamps,t="";Object.keys(e).forEach(i=>{let n=e[i],r=n.length;for(let s=0;s<r;s++){let o=n[s];t+=i,r>1&&(t+=`(${s})`),t+=` => start: ${o.start}, end: ${o.end}, duration: ${o.end-o.start}
|
|
4
|
+
`}}),$.info(t)}disable(){this.registerTiming=Li,this.registerStartTiming=this.registerStartTiming=Li,this.registerEndTiming=this.registerEndTiming=Li}enable(){this.registerTiming=Rs,this.registerStartTiming=this.registerStartTiming=nl,this.registerEndTiming=this.registerEndTiming=Dp}isEnabled(){return this.registerStartTiming===nl}};function Li(){}function Rs(e,t,i){i||(i=this.performanceInstance.now());let n=this.timestamps[e];n||(n=this.timestamps[e]=[]);let r,s=n.length;for(let o=s-1;o>=0&&(r=n[o],!(r&&!r[t]));o--)r=null;r||(r={},n.push(r)),r[t]=i}function nl(e,t){this.registerTiming(e,"start",t)}function Dp(e,t){this.registerTiming(e,"end",t)}var Vp={now:Date.now},Hp=window&&window.performance,pt=new Gh(Hp||Vp);pt.forceRegisterStartTiming("load_vivliostyle");var Up={profiler:{registerStartTiming:pt.registerStartTiming,registerEndTiming:pt.registerEndTiming,printTimings:pt.printTimings,disable:pt.disable,enable:pt.enable}},jh=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",qr=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,Ut="data-adapt-eloff",$p={};function ha(e){return JSON.parse(e)}function Wt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function Wp(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var on=window.location.href;function rl(e){on=e}var ni=window.location.href;function sl(e){ni=e}function Pe(e,t){if(/^data:/i.test(t))return e||t;if(!t||e.match(/^\w{2,}:/))return e.toLowerCase().match("^javascript:")?"#":(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e=`${e}/`),e);t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t=`${t}/`);let i;if(e.match(/^\/\//))return i=t.match(/^(\w{2,}:)\/\//),i?i[1]+e:e;if(e.match(/^\//))return i=t.match(/^(\w{2,}:\/\/[^\/]+)\//),i?i[1]+e:e;if(e.match(/^\.(\/|$)/)&&(e=e.substr(2)),t=Wp(t),e.match(/^#/))return t+e;let n=t.lastIndexOf("/");if(n<0)return e;let r=t.substr(0,n+1)+e,s="";for(i=r.match(/^([^?#]*)([?#].*)$/),i&&(r=i[1],s=i[2]);n=r.indexOf("/../"),!(n<=0);){let o=r.lastIndexOf("/",n-1);if(o<=0)break;r=r.substr(0,o)+r.substr(n+3)}return r.replace(/\/(\.\/)+/g,"/")+s}function jn(e){let t;return(t=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/${t[2]}/${t[3]?"":"master/"}${t[4]}`:(t=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(e))?e=`${t[1]}//raw.githubusercontent.com/aozorabunko/aozorabunko/master/${t[2]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[6]}`:(t=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(?:#|%23)file-(.*)-(\w+)$/.exec(e))?e=`${t[1]}//gist.githubusercontent.com/${t[2]}/raw/${t[3]}.${t[4]}`:(t=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(e))&&(e=`${t[1]}//output.jsbin.com/${t[2]}${t[3]}/`),e}function ol(e){return e==null?e:e.toString()}var Gp=class{constructor(){c(this,"queue",[null])}length(){return this.queue.length-1}add(e){let t=this.queue.length;for(;t>1;){let i=Math.floor(t/2),n=this.queue[i];if(n.compare(e)>0){this.queue[t]=e;return}this.queue[t]=n,t=i}this.queue[1]=e}peek(){return this.queue[1]}remove(){let e=this.queue[1],t=this.queue.pop(),i=this.queue.length;if(i>1){let n=1;for(;;){let r=n*2;if(r>=i)break;if(this.queue[r].compare(t)>0)r+1<i&&this.queue[r+1].compare(this.queue[r])>0&&r++;else if(r+1<i&&this.queue[r+1].compare(t)>0)r++;else break;this.queue[n]=this.queue[r],n=r}this.queue[n]=t}return e}},Xh=["","-webkit-","-moz-"],Mi={};function Nr(e,t){return CSS.supports(e+t,"unset")}function jp(e){let t=Mi[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return Mi[e]=null,null;case"text-combine-upright":if(Nr("-webkit-","text-combine")&&!Nr("","text-combine-upright"))return Mi[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Xh)if(Nr(i,e))return t=[i+e],Mi[e]=t,t;return $.warn("Property not supported by the browser: ",e),Mi[e]=null,null}function T(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=jp(t);if(r)for(let s of r){switch(s){case"-webkit-text-combine":switch(i){case"all":i="horizontal";break}break;case"text-combine-upright":switch(i){case"all":n.setProperty("text-indent","0");break}break}n.setProperty(s,i)}}function ei(e,t,i){try{let n=Mi[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function Qs(e){let t=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");return!t&&e.namespaceURI=="http://www.w3.org/1999/xhtml"&&(t=e.getAttribute("lang")),t}var oi=class{constructor(){c(this,"list",[])}append(e){return this.list.push(e),this}clear(){this.list=[]}toString(){let e=this.list.join("");return this.list=[e],e}};function qh(e){return`\\${e.charCodeAt(0).toString(16)} `}function ri(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,qh)}function ir(e){return e.replace(/[\u0000-\u001F"\\]/g,qh)}function al(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function ll(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function Xp(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Yh(e,t){function i(n){return Xp(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function Zt(e){return Yh(e)}function qp(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Yp(e,t){t=typeof t=="string"?t:"\\u";function i(r){return qp(r,t)}let n=new RegExp(`${Zt(t)}[0-9a-fA-F]{4}`,"g");return e.replace(n,i)}function ai(e,t){let i=0,n=e;for(;;){if(i<=n,i==0||t(i-1),n==e||t(n),i==n)return i;let r=i+n>>1;t(r)?n=r:i=r+1}}function Kh(e,t){return e-t}function hl(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function Kp(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function Fs(e,t){let i={};for(let n of e){let r=t(n);r&&(i[r]?i[r].push(n):i[r]=[n])}return i}function Zp(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var ua=class{constructor(){c(this,"listeners",{})}dispatchEvent(e){let t=this.listeners[e.type];if(t){e.target=this,e.currentTarget=this;for(let i=0;i<t.length;i++)t[i](e)}}addEventListener(e,t,i){if(i)return;let n=this.listeners[e];n?n.includes(t)||n.push(t):this.listeners[e]=[t]}removeEventListener(e,t,i){if(i)return;let n=this.listeners[e];if(n){let r=n.indexOf(t);r>=0&&n.splice(r,1)}}},Ci={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function Zh(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Jp(e){return`^${e}`}function ul(e){return e.replace(/[\[\]\(\),=;^]/g,Jp)}function Qp(e){return e.substr(1)}function eo(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Qp)}function ef(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=eo(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function cl(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=ef(i[2]),e=e.substr(i[0].length)}return t}var dl=class{appendTo(e){e.append("!")}applyTo(e){return!1}},pl=class{constructor(e,t,i){this.index=e,this.id=t,this.sideBias=i}appendTo(e){e.append("/"),e.append(this.index.toString()),(this.id||this.sideBias)&&(e.append("["),this.id&&e.append(this.id),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}applyTo(e){if(e.node.nodeType!=1)throw new Error("E_CFI_NOT_ELEMENT");let t=e.node,i=t.children,n=i.length,r,s=Math.floor(this.index/2)-1;if(s<0||n==0)r=t.firstChild,e.node=r||t;else{if(r=i[Math.min(s,n-1)],this.index&1){let o=r.nextSibling;!o||o.nodeType==1?e.after=!0:r=o}e.node=r}if(this.id&&(e.after||this.id!=Zh(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:$.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},fl=class{constructor(e,t,i,n){this.offset=e,this.textBefore=t,this.textAfter=i,this.sideBias=n}applyTo(e){if(this.offset>0&&!e.after){let t=this.offset,i=e.node;for(;;){let n=i.nodeType;if(n==1)break;let r=i.nextSibling;if(3<=n&&n<=5){let s=i.textContent.length;if(t<=s)break;if(!r){t=s;break}t-=s}if(!r){t=0;break}i=r}e.node=i,e.offset=t}return e.sideBias=this.sideBias,!0}appendTo(e){e.append(":"),e.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(e.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&e.append(ul(this.textBefore)),e.append(","),this.textAfter&&e.append(ul(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},gl=class Jh{constructor(){c(this,"steps",null)}fromString(t){let i=t.match(/^#?epubcfi\((.*)\)$/);if(!i)throw new Error("E_CFI_NOT_CFI");let n=decodeURIComponent(i[1]),r=0,s=[];for(;;){let o;switch(n.charAt(r)){case"/":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[(.*?)(;([^\]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),l=i[3];o=cl(i[4]),s.push(new pl(a,l,ol(o.s)));break}case":":{if(r++,i=n.substr(r).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/),!i)throw new Error("E_CFI_NUMBER_EXPECTED");r+=i[0].length;let a=parseInt(i[1],10),l=i[4];l&&(l=eo(l));let h=i[7];h&&(h=eo(h)),o=cl(i[10]),s.push(new fl(a,l,h,ol(o.s)));break}case"!":r++,s.push(new dl);break;case"~":case"@":case"":this.steps=s;return;default:throw new Error("E_CFI_PARSE_ERROR")}}}navigate(t){let i={node:t.documentElement,offset:0,after:!1,sideBias:null,ref:null};for(let n=0;n<this.steps.length;n++)if(!this.steps[n].applyTo(i)){i.ref=new Jh,i.ref.steps=this.steps.slice(n+1);break}return i}trim(t,i){return t.replace(/\s+/g," ").match(i?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")}prependPathFromNode(t,i,n,r){let s=[],o=t.parentNode,a="",l="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let h=t.textContent,u=h.length;n?(i+=u,a||(a=h)):(i>u&&(i=u),n=!0,a=h.substr(0,i),l=h.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||l)&&(a=this.trim(a,!1),l=this.trim(l,!0),s.push(new fl(i,a,l,r)),r=null);o&&!(!o||o.nodeType==9);){let h=n?null:Zh(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;s.push(new pl(u,h,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new dl),this.steps=s.concat(this.steps)):this.steps=s}toString(){if(!this.steps)return"";let t=new oi;t.append("epubcfi(");for(let i=0;i<this.steps.length;i++)this.steps[i].appendTo(t);return t.append(")"),t.toString().replace(/%/g,"%25")}};function Qh(){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 eu(e){return{fontFamily:e.fontFamily,lineHeight:e.lineHeight,margin:e.margin,hyphenate:e.hyphenate,columnWidth:e.columnWidth,horizontal:e.horizontal,nightMode:e.nightMode,spreadView:e.spreadView,pageBorder:e.pageBorder,enabledMediaTypes:Object.assign({},e.enabledMediaTypes),defaultPaperSize:e.defaultPaperSize?Object.assign({},e.defaultPaperSize):void 0}}var tf=Qh(),ml={PENDING:{}};function tu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function Ls(e){return`"${ir(`${e}`)}"`}function nf(e){return ri(`${e}`)}function to(e,t){return e?`${ri(e)}.${ri(t)}`:ri(t)}var iu=0,io=class{constructor(e,t){if(this.parent=e,this.resolver=t,c(this,"scopeKey"),c(this,"children",[]),c(this,"zero"),c(this,"one"),c(this,"_true"),c(this,"_false"),c(this,"values",{}),c(this,"funcs",{}),c(this,"builtIns",{}),this.scopeKey=`S${iu++}`,this.zero=new We(this,0),this.one=new We(this,1),this._true=new We(this,!0),this._false=new We(this,!1),e&&e.children.push(this),!e){let i=this.builtIns;i.floor=Math.floor,i.ceil=Math.ceil,i.round=Math.round,i.sqrt=Math.sqrt,i.min=Math.min,i.max=Math.max,i.letterbox=tu,i["css-string"]=Ls,i["css-name"]=nf,i.typeof=n=>typeof n,this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return Ls(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return Ls(this.docTitle?this.docTitle:"")})}}defineBuiltInName(e,t){this.values[e]=new ze(this,t,e)}defineName(e,t){this.values[e]=t}defineFunc(e,t){this.funcs[e]=t}defineBuiltIn(e,t){this.builtIns[e]=t}};function rf(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function nu(e){switch(e?.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}function sf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function of(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var At={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 ru(e){switch(e){case"q":return!CSS.supports("font-size","1q");case"lh":return!CSS.supports("line-height","1lh");case"rem":case"rlh":return!0;default:return!1}}var no=class{constructor(e,t,i,n){this.rootScope=e,this.viewportWidth=t,this.viewportHeight=i,c(this,"actualPageWidth",null),c(this,"pageWidth"),c(this,"actualPageHeight",null),c(this,"pageHeight"),c(this,"initialFontSize"),c(this,"rootFontSize",null),c(this,"isRelativeRootFontSize",null),c(this,"fontSize"),c(this,"rootLineHeight",null),c(this,"pref"),c(this,"scopes",{}),c(this,"pageAreaWidth",null),c(this,"pageAreaHeight",null),c(this,"pageVertical",null),c(this,"pubTitle",null),c(this,"docTitle",null),this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(t/2)-this.pref.pageBorder:t},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:i},this.initialFontSize=n,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:n},this.pref=tf}getScopeContext(e){let t=this.scopes[e.scopeKey];return t||(t={},this.scopes[e.scopeKey]=t),t}clearScope(e){this.scopes[e.scopeKey]={};for(let t=0;t<e.children.length;t++)this.clearScope(e.children[t])}queryUnitSize(e,t,i){if(nu(e)){let n=this.pageWidth()/100,r=this.pageHeight()/100,s=this.pageAreaWidth!=null?this.pageAreaWidth/100:n,o=this.pageAreaHeight!=null?this.pageAreaHeight/100:r,a=i??this.pageVertical;switch(e){case"vw":return s;case"vh":return o;case"vi":return a?o:s;case"vb":return a?s:o;case"vmin":return s<o?s:o;case"vmax":return s>o?s:o;case"pvw":return n;case"pvh":return r;case"pvi":return a?r:n;case"pvb":return a?n:r;case"pvmin":return n<r?n:r;case"pvmax":return n>r?n:r}}return e=="em"||e=="rem"?t?this.initialFontSize:this.fontSize():e=="lh"||e=="rlh"?this.rootLineHeight:At[e]}evalName(e,t){do{let i=e.values[t];if(i||e.resolver&&(i=e.resolver.call(this,t,!1),i))return i;e=e.parent}while(e);throw new Error(`Name '${t}' is undefined`)}evalCall(e,t,i,n){do{let r=e.funcs[t];if(r||e.resolver&&(r=e.resolver.call(this,t,!0),r))return r;let s=e.builtIns[t];if(s){if(n)return e.zero;let o=Array(i.length);for(let a=0;a<i.length;a++)o[a]=i[a].evaluate(this);return new We(e,s.apply(this,o))}e=e.parent}while(e);throw new Error(`Function '${t}' is undefined`)}evalMediaName(e,t){let i=e==="all"||!!this.pref.enabledMediaTypes[e];return t?!i:i}evalMediaTest(e,t){let i="",n=e.match(/^(min|max)-(.*)$/);n&&(i=n[1],e=n[2]);let r=null,s=null;switch(e){case"width":case"height":case"device-width":case"device-height":case"color":t&&(r=t.evaluate(this));break}switch(e){case"width":s=this.pageWidth();break;case"height":s=this.pageHeight();break;case"device-width":s=window.screen.availWidth;break;case"device-height":s=window.screen.availHeight;break;case"color":s=window.screen.pixelDepth;break}if(s!=null&&r!=null)switch(i){case"min":return s>=Number(r);case"max":return s<=Number(r);default:return s==r}else if(s!=null&&t==null)return s!==0;return!1}evalSupportsTest(e,t,i){return!1}queryVal(e,t){let i=e&&this.scopes[e.scopeKey];return i?i[t]:void 0}storeVal(e,t,i){this.getScopeContext(e)[t]=i}},Tt=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${iu++}`}toString(){let e=new oi;return this.appendTo(e,0),e.toString()}appendTo(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){throw new Error("F_ABSTRACT")}expand(e,t){return this}dependCore(e,t,i){return e===this}dependOuter(e,t,i){let n=i[this.key];if(n!=null)return n===ml.PENDING?!1:n;{i[this.key]=ml.PENDING;let r=this.dependCore(e,t,i);return i[this.key]=r,r}}depend(e,t){return this.dependOuter(e,t,{})}evaluate(e){let t=e.queryVal(this.scope,this.key);return typeof t<"u"||(t=this.evaluateCore(e),this.scope&&e.storeVal(this.scope,this.key,t)),t}isMediaName(){return!1}},su=class extends Tt{constructor(e,t){super(e),this.val=t}getOp(){throw new Error("F_ABSTRACT")}evalPrefix(e){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.val.evaluate(e);return this.evalPrefix(t)}dependCore(e,t,i){return e===this||this.val.dependOuter(e,t,i)}appendTo(e,t){10<t&&e.append("("),e.append(this.getOp()),this.val.appendTo(e,10),10<t&&e.append(")")}expand(e,t){let i=this.val.expand(e,t);return i===this.val?this:new this.constructor(this.scope,i)}},fs=class extends Tt{constructor(e,t,i){super(e),this.lhs=t,this.rhs=i}getPriority(){throw new Error("F_ABSTRACT")}getOp(){throw new Error("F_ABSTRACT")}evalInfix(e,t){throw new Error("F_ABSTRACT")}evaluateCore(e){let t=this.lhs.evaluate(e),i=this.rhs.evaluate(e);return this.evalInfix(t,i)}dependCore(e,t,i){return e===this||this.lhs.dependOuter(e,t,i)||this.rhs.dependOuter(e,t,i)}appendTo(e,t){let i=this.getPriority();i<=t&&e.append("("),this.lhs.appendTo(e,i),e.append(this.getOp()),this.rhs.appendTo(e,i),i<=t&&e.append(")")}expand(e,t){let i=this.lhs.expand(e,t),n=this.rhs.expand(e,t);return i===this.lhs&&n===this.rhs?this:new this.constructor(this.scope,i,n)}},ou=class extends fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},pn=class extends fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},au=class extends fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},ca=class extends fs{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},si=class extends su{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},af=class extends si{constructor(e,t){super(e,t)}getOp(){return"not "}},ji=class extends su{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},da=class extends ou{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},lf=class extends da{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},pa=class extends ou{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},hf=class extends pa{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},uf=class extends pa{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},cf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},df=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},pf=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},ro=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},fa=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},ff=class extends pn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},lu=class extends au{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},hu=class extends au{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},ga=class extends ca{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},uu=class extends ca{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},cu=class extends ca{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},nr=class extends Tt{constructor(e,t,i){var n;super(e),this.num=t,c(this,"unit"),this.unit=(n=i?.toLowerCase())!=null?n:""}appendTo(e,t){e.append(this.num.toString()),e.append(ri(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},De=class extends Tt{constructor(e,t){super(e),this.qualifiedName=t}appendTo(e,t){e.append(this.qualifiedName)}evaluateCore(e){return e.evalName(this.scope,this.qualifiedName).evaluate(e)}dependCore(e,t,i){return e===this||t.evalName(this.scope,this.qualifiedName).dependOuter(e,t,i)}},wl=class extends Tt{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(ri(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},ze=class extends Tt{constructor(e,t,i){super(e),this.fn=t,this.str=i}appendTo(e,t){e.append(this.str)}evaluateCore(e){return this.fn.call(e)}};function gf(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function mf(e,t,i){let n=t;for(let r=0;r<t.length;r++){let s=t[r].expand(e,i);if(t!==n)n[r]=s;else if(s!==t[r]){n=Array(t.length);for(let o=0;o<r;o++)n[o]=t[o];n[r]=s}}return n}var On=class du extends Tt{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),gf(t,this.params)}evaluateCore(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)}dependCore(t,i,n){if(t===this)return!0;for(let r=0;r<this.params.length;r++)if(this.params[r].dependOuter(t,i,n))return!0;return i.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,i,n)}expand(t,i){let n=mf(t,this.params,i);return n===this.params?this:new du(this.scope,this.qualifiedName,n)}},wf=class pu extends Tt{constructor(t,i,n,r){super(t),this.cond=i,this.ifTrue=n,this.ifFalse=r}appendTo(t,i){i>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),i>0&&t.append(")")}evaluateCore(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)}dependCore(t,i,n){return t===this||this.cond.dependOuter(t,i,n)||this.ifTrue.dependOuter(t,i,n)||this.ifFalse.dependOuter(t,i,n)}expand(t,i){let n=this.cond.expand(t,i),r=this.ifTrue.expand(t,i),s=this.ifFalse.expand(t,i);return n===this.cond&&r===this.ifTrue&&s===this.ifFalse?this:new pu(this.scope,n,r,s)}},We=class extends Tt{constructor(e,t){super(e),this.val=t}appendTo(e,t){switch(typeof this.val){case"number":case"boolean":e.append(this.val.toString());break;case"string":e.append('"'),e.append(ir(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},yl=class fu extends Tt{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(ir(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")}evaluateCore(t){return t.evalMediaTest(this.name.name,this.value)}dependCore(t,i,n){return t===this||this.value.dependOuter(t,i,n)}expand(t,i){let n=this.value.expand(t,i);return n===this.value?this:new fu(this.scope,this.name,n)}},yf=class extends Tt{constructor(e,t,i,n){super(e),this.name=t,this.value=i,this.isFunc=n}appendTo(e,t){this.isFunc&&e.append(this.name),e.append("("),!this.isFunc&&this.name&&(e.append(this.name),e.append(":")),e.append(this.value),e.append(")")}evaluateCore(e){return e.evalSupportsTest(this.name,this.value,this.isFunc)}},gu=class extends Tt{constructor(e,t){super(e),this.index=t}appendTo(e,t){e.append("$"),e.append(this.index.toString())}expand(e,t){let i=t[this.index];if(!i)throw new Error(`Parameter missing: ${this.index}`);return i}};function Et(e,t,i){return t===e._false||t===e.zero||i==e._false||i==e.zero?e._false:t===e._true||t===e.one?i:i===e._true||i===e.one?t:new da(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new lu(e,t,i)}function pe(e,t,i){return t===e.zero?new ji(e,i):i===e.zero?t:new hu(e,t,i)}function Pr(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new ga(e,t,i)}function so(e,t,i){return t===e.zero?e.zero:i===e.one?t:new uu(e,t,i)}var Kt=class{visitValues(e){for(let t=0;t<e.length;t++)e[t].visit(this);return null}visitEmpty(e){return null}visitSlash(e){return null}visitStr(e){return null}visitIdent(e){return null}visitNumeric(e){return null}visitNum(e){return null}visitInt(e){return this.visitNum(e)}visitHexColor(e){return null}visitURL(e){return null}visitURange(e){return null}visitSpaceList(e){return this.visitValues(e.values),null}visitCommaList(e){return this.visitValues(e.values),null}visitFunc(e){return this.visitValues(e.values),null}visitExpr(e){return null}},Ai=class extends Kt{constructor(){super(),c(this,"error",!1)}visitValues(e){let t=null;for(let i=0;i<e.length;i++){let n=e[i],r=n.visit(this);if(this.error)return[];if(t)t[i]=r;else if(n!==r){t=new Array(e.length);for(let s=0;s<i;s++)t[s]=e[s];t[i]=r}}return t||e}visitEmpty(e){return e}visitStr(e){return e}visitIdent(e){return e}visitSlash(e){return e}visitNumeric(e){return e}visitNum(e){return e}visitInt(e){return e}visitHexColor(e){return e}visitURL(e){return e}visitURange(e){return e}visitSpaceList(e){let t=this.visitValues(e.values);return this.error?X:t===e.values?e:new J(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?X:t===e.values?e:new Ze(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?X:t===e.values?e:new Ri(e.name,t)}visitExpr(e){return e}},Je=class{toString(){let e=new oi;return this.appendTo(e,!0),e.toString()}stringValue(){let e=new oi;return this.appendTo(e,!1),e.toString()}toExpr(e,t){return null}appendTo(e,t){e.append("[error]")}isExpr(){return!1}isNumeric(){return!1}isNum(){return!1}isIdent(){return!1}isSpaceList(){return!1}visit(e){return this}},mu=class wu extends Je{static get instance(){return this.empty||(this.empty=new wu),this.empty}constructor(){super()}toExpr(t,i){return new We(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(mu,"empty");var bf=mu,X=bf.instance,yu=class bu extends Je{static get instance(){return this.slash||(this.slash=new bu),this.slash}constructor(){super()}toExpr(t,i){return new We(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(yu,"slash");var vf=yu,fn=vf.instance,j=class extends Je{constructor(e){super(),this.str=e}toExpr(e,t){return new We(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(ir(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},oo={},le=class extends Je{constructor(e){if(super(),this.name=e,oo[e])throw new Error("E_INVALID_CALL");oo[e]=this}toExpr(e,t){return new We(e,this.name)}appendTo(e,t){t?e.append(ri(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function F(e){let t=oo[e];return t||(t=new le(e)),t}var I=class extends Je{constructor(e,t){var i;super(),this.num=e,c(this,"unit"),this.unit=(i=t?.toLowerCase())!=null?i:""}toExpr(e,t){return this.num==0?e.zero:t&&this.unit=="%"?this.num==100?t:new ga(e,t,new We(e,this.num/100)):new nr(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},gt=class extends Je{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new We(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Le=class extends gt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},vu=class extends Je{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},Qe=class extends Je{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(ir(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},xu=class extends Je{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function ma(e,t,i,n){var r,s;let o=t.length;if(o>0){(r=t[0])==null||r.appendTo(e,n);for(let a=1;a<o;a++)e.append(i),(s=t[a])==null||s.appendTo(e,n)}}var J=class extends Je{constructor(e){super(),this.values=e}appendTo(e,t){ma(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},Ze=class extends Je{constructor(e){super(),this.values=e}appendTo(e,t){ma(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Ri=class extends Je{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(ri(this.name)),e.append("("),ma(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},U=class extends Je{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof We||this.expr instanceof nr?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}},_i=class extends Je{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function et(e,t){if(e){if(e.isNumeric()){let i=e;return t.queryUnitSize(i.unit,!1)*i.num}if(e.isNum())return e.num}return 0}function Su(e,t){return new I(et(e,t),"px")}var b={absolute:F("absolute"),all:F("all"),always:F("always"),anywhere:F("anywhere"),auto:F("auto"),avoid:F("avoid"),balance:F("balance"),balance_all:F("balance-all"),block:F("block"),block_end:F("block-end"),block_start:F("block-start"),both:F("both"),bottom:F("bottom"),border_box:F("border-box"),break_all:F("break-all"),break_word:F("break-word"),clip:F("clip"),crop:F("crop"),cross:F("cross"),column:F("column"),discard:F("discard"),exclusive:F("exclusive"),_false:F("false"),fixed:F("fixed"),flex:F("flex"),flow_root:F("flow-root"),footnote:F("footnote"),footer:F("footer"),grid:F("grid"),header:F("header"),hidden:F("hidden"),horizontal_tb:F("horizontal-tb"),inherit:F("inherit"),initial:F("initial"),inline:F("inline"),inline_block:F("inline-block"),inline_end:F("inline-end"),inline_start:F("inline-start"),inside:F("inside"),keep:F("keep"),landscape:F("landscape"),left:F("left"),line:F("line"),list_item:F("list-item"),ltr:F("ltr"),manual:F("manual"),max_content:F("max-content"),min_content:F("min-content"),none:F("none"),normal:F("normal"),oeb_page_foot:F("oeb-page-foot"),oeb_page_head:F("oeb-page-head"),outside:F("outside"),padding_box:F("padding-box"),page:F("page"),relative:F("relative"),revert:F("revert"),right:F("right"),same:F("same"),scale:F("scale"),snap_block:F("snap-block"),snap_inline:F("snap-inline"),solid:F("solid"),spread:F("spread"),_static:F("static"),rtl:F("rtl"),table:F("table"),table_caption:F("table-caption"),table_cell:F("table-cell"),table_footer_group:F("table-footer-group"),table_header_group:F("table-header-group"),table_row:F("table-row"),top:F("top"),transparent:F("transparent"),unset:F("unset"),vertical_lr:F("vertical-lr"),vertical_rl:F("vertical-rl"),visible:F("visible"),_true:F("true")},bl=new I(100,"%"),rr=new I(100,"pvw"),sr=new I(100,"pvh"),Ee=new I(0,"px"),X0=new xu("U+0-10FFFF"),vl={"font-size":1,"line-height":2,color:3};function K(e){return e===b.inherit||e===b.initial||e===b.revert||e===b.unset}function xl(e,t){let i=vl[e]||Number.MAX_VALUE,n=vl[t]||Number.MAX_VALUE;return i-n}function zt(e){return e?.length>2&&e.startsWith("--")}var zi,Di,Vi,Cu=class Vt{constructor(t,i,n){Z(this,zi),Z(this,Di),Z(this,Vi),Fe(this,zi,Math.round(Math.max(0,Math.min(t,Vt.MAX)))),Fe(this,Di,Math.round(Math.max(0,Math.min(i,Vt.MAX)))),Fe(this,Vi,Math.round(Math.max(0,Math.min(n,Vt.MAX))))}static fromInt(t,i,n){return new Vt(t,i,n)}offset(t,i,n){return new Vt(M(this,zi)+t,M(this,Di)+i,M(this,Vi)+n)}toKey(){return JSON.stringify([M(this,zi),M(this,Di),M(this,Vi)])}toColorFunc(t){return new Ri("color",[new J([F("srgb"),new gt(M(this,zi)/Vt.MAX),new gt(M(this,Di)/Vt.MAX),new gt(M(this,Vi)/Vt.MAX),...t!==null?[fn,new gt(t)]:[]])])}};zi=new WeakMap,Di=new WeakMap,Vi=new WeakMap,c(Cu,"MAX",1e4);var Jt=Cu,mi,wi,yi,Lt,ku=class st{constructor(t,i,n,r){Z(this,mi),Z(this,wi),Z(this,yi),Z(this,Lt),Fe(this,mi,Math.round(Math.max(0,Math.min(t,st.MAX)))),Fe(this,wi,Math.round(Math.max(0,Math.min(i,st.MAX)))),Fe(this,yi,Math.round(Math.max(0,Math.min(n,st.MAX)))),Fe(this,Lt,Math.round(Math.max(0,Math.min(r,st.MAX))))}static fromInt(t,i,n,r){return new st(t,i,n,r)}static fromNumber(t,i,n,r){return new st(t*st.MAX,i*st.MAX,n*st.MAX,r*st.MAX)}toSRGB(){let t=st.MAX-M(this,Lt);return Jt.fromInt(Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,mi)*t/st.MAX)+M(this,Lt)),Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,wi)*t/st.MAX)+M(this,Lt)),Jt.MAX-Math.min(Jt.MAX,Math.round(M(this,yi)*t/st.MAX)+M(this,Lt)))}equals(t){return M(this,mi)===M(t,mi)&&M(this,wi)===M(t,wi)&&M(this,yi)===M(t,yi)&&M(this,Lt)===M(t,Lt)}toJSON(){return{c:M(this,mi),m:M(this,wi),y:M(this,yi),k:M(this,Lt)}}};mi=new WeakMap,wi=new WeakMap,yi=new WeakMap,Lt=new WeakMap,c(ku,"MAX",1e4);var xf=ku;function Oi(e){return e instanceof gt?Math.max(0,Math.min(1,e.num)):e instanceof I&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function Eu(e){if(e.name!=="device-cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof J?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=Oi(t[0]),n=Oi(t[1]),r=Oi(t[2]),s=Oi(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===fn){if(t.length!==6)return null;o=Oi(t[5])}else{if(t.length!==5)return null;o=Oi(t[4])}if(o===null)return null}return{cmyk:xf.fromNumber(i,n,r,s),alpha:o}}function*Sf(e){for(let t=-e;t<=e;t++)for(let i=-e;i<=e;i++)for(let n=-e;n<=e;n++)Math.abs(t)+Math.abs(i)+Math.abs(n)===e&&(yield[t,i,n])}var Si,Yr,Nu,Sl,Pu=class{constructor(){Z(this,Yr),Z(this,Si,new Map)}registerDeviceCmyk(e){let t=Eu(e);return t?Se(this,Yr,Nu).call(this,t.cmyk).toColorFunc(t.alpha):null}toJSON(){let e={};return M(this,Si).forEach((t,i)=>{e[i]=t.toJSON()}),e}};Si=new WeakMap,Yr=new WeakSet,Nu=function(e){let t=e.toSRGB(),i=t.toKey(),n=M(this,Si).get(i);return n?n.equals(e)?t:Se(this,Yr,Sl).call(this,e,t):(M(this,Si).set(i,e),t)},Sl=function(e,t){for(let i=1;i<=Jt.MAX;i++)for(let[n,r,s]of Sf(i)){let o=t.offset(n,r,s),a=o.toKey();if(!M(this,Si).has(a))return M(this,Si).set(a,e),o}return $.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Tr,Cn,kn,Tu=class extends Ai{constructor(e){super(),Z(this,Tr),Z(this,Cn,new Map),Z(this,kn,!1),Fe(this,Tr,e??new Pu)}reset(){Fe(this,kn,!1)}hadDeviceCmyk(){return M(this,kn)}recordConversion(e,t){M(this,Cn).set(e,t)}getConversions(){if(M(this,Cn).size===0)return null;let e={};return M(this,Cn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=M(this,Tr).registerDeviceCmyk(e);return t?(Fe(this,kn,!0),t):super.visitFunc(e)}};Tr=new WeakMap,Cn=new WeakMap,kn=new WeakMap;var bt=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},ti=class{constructor(e,t){this.x=e,this.y=t}},Os=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},Cl=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Gt=class{constructor(e,t,i,n){this.y1=e,this.y2=t,this.x1=i,this.x2=n,c(this,"left",null),c(this,"right",null)}};function Cf(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var gs=class Iu{constructor(t){this.points=t}addSegments(t,i){let n=this.points,r=n.length,s=n[r-1];for(let o=0;o<r;o++){let a=n[o],l;s.y<a.y?l=new Cl(s,a,1,i):l=new Cl(a,s,-1,i),t.push(l),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new ti(r.x+t,r.y+i));return new Iu(n)}};function kl(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new ti(e+i*Math.sin(o),t+n*Math.cos(o)))}return new gs(r)}function wa(e,t,i,n){return new gs([new ti(e,t),new ti(i,t),new ti(i,n),new ti(e,n)])}var yr=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function El(e,t){let i=e.low.x+(e.high.x-e.low.x)*(t-e.low.y)/(e.high.y-e.low.y);if(isNaN(i))throw new Error("Bad intersection");return i}function kf(e,t,i,n){let r,s,o,a;t.high.y<i&&$.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=El(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=El(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new yr(r,s,t.shapeId,-1)),e.push(new yr(o,a,t.shapeId,1))):(e.push(new yr(o,a,t.shapeId,-1)),e.push(new yr(r,s,t.shapeId,1)))}function Ef(e,t,i){let n=t+i,r=Array(n),s=Array(n),o;for(o=0;o<=n;o++)r[o]=0,s[o]=0;let a=[],l=!1,h=e.length;for(let u=0;u<h;u++){let d=e[u];r[d.shapeId]+=d.winding,s[d.shapeId]+=d.lowOrHigh;let p=!1;for(o=0;o<t;o++)if(r[o]&&!s[o]){p=!0;break}if(p){for(o=t;o<=n;o++)if(r[o]||s[o]){p=!1;break}}l!=p&&(a.push(d.x),l=p)}return a}function Nf(e,t){return t?Math.ceil(e/t)*t:e}function Nl(e,t){return t?Math.floor(e/t)*t:e}function Pf(e){return new ti(e.y,-e.x)}function Kr(e){return new bt(e.y1,-e.x2,e.y2,-e.x1)}function Au(e){return new bt(-e.y2,e.x1,-e.y1,e.x2)}function Pl(e){return new gs(e.points.map(t=>Pf(t)))}function Tf(e,t,i,n,r,s){s&&(e=Kr(e),t=t.map(y=>Pl(y)),i=i.map(y=>Pl(y)));let o=t.length,a=i?i.length:0,l=[],h=[],u,d,p;for(u=0;u<o;u++)t[u].addSegments(h,u);for(u=0;u<a;u++)i[u].addSegments(h,u+o);let f=h.length;h.sort(Cf);let m=0;for(;h[m].shapeId>=o;)m++;let g=h[m].low.y;g>e.y1&&l.push(new Gt(e.y1,g,e.x2,e.x2));let w=0,v=[];for(;w<f&&(p=h[w]).low.y<g;)p.high.y>g&&v.push(p),w++;for(;w<f||v.length>0;){let y=e.y2,C=Math.min(Nf(Math.ceil(g+n),r),e.y2);for(d=0;d<v.length&&y>C;d++)p=v[d],p.low.x==p.high.x?p.high.y<y&&(y=Math.max(Nl(p.high.y,r),C)):p.low.x!=p.high.x&&(y=C);for(y>e.y2&&(y=e.y2);w<f&&(p=h[w]).low.y<y;){if(p.high.y<g){w++;continue}if(p.low.y<C)p.low.y==p.high.y&&p.low.y==g||(v.push(p),y=C),w++;else{let H=Nl(p.low.y,r);H<y&&(y=H);break}}let E=[];for(d=0;d<v.length;d++)kf(E,v[d],g,y);E.sort((H,V)=>H.x-V.x||H.lowOrHigh-V.lowOrHigh);let A=Ef(E,o,a);if(A.length==0)l.push(new Gt(g,y,e.x2,e.x2));else{let H=0,V=e.x1;for(d=0;d<A.length;d+=2){let ie=Math.max(e.x1,A[d]),ne=Math.min(e.x2,A[d+1])-ie;ne>H&&(H=ne,V=ie)}H==0?l.push(new Gt(g,y,e.x2,e.x2)):l.push(new Gt(g,y,Math.max(V,e.x1),Math.min(V+H,e.x2)))}if(y==e.y2)break;for(g=y,d=v.length-1;d>=0;d--)v[d].high.y<=y&&v.splice(d,1)}return Ru(e,l),l}function Ru(e,t){let i=t.length-1,n=new Gt(e.y2,e.y2,e.x1,e.x2);for(;i>=0;){let r=n;n=t[i],(n.y2-n.y1<1||n.x1==r.x1&&n.x2==r.x2)&&(r.y1=n.y1,t.splice(i,1),n=r),i--}}function Fu(e,t){let i=0,n=e.length;for(;i<n;){let r=Math.floor((i+n)/2);t>=e[r].y2?i=r+1:n=r}return i}function If(e,t){if(!e.length)return t;let i=t.y1,n,r;for(r=0;r<e.length&&(n=e[r],!(n.y2>t.y1&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2));r++)i=Math.max(i,n.y2);let s=i;for(;r<e.length&&(n=e[r],!(n.y1>=t.y2||n.x1-.1>t.x1||n.x2+.1<t.x2));r++)s=n.y2;return r===e.length?s=t.y2:s=Math.min(s,t.y2),s<=i?null:new bt(t.x1,i,t.x2,s)}function Af(e,t){if(!e.length)return t;let i=t.y2,n,r;for(r=e.length-1;r>=0&&(n=e[r],!(r===e.length-1&&n.y2<t.y2))&&!(n.y1<t.y2&&n.x1-.1<=t.x1&&n.x2+.1>=t.x2);r--)i=Math.min(i,n.y1);let s=Math.min(i,n.y2);for(;r>=0&&(n=e[r],!(n.y2<=t.y1||n.x1-.1>t.x1||n.x2+.1<t.x2));r--)s=n.y1;return s=Math.max(s,t.y1),i<=s?null:new bt(t.x1,s,t.x2,i)}function Rf(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=Fu(t,r);for(;;){let l=r+o;if(l>e.y2)return!1;let h=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<l;d++){let p=t[d];p.x1>h&&(h=p.x1),p.x2<u&&(u=p.x2)}if(h+s<=u||a>=t.length)return n=="left"?(i.x1=h,i.x2=h+s):(i.x1=u-s,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Ff(e,t,i,n,r){for(n||(n=[new Gt(i.y1,i.y2,i.x1,i.x2)]);n.length>0&&n[0].y2<=e.y1;)n.shift();if(n.length==0)return;n[0].y1<e.y1&&(n[0].y1=e.y1);let s,o=t.length==0?e.y1:t[t.length-1].y2;o<e.y2&&t.push(new Gt(o,e.y2,e.x1,e.x2));let a=Fu(t,n[0].y1);for(let l of n){if(a==t.length)break;for(t[a].y1<l.y1&&(s=t[a],a++,t.splice(a,0,new Gt(l.y1,s.y2,s.x1,s.x2)),s.y2=l.y1);a<t.length&&(s=t[a++],s.y2>l.y2&&(t.splice(a,0,new Gt(l.y2,s.y2,s.x1,s.x2)),s.y2=l.y2),l.x1!=l.x2&&(r=="left"?s.x1=Math.min(l.x2,e.x2):s.x2=Math.max(l.x1,e.x1)),s.y2!=l.y2););}Ru(e,t)}var Lf=class extends Kt{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Of(e){if(e){let t=new Lf;try{return e.visit(t),t.propSet}catch(i){$.warn(i,"toSet:")}}return{}}var Bf=class extends Kt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Tl(e,t){if(e){let i=new Bf(t);try{return e.visit(i),i.value}catch(n){$.warn(n,"toInt: ")}}return t}var Mf=class extends Kt{constructor(){super(),c(this,"collect",!1),c(this,"coords",[]),c(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 I(0,"px")),null}visitSpaceList(e){return this.visitValues(e.values),null}visitFunc(e){return this.collect||(this.collect=!0,this.visitValues(e.values),this.collect=!1,this.name=e.name.toLowerCase()),null}getShape(e,t,i,n,r){if(this.coords.length>0){let s=[];switch(this.coords.forEach((o,a)=>{if(o.unit=="%"){let l=a%2==0?i:n;a==3&&this.name=="circle"&&(l=Math.sqrt((i*i+n*n)/2)),s.push(o.num*l/100)}else s.push(o.num*r.queryUnitSize(o.unit,!1))}),this.name){case"polygon":if(s.length%2==0){let o=[];for(let a=0;a<s.length;a+=2)o.push(new ti(e+s[a],t+s[a+1]));return new gs(o)}break;case"rectangle":if(s.length==4)return wa(e+s[0],t+s[1],e+s[0]+s[2],t+s[1]+s[3]);break;case"ellipse":if(s.length==4)return kl(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return kl(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function Lu(e,t,i,n,r,s){if(e){let o=new Mf;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){$.warn(a,"toShape:")}}return wa(t,i,t+n,i+r)}var _f=class extends Kt{constructor(e){super(),this.reset=e,c(this,"counters",{}),c(this,"name",null)}visitIdent(e){return this.name=e.toString(),this.reset?this.counters[this.name]=0:this.counters[this.name]=(this.counters[this.name]||0)+1,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:1)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function Bn(e,t){let i=new _f(t);try{e.visit(i)}catch(n){$.warn(n,"toCounters:")}return i.counters}var zf=class extends Ai{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new Qe(this.transformer.transformURL(e.url,this.baseUrl))}};function Bs(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function Xi(e,t){if(t==="content"){let i=e.cloneNode(!0);return i.querySelectorAll("[data-adapt-pseudo]").forEach(n=>n.remove()),i.textContent||""}else{let i=e.querySelector(`[data-adapt-pseudo="${t}"]`);return i&&i.textContent||""}}var Df=class{constructor(e,t){this.targetId=e,this.resolved=t,c(this,"pageCounters",null),c(this,"spineIndex",-1),c(this,"pageIndex",-1)}equals(e){return this===e?!0:e?this.targetId===e.targetId&&this.resolved===e.resolved&&this.spineIndex===e.spineIndex&&this.pageIndex===e.pageIndex:!1}isResolved(){return this.resolved}resolve(){this.resolved=!0}unresolve(){this.resolved=!1}},Vf=class{constructor(e,t){this.counterStore=e,this.baseURL=t}countersOfId(e,t){e=this.counterStore.documentURLTransformer.transformFragment(e,this.baseURL),this.counterStore.countersById[e]=t}getExprContentListener(){return this.counterStore.getExprContentListener()}},Hf=class{constructor(e,t,i,n){this.counterStore=e,this.baseURL=t,this.rootScope=i,this.pageScope=n,c(this,"styler",null),c(this,"namedStringValues",{}),c(this,"runningElements",{})}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Pe(e,this.baseURL),this.baseURL);return t.charAt(0)==="#"&&(t=t.substring(1)),t}getPageCounterVal(e,t){let i=()=>{let s=this.counterStore.currentPageCounters[e];return s&&s.length?s[s.length-1]:null},n=new ze(this.pageScope,()=>t(i()),`page-counter-${e}`),r=s=>t(s[s.length-1]);return this.counterStore.registerPageCounterExpr(e,r,n),n}getPageCountersVal(e,t){let i=()=>this.counterStore.currentPageCounters[e]||[],n=new ze(this.pageScope,()=>t(i()),`page-counters-${e}`);return this.counterStore.registerPageCounterExpr(e,t,n),n}getTargetCounters(e,t,i){let n=this.counterStore.countersById[t];return!n&&i&&e&&(this.styler.styleUntilIdIsReached(e),n=this.counterStore.countersById[t]),n||null}getTargetPageCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageCounters:this.counterStore.pageCountersById[e]||null}getTargetPageText(e,t){if(this.counterStore.currentPage.elementsById[e]){let i=this.counterStore.currentPage.elementsById[e];if(i&&i.length>0){let n=i[0];return t==="before"||t==="after"||t==="marker"?Xi(n,t):Xi(n,"content")}return""}else{if(e in this.counterStore.pageTextById){let i=this.counterStore.pageTextById[e];return i[t]!==void 0?i[t]:i.content||""}return null}}getTargetCounterVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e),s=this.getTargetCounters(n,r,!1);if(s&&s[t]){let a=s[t];return new We(this.rootScope,i(a[a.length-1]||null))}let o=new ze(this.pageScope,()=>{if(s=this.getTargetCounters(n,r,!0),s)if(s[t]){let a=s[t];return i(a[a.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let l=a[t];return i(l[l.length-1]||null)}else return i(0);else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counter-${t}-of-${e}`);return this.counterStore.registerTargetCounterExpr(t,i,o,r),o}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new ze(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=s[t]||[],a=this.getTargetCounters(n,r,!0)[t]||[];return i(o.concat(a))}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new ze(this.pageScope,()=>{if(t==="first-letter"){let s=this.getTargetPageText(i,"before"),o=this.getTargetPageText(i,"content"),a=this.getTargetPageText(i,"after");if(s===null&&o===null&&a===null)return this.counterStore.saveReferenceOfCurrentPage(i,!1),"??";let l=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let h=l.match(qr);return h?h[0]:""}let r=this.getTargetPageText(i,t);return r!==null?(this.counterStore.resolveReference(i),r):(this.counterStore.saveReferenceOfCurrentPage(i,!1),"??")},`target-text-${t}-of-${e}`);return this.counterStore.registerTargetTextExpr(t,n,i),n}getNamedStringVal(e,t){return new ze(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new ze(this.pageScope,()=>this.getRunningValue(this.runningElements,e,t),`running-element-${t}-${e}`)}getRunningValue(e,t,i){let n=e[t];if(!n)return"";let r=Object.keys(n).map(p=>parseInt(p,10)).sort(Kh),s=this.counterStore.currentPage,o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${Ut}]`)).map(p=>parseInt(p.getAttribute(Ut),10))),l=-1,h=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],m=p>0?r[p-1]:-1,g=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(l<0&&(l=f,d=-1),h<0)if(f===o)h=f;else{m<l&&(h=m);let w=s.container.querySelector(`[${Ut}="${f}"]`);if(!w)h<0&&(h=f);else{let v=s.container.querySelector(`[${Ut}="${o}"]`);if(v||(v=s.container.querySelector(`[${Ut}="0"]`)),v){for(let y=v;y;y=y.firstElementChild)if(y===w){h=f;break}}}}u=f}else(g>a||g<0)&&(l=h=u=d=f)}return n[{first:l,start:h,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]={});n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]={});i[t]=String(t)}},Uf=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",{}),c(this,"pageCountersById",{}),c(this,"pageTextById",{}),c(this,"currentPageCounters",{}),c(this,"previousPageCounters",{}),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",{}),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",{}),c(this,"resolvedReferences",{}),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new Vf(this,e)}createCounterResolver(e,t,i){return new Hf(this,e,t,i)}setCurrentPage(e){this.currentPage=e}definePageCounter(e,t){this.currentPageCounters[e]?this.currentPageCounters[e].push(t):this.currentPageCounters[e]=[t]}forceSetPageCounter(e){let t=this.currentPageCounters.page;!t||!t.length?this.currentPageCounters.page=[e]:t[t.length-1]=e}updatePageCounters(e,t){this.previousPageCounters=Bs(this.currentPageCounters);let i,n=e["counter-reset"];if(n){let o=n.evaluate(t);o&&(i=Bn(o,!0))}if(i)for(let o in i)this.definePageCounter(o,i[o]);let r,s=e["counter-increment"];if(s){let o=s.evaluate(t);o&&(r=Bn(o,!1))}r?"page"in r||(r.page=1):(r={},r.page=1);for(let o in r){this.currentPageCounters[o]||this.definePageCounter(o,0);let a=this.currentPageCounters[o];a[a.length-1]+=r[o]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Bs(e)}popPageCounters(){this.currentPageCounters=this.currentPageCountersStack.pop()}resolveReference(e){let t=this.unresolvedReferences[e],i=this.resolvedReferences[e];i||(i=this.resolvedReferences[e]=[]);let n=!1;for(let r=0;r<this.referencesToSolve.length;){let s=this.referencesToSolve[r];if(s.targetId===e){if(s.resolve(),this.referencesToSolve.splice(r,1),t){let o=t.indexOf(s);o>=0&&t.splice(o,1)}i.push(s),n=!0}else r++}n||this.saveReferenceOfCurrentPage(e,!0)}saveReferenceOfCurrentPage(e,t){if(!this.newReferencesOfCurrentPage.some(i=>i.targetId===e)){let i=new Df(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=Bs(this.currentPageCounters);i.forEach(o=>{this.pageCountersById[o]=s;let a=this.currentPage.elementsById[o];if(a&&a.length>0){let h=a[0];this.pageTextById[o]={content:Xi(h,"content"),before:Xi(h,"before"),after:Xi(h,"after"),marker:Xi(h,"marker")}}let l=this.pageIndicesById[o];if(l&&l.pageIndex<t){let h=this.resolvedReferences[o];if(h){let u=this.unresolvedReferences[o];u||(u=this.unresolvedReferences[o]=[]);let d;for(;d=h.shift();)d.unresolve(),u.push(d)}}this.pageIndicesById[o]={spineIndex:e,pageIndex:t}})}let n=this.previousPageCounters,r;for(;r=this.newReferencesOfCurrentPage.shift();){r.pageCounters=n,r.spineIndex=e,r.pageIndex=t;let s;r.isResolved()?(s=this.resolvedReferences[r.targetId],s||(s=this.resolvedReferences[r.targetId]=[])):(s=this.unresolvedReferences[r.targetId],s||(s=this.unresolvedReferences[r.targetId]=[])),s.every(o=>!r.equals(o))&&s.push(r)}this.currentPage=null}getUnresolvedRefsToPage(e){let t=[];Object.keys(e.elementsById).forEach(r=>{let s=this.unresolvedReferences[r];s&&(t=t.concat(s))}),t.sort((r,s)=>r.spineIndex-s.spineIndex||r.pageIndex-s.pageIndex);let i=[],n=null;return t.forEach(r=>{!n||n.spineIndex!==r.spineIndex||n.pageIndex!==r.pageIndex?(n={spineIndex:r.spineIndex,pageIndex:r.pageIndex,pageCounters:r.pageCounters,refs:[r]},i.push(n)):n.refs.push(r)}),i}pushReferencesToSolve(e){this.referencesToSolveStack.push(this.referencesToSolve),this.referencesToSolve=e}popReferencesToSolve(){this.referencesToSolve=this.referencesToSolveStack.pop()}registerPageCounterExpr(e,t,i){e==="pages"?this.pagesCounterExprs.push({expr:i,format:t}):this.pageCounterExprs.push({expr:i,format:t})}registerTargetCounterExpr(e,t,i,n){this.targetCounterExprs.push({name:e,expr:i,format:t,transformedId:n})}registerTargetTextExpr(e,t,i){this.targetTextExprs.push({pseudoElement:e,expr:t,transformedId:i})}getExprContentListener(){return this.exprContentListener.bind(this)}exprContentListener(e,t,i){if(e instanceof ze){if(e.str=="viv-leader"){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute("data-viv-leader",e.key),s.setAttribute("data-viv-leader-value",t),s}else if(e.str.startsWith("running-element-")){let s=t&&i.querySelectorAll(`[${Ut}="${t}"]`);if(!s||s.length===0)return null;let o=s[s.length-1].cloneNode(!0);return this.fixPageCounterInRunningElement(o),o.style.position="",o.style.visibility="",o}else if(e.str.startsWith("target-counter-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(zs,e.key),s}else if(e.str.startsWith("target-text-")){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(Ds,e.key),s}}let n=this.pagesCounterExprs.findIndex(s=>s.expr===e)>=0,r=!n&&this.pageCounterExprs.findIndex(s=>s.expr===e)>=0;if(n||r){let s=i.createElementNS("http://www.w3.org/1999/xhtml","span");return s.textContent=t,s.setAttribute(n?Ms:_s,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${_s}]`);for(let r of t){let s=r.getAttribute(_s),o=this.pageCounterExprs.find(u=>u.expr.key===s),a=(o?.expr).str,l=a?.replace(/^page-counters?-/,""),h=this.currentPageCounters[l];h&&(r.textContent=o.format(h))}let i=e.querySelectorAll(`[${zs}]`);for(let r of i)r.setAttribute(Il,!0);let n=e.querySelectorAll(`[${Ds}]`);for(let r of n)r.setAttribute(Al,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${Ms}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(Ms),l=this.pagesCounterExprs.findIndex(h=>h.expr.key===a);l>=0,o.textContent=this.pagesCounterExprs[l].format([n])}let r=e.root.querySelectorAll(`[${Il}]`);for(let o of r){let a=o.getAttribute(zs),l=this.targetCounterExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageCountersById[l.transformedId];if(h){let u=h[l.name];u&&(o.textContent=l.format(u[u.length-1]))}}}let s=e.root.querySelectorAll(`[${Al}]`);for(let o of s){let a=o.getAttribute(Ds),l=this.targetTextExprs.find(h=>h.expr.key===a);if(l&&l.transformedId){let h=this.pageTextById[l.transformedId];h&&(o.textContent=(t=h[l.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new $f(this,e)}},Ms="data-vivliostyle-pages-counter",_s="data-vivliostyle-page-counter",zs="data-vivliostyle-target-counter",Ds="data-vivliostyle-target-text",Il="data-vivliostyle-target-counter-in-running",Al="data-vivliostyle-target-text-in-running",$f=class{constructor(e,t){this.counterStore=e,this.pageIndex=t}allowLayout(e){if(!e||e.after)return!0;let t=e.viewNode;if(!t||t.nodeType!==1)return!0;let i=t.getAttribute("data-vivliostyle-id")||t.getAttribute("id")||t.getAttribute("name");if(!i||!this.counterStore.resolvedReferences[i]&&!this.counterStore.unresolvedReferences[i])return!0;let n=this.counterStore.pageIndicesById[i];return n?this.pageIndex>=n.pageIndex:!0}};function Wf(e){if(e=e.substr(1),e.match(/^[^0-9a-fA-F\n\r]$/))return e;let t=parseInt(e,16);return isNaN(t)?"":t===0||t>=55296&&t<=57343||t>1114111?"\uFFFD":String.fromCodePoint(t)}function di(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,Wf)}var Gf=class{constructor(){c(this,"type"),c(this,"precededBySpace",!1),c(this,"num",0),c(this,"text",""),c(this,"position",0),this.type=0}toString(){switch(this.type){case 10:return"(";case 11:return")";case 12:return"{";case 13:return"}";case 14:return"[";case 15:return"]";case 16:return",";case 17:return";";case 18:return":";case 19:return"/";case 21:return"%";case 22:return"?";case 23:return"+";case 24:return"-";case 25:return"||";case 26:return"&&";case 31:return"!";case 32:return"$";case 33:return"^";case 34:return"|";case 35:return"~";case 36:return"*";case 37:return">";case 38:return"<";case 39:return"=";case 41:return"!=";case 42:return"$=";case 43:return"^=";case 44:return"|=";case 45:return"~=";case 46:return"*=";case 47:return">=";case 48:return"<=";case 49:return"==";case 50:return"::";case 51:return"<!--";case 52:return"-->";case 3:return this.num.toString()+this.text;case 4:case 5:return this.num.toString();case 20:return"@"+this.text;case 7:return"#"+this.text;case 6:return this.text+"(";case 9:return"."+this.text;case 0:return"/*EOF*/";default:return this.text}}};function Ge(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Ht=[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];Ht[NaN]=80;var Ot=[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];Ot[NaN]=43;var jf=[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];Ot[NaN]=43;var Ou=[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];Ou[NaN]=35;var Bu=[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];Bu[NaN]=45;var ao=[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];ao[NaN]=37;var lo=[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];lo[NaN]=38;var pi=Ge(35,[61,36]),Xf=Ge(35,[58,77]),qf=Ge(35,[61,36,124,50]),Yf=Ge(35,[38,51]),Kf=Ge(35,[42,54]),Zf=Ge(39,[42,55]),Jf=Ge(54,[42,55,47,56]),Qf=Ge(62,[62,82]),eg=Ge(35,[61,36,33,70]),tg=Ge(62,[45,71]),ig=Ge(63,[45,81]),Vs=Ge(76,[10,72,13,72]),ng=Ge(39,[39,46,10,72,13,72,92,48]),rg=Ge(39,[34,46,10,72,13,72,92,49]),sg=Ge(39,[39,47,10,74,13,74,92,48]),og=Ge(39,[34,47,10,74,13,74,92,49]),Rl=Ge(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),ag=Ge(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),lg=Ge(39,[39,68,10,74,13,74,92,75,NaN,67]),hg=Ge(39,[34,68,10,74,13,74,92,75,NaN,67]),ug=Ge(72,[9,39,10,39,13,39,32,39,41,69]),cg=15,Ft=class{constructor(e,t){this.input=e,this.handler=t,c(this,"indexMask"),c(this,"buffer"),c(this,"tail",0),c(this,"curr",0),c(this,"position",0),this.indexMask=cg,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new Gf}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Ht,r=this.input,s=this.position,o=this.buffer,a=0,l=0,h="",u=0,d=!1,p=o[e],f=-9;for(;;){let m=r.charCodeAt(s);switch(n[m]||n[65]){case 72:h=r.substring(l,s),isNaN(m)?a=0:a=54,n=Ht;break;case 1:s++,d=!0;continue;case 2:l=s++,n=ao;continue;case 3:a=1,l=s++,n=Ot;continue;case 4:l=s++,a=31,n=pi;continue;case 33:a=2,l=++s,n=ng;continue;case 34:a=2,l=++s,n=rg;continue;case 6:l=++s,a=7,n=Ot;continue;case 7:l=s++,a=32,n=pi;continue;case 8:l=s++,a=21;break;case 9:l=s++,a=32,n=Yf;continue;case 10:l=s++,a=10;break;case 11:l=s++,a=11;break;case 12:l=s++,a=36,n=pi;continue;case 13:l=s++,a=23;break;case 14:l=s++,a=16;break;case 15:a=24,l=s++,n=Ou;continue;case 16:l=s++,n=jf;continue;case 78:l=s++,a=9,n=Ot;continue;case 17:l=s++,a=19,n=Kf;continue;case 18:l=s++,a=18,n=Xf;continue;case 77:s++,a=50;break;case 19:l=s++,a=17;break;case 20:l=s++,a=38,n=eg;continue;case 21:l=s++,a=39,n=pi;continue;case 22:l=s++,a=37,n=pi;continue;case 23:l=s++,a=22;break;case 24:l=++s,a=20,n=Ot;continue;case 25:l=s++,a=14;break;case 26:l=s++,a=15;break;case 27:l=s++,a=12;break;case 28:l=s++,a=13;break;case 29:l=s++,f=l,a=1,n=Vs;continue;case 30:l=s++,a=33,n=pi;continue;case 31:l=s++,a=34,n=qf;continue;case 32:l=s++,a=35,n=pi;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(l,s),10);break;case 38:a=4,u=parseFloat(r.substring(l,s));break;case 39:s++;continue;case 40:a=3,u=parseFloat(r.substring(l,s)),l=s++,n=Ot;continue;case 41:a=3,u=parseFloat(r.substring(l,s)),h="%",l=s++;break;case 42:s++,n=lo;continue;case 43:if(h=di(r.substring(l,s)),a===27&&m===63||a===1&&h.toLowerCase()==="u"&&/^(\bu\+[?0-9a-f]+(-[?0-9a-f]+)?|,|\s+|\/\*([^*]|\*[^/])*\*\/)+[;}]/i.test(r.substring(s-1))){a=27,s++;continue}break;case 44:f=s++,n=Vs;continue;case 45:h=di(r.substring(l,s));break;case 46:h=r.substring(l,s),s++;break;case 47:h=di(r.substring(l,s)),s++;break;case 48:f=s,s+=2,n=sg;continue;case 49:f=s,s+=2,n=og;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(h=r.substring(l,s),a==1){if(s++,h.toLowerCase()=="url"){n=Rl;continue}a=6}break;case 53:if(h=di(r.substring(l,s)),a==1){if(s++,h.toLowerCase()=="url"){n=Rl;continue}a=6}break;case 54:n=Zf,s++;continue;case 55:n=Jf,s++;continue;case 56:n=Ht,s++;continue;case 57:n=Qf,s++,r[s]!==">"&&(a=1,n=Ot);continue;case 81:a=51,h=r.substring(l,++s),n=Ht;break;case 82:a=52,h=r.substring(l,++s),n=Ht;break;case 58:a=5,n=ao,s++;continue;case 59:a=4,n=lo,s++;continue;case 60:a=1,n=Ot,s++;continue;case 61:a=1,n=Vs,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:l=s++,n=ag;continue;case 65:l=++s,n=lg;continue;case 66:l=++s,n=hg;continue;case 67:a=8,h=di(r.substring(l,s)),s++;break;case 69:s++;break;case 70:n=tg,s++;continue;case 71:n=ig,s++;continue;case 79:if(s-f<8&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])|[ \t]$/)){s++;continue}case 68:a=8,h=di(r.substring(l,s)),s++,n=ug;continue;case 74:if(s++,s-f<9&&r.substring(f+1,s).match(/^[0-9a-fA-F]{0,6}(\r\n|[\n\r])$/))continue;a=54,h="E_CSS_UNEXPECTED_NEWLINE",n=Ht;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=Ot;continue}h=di(r.substring(l,s));break;case 75:f=s++;continue;case 76:s++,n=Bu;continue;default:if(n!==Ht){a=54,h="E_CSS_UNEXPECTED_STATE";break}l=s,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=h,p.position=l,e++,e>=t)break;n=Ht,d=!1,p=o[e&i]}this.position=s,this.tail=e&i}},_e=null,ho=null;function uo(){return _e}function O(e){if(!_e)throw new Error("E_TASK_NO_CONTEXT");_e.name||(_e.name=e);let t=_e,i=new ms(t,t.top,e);return t.top=i,i.state=1,i}function dg(e){return new gg(e||new fg)}function N(e){return new co(e)}function an(e,t,i){let n=O(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function pg(e,t){return(_e?_e.getScheduler():ho||dg()).run(e,t)}var fg=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},gg=class{constructor(e){this.timer=e,c(this,"timeout",1),c(this,"slice",25),c(this,"sliceOverTime",0),c(this,"queue"),c(this,"wakeupTime",null),c(this,"timeoutToken",null),c(this,"inTimeSlice",!1),c(this,"order",0),this.queue=new Gp,ho||(ho=this)}setSlice(e){this.slice=e}setTimeout(e){this.timeout=e}isTimeSliceOver(){return this.timer.currentTime()>=this.sliceOverTime}arm(){if(this.inTimeSlice)return;let e=this.queue.peek().scheduledTime,t=this.timer.currentTime();if(this.timeoutToken!=null){if(t+this.timeout>this.wakeupTime)return;this.timer.clearTimeout(this.timeoutToken)}let i=e-t;i<=this.timeout&&(i=this.timeout),this.wakeupTime=t+i,this.timeoutToken=this.timer.setTimeout(()=>{this.timeoutToken=null,this.doTimeSlice()},i)}schedule(e,t){let i=e,n=this.timer.currentTime();i.order=this.order++,i.scheduledTime=n+(t||0),this.queue.add(i),this.arm()}doTimeSlice(){this.timeoutToken!=null&&(this.timer.clearTimeout(this.timeoutToken),this.timeoutToken=null),this.inTimeSlice=!0;try{let e=this.timer.currentTime();for(this.sliceOverTime=e+this.slice;this.queue.length();){let t=this.queue.peek();if(t.scheduledTime>e||(this.queue.remove(),t.canceled||t.resumeInternal(),e=this.timer.currentTime(),e>=this.sliceOverTime))break}}catch(e){$.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new mg(this,t||"");i.top=new ms(i,null,"bootstrap"),i.top.state=1,i.top.then(()=>{let r=()=>{i.running=!1;for(let s of i.callbacks)try{s()}catch(o){$.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=_e;return _e=i,this.schedule(i.top.suspend("bootstrap")),_e=n,i}},Mu=class{constructor(e){this.task=e,c(this,"scheduledTime",0),c(this,"order",0),c(this,"result",null),c(this,"canceled",!1)}compare(e){let t=e;return t.scheduledTime-this.scheduledTime||t.order-this.order}getTask(){return this.task}schedule(e,t){this.result=e,this.task.scheduler.schedule(this,t)}resumeInternal(){let e=this.task;if(this.task=null,e&&e.continuation==this){e.continuation=null;let t=_e;return _e=e,e.top.finish(this.result),_e=t,!0}return!1}cancel(){this.canceled=!0}},mg=class{constructor(e,t){this.scheduler=e,this.name=t,c(this,"callbacks",[]),c(this,"exception",null),c(this,"running",!0),c(this,"result",null),c(this,"waitTarget",null),c(this,"top",null),c(this,"continuation",null)}getName(){return this.name}interrupt(e){if(this.raise(e||new Error("E_TASK_INTERRUPT")),this!==_e&&this.continuation){this.continuation.cancel();let t=new Mu(this);this.waitTarget="interrupt",this.continuation=t,this.scheduler.schedule(t)}}getScheduler(){return this.scheduler}isRunning(){return this.running}whenDone(e){this.callbacks.push(e)}join(){let e=O("Task.join");if(!this.running)e.finish(this.result);else{let t=e.suspend(this);this.whenDone(()=>{t.schedule(this.result)})}return e.result()}unwind(){for(;this.top&&!this.top.handler;)this.top=this.top.parent;if(this.top&&this.top.handler&&this.exception){let e=this.exception;this.exception=null,this.top.handler(this.top,e)}else this.exception&&$.error(this.exception,"Unhandled exception in task",this.name)}raise(e,t){if(this.fillStack(e),t){let i=this.top;for(;i&&i!=t;)i=i.parent;i==t&&(this.top=i)}this.exception=e,this.unwind()}fillStack(e){let t=e.frameTrace;if(!t){t=e.stack?`${e.stack}
|
|
5
5
|
---- async ---
|
|
6
6
|
`:"";for(let i=this.top;i;i=i.parent)t+=" ",t+=i.getName(),t+=`
|
|
7
|
-
`;e.frameTrace=t}}},
|
|
7
|
+
`;e.frameTrace=t}}},co=class _u{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new _u(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},wg=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new ms(this.frame.task,this.frame.parent,"AsyncResult.thenAsync");return t.state=1,this.frame.parent=t,this.frame.then(i=>{e(i).then(n=>{t.finish(n)})}),t.result()}else return e(this.frame.res)}thenReturn(e){return this.isPending()?this.thenAsync(()=>new co(e)):new co(e)}thenFinish(e){this.isPending()?this.then(t=>{e.finish(t)}):e.finish(this.frame.res)}isPending(){return this.frame.state==1}get(){if(this.isPending())throw new Error("Result is pending");return this.frame.res}},ms=class{constructor(e,t,i){this.task=e,this.parent=t,this.name=i,c(this,"res",null),c(this,"state"),c(this,"callback",null),c(this,"handler",null),this.state=0}checkEnvironment(){if(!_e)throw new Error("F_TASK_NO_CONTEXT");if(this!==_e.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new wg(this)}finish(e){this.checkEnvironment(),_e&&!_e.exception&&(this.res=e),this.state=2;let t=this.parent;if(_e&&(_e.top=t),this.callback){try{this.callback(e)}catch(i){this.task.raise(i,t)}this.state=3}}getTask(){return this.task}getName(){return this.name}getScheduler(){return this.task.scheduler}then(e){switch(this.state){case 1:if(this.callback)throw new Error("F_TASK_FRAME_ALREADY_HAS_CALLBACK");this.callback=e;break;case 2:{let t=this.task,i=this.parent;try{e(this.res),this.state=3}catch(n){this.state=3,t.raise(n,i)}break}case 3:throw new Error("F_TASK_DEAD_FRAME");default:throw new Error(`F_TASK_UNEXPECTED_FRAME_STATE ${this.state}`)}}timeSlice(){let e=O("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?($.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=O("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=O("Frame.loop"),i=n=>{try{for(;n;){let r=e();if(r.isPending()){r.then(i);return}else r.then(s=>{n=s})}t.finish(!0)}catch(r){t.task.raise(r,t)}};return i(!0),t.result()}loopWithFrame(e){let t=_e;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new yg(t,t.top);t.top=n,n.state=1,e(n),i=n.result()}while(!i.isPending()&&i.get());return i})}suspend(e){if(this.checkEnvironment(),this.task.continuation)throw new Error("E_TASK_ALREADY_SUSPENDED");let t=new Mu(this.task);return this.task.continuation=t,_e=null,this.task.waitTarget=e||null,t}},yg=class extends ms{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},or=class{constructor(e,t){this.fetch=e,c(this,"name"),c(this,"arrived",!1),c(this,"resource",null),c(this,"task",null),c(this,"piggybacks",[]),this.name=t}start(){this.task||(this.task=uo().getScheduler().run(()=>{let e=O("Fetcher.run");return this.fetch().then(t=>{let i=this.piggybacks;if(this.arrived=!0,this.resource=t,this.task=null,this.piggybacks=[],i)for(let n=0;n<i.length;n++)try{i[n](t)}catch(r){$.error(r,"Error:")}e.finish(t)}),e.result()},this.name))}piggyback(e){this.arrived?e(this.resource):this.piggybacks.push(e)}get(){return this.arrived?N(this.resource):(this.start(),this.task.join())}hasArrived(){return this.arrived}},ws=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=O("waitForFetches"),i=0;return t.loop(()=>{for(;i<e.length;){let n=e[i++];if(!n.hasArrived())return n.get().thenReturn(!0)}return N(!1)}).then(()=>{t.finish(!0)}),t.result()},zu=`
|
|
8
8
|
@media screen {
|
|
9
9
|
[data-vivliostyle-viewer-viewport] {
|
|
10
10
|
background: #aaaaaa;
|
|
@@ -45,7 +45,7 @@ var Xd=Object.create;var Qn=Object.defineProperty;var qd=Object.getOwnPropertyDe
|
|
|
45
45
|
flex-direction: row-reverse;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
[data-vivliostyle-
|
|
48
|
+
[data-vivliostyle-spread-container] [data-vivliostyle-page-container] {
|
|
49
49
|
margin: 0 auto;
|
|
50
50
|
flex: none;
|
|
51
51
|
transform-origin: center top;
|
|
@@ -73,7 +73,7 @@ var Xd=Object.create;var Qn=Object.defineProperty;var qd=Object.getOwnPropertyDe
|
|
|
73
73
|
transform-origin: center top;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
`,
|
|
76
|
+
`,Du=`
|
|
77
77
|
[data-vivliostyle-layout-box] {
|
|
78
78
|
position: absolute;
|
|
79
79
|
left: 0;
|
|
@@ -86,12 +86,13 @@ var Xd=Object.create;var Qn=Object.defineProperty;var qd=Object.getOwnPropertyDe
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
[data-vivliostyle-debug] [data-vivliostyle-layout-box] {
|
|
89
|
-
right: auto;
|
|
90
|
-
bottom: auto;
|
|
91
|
-
overflow: visible;
|
|
92
89
|
z-index: auto;
|
|
93
90
|
}
|
|
94
91
|
|
|
92
|
+
[data-vivliostyle-layout-box] [data-vivliostyle-page-container] {
|
|
93
|
+
margin: 0 auto 0 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
95
96
|
[data-vivliostyle-spread-container] {
|
|
96
97
|
transform: scale(var(--viv-outputScale,1));
|
|
97
98
|
transform-origin: left top;
|
|
@@ -206,7 +207,7 @@ var Xd=Object.create;var Qn=Object.defineProperty;var qd=Object.getOwnPropertyDe
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
}
|
|
209
|
-
`,
|
|
210
|
+
`,Vu=`
|
|
210
211
|
/*
|
|
211
212
|
* Copyright 2013 Google, Inc.
|
|
212
213
|
* Copyright 2015 Daishinsha Inc.
|
|
@@ -838,7 +839,7 @@ word-wrap = overflow-wrap;
|
|
|
838
839
|
[adapt,webkit]start = inline-start;
|
|
839
840
|
[adapt,webkit]end = inline-end;
|
|
840
841
|
|
|
841
|
-
`,
|
|
842
|
+
`,Hu=`
|
|
842
843
|
<!DOCTYPE html>
|
|
843
844
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
|
|
844
845
|
<head>
|
|
@@ -861,7 +862,7 @@ word-wrap = overflow-wrap;
|
|
|
861
862
|
<s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
|
|
862
863
|
|
|
863
864
|
</body>
|
|
864
|
-
</html>`,
|
|
865
|
+
</html>`,Uu=`
|
|
865
866
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
866
867
|
|
|
867
868
|
:root {
|
|
@@ -988,7 +989,7 @@ word-wrap = overflow-wrap;
|
|
|
988
989
|
margin: 10%;
|
|
989
990
|
}
|
|
990
991
|
}
|
|
991
|
-
|
|
992
|
+
`,$u=`
|
|
992
993
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
993
994
|
@namespace m "http://www.w3.org/1998/Math/MathML";
|
|
994
995
|
@namespace epub "http://www.idpf.org/2007/ops";
|
|
@@ -1385,7 +1386,7 @@ epub|case[required-namespace::supported] ~ epub|case {
|
|
|
1385
1386
|
epub|case[required-namespace::supported] ~ epub|default {
|
|
1386
1387
|
display: none;
|
|
1387
1388
|
}
|
|
1388
|
-
`,
|
|
1389
|
+
`,Wu=`
|
|
1389
1390
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
1390
1391
|
|
|
1391
1392
|
*:not([data-vivliostyle-role=doc-toc],
|
|
@@ -1415,7 +1416,7 @@ epub|case[required-namespace::supported] ~ epub|default {
|
|
|
1415
1416
|
[data-vivliostyle-role=doc-toc]:is(ol,ul) {
|
|
1416
1417
|
-adapt-behavior: toc-container;
|
|
1417
1418
|
}
|
|
1418
|
-
`,
|
|
1419
|
+
`,Gu=`
|
|
1419
1420
|
[data-viv-margin-discard~="block-start"] {
|
|
1420
1421
|
margin-block-start: 0 !important;
|
|
1421
1422
|
}
|
|
@@ -1566,7 +1567,7 @@ span[data-viv-leader] {
|
|
|
1566
1567
|
-webkit-initial-letter: var(--viv-initialLetter);
|
|
1567
1568
|
initial-letter: var(--viv-initialLetter);
|
|
1568
1569
|
}
|
|
1569
|
-
`,
|
|
1570
|
+
`,ju=String.raw`
|
|
1570
1571
|
@counter-style decimal-leading-zero {
|
|
1571
1572
|
system: extends decimal;
|
|
1572
1573
|
pad: 2 '0';
|
|
@@ -1790,12 +1791,12 @@ span[data-viv-leader] {
|
|
|
1790
1791
|
@counter-style upper-russian {
|
|
1791
1792
|
system: alphabetic;
|
|
1792
1793
|
symbols: \u0410 \u0411 \u0412 \u0413 \u0414 \u0415 \u0416 \u0417 \u0418 \u041A \u041B \u041C \u041D \u041E \u041F \u0420 \u0421 \u0422 \u0423 \u0424 \u0425 \u0426 \u0427 \u0428 \u0429 \u042D \u042E \u042F;
|
|
1793
|
-
}`;function tr(e,t,i){let n=B("fetchFromURL"),s={method:i||"GET",mode:"cors"},r=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,s).then(a=>{var l;return o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(l=a.headers.get("Content-Type"))==null?void 0:l.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(h=>new TextDecoder("Shift_JIS").decode(h))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=Su([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),r.schedule(o)}).catch(a=>{H.warn(a,`Error fetching ${e}`),r.schedule(o)}),n.result()}function Su(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Xf(e){let t=B("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function qf(e){return URL.createObjectURL(e)}var ia=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Dt(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=B("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=Pe("user-agent.xml",Qt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent(mu)}`),tr(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);s?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=r),this.parser(a,this).then(l=>{delete this.fetchers[e],this.resources[e]=l,n.finish(l)})}),n.result()}fetch(e,t,i){if(e=Dt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new Wn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Dt(e)]}delete(e){delete this.resources[Dt(e)]}};function Yf(e,t){let i=e.responseText;return N(i?Xo(i):null)}function Kf(){return new ia(Yf,"text")}function Ni(e,t,i){let n=new Wn(()=>{let s=B("loadElement"),r=s.suspend(e),o=!1,a=null,l=h=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),r.schedule(h?h.type:"timeout"))};if(e.addEventListener("load",l,!1),e.addEventListener("error",l,!1),e.addEventListener("abort",l,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(e.localName==="script")a=setTimeout(l,3e3);else if(t)if(e.localName==="img"){let h=e;h.loading==="lazy"&&(h.loading="eager"),h.src=t,i&&(h.alt=i),h.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4)}else e.src=t,i&&(e.alt=i);return s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var fl=0,Zf=16777216,Cu=33554432,ku=50331648,Eu=67108864,Jf=83886080,Qf=100663296,na=class{constructor(e){this.scope=e,c(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return fl;case"User":return Qf;default:return Jf}}getBaseSpecificity(){switch(this.flavor){case"UA":return fl;case"User":return Zf;default:return Cu}}},eg=class extends na{constructor(){super(null),c(this,"stack",[]),c(this,"tokenizer",null),c(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;H.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},gl=class extends na{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,c(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},Gn=class extends gl{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new gl(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ae=[],Fs=[],me=[],Ne=[],vt=[],rt=[],Ie=[],Ue=[],ge=[],Ge=[],et=[],Ve=[],Te=[],Pi=55,Ti=56,ns=57;Ae[1]=28,Ae[36]=29,Ae[7]=29,Ae[9]=29,Ae[14]=29,Ae[18]=29,Ae[50]=29,Ae[20]=30,Ae[13]=27,Ae[0]=200,Fs[1]=46,Fs[0]=200,rt[1]=2,rt[36]=4,rt[7]=6,rt[9]=8,rt[14]=10,rt[18]=14,rt[50]=42,me[37]=11,me[23]=12,me[35]=56,me[1]=1,me[36]=3,me[7]=5,me[9]=7,me[14]=9,me[12]=13,me[18]=55,me[50]=58,me[16]=41,Ne[37]=11,Ne[23]=12,Ne[35]=56,Ne[1]=1,Ne[36]=3,Ne[7]=5,Ne[9]=7,Ne[14]=9,Ne[18]=55,vt[1]=2,vt[36]=4,vt[7]=6,vt[9]=8,vt[18]=14,vt[50]=42,vt[14]=10,vt[12]=13,Ie[1]=15,Ie[7]=16,Ie[4]=17,Ie[5]=18,Ie[3]=19,Ie[2]=20,Ie[8]=21,Ie[27]=57,Ie[16]=22,Ie[19]=23,Ie[6]=24,Ie[11]=25,Ie[17]=26,Ie[13]=48,Ie[31]=47,Ie[23]=54,Ie[0]=44,Ue[1]=31,Ue[4]=32,Ue[5]=32,Ue[3]=33,Ue[2]=34,Ue[10]=40,Ue[6]=38,Ue[31]=36,Ue[24]=36,Ue[32]=35,ge[1]=45,ge[16]=37,ge[37]=37,ge[38]=37,ge[47]=37,ge[48]=37,ge[39]=37,ge[49]=37,ge[41]=37,ge[26]=37,ge[25]=37,ge[23]=37,ge[24]=37,ge[19]=37,ge[21]=37,ge[36]=37,ge[18]=37,ge[22]=37,ge[11]=39,ge[12]=43,ge[17]=49,Ge[0]=200,Ge[12]=50,Ge[13]=51,Ge[14]=50,Ge[15]=51,Ge[10]=50,Ge[11]=51,Ge[17]=53,et[0]=200,et[12]=50,et[13]=52,et[14]=50,et[15]=51,et[10]=50,et[11]=51,et[17]=53,Ve[0]=200,Ve[12]=50,Ve[13]=51,Ve[14]=50,Ve[15]=51,Ve[10]=50,Ve[11]=51,Te[11]=0,Te[16]=0,Te[22]=1,Te[18]=1,Te[26]=2,Te[25]=2,Te[38]=3,Te[37]=3,Te[48]=3,Te[47]=3,Te[39]=3,Te[49]=3,Te[41]=3,Te[23]=4,Te[24]=4,Te[36]=5,Te[19]=5,Te[21]=5,Te[0]=6,Te[Pi]=2,Te[Ti]=2;var jn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,c(this,"valStack",[]),c(this,"namespacePrefixToURI",{}),c(this,"defaultNamespaceURI",null),c(this,"propName",null),c(this,"propImportant",!1),c(this,"exprContext"),c(this,"result",null),c(this,"importReady",!1),c(this,"importURL",null),c(this,"importCondition",null),c(this,"errorBrackets",[]),c(this,"ruleStack",[]),c(this,"regionRule",!1),c(this,"pageRule",!1),c(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(j)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof Ei){if(r.text===")")s++;else if(r.text==="("){if(s===0)return null;s--}}while(typeof r<"u"&&typeof r!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new Q(i.slice(n+1,i.length))),e==",")return null;n++;do r=i[--n];while(typeof r<"u"&&(typeof r!="string"||r==","));if(o=i.length-(n+1),r=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=et);let l=new en(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,l),l.name==="var"){let h=l.values[0]instanceof ae&&l.values[0].name;(!$t(h)||h===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${l.toString()}`,t),this.actions=et)}return l}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=et,null;if(o>1)return new Ke(this.extractVals(",",n+1));let a=i[0];return a instanceof Ze?a:a?new Ei(a.toString()):j}exprError(e,t){this.actions=this.propName?et:Ge,H.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,s=i.pop(),r;for(;;){let o=i.pop();if(e==11){let a=[s];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let l=a.shift(),h=a.shift(),u=new zp(n.getScope(),l,h);a.unshift(u)}return i.push(new U(a[0])),!0}else if(o=="("){let l=i.pop(),h=i.pop();s=new yn(n.getScope(),zr(h,l),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new tl(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new ti(n.getScope(),s);else if(o==-24)s=new Ri(n.getScope(),s);else if(o==-ns)s=new _p(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Te[e]>Te[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Ko(n.getScope(),r,s);break;case Pi:s=new Mp(n.getScope(),r,s);break;case Ti:s=new Dp(n.getScope(),r,s);break;case 25:s=new Zo(n.getScope(),r,s);break;case 38:s=new Vp(n.getScope(),r,s);break;case 37:s=new Hp(n.getScope(),r,s);break;case 48:s=new Up(n.getScope(),r,s);break;case 47:s=new Ur(n.getScope(),r,s);break;case 39:case 49:s=new Jo(n.getScope(),r,s);break;case 41:s=new $p(n.getScope(),r,s);break;case 23:s=new $h(n.getScope(),r,s);break;case 24:s=new Wh(n.getScope(),r,s);break;case 36:s=new Qo(n.getScope(),r,s);break;case 19:s=new Gh(n.getScope(),r,s);break;case 21:s=new jh(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new jp(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new tl(n.getScope(),r,s);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(r),i.push(o),i.push(s),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(s),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,s;if(t)s=e.text,n=e.position+s.length+1;else if(e.type===10){let u=i.nthToken(1),d=i.nthToken(2);if(u.type===1&&d.type===18)i.consume(),i.consume(),s=u.text,n=d.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(d.type===10||d.type===6))return null;n=e.position+1}}else return null;let r=0,o,a=0;for(;r>=0;)switch(i.consume(),o=i.token(),o.type){case 11:r--;break;case 10:case 6:r++;break;case 16:r===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let l=o.position,h=t&&s==="selector"&&a>0?"":i.input.substring(n,l).trim();return new Xp(this.handler.getScope(),s,h,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let s=t.type===24,r=t.type===23||s;if(r&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,r)return null}else if(n<0){if(r)return null}else if(n>=0&&!r)return null;this.tokenizer.consume()}else if(r)return null;return[i,s&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let s of n)switch(s){case"vertical":t=St(i,t,new ti(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=St(i,t,new ze(i,"pref-horizontal"));break;case"day":t=St(i,t,new ti(i,new ze(i,"pref-night-mode")));break;case"night":t=St(i,t,new ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new U(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(e,t,i,n,s,r){let o=this.handler,a=this.tokenizer,l=this.valStack,h,u,d,p,f,m,g,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(h=a.token(),s&&w===null&&(w=h.position-1,a.input[w]==="("&&w++),this.actions===Ie&&this.errorBrackets.length>0&&(h.type===this.errorBrackets[this.errorBrackets.length-1]||h.type===17||h.type===31)){if(h.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),h.type===11&&this.valStackReduce(")",h))){a.consume();continue}l.push(new Ei(h.toString())),a.consume();continue}switch(this.actions[h.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=et):(this.actions=rt,o.startSelectorRule());continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=et,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 29:this.actions=rt,o.startSelectorRule();continue;case 1:if(!h.precededBySpace){this.actions=Ve,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[h.text],d!=null)switch(h=a.token(),h.type){case 1:o.tagSelector(d,h.text),s?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(d,null),s?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=Ge,o.error("E_CSS_NAMESPACE",h)}else this.actions=Ge,o.error("E_CSS_UNDECLARED_PREFIX",h);else o.tagSelector(this.defaultNamespaceURI,h.text),s?this.actions=Ne:this.actions=me,a.consume();continue;case 3:if(!h.precededBySpace){this.actions=Ve,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),h=a.token(),h.type){case 1:o.tagSelector(null,h.text),s?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=Ge,o.error("E_CSS_NAMESPACE",h)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Ne:this.actions=me,a.consume();continue;case 5:h.precededBySpace&&o.descendantSelector();case 6:if(!h.text){o.error("E_CSS_SYNTAX",h),a.consume();continue}o.idSelector(h.text),s?this.actions=Ne:this.actions=me,a.consume();continue;case 7:h.precededBySpace&&o.descendantSelector();case 8:o.classSelector(h.text),s?this.actions=Ne:this.actions=me,a.consume();continue;case 55:h.precededBySpace&&o.descendantSelector();case 14:a.consume(),h=a.token();e:switch(h.type){case 1:o.pseudoclassSelector(h.text,null),a.consume(),s?this.actions=Ne:this.actions=me;continue;case 6:switch(p=h.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=rt,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=me:this.actions=Ve;continue;case"lang":case"href-epub-type":if(h=a.token(),h.type===1){g=[h.text],a.consume(),p==="href-epub-type"&&a.token().type===16&&(a.consume(),h=a.token(),h.type===1&&(g.push(h.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(g=this.readNthPseudoParams(),g)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=rt,o.startFuncWithSelector(p,g),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?s?this.actions=Ne:this.actions=me:this.actions=Ve;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)g.push(u.text),a.consume();else break e;break}else break;else break e;default:g=this.readPseudoParams()}if(h=a.token(),h.type==11){o.pseudoclassSelector(p,g),a.consume(),s?this.actions=Ne:this.actions=me;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",h),this.actions=Ge;continue;case 58:h.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),h=a.token(),h.type){case 1:o.pseudoelementSelector(h.text,null),s?this.actions=Ne:this.actions=me,a.consume();continue;case 6:if(p=h.text,a.consume(),p=="nth-fragment"){if(g=this.readNthPseudoParams(),g===null)break}else g=this.readPseudoParams();if(h=a.token(),h.type==11){o.pseudoelementSelector(p,g),s?this.actions=Ne:this.actions=me,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",h),this.actions=Ge;continue;case 9:h.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),h=a.token(),h.type==1)p=h.text,a.consume();else if(h.type==36)p=null,a.consume();else if(h.type==34)p="";else{this.actions=Ve,o.error("E_CSS_ATTR",h),a.consume();continue}if(h=a.token(),h.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=Ve,o.error("E_CSS_UNDECLARED_PREFIX",h),a.consume();continue}if(a.consume(),h=a.token(),h.type!=1){this.actions=Ve,o.error("E_CSS_ATTR_NAME_EXPECTED",h);continue}p=h.text,a.consume(),h=a.token()}else d="";switch(h.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=h.type,a.consume(),h=a.token();break;case 15:o.attributeSelector(d,p,0,null),s?this.actions=Ne:this.actions=me,a.consume();continue;default:this.actions=Ve,o.error("E_CSS_ATTR_OP_EXPECTED",h);continue}switch(h.type){case 1:case 2:o.attributeSelector(d,p,f,h.text),a.consume(),h=a.token();break;default:this.actions=Ve,o.error("E_CSS_ATTR_VAL_EXPECTED",h);continue}if(h.type!=15){this.actions=Ve,o.error("E_CSS_ATTR",h);continue}s?this.actions=Ne:this.actions=me,a.consume();continue;case 11:o.childSelector(),this.actions=vt,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=vt,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=vt,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=Ae,a.consume();continue;case 41:o.nextSelector(),this.actions=rt,a.consume();continue;case 15:l.push(F(h.text)),a.consume();continue;case 16:f=parseInt(h.text,16),l.push(new tu(h.text)),a.consume();continue;case 17:l.push(new Ht(h.num)),a.consume();continue;case 18:l.push(new Re(h.num)),a.consume();continue;case 19:l.push(new I(h.num,h.text)),a.consume();continue;case 20:l.push(new G(h.text)),a.consume();continue;case 21:l.push(new Je(Pe(h.text,this.baseURL))),a.consume();continue;case 57:l.push(new iu(h.text)),a.consume();continue;case 22:this.valStackReduce(",",h),l.push(","),a.consume();continue;case 23:l.push(Zs),a.consume();continue;case 24:p=h.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ue,this.exprContext=0,l.push("{")):(l.push(p),l.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",h),a.consume();continue;case 47:if(a.consume(),h=a.token(),u=a.nthToken(1),h.type==1&&h.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",h);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}l.push(new Ei("+")),a.consume();continue;case 26:a.consume();case 48:m=this.valStackReduce(";",h),m&&this.propName&&o.property(this.propName,m,this.propImportant),this.actions=i?Fs:Ae;continue;case 44:for(a.consume();l.length>0;){let v=l.length;if(m=this.valStackReduce(";",h),!m||l.length===v)break}return t?(this.result=m,!0):(this.propName&&m&&o.property(this.propName,m,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(l.push(h.text,u.text,"("),a.consume()):(l.push(new ze(o.getScope(),zr(h.text,u.text))),this.actions=ge),a.consume();else{if(this.exprContext==2||this.exprContext==3)h.text.toLowerCase()=="not"?(a.consume(),l.push(new el(o.getScope(),!0,u.text))):(h.text.toLowerCase()=="only"&&(a.consume(),h=u),l.push(new el(o.getScope(),!1,h.text)));else if(this.exprContext===4&&h.text.toLowerCase()==="not"&&l[l.length-1]!==Pi&&l[l.length-1]!==Ti&&(u.type===10||u.type===6)){l.push(-ns),a.consume();continue}else l.push(new ze(o.getScope(),h.text));this.actions=ge}a.consume();continue;case 38:if(this.exprContext===4){l.push(this.readSupportsTest(h)),this.actions=ge;continue}l.push(null,h.text,"("),a.consume();continue;case 32:l.push(new $e(o.getScope(),h.num)),a.consume(),this.actions=ge;continue;case 33:p=h.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),l.push(new Un(o.getScope(),h.num,p)),a.consume(),this.actions=ge;continue;case 34:l.push(new $e(o.getScope(),h.text)),a.consume(),this.actions=ge;continue;case 35:a.consume(),h=a.token(),h.type!=5||h.precededBySpace?this.exprError("E_CSS_SYNTAX",h):(l.push(new Kh(o.getScope(),h.num)),a.consume(),this.actions=ge);continue;case 36:l.push(-h.type),a.consume();continue;case 37:this.actions=Ue,this.exprStackReduce(h.type,h),l.push(h.type),a.consume();continue;case 45:h.text.toLowerCase()==="and"&&l[l.length-2]!==Ti&&l[l.length-2]!==-ns?(this.actions=Ue,this.exprStackReduce(Pi,h),l.push(Pi),a.consume()):h.text.toLowerCase()==="or"&&l[l.length-2]!==Pi&&l[l.length-2]!==-ns?(this.actions=Ue,this.exprStackReduce(Ti,h),l.push(Ti),a.consume()):this.exprError("E_CSS_SYNTAX",h);continue;case 39:this.exprStackReduce(h.type,h)&&(this.actions=Ie),a.consume();continue;case 43:this.exprStackReduce(11,h)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",h):(this.exprContext==1?o.startWhenRule(l.pop()):o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae)),a.consume();continue;case 49:if(this.exprStackReduce(11,h))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",h),this.actions=Ae,a.consume(),!1):(this.importCondition=l.pop(),this.importReady=!0,this.actions=Ae,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let v=this.readSupportsTest(h);if(v){l.push(v),this.actions=ge;continue}}l.push(h.type),a.consume();continue;case 27:if(this.actions=Ae,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=h.text.toLowerCase(),p){case"import":if(a.consume(),h=a.token(),h.type==2||h.type==8){if(this.importURL=h.text,a.consume(),h=a.token(),h.type==17||h.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ue,l.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",h),this.actions=Ge;continue;case"namespace":switch(a.consume(),h=a.token(),h.type){case 1:if(p=h.text,a.consume(),h=a.token(),(h.type==2||h.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=h.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=h.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",h),this.actions=Ge;continue;case"charset":if(a.consume(),h=a.token(),h.type==2&&a.nthToken(1).type==17){p=h.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,h),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",h),this.actions=Ge;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),h=a.token(),h.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),h=a.token(),h.type==1&&a.nthToken(1).type==12){p=h.text,a.consume(),a.consume(),o.startFootnoteRule(p),this.ruleStack.push("-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=rt;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=vt;continue;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),h=a.token(),h.type==12){a.consume(),o.startPageMarginBoxRule(p),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ue,l.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ue,l.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ue,l.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),h=a.token();let v=null,b=null,C=[];for(h.type==1&&(v=h.text,a.consume(),h=a.token()),h.type==18&&a.nthToken(1).type==1&&(b=a.nthToken(1).text,a.consume(),a.consume(),h=a.token());h.type==6&&h.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)C.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),h=a.token();if(h.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(v,b,C);break;case"-epubx-partition":o.startPartitionRule(v,b,C);break;case"-epubx-partition-group":o.startPartitionGroupRule(v,b,C);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,h),this.actions=Ve;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,h),this.actions=Ge;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,h),this.actions=Ge;continue;case 50:this.errorBrackets.push(h.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ae;continue}case 51:if(s&&this.errorBrackets.length==0&&h.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==h.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&h.type==13&&(this.actions=Ae),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ae),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,h)?(this.result=l.pop(),!0):!1;if(s){switch(h.type){case 16:case 11:if(this.actions===rt)o.error("E_CSS_SYNTAX",h);else{let v=a.input.substring(w,h.position);o.pushSelectorText(v),w=h.position+1}if(h.type===16){o.nextSelector(),this.actions=rt,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=me;continue}break;case 12:case 14:case 10:this.errorBrackets.push(h.type+1);break}o.error("E_CSS_SYNTAX",h),a.consume(),this.actions=Ve;continue}if(this.actions!==Ge&&this.actions!==Ve&&this.actions!==et){if(h.type==54)o.error("E_CSS_SYNTAX",h);else if(this.actions===Ie){switch(h.type){case 10:case 12:case 14:this.errorBrackets.push(h.type+1);break}l.push(new Ei(h.toString())),a.consume();continue}else if(h.type===12&&this.actions==Ue&&l.length>0){o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae,a.consume();continue}else{if(h.type===17&&this.actions==Ue)return this.actions=Ae,a.consume(),!1;o.error("E_CSS_SYNTAX",h)}this.isInsidePropertyOnlyRule()?this.actions=et:this.actions=Ve;continue}a.consume();continue}}return!1}},Nu=class extends na{constructor(e){super(null),this.scope=e}error(e,t){H.warn(e,t.toString())}getScope(){return this.scope}};function tg(e,t,i,n,s){let r=B("parseStylesheet"),o=new jn(Ae,e,t,i),a=null;return s&&(a=ng(new At(s,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),r.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let h=Pe(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=B("parseStylesheet.import");return Pu(h,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let l=r.timeSlice();if(l.isPending)return l}return N(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function sa(e,t,i,n,s){return ji("parseStylesheetFromText",r=>{let o=new At(e,t);tg(o,t,i,n,s).thenFinish(r)},(r,o)=>{H.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Pu(e,t,i,n){return ji("parseStylesheetFromURL",s=>{tr(e).then(r=>{r.responseText?sa(r.responseText,t,e,i,n).then(o=>{o||H.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{H.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function tn(e,t,i){let n=new jn(Ie,t,new Nu(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function ig(e,t,i){new jn(Fs,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function ng(e,t,i){let n=new jn(Ue,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var sg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function rg(e){return!!sg[e]}function og(e,t,i){if(t instanceof Me&&t.str==="viv-leader")return new U(t);let n=t.evaluate(e);switch(typeof n){case"number":return rg(i)?n==Math.round(n)?new Re(n):new Ht(n):new I(n,"px");case"string":return n?tn(t.scope,new At(n,null),""):j;case"boolean":return n?y._true:y._false;case"undefined":return j}throw new Error("E_UNEXPECTED")}function Tu(e,t){let i={};return Object.keys(e).forEach(n=>{let s=i[n]={},r=e[n];Object.keys(r).forEach(o=>{s[o]=r[o].map(a=>{let l=t?a.logical:a.physical,h=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${l}(-?)`),to:`$1${h}$2`}})})}),i}function Iu(e,t,i,n){let s=n[t];if(!s)throw new Error(`unknown writing-mode: ${t}`);let r=s[i||"ltr"];if(!r)throw new Error(`unknown direction: ${i}`);for(let o of r){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var Au={"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"}]}},ag=Tu(Au,!0);function Ru(e,t,i){return Iu(e,t,i||null,ag)}var lg=Tu(Au,!1);function Fu(e,t,i){return Iu(e,t,i||null,lg)}var hg={"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 ug(e,t){let i=hg[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function ra(e,t,i){var n;let s=t,r={width:s.style.width,height:s.style.height};function o(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=o("writing-mode")!=="horizontal-tb",l=a?"height":"width",h=a?"width":"height";function u(p,f){s.style[p]=f;let m=o(p);return s.style[p]=r[p],m}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(l,"max-content");break;case"min-content inline size":f=u(l,"min-content");break;case"fit-content inline size":f=u(l,"fit-content");break;case"max-content block size":f=u(h,"max-content");break;case"min-content block size":f=u(h,"min-content");break;case"fit-content block size":f=u(h,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function un(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function Lu(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Bu(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function ft(e,t){let i=Lu(e);i.includes(t)||(i.push(t),Bu(e,i))}function cg(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function dg(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function kr(e,t){let i=cg(e);i.includes(t)||(i.push(t),dg(e,i))}function pg(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===y.always?y.page:i,important:e.important};default:return e}}var Yr={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function tt(e){return!!Yr[e]}var fg={left:!0,right:!0,recto:!0,verso:!0};function Fn(e){return!!fg[e]}var gg={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Ls(e){return!!gg[e]}function nt(e,t){if(e)if(t){if(Fn(t))return t;if(Fn(e))return e;{let i=tt(e),n=tt(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:Ls(t)?t:Ls(e)?e:t}}else return e;else return t}function ml(e){return tt(e)?e:"auto"}Ct("SIMPLE_PROPERTY",pg);var xn=up(dp());function mg(e,t){return(0,xn.default)(e,t,0)}function wl(e){return e.reduce((t,i)=>i[0]===xn.default.DELETE?t:t+i[1],"")}function wg(e,t){return Ou(e,t,1)}function bg(e,t){return Ou(e,t,-1)}function Ou(e,t,i){let n=0,s=0;return e.some(r=>{for(let o=0;o<r[1].length;o++){switch(r[0]*i){case xn.default.INSERT:n++;break;case xn.default.DELETE:n--,s++;break;case xn.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var Kr;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Kr||(Kr={}));var Di;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(Di||(Di={}));var Bs;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Bs||(Bs={}));var wi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||si.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||si.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(wi||(wi={}));var si;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(si||(si={}));var Wt;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(Wt||(Wt={}));var yg={transform:!0,"transform-origin":!0},vg={top:!0,bottom:!0,left:!0,right:!0},oa=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},xg={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function Sg(e,t){let i=xg[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Zr=class cn extends qo{constructor(t,i){super(),this.container=t,this.bleedBox=i,c(this,"pageAreaElement",null),c(this,"delayedItems",[]),c(this,"hrefHandler"),c(this,"elementsById",{}),c(this,"dimensions",{width:0,height:0}),c(this,"isFirstPage",!1),c(this,"isLastPage",!1),c(this,"isBlankPage",!1),c(this,"isAutoPageWidth",!0),c(this,"isAutoPageHeight",!0),c(this,"spineIndex",0),c(this,"position",null),c(this,"offset",-1),c(this,"side",null),c(this,"fetchers",[]),c(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),c(this,"pageType",null),this.hrefHandler=n=>{let s=n.currentTarget,r=s.getAttribute("href")||s.getAttributeNS("http://www.w3.org/1999/xlink","href");if(r){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:s,href:r,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(cn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(cn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(cn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(cn.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(r=>{let o=this.elementsById[r];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[r]});let n=this.delayedItems;for(let r=0;r<n.length;r++){let o=n[r];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||T(o.target,o.name,o.value.toString())}let s=i.getElementClientRect(this.container);this.dimensions.width=s.width,this.dimensions.height=s.height;for(let r=0;r<t.length;r++){let o=t[r],a=this.elementsById[o.ref],l=this.elementsById[o.observer];if(a&&l){let h=Sg(a,o.action);if(h)for(let u=0;u<l.length;u++)l[u].addEventListener(o.event,h,!1)}}}};c(Zr,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(Zr,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var _u=Zr,ot=Wt.Whitespace;function Mu(e){switch(e){case"normal":case"nowrap":return ot.IGNORE;case"pre-line":return ot.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return ot.PRESERVE;default:return null}}function He(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case ot.PRESERVE:return i.length==0;case ot.NEWLINE:return!!i.match(/^[ \t]*$/);case ot.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Cg=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},kg=class{constructor(e,t,i,n,s,r,o,a,l){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=s,this.exclusive=r,this.repeated=o,this.last=a,this.breakBefore=l,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Eg(e,t){return e.top-t.top}function Ng(e,t){return t.right-e.right}function zu(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Wt.ShadowType.ROOTLESS&&t.shadowType===Wt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Qr(e.shadowContext,t.shadowContext)&&Qr(e.nodeShadow,t.nodeShadow)&&zu(e.shadowSibling,t.shadowSibling)}function ri(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!zu(e.steps[i],t.steps[i]))return!1;return!0}function Pg(e){return{steps:[{node:e,shadowType:yt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function Os(e,t){return{steps:[{node:e.sourceNode,shadowType:yt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function _s(e,t){let i=new dn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?_s(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var yt=Wt.ShadowType,Jr=class{constructor(e,t,i,n,s,r,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=r,this.styler=o,c(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Qr(this.parentShadow,e.parentShadow):!1}};function Qr(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Tg=class{constructor(e,t){this.outer=e,this.count=t}},dn=class Du{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,c(this,"offsetInNode",0),c(this,"after",!1),c(this,"shadowType"),c(this,"shadowContext"),c(this,"nodeShadow",null),c(this,"shadowSibling",null),c(this,"shared",!1),c(this,"inline",!0),c(this,"overflow",!1),c(this,"breakPenalty"),c(this,"display",null),c(this,"floatReference"),c(this,"floatSide",null),c(this,"clearSide",null),c(this,"floatMinWrapBlock",null),c(this,"columnSpan",null),c(this,"verticalAlign","baseline"),c(this,"captionSide","top"),c(this,"inlineBorderSpacing",0),c(this,"blockBorderSpacing",0),c(this,"flexContainer",!1),c(this,"whitespace"),c(this,"hyphenateCharacter"),c(this,"breakWord"),c(this,"establishesBFC",!1),c(this,"containingBlockForAbsolute",!1),c(this,"breakBefore",null),c(this,"breakAfter",null),c(this,"viewNode",null),c(this,"clearSpacer",null),c(this,"inheritedProps"),c(this,"vertical"),c(this,"direction"),c(this,"firstPseudo"),c(this,"lang",null),c(this,"preprocessedTextContent",null),c(this,"formattingContext"),c(this,"repeatOnBreak",null),c(this,"pluginProps",{}),c(this,"fragmentIndex",1),c(this,"afterIfContinues",null),c(this,"footnotePolicy",null),c(this,"pageType"),this.shadowType=yt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=Di.FloatReference.INLINE,this.whitespace=i?i.whitespace:ot.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=Di.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.verticalAlign="baseline",this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:ot.IGNORE,this.hyphenateCharacter=this.parent?this.parent.hyphenateCharacter:null,this.breakWord=this.parent?this.parent.breakWord:!1,this.breakBefore=null,this.breakAfter=null,this.nodeShadow=null,this.establishesBFC=!1,this.containingBlockForAbsolute=!1,this.vertical=this.parent?this.parent.vertical:!1,this.nodeShadow=null,this.preprocessedTextContent=null,this.formattingContext=this.parent?this.parent.formattingContext:null,this.repeatOnBreak=null,this.pluginProps={},this.fragmentIndex=1,this.afterIfContinues=null,this.footnotePolicy=null}cloneItem(){let t=new Du(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.verticalAlign=this.verticalAlign,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let s=this,r=[];s.shadowType===Wt.ShadowType.ROOTLESS&&(s.floatReference!==Di.FloatReference.INLINE||s.floatSide==="footnote")&&(n=(i=(t=s.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(s=s.parent);do(!s.firstPseudo||!s.parent||s.parent.firstPseudo===s.firstPseudo)&&r.push(s.toNodePositionStep()),s=s.parent;while(s);let o=this.preprocessedTextContent?bg(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:r,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},oi=class Vu{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new Vu(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!ri(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!ri(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Ig=class Uu{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Uu(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Ag=class Hu{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new Hu,i=this.positions,n=t.positions;for(let s=0;s<i.length;s++)n[s]=i[s].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},Rg=class $u{constructor(){c(this,"page",0),c(this,"flows",{}),c(this,"flowPositions",{}),c(this,"isBlankPage",!1),c(this,"highestSeenOffset",0),c(this,"highestSeenNode"),c(this,"lookupPositionOffset")}clone(){let t=new $u;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let s of i)if(!this.flowPositions[s].isSamePosition(t.flowPositions[s]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&Fn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},Wu=class{constructor(e){this.element=e,c(this,"left",0),c(this,"top",0),c(this,"marginLeft",0),c(this,"marginRight",0),c(this,"marginTop",0),c(this,"marginBottom",0),c(this,"borderLeft",0),c(this,"borderRight",0),c(this,"borderTop",0),c(this,"borderBottom",0),c(this,"paddingLeft",0),c(this,"paddingRight",0),c(this,"paddingTop",0),c(this,"paddingBottom",0),c(this,"width",0),c(this,"height",0),c(this,"originX",0),c(this,"originY",0),c(this,"exclusions",null),c(this,"innerShape",null),c(this,"computedBlockSize",0),c(this,"snapWidth",0),c(this,"snapHeight",0),c(this,"snapOffsetX",0),c(this,"snapOffsetY",0),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,T(this.element,"top",`${e}px`),T(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,T(this.element,"left",`${e}px`),T(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):ta(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new wt(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new wt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return lu(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new wt(e,t,e+i,t+n)}},Ms=class extends Xt{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof Je)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){t instanceof ze&&(i=tn(t.scope,new At(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Me&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Ot(e){return e!=null&&e!==j&&e!==y.normal&&e!==y.none&&!K(e)}var Fe=Di.FloatReference;function Fg(e){switch(e){case"inline":return Fe.INLINE;case"column":return Fe.COLUMN;case"region":return Fe.REGION;case"page":return Fe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function Vi(e){switch(e){case Fe.INLINE:return!1;case Fe.COLUMN:case Fe.REGION:case Fe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function bl(e,t,i,n){let s=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Fu(e,s,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let r=Ru(e,s,i),o=ug(r,s);o==="line-left"?e="left":o==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&(H.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Gu=class{constructor(e,t,i,n,s,r){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=s,this.floatMinWrapBlock=r,c(this,"order",null),c(this,"id",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(e){return!1}},Lg=class{constructor(){c(this,"floats",[]),c(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>ri(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(i=>ri(i.nodePosition,e));return t>=0?this.floats[t]:null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},ju=class{constructor(e,t,i,n,s,r){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=s,this.continues=r}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},yl=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&ri(this.nodePosition,e.nodePosition):!1}},pn=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,c(this,"children",[]),c(this,"writingMode"),c(this,"direction"),c(this,"invalidated",!1),c(this,"floatStore"),c(this,"forbiddenFloats",[]),c(this,"floatFragments",[]),c(this,"stashedFloatFragments",[]),c(this,"floatAnchors",{}),c(this,"floatsDeferredToNext",[]),c(this,"floatsDeferredFromPrevious"),c(this,"layoutConstraints",[]),c(this,"locked",!1),e&&e.children.push(this),this.writingMode=r||e&&e.writingMode||y.horizontal_tb,this.direction=o||e&&e.direction||y.ltr,this.floatStore=e?e.floatStore:new Lg;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}getParent(e){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${e}`);return this.parent}getPreviousSiblingOf(e,t,i,n){let s=this.children.indexOf(e);s<0&&(s=this.children.length);for(let r=s-1;r>=0;r--){let o=this.children[r];if(o.floatReference===t&&o.flowName===i&&ri(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new Xi().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,s)=>n.getOrder()-s.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let s=this.floatFragments.splice(n,1)[0],r=s.area&&s.area.element;r&&r.parentNode&&r.parentNode.removeChild(r),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e)}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(s=>{let r=s.float,o=r.getOrder();o>t&&(!i||o>i.getOrder())&&(i=r)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(s=>s.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i)return this.locked?this.invalidate():(this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)),!0}return this.floatReference===Fe.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(s=>s.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(s=>!i.isAllowedToPrecede(s)&&n>s.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let s=this.findPageFloatFragment(i);this.removePageFloatFragment(s)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return Fu(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Ru(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],s=!1,r=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?s||(i.slice(o+1).some(l=>l.includes("block"))?(n.push("snap-block"),s=!0):n.push(a)):a.includes("inline")&&(r||(i.slice(o+1).some(l=>l.includes("inline"))?(n.push("snap-inline"),r=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n],r=this.toLogicalFloatSides(s.floatSide)[0];(r===i||i==="snap-block"&&r==="block-end"||i==="snap-inline"&&r==="inline-end")&&s.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(s),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,s){this.container;let r=this.toLogical(e),o=this.toPhysical(e),a=t&&this.toLogical(t),l=t&&this.toPhysical(t),h=this.getLimitValueInner(r,a,i,n,s);if(this.parent&&this.parent.container){let u=this.parent.getLimitValue(o,l,i,n,s);switch(o){case"top":return Math.max(h,u);case"left":return Math.max(h,u);case"bottom":return Math.min(h,u);case"right":return Math.min(h,u);default:}}return h}getLimitValueInner(e,t,i,n,s){this.container;let r=this.getLimitValuesInner(i,n,s,e,t);switch(e){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: ${e}`)}}getLimitValuesInner(e,t,i,n,s){this.container;let r=this.container.originX,o=this.container.originY,a=this.container.getPaddingRect(),l={top:a.y1-o,left:a.x1-r,bottom:a.y2-o,right:a.x2-r,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function h(d,p,f){return d.unit==="%"?f*d.num/100:e.convertLengthToPx(d,p,t)}let u=this.floatFragments;return u.length>0&&(l=u.reduce((d,p)=>{if(i&&!i(p,this))return d;let[f,m]=this.toLogicalFloatSides(p.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||s&&m.includes("block")===s.includes("block")&&m!==s))return d;let g=p.area,w=p.continuations[0].float.floatMinWrapBlock,v=d.top,b=d.left,C=d.bottom,E=d.right,A=d.floatMinWrapBlockStart,V=d.floatMinWrapBlockEnd;switch(f){case"inline-start":g.vertical?v=Math.max(v,g.top+g.height):b=Math.max(b,g.left+g.width);break;case"block-start":g.vertical?(w&&g.left<E&&(A=h(w,g.rootViewNodes[0],a.x2-a.x1)),E=Math.min(E,g.left)):(w&&g.top+g.height>v&&(A=h(w,g.rootViewNodes[0],a.y2-a.y1)),v=Math.max(v,g.top+g.height));break;case"inline-end":g.vertical?C=Math.min(C,g.top):E=Math.min(E,g.left);break;case"block-end":g.vertical?(w&&g.left+g.width>b&&(V=h(w,g.rootViewNodes[0],a.x2-a.x1)),b=Math.max(b,g.left+g.width)):(w&&g.top<C&&(V=h(w,g.rootViewNodes[0],a.y2-a.y1)),C=Math.min(C,g.top));break;default:throw new Error(`Unknown logical float side: ${f}`)}return{top:v,left:b,bottom:C,right:E,floatMinWrapBlockStart:A,floatMinWrapBlockEnd:V}},l)),l.left+=r,l.right+=r,l.top+=o,l.bottom+=o,l}setFloatAreaDimensions(e,t,i,n,s,r,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,s,r,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0].includes("block")&&!o[a[0]])return null;e.clientLayout;let l=a.find(A=>A.includes("inline")&&o[A==="inline-start"?"inline-end":"inline-start"]),h=a.find(A=>A.includes("block")),u=this.getLimitValue("block-start",l,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",l,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",h,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",h,e.layoutContext,e.clientLayout),m=e.vertical?e.originX:e.originY,g=e.vertical?e.originY:e.originX;u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+m):Math.max(u,e.top+m),d=e.vertical?Math.max(d,e.left+m):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+m);function w(A,V){let D=A(e.bands,V);return D?(e.vertical&&(D=ru(D)),u=e.vertical?Math.min(u,D.x2):Math.max(u,D.y1),d=e.vertical?Math.max(d,D.x1):Math.min(d,D.y2),!0):r}let v,b,C,E;if(s){let A=e.vertical?Rs(new wt(d,p,u,f)):new wt(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(nf,A)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(sf,A)||(C=(d-u)*e.getBoxDir(),v=C-e.getInsetBefore()-e.getInsetAfter(),E=(f-p)*e.getInlineDir(),b=E-e.getInsetStart()-e.getInsetEnd(),!r&&(v<=0||b<=0)))return null}else{v=e.computedBlockSize,C=v+e.getInsetBefore()+e.getInsetAfter();let A=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let D=this.container.getPaddingRect(),te=this.container.getBoxDir()*(n-(this.container.vertical?D.x2:D.y1)),ie=this.container.getBoxDir()*((this.container.vertical?D.x1:D.y2)-n-C);te<=ie?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!r&&A<C)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?b=ra(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?b=e.getContentInlineSize():b=e.vertical?e.height:e.width,E=b+e.getInsetStart()+e.getInsetEnd();let V=(f-p)*e.getInlineDir();if(!r&&V<E)return null}return u-=m,d-=m,p-=g,f-=g,a.some(A=>A==="inline-start"||A==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,b):(a.some(A=>A==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-E*e.getInlineDir(),b),a.some(A=>A==="block-start"||A==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,v):(a.some(A=>A==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-C*e.getBoxDir(),v),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let e=this.getContainer().vertical;return this.floatFragments.filter(t=>t.floatSide==="block-end").reduce((t,i)=>{let n=i.getOuterRect();return e?Math.max(t,n.x2):Math.min(t,n.y1)},e?0:1/0)}getPageFloatClearEdge(e,t){function i(h){return u=>h.isAnchorAlreadyAppeared(u.float.getId())}function n(h,u){return e==="inline-start"&&(h.floatSide.includes("inline-end")||h.floatSide==="block-end")||e==="inline-end"&&(h.floatSide.includes("inline-start")||h.floatSide==="block-start")?!1:h.continuations.some(i(u))}let s=t.getPaddingRect(),r=t.vertical?s.x1:s.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return r;o=o.parent}function a(h){return h.floatFragments.some(u=>n(u,h))||h.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(o=this;o;o=o.parent)if(o.floatReference===e){if(a(o))return r;break}}t.clientLayout;let l=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<r*t.getBoxDir()?r:l}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let s=this.toLogicalFloatSides(t)[0],r=this.toLogical(i),o;r==="all"?o=["block-start","block-end","inline-start","inline-end"]:r==="both"?o=["inline-start","inline-end"]:r==="same"?s==="snap-block"?o=["block-start","block-end"]:o=[s]:o=[r];let a=e.getOrder();function l(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function h(d,p){return d.children.some(f=>f.floatFragments.some(l(p))||h(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(l(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(l(null))||h(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return o.forEach(d=>{switch(d){case"block-start":n[d]=!h(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(l(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,s=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);s?e.vertical?(o.right<s.right&&(s.right=o.right,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>s.left&&(s.left=o.left,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>s.top&&(s.top=o.top,s.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<s.bottom&&(s.bottom=o.bottom,s.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):s=o,n=n.parent}let r=Math.max(s.floatMinWrapBlockStart,s.floatMinWrapBlockEnd);return(e.vertical?s.right-s.left:s.bottom-s.top)<=r}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},on=[],Xi=class{static register(e){on.push(e)}findByNodeContext(e){for(let t=on.length-1;t>=0;t--){let i=on[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=on.length-1;t>=0;t--){let i=on[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},Bg=class{appliesToNodeContext(e){return Vi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let s=e.floatSide,r=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new Gu(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n,s){let r=e[0].float;return new ju(r.floatReference,t,i,e,n,s)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Xi.register(new Bg);var Og=ju,eo=class Xu extends Gu{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof Xu)}},vl=class extends Og{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof eo?!0:this.getOrder()<e.getOrder()}},_g=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!ri(t,this.footnote.nodePosition)}},Mg=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof eo}createPageFloat(e,t,i){let n=Fe.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Fe.PAGE).hasSameContainerAs(s)&&(n=Fe.PAGE);let r=e.toNodePosition();t.flowName;let o=new eo(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n,s){let r=e[0].float;return new vl(r.floatReference,e,n,s)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof vl);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;e.vertical=i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n),e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e)}forbid(e,t){let i=e;switch(i.footnotePolicy){case y.line:{let n=new _g(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Xi.register(new Mg);var zg="data-vivliostyle-flow-root";function Dg(e){return e.getAttribute(zg)==="true"}function xl(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return F(i)}function aa(e){return e===y.absolute||e===y.fixed}function to(e){return e instanceof en&&e.name==="running"}function qu(e,t,i,n){return e===y.none||(aa(t)?(i=y.none,e=xl(e)):(i&&i!==y.none&&!K(i)||n)&&(e=xl(e))),{display:e,position:t,float:i}}function Yu(e,t,i,n){return qu(e,t,i,n).display===y.block}function ir(e){return e instanceof ae||e instanceof Q||typeof e=="string"}function Lt(e){if(!ir(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function mi(e){return ir(e)?e.toString().includes("list-item"):!1}function Vg(e){if(!ir(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function Ku(e){if(!ir(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Ug(e,t,i,n,s,r,o){return s=s||r||y.horizontal_tb,!!o||!!i&&i!==y.none&&!K(i)||aa(t)||e===y.inline_block||e===y.table_cell||e===y.table_caption||e==y.flex||e==y.grid||e==y.flow_root||(e===y.block||e===y.list_item)&&!!n&&n!==y.visible&&n!==y.clip&&!K(n)||!!r&&s!==r}function Hg(e){return e===y.relative||e===y.absolute||e===y.fixed}var Ft=1e5;function la(e){let t=e.element.style;t.columnGap=`${Ft-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Zu(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Ju(e){return e.element.style.columnCount==="1"}function $g(e){e.element.setAttribute("data-vivliostyle-column","true")}function Wg(e){return e.element.hasAttribute("data-vivliostyle-column")}function zs(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Ft)}function io(e,t){let i=zs(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),s=Math.round(n/Ft),r=s*Ft,o=i*Ft;return t?(e.top-=r,e.bottom-=o,e.bottom<e.top&&(e.bottom+=Ft),e.right-=r,e.left-=o):e.left<-Ft/2?(e.right+=r,e.left+=o,e.left>e.right&&(e.left-=Ft),e.top+=r,e.bottom+=o):(e.left-=r,e.right-=o,e.right<e.left&&(e.right+=Ft),e.top+=r,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,s}function Qu(e,t){for(let i=0;i<e.length;i++)io(e[i],t)}function Nt(e,t,i){var n;let s=e.getElementClientRect(t),r=io(s,i);if(r===1){let o=e.getElementComputedStyle(t);if(o.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&(n=t.parentElement)!=null&&n.parentElement&&(o=e.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),l=a?.style,h=i?"width":"height",u=l&&parseFloat(l[h]);if(u){let d=u,p=r,f=parseFloat(o.paddingBlockEnd),m=parseFloat(o.borderBlockEndWidth),g=Math.ceil(f+m);for(;g-- >0&&p===r&&--d>0;){l[h]=`${d}px`;let w=e.getElementClientRect(t);if(p=io(w,i),p<r||p===r&&(i?w.right>s.right:w.top<s.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),w}l[h]=`${u}px`}}}return s}function Gg(e,t){var i,n;if(e.nodeType===1){let s=e;((i=s.style)==null?void 0:i.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 ha(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(i.columnCount))||!isNaN(parseFloat(i.columnWidth)))return t;if(i.position==="absolute")break}return null}function jg(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,s=n?.breakBefore==="column",r=i.previousElementSibling,o=r&&((t=r.style)==null?void 0:t.breakAfter)==="column";if(!s&&!o)return;let a=ha(i);if(!a)return;let l=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:h,direction:u,columnGap:d,fontSize:p}=l,f=h==="vertical-rl"||h==="vertical-lr",m=u==="rtl",g=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),v=i.getBoundingClientRect();(f?v.top>w.bottom+g:m?v.right<w.left-g:v.left>w.right+g)&&(s&&(n.breakBefore=""),o&&r&&(r.style.breakAfter=""),n.marginBlockStart=`${Ft}px`)}function Ii(e,t,i,n){let s=e.viewNode;if(!s)return NaN;let r=s.nodeType===1?s:s.parentElement;if(r&&r.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=r.style;if(r.localName==="br"||r.localName==="wbr"||o&&Lt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(s===r){if(e.after||!e.inline){if(e.after&&!e.inline&&r.querySelector("ruby")){let a=r.parentNode,l=r.nextSibling;a.removeChild(r),a.insertBefore(r,l)}let o=Nt(t,r,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=s.ownerDocument.createRange(),l=s.textContent.length;if(!l)return NaN;e.after&&(i+=l),i>=l&&(i=l-1),a.setStart(s,i),a.setEnd(s,i+1);let h=t.getRangeClientRects(a);return Qu(h,n),h=h.filter(u=>u.right>u.left&&u.bottom>u.top),h.length?(n?o=Math.min.apply(null,h.map(u=>u.left)):o=Math.max.apply(null,h.map(u=>u.bottom)),o):NaN}}function no(e,t,i){let n=Ju(t);n&&Zu(t);let s=t.clientLayout.getElementClientRect(e);n&&la(t);let r=t.getComputedMargin(e);return i?s.width+r.left+r.right:s.height+r.top+r.bottom}function Li(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function ec(e,t){var i;if(e)for(let n=e.lastChild,s=n;n!==t;n=s)s=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var qi="data-adapt-spec";function ua(e){return!!e.getAttribute(qi)}function Bi(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(ua(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function Oi(e){let t=e?.viewNode;return t?.nodeType===1&&ua(t)}function Xg(e){return e!=="inline"&&(Lt(e)||Ku(e))}function Sl(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Lt(i.display))return i;return null}var ca=class{calculateOffset(e){return Ui(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function Ui(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var Xn=class extends ca{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,c(this,"overflowIfRepetitiveElementsDropped"),c(this,"isEdgeUpdated",!1),c(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Ls(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=Ii(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,s=n?.closest("table, [style*='display: table;']");if(s){let r=s.style.borderCollapse==="collapse",o=0,a=0;for(let l=n;l;l=l.parentElement){let h=e.clientLayout.getElementComputedStyle(l);if((l===n||l===s&&!r)&&(o+=e.parseComputedLength(h.paddingBlockEnd)),l===s&&!r&&(o+=e.parseComputedLength(h.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(h.borderBlockEndWidth)):(l===n||l===s)&&(a+=e.parseComputedLength(h.borderBlockEndWidth)),l===s)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},an=class{find(e){let t=It("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},_i=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new Xn(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var s;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Wt.ShadowType.ROOTLESS&&Oi(i))return;let r=i.viewNode;((s=r.parentElement)==null?void 0:s.localName)==="viv-ts-inner"&&(r=r.parentElement.parentElement);let o=r.parentNode;ec(o,r),n&&o.removeChild(r)}finishBreak(e,t,i,n){let s=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,s),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},da=class{constructor(e){this.parent=e,c(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},pa=new _i,qg=Kr.isInstanceOfBlockFormattingContext;Ct("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,s,r)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&Yu(i,n,s,r)?new da(o?o.formattingContext:null):null});Ct("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof da?pa:null);var fa=class{constructor(){c(this,"initialBreakPositions",null),c(this,"initialStateOfFormattingContext",null),c(this,"initialPosition"),c(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=B("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(s=>{let r=n.accept(s,t);r=n.postLayout(s,this.initialPosition,t,r),r?i.finish(s):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},Yg=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},so=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=B("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?He(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?r=t.afterIgnoredTextNode(i):r=t.startIgnoredTextNode(i):i.nodeContext.after?r=t.afterNonElementNode(i):r=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?r=t.afterInlineElementNode(i):r=t.startInlineElementNode(i):i.nodeContext.after?r=t.afterNonInlineElementNode(i):r=t.startNonInlineElementNode(i):i.nodeContext.after?r=t.afterNonDisplayableNode(i):r=t.startNonDisplayableNode(i);let o=(r&&r.isPending()?r:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?s.breakLoop():(i.nodeContext=a,s.continueLoop())});return}else if(i.break){s.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),s.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},Sn=class extends Yg{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&tt(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,s=!t.allowLayout(n);return s&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),s}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:N(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),N(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:N(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=nt(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},ro=[];function Kg(){ro=[]}function tc(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Zg=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Jg=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},ic=class ds{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=ds.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){ds.fragmentIndices={}}matches(){let t=ds.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&tc(t.fragmentIndex,this.a,this.b)}};c(ic,"fragmentIndices",{});var nr=ic,ss=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new nr(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Jg(e)}static buildAnyMatcher(e){return new Zg(e)}},nc={"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},Qg=["image-resolution","orphans","widows"];function em(){return It("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Qg))}var tm={"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},oo=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],im=["max-%","min-%","%"],Cl=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<oo.length;i++)for(let n=0;n<e.length;n++){let s=oo[i].replace("%",e[n]);t[s]=!0}return t})();function nn(e,t){let i={};for(let n of oo)for(let s in e){let r=n.replace("%",s),o=n.replace("%",e[s]);i[r]=o,i[o]=r}for(let n of im)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var sc=nn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),rc=nn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),nm=nn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),sm=nn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),rm=nn({inside:"right",outside:"left"},{}),om=nn({inside:"left",outside:"right"},{}),_=class ao{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ao(i,this.priority)}increaseSpecificity(t){return t==0?this:new ao(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&$t(i)?this.value:Vs(t,this.value,i,n,s)}isEnabled(t){return!0}},lo=class ho extends _{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new _(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new ho(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new ho(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){H.warn(i)}return!1}};function uo(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Gt(e,t,i,n){if(e)if(!i)delete e[t];else{let s=e[t];(!s||i.priority>=s.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var oc={"region-id":!0,"fragment-selector-id":!0};function am(e){return!!oc[e]}function co(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Hi(e){return e.charAt(0)!=="_"&&!oc[e]}function Cn(e){return!!nc[e]||$t(e)}function _e(e,t){return e[t]}function bi(e,t,i){i?e[t]=i:delete e[t]}function Tt(e,t){return e[t]}function qn(e,t){let i=e[t];return i||(i={},e[t]=i),i}var ac=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function lc(e,t){return e[t]}function hc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function Ds(e,t,i,n,s,r,o){var a,l;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(h=>{if(h.id){let u=qn(t,h.styleKey);t=u[h.id],t||(t={},u[h.id]=t)}}),o){let h=ac(t);t={},h.push({styles:t,matcher:o})}for(let h in i)if(!co(h))if(am(h)){let u=lc(i,h),d=hc(t,h);Array.prototype.push.apply(d,u)}else{let u=_e(i,h);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Gt(t,h,d,e);let p=(l=(a=e.style)==null?void 0:a.validatorSet.shorthands[h])==null?void 0:l.propList;if(p)for(let f of p){let m=new _(j,d.priority);Gt(t,f,m,e)}}}function lm(e,t){let i={};for(let n=0;n<t.length;n++)Ds(e,i,t[n],0,null,null,null);return i}function ga(e,t){if(e.length>0){e.sort((n,s)=>s.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var hm=class extends Qi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=_e(this.props,"font-size");if(!e.value.isNumeric())return Pt.em;let t=e.value;if(!Lp(t.unit))throw new Error("Unexpected state");return t.num*Pt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?po(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ma(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Vs(this.context,e,this.propName).visit(this):e}};function ma(e,t,i){let n=e.unit,s=e.num;return n==="em"?new I(s*t,"px"):n==="rem"?new I(s*i.fontSize(),"px"):n==="rlh"?new I(s*i.rootLineHeight,"px"):e}function po(e,t,i){e=ma(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new I(s/100*t,"px"):new I(s*i.queryUnitSize(n,!1),"px")}var sn=class{apply(e){}mergeWith(e){return new um([this,e])}clone(){return this}},rs=class extends sn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},um=class uc extends sn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new uc([].concat(this.list))}},wa=class extends sn{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){Ds(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ve=class extends sn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},cm=class extends ve{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}},dm=class extends ve{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}},kl=class extends ve{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}},pm=class extends ve{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},fm=class extends ve{constructor(e,t){super(),this.epubTypePatt=e,this.targetLocalName=t}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let s=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");s&&s.match(this.epubTypePatt)&&this.chained.apply(e)}}}},gm=class extends ve{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function sr(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let s of e.getAttributeNames())if((s===i||s.endsWith(`:${i}`))&&n(e,s===i?"":e.lookupNamespaceURI(s.split(":")[0]),i))return!0;return!1}var El=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){sr(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},mm=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){sr(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},wm=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){sr(e.currentElement,this.ns,this.name,(t,i,n)=>!!tm[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},ln=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){sr(e.currentElement,this.ns,this.name,(t,i,n)=>{var s;return!!((s=t.getAttributeNS(i,n))!=null&&s.match(this.regexp))})&&this.chained.apply(e)}},bm=class extends ve{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Nl=class extends ve{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},ym=class extends ve{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},xi=class extends ve{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return tc(e,this.a,this.b)}},vm=class extends xi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},fo=class extends xi{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},go=class extends xi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},mo=class extends xi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,s=i.localName,r=t[n];r||(r=t[n]={}),r[s]=(r[s]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},xm=class extends ve{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},Sm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Cm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},km=class extends ve{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ye=class extends ve{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}},cc=class dc extends sn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new dc;return t.applied=this.applied,t}},ba=class extends ve{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new cc;for(let t of e)this.firstActions.push(ga(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof ve?e.getPriority():0))}positive(){return!0}relational(){return!1}},Em=class extends ba{positive(){return!1}},Nm=class extends ba{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},pc=class extends xi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new cc;for(let n of i)this.firstActions.push(ga(n,this.checkAppliedAction))}apply(e){for(let s of this.firstActions)if(s.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,s=t.currentLocalName,r=t.currentId,o=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let l=1,h=e.previousElementSibling;for(;h;)l++,h=h.previousElementSibling;t.currentSiblingOrder=l;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=s,t.currentId=r,t.currentClassNames=o,t.currentSiblingOrder=a,u}getPriority(){return 5}},Pm=class extends pc{constructor(e,t,i){super(e,t,i)}apply(e){for(let s of this.firstActions)if(s.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},rr=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Tm=class fc extends rr{constructor(t,i,n){super(t,i,n)}fresh(t){return new fc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},Im=class gc extends rr{constructor(t,i,n){super(t,i,n)}fresh(t){return new gc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},Am=class mc extends rr{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new mc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},Rm=class wc extends rr{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new wc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},Fm=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},Lm=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},Bm=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},Om=class extends Qi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new Je(e):new Je("about:invalid");case"string":default:return e?new G(e):new G("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof Q){let s=e.values[0].values;s.length>=2&&(t=s[1].stringValue()),i=s[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function kn(e){if(Ot(e)){if(e instanceof G)return e.stringValue();if(e instanceof Q)return e.values.map(t=>kn(t)).join("")}return""}var wo=class extends Qi{constructor(e,t,i){super(),this.cascade=e,this.element=t,this.counterResolver=i}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let s=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,s}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new G("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new G("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}visitFuncCounter(e){let t=e[0].toString(),i=e.length>1?e[1].stringValue():"decimal",n=this.cascade.counters[t];if(n&&n.length){let s=n&&n.length&&n[n.length-1]||0;return new G(this.format(s,i))}else{let s=new U(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new Q([s])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",s=this.cascade.counters[t],r=new ii;if(s&&s.length)for(let a=0;a<s.length;a++)a>0&&r.append(i),r.append(this.format(s[a],n));let o=new U(this.counterResolver.getPageCountersVal(t,a=>{let l=[];if(a.length)for(let u=0;u<a.length;u++)l.push(this.format(a[u],n));let h=r.toString();return h.length&&l.push(h),l.length?l.join(i):this.format(0,n)}));return new Q([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof Je?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new U(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new Q([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof Je?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e[2].stringValue(),r=e.length>3?e[3].stringValue():"decimal",o=new U(this.counterResolver.getTargetCountersVal(i,n,a=>{let l=a.map(h=>this.format(h,r));return l.length?l.join(s):this.format(0,r)}));return new Q([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof Je?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",s=new U(this.counterResolver.getTargetTextVal(i,n));return new Q([s])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new U(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new U(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,r,o;let a=e.length>0?e[0].stringValue():"text",l="";switch(a){case"text":l=this.element.textContent;break;case"before":case"after":case"marker":{let h=Tt(this.cascade.currentStyle,"_pseudos"),u=(i=(t=h?.[a])==null?void 0:t.content)==null?void 0:i.value;l=kn(u)}break;case"first-letter":{let h=Tt(this.cascade.currentStyle,"_pseudos"),u=(kn((s=(n=h?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||kn((o=(r=h?.after)==null?void 0:r.content)==null?void 0:o.value)).match(As);l=u?u[0]:""}break}return new G(l)}visitFuncLeader(e){let t="";if(e[0]instanceof ae)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof G&&(t=e[0].stringValue());return t.length==0?new G(""):new U(new Me(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function Er(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let s=e.ownerDocument.createRange();s.selectNodeContents(e),n=t.getRangeClientRects(s)}return n.reduce((s,r)=>s+(i==="vertical-rl"||i==="vertical-lr"?r.height:r.width),0)}var _m=(e,t,i)=>{let n=t.filter(l=>l.after&&l.viewNode.nodeType===1&&l.viewNode.getAttribute("data-viv-leader"));for(let l of n){let h=function(k){C==="rtl"?m.textContent=(k.startsWith("\u200F")?"":"\u200F")+k+(k.endsWith("\u200F")?"":"\u200F"):m.textContent=k},u=function(){let k=i.clientLayout.getElementClientRect(g);return b==="vertical-rl"||b==="vertical-lr"?C==="rtl"?k.top-=x:k.bottom+=x:C==="rtl"?k.left-=x:k.right+=x,D.left>k.left||D.right<k.right||D.top>k.top||D.bottom<k.bottom},d=function(){let k,R,L=v.repeat(1e4);if(h(L),u())k=1,R=1e4;else return;for(let z=0;z<16;z++){let $="",q=Math.floor((k+R)/2);for(let Z=0;Z<q;Z++)$+=v;if(h($),u())R=q;else{if(k==q)return;k=q}}h(v)},p=function(k){let R=0,L=g.parentElement;for(;L&&L!==f.viewNode;)R+=i.getComputedInsets(L)[k],L=L.parentElement;return R};var s=h,r=u,o=d,a=p;let f=l.parent;for(;f&&f.inline;)f=f.parent;let m=l.viewNode,g=m.parentElement,w=g.getAttribute("data-adapt-pseudo"),v=m.getAttribute("data-viv-leader-value"),{writingMode:b,direction:C,marginInlineEnd:E}=i.clientLayout.getElementComputedStyle(g);m.style.marginInlineStart="1px",h(v),g.style.display="inline-block",g.style.textIndent="0";let A=ha(f.viewNode),V=A?.style.columnFill||null;A&&(A.style.columnFill="auto");let D=i.clientLayout.getElementClientRect(f.viewNode),te=i.clientLayout.getElementClientRect(g),ie=i.parseComputedLength(E),je=[],at=g.parentElement;for(;at.parentElement&&at.parentElement!==f.viewNode;)at=at.parentElement;let xe=at.nextSibling;for(;xe;){if(xe.nodeType===1){let k=xe,{display:R,float:L,position:z}=i.clientLayout.getElementComputedStyle(k);if(L!=="none"||z==="absolute"||z==="fixed"){xe=xe.nextSibling;continue}if(Lt(R))je.push(k);else if(Vg(R))break}else if(xe.nodeType===3){let k=xe;k.length>0&&je.push(k)}xe=xe.nextSibling}let x=je.reduce((k,R)=>k+Er(R,i.clientLayout,b),0);if(w!=="after"){let k=Er(at,i.clientLayout,b),R=Er(g,i.clientLayout,b);x+=k-R}b==="vertical-rl"||b==="vertical-lr"?(C==="rtl"?D.top+=ie:D.bottom-=ie,D.top=Math.min(te.top,D.top),D.bottom=Math.max(te.bottom,D.bottom)):(C==="rtl"?D.left+=ie:D.right-=ie,D.left=Math.min(te.left,D.left),D.right=Math.max(te.right,D.right)),d();let O=i.clientLayout.getElementClientRect(g);C=="rtl"?g.style.float="left":g.style.float="right";let S=i.clientLayout.getElementClientRect(g),P=0;C=="rtl"?b=="vertical-rl"||b=="vertical-lr"?P=O.top-S.top-p("top"):P=O.left-S.left-p("left"):b=="vertical-rl"||b=="vertical-lr"?P=S.bottom-O.bottom-p("bottom"):P=S.right-O.right-p("right"),P-=x,P=Math.max(0,P-.1),g.style.float="",m.style.marginInlineStart=`${P}px`,A&&(V?A.style.columnFill=V:A.style.removeProperty("column-fill"))}};Ct("POST_LAYOUT_BLOCK",_m);var ya=1/1048576;function Ci(e,t){for(let i in e)t[i]=e[i].clone()}var Mm=class bc{constructor(){c(this,"nsCount",0),c(this,"nsPrefix",{}),c(this,"tags",{}),c(this,"nstags",{}),c(this,"epubtypes",{}),c(this,"classes",{}),c(this,"ids",{}),c(this,"pagetypes",{}),c(this,"order",0)}clone(){let t=new bc;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Ci(this.tags,t.tags),Ci(this.nstags,t.nstags),Ci(this.epubtypes,t.epubtypes),Ci(this.classes,t.classes),Ci(this.ids,t.ids),Ci(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let s=t[i];s&&(n=s.mergeWith(n)),t[i]=n}createInstance(t,i,n,s,r){return new zm(this,t,i,n,s,r)}nextOrder(){return this.order+=ya}},zm=class{constructor(e,t,i,n,s,r){this.context=t,this.counterListener=i,this.counterResolver=n,this.counterStyleStore=r,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",{}),c(this,"currentElement",null),c(this,"currentElementOffset",null),c(this,"currentStyle",null),c(this,"currentClassNames",null),c(this,"currentLocalName",""),c(this,"currentNamespace",""),c(this,"currentId",""),c(this,"currentXmlId",""),c(this,"currentNSTag",""),c(this,"currentEpubTypes",null),c(this,"currentPageType",null),c(this,"previousPageType",null),c(this,"firstPageType",null),c(this,"pageTypePageCounts",{}),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",{}),c(this,"counterScoping",[{}]),c(this,"quotes"),c(this,"quoteDepth",0),c(this,"lang",""),c(this,"siblingOrderStack",[0]),c(this,"currentSiblingOrder",0),c(this,"siblingTypeCountsStack",[{}]),c(this,"currentSiblingTypeCounts"),c(this,"currentFollowingSiblingOrder",null),c(this,"followingSiblingOrderStack"),c(this,"followingSiblingTypeCountsStack",[{}]),c(this,"currentFollowingSiblingTypeCounts"),c(this,"viewConditions",{}),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=e,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(e){this.stack[this.stack.length-1].push(e)}increment(e,t){this.conditions[e]=(this.conditions[e]||0)+1,t&&(this.viewConditions[e]?this.viewConditions[e].push(t):this.viewConditions[e]=[t])}decrement(e,t){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(i=>i!==t),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let t=null;e&&(this.currentElementOffset,t=ss.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let s=this.viewConditions[n];return s&&s.length>0?s.length===1?s[0]:ss.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:ss.buildAllMatcher(i):ss.buildAllMatcher([t].concat(i))}applyAction(e,t){let i=e[t];i&&i.apply(this)}pushRule(e,t,i){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=i,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=e,this.currentNSTag="",this.currentEpubTypes=Nr,this.currentPageType=t,this.applyActions()}defineCounter(e,t){let i=this.counterScoping[this.counterScoping.length-1];i||(i={},this.counterScoping[this.counterScoping.length-1]=i),this.counters[e]?(i[e]&&this.counters[e].pop(),this.counters[e].push(t)):this.counters[e]=[t],i[e]=!0}pushCounters(e){var t,i,n,s,r,o,a;let l=y.inline,h=e.display;if(h&&(l=h.evaluate(this.context)),l===y.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.counterScoping.push(null);return}let u=y.inline,d=e.float;d&&(u=d.evaluate(this.context));let p=null,f=null,m=null,g=e["counter-reset"];if(g){let b=g.evaluate(this.context);b&&(p=vn(b,!0))}let w=e["counter-set"];if(w){let b=w.evaluate(this.context);b&&(m=vn(b,!1))}let v=e["counter-increment"];if(v){let b=v.evaluate(this.context);b&&(f=vn(b,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(p||(p={}),p["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),mi(l)&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((r=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?r:"")&&(m||(m={}),m["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(p||(p={}),p.footnote===void 0&&(p.footnote=0)),u===y.footnote&&(f||(f={}),f.footnote===void 0)){let b=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!b||!(b===y.footnote||b instanceof Q&&b.values.includes(y.footnote)))&&(f.footnote=1)}if(p)for(let b in p)this.defineCounter(b,p[b]);if(f)for(let b in f){this.counters[b]||this.defineCounter(b,0);let C=this.counters[b];C[C.length-1]+=f[b]}if(m)for(let b in m)if(!this.counters[b])this.defineCounter(b,m[b]);else{let C=this.counters[b];C[C.length-1]=m[b]}if(mi(l)){let b=this.counters["list-item"],C=b[b.length-1];e["ua-list-item-count"]=new _(new Ht(C),0);let E=qn(e,"_pseudos");E.marker||(E.marker={})}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let t in e){let i=this.counters[t];i&&(i.length==1?delete this.counters[t]:i.pop())}}setNamedStrings(e){let t=e["string-set"];if(!t)return;t=t.filterValue(new wo(this,this.currentElement,this.counterResolver));let i=t.value instanceof Ke?t.value.values:[t.value];for(let n of i)if(n instanceof Q){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>kn(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof en&&t.value.name==="running"){let i=t.value.values[0].stringValue();this.counterResolver.setRunningElement(i,this.currentElementOffset)}}processPseudoelementProps(e,t){this.pushCounters(e);let i=e.content;i&&(e.content=i.filterValue(new wo(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r,o;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let a=this.code.nsPrefix[this.currentNamespace];a?this.currentNSTag=a+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=t.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=Nr;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Nr;let u=_r(t);u&&(this.stack[this.stack.length-1].push(new Lm(this.lang)),this.lang=u.toLowerCase());let d=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let f=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=f[f.length-1],g=m[this.currentNamespace];g||(g=m[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,f.push({});let w=this.followingSiblingOrderStack;w[w.length-1]!==null?this.currentFollowingSiblingOrder=--w[w.length-1]:this.currentFollowingSiblingOrder=null,w.push(null);let v=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=v[v.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,v.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let C=i.quotes,E=null;if(C){let D=C.evaluate(this.context);D&&(E=new Bm(this.quotes),D===y.none?this.quotes=[new G(""),new G("")]:D===y.auto||D===y.initial?this.quotes=[new G("\u201C"),new G("\u201D"),new G("\u2018"),new G("\u2019")]:D instanceof Q&&(this.quotes=D.values))}this.pushCounters(this.currentStyle);let A=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(d||A){let D={};Object.keys(this.counters).forEach(te=>{D[te]=Array.from(this.counters[te])}),this.counterListener.countersOfId(A,D)}let V=Tt(this.currentStyle,"_pseudos");if(V){let D=!0;for(let te of Dm){te||(D=!1);let ie=V[te];if(ie)if((te==="before"||te==="after")&&!Ot((s=ie.content)==null?void 0:s.value)||te==="marker"&&!mi((r=_e(this.currentStyle,"display"))==null?void 0:r.value)||(te==="footnote-call"||te==="footnote-marker")&&((o=_e(this.currentStyle,"float"))==null?void 0:o.value)!==y.footnote)delete V[te];else if(D){if(this.processPseudoelementProps(ie,t),te==="marker")this.processMarkerPseudoelementProps(ie,t,e);else if(te==="first-letter"&&ie["initial-letter"]){let je=ie["initial-letter"].evaluate(this.context);je!==y.normal&&!K(je)&&(this.currentStyle["--viv-initialLetter"]=new _(je,0)),delete ie["initial-letter"]}}else this.stack[this.stack.length-2].push(new Fm(ie,t))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),E&&this.stack[this.stack.length-2].push(E)}processMarkerPseudoelementProps(e,t,i){var n,s,r,o,a;if(!Ot((n=e.content)==null?void 0:n.value)&&mi((s=this.currentStyle.display)==null?void 0:s.value)){let l=this.getInheritedPropertyValue("list-style-type",i,t),h=this.getInheritedPropertyValue("list-style-image",i,t);if(h instanceof Je)e.content=new _(new Q([h,new G(" ")]),0);else if(l instanceof G)e.content=new _(l,0);else if(l instanceof ae&&l!==y.none){let u=(o=(r=this.currentStyle["ua-list-item-count"])==null?void 0:r.value)==null?void 0:o.num;u!=null&&(e.content=new _(new G(this.counterStyleStore.formatMarker(l.name,u)),0)),e["list-style-type"]=new _(l,0)}}if(!Lt((a=_e(this.currentStyle,"display"))==null?void 0:a.value)){let l=this.getInheritedPropertyValue("list-style-position",i,t);l&&(e["list-style-position"]=new _(l,0))}}getInheritedPropertyValue(e,t,i){var n;for(let r=i;r;r=r.parentElement){let o=(r===this.currentElement?this.currentStyle:t.getStyle(r,!1))[e];if(o){let a=o.evaluate(this.context,e);if(a===y.inherit||a===y.unset||a===y.revert)continue;if(a===y.initial)break;return a}}let s=t.validatorSet;return(n=s?.defaultValues[e])!=null?n:null}applyAttrFilterInner(e,t){for(let i in t)Hi(i)&&!$t(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Om(e),i=this.currentStyle,n=Tt(i,"_pseudos");for(let s in n)this.applyAttrFilterInner(t,n[s]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,s,r;let o=e[0],a=new Ym(e,t,i),l=32,h={};for(let u in o)if(co(u)){let d=Tt(o,u);for(let p in d)this.applyVarFilter([d[p],...e],t,i)}else if(Hi(u)){let d=_e(o,u),p=d.value;for(let f=0;;f++){if(f>=l){p=j;break}let m=p.visit(a);if(a.error){p=j,a.error=!1;break}if(m===p)break;p=m}if(p!==d.value){let f=t.validatorSet,m=(n=f?.shorthands[u])==null?void 0:n.clone();if(m)if(K(p)){for(let g of m.propList){let w=new _(p,d.priority),v=_e(o,g);bi(h,g,uo(this.context,v,w))}delete o[u]}else{let g=tn(t.scope,new At(p.toString(),null),"");if(g&&(g.visit(m),!m.error)){for(let w of m.propList){let v=new _((r=(s=m.values[w])!=null?s:f.defaultValues[w])!=null?r:y.initial,d.priority),b=_e(o,w);bi(h,w,uo(this.context,b,v))}delete o[u]}}else o[u]=new _(p,d.priority)}if(h[u]){let f=_e(o,u);f&&f.value!==j&&Gt(h,u,f,this.context)}}for(let u in h)o[u]=h[u]}applyCalcFilter(e,t){let i=new Pc(t);for(let n in e)if(co(n)){let s=Tt(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(Hi(n)&&!$t(n)){let s=_e(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new _(r,s.priority))}}applyActions(){let e;for(e=0;e<this.currentClassNames.length;e++)this.applyAction(this.code.classes,this.currentClassNames[e]);for(e=0;e<this.currentEpubTypes.length;e++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[e]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2];for(e=0;e<i.length;)i[e].push(this,t)?i.splice(e,1):e++}this.isFirst=!0,this.isRoot=!1}pop(){for(let e=1;e>=-1;--e){let t=this.stack[this.stack.length-e-2],i=0;for(;i<t.length;)t[i].pop(this,e)?t.splice(i,1):i++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},Nr=[],Dm=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"],bo=null;function Vm(e){bo=e}var Ln=class extends Gn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,c(this,"chain",null),c(this,"specificity",0),c(this,"elementStyle",null),c(this,"conditionCount",0),c(this,"pseudoelement",null),c(this,"footnoteContent",!1),c(this,"cascade"),c(this,"state"),c(this,"viewConditionId",null),c(this,"insideSelectorRule"),c(this,"invalid",!1),this.cascade=n?n.cascade:bo?bo.clone():new Mm,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=ga(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||(t&&(this.specificity+=1),t&&e?this.chain.push(new pm(e,t.toLowerCase())):t?this.chain.push(new kl(t.toLowerCase())):this.chain.push(new gm(e)))}invalidSelector(e){H.warn(e),this.chain.push(new Ye("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof Yi;e=e.parent)e.parent.invalid=!0}classSelector(e){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by .${e}`);return}this.specificity+=256,this.chain.push(new cm(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Sm);break;case"disabled":this.chain.push(new Cm);break;case"checked":this.chain.push(new km);break;case"root":case"scope":this.chain.push(new ym);break;case"link":this.chain.push(new kl("a")),this.chain.push(new El("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${qt(i)}($|\\s)`),s=t[1];this.chain.push(new fm(n,s))}else this.chain.push(new Ye(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ye(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new bm(new RegExp(`^${qt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ye(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Um[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ye(""));break}case"first-child":this.chain.push(new Nl);break;case"last-child":this.chain.push(new go(0,1));break;case"first-of-type":this.chain.push(new fo(0,1));break;case"last-of-type":this.chain.push(new mo(0,1));break;case"only-child":this.chain.push(new Nl),this.chain.push(new go(0,1));break;case"only-of-type":this.chain.push(new fo(0,1)),this.chain.push(new mo(0,1));break;case"empty":this.chain.push(new xm);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,t){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ye(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ye(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new dm(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new El(e,t);break;case 39:s=new mm(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ye(""):s=new ln(e,t,new RegExp(`(^|\\s)${qt(n)}($|\\s)`));break;case 44:s=new ln(e,t,new RegExp(`^${qt(n)}($|-)`));break;case 43:n?s=new ln(e,t,new RegExp(`^${qt(n)}`)):s=new Ye("");break;case 42:n?s=new ln(e,t,new RegExp(`${qt(n)}$`)):s=new Ye("");break;case 46:n?s=new ln(e,t,new RegExp(qt(n))):s=new Ye("");break;case 50:if(n=="supported")s=new wm(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(s)}descendantSelector(){let e=`d${os++}`;this.processChain(new rs(new Tm(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}childSelector(){let e=`c${os++}`;this.processChain(new rs(new Im(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${os++}`;this.processChain(new rs(new Am(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${os++}`;this.processChain(new rs(new Rm(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new wa(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new lo(t,0,this.condition):i=new _(t,0),hc(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===y.oeb_page_head||t===y.oeb_page_foot)&&(this.simpleProperty("flow-options",new Q([y.exclusive,y._static]),i),this.simpleProperty("flow-into",t,i),t=y.block),It("SIMPLE_PROPERTY").forEach(r=>{let o=r({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),s=this.condition?new lo(t,n,this.condition):new _(t,n);Gt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new Yi(this);break;case"not":i=new Hm(this);break;case"where":i=new $m(this);break;case"has":i=new Wm(this);break;case"nth-child":t&&t.length>=2&&(i=new vc(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Gm(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},Um={"nth-child":vm,"nth-of-type":fo,"nth-last-child":go,"nth-last-of-type":mo},os=0,Yi=class yc extends Ln{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,c(this,"parentChain"),c(this,"chains",[]),c(this,"maxSpecificity",0),c(this,"selectorTexts",[]),this.parentChain=t.chain}nextSelector(){this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Nm(this.selectorTexts):this.positive()?new ba(this.chains):new Em(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ye("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let s=this;s instanceof yc;s=s.parent)if(s.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},Hm=class extends Yi{positive(){return!1}forgiving(){return!1}},$m=class extends Yi{increasingSpecificity(){return!1}},Wm=class extends Yi{relational(){return!0}},vc=class extends Yi{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new pc(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ye("")),this.owner.popHandler()}forgiving(){return!0}},Gm=class extends vc{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Pm(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ye("")),this.owner.popHandler()}},jm=class extends Gn{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",s=new Un(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},fn=class extends Gn{constructor(e,t,i,n,s,r){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=s,this.ruleType=r,c(this,"order"),this.order=0}property(e,t,i){i?H.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=ya;let s=this.condition?new lo(t,n,this.condition):new _(t,n);Gt(this.elementStyle,e,s)}},Xm=class extends Nu{constructor(e,t){super(e),this.validatorSet=t,c(this,"elementStyle",{}),c(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){H.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){H.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Eu:ku;n+=this.order,this.order+=ya;let s=new _(t,n);Gt(this.elementStyle,e,s)}};function xc(e,t){let i=ac(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function yo(e,t,i){xc(i,n=>{En(e,n,t)})}function qm(e,t,i,n){let s=new Xm(e,t),r=new At(n,s);try{ig(r,s,i)}catch(o){H.warn(o,"Style attribute parse error:")}return s.elementStyle}function Sc(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.vertical_rl}return i}function Cc(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==y.inherit&&s!==y.revert&&s!==y.unset)return s===y.rtl}return i}function kc(e,t,i,n,s){let r={};for(let o in e)Hi(o)&&(r[o]=_e(e,o));return yo(r,t,e),Ec(e,i,n,(o,a)=>{En(r,a,t),yo(r,t,a)}),r}function Ec(e,t,i,n){let s=Tt(e,"_regions");if((t||i)&&s){if(i){let r=["footnote"];t?t=t.concat(r):t=r}for(let r of t){let o=s[r];o&&n(r,o)}}}function En(e,t,i){for(let n in t)if(Hi(n)){let s=_e(t,n),r=e[n];e[n]=uo(i,r,s)}}var Nc=(e,t,i,n,s,r)=>{var o,a;let l=i?n?nm:sc:n?sm:rc,h=s?rm:om;for(let u in e){let d=e[u];if(!d)continue;let p=(o=l[u])!=null?o:l[h[u]],f=(a=h[u])!=null?a:h[l[u]],m=p??f,g;if(m){let w=e[m];if(w&&w.priority>d.priority||p&&f&&p!==f&&(m=f,w=e[m],w&&w.priority>d.priority))continue;g=Cl[p]?p:Cl[f]?f:u}else g=u,u.startsWith("text-align")&&(d.value===y.inside||d.value===y.outside)&&(d=new _(s===(d.value===y.inside)?y.right:y.left,d.priority));t[g]=r(u,d)}},Ym=class extends Qi{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,s,r;let o=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let l=(n=a[e])==null?void 0:n.value;if(l)return l}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(r=(s=this.styler.getStyle(o,!1))==null?void 0:s[e])==null?void 0:r.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof ae&&e.values[0].name;return!t||!$t(t)?(this.error=!0,j):this.getVarValue(t)||(e.values.length<2?(this.error=!0,j):e.values.length===2?e.values[1]:new Ke(e.values.slice(1)))}},Pc=class extends Qi{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=tn(this.context.rootScope,new At(i,null),"");if(n instanceof U)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&!isNaN(s)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new I(s,"px"):/\d[a-z]/i.test(i)||(t=new Ht(s)))}catch(s){H.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(zh(e.unit)||Op(e.unit))?new I(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new I(e.num*this.percentRef/100,"px"):e}};function Vs(e,t,i,n,s){try{if(t instanceof U)return t.expr instanceof Me&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:og(e,t.expr,i);if(t instanceof I||t instanceof en||t instanceof Q||t instanceof Ke)return t.visit(new Pc(e,!0,n,s))}catch(r){return H.warn(r),j}return t}var Pl={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Tl(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.none;if(t===y.none)return Pl;let i=t instanceof Q?t.values:[t],n=Object.create(Pl);for(let s of i)if(s instanceof ae)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 Il(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Km={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Al={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Rl={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Fl(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.normal;if(t===y.normal)return Al;if(t===y.auto)return Rl;let i=t instanceof Q?t.values:[t],n=Object.create(Al);for(let s of i)if(s instanceof ae)switch(s.name){case"trim-both":case"trim-auto":return Rl;case"space-all":return Km;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 Pr={ideographAlpha:!1,ideographNumeric:!1},Zm={ideographAlpha:!0,ideographNumeric:!0};function Ll(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.normal;if(t===y.normal||t===y.auto)return Zm;if(t===y.none)return Pr;let i=t instanceof Q?t.values:[t],n=Object.create(Pr);for(let s of i)if(s instanceof ae)switch(s.name){case"no-autospace":return Pr;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Bl(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Ol(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var Jm=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let s=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\p{M}*(?=\P{M})|.(?=(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000])|(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*(?=(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}])|(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])[\p{L}\p{Nd}]\p{M}*(?=(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF])/gsu,"$&\0").split("\0");if(s.length>1){let r=s.length-1;for(let o=0;o<r;o++)n.parentNode.insertBefore(document.createTextNode(s[o]),n);n.textContent=s[r]}}}processGeneratedContent(e,t,i,n,s,r){s=Ol(s);let o=Ll(t),a=Fl(i),l=Tl(n);if(Il(l)&&Bl(o,a))return;this.preprocessForTextSpacing(e);let h=e.style.whiteSpace;(r?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let m=!d,g=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),v=!p;this.processTextSpacing(f,m||g,m,g,w,v,d,p,o,a,l,s,r),d=f}e.style.whiteSpace=h}postLayoutBlock(e,t){var i,n,s,r,o,a,l;let h=!e||e.fragmentIndex===1&&p(),u=h||f();function d(v){var b;if(v?.nodeType!==1)return!1;let C=v;if(C.hasAttribute(qi))return!0;let{position:E,float:A}=(b=C.style)!=null?b:{};return E==="absolute"||E==="fixed"||A&&A!=="none"}function p(){let v=t[0];for(let b=v;;b=b.parent)if(!b||!b.inline){if(b?.fragmentIndex!==1)return!1;break}if(!v.inline)return!0;for(let b=v.viewNode.previousSibling;b;b=b.previousSibling)if(!He(b,v.whitespace)&&!d(b))return!1;return!0}function f(){var v,b;let C=t[0],E;for(;C&&C.inline&&(E=(v=C.viewNode)==null?void 0:v.previousSibling,!(E&&(E.nodeType===3&&/^[ \t\r\n\f]*$/.test(E.textContent)&&C.whitespace!==ot.PRESERVE&&(E=E.previousSibling),E)));)C=C.parent;for(;E;){if(E.nodeType===1){if(E.localName==="br")return!0;let A=(b=E.style)==null?void 0:b.display;if(A&&A!=="inline")return!/^(inline|ruby)\b/.test(A)}else if(E.nodeType===3){if(C.whitespace===ot.PRESERVE){if(/\n$/.test(E.textContent))return!0}else if(C.whitespace===ot.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.textContent))return!0}E=E.lastChild}return!1}let m=-1;for(let v=0;v<t.length;v++){let b=t[v];if(!b.after&&b.inline&&!b.display&&b.parent&&b.viewNode.parentNode&&b.viewNode.nodeType===Node.TEXT_NODE&&!He(b.viewNode,b.whitespace)){let C=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===ot.PRESERVE){if(/\n$/.test(P.viewNode.textContent))return!0}else if(P.whitespace===ot.NEWLINE&&/\n[ \t\r\n\f]*$/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.previousElementSibling)==null?void 0:L.localName)==="br")return He(P.viewNode,P.whitespace)}return!1},E=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===ot.PRESERVE){if(/^\n/.test(P.viewNode.textContent))return!0}else if(P.whitespace===ot.NEWLINE&&/^[ \t\r\n\f]*\n/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.nextElementSibling)==null?void 0:L.localName)==="br")return He(P.viewNode,P.whitespace)}return!1};var g=C,w=E;let A=Ol((r=(n=(i=b.lang)!=null?i:b.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),V=Ll(b.inheritedProps["text-autospace"]),D=Fl(b.inheritedProps["text-spacing-trim"]),te=Tl(b.inheritedProps["hanging-punctuation"]);if(Il(te)&&Bl(V,D)||/\b(flex|grid)\b/.test(b.parent.display))continue;m<0&&(m=v);let ie=null,je=null,at=v===m,xe=v===m&&h,x=v===m&&u,O=!1,S=!1;for(let P=v-1;P>=0;P--){let k=t[P];if(C(k)){x=!0;break}if(!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){ie=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((o=k.viewNode)==null?void 0:o.nodeType)===1&&(k.viewNode.localName==="br"||gi[k.viewNode.localName]))break;P===0&&(at=!0,h&&(xe=!0,x=!0))}for(let P=v+1;P<t.length;P++){let k=t[P];if(E(k)){O=!0;break}if(k.viewNode!==b.viewNode&&!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){je=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((a=k.viewNode)==null?void 0:a.nodeType)===1&&(k.viewNode.localName==="br"||gi[k.viewNode.localName])){P===t.length-1&&d(k.viewNode)&&(S=!0);break}if(P===t.length-1){O=!0,S=!0;for(let R=k.viewNode.nextSibling;R;R=R.nextSibling)if(!d(R)){S=!1;break}}}if(((l=b.parent)==null?void 0:l.display)==="inline-block"){if(!xe){let P=b.parent.viewNode.firstChild;for(;He(P,b.whitespace);)P=P.nextSibling;b.viewNode===P&&(xe=!0)}if(!S){let P=b.parent.viewNode.lastChild;for(;He(P,b.whitespace);)P=P.previousSibling;b.viewNode===P&&(S=!0)}}if(this.processTextSpacing(b.viewNode,at,xe,x,O,S,ie,je,V,D,te,A,b.vertical)>0)break}}}processTextSpacing(e,t,i,n,s,r,o,a,l,h,u,d,p){let f=e.textContent,m=e.ownerDocument,g=0,w,v,b;function C(){if(t)return!0;if(!o)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;v||(v=m.createRange(),v.selectNode(o));let P=v.getClientRects(),k=P[P.length-1];return k?(g||(g=zs(k,p)),p?S.top<k.top+k.height-S.width||S.left+S.width<k.left+S.width/10||S.left>k.left+k.width-S.width/10:S.left<k.left+k.width-S.height||S.top>k.top+k.height-S.height/10||S.top+S.height<k.top+S.height/10):!1}function E(){if(!a)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;g||(g=zs(S,p)),b||(b=m.createRange(),b.selectNode(a));let P=b.getClientRects()[0];return P?p?S.top+S.height>P.top+S.width||S.left>P.left+P.width-S.width/10||S.left+S.width<P.left+S.width/10:S.left+S.width>P.left+S.height||S.top+S.height<P.top+S.height/10||S.top>P.top+P.height-S.height/10:!1}let A=!1,V=!1,D=!1,te=!1,ie;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(ie="viv-ts-open",A=!0,V=!0):r&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(ie="viv-ts-close",A=!0,D=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(ie="viv-ts-close",A=!0,te=!0):(h.trimStart||h.spaceFirst||h.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(ie="viv-ts-open",A=!0):(h.trimEnd||h.allowEnd||h.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(ie="viv-ts-close",A=!0),A){let S=function(z){let $=parseFloat(m.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>$},P=function(){return p?k.offsetLeft:k.offsetTop};var je=S,at=P;if(e.parentElement.localName==="viv-ts-inner")return 0;let k=m.createElement(ie),R=m.createElement("viv-ts-inner");k.appendChild(R),e.parentNode.insertBefore(k,e),R.appendChild(e);let L=S(R);if(L||V||D||te){if(ie==="viv-ts-open"){if(V)k.className="viv-hang-first";else if(i||n)h.trimStart?k.className="viv-ts-trim":k.className="viv-ts-space";else if(!(h.trimStart||h.spaceFirst)&&C())k.className="viv-ts-space";else if(h.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&S(o.parentElement)))k.className="viv-ts-trim";else if((h.trimStart||h.spaceFirst)&&C()){let z=P();k.className="viv-ts-auto",z===P()&&!C()&&(k.className="viv-ts-trim")}}else if(ie==="viv-ts-close"){if(D)k.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let z=P();te?(k.className=L?u.allowEnd&&h.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===P()&&(h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-hang-end",z===P()&&(k.className="")):k.className="viv-ts-space")):h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-ts-auto",z===P()&&(k.className="")):k.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&h.trimAdjacent&&(k.className="viv-ts-trim");else if(te){let z=E(),$=z&&u.allowEnd;$||(k.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?$&&h.trimEnd?k.className="viv-ts-auto":!$&&!E()?k.className="":!z&&u.allowEnd&&(h.trimEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):(k.className="viv-ts-space",E()||(h.allowEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):k.className="viv-hang-end"))):!z&&!E()&&(k.className="")}else if(h.trimEnd||h.allowEnd)if(E())h.allowEnd?k.className="viv-ts-space":k.className="viv-ts-auto";else{let z=P();k.className="viv-ts-auto",z===P()&&(k.className="")}}}}let xe=!1;function x(S){var P;let k=(P=S?.ownerDocument.defaultView)==null?void 0:P.getComputedStyle(S);return!!k&&(k.textOrientation==="upright"||k.textCombineUpright==="all"||k["-webkit-text-combine"]==="horizontal")}function O(S,P){if(S.nodeType===1){let L=m.defaultView.getComputedStyle(S);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let k=S.parentElement;if(k&&!k.contains(P))return O(k,P);if(P.nodeType===1){let L=m.defaultView.getComputedStyle(P);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let R=P.parentElement;return R&&!R.contains(S)?O(S,R):!1}return(l.ideographAlpha||l.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(l.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||l.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&x(o.parentElement))&&!O(o,e)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e),xe=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(l.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||l.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&x(a.parentElement))&&!O(e,a)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e.nextSibling),xe=!0)),g}registerHooks(){Ct("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Ct("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Ct("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},va=new Jm;va.registerHooks();function Qm(e){va.preprocessForTextSpacing(e)}function ew(e,t,i,n,s,r){va.processGeneratedContent(e,t,i,n,s,r)}var ps=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),tw=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],xa="data-adapt-pseudo";function Mi(e){return e.getAttribute(xa)||""}function vo(e,t){e.setAttribute(xa,t)}var _l=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,c(this,"contentProcessed",{})}getStyle(e,t){let i=Mi(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=Tt(this.style,"_pseudos"),s=n?.[i]||{};if(i.match(/^first-/)&&!s["x-first-pseudo"]){let r=1,o;i=="first-letter"?r=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(r=o[1]-0),s["x-first-pseudo"]=new _(new Re(r),0)}return s}processContent(e,t,i){let n=Mi(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0,n==="marker"&&this.processMarker(e,t,i);let s=t.content;Ot(s)&&(s.visit(new Ms(e.classList.contains("_viv-marker-outside")&&e.firstElementChild||e,this.context,s,this.exprContentListener)),Qm(e))}}processMarker(e,t,i){let n=t.content,s=t["list-style-position"],r=t["list-style-type"];if(Ot(n)){if(n instanceof Je)t.content=new Q([n]);else if(n instanceof G&&r instanceof ae){let o=r.name.toLowerCase();if((o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed")&&(e.classList.add("_viv-marker-bullet"),o==="disclosure-open"||o==="disclosure-closed")){let a=i.direction==="rtl",l=i.vertical;t.content=new G(o==="disclosure-open"?l?"\u25C2 ":"\u25BE ":l?a?"\u25B4 ":"\u25BE ":a?"\u25C2 ":"\u25B8 ")}}}if(s===y.outside){e.classList.add("_viv-marker-outside");let o=e.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","span");o.classList.add("_viv-marker-outside-content"),e.appendChild(o);let a=i.inheritedProps["text-spacing-trim"];a&&a!=="space-all"&&(t["text-spacing-trim"]=y.normal),i.inheritedProps["hanging-punctuation"]&&(t["hanging-punctuation"]=y.none)}delete t["list-style-position"],delete t["list-style-type"]}},C0=Bs.isInstanceOfAfterIfContinuesLayoutConstraint,iw=nr.registerFragmentIndex,k0=nr.clearFragmentIndices,nw=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new Sa(e,i,t),s=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=s;let r=i.firstChild;return T(r,"display","block"),N(r)})}createNodePositionForPseudoElement(){let e=ps.createElementNS("http://www.w3.org/1999/xhtml","div");vo(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new oi(i)}createShadowContext(e){return new Jr(this.sourceNode,e,null,null,null,Wt.ShadowType.ROOTED,this.styler)}},sw=class Tc{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,c(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,s){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),N(!0))):N(!0)}getRepetitiveElements(){return new rw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Tc?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},rw=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function Ic(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return N(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=aw(e,t,n);return t.fragmentLayoutConstraints.push(new sw(e,i,s)),N(e)})}function Ac(e,t){return e.thenAsync(i=>Ic(i,t))}function ow(e,t){let i=B("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=Ic(n,t);return n=n.parent,s.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function aw(e,t,i){let n=e.viewNode;n.appendChild(i);let s=no(i,t,e.vertical);return n.removeChild(i),s}var lw=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},fs=class extends ca{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,c(this,"alreadyEvaluated",!1),c(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},Us=class Rc extends Wu{constructor(t,i,n,s,r){super(t),this.layoutContext=i,this.clientLayout=n,this.layoutConstraint=s,this.pageFloatLayoutContext=r,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isFloat",!1),c(this,"isFootnote",!1),c(this,"startEdge",0),c(this,"endEdge",0),c(this,"beforeEdge",0),c(this,"afterEdge",0),c(this,"footnoteEdge",0),c(this,"box",null),c(this,"chunkPositions",null),c(this,"bands",null),c(this,"overflown",!1),c(this,"breakPositions",null),c(this,"pageBreakType",null),c(this,"forceNonfitting",!0),c(this,"leftFloatEdge",0),c(this,"rightFloatEdge",0),c(this,"bottommostFloatTop",0),c(this,"stopAtOverflow",!0),c(this,"lastAfterPosition",null),c(this,"fragmentLayoutConstraints",[]),c(this,"pseudoParent",null),c(this,"nodeContextOverflowingDueToRepetitiveElements",null),c(this,"blockDistanceToBlockEndFloats",NaN),c(this,"breakAtTheEdgeBeforeFloat",null),new.target===Rc&&$g(this),this.last=t.lastChild,this.viewDocument=t.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(t){return!!t.floatSide&&(!this.isFloat||!!t.parent)}stopByOverflow(t){return this.stopAtOverflow&&!!t&&t.overflow}isOverflown(t){return this.vertical?t<this.footnoteEdge:t>this.footnoteEdge}getExclusions(){let t=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(t)}openAllViews(t){let i=B("openAllViews"),n=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let s=n.length-1,r=null;return i.loop(()=>{for(;s>=0;){let o=r,a=n[s];if(r=_s(a,o),s===n.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),s==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),r.after=t.after,r.preprocessedTextContent=t.preprocessedTextContent,r.after))break;let l=this.layoutContext.setCurrent(r,s==0&&r.offsetInNode==0);if(s--,l.isPending())return l}return N(!1)}).then(()=>{i.finish(r)}),i.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?wg(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,i){var n,s;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0&&t.viewNode.nodeType!=1){let r=t.viewNode.textContent,o=r.match(As),a=o?o[0].length:0;if(!o&&((n=t.sourceNode)==null?void 0:n.nodeType)===3&&((s=t.sourceNode.nextSibling)==null?void 0:s.nodeType)===3&&r===t.sourceNode.textContent){let l=r+t.sourceNode.nextSibling.textContent,h=l.match(As);if(h){let u=h[0];a=u.length,t.sourceNode.textContent=u,t.viewNode.textContent=u,t.sourceNode.nextSibling.textContent=l.substr(a)}}return this.layoutContext.peelOff(t,a)}return N(t)}buildViewToNextBlockEdge(t,i){let n=!1,s=B("buildViewToNextBlockEdge");return s.loopWithFrame(r=>{var o;if(t.viewNode&&!Oi(t)&&((o=t.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(i.push(t.copy()),i.length>1e3)){let a=t.viewNode.nodeType===1?t.viewNode:t.viewNode.parentElement,l=this.clientLayout.getElementClientRect(a);if(zs(l,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let l=a;l!==t&&(t=l,Oi(t)||i.push(t.copy())),this.nextInTree(t).then(h=>{if(t=h,!t){r.breakLoop();return}(n||!this.layoutConstraint.allowLayout(t))&&(n=!0,t=t.modify(),t.overflow=!0),this.isFloatNodeContext(t)&&(Vi(t.floatReference)||t.floatSide==="footnote")?this.layoutFloatOrFootnote(t).then(u=>{if(t=u,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){r.breakLoop();return}r.continueLoop()}):t.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{s.finish(t)}),s.result()}nextInTree(t,i){let n=this.layoutContext.nextInTree(t,i);return Ac(n,this)}buildDeepElementView(t){if(!t.viewNode)return N(t);let i=[],n=t.sourceNode,s=B("buildDeepElementView");return s.loopWithFrame(r=>{t.viewNode&&t.inline&&!Oi(t)?i.push(t.copy()):(i.length>0&&this.postLayoutBlock(t,i),i=[]),this.maybePeelOff(t,0).then(o=>{let a=o;if(a!==t){let l=a;for(;l&&l.sourceNode!=n;)l=l.parent;if(l==null){t=a,r.breakLoop();return}Oi(a)||i.push(a.copy())}this.nextInTree(a).then(l=>{t=l,!t||t.sourceNode==n?r.breakLoop():this.layoutConstraint.allowLayout(t)?r.continueLoop():(t=t.modify(),t.overflow=!0,this.stopAtOverflow?r.breakLoop():r.continueLoop())})})}).then(()=>{i.length>0&&this.postLayoutBlock(t,i),s.finish(t)}),s.result()}createFloat(t,i,n,s){let r=this.viewDocument.createElement("div");return this.vertical?(s>=this.height&&(s-=.1),s<1&&(s=0),T(r,"height",`${n}px`),T(r,"width",`${s}px`)):(n>=this.width&&(n-=.1),n<1&&(n=0),T(r,"width",`${n}px`),T(r,"height",`${s}px`)),T(r,"float",i),T(r,"clear",i),this.element.insertBefore(r,t),r}killFloats(){let t=this.element.firstChild;for(;t;){let i=t.nextSibling;if(t.nodeType==1){let n=t,s=n.style.cssFloat;if(s=="left"||s=="right"||s==="none")this.element.removeChild(n);else break}t=i}}createFloats(){let t=this.element.firstChild,i=this.bands,n=this.vertical?this.getTopEdge():this.getLeftEdge(),s=this.vertical?this.getBottomEdge():this.getRightEdge(),r=null;for(let o of i){let a=o.y2-o.y1;o.left=this.createFloat(t,"left",o.x1-n,a),o.right=this.createFloat(t,"right",s-o.x2,a),o.x1<s&&o.x2>n?r=o:r||T(o.right,"float","none")}if(r){let o=i[i.length-1],a=this.vertical?-this.getLeftEdge():this.getBottomEdge();r!==o&&o.y2>=a&&(this.footnoteEdge=this.vertical?-r.y2:r.y2)}}calculateEdge(t,i,n,s){let r;if(t&&Li(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(r=Ii(t,this.clientLayout,0,this.vertical),!isNaN(r)))return r;t=i[n];let o=s-t.boxOffset;for(;;){if(r=Ii(t,this.clientLayout,o,this.vertical),!isNaN(r))return r;if(o>0){o--;continue}if(n--,n<0)return this.beforeEdge;t=i[n],t.viewNode.nodeType!=1&&(o=t.viewNode.textContent.length)}}parseComputedLength(t){let i=t.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return i?this.clientLayout.adjustLengthValue(parseFloat(i[0])):0}getComputedMargin(t){let i=this.clientLayout.getElementComputedStyle(t),n=new wr(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.marginLeft),n.top=this.parseComputedLength(i.marginTop),n.right=this.parseComputedLength(i.marginRight),n.bottom=this.parseComputedLength(i.marginBottom)),n}getComputedPaddingBorder(t){let i=this.clientLayout.getElementComputedStyle(t),n=new wr(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)),n}getComputedInsets(t){let i=this.clientLayout.getElementComputedStyle(t),n=new wr(0,0,0,0);if(i){if(i.boxSizing=="border-box")return this.getComputedMargin(t);n.left=this.parseComputedLength(i.marginLeft)+this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.marginTop)+this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.marginRight)+this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.marginBottom)+this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)}return n}setComputedInsets(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.marginLeft=this.parseComputedLength(n.marginLeft),i.borderLeft=this.parseComputedLength(n.borderLeftWidth),i.paddingLeft=this.parseComputedLength(n.paddingLeft),i.marginTop=this.parseComputedLength(n.marginTop),i.borderTop=this.parseComputedLength(n.borderTopWidth),i.paddingTop=this.parseComputedLength(n.paddingTop),i.marginRight=this.parseComputedLength(n.marginRight),i.borderRight=this.parseComputedLength(n.borderRightWidth),i.paddingRight=this.parseComputedLength(n.paddingRight),i.marginBottom=this.parseComputedLength(n.marginBottom),i.borderBottom=this.parseComputedLength(n.borderBottomWidth),i.paddingBottom=this.parseComputedLength(n.paddingBottom))}setComputedWidthAndHeight(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.width=this.parseComputedLength(n.width),i.height=this.parseComputedLength(n.height))}layoutUnbreakable(t){return this.buildDeepElementView(t)}layoutFloat(t){let i=B("layoutFloat"),n=t.viewNode,s=bl(t.floatSide,t.vertical,t.direction,this.layoutContext.page.side);return T(n,"float","none"),T(n,"display","inline-block"),T(n,"vertical-align","top"),this.buildDeepElementView(t).then(r=>{let o=Nt(this.clientLayout,n,this.vertical),a=this.getComputedMargin(n),l=new wt(o.left-a.left,o.top-a.top,o.right+a.right,o.bottom+a.bottom),h=this.rtl?this.endEdge:this.startEdge,u=this.rtl?this.startEdge:this.endEdge,d=t.parent;for(;d&&d.inline;)d=d.parent;if(d){let E=d.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"),d.viewNode.appendChild(E);let A=Nt(this.clientLayout,E,this.vertical);h=Math.max(this.rtl?this.getEndEdge(A):this.getStartEdge(A),h),u=Math.min(this.rtl?this.getStartEdge(A):this.getEndEdge(A),u),d.viewNode.removeChild(E);let V=this.vertical?l.y2-l.y1:l.x2-l.x1;s=="left"?u=Math.max(u,h+V):h=Math.min(h,u-V),d!==t.parent&&!t.firstPseudo&&(d.viewNode.appendChild(n),n.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new wt(h,this.getBoxDir()*this.beforeEdge,u,this.getBoxDir()*this.afterEdge),f=l;this.vertical&&(f=Rs(l));let m=this.getBoxDir();if(f.y1<this.bottommostFloatTop*m){let E=f.y2-f.y1;f.y1=this.bottommostFloatTop*m,f.y2=f.y1+E}rf(p,this.bands,f,s),this.vertical&&(l=ru(f));let g=this.getComputedInsets(n);T(n,"width",`${l.x2-l.x1-g.left-g.right}px`),T(n,"height",`${l.y2-l.y1-g.top-g.bottom}px`),T(n,"position","absolute"),t.display,T(n,"display",t.display);let w,v=null;if(d&&(d.containingBlockForAbsolute?v=d:v=d.getContainingBlockForAbsolute()),v){let E=v.viewNode.ownerDocument.createElement("div");E.style.position="absolute",v.vertical?E.style.right="0":E.style.left="0",E.style.top="0",v.viewNode.appendChild(E),w=Nt(this.clientLayout,E,this.vertical),v.viewNode.removeChild(E)}else w={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(v?v.vertical:this.vertical)?T(n,"right",`${w.right-l.x2}px`):T(n,"left",`${l.x1-w.left}px`),T(n,"top",`${l.y1-w.top}px`),t.clearSpacer&&(t.clearSpacer.parentNode.removeChild(t.clearSpacer),t.clearSpacer=null);let b=this.vertical?l.x1:l.y2,C=this.vertical?l.x2:l.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),p=new wt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Rs(p)),of(p,this.bands,f,null,s),this.createFloats(),s=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=C,this.updateMaxReachedAfterEdge(b),i.finish(r)):(t=t.modify(),t.overflow=!0,i.finish(t))}),i.result()}setupFloatArea(t,i,n,s,r,o){let a=this.pageFloatLayoutContext,l=a.getContainer(i),h=t.element;l.element.parentNode.appendChild(h),t.isFloat=!0,t.originX=l.originX,t.originY=l.originY,t.vertical=l.vertical,t.rtl=l.rtl,t.marginLeft=t.marginRight=t.marginTop=t.marginBottom=0,t.borderLeft=t.borderRight=t.borderTop=t.borderBottom=0,t.paddingLeft=t.paddingRight=t.paddingTop=t.paddingBottom=0,t.exclusions=(l.exclusions||[]).concat(),t.forceNonfitting=!a.hasFloatFragments(),t.innerShape=null;let u=l.getPaddingRect();t.setHorizontalPosition(u.x1-l.originX,u.x2-u.x1),t.setVerticalPosition(u.y1-l.originY,u.y2-u.y1),r.adjustPageFloatArea(t,l,this),t.init();let d=!!a.setFloatAreaDimensions(t,i,n,s,!0,!a.hasFloatFragments(),o);return d?(t.killFloats(),t.init()):l.element.parentNode.removeChild(h),d}createPageFloatArea(t,i,n,s,r){let o=this.element.ownerDocument.createElement("div");T(o,"position","absolute");let a=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),l=new pn(null,Fe.COLUMN,null,this.pageFloatLayoutContext.flowName,t.nodePosition,null,null),h=a.getContainer(),u=new cw(i,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,l,h);return l.setContainer(u),this.setupFloatArea(u,t.floatReference,i,n,s,r)?u:null}layoutSinglePageFloatFragment(t,i,n,s,r,o,a){let l=this.pageFloatLayoutContext;t=(a?a.continuations:[]).concat(t);let h=t[0].float,u=l.getPageFloatPlacementCondition(h,i,n),d=this.createPageFloatArea(h,i,o,r,u),p={floatArea:d,pageFloatFragment:null,newPosition:null};if(!d)return N(p);let f=B("layoutSinglePageFloatFragment"),m=!1,g=0;return f.loopWithFrame(w=>{if(g>=t.length){w.breakLoop();return}let v=t[g],b=new oi(v.nodePosition);d.layout(b,!0).then(C=>{p.newPosition=C,!C||s?(g++,w.continueLoop()):(m=!0,w.breakLoop())})}).then(()=>{if(!m){let w=l.setFloatAreaDimensions(d,h.floatReference,i,o,!1,s,u);if(!w)m=!0;else{let v=r.createPageFloatFragment(t,w,n,d,!!p.newPosition);l.addPageFloatFragment(v,!0),p.pageFloatFragment=v}}f.finish(p)}),f.result()}layoutPageFloatInner(t,i,n,s){let r=this.pageFloatLayoutContext,o=t.float;r.stashEndFloatFragments(o);function a(h,u){u?r.removePageFloatFragment(u,!0):h&&h.element.parentNode.removeChild(h.element),r.restoreStashedFragments(o.floatReference),r.deferPageFloat(t)}let l=B("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],o.floatSide,o.clearSide,!r.hasFloatFragments(),i,n,s).then(h=>{let u=h.floatArea,d=h.pageFloatFragment,p=h.newPosition;d?this.layoutStashedPageFloats(o.floatReference,[s]).then(f=>{if(f){if(r.addPageFloatFragment(d),r.discardStashedFragments(o.floatReference),p){let m=new yl(o,p.primary);r.deferPageFloat(m)}l.finish(!0)}else a(u,d),l.finish(!1)}):(a(u,d),l.finish(!1))}),l.result()}layoutStashedPageFloats(t,i){let n=this.pageFloatLayoutContext,s=n.getStashedFloatFragments(t),r=[],o=[],a=!1,l=B("layoutStashedPageFloats"),h=0;return l.loopWithFrame(u=>{if(h>=s.length){u.breakLoop();return}let d=s[h];if(i.includes(d)){h++,u.continueLoop();return}let p=new Xi().findByFloat(d.continuations[0].float);this.layoutSinglePageFloatFragment(d.continuations,d.floatSide,d.clearSide,!1,p,null).then(f=>{let m=f.floatArea;m&&r.push(m);let g=f.pageFloatFragment;g?(o.push(g),h++,u.continueLoop()):(a=!0,u.breakLoop())})}).then(()=>{a?(o.forEach(u=>{n.removePageFloatFragment(u,!0)}),r.forEach(u=>{let d=u.element;d&&d.parentNode&&d.parentNode.removeChild(d)})):s.forEach(u=>{let d=u.area.element;d&&d.parentNode&&d.parentNode.removeChild(d)}),l.finish(!a)}),l.result()}setFloatAnchorViewNode(t){let i=t.viewNode.parentNode,n=i.ownerDocument.createElement("span");n.setAttribute(qi,"1"),t.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(t,"footnote-call",n),i.appendChild(n),i.removeChild(t.viewNode);let s=t.modify();return s.after=!0,s.viewNode=n,s}resolveFloatReferenceFromColumnSpan(t,i,n){let s=B("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,o=r.getPageFloatLayoutContext(Fe.REGION);return r.getContainer().width<o.getContainer().width&&t===Fe.COLUMN?i===y.auto?this.buildDeepElementView(n.copy()).then(a=>{let l=a.viewNode,h=ra(this.clientLayout,l,["min-content inline size"])["min-content inline size"],u=this.getComputedMargin(l);this.vertical?h+=u.top+u.bottom:h+=u.left+u.right,h>this.width?s.finish(Fe.REGION):s.finish(t)}):i===y.all?s.finish(Fe.REGION):s.finish(t):s.finish(t),s.result()}layoutPageFloat(t){let i=this.pageFloatLayoutContext,n=new Xi().findByNodeContext(t),s,r=i.findPageFloatByNodePosition(t.toNodePosition());return r?s=N(r):s=n.createPageFloat(t,i,this),s.thenAsync(o=>{let a=Os(t,0),l=this.setFloatAnchorViewNode(t),h=n.findPageFloatFragment(o,i),u=new yl(o,a);if(h&&h.hasFloat(o))return i.registerPageFloatAnchor(o,l.viewNode),N(l);if(i.isForbidden(o)||i.hasPrecedingFloatsDeferredToNext(o))return i.deferPageFloat(u),i.registerPageFloatAnchor(o,l.viewNode),N(l);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let d=Ii(l,this.clientLayout,0,this.vertical);return this.isOverflown(d)?N(l):this.layoutPageFloatInner(u,n,d,h).thenAsync(p=>p?N(null):(i.registerPageFloatAnchor(o,l.viewNode),N(l)))}})}processLineStyling(t,i,n){let s=B("processLineStyling"),r=n.concat([]);n.splice(0,n.length);let o=0,a=t.firstPseudo;return a.count==0&&(a=a.outer),s.loopWithFrame(l=>{if(!a){l.breakLoop();return}let h=this.findLinePositions(r),u=a.count-o;if(h.length<=u){l.breakLoop();return}let d=this.findAcceptableBreakInside(r,h[u-1],!0);if(d==null){l.breakLoop();return}this.finishBreak(d,!1,!1).then(()=>{o+=u,this.layoutContext.peelOff(d,0).then(p=>{t=p,a=t.firstPseudo,r=[],this.buildViewToNextBlockEdge(t,r).then(f=>{i=f,l.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(n,r),s.finish(i)}),s.result()}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&gi[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let i=0,n=0;for(let s=t.length-1;s>=0;s--){let r=t[s];if(!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let o=this.getComputedMargin(r.viewNode),a=this.vertical?-o.left:o.bottom;a>0?i=Math.max(i,a):n=Math.min(n,a)}return i+n}layoutBreakableBlock(t){let i=B("layoutBreakableBlock"),n=[];return this.buildViewToNextBlockEdge(t,n).then(s=>{let r=n.length-1;if(r<0){i.finish(s);return}this.postLayoutBlock(s,n);let o=this.calculateEdge(s,n,r,n[r].boxOffset),a=!1;if(!s||!Li(s.viewNode)){let h=Ui(s,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*h.minimum),this.isOverflown(o+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=s)}s==null&&(o+=this.getTrailingMarginEdgeAdjustment(n)),this.updateMaxReachedAfterEdge(o);let l;t.firstPseudo?l=this.processLineStyling(t,s,n):l=N(s),l.then(h=>{n.length>0&&(this.saveBoxBreakPosition(n),a&&!this.isLoneImage(n)&&h&&(h=h.modify(),h.overflow=!0)),i.finish(h)})}),i.result()}postLayoutBlock(t,i){It("POST_LAYOUT_BLOCK").forEach(n=>{n(t,i,this)})}findEndOfLine(t,i,n){let s=this.vertical?t-1:t+1,r=0,o=i[0].boxOffset,a=r,l=i.length-1,h=i[l].boxOffset,u;for(;o<h;){u=o+Math.ceil((h-o)/2),a=r;let d=l;for(;a<d;){let f=a+Math.ceil((d-a)/2);i[f].boxOffset>u?d=f-1:a=f}let p=this.calculateEdge(null,i,a,u);if(this.vertical?p<=s:p>=s){for(h=u-1;i[a].boxOffset==u;)a--;l=a}else n&&this.updateMaxReachedAfterEdge(p),o=u,r=a}return{nodeContext:i[a],index:o,checkPointIndex:a}}findAcceptableBreakInside(t,i,n){var s,r,o;let a=this.findEndOfLine(i,t,!0),l=a.nodeContext;if(a.checkPointIndex===0&&a.index===l.boxOffset)return null;let h=l.viewNode;if(h.nodeType!=1&&((s=h.parentElement)==null?void 0:s.localName)!=="viv-ts-inner"){let u=h;l=this.resolveTextNodeBreaker(l).breakTextNode(u,l,a.index,t,a.checkPointIndex,n)}else{let u=Sl(l);if(u){if(((r=this.breakPositions)==null?void 0:r[0])instanceof fs&&u!=null&&u.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(l=u;!l.after&&l.inline&&l.parent;){let d=(o=l.viewNode)==null?void 0:o.previousSibling;for(;d&&(He(d,l.parent.whitespace)||Bi(d));)d=d.previousSibling;if(d)break;l=l.parent}}}return this.clearOverflownViewNodes(l,!1),l}resolveTextNodeBreaker(t){return It("RESOLVE_TEXT_NODE_BREAKER").reduce((i,n)=>n(t)||i,Hs.instance)}getRangeBoxes(t,i){let n=[],s=t.ownerDocument.createRange(),r=!1,o=t,a=null,l=!1,h=!0;for(;h;){let u=!0;do{let d=null;o==i&&(i.nodeType===1?h=!(!i.firstChild||r):h=!1);let p=o.nodeType===1?o:null;p?r?r=!1:ua(p)?u=!l:!p.firstChild||gi[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Xg(this.clientLayout.getElementComputedStyle(p).display)?(u=!l,u?(p.localName==="ruby"&&o.firstChild&&(o=o.firstChild),s.setStartBefore(o),l=!0,a=o):/^r(uby|tc?)$/.test(p.localName)||(a=o),o.contains(i)&&(h=!1)):d=o.firstChild:(l||(o.parentNode==null?h=!1:(s.setStartBefore(o),l=!0)),a=o),d||(d=o.nextSibling,d||(r=!0,d=o.parentNode)),o=d}while(u&&h);if(l){s.setEndAfter(a);let d=this.clientLayout.getRangeClientRects(s);Qu(d,this.vertical);for(let p=0;p<d.length;p++)n.push(d[p]);l=!1}}return n}findLinePositions(t){let i=[],n=this.getRangeBoxes(t[0].viewNode,t[t.length-1].viewNode);n.sort(this.vertical?Ng:Eg);let s=0,r=0,o=0,a=0,l=0,h=this.getBoxDir();for(;;){if(l<n.length){let u=n[l],d=1;if(a>0){let p=Math.max(this.getBoxSize(u),1);h*this.getBeforeEdge(u)<h*s?d=h*(this.getAfterEdge(u)-s)/p:h*this.getAfterEdge(u)>h*r?d=h*(r-this.getBeforeEdge(u))/p:d=1}if(a==0||d>=.6||d>=.2&&this.getStartEdge(u)>=o-1){o=this.getEndEdge(u),this.vertical?(s=a==0?u.right:Math.max(s,u.right),r=a==0?u.left:Math.min(r,u.left)):(s=a==0?u.top:Math.min(s,u.top),r=a==0?u.bottom:Math.max(r,u.bottom)),a++,l++;continue}}if(a>0&&(i.push(r),a=0),l>=n.length)break}return i.sort(Rh),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(t){let i=0;for(let n=t;n;n=n.parent)if(!n.inline&&un(n.viewNode)){let s=this.getComputedPaddingBorder(n.viewNode);i+=n.vertical?-s.left:s.bottom,n.display==="table"&&(i+=(n.vertical?-1:1)*n.blockBorderSpacing)}return i}getOffsetByRepetitiveElements(t){let i;return t?i=t.calculateOffset(this):i=Ui(null,this.collectElementsOffset()),i.current}findBoxBreakPosition(t,i){let n=this.element.parentNode,s=this.element.nextSibling;n.removeChild(this.element),n.insertBefore(this.element,s);let r=t.checkPoints,o=r[0];for(;o.parent&&o.inline;)o=o.parent;let a,l;i?(a=1,l=1):(a=Math.max((o.inheritedProps.widows||2)-0,1),l=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),u=this.findLinePositions(r),d=this.footnoteEdge-h,p=this.getBoxDir(),f=this.getOffsetByRepetitiveElements(t);d-=p*f;let m=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(m.edge)&&(m.edge=p*(1/0));let g=ni(u.length,C=>{let E=u[C];return this.vertical?E<d||E<=m.edge:E>d||E>=m.edge}),w=g<=0;w&&(g=ni(u.length,C=>this.vertical?u[C]<d:u[C]>d));let v=r[r.length-1].viewNode;if(v?.parentElement.localName==="viv-ts-inner"&&(v=v.parentElement.parentElement),(g===u.length&&v.nextSibling||g>=u.length-1&&v.parentElement.querySelector(".MJXc-display"))&&(a=0),g=Math.min(u.length-a,g),g<l)return null;d=u[g-1];let b;if(w?b=m.checkPoint:b=this.findAcceptableBreakInside(t.checkPoints,d,i),b){let C=this.getAfterEdgeOfBlockContainer(b);!isNaN(C)&&p*(d-C)>0&&(d=C),this.computedBlockSize=p*(d-this.beforeEdge)+f}return b}getAfterEdgeOfBlockContainer(t){let i=t;do i=i.parent;while(i&&i.inline);return i?(i=i.copy().modify(),i.after=!0,Ii(i,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let i=t.findIndex(s=>s.overflow);if(i<0)return{edge:NaN,checkPoint:null};let n=t[i];return{edge:this.calculateEdge(null,t,i,n.boxOffset),checkPoint:n}}findEdgeBreakPosition(t){return this.computedBlockSize=t.computedBlockSize+this.getOffsetByRepetitiveElements(t),t.position}finishBreak(t,i,n){t.formattingContext;let s=new an().find(t.formattingContext).finishBreak(this,t,i,n);return s||(s=pa.finishBreak(this,t,i,n)),s}findAcceptableBreakPosition(){let t=null,i=null,n=0,s=0;do{n=s,s=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!i;--r){t=this.breakPositions[r],i=t.findAcceptableBreak(this,n);let o=t.getMinBreakPenalty();o>n&&(s=Math.min(s,o))}}while(s>n&&!i&&this.forceNonfitting);return{breakPosition:i?t:null,nodeContext:i}}doFinishBreak(t,i,n,s){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!i)return N(t);let r=B("doFinishBreak"),o=!1;if(!t){if(this.forceNonfitting)return H.warn("Could not find any page breaks?!!"),this.skipTailEdges(i).then(a=>{a?(a=a.modify(),a.overflow=!1,this.finishBreak(a,o,!0).then(()=>{r.finish(a)})):r.finish(a)}),r.result();t=n,o=!0,this.computedBlockSize=s}return this.finishBreak(t,o,!0).then(()=>{r.finish(t)}),r.result()}isBreakable(t){for(let i=t;i;i=i.parent)if(Bi(i.viewNode))return!1;if(t.after)return!0;switch(t.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!t.flexContainer}zeroIndent(t){let i=t.toString();return i==""||i=="auto"||!!i.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(t,i){if(!t)return!1;for(let o=t;o;o=o.parent)if(Bi(o.viewNode))return!1;if(Li(t.viewNode))return!1;let n=Ii(t,this.clientLayout,0,this.vertical),s=Ui(t,this.collectElementsOffset()),r=this.isOverflown(n+(this.vertical?-1:1)*s.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*s.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=t;else if(i){let o=n+this.getTrailingMarginEdgeAdjustment(i),a=this.footnoteEdge-this.getBoxDir()*s.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),r}checkOverflowAndSaveEdgeAndBreakPosition(t,i,n,s){if(!t||Li(t.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(t,i);return(n||!r)&&this.saveEdgeBreakPosition(t,s,r),r}applyClearance(t){if(!t.viewNode.parentNode||t.floatReference!==Fe.INLINE)return!1;let i=this.getComputedMargin(t.viewNode),n=t.viewNode.ownerDocument.createElement("div");this.vertical?(n.style.bottom="0px",n.style.width="1px",n.style.marginRight=`${i.right}px`):(n.style.right="0px",n.style.height="1px",n.style.marginTop=`${i.top}px`),t.viewNode.parentNode.insertBefore(n,t.viewNode);let s=Nt(this.clientLayout,n,this.vertical),r=this.getBeforeEdge(s),o=this.getBoxDir(),a=t.clearSide==="same"?t.floatSide:t.clearSide,l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(a)?bl(a,t.vertical,t.direction,this.layoutContext.page.side):a,h=l==="left"||l==="right"?t.direction==="rtl"==(l==="left")?"inline-end":"inline-start":l,u=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this);switch(l){case"left":u=o*Math.max(u*o,this.leftFloatEdge*o);break;case"right":u=o*Math.max(u*o,this.rightFloatEdge*o);break;default:u=o*Math.max(u*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let d=1/(this.clientLayout.pixelRatio||1);if(r*o+d>u*o)return t.viewNode.parentNode.removeChild(n),!1;{let p=Math.max(1,(u-r)*o);this.vertical?n.style.width=`${p}px`:n.style.height=`${p}px`,s=Nt(this.clientLayout,n,this.vertical);let f=this.getAfterEdge(s);if(!t.floatSide)if(this.vertical){let m=f-i.right-u;m>0==i.right>=0&&(m+=i.right),n.style.marginLeft=`${m}px`}else{let m=u-(f+i.top);m>0==i.top>=0&&(m+=i.top),n.style.marginBottom=`${m}px`}return t.clearSpacer=n,!0}}isBFC(t){return!!(qg(t)||wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}skipEdges(t,i,n){var s;let r=t.after?(s=t.parent)==null?void 0:s.formattingContext:t.formattingContext;if(r&&!this.isBFC(r))return N(t);let o=B("skipEdges"),a=!n&&i&&t&&t.after,l=n,h=null,u=[],d=[],p=!1;function f(){return!!n||!i&&tt(l)&&!m()}function m(){var w;if(!h||t.floatSide)return!1;for(let v=h;v!=null&&v.parent;v=v.parent){let b=v.after?v.viewNode:(w=v.viewNode)==null?void 0:w.previousSibling;for(;b&&(He(b,v.parent.whitespace)||Bi(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{t=u[0]||t,t.viewNode.parentNode.removeChild(t.viewNode),this.pageBreakType=l};return o.loopWithFrame(w=>{for(var v;t;){t.formattingContext;let b=new an().find(t.formattingContext);do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(He(t.viewNode,t.whitespace))break;if(!t.after){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)?(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0):(t=t.modify(),t.breakBefore=l),w.breakLoop();return}}if(!t.after){if(t.floatSide&&(this.breakAtTheEdgeBeforeFloat=Ls(l)?l:null),b&&b.startNonInlineElementNode(t))break;if(t.clearSide&&this.applyClearance(t)&&i&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(t.copy(),l,!1),!t.inline&&!t.repeatOnBreak&&(h?Sl(h):this.breakPositions[this.breakPositions.length-1]instanceof fs)&&this.saveEdgeBreakPosition(t.copy(),l,!1),!this.isBFC(t.formattingContext)||wi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t.formattingContext)||this.isFloatNodeContext(t)||t.flexContainer||!t.nodeShadow&&!t.sourceNode.firstElementChild&&He(t.sourceNode.firstChild,t.whitespace)){u.push(t.copy()),l=nt(l,t.breakBefore),f()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)||!this.layoutConstraint.allowLayout(t))&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}}if(t.viewNode.nodeType!=1)break;let E=t.viewNode.style;if(t.after){t.floatSide&&(l=l??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let A=t.sourceNode;if(A.localName==="svg"||A.localName==="math"||A.getAttribute("data-math-typeset")==="true"){p=!1,h=t.copy(),d.push(h),l=nt(null,t.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l);break}if(t.inline||b&&b.afterNonInlineElementNode(t,this.stopAtOverflow))break;if(p){if(f()){g(),w.breakLoop();return}u=[],i=!1,a=!1,l=null}p=!1,h=t.copy(),d.push(h),l=nt(l,t.breakAfter),E&&!(this.zeroIndent(E.paddingBottom)&&this.zeroIndent(E.borderBottomWidth))&&(d=[h])}else{if(u.push(t.copy()),l=nt(l,t.breakBefore),h&&tt(l)&&Gg(h.viewNode,t.viewNode),(t.pageType!=((v=t.parent)==null?void 0:v.pageType)||!tt(l))&&!this.layoutConstraint.allowLayout(t)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l),t=t.modify(),t.overflow=!0,this.stopAtOverflow)){w.breakLoop();return}let A=t.viewNode.localName;if(gi[A]){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}E&&!(this.zeroIndent(E.paddingTop)&&this.zeroIndent(E.borderTopWidth))&&(a=!1,d=[]),p=!0}}while(!1);let C=this.nextInTree(t,a);if(C.isPending()){C.then(E=>{t=E,w.continueLoop()});return}else t=C.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,d,!this.stopAtOverflow,l)?h&&this.stopAtOverflow&&(t=h.modify(),t.overflow=!0):tt(l)&&(this.pageBreakType=l),w.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),o.finish(t)}),o.result()}skipTailEdges(t){let i=t.copy(),n=B("skipEdges"),s=null,r=!1;return n.loopWithFrame(o=>{for(;t;){do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if(He(t.viewNode,t.whitespace))break;if(!t.after){tt(s)&&(this.pageBreakType=s),o.breakLoop();return}}if(!t.after&&(this.isFloatNodeContext(t)||t.flexContainer)){s=nt(s,t.breakBefore),tt(s)&&(this.pageBreakType=s),o.breakLoop();return}if(t.viewNode.nodeType!=1)break;let l=t.viewNode.style;if(t.after){if(r){if(tt(s)){this.pageBreakType=s,o.breakLoop();return}s=null}r=!1,s=nt(s,t.breakAfter)}else{s=nt(s,t.breakBefore);let h=t.viewNode.localName;if(gi[h]){tt(s)&&(this.pageBreakType=s),o.breakLoop();return}if(l&&!(this.zeroIndent(l.paddingTop)&&this.zeroIndent(l.borderTopWidth))){o.breakLoop();return}}r=!0}while(!1);let a=this.layoutContext.nextInTree(t);if(a.isPending()){a.then(l=>{t=l,o.continueLoop()});return}else t=a.get()}i=null,o.breakLoop()}).then(()=>{n.finish(i)}),n.result()}layoutFloatOrFootnote(t){return Vi(t.floatReference)||t.floatSide==="footnote"?this.layoutPageFloat(t):this.layoutFloat(t)}layoutNext(t,i,n){let s=B("layoutNext");return this.skipEdges(t,i,n||null).then(r=>{if(t=r,!t||this.pageBreakType||this.stopByOverflow(t))s.finish(t);else{let o=t.formattingContext;new an().find(o).layout(t,this,i).thenFinish(s)}}),s.result()}clearOverflownViewNodes(t,i){if(t)for(let n=t.parent;t;t=n,n=n?n.parent:null){let s=(n||t).formattingContext;new an().find(s).clearOverflownViewNodes(this,n,t,i),i=!1}}initGeom(){let t=this.element.ownerDocument.createElement("div");t.style.position="absolute",t.style.top=`${this.paddingTop}px`,t.style.right=`${this.paddingRight}px`,t.style.bottom=`${this.paddingBottom}px`,t.style.left=`${this.paddingLeft}px`,this.element.appendChild(t);let i=this.clientLayout.getElementClientRect(t);this.element.removeChild(t);let n=this.originX+this.left+this.getInsetLeft(),s=this.originY+this.top+this.getInsetTop();this.box=new wt(n,s,n+this.width,s+this.height),this.startEdge=i?this.vertical?this.rtl?i.bottom:i.top:this.rtl?i.right:i.left:0,this.endEdge=i?this.vertical?this.rtl?i.top:i.bottom:this.rtl?i.left:i.right:0,this.beforeEdge=i?this.vertical?i.right:i.top:0,this.afterEdge=i?this.vertical?i.left:i.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=tf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],T(this.element,"width",`${this.width}px`),T(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(t,i,n){t.formattingContext;let s=t.copy(),r=new an().find(t.formattingContext),o=this.calculateClonedPaddingBorder(s),a=r.createEdgeBreakPosition(s,i,n,this.computedBlockSize+o);this.breakPositions.push(a)}saveBoxBreakPosition(t){let i=t[0].breakPenalty;if(i){let s=t[0];for(;s.parent&&s.inline;)s=s.parent;i=s.breakPenalty}let n=new fs(t,i);this.breakPositions.push(n)}updateMaxReachedAfterEdge(t){if(!isNaN(t)){let i=this.getBoxDir()*(t-this.beforeEdge);this.computedBlockSize=Math.max(i,this.computedBlockSize)}}layout(t,i,n){if(this.chunkPositions.push(t),t.primary.after&&(this.lastAfterPosition=t.primary),this.stopAtOverflow&&this.overflown)return N(t);if(this.isFullWithPageFloats())return t.primary.after&&t.primary.steps.length===1?N(null):N(t);Wg(this)&&la(this);let s=B("layout");return this.openAllViews(t.primary).then(r=>{let o=null;if(r.viewNode)o=r.copy();else{let l=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",l))};this.layoutContext.addEventListener("nextInTree",l)}let a=new hw(i,n);a.layout(r,this).then(l=>{this.doFinishBreak(l,a.context.overflownNodeContext,o,a.initialComputedBlockSize).then(h=>{let u=null;this.pseudoParent?u=N(null):u=this.doFinishBreakOfFragmentLayoutConstraints(h),u.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){s.finish(null);return}if(!h)s.finish(null);else{this.overflown=!0;let d=new oi(h.toNodePosition());s.finish(d)}})})})}),s.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let i=B("doFinishBreakOfFragmentLayoutConstraints"),n=[].concat(this.fragmentLayoutConstraints);n.sort((r,o)=>r.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let s=0;return i.loop(()=>s<n.length?n[s++].finishBreak(t,this).thenReturn(!0):N(!1)).then(()=>{i.finish(!0)}),i.result()}doLayout(t,i,n){let s=B("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,s.loopWithFrame(o=>{for(;t;){let a=!0;if(this.layoutNext(t,i,n||null).then(l=>{if(i=!1,n=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,t=this.nodeContextOverflowingDueToRepetitiveElements,t.overflow=!0):t=l,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(t&&this.stopByOverflow(t)){r=t;let h=this.findAcceptableBreakPosition();t=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else a?a=!1:o.continueLoop()}),a){a=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{s.finish({nodeContext:t,overflownNodeContext:r})}),s.result()}redoLayout(){let t=this.chunkPositions,i=this.element.lastChild;for(;i!=this.last;){let a=i.previousSibling;this.element===i.parentNode&&this.layoutContext.isPseudoelement(i)||this.element.removeChild(i),i=a}this.killFloats(),this.init();let n=B("redoLayout"),s=0,r=null,o=!0;return n.loopWithFrame(a=>{if(s<t.length){let l=t[s++];this.layout(l,o).then(h=>{o=!1,h?(r=h,a.breakLoop()):a.continueLoop()});return}a.breakLoop()}).then(()=>{n.finish(r)}),n.result()}saveDistanceToBlockEndFloats(){let t=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();t>0&&isFinite(t)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(t-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let t=[];for(let i=this;i;i=i.pseudoParent)i.fragmentLayoutConstraints.forEach(n=>{if(wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}if(Bs.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}si.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(s=>{t.push(s)})});return t}},Sa=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let s=this;this.column.openAllViews=function(r){return Us.prototype.openAllViews.call(this,r).thenAsync(o=>(s.startNodeContexts.push(o.copy()),N(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new Xn(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return ri(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Hs=class{breakTextNode(e,t,i,n,s,r){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let s=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":s+Ml(n)),s){let r=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=r.slice(0,i+1)+s+r.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let s=t.charAt(i);i++;let r=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&Ga(s)&&Ga(r)?Ml(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Hs,"instance");Hs.instance=new Hs;function Ml(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var hw=class extends fa{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new uw(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Kg()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&ec(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown}},uw=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=B("DefaultLayoutMode.doLayout");return ow(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(s=>s.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(s=>{s.postLayout(n,e,t,i)}),n}},cw=class extends Us{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),this.floatSide=e,this.parentContainer=o,c(this,"rootViewNodes",[]),c(this,"floatMargins",[]),c(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),N(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function s(r,o){r.forEach(a=>{let l=Kt(e,a);if(l&&l.charAt(l.length-1)==="%"){let h=parseFloat(l),u=o*h/100;T(e,a,`${u}px`)}})}s(["width","max-width","min-width"],i),s(["height","max-height","min-height"],n),s(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(r=>{Kt(e,r)==="auto"&&T(e,r,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=Kt(t,"height");n!==""&&n!=="auto"&&T(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=Kt(t,"width");n!==""&&n!=="auto"&&T(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=Nt(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},vi=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,c(this,"formattingContextType","RepetitiveElementsOwner"),c(this,"isRoot",!1),c(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||ro.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new dw(e,this.rootSourceNode),ro.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},dw=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,c(this,"headerSourceNode",null),c(this,"footerSourceNode",null),c(this,"headerViewNode",null),c(this,"footerViewNode",null),c(this,"headerNodePosition",null),c(this,"footerNodePosition",null),c(this,"headerHeight",0),c(this,"footerHeight",0),c(this,"isSkipHeader",!1),c(this,"isSkipFooter",!1),c(this,"enableSkippingFooter",!0),c(this,"enableSkippingHeader",!0),c(this,"doneInitialLayout",!1),c(this,"firstContentSourceNode",null),c(this,"lastContentSourceNode",null),c(this,"affectedNodeCache",[]),c(this,"afterLastContentNodeCache",[]),c(this,"allowInsert",!1),c(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=Os(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Os(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=no(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=no(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?N(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?N(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let s=t.viewNode.ownerDocument,r=t.viewNode,o=s.createElement("div");r.appendChild(o);let a=new Sa(n,o,t),l=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new oi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),a.getColumn().pageBreakType=l,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(qi,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(s=>s.nodeContext.sourceNode===e.sourceNode&&s.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let s=i(e);return t.push({nodeContext:e,result:s}),s}}isAfterNodeContextOf(e,t,i){let n=[];for(let s=e;s;s=s.parentNode){if(t.sourceNode===s)return t.after;n.push(s)}for(let s=t.sourceNode;s;s=s.parentNode){let r=n.indexOf(s);if(r>=0)return i?r===0:!1;for(let o=s;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},Fc=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let s=this.formattingContext.getRepetitiveElements();return s&&(i.clientLayout,s.doneInitialLayout||(s.updateHeight(i),s.doneInitialLayout=!0)),n}},Lc=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},pw=class extends Fc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},fw=class extends Lc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Ca(e)),this.processor.doLayout(e,t)}},Ca=class Bc{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=zt(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||Li(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,s){let r=this.getRepetitiveElements();r&&t&&s.stopAtOverflow&&(i==null||r.isAfterLastContent(i))&&r.preventSkippingFooter()}finishBreak(t,i){let n=zt(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return N(!0);let r=this.nodeContext;return yw(n,r,i).thenAsync(()=>vw(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return zt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Bc?zt(this.nodeContext.formattingContext)===zt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},gw=class extends fa{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new pw(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new fw(this.formattingContext,this.processor))}},mw=class extends Sn{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),N(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),N(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return Sn.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?N(!0):Sn.prototype.afterNonInlineElementNode.call(this,e)}},ww=class extends _i{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=zt(e.formattingContext);return n.getRootViewNode(e)?(i&&Oc(e.parent,t),e.belongsTo(n)?_i.prototype.layout.call(this,e,t,i):new gw(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=xw(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=zt(e.formattingContext),n=B("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=zt(e.formattingContext),n=new mw(i,t);return new so(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=zt(e.formattingContext),n=B("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Ac(s,t).then(r=>{let o=r;n.loopWithFrame(a=>{for(;o;){let l=!0;if(t.layoutNext(o,!1).then(h=>{o=h,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():l?l=!1:a.continueLoop()}),l){l=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return _i.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){_i.prototype.clearOverflownViewNodes(e,t,i,n)}};function bw(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof vi&&!i.belongsTo(n)&&t(n,i)}}function Oc(e,t){e&&bw(e.after?e.parent:e,(i,n)=>{si.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Ca(n))})}function yw(e,t,i){let n=e.getRepetitiveElements();if(n){let s=e.getRootNodeContext(t);if(s.viewNode){let r=s.viewNode.firstChild;return n.appendHeaderToFragment(s,r,i)}}return N(!0)}function vw(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let s=e.getRootNodeContext(t);if(s.viewNode)return n.appendFooterToFragment(s,null,i)}return N(!0)}function xw(e){let t=e.formattingContext;return!t||!(t instanceof vi)?null:t}function zt(e){return e instanceof vi,e}var Sw=new ww;Ct("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof vi&&!si.isInstanceOfTableFormattingContext(e)?Sw:null);var _c=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Cw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,c(this,"viewElement"),c(this,"colSpan"),c(this,"rowSpan"),c(this,"height",0),c(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},kw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Ew=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new Sa(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&T(e,"vertical-align","top"),i&&i!=="normal"&&T(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return T(e,"vertical-align",t),i&&i!=="normal"&&T(e,"align-content",i),n}},Nw=class{constructor(e,t){this.viewNode=e,this.side=t}},Pw=class extends Xn{constructor(e,t,i,n){super(e,t,i,n),c(this,"formattingContext"),c(this,"acceptableCellBreakPositions",null),c(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?i:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Tw=class extends ca{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,c(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),s=n.every(r=>!!r.nodeContext)&&n.some((r,o)=>{let a=i[o].pseudoColumn,l=r.nodeContext;return!a.isStartNodeContext(l)&&!a.isLastAfterNodeContext(l)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(r=>r.cellNodeContext.breakPenalty));let s=i.some((r,o)=>r.breakPosition instanceof fs&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((r,o)=>{let a=r.breakPosition.getMinBreakPenalty();s&&r.breakPosition instanceof Xn&&r.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(r.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},$i=class extends vi{constructor(e,t){super(e,t),this.tableSourceNode=t,c(this,"formattingContextType","Table"),c(this,"vertical",!1),c(this,"columnCount",-1),c(this,"tableWidth",0),c(this,"captions",[]),c(this,"colGroups",null),c(this,"colWidths",null),c(this,"inlineBorderSpacing",0),c(this,"rows",[]),c(this,"slots",[]),c(this,"cellFragments",[]),c(this,"lastRowViewNode",null),c(this,"cellBreakPositions",[]),c(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(i=>i.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new _c(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,s=this.getRowSlots(e),r=0;for(;s[r];)r++;for(;e<n;e++){s=this.getRowSlots(e);for(let o=r;o<r+t.colSpan;o++){let a=s[o]=new kw(e,o,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=Nt(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let s=this.slots[i][n];if(s.cell===t)return{rowIndex:s.rowIndex,columnIndex:s.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,s)=>{if(s>=e.rowIndex)return i;let r=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!r||t.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),i),t.push(r)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let s=e[n],r=this.getCellFragmentOfCell(i);!r||s.collected.includes(r)||(this.collectElementsOffsetFromColumn(r.pseudoColumn.getColumn(),s.elements),s.collected.push(r))})}),[new Iw(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(wi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}si.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Iw=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let s=Ui(e,n);i=Math.max(i,t(s))}),i}};function xt(e){return e instanceof $i,e}function Aw(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Rw(e){return e==="table"||e==="inline-table"}function zl(e){return Aw(e)||Rw(e)}function Mc(e,t,i){let n=e.nodeContext,s=n.display,r=n.parent?n.parent.display:null,o=!1;if(r==="inline-table"&&!(n.formattingContext instanceof $i)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof $i){o=a.formattingContext===t;break}}return o||s==="table-row"&&!zl(r)||s==="table-cell"&&r!=="table-row"&&!zl(r)||n.formattingContext instanceof $i&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var Fw=class extends Sn{constructor(e,t){super(),this.formattingContext=e,this.column=t,c(this,"rowIndex",-1),c(this,"columnIndex",0),c(this,"inRow",!1),c(this,"checkPoints",[]),c(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=Mc(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,s=n.display,r=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new Nw(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new _c(this.rowIndex,n.sourceNode)),r.firstContentSourceNode||(r.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,s=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let r=s.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(r[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,N(!0);break;case"table-row":this.inHeaderOrFooter||(t.lastRowViewNode=i.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let r=i.viewNode;t.addCell(this.rowIndex,new Cw(this.rowIndex,this.columnIndex,r)),this.columnIndex++}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!Oi(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},zc=class Dc extends Sn{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,c(this,"inRow",!1),c(this,"currentRowIndex",-1),c(this,"currentColumnIndex",0),c(this,"originalStopAtOverflow"),c(this,"inHeader"),c(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let s=0;s<t.colSpan;s++)n+=i[t.anchorSlot.columnIndex+s];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let s=t.rowIndex,r=t.columnIndex,o=t.colSpan,a=i.viewNode,l=i.verticalAlign;o>1&&(T(a,"box-sizing","border-box"),T(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let u=new Ew(this.column,h,i);return this.formattingContext.addCellFragment(s,r,u),n.primary.steps.length===1&&n.primary.after&&(u.empty=!0),u.pseudoColumn.layout(n,!0).thenReturn(!0)}hasBrokenCellAtSlot(t){let i=this.formattingContext.cellBreakPositions[0];return i?i.cell.anchorSlot.columnIndex===t:!1}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let s=t[n],r=s.cell.rowIndex;if(r<this.currentRowIndex){let o=i[r];o||(o=i[r]=[]),o.push(s),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),s=n.reduce(d=>d+1,0);if(s===0)return N(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=B("layoutRowSpanningCellsFromPreviousFragment"),l=N(!0),h=0,u=[];return n.forEach(d=>{l=l.thenAsync(()=>{let p=_s(d[0].cellNodePosition.steps[1],o.parent);return r.setCurrent(p,!1).thenAsync(()=>{let f=N(!0),m=0;function g(w){for(;m<w;){if(!u.includes(m)){let v=p.viewNode.ownerDocument.createElement("td");T(v,"padding","0"),p.viewNode.appendChild(v)}m++}}return d.forEach(w=>{f=f.thenAsync(()=>{let v=w.cell;g(v.anchorSlot.columnIndex);let b=w.cellNodePosition,C=_s(b.steps[0],p);return C.offsetInNode=b.offsetInNode,C.after=b.after,C.fragmentIndex=b.steps[0].fragmentIndex+1,r.setCurrent(C,!1).thenAsync(()=>{let E=w.breakChunkPosition;for(let A=0;A<v.colSpan;A++)u.push(m+A);return m+=v.colSpan,this.layoutCell(v,C,E).thenAsync(()=>(C.viewNode.rowSpan=v.rowIndex+v.rowSpan-this.currentRowIndex+s-h,N(!0)))})})}),f.thenAsync(()=>(g(i.getColumnCount()),h++,N(!0)))})})}),l.then(()=>{r.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),N(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions[t.columnIndex];if(i&&i.cell.anchorSlot.columnIndex==t.anchorSlot.columnIndex){let n=i.cellNodePosition.steps[0],s=this.column.layoutContext.xmldoc.getElementOffset(n.node);iw(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,N(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=B("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=N(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let l=Os(a,0);return N(new oi(l))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=Mc(t,xt(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,s=this.formattingContext.getRepetitiveElements(),r=n.display;return r==="table-header-group"&&s&&s.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):r==="table-row"?this.startTableRow(t):r==="table-cell"?this.startTableCell(t):N(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let s=new Tw(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),s=i.display;if(s==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):T(i.viewNode,"display","table-row-group"):s==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):T(i.viewNode,"display","table-row-group")),s&&Dc.ignoreList[s])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return N(!0)}};c(zc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Lw=zc,Bn=[];function Bw(e){let t=Bn.findIndex(n=>n.root===e),i=Bn[t];return i?i.tableLayoutOption:null}function Ow(e){let t=Bn.findIndex(i=>i.root===e);t>=0&&Bn.splice(t,1)}var Vc=class{layoutEntireTable(e,t){let i=xt(e.formattingContext),n=new Fw(i,t);return new so(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let l=0;l<t;l++){let h=s.createElement("td");r.appendChild(h),o.push(h)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(l=>{let h=Nt(n,l,i),u=i?h.height:h.width;return Math.ceil(u)});return e.parentNode.removeChild(r),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let s=i.firstElementChild;for(;s;){if(s.localName==="col"){let r=s.span;for(s.removeAttribute("span"),n-=r;r-- >1;){let o=s.cloneNode(!0);i.insertBefore(o,s),t.push(o)}t.push(s)}s=s.nextElementSibling}for(;n-- >0;)s=i.ownerDocument.createElement("col"),i.appendChild(s),t.push(s)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let s=n.ownerDocument.createElement("colgroup");t.push(s);for(let r=e.length;r<i;r++){let o=n.ownerDocument.createElement("col");s.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,s=e.lastRowViewNode;if(!s)return;e.lastRowViewNode=null;let r=s.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=r;return}let a=e.colWidths=this.getColumnWidths(s,o,n,i.clientLayout),l=this.getColGroupElements(t),h=this.normalizeAndGetColElements(l);this.addMissingColElements(h,l,o,t),h.forEach((u,d)=>{T(u,n?"height":"width",`${a[d]}px`)}),l.forEach(u=>{r.appendChild(u.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=xt(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Bw(e.sourceNode);Ow(e.sourceNode);let s=B("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,l=Nt(t.clientLayout,a,t.vertical),h=t.vertical?l.left:l.bottom;if(h+=(t.vertical?-1:1)*Ui(e,t.collectElementsOffset()).current,!t.isOverflown(h)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Dw(r)),s.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),s.finish(null)}),s.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((s,r)=>{s&&(t.insertBefore(s.viewNode,i),s.side==="top"&&(n[r]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),T(t,"table-layout","fixed"),T(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=xt(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Lw(i,t),o=new so(r,t.layoutContext),a=B("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=xt(e.formattingContext),s=n.getRootViewNode(e),r=B("TableFormattingContext.layout"),o;return s?(i&&Oc(e.parent,t),o=new Mw(n,this).layout(e,t)):o=t.buildDeepElementView(e),o.then(a=>{r.finish(a),t.element.hasAttribute("data-vivliostyle-column-height-adjusted")&&(T(t.element,"width",`${t.width}px`),T(t.element,"height",`${t.height}px`),t.element.removeAttribute("data-vivliostyle-column-height-adjusted"))}),r.result()}createEdgeBreakPosition(e,t,i,n){return new Pw(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Tr(e),!1}finishBreak(e,t,i,n){let s=xt(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let r=s.findRowIndexBySourceNode(t.sourceNode);s.cellBreakPositions=[];let o;if(t.after?o=s.getRowSpanningCellsOverflowingTheRow(r):o=s.getCellsFallingOnRow(r),o.length){let a=B("TableLayoutProcessor.finishBreak"),l=0;return a.loopWithFrame(h=>{if(l===o.length){h.breakLoop();return}let u=o[l++],d=s.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,m=f.toNodePosition(),g=new oi(p.toNodePosition());s.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:g,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),r<u.rowIndex+u.rowSpan-1&&(w.rowSpan=r-u.rowIndex+1),d.empty?h.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{_w(d,s,p),h.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Tr(t),s.finishFragment(),a.finish(!0)}),a.result()}}return Tr(t),s.finishFragment(),pa.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){_i.prototype.clearOverflownViewNodes(e,t,i,n)}};function _w(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,l=Nt(r.clientLayout,a,s),h=r.getComputedPaddingBorder(a);if(s){let u=l.right-r.footnoteEdge-n.calculateOffset(i)-h.right;T(o,"max-width",`${u}px`)}else{let u=r.footnoteEdge-n.calculateOffset(i)-l.top-h.top;T(o,"max-height",`${u}px`)}}function Tr(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),m=e.vertical?f.width:f.height;return d+m},0),s=i[i.length-1],r=Array.from(t.children).indexOf(s),o=Array.from(s.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&r+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[r+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let l=a.getBoundingClientRect(),h=e.vertical?l.width:l.height,u=n+h;T(a,e.vertical?"width":"height",`${u}px`)}var Mw=class extends fa{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new zw(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Uw(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},zw=class extends Fc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Dw=class extends Xn{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new Vw(this.position.sourceNode))}},Vw=class Uc{constructor(t){this.tableRootNode=t,c(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,Bn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof Uc&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Uw=class extends Lc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Hw(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Hw=class Hc extends Ca{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||Li(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=xt(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(s=>s.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,s){let r=xt(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,r),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,s)})}),!t){let o=r.getRootViewNode(this.nodeContext);new Vc().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=xt(this.nodeContext.formattingContext),s=B("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,l)=>a.concat(l.constraints.map(h=>({constraint:h,breakPosition:l.breakPosition}))),[]),o=0;return s.loop(()=>{if(o<r.length){let a=r[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{s.finish(!0)}),s.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let s=[];for(let r=0;r<n;r++)i.cellFragments[r]&&i.cellFragments[r].forEach(o=>{o&&s.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return s}getElementsOffsetsForTableCell(t){let i=xt(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Hc?xt(this.nodeContext.formattingContext)===xt(t.nodeContext.formattingContext):!1}},$w=new Vc;function Ww(e,t,i,n,s,r){if(!t)return null;if(i===y.table){let o=e.parent;return new $i(o?o.formattingContext:null,e.sourceNode)}return null}function Gw(e){return e instanceof $i?$w:null}Ct("RESOLVE_FORMATTING_CONTEXT",Ww);Ct("RESOLVE_LAYOUT_PROCESSOR",Gw);function Dl(e){return e.reduce((t,i)=>t+i,0)/e.length}function jw(e){let t=Dl(e);return Dl(e.map(i=>{let n=i-t;return n*n}))}var Xw=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function On(e){return e.vertical?e.width:e.height}function _n(e,t){e.vertical?e.width=t:e.height=t}var $c=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=On(e)}balanceColumns(e){let t=B("ColumnBalancer#balanceColumns");this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(s=>{if(this.savePageFloatLayoutContexts(s),this.layoutContainer.clear(),!s){n.breakLoop();return}i.push(this.createTrialResult(s)),n.continueLoop()})}).then(()=>{let n=i.reduce((s,r)=>r.penalty<s.penalty?r:s,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new Xw(e,t)}preBalance(e){}postBalance(){_n(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},xo=1;function Wc(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,s=Math.max.apply(null,n.map(o=>o.computedBlockSize)),r=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return s>r+xo}function Gc(e,t){var i;let n=e[e.length-1].layoutResult.columns,s=Math.max.apply(null,n.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+xo))-xo;if(s<On(t)?_n(t,s):_n(t,On(t)-1),t.vertical){let r=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=r-t.width}}var qw=class extends $c{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,c(this,"originalPosition",null),c(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);_n(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return Vl(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Wc(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Vl(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):On(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Gc(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,On(this.layoutContainer)+this.originalContainerBlockSize*.1);_n(this.layoutContainer,t)}}};function Vl(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=6;return i.every(s=>t>s.computedBlockSize+n)}var Yw=class extends $c{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return jw(t)}hasNextCandidate(e){return Wc(e)}updateCondition(e){Gc(e,this.layoutContainer)}};function Kw(e,t,i,n,s,r,o){if(t===y.auto)return null;{let a=o.positions.length===0,l=r[r.length-1],h=!!(l&&l.pageBreakType);return a||h?new qw(i,n,s,e):t===y.balance_all?new Yw(i,n,s):(y.balance,null)}}var Zw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Jw=new Set(Zw);function Qw(e){return!(e.toLowerCase()==="none"||Jw.has(e))}var eb=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],tb=new Set(eb),ib=["fixed","extends"],nb=new Set(ib),E0=Symbol();function Yn(e){return e instanceof ae&&e.name.toLowerCase()!=="none"}function jc(e){return e.name}function sb(e){if(e instanceof ae)return tb.has(e.name);if(e instanceof Q&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof ae){let n=t.name;return nb.has(n)&&(n==="fixed"&&i instanceof Re||n==="extends"&&Yn(i))}}return!1}function rb(e){let t=it(e,"system");return t instanceof ae&&t.name==="cyclic"}function ob(e){let t=it(e,"system");if(t instanceof ae&&t.name==="fixed")return!0;if(t instanceof Q&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="fixed"&&n instanceof Re}return!1}function ab(e){let t=it(e,"system");return t instanceof ae?1:t.values[1].num}function lb(e){let t=it(e,"system");return t instanceof ae&&t.name==="alphabetic"}function hb(e){let t=it(e,"system");return t instanceof ae&&t.name==="numeric"}function ub(e){let t=it(e,"system");return t instanceof ae&&t.name==="additive"}function cb(e){let t=it(e,"system");if(t instanceof Q&&t.values.length===2){let[i,n]=t.values;return i instanceof ae&&i.name==="extends"&&Yn(n)}return!1}function db(e){let t=it(e,"system");return jc(t.values[1])}function kt(e){return e instanceof G||e instanceof ae}function Ut(e){return e instanceof G?e.str:e.name}function Xc(e){if(kt(e))return!0;if(e instanceof Q&&e.values.length===2){let t=e.values[0],i=e.values[1];return kt(t)&&kt(i)}return!1}function pb(e){if(kt(e))return{prefix:Ut(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:Ut(t),suffix:Ut(i)}}}function Ul(e){return e instanceof Re||e instanceof ae&&e.name==="infinite"}function $s(e,t){return e instanceof Re?e.num:t?-1/0:1/0}var N0=Symbol();function So(e){if(!(e instanceof Q&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Ul(t)&&Ul(i)))return!1;let n=$s(t,!0),s=$s(i,!1);return!(n>s)}function fb(e){return{lower:$s(e.values[0],!0),upper:$s(e.values[1],!1)}}function qc(e){return e instanceof ae&&e.name==="auto"||So(e)||e instanceof Ke&&e.values.length>=1&&e.values.every(t=>So(t))}function gb(e){return e instanceof ae?null:(So(e)?[e]:e.values).map(t=>fb(t))}var P0=Symbol();function Ws(e){if(!(e instanceof Q&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Re&&t.num>=0&&kt(i)||kt(t)&&i instanceof Re&&i.num>=0}function Gs(e){let[t,i]=e.values;return t instanceof Re?[t.num,Ut(i)]:[i.num,Ut(t)]}function Yc(e){return Ws(e)}function mb(e){let[t,i]=Gs(e);return{minLength:t,symbol:i}}function Kc(e){return kt(e)||e instanceof Q&&e.values.length>=1&&e.values.every(t=>kt(t))}function wb(e){return kt(e)?[Ut(e)]:e.values.map(t=>Ut(t))}var T0=Symbol();function Zc(e){if(Ws(e))return!0;if(e instanceof Ke&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!Ws(i))return!1;let[n]=Gs(i);if(n>=t)return!1;t=n}return!0}return!1}function bb(e){if(Ws(e)){let[t,i]=Gs(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Gs(t);return{weight:i,symbol:n}})}var yb=["auto","bullets","numbers","words","spell-out"],vb=new Set(yb);function xb(e){return e instanceof ae&&vb.has(e.name)||Yn(e)}function Sb(e,t){switch(e){case"system":return sb(t);case"negative":return Xc(t);case"prefix":case"suffix":return kt(t);case"range":return qc(t);case"pad":return Yc(t);case"fallback":return Yn(t);case"symbols":return Kc(t);case"additive-symbols":return Zc(t);case"speak-as":return xb(t);default:return!0}}function it(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function Cb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function Ki(e){let t=e.get("decimal");return t||(t=he.createDecimal(e),e.set("decimal",t)),t}var gs,ms,ws,bs,ys,vs,xs,Ss,Co,ko,Eo,No,Po,To,Io,st,Ir,Jc,Qc,Hl,$l,Ar,Wl,gn,Yt=class di{constructor(t,i){ue(this,st),c(this,"_store"),ue(this,gs),ue(this,ms),ue(this,ws),ue(this,bs),ue(this,ys),ue(this,vs),ue(this,xs),ue(this,Ss),this._store=t;let n=it(i,"negative");mt(this,gs,n&&Xc(n)?pb(n):null);let s=it(i,"prefix");mt(this,ms,s&&kt(s)?Ut(s):null);let r=it(i,"suffix");mt(this,ws,r&&kt(r)?Ut(r):null);let o=it(i,"range");mt(this,bs,o&&qc(o)?gb(o):null);let a=it(i,"pad");mt(this,ys,a&&Yc(a)?mb(a):null);let l=it(i,"fallback");mt(this,vs,l&&Yn(l)?jc(l):null);let h=it(i,"symbols");mt(this,xs,h&&Kc(h)?wb(h):null);let u=it(i,"additive-symbols");mt(this,Ss,u&&Zc(u)?bb(u):null)}static create(t,i){return rb(i)?new ui(t,i):ob(i)?new kb(t,i):lb(i)?new Nb(t,i):hb(i)?new Gl(t,i):ub(i)?new Pb(t,i):cb(i)?new Tb(t,i):new Eb(t,i)}static createDecimal(t){return new Gl(t,X(di,Co))}static createDisc(t){return new ui(t,X(di,ko))}static createSquare(t){return new ui(t,X(di,Eo))}static createCircle(t){return new ui(t,X(di,No))}static createDisclosureOpen(t){return new ui(t,X(di,Po))}static createDisclosureClosed(t){return new ui(t,X(this,To))}static createNone(t){return new ui(t,X(di,Io))}static get CHINESE_LONGHAND_NAMES(){return jl.NAMES}static createChineseLonghand(t,i){return new jl(t,i)}static createEthiopicNumeric(t){return new Ab(t)}_getNegative(){return X(this,gs)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return X(this,ms)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return X(this,ws)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return X(this,bs)}static _getRangeFrom(t){return t._getRange()}_getPad(){return X(this,ys)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(X(this,vs)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return X(this,xs)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return X(this,Ss)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Ee(this,st,gn).call(this,t,new Set)}formatMarker(t){return Ee(this,st,Jc).call(this)+this.format(t)+Ee(this,st,Qc).call(this)}};gs=new WeakMap,ms=new WeakMap,ws=new WeakMap,bs=new WeakMap,ys=new WeakMap,vs=new WeakMap,xs=new WeakMap,Ss=new WeakMap,Co=new WeakMap,ko=new WeakMap,Eo=new WeakMap,No=new WeakMap,Po=new WeakMap,To=new WeakMap,Io=new WeakMap,st=new WeakSet,Ir=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Jc=function(){var e;return(e=this._getPrefix())!=null?e:""},Qc=function(){var e;return(e=this._getSuffix())!=null?e:". "},Hl=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},$l=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},Ar=function(){var e;return(e=this._getFallback())!=null?e:Ki(this._store)},Wl=function(e,t){let{minLength:i,symbol:n}=Ee(this,st,$l).call(this);if(i===0||n==="")return e;let{prefix:s,suffix:r}=Ee(this,st,Ir).call(this),o=t?[...s].length+(r?[...r].length:0):0,a=i-[...e].length-o;if(a<=0)return e;let l=[...n].length,h=Math.ceil(a/l);return n.repeat(h)+e},gn=function(e,t){var i,n,s;if(t.has(this))return Ee(i=Ki(this._store),st,gn).call(i,e,new Set);if(t.add(this),!Cb(e,Ee(this,st,Hl).call(this))){let h=Ee(this,st,Ar).call(this);return Ee(n=h,st,gn).call(n,e,t)}let r=this._usesNegativeSign(e),o=r?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let h=Ee(this,st,Ar).call(this);return Ee(s=h,st,gn).call(s,e,t)}let l=Ee(this,st,Wl).call(this,a,r);if(r){let{prefix:h,suffix:u}=Ee(this,st,Ir).call(this);l=h+l+(u??"")}return l},ue(Yt,Co,{system:new _(F("numeric"),0),symbols:new _(new Q([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)}),ue(Yt,ko,{system:new _(F("cyclic"),0),symbols:new _(new G("\u2022"),0),suffix:new _(new G(" "),0)}),ue(Yt,Eo,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25AA"),0),suffix:new _(new G(" "),0)}),ue(Yt,No,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25E6"),0),suffix:new _(new G(" "),0)}),ue(Yt,Po,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25BE"),0),suffix:new _(new G(" "),0)}),ue(Yt,To,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25B8"),0),suffix:new _(new G(" "),0)}),ue(Yt,Io,{system:new _(F("cyclic"),0),symbols:new _(new G(""),0),suffix:new _(new G(""),0)});var he=Yt,ui=class extends he{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},Cs,kb=class extends he{constructor(e,t){super(e,t),ue(this,Cs),mt(this,Cs,ab(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-X(this,Cs);return(t=i[n])!=null?t:null}};Cs=new WeakMap;var Eb=class extends he{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],s=Math.ceil(e/i);return n.repeat(s)}},Nb=class extends he{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",s=e;for(;s!==0;)s=s-1,n=t[s%i]+n,s=Math.floor(s/i);return n}},Gl=class extends he{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",s=e;for(;s!==0;)n=t[s%i]+n,s=Math.floor(s/i);return n}},Pb=class extends he{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let s=t.find(r=>r.weight===0);return s?s.symbol:null}let n=e;for(let s of t){let{weight:r,symbol:o}=s;if(r===0||r>n)continue;let a=Math.floor(n/r);if(i+=o.repeat(a),n-=r*a,n===0)return i}return null}},Nn,ut,gt,ed=class extends he{constructor(t,i){super(t,i),ue(this,ut),ue(this,Nn);let n=db(i),s=n.toLowerCase();s==="disc"||s==="circle"||s==="square"||s==="disclosure-open"||s==="disclosure-closed"?mt(this,Nn,s):mt(this,Nn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:he._getNegativeFrom(Ee(this,ut,gt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:he._getPrefixFrom(Ee(this,ut,gt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:he._getSuffixFrom(Ee(this,ut,gt).call(this))}_getAutoRange(){return he._getAutoRangeFrom(Ee(this,ut,gt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:he._getRangeFrom(Ee(this,ut,gt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:he._getPadFrom(Ee(this,ut,gt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:he._getFallbackFrom(Ee(this,ut,gt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:he._getSymbolsFrom(Ee(this,ut,gt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:he._getAdditiveSymbolsFrom(Ee(this,ut,gt).call(this))}_usesNegativeSign(t){return he._useNegativeSignFrom(Ee(this,ut,gt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:he._generateInitialRepresentationFrom(Ee(this,ut,gt).call(this),t)}};Nn=new WeakMap,ut=new WeakSet,gt=function(e=new Set){var t;if(e.has(this))return Ki(this._store);e.add(this);let i=this._store.get(X(this,Nn));return i?i instanceof ed?Ee(t=i,ut,gt).call(t,e):i:Ki(this._store)};var Tb=ed,Ib=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Rr,Fr,as,Lr,Ao,ks,bt=class td extends he{constructor(t,i){let{chars:n,descriptors:s}=X(td,Ao).get(i);super(t,s),ue(this,ks),mt(this,ks,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=X(this,ks);if(t===0)return i.digits[0];let n=[],s=0,r=t;for(;r>0;)n.unshift({digit:r%10,position:s}),r=Math.floor(r/10),s++;let o=i.informal&&t>=10&&t<=19,a="",l=!1;for(let h=0;h<n.length;h++){let{digit:u,position:d}=n[h],p=h===n.length-1;u===0?!p&&!l&&(l=!0):(l&&(a+=i.digits[0],l=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};Rr=new WeakMap,Fr=new WeakMap,as=new WeakMap,Lr=new WeakMap,Ao=new WeakMap,ks=new WeakMap,ue(bt,Rr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new G("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new Q([new Re(-9999),new Re(9999)]),0),negative:new _(new G("\u8D1F"),0)}}),ue(bt,Fr,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new G("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new Q([new Re(-9999),new Re(9999)]),0),negative:new _(new G("\u8D1F"),0)}}),ue(bt,as,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new G("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new Q([new Re(-9999),new Re(9999)]),0),negative:new _(new G("\u8CA0"),0)}}),ue(bt,Lr,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new G("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new Q([new Re(-9999),new Re(9999)]),0),negative:new _(new G("\u8CA0"),0)}}),c(bt,"NAMES",new Set(Ib)),ue(bt,Ao,new Map([["simp-chinese-informal",X(bt,Rr)],["simp-chinese-formal",X(bt,Fr)],["trad-chinese-informal",X(bt,as)],["trad-chinese-formal",X(bt,Lr)],["cjk-ideographic",X(bt,as)]]));var jl=bt,Ro,Fo,js,Lo,Bo,Ai=class pi extends he{constructor(t){super(t,X(pi,Ro))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return X(pi,js)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let s=i.length,r="";for(let o=s-1;o>=0;o--){let a=i[o],l=o%2===1,h=o===s-1;if(!(a===0||h&&a===1||l&&a===1)){let u=Math.floor(a/10),d=a%10;r+=X(pi,Fo)[u]+X(pi,js)[d]}l?a!==0&&(r+=X(pi,Lo)):o!==0&&(r+=X(pi,Bo))}return r}};Ro=new WeakMap,Fo=new WeakMap,js=new WeakMap,Lo=new WeakMap,Bo=new WeakMap,ue(Ai,Ro,{range:new _(new Q([new Re(1),F("infinite")]),0),suffix:new _(new G("/ "),0)}),ue(Ai,Fo,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ue(Ai,js,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ue(Ai,Lo,"\u137B"),ue(Ai,Bo,"\u137C");var Ab=Ai,Ce,Rb=class{constructor(){ue(this,Ce),mt(this,Ce,new Map),X(this,Ce).set("none",he.createNone(X(this,Ce))),X(this,Ce).set("decimal",he.createDecimal(X(this,Ce))),X(this,Ce).set("disc",he.createDisc(X(this,Ce))),X(this,Ce).set("square",he.createSquare(X(this,Ce))),X(this,Ce).set("circle",he.createCircle(X(this,Ce))),X(this,Ce).set("disclosure-open",he.createDisclosureOpen(X(this,Ce))),X(this,Ce).set("disclosure-closed",he.createDisclosureClosed(X(this,Ce)));for(let e of he.CHINESE_LONGHAND_NAMES)X(this,Ce).set(e,he.createChineseLonghand(X(this,Ce),e));X(this,Ce).set("ethiopic-numeric",he.createEthiopicNumeric(X(this,Ce)))}define(e,t){if(!Qw(e))return null;let i=he.create(X(this,Ce),t);return X(this,Ce).set(e,i),i}getStyle(e){var t;return(t=X(this,Ce).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:Ki(X(this,Ce))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:Ki(X(this,Ce))).formatMarker(t)}};Ce=new WeakMap;var Br=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Fb=class{constructor(){c(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new Br(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new Br(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Br(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ni(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ni(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},Lb=class Oo{constructor(t,i,n,s,r,o,a,l){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=l,c(this,"flowName"),c(this,"isBlockValue",null),c(this,"hasBoxValue",null),c(this,"styleValues",{}),c(this,"beforeBox",null),c(this,"afterBox",null),c(this,"breakBefore",null),this.flowName=r.flowName,this.hasBox()){let h=i._pseudos;if(h&&h.before){let u=new Oo(t,h.before,n,!1,r,this.isBlock(),a,!0),d=u.styleValue("content");Ot(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=nt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&tt(this.breakBefore)&&(r.breakBefore=nt(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new Oo(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Ot(o)&&(this.afterBox=r)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",y.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Yu(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!to(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},Bb=class{constructor(e){this.context=e,c(this,"stack",[]),c(this,"atBlockStart",!0),c(this,"atFlowStart",!0),c(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==y.none)}push(e,t,i,n){let s=this.lastBox();n&&s&&n.flowName!==s.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let r=n||s.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),l=new Lb(this.context,e,t,i,r,o||this.atBlockStart,o,a);return this.stack.push(l),this.atBlockStart=l.hasBox()?!l.beforeBox&&l.isBlock():this.atBlockStart,this.atFlowStart=l.hasBox()?!l.beforeBox&&o:this.atFlowStart,l}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",y.normal).toString(),n=Mu(i);n&&!He(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=nt(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},Xl=class{constructor(e,t,i,n,s,r,o,a,l){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,this.counterListener=o,c(this,"root"),c(this,"cascadeHolder"),c(this,"last"),c(this,"rootStyle",{}),c(this,"styleMap",{}),c(this,"flows",{}),c(this,"flowChunks",[]),c(this,"flowListener",null),c(this,"flowToReach",null),c(this,"idToReach",null),c(this,"cascade"),c(this,"offsetMap"),c(this,"primary",!0),c(this,"primaryStack",[]),c(this,"rootBackgroundAssigned",!1),c(this,"rootLayoutAssigned",!1),c(this,"lastOffset"),c(this,"breakBeforeValues",{}),c(this,"boxStack"),c(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang,l),this.offsetMap=new Fb;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new Bb(n),this.offsetMap.addStuckRange(h);let u=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,u,h),this.postprocessTopStyle(u,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${h}`]=u,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let s=t[i];s&&(this.rootStyle[i]=new _(s,Cu))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)Cn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,s=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!K(n)||s&&!K(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<ql.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,ql[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!K(n.value)){let a=n.evaluate(this.context);if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=this.context.initialFontSize;break;case"%":l*=this.context.initialFontSize/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*Pt.lh/Pt.em;break;default:{let h=Pt[a.unit];h&&(l*=h),s=!1}}this.context.rootFontSize=l,this.context.isRelativeRootFontSize=s}}let r=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!K(o.value)){let a=o.evaluate(this.context);if(a instanceof Ht)this.context.rootLineHeight=a.num*r;else if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=r;break;case"%":l*=r/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let h=Pt[a.unit];h&&(l*=h)}}this.context.rootLineHeight=l}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return qm(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let r=this.getStyle(this.root,!1),o=_e(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",l=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,l)}let n=this.xmldoc.getNodeByOffset(e),s=this.xmldoc.getNodeOffset(n,0,!1);if(!(s>=this.lastOffset))for(;;){if(n.nodeType!=1)s+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),l=a["flow-into"];if(l){let h=l.evaluate(t,"flow-into").toString();this.encounteredFlowElement(h,a,o,s)}s++}if(s>=this.lastOffset)break;let r=n.firstChild;if(r==null){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n===this.root)return}n=r}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let s=0,r=Number.POSITIVE_INFINITY,o=!1,a=!1,l=!1,h=t["flow-options"];if(h){let g=lf(h.evaluate(this.context,"flow-options"));o=!!g.exclusive,a=!!g.static,l=!!g.last}let u=t["flow-linger"];u&&(r=ul(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(s=ul(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let g=this.boxStack.lastFlowName();f=this.flows[e]=new Cg(e,g)}let m=new kg(e,i,n,s,r,o,a,l,p);return this.flowChunks.push(m),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,f),m}registerForcedBreakOffset(e,t,i){if(tt(e)){let s=this.flows[i].forcedBreakOffsets;(s.length===0||s[s.length-1]<t)&&s.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=nt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let s=this.context;for(;;){let r=this.last.firstChild;if(r==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let l=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(l,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=nt(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(r=this.last.nextSibling,r)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=r,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset);let l=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");l&&l===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let h,u=a["flow-into"];if(u){let p=u.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(p,a,o,this.lastOffset);this.primary=!!this.primaryFlows[p],h=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else h=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(h.breakBefore=nt(h.flowChunk.breakBefore,h.breakBefore));let d=this.boxStack.nearestBlockStartOffset(h);if(d===0){let p=a.page,f=p&&!K(p.value)&&p.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(h.breakBefore,d,h.flowName),h.beforeBox){let p=h.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,h.beforeBox.atBlockStart?d:h.offset,h.flowName)}if(this.primary&&h.displayValue()===y.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},ql=["column-count","column-width","column-fill"],zi=class{constructor(e){this.validator=e,c(this,"success",null),c(this,"failure",null),c(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},ci=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},hn=class id{constructor(){c(this,"nodes",[]),c(this,"connections",[]),c(this,"match",[]),c(this,"nomatch",[]),c(this,"error",[]),c(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new id;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new zi(n.validator);s.code=n.code,t.nodes.push(s)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],s=new ci(n.where,n.success);s.what=n.what,t.connections.push(s)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let s=this.nodes.length,r=new zi(Yl);n>=0?i?r.markAsStartAlternate(n):r.markAsEndAlternate(n):i?r.markAsStartGroup():r.markAsEndGroup(),this.nodes.push(r),this.connect(t,s);let o=new ci(s,!0),a=new ci(s,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new zi(Yl);i.markAsStartAlternate(t),this.nodes.push(i);let n=new ci(0,!0),s=new ci(0,!1);this.nomatch.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new zi(t));let n=new ci(i,!0),s=new ci(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(s),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof Le}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let r=0;r<t.nodes.length;r++)this.nodes.push(t.nodes[r]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let s=this.connections.length;for(let r=0;r<t.connections.length;r++){let o=t.connections[r];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let r=0;r<t.match.length;r++)this.match.push(t.match[r]+s);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let r=0;r<t.nomatch.length;r++)this.match.push(t.nomatch[r]+s);else if(this.emptyHead){for(let r=0;r<t.nomatch.length;r++)this.nomatch.push(t.nomatch[r]+s);this.emptyHead=t.emptyHead}else for(let r=0;r<t.nomatch.length;r++)this.error.push(t.nomatch[r]+s);for(let r=0;r<t.error.length;r++)this.error.push(t.error[r]+s);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let s of this.connections)s.success?this.nodes[s.where].success=this.nodes[s.what]:this.nodes[s.where].failure=this.nodes[s.what];for(let s=0;s<n;s++)if(this.nodes[s].failure==null||this.nodes[s].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},Ob=1,nd=2,sd=4,fi=8,Es=16,_o=32,Ns=64,rd=128,mn=256,wn=512,Mo=1024,od=2048,ad=4096,ld=8192,hd=class extends Xt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Le=class ud extends hd{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Ob?t:null}visitSlash(t){return this.allowed&od?t:null}visitStr(t){return this.allowed&nd?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&sd||this.allowed&Ns&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&wn)?t.unit=="%"&&this.allowed&Mo?t:null:t.num<0&&!(this.allowed&mn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&wn?t:null:t.num<=0&&!(this.allowed&mn)?null:this.allowed&Es?t:null}visitInt(t){return t.num==0?this.allowed&wn?t:null:t.num<=0&&!(this.allowed&mn)?null:this.allowed&(_o|Es)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Ns&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&rd?t:null}visitURange(t){return this.allowed&ad?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&Ns&&CSS.supports("color",t.toString())||this.allowed&ld&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(fi|Es|_o|mn|wn|Mo)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let s in this.idents)i[s]=this.idents[s];for(let s in t.idents)i[s]=t.idents[s];for(let s in this.units)n[s]=this.units[s];for(let s in t.units)n[s]=t.units[s];return new ud(this.allowed|t.allowed,i,n)}},re={},Yl=new Le(0,re,re),ka=class extends hd{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new zi(null),this.failureTerminal=new zi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,s=this.first,r=i,o=null,a=null;for(;s!==this.successTerminal&&s!==this.failureTerminal;){if(r>=e.length){s=s.failure;continue}let l=e[r],h=l;if(s.isSpecial()){let u=!0;s.isStartGroup()?(o?o.push(a):o=[a],a=[]):s.isEndGroup()?o.length>0?a=o.pop():a=null:s.isEndAlternate()?a[s.getAlternate()]="taken":u=a[s.getAlternate()]==null,s=u?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof Pn&&this instanceof Pn){if(h=new Q(e).visit(s.validator),h){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof Ea&&this instanceof Pn){if(h=new Ke(e).visit(s.validator),h){r=e.length,s=s.success;continue}}else h=l.visit(s.validator);if(!h){s=s.failure;continue}if(h!==l&&e===n){n=[];for(let u=0;u<r;u++)n[u]=e[u]}e!==n&&(n[r-i]=h),r++,s=s.success}}return s===this.successTerminal&&(t?n.length>0:r==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Pn=class extends ka{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Q(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Ea){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new Ke(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Ea=class extends ka{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Ke(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},_b=class extends ka{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new en(e.name,t):null}},cd=class{tryParse(e,t,i){return t}success(e,t){}},dd=class extends cd{constructor(e,t){super(),this.name=t,c(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let s=n.length,r=s>1?new Q(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},Mb=class extends dd{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},zb=class extends cd{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Zs){if(++t==e.length)return n}else return n;let s=this.nodes[0].tryParse(e,t,i);if(s==t)return n;t=s;for(let r=1;r<this.nodes.length&&t<e.length&&(s=this.nodes[r].tryParse(e,t,i),s!=t);r++)t=s;return t}},Na=class extends Xt{constructor(){super(...arguments),c(this,"syntax",null),c(this,"propList",null),c(this,"error",!1),c(this,"values",{}),c(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new dd(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let s of this.propList)t.simpleProperty(s,(n=(i=this.values[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:y.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},rn=class extends Na{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},pd=class extends Na{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new Mb(this.validatorSet,this.propList)}},Db=class extends Na{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Zs){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let s;if(t+1<e.length)for(s=t+i+1;s>=e.length;)s=s-(s==t+2?1:2);else s=n;let r=[e[n],e[s]];if(this.syntax[i].tryParse(r,0,this)!=2)return this.error=!0,0}return e.length}},Vb=class extends rn{constructor(){super()}mergeIn(e,t){var i,n;for(let s of this.propList){let r=(n=(i=t[s])!=null?i:this.validatorSet.defaultValues[s])!=null?n:y.initial,o=e[s];o||(o=[],e[s]=o),o.push(r)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof Ke?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new Ke(t[i]);return null}},Ub=class extends rn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let s=this.validatorSet.validators;if(!e[t].visit(s["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===Zs){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(s["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let r=t==e.length-1?e[t]:new Q(e.slice(t,e.length));return r.visit(s["font-family"])?(this.values["font-family"]=r,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new Ke(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},Hb=class extends rn{validateList(e){if(e.length===1&&e[0]instanceof ae)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[y.auto,y.auto];break;case"none":e=[F("no-autospace"),F("space-all")];break}return super.validateList(e)}},$b=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],Wb=class extends rn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)$b.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Kl={SIMPLE:rn,INSETS:pd,INSETS_SLASH:Db,COMMA:Vb,FONT:Ub,TEXT_SPACING:Hb,ALL:Wb},Gb=["initial-letter"],jb=class{constructor(){c(this,"validators",{}),c(this,"prefixes",{}),c(this,"defaultValues",{}),c(this,"namedValidators",{}),c(this,"systemFonts",{}),c(this,"shorthands",{}),c(this,"layoutProps",{}),c(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new I(t.num,t.text);else if(t.type==7)i=new tu(t.text);else if(t.type==1)i=F(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new hn;if(e=="||"){for(let s=0;s<t.length;s++){let r=new hn;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new hn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let s=0;s<t.length;s++)i.addGroup(t[s],s==0?1:n);return i}}addCounts(e,t,i){let n=new hn;for(let s=0;s<t;s++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let s=t;s<i;s++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new hn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Ea(t);break;case"SPACE":i=new Pn(t);break;default:i=new _b(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Le(Ns,re,re)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Le(ld,re,re)),this.namedValidators.POS_INT=this.primitive(new Le(_o,re,re)),this.namedValidators.POS_NUM=this.primitive(new Le(Es,re,re)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Le(fi,re,{"%":j})),this.namedValidators.NEGATIVE=this.primitive(new Le(mn,re,re)),this.namedValidators.ZERO=this.primitive(new Le(wn,re,re)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Le(Mo,re,re)),this.namedValidators.POS_LENGTH=this.primitive(new Le(fi,re,{em:j,ex:j,ch:j,rem:j,lh:j,rlh:j,vw:j,vh:j,vi:j,vb:j,vmin:j,vmax:j,pvw:j,pvh:j,pvi:j,pvb:j,pvmin:j,pvmax:j,cm:j,mm:j,in:j,px:j,pt:j,pc:j,q:j})),this.namedValidators.POS_ANGLE=this.primitive(new Le(fi,re,{deg:j,grad:j,rad:j,turn:j})),this.namedValidators.POS_TIME=this.primitive(new Le(fi,re,{s:j,ms:j})),this.namedValidators.FREQUENCY=this.primitive(new Le(fi,re,{Hz:j,kHz:j})),this.namedValidators.RESOLUTION=this.primitive(new Le(fi,re,{dpi:j,dpcm:j,dppx:j})),this.namedValidators.URI=this.primitive(new Le(rd,re,re)),this.namedValidators.URANGE=this.primitive(new Le(ad,re,re)),this.namedValidators.IDENT=this.primitive(new Le(sd,re,re)),this.namedValidators.STRING=this.primitive(new Le(nd,re,re)),this.namedValidators.SLASH=this.primitive(new Le(od,re,re));let e={"font-family":F("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let s=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(s)||(this.prefixes[s]=n)}else if(e.token().type!=18)throw new Error("':' expected");return s}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],s="",r,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(s,i)},l=u=>{if(o)throw new Error(`'${u}': unexpected`);if(s&&s!=u)throw new Error(`mixed operators: '${u}' and '${s}'`);s=u,o=!0},h=null;for(;!h;){e.consume();let u=e.token();switch(u.type){case 1:if(o||l(" "),this.isBuiltIn(u.text)){let d=this.namedValidators[u.text];if(!d)throw new Error(`'${u.text}' unexpected`);i.push(d.clone())}else{let d={};d[u.text.toLowerCase()]=F(u.text),i.push(this.primitive(new Le(0,d,re)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Re(u.num),i.push(this.primitive(new Le(0,d,re))),o=!1;break}case 34:l("|");break;case 25:l("||");break;case 14:o||l(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||l(" "),n.push({vals:i,op:s,b:"(",fn:u.text}),s="",i=[],o=!0;break;case 15:{r=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(r),s=d.op,o=!1;break}case 11:{r=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,r)),s=d.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let d=u.num,p=d;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(h=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=h:h.isSimple()?this.validators[t]=h.nodes[0].validator:this.validators[t]=new Pn(h)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(F(n.text));break;case 4:i.push(new Ht(n.num));break;case 5:i.push(new Re(n.num));break;case 3:i.push(new I(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new Q(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Kl[i.text]?(n=new Kl[i.text],e.consume()):n=new rn,n.setOwner(this);let s=!1,r=[],o=!1,a=[],l=[];for(;!s;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])r.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||l.push(i.text);else if(this.shorthands[i.text]instanceof pd){let h=this.shorthands[i.text];r.push(h.createSyntaxNode()),l.push(...h.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(r.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:r}),r=[],o=!1;break;case 15:{let h=new zb(r,o),u=a.pop();r=u.syntax,o=u.slash,r.push(h);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,l),this.shorthands[t]=n}}parse(e){let t=new At(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let s=this.shorthands[n],r=s?s.propList:[n];for(let o of r)i[o]=(t=this.defaultValues[o])!=null?t:y.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let s=n.ruleType;if($t(e)||s==="font-face"||qb(t)){n.simpleProperty(e,t,i);return}if(s==="counter-style"){Sb(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let r="",o=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(r=a[1],e=a[2]);let l=this.prefixes[e];if(!l||!l[r]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):r&&!Th.includes(`-${r}-`)||n.unknownProperty(o,t);return}else if(Gb.includes(e)&&!Object.keys(l).some(u=>us(u?`-${u}-`:"",e))){n.unknownProperty(o,t);return}let h=this.validators[e];if(h){let u=K(t)||t.isExpr()?t:t.visit(h);u?n.simpleProperty(e,u,i):!r&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(o,t)}else{let u=this.shorthands[e].clone();K(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function fd(){let e=new jb;return e.initBuiltInValidators(),e.parse(gu),e}var Xb=class extends Xt{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function qb(e){let t=new Xb;return e.visit(t),t.varFound}var A0=`OTTO${new Date().valueOf()}`;function Pa(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Yb(e){let t=new ii;for(let i of Pa(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Kb(e,t){let i={};for(let n in e)i[n]=_e(e,n).evaluate(t,n);return i}var gd=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=Yb(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new ii;i.append(`@font-face {
|
|
1794
|
+
}`;function ys(e,t,i){let n=O("fetchFromURL"),r={method:i||"GET",mode:"cors"},s=n.suspend(),o={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};return fetch(e,r).then(a=>{var l;return o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(l=a.headers.get("Content-Type"))==null?void 0:l.replace(/;.*$/,"").toLowerCase(),a.ok?t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(h=>new TextDecoder("Shift_JIS").decode(h))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text()):a.text()}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=Xu([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{$.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function Xu(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function bg(e){let t=O("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function vg(e){return URL.createObjectURL(e)}var ya=class{constructor(e,t){this.parser=e,this.type=t,c(this,"resources",{}),c(this,"fetchers",{})}load(e,t,i){e=Wt(e);let n=this.resources[e];return typeof n<"u"?N(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=O("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let s=Pe("user-agent.xml",ni),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(Hu)}`),ys(e,this.type).then(a=>{if(a.status>=400&&t)throw new Error((i||`Failed to fetch required resource: ${e}`)+` (${a.status}${a.statusText?" "+a.statusText:""})`);r?(e+="?viv-toc-box",a.url+="?viv-toc-box"):o&&(a.url=e=s),this.parser(a,this).then(l=>{delete this.fetchers[e],this.resources[e]=l,n.finish(l)})}),n.result()}fetch(e,t,i){if(e=Wt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new or(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Wt(e)]}delete(e){delete this.resources[Wt(e)]}};function xg(e,t){let i=e.responseText;return N(i?ha(i):null)}function Sg(){return new ya(xg,"text")}function Hi(e,t,i){let n=new or(()=>{let r=O("loadElement"),s=r.suspend(e),o=!1,a=null,l=h=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(h?h.type:"timeout"))};if(e.addEventListener("load",l,!1),e.addEventListener("error",l,!1),e.addEventListener("abort",l,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(l,300);else if(e.localName==="script")a=setTimeout(l,3e3);else if(t)if(e.localName==="img"){let h=e;h.loading==="lazy"&&(h.loading="eager"),h.src=t,i&&(h.alt=i),h.complete?setTimeout(()=>l(new Event("load")),0):a=setTimeout(l,3e4)}else e.src=t,i&&(e.alt=i);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Fl=0,Cg=16777216,qu=33554432,Yu=50331648,Ku=67108864,kg=83886080,Eg=100663296,ba=class{constructor(e){this.scope=e,c(this,"flavor"),this.flavor="Author"}getCurrentToken(){return null}getScope(){return this.scope}error(e,t){}startStylesheet(e){this.flavor=e}tagSelector(e,t){}classSelector(e){}pseudoclassSelector(e,t){}pseudoelementSelector(e,t){}idSelector(e){}attributeSelector(e,t,i,n){}descendantSelector(){}childSelector(){}adjacentSiblingSelector(){}followingSiblingSelector(){}nextSelector(){}startSelectorRule(){}startFontFaceRule(){}startCounterStyleRule(e){}startFootnoteRule(e){}startViewportRule(){}startDefineRule(){}startRegionRule(){}startPageRule(){}startPageMarginBoxRule(e){}startWhenRule(e){}startMediaRule(e){this.startWhenRule(e)}startFlowRule(e){}startPageTemplateRule(){}startPageMasterRule(e,t,i){}startPartitionRule(e,t,i){}startPartitionGroupRule(e,t,i){}startRuleBody(){}property(e,t,i){}endRule(){}startFuncWithSelector(e,t){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Fl;case"User":return Eg;default:return kg}}getBaseSpecificity(){switch(this.flavor){case"UA":return Fl;case"User":return Cg;default:return qu}}},Ng=class extends ba{constructor(){super(null),c(this,"stack",[]),c(this,"tokenizer",null),c(this,"slave",null)}pushHandler(e){this.stack.push(this.slave),this.slave=e}popHandler(){this.slave=this.stack.pop()}getCurrentToken(){return this.tokenizer?this.tokenizer.token():null}getScope(){return this.slave.getScope()}error(e,t){this.slave.error(e,t)}errorMsg(e,t){var i;$.warn(e,(i=t?.toString())!=null?i:"")}startStylesheet(e){super.startStylesheet(e),this.stack.length>0&&(this.slave=this.stack[0],this.stack=[]),this.slave.startStylesheet(e)}tagSelector(e,t){this.slave.tagSelector(e,t)}classSelector(e){this.slave.classSelector(e)}pseudoclassSelector(e,t){this.slave.pseudoclassSelector(e,t)}pseudoelementSelector(e,t){this.slave.pseudoelementSelector(e,t)}idSelector(e){this.slave.idSelector(e)}attributeSelector(e,t,i,n){this.slave.attributeSelector(e,t,i,n)}descendantSelector(){this.slave.descendantSelector()}childSelector(){this.slave.childSelector()}adjacentSiblingSelector(){this.slave.adjacentSiblingSelector()}followingSiblingSelector(){this.slave.followingSiblingSelector()}nextSelector(){this.slave.nextSelector()}startSelectorRule(){this.slave.startSelectorRule()}startFontFaceRule(){this.slave.startFontFaceRule()}startCounterStyleRule(e){this.slave.startCounterStyleRule(e)}startFootnoteRule(e){this.slave.startFootnoteRule(e)}startViewportRule(){this.slave.startViewportRule()}startDefineRule(){this.slave.startDefineRule()}startRegionRule(){this.slave.startRegionRule()}startPageRule(){this.slave.startPageRule()}startPageMarginBoxRule(e){this.slave.startPageMarginBoxRule(e)}startWhenRule(e){this.slave.startWhenRule(e)}startFlowRule(e){this.slave.startFlowRule(e)}startPageTemplateRule(){this.slave.startPageTemplateRule()}startPageMasterRule(e,t,i){this.slave.startPageMasterRule(e,t,i)}startPartitionRule(e,t,i){this.slave.startPartitionRule(e,t,i)}startPartitionGroupRule(e,t,i){this.slave.startPartitionGroupRule(e,t,i)}startRuleBody(){this.slave.startRuleBody()}property(e,t,i){this.slave.property(e,t,i)}endRule(){this.slave.endRule()}startFuncWithSelector(e,t){this.slave.startFuncWithSelector(e,t)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},Ll=class extends ba{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,c(this,"depth",0),t&&(this.flavor=t.flavor)}getCurrentToken(){var e;return(e=this.owner)==null?void 0:e.getCurrentToken()}error(e,t){var i;(i=this.owner)==null||i.errorMsg(e,t)}startRuleBody(){this.depth++}endRule(){--this.depth==0&&!this.topLevel&&this.owner.popHandler()}},ar=class extends Ll{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Ll(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}startCounterStyleRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_COUNTER_STYLE")}startFootnoteRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FOOTNOTE")}startViewportRule(){this.reportAndSkip("E_CSS_UNEXPECTED_VIEWPORT")}startDefineRule(){this.reportAndSkip("E_CSS_UNEXPECTED_DEFINE")}startRegionRule(){this.reportAndSkip("E_CSS_UNEXPECTED_REGION")}startPageRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE")}startWhenRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_WHEN")}startFlowRule(e){this.reportAndSkip("E_CSS_UNEXPECTED_FLOW")}startPageTemplateRule(){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_TEMPLATE")}startPageMasterRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PAGE_MASTER")}startPartitionRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION")}startPartitionGroupRule(e,t,i){this.reportAndSkip("E_CSS_UNEXPECTED_PARTITION_GROUP")}startFuncWithSelector(e,t){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR_FUNC")}endFuncWithSelector(){this.reportAndSkip("E_CSS_UNEXPECTED_END_SELECTOR_FUNC")}property(e,t,i){this.error("E_CSS_UNEXPECTED_PROPERTY",this.getCurrentToken())}},Ae=[],Zr=[],me=[],Ne=[],St=[],at=[],Ie=[],Ue=[],ge=[],je=[],tt=[],He=[],Te=[],Ui=55,$i=56,br=57;Ae[1]=28,Ae[36]=29,Ae[7]=29,Ae[9]=29,Ae[14]=29,Ae[18]=29,Ae[50]=29,Ae[20]=30,Ae[13]=27,Ae[0]=200,Zr[1]=46,Zr[0]=200,at[1]=2,at[36]=4,at[7]=6,at[9]=8,at[14]=10,at[18]=14,at[50]=42,me[37]=11,me[23]=12,me[35]=56,me[1]=1,me[36]=3,me[7]=5,me[9]=7,me[14]=9,me[12]=13,me[18]=55,me[50]=58,me[16]=41,Ne[37]=11,Ne[23]=12,Ne[35]=56,Ne[1]=1,Ne[36]=3,Ne[7]=5,Ne[9]=7,Ne[14]=9,Ne[18]=55,St[1]=2,St[36]=4,St[7]=6,St[9]=8,St[18]=14,St[50]=42,St[14]=10,St[12]=13,Ie[1]=15,Ie[7]=16,Ie[4]=17,Ie[5]=18,Ie[3]=19,Ie[2]=20,Ie[8]=21,Ie[27]=57,Ie[16]=22,Ie[19]=23,Ie[6]=24,Ie[11]=25,Ie[17]=26,Ie[13]=48,Ie[31]=47,Ie[23]=54,Ie[0]=44,Ue[1]=31,Ue[4]=32,Ue[5]=32,Ue[3]=33,Ue[2]=34,Ue[10]=40,Ue[6]=38,Ue[31]=36,Ue[24]=36,Ue[32]=35,ge[1]=45,ge[16]=37,ge[37]=37,ge[38]=37,ge[47]=37,ge[48]=37,ge[39]=37,ge[49]=37,ge[41]=37,ge[26]=37,ge[25]=37,ge[23]=37,ge[24]=37,ge[19]=37,ge[21]=37,ge[36]=37,ge[18]=37,ge[22]=37,ge[11]=39,ge[12]=43,ge[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,tt[0]=200,tt[12]=50,tt[13]=52,tt[14]=50,tt[15]=51,tt[10]=50,tt[11]=51,tt[17]=53,He[0]=200,He[12]=50,He[13]=51,He[14]=50,He[15]=51,He[10]=50,He[11]=51,Te[11]=0,Te[16]=0,Te[22]=1,Te[18]=1,Te[26]=2,Te[25]=2,Te[38]=3,Te[37]=3,Te[48]=3,Te[47]=3,Te[39]=3,Te[49]=3,Te[41]=3,Te[23]=4,Te[24]=4,Te[36]=5,Te[19]=5,Te[21]=5,Te[0]=6,Te[Ui]=2,Te[$i]=2;var lr=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,c(this,"valStack",[]),c(this,"namespacePrefixToURI",{}),c(this,"defaultNamespaceURI",null),c(this,"propName",null),c(this,"propImportant",!1),c(this,"exprContext"),c(this,"result",null),c(this,"importReady",!1),c(this,"importURL",null),c(this,"importCondition",null),c(this,"errorBrackets",[]),c(this,"ruleStack",[]),c(this,"regionRule",!1),c(this,"pageRule",!1),c(this,"inStyleDeclaration",!1),this.exprContext=2}extractVals(e,t){let i=[],n=this.valStack;for(;t<n.length&&(i.push(n[t++]),t!==n.length);){if(n[t++]!==e)throw new Error("Unexpected state");t===n.length&&i.push(X)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,s;do if(s=i[--n],e===")"&&s instanceof _i){if(s.text===")")r++;else if(s.text==="("){if(r===0)return null;r--}}while(typeof s<"u"&&typeof s!="string");let o=i.length-(n+1);if(o>1&&i.splice(n+1,o,new J(i.slice(n+1,i.length))),e==",")return null;n++;do s=i[--n];while(typeof s<"u"&&(typeof s!="string"||s==","));if(o=i.length-(n+1),s=="("){e!=")"&&t.type!==0&&(this.handler.error("E_CSS_MISMATCHED_C_PAR",t),this.actions=tt);let l=new Ri(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,l),l.name==="var"){let h=l.values[0]instanceof le&&l.values[0].name;(!zt(h)||h===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${l.toString()}`,t),this.actions=tt)}return l}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=tt,null;if(o>1)return new Ze(this.extractVals(",",n+1));let a=i[0];return a instanceof Je?a:a?new _i(a.toString()):X}exprError(e,t){this.actions=this.propName?tt:je,$.warn(e,t.toString())}exprStackReduce(e,t){let i=this.valStack,n=this.handler,r=i.pop(),s;for(;;){let o=i.pop();if(e==11){let a=[r];for(;o==16;)a.unshift(i.pop()),o=i.pop();if(typeof o=="string"){if(o=="{"){for(;a.length>=2;){let l=a.shift(),h=a.shift(),u=new hf(n.getScope(),l,h);a.unshift(u)}return i.push(new U(a[0])),!0}else if(o=="("){let l=i.pop(),h=i.pop();r=new On(n.getScope(),to(h,l),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new yl(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new si(n.getScope(),r);else if(o==-24)r=new ji(n.getScope(),r);else if(o==-br)r=new af(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Te[e]>Te[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new da(n.getScope(),s,r);break;case Ui:r=new lf(n.getScope(),s,r);break;case $i:r=new uf(n.getScope(),s,r);break;case 25:r=new pa(n.getScope(),s,r);break;case 38:r=new cf(n.getScope(),s,r);break;case 37:r=new pf(n.getScope(),s,r);break;case 48:r=new df(n.getScope(),s,r);break;case 47:r=new ro(n.getScope(),s,r);break;case 39:case 49:r=new fa(n.getScope(),s,r);break;case 41:r=new ff(n.getScope(),s,r);break;case 23:r=new lu(n.getScope(),s,r);break;case 24:r=new hu(n.getScope(),s,r);break;case 36:r=new ga(n.getScope(),s,r);break;case 19:r=new uu(n.getScope(),s,r);break;case 21:r=new cu(n.getScope(),s,r);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),r=new wf(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new yl(n.getScope(),s,r);else return this.exprError("E_CSS_MEDIA_TEST",t),!1;break}else return this.exprError("E_CSS_EXPR_COND",t),!1;break;case 22:if(e!=18)return this.exprError("E_CSS_EXPR_COND",t),!1;case 10:return i.push(s),i.push(o),i.push(r),!1;default:return this.exprError("F_UNEXPECTED_STATE",t),!1}}}return i.push(r),!1}readSupportsTest(e){let t=e.type===6,i=this.tokenizer,n,r;if(t)r=e.text,n=e.position+r.length+1;else if(e.type===10){let u=i.nthToken(1),d=i.nthToken(2);if(u.type===1&&d.type===18)i.consume(),i.consume(),r=u.text,n=d.position+1;else{if(u.type===10||u.type===6||u.type===1&&u.text.toLowerCase()==="not"&&(d.type===10||d.type===6))return null;n=e.position+1}}else return null;let s=0,o,a=0;for(;s>=0;)switch(i.consume(),o=i.token(),o.type){case 11:s--;break;case 10:case 6:s++;break;case 16:s===0&&a++;break;case 0:return this.exprError("E_CSS_UNEXPECTED_EOF",o),null}i.consume();let l=o.position,h=t&&r==="selector"&&a>0?"":i.input.substring(n,l).trim();return new yf(this.handler.getScope(),r,h,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let r=t.type===24,s=t.type===23||r;if(s&&(this.tokenizer.consume(),t=this.tokenizer.token()),t.type===5){if(n=t.num,1/n===-1/0){if(n=0,s)return null}else if(n<0){if(s)return null}else if(n>=0&&!s)return null;this.tokenizer.consume()}else if(s)return null;return[i,r&&n>0?-n:n]}else if(t.text==="n-"||t.text==="-n-"){if(e&&t.precededBySpace)return null;let i=t.text==="-n-"?-1:1;if(t.type===3&&(i=t.num),this.tokenizer.consume(),t=this.tokenizer.token(),t.type===5)return t.num<0||1/t.num===-1/0?null:(this.tokenizer.consume(),[i,t.num])}else{let i=t.text.match(/^n(-[0-9]+)$/);if(i)return e&&t.precededBySpace?null:(this.tokenizer.consume(),[t.type===3?t.num:1,parseInt(i[1],10)]);if(i=t.text.match(/^-n(-[0-9]+)$/),i)return this.tokenizer.consume(),[-1,parseInt(i[1],10)]}return null;case 5:return e&&(t.precededBySpace||t.num<0)?null:(this.tokenizer.consume(),[0,t.num])}return null}makeCondition(e,t){let i=this.handler.getScope();if(!i)return null;if(t=t||i._true,e){let n=e.split(/\s+/);for(let r of n)switch(r){case"vertical":t=Et(i,t,new si(i,new De(i,"pref-horizontal")));break;case"horizontal":t=Et(i,t,new De(i,"pref-horizontal"));break;case"day":t=Et(i,t,new si(i,new De(i,"pref-night-mode")));break;case"night":t=Et(i,t,new De(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new U(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":case"counter-style":case"-epubx-flow":case"-epubx-viewport":case"-epubx-define":case"-adapt-footnote-area":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,l=this.valStack,h,u,d,p,f,m,g,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(h=a.token(),r&&w===null&&(w=h.position-1,a.input[w]==="("&&w++),this.actions===Ie&&this.errorBrackets.length>0&&(h.type===this.errorBrackets[this.errorBrackets.length-1]||h.type===17||h.type===31)){if(h.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),h.type===11&&this.valStackReduce(")",h))){a.consume();continue}l.push(new _i(h.toString())),a.consume();continue}switch(this.actions[h.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=tt):(this.actions=at,o.startSelectorRule());continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=tt,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=h.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Ie,l.splice(0,l.length);continue;case 29:this.actions=at,o.startSelectorRule();continue;case 1:if(!h.precededBySpace){this.actions=He,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[h.text],d!=null)switch(h=a.token(),h.type){case 1:o.tagSelector(d,h.text),r?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(d,null),r?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=je,o.error("E_CSS_NAMESPACE",h)}else this.actions=je,o.error("E_CSS_UNDECLARED_PREFIX",h);else o.tagSelector(this.defaultNamespaceURI,h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 3:if(!h.precededBySpace){this.actions=He,o.error("E_CSS_SPACE_EXPECTED",h);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),h=a.token(),h.type){case 1:o.tagSelector(null,h.text),r?this.actions=Ne:this.actions=me,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Ne:this.actions=me,a.consume();break;default:this.actions=je,o.error("E_CSS_NAMESPACE",h)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Ne:this.actions=me,a.consume();continue;case 5:h.precededBySpace&&o.descendantSelector();case 6:if(!h.text){o.error("E_CSS_SYNTAX",h),a.consume();continue}o.idSelector(h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 7:h.precededBySpace&&o.descendantSelector();case 8:o.classSelector(h.text),r?this.actions=Ne:this.actions=me,a.consume();continue;case 55:h.precededBySpace&&o.descendantSelector();case 14:a.consume(),h=a.token();e:switch(h.type){case 1:o.pseudoclassSelector(h.text,null),a.consume(),r?this.actions=Ne:this.actions=me;continue;case 6:switch(p=h.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=at,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=me:this.actions=He;continue;case"lang":case"href-epub-type":if(h=a.token(),h.type===1){g=[h.text],a.consume(),p==="href-epub-type"&&a.token().type===16&&(a.consume(),h=a.token(),h.type===1&&(g.push(h.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(g=this.readNthPseudoParams(),g)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=at,o.startFuncWithSelector(p,g),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Ne:this.actions=me:this.actions=He;continue}break}else if(p==="nth"){if(u=a.nthToken(0),u.type===1&&u.text==="of")if(a.consume(),u=a.token(),u.type===1)g.push(u.text),a.consume();else break e;break}else break;else break e;default:g=this.readPseudoParams()}if(h=a.token(),h.type==11){o.pseudoclassSelector(p,g),a.consume(),r?this.actions=Ne:this.actions=me;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",h),this.actions=je;continue;case 58:h.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),h=a.token(),h.type){case 1:o.pseudoelementSelector(h.text,null),r?this.actions=Ne:this.actions=me,a.consume();continue;case 6:if(p=h.text,a.consume(),p=="nth-fragment"){if(g=this.readNthPseudoParams(),g===null)break}else g=this.readPseudoParams();if(h=a.token(),h.type==11){o.pseudoelementSelector(p,g),r?this.actions=Ne:this.actions=me,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",h),this.actions=je;continue;case 9:h.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),h=a.token(),h.type==1)p=h.text,a.consume();else if(h.type==36)p=null,a.consume();else if(h.type==34)p="";else{this.actions=He,o.error("E_CSS_ATTR",h),a.consume();continue}if(h=a.token(),h.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=He,o.error("E_CSS_UNDECLARED_PREFIX",h),a.consume();continue}if(a.consume(),h=a.token(),h.type!=1){this.actions=He,o.error("E_CSS_ATTR_NAME_EXPECTED",h);continue}p=h.text,a.consume(),h=a.token()}else d="";switch(h.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=h.type,a.consume(),h=a.token();break;case 15:o.attributeSelector(d,p,0,null),r?this.actions=Ne:this.actions=me,a.consume();continue;default:this.actions=He,o.error("E_CSS_ATTR_OP_EXPECTED",h);continue}switch(h.type){case 1:case 2:o.attributeSelector(d,p,f,h.text),a.consume(),h=a.token();break;default:this.actions=He,o.error("E_CSS_ATTR_VAL_EXPECTED",h);continue}if(h.type!=15){this.actions=He,o.error("E_CSS_ATTR",h);continue}r?this.actions=Ne:this.actions=me,a.consume();continue;case 11:o.childSelector(),this.actions=St,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=St,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=St,a.consume();continue;case 13:this.regionRule?(this.ruleStack.push("-epubx-region"),this.regionRule=!1):this.pageRule?(this.ruleStack.push("page"),this.pageRule=!1,this.inStyleDeclaration=!0):(this.ruleStack.push("[selector]"),this.inStyleDeclaration=!0),o.startRuleBody(),this.actions=Ae,a.consume();continue;case 41:o.nextSelector(),this.actions=at,a.consume();continue;case 15:l.push(F(h.text)),a.consume();continue;case 16:f=parseInt(h.text,16),l.push(new vu(h.text)),a.consume();continue;case 17:l.push(new gt(h.num)),a.consume();continue;case 18:l.push(new Le(h.num)),a.consume();continue;case 19:l.push(new I(h.num,h.text)),a.consume();continue;case 20:l.push(new j(h.text)),a.consume();continue;case 21:l.push(new Qe(Pe(h.text,this.baseURL))),a.consume();continue;case 57:l.push(new xu(h.text)),a.consume();continue;case 22:this.valStackReduce(",",h),l.push(","),a.consume();continue;case 23:l.push(fn),a.consume();continue;case 24:p=h.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=Ue,this.exprContext=0,l.push("{")):(l.push(p),l.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",h),a.consume();continue;case 47:if(a.consume(),h=a.token(),u=a.nthToken(1),h.type==1&&h.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",h);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}l.push(new _i("+")),a.consume();continue;case 26:a.consume();case 48:m=this.valStackReduce(";",h),m&&this.propName&&o.property(this.propName,m,this.propImportant),this.actions=i?Zr:Ae;continue;case 44:for(a.consume();l.length>0;){let v=l.length;if(m=this.valStackReduce(";",h),!m||l.length===v)break}return t?(this.result=m,!0):(this.propName&&m&&o.property(this.propName,m,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(l.push(h.text,u.text,"("),a.consume()):(l.push(new De(o.getScope(),to(h.text,u.text))),this.actions=ge),a.consume();else{if(this.exprContext==2||this.exprContext==3)h.text.toLowerCase()=="not"?(a.consume(),l.push(new wl(o.getScope(),!0,u.text))):(h.text.toLowerCase()=="only"&&(a.consume(),h=u),l.push(new wl(o.getScope(),!1,h.text)));else if(this.exprContext===4&&h.text.toLowerCase()==="not"&&l[l.length-1]!==Ui&&l[l.length-1]!==$i&&(u.type===10||u.type===6)){l.push(-br),a.consume();continue}else l.push(new De(o.getScope(),h.text));this.actions=ge}a.consume();continue;case 38:if(this.exprContext===4){l.push(this.readSupportsTest(h)),this.actions=ge;continue}l.push(null,h.text,"("),a.consume();continue;case 32:l.push(new We(o.getScope(),h.num)),a.consume(),this.actions=ge;continue;case 33:p=h.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),l.push(new nr(o.getScope(),h.num,p)),a.consume(),this.actions=ge;continue;case 34:l.push(new We(o.getScope(),h.text)),a.consume(),this.actions=ge;continue;case 35:a.consume(),h=a.token(),h.type!=5||h.precededBySpace?this.exprError("E_CSS_SYNTAX",h):(l.push(new gu(o.getScope(),h.num)),a.consume(),this.actions=ge);continue;case 36:l.push(-h.type),a.consume();continue;case 37:this.actions=Ue,this.exprStackReduce(h.type,h),l.push(h.type),a.consume();continue;case 45:h.text.toLowerCase()==="and"&&l[l.length-2]!==$i&&l[l.length-2]!==-br?(this.actions=Ue,this.exprStackReduce(Ui,h),l.push(Ui),a.consume()):h.text.toLowerCase()==="or"&&l[l.length-2]!==Ui&&l[l.length-2]!==-br?(this.actions=Ue,this.exprStackReduce($i,h),l.push($i),a.consume()):this.exprError("E_CSS_SYNTAX",h);continue;case 39:this.exprStackReduce(h.type,h)&&(this.actions=Ie),a.consume();continue;case 43:this.exprStackReduce(11,h)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",h):(this.exprContext==1?o.startWhenRule(l.pop()):o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae)),a.consume();continue;case 49:if(this.exprStackReduce(11,h))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",h),this.actions=Ae,a.consume(),!1):(this.importCondition=l.pop(),this.importReady=!0,this.actions=Ae,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let v=this.readSupportsTest(h);if(v){l.push(v),this.actions=ge;continue}}l.push(h.type),a.consume();continue;case 27:if(this.actions=Ae,a.consume(),o.endRule(),this.inStyleDeclaration=!1,this.ruleStack.length)switch(this.ruleStack.pop(),this.ruleStack[this.ruleStack.length-1]){case"page":case"-epubx-page-master":case"-epubx-partition-group":this.inStyleDeclaration=!0}continue;case 30:switch(p=h.text.toLowerCase(),p){case"import":if(a.consume(),h=a.token(),h.type==2||h.type==8){if(this.importURL=h.text,a.consume(),h=a.token(),h.type==17||h.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=Ue,l.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",h),this.actions=je;continue;case"namespace":switch(a.consume(),h=a.token(),h.type){case 1:if(p=h.text,a.consume(),h=a.token(),(h.type==2||h.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=h.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=h.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",h),this.actions=je;continue;case"charset":if(a.consume(),h=a.token(),h.type==2&&a.nthToken(1).type==17){p=h.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,h),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",h),this.actions=je;continue;case"font-face":case"-epubx-page-template":case"-epubx-define":case"-epubx-viewport":if(a.nthToken(1).type==12){switch(a.consume(),a.consume(),p){case"font-face":o.startFontFaceRule(),this.inStyleDeclaration=!0;break;case"-epubx-page-template":o.startPageTemplateRule();break;case"-epubx-define":o.startDefineRule(),this.inStyleDeclaration=!0;break;case"-epubx-viewport":o.startViewportRule(),this.inStyleDeclaration=!0;break}this.ruleStack.push(p),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),h=a.token(),h.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),h=a.token(),h.type==1&&a.nthToken(1).type==12){p=h.text,a.consume(),a.consume(),o.startFootnoteRule(p),this.ruleStack.push("-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=at;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=St;continue;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),h=a.token(),h.type==12){a.consume(),o.startPageMarginBoxRule(p),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Ue,l.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Ue,l.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Ue,l.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"counter-style":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startCounterStyleRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-page-master":case"-epubx-partition":case"-epubx-partition-group":{a.consume(),h=a.token();let v=null,y=null,C=[];for(h.type==1&&(v=h.text,a.consume(),h=a.token()),h.type==18&&a.nthToken(1).type==1&&(y=a.nthToken(1).text,a.consume(),a.consume(),h=a.token());h.type==6&&h.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)C.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),h=a.token();if(h.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(v,y,C);break;case"-epubx-partition":o.startPartitionRule(v,y,C);break;case"-epubx-partition-group":o.startPartitionGroupRule(v,y,C);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,h),this.actions=He;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,h),this.actions=je;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,h),this.actions=je;continue;case 50:this.errorBrackets.push(h.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ae;continue}case 51:if(r&&this.errorBrackets.length==0&&h.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==h.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&h.type==13&&(this.actions=Ae),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ae),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,h)?(this.result=l.pop(),!0):!1;if(r){switch(h.type){case 16:case 11:if(this.actions===at)o.error("E_CSS_SYNTAX",h);else{let v=a.input.substring(w,h.position);o.pushSelectorText(v),w=h.position+1}if(h.type===16){o.nextSelector(),this.actions=at,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=me;continue}break;case 12:case 14:case 10:this.errorBrackets.push(h.type+1);break}o.error("E_CSS_SYNTAX",h),a.consume(),this.actions=He;continue}if(this.actions!==je&&this.actions!==He&&this.actions!==tt){if(h.type==54)o.error("E_CSS_SYNTAX",h);else if(this.actions===Ie){switch(h.type){case 10:case 12:case 14:this.errorBrackets.push(h.type+1);break}l.push(new _i(h.toString())),a.consume();continue}else if(h.type===12&&this.actions==Ue&&l.length>0){o.startMediaRule(l.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ae,a.consume();continue}else{if(h.type===17&&this.actions==Ue)return this.actions=Ae,a.consume(),!1;o.error("E_CSS_SYNTAX",h)}this.isInsidePropertyOnlyRule()?this.actions=tt:this.actions=He;continue}a.consume();continue}}return!1}},Zu=class extends ba{constructor(e){super(null),this.scope=e}error(e,t){$.warn(e,t.toString())}getScope(){return this.scope}};function Pg(e,t,i,n,r){let s=O("parseStylesheet"),o=new lr(Ae,e,t,i),a=null;return r&&(a=Ig(new Ft(r,t),t,i)),a=o.makeCondition(n,a&&a.toExpr()),a&&(t.startMediaRule(a),t.startRuleBody()),s.loop(()=>{for(;!o.runParser(100,!1,!1,!1,!1);){if(o.importReady){let h=Pe(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=O("parseStylesheet.import");return Ju(h,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let l=s.timeSlice();if(l.isPending)return l}return N(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function va(e,t,i,n,r){return an("parseStylesheetFromText",s=>{let o=new Ft(e,t);Pg(o,t,i,n,r).thenFinish(s)},(s,o)=>{$.warn(o,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function Ju(e,t,i,n){return an("parseStylesheetFromURL",r=>{ys(e).then(s=>{s.responseText?va(s.responseText,t,e,i,n).then(o=>{o||$.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{$.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function gn(e,t,i){let n=new lr(Ie,t,new Zu(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Tg(e,t,i){new lr(Zr,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Ig(e,t,i){let n=new lr(Ue,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Ag={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Rg(e){return!!Ag[e]}function Fg(e,t,i){if(t instanceof ze&&t.str==="viv-leader")return new U(t);let n=t.evaluate(e);switch(typeof n){case"number":return Rg(i)?n==Math.round(n)?new Le(n):new gt(n):new I(n,"px");case"string":return n?gn(t.scope,new Ft(n,null),""):X;case"boolean":return n?b._true:b._false;case"undefined":return X}throw new Error("E_UNEXPECTED")}function Qu(e,t){let i={};return Object.keys(e).forEach(n=>{let r=i[n]={},s=e[n];Object.keys(s).forEach(o=>{r[o]=s[o].map(a=>{let l=t?a.logical:a.physical,h=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${l}(-?)`),to:`$1${h}$2`}})})}),i}function ec(e,t,i,n){let r=n[t];if(!r)throw new Error(`unknown writing-mode: ${t}`);let s=r[i||"ltr"];if(!s)throw new Error(`unknown direction: ${i}`);for(let o of s){let a=e.replace(o.regexp,o.to);if(a!==e)return a}return e}var tc={"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"}]}},Lg=Qu(tc,!0);function ic(e,t,i){return ec(e,t,i||null,Lg)}var Og=Qu(tc,!1);function nc(e,t,i){return ec(e,t,i||null,Og)}var Bg={"horizontal-tb":[{logical:"line-left",physical:"left"},{logical:"line-right",physical:"right"},{logical:"over",physical:"top"},{logical:"under",physical:"bottom"}],"vertical-rl":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}],"vertical-lr":[{logical:"line-left",physical:"top"},{logical:"line-right",physical:"bottom"},{logical:"over",physical:"right"},{logical:"under",physical:"left"}]};function Mg(e,t){let i=Bg[t];if(!i)throw new Error(`unknown writing-mode: ${t}`);for(let n=0;n<i.length;n++)if(i[n].physical===e)return i[n].logical;return e}function xa(e,t,i){var n;let r=t,s={width:r.style.width,height:r.style.height};function o(p){return e.getElementComputedStyle(t).getPropertyValue(p)}let a=o("writing-mode")!=="horizontal-tb",l=a?"height":"width",h=a?"width":"height";function u(p,f){r.style[p]=f;let m=o(p);return r.style[p]=s[p],m}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(l,"max-content");break;case"min-content inline size":f=u(l,"min-content");break;case"fit-content inline size":f=u(l,"fit-content");break;case"max-content block size":f=u(h,"max-content");break;case"min-content block size":f=u(h,"min-content");break;case"fit-content block size":f=u(h,"fit-content");break;case"max-content width":f=u("width","max-content");break;case"max-content height":f=u("height","max-content");break;case"min-content width":f=u("width","min-content");break;case"min-content height":f=u("height","min-content");break;case"fit-content width":f=u("width","fit-content");break;case"fit-content height":f=u("height","fit-content");break}f==="0px"&&t.childNodes.length===1&&((n=t.firstElementChild)==null?void 0:n.localName)==="img"&&!t.firstElementChild.complete&&(f="1px"),d[p]=parseFloat(f)}return d}function En(e){var t,i;return((t=e?.style)==null?void 0:t["box-decoration-break"])==="clone"||((i=e?.style)==null?void 0:i["-webkit-box-decoration-break"])==="clone"}function rc(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function sc(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function wt(e,t){let i=rc(e);i.includes(t)||(i.push(t),sc(e,i))}function _g(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function zg(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Hs(e,t){let i=_g(e);i.includes(t)||(i.push(t),zg(e,i))}function Dg(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===b.always?b.page:i,important:e.important};default:return e}}var po={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function it(e){return!!po[e]}var Vg={left:!0,right:!0,recto:!0,verso:!0};function Xn(e){return!!Vg[e]}var Hg={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Jr(e){return!!Hg[e]}function rt(e,t){if(e)if(t){if(Xn(t))return t;if(Xn(e))return e;{let i=it(e),n=it(t);if(i&&n)switch(t){case"column":return e;case"region":return e==="column"?t:e;default:return t}else return n?t:i?e:Jr(t)?t:Jr(e)?e:t}}else return e;else return t}function Ol(e){return it(e)?e:"auto"}Nt("SIMPLE_PROPERTY",Dg);var Mn=Op(Mp());function Ug(e,t){return(0,Mn.default)(e,t,0)}function Bl(e){return e.reduce((t,i)=>i[0]===Mn.default.DELETE?t:t+i[1],"")}function $g(e,t){return oc(e,t,1)}function Wg(e,t){return oc(e,t,-1)}function oc(e,t,i){let n=0,r=0;return e.some(s=>{for(let o=0;o<s[1].length;o++){switch(s[0]*i){case Mn.default.INSERT:n++;break;case Mn.default.DELETE:n--,r++;break;case Mn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var fo;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(fo||(fo={}));var en;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(en||(en={}));var Qr;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Qr||(Qr={}));var Ni;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||li.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||li.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Ni||(Ni={}));var li;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(li||(li={}));var Xt;(e=>{let t;(n=>(n[n.IGNORE=0]="IGNORE",n[n.NEWLINE=1]="NEWLINE",n[n.PRESERVE=2]="PRESERVE"))(t=e.Whitespace||(e.Whitespace={}));let i;(n=>(n[n.NONE=0]="NONE",n[n.CONTENT=1]="CONTENT",n[n.ROOTLESS=2]="ROOTLESS",n[n.ROOTED=3]="ROOTED"))(i=e.ShadowType||(e.ShadowType={}))})(Xt||(Xt={}));var Gg={transform:!0,"transform-origin":!0},jg={top:!0,bottom:!0,left:!0,right:!0},Sa=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Xg={show:function(e){e.style.visibility="visible"},hide:function(e){e.style.visibility="hidden"},play:function(e){e.currentTime=0,e.play()},pause:function(e){e.pause()},resume:function(e){e.play()},mute:function(e){e.muted=!0},unmute:function(e){e.muted=!1}};function qg(e,t){let i=Xg[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var go=class Nn extends ua{constructor(t,i){super(),this.container=t,this.bleedBox=i,c(this,"pageAreaElement",null),c(this,"delayedItems",[]),c(this,"hrefHandler"),c(this,"elementsById",{}),c(this,"dimensions",{width:0,height:0}),c(this,"isFirstPage",!1),c(this,"isLastPage",!1),c(this,"isBlankPage",!1),c(this,"isAutoPageWidth",!0),c(this,"isAutoPageHeight",!0),c(this,"spineIndex",0),c(this,"position",null),c(this,"offset",-1),c(this,"side",null),c(this,"fetchers",[]),c(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),c(this,"pageType",null),this.hrefHandler=n=>{let r=n.currentTarget,s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(s){let o={type:"hyperlink",target:null,currentTarget:null,anchorElement:r,href:s,preventDefault(){n.preventDefault()}};this.dispatchEvent(o)}}}setAutoPageWidth(t){this.isAutoPageWidth=t,t?this.container.setAttribute(Nn.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Nn.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Nn.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Nn.AUTO_PAGE_HEIGHT_ATTRIBUTE)}registerElementWithId(t,i){let n=this.elementsById[i];n?n.push(t):this.elementsById[i]=[t]}finish(t,i){Object.keys(this.elementsById).forEach(s=>{let o=this.elementsById[s];for(let a=0;a<o.length;)this.container.contains(o[a])?a++:o.splice(a,1);o.length===0&&delete this.elementsById[s]});let n=this.delayedItems;for(let s=0;s<n.length;s++){let o=n[s];o.target===this.container&&o.name==="transform"&&!this.isAutoPageWidth&&!this.isAutoPageHeight||T(o.target,o.name,o.value.toString())}let r=i.getElementClientRect(this.container);this.dimensions.width=r.width,this.dimensions.height=r.height;for(let s=0;s<t.length;s++){let o=t[s],a=this.elementsById[o.ref],l=this.elementsById[o.observer];if(a&&l){let h=qg(a,o.action);if(h)for(let u=0;u<l.length;u++)l[u].addEventListener(o.event,h,!1)}}}};c(go,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(go,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var ac=go,lt=Xt.Whitespace;function lc(e){switch(e){case"normal":case"nowrap":return lt.IGNORE;case"pre-line":return lt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return lt.PRESERVE;default:return null}}function $e(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case lt.PRESERVE:return i.length==0;case lt.NEWLINE:return!!i.match(/^[ \t]*$/);case lt.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Yg=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},Kg=class{constructor(e,t,i,n,r,s,o,a,l){this.flowName=e,this.element=t,this.startOffset=i,this.priority=n,this.linger=r,this.exclusive=s,this.repeated=o,this.last=a,this.breakBefore=l,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Zg(e,t){return e.top-t.top}function Jg(e,t){return t.right-e.right}function hc(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Xt.ShadowType.ROOTLESS&&t.shadowType===Xt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&wo(e.shadowContext,t.shadowContext)&&wo(e.nodeShadow,t.nodeShadow)&&hc(e.shadowSibling,t.shadowSibling)}function hi(e,t){if(e===t)return!0;if(!e||!t||e.offsetInNode!==t.offsetInNode||e.after!==t.after||e.steps.length!==t.steps.length)return!1;for(let i=0;i<e.steps.length;i++)if(!hc(e.steps[i],t.steps[i]))return!1;return!0}function Qg(e){return{steps:[{node:e,shadowType:xt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function es(e,t){return{steps:[{node:e.sourceNode,shadowType:xt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ts(e,t){let i=new Pn(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ts(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var xt=Xt.ShadowType,mo=class{constructor(e,t,i,n,r,s,o){this.owner=e,this.root=t,this.xmldoc=i,this.parentShadow=n,this.type=s,this.styler=o,c(this,"subShadow",null),r&&(r.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&wo(this.parentShadow,e.parentShadow):!1}};function wo(e,t){return e===t||!!e&&!!t&&e.equals(t)}var em=class{constructor(e,t){this.outer=e,this.count=t}},Pn=class uc{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,c(this,"offsetInNode",0),c(this,"after",!1),c(this,"shadowType"),c(this,"shadowContext"),c(this,"nodeShadow",null),c(this,"shadowSibling",null),c(this,"shared",!1),c(this,"inline",!0),c(this,"overflow",!1),c(this,"breakPenalty"),c(this,"display",null),c(this,"floatReference"),c(this,"floatSide",null),c(this,"clearSide",null),c(this,"floatMinWrapBlock",null),c(this,"columnSpan",null),c(this,"verticalAlign","baseline"),c(this,"captionSide","top"),c(this,"inlineBorderSpacing",0),c(this,"blockBorderSpacing",0),c(this,"flexContainer",!1),c(this,"whitespace"),c(this,"hyphenateCharacter"),c(this,"breakWord"),c(this,"establishesBFC",!1),c(this,"containingBlockForAbsolute",!1),c(this,"breakBefore",null),c(this,"breakAfter",null),c(this,"viewNode",null),c(this,"clearSpacer",null),c(this,"inheritedProps"),c(this,"vertical"),c(this,"direction"),c(this,"firstPseudo"),c(this,"lang",null),c(this,"preprocessedTextContent",null),c(this,"formattingContext"),c(this,"repeatOnBreak",null),c(this,"pluginProps",{}),c(this,"fragmentIndex",1),c(this,"afterIfContinues",null),c(this,"footnotePolicy",null),c(this,"pageType"),this.shadowType=xt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=en.FloatReference.INLINE,this.whitespace=i?i.whitespace:lt.IGNORE,this.hyphenateCharacter=i?i.hyphenateCharacter:null,this.breakWord=i?i.breakWord:!1,this.inheritedProps=i?i.inheritedProps:{},this.vertical=i?i.vertical:!1,this.direction=i?i.direction:"ltr",this.firstPseudo=i?i.firstPseudo:null,this.formattingContext=i?i.formattingContext:null,this.pageType=i?i.pageType:null}resetView(){this.inline=!0,this.breakPenalty=this.parent?this.parent.breakPenalty:0,this.viewNode=null,this.clearSpacer=null,this.offsetInNode=0,this.after=!1,this.display=null,this.floatReference=en.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.verticalAlign="baseline",this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:lt.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 uc(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.verticalAlign=this.verticalAlign,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),i=t,n;for(;(n=i.parent)!=null;)n=n.cloneItem(),i.parent=n,i=n;return t}toNodePositionStep(){var t;return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:((t=this.viewNode)==null?void 0:t.parentNode)===null?0:this.fragmentIndex}}toNodePosition(){var t,i,n;let r=this,s=[];r.shadowType===Xt.ShadowType.ROOTLESS&&(r.floatReference!==en.FloatReference.INLINE||r.floatSide==="footnote")&&(n=(i=(t=r.shadowContext)==null?void 0:t.styler)==null?void 0:i.style)!=null&&n._pseudos&&(r=r.parent);do(!r.firstPseudo||!r.parent||r.parent.firstPseudo===r.firstPseudo)&&s.push(r.toNodePositionStep()),r=r.parent;while(r);let o=this.preprocessedTextContent?Wg(this.preprocessedTextContent,this.offsetInNode):this.offsetInNode;return{steps:s,offsetInNode:o,after:this.after,preprocessedTextContent:this.preprocessedTextContent}}isInsideBFC(){let t=this.parent;for(;t;){if(t.establishesBFC)return!0;t=t.parent}return!1}getContainingBlockForAbsolute(){let t=this.parent;for(;t;){if(t.containingBlockForAbsolute)return t;t=t.parent}return null}belongsTo(t){return this.formattingContext===t&&!!this.parent&&this.parent.formattingContext===t}},ui=class cc{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new cc(this.primary);if(this.floats){t.floats=[];for(let i=0;i<this.floats.length;++i)t.floats[i]=this.floats[i]}return t}isSamePosition(t){if(!t)return!1;if(this===t)return!0;if(!hi(this.primary,t.primary))return!1;if(this.floats){if(!t.floats||this.floats.length!==t.floats.length)return!1;for(let i=0;i<this.floats.length;i++)if(!hi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},tm=class dc{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new dc(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},im=class pc{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new pc,i=this.positions,n=t.positions;for(let r=0;r<i.length;r++)n[r]=i[r].clone();return t.startBreakType=this.startBreakType,t.breakAfter=this.breakAfter,t}isSamePosition(t){if(this===t)return!0;if(!t||this.positions.length!==t.positions.length)return!1;for(let i=0;i<this.positions.length;i++)if(!this.positions[i].isSamePosition(t.positions[i]))return!1;return!0}hasContent(t){return this.positions.length>0&&this.positions[0].flowChunk.startOffset<=t}},nm=class fc{constructor(){c(this,"page",0),c(this,"flows",{}),c(this,"flowPositions",{}),c(this,"isBlankPage",!1),c(this,"highestSeenOffset",0),c(this,"highestSeenNode"),c(this,"lookupPositionOffset")}clone(){let t=new fc;t.page=this.page,t.isBlankPage=this.isBlankPage,t.highestSeenNode=this.highestSeenNode,t.highestSeenOffset=this.highestSeenOffset,t.lookupPositionOffset=this.lookupPositionOffset,t.flows=this.flows;for(let i in this.flowPositions)t.flowPositions[i]=this.flowPositions[i].clone();return t}isSamePosition(t){if(this===t)return!0;if(!t||this.page!==t.page)return!1;let i=Object.keys(this.flowPositions),n=Object.keys(t.flowPositions);if(i.length!==n.length)return!1;for(let r of i)if(!this.flowPositions[r].isSamePosition(t.flowPositions[r]))return!1;return!0}hasContent(t,i){let n=this.flowPositions[t];return n?n.hasContent(i):!1}startSideOfFlow(t){var i;let n=(i=this.flowPositions[t])==null?void 0:i.startBreakType;return n&&Xn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},gc=class{constructor(e){this.element=e,c(this,"left",0),c(this,"top",0),c(this,"marginLeft",0),c(this,"marginRight",0),c(this,"marginTop",0),c(this,"marginBottom",0),c(this,"borderLeft",0),c(this,"borderRight",0),c(this,"borderTop",0),c(this,"borderBottom",0),c(this,"paddingLeft",0),c(this,"paddingRight",0),c(this,"paddingTop",0),c(this,"paddingBottom",0),c(this,"width",0),c(this,"height",0),c(this,"originX",0),c(this,"originY",0),c(this,"exclusions",null),c(this,"innerShape",null),c(this,"computedBlockSize",0),c(this,"snapWidth",0),c(this,"snapHeight",0),c(this,"snapOffsetX",0),c(this,"snapOffsetY",0),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"borderBoxSizing",!1)}getInsetTop(){return this.marginTop+(this.borderBoxSizing?0:this.borderTop+this.paddingTop)}getInsetBottom(){return this.marginBottom+(this.borderBoxSizing?0:this.borderBottom+this.paddingBottom)}getInsetLeft(){return this.marginLeft+(this.borderBoxSizing?0:this.borderLeft+this.paddingLeft)}getInsetRight(){return this.marginRight+(this.borderBoxSizing?0:this.borderRight+this.paddingRight)}getInsetBefore(){return this.vertical?this.getInsetRight():this.getInsetTop()}getInsetAfter(){return this.vertical?this.getInsetLeft():this.getInsetBottom()}getInsetStart(){return this.vertical?this.getInsetTop():this.getInsetLeft()}getInsetEnd(){return this.vertical?this.getInsetBottom():this.getInsetRight()}getBeforeEdge(e){return this.vertical?e.right:e.top}getAfterEdge(e){return this.vertical?e.left:e.bottom}getStartEdge(e){return this.vertical?this.rtl?e.bottom:e.top:this.rtl?e.right:e.left}getEndEdge(e){return this.vertical?this.rtl?e.top:e.bottom:this.rtl?e.left:e.right}getInlineSize(e){return this.vertical?e.bottom-e.top:e.right-e.left}getBoxSize(e){return this.vertical?e.right-e.left:e.bottom-e.top}getBoxDir(){return this.vertical?-1:1}getInlineDir(){return this.rtl?-1:1}copyFrom(e){this.element=e.element,this.left=e.left,this.top=e.top,this.marginLeft=e.marginLeft,this.marginRight=e.marginRight,this.marginTop=e.marginTop,this.marginBottom=e.marginBottom,this.borderLeft=e.borderLeft,this.borderRight=e.borderRight,this.borderTop=e.borderTop,this.borderBottom=e.borderBottom,this.paddingLeft=e.paddingLeft,this.paddingRight=e.paddingRight,this.paddingTop=e.paddingTop,this.paddingBottom=e.paddingBottom,this.width=e.width,this.height=e.height,this.originX=e.originX,this.originY=e.originY,this.innerShape=e.innerShape,this.exclusions=e.exclusions,this.computedBlockSize=e.computedBlockSize,this.snapWidth=e.snapWidth,this.snapHeight=e.snapHeight,this.vertical=e.vertical,this.rtl=e.rtl,this.borderBoxSizing=e.borderBoxSizing}setVerticalPosition(e,t){this.top=e,this.height=t,T(this.element,"top",`${e}px`),T(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,T(this.element,"left",`${e}px`),T(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getBoxDir(),t)}else this.setVerticalPosition(e,t)}setInlinePosition(e,t){if(this.vertical)if(this.rtl){let i=t+this.marginTop+this.marginBottom+(this.borderBoxSizing?0:this.paddingTop+this.paddingBottom+this.borderTop+this.borderBottom);this.setVerticalPosition(e+i*this.getInlineDir(),t)}else this.setVerticalPosition(e,t);else if(this.rtl){let i=t+this.marginLeft+this.marginRight+(this.borderBoxSizing?0:this.paddingLeft+this.paddingRight+this.borderLeft+this.borderRight);this.setHorizontalPosition(e+i*this.getInlineDir(),t)}else this.setHorizontalPosition(e,t)}clear(){let e=this.element,t;for(;t=e.lastChild;)e.removeChild(t)}getInnerShape(){let e=this.getInnerRect();return this.innerShape?this.innerShape.withOffset(e.x1,e.y1):wa(e.x1,e.y1,e.x2,e.y2)}getInnerRect(){let e=this.originX+this.left+this.getInsetLeft(),t=this.originY+this.top+this.getInsetTop();return new bt(e,t,e+this.width,t+this.height)}getPaddingRect(){let e=this.originX+this.left+this.marginLeft+this.borderLeft,t=this.originY+this.top+this.marginTop+this.borderTop,i=this.paddingLeft+this.width+this.paddingRight,n=this.paddingTop+this.height+this.paddingBottom;return new bt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Lu(e,i.x1,i.y1,i.x2-i.x1,i.y2-i.y1,t)}getOuterRect(){let e=this.originX+this.left,t=this.originY+this.top,i=this.getInsetLeft()+this.width+this.getInsetRight(),n=this.getInsetTop()+this.height+this.getInsetBottom();return new bt(e,t,e+i,t+n)}},is=class extends Kt{constructor(e,t,i,n){super(),this.elem=e,this.context=t,this.rootContentValue=i,this.exprContentListener=n}visitStrInner(e,t){var i;if(!t){if(((i=this.elem.lastChild)==null?void 0:i.nodeType)===3){this.elem.lastChild.textContent+=e;return}t=this.elem.ownerDocument.createTextNode(e)}this.elem.appendChild(t)}visitStr(e){return this.visitStrInner(e.str),null}visitURL(e){if(this.rootContentValue instanceof Qe)this.elem.setAttribute("src",e.url);else{let t=this.elem.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","img");t.setAttribute("src",e.url),this.elem.appendChild(t)}return null}visitSpaceList(e){return this.visitValues(e.values),null}visitExpr(e){let t=e.toExpr(),i=t.evaluate(this.context);if(typeof i=="string"){t instanceof De&&(i=gn(t.scope,new Ft(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof ze&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Dt(e){return e!=null&&e!==X&&e!==b.normal&&e!==b.none&&!K(e)}var Oe=en.FloatReference;function rm(e){switch(e){case"inline":return Oe.INLINE;case"column":return Oe.COLUMN;case"region":return Oe.REGION;case"page":return Oe.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function tn(e){switch(e){case Oe.INLINE:return!1;case Oe.COLUMN:case Oe.REGION:case Oe.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Ml(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=nc(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=ic(e,r,i),o=Mg(s,r);o==="line-left"?e="left":o==="line-right"&&(e="right")}else e==="inside"?e=n==="left"?"right":"left":e==="outside"&&(e=n==="left"?"left":"right");return e!=="left"&&e!=="right"&&($.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var mc=class{constructor(e,t,i,n,r,s){this.nodePosition=e,this.floatReference=t,this.floatSide=i,this.clearSide=n,this.flowName=r,this.floatMinWrapBlock=s,c(this,"order",null),c(this,"id",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())}isAllowedToPrecede(e){return!1}},sm=class{constructor(){c(this,"floats",[]),c(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>hi(t.nodePosition,e.nodePosition))>=0)throw new Error("A page float with the same source node is already registered");{let t=e.order=this.nextOrder();e.id=this.createPageFloatId(t),this.floats.push(e)}}findPageFloatByNodePosition(e){let t=this.floats.findIndex(i=>hi(i.nodePosition,e));return t>=0?this.floats[t]:null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},wc=class{constructor(e,t,i,n,r,s){this.floatReference=e,this.floatSide=t,this.clearSide=i,this.continuations=n,this.area=r,this.continues=s}hasFloat(e){return this.continuations.some(t=>t.float===e)}findNotAllowedFloat(e){for(let t=this.continuations.length-1;t>=0;t--){let i=this.continuations[t].float;if(!i.isAllowedOnContext(e))return i}return null}getOuterShape(){return this.area.getOuterShape(null,null)}getOuterRect(){return this.area.getOuterRect()}getOrder(){let e=this.continuations.map(t=>t.float);return Math.min.apply(null,e.map(t=>t.getOrder()))}shouldBeStashedBefore(e){return this.getOrder()<e.getOrder()}addContinuations(e){e.forEach(t=>{this.continuations.push(t)})}getFlowName(){let e=this.continuations[0].float.flowName;return this.continuations.every(t=>t.float.flowName===e),e}},_l=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&hi(this.nodePosition,e.nodePosition):!1}},Tn=class{constructor(e,t,i,n,r,s,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=r,c(this,"children",[]),c(this,"writingMode"),c(this,"direction"),c(this,"invalidated",!1),c(this,"floatStore"),c(this,"forbiddenFloats",[]),c(this,"floatFragments",[]),c(this,"stashedFloatFragments",[]),c(this,"floatAnchors",{}),c(this,"floatsDeferredToNext",[]),c(this,"floatsDeferredFromPrevious"),c(this,"layoutConstraints",[]),c(this,"locked",!1),e&&e.children.push(this),this.writingMode=s||e&&e.writingMode||b.horizontal_tb,this.direction=o||e&&e.direction||b.ltr,this.floatStore=e?e.floatStore:new sm;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}getParent(e){if(!this.parent)throw new Error(`No PageFloatLayoutContext for ${e}`);return this.parent}getPreviousSiblingOf(e,t,i,n){let r=this.children.indexOf(e);r<0&&(r=this.children.length);for(let s=r-1;s>=0;s--){let o=this.children[s];if(o.floatReference===t&&o.flowName===i&&hi(o.generatingNodePosition,n)||(o=o.getPreviousSiblingOf(null,t,i,n),o))return o}return null}getPreviousSibling(){let e=this,t=this.parent,i;for(;t;){if(i=t.getPreviousSiblingOf(e,this.floatReference,this.flowName,this.generatingNodePosition),i)return i;e=t,t=t.parent}return null}getContainer(e){return!e||e===this.floatReference?this.container:this.getParent(e).getContainer(e)}setContainer(e){this.container=e,this.reattachFloatFragments()}addPageFloat(e){this.floatStore.addPageFloat(e)}getPageFloatLayoutContext(e){return e===this.floatReference?this:this.getParent(e).getPageFloatLayoutContext(e)}findPageFloatByNodePosition(e){return this.floatStore.findPageFloatByNodePosition(e)}forbid(e){let t=e.getId(),i=e.floatReference;i===this.floatReference?this.forbiddenFloats.includes(t)||(this.forbiddenFloats.push(t),new ln().findByFloat(e).forbid(e,this)):this.getParent(i).forbid(e)}isForbidden(e){let t=e.getId(),i=e.floatReference;return i===this.floatReference?this.forbiddenFloats.includes(t):this.getParent(i).isForbidden(e)}addPageFloatFragment(e,t){let i=e.floatReference;i!==this.floatReference?this.getParent(i).addPageFloatFragment(e,t):this.floatFragments.includes(e)||(this.floatFragments.push(e),this.floatFragments.sort((n,r)=>n.getOrder()-r.getOrder())),t||this.invalidate()}removePageFloatFragment(e,t){let i=e.floatReference;if(i!==this.floatReference)this.getParent(i).removePageFloatFragment(e,t);else{let n=this.floatFragments.indexOf(e);if(n>=0){let r=this.floatFragments.splice(n,1)[0],s=r.area&&r.area.element;s&&s.parentNode&&s.parentNode.removeChild(s),t||this.invalidate()}}}findPageFloatFragment(e){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).findPageFloatFragment(e);let t=this.floatFragments.findIndex(i=>i.hasFloat(e));return t>=0?this.floatFragments[t]:null}hasFloatFragments(e){return this.floatFragments.length>0&&(!e||this.floatFragments.some(e))?!0:this.parent?this.parent.hasFloatFragments(e):!1}hasContinuingFloatFragmentsInFlow(e){return this.hasFloatFragments(t=>t.continues&&t.getFlowName()===e)}registerPageFloatAnchor(e,t){this.floatAnchors[e.getId()]=t}collectPageFloatAnchors(){let e=Object.assign({},this.floatAnchors);return this.children.reduce((t,i)=>Object.assign(t,i.collectPageFloatAnchors()),e)}isAnchorAlreadyAppeared(e){if(this.getDeferredPageFloatContinuations().some(i=>i.float.getId()===e))return!0;let t=this.collectPageFloatAnchors()[e];return t&&this.container&&this.container.element?this.container.element.contains(t):!1}deferPageFloat(e){let t=e.float;if(t.floatReference===this.floatReference){let i=this.floatsDeferredToNext.findIndex(n=>n.float===t);i>=0?this.floatsDeferredToNext.splice(i,1,e):this.floatsDeferredToNext.push(e)}else this.getParent(t.floatReference).deferPageFloat(e)}hasPrecedingFloatsDeferredToNext(e,t){if(!t&&e.floatReference!==this.floatReference)return this.getParent(e.floatReference).hasPrecedingFloatsDeferredToNext(e,!1);let i=e.getOrder();return this.floatsDeferredToNext.some(n=>n.float.getOrder()<i&&!e.isAllowedToPrecede(n.float))?!0:this.parent?this.parent.hasPrecedingFloatsDeferredToNext(e,!0):!1}getLastFollowingFloatInFragments(e){let t=e.getOrder(),i=null;if(this.floatFragments.forEach(n=>{n.continuations.forEach(r=>{let s=r.float,o=s.getOrder();o>t&&(!i||o>i.getOrder())&&(i=s)})}),this.parent){let n=this.parent.getLastFollowingFloatInFragments(e);n&&(!i||n.getOrder()>i.getOrder())&&(i=n)}return i}getDeferredPageFloatContinuations(e){e=e||this.flowName;let t=this.floatsDeferredFromPrevious.filter(i=>!e||i.float.flowName===e);return this.parent&&(t=this.parent.getDeferredPageFloatContinuations(e).concat(t)),t.sort((i,n)=>i.float.getOrder()-n.float.getOrder())}getPageFloatContinuationsDeferredToNext(e){e=e||this.flowName;let t=this.floatsDeferredToNext.filter(i=>!e||i.float.flowName===e);return this.parent?this.parent.getPageFloatContinuationsDeferredToNext(e).concat(t):t}getFloatsDeferredToNextInChildContexts(){let e=[],t=[];for(let i=this.children.length-1;i>=0;i--){let n=this.children[i];t.includes(n.flowName)||(t.push(n.flowName),e=e.concat(n.floatsDeferredToNext.map(r=>r.float)),e=e.concat(n.getFloatsDeferredToNextInChildContexts()))}return e}checkAndForbidNotAllowedFloat(){if(this.checkAndForbidFloatFollowingDeferredFloat())return!0;for(let e=this.floatFragments.length-1;e>=0;e--){let t=this.floatFragments[e],i=t.findNotAllowedFloat(this);if(i)return this.locked?this.invalidate():(this.removePageFloatFragment(t),this.forbid(i),this.removeEndFloatFragments(t.floatSide)),!0}return this.floatReference===Oe.REGION&&this.parent.locked?this.parent.checkAndForbidNotAllowedFloat():!1}checkAndForbidFloatFollowingDeferredFloat(){let e=this.getFloatsDeferredToNextInChildContexts(),t=this.floatFragments.reduce((i,n)=>i.concat(n.continuations.map(r=>r.float)),[]);t.sort((i,n)=>n.getOrder()-i.getOrder());for(let i of t){let n=i.getOrder();if(e.some(r=>!i.isAllowedToPrecede(r)&&n>r.getOrder())){if(this.locked)this.invalidate();else{this.forbid(i);let r=this.findPageFloatFragment(i);this.removePageFloatFragment(r)}return!0}}return!1}finish(){if(!this.checkAndForbidNotAllowedFloat()){for(let e=this.floatsDeferredToNext.length-1;e>=0;e--)if(!this.floatsDeferredToNext[e].float.isAllowedOnContext(this)){if(this.locked){this.invalidate();return}this.floatsDeferredToNext.splice(e,1)}this.floatsDeferredFromPrevious.forEach(e=>{this.floatsDeferredToNext.findIndex(t=>e.equals(t))>=0||this.floatFragments.some(t=>t.hasFloat(e.float))||this.floatsDeferredToNext.push(e)})}}hasSameContainerAs(e){return!!this.container&&!!e.container&&this.container.element===e.container.element}invalidate(){this.invalidated=!0,!this.locked&&(this.container&&(this.children.forEach(e=>{this.hasSameContainerAs(e)&&e.floatFragments.forEach(t=>{let i=t.area.element;i&&i.parentNode&&i.parentNode.removeChild(i)})}),this.container.clear()),this.children.forEach(e=>{e.layoutConstraints.splice(0)}),this.children.splice(0),Object.keys(this.floatAnchors).forEach(e=>{delete this.floatAnchors[e]}))}detachChildren(){let e=this.children.splice(0);return e.forEach(t=>{t.floatFragments.forEach(i=>{let n=i.area.element;n&&n.parentNode&&n.parentNode.removeChild(n)})}),e}attachChildren(e){e.forEach(t=>{this.children.push(t),t.reattachFloatFragments()})}isInvalidated(){return this.invalidated||!!this.parent&&this.parent.isInvalidated()}validate(){this.invalidated=!1}toLogical(e){let t=this.writingMode.toString(),i=this.direction.toString();if(e==="inside"||e==="outside"){let n=!!this.container.element.closest("[data-vivliostyle-page-side='left']");e=e==="inside"?n?"right":"left":n?"left":"right"}return nc(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return ic(e,t,i)}toLogicalFloatSides(e){let t=e.split(" "),i=[];for(let o of t){let a=this.toLogical(o);i.includes(a)||i.push(a)}let n=[],r=!1,s=!1;for(let o=0;o<i.length;o++){let a=i[o];a.includes("block")?r||(i.slice(o+1).some(l=>l.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(l=>l.includes("inline"))?(n.push("snap-inline"),s=!0):n.push(a)))}return n}removeEndFloatFragments(e){let t=this.toLogicalFloatSides(e)[0];if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogicalFloatSides(n.floatSide)[0]===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogicalFloatSides(e.floatSide)[0];if(i==="block-end"||i==="snap-block"||i==="inline-end"||i==="snap-inline"){let n=0;for(;n<this.floatFragments.length;){let r=this.floatFragments[n],s=this.toLogicalFloatSides(r.floatSide)[0];(s===i||i==="snap-block"&&s==="block-end"||i==="snap-inline"&&s==="inline-end")&&r.shouldBeStashedBefore(e)?(this.stashedFloatFragments.push(r),this.floatFragments.splice(n,1)):n++}}}restoreStashedFragments(e){if(e!==this.floatReference){this.getParent(e).restoreStashedFragments(e);return}this.stashedFloatFragments.forEach(t=>{this.addPageFloatFragment(t,!0)}),this.stashedFloatFragments.splice(0)}discardStashedFragments(e){if(e!==this.floatReference){this.getParent(e).discardStashedFragments(e);return}this.stashedFloatFragments.splice(0)}getStashedFloatFragments(e){return e===this.floatReference?this.stashedFloatFragments.concat().sort((t,i)=>i.getOrder()-t.getOrder()):this.getParent(e).getStashedFloatFragments(e)}getLimitValue(e,t,i,n,r){this.container;let s=this.toLogical(e),o=this.toPhysical(e),a=t&&this.toLogical(t),l=t&&this.toPhysical(t),h=this.getLimitValueInner(s,a,i,n,r);if(this.parent&&this.parent.container){let u=this.parent.getLimitValue(o,l,i,n,r);switch(o){case"top":return Math.max(h,u);case"left":return Math.max(h,u);case"bottom":return Math.min(h,u);case"right":return Math.min(h,u);default:}}return h}getLimitValueInner(e,t,i,n,r){this.container;let s=this.getLimitValuesInner(i,n,r,e,t);switch(e){case"block-start":return this.container.vertical?s.right:s.top;case"block-end":return this.container.vertical?s.left:s.bottom;case"inline-start":return this.container.vertical?this.container.rtl?s.bottom:s.top:this.container.rtl?s.right:s.left;case"inline-end":return this.container.vertical?this.container.rtl?s.top:s.bottom:this.container.rtl?s.left:s.right;default:throw new Error(`Unknown logical side: ${e}`)}}getLimitValuesInner(e,t,i,n,r){this.container;let s=this.container.originX,o=this.container.originY,a=this.container.getPaddingRect(),l={top:a.y1-o,left:a.x1-s,bottom:a.y2-o,right:a.x2-s,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function h(d,p,f){return d.unit==="%"?f*d.num/100:e.convertLengthToPx(d,p,t)}let u=this.floatFragments;return u.length>0&&(l=u.reduce((d,p)=>{if(i&&!i(p,this))return d;let[f,m]=this.toLogicalFloatSides(p.floatSide);if(m&&(n&&m.includes("block")===n.includes("block")&&m!==n||r&&m.includes("block")===r.includes("block")&&m!==r))return d;let g=p.area,w=p.continuations[0].float.floatMinWrapBlock,v=d.top,y=d.left,C=d.bottom,E=d.right,A=d.floatMinWrapBlockStart,H=d.floatMinWrapBlockEnd;switch(f){case"inline-start":g.vertical?v=Math.max(v,g.top+g.height):y=Math.max(y,g.left+g.width);break;case"block-start":g.vertical?(w&&g.left<E&&(A=h(w,g.rootViewNodes[0],a.x2-a.x1)),E=Math.min(E,g.left)):(w&&g.top+g.height>v&&(A=h(w,g.rootViewNodes[0],a.y2-a.y1)),v=Math.max(v,g.top+g.height));break;case"inline-end":g.vertical?C=Math.min(C,g.top):E=Math.min(E,g.left);break;case"block-end":g.vertical?(w&&g.left+g.width>y&&(H=h(w,g.rootViewNodes[0],a.x2-a.x1)),y=Math.max(y,g.left+g.width)):(w&&g.top<C&&(H=h(w,g.rootViewNodes[0],a.y2-a.y1)),C=Math.min(C,g.top));break;default:throw new Error(`Unknown logical float side: ${f}`)}return{top:v,left:y,bottom:C,right:E,floatMinWrapBlockStart:A,floatMinWrapBlockEnd:H}},l)),l.left+=s,l.right+=s,l.top+=o,l.bottom+=o,l}setFloatAreaDimensions(e,t,i,n,r,s,o){if(t!==this.floatReference)return this.getParent(t).setFloatAreaDimensions(e,t,i,n,r,s,o);let a=this.toLogicalFloatSides(i);if(a[0]==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(a[0].includes("block")&&!o[a[0]])return null;e.clientLayout;let l=a.find(A=>A.includes("inline")&&o[A==="inline-start"?"inline-end":"inline-start"]),h=a.find(A=>A.includes("block")),u=this.getLimitValue("block-start",l,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",l,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",h,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",h,e.layoutContext,e.clientLayout),m=e.vertical?e.originX:e.originY,g=e.vertical?e.originY:e.originX;u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+m):Math.max(u,e.top+m),d=e.vertical?Math.max(d,e.left+m):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+m);function w(A,H){let V=A(e.bands,H);return V?(e.vertical&&(V=Au(V)),u=e.vertical?Math.min(u,V.x2):Math.max(u,V.y1),d=e.vertical?Math.max(d,V.x1):Math.min(d,V.y2),!0):s}let v,y,C,E;if(r){let A=e.vertical?Kr(new bt(d,p,u,f)):new bt(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(If,A)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Af,A)||(C=(d-u)*e.getBoxDir(),v=C-e.getInsetBefore()-e.getInsetAfter(),E=(f-p)*e.getInlineDir(),y=E-e.getInsetStart()-e.getInsetEnd(),!s&&(v<=0||y<=0)))return null}else{v=e.computedBlockSize,C=v+e.getInsetBefore()+e.getInsetAfter();let A=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let V=this.container.getPaddingRect(),ie=this.container.getBoxDir()*(n-(this.container.vertical?V.x2:V.y1)),ne=this.container.getBoxDir()*((this.container.vertical?V.x1:V.y2)-n-C);ie<=ne?a[0]="block-start":a[0]="block-end"}if(!o[a[0]])if(o["block-end"])a[0]="block-end";else return null}else if(a[0]==="snap-inline")if(n===null)a[0]="inline-start";else if(o["inline-start"])a[0]="inline-start";else if(o["inline-end"])a[0]="inline-end";else return null;if(!s&&A<C)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?y=xa(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,E=y+e.getInsetStart()+e.getInsetEnd();let H=(f-p)*e.getInlineDir();if(!s&&H<E)return null}return u-=m,d-=m,p-=g,f-=g,a.some(A=>A==="inline-start"||A==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,y):(a.some(A=>A==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-E*e.getInlineDir(),y),a.some(A=>A==="block-start"||A==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,v):(a.some(A=>A==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-C*e.getBoxDir(),v),a.join(" ")}getFloatFragmentExclusions(){let e=this.floatFragments.map(t=>t.getOuterShape());return this.parent?this.parent.getFloatFragmentExclusions().concat(e):e}reattachFloatFragments(){let e=this.container.element&&this.container.element.parentNode;e&&this.floatFragments.forEach(t=>{e.appendChild(t.area.element)})}getMaxReachedAfterEdge(){let e=this.getContainer().vertical;return this.floatFragments.reduce((t,i)=>{let n=i.getOuterRect();return e?Math.min(t,n.x1):Math.max(t,n.y2)},e?1/0:0)}getBlockStartEdgeOfBlockEndFloats(){let e=this.getContainer().vertical;return this.floatFragments.filter(t=>t.floatSide==="block-end").reduce((t,i)=>{let n=i.getOuterRect();return e?Math.max(t,n.x2):Math.min(t,n.y1)},e?0:1/0)}getPageFloatClearEdge(e,t){function i(h){return u=>h.isAnchorAlreadyAppeared(u.float.getId())}function n(h,u){return e==="inline-start"&&(h.floatSide.includes("inline-end")||h.floatSide==="block-end")||e==="inline-end"&&(h.floatSide.includes("inline-start")||h.floatSide==="block-start")?!1:h.continuations.some(i(u))}let r=t.getPaddingRect(),s=t.vertical?r.x1:r.y2,o=this;for(;o;){if(o.floatsDeferredToNext.some(i(o)))return s;o=o.parent}function a(h){return h.floatFragments.some(u=>n(u,h))||h.children.some(u=>a(u))}if(e==="column"||e==="region"||e==="page"){for(o=this;o;o=o.parent)if(o.floatReference===e){if(a(o))return s;break}}t.clientLayout;let l=this.getLimitValue("block-start",null,t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",null,t.layoutContext,t.clientLayout,n)*t.getBoxDir()<s*t.getBoxDir()?s:l}getPageFloatPlacementCondition(e,t,i){if(e.floatReference!==this.floatReference)return this.getParent(e.floatReference).getPageFloatPlacementCondition(e,t,i);let n={"block-start":!0,"block-end":!0,"inline-start":!0,"inline-end":!0};if(!i)return n;let r=this.toLogicalFloatSides(t)[0],s=this.toLogical(i),o;s==="all"?o=["block-start","block-end","inline-start","inline-end"]:s==="both"?o=["inline-start","inline-end"]:s==="same"?r==="snap-block"?o=["block-start","block-end"]:o=[r]:o=[s];let a=e.getOrder();function l(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function h(d,p){return d.children.some(f=>f.floatFragments.some(l(p))||h(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(l(p))||u(f,p))}if(i==="column"||i==="region"||i==="page"){for(let d=this;d;d=d.parent)if(d.floatReference===i){(d.floatFragments.some(l(null))||h(d,null))&&(n["block-start"]=!1,n["block-end"]=!1,n["inline-start"]=!1,n["inline-end"]=!1);break}return n}return o.forEach(d=>{switch(d){case"block-start":n[d]=!h(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(l(d));break;default:throw new Error(`Unexpected side: ${d}`)}}),n}getLayoutConstraints(){return(this.parent?this.parent.getLayoutConstraints():[]).concat(this.layoutConstraints)}addLayoutConstraint(e,t){t===this.floatReference?this.layoutConstraints.push(e):this.getParent(t).addLayoutConstraint(e,t)}isColumnFullWithPageFloats(e){let t=e.layoutContext,i=e.clientLayout,n=this,r=null;for(;n&&n.container;){let o=n.getLimitValuesInner(t,i);r?e.vertical?(o.right<r.right&&(r.right=o.right,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.left>r.left&&(r.left=o.left,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):(o.top>r.top&&(r.top=o.top,r.floatMinWrapBlockStart=o.floatMinWrapBlockStart),o.bottom<r.bottom&&(r.bottom=o.bottom,r.floatMinWrapBlockEnd=o.floatMinWrapBlockEnd)):r=o,n=n.parent}let s=Math.max(r.floatMinWrapBlockStart,r.floatMinWrapBlockEnd);return(e.vertical?r.right-r.left:r.bottom-r.top)<=s}getMaxBlockSizeOfPageFloats(){let e=this.getContainer().vertical;return this.floatFragments.length?Math.max.apply(null,this.floatFragments.map(t=>{let i=t.area;return e?i.width:i.height})):0}lock(){this.locked=!0}unlock(){this.locked=!1}isLocked(){return this.locked}},bn=[],ln=class{static register(e){bn.push(e)}findByNodeContext(e){for(let t=bn.length-1;t>=0;t--){let i=bn[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=bn.length-1;t>=0;t--){let i=bn[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},om=class{appliesToNodeContext(e){return tn(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition();return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(o=>{n=o,t.flowName;let a=new mc(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),N(a)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new wc(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};ln.register(new om);var am=wc,yo=class yc extends mc{constructor(t,i,n,r,s){super(t,i,"block-end",null,n,s),this.footnotePolicy=r}isAllowedToPrecede(t){return!(t instanceof yc)}},zl=class extends am{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof yo?!0:this.getOrder()<e.getOrder()}},lm=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!hi(t,this.footnote.nodePosition)}},hm=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof yo}createPageFloat(e,t,i){let n=Oe.REGION,r=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Oe.PAGE).hasSameContainerAs(r)&&(n=Oe.PAGE);let s=e.toNodePosition();t.flowName;let o=new yo(s,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),N(o)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new zl(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof zl);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;e.vertical=i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n),e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e)}forbid(e,t){let i=e;switch(i.footnotePolicy){case b.line:{let n=new lm(i);t.addLayoutConstraint(n,i.floatReference);break}}}};ln.register(new hm);var um="data-vivliostyle-flow-root";function cm(e){return e.getAttribute(um)==="true"}function Dl(e){let t=e?.toString()||"block",i;switch(t){case"inline-flex":i="flex";break;case"inline-grid":i="grid";break;case"inline-table":i="table";break;case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return F(i)}function Ca(e){return e===b.absolute||e===b.fixed}function bo(e){return e instanceof Ri&&e.name==="running"}function bc(e,t,i,n){return e===b.none||(Ca(t)?(i=b.none,e=Dl(e)):(i&&i!==b.none&&!K(i)||n)&&(e=Dl(e))),{display:e,position:t,float:i}}function vc(e,t,i,n){return bc(e,t,i,n).display===b.block}function bs(e){return e instanceof le||e instanceof J||typeof e=="string"}function Mt(e){if(!bs(e))return!1;let t=e.toString();switch(t){case"inline":case"inline-block":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return t.includes("inline")}}function ki(e){return bs(e)?e.toString().includes("list-item"):!1}function dm(e){if(!bs(e))return!1;switch(e.toString()){case"block":case"flex":case"grid":case"table":case"list-item":case"flow-root":return!0;default:return!1}}function xc(e){if(!bs(e))return!1;switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function pm(e,t,i,n,r,s,o){return r=r||s||b.horizontal_tb,!!o||!!i&&i!==b.none&&!K(i)||Ca(t)||e===b.inline_block||e===b.table_cell||e===b.table_caption||e==b.flex||e==b.grid||e==b.flow_root||(e===b.block||e===b.list_item)&&!!n&&n!==b.visible&&n!==b.clip&&!K(n)||!!s&&r!==s}function fm(e){return e===b.relative||e===b.absolute||e===b.fixed}var Bt=1e5;function ka(e){let t=e.element.style;t.columnGap=`${Bt-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Ea(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Sc(e){return e.element.style.columnCount==="1"}function gm(e){e.element.setAttribute("data-vivliostyle-column","true")}function Vl(e){return e.element.hasAttribute("data-vivliostyle-column")}function qn(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Bt)}function vo(e,t){let i=qn(e,t);if(i===0)return 0;let n=t?e.top:Math.min(Math.abs(e.left),Math.abs(e.right)),r=Math.round(n/Bt),s=r*Bt,o=i*Bt;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=Bt),e.right-=s,e.left-=o):e.left<-Bt/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=Bt),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=Bt),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Cc(e,t){for(let i=0;i<e.length;i++)vo(e[i],t)}function It(e,t,i){var n;let r=e.getElementClientRect(t),s=vo(r,i);if(s===1){let o=e.getElementComputedStyle(t);if(o.display==="table-cell"||t.className==="-vivliostyle-table-cell-container"&&(n=t.parentElement)!=null&&n.parentElement&&(o=e.getElementComputedStyle(t.parentElement.parentElement)).display==="table-cell"){let a=t.closest("[data-vivliostyle-column]"),l=a?.style,h=i?"width":"height",u=l&&parseFloat(l[h]);if(u){let d=u,p=s,f=parseFloat(o.paddingBlockEnd),m=parseFloat(o.borderBlockEndWidth),g=Math.ceil(f+m);for(;g-- >0&&p===s&&--d>0;){l[h]=`${d}px`;let w=e.getElementClientRect(t);if(p=vo(w,i),p<s||p===s&&(i?w.right>r.right:w.top<r.top))return a.setAttribute("data-vivliostyle-column-height-adjusted","true"),w}l[h]=`${u}px`}}}return r}function mm(e,t){var i,n;if(e.nodeType===1){let r=e;((i=r.style)==null?void 0:i.breakAfter)==="column"&&(r.style.breakAfter="")}if(t.nodeType===1){let r=t;((n=r.style)==null?void 0:n.breakBefore)==="column"&&(r.style.breakBefore="")}}function Na(e){for(let t=e.nodeType===1?e:e.parentElement;t;t=t.parentElement){let i=t.style;if(!i||t.hasAttribute("data-vivliostyle-column"))break;if(!isNaN(parseFloat(i.columnCount))||!isNaN(parseFloat(i.columnWidth)))return t;if(i.position==="absolute")break}return null}function wm(e){var t;if(e.nodeType!==1)return;let i=e,n=i.style,r=n?.breakBefore==="column",s=i.previousElementSibling,o=s&&((t=s.style)==null?void 0:t.breakAfter)==="column";if(!r&&!o)return;let a=Na(i);if(!a)return;let l=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:h,direction:u,columnGap:d,fontSize:p}=l,f=h==="vertical-rl"||h==="vertical-lr",m=u==="rtl",g=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),v=i.getBoundingClientRect();(f?v.top>w.bottom+g:m?v.right<w.left-g:v.left>w.right+g)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${Bt}px`)}function Wi(e,t,i,n){let r=e.viewNode;if(!r)return NaN;let s=r.nodeType===1?r:r.parentElement;if(s&&s.namespaceURI==="http://www.w3.org/1999/xhtml"){let o=s.style;if(s.localName==="br"||s.localName==="wbr"||o&&Mt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,l=s.nextSibling;a.removeChild(s),a.insertBefore(s,l)}let o=It(t,s,n);if(o.left===0&&o.top===0&&o.right===0&&o.bottom===0)return NaN;if(o.right>=o.left&&o.bottom>=o.top)return e.after?n?o.left:o.bottom:n?o.right:o.top}return NaN}else{let o=NaN,a=r.ownerDocument.createRange(),l=r.textContent.length;if(!l)return NaN;e.after&&(i+=l),i>=l&&(i=l-1),a.setStart(r,i),a.setEnd(r,i+1);let h=t.getRangeClientRects(a);return Cc(h,n),h=h.filter(u=>u.right>u.left&&u.bottom>u.top),h.length?(n?o=Math.min.apply(null,h.map(u=>u.left)):o=Math.max.apply(null,h.map(u=>u.bottom)),o):NaN}}function xo(e,t,i){let n=Sc(t);n&&Ea(t);let r=t.clientLayout.getElementClientRect(e);n&&ka(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function qi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function kc(e,t){var i;if(e)for(let n=e.lastChild,r=n;n!==t;n=r)r=n.previousSibling,!(n.nodeType===1&&n.hasAttribute("data-vivliostyle-float-box-moved")&&((i=t.style)==null?void 0:i.display)==="inline")&&e.removeChild(n)}var hn="data-adapt-spec";function Pa(e){return!!e.getAttribute(hn)}function Yi(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Pa(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function Ki(e){let t=e?.viewNode;return t?.nodeType===1&&Pa(t)}function ym(e){return e!=="inline"&&(Mt(e)||xc(e))}function Hl(e){var t;for(let i=e.parent;i;i=i.parent)if((i.display!=="inline"||i.vertical!==((t=i.parent)==null?void 0:t.vertical))&&Mt(i.display))return i;return null}var Ta=class{calculateOffset(e){return nn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function nn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var hr=class extends Ta{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,c(this,"overflowIfRepetitiveElementsDropped"),c(this,"isEdgeUpdated",!1),c(this,"edge",0),this.overflowIfRepetitiveElementsDropped=i}findAcceptableBreak(e,t){return this.updateOverflows(e),t<this.getMinBreakPenalty()?null:e.findEdgeBreakPosition(this)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");let e=this.isFirstContentOfRepetitiveElementsOwner()&&!this.overflowIfRepetitiveElementsDropped;return(Jr(this.breakOnEdge)?1:0)+(this.overflows&&!e?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}updateEdge(e){var t;let i=e.calculateClonedPaddingBorder(this.position);if(this.edge=Wi(this.position,e.clientLayout,0,e.vertical)+i,!this.position.after&&!this.position.inline){let n=e.parseComputedLength(e.clientLayout.getElementComputedStyle(this.position.viewNode).marginBlockStart);this.edge-=(e.vertical?-1:1)*n}else if(this.position.after&&((t=this.position.shadowContext)==null?void 0:t.root.id)==="table-cell"){let n=e.element.parentElement,r=n?.closest("table, [style*='display: table;']");if(r){let s=r.style.borderCollapse==="collapse",o=0,a=0;for(let l=n;l;l=l.parentElement){let h=e.clientLayout.getElementComputedStyle(l);if((l===n||l===r&&!s)&&(o+=e.parseComputedLength(h.paddingBlockEnd)),l===r&&!s&&(o+=e.parseComputedLength(h.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(h.borderBlockEndWidth)):(l===n||l===r)&&(a+=e.parseComputedLength(h.borderBlockEndWidth)),l===r)break}this.edge+=(e.vertical?-1:1)*(o+a)}}this.isEdgeUpdated=!0}updateOverflows(e){this.isEdgeUpdated||this.updateEdge(e);let t=this.edge,i=this.calculateOffset(e);this.overflowIfRepetitiveElementsDropped=e.isOverflown(t+(e.vertical?-1:1)*i.minimum),this.overflows=this.position.overflow=e.isOverflown(t+(e.vertical?-1:1)*i.current)}getNodeContext(){return this.position}isFirstContentOfRepetitiveElementsOwner(){let e=this.getNodeContext();if(!e||!e.parent)return!1;let{formattingContext:t}=e.parent;if(!Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},vn=class{find(e){let t=Rt("RESOLVE_LAYOUT_PROCESSOR");for(let i=0;i<t.length;i++){let n=t[i](e);if(n)return n}throw new Error(`No processor found for a formatting context: ${e.getName()}`)}},Zi=class{layout(e,t,i){return t.isFloatNodeContext(e)?t.layoutFloatOrFootnote(e):t.isBreakable(e)?t.layoutBreakableBlock(e):t.layoutUnbreakable(e)}createEdgeBreakPosition(e,t,i,n){return new hr(e.copy(),t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}clearOverflownViewNodes(e,t,i,n){var r;if(!i.viewNode||!i.viewNode.parentNode||i.shadowType===Xt.ShadowType.ROOTLESS&&Ki(i))return;let s=i.viewNode;((r=s.parentElement)==null?void 0:r.localName)==="viv-ts-inner"&&(s=s.parentElement.parentElement);let o=s.parentNode;kc(o,s),n&&o.removeChild(s)}finishBreak(e,t,i,n){let r=i||t.viewNode!=null&&t.viewNode.nodeType==1&&!t.after;return e.clearOverflownViewNodes(t,r),n&&e.layoutContext.processFragmentedBlockEdge(t),N(!0)}},Ia=class{constructor(e){this.parent=e,c(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Aa=new Zi,bm=fo.isInstanceOfBlockFormattingContext;Nt("RESOLVE_FORMATTING_CONTEXT",(e,t,i,n,r,s)=>{let o=e.parent;return!o&&e.formattingContext||o&&e.formattingContext!==o.formattingContext?null:e.establishesBFC||!e.formattingContext&&vc(i,n,r,s)?new Ia(o?o.formattingContext:null):null});Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ia?Aa:null);var Ra=class{constructor(){c(this,"initialBreakPositions",null),c(this,"initialStateOfFormattingContext",null),c(this,"initialPosition"),c(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=O("AbstractLayoutRetryer.tryLayout");this.saveState(e,t);let n=this.resolveLayoutMode(e);return n.doLayout(e,t).then(r=>{let s=n.accept(r,t);s=n.postLayout(r,this.initialPosition,t,s),s?i.finish(r):(this.initialPosition,this.clearNodes(this.initialPosition),this.restoreState(e,t),this.tryLayout(this.initialPosition,t).thenFinish(i))}),i.result()}prepareLayout(e,t){}clearNodes(e){let t=e.viewNode||e.parent.viewNode,i;for(;i=t.lastChild;)t.removeChild(i);let n;for(;n=t.nextSibling;)n.parentNode.removeChild(n)}saveState(e,t){this.initialPosition=e.copy(),this.initialBreakPositions=[].concat(t.breakPositions),this.initialFragmentLayoutConstraints=[].concat(t.fragmentLayoutConstraints),e.formattingContext&&(this.initialStateOfFormattingContext=e.formattingContext.saveState())}restoreState(e,t){t.breakPositions=this.initialBreakPositions,t.fragmentLayoutConstraints=this.initialFragmentLayoutConstraints,e.formattingContext&&e.formattingContext.restoreState(this.initialStateOfFormattingContext)}},vm=class{initialState(e){return{nodeContext:e,atUnforcedBreak:!1,break:!1}}startNonDisplayableNode(e){}afterNonDisplayableNode(e){}startIgnoredTextNode(e){}afterIgnoredTextNode(e){}startNonElementNode(e){}afterNonElementNode(e){}startInlineElementNode(e){}afterInlineElementNode(e){}startNonInlineElementNode(e){}afterNonInlineElementNode(e){}finish(e){}},So=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=O("LayoutIterator");return n.loopWithFrame(r=>{let s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?$e(i.nodeContext.viewNode,i.nodeContext.whitespace)?i.nodeContext.after?s=t.afterIgnoredTextNode(i):s=t.startIgnoredTextNode(i):i.nodeContext.after?s=t.afterNonElementNode(i):s=t.startNonElementNode(i):i.nodeContext.inline?i.nodeContext.after?s=t.afterInlineElementNode(i):s=t.startInlineElementNode(i):i.nodeContext.after?s=t.afterNonInlineElementNode(i):s=t.startNonInlineElementNode(i):i.nodeContext.after?s=t.afterNonDisplayableNode(i):s=t.startNonDisplayableNode(i);let o=(s&&s.isPending()?s:N(!0)).thenAsync(()=>i.break?N(null):this.layoutContext.nextInTree(i.nodeContext,i.atUnforcedBreak));if(o.isPending()){o.then(a=>{i.break?r.breakLoop():(i.nodeContext=a,r.continueLoop())});return}else if(i.break){r.breakLoop();return}else i.nodeContext=o.get()}t.finish(i),r.breakLoop()}).then(()=>{n.finish(i.nodeContext)}),n.result()}},_n=class extends vm{constructor(e){super(),this.leadingEdge=e}startNonInlineBox(e){}endEmptyNonInlineBox(e){}endNonInlineBox(e){}initialState(e){return{nodeContext:e,atUnforcedBreak:!!this.leadingEdge&&e.after,break:!1,leadingEdge:this.leadingEdge,breakAtTheEdge:null,onStartEdges:!1,leadingEdgeContexts:[],lastAfterNodeContext:null}}processForcedBreak(e,t){let i=!e.leadingEdge&&it(e.breakAtTheEdge);if(i){let n=e.nodeContext=e.leadingEdgeContexts[0]||e.nodeContext;n.viewNode.parentNode.removeChild(n.viewNode),t.pageBreakType=e.breakAtTheEdge}return i}saveEdgeAndProcessOverflow(e,t){let i=t.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!0,e.breakAtTheEdge);return i&&(e.nodeContext=(e.lastAfterNodeContext||e.nodeContext).modify(),e.nodeContext.overflow=!0),i}processLayoutConstraint(e,t,i){let n=e.nodeContext,r=!t.allowLayout(n);return r&&(i.checkOverflowAndSaveEdgeAndBreakPosition(e.lastAfterNodeContext,null,!1,e.breakAtTheEdge),n=e.nodeContext=n.modify(),n.overflow=!0),r}startNonElementNode(e){e.onStartEdges=!1}startNonInlineElementNode(e){return e.leadingEdgeContexts.push(e.nodeContext.copy()),e.breakAtTheEdge=rt(e.breakAtTheEdge,e.nodeContext.breakBefore),e.onStartEdges=!0,this.startNonInlineBox(e)}afterNonInlineElementNode(e){let t,i;return e.onStartEdges?(t=this.endEmptyNonInlineBox(e),i=t&&t.isPending()?t:N(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),N(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:N(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=rt(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},Co=[];function xm(){Co=[]}function Ec(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Sm=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Cm=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Nc=class Ir{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Ir.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Ir.fragmentIndices={}}matches(){let t=Ir.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Ec(t.fragmentIndex,this.a,this.b)}};c(Nc,"fragmentIndices",{});var vs=Nc,vr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new vs(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Cm(e)}static buildAnyMatcher(e){return new Sm(e)}},Pc={"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},km=["image-resolution","orphans","widows"];function Em(){return Rt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(km))}var Nm={"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},ko=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Pm=["max-%","min-%","%"],Ul=(()=>{let e=["left","right","top","bottom"],t={width:!0,height:!0,"max-width":!0,"max-height":!0,"min-width":!0,"min-height":!0};for(let i=0;i<ko.length;i++)for(let n=0;n<e.length;n++){let r=ko[i].replace("%",e[n]);t[r]=!0}return t})();function mn(e,t){let i={};for(let n of ko)for(let r in e){let s=n.replace("%",r),o=n.replace("%",e[r]);i[s]=o,i[o]=s}for(let n of Pm)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var Tc=mn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),Ic=mn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Tm=mn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Im=mn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Am=mn({inside:"right",outside:"left"},{}),Rm=mn({inside:"left",outside:"right"},{}),_=class Eo{constructor(t,i){this.value=t,this.priority=i}getBaseValue(){return this}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Eo(i,this.priority)}increaseSpecificity(t){return t==0?this:new Eo(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&zt(i)?this.value:rs(t,this.value,i,n,r)}isEnabled(t){return!0}},No=class Po extends _{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new _(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Po(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Po(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){$.warn(i)}return!1}};function To(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function qt(e,t,i,n){if(e)if(!i)delete e[t];else{let r=e[t];(!r||i.priority>=r.priority)&&(n?i.isEnabled(n)&&(e[t]=i.getBaseValue()):e[t]=i)}}var Ac={"region-id":!0,"fragment-selector-id":!0};function Fm(e){return!!Ac[e]}function Ar(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Ei(e){return e.charAt(0)!=="_"&&!Ac[e]}function zn(e){return!!Pc[e]||zt(e)}function Re(e,t){return e[t]}function Pi(e,t,i){i?e[t]=i:delete e[t]}function kt(e,t){return e[t]}function ur(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Rc=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Fc(e,t){return e[t]}function Lc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function ns(e,t,i,n,r,s,o){var a,l;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(h=>{if(h.id){let u=ur(t,h.styleKey);t=u[h.id],t||(t={},u[h.id]=t)}}),o){let h=Rc(t);t={},h.push({styles:t,matcher:o})}for(let h in i)if(!Ar(h))if(Fm(h)){let u=Fc(i,h),d=Lc(t,h);Array.prototype.push.apply(d,u)}else{let u=Re(i,h);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);qt(t,h,d,e);let p=(l=(a=e.style)==null?void 0:a.validatorSet.shorthands[h])==null?void 0:l.propList;if(p)for(let f of p){let m=new _(X,d.priority);qt(t,f,m,e)}}}function Lm(e,t){let i={};for(let n=0;n<t.length;n++)ns(e,i,t[n],0,null,null,null);return i}function Fa(e,t){if(e.length>0){e.sort((n,r)=>r.getPriority()-n.getPriority());let i=null;for(let n=e.length-1;n>=0;n--)i=e[n],i.chained=t,t=i;return i}return t}var Om=class extends Ai{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Re(this.props,"font-size");if(!e.value.isNumeric())return At.em;let t=e.value;if(!rf(t.unit))throw new Error("Unexpected state");return t.num*At[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Io(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?La(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?rs(this.context,e,this.propName).visit(this):e}};function La(e,t,i){let n=e.unit,r=e.num;return n==="em"?new I(r*t,"px"):n==="rem"?new I(r*i.fontSize(),"px"):n==="rlh"?new I(r*i.rootLineHeight,"px"):e}function Io(e,t,i){e=La(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new I(r/100*t,"px"):new I(r*i.queryUnitSize(n,!1),"px")}var wn=class{apply(e){}mergeWith(e){return new Bm([this,e])}clone(){return this}},xr=class extends wn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},Bm=class Oc extends wn{constructor(t){super(),this.list=t}apply(t){for(let i=0;i<this.list.length;i++)this.list[i].apply(t)}mergeWith(t){return this.list.push(t),this}clone(){return new Oc([].concat(this.list))}},Oa=class extends wn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){ns(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},ve=class extends wn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Mm=class extends ve{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}},_m=class extends ve{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 ve{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}},zm=class extends ve{constructor(e,t){super(),this.ns=e,this.localName=t}apply(e){e.currentLocalName==this.localName&&e.currentNamespace==this.ns&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){if(this.chained){let t=e.nsPrefix[this.ns];t||(t=`ns${e.nsCount++}:`,e.nsPrefix[this.ns]=t);let i=t+this.localName;e.insertInTable(e.nstags,i,this.chained)}return!0}},Dm=class extends ve{constructor(e,t){super(),this.epubTypePatt=e,this.targetLocalName=t}apply(e){let t=e.currentElement;if(t instanceof HTMLAnchorElement&&t.hash&&t.href==t.baseURI.replace(/#.*$/,"")+t.hash){let i=t.hash.substring(1),n=t.ownerDocument.getElementById(i);if(n&&(!this.targetLocalName||n.localName==this.targetLocalName)){let r=n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},Vm=class extends ve{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function xs(e,t,i,n){if(!e)return!1;if(t!==null)return n(e,t,i);for(let r of e.getAttributeNames())if((r===i||r.endsWith(`:${i}`))&&n(e,r===i?"":e.lookupNamespaceURI(r.split(":")[0]),i))return!0;return!1}var Wl=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},Hm=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>t.getAttributeNS(i,n)==this.value)&&this.chained.apply(e)}getPriority(){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?9:0}makePrimary(e){return this.name=="type"&&this.ns=="http://www.idpf.org/2007/ops"?(this.chained&&e.insertInTable(e.epubtypes,this.value,this.chained),!0):!1}},Um=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>!!Nm[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},xn=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){xs(e.currentElement,this.ns,this.name,(t,i,n)=>{var r;return!!((r=t.getAttributeNS(i,n))!=null&&r.match(this.regexp))})&&this.chained.apply(e)}},$m=class extends ve{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Gl=class extends ve{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Wm=class extends ve{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},Fi=class extends ve{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Ec(e,this.a,this.b)}},Gm=class extends Fi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},Ao=class extends Fi{constructor(e,t){super(e,t)}apply(e){let t=e.currentSiblingTypeCounts[e.currentNamespace][e.currentLocalName];this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 5}},Ro=class extends Fi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingOrder;t===null&&(t=e.currentFollowingSiblingOrder=e.currentElement.parentNode.childElementCount-e.currentSiblingOrder+1),this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 4}},Fo=class extends Fi{constructor(e,t){super(e,t)}apply(e){let t=e.currentFollowingSiblingTypeCounts;if(!t[e.currentNamespace]){let i=e.currentElement;do{let n=i.namespaceURI,r=i.localName,s=t[n];s||(s=t[n]={}),s[r]=(s[r]||0)+1}while(i=i.nextElementSibling)}this.matchANPlusB(t[e.currentNamespace][e.currentLocalName])&&this.chained.apply(e)}getPriority(){return 4}},jm=class extends ve{constructor(){super()}apply(e){let t=e.currentElement.firstChild;for(;t;){switch(t.nodeType){case Node.ELEMENT_NODE:return;case Node.TEXT_NODE:if(t.length>0)return}t=t.nextSibling}this.chained.apply(e)}getPriority(){return 4}},Xm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},qm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Ym=class extends ve{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ke=class extends ve{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}},Bc=class Mc extends wn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Mc;return t.applied=this.applied,t}},Ba=class extends ve{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new Bc;for(let t of e)this.firstActions.push(Fa(t,this.checkAppliedAction))}apply(e){for(let t of this.firstActions)if(t.apply(e),this.checkAppliedAction.applied)break;this.checkAppliedAction.applied===this.positive()&&this.chained.apply(e),this.checkAppliedAction.applied=!1}getPriority(){return Math.max(...this.firstActions.map(e=>e instanceof ve?e.getPriority():0))}positive(){return!0}relational(){return!1}},Km=class extends Ba{positive(){return!1}},Zm=class extends Ba{constructor(e){super([]),this.selectorTexts=e}apply(e){for(let t of this.selectorTexts){let i,n;/^\s*[+~]/.test(t)?(n=e.currentElement.parentNode,i=`:scope > :nth-child(${Array.from(n.children).indexOf(e.currentElement)+1}) ${t}`):(n=e.currentElement,i=`:scope ${t}`);try{if(n.querySelector(i)){this.checkAppliedAction.apply(e);break}}catch{}}this.checkAppliedAction.applied&&this.chained.apply(e),this.checkAppliedAction.applied=!1}relational(){return!0}},_c=class extends Fi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new Bc;for(let n of i)this.firstActions.push(Fa(n,this.checkAppliedAction))}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.previousElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.previousElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}matchesSelector(e,t){let i=t.currentElement,n=t.currentNamespace,r=t.currentLocalName,s=t.currentId,o=t.currentClassNames,a=t.currentSiblingOrder;t.currentElement=e,t.currentNamespace=e.namespaceURI||"",t.currentLocalName=e.localName,t.currentId=e.id,t.currentClassNames=e.classList?Array.from(e.classList):[];let l=1,h=e.previousElementSibling;for(;h;)l++,h=h.previousElementSibling;t.currentSiblingOrder=l;for(let d of this.firstActions)if(d.apply(t),this.checkAppliedAction.applied)break;let u=this.checkAppliedAction.applied;return this.checkAppliedAction.applied=!1,t.currentElement=i,t.currentNamespace=n,t.currentLocalName=r,t.currentId=s,t.currentClassNames=o,t.currentSiblingOrder=a,u}getPriority(){return 5}},Jm=class extends _c{constructor(e,t,i){super(e,t,i)}apply(e){for(let r of this.firstActions)if(r.apply(e),this.checkAppliedAction.applied)break;if(!this.checkAppliedAction.applied)return;this.checkAppliedAction.applied=!1;let t=e.currentElement,i=1,n=t.nextElementSibling;for(;n;)this.matchesSelector(n,e)&&i++,n=n.nextElementSibling;this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 4}},Ss=class{constructor(e,t,i){this.condition=e,this.viewConditionId=t,this.viewCondition=i}increment(e){e.increment(this.condition,this.viewCondition)}decrement(e){e.decrement(this.condition,this.viewCondition)}buildViewConditionMatcher(e){return e.buildViewConditionMatcher(this.viewConditionId)}},Qm=class zc extends Ss{constructor(t,i,n){super(t,i,n)}fresh(t){return new zc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0&&this.increment(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):!1}},ew=class Dc extends Ss{constructor(t,i,n){super(t,i,n)}fresh(t){return new Dc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return i==0?this.increment(t):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},tw=class Vc extends Ss{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Vc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired?(this.decrement(t),!0):!1}pop(t,i){return this.fired?(this.decrement(t),!0):(i==0&&(this.fired=!0,this.increment(t)),!1)}},iw=class Hc extends Ss{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new Hc(this.condition,this.viewConditionId,this.buildViewConditionMatcher(t))}push(t,i){return this.fired&&(i==-1?this.increment(t):i==0&&this.decrement(t)),!1}pop(t,i){if(this.fired){if(i==-1)return this.decrement(t),!0;i==0&&this.increment(t)}else i==0&&(this.fired=!0,this.increment(t));return!1}},nw=class{constructor(e,t){this.afterprop=e,this.element=t}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.processPseudoelementProps(this.afterprop,this.element),!0):!1}},rw=class{constructor(e){this.lang=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.lang=this.lang,!0):!1}},sw=class{constructor(e){this.oldQuotes=e}fresh(e){return this}push(e,t){return!1}pop(e,t){return t==0?(e.quotes=this.oldQuotes,!0):!1}},ow=class extends Ai{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new Qe(e):new Qe("about:invalid");case"string":default:return e?new j(e):new j("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof J){let r=e.values[0].values;r.length>=2&&(t=r[1].stringValue()),i=r[0].stringValue()}else i=e.values[0].stringValue();return e.values.length>1?n=this.createValueFromString(e.values[1].stringValue(),t):n=this.createValueFromString(null,t),this.element&&this.element.hasAttribute(i)?this.createValueFromString(this.element.getAttribute(i),t):n}};function Dn(e){if(Dt(e)){if(e instanceof j)return e.stringValue();if(e instanceof J)return e.values.map(t=>Dn(t)).join("")}return""}var Lo=class extends Ai{constructor(e,t,i){super(),this.cascade=e,this.element=t,this.counterResolver=i}visitIdent(e){let t=this.cascade,i=t.quotes,n=Math.floor(i.length/2)-1;switch(e.name){case"open-quote":{let r=i[2*Math.min(n,t.quoteDepth)];return t.quoteDepth++,r}case"close-quote":return t.quoteDepth>0&&t.quoteDepth--,i[2*Math.min(n,t.quoteDepth)+1];case"no-open-quote":return t.quoteDepth++,new j("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new j("")}return e}format(e,t){return this.cascade.counterStyleStore.format(t,e)}visitFuncCounter(e){let t=e[0].toString(),i=e.length>1?e[1].stringValue():"decimal",n=this.cascade.counters[t];if(n&&n.length){let r=n&&n.length&&n[n.length-1]||0;return new j(this.format(r,i))}else{let r=new U(this.counterResolver.getPageCounterVal(t,s=>this.format(s||0,i)));return new J([r])}}visitFuncCounters(e){let t=e[0].toString(),i=e[1].stringValue(),n=e.length>2?e[2].stringValue():"decimal",r=this.cascade.counters[t],s=new oi;if(r&&r.length)for(let a=0;a<r.length;a++)a>0&&s.append(i),s.append(this.format(r[a],n));let o=new U(this.counterResolver.getPageCountersVal(t,a=>{let l=[];if(a.length)for(let u=0;u<a.length;u++)l.push(this.format(a[u],n));let h=s.toString();return h.length&&l.push(h),l.length?l.join(i):this.format(0,n)}));return new J([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new U(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new J([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e[2].stringValue(),s=e.length>3?e[3].stringValue():"decimal",o=new U(this.counterResolver.getTargetCountersVal(i,n,a=>{let l=a.map(h=>this.format(h,s));return l.length?l.join(r):this.format(0,s)}));return new J([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof Qe?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new U(this.counterResolver.getTargetTextVal(i,n));return new J([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new U(this.counterResolver.getNamedStringVal(t,i))}visitFuncElement(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new U(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o;let a=e.length>0?e[0].stringValue():"text",l="";switch(a){case"text":l=this.element.textContent;break;case"before":case"after":case"marker":{let h=kt(this.cascade.currentStyle,"_pseudos"),u=(i=(t=h?.[a])==null?void 0:t.content)==null?void 0:i.value;l=Dn(u)}break;case"first-letter":{let h=kt(this.cascade.currentStyle,"_pseudos"),u=(Dn((r=(n=h?.before)==null?void 0:n.content)==null?void 0:r.value)||this.element.textContent||Dn((o=(s=h?.after)==null?void 0:s.content)==null?void 0:o.value)).match(qr);l=u?u[0]:""}break}return new j(l)}visitFuncLeader(e){let t="";if(e[0]instanceof le)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof j&&(t=e[0].stringValue());return t.length==0?new j(""):new U(new ze(null,()=>t,"viv-leader"))}visitFunc(e){switch(e.name){case"counter":if(e.values.length<=2)return this.visitFuncCounter(e.values);break;case"counters":if(e.values.length<=3)return this.visitFuncCounters(e.values);break;case"target-counter":if(e.values.length<=3)return this.visitFuncTargetCounter(e.values);break;case"target-counters":if(e.values.length<=4)return this.visitFuncTargetCounters(e.values);break;case"target-text":if(e.values.length>=1&&e.values.length<=2)return this.visitFuncTargetText(e.values);break;case"string":if(e.values.length<=2)return this.visitFuncString(e.values);break;case"element":if(e.values.length<=2)return this.visitFuncElement(e.values);break;case"content":if(e.values.length<=1)return this.visitFuncContent(e.values);break;case"leader":if(e.values.length<=1)return this.visitFuncLeader(e.values);break}return e}};function Us(e,t,i){let n;if(e.nodeType===1)n=Array.from(e.getClientRects());else{let r=e.ownerDocument.createRange();r.selectNodeContents(e),n=t.getRangeClientRects(r)}return n.reduce((r,s)=>r+(i==="vertical-rl"||i==="vertical-lr"?s.height:s.width),0)}var aw=(e,t,i)=>{let n=t.filter(l=>l.after&&l.viewNode.nodeType===1&&l.viewNode.getAttribute("data-viv-leader"));for(let l of n){let h=function(k){C==="rtl"?m.textContent=(k.startsWith("\u200F")?"":"\u200F")+k+(k.endsWith("\u200F")?"":"\u200F"):m.textContent=k},u=function(){let k=i.clientLayout.getElementClientRect(g);return y==="vertical-rl"||y==="vertical-lr"?C==="rtl"?k.top-=x:k.bottom+=x:C==="rtl"?k.left-=x:k.right+=x,V.left>k.left||V.right<k.right||V.top>k.top||V.bottom<k.bottom},d=function(){let k,R,L=v.repeat(1e4);if(h(L),u())k=1,R=1e4;else return;for(let D=0;D<16;D++){let W="",q=Math.floor((k+R)/2);for(let Q=0;Q<q;Q++)W+=v;if(h(W),u())R=q;else{if(k==q)return;k=q}}h(v)},p=function(k){let R=0,L=g.parentElement;for(;L&&L!==f.viewNode;)R+=i.getComputedInsets(L)[k],L=L.parentElement;return R};var r=h,s=u,o=d,a=p;let f=l.parent;for(;f&&f.inline;)f=f.parent;let m=l.viewNode,g=m.parentElement,w=g.getAttribute("data-adapt-pseudo"),v=m.getAttribute("data-viv-leader-value"),{writingMode:y,direction:C,marginInlineEnd:E}=i.clientLayout.getElementComputedStyle(g);m.style.marginInlineStart="1px",h(v),g.style.display="inline-block",g.style.textIndent="0";let A=Na(f.viewNode),H=A?.style.columnFill||null;A&&(A.style.columnFill="auto");let V=i.clientLayout.getElementClientRect(f.viewNode),ie=i.clientLayout.getElementClientRect(g),ne=i.parseComputedLength(E),Xe=[],ht=g.parentElement;for(;ht.parentElement&&ht.parentElement!==f.viewNode;)ht=ht.parentElement;let xe=ht.nextSibling;for(;xe;){if(xe.nodeType===1){let k=xe,{display:R,float:L,position:D}=i.clientLayout.getElementComputedStyle(k);if(L!=="none"||D==="absolute"||D==="fixed"){xe=xe.nextSibling;continue}if(Mt(R))Xe.push(k);else if(dm(R))break}else if(xe.nodeType===3){let k=xe;k.length>0&&Xe.push(k)}xe=xe.nextSibling}let x=Xe.reduce((k,R)=>k+Us(R,i.clientLayout,y),0);if(w!=="after"){let k=Us(ht,i.clientLayout,y),R=Us(g,i.clientLayout,y);x+=k-R}y==="vertical-rl"||y==="vertical-lr"?(C==="rtl"?V.top+=ne:V.bottom-=ne,V.top=Math.min(ie.top,V.top),V.bottom=Math.max(ie.bottom,V.bottom)):(C==="rtl"?V.left+=ne:V.right-=ne,V.left=Math.min(ie.left,V.left),V.right=Math.max(ie.right,V.right)),d();let B=i.clientLayout.getElementClientRect(g);C=="rtl"?g.style.float="left":g.style.float="right";let S=i.clientLayout.getElementClientRect(g),P=0;C=="rtl"?y=="vertical-rl"||y=="vertical-lr"?P=B.top-S.top-p("top"):P=B.left-S.left-p("left"):y=="vertical-rl"||y=="vertical-lr"?P=S.bottom-B.bottom-p("bottom"):P=S.right-B.right-p("right"),P-=x,P=Math.max(0,P-.1),g.style.float="",m.style.marginInlineStart=`${P}px`,A&&(H?A.style.columnFill=H:A.style.removeProperty("column-fill"))}};Nt("POST_LAYOUT_BLOCK",aw);var Ma=1/1048576;function Bi(e,t){for(let i in e)t[i]=e[i].clone()}var lw=class Uc{constructor(){c(this,"nsCount",0),c(this,"nsPrefix",{}),c(this,"tags",{}),c(this,"nstags",{}),c(this,"epubtypes",{}),c(this,"classes",{}),c(this,"ids",{}),c(this,"pagetypes",{}),c(this,"order",0)}clone(){let t=new Uc;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Bi(this.tags,t.tags),Bi(this.nstags,t.nstags),Bi(this.epubtypes,t.epubtypes),Bi(this.classes,t.classes),Bi(this.ids,t.ids),Bi(this.pagetypes,t.pagetypes),t.order=this.order,t}insertInTable(t,i,n){let r=t[i];r&&(n=r.mergeWith(n)),t[i]=n}createInstance(t,i,n,r,s,o){return new hw(this,t,i,n,r,s,o)}nextOrder(){return this.order+=Ma}},hw=class{constructor(e,t,i,n,r,s,o){this.context=t,this.counterListener=i,this.counterResolver=n,this.counterStyleStore=s,this.cmykStore=o,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",{}),c(this,"currentElement",null),c(this,"currentElementOffset",null),c(this,"currentStyle",null),c(this,"currentClassNames",null),c(this,"currentLocalName",""),c(this,"currentNamespace",""),c(this,"currentId",""),c(this,"currentXmlId",""),c(this,"currentNSTag",""),c(this,"currentEpubTypes",null),c(this,"currentPageType",null),c(this,"previousPageType",null),c(this,"firstPageType",null),c(this,"pageTypePageCounts",{}),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",{}),c(this,"counterScoping",[{}]),c(this,"quotes"),c(this,"quoteDepth",0),c(this,"lang",""),c(this,"siblingOrderStack",[0]),c(this,"currentSiblingOrder",0),c(this,"siblingTypeCountsStack",[{}]),c(this,"currentSiblingTypeCounts"),c(this,"currentFollowingSiblingOrder",null),c(this,"followingSiblingOrderStack"),c(this,"followingSiblingTypeCountsStack",[{}]),c(this,"currentFollowingSiblingTypeCounts"),c(this,"viewConditions",{}),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=e,this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")],this.currentSiblingTypeCounts=this.siblingTypeCountsStack[0],this.followingSiblingOrderStack=[this.currentFollowingSiblingOrder],this.currentFollowingSiblingTypeCounts=this.siblingTypeCountsStack[0]}pushConditionItem(e){this.stack[this.stack.length-1].push(e)}increment(e,t){this.conditions[e]=(this.conditions[e]||0)+1,t&&(this.viewConditions[e]?this.viewConditions[e].push(t):this.viewConditions[e]=[t])}decrement(e,t){this.conditions[e]--,this.viewConditions[e]&&(this.viewConditions[e]=this.viewConditions[e].filter(i=>i!==t),this.viewConditions[e].length===0&&delete this.viewConditions[e])}buildViewConditionMatcher(e){let t=null;e&&(this.currentElementOffset,t=vr.buildViewConditionMatcher(this.currentElementOffset,e));let i=this.dependentConditions.map(n=>{let r=this.viewConditions[n];return r&&r.length>0?r.length===1?r[0]:vr.buildAnyMatcher([].concat(r)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:vr.buildAllMatcher(i):vr.buildAllMatcher([t].concat(i))}applyAction(e,t){let i=e[t];i&&i.apply(this)}pushRule(e,t,i){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=i,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=e,this.currentNSTag="",this.currentEpubTypes=$s,this.currentPageType=t,this.applyActions()}defineCounter(e,t){let i=this.counterScoping[this.counterScoping.length-1];i||(i={},this.counterScoping[this.counterScoping.length-1]=i),this.counters[e]?(i[e]&&this.counters[e].pop(),this.counters[e].push(t)):this.counters[e]=[t],i[e]=!0}pushCounters(e){var t,i,n,r,s,o,a;let l=b.inline,h=e.display;if(h&&(l=h.evaluate(this.context)),l===b.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.counterScoping.push(null);return}let u=b.inline,d=e.float;d&&(u=d.evaluate(this.context));let p=null,f=null,m=null,g=e["counter-reset"];if(g){let y=g.evaluate(this.context);y&&(p=Bn(y,!0))}let w=e["counter-set"];if(w){let y=w.evaluate(this.context);y&&(m=Bn(y,!1))}let v=e["counter-increment"];if(v){let y=v.evaluate(this.context);y&&(f=Bn(y,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(p||(p={}),p["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),ki(l)&&(f||(f={}),f["list-item"]=(n=f["list-item"])!=null?n:1,/^\s*[-+]?\d/.test((s=(r=this.currentElement)==null?void 0:r.getAttribute("value"))!=null?s:"")&&(m||(m={}),m["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(p||(p={}),p.footnote===void 0&&(p.footnote=0)),u===b.footnote&&(f||(f={}),f.footnote===void 0)){let y=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!y||!(y===b.footnote||y instanceof J&&y.values.includes(b.footnote)))&&(f.footnote=1)}if(p)for(let y in p)this.defineCounter(y,p[y]);if(f)for(let y in f){this.counters[y]||this.defineCounter(y,0);let C=this.counters[y];C[C.length-1]+=f[y]}if(m)for(let y in m)if(!this.counters[y])this.defineCounter(y,m[y]);else{let C=this.counters[y];C[C.length-1]=m[y]}if(ki(l)){let y=this.counters["list-item"],C=y[y.length-1];e["ua-list-item-count"]=new _(new gt(C),0);let E=ur(e,"_pseudos");E.marker||(E.marker={})}this.counterScoping.push(null)}popCounters(){let e=this.counterScoping.pop();if(e)for(let t in e){let i=this.counters[t];i&&(i.length==1?delete this.counters[t]:i.pop())}}setNamedStrings(e){let t=e["string-set"];if(!t)return;t=t.filterValue(new Lo(this,this.currentElement,this.counterResolver));let i=t.value instanceof Ze?t.value.values:[t.value];for(let n of i)if(n instanceof J){let r=n.values[0].stringValue(),s=n.values.slice(1).map(o=>Dn(o)).join("");this.counterResolver.setNamedString(r,s,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof Ri&&t.value.name==="running"){let i=t.value.values[0].stringValue();this.counterResolver.setRunningElement(i,this.currentElementOffset)}}processPseudoelementProps(e,t){this.pushCounters(e);let i=e.content;i&&(e.content=i.filterValue(new Lo(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var r,s,o;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let a=this.code.nsPrefix[this.currentNamespace];a?this.currentNSTag=a+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=t.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=$s;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=$s;let u=Qs(t);u&&(this.stack[this.stack.length-1].push(new rw(this.lang)),this.lang=u.toLowerCase());let d=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let f=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=f[f.length-1],g=m[this.currentNamespace];g||(g=m[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,f.push({});let w=this.followingSiblingOrderStack;w[w.length-1]!==null?this.currentFollowingSiblingOrder=--w[w.length-1]:this.currentFollowingSiblingOrder=null,w.push(null);let v=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=v[v.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,v.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(t);let C=i.quotes,E=null;if(C){let V=C.evaluate(this.context);V&&(E=new sw(this.quotes),V===b.none?this.quotes=[new j(""),new j("")]:V===b.auto||V===b.initial?this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")]:V instanceof J&&(this.quotes=V.values))}this.pushCounters(this.currentStyle);let A=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(d||A){let V={};Object.keys(this.counters).forEach(ie=>{V[ie]=Array.from(this.counters[ie])}),this.counterListener.countersOfId(A,V)}let H=kt(this.currentStyle,"_pseudos");if(H){let V=!0;for(let ie of uw){ie||(V=!1);let ne=H[ie];if(ne)if((ie==="before"||ie==="after")&&!Dt((r=ne.content)==null?void 0:r.value)||ie==="marker"&&!ki((s=Re(this.currentStyle,"display"))==null?void 0:s.value)||(ie==="footnote-call"||ie==="footnote-marker")&&((o=Re(this.currentStyle,"float"))==null?void 0:o.value)!==b.footnote)delete H[ie];else if(V){if(this.processPseudoelementProps(ne,t),ie==="marker")this.processMarkerPseudoelementProps(ne,t,e);else if(ie==="first-letter"&&ne["initial-letter"]){let Xe=ne["initial-letter"].evaluate(this.context);Xe!==b.normal&&!K(Xe)&&(this.currentStyle["--viv-initialLetter"]=new _(Xe,0)),delete ne["initial-letter"]}}else this.stack[this.stack.length-2].push(new nw(ne,t))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),E&&this.stack[this.stack.length-2].push(E)}processMarkerPseudoelementProps(e,t,i){var n,r,s,o,a;if(!Dt((n=e.content)==null?void 0:n.value)&&ki((r=this.currentStyle.display)==null?void 0:r.value)){let l=this.getInheritedPropertyValue("list-style-type",i,t),h=this.getInheritedPropertyValue("list-style-image",i,t);if(h instanceof Qe)e.content=new _(new J([h,new j(" ")]),0);else if(l instanceof j)e.content=new _(l,0);else if(l instanceof le&&l!==b.none){let u=(o=(s=this.currentStyle["ua-list-item-count"])==null?void 0:s.value)==null?void 0:o.num;u!=null&&(e.content=new _(new j(this.counterStyleStore.formatMarker(l.name,u)),0)),e["list-style-type"]=new _(l,0)}}if(!Mt((a=Re(this.currentStyle,"display"))==null?void 0:a.value)){let l=this.getInheritedPropertyValue("list-style-position",i,t);l&&(e["list-style-position"]=new _(l,0))}}getInheritedPropertyValue(e,t,i){var n;for(let s=i;s;s=s.parentElement){let o=(s===this.currentElement?this.currentStyle:t.getStyle(s,!1))[e];if(o){let a=o.evaluate(this.context,e);if(a===b.inherit||a===b.unset||a===b.revert)continue;if(a===b.initial)break;return a}}let r=t.validatorSet;return(n=r?.defaultValues[e])!=null?n:null}applyAttrFilterInner(e,t){for(let i in t)Ei(i)&&!zt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new ow(e),i=this.currentStyle,n=kt(i,"_pseudos");for(let r in n)this.applyAttrFilterInner(t,n[r]);this.applyAttrFilterInner(t,i)}applyVarFilter(e,t,i){var n,r,s;let o=e[0],a=new vw(e,t,i),l=32,h={};for(let u in o)if(Ar(u)){let d=kt(o,u);for(let p in d)this.applyVarFilter([d[p],...e],t,i)}else if(Ei(u)){let d=Re(o,u),p=d.value;for(let f=0;;f++){if(f>=l){p=X;break}let m=p.visit(a);if(a.error){p=X,a.error=!1;break}if(m===p)break;p=m}if(p!==d.value){let f=t.validatorSet,m=(n=f?.shorthands[u])==null?void 0:n.clone();if(m)if(K(p)){for(let g of m.propList){let w=new _(p,d.priority),v=Re(o,g);Pi(h,g,To(this.context,v,w))}delete o[u]}else{let g=gn(t.scope,new Ft(p.toString(),null),"");if(g&&(g.visit(m),!m.error)){for(let w of m.propList){let v=new _((s=(r=m.values[w])!=null?r:f.defaultValues[w])!=null?s:b.initial,d.priority),y=Re(o,w);Pi(h,w,To(this.context,y,v))}delete o[u]}}else o[u]=new _(p,d.priority)}if(h[u]){let f=Re(o,u);f&&f.value!==X&&qt(h,u,f,this.context)}}for(let u in h)o[u]=h[u]}applyCalcFilter(e,t){let i=new Zc(t);for(let n in e)if(Ar(n)){let r=kt(e,n);for(let s in r)this.applyCalcFilter(r[s],t)}else if(Ei(n)&&!zt(n)){let r=Re(e,n),s=r.value.visit(i);s!==r.value&&(e[n]=new _(s,r.priority))}}applyCmykFilter(e,t){let i=new Tu(this.cmykStore);if(this.applyCmykFilterInternal(e,i,""),t){let n=i.getConversions();n&&t.setAttribute("data-viv-device-cmyk",JSON.stringify(n))}}applyCmykFilterInternal(e,t,i){for(let n in e)if(Ar(n)){let r=kt(e,n);for(let s in r)this.applyCmykFilterInternal(r[s],t,`::${s}:`)}else if(Ei(n)&&!zt(n)){let r=Re(e,n),s=r.value.toString();t.reset();let o=r.value.visit(t);o!==r.value&&(t.hadDeviceCmyk()&&t.recordConversion(i+n,s),e[n]=new _(o,r.priority))}}applyActions(){let e;for(e=0;e<this.currentClassNames.length;e++)this.applyAction(this.code.classes,this.currentClassNames[e]);for(e=0;e<this.currentEpubTypes.length;e++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[e]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2];for(e=0;e<i.length;)i[e].push(this,t)?i.splice(e,1):e++}this.isFirst=!0,this.isRoot=!1}pop(){for(let e=1;e>=-1;--e){let t=this.stack[this.stack.length-e-2],i=0;for(;i<t.length;)t[i].pop(this,e)?t.splice(i,1):i++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(e){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}},$s=[],uw=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"],Oo=null;function cw(e){Oo=e}var Yn=class extends ar{constructor(e,t,i,n,r,s,o){super(e,t,o),this.condition=i,this.regionId=r,this.validatorSet=s,c(this,"chain",null),c(this,"specificity",0),c(this,"elementStyle",null),c(this,"conditionCount",0),c(this,"pseudoelement",null),c(this,"footnoteContent",!1),c(this,"cascade"),c(this,"state"),c(this,"viewConditionId",null),c(this,"insideSelectorRule"),c(this,"invalid",!1),this.cascade=n?n.cascade:Oo?Oo.clone():new lw,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Fa(this.chain,e);t!==e&&t.makePrimary(this.cascade)||this.insertNonPrimary(t)}isInsideSelectorRule(e){return this.state!=0?(this.reportAndSkip(e),!0):!1}tagSelector(e,t){!t&&!e||(t&&(this.specificity+=1),t&&e?this.chain.push(new zm(e,t.toLowerCase())):t?this.chain.push(new $l(t.toLowerCase())):this.chain.push(new Vm(e)))}invalidSelector(e){$.warn(e),this.chain.push(new Ke("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof un;e=e.parent)e.parent.invalid=!0}classSelector(e){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by .${e}`);return}this.specificity+=256,this.chain.push(new Mm(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Xm);break;case"disabled":this.chain.push(new qm);break;case"checked":this.chain.push(new Ym);break;case"root":case"scope":this.chain.push(new Wm);break;case"link":this.chain.push(new $l("a")),this.chain.push(new Wl("","href"));break;case"-adapt-href-epub-type":case"href-epub-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${Zt(i)}($|\\s)`),r=t[1];this.chain.push(new Dm(n,r))}else this.chain.push(new Ke(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ke(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new $m(new RegExp(`^${Zt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ke(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=dw[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ke(""));break}case"first-child":this.chain.push(new Gl);break;case"last-child":this.chain.push(new Ro(0,1));break;case"first-of-type":this.chain.push(new Ao(0,1));break;case"last-of-type":this.chain.push(new Fo(0,1));break;case"only-child":this.chain.push(new Gl),this.chain.push(new Ro(0,1));break;case"only-of-type":this.chain.push(new Ao(0,1)),this.chain.push(new Fo(0,1));break;case"empty":this.chain.push(new jm);break;case"before":case"after":case"first-line":case"first-letter":this.pseudoelementSelector(e,t);return;default:this.invalidSelector(`Unknown pseudo-class :${e}`);return}this.specificity+=256}pseudoelementSelector(e,t){switch(e){case"before":case"after":case"first-line":case"first-letter":case"footnote-call":case"footnote-marker":case"marker":case"inner":case"after-if-continues":if(!this.pseudoelement)this.pseudoelement=e;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break;case"first-n-lines":if(t&&t.length==1&&typeof t[0]=="number"){let i=Math.round(t[0]);if(i>0&&i==t[0]){if(!this.pseudoelement)this.pseudoelement=`first-${i}-lines`;else{this.invalidSelector(`Double pseudo-element ::${this.pseudoelement}::${e}`);return}break}}this.chain.push(new Ke(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ke(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new _m(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new Wl(e,t);break;case 39:r=new Hm(e,t,n);break;case 45:!n||n.match(/\s/)?r=new Ke(""):r=new xn(e,t,new RegExp(`(^|\\s)${Zt(n)}($|\\s)`));break;case 44:r=new xn(e,t,new RegExp(`^${Zt(n)}($|-)`));break;case 43:n?r=new xn(e,t,new RegExp(`^${Zt(n)}`)):r=new Ke("");break;case 42:n?r=new xn(e,t,new RegExp(`${Zt(n)}$`)):r=new Ke("");break;case 46:n?r=new xn(e,t,new RegExp(Zt(n))):r=new Ke("");break;case 50:if(n=="supported")r=new Um(e,t);else{this.invalidSelector(`Unsupported :: attr selector op: ${n}`);return}break;default:this.invalidSelector(`Unsupported attr selector: ${i}`);return}this.chain.push(r)}descendantSelector(){let e=`d${Sr++}`;this.processChain(new xr(new Qm(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}childSelector(){let e=`c${Sr++}`;this.processChain(new xr(new ew(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Sr++}`;this.processChain(new xr(new tw(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Sr++}`;this.processChain(new xr(new iw(e,this.viewConditionId,null))),this.chain=[new Ke(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,t){super.error(e,t),this.state==1&&(this.state=0),this.setInvalid()}startStylesheet(e){super.startStylesheet(e),this.state=0}startRuleBody(){this.finishChain(),super.startRuleBody(),this.state==1&&(this.state=0)}endRule(){super.endRule(),this.insideSelectorRule=0}finishChain(){this.chain&&(this.processChain(this.makeApplyRuleAction(this.specificity)),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0)}makeApplyRuleAction(e){let t=this.regionId;return this.footnoteContent&&(t?t="xxx-bogus-xxx":t="footnote"),new Oa(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new No(t,0,this.condition):i=new _(t,0),Lc(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===b.oeb_page_head||t===b.oeb_page_foot)&&(this.simpleProperty("flow-options",new J([b.exclusive,b._static]),i),this.simpleProperty("flow-into",t,i),t=b.block),Rt("SIMPLE_PROPERTY").forEach(s=>{let o=s({name:e,value:t,important:i});e=o.name,t=o.value,i=o.important});let n=(i?this.getImportantSpecificity():this.getBaseSpecificity())+this.cascade.nextOrder(),r=this.condition?new No(t,n,this.condition):new _(t,n);qt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new un(this);break;case"not":i=new pw(this);break;case"where":i=new fw(this);break;case"has":i=new gw(this);break;case"nth-child":t&&t.length>=2&&(i=new Wc(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new mw(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},dw={"nth-child":Gm,"nth-of-type":Ao,"nth-last-child":Ro,"nth-last-of-type":Fo},Sr=0,un=class $c extends Yn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,c(this,"parentChain"),c(this,"chains",[]),c(this,"maxSpecificity",0),c(this,"selectorTexts",[]),this.parentChain=t.chain}nextSelector(){this.chain&&this.chains.push(this.chain),this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.chain=[],this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(this.relational()?new Zm(this.selectorTexts):this.positive()?new Ba(this.chains):new Km(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ke("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(t,i){super.error(t,i),this.chain=null,this.pseudoelement=null,this.viewConditionId=null,this.footnoteContent=!1,this.specificity=0;let n=!1;for(let r=this;r instanceof $c;r=r.parent)if(r.forgiving()){n=!0;break}n||this.owner.popHandler()}pushSelectorText(t){this.chain&&this.relational()&&this.selectorTexts.push(t)}positive(){return!0}increasingSpecificity(){return!0}forgiving(){return!0}relational(){return!1}},pw=class extends un{positive(){return!1}forgiving(){return!1}},fw=class extends un{increasingSpecificity(){return!1}},gw=class extends un{relational(){return!0}},Wc=class extends un{constructor(e,t,i){super(e),this.a=t,this.b=i}endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new _c(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ke("")),this.owner.popHandler()}forgiving(){return!0}},mw=class extends Wc{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new Jm(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ke("")),this.owner.popHandler()}},ww=class extends ar{constructor(e,t){super(e,t,!1)}property(e,t,i){if(this.scope.values[e])this.error(`E_CSS_NAME_REDEFINED ${e}`,this.getCurrentToken());else{let n=e.match(/height|^(top|bottom)$/)?"vh":"vw",r=new nr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},In=class extends ar{constructor(e,t,i,n,r,s){super(e,t,!1),this.condition=i,this.elementStyle=n,this.validatorSet=r,this.ruleType=s,c(this,"order"),this.order=0}property(e,t,i){i?$.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){$.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){$.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Ma;let r=this.condition?new No(t,n,this.condition):new _(t,n);qt(this.elementStyle,e,r)}},yw=class extends Zu{constructor(e,t){super(e),this.validatorSet=t,c(this,"elementStyle",{}),c(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){$.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){$.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Ku:Yu;n+=this.order,this.order+=Ma;let r=new _(t,n);qt(this.elementStyle,e,r)}};function Gc(e,t){let i=Rc(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Bo(e,t,i){Gc(i,n=>{Vn(e,n,t)})}function bw(e,t,i,n){let r=new yw(e,t),s=new Ft(n,r);try{Tg(s,r,i)}catch(o){$.warn(o,"Style attribute parse error:")}return r.elementStyle}function jc(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==b.inherit&&r!==b.revert&&r!==b.unset)return r===b.vertical_rl}return i}function Xc(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==b.inherit&&r!==b.revert&&r!==b.unset)return r===b.rtl}return i}function qc(e,t,i,n,r){let s={};for(let o in e)Ei(o)&&(s[o]=Re(e,o));return Bo(s,t,e),Yc(e,i,n,(o,a)=>{Vn(s,a,t),Bo(s,t,a)}),s}function Yc(e,t,i,n){let r=kt(e,"_regions");if((t||i)&&r){if(i){let s=["footnote"];t?t=t.concat(s):t=s}for(let s of t){let o=r[s];o&&n(s,o)}}}function Vn(e,t,i){for(let n in t)if(Ei(n)){let r=Re(t,n),s=e[n];e[n]=To(i,s,r)}}var Kc=(e,t,i,n,r,s)=>{var o,a;let l=i?n?Tm:Tc:n?Im:Ic,h=r?Am:Rm;for(let u in e){let d=e[u];if(!d)continue;let p=(o=l[u])!=null?o:l[h[u]],f=(a=h[u])!=null?a:h[l[u]],m=p??f,g;if(m){let w=e[m];if(w&&w.priority>d.priority||p&&f&&p!==f&&(m=f,w=e[m],w&&w.priority>d.priority))continue;g=Ul[p]?p:Ul[f]?f:u}else g=u,u.startsWith("text-align")&&(d.value===b.inside||d.value===b.outside)&&(d=new _(r===(d.value===b.inside)?b.right:b.left,d.priority));t[g]=s(u,d)}},vw=class extends Ai{constructor(e,t,i){super(),this.elementStyles=e,this.styler=t,this.element=i}getVarValue(e){var t,i,n,r,s;let o=(t=this.element)!=null?t:this.styler.root;if((i=this.elementStyles)!=null&&i.length){for(let a of this.elementStyles){let l=(n=a[e])==null?void 0:n.value;if(l)return l}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(s=(r=this.styler.getStyle(o,!1))==null?void 0:r[e])==null?void 0:s.value;if(a)return a}return null}visitFunc(e){if(e.name!=="var")return super.visitFunc(e);let t=e.values[0]instanceof le&&e.values[0].name;return!t||!zt(t)?(this.error=!0,X):this.getVarValue(t)||(e.values.length<2?(this.error=!0,X):e.values.length===2?e.values[1]:new Ze(e.values.slice(1)))}},Zc=class extends Ai{constructor(e,t,i,n){super(),this.context=e,this.resolveViewportUnit=t,this.percentRef=i,this.vertical=n}visitFunc(e){let t=super.visitFunc(e);if(e.name!=="calc")return t;let i=t.toString().replace(/^calc\b/,"-epubx-expr");if(/\d(%|em|ex|cap|ch|ic|lh|p?v[whbi]|p?vmin|p?vmax)\W|\Wvar\(\s*--/i.test(i))return t;let n=gn(this.context.rootScope,new Ft(i,null),"");if(n instanceof U)try{let r=n.expr.evaluate(this.context);typeof r=="number"&&!isNaN(r)&&(/\d(px|in|pt|pc|cm|mm|q|rem|rlh)\W/i.test(i)?t=new I(r,"px"):/\d[a-z]/i.test(i)||(t=new gt(r)))}catch(r){$.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&(nu(e.unit)||of(e.unit))?new I(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new I(e.num*this.percentRef/100,"px"):e}};function rs(e,t,i,n,r){try{if(t instanceof U)return t.expr instanceof ze&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Fg(e,t.expr,i);if(t instanceof I||t instanceof Ri||t instanceof J||t instanceof Ze)return t.visit(new Zc(e,!0,n,r))}catch(s){return $.warn(s),X}return t}var jl={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Xl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.none;if(t===b.none)return jl;let i=t instanceof J?t.values:[t],n=Object.create(jl);for(let r of i)if(r instanceof le)switch(r.name){case"first":n.first=!0;break;case"force-end":n.forceEnd=!0,n.allowEnd=!1;break;case"allow-end":n.forceEnd=!1,n.allowEnd=!0;break;case"last":n.last=!0;break}return n}function ql(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var xw={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Yl={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Kl={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Zl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.normal;if(t===b.normal)return Yl;if(t===b.auto)return Kl;let i=t instanceof J?t.values:[t],n=Object.create(Yl);for(let r of i)if(r instanceof le)switch(r.name){case"trim-both":case"trim-auto":return Kl;case"space-all":return xw;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 Ws={ideographAlpha:!1,ideographNumeric:!1},Sw={ideographAlpha:!0,ideographNumeric:!0};function Jl(e){let t=e instanceof Je?e:typeof e=="string"?F(e):b.normal;if(t===b.normal||t===b.auto)return Sw;if(t===b.none)return Ws;let i=t instanceof J?t.values:[t],n=Object.create(Ws);for(let r of i)if(r instanceof le)switch(r.name){case"no-autospace":return Ws;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Ql(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function eh(e){return e?(e=e.toLowerCase(),/^zh\b.*-(hant|tw|hk)\b/.test(e)?"zh-hant":/^zh\b/.test(e)?"zh-hans":/^ja\b/.test(e)?"ja":/^ko\b/.test(e)?"ko":e):null}var Cw=class{getPolyfilledInheritedProps(){return["hanging-punctuation","text-autospace","text-spacing-trim"]}preprocessSingleDocument(e){e.body&&this.preprocessForTextSpacing(e.body)}preprocessForTextSpacing(e){var t;let i=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let n=i.nextNode();n;n=i.nextNode()){if(n.parentElement.namespaceURI!=="http://www.w3.org/1999/xhtml"||((t=n.parentElement.dataset)==null?void 0:t.mathTypeset)==="true")continue;let r=n.textContent.replace(/(?![()\[\]{}])[\p{Ps}\p{Pe}\p{Pf}\p{Pi}、。,.:;、。\u3000]\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(r.length>1){let s=r.length-1;for(let o=0;o<s;o++)n.parentNode.insertBefore(document.createTextNode(r[o]),n);n.textContent=r[s]}}}processGeneratedContent(e,t,i,n,r,s){r=eh(r);let o=Jl(t),a=Zl(i),l=Xl(n);if(ql(l)&&Ql(o,a))return;this.preprocessForTextSpacing(e);let h=e.style.whiteSpace;(s?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let u=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),d=null,p=null;for(let f=u.nextNode();f;f=p){p=u.nextNode();let m=!d,g=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),v=!p;this.processTextSpacing(f,m||g,m,g,w,v,d,p,o,a,l,r,s),d=f}e.style.whiteSpace=h}postLayoutBlock(e,t){var i,n,r,s,o,a,l;let h=!e||e.fragmentIndex===1&&p(),u=h||f();function d(v){var y;if(v?.nodeType!==1)return!1;let C=v;if(C.hasAttribute(hn))return!0;let{position:E,float:A}=(y=C.style)!=null?y:{};return E==="absolute"||E==="fixed"||A&&A!=="none"}function p(){let v=t[0];for(let y=v;;y=y.parent)if(!y||!y.inline){if(y?.fragmentIndex!==1)return!1;break}if(!v.inline)return!0;for(let y=v.viewNode.previousSibling;y;y=y.previousSibling)if(!$e(y,v.whitespace)&&!d(y))return!1;return!0}function f(){var v,y;let C=t[0],E;for(;C&&C.inline&&(E=(v=C.viewNode)==null?void 0:v.previousSibling,!(E&&(E.nodeType===3&&/^[ \t\r\n\f]*$/.test(E.textContent)&&C.whitespace!==lt.PRESERVE&&(E=E.previousSibling),E)));)C=C.parent;for(;E;){if(E.nodeType===1){if(E.localName==="br")return!0;let A=(y=E.style)==null?void 0:y.display;if(A&&A!=="inline")return!/^(inline|ruby)\b/.test(A)}else if(E.nodeType===3){if(C.whitespace===lt.PRESERVE){if(/\n$/.test(E.textContent))return!0}else if(C.whitespace===lt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.textContent))return!0}E=E.lastChild}return!1}let m=-1;for(let v=0;v<t.length;v++){let y=t[v];if(!y.after&&y.inline&&!y.display&&y.parent&&y.viewNode.parentNode&&y.viewNode.nodeType===Node.TEXT_NODE&&!$e(y.viewNode,y.whitespace)){let C=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===lt.PRESERVE){if(/\n$/.test(P.viewNode.textContent))return!0}else if(P.whitespace===lt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.previousElementSibling)==null?void 0:L.localName)==="br")return $e(P.viewNode,P.whitespace)}return!1},E=function(P){var k,R,L;if(((k=P.viewNode)==null?void 0:k.nodeType)===1)return P.viewNode.localName==="br";if(((R=P.viewNode)==null?void 0:R.nodeType)===3){if(P.whitespace===lt.PRESERVE){if(/^\n/.test(P.viewNode.textContent))return!0}else if(P.whitespace===lt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(P.viewNode.textContent))return!0;if(((L=P.viewNode.nextElementSibling)==null?void 0:L.localName)==="br")return $e(P.viewNode,P.whitespace)}return!1};var g=C,w=E;let A=eh((s=(n=(i=y.lang)!=null?i:y.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),H=Jl(y.inheritedProps["text-autospace"]),V=Zl(y.inheritedProps["text-spacing-trim"]),ie=Xl(y.inheritedProps["hanging-punctuation"]);if(ql(ie)&&Ql(H,V)||/\b(flex|grid)\b/.test(y.parent.display))continue;m<0&&(m=v);let ne=null,Xe=null,ht=v===m,xe=v===m&&h,x=v===m&&u,B=!1,S=!1;for(let P=v-1;P>=0;P--){let k=t[P];if(C(k)){x=!0;break}if(!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){ne=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((o=k.viewNode)==null?void 0:o.nodeType)===1&&(k.viewNode.localName==="br"||Ci[k.viewNode.localName]))break;P===0&&(ht=!0,h&&(xe=!0,x=!0))}for(let P=v+1;P<t.length;P++){let k=t[P];if(E(k)){B=!0;break}if(k.viewNode!==y.viewNode&&!k.display&&k.viewNode.nodeType===Node.TEXT_NODE&&k.viewNode.textContent.length>0){Xe=k.viewNode;break}if(k.display&&!/^(inline|ruby)\b/.test(k.display)||((a=k.viewNode)==null?void 0:a.nodeType)===1&&(k.viewNode.localName==="br"||Ci[k.viewNode.localName])){P===t.length-1&&d(k.viewNode)&&(S=!0);break}if(P===t.length-1){B=!0,S=!0;for(let R=k.viewNode.nextSibling;R;R=R.nextSibling)if(!d(R)){S=!1;break}}}if(((l=y.parent)==null?void 0:l.display)==="inline-block"){if(!xe){let P=y.parent.viewNode.firstChild;for(;$e(P,y.whitespace);)P=P.nextSibling;y.viewNode===P&&(xe=!0)}if(!S){let P=y.parent.viewNode.lastChild;for(;$e(P,y.whitespace);)P=P.previousSibling;y.viewNode===P&&(S=!0)}}if(this.processTextSpacing(y.viewNode,ht,xe,x,B,S,ne,Xe,H,V,ie,A,y.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,l,h,u,d,p){let f=e.textContent,m=e.ownerDocument,g=0,w,v,y;function C(){if(t)return!0;if(!o)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;v||(v=m.createRange(),v.selectNode(o));let P=v.getClientRects(),k=P[P.length-1];return k?(g||(g=qn(k,p)),p?S.top<k.top+k.height-S.width||S.left+S.width<k.left+S.width/10||S.left>k.left+k.width-S.width/10:S.left<k.left+k.width-S.height||S.top>k.top+k.height-S.height/10||S.top+S.height<k.top+S.height/10):!1}function E(){if(!a)return!1;w||(w=m.createRange(),w.selectNode(e));let S=w.getClientRects()[0];if(!S)return!1;g||(g=qn(S,p)),y||(y=m.createRange(),y.selectNode(a));let P=y.getClientRects()[0];return P?p?S.top+S.height>P.top+S.width||S.left>P.left+P.width-S.width/10||S.left+S.width<P.left+S.width/10:S.left+S.width>P.left+S.height||S.top+S.height<P.top+S.height/10||S.top>P.top+P.height-S.height/10:!1}let A=!1,H=!1,V=!1,ie=!1,ne;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(ne="viv-ts-open",A=!0,H=!0):s&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(ne="viv-ts-close",A=!0,V=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(ne="viv-ts-close",A=!0,ie=!0):(h.trimStart||h.spaceFirst||h.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(ne="viv-ts-open",A=!0):(h.trimEnd||h.allowEnd||h.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(ne="viv-ts-close",A=!0),A){let S=function(D){let W=parseFloat(m.defaultView.getComputedStyle(D).fontSize)*.7;return(p?D.offsetHeight:D.offsetWidth)>W},P=function(){return p?k.offsetLeft:k.offsetTop};var Xe=S,ht=P;if(e.parentElement.localName==="viv-ts-inner")return 0;let k=m.createElement(ne),R=m.createElement("viv-ts-inner");k.appendChild(R),e.parentNode.insertBefore(k,e),R.appendChild(e);let L=S(R);if(L||H||V||ie){if(ne==="viv-ts-open"){if(H)k.className="viv-hang-first";else if(i||n)h.trimStart?k.className="viv-ts-trim":k.className="viv-ts-space";else if(!(h.trimStart||h.spaceFirst)&&C())k.className="viv-ts-space";else if(h.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&S(o.parentElement)))k.className="viv-ts-trim";else if((h.trimStart||h.spaceFirst)&&C()){let D=P();k.className="viv-ts-auto",D===P()&&!C()&&(k.className="viv-ts-trim")}}else if(ne==="viv-ts-close"){if(V)k.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let D=P();ie?(k.className=L?u.allowEnd&&h.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&D===P()&&(h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-hang-end",D===P()&&(k.className="")):k.className="viv-ts-space")):h.trimEnd?k.className="viv-ts-trim":h.allowEnd?(k.className="viv-ts-auto",D===P()&&(k.className="")):k.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&h.trimAdjacent&&(k.className="viv-ts-trim");else if(ie){let D=E(),W=D&&u.allowEnd;W||(k.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?W&&h.trimEnd?k.className="viv-ts-auto":!W&&!E()?k.className="":!D&&u.allowEnd&&(h.trimEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):(k.className="viv-ts-space",E()||(h.allowEnd?(k.className="viv-ts-auto",E()||(k.className="viv-hang-end")):k.className="viv-hang-end"))):!D&&!E()&&(k.className="")}else if(h.trimEnd||h.allowEnd)if(E())h.allowEnd?k.className="viv-ts-space":k.className="viv-ts-auto";else{let D=P();k.className="viv-ts-auto",D===P()&&(k.className="")}}}}let xe=!1;function x(S){var P;let k=(P=S?.ownerDocument.defaultView)==null?void 0:P.getComputedStyle(S);return!!k&&(k.textOrientation==="upright"||k.textCombineUpright==="all"||k["-webkit-text-combine"]==="horizontal")}function B(S,P){if(S.nodeType===1){let L=m.defaultView.getComputedStyle(S);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let k=S.parentElement;if(k&&!k.contains(P))return B(k,P);if(P.nodeType===1){let L=m.defaultView.getComputedStyle(P);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let R=P.parentElement;return R&&!R.contains(S)?B(S,R):!1}return(l.ideographAlpha||l.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(l.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||l.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&x(o.parentElement))&&!B(o,e)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e),xe=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(l.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||l.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&x(a.parentElement))&&!B(e,a)&&(e.parentNode.insertBefore(m.createElement("viv-ts-thin-sp"),e.nextSibling),xe=!0)),g}registerHooks(){Nt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),Nt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),Nt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},_a=new Cw;_a.registerHooks();function kw(e){_a.preprocessForTextSpacing(e)}function Ew(e,t,i,n,r,s){_a.processGeneratedContent(e,t,i,n,r,s)}var Rr=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Nw=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],za="data-adapt-pseudo";function Ji(e){return e.getAttribute(za)||""}function Mo(e,t){e.setAttribute(za,t)}var th=class{constructor(e,t,i,n,r){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=r,c(this,"contentProcessed",{})}getStyle(e,t){let i=Ji(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=kt(this.style,"_pseudos"),r=n?.[i]||{};if(i.match(/^first-/)&&!r["x-first-pseudo"]){let s=1,o;i=="first-letter"?s=0:(o=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=o[1]-0),r["x-first-pseudo"]=new _(new Le(s),0)}return r}processContent(e,t,i){let n=Ji(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0,n==="marker"&&this.processMarker(e,t,i);let r=t.content;Dt(r)&&(r.visit(new is(e.classList.contains("_viv-marker-outside")&&e.firstElementChild||e,this.context,r,this.exprContentListener)),kw(e))}}processMarker(e,t,i){let n=t.content,r=t["list-style-position"],s=t["list-style-type"];if(Dt(n)){if(n instanceof Qe)t.content=new J([n]);else if(n instanceof j&&s instanceof le){let o=s.name.toLowerCase();if((o==="disc"||o==="circle"||o==="square"||o==="disclosure-open"||o==="disclosure-closed")&&(e.classList.add("_viv-marker-bullet"),o==="disclosure-open"||o==="disclosure-closed")){let a=i.direction==="rtl",l=i.vertical;t.content=new j(o==="disclosure-open"?l?"\u25C2 ":"\u25BE ":l?a?"\u25B4 ":"\u25BE ":a?"\u25C2 ":"\u25B8 ")}}}if(r===b.outside){e.classList.add("_viv-marker-outside");let o=e.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml","span");o.classList.add("_viv-marker-outside-content"),e.appendChild(o);let a=i.inheritedProps["text-spacing-trim"];a&&a!=="space-all"&&(t["text-spacing-trim"]=b.normal),i.inheritedProps["hanging-punctuation"]&&(t["hanging-punctuation"]=b.none)}delete t["list-style-position"],delete t["list-style-type"]}},q0=Qr.isInstanceOfAfterIfContinuesLayoutConstraint,Pw=vs.registerFragmentIndex,Y0=vs.clearFragmentIndices,Tw=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new Da(e,i,t),r=n.getColumn().pageBreakType;return n.getColumn().pageBreakType=null,n.layout(this.createNodePositionForPseudoElement(),!0).thenAsync(()=>{this.styler.contentProcessed["after-if-continues"]=!1,n.getColumn().pageBreakType=r;let s=i.firstChild;return T(s,"display","block"),N(s)})}createNodePositionForPseudoElement(){let e=Rr.createElementNS("http://www.w3.org/1999/xhtml","div");Mo(e,"after-if-continues");let t=this.createShadowContext(e),i={steps:[{node:e,shadowType:t.type,shadowContext:t,nodeShadow:null,shadowSibling:null}],offsetInNode:0,after:!1,preprocessedTextContent:null};return new ui(i)}createShadowContext(e){return new mo(this.sourceNode,e,null,null,null,Xt.ShadowType.ROOTED,this.styler)}},Iw=class Jc{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,c(this,"flagmentLayoutConstraintType","AfterIfContinue")}allowLayout(t,i,n){return!(i&&!t||t&&t.overflow)}nextCandidate(t){return!1}postLayout(t,i,n,r){}finishBreak(t,i){return this.getRepetitiveElements().affectTo(t)?this.afterIfContinues.createElement(i,this.nodeContext).thenAsync(n=>(this.nodeContext.viewNode.appendChild(n),N(!0))):N(!0)}getRepetitiveElements(){return new Aw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Jc?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},Aw=class{constructor(e,t){this.nodeContext=e,this.pseudoElementHeight=t}calculateOffset(e){return this.affectTo(e)?this.pseudoElementHeight:0}calculateMinimumOffset(e){return this.calculateOffset(e)}affectTo(e){if(!e)return!1;let t=e.shadowContext?e.shadowContext.owner:e.sourceNode;if(t===this.nodeContext.sourceNode)return!!e.after;for(let i=t.parentNode;i;i=i.parentNode)if(i===this.nodeContext.sourceNode)return!0;return!1}};function Qc(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return N(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let r=Fw(e,t,n);return t.fragmentLayoutConstraints.push(new Iw(e,i,r)),N(e)})}function ed(e,t){return e.thenAsync(i=>Qc(i,t))}function Rw(e,t){let i=O("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=Qc(n,t);return n=n.parent,r.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function Fw(e,t,i){let n=e.viewNode;n.appendChild(i);let r=xo(i,t,e.vertical);return n.removeChild(i),r}var Lw=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Fr=class extends Ta{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,c(this,"alreadyEvaluated",!1),c(this,"breakNodeContext",null)}findAcceptableBreak(e,t){return t<this.getMinBreakPenalty()?null:(this.alreadyEvaluated||(this.breakNodeContext=e.findBoxBreakPosition(this,t>0),this.alreadyEvaluated=!!this.breakNodeContext||t>0||!!e.pseudoParent),this.breakNodeContext)}getMinBreakPenalty(){return this.penalty}getNodeContext(){return this.alreadyEvaluated?this.breakNodeContext:this.checkPoints[this.checkPoints.length-1]}},ss=class td extends gc{constructor(t,i,n,r,s){super(t),this.layoutContext=i,this.clientLayout=n,this.layoutConstraint=r,this.pageFloatLayoutContext=s,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isFloat",!1),c(this,"isFootnote",!1),c(this,"startEdge",0),c(this,"endEdge",0),c(this,"beforeEdge",0),c(this,"afterEdge",0),c(this,"footnoteEdge",0),c(this,"box",null),c(this,"chunkPositions",null),c(this,"bands",null),c(this,"overflown",!1),c(this,"breakPositions",null),c(this,"pageBreakType",null),c(this,"forceNonfitting",!0),c(this,"leftFloatEdge",0),c(this,"rightFloatEdge",0),c(this,"bottommostFloatTop",0),c(this,"stopAtOverflow",!0),c(this,"lastAfterPosition",null),c(this,"fragmentLayoutConstraints",[]),c(this,"pseudoParent",null),c(this,"nodeContextOverflowingDueToRepetitiveElements",null),c(this,"blockDistanceToBlockEndFloats",NaN),c(this,"breakAtTheEdgeBeforeFloat",null),new.target===td&&gm(this),this.last=t.lastChild,this.viewDocument=t.ownerDocument,s.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(t){return!!t.floatSide&&(!this.isFloat||!!t.parent)}stopByOverflow(t){return this.stopAtOverflow&&!!t&&t.overflow}isOverflown(t){return this.vertical?t<this.footnoteEdge:t>this.footnoteEdge}getExclusions(){let t=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(t)}openAllViews(t){let i=O("openAllViews"),n=t.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let r=n.length-1,s=null;return i.loop(()=>{for(;r>=0;){let o=s,a=n[r];if(s=ts(a,o),r===n.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),r==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(t),s.after=t.after,s.preprocessedTextContent=t.preprocessedTextContent,s.after))break;let l=this.layoutContext.setCurrent(s,r==0&&s.offsetInNode==0);if(r--,l.isPending())return l}return N(!1)}).then(()=>{i.finish(s)}),i.result()}calculateOffsetInNodeForNodeContext(t){return t.preprocessedTextContent?$g(t.preprocessedTextContent,t.offsetInNode):t.offsetInNode}maybePeelOff(t,i){var n,r;if(t.firstPseudo&&t.inline&&!t.after&&t.firstPseudo.count==0&&t.viewNode.nodeType!=1){let s=t.viewNode.textContent,o=s.match(qr),a=o?o[0].length:0;if(!o&&((n=t.sourceNode)==null?void 0:n.nodeType)===3&&((r=t.sourceNode.nextSibling)==null?void 0:r.nodeType)===3&&s===t.sourceNode.textContent){let l=s+t.sourceNode.nextSibling.textContent,h=l.match(qr);if(h){let u=h[0];a=u.length,t.sourceNode.textContent=u,t.viewNode.textContent=u,t.sourceNode.nextSibling.textContent=l.substr(a)}}return this.layoutContext.peelOff(t,a)}return N(t)}buildViewToNextBlockEdge(t,i){let n=!1,r=O("buildViewToNextBlockEdge");return r.loopWithFrame(s=>{var o;if(t.viewNode&&!Ki(t)&&((o=t.viewNode.parentElement)==null?void 0:o.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(i.push(t.copy()),i.length>1e3)){let a=t.viewNode.nodeType===1?t.viewNode:t.viewNode.parentElement,l=this.clientLayout.getElementClientRect(a);if(qn(l,this.vertical)>=2){s.breakLoop();return}}this.maybePeelOff(t,0).then(a=>{let l=a;l!==t&&(t=l,Ki(t)||i.push(t.copy())),this.nextInTree(t).then(h=>{if(t=h,!t){s.breakLoop();return}(n||!this.layoutConstraint.allowLayout(t))&&(n=!0,t=t.modify(),t.overflow=!0),this.isFloatNodeContext(t)&&(tn(t.floatReference)||t.floatSide==="footnote")?this.layoutFloatOrFootnote(t).then(u=>{if(t=u,this.pageFloatLayoutContext.isInvalidated()&&(t=null),!t){s.breakLoop();return}s.continueLoop()}):t.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{r.finish(t)}),r.result()}nextInTree(t,i){let n=this.layoutContext.nextInTree(t,i);return ed(n,this)}buildDeepElementView(t){if(!t.viewNode)return N(t);let i=[],n=t.sourceNode,r=O("buildDeepElementView");return r.loopWithFrame(s=>{t.viewNode&&t.inline&&!Ki(t)?i.push(t.copy()):(i.length>0&&this.postLayoutBlock(t,i),i=[]),this.maybePeelOff(t,0).then(o=>{let a=o;if(a!==t){let l=a;for(;l&&l.sourceNode!=n;)l=l.parent;if(l==null){t=a,s.breakLoop();return}Ki(a)||i.push(a.copy())}this.nextInTree(a).then(l=>{t=l,!t||t.sourceNode==n?s.breakLoop():this.layoutConstraint.allowLayout(t)?s.continueLoop():(t=t.modify(),t.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{i.length>0&&this.postLayoutBlock(t,i),r.finish(t)}),r.result()}createFloat(t,i,n,r){let s=this.viewDocument.createElement("div");return this.vertical?(r>=this.height&&(r-=.1),r<1&&(r=0),T(s,"height",`${n}px`),T(s,"width",`${r}px`)):(n>=this.width&&(n-=.1),n<1&&(n=0),T(s,"width",`${n}px`),T(s,"height",`${r}px`)),T(s,"float",i),T(s,"clear",i),this.element.insertBefore(s,t),s}killFloats(){let t=this.element.firstChild;for(;t;){let i=t.nextSibling;if(t.nodeType==1){let n=t,r=n.style.cssFloat;if(r=="left"||r=="right"||r==="none")this.element.removeChild(n);else break}t=i}}createFloats(){let t=this.element.firstChild,i=this.bands,n=this.vertical?this.getTopEdge():this.getLeftEdge(),r=this.vertical?this.getBottomEdge():this.getRightEdge(),s=null;for(let o of i){let a=o.y2-o.y1;o.left=this.createFloat(t,"left",o.x1-n,a),o.right=this.createFloat(t,"right",r-o.x2,a),o.x1<r&&o.x2>n?s=o:s||T(o.right,"float","none")}if(s){let o=i[i.length-1],a=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==o&&o.y2>=a&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(t,i,n,r){let s;if(t&&qi(t.viewNode))return NaN;if(t&&t.after&&!t.inline&&(s=Wi(t,this.clientLayout,0,this.vertical),!isNaN(s)))return s;t=i[n];let o=r-t.boxOffset;for(;;){if(s=Wi(t,this.clientLayout,o,this.vertical),!isNaN(s))return s;if(o>0){o--;continue}if(n--,n<0)return this.beforeEdge;t=i[n],t.viewNode.nodeType!=1&&(o=t.viewNode.textContent.length)}}parseComputedLength(t){let i=t.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return i?this.clientLayout.adjustLengthValue(parseFloat(i[0])):0}getComputedMargin(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Os(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.marginLeft),n.top=this.parseComputedLength(i.marginTop),n.right=this.parseComputedLength(i.marginRight),n.bottom=this.parseComputedLength(i.marginBottom)),n}getComputedPaddingBorder(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Os(0,0,0,0);return i&&(n.left=this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)),n}getComputedInsets(t){let i=this.clientLayout.getElementComputedStyle(t),n=new Os(0,0,0,0);if(i){if(i.boxSizing=="border-box")return this.getComputedMargin(t);n.left=this.parseComputedLength(i.marginLeft)+this.parseComputedLength(i.borderLeftWidth)+this.parseComputedLength(i.paddingLeft),n.top=this.parseComputedLength(i.marginTop)+this.parseComputedLength(i.borderTopWidth)+this.parseComputedLength(i.paddingTop),n.right=this.parseComputedLength(i.marginRight)+this.parseComputedLength(i.borderRightWidth)+this.parseComputedLength(i.paddingRight),n.bottom=this.parseComputedLength(i.marginBottom)+this.parseComputedLength(i.borderBottomWidth)+this.parseComputedLength(i.paddingBottom)}return n}setComputedInsets(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.marginLeft=this.parseComputedLength(n.marginLeft),i.borderLeft=this.parseComputedLength(n.borderLeftWidth),i.paddingLeft=this.parseComputedLength(n.paddingLeft),i.marginTop=this.parseComputedLength(n.marginTop),i.borderTop=this.parseComputedLength(n.borderTopWidth),i.paddingTop=this.parseComputedLength(n.paddingTop),i.marginRight=this.parseComputedLength(n.marginRight),i.borderRight=this.parseComputedLength(n.borderRightWidth),i.paddingRight=this.parseComputedLength(n.paddingRight),i.marginBottom=this.parseComputedLength(n.marginBottom),i.borderBottom=this.parseComputedLength(n.borderBottomWidth),i.paddingBottom=this.parseComputedLength(n.paddingBottom))}setComputedWidthAndHeight(t,i){let n=this.clientLayout.getElementComputedStyle(t);n&&(i.width=this.parseComputedLength(n.width),i.height=this.parseComputedLength(n.height))}layoutUnbreakable(t){return this.buildDeepElementView(t)}layoutFloat(t){let i=O("layoutFloat"),n=t.viewNode,r=Ml(t.floatSide,t.vertical,t.direction,this.layoutContext.page.side);return T(n,"float","none"),T(n,"display","inline-block"),T(n,"vertical-align","top"),this.buildDeepElementView(t).then(s=>{let o=It(this.clientLayout,n,this.vertical),a=this.getComputedMargin(n),l=new bt(o.left-a.left,o.top-a.top,o.right+a.right,o.bottom+a.bottom),h=this.rtl?this.endEdge:this.startEdge,u=this.rtl?this.startEdge:this.endEdge,d=t.parent;for(;d&&d.inline;)d=d.parent;if(d){let E=d.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"),d.viewNode.appendChild(E);let A=It(this.clientLayout,E,this.vertical);h=Math.max(this.rtl?this.getEndEdge(A):this.getStartEdge(A),h),u=Math.min(this.rtl?this.getStartEdge(A):this.getEndEdge(A),u),d.viewNode.removeChild(E);let H=this.vertical?l.y2-l.y1:l.x2-l.x1;r=="left"?u=Math.max(u,h+H):h=Math.min(h,u-H),d!==t.parent&&!t.firstPseudo&&(d.viewNode.appendChild(n),n.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new bt(h,this.getBoxDir()*this.beforeEdge,u,this.getBoxDir()*this.afterEdge),f=l;this.vertical&&(f=Kr(l));let m=this.getBoxDir();if(f.y1<this.bottommostFloatTop*m){let E=f.y2-f.y1;f.y1=this.bottommostFloatTop*m,f.y2=f.y1+E}Rf(p,this.bands,f,r),this.vertical&&(l=Au(f));let g=this.getComputedInsets(n);T(n,"width",`${l.x2-l.x1-g.left-g.right}px`),T(n,"height",`${l.y2-l.y1-g.top-g.bottom}px`),T(n,"position","absolute"),t.display,T(n,"display",t.display);let w,v=null;if(d&&(d.containingBlockForAbsolute?v=d:v=d.getContainingBlockForAbsolute()),v){let E=v.viewNode.ownerDocument.createElement("div");E.style.position="absolute",v.vertical?E.style.right="0":E.style.left="0",E.style.top="0",v.viewNode.appendChild(E),w=It(this.clientLayout,E,this.vertical),v.viewNode.removeChild(E)}else w={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(v?v.vertical:this.vertical)?T(n,"right",`${w.right-l.x2}px`):T(n,"left",`${l.x1-w.left}px`),T(n,"top",`${l.y1-w.top}px`),t.clearSpacer&&(t.clearSpacer.parentNode.removeChild(t.clearSpacer),t.clearSpacer=null);let y=this.vertical?l.x1:l.y2,C=this.vertical?l.x2:l.y1;!this.isOverflown(y)||this.breakPositions.length==0?(this.killFloats(),p=new bt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Kr(p)),Ff(p,this.bands,f,null,r),this.createFloats(),r=="left"?this.leftFloatEdge=y:this.rightFloatEdge=y,this.bottommostFloatTop=C,this.updateMaxReachedAfterEdge(y),i.finish(s)):(t=t.modify(),t.overflow=!0,i.finish(t))}),i.result()}setupFloatArea(t,i,n,r,s,o){let a=this.pageFloatLayoutContext,l=a.getContainer(i),h=t.element;l.element.parentNode.appendChild(h),t.isFloat=!0,t.originX=l.originX,t.originY=l.originY,t.vertical=l.vertical,t.rtl=l.rtl,t.marginLeft=t.marginRight=t.marginTop=t.marginBottom=0,t.borderLeft=t.borderRight=t.borderTop=t.borderBottom=0,t.paddingLeft=t.paddingRight=t.paddingTop=t.paddingBottom=0,t.exclusions=(l.exclusions||[]).concat(),t.forceNonfitting=!a.hasFloatFragments(),t.innerShape=null;let u=l.getPaddingRect();t.setHorizontalPosition(u.x1-l.originX,u.x2-u.x1),t.setVerticalPosition(u.y1-l.originY,u.y2-u.y1),s.adjustPageFloatArea(t,l,this),t.init();let d=!!a.setFloatAreaDimensions(t,i,n,r,!0,!a.hasFloatFragments(),o);return d?(t.killFloats(),t.init()):l.element.parentNode.removeChild(h),d}createPageFloatArea(t,i,n,r,s){let o=this.element.ownerDocument.createElement("div");T(o,"position","absolute");let a=this.pageFloatLayoutContext.getPageFloatLayoutContext(t.floatReference),l=new Tn(null,Oe.COLUMN,null,this.pageFloatLayoutContext.flowName,t.nodePosition,null,null),h=a.getContainer(),u=new Mw(i,o,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,l,h);return l.setContainer(u),this.setupFloatArea(u,t.floatReference,i,n,r,s)?u:null}layoutSinglePageFloatFragment(t,i,n,r,s,o,a){let l=this.pageFloatLayoutContext;t=(a?a.continuations:[]).concat(t);let h=t[0].float,u=l.getPageFloatPlacementCondition(h,i,n),d=this.createPageFloatArea(h,i,o,s,u),p={floatArea:d,pageFloatFragment:null,newPosition:null};if(!d)return N(p);let f=O("layoutSinglePageFloatFragment"),m=!1,g=0;return f.loopWithFrame(w=>{if(g>=t.length){w.breakLoop();return}let v=t[g],y=new ui(v.nodePosition);d.layout(y,!0).then(C=>{p.newPosition=C,!C||r?(g++,w.continueLoop()):(m=!0,w.breakLoop())})}).then(()=>{if(!m){let w=l.setFloatAreaDimensions(d,h.floatReference,i,o,!1,r,u);if(!w)m=!0;else{let v=s.createPageFloatFragment(t,w,n,d,!!p.newPosition);l.addPageFloatFragment(v,!0),p.pageFloatFragment=v}}f.finish(p)}),f.result()}layoutPageFloatInner(t,i,n,r){let s=this.pageFloatLayoutContext,o=t.float;s.stashEndFloatFragments(o);function a(h,u){u?s.removePageFloatFragment(u,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(o.floatReference),s.deferPageFloat(t)}let l=O("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([t],o.floatSide,o.clearSide,!s.hasFloatFragments(),i,n,r).then(h=>{let u=h.floatArea,d=h.pageFloatFragment,p=h.newPosition;d?this.layoutStashedPageFloats(o.floatReference,[r]).then(f=>{if(f){if(s.addPageFloatFragment(d),s.discardStashedFragments(o.floatReference),p){let m=new _l(o,p.primary);s.deferPageFloat(m)}l.finish(!0)}else a(u,d),l.finish(!1)}):(a(u,d),l.finish(!1))}),l.result()}layoutStashedPageFloats(t,i){let n=this.pageFloatLayoutContext,r=n.getStashedFloatFragments(t),s=[],o=[],a=!1,l=O("layoutStashedPageFloats"),h=0;return l.loopWithFrame(u=>{if(h>=r.length){u.breakLoop();return}let d=r[h];if(i.includes(d)){h++,u.continueLoop();return}let p=new ln().findByFloat(d.continuations[0].float);this.layoutSinglePageFloatFragment(d.continuations,d.floatSide,d.clearSide,!1,p,null).then(f=>{let m=f.floatArea;m&&s.push(m);let g=f.pageFloatFragment;g?(o.push(g),h++,u.continueLoop()):(a=!0,u.breakLoop())})}).then(()=>{a?(o.forEach(u=>{n.removePageFloatFragment(u,!0)}),s.forEach(u=>{let d=u.element;d&&d.parentNode&&d.parentNode.removeChild(d)})):r.forEach(u=>{let d=u.area.element;d&&d.parentNode&&d.parentNode.removeChild(d)}),l.finish(!a)}),l.result()}setFloatAnchorViewNode(t){let i=t.viewNode.parentNode,n=i.ownerDocument.createElement("span");n.setAttribute(hn,"1"),t.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(t,"footnote-call",n),i.appendChild(n),i.removeChild(t.viewNode);let r=t.modify();return r.after=!0,r.viewNode=n,r}resolveFloatReferenceFromColumnSpan(t,i,n){let r=O("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,o=s.getPageFloatLayoutContext(Oe.REGION);return s.getContainer().width<o.getContainer().width&&t===Oe.COLUMN?i===b.auto?this.buildDeepElementView(n.copy()).then(a=>{let l=a.viewNode,h=xa(this.clientLayout,l,["min-content inline size"])["min-content inline size"],u=this.getComputedMargin(l);this.vertical?h+=u.top+u.bottom:h+=u.left+u.right,h>this.width?r.finish(Oe.REGION):r.finish(t)}):i===b.all?r.finish(Oe.REGION):r.finish(t):r.finish(t),r.result()}layoutPageFloat(t){let i=this.pageFloatLayoutContext,n=new ln().findByNodeContext(t),r,s=i.findPageFloatByNodePosition(t.toNodePosition());return s?r=N(s):r=n.createPageFloat(t,i,this),r.thenAsync(o=>{let a=es(t,0),l=this.setFloatAnchorViewNode(t),h=n.findPageFloatFragment(o,i),u=new _l(o,a);if(h&&h.hasFloat(o))return i.registerPageFloatAnchor(o,l.viewNode),N(l);if(i.isForbidden(o)||i.hasPrecedingFloatsDeferredToNext(o))return i.deferPageFloat(u),i.registerPageFloatAnchor(o,l.viewNode),N(l);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let d=Wi(l,this.clientLayout,0,this.vertical);return this.isOverflown(d)?N(l):this.layoutPageFloatInner(u,n,d,h).thenAsync(p=>p?N(null):(i.registerPageFloatAnchor(o,l.viewNode),N(l)))}})}processLineStyling(t,i,n){let r=O("processLineStyling"),s=n.concat([]);n.splice(0,n.length);let o=0,a=t.firstPseudo;return a.count==0&&(a=a.outer),r.loopWithFrame(l=>{if(!a){l.breakLoop();return}let h=this.findLinePositions(s),u=a.count-o;if(h.length<=u){l.breakLoop();return}let d=this.findAcceptableBreakInside(s,h[u-1],!0);if(d==null){l.breakLoop();return}this.finishBreak(d,!1,!1).then(()=>{o+=u,this.layoutContext.peelOff(d,0).then(p=>{t=p,a=t.firstPseudo,s=[],this.buildViewToNextBlockEdge(t,s).then(f=>{i=f,l.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(n,s),r.finish(i)}),r.result()}isLoneImage(t){return t.length!=2&&this.breakPositions.length>0?!1:t[0].sourceNode==t[1].sourceNode&&Ci[t[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(t){let i=0,n=0;for(let r=t.length-1;r>=0;r--){let s=t[r];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let o=this.getComputedMargin(s.viewNode),a=this.vertical?-o.left:o.bottom;a>0?i=Math.max(i,a):n=Math.min(n,a)}return i+n}layoutBreakableBlock(t){let i=O("layoutBreakableBlock"),n=[];return this.buildViewToNextBlockEdge(t,n).then(r=>{let s=n.length-1;if(s<0){i.finish(r);return}this.postLayoutBlock(r,n);let o=this.calculateEdge(r,n,s,n[s].boxOffset),a=!1;if(!r||!qi(r.viewNode)){let h=nn(r,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*h.minimum),this.isOverflown(o+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=r)}r==null&&(o+=this.getTrailingMarginEdgeAdjustment(n)),this.updateMaxReachedAfterEdge(o);let l;t.firstPseudo?l=this.processLineStyling(t,r,n):l=N(r),l.then(h=>{n.length>0&&(this.saveBoxBreakPosition(n),a&&!this.isLoneImage(n)&&h&&(h=h.modify(),h.overflow=!0)),i.finish(h)})}),i.result()}postLayoutBlock(t,i){Rt("POST_LAYOUT_BLOCK").forEach(n=>{n(t,i,this)})}findEndOfLine(t,i,n){let r=this.vertical?t-1:t+1,s=0,o=i[0].boxOffset,a=s,l=i.length-1,h=i[l].boxOffset,u;for(;o<h;){u=o+Math.ceil((h-o)/2),a=s;let d=l;for(;a<d;){let f=a+Math.ceil((d-a)/2);i[f].boxOffset>u?d=f-1:a=f}let p=this.calculateEdge(null,i,a,u);if(this.vertical?p<=r:p>=r){for(h=u-1;i[a].boxOffset==u;)a--;l=a}else n&&this.updateMaxReachedAfterEdge(p),o=u,s=a}return{nodeContext:i[a],index:o,checkPointIndex:a}}findAcceptableBreakInside(t,i,n){var r,s,o;let a=this.findEndOfLine(i,t,!0),l=a.nodeContext;if(a.checkPointIndex===0&&a.index===l.boxOffset)return null;let h=l.viewNode;if(h.nodeType!=1&&((r=h.parentElement)==null?void 0:r.localName)!=="viv-ts-inner"){let u=h;l=this.resolveTextNodeBreaker(l).breakTextNode(u,l,a.index,t,a.checkPointIndex,n)}else{let u=Hl(l);if(u){if(((s=this.breakPositions)==null?void 0:s[0])instanceof Fr&&u!=null&&u.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(l=u;!l.after&&l.inline&&l.parent;){let d=(o=l.viewNode)==null?void 0:o.previousSibling;for(;d&&($e(d,l.parent.whitespace)||Yi(d));)d=d.previousSibling;if(d)break;l=l.parent}}}return this.clearOverflownViewNodes(l,!1),l}resolveTextNodeBreaker(t){return Rt("RESOLVE_TEXT_NODE_BREAKER").reduce((i,n)=>n(t)||i,os.instance)}getRangeBoxes(t,i){let n=[],r=t.ownerDocument.createRange(),s=!1,o=t,a=null,l=!1,h=!0;for(;h;){let u=!0;do{let d=null;o==i&&(i.nodeType===1?h=!(!i.firstChild||s):h=!1);let p=o.nodeType===1?o:null;p?s?s=!1:Pa(p)?u=!l:!p.firstChild||Ci[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||ym(this.clientLayout.getElementComputedStyle(p).display)?(u=!l,u?(p.localName==="ruby"&&o.firstChild&&(o=o.firstChild),r.setStartBefore(o),l=!0,a=o):/^r(uby|tc?)$/.test(p.localName)||(a=o),o.contains(i)&&(h=!1)):d=o.firstChild:(l||(o.parentNode==null?h=!1:(r.setStartBefore(o),l=!0)),a=o),d||(d=o.nextSibling,d||(s=!0,d=o.parentNode)),o=d}while(u&&h);if(l){r.setEndAfter(a);let d=this.clientLayout.getRangeClientRects(r);Cc(d,this.vertical);for(let p=0;p<d.length;p++)n.push(d[p]);l=!1}}return n}findLinePositions(t){let i=[],n=this.getRangeBoxes(t[0].viewNode,t[t.length-1].viewNode);n.sort(this.vertical?Jg:Zg);let r=0,s=0,o=0,a=0,l=0,h=this.getBoxDir();for(;;){if(l<n.length){let u=n[l],d=1;if(a>0){let p=Math.max(this.getBoxSize(u),1);h*this.getBeforeEdge(u)<h*r?d=h*(this.getAfterEdge(u)-r)/p:h*this.getAfterEdge(u)>h*s?d=h*(s-this.getBeforeEdge(u))/p:d=1}if(a==0||d>=.6||d>=.2&&this.getStartEdge(u)>=o-1){o=this.getEndEdge(u),this.vertical?(r=a==0?u.right:Math.max(r,u.right),s=a==0?u.left:Math.min(s,u.left)):(r=a==0?u.top:Math.min(r,u.top),s=a==0?u.bottom:Math.max(s,u.bottom)),a++,l++;continue}}if(a>0&&(i.push(s),a=0),l>=n.length)break}return i.sort(Kh),this.vertical&&i.reverse(),i}calculateClonedPaddingBorder(t){let i=0;for(let n=t;n;n=n.parent)if(!n.inline&&En(n.viewNode)){let r=this.getComputedPaddingBorder(n.viewNode);i+=n.vertical?-r.left:r.bottom,n.display==="table"&&(i+=(n.vertical?-1:1)*n.blockBorderSpacing)}return i}getOffsetByRepetitiveElements(t){let i;return t?i=t.calculateOffset(this):i=nn(null,this.collectElementsOffset()),i.current}findBoxBreakPosition(t,i){let n=this.element.parentNode,r=this.element.nextSibling;n.removeChild(this.element),n.insertBefore(this.element,r);let s=t.checkPoints,o=s[0];for(;o.parent&&o.inline;)o=o.parent;let a,l;i?(a=1,l=1):(a=Math.max((o.inheritedProps.widows||2)-0,1),l=Math.max((o.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(o),u=this.findLinePositions(s),d=this.footnoteEdge-h,p=this.getBoxDir(),f=this.getOffsetByRepetitiveElements(t);d-=p*f;let m=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(m.edge)&&(m.edge=p*(1/0));let g=ai(u.length,C=>{let E=u[C];return this.vertical?E<d||E<=m.edge:E>d||E>=m.edge}),w=g<=0;w&&(g=ai(u.length,C=>this.vertical?u[C]<d:u[C]>d));let v=s[s.length-1].viewNode;if(v?.parentElement.localName==="viv-ts-inner"&&(v=v.parentElement.parentElement),(g===u.length&&v.nextSibling||g>=u.length-1&&v.parentElement.querySelector(".MJXc-display"))&&(a=0),g=Math.min(u.length-a,g),g<l)return null;d=u[g-1];let y;if(w?y=m.checkPoint:y=this.findAcceptableBreakInside(t.checkPoints,d,i),y){let C=this.getAfterEdgeOfBlockContainer(y);!isNaN(C)&&p*(d-C)>0&&(d=C),this.computedBlockSize=p*(d-this.beforeEdge)+f}return y}getAfterEdgeOfBlockContainer(t){let i=t;do i=i.parent;while(i&&i.inline);return i?(i=i.copy().modify(),i.after=!0,Wi(i,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(t){let i=t.findIndex(r=>r.overflow);if(i<0)return{edge:NaN,checkPoint:null};let n=t[i];return{edge:this.calculateEdge(null,t,i,n.boxOffset),checkPoint:n}}findEdgeBreakPosition(t){return this.computedBlockSize=t.computedBlockSize+this.getOffsetByRepetitiveElements(t),t.position}finishBreak(t,i,n){t.formattingContext;let r=new vn().find(t.formattingContext).finishBreak(this,t,i,n);return r||(r=Aa.finishBreak(this,t,i,n)),r}findAcceptableBreakPosition(){let t=null,i=null,n=0,r=0;do{n=r,r=Number.MAX_VALUE;for(let s=this.breakPositions.length-1;s>=0&&!i;--s){t=this.breakPositions[s],i=t.findAcceptableBreak(this,n);let o=t.getMinBreakPenalty();o>n&&(r=Math.min(r,o))}}while(r>n&&!i&&this.forceNonfitting);return{breakPosition:i?t:null,nodeContext:i}}doFinishBreak(t,i,n,r){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!i)return N(t);let s=O("doFinishBreak"),o=!1;if(!t){if(this.forceNonfitting)return $.warn("Could not find any page breaks?!!"),this.skipTailEdges(i).then(a=>{a?(a=a.modify(),a.overflow=!1,this.finishBreak(a,o,!0).then(()=>{s.finish(a)})):s.finish(a)}),s.result();t=n,o=!0,this.computedBlockSize=r}return this.finishBreak(t,o,!0).then(()=>{s.finish(t)}),s.result()}isBreakable(t){for(let i=t;i;i=i.parent)if(Yi(i.viewNode))return!1;if(t.after)return!0;switch(t.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!t.flexContainer}zeroIndent(t){let i=t.toString();return i==""||i=="auto"||!!i.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(t,i){if(!t)return!1;for(let o=t;o;o=o.parent)if(Yi(o.viewNode))return!1;if(qi(t.viewNode))return!1;let n=Wi(t,this.clientLayout,0,this.vertical),r=nn(t,this.collectElementsOffset()),s=this.isOverflown(n+(this.vertical?-1:1)*r.minimum);if(this.isOverflown(n+(this.vertical?-1:1)*r.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=t;else if(i){let o=n+this.getTrailingMarginEdgeAdjustment(i),a=this.footnoteEdge-this.getBoxDir()*r.current;n=this.vertical?Math.min(n,Math.max(o,a)):Math.max(n,Math.min(o,a))}return this.updateMaxReachedAfterEdge(n),s}checkOverflowAndSaveEdgeAndBreakPosition(t,i,n,r){if(!t||qi(t.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(t,i);return(n||!s)&&this.saveEdgeBreakPosition(t,r,s),s}applyClearance(t){if(!t.viewNode.parentNode||t.floatReference!==Oe.INLINE)return!1;let i=this.getComputedMargin(t.viewNode),n=t.viewNode.ownerDocument.createElement("div");this.vertical?(n.style.bottom="0px",n.style.width="1px",n.style.marginRight=`${i.right}px`):(n.style.right="0px",n.style.height="1px",n.style.marginTop=`${i.top}px`),t.viewNode.parentNode.insertBefore(n,t.viewNode);let r=It(this.clientLayout,n,this.vertical),s=this.getBeforeEdge(r),o=this.getBoxDir(),a=t.clearSide==="same"?t.floatSide:t.clearSide,l=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(a)?Ml(a,t.vertical,t.direction,this.layoutContext.page.side):a,h=l==="left"||l==="right"?t.direction==="rtl"==(l==="left")?"inline-end":"inline-start":l,u=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this);switch(l){case"left":u=o*Math.max(u*o,this.leftFloatEdge*o);break;case"right":u=o*Math.max(u*o,this.rightFloatEdge*o);break;default:u=o*Math.max(u*o,Math.max(this.rightFloatEdge*o,this.leftFloatEdge*o))}let d=1/(this.clientLayout.pixelRatio||1);if(s*o+d>u*o)return t.viewNode.parentNode.removeChild(n),!1;{let p=Math.max(1,(u-s)*o);this.vertical?n.style.width=`${p}px`:n.style.height=`${p}px`,r=It(this.clientLayout,n,this.vertical);let f=this.getAfterEdge(r);if(!t.floatSide)if(this.vertical){let m=f-i.right-u;m>0==i.right>=0&&(m+=i.right),n.style.marginLeft=`${m}px`}else{let m=u-(f+i.top);m>0==i.top>=0&&(m+=i.top),n.style.marginBottom=`${m}px`}return t.clearSpacer=n,!0}}isBFC(t){return!!(bm(t)||Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))}skipEdges(t,i,n){var r;let s=t.after?(r=t.parent)==null?void 0:r.formattingContext:t.formattingContext;if(s&&!this.isBFC(s))return N(t);let o=O("skipEdges"),a=!n&&i&&t&&t.after,l=n,h=null,u=[],d=[],p=!1;function f(){return!!n||!i&&it(l)&&!m()}function m(){var w;if(!h||t.floatSide)return!1;for(let v=h;v!=null&&v.parent;v=v.parent){let y=v.after?v.viewNode:(w=v.viewNode)==null?void 0:w.previousSibling;for(;y&&($e(y,v.parent.whitespace)||Yi(y));)y=y.previousSibling;if(y)return!1}return!0}let g=()=>{t=u[0]||t,t.viewNode.parentNode.removeChild(t.viewNode),this.pageBreakType=l};return o.loopWithFrame(w=>{for(var v;t;){t.formattingContext;let y=new vn().find(t.formattingContext);do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if($e(t.viewNode,t.whitespace))break;if(!t.after){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)?(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0):(t=t.modify(),t.breakBefore=l),w.breakLoop();return}}if(!t.after){if(t.floatSide&&(this.breakAtTheEdgeBeforeFloat=Jr(l)?l:null),y&&y.startNonInlineElementNode(t))break;if(t.clearSide&&this.applyClearance(t)&&i&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(t.copy(),l,!1),!t.inline&&!t.repeatOnBreak&&(h?Hl(h):this.breakPositions[this.breakPositions.length-1]instanceof Fr)&&this.saveEdgeBreakPosition(t.copy(),l,!1),!this.isBFC(t.formattingContext)||Ni.isInstanceOfRepetitiveElementsOwnerFormattingContext(t.formattingContext)||this.isFloatNodeContext(t)||t.flexContainer||!t.nodeShadow&&!t.sourceNode.firstElementChild&&$e(t.sourceNode.firstChild,t.whitespace)){u.push(t.copy()),l=rt(l,t.breakBefore),f()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)||!this.layoutConstraint.allowLayout(t))&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}}if(t.viewNode.nodeType!=1)break;let E=t.viewNode.style;if(t.after){t.floatSide&&(l=l??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let A=t.sourceNode;if(A.localName==="svg"||A.localName==="math"||A.getAttribute("data-math-typeset")==="true"){p=!1,h=t.copy(),d.push(h),l=rt(null,t.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l);break}if(t.inline||y&&y.afterNonInlineElementNode(t,this.stopAtOverflow))break;if(p){if(f()){g(),w.breakLoop();return}u=[],i=!1,a=!1,l=null}p=!1,h=t.copy(),d.push(h),l=rt(l,t.breakAfter),E&&!(this.zeroIndent(E.paddingBottom)&&this.zeroIndent(E.borderBottomWidth))&&(d=[h])}else{if(u.push(t.copy()),l=rt(l,t.breakBefore),h&&it(l)&&mm(h.viewNode,t.viewNode),(t.pageType!=((v=t.parent)==null?void 0:v.pageType)||!it(l))&&!this.layoutConstraint.allowLayout(t)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,l),t=t.modify(),t.overflow=!0,this.stopAtOverflow)){w.breakLoop();return}let A=t.viewNode.localName;if(Ci[A]){f()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,l)&&(t=(this.stopAtOverflow&&h||t).modify(),t.overflow=!0),w.breakLoop();return}E&&!(this.zeroIndent(E.paddingTop)&&this.zeroIndent(E.borderTopWidth))&&(a=!1,d=[]),p=!0}}while(!1);let C=this.nextInTree(t,a);if(C.isPending()){C.then(E=>{t=E,w.continueLoop()});return}else t=C.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,d,!this.stopAtOverflow,l)?h&&this.stopAtOverflow&&(t=h.modify(),t.overflow=!0):it(l)&&(this.pageBreakType=l),w.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),o.finish(t)}),o.result()}skipTailEdges(t){let i=t.copy(),n=O("skipEdges"),r=null,s=!1;return n.loopWithFrame(o=>{for(;t;){do{if(!t.viewNode)break;if(t.inline&&t.viewNode.nodeType!=1){if($e(t.viewNode,t.whitespace))break;if(!t.after){it(r)&&(this.pageBreakType=r),o.breakLoop();return}}if(!t.after&&(this.isFloatNodeContext(t)||t.flexContainer)){r=rt(r,t.breakBefore),it(r)&&(this.pageBreakType=r),o.breakLoop();return}if(t.viewNode.nodeType!=1)break;let l=t.viewNode.style;if(t.after){if(s){if(it(r)){this.pageBreakType=r,o.breakLoop();return}r=null}s=!1,r=rt(r,t.breakAfter)}else{r=rt(r,t.breakBefore);let h=t.viewNode.localName;if(Ci[h]){it(r)&&(this.pageBreakType=r),o.breakLoop();return}if(l&&!(this.zeroIndent(l.paddingTop)&&this.zeroIndent(l.borderTopWidth))){o.breakLoop();return}}s=!0}while(!1);let a=this.layoutContext.nextInTree(t);if(a.isPending()){a.then(l=>{t=l,o.continueLoop()});return}else t=a.get()}i=null,o.breakLoop()}).then(()=>{n.finish(i)}),n.result()}layoutFloatOrFootnote(t){return tn(t.floatReference)||t.floatSide==="footnote"?this.layoutPageFloat(t):this.layoutFloat(t)}layoutNext(t,i,n){let r=O("layoutNext");return this.skipEdges(t,i,n||null).then(s=>{if(t=s,!t||this.pageBreakType||this.stopByOverflow(t))r.finish(t);else{let o=t.formattingContext;new vn().find(o).layout(t,this,i).thenFinish(r)}}),r.result()}clearOverflownViewNodes(t,i){if(t)for(let n=t.parent;t;t=n,n=n?n.parent:null){let r=(n||t).formattingContext;new vn().find(r).clearOverflownViewNodes(this,n,t,i),i=!1}}initGeom(){let t=this.element.ownerDocument.createElement("div");t.style.position="absolute",t.style.top=`${this.paddingTop}px`,t.style.right=`${this.paddingRight}px`,t.style.bottom=`${this.paddingBottom}px`,t.style.left=`${this.paddingLeft}px`,this.element.appendChild(t);let i=this.clientLayout.getElementClientRect(t);this.element.removeChild(t);let n=this.originX+this.left+this.getInsetLeft(),r=this.originY+this.top+this.getInsetTop();this.box=new bt(n,r,n+this.width,r+this.height),this.startEdge=i?this.vertical?this.rtl?i.bottom:i.top:this.rtl?i.right:i.left:0,this.endEdge=i?this.vertical?this.rtl?i.top:i.bottom:this.rtl?i.left:i.right:0,this.beforeEdge=i?this.vertical?i.right:i.top:0,this.afterEdge=i?this.vertical?i.left:i.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Tf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],T(this.element,"width",`${this.width}px`),T(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(t,i,n){t.formattingContext;let r=t.copy(),s=new vn().find(t.formattingContext),o=this.calculateClonedPaddingBorder(r),a=s.createEdgeBreakPosition(r,i,n,this.computedBlockSize+o);this.breakPositions.push(a)}saveBoxBreakPosition(t){let i=t[0].breakPenalty;if(i){let r=t[0];for(;r.parent&&r.inline;)r=r.parent;i=r.breakPenalty}let n=new Fr(t,i);this.breakPositions.push(n)}updateMaxReachedAfterEdge(t){if(!isNaN(t)){let i=this.getBoxDir()*(t-this.beforeEdge);this.computedBlockSize=Math.max(i,this.computedBlockSize)}}layout(t,i,n){if(this.chunkPositions.push(t),t.primary.after&&(this.lastAfterPosition=t.primary),this.stopAtOverflow&&this.overflown)return N(t);if(this.isFullWithPageFloats())return t.primary.after&&t.primary.steps.length===1?N(null):N(t);Vl(this)&&ka(this);let r=O("layout");return this.openAllViews(t.primary).then(s=>{let o=null;if(s.viewNode)o=s.copy();else{let l=h=>{h.nodeContext.viewNode&&(o=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",l))};this.layoutContext.addEventListener("nextInTree",l)}let a=new Ow(i,n);a.layout(s,this).then(l=>{if(Vl(this)){let h=this.element.lastElementChild&&this.clientLayout.getElementClientRect(this.element.lastElementChild);h&&qn(h,this.vertical)&&Ea(this)}this.doFinishBreak(l,a.context.overflownNodeContext,o,a.initialComputedBlockSize).then(h=>{let u=null;this.pseudoParent?u=N(null):u=this.doFinishBreakOfFragmentLayoutConstraints(h),u.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){r.finish(null);return}if(!h)r.finish(null);else{this.overflown=!0;let d=new ui(h.toNodePosition());r.finish(d)}})})})}),r.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(t){let i=O("doFinishBreakOfFragmentLayoutConstraints"),n=[].concat(this.fragmentLayoutConstraints);n.sort((s,o)=>s.getPriorityOfFinishBreak()-o.getPriorityOfFinishBreak());let r=0;return i.loop(()=>r<n.length?n[r++].finishBreak(t,this).thenReturn(!0):N(!1)).then(()=>{i.finish(!0)}),i.result()}doLayout(t,i,n){let r=O("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,r.loopWithFrame(o=>{for(;t;){let a=!0;if(this.layoutNext(t,i,n||null).then(l=>{if(i=!1,n=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,t=this.nodeContextOverflowingDueToRepetitiveElements,t.overflow=!0):t=l,this.pageFloatLayoutContext.isInvalidated())o.breakLoop();else if(this.pageBreakType)o.breakLoop();else if(t&&this.stopByOverflow(t)){s=t;let h=this.findAcceptableBreakPosition();t=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),o.breakLoop()}else a?a=!1:o.continueLoop()}),a){a=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),o.breakLoop()}).then(()=>{r.finish({nodeContext:t,overflownNodeContext:s})}),r.result()}redoLayout(){let t=this.chunkPositions,i=this.element.lastChild;for(;i!=this.last;){let a=i.previousSibling;this.element===i.parentNode&&this.layoutContext.isPseudoelement(i)||this.element.removeChild(i),i=a}this.killFloats(),this.init();let n=O("redoLayout"),r=0,s=null,o=!0;return n.loopWithFrame(a=>{if(r<t.length){let l=t[r++];this.layout(l,o).then(h=>{o=!1,h?(s=h,a.breakLoop()):a.continueLoop()});return}a.breakLoop()}).then(()=>{n.finish(s)}),n.result()}saveDistanceToBlockEndFloats(){let t=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();t>0&&isFinite(t)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(t-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let t=[];for(let i=this;i;i=i.pseudoParent)i.fragmentLayoutConstraints.forEach(n=>{if(Ni.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(n)){let r=n.getRepetitiveElements();t.push(r)}if(Qr.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let r=n.getRepetitiveElements();t.push(r)}li.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(r=>{t.push(r)})});return t}},Da=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),this.column=Object.create(e),this.column.element=t,this.column.layoutContext=e.layoutContext.clone(),this.column.stopAtOverflow=!1,this.column.flowRootFormattingContext=i.formattingContext,this.column.pseudoParent=e;let n=this.column.calculateClonedPaddingBorder(i);this.column.footnoteEdge=this.column.footnoteEdge-n;let r=this;this.column.openAllViews=function(s){return ss.prototype.openAllViews.call(this,s).thenAsync(o=>(r.startNodeContexts.push(o.copy()),N(o)))}}layout(e,t){return this.column.layout(e,t)}findAcceptableBreakPosition(e){let t=this.column.findAcceptableBreakPosition();if(e){let i=this.startNodeContexts[0].copy(),n=new hr(i,null,i.overflow,0);if(n.findAcceptableBreak(this.column,0),!t.nodeContext)return{breakPosition:n,nodeContext:i}}return t}finishBreak(e,t,i){return this.column.finishBreak(e,t,i)}doFinishBreakOfFragmentLayoutConstraints(e){this.column.doFinishBreakOfFragmentLayoutConstraints(e)}isStartNodeContext(e){let t=this.startNodeContexts[0];return t.viewNode===e.viewNode&&t.after===e.after&&t.offsetInNode===e.offsetInNode}isLastAfterNodeContext(e){return hi(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},os=class{breakTextNode(e,t,i,n,r,s){if(t.after)t.offsetInNode=e.length;else{let o=i-t.boxOffset,a=e.data;a.charCodeAt(o)==173?o=this.breakAfterSoftHyphen(e,a,o,t):o=this.breakAfterOtherCharacter(e,a,o,t),o>0&&(t=this.updateNodeContext(t,o,e))}return t}breakAfterSoftHyphen(e,t,i,n){let r=/[\u0620\u0626\u0628\u062A-\u062E\u0633-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u07FA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u0883-\u0886\u0889-\u088D\u08A0-\u08A9\u08AF\u08B0\u08B3-\u08B8\u08BA-\u08C8\u1807\u180A\u1820-\u1878\u1887-\u18A8\u18AA\u200D\uA840-\uA871\u{10AC0}-\u{10AC4}\u{10AD3}-\u{10AD6}\u{10AD8}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D01}-\u{10D21}\u{10D23}\u{10EC3}\u{10EC4}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{10F70}-\u{10F73}\u{10F76}-\u{10F81}\u{10FB0}\u{10FB2}\u{10FB3}\u{10FB8}\u{10FBB}\u{10FBC}\u{10FBE}\u{10FBF}\u{10FC1}\u{10FC4}\u{10FCA}\u{1E900}-\u{1E943}]\p{Mn}*$/u.test(t.slice(0,i))?"\u200D":"";if(e.replaceData(i,t.length-i,n.breakWord?"":r+ih(n)),r){let s=n.preprocessedTextContent[0][1];n.preprocessedTextContent[0][1]=s.slice(0,i+1)+r+s.slice(i+1)}return i+1}breakAfterOtherCharacter(e,t,i,n){let r=t.charAt(i);i++;let s=t.charAt(i);return e.replaceData(i,t.length-i,!n.breakWord&&ll(r)&&ll(s)?ih(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(os,"instance");os.instance=new os;function ih(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var Ow=class extends Ra{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new Bw(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||xm()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&kc(i.parentNode,i),t=t.parent}}saveState(e,t){super.saveState(e,t),this.initialPageBreakType=t.pageBreakType,this.initialComputedBlockSize=t.computedBlockSize,this.initialOverflown=t.overflown}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown}},Bw=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=O("DefaultLayoutMode.doLayout");return Rw(e,t).then(()=>{t.doLayout(e,this.leadingEdge,this.breakAfter).then(n=>{this.context.overflownNodeContext=n.overflownNodeContext,i.finish(n.nodeContext)})}),i.result()}accept(e,t){return t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||t.fragmentLayoutConstraints.length<=0?!0:t.fragmentLayoutConstraints.every(i=>i.allowLayout(e,this.context.overflownNodeContext,t))}postLayout(e,t,i,n){return n||(n=!i.fragmentLayoutConstraints.some(r=>r.nextCandidate(e))),i.fragmentLayoutConstraints.forEach(r=>{r.postLayout(n,e,t,i)}),n}},Mw=class extends ss{constructor(e,t,i,n,r,s,o){super(t,i,n,r,s),this.floatSide=e,this.parentContainer=o,c(this,"rootViewNodes",[]),c(this,"floatMargins",[]),c(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),N(t)))}convertPercentageSizesToPx(e){let t=this.parentContainer.getPaddingRect(),i=t.x2-t.x1,n=t.y2-t.y1;function r(s,o){s.forEach(a=>{let l=ei(e,a);if(l&&l.charAt(l.length-1)==="%"){let h=parseFloat(l),u=o*h/100;T(e,a,`${u}px`)}})}r(["width","max-width","min-width"],i),r(["height","max-height","min-height"],n),r(["margin-top","margin-right","margin-bottom","margin-left","padding-top","padding-right","padding-bottom","padding-left"],this.vertical?n:i),["margin-top","margin-right","margin-bottom","margin-left"].forEach(s=>{ei(e,s)==="auto"&&T(e,s,"0")})}fixFloatSizeAndPosition(e){for(;e.parent;)e=e.parent;e.viewNode.nodeType;let t=e.viewNode;if(this.rootViewNodes.push(t),this.adjustContentRelativeSize&&this.convertPercentageSizesToPx(t),this.floatMargins.push(this.getComputedMargin(t)),this.adjustContentRelativeSize){let i=this.floatSide;if(this.parentContainer.vertical){if(i==="block-end"||i==="left"){let n=ei(t,"height");n!==""&&n!=="auto"&&T(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ei(t,"width");n!==""&&n!=="auto"&&T(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=It(this.clientLayout,e,this.vertical),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},Ii=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,c(this,"formattingContextType","RepetitiveElementsOwner"),c(this,"isRoot",!1),c(this,"repetitiveElements",null)}getName(){return"Repetitive elements owner formatting context (RepetitiveElementsOwnerFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}getRepetitiveElements(){return this.repetitiveElements}getRootViewNode(e){let t=this.getRootNodeContext(e);return t?t.viewNode:null}getRootNodeContext(e){do if(!e.belongsTo(this)&&e.sourceNode===this.rootSourceNode)return e;while(e=e.parent);return null}initializeRepetitiveElements(e){this.repetitiveElements||Co.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new _w(e,this.rootSourceNode),Co.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},_w=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,c(this,"headerSourceNode",null),c(this,"footerSourceNode",null),c(this,"headerViewNode",null),c(this,"footerViewNode",null),c(this,"headerNodePosition",null),c(this,"footerNodePosition",null),c(this,"headerHeight",0),c(this,"footerHeight",0),c(this,"isSkipHeader",!1),c(this,"isSkipFooter",!1),c(this,"enableSkippingFooter",!0),c(this,"enableSkippingHeader",!0),c(this,"doneInitialLayout",!1),c(this,"firstContentSourceNode",null),c(this,"lastContentSourceNode",null),c(this,"affectedNodeCache",[]),c(this,"afterLastContentNodeCache",[]),c(this,"allowInsert",!1),c(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=es(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=es(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=xo(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=xo(this.footerViewNode,e,this.vertical),this.footerViewNode=null)}prepareLayoutFragment(){this.isSkipHeader=this.isSkipFooter=!1,this.enableSkippingFooter=!0,this.enableSkippingHeader=!0}appendHeaderToFragment(e,t,i){return!this.headerNodePosition||this.isSkipHeader?N(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?N(!0):this.appendElementToFragment(this.footerNodePosition,e,t,i)}appendElementToFragment(e,t,i,n){let r=t.viewNode.ownerDocument,s=t.viewNode,o=r.createElement("div");s.appendChild(o);let a=new Da(n,o,t),l=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new ui(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=l,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(hn,"1"),i?t.insertBefore(n,i):t.appendChild(n)}}calculateOffset(e){let t=0;return e&&!this.affectTo(e)||((!this.isSkipFooter||e&&this.isAfterLastContent(e))&&(t+=this.footerHeight),this.isSkipHeader||(t+=this.headerHeight)),t}calculateMinimumOffset(e){let t=0;return e&&!this.affectTo(e)||(!this.enableSkippingFooter&&e&&this.isAfterLastContent(e)&&(t+=this.footerHeight),this.enableSkippingHeader||(t+=this.headerHeight)),t}isAfterLastContent(e){return this.findResultFromCache(e,this.afterLastContentNodeCache,t=>this.isAfterNodeContextOf(this.lastContentSourceNode,e,!1))}affectTo(e){return this.findResultFromCache(e,this.affectedNodeCache,t=>this.isAfterNodeContextOf(this.ownerSourceNode,e,!0))}findResultFromCache(e,t,i){let n=t.filter(r=>r.nodeContext.sourceNode===e.sourceNode&&r.nodeContext.after===e.after);if(n.length>0)return n[0].result;{let r=i(e);return t.push({nodeContext:e,result:r}),r}}isAfterNodeContextOf(e,t,i){let n=[];for(let r=e;r;r=r.parentNode){if(t.sourceNode===r)return t.after;n.push(r)}for(let r=t.sourceNode;r;r=r.parentNode){let s=n.indexOf(r);if(s>=0)return i?s===0:!1;for(let o=r;o;o=o.previousElementSibling)if(n.includes(o))return!0}return t.after}isFirstContentNode(e){return e&&this.firstContentSourceNode===e.sourceNode}isEnableToUpdateState(){return!!(!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition||!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition)}updateState(){!this.isSkipFooter&&this.enableSkippingFooter&&this.footerNodePosition?this.isSkipFooter=!0:!this.isSkipHeader&&this.enableSkippingHeader&&this.headerNodePosition&&(this.isSkipHeader=!0)}preventSkippingHeader(){this.isSkipHeader=!1,this.enableSkippingHeader=!1}preventSkippingFooter(){this.isSkipFooter=!1,this.enableSkippingFooter=!1}isHeaderRegistered(){return!!this.headerNodePosition}isFooterRegistered(){return!!this.footerNodePosition}isHeaderSourceNode(e){return this.headerSourceNode===e}isFooterSourceNode(e){return this.footerSourceNode===e}},id=class{constructor(e){this.formattingContext=e}accept(e,t){return!!e}postLayout(e,t,i,n){let r=this.formattingContext.getRepetitiveElements();return r&&(i.clientLayout,r.doneInitialLayout||(r.updateHeight(i),r.doneInitialLayout=!0)),n}},nd=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},zw=class extends id{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Dw=class extends nd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Va(e)),this.processor.doLayout(e,t)}},Va=class rd{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=$t(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||qi(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=this.getRepetitiveElements();return i&&i.isEnableToUpdateState()?(i.updateState(),!0):!1}postLayout(t,i,n,r){let s=this.getRepetitiveElements();s&&t&&r.stopAtOverflow&&(i==null||s.isAfterLastContent(i))&&s.preventSkippingFooter()}finishBreak(t,i){let n=$t(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return N(!0);let s=this.nodeContext;return Ww(n,s,i).thenAsync(()=>Gw(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return $t(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof rd?$t(this.nodeContext.formattingContext)===$t(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Vw=class extends Ra{constructor(e,t){super(),this.formattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.formattingContext.getRepetitiveElements();return!e.belongsTo(this.formattingContext)&&!t.doneInitialLayout?new zw(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Dw(this.formattingContext,this.processor))}},Hw=class extends _n{constructor(e,t){super(),this.formattingContext=e,this.column=t}startNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=t.getRepetitiveElements();if(i.parent&&t.rootSourceNode===i.parent.sourceNode){switch(i.repeatOnBreak){case"header":if(n.isHeaderRegistered())i.repeatOnBreak="none";else return n.setHeaderNodeContext(i),N(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),N(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return _n.prototype.startNonInlineElementNode.call(this,e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext;return i.sourceNode===t.rootSourceNode&&(t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0),i.repeatOnBreak==="header"||i.repeatOnBreak==="footer"?N(!0):_n.prototype.afterNonInlineElementNode.call(this,e)}},Uw=class extends Zi{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=$t(e.formattingContext);return n.getRootViewNode(e)?(i&&sd(e.parent,t),e.belongsTo(n)?Zi.prototype.layout.call(this,e,t,i):new Vw(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=jw(e).getRepetitiveElements();return t&&!t.allowInsertRepeatitiveElements&&(t.isHeaderSourceNode(e.sourceNode)||t.isFooterSourceNode(e.sourceNode))&&e.viewNode.parentNode.removeChild(e.viewNode),!1}doInitialLayout(e,t){let i=$t(e.formattingContext),n=O("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=$t(e.formattingContext),n=new Hw(i,t);return new So(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=$t(e.formattingContext),n=O("doLayout"),r=t.layoutContext.nextInTree(e,!1);return ed(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let l=!0;if(t.layoutNext(o,!1).then(h=>{o=h,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():l?l=!1:a.continueLoop()}),l){l=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return Zi.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Zi.prototype.clearOverflownViewNodes(e,t,i,n)}};function $w(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Ii&&!i.belongsTo(n)&&t(n,i)}}function sd(e,t){e&&$w(e.after?e.parent:e,(i,n)=>{li.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Va(n))})}function Ww(e,t,i){let n=e.getRepetitiveElements();if(n){let r=e.getRootNodeContext(t);if(r.viewNode){let s=r.viewNode.firstChild;return n.appendHeaderToFragment(r,s,i)}}return N(!0)}function Gw(e,t,i){let n=e.getRepetitiveElements();if(n&&!n.isSkipFooter){let r=e.getRootNodeContext(t);if(r.viewNode)return n.appendFooterToFragment(r,null,i)}return N(!0)}function jw(e){let t=e.formattingContext;return!t||!(t instanceof Ii)?null:t}function $t(e){return e instanceof Ii,e}var Xw=new Uw;Nt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Ii&&!li.isInstanceOfTableFormattingContext(e)?Xw:null);var od=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},qw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,c(this,"viewElement"),c(this,"colSpan"),c(this,"rowSpan"),c(this,"height",0),c(this,"anchorSlot",null),this.viewElement=i,this.colSpan=i.colSpan||1,this.rowSpan=i.rowSpan||1}setHeight(e){this.height=e}setAnchorSlot(e){this.anchorSlot=e}},Yw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Kw=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new Da(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&T(e,"vertical-align","top"),i&&i!=="normal"&&T(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return T(e,"vertical-align",t),i&&i!=="normal"&&T(e,"align-content",i),n}},Zw=class{constructor(e,t){this.viewNode=e,this.side=t}},Jw=class extends hr{constructor(e,t,i,n){super(e,t,i,n),c(this,"formattingContext"),c(this,"acceptableCellBreakPositions",null),c(this,"rowIndex",null),this.formattingContext=e.formattingContext}findAcceptableBreak(e,t){let i=super.findAcceptableBreak(e,t);return t<this.getMinBreakPenalty()?null:this.getAcceptableCellBreakPositions().every(n=>!!n.nodeContext)?i:null}getMinBreakPenalty(){let e=super.getMinBreakPenalty();this.getAcceptableCellBreakPositions().forEach(i=>{e+=i.breakPosition.getMinBreakPenalty()});let t=this.getCellFragments();return e+=Math.max(0,...t.map(i=>i.cellNodeContext.breakPenalty)),e}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.formattingContext,t=this.getCellFragments();this.acceptableCellBreakPositions=t.map(i=>i.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getRowIndex(){return this.rowIndex!=null?this.rowIndex:this.rowIndex=this.formattingContext.findRowIndexBySourceNode(this.position.sourceNode)}getCellFragments(){return this.formattingContext.getRowSpanningCellsOverflowingTheRow(this.getRowIndex()).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},Qw=class extends Ta{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,c(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(this!==e.breakPositions[0]&&t<this.getMinBreakPenalty())return null;let i=this.getCellFragments(),n=this.getAcceptableCellBreakPositions(),r=n.every(s=>!!s.nodeContext)&&n.some((s,o)=>{let a=i[o].pseudoColumn,l=s.nodeContext;return!a.isStartNodeContext(l)&&!a.isLastAfterNodeContext(l)});return this.beforeNodeContext.overflow=n.some(s=>s.nodeContext&&s.nodeContext.overflow),r?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext.getRowByIndex(this.rowIndex),t=this.beforeNodeContext.breakPenalty,i=this.getAcceptableCellBreakPositions(),n=this.getCellFragments();t+=Math.max(0,...n.map(s=>s.cellNodeContext.breakPenalty));let r=i.some((s,o)=>s.breakPosition instanceof Fr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof hr&&s.breakPosition.overflows&&a>=3&&(n[o].column.checkOverflowAndSaveEdge(s.nodeContext,null)||(a-=3)),t+=a}),t}getAcceptableCellBreakPositions(){if(!this.acceptableCellBreakPositions){let e=this.getCellFragments();this.acceptableCellBreakPositions=e.map(t=>t.findAcceptableBreakPosition())}return this.acceptableCellBreakPositions}getCellFragments(){return this.formattingContext.getCellsFallingOnRow(this.rowIndex).map(this.formattingContext.getCellFragmentOfCell,this.formattingContext)}},rn=class extends Ii{constructor(e,t){super(e,t),this.tableSourceNode=t,c(this,"formattingContextType","Table"),c(this,"vertical",!1),c(this,"columnCount",-1),c(this,"tableWidth",0),c(this,"captions",[]),c(this,"colGroups",null),c(this,"colWidths",null),c(this,"inlineBorderSpacing",0),c(this,"rows",[]),c(this,"slots",[]),c(this,"cellFragments",[]),c(this,"lastRowViewNode",null),c(this,"cellBreakPositions",[]),c(this,"repetitiveElements",null)}getName(){return"Table formatting context (Table.TableFormattingContext)"}isFirstTime(e,t){if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0;case"table-cell":return!this.cellBreakPositions.some(i=>i.cellNodePosition.steps[0].node===e.sourceNode);default:return t}}getParent(){return this.parent}finishFragment(){this.cellFragments=[]}addRow(e,t){this.rows[e]=t}getRowSlots(e){let t=this.slots[e];return t||(t=this.slots[e]=[]),t}addCell(e,t){let i=this.rows[e];i||(this.addRow(e,new od(e,null)),i=this.rows[e]),i.addCell(t);let n=e+t.rowSpan,r=this.getRowSlots(e),s=0;for(;r[s];)s++;for(;e<n;e++){r=this.getRowSlots(e);for(let o=s;o<s+t.colSpan;o++){let a=r[o]=new Yw(e,o,t);t.anchorSlot||t.setAnchorSlot(a)}}}getRowByIndex(e){return this.rows[e]}findRowIndexBySourceNode(e){return this.rows.findIndex(t=>e===t.sourceNode)}addCellFragment(e,t,i){let n=this.cellFragments[e];n||(n=this.cellFragments[e]=[]),n[t]=i}getCellsFallingOnRow(e){return this.getRowSlots(e).reduce((t,i)=>i.cell!==t[t.length-1]?t.concat(i.cell):t,[])}getRowSpanningCellsOverflowingTheRow(e){return this.getCellsFallingOnRow(e).filter(t=>t.rowIndex+t.rowSpan-1>e)}getCellFragmentOfCell(e){return this.cellFragments[e.rowIndex]&&this.cellFragments[e.rowIndex][e.columnIndex]}getColumnCount(){return this.columnCount<0&&(this.columnCount=Math.max.apply(null,this.rows.map(e=>e.cells.reduce((t,i)=>t+i.colSpan,0)))),this.columnCount}updateCellSizes(e){this.rows.forEach(t=>{t.cells.forEach(i=>{let n=It(e,i.viewElement,this.vertical);i.viewElement=null,i.setHeight(this.vertical?n.width:n.height)})})}findCellFromColumn(e){if(!e)return null;let t=null,i=0,n=0;e:for(i=0;i<this.cellFragments.length;i++)if(this.cellFragments[i]){for(n=0;n<this.cellFragments[i].length;n++)if(this.cellFragments[i][n]&&e===this.cellFragments[i][n].pseudoColumn.getColumn()){t=this.rows[i].cells[n];break e}}if(!t)return null;for(;i<this.slots.length;i++)for(;n<this.slots[i].length;n++){let r=this.slots[i][n];if(r.cell===t)return{rowIndex:r.rowIndex,columnIndex:r.columnIndex}}return null}collectElementsOffsetOfUpperCells(e){let t=[];return this.slots.reduce((i,n,r)=>{if(r>=e.rowIndex)return i;let s=n[e.columnIndex]&&this.getCellFragmentOfCell(n[e.columnIndex].cell);return!s||t.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),i),t.push(s)),i},[])}collectElementsOffsetOfHighestColumn(){let e=[];return this.rows.forEach(t=>{t.cells.forEach((i,n)=>{e[n]||(e[n]={collected:[],elements:[]});let r=e[n],s=this.getCellFragmentOfCell(i);!s||r.collected.includes(s)||(this.collectElementsOffsetFromColumn(s.pseudoColumn.getColumn(),r.elements),r.collected.push(s))})}),[new ey(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Ni.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}li.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},ey=class{constructor(e){this.repeatitiveElementsInColumns=e}calculateOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.current)}calculateMinimumOffset(e){return this.calculateMaxOffsetOfColumn(e,t=>t.minimum)}calculateMaxOffsetOfColumn(e,t){let i=0;return this.repeatitiveElementsInColumns.forEach(n=>{let r=nn(e,n);i=Math.max(i,t(r))}),i}};function Ct(e){return e instanceof rn,e}function ty(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function iy(e){return e==="table"||e==="inline-table"}function nh(e){return ty(e)||iy(e)}function ad(e,t,i){let n=e.nodeContext,r=n.display,s=n.parent?n.parent.display:null,o=!1;if(s==="inline-table"&&!(n.formattingContext instanceof rn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof rn){o=a.formattingContext===t;break}}return o||r==="table-row"&&!nh(s)||r==="table-cell"&&s!=="table-row"&&!nh(s)||n.formattingContext instanceof rn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var ny=class extends _n{constructor(e,t){super(),this.formattingContext=e,this.column=t,c(this,"rowIndex",-1),c(this,"columnIndex",0),c(this,"inRow",!1),c(this,"checkPoints",[]),c(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=ad(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=e.nodeContext,r=n.display,s=t.getRepetitiveElements();switch(r){case"table":t.inlineBorderSpacing=n.inlineBorderSpacing;break;case"table-caption":{let o=new Zw(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return s.isHeaderRegistered()||(this.inHeaderOrFooter=!0,s.setHeaderNodeContext(n)),N(!0);case"table-footer-group":return s.isFooterRegistered()||(this.inHeaderOrFooter=!0,s.setFooterNodeContext(n)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new od(this.rowIndex,n.sourceNode)),s.firstContentSourceNode||(s.firstContentSourceNode=n.sourceNode));break}return super.startNonInlineElementNode(e)}afterNonInlineElementNode(e){let t=this.formattingContext,i=e.nodeContext,n=i.display,r=this.column.clientLayout;if(this.postLayoutBlockContents(e),i.sourceNode===t.tableSourceNode){let s=r.getElementComputedStyle(t.getRootViewNode(i));t.tableWidth=parseFloat(s[t.vertical?"height":"width"]),t.getRepetitiveElements().lastContentSourceNode=e.lastAfterNodeContext&&e.lastAfterNodeContext.sourceNode,e.break=!0}else switch(n){case"table-header-group":case"table-footer-group":if(this.inHeaderOrFooter)return this.inHeaderOrFooter=!1,N(!0);break;case"table-row":this.inHeaderOrFooter||(t.lastRowViewNode=i.viewNode,this.inRow=!1);break;case"table-cell":if(!this.inHeaderOrFooter){this.inRow||(this.rowIndex++,this.columnIndex=0,this.inRow=!0);let s=i.viewNode;t.addCell(this.rowIndex,new qw(this.rowIndex,this.columnIndex,s)),this.columnIndex++}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!Ki(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},ld=class hd extends _n{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,c(this,"inRow",!1),c(this,"currentRowIndex",-1),c(this,"currentColumnIndex",0),c(this,"originalStopAtOverflow"),c(this,"inHeader"),c(this,"inFooter"),this.originalStopAtOverflow=i.stopAtOverflow,i.stopAtOverflow=!1}resetColumn(){this.column.stopAtOverflow=this.originalStopAtOverflow}getColSpanningCellWidth(t){let i=this.formattingContext.colWidths,n=0;for(let r=0;r<t.colSpan;r++)n+=i[t.anchorSlot.columnIndex+r];return n+=this.formattingContext.inlineBorderSpacing*(t.colSpan-1),n}layoutCell(t,i,n){let r=t.rowIndex,s=t.columnIndex,o=t.colSpan,a=i.viewNode,l=i.verticalAlign;o>1&&(T(a,"box-sizing","border-box"),T(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let u=new Kw(this.column,h,i);return this.formattingContext.addCellFragment(r,s,u),n.primary.steps.length===1&&n.primary.after&&(u.empty=!0),u.pseudoColumn.layout(n,!0).thenReturn(!0)}hasBrokenCellAtSlot(t){let i=this.formattingContext.cellBreakPositions[0];return i?i.cell.anchorSlot.columnIndex===t:!1}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],s=r.cell.rowIndex;if(s<this.currentRowIndex){let o=i[s];o||(o=i[s]=[]),o.push(r),t.splice(n,1)}else n++}while(n<t.length);return i}layoutRowSpanningCellsFromPreviousFragment(t){let i=this.formattingContext,n=this.extractRowSpanningCellBreakPositions(),r=n.reduce(d=>d+1,0);if(r===0)return N(!0);let s=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=O("layoutRowSpanningCellsFromPreviousFragment"),l=N(!0),h=0,u=[];return n.forEach(d=>{l=l.thenAsync(()=>{let p=ts(d[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=N(!0),m=0;function g(w){for(;m<w;){if(!u.includes(m)){let v=p.viewNode.ownerDocument.createElement("td");T(v,"padding","0"),p.viewNode.appendChild(v)}m++}}return d.forEach(w=>{f=f.thenAsync(()=>{let v=w.cell;g(v.anchorSlot.columnIndex);let y=w.cellNodePosition,C=ts(y.steps[0],p);return C.offsetInNode=y.offsetInNode,C.after=y.after,C.fragmentIndex=y.steps[0].fragmentIndex+1,s.setCurrent(C,!1).thenAsync(()=>{let E=w.breakChunkPosition;for(let A=0;A<v.colSpan;A++)u.push(m+A);return m+=v.colSpan,this.layoutCell(v,C,E).thenAsync(()=>(C.viewNode.rowSpan=v.rowIndex+v.rowSpan-this.currentRowIndex+r-h,N(!0)))})})}),f.thenAsync(()=>(g(i.getColumnCount()),h++,N(!0)))})})}),l.then(()=>{s.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext,n=this.formattingContext;return this.currentRowIndex<0?(i.sourceNode,this.currentRowIndex=n.findRowIndexBySourceNode(i.sourceNode)):this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0,this.layoutRowSpanningCellsFromPreviousFragment(t).thenAsync(()=>(this.registerCellFragmentIndex(),this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,t.breakAtTheEdge)&&n.getRowSpanningCellsOverflowingTheRow(this.currentRowIndex-1).length===0&&(this.resetColumn(),i.overflow=!0,t.break=!0),N(!0)))}registerCellFragmentIndex(){this.formattingContext.getRowByIndex(this.currentRowIndex).cells.forEach(t=>{let i=this.formattingContext.cellBreakPositions[t.columnIndex];if(i&&i.cell.anchorSlot.columnIndex==t.anchorSlot.columnIndex){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);Pw(r,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return N(!0);let i=t.nodeContext;this.inRow||(this.currentRowIndex<0?this.currentRowIndex=0:this.currentRowIndex++,this.currentColumnIndex=0,this.inRow=!0);let n=this.formattingContext.getRowByIndex(this.currentRowIndex).cells[this.currentColumnIndex];if(!n)return t.break=!0,N(!0);let r=i.copy().modify();r.after=!0,t.nodeContext=r;let s=O("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=N(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let l=es(a,0);return N(new ui(l))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=ad(t,Ct(this.formattingContext),this.column);if(i)return i;let n=t.nodeContext,r=this.formattingContext.getRepetitiveElements(),s=n.display;return s==="table-header-group"&&r&&r.isHeaderSourceNode(n.sourceNode)?(this.inHeader=!0,N(!0)):s==="table-footer-group"&&r&&r.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,N(!0)):s==="table-row"?this.startTableRow(t):s==="table-cell"?this.startTableCell(t):N(!0)}endNonInlineBox(t){let i=t.nodeContext;if(i.display==="table-row"&&(this.inRow=!1,!this.inHeader&&!this.inFooter)){let n=i.copy().modify();n.after=!1;let r=new Qw(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(r)}return N(!0)}afterNonInlineElementNode(t){let i=t.nodeContext,n=this.formattingContext.getRepetitiveElements(),r=i.display;if(r==="table-header-group"?n&&!n.allowInsertRepeatitiveElements&&n.isHeaderSourceNode(i.sourceNode)?(this.inHeader=!1,i.viewNode.parentNode.removeChild(i.viewNode)):T(i.viewNode,"display","table-row-group"):r==="table-footer-group"&&(n&&!n.allowInsertRepeatitiveElements&&n.isFooterSourceNode(i.sourceNode)?(this.inFooter=!1,i.viewNode.parentNode.removeChild(i.viewNode)):T(i.viewNode,"display","table-row-group")),r&&hd.ignoreList[r])i.viewNode.parentNode.removeChild(i.viewNode);else if(i.sourceNode===this.formattingContext.tableSourceNode)i.overflow=this.column.checkOverflowAndSaveEdge(i,null),this.resetColumn(),t.break=!0;else return super.afterNonInlineElementNode(t);return N(!0)}};c(ld,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var ry=ld,Kn=[];function sy(e){let t=Kn.findIndex(n=>n.root===e),i=Kn[t];return i?i.tableLayoutOption:null}function oy(e){let t=Kn.findIndex(i=>i.root===e);t>=0&&Kn.splice(t,1)}var ud=class{layoutEntireTable(e,t){let i=Ct(e.formattingContext),n=new ny(i,t);return new So(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let l=0;l<t;l++){let h=r.createElement("td");s.appendChild(h),o.push(h)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(l=>{let h=It(n,l,i),u=i?h.height:h.width;return Math.ceil(u)});return e.parentNode.removeChild(s),a}getColGroupElements(e){let t=[],i=e.firstElementChild;for(;i;)i.localName==="colgroup"&&t.push(i),i=i.nextElementSibling;return t}normalizeAndGetColElements(e){let t=[];return e.forEach(i=>{let n=i.span;i.removeAttribute("span");let r=i.firstElementChild;for(;r;){if(r.localName==="col"){let s=r.span;for(r.removeAttribute("span"),n-=s;s-- >1;){let o=r.cloneNode(!0);i.insertBefore(o,r),t.push(o)}t.push(r)}r=r.nextElementSibling}for(;n-- >0;)r=i.ownerDocument.createElement("col"),i.appendChild(r),t.push(r)}),t}addMissingColElements(e,t,i,n){if(e.length<i){let r=n.ownerDocument.createElement("colgroup");t.push(r);for(let s=e.length;s<i;s++){let o=n.ownerDocument.createElement("col");r.appendChild(o),e.push(o)}}}normalizeColGroups(e,t,i){let n=e.vertical,r=e.lastRowViewNode;if(!r)return;e.lastRowViewNode=null;let s=r.ownerDocument.createDocumentFragment(),o=e.getColumnCount();if(!(o>0)){e.colGroups=s;return}let a=e.colWidths=this.getColumnWidths(r,o,n,i.clientLayout),l=this.getColGroupElements(t),h=this.normalizeAndGetColElements(l);this.addMissingColElements(h,l,o,t),h.forEach((u,d)=>{T(u,n?"height":"width",`${a[d]}px`)}),l.forEach(u=>{s.appendChild(u.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=Ct(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=sy(e.sourceNode);oy(e.sourceNode);let r=O("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,l=It(t.clientLayout,a,t.vertical),h=t.vertical?l.left:l.bottom;if(h+=(t.vertical?-1:1)*nn(e,t.collectElementsOffset()).current,!t.isOverflown(h)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new uy(s)),r.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}addCaptions(e,t,i){let n=e.captions;n.forEach((r,s)=>{r&&(t.insertBefore(r.viewNode,i),r.side==="top"&&(n[s]=null))})}addColGroups(e,t,i){e.colGroups&&this.getColGroupElements(t).length===0&&(t.insertBefore(e.colGroups.cloneNode(!0),i),T(t,"table-layout","fixed"),T(t,e.vertical?"height":"width",`${e.tableWidth}px`))}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=Ct(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new ry(i,t),o=new So(s,t.layoutContext),a=O("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Ct(e.formattingContext),r=n.getRootViewNode(e),s=O("TableFormattingContext.layout"),o;return r?(i&&sd(e.parent,t),o=new ly(n,this).layout(e,t)):o=t.buildDeepElementView(e),o.then(a=>{s.finish(a),t.element.hasAttribute("data-vivliostyle-column-height-adjusted")&&(T(t.element,"width",`${t.width}px`),T(t.element,"height",`${t.height}px`),t.element.removeAttribute("data-vivliostyle-column-height-adjusted"))}),s.result()}createEdgeBreakPosition(e,t,i,n){return new Jw(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Gs(e),!1}finishBreak(e,t,i,n){let r=Ct(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode);r.cellBreakPositions=[];let o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),o.length){let a=O("TableLayoutProcessor.finishBreak"),l=0;return a.loopWithFrame(h=>{if(l===o.length){h.breakLoop();return}let u=o[l++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,m=f.toNodePosition(),g=new ui(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:m,breakChunkPosition:g,cell:u});let w=f.viewNode;d.column.layoutContext.processFragmentedBlockEdge(d.cellNodeContext),s<u.rowIndex+u.rowSpan-1&&(w.rowSpan=s-u.rowIndex+1),d.empty?h.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{ay(d,r,p),h.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Gs(t),r.finishFragment(),a.finish(!0)}),a.result()}}return Gs(t),r.finishFragment(),Aa.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){Zi.prototype.clearOverflownViewNodes(e,t,i,n)}};function ay(e,t,i){let n=t.getRepetitiveElements();if(!n||!(n.isHeaderRegistered()||n.isFooterRegistered()))return;let r=t.vertical,s=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,l=It(s.clientLayout,a,r),h=s.getComputedPaddingBorder(a);if(r){let u=l.right-s.footnoteEdge-n.calculateOffset(i)-h.right;T(o,"max-width",`${u}px`)}else{let u=s.footnoteEdge-n.calculateOffset(i)-l.top-h.top;T(o,"max-height",`${u}px`)}}function Gs(e){let t=e.display==="table-row"?e.viewNode.parentElement:e.display==="table"?e.viewNode.querySelector("tbody"):null;if(!t)return;let i;try{i=t.querySelectorAll(":scope>tr:has(>:empty):not(:has(>:not([rowspan]:not([rowspan='1']),:empty)))")}catch{return}if(i.length===0)return;let n=Array.from(i).reduce((d,p)=>{let f=p.getBoundingClientRect(),m=e.vertical?f.width:f.height;return d+m},0),r=i[i.length-1],s=Array.from(t.children).indexOf(r),o=Array.from(r.children).reduce((d,p)=>{let f=p.rowSpan;return f>1&&s+f<t.childElementCount?Math.max(d,f):d},0),a=o?t.children[s+o-1]:t.lastElementChild;if(a!=t.lastElementChild&&a.querySelector(":scope>*>div>div")){for(let d=a;d&&d!==t.lastElementChild;d=d.nextElementSibling)if(d.querySelector(":scope>[rowspan]:not([rowspan='1'])")){a=d;break}}let l=a.getBoundingClientRect(),h=e.vertical?l.width:l.height,u=n+h;T(a,e.vertical?"width":"height",`${u}px`)}var ly=class extends Ra{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new hy(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new dy(this.tableFormattingContext,this.processor))}clearNodes(e){super.clearNodes(e);let t=this.tableFormattingContext.getRootViewNode(e);this.processor.removeColGroups(this.tableFormattingContext,t)}restoreState(e,t){super.restoreState(e,t),this.tableFormattingContext.finishFragment()}},hy=class extends id{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},uy=class extends hr{constructor(e){super(e,null,e.overflow,0)}getMinBreakPenalty(){if(!this.isEdgeUpdated)throw new Error("EdgeBreakPosition.prototype.updateEdge not called");return(this.overflows?3:0)+(this.position.parent?this.position.parent.breakPenalty:0)}breakPositionChosen(e){e.fragmentLayoutConstraints.push(new cy(this.position.sourceNode))}},cy=class cd{constructor(t){this.tableRootNode=t,c(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,r){i.sourceNode,Kn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof cd&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},dy=class extends nd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new py(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},py=class dd extends Va{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||qi(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=Ct(this.nodeContext.formattingContext);return this.collectCellFragmentLayoutConstraints(t,i).some(n=>n.constraints.some(r=>r.nextCandidate(t)))?!0:super.nextCandidate(t)}postLayout(t,i,n,r){let s=Ct(this.nodeContext.formattingContext);if(this.cellFragmentLayoutConstraints=this.collectCellFragmentLayoutConstraints(i,s),this.cellFragmentLayoutConstraints.forEach(o=>{o.constraints.forEach(a=>{a.postLayout(t,o.breakPosition,n,r)})}),!t){let o=s.getRootViewNode(this.nodeContext);new ud().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Ct(this.nodeContext.formattingContext),r=O("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,l)=>a.concat(l.constraints.map(h=>({constraint:h,breakPosition:l.breakPosition}))),[]),o=0;return r.loop(()=>{if(o<s.length){let a=s[o++];return a.constraint.finishBreak(a.breakPosition,i).thenReturn(!0)}else return N(!1)}).then(()=>{r.finish(!0)}),r.result().thenAsync(()=>super.finishBreak(t,i))}removeDummyRowNodes(t){if(!(!t||t.display!=="table-row"||!t.viewNode))for(;t.viewNode.previousElementSibling;){let i=t.viewNode.previousElementSibling;i.parentNode&&i.parentNode.removeChild(i)}}collectCellFragmentLayoutConstraints(t,i){return this.getCellFragemnts(t,i).map(n=>({constraints:n.fragment.pseudoColumn.getColumn().fragmentLayoutConstraints,breakPosition:n.breakPosition}))}getCellFragemnts(t,i){let n=Number.MAX_VALUE;t&&t.display==="table-row"&&(t.sourceNode,n=i.findRowIndexBySourceNode(t.sourceNode)+1),n=Math.min(i.cellFragments.length,n);let r=[];for(let s=0;s<n;s++)i.cellFragments[s]&&i.cellFragments[s].forEach(o=>{o&&r.push({fragment:o,breakPosition:o.findAcceptableBreakPosition().nodeContext})});return r}getElementsOffsetsForTableCell(t){let i=Ct(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof dd?Ct(this.nodeContext.formattingContext)===Ct(t.nodeContext.formattingContext):!1}},fy=new ud;function gy(e,t,i,n,r,s){if(!t)return null;if(i===b.table){let o=e.parent;return new rn(o?o.formattingContext:null,e.sourceNode)}return null}function my(e){return e instanceof rn?fy:null}Nt("RESOLVE_FORMATTING_CONTEXT",gy);Nt("RESOLVE_LAYOUT_PROCESSOR",my);function rh(e){return e.reduce((t,i)=>t+i,0)/e.length}function wy(e){let t=rh(e);return rh(e.map(i=>{let n=i-t;return n*n}))}var yy=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function Zn(e){return e.vertical?e.width:e.height}function Jn(e,t){e.vertical?e.width=t:e.height=t}var pd=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=Zn(e)}balanceColumns(e){let t=O("ColumnBalancer#balanceColumns");this.preBalance(e),this.savePageFloatLayoutContexts(e),this.layoutContainer.clear();let i=[this.createTrialResult(e)];return t.loopWithFrame(n=>{if(!this.hasNextCandidate(i)){n.breakLoop();return}this.updateCondition(i),this.columnGenerator().then(r=>{if(this.savePageFloatLayoutContexts(r),this.layoutContainer.clear(),!r){n.breakLoop();return}i.push(this.createTrialResult(r)),n.continueLoop()})}).then(()=>{let n=i.reduce((r,s)=>s.penalty<r.penalty?s:r,i[0]);this.restoreContents(n.layoutResult),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new yy(e,t)}preBalance(e){}postBalance(){Jn(this.layoutContainer,this.originalContainerBlockSize)}savePageFloatLayoutContexts(e){let t=this.regionPageFloatLayoutContext.detachChildren();e&&(e.columnPageFloatLayoutContexts=t)}restoreContents(e){let t=this.layoutContainer.element;e.columns.forEach(i=>{t.appendChild(i.element)}),e.columnPageFloatLayoutContexts,this.regionPageFloatLayoutContext.attachChildren(e.columnPageFloatLayoutContexts)}},_o=1;function fd(e){let t=e[e.length-1];if(t.penalty===0)return!1;let i=e[e.length-2];if(i&&t.penalty>=i.penalty)return!1;let n=t.layoutResult.columns,r=Math.max.apply(null,n.map(o=>o.computedBlockSize)),s=Math.max.apply(null,n.map(o=>o.getMaxBlockSizeOfPageFloats()));return r>s+_o}function gd(e,t){var i;let n=e[e.length-1].layoutResult.columns,r=Math.max.apply(null,n.map(s=>isNaN(s.blockDistanceToBlockEndFloats)?s.computedBlockSize:s.computedBlockSize-s.blockDistanceToBlockEndFloats+_o))-_o;if(r<Zn(t)?Jn(t,r):Jn(t,Zn(t)-1),t.vertical){let s=parseFloat((i=t.element.style)==null?void 0:i.width);t.originX=s-t.width}}var by=class extends pd{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,c(this,"originalPosition",null),c(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);Jn(this.layoutContainer,t/this.columnCount),this.originalPosition=e.position}checkPosition(e){return this.originalPosition?this.originalPosition.isSamePosition(e):e===null}calculatePenalty(e){if(!this.checkPosition(e.position))return 1/0;let t=e.columns;return sh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return fd(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!sh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):Zn(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)gd(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,Zn(this.layoutContainer)+this.originalContainerBlockSize*.1);Jn(this.layoutContainer,t)}}};function sh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=6;return i.every(r=>t>r.computedBlockSize+n)}var vy=class extends pd{constructor(e,t,i){super(i,e,t)}calculatePenalty(e){if(e.columns.every(i=>i.computedBlockSize===0))return 1/0;let t=e.columns.filter(i=>!i.pageBreakType).map(i=>i.computedBlockSize);return wy(t)}hasNextCandidate(e){return fd(e)}updateCondition(e){gd(e,this.layoutContainer)}};function xy(e,t,i,n,r,s,o){if(t===b.auto)return null;{let a=o.positions.length===0,l=s[s.length-1],h=!!(l&&l.pageBreakType);return a||h?new by(i,n,r,e):t===b.balance_all?new vy(i,n,r):(b.balance,null)}}var Sy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Cy=new Set(Sy);function ky(e){return!(e.toLowerCase()==="none"||Cy.has(e))}var Ey=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Ny=new Set(Ey),Py=["fixed","extends"],Ty=new Set(Py),K0=Symbol();function cr(e){return e instanceof le&&e.name.toLowerCase()!=="none"}function md(e){return e.name}function Iy(e){if(e instanceof le)return Ny.has(e.name);if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof le){let n=t.name;return Ty.has(n)&&(n==="fixed"&&i instanceof Le||n==="extends"&&cr(i))}}return!1}function Ay(e){let t=nt(e,"system");return t instanceof le&&t.name==="cyclic"}function Ry(e){let t=nt(e,"system");if(t instanceof le&&t.name==="fixed")return!0;if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof le&&i.name==="fixed"&&n instanceof Le}return!1}function Fy(e){let t=nt(e,"system");return t instanceof le?1:t.values[1].num}function Ly(e){let t=nt(e,"system");return t instanceof le&&t.name==="alphabetic"}function Oy(e){let t=nt(e,"system");return t instanceof le&&t.name==="numeric"}function By(e){let t=nt(e,"system");return t instanceof le&&t.name==="additive"}function My(e){let t=nt(e,"system");if(t instanceof J&&t.values.length===2){let[i,n]=t.values;return i instanceof le&&i.name==="extends"&&cr(n)}return!1}function _y(e){let t=nt(e,"system");return md(t.values[1])}function Pt(e){return e instanceof j||e instanceof le}function jt(e){return e instanceof j?e.str:e.name}function wd(e){if(Pt(e))return!0;if(e instanceof J&&e.values.length===2){let t=e.values[0],i=e.values[1];return Pt(t)&&Pt(i)}return!1}function zy(e){if(Pt(e))return{prefix:jt(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:jt(t),suffix:jt(i)}}}function oh(e){return e instanceof Le||e instanceof le&&e.name==="infinite"}function as(e,t){return e instanceof Le?e.num:t?-1/0:1/0}var Z0=Symbol();function zo(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(oh(t)&&oh(i)))return!1;let n=as(t,!0),r=as(i,!1);return!(n>r)}function Dy(e){return{lower:as(e.values[0],!0),upper:as(e.values[1],!1)}}function yd(e){return e instanceof le&&e.name==="auto"||zo(e)||e instanceof Ze&&e.values.length>=1&&e.values.every(t=>zo(t))}function Vy(e){return e instanceof le?null:(zo(e)?[e]:e.values).map(t=>Dy(t))}var J0=Symbol();function ls(e){if(!(e instanceof J&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Le&&t.num>=0&&Pt(i)||Pt(t)&&i instanceof Le&&i.num>=0}function hs(e){let[t,i]=e.values;return t instanceof Le?[t.num,jt(i)]:[i.num,jt(t)]}function bd(e){return ls(e)}function Hy(e){let[t,i]=hs(e);return{minLength:t,symbol:i}}function vd(e){return Pt(e)||e instanceof J&&e.values.length>=1&&e.values.every(t=>Pt(t))}function Uy(e){return Pt(e)?[jt(e)]:e.values.map(t=>jt(t))}var Q0=Symbol();function xd(e){if(ls(e))return!0;if(e instanceof Ze&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!ls(i))return!1;let[n]=hs(i);if(n>=t)return!1;t=n}return!0}return!1}function $y(e){if(ls(e)){let[t,i]=hs(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=hs(t);return{weight:i,symbol:n}})}var Wy=["auto","bullets","numbers","words","spell-out"],Gy=new Set(Wy);function jy(e){return e instanceof le&&Gy.has(e.name)||cr(e)}function Xy(e,t){switch(e){case"system":return Iy(t);case"negative":return wd(t);case"prefix":case"suffix":return Pt(t);case"range":return yd(t);case"pad":return bd(t);case"fallback":return cr(t);case"symbols":return vd(t);case"additive-symbols":return xd(t);case"speak-as":return jy(t);default:return!0}}function nt(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function qy(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function cn(e){let t=e.get("decimal");return t||(t=ue.createDecimal(e),e.set("decimal",t)),t}var Lr,Or,Br,Mr,_r,zr,Dr,Vr,Do,Vo,Ho,Uo,$o,Wo,Go,ot,js,Sd,Cd,ah,lh,Xs,hh,An,Qt=class bi{constructor(t,i){Z(this,ot),c(this,"_store"),Z(this,Lr),Z(this,Or),Z(this,Br),Z(this,Mr),Z(this,_r),Z(this,zr),Z(this,Dr),Z(this,Vr),this._store=t;let n=nt(i,"negative");Fe(this,Lr,n&&wd(n)?zy(n):null);let r=nt(i,"prefix");Fe(this,Or,r&&Pt(r)?jt(r):null);let s=nt(i,"suffix");Fe(this,Br,s&&Pt(s)?jt(s):null);let o=nt(i,"range");Fe(this,Mr,o&&yd(o)?Vy(o):null);let a=nt(i,"pad");Fe(this,_r,a&&bd(a)?Hy(a):null);let l=nt(i,"fallback");Fe(this,zr,l&&cr(l)?md(l):null);let h=nt(i,"symbols");Fe(this,Dr,h&&vd(h)?Uy(h):null);let u=nt(i,"additive-symbols");Fe(this,Vr,u&&xd(u)?$y(u):null)}static create(t,i){return Ay(i)?new fi(t,i):Ry(i)?new Yy(t,i):Ly(i)?new Zy(t,i):Oy(i)?new uh(t,i):By(i)?new Jy(t,i):My(i)?new Qy(t,i):new Ky(t,i)}static createDecimal(t){return new uh(t,M(bi,Do))}static createDisc(t){return new fi(t,M(bi,Vo))}static createSquare(t){return new fi(t,M(bi,Ho))}static createCircle(t){return new fi(t,M(bi,Uo))}static createDisclosureOpen(t){return new fi(t,M(bi,$o))}static createDisclosureClosed(t){return new fi(t,M(this,Wo))}static createNone(t){return new fi(t,M(bi,Go))}static get CHINESE_LONGHAND_NAMES(){return ch.NAMES}static createChineseLonghand(t,i){return new ch(t,i)}static createEthiopicNumeric(t){return new tb(t)}_getNegative(){return M(this,Lr)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return M(this,Or)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return M(this,Br)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return M(this,Mr)}static _getRangeFrom(t){return t._getRange()}_getPad(){return M(this,_r)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(M(this,zr)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return M(this,Dr)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return M(this,Vr)}static _getAdditiveSymbolsFrom(t){return t._getAdditiveSymbols()}static _useNegativeSignFrom(t,i){return t._usesNegativeSign(i)}static _generateInitialRepresentationFrom(t,i){return t._generateInitialRepresentation(i)}format(t){return Se(this,ot,An).call(this,t,new Set)}formatMarker(t){return Se(this,ot,Sd).call(this)+this.format(t)+Se(this,ot,Cd).call(this)}};Lr=new WeakMap,Or=new WeakMap,Br=new WeakMap,Mr=new WeakMap,_r=new WeakMap,zr=new WeakMap,Dr=new WeakMap,Vr=new WeakMap,Do=new WeakMap,Vo=new WeakMap,Ho=new WeakMap,Uo=new WeakMap,$o=new WeakMap,Wo=new WeakMap,Go=new WeakMap,ot=new WeakSet,js=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Sd=function(){var e;return(e=this._getPrefix())!=null?e:""},Cd=function(){var e;return(e=this._getSuffix())!=null?e:". "},ah=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},lh=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},Xs=function(){var e;return(e=this._getFallback())!=null?e:cn(this._store)},hh=function(e,t){let{minLength:i,symbol:n}=Se(this,ot,lh).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=Se(this,ot,js).call(this),o=t?[...r].length+(s?[...s].length:0):0,a=i-[...e].length-o;if(a<=0)return e;let l=[...n].length,h=Math.ceil(a/l);return n.repeat(h)+e},An=function(e,t){var i,n,r;if(t.has(this))return Se(i=cn(this._store),ot,An).call(i,e,new Set);if(t.add(this),!qy(e,Se(this,ot,ah).call(this))){let h=Se(this,ot,Xs).call(this);return Se(n=h,ot,An).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let h=Se(this,ot,Xs).call(this);return Se(r=h,ot,An).call(r,e,t)}let l=Se(this,ot,hh).call(this,a,s);if(s){let{prefix:h,suffix:u}=Se(this,ot,js).call(this);l=h+l+(u??"")}return l},Z(Qt,Do,{system:new _(F("numeric"),0),symbols:new _(new J([new j("0"),new j("1"),new j("2"),new j("3"),new j("4"),new j("5"),new j("6"),new j("7"),new j("8"),new j("9")]),0)}),Z(Qt,Vo,{system:new _(F("cyclic"),0),symbols:new _(new j("\u2022"),0),suffix:new _(new j(" "),0)}),Z(Qt,Ho,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25AA"),0),suffix:new _(new j(" "),0)}),Z(Qt,Uo,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25E6"),0),suffix:new _(new j(" "),0)}),Z(Qt,$o,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25BE"),0),suffix:new _(new j(" "),0)}),Z(Qt,Wo,{system:new _(F("cyclic"),0),symbols:new _(new j("\u25B8"),0),suffix:new _(new j(" "),0)}),Z(Qt,Go,{system:new _(F("cyclic"),0),symbols:new _(new j(""),0),suffix:new _(new j(""),0)});var ue=Qt,fi=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0)return null;let i=t.length,n=((e-1)%i+i)%i;return t[n]}},Hr,Yy=class extends ue{constructor(e,t){super(e,t),Z(this,Hr),Fe(this,Hr,Fy(t))}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return!1}_generateInitialRepresentation(e){var t;let i=this._getSymbols();if(!i||i.length===0)return null;let n=e-M(this,Hr);return(t=i[n])!=null?t:null}};Hr=new WeakMap;var Ky=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length===0||e<1)return null;let i=t.length,n=t[(e-1)%i],r=Math.ceil(e/i);return n.repeat(r)}},Zy=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2||e<1)return null;let i=t.length,n="",r=e;for(;r!==0;)r=r-1,n=t[r%i]+n,r=Math.floor(r/i);return n}},uh=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:-1/0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getSymbols();if(!t||t.length<2)return null;let i=t.length;if(e===0)return t[0];let n="",r=e;for(;r!==0;)n=t[r%i]+n,r=Math.floor(r/i);return n}},Jy=class extends ue{constructor(e,t){super(e,t)}_getAutoRange(){return[{lower:0,upper:1/0}]}_usesNegativeSign(e){return e<0}_generateInitialRepresentation(e){let t=this._getAdditiveSymbols();if(!t||t.length===0)return null;let i="";if(e===0){let r=t.find(s=>s.weight===0);return r?r.symbol:null}let n=e;for(let r of t){let{weight:s,symbol:o}=r;if(s===0||s>n)continue;let a=Math.floor(n/s);if(i+=o.repeat(a),n-=s*a,n===0)return i}return null}},Hn,dt,yt,kd=class extends ue{constructor(t,i){super(t,i),Z(this,dt),Z(this,Hn);let n=_y(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Fe(this,Hn,r):Fe(this,Hn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ue._getNegativeFrom(Se(this,dt,yt).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ue._getPrefixFrom(Se(this,dt,yt).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ue._getSuffixFrom(Se(this,dt,yt).call(this))}_getAutoRange(){return ue._getAutoRangeFrom(Se(this,dt,yt).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ue._getRangeFrom(Se(this,dt,yt).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ue._getPadFrom(Se(this,dt,yt).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ue._getFallbackFrom(Se(this,dt,yt).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ue._getSymbolsFrom(Se(this,dt,yt).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ue._getAdditiveSymbolsFrom(Se(this,dt,yt).call(this))}_usesNegativeSign(t){return ue._useNegativeSignFrom(Se(this,dt,yt).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ue._generateInitialRepresentationFrom(Se(this,dt,yt).call(this),t)}};Hn=new WeakMap,dt=new WeakSet,yt=function(e=new Set){var t;if(e.has(this))return cn(this._store);e.add(this);let i=this._store.get(M(this,Hn));return i?i instanceof kd?Se(t=i,dt,yt).call(t,e):i:cn(this._store)};var Qy=kd,eb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],qs,Ys,Cr,Ks,jo,Ur,vt=class Ed extends ue{constructor(t,i){let{chars:n,descriptors:r}=M(Ed,jo).get(i);super(t,r),Z(this,Ur),Fe(this,Ur,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=M(this,Ur);if(t===0)return i.digits[0];let n=[],r=0,s=t;for(;s>0;)n.unshift({digit:s%10,position:r}),s=Math.floor(s/10),r++;let o=i.informal&&t>=10&&t<=19,a="",l=!1;for(let h=0;h<n.length;h++){let{digit:u,position:d}=n[h],p=h===n.length-1;u===0?!p&&!l&&(l=!0):(l&&(a+=i.digits[0],l=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};qs=new WeakMap,Ys=new WeakMap,Cr=new WeakMap,Ks=new WeakMap,jo=new WeakMap,Ur=new WeakMap,Z(vt,qs,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8D1F"),0)}}),Z(vt,Ys,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8D1F"),0)}}),Z(vt,Cr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8CA0"),0)}}),Z(vt,Ks,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new _(new j("\u3001"),0),fallback:new _(F("cjk-decimal"),0),range:new _(new J([new Le(-9999),new Le(9999)]),0),negative:new _(new j("\u8CA0"),0)}}),c(vt,"NAMES",new Set(eb)),Z(vt,jo,new Map([["simp-chinese-informal",M(vt,qs)],["simp-chinese-formal",M(vt,Ys)],["trad-chinese-informal",M(vt,Cr)],["trad-chinese-formal",M(vt,Ks)],["cjk-ideographic",M(vt,Cr)]]));var ch=vt,Xo,qo,us,Yo,Ko,Gi=class vi extends ue{constructor(t){super(t,M(vi,Xo))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return M(vi,us)[1];let i=[],n=t;for(;n>0;)i.push(n%100),n=Math.floor(n/100);let r=i.length,s="";for(let o=r-1;o>=0;o--){let a=i[o],l=o%2===1,h=o===r-1;if(!(a===0||h&&a===1||l&&a===1)){let u=Math.floor(a/10),d=a%10;s+=M(vi,qo)[u]+M(vi,us)[d]}l?a!==0&&(s+=M(vi,Yo)):o!==0&&(s+=M(vi,Ko))}return s}};Xo=new WeakMap,qo=new WeakMap,us=new WeakMap,Yo=new WeakMap,Ko=new WeakMap,Z(Gi,Xo,{range:new _(new J([new Le(1),F("infinite")]),0),suffix:new _(new j("/ "),0)}),Z(Gi,qo,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),Z(Gi,us,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),Z(Gi,Yo,"\u137B"),Z(Gi,Ko,"\u137C");var tb=Gi,ke,ib=class{constructor(){Z(this,ke),Fe(this,ke,new Map),M(this,ke).set("none",ue.createNone(M(this,ke))),M(this,ke).set("decimal",ue.createDecimal(M(this,ke))),M(this,ke).set("disc",ue.createDisc(M(this,ke))),M(this,ke).set("square",ue.createSquare(M(this,ke))),M(this,ke).set("circle",ue.createCircle(M(this,ke))),M(this,ke).set("disclosure-open",ue.createDisclosureOpen(M(this,ke))),M(this,ke).set("disclosure-closed",ue.createDisclosureClosed(M(this,ke)));for(let e of ue.CHINESE_LONGHAND_NAMES)M(this,ke).set(e,ue.createChineseLonghand(M(this,ke),e));M(this,ke).set("ethiopic-numeric",ue.createEthiopicNumeric(M(this,ke)))}define(e,t){if(!ky(e))return null;let i=ue.create(M(this,ke),t);return M(this,ke).set(e,i),i}getStyle(e){var t;return(t=M(this,ke).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:cn(M(this,ke))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:cn(M(this,ke))).formatMarker(t)}};ke=new WeakMap;var Zs=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},nb=class{constructor(){c(this,"map",[])}getMaxFixed(){return this.map.length==0?0:this.map[this.map.length-1].endFixed}getMaxSlipped(){return this.map.length==0?0:this.map[this.map.length-1].endSlipped}addStuckRange(e){if(this.map.length==0)this.map.push(new Zs(e,e,e));else{let t=this.map[this.map.length-1],i=t.endSlipped+e-t.endFixed;t.endFixed==t.endStuckFixed?(t.endFixed=e,t.endStuckFixed=e,t.endSlipped=i):this.map.push(new Zs(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Zs(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=ai(this.map.length,n=>e<=this.map[n].endFixed),i=this.map[t];return i.endSlipped-Math.max(0,i.endStuckFixed-e)}fixedBySlipped(e){let t=ai(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},rb=class Zo{constructor(t,i,n,r,s,o,a,l){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=s,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=l,c(this,"flowName"),c(this,"isBlockValue",null),c(this,"hasBoxValue",null),c(this,"styleValues",{}),c(this,"beforeBox",null),c(this,"afterBox",null),c(this,"breakBefore",null),this.flowName=s.flowName,this.hasBox()){let h=i._pseudos;if(h&&h.before){let u=new Zo(t,h.before,n,!1,s,this.isBlock(),a,!0),d=u.styleValue("content");Dt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=rt(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&it(this.breakBefore)&&(s.breakBefore=rt(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new Zo(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");Dt(o)&&(this.afterBox=s)}}}styleValue(t,i){if(!(t in this.styleValues)){let n=this.style[t];this.styleValues[t]=n?n.evaluate(this.context,t):i||null}return this.styleValues[t]}displayValue(){return this.styleValue("display",b.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=vc(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==b.none&&!bo(this.styleValue("position"))),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},sb=class{constructor(e){this.context=e,c(this,"stack",[]),c(this,"atBlockStart",!0),c(this,"atFlowStart",!0),c(this,"atStartStack",[])}empty(){return this.stack.length===0}lastBox(){return this.stack[this.stack.length-1]}lastFlowName(){let e=this.lastBox();return e?e.flowChunk.flowName:null}isCurrentBoxDisplayed(){return this.stack.every(e=>e.displayValue()!==b.none)}push(e,t,i,n){let r=this.lastBox();n&&r&&n.flowName!==r.flowName&&this.atStartStack.push({atBlockStart:this.atBlockStart,atFlowStart:this.atFlowStart});let s=n||r.flowChunk,o=this.atFlowStart||!!n,a=this.isCurrentBoxDisplayed(),l=new rb(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(l),this.atBlockStart=l.hasBox()?!l.beforeBox&&l.isBlock():this.atBlockStart,this.atFlowStart=l.hasBox()?!l.beforeBox&&o:this.atFlowStart,l}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",b.normal).toString(),n=lc(i);n&&!$e(e,n)&&(this.atBlockStart=!1,this.atFlowStart=!1)}}pop(e){let t=this.stack.pop();if(t.buildAfterPseudoElementBox(e,this.atBlockStart,this.atFlowStart),this.atFlowStart&&t.afterBox){let n=t.afterBox.getBreakValue("before");t.flowChunk.breakBefore=rt(t.flowChunk.breakBefore,n)}let i=this.lastBox();if(i)if(i.flowName===t.flowName)t.hasBox()&&(this.atBlockStart=this.atFlowStart=!1);else{let n=this.atStartStack.pop();this.atBlockStart=n.atBlockStart,this.atFlowStart=n.atFlowStart}return t}nearestBlockStartOffset(e){if(!e.atBlockStart)return e.offset;let t=this.stack.length-1,i=this.stack[t];for(i===e&&(t--,i=this.stack[t]);t>=0;){if(i.flowName!==e.flowName)return e.offset;if(!i.atBlockStart||i.isRoot)return i.offset;e=i,i=this.stack[--t]}throw new Error("No block start offset found!")}},dh=class{constructor(e,t,i,n,r,s,o,a,l,h){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=r,this.validatorSet=s,this.counterListener=o,c(this,"root"),c(this,"cascadeHolder"),c(this,"last"),c(this,"rootStyle",{}),c(this,"styleMap",{}),c(this,"flows",{}),c(this,"flowChunks",[]),c(this,"flowListener",null),c(this,"flowToReach",null),c(this,"idToReach",null),c(this,"cascade"),c(this,"offsetMap"),c(this,"primary",!0),c(this,"primaryStack",[]),c(this,"rootBackgroundAssigned",!1),c(this,"rootLayoutAssigned",!1),c(this,"lastOffset"),c(this,"breakBeforeValues",{}),c(this,"boxStack"),c(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang,l,h),this.offsetMap=new nb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new sb(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.postprocessTopStyle(d,!1),this.root.namespaceURI){case"http://www.w3.org/1999/xhtml":this.bodyReached=!1;break}this.primaryStack.push(!0),this.styleMap={},this.styleMap[`e${u}`]=d,this.lastOffset++,this.replayFlowElementsFromOffset(-1)}hasProp(e,t,i){let n=e[i];return n&&n.evaluate(this.context)!==t[i]}transferPropsToRoot(e,t){for(let i in t){let n=e[i];if(n)this.rootStyle[i]=n,delete e[i];else{let r=t[i];r&&(this.rootStyle[i]=new _(r,qu))}}}postprocessTopStyle(e,t){var i;if(t)for(let n of["writing-mode","direction"])e[n]&&!(t&&this.rootStyle[n])&&(this.rootStyle[n]=e[n]);else for(let n in e)zn(n)&&(this.rootStyle[n]=e[n]);if(!this.rootBackgroundAssigned){let n=this.hasProp(e,this.validatorSet.backgroundProps,"background-color")?e["background-color"].evaluate(this.context):null,r=this.hasProp(e,this.validatorSet.backgroundProps,"background-image")?e["background-image"].evaluate(this.context):null;(n&&!K(n)||r&&!K(r))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<ph.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,ph[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],r=!0;if(n&&!K(n.value)){let a=n.evaluate(this.context);if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=this.context.initialFontSize;break;case"%":l*=this.context.initialFontSize/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*At.lh/At.em;break;default:{let h=At[a.unit];h&&(l*=h),r=!1}}this.context.rootFontSize=l,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!K(o.value)){let a=o.evaluate(this.context);if(a instanceof gt)this.context.rootLineHeight=a.num*s;else if(a instanceof I){let l=a.num;switch(a.unit){case"em":case"rem":l*=s;break;case"%":l*=s/100;break;case"lh":case"rlh":l*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let h=At[a.unit];h&&(l*=h)}}this.context.rootLineHeight=l}}else this.context.rootLineHeight=this.context.fontSize()*this.context.pref.lineHeight}}getTopContainerStyle(){let e=0;for(;!this.bodyReached&&(e+=5e3,this.styleUntil(e,0)!=Number.POSITIVE_INFINITY););return this.rootStyle}getAttrStyle(e){if(e.style instanceof CSSStyleDeclaration){let t=e.getAttribute("style");if(t)return bw(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}getReachedOffset(){return this.lastOffset}replayFlowElementsFromOffset(e){if(e>=this.lastOffset)return;let t=this.context,i=this.xmldoc.getElementOffset(this.root);if(e<i){let s=this.getStyle(this.root,!1),o=Re(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",l=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,l)}let n=this.xmldoc.getNodeByOffset(e),r=this.xmldoc.getNodeOffset(n,0,!1);if(!(r>=this.lastOffset))for(;;){if(n.nodeType!=1)r+=n.textContent.length;else{let o=n,a=this.getStyle(o,!1),l=a["flow-into"];if(l){let h=l.evaluate(t,"flow-into").toString();this.encounteredFlowElement(h,a,o,r)}r++}if(r>=this.lastOffset)break;let s=n.firstChild;if(s==null){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n===this.root)return}n=s}}resetFlowChunkStream(e){this.flowListener=e;for(let t=0;t<this.flowChunks.length;t++)this.flowListener.encounteredFlowChunk(this.flowChunks[t],this.flows[this.flowChunks[t].flowName])}styleUntilFlowIsReached(e){this.flowToReach=e;let t=0;for(;!(this.flowToReach==null||(t+=5e3,this.styleUntil(t,0)==Number.POSITIVE_INFINITY)););}styleUntilIdIsReached(e){if(!e)return;this.idToReach=e;let t=0;for(;!(!this.idToReach||(t+=5e3,this.styleUntil(t,0)===Number.POSITIVE_INFINITY)););this.idToReach=null}encounteredFlowElement(e,t,i,n){let r=0,s=Number.POSITIVE_INFINITY,o=!1,a=!1,l=!1,h=t["flow-options"];if(h){let g=Of(h.evaluate(this.context,"flow-options"));o=!!g.exclusive,a=!!g.static,l=!!g.last}let u=t["flow-linger"];u&&(s=Tl(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=Tl(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let g=this.boxStack.lastFlowName();f=this.flows[e]=new Yg(e,g)}let m=new Kg(e,i,n,r,s,o,a,l,p);return this.flowChunks.push(m),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(m,f),m}registerForcedBreakOffset(e,t,i){if(it(e)){let r=this.flows[i].forcedBreakOffsets;(r.length===0||r[r.length-1]<t)&&r.push(t)}let n=this.breakBeforeValues[t];this.breakBeforeValues[t]=rt(n,e)}styleUntil(e,t){let i=-1,n;if(e<=this.lastOffset&&(n=this.offsetMap.slippedByFixed(e),i=n+t,i<this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i);if(this.last==null)return Number.POSITIVE_INFINITY;let r=this.context;for(;;){let s=this.last.firstChild;if(s==null)for(;;){if(this.last.nodeType==1){this.cascade.popElement(this.last),this.primary=this.primaryStack.pop();let o=this.boxStack.pop(this.lastOffset),a=null;if(o.afterBox){let l=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(l,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=rt(a,o.getBreakValue("after")),this.registerForcedBreakOffset(a,this.lastOffset,o.flowName)}if(s=this.last.nextSibling,s)break;if(this.last=this.last.parentNode,this.last===this.root)return this.last=null,e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped())?this.offsetMap.fixedBySlipped(i):Number.POSITIVE_INFINITY}if(this.last=s,this.last.nodeType!=1)this.lastOffset+=this.last.textContent.length,this.boxStack.encounteredTextNode(this.last),this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset);else{let o=this.last,a=this.getAttrStyle(o);this.primaryStack.push(this.primary),this.cascade.pushElement(this,o,a,this.lastOffset);let l=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");l&&l===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let h,u=a["flow-into"];if(u){let p=u.evaluate(r,"flow-into").toString(),f=this.encounteredFlowElement(p,a,o,this.lastOffset);this.primary=!!this.primaryFlows[p],h=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else h=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(h.breakBefore=rt(h.flowChunk.breakBefore,h.breakBefore));let d=this.boxStack.nearestBlockStartOffset(h);if(d===0){let p=a.page,f=p&&!K(p.value)&&p.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(h.breakBefore,d,h.flowName),h.beforeBox){let p=h.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,h.beforeBox.atBlockStart?d:h.offset,h.flowName)}if(this.primary&&h.displayValue()===b.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&d===0)continue;if(e<this.lastOffset&&(i<0&&(n=this.offsetMap.slippedByFixed(e),i=n+t),i<=this.offsetMap.getMaxSlipped()))return this.offsetMap.fixedBySlipped(i)}}}getStyle(e,t){let i=this.xmldoc.getElementOffset(e),n=`e${i}`;return t&&(i=this.xmldoc.getNodeOffset(e,0,!0)),this.lastOffset<=i&&this.styleUntil(i,0),this.styleMap[n]}processContent(e,t,i){}},ph=["column-count","column-width","column-fill"],Qi=class{constructor(e){this.validator=e,c(this,"success",null),c(this,"failure",null),c(this,"code",0)}isSpecial(){return this.code!=0}markAsStartGroup(){this.code=-1}isStartGroup(){return this.code==-1}markAsEndGroup(){this.code=-2}isEndGroup(){return this.code==-2}markAsStartAlternate(e){this.code=2*e+1}isStartAlternate(){return this.code>0&&this.code%2!=0}markAsEndAlternate(e){this.code=2*e+2}isEndAlternate(){return this.code>0&&this.code%2==0}getAlternate(){return Math.floor((this.code-1)/2)}},gi=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Sn=class Nd{constructor(){c(this,"nodes",[]),c(this,"connections",[]),c(this,"match",[]),c(this,"nomatch",[]),c(this,"error",[]),c(this,"emptyHead",!0)}connect(t,i){for(let n=0;n<t.length;n++)this.connections[t[n]].what=i;t.splice(0,t.length)}clone(){let t=new Nd;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new Qi(n.validator);r.code=n.code,t.nodes.push(r)}for(let i=0;i<this.connections.length;i++){let n=this.connections[i],r=new gi(n.where,n.success);r.what=n.what,t.connections.push(r)}return t.match.push(...this.match),t.nomatch.push(...this.nomatch),t.error.push(...this.error),t}addSpecialToArr(t,i,n){let r=this.nodes.length,s=new Qi(fh);n>=0?i?s.markAsStartAlternate(n):s.markAsEndAlternate(n):i?s.markAsStartGroup():s.markAsEndGroup(),this.nodes.push(s),this.connect(t,r);let o=new gi(r,!0),a=new gi(r,!1);t.push(this.connections.length),this.connections.push(a),t.push(this.connections.length),this.connections.push(o)}endSpecialGroup(){let t=[this.match,this.nomatch,this.error];for(let i=0;i<t.length;i++)this.addSpecialToArr(t[i],!1,-1)}startSpecialGroup(){if(this.nodes.length)throw new Error("invalid call");this.addSpecialToArr(this.match,!0,-1)}endClause(t){this.addSpecialToArr(this.match,!1,t)}startClause(t){if(this.nodes.length)throw new Error("invalid call");let i=new Qi(fh);i.markAsStartAlternate(t),this.nodes.push(i);let n=new gi(0,!0),r=new gi(0,!1);this.nomatch.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}addPrimitive(t){let i=this.nodes.length;this.nodes.push(new Qi(t));let n=new gi(i,!0),r=new gi(i,!1);this.connect(this.match,i),this.emptyHead?(this.nomatch.push(this.connections.length),this.emptyHead=!1):this.error.push(this.connections.length),this.connections.push(r),this.match.push(this.connections.length),this.connections.push(n)}isSimple(){return this.nodes.length==1&&!this.nodes[0].isSpecial()}isPrimitive(){return this.isSimple()&&this.nodes[0].validator instanceof Be}addGroup(t,i){if(t.nodes.length==0)return;let n=this.nodes.length;if(i==4&&n==1&&t.isPrimitive()&&this.isPrimitive()){this.nodes[0].validator=this.nodes[0].validator.combine(t.nodes[0].validator);return}for(let s=0;s<t.nodes.length;s++)this.nodes.push(t.nodes[s]);i==4?(this.emptyHead=!0,this.connect(this.nomatch,n)):this.connect(this.match,n);let r=this.connections.length;for(let s=0;s<t.connections.length;s++){let o=t.connections[s];o.where+=n,o.what>=0&&(o.what+=n),this.connections.push(o)}for(let s=0;s<t.match.length;s++)this.match.push(t.match[s]+r);if(i==3&&this.connect(this.match,n),i==2||i==3)for(let s=0;s<t.nomatch.length;s++)this.match.push(t.nomatch[s]+r);else if(this.emptyHead){for(let s=0;s<t.nomatch.length;s++)this.nomatch.push(t.nomatch[s]+r);this.emptyHead=t.emptyHead}else for(let s=0;s<t.nomatch.length;s++)this.error.push(t.nomatch[s]+r);for(let s=0;s<t.error.length;s++)this.error.push(t.error[s]+r);t.nodes=null,t.connections=null}finish(t,i){let n=this.nodes.length;this.nodes.push(t),this.nodes.push(i),this.connect(this.match,n),this.connect(this.nomatch,n+1),this.connect(this.error,n+1);for(let r of this.connections)r.success?this.nodes[r.where].success=this.nodes[r.what]:this.nodes[r.where].failure=this.nodes[r.what];for(let r=0;r<n;r++)if(this.nodes[r].failure==null||this.nodes[r].success==null)throw new Error("Invalid validator state");return this.nodes[0]}},ob=1,Pd=2,Td=4,xi=8,$r=16,Jo=32,Wr=64,Id=128,Rn=256,Fn=512,Qo=1024,Ad=2048,Rd=4096,Fd=8192,Ld=class extends Kt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Be=class Od extends Ld{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&ob?t:null}visitSlash(t){return this.allowed&Ad?t:null}visitStr(t){return this.allowed&Pd?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&Td||this.allowed&Wr&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Fn)?t.unit=="%"&&this.allowed&Qo?t:null:t.num<0&&!(this.allowed&Rn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Fn?t:null:t.num<=0&&!(this.allowed&Rn)?null:this.allowed&$r?t:null}visitInt(t){return t.num==0?this.allowed&Fn?t:null:t.num<=0&&!(this.allowed&Rn)?null:this.allowed&(Jo|$r)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Wr&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Id?t:null}visitURange(t){return this.allowed&Rd?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&Wr){if(t.name==="device-cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Eu(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Fd){let i=t.visit(new Tu);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(xi|$r|Jo|Rn|Fn|Qo)?t:null}visitExpr(t){return this.allowed&2046?t:null}combine(t){let i={},n={};for(let r in this.idents)i[r]=this.idents[r];for(let r in t.idents)i[r]=t.idents[r];for(let r in this.units)n[r]=this.units[r];for(let r in t.units)n[r]=t.units[r];return new Od(this.allowed|t.allowed,i,n)}},oe={},fh=new Be(0,oe,oe),Ha=class extends Ld{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new Qi(null),this.failureTerminal=new Qi(null),this.first=e.finish(this.successTerminal,this.failureTerminal)}validateList(e,t,i){let n=t?[]:e,r=this.first,s=i,o=null,a=null;for(;r!==this.successTerminal&&r!==this.failureTerminal;){if(s>=e.length){r=r.failure;continue}let l=e[s],h=l;if(r.isSpecial()){let u=!0;r.isStartGroup()?(o?o.push(a):o=[a],a=[]):r.isEndGroup()?o.length>0?a=o.pop():a=null:r.isEndAlternate()?a[r.getAlternate()]="taken":u=a[r.getAlternate()]==null,r=u?r.success:r.failure}else{if(s==0&&!t&&r.validator instanceof Un&&this instanceof Un){if(h=new J(e).visit(r.validator),h){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof Ua&&this instanceof Un){if(h=new Ze(e).visit(r.validator),h){s=e.length,r=r.success;continue}}else h=l.visit(r.validator);if(!h){r=r.failure;continue}if(h!==l&&e===n){n=[];for(let u=0;u<s;u++)n[u]=e[u]}e!==n&&(n[s-i]=h),s++,r=r.success}}return r===this.successTerminal&&(t?n.length>0:s==e.length)?n:null}validateSingle(e){let t=null,i=this.first;for(;i!==this.successTerminal&&i!==this.failureTerminal;){if(!e){i=i.failure;continue}if(i.isSpecial()){i=i.success;continue}if(t=e.visit(i.validator),!t){i=i.failure;continue}e=null,i=i.success}return i===this.successTerminal?t:null}visitEmpty(e){return this.validateSingle(e)}visitSlash(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitURange(e){return this.validateSingle(e)}visitSpaceList(e){return null}visitCommaList(e){return null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return null}},Un=class extends Ha{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new J(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof Ua){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new Ze(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},Ua=class extends Ha{constructor(e){super(e)}visitSpaceList(e){return this.validateSingle(e)}visitCommaList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Ze(t):null}validateForShorthand(e,t){let i=this.first,n;for(;i!==this.failureTerminal;){if(n=i.validator.validateForShorthand(e,t),n)return n;i=i.failure}return null}},ab=class extends Ha{constructor(e,t){super(t),this.name=e}validateSingle(e){return null}visitFunc(e){if(e.name.toLowerCase()!=this.name)return null;let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new Ri(e.name,t):null}},Bd=class{tryParse(e,t,i){return t}success(e,t){}},Md=class extends Bd{constructor(e,t){super(),this.name=t,c(this,"validator"),this.validator=e.validators[this.name]}tryParse(e,t,i){if(i.values[this.name])return t;let n=this.validator.validateForShorthand(e,t);if(n){let r=n.length,s=r>1?new J(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},lb=class extends Md{constructor(e,t){super(e,t[0]),this.names=t}success(e,t){for(let i=0;i<this.names.length;i++)t.values[this.names[i]]=e}},hb=class extends Bd{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==fn){if(++t==e.length)return n}else return n;let r=this.nodes[0].tryParse(e,t,i);if(r==t)return n;t=r;for(let s=1;s<this.nodes.length&&t<e.length&&(r=this.nodes[s].tryParse(e,t,i),r!=t);s++)t=r;return t}},$a=class extends Kt{constructor(){super(...arguments),c(this,"syntax",null),c(this,"propList",null),c(this,"error",!1),c(this,"values",{}),c(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new Md(this.validatorSet,e)}clone(){let e=new this.constructor;return e.syntax=this.syntax,e.propList=this.propList,e.validatorSet=this.validatorSet,e}init(e,t){this.syntax=e,this.propList=t}finish(e,t){var i,n;if(!this.error){for(let r of this.propList)t.simpleProperty(r,(n=(i=this.values[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:b.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},yn=class extends $a{constructor(){super()}validateList(e){let t=0,i=0;for(;t<e.length;){let n=this.syntax[i].tryParse(e,t,this);if(n>t){t=n,i=0;continue}if(++i==this.syntax.length){this.error=!0;break}}return t}},_d=class extends $a{constructor(){super()}validateList(e){if(e.length>this.syntax.length||e.length==0)return this.error=!0,0;for(let t=0;t<this.syntax.length;t++){let i=t;for(;i>=e.length;)i=i==1?0:i-2;if(this.syntax[t].tryParse(e,i,this)!=i+1)return this.error=!0,0}return e.length}createSyntaxNode(){return new lb(this.validatorSet,this.propList)}},ub=class extends $a{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===fn){t=i;break}if(t>this.syntax.length||e.length==0)return this.error=!0,0;for(let i=0;i<this.syntax.length;i++){let n=i;for(;n>=t;)n=n==1?0:n-2;let r;if(t+1<e.length)for(r=t+i+1;r>=e.length;)r=r-(r==t+2?1:2);else r=n;let s=[e[n],e[r]];if(this.syntax[i].tryParse(s,0,this)!=2)return this.error=!0,0}return e.length}},cb=class extends yn{constructor(){super()}mergeIn(e,t){var i,n;for(let r of this.propList){let s=(n=(i=t[r])!=null?i:this.validatorSet.defaultValues[r])!=null?n:b.initial,o=e[r];o||(o=[],e[r]=o),o.push(s)}}visitCommaList(e){let t={};for(let i=0;i<e.values.length;i++)if(this.values={},e.values[i]instanceof Ze?this.error=!0:(e.values[i].visit(this),this.mergeIn(t,this.values),this.values["background-color"]&&i!=e.values.length-1&&(this.error=!0)),this.error)return null;this.values={};for(let i in t)i=="background-color"?this.values[i]=t[i].pop():this.values[i]=new Ze(t[i]);return null}},db=class extends yn{constructor(){super()}init(e,t){super.init(e,t),this.propList.push("font-family","line-height","font-size","font-stretch","font-variant-ligatures","font-variant-caps","font-variant-numeric","font-variant-east-asian")}validateList(e){let t=super.validateList(e),i=this.values["font-variant_css2"];i&&(delete this.values["font-variant_css2"],this.values["font-variant-caps"]=i);let n=this.values["font-stretch_css3"];if(n&&(delete this.values["font-stretch_css3"],this.values["font-stretch"]=n),t+2>e.length)return this.error=!0,t;this.error=!1;let r=this.validatorSet.validators;if(!e[t].visit(r["font-size"]))return this.error=!0,t;if(this.values["font-size"]=e[t++],e[t]===fn){if(t++,t+2>e.length)return this.error=!0,t;if(!e[t].visit(r["line-height"]))return this.error=!0,t;this.values["line-height"]=e[t++]}let s=t==e.length-1?e[t]:new J(e.slice(t,e.length));return s.visit(r["font-family"])?(this.values["font-family"]=s,e.length):(this.error=!0,t)}visitCommaList(e){if(e.values[0].visit(this),this.error)return null;let t=[this.values["font-family"]];for(let n=1;n<e.values.length;n++)t.push(e.values[n]);let i=new Ze(t);return i.visit(this.validatorSet.validators["font-family"])?this.values["font-family"]=i:this.error=!0,null}visitIdent(e){let t=this.validatorSet.systemFonts[e.name];if(t)for(let i in t)this.values[i]=t[i];else this.error=!0;return null}},pb=class extends yn{validateList(e){if(e.length===1&&e[0]instanceof le)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[b.auto,b.auto];break;case"none":e=[F("no-autospace"),F("space-all")];break}return super.validateList(e)}},fb=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],gb=class extends yn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)fb.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},gh={SIMPLE:yn,INSETS:_d,INSETS_SLASH:ub,COMMA:cb,FONT:db,TEXT_SPACING:pb,ALL:gb},mb=["initial-letter"],wb=class{constructor(){c(this,"validators",{}),c(this,"prefixes",{}),c(this,"defaultValues",{}),c(this,"namedValidators",{}),c(this,"systemFonts",{}),c(this,"shorthands",{}),c(this,"layoutProps",{}),c(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new I(t.num,t.text);else if(t.type==7)i=new vu(t.text);else if(t.type==1)i=F(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Sn;if(e=="||"){for(let r=0;r<t.length;r++){let s=new Sn;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new Sn;return n.startSpecialGroup(),n.addGroup(i,3),n.endSpecialGroup(),n}else{let n;switch(e){case" ":n=1;break;case"|":case"||":n=4;break;default:throw new Error("unexpected op")}for(let r=0;r<t.length;r++)i.addGroup(t[r],r==0?1:n);return i}}addCounts(e,t,i){let n=new Sn;for(let r=0;r<t;r++)n.addGroup(e.clone(),1);if(i==Number.POSITIVE_INFINITY)n.addGroup(e,3);else for(let r=t;r<i;r++)n.addGroup(e.clone(),2);return n}primitive(e){let t=new Sn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new Ua(t);break;case"SPACE":i=new Un(t);break;default:i=new ab(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Be(Wr,oe,oe)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Be(Fd,oe,oe)),this.namedValidators.POS_INT=this.primitive(new Be(Jo,oe,oe)),this.namedValidators.POS_NUM=this.primitive(new Be($r,oe,oe)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Be(xi,oe,{"%":X})),this.namedValidators.NEGATIVE=this.primitive(new Be(Rn,oe,oe)),this.namedValidators.ZERO=this.primitive(new Be(Fn,oe,oe)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Be(Qo,oe,oe)),this.namedValidators.POS_LENGTH=this.primitive(new Be(xi,oe,{em:X,ex:X,ch:X,rem:X,lh:X,rlh:X,vw:X,vh:X,vi:X,vb:X,vmin:X,vmax:X,pvw:X,pvh:X,pvi:X,pvb:X,pvmin:X,pvmax:X,cm:X,mm:X,in:X,px:X,pt:X,pc:X,q:X})),this.namedValidators.POS_ANGLE=this.primitive(new Be(xi,oe,{deg:X,grad:X,rad:X,turn:X})),this.namedValidators.POS_TIME=this.primitive(new Be(xi,oe,{s:X,ms:X})),this.namedValidators.FREQUENCY=this.primitive(new Be(xi,oe,{Hz:X,kHz:X})),this.namedValidators.RESOLUTION=this.primitive(new Be(xi,oe,{dpi:X,dpcm:X,dppx:X})),this.namedValidators.URI=this.primitive(new Be(Id,oe,oe)),this.namedValidators.URANGE=this.primitive(new Be(Rd,oe,oe)),this.namedValidators.IDENT=this.primitive(new Be(Td,oe,oe)),this.namedValidators.STRING=this.primitive(new Be(Pd,oe,oe)),this.namedValidators.SLASH=this.primitive(new Be(Ad,oe,oe));let e={"font-family":F("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let r=i.text;if(e.consume(),t!=2){if(e.token().type!=39)throw new Error("'=' expected");this.isBuiltIn(r)||(this.prefixes[r]=n)}else if(e.token().type!=18)throw new Error("':' expected");return r}parseValidators(e){for(;;){let t=this.readNameAndPrefixes(e,1);if(!t)return;let i=[],n=[],r="",s,o=!0,a=()=>{if(i.length==0)throw new Error("No values");return i.length==1?i[0]:this.newGroup(r,i)},l=u=>{if(o)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,o=!0},h=null;for(;!h;){e.consume();let u=e.token();switch(u.type){case 1:if(o||l(" "),this.isBuiltIn(u.text)){let d=this.namedValidators[u.text];if(!d)throw new Error(`'${u.text}' unexpected`);i.push(d.clone())}else{let d={};d[u.text.toLowerCase()]=F(u.text),i.push(this.primitive(new Be(0,d,oe)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Le(u.num),i.push(this.primitive(new Be(0,d,oe))),o=!1;break}case 34:l("|");break;case 25:l("||");break;case 14:o||l(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||l(" "),n.push({vals:i,op:r,b:"(",fn:u.text}),r="",i=[],o=!0;break;case 15:{s=a();let d=n.pop();if(d.b!="[")throw new Error("']' unexpected");i=d.vals,i.push(s),r=d.op,o=!1;break}case 11:{s=a();let d=n.pop();if(d.b!="(")throw new Error("')' unexpected");i=d.vals,i.push(this.newFunc(d.fn,s)),r=d.op,o=!1;break}case 18:if(o)throw new Error("':' unexpected");e.consume(),i.push(this.addReplacement(i.pop(),e.token()));break;case 22:if(o)throw new Error("'?' unexpected");i.push(this.addCounts(i.pop(),0,1));break;case 36:if(o)throw new Error("'*' unexpected");i.push(this.addCounts(i.pop(),0,Number.POSITIVE_INFINITY));break;case 23:if(o)throw new Error("'+' unexpected");i.push(this.addCounts(i.pop(),1,Number.POSITIVE_INFINITY));break;case 12:{if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");let d=u.num,p=d;if(e.consume(),u=e.token(),u.type==16){if(e.consume(),u=e.token(),u.type!=5)throw new Error("<int> expected");p=u.num,e.consume(),u=e.token()}if(u.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),d,p));break}case 17:if(h=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=h:h.isSimple()?this.validators[t]=h.nodes[0].validator:this.validators[t]=new Un(h)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(F(n.text));break;case 4:i.push(new gt(n.num));break;case 5:i.push(new Le(n.num));break;case 3:i.push(new I(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new J(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&gh[i.text]?(n=new gh[i.text],e.consume()):n=new yn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],l=[];for(;!r;)switch(e.consume(),i=e.token(),i.type){case 1:if(this.validators[i.text])s.push(n.syntaxNodeForProperty(i.text)),i.text.includes("_")||l.push(i.text);else if(this.shorthands[i.text]instanceof _d){let h=this.shorthands[i.text];s.push(h.createSyntaxNode()),l.push(...h.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(s.length>0||o)throw new Error("unexpected slash");o=!0;break;case 14:a.push({slash:o,syntax:s}),s=[],o=!1;break;case 15:{let h=new hb(s,o),u=a.pop();s=u.syntax,o=u.slash,s.push(h);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,l),this.shorthands[t]=n}}parse(e){let t=new Ft(e,null);this.parseValidators(t),this.parseDefaults(t),this.parseShorthands(t),this.backgroundProps=this.makePropSet(["background"]),this.layoutProps=this.makePropSet(["margin","border","padding","columns","column-gap","column-rule","column-fill"])}makePropSet(e){var t;let i={};for(let n of e){let r=this.shorthands[n],s=r?r.propList:[n];for(let o of s)i[o]=(t=this.defaultValues[o])!=null?t:b.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(zt(e)||r==="font-face"||bb(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){Xy(e,t)?n.simpleProperty(e,t,i):n.invalidPropertyValue(e,t);return}let s="",o=e;e=e.toLowerCase();let a=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);a&&(s=a[1],e=a[2]);let l=this.prefixes[e];if(!l||!l[s]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):s&&!Xh.includes(`-${s}-`)||n.unknownProperty(o,t);return}else if(mb.includes(e)&&!Object.keys(l).some(u=>Nr(u?`-${u}-`:"",e))){n.unknownProperty(o,t);return}let h=this.validators[e];if(h){let u=K(t)||t.isExpr()?t:t.visit(h);u?n.simpleProperty(e,u,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(o,t)}else{let u=this.shorthands[e].clone();K(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function zd(){let e=new wb;return e.initBuiltInValidators(),e.parse(Vu),e}var yb=class extends Kt{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function bb(e){let t=new yb;return e.visit(t),t.varFound}var tv=`OTTO${new Date().valueOf()}`;function Wa(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function vb(e){let t=new oi;for(let i of Wa(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function xb(e,t){let i={};for(let n in e)i[n]=Re(e,n).evaluate(t,n);return i}var Dd=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=vb(this.properties),this.src=this.properties.src?this.properties.src.toString():null;let t=this.properties["font-family"];this.family=t?t.stringValue():null}traitsEqual(e){return this.fontTraitKey==e.fontTraitKey}makeAtRule(e,t){let i=new oi;i.append(`@font-face {
|
|
1794
1795
|
font-family: `),i.append(this.family),i.append(`;
|
|
1795
|
-
`);for(let n of
|
|
1796
|
-
`);if(t){i.append('src: url("');let n=
|
|
1796
|
+
`);for(let n of Wa(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1797
|
+
`);if(t){i.append('src: url("');let n=vg(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
|
|
1797
1798
|
}
|
|
1798
|
-
`),i.toString()}},Zb=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],s=t.family;if(n){if(n!=s)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=s}filterFontFamily(e){if(e instanceof Ke){let t=e.values,i=[];for(let n of t){let s=this.familyMap[n.stringValue()];s&&i.push(F(s)),i.push(n)}return new Ke(i)}else{let t=this.familyMap[e.stringValue()];return t?new Ke([F(t),e]):e}}},Jb=class{constructor(e,t,i){this.head=e,this.body=t,c(this,"srcURLMap",{}),c(this,"familyPrefix"),c(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=B("initFont"),s=e.src,r={};for(let h of Pa(e.properties))r[h]=e.properties[h];let o=this.getViewFontFamily(e,i);r["font-family"]=F(o);let a=new gd(r),l=this.head.ownerDocument.createElement("style");return l.textContent=a.makeAtRule(s,t),this.head.appendChild(l),H.debug("Load font:",s),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,s=this.srcURLMap[n];return s?s.piggyback(r=>{let o=r;o.traitsEqual(e)?(t.registerFamily(e,o),H.debug("Found already-loaded font:",i)):H.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(s=new Wn(()=>{let r=B("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?tr(o,"blob").then(l=>{if(!l.responseBlob){r.finish(null);return}a(l.responseBlob).then(h=>{this.initFont(e,h,t).thenFinish(r)})}):this.initFont(e,null,t).thenFinish(r),r.result()},`loadFont ${i}`),this.srcURLMap[n]=s,s.start()),s}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){H.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return er(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(s=>{}))}),t===0)return N(!0);let i=B("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},Qb=1,or=class{constructor(e,t,i,n,s){this.name=t,this.pseudoName=i,this.classes=n,this.parent=s,c(this,"specified",{}),c(this,"children",[]),c(this,"pageMaster",null),c(this,"index",0),c(this,"key"),c(this,"_scope"),this._scope=e,this.key=`p${Qb++}`,s&&(this.index=s.children.length,s.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},ey=class extends or{constructor(e){super(e,null,null,[],null),this.specified.width=new _(Hn,0),this.specified.height=new _($n,0)}},Zl=class extends Dr{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(s,r){let o=s.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let l=this.lookupInstance(a);if(l)return r?l.resolveFunc(o[2]):l.resolveName(o[2])}}return null}}},md=class wd extends or{constructor(t,i,n,s,r,o,a){super(t,i,n,s,r),this.condition=o,this.specificity=a,c(this,"keyMap",{}),t instanceof Zl||(this._scope=new Zl(t,this)),this.pageMaster=this,this.specified.width=new _(Hn,0),this.specified.height=new _($n,0),this.specified["wrap-flow"]=new _(y.auto,0),this.specified.position=new _(y.relative,0),this.specified.overflow=new _(y.visible,0)}createInstance(t){return new Ia(t,this)}clone(t){let i=new wd(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},bd=class yd extends or{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new _(y.auto,0)}createInstance(t){return new sy(t,this)}clone(t){let i=new yd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Kn=class vd extends or{constructor(t,i,n,s,r){super(t,i,n,s,r),this.pageMaster=r.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new Zi(t,this)}clone(t){let i=new vd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function ty(e,t,i){return!t||K(t)?new $e(e,i):t.toExpr(e,e.zero)}function fe(e,t,i){return!t||t===y.auto||K(t)?null:t.toExpr(e,i)}function iy(e,t,i){return!t||t===y.normal||K(t)?null:t.toExpr(e,i)}function dt(e,t,i){return!t||t===y.auto||K(t)?e.zero:t.toExpr(e,i)}function Jl(e,t,i){return!t||K(t)?e.zero:t===y.auto?null:t.toExpr(e,i)}function Bt(e,t,i,n){return!t||i===y.none||K(t)?e.zero:t.toExpr(e,n)}function xd(e,t,i){return!t||K(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var ar=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,c(this,"cascaded",{}),c(this,"style",{}),c(this,"autoWidth",null),c(this,"autoHeight",null),c(this,"children",[]),c(this,"isAutoWidth",!1),c(this,"isAutoHeight",!1),c(this,"isTopDependentOnAutoHeight",!1),c(this,"isRightDependentOnAutoWidth",!1),c(this,"calculatedWidth",0),c(this,"calculatedHeight",0),c(this,"pageMasterInstance",null),c(this,"namedValues",{}),c(this,"namedFuncs",{}),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"suppressEmptyBoxGeneration",!1),c(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return Y(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let s=this.vertical?sc:rc;n=e;for(let r in s)n=n.replace(r,s[r])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new Kh(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=pe(i,cs(i,new yn(i,"min",[n,s]),Y(i,r,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=xd(e,t.enabled,e._true),n=fe(e,t.page,e.zero);if(n){let o=new ze(e,"page-number");i=St(e,i,new Jo(e,n,o))}let s=fe(e,t["min-page-width"],e.zero);s&&(i=St(e,i,new Ur(e,new ze(e,"page-width"),s)));let r=fe(e,t["min-page-height"],e.zero);r&&(i=St(e,i,new Ur(e,new ze(e,"page-height"),r))),i=this.boxSpecificEnabled(i),t.enabled=new U(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=fe(e,t.left,i),s=fe(e,t["margin-left"],i),r=Bt(e,t["border-left-width"],t["border-left-style"],i),o=dt(e,t["padding-left"],i),a=fe(e,t.width,i),l=fe(e,t["max-width"],i),h=dt(e,t["padding-right"],i),u=Bt(e,t["border-right-width"],t["border-right-style"],i),d=fe(e,t["margin-right"],i),p=fe(e,t.right,i),f=Y(e,r,o),m=Y(e,r,h);if(n&&p&&a){let v=pe(e,i,Y(e,a,Y(e,Y(e,n,f),m)));s?d?p=pe(e,v,d):d=pe(e,v,Y(e,p,s)):(v=pe(e,v,p),d?s=pe(e,v,d):(s=cs(e,v,new $e(e,.5)),d=s))}else{s||(s=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let v=pe(e,i,Y(e,Y(e,s,f),Y(e,d,m)));this.isAutoWidth&&(l||(l=pe(e,v,n||p)),!this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(a=l,this.isAutoWidth=!1)),n?a?p||(p=pe(e,v,Y(e,n,a))):a=pe(e,v,Y(e,n,p)):n=pe(e,v,Y(e,p,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=dt(e,g,i);t.left=new U(n),t["margin-left"]=new U(s),t["border-left-width"]=new U(r),t["padding-left"]=new U(o),t.width=new U(a),t["max-width"]=new U(l||a),t["padding-right"]=new U(h),t["border-right-width"]=new U(u),t["margin-right"]=new U(d),t.right=new U(p),t["snap-width"]=new U(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,s=fe(e,t.top,n),r=fe(e,t["margin-top"],i),o=Bt(e,t["border-top-width"],t["border-top-style"],i),a=dt(e,t["padding-top"],i),l=fe(e,t.height,n),h=fe(e,t["max-height"],n),u=dt(e,t["padding-bottom"],i),d=Bt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=fe(e,t["margin-bottom"],i),f=fe(e,t.bottom,n),m=Y(e,o,a),g=Y(e,d,u);if(s&&f&&l){let b=pe(e,n,Y(e,l,Y(e,Y(e,s,m),g)));r?p?f=pe(e,b,r):p=pe(e,b,Y(e,f,r)):(b=pe(e,b,f),p?r=pe(e,b,p):(r=cs(e,b,new $e(e,.5)),p=r))}else{r||(r=e.zero),p||(p=e.zero),!s&&!f&&!l&&(s=e.zero),!s&&!l?(l=this.autoHeight,this.isAutoHeight=!0):!s&&!f?s=e.zero:!l&&!f&&(l=this.autoHeight,this.isAutoHeight=!0);let b=pe(e,n,Y(e,Y(e,r,m),Y(e,p,g)));this.isAutoHeight&&(h||(h=pe(e,b,s||f)),this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(l=h,this.isAutoHeight=!1)),s?l?f||(f=pe(e,b,Y(e,s,l))):l=pe(e,b,Y(e,f,s)):s=pe(e,b,Y(e,f,l))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),v=dt(e,w,i);t.top=new U(s),t["margin-top"]=new U(r),t["border-top-width"]=new U(o),t["padding-top"]=new U(a),t.height=new U(l),t["max-height"]=new U(h||l),t["padding-bottom"]=new U(u),t["border-bottom-width"]=new U(d),t["margin-bottom"]=new U(p),t.bottom=new U(f),t["snap-height"]=new U(v)}initColumns(){let e=this.pageBox.scope,t=this.style,i=fe(e,t[this.vertical?"height":"width"],null),n=fe(e,t["column-width"],i),s=fe(e,t["column-count"],null),r=iy(e,t["column-gap"],null);r||(r=new Un(e,1,"em")),n&&!s&&(s=new yn(e,"floor",[Hr(e,Y(e,i,r),Y(e,n,r))]),s=new yn(e,"max",[e.one,s])),s||(s=e.one),n=pe(e,Hr(e,Y(e,i,r),s),r),t["column-width"]=new U(n),t["column-count"]=new U(s),t["column-gap"]=new U(r)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,s=this.parentInstance?this.parentInstance.getActiveRegions(e):null,r=kc(this.cascaded,e,s,!1,null);this.vertical=Sc(r,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Cc(r,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=r["box-sizing"])==null?void 0:t.value)===y.border_box;let o=!!(e instanceof Ba&&e.currentLayoutPosition&&new ze(i,"left-page").evaluate(e));Nc(r,n,this.vertical,this.rtl,o,(a,l)=>l.value),this.autoWidth=new Me(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Me(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let s=this.style[t];return!s&&Cn(t)&&this.pageMasterInstance instanceof Wi&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?s=new I(e.rootFontSize,"px"):s=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),s&&(s=Vs(e,s,t)),s}getPropAsNumber(e,t){var i,n;let s=this.style[t];if(s){let r=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();s=Vs(e,s,t,r)}return Qe(s,e)}getSpecial(e,t){let i=lc(this.cascaded,t);if(i){let n=[];for(let s=0;s<i.length;s++){let r=i[s].evaluate(e,"");r&&r!==j&&n.push(r)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let s=this.getProp(e,i);s&&(s.isNumeric()&&Dh(s.unit)&&(s=nu(s,e)),i==="font-family"&&(s=n.filterFontFamily(s)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),T(t,i,s.toString()))}propagateDelayedProperty(e,t,i,n){let s=this.getProp(e,i);s&&n.push(new oa(t.element,i,s))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),s=this.getPropAsNumber(e,"padding-left"),r=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),T(t.element,"margin-left",`${n}px`),T(t.element,"padding-left",`${s}px`),T(t.element,"border-left-width",`${r}px`),t.marginLeft=n,t.borderLeft=r,t.paddingLeft=s}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),s=this.getPropAsNumber(e,"margin-right"),r=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(T(t.element,"margin-right",`${s}px`),T(t.element,"padding-right",`${r}px`),T(t.element,"border-right-width",`${o}px`),t.marginRight=s,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),l=a-Math.floor(a/n)*n;l>0&&(t.snapOffsetX=n-l,r+=t.snapOffsetX)}t.paddingRight=r,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),s=this.getPropAsNumber(e,"margin-top"),r=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=s,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),l=a-Math.floor(a/i)*i;l>0&&(t.snapOffsetY=i-l,r+=t.snapOffsetY)}t.paddingTop=r,T(t.element,"top",`${n}px`),T(t.element,"margin-top",`${s}px`),T(t.element,"padding-top",`${r}px`),T(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),s=this.getPropAsNumber(e,"border-bottom-width"),r=this.getPropAsNumber(e,"height")-t.snapOffsetY;T(t.element,"height",`${r}px`),T(t.element,"margin-bottom",`${i}px`),T(t.element,"padding-bottom",`${n}px`),T(t.element,"border-bottom-width",`${s}px`),t.height=r-t.snapOffsetY,t.marginBottom=i,t.borderBottom=s,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){T(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,T(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){T(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");T(t.element,"right",`${n}px`),T(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,s){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&T(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&T(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let r=0;r<Ql.length;r++)this.propagateProperty(e,t,Ql[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<th.length;s++)this.propagateProperty(e,t,th[s],n);if(this.style["text-overflow"]){let s=t.element.firstElementChild;T(s,"text-overflow","inherit"),T(s,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var r,o;let a=(o=(r=this.cascaded.width)!=null?r:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==y.auto&&!K(a)},s=()=>{var r,o;let a=(o=(r=this.cascaded.height)!=null?r:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==y.auto&&!K(a)};for(let r=0;r<ih.length;r++){let o=ih[r];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!s())continue;T(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,s,r,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,l=(!this.vertical||!n)&&this.isAutoWidth,h=null;if(l||a){l&&T(t.element,"width","auto"),a&&T(t.element,"height","auto");let u=n&&Ju(n);u&&Zu(n),h=r.getElementClientRect(n?n.element:t.element),u&&la(n),l&&(this.calculatedWidth=Math.ceil(h.right-h.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=h.bottom-h.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),s>1){let u=this.getPropAsNumber(e,"column-rule-width"),d=this.getProp(e,"column-rule-style"),p=this.getProp(e,"column-rule-color");if(u>0&&d&&d!=y.none&&p!=y.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<s;w++){let v=this.vertical?(m+f)*w/s-f/2+t.paddingTop-u/2:(m+f)*w/s-f/2+t.paddingLeft-u/2,b=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,C=t.element.ownerDocument.createElement("div");T(C,"position","absolute"),T(C,this.vertical?"left":"top","0px"),T(C,this.vertical?"top":"left",`${v}px`),T(C,this.vertical?"height":"width","0px"),T(C,this.vertical?"width":"height",`${b}px`),T(C,g,`${u}px ${d.toString()}${p?` ${p.toString()}`:""}`),t.element.insertBefore(C,t.element.firstChild)}}}for(let u=0;u<eh.length;u++)this.propagateProperty(e,t,eh[u],o);for(let u=0;u<nh.length;u++)this.propagateDelayedProperty(e,t,nh[u],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let r in n)this instanceof Wi&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(r==="writing-mode"||r==="direction")||Hi(r)&&bi(i,r,_e(n,r));if(this.pageBox.pseudoName==Ta)for(let r in t)(r.match(/^background-/)||r=="writing-mode")&&(i[r]=t[r]);if(this.pageBox.pseudoName=="layout-host")for(let r in t)!r.match(/^background-/)&&r!="writing-mode"&&(i[r]=t[r]);e.pushRule(this.pageBox.classes,null,i);let s=i.content;s&&(i.content=s.filterValue(new wo(e,null,e.counterResolver))),this.init(e.context);for(let r of this.pageBox.children)r.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},Ql=["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"],eh=["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"],th=["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"],ih=["width","height","image-resolution","object-fit","object-position"],nh=["transform","transform-origin"],Ta="background-host",ny=class extends ar{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},Ia=class extends ar{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=St(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},sy=class extends ar{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Zi=class extends ar{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof ae&&(n=[t]),t instanceof Ke&&(n=t.values),n){let s=this.pageBox.scope;for(let r=0;r<n.length;r++)if(n[r]instanceof ae){let o=zr(n[r].name,"enabled"),a=new ze(s,o);i&&(a=new ti(s,a)),e=St(s,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=xd(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=ty(t,i["flow-from"],"body"),r=new yn(t,"has-content",[s]);e=St(t,e,r)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let s=this.pageMasterInstance.style.enabled,r=s?s.toExpr(t,null):t._true;r=St(t,r,e),this.pageMasterInstance.style.enabled=new U(r)}return e}prepareContainer(e,t,i,n,s){var r;this.pageBox.pageMaster instanceof Nd||(T(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(r=this.pageBox.name)!=null?r:"")),super.prepareContainer(e,t,i,n,s)}},Aa=class extends Gn{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new _(t,i?ku:Eu)}},Sd=class extends Aa{constructor(e,t,i,n){super(e,t,i,n)}},ry=class Cd extends Aa{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new _(il,0),n.specified.height=new _(il,0)}startPartitionRule(t,i,n){let s=new Kn(this.scope,t,i,n,this.target),r=new Sd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new bd(this.scope,t,i,n,this.target),r=new Cd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},oy=class extends Aa{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Kn(this.scope,e,t,i,this.target),s=new Sd(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new bd(this.scope,e,t,i,this.target),s=new ry(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function kd(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,s=(i=e.direction)==null?void 0:i.value;return n===y.vertical_lr||n!==y.vertical_rl&&s!==y.rtl?"ltr":"rtl"}var ay={a10:{width:new I(26,"mm"),height:new I(37,"mm")},a9:{width:new I(37,"mm"),height:new I(52,"mm")},a8:{width:new I(52,"mm"),height:new I(74,"mm")},a7:{width:new I(74,"mm"),height:new I(105,"mm")},a6:{width:new I(105,"mm"),height:new I(148,"mm")},a5:{width:new I(148,"mm"),height:new I(210,"mm")},a4:{width:new I(210,"mm"),height:new I(297,"mm")},a3:{width:new I(297,"mm"),height:new I(420,"mm")},a2:{width:new I(420,"mm"),height:new I(594,"mm")},a1:{width:new I(594,"mm"),height:new I(841,"mm")},a0:{width:new I(841,"mm"),height:new I(1189,"mm")},b10:{width:new I(31,"mm"),height:new I(44,"mm")},b9:{width:new I(44,"mm"),height:new I(62,"mm")},b8:{width:new I(62,"mm"),height:new I(88,"mm")},b7:{width:new I(88,"mm"),height:new I(125,"mm")},b6:{width:new I(125,"mm"),height:new I(176,"mm")},b5:{width:new I(176,"mm"),height:new I(250,"mm")},b4:{width:new I(250,"mm"),height:new I(353,"mm")},b3:{width:new I(353,"mm"),height:new I(500,"mm")},b2:{width:new I(500,"mm"),height:new I(707,"mm")},b1:{width:new I(707,"mm"),height:new I(1e3,"mm")},b0:{width:new I(1e3,"mm"),height:new I(1414,"mm")},c10:{width:new I(28,"mm"),height:new I(40,"mm")},c9:{width:new I(40,"mm"),height:new I(57,"mm")},c8:{width:new I(57,"mm"),height:new I(81,"mm")},c7:{width:new I(81,"mm"),height:new I(114,"mm")},c6:{width:new I(114,"mm"),height:new I(162,"mm")},c5:{width:new I(162,"mm"),height:new I(229,"mm")},c4:{width:new I(229,"mm"),height:new I(324,"mm")},c3:{width:new I(324,"mm"),height:new I(458,"mm")},c2:{width:new I(458,"mm"),height:new I(648,"mm")},c1:{width:new I(648,"mm"),height:new I(917,"mm")},c0:{width:new I(917,"mm"),height:new I(1297,"mm")},"jis-b10":{width:new I(32,"mm"),height:new I(45,"mm")},"jis-b9":{width:new I(45,"mm"),height:new I(64,"mm")},"jis-b8":{width:new I(64,"mm"),height:new I(91,"mm")},"jis-b7":{width:new I(91,"mm"),height:new I(128,"mm")},"jis-b6":{width:new I(128,"mm"),height:new I(182,"mm")},"jis-b5":{width:new I(182,"mm"),height:new I(257,"mm")},"jis-b4":{width:new I(257,"mm"),height:new I(364,"mm")},"jis-b3":{width:new I(364,"mm"),height:new I(515,"mm")},"jis-b2":{width:new I(515,"mm"),height:new I(728,"mm")},"jis-b1":{width:new I(728,"mm"),height:new I(1030,"mm")},"jis-b0":{width:new I(1030,"mm"),height:new I(1456,"mm")},letter:{width:new I(8.5,"in"),height:new I(11,"in")},legal:{width:new I(8.5,"in"),height:new I(14,"in")},ledger:{width:new I(11,"in"),height:new I(17,"in")}},ly=new I(.24,"pt"),R0=new I(3,"mm"),hy=new I(10,"mm"),uy=new I(13,"mm");function Xs(e){let t={width:Hn,height:$n,bleed:ke,bleedOffset:ke,cropOffset:ke},i=e.size;if(!(!i||i.value===y.auto)){let h=i.value,u,d;if(h.isSpaceList()?(u=h.values[0],d=h.values[1]):(u=h,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&ay[u.name.toLowerCase()];p&&(d&&d===y.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,s=e.bleed,r=n&&!K(n.value)?n.value:y.none,o=s&&!K(s.value)?s.value:y.auto;if(o===y.auto){if(r!==y.none){let h=!1;r.isSpaceList()?h=r.values.some(u=>u===y.crop):h=r===y.crop,h&&(t.bleed=new I(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],l=a&&!K(a.value)?a.value:y.auto;return l===y.auto?r!==y.none&&(t.bleedOffset=uy):l.isNumeric()&&(t.cropOffset=l),t}function sh(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),s=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),r=n+s,o=e.width;o===Hn?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-r*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===$n?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-r*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=s,i.cropOffset=r,i}function Ed(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function Tn(e,t,i,n){n=n||"polyline";let s=e.createElementNS("http://www.w3.org/2000/svg",n);return s.setAttribute("stroke",i===y.auto?"#010101":i.toString()),s.setAttribute("stroke-width",t),s.setAttribute("fill","none"),s}var zo=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(zo||{});function cy(e,t,i,n,s,r,o){let a=s;a<=r+2*Pt.mm&&(a=r+s/2);let l=Math.max(s,a),h=r+l+i/2,u=Ed(e,h,h),d=[[0,r+s],[s,r+s],[s,r+s-a]],p=d.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(g=>[r+l-g[0],g[1]]),p=p.map(g=>[r+l-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(g=>[g[0],r+l-g[1]]),p=p.map(g=>[g[0],r+l-g[1]]));let f=Tn(e,i,n);f.setAttribute("points",d.map(g=>g.join(",")).join(" ")),u.appendChild(f);let m=Tn(e,i,n);return m.setAttribute("points",p.map(g=>g.join(",")).join(" ")),u.appendChild(m),t.split(" ").forEach(g=>{u.style[g]=`${o}px`}),u}var Mn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Mn||{});function dy(e,t,i,n,s,r){let o=s*2,a,l;t==="top"||t==="bottom"?(a=o,l=s):(a=s,l=o);let h=Ed(e,a,l),u=Tn(e,i,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),h.appendChild(u);let d=Tn(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),h.appendChild(d);let p=Tn(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",l/2),p.setAttribute("r",s/4),h.appendChild(p);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Mn).forEach(m=>{let g=Mn[m];g===t?h.style[g]=`${r}px`:g!==f&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function py(e,t,i,n){let s=!1,r=!1,o=e.marks;if(o){let g=o.value;g instanceof Q?g.values.forEach(w=>{w===y.crop?s=!0:w===y.cross&&(r=!0)}):g===y.crop?s=!0:g===y.cross&&(r=!0)}let a=t.bleed;if(!s&&!r)return;let l=i.container,h=l.ownerDocument,u=Qe(ly,n),d=Math.max(0,t.bleedOffset-Qe(hy,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:y.auto;s&&Object.keys(zo).forEach(g=>{let w=zo[g],v=cy(h,w,u,m,p,a,d);l.appendChild(v)}),r&&Object.keys(Mn).forEach(g=>{let w=Mn[g],v=dy(h,w,u,m,p,d);l.appendChild(v)})}var Do=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),Ra={"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"}},fy=(()=>{let e=Ra;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Fa="vivliostyle-page-rule-master",zn="_marginBoxes",Nd=class extends md{constructor(e,t,i){super(e,null,Fa,[],t,null,0),c(this,"pageMarginBoxes",{});let n=Xs(i),s=new gy(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[zn];t&&fy.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new wy(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new _(y.relative,0),this.specified.width=new _(t.width,0),this.specified.height=new _(t.height,0);for(let i in e)!Do[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Wi(e,this)}},gy=class extends Kn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new my(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new _(y.auto,0),this.specified["z-index"]=new _(new Re(0),0),this.specified.position=new _(y.absolute,0),this.specified.overflow=new _(y.visible,0);for(let t in Do)Do.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new yy(e,this)}},my=class extends Kn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new _(F("body"),0)}createInstance(e){return new Pd(e,this)}},wy=class extends Kn{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[zn][this.marginBoxName];for(let i in e){let n=e[i],s=t[i];(nc[i]||s&&s.value===y.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==j&&n.value!==y.inherit&&n.value!==y.unset&&n.value!==y.revert&&(this.specified[i]=n)}}createInstance(e){return new Td(e,this)}},Wi=class extends Ia{constructor(e,t){super(e,t),c(this,"pageAreaDimension",null),c(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=ke,e["margin-left"]=ke,e["border-left-width"]=ke,e["padding-left"]=ke,e["padding-right"]=ke,e["border-right-width"]=ke,e["margin-right"]=ke,e.right=ke}initVertical(){let e=this.style;e.top=ke,e["margin-top"]=ke,e["border-top-width"]=ke,e["padding-top"]=ke,e["padding-bottom"]=ke,e["border-bottom-width"]=ke,e["margin-bottom"]=ke,e.bottom=ke}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new U(e.borderBoxWidth),t.height=new U(e.borderBoxHeight),t["padding-left"]=new U(e.marginLeft),t["padding-right"]=new U(e.marginRight),t["padding-top"]=new U(e.marginTop),t["padding-bottom"]=new U(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,s={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},r={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,r,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,s){let r="start",o="center",a="end",l=this.pageBox.scope,h={},u={},d={};for(let C in e){let E=Ra[C];if(E){let A=e[C],V=this.pageMarginBoxInstances[C],D=new Ps(A,V.style,t,l,s);h[E.positionAlongVariableDimension]=A,u[E.positionAlongVariableDimension]=V,d[E.positionAlongVariableDimension]=D}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,g={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"max-width":"max-height"],i.extent);if(A){let V=A.evaluate(n);if(f[E]>V){let D=d[E]=new rh(h[E],u[E].style,t,l,s,V);g[E]=D.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,[r,o,a].forEach(C=>{var E;f[C]=(E=g[C])!=null?E:f[C]}));let w={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"min-width":"min-height"],i.extent);if(A){let V=A.evaluate(n);if(f[E]<V){let D=d[E]=new rh(h[E],u[E].style,t,l,s,V);w[E]=D.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[r,o,a].forEach(C=>{f[C]=w[C]||f[C]}));let v=p.start+p.extent,b=p.start+(p.start+p.extent);[r,o,a].forEach(C=>{let E=f[C];if(E!=null){let A=h[C],V=0;switch(C){case r:V=t?A.left:A.top;break;case o:V=(b-E)/2;break;case a:V=v-E;break}t?A.setHorizontalPosition(V,E-A.getInsetLeft()-A.getInsetRight()):A.setVerticalPosition(V,E-A.getInsetTop()-A.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,s=e.center,r=e.end,o={};if(s){let a=[n,r],l=new by(a),h=this.distributeAutoMarginBoxSizes(s,l,t);h.xSize!=null&&(o.center=h.xSize);let u=(i=h.xSize)!=null?i:s.getOuterSize(),d=Math.max((t-u)/2,0);n&&(o.start=n.hasAutoSize()?d:n.getOuterSize()),r&&(o.end=r.hasAutoSize()?d:r.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,r,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Ps&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Ps&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let s=e.getOuterMaxContentSize(),r=t.getOuterMaxContentSize();if(s>0&&r>0){let o=s+r;if(o<i)n.xSize=i*s/o;else{let a=e.getOuterMinContentSize(),l=t.getOuterMinContentSize(),h=a+l;h<i?n.xSize=a+(i-h)*(s-a)/(o-h):h>0&&(n.xSize=i*a/h)}n.xSize>0&&(n.ySize=i-n.xSize)}else s>0?n.xSize=i:r>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,s)}},Ps=class{constructor(e,t,i,n,s){this.container=e,this.isHorizontal=i,this.clientLayout=s,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let r=t[i?"width":"height"];if(this.hasAutoSize_=!r||r===y.auto||K(r),this.minMaxFitContent=r instanceof ae&&(r.name==="min-content"||r.name==="max-content"||r.name==="fit-content")?r.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=ra(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},by=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},rh=class extends Ps{constructor(e,t,i,n,s,r){super(e,t,i,n,s),c(this,"fixedSize"),this.fixedSize=r}hasAutoSize(){return!1}getOuterMaxContentSize(){return this.getOuterSize()}getOuterMinContentSize(){return this.getOuterSize()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.fixedSize+this.container.getInsetRight():this.container.getInsetTop()+this.fixedSize+this.container.getInsetBottom()}},yy=class extends Zi{constructor(e,t){super(e,t),c(this,"borderBoxWidth",null),c(this,"borderBoxHeight",null),c(this,"contentBoxWidth",null),c(this,"contentBoxHeight",null),c(this,"marginTop",null),c(this,"marginRight",null),c(this,"marginBottom",null),c(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=i[o].toExpr(n,null),l=fe(n,t[o],a),h=fe(n,t[`margin-${s}`],a),u=fe(n,t[`margin-${r}`],a),d=dt(n,t[`padding-${s}`],a),p=dt(n,t[`padding-${r}`],a),f=Bt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=Bt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Y(n,Y(n,f,d),Y(n,m,p)),w,v,b;return l?(this.borderBoxSizing?(v=l,b=pe(n,v,g)):(b=l,v=Y(n,b,g)),w=pe(n,a,v),!h&&!u?(h=cs(n,w,new $e(n,.5)),u=h):h?u=pe(n,w,h):h=pe(n,w,u)):(h||(h=n.zero),u||(u=n.zero),w=Y(n,h,u),v=pe(n,a,w),b=pe(n,v,g),l=this.borderBoxSizing?v:b),t[s]=new U(h),t[r]=new U(u),t[`margin-${s}`]=ke,t[`margin-${r}`]=ke,t[`border-${s}-width`]=new U(f),t[`border-${r}-width`]=new U(m),t[`padding-${s}`]=new U(d),t[`padding-${r}`]=new U(p),t[o]=new U(l),t[`max-${o}`]=new U(l),{borderBoxExtent:v,contentBoxExtent:b,marginStart:h,marginEnd:u}}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,s)}},Pd=class extends Zi{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new U(this.parentInstance.contentBoxWidth),e["margin-left"]=new U(new Ri(i,t.left.toExpr(i,null))),e["margin-right"]=new U(new Ri(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=y.solid,e["border-right-style"]=y.solid,e["border-left-color"]=y.transparent,e["border-right-color"]=y.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new U(this.parentInstance.contentBoxHeight),e["margin-top"]=new U(new Ri(i,t.top.toExpr(i,null))),e["margin-bottom"]=new U(new Ri(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=y.solid,e["border-bottom-style"]=y.solid,e["border-top-color"]=y.transparent,e["border-bottom-color"]=y.transparent}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,s),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},Td=class extends Zi{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Ra[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,s){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,s)}applyVerticalAlign(e,t){T(t,"display","flex"),T(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===F("middle")?n="center":i===F("top")?n="flex-start":i===F("bottom")&&(n="flex-end"),n&&T(t,"justify-content",n);let s=this.getProp(e,"content");if(this.vertical||s instanceof Je||s instanceof U&&s.expr instanceof Me&&s.expr.str.startsWith("running-element-")){let r="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?r=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(r=this.vertical||this.rtl?"end":"start")),T(t,"align-items",r)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,s=e.start,r=e.end,o=e.extent,a=s==="left",l=a?t.borderBoxWidth:t.borderBoxHeight,h=fe(n,i[o],l),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[s]=new U(u);else if(h){let d=dt(n,i[`margin-${s}`],l),p=dt(n,i[`margin-${r}`],l),f=dt(n,i[`padding-${s}`],l),m=dt(n,i[`padding-${r}`],l),g=Bt(n,i[`border-${s}-width`],i[`border-${s}-style`],l),w=Bt(n,i[`border-${r}-width`],i[`border-${r}-style`],l),v=Y(n,h,Y(n,this.borderBoxSizing?n.zero:Y(n,Y(n,f,m),Y(n,g,w)),Y(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[s]=new U(Y(n,u,Hr(n,pe(n,l,v),new $e(n,2))));break;case"end":i[s]=new U(pe(n,Y(n,u,l),v));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,s=this.borderBoxSizing,r=e.inside,o=e.outside,a=e.extent,l=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],h=Jl(n,i[`margin-${r}`],l),u=Jl(n,i[`margin-${o}`],l),d=dt(n,i[`padding-${r}`],l),p=dt(n,i[`padding-${o}`],l),f=Bt(n,i[`border-${r}-width`],i[`border-${r}-style`],l),m=Bt(n,i[`border-${o}-width`],i[`border-${o}-style`],l),g=fe(n,i[a],l),w=null;function v(b){if(w)return w;w={extent:g?g.evaluate(b):null,marginInside:h?h.evaluate(b):null,marginOutside:u?u.evaluate(b):null};let C=l.evaluate(b),E=0;return s||[f,d,p,m].forEach(A=>{A&&(E+=A.evaluate(b))}),(w.marginInside===null||w.marginOutside===null)&&E+w.extent+w.marginInside+w.marginOutside>C&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=C-E-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=C-E-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=C-E-w.extent-w.marginInside:w.marginInside=w.marginOutside=(C-E-w.extent)/2),w}i[a]=new U(new Me(n,function(){let b=v(this).extent;return b===null?"auto":b},a)),i[`margin-${r}`]=new U(new Me(n,function(){let b=v(this).marginInside;return b===null?"auto":b},`margin-${r}`)),i[`margin-${o}`]=new U(new Me(n,function(){let b=v(this).marginOutside;return b===null?"auto":b},`margin-${o}`)),r==="left"?i.left=new U(Y(n,t.marginLeft,t.borderBoxWidth)):r==="top"&&(i.top=new U(Y(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,s,r,o){super.finishContainer(e,t,i,n,s,r,o);let a=i.marginBoxes,l=this.pageBox.marginBoxName,h=this.boxInfo;!h.isInLeftColumn&&!h.isInRightColumn?h.isInTopRow?a.top[l]=t:h.isInBottomRow&&(a.bottom[l]=t):!h.isInTopRow&&!h.isInBottomRow&&(h.isInLeftColumn?a.left[l]=t:h.isInRightColumn&&(a.right[l]=t));let u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof ae&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(p||f||m){p&&T(t.element,"width",p),f&&T(t.element,"min-width",`${f}px`),m&&T(t.element,"max-width",`${m}px`);let C=this.getProp(e,"margin-left"),E=this.getProp(e,"margin-right");if(h.isInLeftColumn){let A=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);T(t.element,"right",`${A}px`),(C===y.auto||E!==y.auto)&&T(t.element,"margin-left","auto"),E===y.auto&&T(t.element,"margin-right","auto")}else h.isInRightColumn&&(T(t.element,"right","0"),(E===y.auto||C!==y.auto)&&T(t.element,"margin-right","auto"),C===y.auto&&T(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof ae&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,v=this.getPropAsNumber(e,"min-height"),b=this.getPropAsNumber(e,"max-height");if(w||v||b){w&&T(t.element,"height",w),v&&T(t.element,"min-height",`${v}px`),b&&T(t.element,"max-height",`${b}px`);let C=this.getProp(e,"margin-top"),E=this.getProp(e,"margin-bottom");if(h.isInTopRow){let A=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);T(t.element,"bottom",`${A}px`),(C===y.auto||E!==y.auto)&&T(t.element,"margin-top","auto"),E===y.auto&&T(t.element,"margin-bottom","auto")}else h.isInBottomRow&&(T(t.element,"bottom","0"),(E===y.auto||C!==y.auto)&&T(t.element,"margin-bottom","auto"),C===y.auto&&T(t.element,"margin-top","auto"))}}},vy=class{constructor(e,t,i,n,s){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=s,c(this,"pageMasterCache",{}),c(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new ze(e,"page-number"),s=new Jo(e,new jh(e,n,new $e(e,2)),i?e.one:e.zero);e.defineName("recto-page",new ti(e,s)),e.defineName("verso-page",s),(t.pageProgression||kd(this.docElementStyle))==="ltr"?(e.defineName("left-page",s),e.defineName("right-page",new ti(e,s))):(e.defineName("left-page",new ti(e,s)),e.defineName("right-page",s))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),s=this.pageMasterCache[n];return s||(i.pseudoName===Ta?s=this.generatePageRuleMaster(t):s=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=s),s.pageBox.resetScope(),s}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),s=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${s}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],s;n instanceof _?s=`${n.value}`:s=this.makeCascadeValueObjectKey(n),t.push(i+s+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new Nd(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Fa}),n=i.specified,s=e.size;if(s&&!K(s.value)){let o=Xs(e),a=s.priority;Gt(n,"width",new _(o.width,a),this.context),Gt(n,"height",new _(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let r=i.createInstance(this.rootPageBoxInstance);return r.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),r.resolveAutoSizing(this.context),r}},xy=class extends ve{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}},Sy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},Cy=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},ky=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ey=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ny=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Py=class extends ve{constructor(e){super(),this.scope=e}apply(e){new ze(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Ty=class extends xi{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},Iy=class extends xi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){if(e.currentPageType!==this.pageType)return;let t=e.pageTypePageCounts[this.pageType]||0;this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 3}},Ay=class extends wa{constructor(e,t){super(e,t,null,null,null)}apply(e){Ry(e.context,e.currentStyle,this.style,this.specificity,e)}};function Ry(e,t,i,n,s){Ds(e,t,i,n,null,null,null);let r=i[zn];if(r){let o=qn(t,zn);for(let a in r)if(r.hasOwnProperty(a)){let l=o[a];l||(l={},o[a]=l),Ds(e,l,r[a],n,null,null,null)}}}var Fy=class extends Ln{constructor(e,t,i,n,s){super(e,t,i?.condition,i,null,n,!1),this.pageProps=s,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new xy(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let s=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${s})`),this.chain.push(new Iy(this.scope,i,n,s)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Ty(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new Sy(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new Cy(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new ky(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Ey(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Ny(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Py(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(r=>r.selectors===null))return;super.simpleProperty(e,t,i);let n=_e(this.elementStyle,e),s=this.pageProps;if(e==="bleed"||e==="marks")s[""]||(s[""]={}),Object.keys(s).forEach(r=>{bi(s[r],e,n)});else if(e==="size"){let r=s[""];this.currentPageSelectors.forEach(o=>{let a=new _(n.value,n.priority+o.specificity),l=o.selectors?o.selectors.join(""):"",h=s[l];h?Gt(h,e,a):(h=s[l]={},bi(h,e,a),r&&["bleed","marks"].forEach(u=>{r[u]&&bi(h,u,r[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Ay(this.elementStyle,e)}startPageMarginBoxRule(e){let t=qn(this.elementStyle,zn),i=t[e];i||(i={},t[e]=i);let n=new Ly(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Ly=class extends Gn{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),s=new _(t,n);bi(this.boxStyle,e,s)}},jt=!0;function By(e){jt=e}var yi=[];function oh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Id(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function La(e,t,i){if(!jt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Id(e.ownerDocument).includes(e))return N(!1);let n=e.textContent,s=e.src,r=e.type==="module",o=s&&s.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return N(!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=(r||s)&&e.async&&!o,l=(r&&!a||s&&e.defer)&&!o,h=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||a);if(Ad(t)||(t.onload=null),h)return yi.some(d=>oh(d,e))||yi.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&oh(d,e)&&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 e.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if(H.debug("script:",s),s){let d=Ni(u);return t.document.head.appendChild(u),er([d])}else return t.document.head.appendChild(u),N(!0)}function Oy(e,t){var i;let n={},s=o=>{var a;let l=(a=o["font-family"])==null?void 0:a.value;if(l)if(l.values)for(let u of l.values)n[u.stringValue()]=!0;else n[l.stringValue()]=!0;let h=o._marginBoxes;if(h)for(let u of Object.values(h))s(u)},r=o=>{if(o instanceof wa)s(o.style);else if(o instanceof sn||Array.isArray(o))for(let a of Object.values(o))r(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))r(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function _y(e,t,i){var n;let s=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return s.style.position="fixed",s.style.fontSize="0",s.setAttribute("data-vivliostyle-textcontent","true"),s.setAttribute("aria-hidden","true"),s.style.fontFamily=Oy(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function My(e,t,i){if(!jt)return N(!1);let n=Id(e);if(n.length===0)return N(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),r=s?_y(e,t,i):null,o=t.document.fonts,a=t.$,l=!1,h=B("loadScripts");return h.loop(()=>{if(n.length===0)return s?h.sleep(20).thenAsync(()=>{var d,p;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let u=n.shift();return La(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(yi.push(u),l=!0),n.length===0&&s&&(H.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{r&&r.remove(),h.finish(!0)}),h.result()}function zy(e){if(!jt)return N(!1);let t=B("loadScripts");return t.loop(()=>yi.length===0?N(!1):La(yi.shift(),e,{atEnd:!0}).thenReturn(yi.length>0)).then(()=>{H.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),H.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function Ad(e){return jt?yi.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var Dy=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,s)=>`url("${i.transformURL(s,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,s)=>`url('${i.transformURL(s,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,s)=>`url(${i.transformURL(s,t)}`),Vy={};function Uy(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var Rd=class Vo extends qo{constructor(t,i,n,s,r,o,a,l,h,u,d,p,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=s,this.regionIds=r,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=l,this.stylerProducer=h,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,c(this,"document"),c(this,"exprContentListener"),c(this,"nodeContext",null),c(this,"viewRoot",null),c(this,"isFootnote",!1),c(this,"sourceNode",null),c(this,"offsetInNode",0),c(this,"viewNode",null),this.document=n.document,this.exprContentListener=s.counterListener.getExprContentListener()}clone(){return new Vo(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,s,r,o,a,l){var h;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return l;let d=[],p=ps.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let g of tw){let w;if(g){if(!u[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let v=s.display;if(!v||v===y.inline)continue;let b=t.firstElementChild;if(b&&He(b.previousSibling)){let C=r.getStyle(b,!1);if(C){let E=_e(C,"display");if(E!=null&&E.value&&E.value!==y.inline)continue}}}if(g==="before"||g==="after"||g==="marker"){let v=u[g].content;if(!v||!Ot(v.value)||g==="marker"&&(!mi(s.display)||((h=_e(n,"behavior"))==null?void 0:h.value)===F("toc-node")))continue}d.push(g),w=ps.createElementNS("http://www.w3.org/1999/xhtml","span"),vo(w,g)}else w=ps.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(w),g.match(/^first-/)&&(f=w)}if(!d.length)return l;let m=new _l(t,n,r,o,this.exprContentListener);return new Jr(t,p,null,a,l,yt.ROOTLESS,m)}getPseudoMap(t,i,n,s,r){let o=Tt(t,"_pseudos");if(!o)return null;let a={};for(let l in o){let h=a[l]={};En(h,o[l],r),yo(h,r,o[l]),Ec(o[l],i,n,(u,d)=>{En(h,d,r),xc(d,p=>{En(h,p,r)})})}return a}createRefShadow(t,i,n,s,r){let o=B("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let l=a;if(l){let h=l.getElement(t);if(h){let u=this.stylerProducer.getStylerForDoc(l);r=new Jr(n,h,l,s,r,i,u)}}o.finish(r)}),o.result()}createShadows(t,i,n,s,r,o,a){let l=B("createShadows"),h=null,u=s.template,d;if(u instanceof Je||u===y.footnote){let p=u instanceof Je?u.url:Pe("user-agent.xml#footnote",Qt);d=this.createRefShadow(p,yt.ROOTLESS,t,a,h)}else d=N(h);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Pe(g,w.url),f=this.createRefShadow(g,yt.ROOTED,t,a,p))}f==null&&(f=N(p));let m=null;f.then(g=>{if(s.display===y.table_cell){let w=Pe("user-agent.xml#table-cell",Qt);m=this.createRefShadow(w,yt.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,s,r,o,a,w),l.finish(w)})})}),l.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,s){var r;let o=this.context,a=kc(n,o,this.regionIds,this.isFootnote,this.nodeContext),l=!((r=this.nodeContext)!=null&&r.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 h=t;t=Sc(a,o,t);let u=!l&&t!==h;i=Cc(a,o,i);let d=(v,b)=>{let C;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(v)&&(C=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(v)&&(C=o.pageAreaWidth));let E=b.evaluate(o,v,C,t);return v=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},p=!!new ze(o.style.pageScope,"left-page").evaluate(o);if(Nc(a,s,t,i,p,d),u){let v=s[t?"height":"width"];(!v||v===y.auto)&&(s[t?"height":"width"]=y.max_content)}if(to(s.position))return s.position=y.fixed,s.visibility=y.hidden,t;let f=s.position,m=s.float,g=s.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?y.inline:void 0),w=qu(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(v=>{w[v]&&(s[v]=w[v])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],s=null,r=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let d=r&&r.root==i;if(!d||r.type==yt.ROOTLESS){let p=(r?r.styler:this.styler).getStyle(i,!1);n.push(p),s=s||_r(i)}d?(i=r.owner,r=r.parentShadow):(i=i.parentNode,o++)}let a=o===0,l=this.context.queryUnitSize("em",a),h={"font-size":new _(new I(l,"px"),0)};a&&(h["line-height"]=new _(new Ht(this.context.pref.lineHeight),0));let u=new hm(h,this.context);for(let d=n.length-1;d>=0;--d){let p=n[d],f=[];for(let w in p)Cn(w)&&f.push(w);f.sort(sl);let m,g;for(let w of f){u.setPropName(w);let v=_e(p,w),b=v;if(!K(v.value)){if(w==="font-size"&&d===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)b=new _(new I(this.context.rootFontSize,"px"),v.priority);else if(w==="line-height"&&d===n.length-1&&this.context.rootLineHeight&&v.value instanceof I&&(v.value.unit==="lh"||v.value.unit==="rlh"))b=new _(new I(this.context.rootLineHeight,"px"),v.priority);else if(d===0&&v.value instanceof I&&v.value.unit==="lh"){let C=this.getLineHeightUnitSize(w,m,g);C!=null&&(b=new _(new I(v.value.num*C,"px"),v.priority))}else $t(w)||(b=v.filterValue(u));w==="font-size"?m=b.value:w==="line-height"&&(g=b.value),h[w]=b}}}for(let d in t)Cn(d)||(h[d]=t[d]);return{lang:s,elementStyle:h}}resolveURL(t){return t=Pe(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=_r(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=em().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let s in this.nodeContext.parent.inheritedProps)n[s]=this.nodeContext.parent.inheritedProps[s]}i.forEach(s=>{let r=t[s];if(r){if(K(r))r===y.initial&&(n[s]=void 0);else if(r instanceof Re)n[s]=r.num;else if(r instanceof ae)n[s]=r.name;else if(r instanceof I){let o=r;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[s]=o.num*Pt[o.unit];break;default:n[s]=r}}else n[s]=r;["widows","orphans"].includes(s)||delete t[s]}})}}resolveFormattingContext(t,i,n,s,r,o){let a=It("RESOLVE_FORMATTING_CONTEXT");for(let l=0;l<a.length;l++){let h=a[l](t,i,n,s,r,o);if(h){t.formattingContext=h;return}}}createElementView(t,i){var n,s;let r=!0,o=B("createElementView"),a=this.sourceNode,l=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,h=l.getStyle(a,!1);if(!this.nodeContext.shadowContext){let b=this.xmldoc.getElementOffset(a);nr.registerFragmentIndex(b,this.nodeContext.fragmentIndex,0)}let u={};if(!this.nodeContext.parent){let b=this.inheritFromSourceParent(h);h=b.elementStyle,this.nodeContext.lang=b.lang}let d=h.position,p=h.float,f=h["float-reference"],m=p&&!K(p.value)&&p.value!==y.none&&f&&!K(f.value)?Fg(f.value.toString()):null;if(this.nodeContext.parent&&(to(d?.value)||m&&Vi(m))){let b=this.inheritFromSourceParent(h);h=b.elementStyle,this.nodeContext.lang=b.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",h,u),m&&Vi(m)&&u.display===y.block&&(u.display=y.flow_root),l.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let g=u["flow-into"];if(g&&g.toString()!=this.flowName)return o.finish(!1),o.result();if(jt&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return La(a,this.viewport.window).thenFinish(o),o.result();let w=u.display;if(K(w)&&(w===y.initial||w===y.unset?w=y.inline:w===y.inherit?w=((n=this.nodeContext.parent)==null?void 0:n.display)&&F((s=this.nodeContext.parent)==null?void 0:s.display):w=null),w===y.none)return o.finish(!1),o.result();let v=this.nodeContext.parent==null;return this.nodeContext.flexContainer=w===y.flex,this.createShadows(a,v,h,u,l,this.context,this.nodeContext.shadowContext).then(b=>{this.nodeContext.nodeShadow=b;let C=u.position,E=u.float,A=u.clear,V=this.nodeContext.vertical?y.vertical_rl:y.horizontal_tb,D=this.nodeContext.parent?this.nodeContext.parent.vertical?y.vertical_rl:y.horizontal_tb:V,te=Dg(a),ie=u["column-count"],je=u["column-width"],at=ie&&ie!==y.auto&&!K(ie)||je&&je!==y.auto&&!K(je);this.nodeContext.establishesBFC=Ug(w,C,E,u.overflow,V,D,at||te),this.nodeContext.containingBlockForAbsolute=Hg(C),this.nodeContext.isInsideBFC()&&E!==y.footnote&&!(m&&Vi(m))&&(E=null,A=null);let xe=E instanceof Q||E===y.left||E===y.right||E===y.top||E===y.bottom||E===y.inline_start||E===y.inline_end||E===y.block_start||E===y.block_end||E===y.snap_block||E===y.snap_inline||E===y.inside||E===y.outside||E===y.footnote;E&&(delete u.float,E===y.footnote&&(this.isFootnote?(xe=!1,u.display=y.block):u.display=y.inline)),A&&(A===y.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(A=F(this.nodeContext.parent.clearSide)),(A===y.left||A===y.right||A===y.top||A===y.bottom||A===y.inline_start||A===y.inline_end||A===y.block_start||A===y.block_end||A===y.inside||A===y.outside||A===y.both||A===y.all||A===y.same||A===y.column||A===y.region||A===y.page)&&(delete u.clear,u.display&&u.display!=y.inline&&(this.nodeContext.clearSide=A.toString())));let x=mi(w)&&!!u["ua-list-item-count"],O=u["break-inside"];(xe||O&&!K(O)&&O!==y.auto)&&this.nodeContext.breakPenalty++,w&&w!==y.inline&&Lt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!xe&&!w||Lt(w)||Ku(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=xe?E.toString():null,this.nodeContext.floatReference=m||Fe.INLINE;let S=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=S&&!K(S)?S:null;let P=this.isInsideNonRootMultiColumn(),k=u["column-span"];if(this.nodeContext.columnSpan=!P&&k&&!K(k)?k:null,!this.nodeContext.inline){let M=u["break-after"];M&&!K(M)&&!(P&&M===y.column)&&(this.nodeContext.breakAfter=M.toString(),Yr[this.nodeContext.breakAfter]&&(u["break-after"]=y.column));let ne=u["break-before"];ne&&!K(ne)&&!(P&&ne===y.column)&&(this.nodeContext.breakBefore=ne.toString(),Yr[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=y.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let se=u.page,ye=se&&!K(se)&&se.toString();!ye&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||w===y.table_header_group||w===y.table_footer_group)&&(ye=this.styler.cascade.currentPageType),!ye||ye.toLowerCase()==="auto"?ye=this.nodeContext.pageType:this.nodeContext.pageType=ye,this.styler.cascade.currentPageType!==ye&&!(!ye&&u.position===y.fixed)&&(this.nodeContext.fragmentIndex===1&&!Fn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),ye!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=ye)}this.nodeContext.verticalAlign=u["vertical-align"]&&u["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let R=u["border-collapse"];if(!R||R===F("separate")){let M=u["border-spacing"],ne,se;M&&(M instanceof Q?(ne=M.values[0],se=M.values[1]):ne=se=M,ne.isNumeric()&&(this.nodeContext.inlineBorderSpacing=Qe(ne,this.context)),se.isNumeric()&&(this.nodeContext.blockBorderSpacing=Qe(se,this.context)))}let L=u["footnote-policy"];this.nodeContext.footnotePolicy=L&&!K(L)?L:null;let z=u["x-first-pseudo"];if(z){let M=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new Tg(M,z.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,h,l,this.context);let $=u["white-space"];if($){let M=Mu($.toString());M!==null&&(this.nodeContext.whitespace=M)}let q=u["hyphenate-character"];q&&q instanceof G&&(this.nodeContext.hyphenateCharacter=q.str);let Z=u["word-break"],J=u["line-break"],we=u["overflow-wrap"];(Z===y.break_all||J===y.anywhere||we===y.break_word||we===y.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,w,C,E,v),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,l));let ee=!1,be=null,Se=[],le=a.namespaceURI,W=a.localName,ce=W;if(le=="http://www.w3.org/1999/xhtml"?(W=="html"||W=="body"||W=="script"||W=="link"||W=="meta"?W="div":W=="vide_"?W="video":W=="audi_"?W="audio":W=="object"&&(ee=!!this.customRenderer),a.hasAttribute(xa)&&a.hasAttribute("src")&&u.content instanceof Je&&(W="img")):le=="http://www.idpf.org/2007/ops"?(W="span",le="http://www.w3.org/1999/xhtml"):le=="http://www.pyroxy.com/ns/shadow"?(le="http://www.w3.org/1999/xhtml",W=this.nodeContext.inline?"span":"div"):ee=!!this.customRenderer,x)w=Lt(w)?y.inline:y.block,u.display=w,t?W="li":W="div";else if(W=="body"||W=="li")W="div";else if(W=="q")W="span";else if(W=="a"){let M=u["hyperlink-processing"];M&&M.toString()!="normal"&&(W="span")}u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(ee=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(ee=!0);let de;if(ee){let M=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;de=this.customRenderer(a,M,u)}else de=N(null);de.then(M=>{var ne,se,ye,lt,_a;if(M)ee&&(r=M.getAttribute("data-adapt-process-children")=="true");else if(u.display===y.none){o.finish(!1);return}else M=this.createElement(le,W);W!=ce&&(M.setAttribute("data-vivliostyle-original-tag",ce),(ce==="html"||ce==="body")&&(M.role="presentation")),W=="a"&&M.addEventListener("click",this.page.hrefHandler,!1),be&&(this.applyPseudoelementStyle(this.nodeContext,"inner",be),M.appendChild(be)),M.localName=="iframe"&&M.namespaceURI=="http://www.w3.org/1999/xhtml"&&Uy(M);let Zn=this.nodeContext.inheritedProps["image-resolution"],lr=[],hr=u.width,ur=u.height,Wd=a.getAttribute("width"),Gd=a.getAttribute("height"),cr=hr===y.auto||!hr&&!Wd,dr=ur===y.auto||!ur&&!Gd,Ma=a.attributes,jd=Ma.length,Jn=null,za=null;w===y.table_cell&&((ye=(se=(ne=this.nodeContext.parent)==null?void 0:ne.viewNode)==null?void 0:se.lastElementChild)==null?void 0:ye.localName)==="a"&&M.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Xe=0;Xe<jd;Xe++){let pt=Ma[Xe],ht=pt.namespaceURI,oe=pt.localName,De=pt.nodeValue;if(ht){if(ht=="http://www.w3.org/2000/xmlns/")continue;ht=="http://www.w3.org/1999/xlink"&&oe=="href"&&(De=this.documentURLTransformer.transformURL(this.resolveURL(De),this.xmldoc.url))}else{if(!jt&&oe.match(/^on/)||oe=="style")continue;if((oe=="id"||oe=="name")&&t){let qe=this.documentURLTransformer.transformFragment(De,this.xmldoc.url);M.setAttribute(oe,De),M.setAttribute("data-vivliostyle-id",qe);let ai=M.ownerDocument.createElement("a");ai.setAttribute(oe,qe),ai.setAttribute(qi,"1"),ai.style.position="absolute",M.appendChild(ai),this.page.registerElementWithId(M,qe);continue}if(oe=="src"||oe=="href"||oe=="poster")De=this.resolveURL(De),oe==="href"&&(De=this.documentURLTransformer.transformURL(De,this.xmldoc.url));else if(oe=="srcset")De=De.split(",").map(qe=>this.resolveURL(qe.trim())).join(",");else if(oe==="data"&&ee&&W==="object"&&M.hasAttribute("data"))continue;if(oe==="poster"&&W==="video"&&le==="http://www.w3.org/1999/xhtml"&&cr&&dr){let qe=new Image,ai=Ni(qe,De);Se.push(ai),lr.push({image:qe,element:M,fetcher:ai})}}if(le=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(oe)&&(oe=oe.toLowerCase()),this.isSVGUrlAttribute(oe)&&(De=Dy(De,this.xmldoc.url,this.documentURLTransformer)),ht){let qe=Vy[ht];qe&&(oe=`${qe}:${oe}`)}if(oe=="src"&&!ht&&(W=="img"||W=="input")&&le=="http://www.w3.org/1999/xhtml")Jn=De;else if(oe=="alt"&&!ht&&W=="img"&&le=="http://www.w3.org/1999/xhtml")za=De;else if(oe=="href"&&W=="image"&&le=="http://www.w3.org/2000/svg"&&ht=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Ni(M,De));else if(ht)M.setAttributeNS(ht,oe,De);else try{M.setAttribute(oe,De)}catch(qe){H.warn(qe)}}if(Jn){let Xe=W==="input"?new Image:M,pt=Ni(Xe,Jn,za);Xe!==M&&(M.src=Jn);let ht=()=>{var oe,De;if(u.position===y.fixed)return!0;for(let qe=(oe=this.nodeContext.parent)==null?void 0:oe.viewNode;qe&&qe!==this.viewRoot;qe=qe.parentElement)if(((De=qe.style)==null?void 0:De.position)==="fixed")return!0;return!1};!cr&&!dr&&!(()=>{let oe=this.nodeContext.vertical?hr:ur;return oe instanceof I&&oe.unit==="%"})()&&!ht()?this.page.fetchers.push(pt):(cr&&dr&&Zn&&Zn!==1&&lr.push({image:Xe,element:M,fetcher:pt}),Se.push(pt))}delete u.content;let pr=u["list-style-image"];if(pr&&pr instanceof Je){let Xe=pr.url;Se.push(Ni(new Image,Xe))}if(this.preprocessElementStyle(u),this.applyComputedStyles(M,u),this.nodeContext.inline)t||(ft(M,"inline-start"),un(M)&&ft(M,"clone"));else if(t){if(!aa(u.position)){let Xe=u["margin-break"],pt=this.getBreakTypeAt(this.nodeContext),ht=pt!==null,oe=pt==="auto";(Xe===y.discard&&ht||Xe!==y.keep&&oe&&!this.nodeContext.floatSide)&&kr(M,"block-start")}}else{let Xe=this.nodeContext.vertical?"width":"height";Kt(M,Xe)&&T(M,Xe,this.nodeContext.display==="table-row"?"0.01px":""),ft(M,"block-start"),un(M)&&ft(M,"clone"),kr(M,"block-start")}if(x&&M.setAttribute("value",u["ua-list-item-count"].stringValue()),M.classList.contains("_viv-marker-outside-content")&&mi((_a=(lt=this.nodeContext.parent)==null?void 0:lt.parent)==null?void 0:_a.display)){let Xe=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),pt=parseFloat(Xe.borderInlineStartWidth)+parseFloat(Xe.paddingInlineStart)+parseFloat(Xe.textIndent);pt&&(M.style.insetInlineEnd=`${pt}px`)}this.viewNode=M,Se.length?er(Se).then(()=>{Zn>0&&this.modifyElemDimensionWithImageResolution(lr,Zn,u,this.nodeContext.vertical),o.finish(r)}):o.timeSlice().then(()=>{o.finish(r)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let s=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;s&&(He(s,n.parent.whitespace)||Bi(s));)s=s.previousSibling;if(s)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&ha(i))}getBreakTypeAt(t){var i,n,s,r,o;if(this.isInsideTable(t))return null;for(let l=t;l&&!l.after;l=l.parent){if(tt(l.breakBefore))return l.breakBefore;if(l.fragmentIndex===1&&!l.parent)return l.sourceNode===l.sourceNode.ownerDocument.documentElement?"page":null;if((i=l.parent)!=null&&i.floatSide)return null;let h=(n=l.parent)==null?void 0:n.viewNode;if(h){let u=this.viewport.window.getComputedStyle(h),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=h?.firstChild;for(;f&&(He(f,l.parent.whitespace)||!l.floatSide&&Bi(f));)f=f.nextSibling;if(f&&f!==l.viewNode)return null}}let a=(o=(r=(s=this.context)==null?void 0:s.currentLayoutPosition)==null?void 0:r.flowPositions[this.flowName])==null?void 0:o.startBreakType;return tt(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,s){let r=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,s);if(r&&r["after-if-continues"]&&r["after-if-continues"].content){let o=new _l(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new nw(t,o)}}isSVGUrlAttribute(t){return Vo.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,s){t.forEach(r=>{if(r.fetcher.get().get()==="load"){let o=r.image,a=o.width/i,l=o.height/i,h=r.element;if(a>0&&l>0){if(n["box-sizing"]===y.border_box&&(n["border-left-style"]!==y.none&&(a+=Qe(n["border-left-width"],this.context)),n["border-right-style"]!==y.none&&(a+=Qe(n["border-right-width"],this.context)),n["border-top-style"]!==y.none&&(l+=Qe(n["border-top-width"],this.context)),n["border-bottom-style"]!==y.none&&(l+=Qe(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||y.none,d=n["max-height"]||y.none;if(u===y.none&&d===y.none)T(h,"max-width",`${a}px`);else if(u!==y.none&&d===y.none)T(h,"width",`${a}px`);else if(u===y.none&&d!==y.none)T(h,"height",`${l}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?T(h,"max-width",`${Math.min(a,Qe(p,this.context))}px`):f.unit!=="%"?T(h,"max-height",`${Math.min(l,Qe(f,this.context))}px`):s?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||ke,d=n["min-height"]||ke;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?T(h,"min-width",`${a}px`):p.num!==0&&f.num===0?T(h,"width",`${a}px`):p.num===0&&f.num!==0?T(h,"height",`${l}px`):p.unit!=="%"?T(h,"min-width",`${Math.max(a,Qe(p,this.context))}px`):f.unit!=="%"?T(h,"min-height",`${Math.max(l,Qe(f,this.context))}px`):s?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}}})}preprocessElementStyle(t){It("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let s={},r=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",r,s),!this.processRepeatOnBreak(s))continue;if(this.nodeContext.formattingContext instanceof vi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new vi(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==y.none&&((i===y.auto||K(i))&&(t.display===y.table_header_group?i=y.header:t.display===y.table_footer_group?i=y.footer:i=y.none),i&&i!==y.none)?i.toString():null}createTextNodeView(){let t=B("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=wl(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=B("preprocessTextContent"),s=It("PREPROCESS_TEXT_CONTENT"),r=0;return n.loop(()=>r>=s.length?N(!1):s[r++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=mg(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=B("createNodeView"),s,r=!0;return this.sourceNode.nodeType==1?s=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,s=N(!0)):s=this.createTextNodeView(),s.then(o=>{var a;if(r=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let l=(d,p)=>d?.nodeType===1&&Mi(d)===p,h=this.nodeContext.parent,u=h?l(this.viewNode,"after")&&l(h.viewNode,"first-letter")&&(a=h.viewNode)!=null&&a.hasChildNodes()?h.parent.viewNode:h.viewNode:this.viewRoot;u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&He(this.viewNode))&&!u.hasChildNodes()&&Lu(u).includes("block-start")&&ft(u,"text-start"),u.appendChild(this.viewNode),jg(this.viewNode))}n.finish(r)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,s=t.parent,r,o,a=n.subShadow||n.parentShadow;n.subShadow?(r=n.root,o=n.type,o==yt.ROOTLESS&&(r=r.firstChild)):(r=n.owner.firstChild,o=yt.ROOTLESS);let l=t.sourceNode.nextSibling;if(l?(t.sourceNode=l,t.resetView()):t.shadowSibling?t=t.shadowSibling:r?t=null:(t=t.parent.modify(),t.after=!0),r){let h=new dn(r,s,i);return h.shadowContext=a,h.shadowType=o,h.shadowSibling=t,h}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=yt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let s=t.nodeShadow.root;if(t.nodeShadow.type==yt.ROOTLESS&&(s=s.firstChild),s){let r=new dn(s,t,i);return r.shadowContext=t.nodeShadow,r.shadowType=t.nodeShadow.type,this.processShadowContent(r)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new dn(n,t,i));if(t.sourceNode.nodeType!=1){let s=wl(t.preprocessedTextContent);i+=s.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let s=_e(i,"hyperlink-processing");if(!s)return!1;let r=s.evaluate(this.context,"hyperlink-processing");return r?r.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let s=B("nextInTree");return this.setCurrent(n,!0,i).then(r=>{(!n.viewNode||!r)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),s.finish(n)}),s.result()}addImageFetchers(t){if(t instanceof Ke){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof Je){let i=t.url;this.page.fetchers.push(Ni(new Image,i))}}applyComputedStyles(t,i){var n,s,r;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===y.relative,l=((n=this.nodeContext)==null?void 0:n.parent)===null&&((s=this.sourceNode)==null?void 0:s.parentElement)===null&&!!((r=this.viewRoot)!=null&&r.parentElement),h=Object.keys(i);h.sort(sl);let u,d;for(let p of h){if($y[p])continue;let f=i[p];if(!(!f||f===j&&!$t(p))){if(f=f.visit(new df(this.xmldoc.url,this.documentURLTransformer)),f instanceof I)if(f.unit==="em"){let m=this.getEmUnitSize(p,u);m!=null&&(f=new I(f.num*m,"px"))}else if(f.unit==="lh"){let m=this.getLineHeightUnitSize(p,u,d);m!=null&&(f=new I(f.num*m,"px"))}else Dh(f.unit)&&(f=nu(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof I&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new Ei(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),yg[p]||a&&vg[p]){this.page.delayedItems.push(new oa(t,p,f));continue}l&&this.page.pageAreaElement&&Cn(p)?T(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()):T(t,p,f.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(t,i,n){var s,r,o,a,l,h;let u=((o=(r=(s=this.nodeContext)==null?void 0:s.parent)==null?void 0:r.viewNode)==null?void 0:o.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,d=u?this.parsePlusLayoutUnitAdj(u.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return d;let p=null;if(n)if(n instanceof Ht||n instanceof I&&(n.unit==="em"||n.unit==="%"))p=n instanceof I&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof I&&n.unit!=="lh"){let f=this.context.queryUnitSize(n.unit,!1);if(f!=null)return n.num*f}return null}if(p==null)for(let f=(l=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:l.viewNode;f&&f.nodeType===1;f=f.parentNode){let m=(h=f?.style)==null?void 0:h.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(p=parseFloat(m));break}}if(p!=null){if(i&&!(i instanceof I))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof I){let m=po(i,f,this.context).num;return typeof m!="number"||isNaN(m)?null:p*m}else return f==null?null:p*f}return d}getEmUnitSize(t,i){var n,s,r;let o=((r=(s=(n=this.nodeContext)==null?void 0:n.parent)==null?void 0:s.viewNode)==null?void 0:r.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,a=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(t==="font-size"||i==null)return a;if(i instanceof I){let l=po(i,a,this.context).num;if(typeof l=="number"&&!isNaN(l))return l}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let s=this.sourceNode,r=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(s,!1),o=Tt(r,"_pseudos");if(!o||(r=o[i],!r))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",r,a);let l=a.content;Ot(l)&&(l.visit(new Ms(n,this.context,l,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=B("peelOff"),s=t.firstPseudo,r=t.offsetInNode,o=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),r+=i}else if(!o&&t.viewNode&&r==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,l=[];for(;t.firstPseudo===s;)l.push(t),t=t.parent;let h=l.pop(),u=h.shadowSibling;return n.loop(()=>{for(;l.length>0;){h=l.pop(),t=new dn(h.sourceNode,t,a),l.length==0&&(t.offsetInNode=r,t.after=o),t.shadowType=h.shadowType,t.shadowContext=h.shadowContext,t.nodeShadow=h.nodeShadow,t.shadowSibling=h.shadowSibling?h.shadowSibling:u,u=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let s={},r=Tt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,s),r&&r.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");vo(a,"before"),n.appendChild(a),this.computeStyle(t,i,r.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete s.content,this.applyComputedStyles(n,s),t}processFragmentedBlockEdge(t){var i,n,s;let r=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let l=t.sourceNode.nextSibling,h=(n=_e(this.styler.getStyle(l,!1),"display"))==null?void 0:n.value.toString();o=h&&!Lt(h)||l.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(l.textContent)}let a=0;for(let l=r;l;l=l.parent){if(((s=l.viewNode)==null?void 0:s.nodeType)!==1)continue;let h=l.viewNode;if(h.style)if(l.inline){if(ft(h,"inline-end"),un(h)){let u=l.vertical?h.offsetWidth:h.offsetHeight;ft(h,"clone"),(l.vertical?h.offsetWidth:h.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(h)}}else{let u=this.nodeContext.vertical?"width":"height";if(Kt(h,u)&&T(h,u,""),ft(h,"block-end"),!a++&&l!==r){let{textAlign:d}=this.viewport.window.getComputedStyle(h);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(h);p?p!==h?Bu(p,["block-start","text-start","block-end","text-end","justify"]):(ft(h,"text-end"),ft(h,"justify")):ft(h,"text-end")}else ft(h,"text-end")}un(h)&&ft(h,"clone"),kr(h,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),s=parseFloat(i.borderInlineEndWidth),r=-(n+s);isNaN(r)||(t.style.marginInlineEnd=`${r}px`)}createChildAnonymousBlockIfNeeded(t){let i=r=>{let{display:o,position:a,float:l}=this.viewport.window.getComputedStyle(r);if(r.localName==="ruby"||gi[r.localName])return!1;if(r.localName==="br")return!0;if((o==="inline"||o==="contents")&&r.hasChildNodes()){let h=r.lastElementChild;if(h&&(!h.nextSibling||h.nextSibling===r.lastChild&&He(h.nextSibling))){let u=i(h);if(u||u===null)return u}for(let u=h?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||l&&l!=="none"||r.hasAttribute(qi)){let h=r.previousElementSibling;return h&&(h.nextSibling===r||h.nextSibling===r.previousSibling&&He(h.nextSibling))?i(h):!1}return!(!o||Lt(o))},n=null;for(let r=t.lastElementChild;r;r=r.previousElementSibling){let o=i(r);if(o){n=r;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&He(n.nextSibling)))return null;let s=t.ownerDocument.createElement("span");s.className="viv-anonymous-block";for(let r=n.nextSibling,o=null;r;r=o)o=r.nextSibling,s.appendChild(r);return t.appendChild(s),s}convertLengthToPx(t,i,n){let s=t.num,r=t.unit;if(Bp(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,ma(t,a,this.context).num}else{let o=this.context.queryUnitSize(r,!1);return o?s*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,s=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Mi(n)===Mi(s)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,s)=>{let r=i.steps[s];return this.isSameNodePositionStep(n,r)})}isPseudoelement(t){return!!Mi(t)}};c(Rd,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var Hy=Rd,$y={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},Wy=class{constructor(e){c(this,"layoutBox"),c(this,"window"),c(this,"pixelRatio"),c(this,"scaleRatio"),c(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.subtractOffsets(n,i))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},qs=class{constructor(e,t,i,n,s,r){this.window=e,this.fontSize=t,this.pixelRatio=i,c(this,"document"),c(this,"root"),c(this,"outerZoomBox"),c(this,"contentContainer"),c(this,"layoutBox"),c(this,"width"),c(this,"height"),c(this,"scaleRatio",1),c(this,"layoutUnitPerPixel"),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body;let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(T(this.root,"--viv-outputPixelRatio",`${i}`),T(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Ph){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&T(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let l=o.nextElementSibling;l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-layout-box","true"),l.role="presentation",this.root.appendChild(l)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=l,this.width=s||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=r||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let h={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!s&&u)&&(this.width=h.width),(!this.height||!r&&u)&&(this.height=h.height)}resetZoom(){T(this.outerZoomBox,"width",""),T(this.outerZoomBox,"height",""),T(this.contentContainer,"width",""),T(this.contentContainer,"height",""),T(this.contentContainer,"transform","")}zoom(e,t,i){T(this.root,"--viv-outputScale",`${i}`),T(this.outerZoomBox,"width",`${e*i}px`),T(this.outerZoomBox,"height",`${t*i}px`),T(this.contentContainer,"width",`${e}px`),T(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},Fd=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,c(this,"lang",null),c(this,"totalOffset",-1),c(this,"root"),c(this,"body"),c(this,"head"),c(this,"last"),c(this,"lastOffset",1),c(this,"idMap"),this.root=i.documentElement;let n=null,s=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let r=this.root.firstChild;r;r=r.nextSibling){if(r.nodeType!=1)continue;let o=r;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":s=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=s,this.last=this.root,this.last.setAttribute(Mt,"0")}doc(){return new Bd([this.document])}getElementOffset(e){let t=e.getAttribute(Mt);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let s=n.firstChild;if(!s){for(;s=n.nextSibling,!s;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=s,s.nodeType==1?(s.setAttribute(Mt,i.toString()),++i):i+=s.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,s=e,r=null;if(s.nodeType==1){if(!i)return this.getElementOffset(s)}else{if(n=t,r=s.previousSibling,!r)return s=s.parentNode,n+=1,this.getElementOffset(s)+n;s=r}for(;;){for(;s.lastChild;)s=s.lastChild;if(s.nodeType==1)break;if(n+=s.textContent.length,r=s.previousSibling,!r){s=s.parentNode;break}s=r}return n+=1,this.getElementOffset(s)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let l=ni(a.length,h=>{let u=a[h];return this.getElementOffset(u)>e});if(l==0)break;i=a[l-1]}let n=t+1,s=i,r=s.firstChild||s.nextSibling,o=null;for(;;){if(r){if(r.nodeType==1||(s=r,o=s,n+=r.textContent.length,n>e&&!/^\s*$/.test(r.textContent)))break}else if(s=s.parentNode,!s)break;r=s.nextSibling}return r&&o&&/^\s*$/.test(o.textContent)&&(o=r),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},Uo=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(Uo||{});function ls(e,t,i){let n=i||new DOMParser,s;try{s=n.parseFromString(e,t)}catch{}if(s){let r=s.documentElement,o="parsererror";if(r.localName===o)return null;for(let a=r.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return s}function Gy(e){let t=e.contentType;if(t){let n=Object.keys(Uo);for(let s=0;s<n.length;s++)if(Uo[n[s]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function Ld(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=Gy(e);if(i=ls(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=ls(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=ls(r,"image/svg+xml",s))}i||(i=ls(r,"text/html",s))}}let n=i?new Fd(t,e.url,i):null;return N(n)}function jy(){return new ia(Ld,"document")}var Xy=class Ho{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Ho(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Ho(n=>{if(!this.check(n))return!1;let s=new Bd([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},ah=new Xy(e=>!0),Bd=class $o{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new $o(i)}forEachNode(t){let i=[],n=s=>{i.push(s)};for(let s=0;s<this.nodes.length;s++)t(this.nodes[s],n);return new $o(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let s=t(this.nodes[n]);s!=null&&i.push(s)}return i}child(t){return this.forEachNode((i,n)=>{for(let s=i.firstChild;s;s=s.nextSibling)s.nodeType==1&&s.localName==t&&n(s)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},qy=new Wn(()=>{let e=B("uaStylesheetBase"),t=fd(),i=Pe("user-agent-base.css",Qt),n=new Ln(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Vm(n.cascade),sa(bu,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Yy(){return qy.get()}var Ky=class extends fn{constructor(e,t,i,n,s,r){super(e,t,null,i,n,"counter-style"),this.counterStyleName=s,this.counterStyles=r}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||H.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Zy=class{constructor(e,t,i,n,s,r,o,a,l,h,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=s,this.fontFaces=r,this.footnoteProps=o,this.flowProps=a,this.viewportProps=l,this.pageProps=h,this.counterStyleStore=u,c(this,"fontDeobfuscator"),c(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,m=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!m&&!p.flowChunkIsAfterParentFlowForcedBreak(m)}),this.pageScope.defineName("page-number",new Me(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Me(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let s=new Vr(this.rootScope,e,t,i),r=lm(s,this.viewportProps),o=r.width,a=r.height,l=r["text-zoom"],h=1;if(o&&a||l){let u=Pt.em;if((l?l.evaluate(s,"text-zoom"):null)===y.scale&&(h=u/i,i=u,e*=h,t*=h),o&&a){let d=Qe(o.evaluate(s,"width"),s),p=Qe(a.evaluate(s,"height"),s);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},Ba=class extends Vr{constructor(e,t,i,n,s,r,o,a,l,h,u,d,p){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=s,this.fontMapper=r,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=l,this.documentURLTransformer=h,this.counterStore=u,c(this,"lang"),c(this,"primaryFlows",{body:!0}),c(this,"rootPageBoxInstance",null),c(this,"styler",null),c(this,"stylerMap",null),c(this,"currentLayoutPosition",null),c(this,"layoutPositionAtPageStart",null),c(this,"lookupOffset",0),c(this,"faces"),c(this,"pageBoxInstances",{}),c(this,"pageManager",null),c(this,"rootPageFloatLayoutContext"),c(this,"pageBreaks",{}),c(this,"pageProgression",null),c(this,"isVersoFirstPage",!1),c(this,"blankPageAtStart",!1),c(this,"pageSheetSize",{}),c(this,"pageSheetHeight",0),c(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Zb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new pn(null,null,null,null,null,null,null),this.pageProgression=d||null,this.isVersoFirstPage=!!p;for(let f in e.flowProps){let m=e.flowProps[f],g=_e(m,"flow-consume");g&&(g.evaluate(this,"flow-consume")==y.all?this.primaryFlows[f]=!0:delete this.primaryFlows[f])}}init(){let e=B("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new Xl(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=kd(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new ny(s);let r=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(r,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new vy(r,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let l of this.style.fontFaces){if(l.condition&&!l.condition.evaluate(this))continue;let h=Kb(l.properties,this),u=new gd(h);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{My(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(l=>{let h=a[l];this.styler.cascade.applyVarFilter([h],this.styler,null),this.styler.cascade.applyCalcFilter(h,this.styler.context);let u=sh(Xs(h),this);this.pageSheetSize[l]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new Vr(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),s=this.counterStore.createCounterListener(e.url),r=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new Xl(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,s,r,i.counterStyleStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new Ag,i.flowPositions[e.flowName]=n);let s=Pg(e.element),r=new oi(s),o=new Ig(r,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class s{unknownProperty(l,h){n=!1}invalidPropertyValue(l,h){n=!1}simpleProperty(l,h,u){}}let r=new s,o=tn(this.style.rootScope,new At(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,r),n):!1}evalSupportsSelector(e){let t=new Od(null),i=new At(e+"{}",t);return new jn(Ae,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,s=n.steps[0].node,r=n.offsetInNode,o=n.after,a=0;for(;s.ownerDocument!=this.xmldoc.document;)a++,s=n.steps[a].node,o=!1,r=0;let l=this.xmldoc.getNodeOffset(s,r,o);l<t&&(t=l)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let s=e.flowPositions[n];if(!t&&(!s||s.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),s=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&s&&(s=s.clone(),e.flowPositions[n]=s)),s){let r=this.getConsumedOffset(s);r<i&&(i=r)}}return i}dumpLocation(e){H.debug("Location - page",this.currentLayoutPosition.page),H.debug(" current:",e),H.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)H.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new ze(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let s=i.positions[0].flowChunk.breakBefore,r=i.startBreakType;i.startBreakType=ml(nt(r,s))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,s;for(let r=0;r<n.length;r++){if(s=n[r],s.pageBox.pseudoName===Fa)continue;let o=1;s.pageBox.pseudoName===Ta&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=s.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let l=this.queryUnitSize("em",!1),h=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*h/(l*l)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=s.getProp(this,"enabled");if(!p||p===y._true){if(t.page===1&&this.blankPageAtStart){s.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(s,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,s=t[i].forcedBreakOffsets;if(!s.length||n<s[0])return!1;let r=ni(s.length,h=>s[h]>n)-1,o=s[r],a=this.layoutPositionAtPageStart.flowPositions[i],l=this.getConsumedOffset(a);return o<l?!1:l<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new da(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Fe.PAGE)return!1;let l=this.layoutPositionAtPageStart.flowPositions.body,h=l&&this.getConsumedOffset(l),u=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return u!=null&&h!=null&&u>h},s=B("layoutDeferredPageFloats"),r=!1,o=0;return s.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let l=i[o++],h=l.float;if(n(h)){a.breakLoop();return}let u=new Xi().findByFloat(h),d=u.findPageFloatFragment(h,t);if(d&&d.hasFloat(h)){a.continueLoop();return}else if(t.isForbidden(h)||t.hasPrecedingFloatsDeferredToNext(h)){t.deferPageFloat(l),a.breakLoop();return}e.layoutPageFloatInner(l,u,null,d).then(p=>{if(!p){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(r=!0,t.validate());a.continueLoop()})}).then(()=>{r&&t.invalidate(),s.finish(!0)}),s.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new oi(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=B("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let s=[],r=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-r.length>0;){let l=0;for(;r.includes(l);)l++;let h=i.positions[l];if(h.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(h.flowChunk))break;for(let p=l+1;p<i.positions.length;p++){if(r.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(h.flowChunk)&&(h=f,l=p)}let u=h.flowChunk,d=!0;if(e.layout(h.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,h.flowChunk.repeated&&(p===null||u.exclusive)&&s.push(l),u.exclusive){r.push(l),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(e.pageBreakType&&m?(h.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(r.push(l),(p||m)&&(h.chunkPosition=p||m,s.push(l)),i.startBreakType=ml(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,h)=>s.includes(h)||!r.includes(h)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new lw([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,s,r,o,a,l,h,u,d,p,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=s.element,w=new pn(a,Fe.COLUMN,null,o,null,null,null),v=this.currentLayoutPosition.clone(),b=B("createAndLayoutColumn"),C;return b.loopWithFrame(E=>{let A=this.createLayoutConstraint(w);if(l>1){let V=this.viewport.document.createElement("div");if(T(V,"position","absolute"),g.appendChild(V),C=new Us(V,p,this.clientLayout,A,w),C.forceNonfitting=f,C.vertical=s.vertical,C.rtl=s.rtl,C.snapHeight=s.snapHeight,C.snapWidth=s.snapWidth,s.vertical){let D=(s.rtl?l-r-1:r)*(u+h)+s.paddingTop,te=parseFloat(g.style.width);C.setHorizontalPosition(s.paddingLeft+te-s.width,s.width),C.setVerticalPosition(D,u)}else{let D=(s.rtl?l-r-1:r)*(u+h)+s.paddingLeft;C.setVerticalPosition(s.paddingTop,s.height),C.setHorizontalPosition(D,u)}C.originX=t,C.originY=i}else C=new Us(g,p,this.clientLayout,A,w),C.copyFrom(s);C.exclusions=m?[]:n.concat(),C.innerShape=d,w.setContainer(C),(C.vertical?C.height:C.width)>=0?this.layoutColumn(C,o).then(()=>{w.isInvalidated()||w.finish(),C.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(C.pageFloatLayoutContext.validate(),this.currentLayoutPosition=v.clone(),C.element!==g&&g.removeChild(C.element),E.continueLoop()):E.breakLoop()}):(w.finish(),E.breakLoop())}).then(()=>{b.finish(C)}),b.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Pd||t instanceof Ia&&!(t instanceof Wi))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Zi;let s=t.getProp(this,"writing-mode")||null,r=t.getProp(this,"direction")||null;return new pn(e,Fe.REGION,i,n,null,s,r)}layoutFlowColumnsWithBalancing(e,t,i,n,s,r,o,a,l){let h=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(r,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=h.clone(),this.layoutFlowColumns(e,t,i,n,s,r,u,o,a,l,d).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return N(null);if(l<=1)return N(f.columns);let m=t.getProp(this,"column-fill")||y.balance,g=this.currentLayoutPosition.flowPositions[a],w=Kw(l,m,p,u,o,f.columns,g);return w?(d=!1,r.lock(),u.lock(),w.balanceColumns(f).thenAsync(v=>(r.unlock(),r.validate(),u.unlock(),this.currentLayoutPosition=v.position,N(v.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,s,r,o,a,l,h,u){let d=B("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=h>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),v=lu(w,0,0,a.width,a.height,this),b=new Hy(l,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),C=0,E=null,A=[];return d.loopWithFrame(V=>{this.createAndLayoutColumn(t,i,n,s,a,C++,l,o,h,f,m,v,b,u).then(D=>{if(r.isInvalidated()){A=null,V.breakLoop();return}if((D.pageBreakType&&D.pageBreakType!=="column"||C===h)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),o.validate(),o.isLocked()?(A=null,V.breakLoop()):V.continueLoop();return}E=D,A[C-1]=E,E.pageBreakType&&E.pageBreakType!="column"&&(C=h,E.pageBreakType!="region"&&(this.pageBreaks[l]=!0)),C<h?V.continueLoop():V.breakLoop()})}).then(()=>{d.finish(A)}),d.result()}layoutContainer(e,t,i,n,s,r,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==y._true)return N(!0);let l=B("layoutContainer"),h=t.getProp(this,"wrap-flow")===y.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof Td?"complementary":"presentation";let p=t.getProp(this,"position");T(d,"position",p?p.name:"absolute");let f=t instanceof Wi;t instanceof Zi?i.appendChild(d):i.insertBefore(d,i.firstChild);let m=new Wu(d);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=r,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof Wi&&(m.width<=0||m.height<=0)&&H.warn("Negative or zero page area size"),m.originX=n,m.originY=s,n+=m.left+m.marginLeft+m.borderLeft,s+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!u||!u.isIdent()){let v=t.getProp(this,"content");if(v instanceof U&&v.expr instanceof Me&&v.expr.str.startsWith("running-element-"))v.visit(new Ms(d,this,v,this.counterStore.getExprContentListener()));else if(Ot(v)){let b="span";v instanceof Je&&(b="img");let C=this.viewport.document.createElement(b);v.visit(new Ms(C,this,v,this.counterStore.getExprContentListener())),d.appendChild(C),b=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,m,e,this.faces),b=="span"&&ew(C,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(d),w=!0);w||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0);else{let v=B("layoutContainer.inner"),b=u.toString(),C=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,s,r,o,m,b,C).then(E=>{if(!o.isInvalidated()){let A=E[0];A.element===d&&(m=A),m.computedBlockSize=Math.max.apply(null,E.map(D=>D.computedBlockSize)),t.finishContainer(this,m,e,A,C,this.clientLayout,this.faces);let V=this.currentLayoutPosition.flowPositions[b];V&&V.breakAfter==="region"&&(V.breakAfter=null)}v.finish(!0)}),g=v.result()}return g.then(()=>{if(o.isInvalidated()){l.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!h){let b=t.getProp(this,"shape-outside"),C=m.getOuterShape(b,this);r.push(C)}}else if(t.children.length==0){i.removeChild(d),l.finish(!0);return}let v=f?0:t.children.length-1;l.loop(()=>{for(;v>=0&&v<t.children.length;){let b=t.children[f?v++:v--],C=this.layoutContainer(e,b,d,n,s,r,o);if(C.isPending())return C.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{l.finish(!0)})}),l.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage>=0&&s.flowChunk.startPage+s.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let s=i.positions[n];s.flowChunk.startPage<0&&s.flowChunk.startOffset<this.lookupOffset&&(s.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Rg,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let s=1e4;if(t.page>s)throw new Error(`Too many pages generated (over ${s} pages)`);let r=t.startSideOfFlow("body");t.isBlankPage=Fn(r)&&this.matchPageSide(r),e.isBlankPage=t.isBlankPage,t.page++;let o=this.styler.cascade.previousPageType;e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType);let a=this.pageManager.pageCascadeInstance;e.pageType&&(o!==e.pageType&&(a.pageTypePageCounts[e.pageType]=0),a.pageTypePageCounts[e.pageType]=(a.pageTypePageCounts[e.pageType]||0)+1),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),!n){let g=new ze(this.style.pageScope,"left-page");e.side=g.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let h=this.selectPageMaster(l);if(!h)return N(null);let u=0;if(!n){e.setAutoPageWidth(h.pageBox.specified.width.value===Hn),e.setAutoPageHeight(h.pageBox.specified.height.value===$n),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let g=sh(Xs(l),this);this.setPageSizeAndBleed(g,e),py(l,g,e,this),u=g.bleedOffset+g.bleed}let d=!n&&h.getProp(this,"writing-mode")||y.horizontal_tb;this.pageVertical=d!=y.horizontal_tb;let p=h.getProp(this,"direction")||y.ltr,f=new pn(this.rootPageFloatLayoutContext,Fe.PAGE,null,null,null,d,p),m=B("layoutNextPage");return m.loopWithFrame(g=>{this.layoutContainer(e,h,e.bleedBox,u,u,[],f).then(()=>{f.isInvalidated()||f.finish(),f.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),f.validate(),g.continueLoop()):g.breakLoop()})}).then(()=>{h.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(w=>{let v=t.flowPositions[w],b=v.breakAfter;b&&(b==="page"||!this.matchPageSide(b))&&(v.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let g=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(g,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),m.finish(t)}),m.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},Jy=class Wo extends Ln{constructor(t,i,n,s){super(t.rootScope,t,i,n,s,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let s=new md(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new oy(s.scope,this.masterHandler,s,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=St(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Wo(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new jm(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new fn(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new Ky(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new fn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new fn(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=qn(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new fn(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Fy(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Ln.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",F(t)),this.endRule();let i=new Wo(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Od=class extends eg{constructor(e){super(),this.validatorSet=e,c(this,"rootScope"),c(this,"pageScope"),c(this,"rootBox"),c(this,"cascadeParserHandler"),c(this,"regionCount",0),c(this,"fontFaces",[]),c(this,"counterStyles",new Rb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new Dr(null),this.pageScope=new Dr(this.rootScope),this.rootBox=new ey(this.rootScope),this.cascadeParserHandler=new Jy(this,null,null,null),this.slave=this.cascadeParserHandler}};function Qy(e,t){return t.parseOPSResource(e)}var e0=class extends ia{constructor(e){super(Qy,"document"),this.fontDeobfuscator=e,c(this,"styleByKey",{}),c(this,"styleFetcherByKey",{}),c(this,"styleByDocURL",{}),c(this,"triggersByDocURL",{}),c(this,"validatorSet",null),c(this,"styleSheets",[]),c(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=B("OPSDocStore.init");return this.validatorSet=fd(),Yy().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Pe(Rn(t),Gi)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Pe(Rn(t),Gi)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=B("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return Ld(e,this).then(s=>{var r;if(!s){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=It("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](s.document)}catch(m){H.warn("Error during single document preprocessing:",m)}}let o=[],a=s.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),v=f.getAttribute("ref");m&&g&&w&&v&&o.push({observer:m,event:g,action:w,ref:v})}this.triggersByDocURL[i]=o;let l=[];if(l.push({url:Pe("user-agent-page.css",Qt),text:wu,flavor:"UA",classes:null,media:null}),l.push({url:Pe("user-agent-counter-styles.css",Qt),text:xu,flavor:"UA",classes:null,media:null}),n)l.push({url:Pe("user-agent-toc.css",Qt),text:yu,flavor:"UA",classes:null,media:null});else{let p=s.document.querySelectorAll("style, link, meta");for(let f of p){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),v=f.getAttribute("media"),b=f.getAttribute("title");l.push({url:i,text:f.textContent,flavor:"Author",classes:b?w:null,media:v})}else if(g=="link"){let w=f.getAttribute("href"),v=(r=f.getAttribute("rel"))==null?void 0:r.split(/\s+/),b=f.getAttribute("class"),C=f.getAttribute("media");if(w&&v!=null&&v.includes("stylesheet")&&(!v.includes("alternate")||b)){let E=Pe(w,i),A=f.getAttribute("title");l.push({url:E,text:null,classes:A?b:null,media:C,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&l.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)l.push(this.styleSheets[f])}let h="";for(let p=0;p<l.length;p++)h+=l[p].url,h+="^",l[p].text&&(h+=l[p].text),h+="^";let u=this.styleByKey[h];if(u){this.styleByDocURL[i]=u,t.finish(s);return}let d=this.styleFetcherByKey[h];d||(d=new Wn(()=>{let p=B("fetchStylesheet"),f=0,m=new Od(this.validatorSet);return p.loop(()=>{if(f<l.length){let g=l[f++];return m.startStylesheet(g.flavor),g.text!==null?sa(g.text,m,g.url,g.classes,g.media).thenReturn(!0):Pu(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();u=new Zy(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps,m.counterStyles),this.styleByKey[h]=u,delete this.styleFetcherByKey[h],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[h]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(s)})}),t.result()}processViewportMeta(e){return""}},In="\u25B8",lh="\u25BE",t0="\u25B9";function Oa(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(r=>r.contains(n)))continue;let s=n;/^h[1-6]$/.test(s.localName)&&(s.previousElementSibling?s=s.nextElementSibling:s=s.parentElement),s&&s.querySelector("li a[href]")&&t.push(s)}return t}function i0(e){let t=Oa(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var n0=class{constructor(e,t,i,n,s,r,o,a,l,h){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=s,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=l,this.counterStore=h,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=Oh(r),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;Kt(n,"height","auto")!="auto"&&(T(n,"height","auto"),this.setAutoHeight(n,t)),Kt(n,"position","static")=="absolute"&&(T(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,s)=>{let r=s.behavior;if(r)switch(r.toString()){case"toc-node-anchor":s.color=y.inherit,s["text-decoration"]=y.none;break;case"toc-node":s.display=y.block,s.margin=ke,s.padding=ke,s["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":s.display=y.inline_block,s.margin=new I(.2,"em"),s["vertical-align"]=y.top,s.color=y.inherit,s["text-decoration"]=y.none;break;case"toc-container":s.padding=ke;break}if(!r||r.toString()!="toc-node"&&r.toString()!="toc-container")return t(i,n,s);let o=i.firstChild;o&&o.nodeType!==1&&He(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let h=n.firstChild;h.textContent!=In&&(h.textContent=In,T(h,"cursor","pointer"),h.addEventListener("click",s0,!1),h.setAttribute("role","button"),h.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(h.tabIndex=0))}let l=n.ownerDocument.createElement("div");if(l.setAttribute("data-adapt-process-children","true"),r.toString()=="toc-node"){let h=n.ownerDocument.createElement("div");if(h.textContent=t0,T(h,"margin","0.2em 0 0 -1em"),T(h,"margin-inline-start","-1em"),T(h,"margin-inline-end","0"),T(h,"display","inline-block"),T(h,"width","1em"),T(h,"text-align","center"),T(h,"vertical-align","top"),T(h,"cursor","default"),T(h,"font-family","Menlo,sans-serif"),l.appendChild(h),T(l,"overflow","hidden"),l.setAttribute("data-adapt-class","toc-node"),l.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){T(l,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(l.setAttribute("data-adapt-class","toc-container"),l.setAttribute("role","group"),l.setAttribute("aria-hidden","true"));return N(l)}}showTOC(e,t,i,n,s){if(this.page)return N(this.page);let r=B("showTOC"),o=new _u(e,e);this.page=o;let a=Dt(this.url)+"?viv-toc-box";return this.store.load(a).then(l=>{for(let f of Oa(l.document))f.setAttribute("data-vivliostyle-role","doc-toc");let h=this.store.getStyleForDoc(l),u=h.sizeViewport(i,1e5,s);t=new qs(t.window,u.fontSize,0,t.root,u.width,u.height);let d=this.makeCustomRenderer(l),p=new Ba(h,l,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),r.finish(o)})})}),r.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let s=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(s).map(t)}function t(n){let s=new URL(n.href),[,r]=s.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),l=e(a);return{id:r,title:o,children:l}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function s0(e){let t=e.target,i=t.textContent==In;t.textContent=i?lh:In;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let s=n.firstChild;for(;s;){if(s.nodeType===1){let r=s,o=r.getAttribute("data-adapt-class");if(o==="toc-container"){if(r.setAttribute("aria-hidden",i?"false":"true"),r.firstChild){s=r.firstChild;continue}}else if(o==="toc-node"&&(r.style.height=i?"auto":"0px",r.children.length>=2&&(r.children[1].tabIndex=i?0:-1),r.children.length>=3&&(r.children[0].tabIndex=i?0:-1,!i))){let a=r.children[0];if(a.textContent==lh){a.textContent=In,a.setAttribute("aria-expanded","false"),r.setAttribute("aria-expanded","false"),s=r.children[2];continue}}}for(;!s.nextSibling&&s.parentNode!==n;)s=s.parentNode;s=s.nextSibling}e.stopPropagation()}var hh=class extends e0{constructor(){super(null),c(this,"plainXMLStore"),c(this,"jsonStore"),c(this,"opfByURL",{}),c(this,"primaryOPFByEPubURL",{}),c(this,"deobfuscators",{}),c(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=jy(),this.jsonStore=Kf()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=B("loadPubDoc");return tr(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}H.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,s]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,s).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let s=new Ts(this,e);s.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(s)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(s=>{if(s){t.finish(s);return}H.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=B("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let s=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let r of s)if(r){this.loadOPF(e,r).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let s=B("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(r=>{r?(n=new Ts(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(r,o).then(()=>{s.finish(n)})}):n.initWithXMLDoc(r,null).then(()=>{s.finish(n)})):this.reportLoadError(i)}),s.result()}loadWebPub(e){let t=B("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,s=new Ts(this,e),r=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(r){let o=r.getAttribute("href");if(/^#/.test(o)){let a=Xo(n.getElementById(o.substr(1)).textContent);s.initWithWebPubManifest(a,n).then(()=>{t.finish(s)})}else{let a=Pe(r.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(l=>{s.initWithWebPubManifest(l,n,a).then(()=>{t.finish(s)})})}}else s.initWithWebPubManifest({},n).then(()=>{s.toc&&s.toc.src===i.url&&Oa(n).length===0&&(s.toc=null),t.finish(s)})}}),t.result()}addDocument(e,t){let i=B("EPUBDocStore.load"),n=Dt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(Gi)||Object.keys(this.resources).find(s=>this.resources[s]&&t(s)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?H.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Gi.startsWith("https:")?H.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?H.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):H.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Dt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=B("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(s=>{s?n.finish(s):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let s=i.width-0,r=i.height-0;if(s&&r){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${s}px;height:${r}px;}`+(o?`@page{size:${s}px ${r}px;margin:0;}`:"@page{margin:0;}")}return""}},uh=class{constructor(){c(this,"id",null),c(this,"src",""),c(this,"mediaType",null),c(this,"title",null),c(this,"itemRefElement",null),c(this,"spineIndex",-1),c(this,"compressedSize",0),c(this,"compressed",null),c(this,"epage",0),c(this,"epageCount",0),c(this,"startPage",null),c(this,"skipPagesBefore",null),c(this,"itemProperties"),this.itemProperties=yp}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Pe(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Np(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function r0(e){return e.id}function o0(e){return t=>{let i=B("deobfuscator");return a0("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);Xf(s).then(o=>{let a=new DataView(o);for(let l=0;l<a.byteLength;l++){let h=a.getUint8(l);h^=n[l%20],a.setUint8(l,h)}i.finish(Su([a,r]))})}),i.result()}}function a0(e,t){let i=B("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(s=>{n.schedule(new Uint8Array(s))}),i.result()}var Jt={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"},bn="http://idpf.org/epub/vocab/package/meta/#",Be={language:`${Jt.dcterms}language`,title:`${Jt.dcterms}title`,creator:`${Jt.dcterms}creator`,layout:`${Jt.rendition}layout`,titleType:`${bn}title-type`,displaySeq:`${bn}display-seq`,alternateScript:`${bn}alternate-script`,role:`${bn}role`};function l0(e,t){let i={};return(n,s)=>{var r,o,a,l,h,u;let d,p,f=n.r||i,m=s.r||i;if(e==Be.title&&(d=((r=f[Be.titleType])==null?void 0:r[0].v)=="main",p=((o=m[Be.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let g=parseInt((a=f[Be.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((l=m[Be.displaySeq])==null?void 0:l[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Be.language&&t&&(d=((h=f[Be.language]||f[Be.alternateScript])==null?void 0:h[0].v)==t,p=((u=m[Be.language]||m[Be.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-s.o}}function h0(e,t){let i;if(!t)i=Jt;else{i={};for(let p in Jt)i[p]=Jt[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:bn;if(f)return f+p[3]}}return null},s=1,r=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order: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:Jt.dcterms+d.localName,order:s++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=gr(r,d=>d.refines),a=d=>Pp(d,(p,f)=>p.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=o[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Be.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Be.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let v=gr(w,b=>b.name);g.r=a(v)}return g})),l=a(gr(r,d=>d.refines?null:d.name)),h=null;l[Be.language]&&(h=l[Be.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(l0(p,h));for(let m=0;m<f.length;m++){let g=f[m].r;g&&u(g)}}};return u(l),l}function u0(){let e=window.MathJax;return e?e.Hub:null}var ch={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Or="viv-id-",Ts=class{constructor(e,t){this.store=e,this.pubURL=t,c(this,"opfXML",null),c(this,"encXML",null),c(this,"items",null),c(this,"spine",null),c(this,"itemMap",null),c(this,"itemMapByPath",null),c(this,"uid",null),c(this,"bindings",{}),c(this,"lang",null),c(this,"epageCount",0),c(this,"prePaginated",!1),c(this,"epageIsRenderedPage",!0),c(this,"epageCountCallback",null),c(this,"metadata",{}),c(this,"toc",null),c(this,"cover",null),c(this,"fallbackMap",{}),c(this,"pageProgression",null),c(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,s){let r=s+(n?`#${n}`:"");return Or+Ah(r,":")}transformURL(n,s){let r=n.match(/^([^#]*)#?(.*)$/);if(r){let o=r[1]||s.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(r[2]);if(o&&e.spine.some(l=>l.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Or)===0&&(n=n.substring(Or.length));let s=Ep(n,":").match(/^([^#]*)#?(.*)$/);return s?[s[1],s[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Pe("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let l=e.getElement(`${e.url}#${n}`);l&&(this.uid=l.textContent.replace(/[ \n\r\t]/g,""))}let s={};this.items=i.child("manifest").child("item").asArray().map(l=>{let h=new uh,u=l;h.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!ch[h.mediaType]&&(s[h.src]=d),!this.toc&&h.itemProperties.nav&&(this.toc=h),!this.cover&&h.itemProperties["cover-image"]&&(this.cover=h),h}),this.itemMap=ja(this.items,r0),this.itemMapByPath=ja(this.items,l=>this.getPathFromURL(l.src));for(let l in s){let h=l;for(;;){let u=this.itemMap[s[h]];if(!u)break;if(ch[u.mediaType]){this.fallbackMap[l]=u.src;break}h=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((l,h)=>{let u=l,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=h),p});let r=i.child("spine").attribute("page-progression-direction")[0];r&&(this.pageProgression=xh(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(ah.withChild("EncryptionMethod",ah.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let l=0;l<a.length;l++){let h=a[l].getAttribute("handler"),u=a[l].getAttribute("media-type");u&&h&&this.itemMap[h]&&(this.bindings[u]=this.itemMap[h].src)}if(this.metadata=h0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Be.language]&&(this.lang=this.metadata[Be.language][0].v),this.metadata[Be.layout]&&(this.prePaginated=this.metadata[Be.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let l=o0(this.uid);for(let h=0;h<o.length;h++)this.store.deobfuscators[this.pubURL+o[h]]=l}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=B("countEPages");return n.loopWithFrame(s=>{if(i===this.spine.length){s.breakLoop();return}let r=this.spine[i++];r.epage=t,this.store.load(r.src).then(o=>{let a=1800,l=o.lang||this.lang;l&&l.match(/^(ja|ko|zh)/)&&(a/=3),r.epageCount=Math.ceil(o.getTotalOffset()/a),t+=r.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),s.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new Fd(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new uh;s.initWithParam(n),s.id;let r=i.document.createElement("itemref");r.setAttribute("idref",s.id),i.root.appendChild(r),s.itemRefElement=r,this.itemMap[s.id]=s;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=s,this.items.push(s)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,s,r,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Be.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let l=e.author||e.creator||((s=e.metadata)==null?void 0:s.author)||Array.from((r=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?r:[]).map(g=>g.content);l&&l.length!==0&&(this.metadata[Be.creator]=(Array.isArray(l)?l:[l]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let h=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");h&&(this.metadata[Be.language]=(Array.isArray(h)?h:[h]).map(g=>({v:g})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let g of i0(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let v=Dt(Pe(w,this.pubURL)),b=this.getPathFromURL(v),C=b!==null?encodeURI(b):v;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let d=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let v=g===e.readingOrder,b=typeof w=="string"?w:w.url||w.href,C=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(v||C==="text/html"||C==="application/xhtml+xml"||!C&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(b)){let E=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,A={url:Pe(Rn(b),E),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=A.index),d.push(A)}})});let m=B("initWithWebPubManifest");return this.initWithChapters(d).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[u]);let v=(w=e.readingOrder)==null?void 0:w.length;v&&v<this.items.length&&this.items.splice(v),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=B("getCFI");return this.store.load(i.src).then(s=>{let r=s.getNodeByOffset(t),o=null;if(r){let a=s.getNodeOffset(r,0,!1),l=t-a,h=new Ja;h.prependPathFromNode(r,l,!1,null),i.itemRefElement&&h.prependPathFromNode(i.itemRefElement,0,!1,null),o=h.toString()}n.finish(o)}),n.result()}resolveFragment(e){return ji("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Ja;i.fromString(e);let n;if(this.opfXML){let s=i.navigate(this.opfXML.document);if(s.node.nodeType!=1||s.after||!s.ref){t.finish(null);return}let r=s.node,o=r.getAttribute("idref");if(r.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=s.ref}else n=this.spine[0];this.store.load(n.src).then(s=>{let r=i.navigate(s.document),o=s.getNodeOffset(r.node,r.offset,r.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return ji("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let s=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);s==-1&&(s=this.spine.length-1);let r=this.spine[s];(!r||r.epageCount==0)&&(r=this.spine[--s]);let o=Math.floor(e-r.epage);t.finish({spineIndex:s,offsetInItem:-1,pageIndex:o});return}let i=ni(this.spine.length,s=>{let r=this.spine[s];return r.epage+r.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(s=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let r=0;if(e>0){let o=s.getTotalOffset();r=Math.round(o*e/n.epageCount),r==o&&r--}t.finish({spineIndex:i,offsetInItem:r,pageIndex:-1})})},(t,i)=>{H.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=B("getEPage");return this.store.load(t.src).then(n=>{let s=n.getTotalOffset(),r=Math.min(s,e.offsetInItem);i.finish(t.epage+r*t.epageCount/s)}),i.result()}},hs=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),c0=class{constructor(e,t,i,n,s){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=s,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),this.pref=Oh(n),this.clientLayout=new Wy(t),this.counterStore=new mf(e.documentURLTransformer)}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let s=this.opf.spine[e.item.spineIndex-1];e.item.epage=s.epage+s.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((s,r)=>s+r.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let s=null;if(i>0)s=e.pages[i-1].container.nextElementSibling;else for(let r=e.item.spineIndex+1;r<this.spineItems.length;r++){let o=this.spineItems[r];if(o&&o.pages[0]){s=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,s)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=B("renderSinglePage"),n=e.pages[t?t.page:0],s=this.makePage(e,t);return n&&(s.pageType=n.pageType),e.instance.layoutNextPage(s,t).then(r=>{t=r;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,s,o),this.counterStore.finishPage(s.spineIndex,o);let a=null;if(t){let l=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,l&&e.pages[t.page]&&(t.isSamePosition(l)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let l=this.counterStore.getUnresolvedRefsToPage(s),h=0;i.loopWithFrame(u=>{if(h++,h>l.length){u.breakLoop();return}let d=l[h-1];if(d.refs=d.refs.filter(p=>!p.isResolved()),d.refs.length===0){u.continueLoop();return}this.getPageViewItem(d.spineIndex).then(p=>{if(!p){u.continueLoop();return}let{currentPageType:f,previousPageType:m}=p.instance.styler.cascade,g=p.instance.scopes;p.instance.scopes={},this.counterStore.pushPageCounters(d.pageCounters),this.counterStore.pushReferencesToSolve(d.refs);let w=p.layoutPositions[d.pageIndex];this.renderSinglePage(p,w).then(v=>{p.instance.styler.cascade.currentPageType=f,p.instance.styler.cascade.previousPageType=m,p.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let b=v.pageAndPosition.position;b.spineIndex===s.spineIndex&&b.pageIndex===o&&(s=v.pageAndPosition.page),u.continueLoop()})})}).then(()=>{s.container.parentElement||(s=e.pages[o]),s.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,s.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),s.container.setAttribute("data-vivliostyle-page-index",o),s.container.setAttribute("data-vivliostyle-spine-index",s.spineIndex),i.finish({pageAndPosition:hs(s,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let s=ni(t.layoutPositions.length,r=>t.instance.getPosition(t.layoutPositions[r],!0)>n);s===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=s-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=B("findPage");return this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let s=null,r;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);r=a.pageIndex,s=n.pages[r],s?o.breakLoop():n.complete?(r=n.layoutPositions.length-1,s=n.pages[r],o.breakLoop()):t?this.renderPage(a).then(l=>{l&&(s=l.page,r=l.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(hs(s,r))})}),i.result()}renderPage(e){let t=B("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),s=n.pageIndex,r=n.offsetInItem,o=i.pages[s];if(o){t.finish(hs(o,s));return}t.loopWithFrame(a=>{if(s<i.layoutPositions.length){a.breakLoop();return}if(i.complete){s=i.layoutPositions.length-1,a.breakLoop();return}let l=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,l).then(h=>{let u=h.pageAndPosition.page;if(l=h.nextLayoutPosition,l){if(r>=0&&i.instance.getPosition(l)>r){o=u,s=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,s=h.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[s];let a=i.layoutPositions[s];if(o){t.finish(hs(o,s));return}this.renderSinglePage(i,a).then(l=>{l.nextLayoutPosition||(i.complete=!0),t.finish(l.pageAndPosition)})})}),t.result()}renderAllPages(){let e=B("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(s=>s?.fetchers.some(r=>!r.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=B("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,s=e.pageIndex,r=0;t&&(r=n);let o;return i.loopWithFrame(a=>{let l={spineIndex:r,pageIndex:r===n?s:Number.POSITIVE_INFINITY,offsetInItem:r===n?e.offsetInItem:-1};this.renderPage(l).then(h=>{o=h,++r>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,s=B("nextPage");return this.getPageViewItem(i).then(r=>{if(!r){s.finish(null);return}if(r.complete&&n==r.layoutPositions.length-1){if(i>=this.opf.spine.length-1){s.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],l=r.pages[r.pages.length-1];a&&l&&a.side==l.side&&(o.pages.forEach(h=>{h.container&&h.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(s)}),s.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=B("getSpread"),s=i.side==="left",r;return this.isRectoPage(i,e)?r=this.previousPage(e,t):r=this.nextPage(e,t),r.then(o=>{let a=this.getPage(e),l=o&&o.page;l&&l.side===a.side&&(l=null),s?n.finish({left:a,right:l}):n.finish({left:l,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.nextPage(e,t);return n?s:s.thenAsync(r=>{if(r){if(r.page.side===i.side)return s;let o=this.nextPage(r.position,t);return o.thenAsync(a=>a?o:s)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),s=this.previousPage(e,t),r=i.container.previousElementSibling;return n?s.thenAsync(o=>o?o.page.side===i.side||o.page.container!==r?s:this.previousPage(o.position,t):N(null)):s}navigateToEPage(e,t,i){let n=B("navigateToEPage");return this.opf.resolveEPage(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=B("navigateToCFI");return this.opf.resolveFragment(e).then(s=>{s?this.findPage(s,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){H.debug("Navigate to",e);let n=this.opf.getPathFromURL(Dt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let s=this.opf.itemMapByPath[n];if(!s){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let r=B("navigateTo");return this.getPageViewItem(s.spineIndex).then(o=>{if(!o){r.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:s.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(r)}),r.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",An||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let s=i.document.createElement("div");s.setAttribute("data-vivliostyle-bleed-box","true"),s.role="presentation",n.appendChild(s);let r=new _u(n,s);if(r.spineIndex=e.item.spineIndex,r.position=t,r.offset=e.instance.getPosition(t),r.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);s.setAttribute("id",o),r.registerElementWithId(s,o)}if(i!==this.viewport){let o=_h(this.viewport.width,this.viewport.height,i.width,i.height),a=tn(null,new At(o,null),"");r.delayedItems.push(new oa(n,"transform",a))}return r}makeObjectView(e,t,i,n){let s=t.getAttribute("data"),r=null;if(s){s=Pe(s,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(s);if(a){let l=this.opf.itemMapByPath[a];l&&(o=l.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){r=this.viewport.document.createElement("iframe"),r.style.border="none";let l=Wa(s),h=Wa(o),u=new ii;u.append(a),u.append("?src="),u.append(l),u.append("&type="),u.append(h);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(u.append("&"),u.append(encodeURIComponent(g)),u.append("="),u.append(encodeURIComponent(w)))}}r.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&r.setAttribute("width",d);let p=t.getAttribute("height");p&&r.setAttribute("height",p)}}}return r||(r=this.viewport.document.createElement("object"),s&&r.setAttribute("data",s),r.setAttribute("data-adapt-process-children","true")),N(r)}makeMathJaxView(e,t,i,n){let s=u0();if(s){let r=i.ownerDocument,o=r.createElement("span");i.appendChild(o);let a=r.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let l=s.queue;l.Push(["Typeset",s,o]);let h=B("makeMathJaxView"),u=h.suspend();return l.Push(()=>{u.schedule(o)}),h.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let s=Pe(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,s):e.setAttribute(n.name,s)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=B("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let s=this.opf.spine[e],r=this.opf.store;return r.load(s.src).then(o=>{var a;let l=s.itemRefElement.getAttribute("properties");l&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",l),s.title=o.document.title;let h=r.getStyleForDoc(o),u=this.makeCustomRenderer(o),d=this.viewport,p=h.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new qs(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(s.startPage!==null)g=s.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=s.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?g:C[C.length-1]}s.skipPagesBefore!==null&&(g+=s.skipPagesBefore,w+=s.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let v=new Ba(h,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.opf.pageProgression,f);v.pref=this.pref;let b=this.opf.metadata&&this.opf.metadata[Be.title];v.pubTitle=b&&b[0]&&b[0].v||"",v.docTitle=s.title||"",v.init().then(()=>{!this.opf.pageProgression&&v.pageProgression&&(this.opf.pageProgression=v.pageProgression),t={item:s,xmldoc:o,instance:v,layoutPositions:[null],pages:[],complete:!1},this.spineItems[e]=t,i.finish(t),n.forEach(C=>{C.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return N(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),N(this.tocView.page);let n=B("showTOC");this.tocView||(this.tocView=new n0(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore));let s=this.viewport,r=Math.min(344,Math.round(.67*s.width)-16),o=s.height-6,a=s.document.createElement("div");return s.root.appendChild(a),An||(a.style.visibility="hidden"),a.style.width=`${r+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,s,r,o,this.viewport.fontSize).then(l=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(l)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},dh="data-vivliostyle-viewer-status",d0="data-vivliostyle-spread-view",_d=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(_d||{}),p0=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,c(this,"fontMapper"),c(this,"kick"),c(this,"sendCommand"),c(this,"resizeListener"),c(this,"hyperlinkListener"),c(this,"pageRuleStyleElement"),c(this,"pageSheetSizeAlreadySet",!1),c(this,"renderTask",null),c(this,"actions"),c(this,"readyState"),c(this,"packageURL"),c(this,"opf"),c(this,"touchActive"),c(this,"touchX"),c(this,"touchY"),c(this,"needResize"),c(this,"resized"),c(this,"needRefresh"),c(this,"viewportSize"),c(this,"currentPage"),c(this,"currentSpread"),c(this,"pagePosition"),c(this,"fontSize"),c(this,"zoom"),c(this,"fitToScreen"),c(this,"pageViewMode"),c(this,"waitForLoading"),c(this,"renderAllPages"),c(this,"pref"),c(this,"pageSizes"),c(this,"pixelRatio"),c(this,"pixelRatioLimit"),c(this,"viewport"),c(this,"opfView");let s=t.ownerDocument,r=(o,a)=>{let l=s.getElementById(o);return l||(l=s.createElement("style"),l.id=o,a&&(l.textContent=a),s.head.appendChild(l)),l};r("vivliostyle-viewport-screen-css",pu),r("vivliostyle-viewport-css",fu),r("vivliostyle-polyfill-css",vu),t.setAttribute("data-vivliostyle-viewer-viewport",!0),An&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(dh,"loading"),this.fontMapper=new Jb(s.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=r("vivliostyle-page-rules"),this.actions={loadPublication:this.loadPublication,loadXML:this.loadXML,configure:this.configure,moveTo:this.moveTo,toc:this.showTOC},this.addLogListeners()}init(){this.readyState="loading",this.packageURL=[],this.opf=null,this.touchActive=!1,this.touchX=0,this.touchY=0,this.needResize=!1,this.resized=!1,this.needRefresh=!1,this.viewportSize=null,this.currentPage=null,this.currentSpread=null,this.pagePosition=null,this.fontSize=16,this.zoom=1,this.fitToScreen=!1,this.pageViewMode="singlePage",this.waitForLoading=!1,this.renderAllPages=!0,this.pref=Bh(),this.pageSizes=[],this.pixelRatioLimit=Ph==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=kh;H.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),H.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),H.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),H.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(dh,e),this.callback({t:"readystatechange"}))}loadPublication(e){ct.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let r=B("loadPublication");return this.configure(e).then(()=>{let o=new hh;o.init(n,s).then(()=>{let a=Pe(Rn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(l=>{l?(this.opf=l,this.render(i).then(()=>{r.finish(!0)})):r.finish(!1)})})}),r.result()}loadXML(e){ct.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,s=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let o=B("loadXML");return this.configure(e).then(()=>{let a=new hh;a.init(s,r).then(()=>{let l=t.map((h,u)=>({url:Pe(Rn(h.url),this.window.location.href),index:u,startPage:h.startPage,skipPagesBefore:h.skipPagesBefore}));this.packageURL=l.map(h=>h.url),this.opf=new Ts(a,""),this.opf.initWithChapters(l,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(ct.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let s=n[0];if(s==="em"||s==="rem")return t*this.fontSize;let r=Pt[s];if(r)return t*r}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(Ua(e.userAgentRootURL.replace(/resources\/?$/,"")),Ha(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Ua(e.rootURL),Ha(`${Gi}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==jt&&(By(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){It("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{T(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),T(e.container,"visibility","visible"),T(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=B("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?er(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new qs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new qs(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return e!=null&&(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(d0,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let s=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!s&&t.width==this.viewport.width&&t.height==this.viewport.height||!s&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,s;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((s=this.pageSizes[i-1])==null?void 0:s.height))){let o=function(m){let g=m*.75;return Math.ceil(g)};var r=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),h=o(a),u=o(l),d=h*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${h}pt ${u}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new c0(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new ph),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Xr().getScheduler().run(()=>ji("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,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(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let s={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(s.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(s)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),ct.registerEndTiming("render (resize)"),jt&&Ad(this.window)?zy(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof ph)ct.registerEndTiming("render (resize)"),H.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=B("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(s=>{n.epage=s,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let s;switch(e.where){case"next":s=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":s=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":s=this.opfView.lastPage;break;case"first":s=this.opfView.firstPage;break;default:return N(!0)}s&&(i=()=>s.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let s=e.epage;i=()=>this.opfView.navigateToEPage(s,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let s=e.url;i=()=>this.opfView.navigateTo(s,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let s=e.position;i=()=>this.opfView.findPage(s,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=B("moveTo");return i.call(this.opfView).then(s=>{let r;if(s){this.pagePosition=s.position;let o=B("moveTo.showCurrent");r=o.result(),this.showCurrent(s.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else r=N(!0);r.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),s=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!s)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let r=B("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(s&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}r.finish(!0)}),r.result()}}runCommand(e){let t=e.a||"";return ji("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(H.error("No such action:",t),i.finish(!0))},(i,n)=>{H.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=fh(e),i=null,n=this;Uf(()=>{let s=B("commandLoop"),r=Xr().getScheduler();return n.hyperlinkListener=o=>{let a=o,l=a.href.charAt(0)==="#"||n.packageURL.some(h=>a.href.substr(0,h.length)==h);if(l){o.preventDefault();let h={t:"hyperlink",href:a.href,internal:l};r.run(()=>(n.callback(h),N(!0)))}},s.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=B("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(s),s.result()}),n.kick=()=>{let s=i;s&&(i=null,s.schedule(!0))},n.sendCommand=s=>t?!1:(t=fh(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},Md=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(Md||{}),ph=class zd extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,zd.prototype),this.stack=new Error().stack}};function fh(e){return typeof e=="string"?Xo(e):e}var gh=jo;function f0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function mh(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var Dd=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),vh(e.debug),this.adaptViewer_=new p0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=f0(),t&&this.setOptions(t),this.eventTarget=new qo,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},mh(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let s=i||{};function r(h){if(h)return h.map(u=>({url:u.url||null,text:u.text||null}))}let o=r(s.authorStyleSheet),a=r(s.userStyleSheet);n&&Object.assign(this.options,n);let l=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:g0(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},mh(this.options));this.initialized?this.adaptViewer_.sendCommand(l):(this.initialized=!0,this.adaptViewer_.initEmbed(l))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===gh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===gh.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}};function g0(e){function t(n){return typeof n=="number"?n:null}function i(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(e)?e.map(i):e?[i(e)]:null}var Vd=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Vd||{}),m0=Md,w0=_d;ct.forceRegisterEndTiming("load_vivliostyle");var b0=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:s=!0,removeIframe:r=!0}){c(this,"htmlDoc"),c(this,"title"),c(this,"printCallback"),c(this,"errorCallback"),c(this,"hideIframe"),c(this,"removeIframe"),c(this,"iframe"),c(this,"iframeWin"),c(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=s,this.removeIframe=r}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1799
|
+
`),i.toString()}},Sb=class{constructor(e){this.deobfuscator=e,c(this,"familyMap",{})}registerFamily(e,t){let i=e.family,n=this.familyMap[i],r=t.family;if(n){if(n!=r)throw new Error(`E_FONT_FAMILY_INCONSISTENT ${e.family}`)}else this.familyMap[i]=r}filterFontFamily(e){if(e instanceof Ze){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(F(r)),i.push(n)}return new Ze(i)}else{let t=this.familyMap[e.stringValue()];return t?new Ze([F(t),e]):e}}},Cb=class{constructor(e,t,i){this.head=e,this.body=t,c(this,"srcURLMap",{}),c(this,"familyPrefix"),c(this,"familyCounter",0),this.familyPrefix=i||"Fnt_"}getViewFontFamily(e,t){let i=e.family,n=t.familyMap[i];return n||(n=this.familyPrefix+ ++this.familyCounter,t.familyMap[i]=n,n)}initFont(e,t,i){let n=O("initFont"),r=e.src,s={};for(let h of Wa(e.properties))s[h]=e.properties[h];let o=this.getViewFontFamily(e,i);s["font-family"]=F(o);let a=new Dd(s),l=this.head.ownerDocument.createElement("style");return l.textContent=a.makeAtRule(r,t),this.head.appendChild(l),$.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i,r=this.srcURLMap[n];return r?r.piggyback(s=>{let o=s;o.traitsEqual(e)?(t.registerFamily(e,o),$.debug("Found already-loaded font:",i)):$.warn("E_FONT_FACE_INCOMPATIBLE",e.src)}):(r=new or(()=>{let s=O("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?ys(o,"blob").then(l=>{if(!l.responseBlob){s.finish(null);return}a(l.responseBlob).then(h=>{this.initFont(e,h,t).thenFinish(s)})}):this.initFont(e,null,t).thenFinish(s),s.result()},`loadFont ${i}`),this.srcURLMap[n]=r,r.start()),r}findOrLoadFonts(e,t){let i=[];for(let n of e){if(!n.src||!n.family){$.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return ws(i).thenAsync(()=>this.waitFontLoading())}waitFontLoading(){let e=this.head.ownerDocument.fonts,t=0;if(e.forEach(n=>{n.status==="unloaded"&&(t++,n.load().catch(r=>{}))}),t===0)return N(!0);let i=O("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},kb=1,Cs=class{constructor(e,t,i,n,r){this.name=t,this.pseudoName=i,this.classes=n,this.parent=r,c(this,"specified",{}),c(this,"children",[]),c(this,"pageMaster",null),c(this,"index",0),c(this,"key"),c(this,"_scope"),this._scope=e,this.key=`p${kb++}`,r&&(this.index=r.children.length,r.children.push(this))}get scope(){return this._scope}createInstance(e){throw new Error("E_UNEXPECTED_CALL")}clone(e){throw new Error("E_UNEXPECTED_CALL")}copySpecified(e){let t=this.specified,i=e.specified;for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}cloneChildren(e){for(let t=0;t<this.children.length;t++)this.children[t].clone({parent:e})}},Eb=class extends Cs{constructor(e){super(e,null,null,[],null),this.specified.width=new _(rr,0),this.specified.height=new _(sr,0)}},mh=class extends io{constructor(e,t){super(e,n),this.pageMaster=t;let i=this;function n(r,s){let o=r.match(/^([^.]+)\.([^.]+)$/);if(o){let a=i.pageMaster.keyMap[o[1]];if(a){let l=this.lookupInstance(a);if(l)return s?l.resolveFunc(o[2]):l.resolveName(o[2])}}return null}}},Vd=class Hd extends Cs{constructor(t,i,n,r,s,o,a){super(t,i,n,r,s),this.condition=o,this.specificity=a,c(this,"keyMap",{}),t instanceof mh||(this._scope=new mh(t,this)),this.pageMaster=this,this.specified.width=new _(rr,0),this.specified.height=new _(sr,0),this.specified["wrap-flow"]=new _(b.auto,0),this.specified.position=new _(b.relative,0),this.specified.overflow=new _(b.visible,0)}createInstance(t){return new ja(t,this)}clone(t){let i=new Hd(this.scope,this.name,t.pseudoName||this.pseudoName,this.classes,this.parent,this.condition,this.specificity);return this.copySpecified(i),this.cloneChildren(i),i}resetScope(){this.scope.pageMaster=this}},Ud=class $d extends Cs{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key),this.specified["wrap-flow"]=new _(b.auto,0)}createInstance(t){return new Ib(t,this)}clone(t){let i=new $d(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},dr=class Wd extends Cs{constructor(t,i,n,r,s){super(t,i,n,r,s),this.pageMaster=s.pageMaster,i&&(this.pageMaster.keyMap[i]=this.key)}createInstance(t){return new dn(t,this)}clone(t){let i=new Wd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Nb(e,t,i){return!t||K(t)?new We(e,i):t.toExpr(e,e.zero)}function fe(e,t,i){return!t||t===b.auto||K(t)?null:t.toExpr(e,i)}function Pb(e,t,i){return!t||t===b.normal||K(t)?null:t.toExpr(e,i)}function ft(e,t,i){return!t||t===b.auto||K(t)?e.zero:t.toExpr(e,i)}function wh(e,t,i){return!t||K(t)?e.zero:t===b.auto?null:t.toExpr(e,i)}function _t(e,t,i,n){return!t||i===b.none||K(t)?e.zero:t.toExpr(e,n)}function Gd(e,t,i){return!t||K(t)?i:t===b._true?e._true:t===b._false?e._false:t.toExpr(e,e.zero)}var ks=class{constructor(e,t){this.parentInstance=e,this.pageBox=t,c(this,"cascaded",{}),c(this,"style",{}),c(this,"autoWidth",null),c(this,"autoHeight",null),c(this,"children",[]),c(this,"isAutoWidth",!1),c(this,"isAutoHeight",!1),c(this,"isTopDependentOnAutoHeight",!1),c(this,"isRightDependentOnAutoWidth",!1),c(this,"calculatedWidth",0),c(this,"calculatedHeight",0),c(this,"pageMasterInstance",null),c(this,"namedValues",{}),c(this,"namedFuncs",{}),c(this,"vertical",!1),c(this,"rtl",!1),c(this,"suppressEmptyBoxGeneration",!1),c(this,"borderBoxSizing",!1),e&&e.children.push(this)}reset(){this.calculatedWidth=0,this.calculatedHeight=0}addNamedValues(e,t){let i=this.resolveName(e),n=this.resolveName(t);if(!i||!n)throw new Error("E_INTERNAL");return Y(this.pageBox.scope,i,n)}resolveName(e){let t=this.namedValues[e];if(t)return t;let i=this.style[e];switch(i&&(t=i.toExpr(this.pageBox.scope,this.pageBox.scope.zero)),e){case"margin-left-edge":t=this.resolveName("left");break;case"margin-top-edge":t=this.resolveName("top");break;case"margin-right-edge":t=this.addNamedValues("border-right-edge","margin-right");break;case"margin-bottom-edge":t=this.addNamedValues("border-bottom-edge","margin-bottom");break;case"border-left-edge":t=this.addNamedValues("margin-left-edge","margin-left");break;case"border-top-edge":t=this.addNamedValues("margin-top-edge","margin-top");break;case"border-right-edge":t=this.addNamedValues("padding-right-edge","border-right-width");break;case"border-bottom-edge":t=this.addNamedValues("padding-bottom-edge","border-bottom-width");break;case"padding-left-edge":t=this.addNamedValues("border-left-edge","border-left-width");break;case"padding-top-edge":t=this.addNamedValues("border-top-edge","border-top-width");break;case"padding-right-edge":t=this.addNamedValues("right-edge","padding-right");break;case"padding-bottom-edge":t=this.addNamedValues("bottom-edge","padding-bottom");break;case"left-edge":t=this.addNamedValues("padding-left-edge","padding-left");break;case"top-edge":t=this.addNamedValues("padding-top-edge","padding-top");break;case"right-edge":t=this.addNamedValues("left-edge","width");break;case"bottom-edge":t=this.addNamedValues("top-edge","height");break}if(!t){let n;if(e=="extent")n=this.vertical?"width":"height";else if(e=="measure")n=this.vertical?"height":"width";else{let r=this.vertical?Tc:Ic;n=e;for(let s in r)n=n.replace(s,r[s])}n!=e&&(t=this.resolveName(n))}return t&&(this.namedValues[e]=t),t}resolveFunc(e){let t=this.namedFuncs[e];if(t)return t;switch(e){case"columns":{let i=this.pageBox.scope,n=new gu(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=pe(i,Pr(i,new On(i,"min",[n,r]),Y(i,s,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=Gd(e,t.enabled,e._true),n=fe(e,t.page,e.zero);if(n){let o=new De(e,"page-number");i=Et(e,i,new fa(e,n,o))}let r=fe(e,t["min-page-width"],e.zero);r&&(i=Et(e,i,new ro(e,new De(e,"page-width"),r)));let s=fe(e,t["min-page-height"],e.zero);s&&(i=Et(e,i,new ro(e,new De(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new U(i)}boxSpecificEnabled(e){return e}initHorizontal(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=fe(e,t.left,i),r=fe(e,t["margin-left"],i),s=_t(e,t["border-left-width"],t["border-left-style"],i),o=ft(e,t["padding-left"],i),a=fe(e,t.width,i),l=fe(e,t["max-width"],i),h=ft(e,t["padding-right"],i),u=_t(e,t["border-right-width"],t["border-right-style"],i),d=fe(e,t["margin-right"],i),p=fe(e,t.right,i),f=Y(e,s,o),m=Y(e,s,h);if(n&&p&&a){let v=pe(e,i,Y(e,a,Y(e,Y(e,n,f),m)));r?d?p=pe(e,v,d):d=pe(e,v,Y(e,p,r)):(v=pe(e,v,p),d?r=pe(e,v,d):(r=Pr(e,v,new We(e,.5)),d=r))}else{r||(r=e.zero),d||(d=e.zero),!n&&!p&&!a&&(n=e.zero),!n&&!a?(a=this.autoWidth,this.isAutoWidth=!0):!n&&!p?n=e.zero:!a&&!p&&(a=this.autoWidth,this.isAutoWidth=!0);let v=pe(e,i,Y(e,Y(e,r,f),Y(e,d,m)));this.isAutoWidth&&(l||(l=pe(e,v,n||p)),!this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(a=l,this.isAutoWidth=!1)),n?a?p||(p=pe(e,v,Y(e,n,a))):a=pe(e,v,Y(e,n,p)):n=pe(e,v,Y(e,p,a))}let g=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=ft(e,g,i);t.left=new U(n),t["margin-left"]=new U(r),t["border-left-width"]=new U(s),t["padding-left"]=new U(o),t.width=new U(a),t["max-width"]=new U(l||a),t["padding-right"]=new U(h),t["border-right-width"]=new U(u),t["margin-right"]=new U(d),t.right=new U(p),t["snap-width"]=new U(w)}initVertical(){let e=this.pageBox.scope,t=this.style,i=this.parentInstance?this.parentInstance.style.width.toExpr(e,null):null,n=this.parentInstance?this.parentInstance.style.height.toExpr(e,null):null,r=fe(e,t.top,n),s=fe(e,t["margin-top"],i),o=_t(e,t["border-top-width"],t["border-top-style"],i),a=ft(e,t["padding-top"],i),l=fe(e,t.height,n),h=fe(e,t["max-height"],n),u=ft(e,t["padding-bottom"],i),d=_t(e,t["border-bottom-width"],t["border-bottom-style"],i),p=fe(e,t["margin-bottom"],i),f=fe(e,t.bottom,n),m=Y(e,o,a),g=Y(e,d,u);if(r&&f&&l){let y=pe(e,n,Y(e,l,Y(e,Y(e,r,m),g)));s?p?f=pe(e,y,s):p=pe(e,y,Y(e,f,s)):(y=pe(e,y,f),p?s=pe(e,y,p):(s=Pr(e,y,new We(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!l&&(r=e.zero),!r&&!l?(l=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!l&&!f&&(l=this.autoHeight,this.isAutoHeight=!0);let y=pe(e,n,Y(e,Y(e,s,m),Y(e,p,g)));this.isAutoHeight&&(h||(h=pe(e,y,r||f)),this.vertical&&(fe(e,t["column-width"],null)||fe(e,t["column-count"],null))&&(l=h,this.isAutoHeight=!1)),r?l?f||(f=pe(e,y,Y(e,r,l))):l=pe(e,y,Y(e,f,r)):r=pe(e,y,Y(e,f,l))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),v=ft(e,w,i);t.top=new U(r),t["margin-top"]=new U(s),t["border-top-width"]=new U(o),t["padding-top"]=new U(a),t.height=new U(l),t["max-height"]=new U(h||l),t["padding-bottom"]=new U(u),t["border-bottom-width"]=new U(d),t["margin-bottom"]=new U(p),t.bottom=new U(f),t["snap-height"]=new U(v)}initColumns(){let e=this.pageBox.scope,t=this.style,i=fe(e,t[this.vertical?"height":"width"],null),n=fe(e,t["column-width"],i),r=fe(e,t["column-count"],null),s=Pb(e,t["column-gap"],null);s||(s=new nr(e,1,"em")),n&&!r&&(r=new On(e,"floor",[so(e,Y(e,i,s),Y(e,n,s))]),r=new On(e,"max",[e.one,r])),r||(r=e.one),n=pe(e,so(e,Y(e,i,s),r),s),t["column-width"]=new U(n),t["column-count"]=new U(r),t["column-gap"]=new U(s)}depends(e,t,i){return this.style[e].toExpr(this.pageBox.scope,null).depend(t,i)}init(e){var t;e.registerInstance(this.pageBox.key,this);let i=this.pageBox.scope,n=this.style,r=this.parentInstance?this.parentInstance.getActiveRegions(e):null,s=qc(this.cascaded,e,r,!1,null);this.vertical=jc(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Xc(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===b.border_box;let o=!!(e instanceof Za&&e.currentLayoutPosition&&new De(i,"left-page").evaluate(e));Kc(s,n,this.vertical,this.rtl,o,(a,l)=>l.value),this.autoWidth=new ze(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new ze(i,()=>this.calculatedHeight,"autoHeight"),this.initHorizontal(),this.initVertical(),this.initColumns(),this.initEnabled()}getProp(e,t){var i,n;let r=this.style[t];return!r&&zn(t)&&this.pageMasterInstance instanceof sn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new I(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=rs(e,r,t)),r}getPropAsNumber(e,t){var i,n;let r=this.style[t];if(r){let s=/\b(height|top|bottom)\b/.test(t)?(i=e.pageAreaHeight)!=null?i:e.pageHeight():(n=e.pageAreaWidth)!=null?n:e.pageWidth();r=rs(e,r,t,s)}return et(r,e)}getSpecial(e,t){let i=Fc(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==X&&n.push(s)}if(n.length)return n}return null}getActiveRegions(e){let t=this.getSpecial(e,"region-id");if(t){let i=[];for(let n=0;n<t.length;n++)i[n]=t[n].toString();return i}return null}propagateProperty(e,t,i,n){this.propagatePropertyToElement(e,t.element,i,n)}propagatePropertyToElement(e,t,i,n){let r=this.getProp(e,i);r&&(r.isNumeric()&&ru(r.unit)&&(r=Su(r,e)),i==="font-family"&&(r=n.filterFontFamily(r)),(i.startsWith("background")||i==="z-index")&&t.parentElement.hasAttribute("data-vivliostyle-bleed-box")&&(t=t.parentElement),T(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new Sa(t.element,i,r))}assignLeftPosition(e,t){let i=this.getPropAsNumber(e,"left"),n=this.getPropAsNumber(e,"margin-left"),r=this.getPropAsNumber(e,"padding-left"),s=this.getPropAsNumber(e,"border-left-width"),o=this.getPropAsNumber(e,"width");t.setHorizontalPosition(i,o),T(t.element,"margin-left",`${n}px`),T(t.element,"padding-left",`${r}px`),T(t.element,"border-left-width",`${s}px`),t.marginLeft=n,t.borderLeft=s,t.paddingLeft=r}assignRightPosition(e,t){let i=this.getPropAsNumber(e,"right"),n=this.getPropAsNumber(e,"snap-height"),r=this.getPropAsNumber(e,"margin-right"),s=this.getPropAsNumber(e,"padding-right"),o=this.getPropAsNumber(e,"border-right-width");if(T(t.element,"margin-right",`${r}px`),T(t.element,"padding-right",`${s}px`),T(t.element,"border-right-width",`${o}px`),t.marginRight=r,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),l=a-Math.floor(a/n)*n;l>0&&(t.snapOffsetX=n-l,s+=t.snapOffsetX)}t.paddingRight=s,t.snapWidth=n}assignTopPosition(e,t){let i=this.getPropAsNumber(e,"snap-height"),n=this.getPropAsNumber(e,"top"),r=this.getPropAsNumber(e,"margin-top"),s=this.getPropAsNumber(e,"padding-top"),o=this.getPropAsNumber(e,"border-top-width");if(t.top=n,t.marginTop=r,t.borderTop=o,t.snapHeight=i,!this.vertical&&i>0){let a=n+t.getInsetTop(),l=a-Math.floor(a/i)*i;l>0&&(t.snapOffsetY=i-l,s+=t.snapOffsetY)}t.paddingTop=s,T(t.element,"top",`${n}px`),T(t.element,"margin-top",`${r}px`),T(t.element,"padding-top",`${s}px`),T(t.element,"border-top-width",`${o}px`)}assignBottomPosition(e,t){let i=this.getPropAsNumber(e,"margin-bottom"),n=this.getPropAsNumber(e,"padding-bottom"),r=this.getPropAsNumber(e,"border-bottom-width"),s=this.getPropAsNumber(e,"height")-t.snapOffsetY;T(t.element,"height",`${s}px`),T(t.element,"margin-bottom",`${i}px`),T(t.element,"padding-bottom",`${n}px`),T(t.element,"border-bottom-width",`${r}px`),t.height=s-t.snapOffsetY,t.marginBottom=i,t.borderBottom=r,t.paddingBottom=n}assignBeforePosition(e,t){this.vertical?this.assignRightPosition(e,t):this.assignTopPosition(e,t)}assignAfterPosition(e,t){this.vertical?this.assignLeftPosition(e,t):this.assignBottomPosition(e,t)}assignStartEndPosition(e,t){this.vertical?(this.assignTopPosition(e,t),this.assignBottomPosition(e,t)):(this.assignRightPosition(e,t),this.assignLeftPosition(e,t))}sizeWithMaxHeight(e,t){T(t.element,"border-top-width","0px");let i=this.getPropAsNumber(e,"max-height");this.isTopDependentOnAutoHeight?t.setVerticalPosition(0,i):(this.assignTopPosition(e,t),i-=t.snapOffsetY,t.height=i,T(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){T(t.element,"border-left-width","0px");let i=this.getPropAsNumber(e,"max-width");if(this.isRightDependentOnAutoWidth)t.setHorizontalPosition(0,i);else{this.assignRightPosition(e,t),i-=t.snapOffsetX,t.width=i;let n=this.getPropAsNumber(e,"right");T(t.element,"right",`${n}px`),T(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&T(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&T(t.element,"direction",this.rtl?"rtl":"ltr"),(this.vertical?this.isAutoWidth:this.isAutoHeight)?this.vertical?this.sizeWithMaxWidth(e,t):this.sizeWithMaxHeight(e,t):(this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),(this.vertical?this.isAutoHeight:this.isAutoWidth)?this.vertical?this.sizeWithMaxHeight(e,t):this.sizeWithMaxWidth(e,t):this.assignStartEndPosition(e,t);for(let s=0;s<yh.length;s++)this.propagateProperty(e,t,yh[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<vh.length;r++)this.propagateProperty(e,t,vh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;T(r,"text-overflow","inherit"),T(r,"overflow","inherit")}}transferSingleUriContentProps(e,t,i){let n=()=>{var s,o;let a=(o=(s=this.cascaded.width)!=null?s:this.cascaded[this.vertical?"block-size":"inline-size"])==null?void 0:o.value;return!!a&&a!==b.auto&&!K(a)},r=()=>{var s,o;let a=(o=(s=this.cascaded.height)!=null?s:this.cascaded[this.vertical?"inline-size":"block-size"])==null?void 0:o.value;return!!a&&a!==b.auto&&!K(a)};for(let s=0;s<xh.length;s++){let o=xh[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;T(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let a=(this.vertical||!n)&&this.isAutoHeight,l=(!this.vertical||!n)&&this.isAutoWidth,h=null;if(l||a){l&&T(t.element,"width","auto"),a&&T(t.element,"height","auto");let u=n&&Sc(n);u&&Ea(n),h=s.getElementClientRect(n?n.element:t.element),u&&ka(n),l&&(this.calculatedWidth=Math.ceil(h.right-h.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),a&&(this.calculatedHeight=h.bottom-h.top-t.paddingTop-t.borderTop-t.paddingBottom-t.borderBottom,this.vertical||(this.calculatedHeight+=t.snapOffsetY))}if((this.vertical?this.isAutoHeight:this.isAutoWidth)&&this.assignStartEndPosition(e,t),(this.vertical?this.isAutoWidth:this.isAutoHeight)&&((this.vertical?this.isRightDependentOnAutoWidth:this.isTopDependentOnAutoHeight)&&this.assignBeforePosition(e,t),this.assignAfterPosition(e,t)),r>1){let u=this.getPropAsNumber(e,"column-rule-width"),d=this.getProp(e,"column-rule-style"),p=this.getProp(e,"column-rule-color");if(u>0&&d&&d!=b.none&&p!=b.transparent){let f=this.getPropAsNumber(e,"column-gap"),m=this.vertical?t.height:t.width,g=this.vertical?"border-top":"border-left";for(let w=1;w<r;w++){let v=this.vertical?(m+f)*w/r-f/2+t.paddingTop-u/2:(m+f)*w/r-f/2+t.paddingLeft-u/2,y=this.vertical?t.width+t.paddingLeft+t.paddingRight:t.height+t.paddingTop+t.paddingBottom,C=t.element.ownerDocument.createElement("div");T(C,"position","absolute"),T(C,this.vertical?"left":"top","0px"),T(C,this.vertical?"top":"left",`${v}px`),T(C,this.vertical?"height":"width","0px"),T(C,this.vertical?"width":"height",`${y}px`),T(C,g,`${u}px ${d.toString()}${p?` ${p.toString()}`:""}`),t.element.insertBefore(C,t.element.firstChild)}}}for(let u=0;u<bh.length;u++)this.propagateProperty(e,t,bh[u],o);for(let u=0;u<Sh.length;u++)this.propagateDelayedProperty(e,t,Sh[u],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof sn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Ei(s)&&Pi(i,s,Re(n,s));if(this.pageBox.pseudoName==Ga)for(let s in t)(s.match(/^background-/)||s=="writing-mode")&&(i[s]=t[s]);if(this.pageBox.pseudoName=="layout-host")for(let s in t)!s.match(/^background-/)&&s!="writing-mode"&&(i[s]=t[s]);e.pushRule(this.pageBox.classes,null,i);let r=i.content;r&&(i.content=r.filterValue(new Lo(e,null,e.counterResolver))),this.init(e.context);for(let s of this.pageBox.children)s.createInstance(this).applyCascadeAndInit(e,t);e.popRule()}resolveAutoSizing(e){this.isAutoWidth&&(this.isRightDependentOnAutoWidth=this.depends("right",this.autoWidth,e)||this.depends("margin-right",this.autoWidth,e)||this.depends("border-right-width",this.autoWidth,e)||this.depends("padding-right",this.autoWidth,e)),this.isAutoHeight&&(this.isTopDependentOnAutoHeight=this.depends("top",this.autoHeight,e)||this.depends("margin-top",this.autoHeight,e)||this.depends("border-top-width",this.autoHeight,e)||this.depends("padding-top",this.autoHeight,e));for(let t of this.children)t.resolveAutoSizing(e)}},yh=["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"],bh=["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"],vh=["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"],xh=["width","height","image-resolution","object-fit","object-position"],Sh=["transform","transform-origin"],Ga="background-host",Tb=class extends ks{constructor(e){super(null,e)}applyCascadeAndInit(e,t){super.applyCascadeAndInit(e,t),this.children.sort((i,n)=>n.pageBox.specificity-i.pageBox.specificity||i.pageBox.index-n.pageBox.index)}},ja=class extends ks{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=Et(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Ib=class extends ks{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},dn=class extends ks{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof le&&(n=[t]),t instanceof Ze&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof le){let o=to(n[s].name,"enabled"),a=new De(r,o);i&&(a=new si(r,a)),e=Et(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=Gd(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Nb(t,i["flow-from"],"body"),s=new On(t,"has-content",[r]);e=Et(t,e,s)}if(e=this.processPartitionList(e,i["required-partitions"],!1),e=this.processPartitionList(e,i["conflicting-partitions"],!0),n){let r=this.pageMasterInstance.style.enabled,s=r?r.toExpr(t,null):t._true;s=Et(t,s,e),this.pageMasterInstance.style.enabled=new U(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof Kd||(T(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},Xa=class extends ar{constructor(e,t,i,n){super(e,t,!1),this.target=i,this.validatorSet=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}simpleProperty(e,t,i){this.target.specified[e]=new _(t,i?Yu:Ku)}},jd=class extends Xa{constructor(e,t,i,n){super(e,t,i,n)}},Ab=class Xd extends Xa{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new _(bl,0),n.specified.height=new _(bl,0)}startPartitionRule(t,i,n){let r=new dr(this.scope,t,i,n,this.target),s=new jd(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new Ud(this.scope,t,i,n,this.target),s=new Xd(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},Rb=class extends Xa{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new dr(this.scope,e,t,i,this.target),r=new jd(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new Ud(this.scope,e,t,i,this.target),r=new Ab(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function qd(e){var t,i;let n=(t=e["writing-mode"])==null?void 0:t.value,r=(i=e.direction)==null?void 0:i.value;return n===b.vertical_lr||n!==b.vertical_rl&&r!==b.rtl?"ltr":"rtl"}var Fb={a10:{width:new I(26,"mm"),height:new I(37,"mm")},a9:{width:new I(37,"mm"),height:new I(52,"mm")},a8:{width:new I(52,"mm"),height:new I(74,"mm")},a7:{width:new I(74,"mm"),height:new I(105,"mm")},a6:{width:new I(105,"mm"),height:new I(148,"mm")},a5:{width:new I(148,"mm"),height:new I(210,"mm")},a4:{width:new I(210,"mm"),height:new I(297,"mm")},a3:{width:new I(297,"mm"),height:new I(420,"mm")},a2:{width:new I(420,"mm"),height:new I(594,"mm")},a1:{width:new I(594,"mm"),height:new I(841,"mm")},a0:{width:new I(841,"mm"),height:new I(1189,"mm")},b10:{width:new I(31,"mm"),height:new I(44,"mm")},b9:{width:new I(44,"mm"),height:new I(62,"mm")},b8:{width:new I(62,"mm"),height:new I(88,"mm")},b7:{width:new I(88,"mm"),height:new I(125,"mm")},b6:{width:new I(125,"mm"),height:new I(176,"mm")},b5:{width:new I(176,"mm"),height:new I(250,"mm")},b4:{width:new I(250,"mm"),height:new I(353,"mm")},b3:{width:new I(353,"mm"),height:new I(500,"mm")},b2:{width:new I(500,"mm"),height:new I(707,"mm")},b1:{width:new I(707,"mm"),height:new I(1e3,"mm")},b0:{width:new I(1e3,"mm"),height:new I(1414,"mm")},c10:{width:new I(28,"mm"),height:new I(40,"mm")},c9:{width:new I(40,"mm"),height:new I(57,"mm")},c8:{width:new I(57,"mm"),height:new I(81,"mm")},c7:{width:new I(81,"mm"),height:new I(114,"mm")},c6:{width:new I(114,"mm"),height:new I(162,"mm")},c5:{width:new I(162,"mm"),height:new I(229,"mm")},c4:{width:new I(229,"mm"),height:new I(324,"mm")},c3:{width:new I(324,"mm"),height:new I(458,"mm")},c2:{width:new I(458,"mm"),height:new I(648,"mm")},c1:{width:new I(648,"mm"),height:new I(917,"mm")},c0:{width:new I(917,"mm"),height:new I(1297,"mm")},"jis-b10":{width:new I(32,"mm"),height:new I(45,"mm")},"jis-b9":{width:new I(45,"mm"),height:new I(64,"mm")},"jis-b8":{width:new I(64,"mm"),height:new I(91,"mm")},"jis-b7":{width:new I(91,"mm"),height:new I(128,"mm")},"jis-b6":{width:new I(128,"mm"),height:new I(182,"mm")},"jis-b5":{width:new I(182,"mm"),height:new I(257,"mm")},"jis-b4":{width:new I(257,"mm"),height:new I(364,"mm")},"jis-b3":{width:new I(364,"mm"),height:new I(515,"mm")},"jis-b2":{width:new I(515,"mm"),height:new I(728,"mm")},"jis-b1":{width:new I(728,"mm"),height:new I(1030,"mm")},"jis-b0":{width:new I(1030,"mm"),height:new I(1456,"mm")},letter:{width:new I(8.5,"in"),height:new I(11,"in")},legal:{width:new I(8.5,"in"),height:new I(14,"in")},ledger:{width:new I(11,"in"),height:new I(17,"in")}},Lb=new I(.24,"pt"),iv=new I(3,"mm"),Ob=new I(10,"mm"),Bb=new I(13,"mm");function cs(e){let t={width:rr,height:sr,bleed:Ee,bleedOffset:Ee,cropOffset:Ee},i=e.size;if(!(!i||i.value===b.auto)){let h=i.value,u,d;if(h.isSpaceList()?(u=h.values[0],d=h.values[1]):(u=h,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&Fb[u.name.toLowerCase()];p&&(d&&d===b.landscape?(t.width=p.height,t.height=p.width):(t.width=p.width,t.height=p.height))}}let n=e.marks,r=e.bleed,s=n&&!K(n.value)?n.value:b.none,o=r&&!K(r.value)?r.value:b.auto;if(o===b.auto){if(s!==b.none){let h=!1;s.isSpaceList()?h=s.values.some(u=>u===b.crop):h=s===b.crop,h&&(t.bleed=new I(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],l=a&&!K(a.value)?a.value:b.auto;return l===b.auto?s!==b.none&&(t.bleedOffset=Bb):l.isNumeric()&&(t.cropOffset=l),t}function Ch(e,t){let i={},n=Math.max(0,e.bleed.num)*t.queryUnitSize(e.bleed.unit,!1),r=!e.cropOffset.num&&e.bleedOffset.num?e.bleedOffset.num*t.queryUnitSize(e.bleedOffset.unit,!1):Math.max(0,e.cropOffset.num*t.queryUnitSize(e.cropOffset.unit,!1)-n),s=n+r,o=e.width;o===rr?t.pref.defaultPaperSize?i.pageWidth=t.pref.defaultPaperSize.width*t.queryUnitSize("px",!1):i.pageWidth=(t.pref.spreadView?Math.floor(t.viewportWidth/2)-t.pref.pageBorder:t.viewportWidth)-s*2:i.pageWidth=o.num*t.queryUnitSize(o.unit,!1);let a=e.height;return a===sr?t.pref.defaultPaperSize?i.pageHeight=t.pref.defaultPaperSize.height*t.queryUnitSize("px",!1):i.pageHeight=t.viewportHeight-s*2:i.pageHeight=a.num*t.queryUnitSize(a.unit,!1),i.bleed=n,i.bleedOffset=r,i.cropOffset=s,i}function Yd(e,t,i){let n=e.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("width",t),n.setAttribute("height",i),n.style.position="absolute",n}function $n(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===b.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var ea=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(ea||{});function Mb(e,t,i,n,r,s,o){let a=r;a<=s+2*At.mm&&(a=s+r/2);let l=Math.max(r,a),h=s+l+i/2,u=Yd(e,h,h),d=[[0,s+r],[r,s+r],[r,s+r-a]],p=d.map(g=>[g[1],g[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(g=>[s+l-g[0],g[1]]),p=p.map(g=>[s+l-g[0],g[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(g=>[g[0],s+l-g[1]]),p=p.map(g=>[g[0],s+l-g[1]]));let f=$n(e,i,n);f.setAttribute("points",d.map(g=>g.join(",")).join(" ")),u.appendChild(f);let m=$n(e,i,n);return m.setAttribute("points",p.map(g=>g.join(",")).join(" ")),u.appendChild(m),t.split(" ").forEach(g=>{u.style[g]=`${o}px`}),u}var Qn=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(Qn||{});function _b(e,t,i,n,r,s){let o=r*2,a,l;t==="top"||t==="bottom"?(a=o,l=r):(a=r,l=o);let h=Yd(e,a,l),u=$n(e,i,n);u.setAttribute("points",`0,${l/2} ${a},${l/2}`),h.appendChild(u);let d=$n(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${l}`),h.appendChild(d);let p=$n(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",l/2),p.setAttribute("r",r/4),h.appendChild(p);let f;switch(t){case"top":f="bottom";break;case"bottom":f="top";break;case"left":f="right";break;case"right":f="left";break}return Object.keys(Qn).forEach(m=>{let g=Qn[m];g===t?h.style[g]=`${s}px`:g!==f&&(h.style[g]="0",h.style[`margin-${g}`]="auto")}),h}function zb(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let g=o.value;g instanceof J?g.values.forEach(w=>{w===b.crop?r=!0:w===b.cross&&(s=!0)}):g===b.crop?r=!0:g===b.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let l=i.container,h=l.ownerDocument,u=et(Lb,n),d=Math.max(0,t.bleedOffset-et(Ob,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:b.auto;r&&Object.keys(ea).forEach(g=>{let w=ea[g],v=Mb(h,w,u,m,p,a,d);l.appendChild(v)}),s&&Object.keys(Qn).forEach(g=>{let w=Qn[g],v=_b(h,w,u,m,p,d);l.appendChild(v)})}var ta=(()=>{let e=["left","right","top","bottom","before","after","start","end","block-start","block-end","inline-start","inline-end","inside","outside"],t={width:!0,height:!0,"block-size":!0,"inline-size":!0,margin:!0,padding:!0,border:!0,outline:!0,"outline-width":!0,"outline-style":!0,"outline-color":!0,"border-radius":!0,"border-top-left-radius":!0,"border-top-right-radius":!0,"border-bottom-right-radius":!0,"border-bottom-left-radius":!0,"border-start-start-radius":!0,"border-start-end-radius":!0,"border-end-start-radius":!0,"border-end-end-radius":!0,"box-shadow":!0,"box-sizing":!0};return e.forEach(i=>{t[`margin-${i}`]=!0,t[`padding-${i}`]=!0,t[`border-${i}-width`]=!0,t[`border-${i}-style`]=!0,t[`border-${i}-color`]=!0}),t})(),qa={"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"}},Db=(()=>{let e=qa;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Ya="vivliostyle-page-rule-master",er="_marginBoxes",Kd=class extends Vd{constructor(e,t,i){super(e,null,Ya,[],t,null,0),c(this,"pageMarginBoxes",{});let n=cs(i),r=new Vb(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[er];t&&Db.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new Ub(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new _(b.relative,0),this.specified.width=new _(t.width,0),this.specified.height=new _(t.height,0);for(let i in e)!ta[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new sn(e,this)}},Vb=class extends dr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new Hb(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new _(b.auto,0),this.specified["z-index"]=new _(new Le(0),0),this.specified.position=new _(b.absolute,0),this.specified.overflow=new _(b.visible,0);for(let t in ta)ta.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new Wb(e,this)}},Hb=class extends dr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new _(F("body"),0)}createInstance(e){return new Zd(e,this)}},Ub=class extends dr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[er][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Pc[i]||r&&r.value===b.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==X&&n.value!==b.inherit&&n.value!==b.unset&&n.value!==b.revert&&(this.specified[i]=n)}}createInstance(e){return new Jd(e,this)}},sn=class extends ja{constructor(e,t){super(e,t),c(this,"pageAreaDimension",null),c(this,"pageMarginBoxInstances",{})}applyCascadeAndInit(e,t){let i=this.cascaded;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n))switch(n){case"writing-mode":case"direction":i[n]=t[n]}super.applyCascadeAndInit(e,t)}initHorizontal(){let e=this.style;e.left=Ee,e["margin-left"]=Ee,e["border-left-width"]=Ee,e["padding-left"]=Ee,e["padding-right"]=Ee,e["border-right-width"]=Ee,e["margin-right"]=Ee,e.right=Ee}initVertical(){let e=this.style;e.top=Ee,e["margin-top"]=Ee,e["border-top-width"]=Ee,e["padding-top"]=Ee,e["padding-bottom"]=Ee,e["border-bottom-width"]=Ee,e["margin-bottom"]=Ee,e.bottom=Ee}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new U(e.borderBoxWidth),t.height=new U(e.borderBoxHeight),t["padding-left"]=new U(e.marginLeft),t["padding-right"]=new U(e.marginRight),t["padding-top"]=new U(e.marginTop),t["padding-bottom"]=new U(e.marginBottom)}adjustPageLayout(e,t,i){let n=t.marginBoxes,r={start:this.pageAreaDimension.marginLeft,end:this.pageAreaDimension.marginRight,extent:this.pageAreaDimension.borderBoxWidth},s={start:this.pageAreaDimension.marginTop,end:this.pageAreaDimension.marginBottom,extent:this.pageAreaDimension.borderBoxHeight};this.sizeMarginBoxesAlongVariableDimension(n.top,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.bottom,!0,r,e,i),this.sizeMarginBoxesAlongVariableDimension(n.left,!1,s,e,i),this.sizeMarginBoxesAlongVariableDimension(n.right,!1,s,e,i)}sizeMarginBoxesAlongVariableDimension(e,t,i,n,r){let s="start",o="center",a="end",l=this.pageBox.scope,h={},u={},d={};for(let C in e){let E=qa[C];if(E){let A=e[C],H=this.pageMarginBoxInstances[C],V=new Gr(A,H.style,t,l,r);h[E.positionAlongVariableDimension]=A,u[E.positionAlongVariableDimension]=H,d[E.positionAlongVariableDimension]=V}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,g={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"max-width":"max-height"],i.extent);if(A){let H=A.evaluate(n);if(f[E]>H){let V=d[E]=new kh(h[E],u[E].style,t,l,r,H);g[E]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),m=!1,[s,o,a].forEach(C=>{var E;f[C]=(E=g[C])!=null?E:f[C]}));let w={};Object.keys(h).forEach(C=>{let E=C,A=fe(l,u[E].style[t?"min-width":"min-height"],i.extent);if(A){let H=A.evaluate(n);if(f[E]<H){let V=d[E]=new kh(h[E],u[E].style,t,l,r,H);w[E]=V.getOuterSize(),m=!0}}}),m&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[s,o,a].forEach(C=>{f[C]=w[C]||f[C]}));let v=p.start+p.extent,y=p.start+(p.start+p.extent);[s,o,a].forEach(C=>{let E=f[C];if(E!=null){let A=h[C],H=0;switch(C){case s:H=t?A.left:A.top;break;case o:H=(y-E)/2;break;case a:H=v-E;break}t?A.setHorizontalPosition(H,E-A.getInsetLeft()-A.getInsetRight()):A.setVerticalPosition(H,E-A.getInsetTop()-A.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],l=new $b(a),h=this.distributeAutoMarginBoxSizes(r,l,t);h.xSize!=null&&(o.center=h.xSize);let u=(i=h.xSize)!=null?i:r.getOuterSize(),d=Math.max((t-u)/2,0);n&&(o.start=n.hasAutoSize()?d:n.getOuterSize()),s&&(o.end=s.hasAutoSize()?d:s.getOuterSize())}else{let a=this.distributeAutoMarginBoxSizes(n,s,t);a.xSize!=null&&(o.start=a.xSize),a.ySize!=null&&(o.end=a.ySize)}return o}distributeAutoMarginBoxSizes(e,t,i){let n={xSize:null,ySize:null};if(e instanceof Gr&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Gr&&t.minMaxFitContent&&(n.ySize=t.getOuterSize()),e&&t)if(e.hasAutoSize()&&t.hasAutoSize()){let r=e.getOuterMaxContentSize(),s=t.getOuterMaxContentSize();if(r>0&&s>0){let o=r+s;if(o<i)n.xSize=i*r/o;else{let a=e.getOuterMinContentSize(),l=t.getOuterMinContentSize(),h=a+l;h<i?n.xSize=a+(i-h)*(r-a)/(o-h):h>0&&(n.xSize=i*a/h)}n.xSize>0&&(n.ySize=i-n.xSize)}else r>0?n.xSize=i:s>0&&(n.ySize=i)}else e.hasAutoSize()?n.xSize=Math.max(i-t.getOuterSize(),0):t.hasAutoSize()&&(n.ySize=Math.max(i-e.getOuterSize(),0));else e?e.hasAutoSize()&&(n.xSize=i):t&&t.hasAutoSize()&&(n.ySize=i);return n}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-box",!0),super.prepareContainer(e,t,i,n,r)}},Gr=class{constructor(e,t,i,n,r){this.container=e,this.isHorizontal=i,this.clientLayout=r,c(this,"hasAutoSize_"),c(this,"size",null),c(this,"minMaxFitContent",null);let s=t[i?"width":"height"];if(this.hasAutoSize_=!s||s===b.auto||K(s),this.minMaxFitContent=s instanceof le&&(s.name==="min-content"||s.name==="max-content"||s.name==="fit-content")?s.name:null,this.minMaxFitContent){let o=this.getSize();if(this.isHorizontal){let a=o[this.minMaxFitContent==="min-content"?"min-content width":this.minMaxFitContent==="max-content"?"max-content width":"fit-content width"];this.container.setHorizontalPosition(this.container.left,a)}else{let a=o[this.minMaxFitContent==="min-content"?"min-content height":this.minMaxFitContent==="max-content"?"max-content height":"fit-content height"];this.container.setVerticalPosition(this.container.top,a)}}}hasAutoSize(){return this.hasAutoSize_}getSize(){if(!this.size){let e=this.isHorizontal?["max-content width","min-content width","fit-content width"]:["max-content height","min-content height","fit-content height"];this.size=xa(this.clientLayout,this.container.element,e)}return this.size}getOuterMaxContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["max-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["max-content height"]+this.container.getInsetBottom()}getOuterMinContentSize(){let e=this.getSize();return this.isHorizontal?this.container.getInsetLeft()+e["min-content width"]+this.container.getInsetRight():this.container.getInsetTop()+e["min-content height"]+this.container.getInsetBottom()}getOuterSize(){return this.isHorizontal?this.container.getInsetLeft()+this.container.width+this.container.getInsetRight():this.container.getInsetTop()+this.container.height+this.container.getInsetBottom()}},$b=class{constructor(e){this.params=e}hasAutoSize(){return this.params.some(e=>{var t;return(t=e?.hasAutoSize())!=null?t:!1})}getOuterMaxContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMaxContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterMinContentSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterMinContentSize())!=null?i:0});return Math.max.apply(null,e)*e.length}getOuterSize(){let e=this.params.map(t=>{var i;return(i=t?.getOuterSize())!=null?i:0});return Math.max.apply(null,e)*e.length}},kh=class extends Gr{constructor(e,t,i,n,r,s){super(e,t,i,n,r),c(this,"fixedSize"),this.fixedSize=s}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()}},Wb=class extends dn{constructor(e,t){super(e,t),c(this,"borderBoxWidth",null),c(this,"borderBoxHeight",null),c(this,"contentBoxWidth",null),c(this,"contentBoxHeight",null),c(this,"marginTop",null),c(this,"marginRight",null),c(this,"marginBottom",null),c(this,"marginLeft",null)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^background-/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,t),this.parentInstance.setPageAreaDimension({borderBoxWidth:this.borderBoxWidth,borderBoxHeight:this.borderBoxHeight,marginTop:this.marginTop,marginRight:this.marginRight,marginBottom:this.marginBottom,marginLeft:this.marginLeft})}initHorizontal(){let e=this.resolvePageBoxDimensions({start:"left",end:"right",extent:"width"});this.borderBoxWidth=e.borderBoxExtent,this.contentBoxWidth=e.contentBoxExtent,this.marginLeft=e.marginStart,this.marginRight=e.marginEnd}initVertical(){let e=this.resolvePageBoxDimensions({start:"top",end:"bottom",extent:"height"});this.borderBoxHeight=e.borderBoxExtent,this.contentBoxHeight=e.contentBoxExtent,this.marginTop=e.marginStart,this.marginBottom=e.marginEnd}resolvePageBoxDimensions(e){let t=this.style,i=this.pageBox.pageSize,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=i[o].toExpr(n,null),l=fe(n,t[o],a),h=fe(n,t[`margin-${r}`],a),u=fe(n,t[`margin-${s}`],a),d=ft(n,t[`padding-${r}`],a),p=ft(n,t[`padding-${s}`],a),f=_t(n,t[`border-${r}-width`],t[`border-${r}-style`],a),m=_t(n,t[`border-${s}-width`],t[`border-${s}-style`],a),g=Y(n,Y(n,f,d),Y(n,m,p)),w,v,y;return l?(this.borderBoxSizing?(v=l,y=pe(n,v,g)):(y=l,v=Y(n,y,g)),w=pe(n,a,v),!h&&!u?(h=Pr(n,w,new We(n,.5)),u=h):h?u=pe(n,w,h):h=pe(n,w,u)):(h||(h=n.zero),u||(u=n.zero),w=Y(n,h,u),v=pe(n,a,w),y=pe(n,v,g),l=this.borderBoxSizing?v:y),t[r]=new U(h),t[s]=new U(u),t[`margin-${r}`]=Ee,t[`margin-${s}`]=Ee,t[`border-${r}-width`]=new U(f),t[`border-${s}-width`]=new U(m),t[`padding-${r}`]=new U(d),t[`padding-${s}`]=new U(p),t[o]=new U(l),t[`max-${o}`]=new U(l),{borderBoxExtent:v,contentBoxExtent:y,marginStart:h,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},Zd=class extends dn{constructor(e,t){super(e,t)}applyCascadeAndInit(e,t){for(let i in t)i.match(/^column.*$/)&&(this.cascaded[i]=t[i]);super.applyCascadeAndInit(e,{})}initHorizontal(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.left=t["padding-left"],e.width=new U(this.parentInstance.contentBoxWidth),e["margin-left"]=new U(new ji(i,t.left.toExpr(i,null))),e["margin-right"]=new U(new ji(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=b.solid,e["border-right-style"]=b.solid,e["border-left-color"]=b.transparent,e["border-right-color"]=b.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new U(this.parentInstance.contentBoxHeight),e["margin-top"]=new U(new ji(i,t.top.toExpr(i,null))),e["margin-bottom"]=new U(new ji(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=b.solid,e["border-bottom-style"]=b.solid,e["border-top-color"]=b.transparent,e["border-bottom-color"]=b.transparent}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area",!0),i.pageAreaElement=t.element,super.prepareContainer(e,t,i,n,r),e.pageAreaWidth=t.width,e.pageAreaHeight=t.height}},Jd=class extends dn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=qa[i];let n=e;n.pageMarginBoxInstances[i]=this}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-margin-box",this.pageBox.marginBoxName),this.applyVerticalAlign(e,t.element),super.prepareContainer(e,t,i,n,r)}applyVerticalAlign(e,t){T(t,"display","flex"),T(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===F("middle")?n="center":i===F("top")?n="flex-start":i===F("bottom")&&(n="flex-end"),n&&T(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof Qe||r instanceof U&&r.expr instanceof ze&&r.expr.str.startsWith("running-element-")){let s="center";(this.boxInfo.isInTopRow||this.boxInfo.isInBottomRow)&&(this.boxInfo.isInLeftColumn||this.boxInfo.positionAlongVariableDimension==="end"?s=this.vertical||this.rtl?"start":"end":(this.boxInfo.isInRightColumn||this.boxInfo.positionAlongVariableDimension==="start")&&(s=this.vertical||this.rtl?"end":"start")),T(t,"align-items",s)}}positionAlongVariableDimension(e,t){let i=this.style,n=this.pageBox.scope,r=e.start,s=e.end,o=e.extent,a=r==="left",l=a?t.borderBoxWidth:t.borderBoxHeight,h=fe(n,i[o],l),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new U(u);else if(h){let d=ft(n,i[`margin-${r}`],l),p=ft(n,i[`margin-${s}`],l),f=ft(n,i[`padding-${r}`],l),m=ft(n,i[`padding-${s}`],l),g=_t(n,i[`border-${r}-width`],i[`border-${r}-style`],l),w=_t(n,i[`border-${s}-width`],i[`border-${s}-style`],l),v=Y(n,h,Y(n,this.borderBoxSizing?n.zero:Y(n,Y(n,f,m),Y(n,g,w)),Y(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new U(Y(n,u,so(n,pe(n,l,v),new We(n,2))));break;case"end":i[r]=new U(pe(n,Y(n,u,l),v));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,l=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],h=wh(n,i[`margin-${s}`],l),u=wh(n,i[`margin-${o}`],l),d=ft(n,i[`padding-${s}`],l),p=ft(n,i[`padding-${o}`],l),f=_t(n,i[`border-${s}-width`],i[`border-${s}-style`],l),m=_t(n,i[`border-${o}-width`],i[`border-${o}-style`],l),g=fe(n,i[a],l),w=null;function v(y){if(w)return w;w={extent:g?g.evaluate(y):null,marginInside:h?h.evaluate(y):null,marginOutside:u?u.evaluate(y):null};let C=l.evaluate(y),E=0;return r||[f,d,p,m].forEach(A=>{A&&(E+=A.evaluate(y))}),(w.marginInside===null||w.marginOutside===null)&&E+w.extent+w.marginInside+w.marginOutside>C&&(w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)),w.extent!==null&&w.marginInside!==null&&w.marginOutside!==null&&(w.marginOutside=null),w.extent===null?(w.extent=C-E-w.marginInside-w.marginOutside,w.marginInside===null&&(w.marginInside=0),w.marginOutside===null&&(w.marginOutside=0)):typeof w.extent=="number"&&(w.marginInside===null&&typeof w.marginOutside=="number"?w.marginInside=C-E-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=C-E-w.extent-w.marginInside:w.marginInside=w.marginOutside=(C-E-w.extent)/2),w}i[a]=new U(new ze(n,function(){let y=v(this).extent;return y===null?"auto":y},a)),i[`margin-${s}`]=new U(new ze(n,function(){let y=v(this).marginInside;return y===null?"auto":y},`margin-${s}`)),i[`margin-${o}`]=new U(new ze(n,function(){let y=v(this).marginOutside;return y===null?"auto":y},`margin-${o}`)),s==="left"?i.left=new U(Y(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new U(Y(n,t.marginTop,t.borderBoxHeight)))}initHorizontal(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInLeftColumn?this.positionAndSizeAlongFixedDimension({inside:"right",outside:"left",extent:"width"},e):this.boxInfo.isInRightColumn?this.positionAndSizeAlongFixedDimension({inside:"left",outside:"right",extent:"width"},e):this.positionAlongVariableDimension({start:"left",end:"right",extent:"width"},e)}initVertical(){let e=this.parentInstance.pageAreaDimension;this.boxInfo.isInTopRow?this.positionAndSizeAlongFixedDimension({inside:"bottom",outside:"top",extent:"height"},e):this.boxInfo.isInBottomRow?this.positionAndSizeAlongFixedDimension({inside:"top",outside:"bottom",extent:"height"},e):this.positionAlongVariableDimension({start:"top",end:"bottom",extent:"height"},e)}finishContainer(e,t,i,n,r,s,o){super.finishContainer(e,t,i,n,r,s,o);let a=i.marginBoxes,l=this.pageBox.marginBoxName,h=this.boxInfo;!h.isInLeftColumn&&!h.isInRightColumn?h.isInTopRow?a.top[l]=t:h.isInBottomRow&&(a.bottom[l]=t):!h.isInTopRow&&!h.isInBottomRow&&(h.isInLeftColumn?a.left[l]=t:h.isInRightColumn&&(a.right[l]=t));let u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof le&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),m=this.getPropAsNumber(e,"max-width");if(p||f||m){p&&T(t.element,"width",p),f&&T(t.element,"min-width",`${f}px`),m&&T(t.element,"max-width",`${m}px`);let C=this.getProp(e,"margin-left"),E=this.getProp(e,"margin-right");if(h.isInLeftColumn){let A=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);T(t.element,"right",`${A}px`),(C===b.auto||E!==b.auto)&&T(t.element,"margin-left","auto"),E===b.auto&&T(t.element,"margin-right","auto")}else h.isInRightColumn&&(T(t.element,"right","0"),(E===b.auto||C!==b.auto)&&T(t.element,"margin-right","auto"),C===b.auto&&T(t.element,"margin-left","auto"))}let g=this.getProp(e,"height"),w=g instanceof le&&(g.name==="min-content"||g.name==="max-content"||g.name==="fit-content")?g.name:null,v=this.getPropAsNumber(e,"min-height"),y=this.getPropAsNumber(e,"max-height");if(w||v||y){w&&T(t.element,"height",w),v&&T(t.element,"min-height",`${v}px`),y&&T(t.element,"max-height",`${y}px`);let C=this.getProp(e,"margin-top"),E=this.getProp(e,"margin-bottom");if(h.isInTopRow){let A=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);T(t.element,"bottom",`${A}px`),(C===b.auto||E!==b.auto)&&T(t.element,"margin-top","auto"),E===b.auto&&T(t.element,"margin-bottom","auto")}else h.isInBottomRow&&(T(t.element,"bottom","0"),(E===b.auto||C!==b.auto)&&T(t.element,"margin-bottom","auto"),C===b.auto&&T(t.element,"margin-top","auto"))}}},Gb=class{constructor(e,t,i,n,r){this.pageScope=t,this.rootPageBoxInstance=i,this.context=n,this.docElementStyle=r,c(this,"pageMasterCache",{}),c(this,"pageCascadeInstance"),this.pageCascadeInstance=e,this.definePageProgression()}definePageProgression(){let e=this.pageScope,t=this.context,i=t.isVersoFirstPage,n=new De(e,"page-number"),r=new fa(e,new cu(e,n,new We(e,2)),i?e.one:e.zero);e.defineName("recto-page",new si(e,r)),e.defineName("verso-page",r),(t.pageProgression||qd(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new si(e,r))):(e.defineName("left-page",new si(e,r)),e.defineName("right-page",r))}getCascadedPageStyle(e){let t={};return this.pageCascadeInstance.pushRule([],e,t),this.pageCascadeInstance.popRule(),t}getPageRulePageMaster(e,t){let i=e.pageBox;if(Object.keys(t).length===0)return i.resetScope(),e;let n=this.makeCacheKey(t,i),r=this.pageMasterCache[n];return r||(i.pseudoName===Ga?r=this.generatePageRuleMaster(t):r=this.generateCascadedPageMaster(t,i),this.pageMasterCache[n]=r),r.pageBox.resetScope(),r}makeCacheKey(e,t){var i;let n=this.makeCascadeValueObjectKey(e),r=((i=this.context.currentLayoutPosition)==null?void 0:i.page)%2;return`${t.key}^${n}^${r}`}makeCascadeValueObjectKey(e){let t=[];for(let i in e)if(Object.prototype.hasOwnProperty.call(e,i)){let n=e[i],r;n instanceof _?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new Kd(this.pageScope,this.rootPageBoxInstance.pageBox,e).createInstance(this.rootPageBoxInstance);return t.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),t.resolveAutoSizing(this.context),t}generateCascadedPageMaster(e,t){let i=t.clone({pseudoName:Ya}),n=i.specified,r=e.size;if(r&&!K(r.value)){let o=cs(e),a=r.priority;qt(n,"width",new _(o.width,a),this.context),qt(n,"height",new _(o.height,a),this.context)}["counter-reset","counter-increment"].forEach(o=>{n[o]&&(e[o]=n[o])});let s=i.createInstance(this.rootPageBoxInstance);return s.applyCascadeAndInit(this.pageCascadeInstance,this.docElementStyle),s.resolveAutoSizing(this.context),s}},jb=class extends ve{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}},Xb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},qb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},Yb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Kb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Zb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Jb=class extends ve{constructor(e){super(),this.scope=e}apply(e){new De(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Qb=class extends Fi{constructor(e,t,i){super(t,i),this.scope=e,this.a=t,this.b=i}apply(e){let t=e.context,i=t.layoutPositionAtPageStart.page;t.blankPageAtStart&&i--,i&&this.matchANPlusB(i)&&this.chained.apply(e)}getPriority(){return 2}},e0=class extends Fi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){if(e.currentPageType!==this.pageType)return;let t=e.pageTypePageCounts[this.pageType]||0;this.matchANPlusB(t)&&this.chained.apply(e)}getPriority(){return 3}},t0=class extends Oa{constructor(e,t){super(e,t,null,null,null)}apply(e){i0(e.context,e.currentStyle,this.style,this.specificity,e)}};function i0(e,t,i,n,r){ns(e,t,i,n,null,null,null);let s=i[er];if(s){let o=ur(t,er);for(let a in s)if(s.hasOwnProperty(a)){let l=o[a];l||(l={},o[a]=l),ns(e,l,s[a],n,null,null,null)}}}var n0=class extends Yn{constructor(e,t,i,n,r){super(e,t,i?.condition,i,null,n,!1),this.pageProps=r,c(this,"currentPageSelectors",[]),c(this,"currentNamedPageSelector",""),c(this,"currentPseudoPageClassSelectors",[])}startPageRule(){this.startSelectorRule()}tagSelector(e,t){this.currentNamedPageSelector=t,t&&(this.chain.push(new jb(t)),this.specificity+=65536)}pseudoclassSelector(e,t){if(e=e.toLowerCase(),t)switch(e){case"nth":{let i=t[0],n=t[1];if(t.length===3&&typeof t[2]=="string"){let r=t[2];this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n} of ${r})`),this.chain.push(new e0(this.scope,i,n,r)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Qb(this.scope,i,n)),this.specificity+=256}break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}(${t.join("")})`);break}else switch(this.currentPseudoPageClassSelectors.push(`:${e}`),e){case"first":this.chain.push(new Xb(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new qb(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new Yb(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Kb(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Zb(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Jb(this.scope)),this.specificity+=1;break;default:this.reportAndSkip(`E_INVALID_PAGE_SELECTOR :${e}`);break}}finishSelector(){let e;!this.currentNamedPageSelector&&!this.currentPseudoPageClassSelectors.length?e=null:e=[this.currentNamedPageSelector].concat(this.currentPseudoPageClassSelectors.sort()),this.currentPageSelectors.push({selectors:e,specificity:this.specificity}),this.currentNamedPageSelector="",this.currentPseudoPageClassSelectors=[]}nextSelector(){this.finishSelector(),super.nextSelector()}startRuleBody(){this.finishSelector(),super.startRuleBody()}simpleProperty(e,t,i){if((e==="bleed"||e==="marks")&&!this.currentPageSelectors.some(s=>s.selectors===null))return;super.simpleProperty(e,t,i);let n=Re(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{Pi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new _(n.value,n.priority+o.specificity),l=o.selectors?o.selectors.join(""):"",h=r[l];h?qt(h,e,a):(h=r[l]={},Pi(h,e,a),s&&["bleed","marks"].forEach(u=>{s[u]&&Pi(h,u,s[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new t0(this.elementStyle,e)}startPageMarginBoxRule(e){let t=ur(this.elementStyle,er),i=t[e];i||(i={},t[e]=i);let n=new r0(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},r0=class extends ar{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.boxStyle=n}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity(),r=new _(t,n);Pi(this.boxStyle,e,r)}},Yt=!0;function s0(e){Yt=e}var Ti=[];function Eh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Qd(e){let t=Array.from(e.querySelectorAll("body > :not(script):not(link):not(style) ~ script"));return Array.from(e.querySelectorAll("head > script, body > script")).filter(i=>!t.includes(i))}function Ka(e,t,i){if(!Yt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Qd(e.ownerDocument).includes(e))return N(!1);let n=e.textContent,r=e.src,s=e.type==="module",o=r&&r.includes("/MathJax.js");if(o){if(t.document.head.querySelector("script[src*='/MathJax.js']"))return N(!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=(s||r)&&e.async&&!o,l=(s&&!a||r&&e.defer)&&!o,h=!(i!=null&&i.atEnd)&&(i?.forceDefer||l||a);if(ep(t)||(t.onload=null),h)return Ti.some(d=>Eh(d,e))||Ti.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Eh(d,e)&&t.document.head.removeChild(d);let u=t.document.createElement("script");u.textContent=n,r&&(u.src=r),u.async=a,u.defer=l,u.setAttribute("data-vivliostyle-scripting","true");for(let d of e.attributes)["src","async","defer"].includes(d.name)||u.setAttribute(d.name,d.value);if($.debug("script:",r),r){let d=Hi(u);return t.document.head.appendChild(u),ws([d])}else return t.document.head.appendChild(u),N(!0)}function o0(e,t){var i;let n={},r=o=>{var a;let l=(a=o["font-family"])==null?void 0:a.value;if(l)if(l.values)for(let u of l.values)n[u.stringValue()]=!0;else n[l.stringValue()]=!0;let h=o._marginBoxes;if(h)for(let u of Object.values(h))r(u)},s=o=>{if(o instanceof Oa)r(o.style);else if(o instanceof wn||Array.isArray(o))for(let a of Object.values(o))s(a)};for(let o of Object.values(t.cascade.code))for(let a of Object.values(o??{}))s(a);for(let o of e.querySelectorAll("[style]"))(i=o.style)!=null&&i.fontFamily&&(n[o.style.fontFamily]=!0);return Object.keys(n).join(",")}function a0(e,t,i){var n;let r=(n=t.document.querySelector("[data-vivliostyle-textcontent]"))!=null?n:t.document.createElement("div");return r.style.position="fixed",r.style.fontSize="0",r.setAttribute("data-vivliostyle-textcontent","true"),r.setAttribute("aria-hidden","true"),r.style.fontFamily=o0(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function l0(e,t,i){if(!Yt)return N(!1);let n=Qd(e);if(n.length===0)return N(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),s=r?a0(e,t,i):null,o=t.document.fonts,a=t.$,l=!1,h=O("loadScripts");return h.loop(()=>{if(n.length===0)return r?h.sleep(20).thenAsync(()=>{var d,p;return o.status==="loading"||t.document.documentElement.classList.contains("wf-loading")||(d=t.FontJSON)!=null&&d.Font&&(p=t.ret)!=null&&p.readyState&&t.ret.readyState<4?N(!0):N(!1)}):N(!1);let u=n.shift();return Ka(u,t,{inHead:!0,forceDefer:l}).thenAsync(()=>(!l&&t.$!==a&&(Ti.push(u),l=!0),n.length===0&&r&&($.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{s&&s.remove(),h.finish(!0)}),h.result()}function h0(e){if(!Yt)return N(!1);let t=O("loadScripts");return t.loop(()=>Ti.length===0?N(!1):Ka(Ti.shift(),e,{atEnd:!0}).thenReturn(Ti.length>0)).then(()=>{$.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),$.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function ep(e){return Yt?Ti.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var u0=(e,t,i)=>e.replace(/[uU][rR][lL]\(\s*"((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"\r\n])+)"/gm,(n,r)=>`url("${i.transformURL(r,t)}"`).replace(/[uU][rR][lL]\(\s*'((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^'\r\n])+)'/gm,(n,r)=>`url('${i.transformURL(r,t)}'`).replace(/[uU][rR][lL]\(\s*((\\([^0-9a-fA-F]+|[0-9a-fA-F]+\s*)|[^"'\r\n\)\s])+)/gm,(n,r)=>`url(${i.transformURL(r,t)}`),c0={};function d0(e){e.addEventListener("load",()=>{e.contentWindow.navigator.epubReadingSystem={name:"adapt",version:"0.1",layoutStyle:"paginated",hasFeature:function(t,i){switch(t){case"mouse-events":return!0}return!1}}},!1)}var tp=class ia extends ua{constructor(t,i,n,r,s,o,a,l,h,u,d,p,f){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=s,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=l,this.stylerProducer=h,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,c(this,"document"),c(this,"exprContentListener"),c(this,"nodeContext",null),c(this,"viewRoot",null),c(this,"isFootnote",!1),c(this,"sourceNode",null),c(this,"offsetInNode",0),c(this,"viewNode",null),this.document=n.document,this.exprContentListener=r.counterListener.getExprContentListener()}clone(){return new ia(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer)}createPseudoelementShadow(t,i,n,r,s,o,a,l){var h;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return l;let d=[],p=Rr.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let g of Nw){let w;if(g){if(!u[g]||g=="footnote-marker"&&!(i&&this.isFootnote))continue;if(g.match(/^first-/)){let v=r.display;if(!v||v===b.inline)continue;let y=t.firstElementChild;if(y&&$e(y.previousSibling)){let C=s.getStyle(y,!1);if(C){let E=Re(C,"display");if(E!=null&&E.value&&E.value!==b.inline)continue}}}if(g==="before"||g==="after"||g==="marker"){let v=u[g].content;if(!v||!Dt(v.value)||g==="marker"&&(!ki(r.display)||((h=Re(n,"behavior"))==null?void 0:h.value)===F("toc-node")))continue}d.push(g),w=Rr.createElementNS("http://www.w3.org/1999/xhtml","span"),Mo(w,g)}else w=Rr.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(w),g.match(/^first-/)&&(f=w)}if(!d.length)return l;let m=new th(t,n,s,o,this.exprContentListener);return new mo(t,p,null,a,l,xt.ROOTLESS,m)}getPseudoMap(t,i,n,r,s){let o=kt(t,"_pseudos");if(!o)return null;let a={};for(let l in o){let h=a[l]={};Vn(h,o[l],s),Bo(h,s,o[l]),Yc(o[l],i,n,(u,d)=>{Vn(h,d,s),Gc(d,p=>{Vn(h,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=O("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let l=a;if(l){let h=l.getElement(t);if(h){let u=this.stylerProducer.getStylerForDoc(l);s=new mo(n,h,l,r,s,i,u)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let l=O("createShadows"),h=null,u=r.template,d;if(u instanceof Qe||u===b.footnote){let p=u instanceof Qe?u.url:Pe("user-agent.xml#footnote",ni);d=this.createRefShadow(p,xt.ROOTLESS,t,a,h)}else d=N(h);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let g=t.getAttribute("href"),w=null;g?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?g=a.owner.getAttribute("href"):g=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),g&&(g=Pe(g,w.url),f=this.createRefShadow(g,xt.ROOTED,t,a,p))}f==null&&(f=N(p));let m=null;f.then(g=>{if(r.display===b.table_cell){let w=Pe("user-agent.xml#table-cell",ni);m=this.createRefShadow(w,xt.ROOTLESS,t,a,g)}else m=N(g);m.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,s,o,a,w),l.finish(w)})})}),l.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=qc(n,o,this.regionIds,this.isFootnote,this.nodeContext),l=!((s=this.nodeContext)!=null&&s.parent);l&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let h=t;t=jc(a,o,t);let u=!l&&t!==h;i=Xc(a,o,i);let d=(v,y)=>{let C;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(v)&&(C=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(v)&&(C=o.pageAreaWidth));let E=y.evaluate(o,v,C,t);return v=="font-family"&&(E=this.docFaces.filterFontFamily(E)),E},p=!!new De(o.style.pageScope,"left-page").evaluate(o);if(Kc(a,r,t,i,p,d),u){let v=r[t?"height":"width"];(!v||v===b.auto)&&(r[t?"height":"width"]=b.max_content)}if(bo(r.position))return r.position=b.fixed,r.visibility=b.hidden,t;let f=r.position,m=r.float,g=r.display||(this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?b.inline:void 0),w=bc(g,f,m,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(v=>{w[v]&&(r[v]=w[v])}),t}inheritFromSourceParent(t){let i=this.nodeContext.sourceNode,n=[],r=null,s=this.nodeContext.shadowContext,o=-1;for(;i&&i.nodeType==1;){let d=s&&s.root==i;if(!d||s.type==xt.ROOTLESS){let p=(s?s.styler:this.styler).getStyle(i,!1);n.push(p),r=r||Qs(i)}d?(i=s.owner,s=s.parentShadow):(i=i.parentNode,o++)}let a=o===0,l=this.context.queryUnitSize("em",a),h={"font-size":new _(new I(l,"px"),0)};a&&(h["line-height"]=new _(new gt(this.context.pref.lineHeight),0));let u=new Om(h,this.context);for(let d=n.length-1;d>=0;--d){let p=n[d],f=[];for(let w in p)zn(w)&&f.push(w);f.sort(xl);let m,g;for(let w of f){u.setPropName(w);let v=Re(p,w),y=v;if(!K(v.value)){if(w==="font-size"&&d===n.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)y=new _(new I(this.context.rootFontSize,"px"),v.priority);else if(w==="line-height"&&d===n.length-1&&this.context.rootLineHeight&&v.value instanceof I&&(v.value.unit==="lh"||v.value.unit==="rlh"))y=new _(new I(this.context.rootLineHeight,"px"),v.priority);else if(d===0&&v.value instanceof I&&v.value.unit==="lh"){let C=this.getLineHeightUnitSize(w,m,g);C!=null&&(y=new _(new I(v.value.num*C,"px"),v.priority))}else zt(w)||(y=v.filterValue(u));w==="font-size"?m=y.value:w==="line-height"&&(g=y.value),h[w]=y}}}for(let d in t)zn(d)||(h[d]=t[d]);return{lang:r,elementStyle:h}}resolveURL(t){return t=Pe(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=Qs(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Em().filter(n=>t[n]);if(i.length){let n=this.nodeContext.inheritedProps;if(this.nodeContext.parent){n=this.nodeContext.inheritedProps={};for(let r in this.nodeContext.parent.inheritedProps)n[r]=this.nodeContext.parent.inheritedProps[r]}i.forEach(r=>{let s=t[r];if(s){if(K(s))s===b.initial&&(n[r]=void 0);else if(s instanceof Le)n[r]=s.num;else if(s instanceof le)n[r]=s.name;else if(s instanceof I){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*At[o.unit];break;default:n[r]=s}}else n[r]=s;["widows","orphans"].includes(r)||delete t[r]}})}}resolveFormattingContext(t,i,n,r,s,o){let a=Rt("RESOLVE_FORMATTING_CONTEXT");for(let l=0;l<a.length;l++){let h=a[l](t,i,n,r,s,o);if(h){t.formattingContext=h;return}}}createElementView(t,i){var n,r;let s=!0,o=O("createElementView"),a=this.sourceNode,l=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,h=l.getStyle(a,!1);if(!this.nodeContext.shadowContext){let y=this.xmldoc.getElementOffset(a);vs.registerFragmentIndex(y,this.nodeContext.fragmentIndex,0)}let u={};if(!this.nodeContext.parent){let y=this.inheritFromSourceParent(h);h=y.elementStyle,this.nodeContext.lang=y.lang}let d=h.position,p=h.float,f=h["float-reference"],m=p&&!K(p.value)&&p.value!==b.none&&f&&!K(f.value)?rm(f.value.toString()):null;if(this.nodeContext.parent&&(bo(d?.value)||m&&tn(m))){let y=this.inheritFromSourceParent(h);h=y.elementStyle,this.nodeContext.lang=y.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",h,u),m&&tn(m)&&u.display===b.block&&(u.display=b.flow_root),l.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let g=u["flow-into"];if(g&&g.toString()!=this.flowName)return o.finish(!1),o.result();if(Yt&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return Ka(a,this.viewport.window).thenFinish(o),o.result();let w=u.display;if(K(w)&&(w===b.initial||w===b.unset?w=b.inline:w===b.inherit?w=((n=this.nodeContext.parent)==null?void 0:n.display)&&F((r=this.nodeContext.parent)==null?void 0:r.display):w=null),w===b.none)return o.finish(!1),o.result();let v=this.nodeContext.parent==null;return this.nodeContext.flexContainer=w===b.flex,this.createShadows(a,v,h,u,l,this.context,this.nodeContext.shadowContext).then(y=>{this.nodeContext.nodeShadow=y;let C=u.position,E=u.float,A=u.clear,H=this.nodeContext.vertical?b.vertical_rl:b.horizontal_tb,V=this.nodeContext.parent?this.nodeContext.parent.vertical?b.vertical_rl:b.horizontal_tb:H,ie=cm(a),ne=u["column-count"],Xe=u["column-width"],ht=ne&&ne!==b.auto&&!K(ne)||Xe&&Xe!==b.auto&&!K(Xe);this.nodeContext.establishesBFC=pm(w,C,E,u.overflow,H,V,ht||ie),this.nodeContext.containingBlockForAbsolute=fm(C),this.nodeContext.isInsideBFC()&&E!==b.footnote&&!(m&&tn(m))&&(E=null,A=null);let xe=E instanceof J||E===b.left||E===b.right||E===b.top||E===b.bottom||E===b.inline_start||E===b.inline_end||E===b.block_start||E===b.block_end||E===b.snap_block||E===b.snap_inline||E===b.inside||E===b.outside||E===b.footnote;E&&(delete u.float,E===b.footnote&&(this.isFootnote?(xe=!1,u.display=b.block):u.display=b.inline)),A&&(A===b.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(A=F(this.nodeContext.parent.clearSide)),(A===b.left||A===b.right||A===b.top||A===b.bottom||A===b.inline_start||A===b.inline_end||A===b.block_start||A===b.block_end||A===b.inside||A===b.outside||A===b.both||A===b.all||A===b.same||A===b.column||A===b.region||A===b.page)&&(delete u.clear,u.display&&u.display!=b.inline&&(this.nodeContext.clearSide=A.toString())));let x=ki(w)&&!!u["ua-list-item-count"],B=u["break-inside"];(xe||B&&!K(B)&&B!==b.auto)&&this.nodeContext.breakPenalty++,w&&w!==b.inline&&Mt(w)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!xe&&!w||Mt(w)||xc(w),this.nodeContext.display=w?w.toString():"inline",this.nodeContext.floatSide=xe?E.toString():null,this.nodeContext.floatReference=m||Oe.INLINE;let S=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=S&&!K(S)?S:null;let P=this.isInsideNonRootMultiColumn(),k=u["column-span"];if(this.nodeContext.columnSpan=!P&&k&&!K(k)?k:null,!this.nodeContext.inline){let z=u["break-after"];z&&!K(z)&&!(P&&z===b.column)&&(this.nodeContext.breakAfter=z.toString(),po[this.nodeContext.breakAfter]&&(u["break-after"]=b.column));let re=u["break-before"];re&&!K(re)&&!(P&&re===b.column)&&(this.nodeContext.breakBefore=re.toString(),po[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=b.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let se=u.page,be=se&&!K(se)&&se.toString();!be&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||w===b.table_header_group||w===b.table_footer_group)&&(be=this.styler.cascade.currentPageType),!be||be.toLowerCase()==="auto"?be=this.nodeContext.pageType:this.nodeContext.pageType=be,this.styler.cascade.currentPageType!==be&&!(!be&&u.position===b.fixed)&&(this.nodeContext.fragmentIndex===1&&!Xn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),be!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=be)}this.nodeContext.verticalAlign=u["vertical-align"]&&u["vertical-align"].toString()||"baseline",this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let R=u["border-collapse"];if(!R||R===F("separate")){let z=u["border-spacing"],re,se;z&&(z instanceof J?(re=z.values[0],se=z.values[1]):re=se=z,re.isNumeric()&&(this.nodeContext.inlineBorderSpacing=et(re,this.context)),se.isNumeric()&&(this.nodeContext.blockBorderSpacing=et(se,this.context)))}let L=u["footnote-policy"];this.nodeContext.footnotePolicy=L&&!K(L)?L:null;let D=u["x-first-pseudo"];if(D){let z=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new em(z,D.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,h,l,this.context);let W=u["white-space"];if(W){let z=lc(W.toString());z!==null&&(this.nodeContext.whitespace=z)}let q=u["hyphenate-character"];q&&q instanceof j&&(this.nodeContext.hyphenateCharacter=q.str);let Q=u["word-break"],ee=u["line-break"],we=u["overflow-wrap"];(Q===b.break_all||ee===b.anywhere||we===b.break_word||we===b.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,w,C,E,v),this.nodeContext.parent&&this.nodeContext.parent.formattingContext&&(t=this.nodeContext.parent.formattingContext.isFirstTime(this.nodeContext,t)),this.nodeContext.inline||(this.nodeContext.repeatOnBreak=this.processRepeatOnBreak(u),this.findAndProcessRepeatingElements(a,l));let te=!1,ye=null,Ce=[],he=a.namespaceURI,G=a.localName,ce=G;if(he=="http://www.w3.org/1999/xhtml"?(G=="html"||G=="body"||G=="script"||G=="link"||G=="meta"?G="div":G=="vide_"?G="video":G=="audi_"?G="audio":G=="object"&&(te=!!this.customRenderer),a.hasAttribute(za)&&a.hasAttribute("src")&&u.content instanceof Qe&&(G="img")):he=="http://www.idpf.org/2007/ops"?(G="span",he="http://www.w3.org/1999/xhtml"):he=="http://www.pyroxy.com/ns/shadow"?(he="http://www.w3.org/1999/xhtml",G=this.nodeContext.inline?"span":"div"):te=!!this.customRenderer,x)w=Mt(w)?b.inline:b.block,u.display=w,t?G="li":G="div";else if(G=="body"||G=="li")G="div";else if(G=="q")G="span";else if(G=="a"){let z=u["hyperlink-processing"];z&&z.toString()!="normal"&&(G="span")}u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(te=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(te=!0);let de;if(te){let z=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;de=this.customRenderer(a,z,u)}else de=N(null);de.then(z=>{var re,se,be,ut,Qa;if(z)te&&(s=z.getAttribute("data-adapt-process-children")=="true");else if(u.display===b.none){o.finish(!1);return}else z=this.createElement(he,G);G!=ce&&(z.setAttribute("data-vivliostyle-original-tag",ce),(ce==="html"||ce==="body")&&(z.role="presentation")),G=="a"&&z.addEventListener("click",this.page.hrefHandler,!1),ye&&(this.applyPseudoelementStyle(this.nodeContext,"inner",ye),z.appendChild(ye)),z.localName=="iframe"&&z.namespaceURI=="http://www.w3.org/1999/xhtml"&&d0(z);let pr=this.nodeContext.inheritedProps["image-resolution"],Es=[],Ns=u.width,Ps=u.height,fp=a.getAttribute("width"),gp=a.getAttribute("height"),Ts=Ns===b.auto||!Ns&&!fp,Is=Ps===b.auto||!Ps&&!gp,el=a.attributes,mp=el.length,fr=null,tl=null;w===b.table_cell&&((be=(se=(re=this.nodeContext.parent)==null?void 0:re.viewNode)==null?void 0:se.lastElementChild)==null?void 0:be.localName)==="a"&&z.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let qe=0;qe<mp;qe++){let mt=el[qe],ct=mt.namespaceURI,ae=mt.localName,Ve=mt.nodeValue;if(ct){if(ct=="http://www.w3.org/2000/xmlns/")continue;ct=="http://www.w3.org/1999/xlink"&&ae=="href"&&(Ve=this.documentURLTransformer.transformURL(this.resolveURL(Ve),this.xmldoc.url))}else{if(!Yt&&ae.match(/^on/)||ae=="style")continue;if((ae=="id"||ae=="name")&&t){let Ye=this.documentURLTransformer.transformFragment(Ve,this.xmldoc.url);z.setAttribute(ae,Ve),z.setAttribute("data-vivliostyle-id",Ye);let ci=z.ownerDocument.createElement("a");ci.setAttribute(ae,Ye),ci.setAttribute(hn,"1"),ci.style.position="absolute",z.appendChild(ci),this.page.registerElementWithId(z,Ye);continue}if(ae=="src"||ae=="href"||ae=="poster")Ve=this.resolveURL(Ve),ae==="href"&&(Ve=this.documentURLTransformer.transformURL(Ve,this.xmldoc.url));else if(ae=="srcset")Ve=Ve.split(",").map(Ye=>this.resolveURL(Ye.trim())).join(",");else if(ae==="data"&&te&&G==="object"&&z.hasAttribute("data"))continue;if(ae==="poster"&&G==="video"&&he==="http://www.w3.org/1999/xhtml"&&Ts&&Is){let Ye=new Image,ci=Hi(Ye,Ve);Ce.push(ci),Es.push({image:Ye,element:z,fetcher:ci})}}if(he=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(ae)&&(ae=ae.toLowerCase()),this.isSVGUrlAttribute(ae)&&(Ve=u0(Ve,this.xmldoc.url,this.documentURLTransformer)),ct){let Ye=c0[ct];Ye&&(ae=`${Ye}:${ae}`)}if(ae=="src"&&!ct&&(G=="img"||G=="input")&&he=="http://www.w3.org/1999/xhtml")fr=Ve;else if(ae=="alt"&&!ct&&G=="img"&&he=="http://www.w3.org/1999/xhtml")tl=Ve;else if(ae=="href"&&G=="image"&&he=="http://www.w3.org/2000/svg"&&ct=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Hi(z,Ve));else if(ct)z.setAttributeNS(ct,ae,Ve);else try{z.setAttribute(ae,Ve)}catch(Ye){$.warn(Ye)}}if(fr){let qe=G==="input"?new Image:z,mt=Hi(qe,fr,tl);qe!==z&&(z.src=fr);let ct=()=>{var ae,Ve;if(u.position===b.fixed)return!0;for(let Ye=(ae=this.nodeContext.parent)==null?void 0:ae.viewNode;Ye&&Ye!==this.viewRoot;Ye=Ye.parentElement)if(((Ve=Ye.style)==null?void 0:Ve.position)==="fixed")return!0;return!1};!Ts&&!Is&&!(()=>{let ae=this.nodeContext.vertical?Ns:Ps;return ae instanceof I&&ae.unit==="%"})()&&!ct()?this.page.fetchers.push(mt):(Ts&&Is&&pr&&pr!==1&&Es.push({image:qe,element:z,fetcher:mt}),Ce.push(mt))}delete u.content;let As=u["list-style-image"];if(As&&As instanceof Qe){let qe=As.url;Ce.push(Hi(new Image,qe))}if(this.preprocessElementStyle(u),this.applyComputedStyles(z,u),this.nodeContext.inline)t||(wt(z,"inline-start"),En(z)&&wt(z,"clone"));else if(t){if(!Ca(u.position)){let qe=u["margin-break"],mt=this.getBreakTypeAt(this.nodeContext),ct=mt!==null,ae=mt==="auto";(qe===b.discard&&ct||qe!==b.keep&&ae&&!this.nodeContext.floatSide)&&Hs(z,"block-start")}}else{let qe=this.nodeContext.vertical?"width":"height";ei(z,qe)&&T(z,qe,this.nodeContext.display==="table-row"?"0.01px":""),wt(z,"block-start"),En(z)&&wt(z,"clone"),Hs(z,"block-start")}if(x&&z.setAttribute("value",u["ua-list-item-count"].stringValue()),z.classList.contains("_viv-marker-outside-content")&&ki((Qa=(ut=this.nodeContext.parent)==null?void 0:ut.parent)==null?void 0:Qa.display)){let qe=this.viewport.window.getComputedStyle(this.nodeContext.parent.parent.viewNode),mt=parseFloat(qe.borderInlineStartWidth)+parseFloat(qe.paddingInlineStart)+parseFloat(qe.textIndent);mt&&(z.style.insetInlineEnd=`${mt}px`)}this.viewNode=z,Ce.length?ws(Ce).then(()=>{pr>0&&this.modifyElemDimensionWithImageResolution(Es,pr,u,this.nodeContext.vertical),o.finish(s)}):o.timeSlice().then(()=>{o.finish(s)})})}),o.result()}isAtStartOfPage(){var t,i;for(let n=this.nodeContext;n!=null&&n.parent&&!n.after;n=n.parent){let r=n===this.nodeContext&&!n.viewNode?(t=n.parent.viewNode)==null?void 0:t.lastChild:(i=n.viewNode)==null?void 0:i.previousSibling;for(;r&&($e(r,n.parent.whitespace)||Yi(r));)r=r.previousSibling;if(r)return!1}return!0}isInsideNonRootMultiColumn(){var t;let i=(t=this.nodeContext.parent)==null?void 0:t.viewNode;return!!(i&&Na(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let l=t;l&&!l.after;l=l.parent){if(it(l.breakBefore))return l.breakBefore;if(l.fragmentIndex===1&&!l.parent)return l.sourceNode===l.sourceNode.ownerDocument.documentElement?"page":null;if((i=l.parent)!=null&&i.floatSide)return null;let h=(n=l.parent)==null?void 0:n.viewNode;if(h){let u=this.viewport.window.getComputedStyle(h),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=h?.firstChild;for(;f&&($e(f,l.parent.whitespace)||!l.floatSide&&Yi(f));)f=f.nextSibling;if(f&&f!==l.viewNode)return null}}let a=(o=(s=(r=this.context)==null?void 0:r.currentLayoutPosition)==null?void 0:s.flowPositions[this.flowName])==null?void 0:o.startBreakType;return it(a)?a:"auto"}isInsideTable(t){for(let i=t;i&&!i.after;i=i.parent)if(i.display&&i.display.startsWith("table"))return!0;return!1}processAfterIfcontinues(t,i,n,r){let s=this.getPseudoMap(i,this.regionIds,this.isFootnote,this.nodeContext,r);if(s&&s["after-if-continues"]&&s["after-if-continues"].content){let o=new th(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new Tw(t,o)}}isSVGUrlAttribute(t){return ia.SVG_URL_ATTRIBUTES.includes(t.toLowerCase())}modifyElemDimensionWithImageResolution(t,i,n,r){t.forEach(s=>{if(s.fetcher.get().get()==="load"){let o=s.image,a=o.width/i,l=o.height/i,h=s.element;if(a>0&&l>0){if(n["box-sizing"]===b.border_box&&(n["border-left-style"]!==b.none&&(a+=et(n["border-left-width"],this.context)),n["border-right-style"]!==b.none&&(a+=et(n["border-right-width"],this.context)),n["border-top-style"]!==b.none&&(l+=et(n["border-top-width"],this.context)),n["border-bottom-style"]!==b.none&&(l+=et(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||b.none,d=n["max-height"]||b.none;if(u===b.none&&d===b.none)T(h,"max-width",`${a}px`);else if(u!==b.none&&d===b.none)T(h,"width",`${a}px`);else if(u===b.none&&d!==b.none)T(h,"height",`${l}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?T(h,"max-width",`${Math.min(a,et(p,this.context))}px`):f.unit!=="%"?T(h,"max-height",`${Math.min(l,et(f,this.context))}px`):r?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ee,d=n["min-height"]||Ee;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?T(h,"min-width",`${a}px`):p.num!==0&&f.num===0?T(h,"width",`${a}px`):p.num===0&&f.num!==0?T(h,"height",`${l}px`):p.unit!=="%"?T(h,"min-width",`${Math.max(a,et(p,this.context))}px`):f.unit!=="%"?T(h,"min-height",`${Math.max(l,et(f,this.context))}px`):r?T(h,"height",`${l}px`):T(h,"width",`${a}px`)}}}})}preprocessElementStyle(t){Rt("PREPROCESS_ELEMENT_STYLE").forEach(i=>{i(this.nodeContext,t)})}findAndProcessRepeatingElements(t,i){for(let n=t.firstChild;n;n=n.nextSibling){if(n.nodeType!==1)continue;let r={},s=i.getStyle(n,!1);if(this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",s,r),!this.processRepeatOnBreak(r))continue;if(this.nodeContext.formattingContext instanceof Ii&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new Ii(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==b.none&&((i===b.auto||K(i))&&(t.display===b.table_header_group?i=b.header:t.display===b.table_footer_group?i=b.footer:i=b.none),i&&i!==b.none)?i.toString():null}createTextNodeView(){let t=O("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Bl(this.nodeContext.preprocessedTextContent).substr(i);this.viewNode=document.createTextNode(n),t.finish(!0)}),t.result()}preprocessTextContent(){if(this.nodeContext.preprocessedTextContent!=null)return N(!0);let t,i=t=this.sourceNode.textContent,n=O("preprocessTextContent"),r=Rt("PREPROCESS_TEXT_CONTENT"),s=0;return n.loop(()=>s>=r.length?N(!1):r[s++](this.nodeContext,i).thenAsync(o=>(i=o,N(!0)))).then(()=>{this.nodeContext.preprocessedTextContent=Ug(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=O("createNodeView"),r,s=!0;return this.sourceNode.nodeType==1?r=this.createElementView(t,i):this.sourceNode.nodeType==8?(this.viewNode=null,r=N(!0)):r=this.createTextNodeView(),r.then(o=>{var a;if(s=o,this.nodeContext.viewNode=this.viewNode,this.viewNode){let l=(d,p)=>d?.nodeType===1&&Ji(d)===p,h=this.nodeContext.parent,u=h?l(this.viewNode,"after")&&l(h.viewNode,"first-letter")&&(a=h.viewNode)!=null&&a.hasChildNodes()?h.parent.viewNode:h.viewNode:this.viewRoot;u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&$e(this.viewNode))&&!u.hasChildNodes()&&rc(u).includes("block-start")&&wt(u,"text-start"),u.appendChild(this.viewNode),wm(this.viewNode))}n.finish(s)}),n.result()}setCurrent(t,i,n){return this.nodeContext=t,t?(this.sourceNode=t.sourceNode,this.offsetInNode=t.offsetInNode):(this.sourceNode=null,this.offsetInNode=-1),this.viewNode=null,this.nodeContext?this.createNodeView(i,!!n):N(!0)}processShadowContent(t){if(t.shadowContext==null||t.sourceNode.localName!="content"||t.sourceNode.namespaceURI!="http://www.pyroxy.com/ns/shadow")return t;let i=t.boxOffset,n=t.shadowContext,r=t.parent,s,o,a=n.subShadow||n.parentShadow;n.subShadow?(s=n.root,o=n.type,o==xt.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=xt.ROOTLESS);let l=t.sourceNode.nextSibling;if(l?(t.sourceNode=l,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let h=new Pn(s,r,i);return h.shadowContext=a,h.shadowType=o,h.shadowSibling=t,h}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=xt.ROOTED){let n=t.sourceNode.nextSibling;if(n)return t=t.modify(),t.boxOffset=i,t.sourceNode=n,t.resetView(),this.processShadowContent(t)}return t.shadowSibling?(t=t.shadowSibling.modify(),t.boxOffset=i,t):(t=t.parent.modify(),t.boxOffset=i,t.after=!0,t)}else{if(t.nodeShadow){let r=t.nodeShadow.root;if(t.nodeShadow.type==xt.ROOTLESS&&(r=r.firstChild),r){let s=new Pn(r,t,i);return s.shadowContext=t.nodeShadow,s.shadowType=t.nodeShadow.type,this.processShadowContent(s)}}let n=t.sourceNode.firstChild;if(n)return this.processShadowContent(new Pn(n,t,i));if(t.sourceNode.nodeType!=1){let r=Bl(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}isTransclusion(t,i,n){let r=Re(i,"hyperlink-processing");if(!r)return!1;let s=r.evaluate(this.context,"hyperlink-processing");return s?s.toString()==n:!1}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let r=O("nextInTree");return this.setCurrent(n,!0,i).then(s=>{(!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){if(t instanceof Ze){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof Qe){let i=t.url;this.page.fetchers.push(Hi(new Image,i))}}applyComputedStyles(t,i){var n,r,s;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===b.relative,l=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),h=Object.keys(i);h.sort(xl);let u,d;for(let p of h){if(f0[p])continue;let f=i[p];if(!(!f||f===X&&!zt(p))){if(f=f.visit(new zf(this.xmldoc.url,this.documentURLTransformer)),f instanceof I)if(f.unit==="em"){let m=this.getEmUnitSize(p,u);m!=null&&(f=new I(f.num*m,"px"))}else if(f.unit==="lh"){let m=this.getLineHeightUnitSize(p,u,d);m!=null&&(f=new I(f.num*m,"px"))}else ru(f.unit)&&(f=Su(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof I&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new _i(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),Gg[p]||a&&jg[p]){this.page.delayedItems.push(new Sa(t,p,f));continue}l&&this.page.pageAreaElement&&zn(p)?T(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()):T(t,p,f.toString())}}}parsePlusLayoutUnitAdj(t){if(t.endsWith("px")){let i=parseFloat(t);if(!isNaN(i))return Math.round((i+this.viewport.layoutUnitAdj)*this.viewport.layoutUnitPerPixel)/this.viewport.layoutUnitPerPixel}return null}getLineHeightUnitSize(t,i,n){var r,s,o,a,l,h;let u=((o=(s=(r=this.nodeContext)==null?void 0:r.parent)==null?void 0:s.viewNode)==null?void 0:o.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,d=u?this.parsePlusLayoutUnitAdj(u.lineHeight):this.context.rootLineHeight;if(t==="line-height"||t==="font-size")return d;let p=null;if(n)if(n instanceof gt||n instanceof I&&(n.unit==="em"||n.unit==="%"))p=n instanceof I&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof I&&n.unit!=="lh"){let f=this.context.queryUnitSize(n.unit,!1);if(f!=null)return n.num*f}return null}if(p==null)for(let f=(l=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:l.viewNode;f&&f.nodeType===1;f=f.parentNode){let m=(h=f?.style)==null?void 0:h.lineHeight;if(m){/^[0-9.]+$/.test(m)&&(p=parseFloat(m));break}}if(p!=null){if(i&&!(i instanceof I))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof I){let m=Io(i,f,this.context).num;return typeof m!="number"||isNaN(m)?null:p*m}else return f==null?null:p*f}return d}getEmUnitSize(t,i){var n,r,s;let o=((s=(r=(n=this.nodeContext)==null?void 0:n.parent)==null?void 0:r.viewNode)==null?void 0:s.nodeType)===1?this.viewport.window.getComputedStyle(this.nodeContext.parent.viewNode):null,a=o?this.parsePlusLayoutUnitAdj(o.fontSize):this.context.rootFontSize;if(t==="font-size"||i==null)return a;if(i instanceof I){let l=Io(i,a,this.context).num;if(typeof l=="number"&&!isNaN(l))return l}return null}applyPseudoelementStyle(t,i,n){if(t.after)return;let r=this.sourceNode,s=(t.shadowContext?t.shadowContext.styler:this.styler).getStyle(r,!1),o=kt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let l=a.content;Dt(l)&&(l.visit(new is(n,this.context,l,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=O("peelOff"),r=t.firstPseudo,s=t.offsetInNode,o=t.after;if(i>0){let d=t.viewNode.textContent;t.viewNode.textContent=d.substr(0,i),s+=i}else if(!o&&t.viewNode&&s==0){let d=t.viewNode.parentNode;d&&d.removeChild(t.viewNode)}let a=t.boxOffset+i,l=[];for(;t.firstPseudo===r;)l.push(t),t=t.parent;let h=l.pop(),u=h.shadowSibling;return n.loop(()=>{for(;l.length>0;){h=l.pop(),t=new Pn(h.sourceNode,t,a),l.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=h.shadowType,t.shadowContext=h.shadowContext,t.nodeShadow=h.nodeShadow,t.shadowSibling=h.shadowSibling?h.shadowSibling:u,u=null;let d=this.setCurrent(t,!1);if(d.isPending())return d}return N(!1)}).then(()=>{n.finish(t)}),n.result()}createElement(t,i){return t=="http://www.w3.org/1999/xhtml"?this.document.createElement(i):this.document.createElementNS(t,i)}applyFootnoteStyle(t,i,n){let r={},s=kt(this.footnoteStyle,"_pseudos");if(t=this.computeStyle(t,i,this.footnoteStyle,r),s&&s.before){let o={},a=this.createElement("http://www.w3.org/1999/xhtml","span");Mo(a,"before"),n.appendChild(a),this.computeStyle(t,i,s.before,o),delete o.content,this.applyComputedStyles(a,o)}return delete r.content,this.applyComputedStyles(n,r),t}processFragmentedBlockEdge(t){var i,n,r;let s=!t.inline&&t.after?t.parent:t,o=!1;if(t.inline&&t.after&&!t.shadowContext&&((i=t.sourceNode.nextSibling)==null?void 0:i.nodeType)===1){let l=t.sourceNode.nextSibling,h=(n=Re(this.styler.getStyle(l,!1),"display"))==null?void 0:n.value.toString();o=h&&!Mt(h)||l.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(l.textContent)}let a=0;for(let l=s;l;l=l.parent){if(((r=l.viewNode)==null?void 0:r.nodeType)!==1)continue;let h=l.viewNode;if(h.style)if(l.inline){if(wt(h,"inline-end"),En(h)){let u=l.vertical?h.offsetWidth:h.offsetHeight;wt(h,"clone"),(l.vertical?h.offsetWidth:h.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(h)}}else{let u=this.nodeContext.vertical?"width":"height";if(ei(h,u)&&T(h,u,""),wt(h,"block-end"),!a++&&l!==s){let{textAlign:d}=this.viewport.window.getComputedStyle(h);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(h);p?p!==h?sc(p,["block-start","text-start","block-end","text-end","justify"]):(wt(h,"text-end"),wt(h,"justify")):wt(h,"text-end")}else wt(h,"text-end")}En(h)&&wt(h,"clone"),Hs(h,"block-end")}}}fixClonedBoxDecorationOverflow(t){let i=this.viewport.window.getComputedStyle(t),n=parseFloat(i.paddingInlineEnd),r=parseFloat(i.borderInlineEndWidth),s=-(n+r);isNaN(s)||(t.style.marginInlineEnd=`${s}px`)}createChildAnonymousBlockIfNeeded(t){let i=s=>{let{display:o,position:a,float:l}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||Ci[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let h=s.lastElementChild;if(h&&(!h.nextSibling||h.nextSibling===s.lastChild&&$e(h.nextSibling))){let u=i(h);if(u||u===null)return u}for(let u=h?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||l&&l!=="none"||s.hasAttribute(hn)){let h=s.previousElementSibling;return h&&(h.nextSibling===s||h.nextSibling===s.previousSibling&&$e(h.nextSibling))?i(h):!1}return!(!o||Mt(o))},n=null;for(let s=t.lastElementChild;s;s=s.previousElementSibling){let o=i(s);if(o){n=s;break}if(o===null)return null}if(!n)return t;if(n===t.lastElementChild&&(!n.nextSibling||n.nextSibling===t.lastChild&&$e(n.nextSibling)))return null;let r=t.ownerDocument.createElement("span");r.className="viv-anonymous-block";for(let s=n.nextSibling,o=null;s;s=o)o=s.nextSibling,r.appendChild(s);return t.appendChild(r),r}convertLengthToPx(t,i,n){let r=t.num,s=t.unit;if(sf(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,La(t,a,this.context).num}else{let o=this.context.queryUnitSize(s,!1);return o?r*o:t}}isSameNodePositionStep(t,i){if(t.shadowContext){if(!i.shadowContext)return!1;let n=t.node.nodeType===1?t.node:t.node.parentElement,r=i.node.nodeType===1?i.node:i.node.parentElement;return t.shadowContext.owner===i.shadowContext.owner&&Ji(n)===Ji(r)}else return t.node===i.node}isSameNodePosition(t,i){return t.offsetInNode===i.offsetInNode&&t.after==i.after&&t.steps.length===i.steps.length&&t.steps.every((n,r)=>{let s=i.steps[r];return this.isSameNodePositionStep(n,s)})}isPseudoelement(t){return!!Ji(t)}};c(tp,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var p0=tp,f0={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-policy":!0,"margin-break":!0,page:!0},g0=class{constructor(e){c(this,"layoutBox"),c(this,"window"),c(this,"pixelRatio"),c(this,"scaleRatio"),c(this,"layoutUnitPerPixel"),this.layoutBox=e.layoutBox,this.window=e.window,this.pixelRatio=e.pixelRatio,this.scaleRatio=e.scaleRatio,this.layoutUnitPerPixel=e.layoutUnitPerPixel}subtractOffsets(e,t){let i=t.left,n=t.top;return{left:e.left-i,top:e.top-n,right:e.right-i,bottom:e.bottom-n,width:e.width,height:e.height}}getRangeClientRects(e){let t=e.getClientRects(),i=this.layoutBox.getBoundingClientRect();return Array.from(t).map(n=>this.subtractOffsets(n,i))}getElementClientRect(e){let t=e.getBoundingClientRect();if(t.left===0&&t.top===0&&t.right===0&&t.bottom===0)return t;let i=this.layoutBox.getBoundingClientRect();return this.subtractOffsets(t,i)}getElementComputedStyle(e){return this.window.getComputedStyle(e,null)}adjustLengthValue(e){return this.layoutUnitPerPixel?Math.floor(e*this.layoutUnitPerPixel)/this.layoutUnitPerPixel:e}},ds=class{constructor(e,t,i,n,r,s){if(this.window=e,this.fontSize=t,this.pixelRatio=i,c(this,"document"),c(this,"root"),c(this,"outerZoomBox"),c(this,"contentContainer"),c(this,"layoutBox"),c(this,"width"),c(this,"height"),c(this,"scaleRatio",1),c(this,"layoutUnitPerPixel",64),c(this,"layoutUnitAdj",0),this.document=e.document,this.root=n||this.document.body,this.root.hasAttribute("data-vivliostyle-toc-box")){this.outerZoomBox=this.contentContainer=this.layoutBox=this.root,this.width=r||this.root.clientWidth,this.height=s||this.root.clientHeight;return}let o=this.root.firstElementChild;o||(o=this.document.createElement("div"),o.setAttribute("data-vivliostyle-outer-zoom-box","true"),o.role="presentation",this.root.appendChild(o));let a=o.firstElementChild;switch(a||(a=this.document.createElement("div"),a.setAttribute("data-vivliostyle-spread-container","true"),a.role="presentation",o.appendChild(a)),i>0&&CSS.supports("zoom","8")&&(T(this.root,"--viv-outputPixelRatio",`${i}`),T(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),jh){case"chromium":this.layoutUnitPerPixel=64*(this.pixelRatio||e.devicePixelRatio),this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"firefox":this.layoutUnitPerPixel=60,this.layoutUnitAdj=1/this.layoutUnitPerPixel;break;case"webkit":default:this.layoutUnitPerPixel=64,this.layoutUnitAdj=0}this.layoutUnitAdj&&T(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let l=o.nextElementSibling;l||(l=this.document.createElement("div"),l.setAttribute("data-vivliostyle-layout-box","true"),l.role="presentation",this.root.appendChild(l)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=l,this.width=r||parseFloat(e.getComputedStyle(this.root).width)||this.root.offsetWidth||e.innerWidth,this.height=s||parseFloat(e.getComputedStyle(this.root).height)||this.root.offsetHeight||e.innerHeight;let h={width:794,height:1056},u=!e.outerWidth&&!e.outerHeight||/Headless/.test(navigator.userAgent)||navigator.webdriver&&e.innerWidth===800&&e.innerHeight===600;(!this.width||!r&&u)&&(this.width=h.width),(!this.height||!s&&u)&&(this.height=h.height)}resetZoom(){T(this.outerZoomBox,"width",""),T(this.outerZoomBox,"height",""),T(this.contentContainer,"width",""),T(this.contentContainer,"height",""),T(this.contentContainer,"transform","")}zoom(e,t,i){T(this.root,"--viv-outputScale",`${i}`),T(this.outerZoomBox,"width",`${e*i}px`),T(this.outerZoomBox,"height",`${t*i}px`),T(this.contentContainer,"width",`${e}px`),T(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},ip=class{constructor(e,t,i){this.store=e,this.url=t,this.document=i,c(this,"lang",null),c(this,"totalOffset",-1),c(this,"root"),c(this,"body"),c(this,"head"),c(this,"last"),c(this,"lastOffset",1),c(this,"idMap"),this.root=i.documentElement;let n=null,r=null;if(this.root.namespaceURI=="http://www.w3.org/1999/xhtml"){for(let s=this.root.firstChild;s;s=s.nextSibling){if(s.nodeType!=1)continue;let o=s;if(o.namespaceURI=="http://www.w3.org/1999/xhtml")switch(o.localName){case"head":r=o;break;case"body":n=o;break}}this.lang=this.root.getAttribute("lang")}this.body=n,this.head=r,this.last=this.root,this.last.setAttribute(Ut,"0")}doc(){return new rp([this.document])}getElementOffset(e){let t=e.getAttribute(Ut);if(t)return parseInt(t,10);let i=this.lastOffset,n=this.last;for(;n!=e;){let r=n.firstChild;if(!r){for(;r=n.nextSibling,!r;)if(n=n.parentNode,n==null)throw new Error("Internal error")}n=r,r.nodeType==1?(r.setAttribute(Ut,i.toString()),++i):i+=r.textContent.length}return this.lastOffset=i,this.last=e,i-1}getNodeOffset(e,t,i){let n=0,r=e,s=null;if(r.nodeType==1){if(!i)return this.getElementOffset(r)}else{if(n=t,s=r.previousSibling,!s)return r=r.parentNode,n+=1,this.getElementOffset(r)+n;r=s}for(;;){for(;r.lastChild;)r=r.lastChild;if(r.nodeType==1)break;if(n+=r.textContent.length,s=r.previousSibling,!s){r=r.parentNode;break}r=s}return n+=1,this.getElementOffset(r)+n}getTotalOffset(){return this.totalOffset<0&&(this.totalOffset=this.getNodeOffset(this.root,0,!0)),this.totalOffset}getNodeByOffset(e){let t,i=this.root;for(;;){if(t=this.getElementOffset(i),t>=e)return i;let a=i.children;if(!a)break;let l=ai(a.length,h=>{let u=a[h];return this.getElementOffset(u)>e});if(l==0)break;i=a[l-1]}let n=t+1,r=i,s=r.firstChild||r.nextSibling,o=null;for(;;){if(s){if(s.nodeType==1||(r=s,o=r,n+=s.textContent.length,n>e&&!/^\s*$/.test(s.textContent)))break}else if(r=r.parentNode,!r)break;s=r.nextSibling}return s&&o&&/^\s*$/.test(o.textContent)&&(o=s),o||i}buildIdMap(e){let t=e.getAttribute("id");t&&!this.idMap[t]&&(this.idMap[t]=e);let i=e.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");i&&!this.idMap[i]&&(this.idMap[i]=e);for(let n=e.firstElementChild;n;n=n.nextElementSibling)this.buildIdMap(n)}getElement(e){let t=e.match(/([^#]*)#(.+)$/);if(!t||t[1]&&t[1]!=this.url)return null;let i=t[2],n=this.document.getElementById(i);return!n&&this.document.getElementsByName&&(n=this.document.getElementsByName(i)[0]),n||(this.idMap||(this.idMap={},this.buildIdMap(this.document.documentElement)),n=this.idMap[i]),n}},na=(e=>(e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML_XML="application/xhtml+xml",e.IMAGE_SVG_XML="image/svg+xml",e))(na||{});function kr(e,t,i){let n=i||new DOMParser,r;try{r=n.parseFromString(e,t)}catch{}if(r){let s=r.documentElement,o="parsererror";if(s.localName===o)return null;for(let a=s.firstElementChild;a;a=a.nextElementSibling)if(a.localName===o)return null}else return null;return r}function m0(e){let t=e.contentType;if(t){let n=Object.keys(na);for(let r=0;r<n.length;r++)if(na[n[r]]===t)return t;if(t.match(/\+xml$/))return"application/xml"}let i=e.url.match(/\.([^./#?]+)([#?]|$)/);if(i)switch(i[1]){case"html":case"htm":return"text/html";case"xhtml":case"xht":return"application/xhtml+xml";case"svg":case"svgz":return"image/svg+xml";case"opf":case"xml":return"application/xml"}return null}function np(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s){let o=m0(e);if(i=kr(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=kr(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=kr(s,"image/svg+xml",r))}i||(i=kr(s,"text/html",r))}}let n=i?new ip(t,e.url,i):null;return N(n)}function w0(){return new ya(np,"document")}var y0=class ra{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new ra(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new ra(n=>{if(!this.check(n))return!1;let r=new rp([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},Nh=new y0(e=>!0),rp=class sa{constructor(t){this.nodes=t}asArray(){return this.nodes}size(){return this.nodes.length}predicate(t){let i=[];for(let n of this.nodes)t.check(n)&&i.push(n);return new sa(i)}forEachNode(t){let i=[],n=r=>{i.push(r)};for(let r=0;r<this.nodes.length;r++)t(this.nodes[r],n);return new sa(i)}forEach(t){let i=[];for(let n=0;n<this.nodes.length;n++)i.push(t(this.nodes[n]));return i}forEachNonNull(t){let i=[];for(let n=0;n<this.nodes.length;n++){let r=t(this.nodes[n]);r!=null&&i.push(r)}return i}child(t){return this.forEachNode((i,n)=>{for(let r=i.firstChild;r;r=r.nextSibling)r.nodeType==1&&r.localName==t&&n(r)})}childElements(){return this.forEachNode((t,i)=>{for(let n=t.firstChild;n;n=n.nextSibling)n.nodeType==1&&i(n)})}attribute(t){return this.forEachNonNull(i=>i.nodeType==1?i.getAttribute(t):null)}textContent(){return this.forEach(t=>t.textContent)}},b0=new or(()=>{let e=O("uaStylesheetBase"),t=zd(),i=Pe("user-agent-base.css",ni),n=new Yn(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),cw(n.cascade),va($u,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function v0(){return b0.get()}var x0=class extends In{constructor(e,t,i,n,r,s){super(e,t,null,i,n,"counter-style"),this.counterStyleName=r,this.counterStyles=s}endRule(){super.endRule(),this.counterStyles.define(this.counterStyleName,this.elementStyle)||$.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},S0=class{constructor(e,t,i,n,r,s,o,a,l,h,u){this.store=e,this.rootScope=t,this.pageScope=i,this.cascade=n,this.rootBox=r,this.fontFaces=s,this.footnoteProps=o,this.flowProps=a,this.viewportProps=l,this.pageProps=h,this.counterStyleStore=u,c(this,"fontDeobfuscator"),c(this,"validatorSet"),this.fontDeobfuscator=e.fontDeobfuscator,this.validatorSet=e.validatorSet,this.pageScope.defineBuiltIn("has-content",function(d){d=d;let p=this,f=p.currentLayoutPosition,m=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!m&&!p.flowChunkIsAfterParentFlowForcedBreak(m)}),this.pageScope.defineName("page-number",new ze(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new ze(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new no(this.rootScope,e,t,i),s=Lm(r,this.viewportProps),o=s.width,a=s.height,l=s["text-zoom"],h=1;if(o&&a||l){let u=At.em;if((l?l.evaluate(r,"text-zoom"):null)===b.scale&&(h=u/i,i=u,e*=h,t*=h),o&&a){let d=et(o.evaluate(r,"width"),r),p=et(a.evaluate(r,"height"),r);if(d>0&&p>0)return{width:n&&n.spreadView?(d+n.pageBorder)*2:d,height:p,fontSize:i}}}}return{width:e,height:t,fontSize:i}}},Za=class extends no{constructor(e,t,i,n,r,s,o,a,l,h,u,d,p,f){super(e.rootScope,n.width,n.height,n.fontSize),this.style=e,this.xmldoc=t,this.viewport=n,this.clientLayout=r,this.fontMapper=s,this.customRenderer=o,this.fallbackMap=a,this.pageNumberOffset=l,this.documentURLTransformer=h,this.counterStore=u,this.cmykStore=d,c(this,"lang"),c(this,"primaryFlows",{body:!0}),c(this,"rootPageBoxInstance",null),c(this,"styler",null),c(this,"stylerMap",null),c(this,"currentLayoutPosition",null),c(this,"layoutPositionAtPageStart",null),c(this,"lookupOffset",0),c(this,"faces"),c(this,"pageBoxInstances",{}),c(this,"pageManager",null),c(this,"rootPageFloatLayoutContext"),c(this,"pageBreaks",{}),c(this,"pageProgression",null),c(this,"isVersoFirstPage",!1),c(this,"blankPageAtStart",!1),c(this,"pageSheetSize",{}),c(this,"pageSheetHeight",0),c(this,"pageSheetWidth",0),this.lang=t.lang||i,this.faces=new Sb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new Tn(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let m in e.flowProps){let g=e.flowProps[m],w=Re(g,"flow-consume");w&&(w.evaluate(this,"flow-consume")==b.all?this.primaryFlows[m]=!0:delete this.primaryFlows[m])}}init(){let e=O("StyleInstance.init"),t=this.counterStore.createCounterListener(this.xmldoc.url),i=this.counterStore.createCounterResolver(this.xmldoc.url,this.style.rootScope,this.style.pageScope);this.styler=new dh(this.xmldoc,this.style.cascade,this.style.rootScope,this,this.primaryFlows,this.style.validatorSet,t,i,this.style.counterStyleStore,this.cmykStore),i.setStyler(this.styler),this.styler.resetFlowChunkStream(this),this.stylerMap={},this.stylerMap[this.xmldoc.url]=this.styler;let n=this.styler.getTopContainerStyle();this.pageProgression||(this.pageProgression=qd(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Tb(r);let s=this.style.cascade.createInstance(this,t,i,this.lang,this.style.counterStyleStore,this.cmykStore);this.styler.cascade.currentPageType=this.styler.cascade.firstPageType,this.rootPageBoxInstance.applyCascadeAndInit(s,n),this.rootPageBoxInstance.resolveAutoSizing(this),this.pageManager=new Gb(s,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let l of this.style.fontFaces){if(l.condition&&!l.condition.evaluate(this))continue;let h=xb(l.properties,this),u=new Dd(h);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{l0(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(l=>{let h=a[l];this.styler.cascade.applyVarFilter([h],this.styler,null),this.styler.cascade.applyCalcFilter(h,this.styler.context),this.styler.cascade.applyCmykFilter(h);let u=Ch(cs(h),this);this.pageSheetSize[l]={width:u.pageWidth+u.cropOffset*2,height:u.pageHeight+u.cropOffset*2}}),e.result()}matchStartPageSide(e){let t=this.pageNumberOffset%2==(this.isVersoFirstPage?1:0),i=this.pageProgression=="ltr";switch(e){case"left":return t!==i;case"right":return t===i;case"recto":return t;case"verso":return!t;default:return!0}}getStylerForDoc(e){let t=this.stylerMap[e.url];if(!t){let i=this.style.store.getStyleForDoc(e),n=new no(i.rootScope,this.pageWidth(),this.pageHeight(),this.initialFontSize),r=this.counterStore.createCounterListener(e.url),s=this.counterStore.createCounterResolver(e.url,i.rootScope,i.pageScope);t=new dh(e,i.cascade,i.rootScope,n,this.primaryFlows,i.validatorSet,r,s,i.counterStyleStore,this.cmykStore),this.stylerMap[e.url]=t}return t}registerInstance(e,t){this.pageBoxInstances[e]=t}lookupInstance(e){return this.pageBoxInstances[e]}encounteredFlowChunk(e,t){let i=this.currentLayoutPosition;if(i){i.flows[e.flowName]?t=i.flows[e.flowName]:i.flows[e.flowName]=t;let n=i.flowPositions[e.flowName];n||(n=new im,i.flowPositions[e.flowName]=n);let r=Qg(e.element),s=new ui(r),o=new tm(s,e);n.positions.push(o)}}evalSupportsTest(e,t,i){if(i)return e==="selector"?this.evalSupportsSelector(t):!1;if(!e)return!1;let n=!0;class r{unknownProperty(l,h){n=!1}invalidPropertyValue(l,h){n=!1}simpleProperty(l,h,u){}}let s=new r,o=gn(this.style.rootScope,new Ft(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}evalSupportsSelector(e){let t=new sp(null),i=new Ft(e+"{}",t);return new lr(Ae,i,t,"").runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!1)?!t.cascadeParserHandler.invalid:!1}getConsumedOffset(e){let t=Number.POSITIVE_INFINITY;for(let i=0;i<e.positions.length;i++){let n=e.positions[i].chunkPosition.primary,r=n.steps[0].node,s=n.offsetInNode,o=n.after,a=0;for(;r.ownerDocument!=this.xmldoc.document;)a++,r=n.steps[a].node,o=!1,s=0;let l=this.xmldoc.getNodeOffset(r,s,o);l<t&&(t=l)}return t}getPosition(e,t){if(!e)return 0;let i=Number.POSITIVE_INFINITY;for(let n in this.primaryFlows){let r=e.flowPositions[n];if(!t&&(!r||r.positions.length==0)&&this.currentLayoutPosition&&(this.styler.styleUntilFlowIsReached(n),r=this.currentLayoutPosition.flowPositions[n],e!=this.currentLayoutPosition&&r&&(r=r.clone(),e.flowPositions[n]=r)),r){let s=this.getConsumedOffset(r);s<i&&(i=s)}}return i}dumpLocation(e){$.debug("Location - page",this.currentLayoutPosition.page),$.debug(" current:",e),$.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)$.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new De(this.style.pageScope,`${e}-page`).evaluate(this);default:return!0}}updateStartSide(e){for(let t in e.flowPositions){let i=e.flowPositions[t];if(i&&i.positions.length>0){let n=i.positions[0].flowChunk;if(this.getConsumedOffset(i)===n.startOffset){let r=i.positions[0].flowChunk.breakBefore,s=i.startBreakType;i.startBreakType=Ol(rt(s,r))}}}}selectPageMaster(e){let t=this.currentLayoutPosition,i=this.getPosition(t);if(i==Number.POSITIVE_INFINITY)return null;let n=this.rootPageBoxInstance.children,r;for(let s=0;s<n.length;s++){if(r=n[s],r.pageBox.pseudoName===Ya)continue;let o=1;r.pageBox.pseudoName===Ga&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let l=this.queryUnitSize("em",!1),h=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*h/(l*l)),d=this.styler.cascade.currentPageType;this.lookupOffset=this.styler.styleUntil(i,u),this.styler.cascade.currentPageType=d,this.updateStartSide(t),this.layoutPositionAtPageStart=t.clone(),this.initLingering(),this.clearScope(this.style.pageScope);let p=r.getProp(this,"enabled");if(!p||p===b._true){if(t.page===1&&this.blankPageAtStart){r.style={};let f=e.size;e={},f&&(e.size=f)}return this.pageManager.getPageRulePageMaster(r,e)}}throw new Error("No enabled page masters")}flowChunkIsAfterParentFlowForcedBreak(e){let t=this.layoutPositionAtPageStart.flows,i=t[e.flowName].parentFlowName;if(i){let n=e.startOffset,r=t[i].forcedBreakOffsets;if(!r.length||n<r[0])return!1;let s=ai(r.length,h=>r[h]>n)-1,o=r[s],a=this.layoutPositionAtPageStart.flowPositions[i],l=this.getConsumedOffset(a);return o<l?!1:l<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Ia(null)),e.flowRootFormattingContext=i.formattingContext}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=a=>{if(a.floatReference!==Oe.PAGE)return!1;let l=this.layoutPositionAtPageStart.flowPositions.body,h=l&&this.getConsumedOffset(l),u=this.xmldoc.getNodeOffset(a.nodePosition.steps[0].node,0,!1);return u!=null&&h!=null&&u>h},r=O("layoutDeferredPageFloats"),s=!1,o=0;return r.loopWithFrame(a=>{if(o===i.length){a.breakLoop();return}let l=i[o++],h=l.float;if(n(h)){a.breakLoop();return}let u=new ln().findByFloat(h),d=u.findPageFloatFragment(h,t);if(d&&d.hasFloat(h)){a.continueLoop();return}else if(t.isForbidden(h)||t.hasPrecedingFloatsDeferredToNext(h)){t.deferPageFloat(l),a.breakLoop();return}e.layoutPageFloatInner(l,u,null,d).then(p=>{if(!p){a.breakLoop();return}let f=t.parent.isInvalidated();if(f){a.breakLoop();return}else t.isInvalidated()&&!f&&(s=!0,t.validate());a.continueLoop()})}).then(()=>{s&&t.invalidate(),r.finish(!0)}),r.result()}getLastAfterPositionIfDeferredFloatsExists(e,t){if(e.pageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0)if(e.lastAfterPosition){let i;return t?(i=t.clone(),i.primary=e.lastAfterPosition):i=new ui(e.lastAfterPosition),i}else return null;else return null}layoutColumn(e,t){let i=this.currentLayoutPosition.flowPositions[t];if(!i||!this.matchPageSide(i.startBreakType))return N(!0);this.setFormattingContextToColumn(e,t),e.init(),this.primaryFlows[t]&&e.bands.length>0&&(e.forceNonfitting=!1);let n=O("layoutColumn");return this.layoutDeferredPageFloats(e).then(()=>{if(e.pageFloatLayoutContext.isInvalidated()){n.finish(!0);return}let r=[],s=[],o=!0;n.loopWithFrame(a=>{if(e.pageFloatLayoutContext.hasContinuingFloatFragmentsInFlow(t)){a.breakLoop();return}for(;i.positions.length-s.length>0;){let l=0;for(;s.includes(l);)l++;let h=i.positions[l];if(h.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(h.flowChunk))break;for(let p=l+1;p<i.positions.length;p++){if(s.includes(p))continue;let f=i.positions[p];if(f.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(f.flowChunk))break;f.flowChunk.isBetter(h.flowChunk)&&(h=f,l=p)}let u=h.flowChunk,d=!0;if(e.layout(h.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,h.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(l),u.exclusive){s.push(l),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,m=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(e.pageBreakType&&m?(h.chunkPosition=m,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(l),(p||m)&&(h.chunkPosition=p||m,r.push(l)),i.startBreakType=Ol(e.pageBreakType)),f){a.breakLoop();return}}e.forceNonfitting=!1,d?d=!1:a.continueLoop()}),d){d=!1;return}}a.breakLoop()}).then(()=>{if(!e.pageFloatLayoutContext.isInvalidated()){i.positions=i.positions.filter((l,h)=>r.includes(h)||!s.includes(h)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new Lw([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,l,h,u,d,p,f){let m=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,g=r.element,w=new Tn(a,Oe.COLUMN,null,o,null,null,null),v=this.currentLayoutPosition.clone(),y=O("createAndLayoutColumn"),C;return y.loopWithFrame(E=>{let A=this.createLayoutConstraint(w);if(l>1){let H=this.viewport.document.createElement("div");if(T(H,"position","absolute"),g.appendChild(H),C=new ss(H,p,this.clientLayout,A,w),C.forceNonfitting=f,C.vertical=r.vertical,C.rtl=r.rtl,C.snapHeight=r.snapHeight,C.snapWidth=r.snapWidth,r.vertical){let V=(r.rtl?l-s-1:s)*(u+h)+r.paddingTop,ie=parseFloat(g.style.width);C.setHorizontalPosition(r.paddingLeft+ie-r.width,r.width),C.setVerticalPosition(V,u)}else{let V=(r.rtl?l-s-1:s)*(u+h)+r.paddingLeft;C.setVerticalPosition(r.paddingTop,r.height),C.setHorizontalPosition(V,u)}C.originX=t,C.originY=i}else C=new ss(g,p,this.clientLayout,A,w),C.copyFrom(r);C.exclusions=m?[]:n.concat(),C.innerShape=d,w.setContainer(C),(C.vertical?C.height:C.width)>=0?this.layoutColumn(C,o).then(()=>{w.isInvalidated()||w.finish(),C.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(C.pageFloatLayoutContext.validate(),this.currentLayoutPosition=v.clone(),C.element!==g&&g.removeChild(C.element),E.continueLoop()):E.breakLoop()}):(w.finish(),E.breakLoop())}).then(()=>{y.finish(C)}),y.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof Zd||t instanceof ja&&!(t instanceof sn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof dn;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new Tn(e,Oe.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,l){let h=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(s,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=h.clone(),this.layoutFlowColumns(e,t,i,n,r,s,u,o,a,l,d).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return N(null);if(l<=1)return N(f.columns);let m=t.getProp(this,"column-fill")||b.balance,g=this.currentLayoutPosition.flowPositions[a],w=xy(l,m,p,u,o,f.columns,g);return w?(d=!1,s.lock(),u.lock(),w.balanceColumns(f).thenAsync(v=>(s.unlock(),s.validate(),u.unlock(),this.currentLayoutPosition=v.position,N(v.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,l,h,u){let d=O("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=t.getPropAsNumber(this,"column-gap"),m=h>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,g=t.getActiveRegions(this),w=t.getProp(this,"shape-inside"),v=Lu(w,0,0,a.width,a.height,this),y=new p0(l,this,this.viewport,this.styler,g,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer),C=0,E=null,A=[];return d.loopWithFrame(H=>{this.createAndLayoutColumn(t,i,n,r,a,C++,l,o,h,f,m,v,y,u).then(V=>{if(s.isInvalidated()){A=null,H.breakLoop();return}if((V.pageBreakType&&V.pageBreakType!=="column"||C===h)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){C=0,this.currentLayoutPosition=p.clone(),o.validate(),o.isLocked()?(A=null,H.breakLoop()):H.continueLoop();return}E=V,A[C-1]=E,E.pageBreakType&&E.pageBreakType!="column"&&(C=h,E.pageBreakType!="region"&&(this.pageBreaks[l]=!0)),C<h?H.continueLoop():H.breakLoop()})}).then(()=>{d.finish(A)}),d.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==b._true)return N(!0);let l=O("layoutContainer"),h=t.getProp(this,"wrap-flow")===b.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof Jd?"complementary":"presentation";let p=t.getProp(this,"position");T(d,"position",p?p.name:"absolute");let f=t instanceof sn;t instanceof dn?i.appendChild(d):i.insertBefore(d,i.firstChild);let m=new gc(d);m.vertical=t.vertical,m.rtl=t.rtl,m.borderBoxSizing=t.borderBoxSizing,m.exclusions=s,t.prepareContainer(this,m,e,this.faces,this.clientLayout),t instanceof sn&&(m.width<=0||m.height<=0)&&$.warn("Negative or zero page area size"),m.originX=n,m.originY=r,n+=m.left+m.marginLeft+m.borderLeft,r+=m.top+m.marginTop+m.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,m);let g,w=!1;if(!u||!u.isIdent()){let v=t.getProp(this,"content");if(v instanceof U&&v.expr instanceof ze&&v.expr.str.startsWith("running-element-"))v.visit(new is(d,this,v,this.counterStore.getExprContentListener()));else if(Dt(v)){let y="span";v instanceof Qe&&(y="img");let C=this.viewport.document.createElement(y);v.visit(new is(C,this,v,this.counterStore.getExprContentListener())),d.appendChild(C),y=="img"&&t.transferSingleUriContentProps(this,C,this.faces),t.transferContentProps(this,m,e,this.faces),y=="span"&&Ew(C,t.getProp(this,"text-autospace"),t.getProp(this,"text-spacing-trim"),t.getProp(this,"hanging-punctuation"),this.lang,t.vertical)}else t.suppressEmptyBoxGeneration&&(i.removeChild(d),w=!0);w||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,m,e,null,1,this.clientLayout,this.faces),g=N(!0);else{let v=O("layoutContainer.inner"),y=u.toString(),C=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,m,y,C).then(E=>{if(!o.isInvalidated()){let A=E[0];A.element===d&&(m=A),m.computedBlockSize=Math.max.apply(null,E.map(V=>V.computedBlockSize)),t.finishContainer(this,m,e,A,C,this.clientLayout,this.faces);let H=this.currentLayoutPosition.flowPositions[y];H&&H.breakAfter==="region"&&(H.breakAfter=null)}v.finish(!0)}),g=v.result()}return g.then(()=>{if(o.isInvalidated()){l.finish(!0);return}if(!t.isAutoHeight||Math.floor(m.computedBlockSize)>0){if(!w&&!h){let y=t.getProp(this,"shape-outside"),C=m.getOuterShape(y,this);s.push(C)}}else if(t.children.length==0){i.removeChild(d),l.finish(!0);return}let v=f?0:t.children.length-1;l.loop(()=>{for(;v>=0&&v<t.children.length;){let y=t.children[f?v++:v--],C=this.layoutContainer(e,y,d,n,r,s,o);if(C.isPending())return C.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{l.finish(!0)})}),l.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage>=0&&r.flowChunk.startPage+r.flowChunk.linger-1<=e&&i.positions.splice(n,1)}}}initLingering(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let r=i.positions[n];r.flowChunk.startPage<0&&r.flowChunk.startOffset<this.lookupOffset&&(r.flowChunk.startPage=e)}}}noMorePrimaryFlows(e){for(let t in this.primaryFlows){let i=e.flowPositions[t];if(i&&i.positions.length>0)return!1}return!0}layoutNextPage(e,t){var i;let n=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new nm,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let r=1e4;if(t.page>r)throw new Error(`Too many pages generated (over ${r} pages)`);let s=t.startSideOfFlow("body");t.isBlankPage=Xn(s)&&this.matchPageSide(s),e.isBlankPage=t.isBlankPage,t.page++;let o=this.styler.cascade.previousPageType;e.pageType==null&&(e.pageType=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType);let a=this.pageManager.pageCascadeInstance;e.pageType&&(o!==e.pageType&&(a.pageTypePageCounts[e.pageType]=0),a.pageTypePageCounts[e.pageType]=(a.pageTypePageCounts[e.pageType]||0)+1),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=n?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l),!n){let g=new De(this.style.pageScope,"left-page");e.side=g.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let h=this.selectPageMaster(l);if(!h)return N(null);let u=0;if(!n){e.setAutoPageWidth(h.pageBox.specified.width.value===rr),e.setAutoPageHeight(h.pageBox.specified.height.value===sr),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(l,this);let g=Ch(cs(l),this);this.setPageSizeAndBleed(g,e),zb(l,g,e,this),u=g.bleedOffset+g.bleed}let d=!n&&h.getProp(this,"writing-mode")||b.horizontal_tb;this.pageVertical=d!=b.horizontal_tb;let p=h.getProp(this,"direction")||b.ltr,f=new Tn(this.rootPageFloatLayoutContext,Oe.PAGE,null,null,null,d,p),m=O("layoutNextPage");return m.loopWithFrame(g=>{this.layoutContainer(e,h,e.bleedBox,u,u,[],f).then(()=>{f.isInvalidated()||f.finish(),f.isInvalidated()?(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),f.validate(),g.continueLoop()):g.breakLoop()})}).then(()=>{h.adjustPageLayout(this,e,this.clientLayout),n||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(w=>{let v=t.flowPositions[w],y=v.breakAfter;y&&(y==="page"||!this.matchPageSide(y))&&(v.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let g=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(g,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),m.finish(t)}),m.result()}setPageSizeAndBleed(e,t){this.actualPageWidth=e.pageWidth,this.actualPageHeight=e.pageHeight,this.pageSheetWidth=e.pageWidth+e.cropOffset*2,this.pageSheetHeight=e.pageHeight+e.cropOffset*2,t.container.style.width=`${this.pageSheetWidth}px`,t.container.style.height=`${this.pageSheetHeight}px`,t.bleedBox.style.left=`${e.bleedOffset}px`,t.bleedBox.style.right=`${e.bleedOffset}px`,t.bleedBox.style.top=`${e.bleedOffset}px`,t.bleedBox.style.bottom=`${e.bleedOffset}px`,t.bleedBox.style.padding=`${e.bleed}px`}},C0=class oa extends Yn{constructor(t,i,n,r){super(t.rootScope,t,i,n,r,t.validatorSet,!n),this.masterHandler=t,c(this,"insideRegion",!1)}startPageTemplateRule(){}startPageMasterRule(t,i,n){let r=new Vd(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new Rb(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=Et(this.scope,this.condition,i)),this.masterHandler.pushHandler(new oa(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new ww(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new In(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new x0(this.scope,this.owner,{},this.masterHandler.validatorSet,t,this.masterHandler.counterStyles))}startFlowRule(t){let i=this.masterHandler.flowProps[t];i||(i={},this.masterHandler.flowProps[t]=i),this.masterHandler.pushHandler(new In(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new In(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ur(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new In(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new n0(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(Yn.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",F(t)),this.endRule();let i=new oa(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},sp=class extends Ng{constructor(e){super(),this.validatorSet=e,c(this,"rootScope"),c(this,"pageScope"),c(this,"rootBox"),c(this,"cascadeParserHandler"),c(this,"regionCount",0),c(this,"fontFaces",[]),c(this,"counterStyles",new ib),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new io(null),this.pageScope=new io(this.rootScope),this.rootBox=new Eb(this.rootScope),this.cascadeParserHandler=new C0(this,null,null,null),this.slave=this.cascadeParserHandler}};function k0(e,t){return t.parseOPSResource(e)}var E0=class extends ya{constructor(e){super(k0,"document"),this.fontDeobfuscator=e,c(this,"styleByKey",{}),c(this,"styleFetcherByKey",{}),c(this,"styleByDocURL",{}),c(this,"triggersByDocURL",{}),c(this,"validatorSet",null),c(this,"styleSheets",[]),c(this,"triggerSingleDocumentPreprocessing",!1)}init(e,t){this.setStyleSheets(e,t);let i=O("OPSDocStore.init");return this.validatorSet=zd(),v0().then(()=>{this.triggerSingleDocumentPreprocessing=!0,i.finish(!0)}),i.result()}getStyleForDoc(e){return this.styleByDocURL[e.url]}getTriggersForDoc(e){return this.triggersByDocURL[e.url]}setStyleSheets(e,t){this.clearStyleSheets(),e&&e.forEach(this.addAuthorStyleSheet,this),t&&t.forEach(this.addUserStyleSheet,this)}clearStyleSheets(){this.styleSheets.splice(0)}addAuthorStyleSheet(e){let t=e.url;t&&(t=Pe(jn(t),on)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Pe(jn(t),on)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=O("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return np(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Rt("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(m){$.warn("Error during single document preprocessing:",m)}}let o=[],a=r.document.getElementsByTagNameNS("http://www.idpf.org/2007/ops","trigger");for(let p=0;p<a.length;p++){let f=a[p],m=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),g=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),v=f.getAttribute("ref");m&&g&&w&&v&&o.push({observer:m,event:g,action:w,ref:v})}this.triggersByDocURL[i]=o;let l=[];if(l.push({url:Pe("user-agent-page.css",ni),text:Uu,flavor:"UA",classes:null,media:null}),l.push({url:Pe("user-agent-counter-styles.css",ni),text:ju,flavor:"UA",classes:null,media:null}),n)l.push({url:Pe("user-agent-toc.css",ni),text:Wu,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let m=f.namespaceURI,g=f.localName;if(m=="http://www.w3.org/1999/xhtml")if(g=="style"){let w=f.getAttribute("class"),v=f.getAttribute("media"),y=f.getAttribute("title");l.push({url:i,text:f.textContent,flavor:"Author",classes:y?w:null,media:v})}else if(g=="link"){let w=f.getAttribute("href"),v=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),y=f.getAttribute("class"),C=f.getAttribute("media");if(w&&v!=null&&v.includes("stylesheet")&&(!v.includes("alternate")||y)){let E=Pe(w,i),A=f.getAttribute("title");l.push({url:E,text:null,classes:A?y:null,media:C,flavor:"Author"})}}else g=="meta"&&f.getAttribute("name")=="viewport"&&l.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)l.push(this.styleSheets[f])}let h="";for(let p=0;p<l.length;p++)h+=l[p].url,h+="^",l[p].text&&(h+=l[p].text),h+="^";let u=this.styleByKey[h];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[h];d||(d=new or(()=>{let p=O("fetchStylesheet"),f=0,m=new sp(this.validatorSet);return p.loop(()=>{if(f<l.length){let g=l[f++];return m.startStylesheet(g.flavor),g.text!==null?va(g.text,m,g.url,g.classes,g.media).thenReturn(!0):Ju(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();u=new S0(this,m.rootScope,m.pageScope,g,m.rootBox,m.fontFaces,m.footnoteProps,m.flowProps,m.viewportProps,m.pageProps,m.counterStyles),this.styleByKey[h]=u,delete this.styleFetcherByKey[h],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[h]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},Wn="\u25B8",Ph="\u25BE",N0="\u25B9";function Ja(e){let t=Array.from(e.querySelectorAll("nav[*|type],nav[epub\\:type]"));if(t.length>0||(t=Array.from(e.querySelectorAll("[role=doc-toc]")),t.length>0))return t;let i="nav,.toc,#toc,#table-of-contents,#contents,[role=directory]";for(let n of e.querySelectorAll(i)){if(t.find(s=>s.contains(n)))continue;let r=n;/^h[1-6]$/.test(r.localName)&&(r.previousElementSibling?r=r.nextElementSibling:r=r.parentElement),r&&r.querySelector("li a[href]")&&t.push(r)}return t}function P0(e){let t=Ja(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var T0=class{constructor(e,t,i,n,r,s,o,a,l,h,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=l,this.counterStore=h,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=eu(s),this.pref.spreadView=!1}setAutoHeight(e,t){if(t--!=0){for(let i=e.firstChild;i;i=i.nextSibling)if(i.nodeType==1){let n=i;ei(n,"height","auto")!="auto"&&(T(n,"height","auto"),this.setAutoHeight(n,t)),ei(n,"position","static")=="absolute"&&(T(n,"position","relative"),this.setAutoHeight(n,t))}}}makeCustomRenderer(e){let t=this.rendererFactory.makeCustomRenderer(e);return(i,n,r)=>{let s=r.behavior;if(s)switch(s.toString()){case"toc-node-anchor":r.color=b.inherit,r["text-decoration"]=b.none;break;case"toc-node":r.display=b.block,r.margin=Ee,r.padding=Ee,r["padding-inline-start"]=new I(1.25,"em");break;case"toc-node-first-child":r.display=b.inline_block,r.margin=new I(.2,"em"),r["vertical-align"]=b.top,r.color=b.inherit,r["text-decoration"]=b.none;break;case"toc-container":r.padding=Ee;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&$e(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let h=n.firstChild;h.textContent!=Wn&&(h.textContent=Wn,T(h,"cursor","pointer"),h.addEventListener("click",I0,!1),h.setAttribute("role","button"),h.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(h.tabIndex=0))}let l=n.ownerDocument.createElement("div");if(l.setAttribute("data-adapt-process-children","true"),s.toString()=="toc-node"){let h=n.ownerDocument.createElement("div");if(h.textContent=N0,T(h,"margin","0.2em 0 0 -1em"),T(h,"margin-inline-start","-1em"),T(h,"margin-inline-end","0"),T(h,"display","inline-block"),T(h,"width","1em"),T(h,"text-align","center"),T(h,"vertical-align","top"),T(h,"cursor","default"),T(h,"font-family","Menlo,sans-serif"),l.appendChild(h),T(l,"overflow","hidden"),l.setAttribute("data-adapt-class","toc-node"),l.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){T(l,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(l.setAttribute("data-adapt-class","toc-container"),l.setAttribute("role","group"),l.setAttribute("aria-hidden","true"));return N(l)}}showTOC(e,t,i,n,r){if(this.page)return N(this.page);let s=O("showTOC"),o=new ac(e,e);this.page=o;let a=Wt(this.url)+"?viv-toc-box";return this.store.load(a).then(l=>{for(let f of Ja(l.document))f.setAttribute("data-vivliostyle-role","doc-toc");let h=this.store.getStyleForDoc(l),u=h.sizeViewport(i,1e5,r);t=new ds(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(l),p=new Za(h,l,this.lang,t,this.clientLayout,this.fontMapper,d,this.fallbackMap,0,this.documentURLTransformer,this.counterStore,this.cmykStore);this.instance=p,p.pref=this.pref,p.init().then(()=>{p.layoutNextPage(o,null).then(()=>{this.setAutoHeight(e,2),s.finish(o)})})}),s.result()}hideTOC(){this.page&&(this.page.container.style.visibility="hidden",this.page.container.setAttribute("aria-hidden","true"))}isTOCVisible(){return!!this.page&&this.page.container.style.visibility==="visible"}getTOC(){if(!this.page)return[];function e(n){if(!n)return[];let r=n.querySelectorAll(":scope > [role=treeitem] > a[href]");return Array.from(r).map(t)}function t(n){let r=new URL(n.href),[,s]=r.hash.match(/^#?(.*)$/),o=n.innerText,a=n.parentElement.querySelector("[role=group]"),l=e(a);return{id:s,title:o,children:l}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function I0(e){let t=e.target,i=t.textContent==Wn;t.textContent=i?Ph:Wn;let n=t.parentNode;t.setAttribute("aria-expanded",i?"true":"false"),n.setAttribute("aria-expanded",i?"true":"false");let r=n.firstChild;for(;r;){if(r.nodeType===1){let s=r,o=s.getAttribute("data-adapt-class");if(o==="toc-container"){if(s.setAttribute("aria-hidden",i?"false":"true"),s.firstChild){r=s.firstChild;continue}}else if(o==="toc-node"&&(s.style.height=i?"auto":"0px",s.children.length>=2&&(s.children[1].tabIndex=i?0:-1),s.children.length>=3&&(s.children[0].tabIndex=i?0:-1,!i))){let a=s.children[0];if(a.textContent==Ph){a.textContent=Wn,a.setAttribute("aria-expanded","false"),s.setAttribute("aria-expanded","false"),r=s.children[2];continue}}}for(;!r.nextSibling&&r.parentNode!==n;)r=r.parentNode;r=r.nextSibling}e.stopPropagation()}var Th=class extends E0{constructor(){super(null),c(this,"plainXMLStore"),c(this,"jsonStore"),c(this,"opfByURL",{}),c(this,"primaryOPFByEPubURL",{}),c(this,"deobfuscators",{}),c(this,"documents",{}),this.fontDeobfuscator=this.makeDeobfuscatorFactory(),this.plainXMLStore=w0(),this.jsonStore=Sg()}makeDeobfuscatorFactory(){return e=>this.deobfuscators[e]}loadAsPlainXML(e,t,i){return this.plainXMLStore.load(e,t,i)}startLoadingAsPlainXML(e){this.plainXMLStore.fetch(e)}loadAsJSON(e,t,i){return this.jsonStore.load(e,t,i)}loadPubDoc(e){let t=O("loadPubDoc");return ys(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}$.error(`Failed to fetch a source document from ${e} (${i.status}${i.statusText?" "+i.statusText:""})`),t.finish(null)});else if(!i.status&&!i.responseXML&&!i.responseText&&!i.responseBlob&&!i.contentType&&/\/[^/.]+(?:[#?]|$)/.test(e)&&(e=e.replace(/([#?]|$)/,"/$1")),i.contentType=="application/oebps-package+xml"||/\.opf(?:[#?]|$)/.test(e)){let[,n,r]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(n,r).thenFinish(t)}else i.contentType=="application/ld+json"||i.contentType=="application/webpub+json"||i.contentType=="application/audiobook+json"||i.contentType=="application/json"||/\.json(?:ld)?(?:[#?]|$)/.test(e)?this.loadAsJSON(e,!0).then(n=>{if(!n){this.reportLoadError(e),t.finish(null);return}let r=new jr(this,e);r.initWithWebPubManifest(n,void 0,e).then(()=>{t.finish(r)})}):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}$.error(`Failed to load ${e}.`),t.finish(null)})})}),t.result()}loadEPUBDoc(e){let t=O("loadEPUBDoc");e.endsWith("/")||(e=e+"/"),this.startLoadingAsPlainXML(e+"META-INF/encryption.xml");let i=e+"META-INF/container.xml";return this.loadAsPlainXML(i).then(n=>{if(n){let r=n.doc().child("container").child("rootfiles").child("rootfile").attribute("full-path");for(let s of r)if(s){this.loadOPF(e,s).thenFinish(t);return}}t.finish(null)}),t.result()}loadOPF(e,t){let i=e+t,n=this.opfByURL[i];if(n)return N(n);let r=O("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new jr(this,e),this.opfByURL[i]=n,this.primaryOPFByEPubURL[e]=n,this.plainXMLStore.resources[e+"META-INF/container.xml"]?this.loadAsPlainXML(e+"META-INF/encryption.xml").then(o=>{n.initWithXMLDoc(s,o).then(()=>{r.finish(n)})}):n.initWithXMLDoc(s,null).then(()=>{r.finish(n)})):this.reportLoadError(i)}),r.result()}loadWebPub(e){let t=O("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new jr(this,e),s=n.querySelector("link[rel='publication'],link[rel='manifest'][type='application/webpub+json']");if(s){let o=s.getAttribute("href");if(/^#/.test(o)){let a=ha(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Pe(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(l=>{r.initWithWebPubManifest(l,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&Ja(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=O("EPUBDocStore.load"),n=Wt(e);return(this.documents[n]=this.parseOPSResource({status:200,statusText:"",url:n,contentType:t.contentType,responseText:null,responseXML:t,responseBlob:null})).thenFinish(i),i.result()}reportLoadError(e){let t=n=>n.replace(/([^:/?#]|^)[/?#].*/,"$1"),i=()=>{let n=t(e);return!(n===t(on)||Object.keys(this.resources).find(r=>this.resources[r]&&t(r)===n)||!/^https?:?\/\/[^/]/.test(e)||/\.(xhtml|xht|xml|opf)$/i.test(e))};e.startsWith("data:")?$.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&on.startsWith("https:")?$.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?$.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):$.error(`Failed to load ${e}. The target resource is invalid.`)}load(e){let t=Wt(e),i=this.documents[t];if(i)return i.isPending()?i:N(i.get());{let n=O("EPUBDocStore.load");return i=super.load(t,!0,`Failed to fetch a source document from ${t}`),i.then(r=>{r?n.finish(r):this.reportLoadError(t)}),n.result()}}processViewportMeta(e){let t=e.getAttribute("content");if(!t)return"";let i={},n;for(;(n=t.match(/^,?\s*([-A-Za-z_.][-A-Za-z_0-9.]*)\s*=\s*([-+A-Za-z_0-9.]*)\s*/))!=null;)t=t.substr(n[0].length),i[n[1]]=n[2];let r=i.width-0,s=i.height-0;if(r&&s){let o=!!Object.values(this.primaryOPFByEPubURL).find(a=>a.prePaginated);return`@-epubx-viewport{width:${r}px;height:${s}px;}`+(o?`@page{size:${r}px ${s}px;margin:0;}`:"@page{margin:0;}")}return""}},Ih=class{constructor(){c(this,"id",null),c(this,"src",""),c(this,"mediaType",null),c(this,"title",null),c(this,"itemRefElement",null),c(this,"spineIndex",-1),c(this,"compressedSize",0),c(this,"compressed",null),c(this,"epage",0),c(this,"epageCount",0),c(this,"startPage",null),c(this,"skipPagesBefore",null),c(this,"itemProperties"),this.itemProperties=$p}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Pe(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=Kp(i.split(/\s+/)))}initWithParam(e){this.spineIndex=e.index,this.id=`item${e.index+1}`,this.src=e.url,this.startPage=e.startPage,this.skipPagesBefore=e.skipPagesBefore}};function A0(e){return e.id}function R0(e){return t=>{let i=O("deobfuscator");return F0("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);bg(r).then(o=>{let a=new DataView(o);for(let l=0;l<a.byteLength;l++){let h=a.getUint8(l);h^=n[l%20],a.setUint8(l,h)}i.finish(Xu([a,s]))})}),i.result()}}function F0(e,t){let i=O("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var ii={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"},Ln="http://idpf.org/epub/vocab/package/meta/#",Me={language:`${ii.dcterms}language`,title:`${ii.dcterms}title`,creator:`${ii.dcterms}creator`,layout:`${ii.rendition}layout`,titleType:`${Ln}title-type`,displaySeq:`${Ln}display-seq`,alternateScript:`${Ln}alternate-script`,role:`${Ln}role`};function L0(e,t){let i={};return(n,r)=>{var s,o,a,l,h,u;let d,p,f=n.r||i,m=r.r||i;if(e==Me.title&&(d=((s=f[Me.titleType])==null?void 0:s[0].v)=="main",p=((o=m[Me.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let g=parseInt((a=f[Me.displaySeq])==null?void 0:a[0].v,10);isNaN(g)&&(g=Number.MAX_VALUE);let w=parseInt((l=m[Me.displaySeq])==null?void 0:l[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),g!=w?g-w:e!=Me.language&&t&&(d=((h=f[Me.language]||f[Me.alternateScript])==null?void 0:h[0].v)==t,p=((u=m[Me.language]||m[Me.alternateScript])==null?void 0:u[0].v)==t,d!=p)?d?-1:1:n.o-r.o}}function O0(e,t){let i;if(!t)i=ii;else{i={};for(let p in ii)i[p]=ii[p];let d;for(;(d=t.match(/^\s*([A-Z_a-z\u007F-\uFFFF][-.A-Z_a-z0-9\u007F-\uFFFF]*):\s*(\S+)/))!=null;)t=t.substr(d[0].length),i[d[1]]=d[2]}let n=d=>{if(d){let p=d.match(/^\s*(([^:]*):)?(\S+)\s*$/);if(p){let f=p[2]?i[p[2]]:Ln;if(f)return f+p[3]}}return null},r=1,s=e.childElements().forEachNonNull(d=>{if(d.localName=="meta"){let p=n(d.getAttribute("property"));if(p)return{name:p,value:d.textContent,id:d.getAttribute("id"),order:r++,refines:d.getAttribute("refines"),lang:null,scheme:n(d.getAttribute("scheme")),role:null}}else if(d.namespaceURI=="http://purl.org/dc/elements/1.1/")return{name:ii.dcterms+d.localName,order:r++,lang:d.getAttribute("xml:lang"),value:d.textContent,id:d.getAttribute("id"),refines:null,scheme:null,role:d.getAttribute("role")||d.getAttribute("opf:role")};return null}),o=Fs(s,d=>d.refines),a=d=>Zp(d,(p,f)=>p.map(m=>{let g={v:m.value,o:m.order};m.scheme&&(g.s=m.scheme);let w=o[`#${m.id}`]||[];if(w.length||m.lang||m.role){m.lang&&w.push({name:Me.language,value:m.lang,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null}),m.role&&w.push({name:Me.role,value:m.role,lang:null,id:null,refines:m.id,scheme:null,order:m.order,role:null});let v=Fs(w,y=>y.name);g.r=a(v)}return g})),l=a(Fs(s,d=>d.refines?null:d.name)),h=null;l[Me.language]&&(h=l[Me.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(L0(p,h));for(let m=0;m<f.length;m++){let g=f[m].r;g&&u(g)}}};return u(l),l}function B0(){let e=window.MathJax;return e?e.Hub:null}var Ah={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Js="viv-id-",jr=class{constructor(e,t){this.store=e,this.pubURL=t,c(this,"opfXML",null),c(this,"encXML",null),c(this,"items",null),c(this,"spine",null),c(this,"itemMap",null),c(this,"itemMapByPath",null),c(this,"uid",null),c(this,"bindings",{}),c(this,"lang",null),c(this,"epageCount",0),c(this,"prePaginated",!1),c(this,"epageIsRenderedPage",!0),c(this,"epageCountCallback",null),c(this,"metadata",{}),c(this,"toc",null),c(this,"cover",null),c(this,"fallbackMap",{}),c(this,"pageProgression",null),c(this,"documentURLTransformer"),this.documentURLTransformer=this.createDocumentURLTransformer()}createDocumentURLTransformer(){let e=this;class t{transformFragment(n,r){let s=r+(n?`#${n}`:"");return Js+Yh(s,":")}transformURL(n,r){let s=n.match(/^([^#]*)#?(.*)$/);if(s){let o=s[1]||r.replace(/\?viv-toc-box$/,""),a=decodeURIComponent(s[2]);if(o&&e.spine.some(l=>l.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(Js)===0&&(n=n.substring(Js.length));let r=Yp(n,":").match(/^([^#]*)#?(.*)$/);return r?[r[1],r[2]]:[]}}return new t}getMetadata(){return this.metadata}getPathFromURL(e){if(e.startsWith("data:"))return e===this.pubURL?"":e;if(this.pubURL){let t=Pe("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let l=e.getElement(`${e.url}#${n}`);l&&(this.uid=l.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(l=>{let h=new Ih,u=l;h.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!Ah[h.mediaType]&&(r[h.src]=d),!this.toc&&h.itemProperties.nav&&(this.toc=h),!this.cover&&h.itemProperties["cover-image"]&&(this.cover=h),h}),this.itemMap=hl(this.items,A0),this.itemMapByPath=hl(this.items,l=>this.getPathFromURL(l.src));for(let l in r){let h=l;for(;;){let u=this.itemMap[r[h]];if(!u)break;if(Ah[u.mediaType]){this.fallbackMap[l]=u.src;break}h=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((l,h)=>{let u=l,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=h),p});let s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=Vh(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(Nh.withChild("EncryptionMethod",Nh.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let l=0;l<a.length;l++){let h=a[l].getAttribute("handler"),u=a[l].getAttribute("media-type");u&&h&&this.itemMap[h]&&(this.bindings[u]=this.itemMap[h].src)}if(this.metadata=O0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Me.language]&&(this.lang=this.metadata[Me.language][0].v),this.metadata[Me.layout]&&(this.prePaginated=this.metadata[Me.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let l=R0(this.uid);for(let h=0;h<o.length;h++)this.store.deobfuscators[this.pubURL+o[h]]=l}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=O("countEPages");return n.loopWithFrame(r=>{if(i===this.spine.length){r.breakLoop();return}let s=this.spine[i++];s.epage=t,this.store.load(s.src).then(o=>{let a=1800,l=o.lang||this.lang;l&&l.match(/^(ja|ko|zh)/)&&(a/=3),s.epageCount=Math.ceil(o.getTotalOffset()/a),t+=s.epageCount,this.epageCount=t,this.epageCountCallback&&this.epageCountCallback(this.epageCount),r.continueLoop()})}).thenFinish(n),n.result()}initWithChapters(e,t){this.itemMap={},this.itemMapByPath={},this.items=[],this.spine=this.items;let i=this.opfXML=new ip(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Ih;r.initWithParam(n),r.id;let s=i.document.createElement("itemref");s.setAttribute("idref",r.id),i.root.appendChild(s),r.itemRefElement=s,this.itemMap[r.id]=r;let o=this.getPathFromURL(n.url);o==null&&(o=n.url),this.itemMapByPath[o]=r,this.items.push(r)}),t?this.store.addDocument(e[0].url,t):N(null)}initWithWebPubManifest(e,t,i){var n,r,s,o;e.readingProgression&&(this.pageProgression=e.readingProgression),this.metadata===void 0&&(this.metadata={});let a=e.name||((n=e.metadata)==null?void 0:n.title)||t?.title;a&&(this.metadata[Me.title]=(Array.isArray(a)?a:[a]).map(g=>{var w;return{v:(w=g.value)!=null?w:g}}));let l=e.author||e.creator||((r=e.metadata)==null?void 0:r.author)||Array.from((s=t?.querySelectorAll("meta[name='author'], meta[name='DC.Creator']"))!=null?s:[]).map(g=>g.content);l&&l.length!==0&&(this.metadata[Me.creator]=(Array.isArray(l)?l:[l]).map(g=>{var w;return{v:(w=g.name)!=null?w:g}}));let h=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");h&&(this.metadata[Me.language]=(Array.isArray(h)?h:[h]).map(g=>({v:g})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let g of P0(t)){let w=g.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let v=Wt(Pe(w,this.pubURL)),y=this.getPathFromURL(v),C=y!==null?encodeURI(y):v;e.readingOrder.indexOf(C)==-1&&e.readingOrder.push(C)}}let d=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(g=>{g instanceof Array&&g.forEach(w=>{let v=g===e.readingOrder,y=typeof w=="string"?w:w.url||w.href,C=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(v||C==="text/html"||C==="application/xhtml+xml"||!C&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(y)){let E=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,A={url:Pe(jn(y),E),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=A.index),d.push(A)}})});let m=O("initWithWebPubManifest");return this.initWithChapters(d).then(()=>{var g,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(g=this.items)==null?void 0:g[0]:this.itemMapByPath[u]);let v=(w=e.readingOrder)==null?void 0:w.length;v&&v<this.items.length&&this.items.splice(v),m.finish(!0)}),m.result()}getCFI(e,t){let i=this.spine[e],n=O("getCFI");return this.store.load(i.src).then(r=>{let s=r.getNodeByOffset(t),o=null;if(s){let a=r.getNodeOffset(s,0,!1),l=t-a,h=new gl;h.prependPathFromNode(s,l,!1,null),i.itemRefElement&&h.prependPathFromNode(i.itemRefElement,0,!1,null),o=h.toString()}n.finish(o)}),n.result()}resolveFragment(e){return an("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new gl;i.fromString(e);let n;if(this.opfXML){let r=i.navigate(this.opfXML.document);if(r.node.nodeType!=1||r.after||!r.ref){t.finish(null);return}let s=r.node,o=s.getAttribute("idref");if(s.localName!="itemref"||!o||!this.itemMap[o]){t.finish(null);return}n=this.itemMap[o],i=r.ref}else n=this.spine[0];this.store.load(n.src).then(r=>{let s=i.navigate(r.document),o=r.getNodeOffset(s.node,s.offset,s.after);t.finish({spineIndex:n.spineIndex,offsetInItem:o,pageIndex:-1})})},(t,i)=>{$.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return an("resolveEPage",t=>{if(e<=0){t.finish({spineIndex:0,offsetInItem:0,pageIndex:-1});return}if(this.epageIsRenderedPage){let r=this.spine.findIndex(a=>a.epage==0&&a.epageCount==0||a.epage<=e&&a.epage+a.epageCount>e);r==-1&&(r=this.spine.length-1);let s=this.spine[r];(!s||s.epageCount==0)&&(s=this.spine[--r]);let o=Math.floor(e-s.epage);t.finish({spineIndex:r,offsetInItem:-1,pageIndex:o});return}let i=ai(this.spine.length,r=>{let s=this.spine[r];return s.epage+s.epageCount>e});i==this.spine.length&&i--;let n=this.spine[i];this.store.load(n.src).then(r=>{e-=n.epage,e>n.epageCount&&(e=n.epageCount);let s=0;if(e>0){let o=r.getTotalOffset();s=Math.round(o*e/n.epageCount),s==o&&s--}t.finish({spineIndex:i,offsetInItem:s,pageIndex:-1})})},(t,i)=>{$.warn(i,"Cannot resolve epage:",e),t.finish(null)})}getEPageFromPosition(e){let t=this.spine[e.spineIndex];if(this.epageIsRenderedPage){let n=t.epage+e.pageIndex;return N(n)}if(e.offsetInItem<=0)return N(t.epage);let i=O("getEPage");return this.store.load(t.src).then(n=>{let r=n.getTotalOffset(),s=Math.min(r,e.offsetInItem);i.finish(t.epage+s*t.epageCount/r)}),i.result()}},Er=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),M0=class{constructor(e,t,i,n,r){this.opf=e,this.viewport=t,this.fontMapper=i,this.pageSheetSizeReporter=r,c(this,"spineItems",[]),c(this,"spineItemLoadingContinuations",[]),c(this,"pref"),c(this,"clientLayout"),c(this,"counterStore"),c(this,"cmykStore"),c(this,"tocAutohide",!1),c(this,"tocVisible",!1),c(this,"tocView"),this.pref=eu(n),this.clientLayout=new g0(t),this.counterStore=new Uf(e.documentURLTransformer),this.cmykStore=new Pu}getPage(e){let t=this.spineItems[e.spineIndex];return t?t.pages[e.pageIndex]:null}waitForPreviousSpines(e,t){if(t||e===0)return N(!0);let i=O("waitForPreviousSpines");return i.loopWithFrame(n=>{let r=!0;for(let s=0;s<e;s++){let o=this.spineItems[s];if(!o||!o.complete){r=!1;break}}r?n.breakLoop():i.sleep(100).then(()=>{n.continueLoop()})}).then(()=>{i.finish(!0)}),i.result()}getCurrentPageProgression(e){if(this.opf.pageProgression)return this.opf.pageProgression;{let t=this.spineItems[e?e.spineIndex:0];return t?t.instance.pageProgression:null}}finishPageContainer(e,t,i){t.container.style.display="none",t.container.style.visibility="visible",t.container.style.position="",t.container.style.top="",t.container.style.left="",t.container.setAttribute("data-vivliostyle-page-side",t.side);let n=e.pages[i];if(t.isFirstPage=e.item.spineIndex==0&&i==0,e.pages[i]=t,this.opf.epageIsRenderedPage){if(i==0&&e.item.spineIndex>0){let r=this.opf.spine[e.item.spineIndex-1];e.item.epage=r.epage+r.epageCount}e.item.epageCount=e.pages.length,this.opf.epageCount=this.opf.spine.reduce((r,s)=>r+s.epageCount,0),this.opf.epageCountCallback&&this.opf.epageCountCallback(this.opf.epageCount)}if(n)e.instance.viewport.contentContainer.replaceChild(t.container,n.container),n.dispatchEvent({type:"replaced",target:null,currentTarget:null,preventDefault:null,newPage:t});else{let r=null;if(i>0)r=e.pages[i-1].container.nextElementSibling;else for(let s=e.item.spineIndex+1;s<this.spineItems.length;s++){let o=this.spineItems[s];if(o&&o.pages[0]){r=o.pages[0].container;break}}e.instance.viewport.contentContainer.insertBefore(t.container,r)}this.pageSheetSizeReporter({width:e.instance.pageSheetWidth,height:e.instance.pageSheetHeight},e.instance.pageSheetSize,e.item.spineIndex,e.instance.pageNumberOffset+i)}renderSinglePage(e,t){let i=O("renderSinglePage"),n=e.pages[t?t.page:0],r=this.makePage(e,t);return n&&(r.pageType=n.pageType),e.instance.layoutNextPage(r,t).then(s=>{t=s;let o=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,r,o),this.counterStore.finishPage(r.spineIndex,o);let a=null;if(t){let l=e.layoutPositions[t.page];e.layoutPositions[t.page]=t,l&&e.pages[t.page]&&(t.isSamePosition(l)||(a=this.renderSinglePage(e,t)))}a||(a=N(!0)),a.then(()=>{let l=this.counterStore.getUnresolvedRefsToPage(r),h=0;i.loopWithFrame(u=>{if(h++,h>l.length){u.breakLoop();return}let d=l[h-1];if(d.refs=d.refs.filter(p=>!p.isResolved()),d.refs.length===0){u.continueLoop();return}this.getPageViewItem(d.spineIndex).then(p=>{if(!p){u.continueLoop();return}let{currentPageType:f,previousPageType:m}=p.instance.styler.cascade,g=p.instance.scopes;p.instance.scopes={},this.counterStore.pushPageCounters(d.pageCounters),this.counterStore.pushReferencesToSolve(d.refs);let w=p.layoutPositions[d.pageIndex];this.renderSinglePage(p,w).then(v=>{p.instance.styler.cascade.currentPageType=f,p.instance.styler.cascade.previousPageType=m,p.instance.scopes=g,this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve();let y=v.pageAndPosition.position;y.spineIndex===r.spineIndex&&y.pageIndex===o&&(r=v.pageAndPosition.page),u.continueLoop()})})}).then(()=>{r.container.parentElement||(r=e.pages[o]),r.isLastPage=!t&&e.item.spineIndex===this.opf.spine.length-1,r.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),r.container.setAttribute("data-vivliostyle-page-index",o),r.container.setAttribute("data-vivliostyle-spine-index",r.spineIndex),i.finish({pageAndPosition:Er(r,o),nextLayoutPosition:t})})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=ai(t.layoutPositions.length,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.layoutPositions.length-1:i=Number.POSITIVE_INFINITY:i=r-1}else i===Number.POSITIVE_INFINITY&&e.offsetInItem!==-1&&(n=e.offsetInItem);return{spineIndex:e.spineIndex,pageIndex:i,offsetInItem:n}}findPage(e,t){let i=O("findPage");return this.waitForPreviousSpines(e.spineIndex,t).then(()=>{this.getPageViewItem(e.spineIndex).then(n=>{if(!n){i.finish(null);return}let r=null,s;i.loopWithFrame(o=>{let a=this.normalizeSeekPosition(e,n);s=a.pageIndex,r=n.pages[s],r?o.breakLoop():n.complete?(s=n.layoutPositions.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(l=>{l&&(r=l.page,s=l.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(Er(r,s))})})}),i.result()}renderPage(e){let t=O("renderPage");return this.getPageViewItem(e.spineIndex).then(i=>{if(!i){t.finish(null);return}let n=this.normalizeSeekPosition(e,i),r=n.pageIndex,s=n.offsetInItem,o=i.pages[r];if(o){t.finish(Er(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.layoutPositions.length-1,a.breakLoop();return}let l=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,l).then(h=>{let u=h.pageAndPosition.page;if(l=h.nextLayoutPosition,l){if(s>=0&&i.instance.getPosition(l)>s){o=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,r=h.pageAndPosition.position.pageIndex,i.complete=!0,a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(Er(o,r));return}this.renderSinglePage(i,a).then(l=>{l.nextLayoutPosition||(i.complete=!0),t.finish(l.pageAndPosition)})})}),t.result()}renderAllPages(){let e=O("renderAllPages");return this.renderPagesUpto({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},!1).then(t=>{e.loopWithFrame(i=>{this.spineItems.some(n=>n?.pages.some(r=>r?.fetchers.some(s=>!s.arrived)))?e.sleep(100).then(()=>{i.continueLoop()}):i.breakLoop()}).then(()=>{e.finish(t)})}),e.result()}renderPagesUpto(e,t){let i=O("renderPagesUpto");e||(e={spineIndex:0,pageIndex:0,offsetInItem:0});let n=e.spineIndex,r=e.pageIndex,s=0;t&&(s=n);let o;return i.loopWithFrame(a=>{let l={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(l).then(h=>{o=h,++s>n?a.breakLoop():a.continueLoop()})}).then(()=>{i.finish(o)}),i.result()}firstPage(e,t){return this.findPage({spineIndex:0,pageIndex:0,offsetInItem:-1},t)}lastPage(e,t){return this.findPage({spineIndex:this.opf.spine.length-1,pageIndex:Number.POSITIVE_INFINITY,offsetInItem:-1},t)}nextPage(e,t){let i=e.spineIndex,n=e.pageIndex,r=O("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.layoutPositions.length-1){if(i>=this.opf.spine.length-1){r.finish(null);return}i++,n=0;let o=this.spineItems[i],a=o&&o.pages[0],l=s.pages[s.pages.length-1];a&&l&&a.side==l.side&&(o.pages.forEach(h=>{h.container&&h.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(r)}),r.result()}previousPage(e,t){let i=e.spineIndex,n=e.pageIndex;if(n==0){if(i==0)return N(null);i--,n=Number.POSITIVE_INFINITY}else n--;return this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t)}isRectoPage(e,t){let i=e.side==="left",n=this.getCurrentPageProgression(t)==="ltr";return!i&&n||i&&!n}getSpread(e,t){let i=this.getPage(e);if(!i)return N({left:null,right:null});let n=O("getSpread"),r=i.side==="left",s;return this.isRectoPage(i,e)?s=this.previousPage(e,t):s=this.nextPage(e,t),s.then(o=>{let a=this.getPage(e),l=o&&o.page;l&&l.side===a.side&&(l=null),r?n.finish({left:a,right:l}):n.finish({left:l,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),r=this.nextPage(e,t);return n?r:r.thenAsync(s=>{if(s){if(s.page.side===i.side)return r;let o=this.nextPage(s.position,t);return o.thenAsync(a=>a?o:r)}else return N(null)})}previousSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),r=this.previousPage(e,t),s=i.container.previousElementSibling;return n?r.thenAsync(o=>o?o.page.side===i.side||o.page.container!==s?r:this.previousPage(o.position,t):N(null)):r}navigateToEPage(e,t,i){let n=O("navigateToEPage");return this.opf.resolveEPage(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateToFragment(e,t,i){let n=O("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}navigateTo(e,t,i){$.debug("Navigate to",e);let n=this.opf.getPathFromURL(Wt(e));if(!n){if(this.opf.opfXML&&e.match(/^#epubcfi\(/))n=this.opf.getPathFromURL(this.opf.opfXML.url);else if(e.charAt(0)==="#"){let o=this.opf.documentURLTransformer.restoreURL(e);this.opf.opfXML?(n=this.opf.getPathFromURL(o[0]),n==null&&(n=o[0])):n=o[0],e=o[0]+(o[1]?`#${o[1]}`:"")}if(n==null)return N(null)}let r=this.opf.itemMapByPath[n];if(!r){if(this.opf.opfXML&&n==this.opf.getPathFromURL(this.opf.opfXML.url)){let o=e.indexOf("#");if(o>=0)return this.navigateToFragment(e.substr(o+1),t,i)}return N(null)}let s=O("navigateTo");return this.waitForPreviousSpines(r.spineIndex,i).then(()=>{this.getPageViewItem(r.spineIndex).then(o=>{if(!o){s.finish(null);return}let a=o.xmldoc.getElement(e);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:a?o.xmldoc.getElementOffset(a):0},i).thenFinish(s)})}),s.result()}makePage(e,t){let i=e.instance.viewport,n=i.document.createElement("div");n.setAttribute("data-vivliostyle-page-container","true"),n.role="presentation",Gn||(n.style.visibility="hidden"),i.layoutBox.appendChild(n);let r=i.document.createElement("div");r.setAttribute("data-vivliostyle-bleed-box","true"),r.role="presentation",n.appendChild(r);let s=new ac(n,r);if(s.spineIndex=e.item.spineIndex,s.position=t,s.offset=e.instance.getPosition(t),s.offset===0&&!(e.instance.blankPageAtStart&&e.pages.length===0)){let o=this.opf.documentURLTransformer.transformFragment("",e.item.src);r.setAttribute("id",o),s.registerElementWithId(r,o)}if(i!==this.viewport){let o=tu(this.viewport.width,this.viewport.height,i.width,i.height),a=gn(null,new Ft(o,null),"");s.delayedItems.push(new Sa(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Pe(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let l=this.opf.itemMapByPath[a];l&&(o=l.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let l=al(r),h=al(o),u=new oi;u.append(a),u.append("?src="),u.append(l),u.append("&type="),u.append(h);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let m=f;if(m.localName=="param"&&m.namespaceURI=="http://www.w3.org/1999/xhtml"){let g=m.getAttribute("name"),w=m.getAttribute("value");g&&w&&(u.append("&"),u.append(encodeURIComponent(g)),u.append("="),u.append(encodeURIComponent(w)))}}s.setAttribute("src",u.toString());let d=t.getAttribute("width");d&&s.setAttribute("width",d);let p=t.getAttribute("height");p&&s.setAttribute("height",p)}}}return s||(s=this.viewport.document.createElement("object"),r&&s.setAttribute("data",r),s.setAttribute("data-adapt-process-children","true")),N(s)}makeMathJaxView(e,t,i,n){let r=B0();if(r){let s=i.ownerDocument,o=s.createElement("span");i.appendChild(o);let a=s.importNode(t,!0);this.resolveURLsInMathML(a,e),o.appendChild(a);let l=r.queue;l.Push(["Typeset",r,o]);let h=O("makeMathJaxView"),u=h.suspend();return l.Push(()=>{u.schedule(o)}),h.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Pe(n.nodeValue,t.url);n.namespaceURI?e.setAttributeNS(n.namespaceURI,n.name,r):e.setAttribute(n.name,r)}}e.firstChild&&this.resolveURLsInMathML(e.firstChild,t),e.nextSibling&&this.resolveURLsInMathML(e.nextSibling,t)}}makeCustomRenderer(e){return(t,i,n)=>t.localName=="object"&&t.namespaceURI=="http://www.w3.org/1999/xhtml"?this.makeObjectView(e,t,i,n):t.namespaceURI=="http://www.w3.org/1998/Math/MathML"?this.makeMathJaxView(e,t,i,n):t.dataset&&t.dataset.mathTypeset=="true"?this.makeMathJaxView(e,t,i,n):N(null)}getPageViewItem(e){if(e===-1||e>=this.opf.spine.length)return N(null);let t=this.spineItems[e];if(t)return N(t);let i=O("getPageViewItem"),n=this.spineItemLoadingContinuations[e];if(n){let o=i.suspend();return n.push(o),i.result()}else n=this.spineItemLoadingContinuations[e]=[];let r=this.opf.spine[e],s=this.opf.store;return s.load(r.src).then(o=>{var a;let l=r.itemRefElement.getAttribute("properties");l&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",l),r.title=o.document.title;let h=s.getStyleForDoc(o),u=this.makeCustomRenderer(o),d=this.viewport,p=h.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new ds(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,m=this.spineItems[e-1],g,w;if(r.startPage!==null)g=r.startPage-1,w=g;else{if(e>0&&(!m||!m.complete))g=r.epage||e,!this.opf.prePaginated&&g%2==(f?1:0)&&g++,w=g;else{g=m?m.instance.pageNumberOffset+m.pages.length:0;let C=this.counterStore.currentPageCounters.page;w=!C||!C.length?g:C[C.length-1]}r.skipPagesBefore!==null&&(g+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let v=new Za(h,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,g,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);v.pref=this.pref;let y=this.opf.metadata&&this.opf.metadata[Me.title];v.pubTitle=y&&y[0]&&y[0].v||"",v.docTitle=r.title||"",v.init().then(()=>{!this.opf.pageProgression&&v.pageProgression&&(this.opf.pageProgression=v.pageProgression),t={item:r,xmldoc:o,instance:v,layoutPositions:[null],pages:[],complete:!1},this.spineItems[e]=t,i.finish(t),n.forEach(C=>{C.schedule(t)})})}),i.result()}removeRenderedPages(){let e=this.spineItems;for(let t of e)t&&t.pages.splice(0);this.viewport.clear()}hasAutoSizedPages(){let e=this.spineItems;for(let t of e)if(t){let i=t.pages;for(let n of i)if(n.isAutoPageWidth&&n.isAutoPageHeight)return!0}return!1}hasPages(){return this.spineItems.some(e=>e&&e.pages.length>0)}showTOC(e){let t=this.opf,i=t.toc;if(this.tocAutohide=e,!i)return N(null);if(this.tocVisible=!0,this.tocView&&this.tocView.page)return this.tocView.page.container.style.visibility="visible",this.tocView.page.container.setAttribute("aria-hidden","false"),N(this.tocView.page);let n=O("showTOC");this.tocView||(this.tocView=new T0(t.store,i.src,t.lang,this.clientLayout,this.fontMapper,this.pref,this,t.fallbackMap,t.documentURLTransformer,this.counterStore,this.cmykStore));let r=this.viewport,s=Math.min(344,Math.round(.67*r.width)-16),o=r.height-6,a=r.document.createElement("div");return r.root.appendChild(a),Gn||(a.style.visibility="hidden"),a.style.width=`${s+16}px`,a.style.maxHeight=`${o}px`,a.setAttribute("data-vivliostyle-toc-box","true"),a.setAttribute("role","navigation"),this.tocView.showTOC(a,r,s,o,this.viewport.fontSize).then(l=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(l)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},Rh="data-vivliostyle-viewer-status",_0="data-vivliostyle-spread-view",op=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(op||{}),z0=class{constructor(e,t,i,n){this.window=e,this.viewportElement=t,this.instanceId=i,this.callbackFn=n,c(this,"fontMapper"),c(this,"kick"),c(this,"sendCommand"),c(this,"resizeListener"),c(this,"hyperlinkListener"),c(this,"pageRuleStyleElement"),c(this,"pageSheetSizeAlreadySet",!1),c(this,"renderTask",null),c(this,"actions"),c(this,"readyState"),c(this,"packageURL"),c(this,"opf"),c(this,"touchActive"),c(this,"touchX"),c(this,"touchY"),c(this,"needResize"),c(this,"resized"),c(this,"needRefresh"),c(this,"viewportSize"),c(this,"currentPage"),c(this,"currentSpread"),c(this,"pagePosition"),c(this,"fontSize"),c(this,"zoom"),c(this,"fitToScreen"),c(this,"pageViewMode"),c(this,"waitForLoading"),c(this,"renderAllPages"),c(this,"pref"),c(this,"pageSizes"),c(this,"pixelRatio"),c(this,"pixelRatioLimit"),c(this,"viewport"),c(this,"opfView");let r=t.ownerDocument,s=(o,a)=>{let l=r.getElementById(o);return l||(l=r.createElement("style"),l.id=o,a&&(l.textContent=a),r.head.appendChild(l)),l};s("vivliostyle-viewport-screen-css",zu),s("vivliostyle-viewport-css",Du),s("vivliostyle-polyfill-css",Gu),t.setAttribute("data-vivliostyle-viewer-viewport",!0),Gn&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(Rh,"loading"),this.fontMapper=new Cb(r.head,t),this.init(),this.kick=()=>{},this.sendCommand=()=>{},this.resizeListener=()=>{this.needResize=!0,this.resized=!0,this.kick()},this.pageReplacedListener=this.pageReplacedListener.bind(this),this.hyperlinkListener=o=>{},this.pageRuleStyleElement=s("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=Qh(),this.pageSizes=[],this.pixelRatioLimit=jh==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=$h;$.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),$.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),$.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),$.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){this.readyState!==e&&(this.readyState=e,this.viewportElement.setAttribute(Rh,e),this.callback({t:"readystatechange"}))}loadPublication(e){pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.viewport=null;let s=O("loadPublication");return this.configure(e).then(()=>{let o=new Th;o.init(n,r).then(()=>{let a=Pe(jn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(l=>{l?(this.opf=l,this.render(i).then(()=>{s.finish(!0)})):s.finish(!1)})})}),s.result()}loadXML(e){pt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.viewport=null;let o=O("loadXML");return this.configure(e).then(()=>{let a=new Th;a.init(r,s).then(()=>{let l=t.map((h,u)=>({url:Pe(jn(h.url),this.window.location.href),index:u,startPage:h.startPage,skipPagesBefore:h.skipPagesBefore}));this.packageURL=l.map(h=>h.url),this.opf=new jr(a,""),this.opf.initWithChapters(l,i).then(()=>{this.render(n).then(()=>{o.finish(!0)})})})}),o.result()}render(e){this.cancelRenderingTask();let t;return e?t=this.opf.resolveFragment(e).thenAsync(i=>(this.pagePosition=i,N(!0))):t=N(!0),t.thenAsync(()=>(pt.registerEndTiming("beforeRender"),this.resize()))}resolveLength(e){let t=parseFloat(e),i=/[a-z]+$/,n;if(typeof e=="string"&&(n=e.match(i))){let r=n[0];if(r==="em"||r==="rem")return t*this.fontSize;let s=At[r];if(s)return t*s}return t}configure(e){if(typeof e.autoresize=="boolean"&&(e.autoresize?(this.viewportSize=null,this.window.addEventListener("resize",this.resizeListener,!1),this.needResize=!0):this.window.removeEventListener("resize",this.resizeListener,!1)),typeof e.fontSize=="number"){let t=e.fontSize;t>=5&&t<=72&&this.fontSize!=t&&(this.fontSize=t,this.needResize=!0)}if(typeof e.viewport=="object"&&e.viewport){let t=e.viewport,i={marginLeft:this.resolveLength(t["margin-left"])||0,marginRight:this.resolveLength(t["margin-right"])||0,marginTop:this.resolveLength(t["margin-top"])||0,marginBottom:this.resolveLength(t["margin-bottom"])||0,width:this.resolveLength(t.width)||0,height:this.resolveLength(t.height)||0};(i.width>=200||i.height>=200)&&(this.window.removeEventListener("resize",this.resizeListener,!1),this.viewportSize=i,this.needResize=!0)}if(typeof e.hyphenate=="boolean"&&(this.pref.hyphenate=e.hyphenate,this.needResize=!0),typeof e.horizontal=="boolean"&&(this.pref.horizontal=e.horizontal,this.needResize=!0),typeof e.nightMode=="boolean"&&(this.pref.nightMode=e.nightMode,this.needResize=!0),typeof e.lineHeight=="number"&&(this.pref.lineHeight=e.lineHeight,this.needResize=!0),typeof e.columnWidth=="number"&&(this.pref.columnWidth=e.columnWidth,this.needResize=!0),typeof e.fontFamily=="string"&&(this.pref.fontFamily=e.fontFamily,this.needResize=!0),typeof e.load=="boolean"&&(this.waitForLoading=e.load),typeof e.renderAllPages=="boolean"&&(this.renderAllPages=e.renderAllPages),typeof e.userAgentRootURL=="string"&&(rl(e.userAgentRootURL.replace(/resources\/?$/,"")),sl(e.userAgentRootURL)),typeof e.rootURL=="string"&&(rl(e.rootURL),sl(`${on}resources/`)),typeof e.pageViewMode=="string"&&e.pageViewMode!==this.pageViewMode&&(this.pageViewMode=e.pageViewMode,this.needResize=!0),typeof e.pageBorder=="number"&&e.pageBorder!==this.pref.pageBorder&&(this.viewport=null,this.pref.pageBorder=e.pageBorder,this.needResize=!0),typeof e.zoom=="number"&&e.zoom!==this.zoom&&(this.zoom=e.zoom,this.needRefresh=!0),typeof e.fitToScreen=="boolean"&&e.fitToScreen!==this.fitToScreen&&(this.fitToScreen=e.fitToScreen,this.needRefresh=!0),typeof e.defaultPaperSize=="object"&&typeof e.defaultPaperSize.width=="number"&&typeof e.defaultPaperSize.height=="number"&&(this.viewport=null,this.pref.defaultPaperSize=e.defaultPaperSize,this.needResize=!0),typeof e.allowScripts=="boolean"&&e.allowScripts!==Yt&&(s0(e.allowScripts),this.needResize=!0),typeof e.pixelRatio=="number"){let t=Math.min(e.pixelRatio,this.pixelRatioLimit);t!==this.pixelRatio&&(this.pixelRatio=t,this.needResize=!0)}return this.configurePlugins(e),N(!0)}configurePlugins(e){Rt("CONFIGURATION").forEach(t=>{let i=t(e);this.needResize=i.needResize||this.needResize,this.needRefresh=i.needRefresh||this.needRefresh})}pageReplacedListener(e){let t=this.currentPage,i=this.currentSpread,n=e.target;i?(i.left===n||i.right===n)&&this.showCurrent(e.newPage):t===e.target&&this.showCurrent(e.newPage)}forCurrentPages(e){let t=[];this.currentPage&&t.push(this.currentPage),this.currentSpread&&(t.push(this.currentSpread.left),t.push(this.currentSpread.right)),t.forEach(i=>{i&&e(i)})}removePageListeners(){this.forCurrentPages(e=>{e.removeEventListener("hyperlink",this.hyperlinkListener,!1),e.removeEventListener("replaced",this.pageReplacedListener,!1)})}hidePages(){this.removePageListeners(),this.forCurrentPages(e=>{T(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),T(e.container,"visibility","visible"),T(e.container,"display","block")}showPage(e){this.hidePages(),this.currentPage=e,e.container.style.marginLeft="",e.container.style.marginRight="",this.showSinglePage(e)}showSpread(e){if(this.hidePages(),this.currentSpread=e,e.left&&e.right){let t=parseFloat(e.left.container.style.width),i=parseFloat(e.right.container.style.width);t&&i&&t!==i&&(t<i?e.left.container.style.marginLeft=`${i-t}px`:e.right.container.style.marginRight=`${t-i}px`)}e.left&&(this.showSinglePage(e.left),e.right?e.left.container.removeAttribute("data-vivliostyle-unpaired-page"):e.left.container.setAttribute("data-vivliostyle-unpaired-page",!0)),e.right&&(this.showSinglePage(e.right),e.left?e.right.container.removeAttribute("data-vivliostyle-unpaired-page"):e.right.container.setAttribute("data-vivliostyle-unpaired-page",!0))}reportPosition(){let e=O("reportPosition");return this.pagePosition,this.opf.getCFI(this.pagePosition.spineIndex,this.pagePosition.offsetInItem).then(t=>{let i=this.currentPage;(this.waitForLoading&&i.fetchers.length>0?ws(i.fetchers):N(!0)).then(()=>{this.sendLocationNotification(i,t).thenFinish(e)})}),e.result()}createViewport(){let e=this.viewportElement;if(this.viewportSize){let t=this.viewportSize;return e.style.marginLeft=`${t.marginLeft}px`,e.style.marginRight=`${t.marginRight}px`,e.style.marginTop=`${t.marginTop}px`,e.style.marginBottom=`${t.marginBottom}px`,new ds(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new ds(this.window,this.fontSize,this.pixelRatio,e)}resolveSpreadView(e,t){switch(this.pageViewMode){case"singlePage":return!1;case"spread":return!0;case"autoSpread":default:return e!=null&&(e.width-this.pref.pageBorder)/e.height>=(t?t.width*2/t.height:1.45)&&(!!t||e.width>800)}}updateSpreadView(e){this.pref.spreadView=e,this.viewportElement.setAttribute(_0,e.toString())}sizeIsGood(){var e;let t=this.createViewport(),i=((e=this.opfView)==null?void 0:e.hasPages())&&!this.opfView.hasAutoSizedPages(),n=this.resolveSpreadView(t,this.resized&&i?this.pageSizes[0]:null);this.resized=!1;let r=this.pref.spreadView!==n;return this.updateSpreadView(n),this.pixelRatio&&this.opfView&&this.pixelRatio/this.window.devicePixelRatio!==this.opfView.clientLayout.scaleRatio||this.viewportSize||!this.viewport||this.viewport.fontSize!=this.fontSize?!1:!r&&t.width==this.viewport.width&&t.height==this.viewport.height||!r&&t.width==this.viewport.width&&t.height!=this.viewport.height&&/Android|iPhone|iPad|iPod/.test(navigator.userAgent)?!0:i?(this.viewport.width=t.width,this.viewport.height=t.height,this.needRefresh=!0,!0):!1}setPageSize(e,t,i,n){this.pageSizes[n]=e,this.setPageSizePageRules(t,i,n),n===0&&this.pageViewMode==="autoSpread"&&!this.opfView.hasAutoSizedPages()&&this.updateSpreadView(this.resolveSpreadView(this.viewport,e))}setPageSizePageRules(e,t,i){var n,r;if(this.pageRuleStyleElement&&(!this.pageSheetSizeAlreadySet||this.pageSizes[i].width!==((n=this.pageSizes[i-1])==null?void 0:n.width)||this.pageSizes[i].height!==((r=this.pageSizes[i-1])==null?void 0:r.height))){let o=function(m){let g=m*.75;return Math.ceil(g)};var s=o;let a=Math.max(...this.pageSizes.map(m=>m.width)),l=Math.max(...this.pageSizes.map(m=>m.height)),h=o(a),u=o(l),d=h*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${h}pt ${u}pt; margin: 0 ${-d}pt ${-p}pt 0;}`;this.pageRuleStyleElement.textContent=f,this.pageSheetSizeAlreadySet=!0}}removePageSizePageRules(){this.pageRuleStyleElement&&(this.pageRuleStyleElement.textContent="",this.pageSheetSizeAlreadySet=!1)}reset(){let e=!1,t=!1;this.opfView&&(e=this.opfView.tocVisible,t=this.opfView.tocAutohide,this.opfView.removeRenderedPages()),this.pageSizes=[],this.removePageSizePageRules(),this.viewport=this.createViewport(),this.viewport.resetZoom(),this.opfView=new M0(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this)),e&&this.sendCommand({a:"toc",v:"show",autohide:t})}showCurrent(e,t){this.needRefresh=!1,this.removePageListeners();let i=this.resolveSpreadView(this.viewport,e.dimensions);return i!==this.pref.spreadView&&this.updateSpreadView(i),i?this.opfView.getSpread(this.pagePosition,t).thenAsync(n=>!n.left&&!n.right?N(null):n.left&&n.right&&(!this.resolveSpreadView(this.viewport,n.left.dimensions)||!this.resolveSpreadView(this.viewport,n.right.dimensions))?(this.updateSpreadView(!1),this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null)):(this.showSpread(n),this.setSpreadZoom(n),this.currentPage=e.side==="left"?n.left:n.right,N(null))):(this.showPage(e),this.setPageZoom(e),this.currentPage=e,N(null))}setPageZoom(e){var t;let i=this.getAdjustedZoomFactor(e.dimensions);(t=this.viewport)==null||t.zoom(e.dimensions.width,e.dimensions.height,i)}setSpreadZoom(e){var t;let i=this.getSpreadDimensions(e);(t=this.viewport)==null||t.zoom(i.width,i.height,this.getAdjustedZoomFactor(i))}getAdjustedZoomFactor(e){return this.fitToScreen?this.calculateZoomFactorToFitInsideViewPort(e):this.zoom}getSpreadDimensions(e){let t=0,i=0;return e.left&&(t+=e.left.dimensions.width,i=e.left.dimensions.height),e.right&&(t+=e.right.dimensions.width,i=Math.max(i,e.right.dimensions.height)),e.left&&e.right&&(t+=this.pref.pageBorder*2,t+=Math.abs(e.left.dimensions.width-e.right.dimensions.width)),{width:t,height:i}}queryZoomFactor(e){if(!this.currentPage)throw new Error("no page exists.");switch(e){case"fit inside viewport":{let t;return this.pref.spreadView?(this.currentSpread,t=this.getSpreadDimensions(this.currentSpread)):t=this.currentPage.dimensions,this.calculateZoomFactorToFitInsideViewPort(t)}default:throw new Error(`unknown zoom type: ${e}`)}}calculateZoomFactorToFitInsideViewPort(e){if(!this.viewport)return this.zoom;let t=this.viewport.width/e.width,i=this.viewport.height/e.height;return Math.min(t,i)}cancelRenderingTask(){this.renderTask&&this.renderTask.interrupt(new Fh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=uo().getScheduler().run(()=>an("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,pt.registerStartTiming("render (resize)"),this.reset(),this.pagePosition&&(this.pagePosition.pageIndex==0&&this.pagePosition.offsetInItem==0||(this.pagePosition.pageIndex=-1)),this.opf.setEPageCountMode(this.renderAllPages),this.opfView.renderPagesUpto(this.pagePosition,!this.renderAllPages).then(i=>{if(!i){t.finish(!1);return}this.pagePosition=i.position,this.showCurrent(i.page,!0).then(()=>{this.setReadyState("interactive"),this.opf.countEPages(n=>{let r={t:"nav",epageCount:n,first:this.currentPage.isFirstPage,last:this.currentPage.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(r.epage=this.opf.spine[this.pagePosition.spineIndex].epage),this.callback(r)}).then(()=>{this.reportPosition().then(n=>{(this.renderAllPages?this.opfView.renderAllPages():N(null)).then(()=>{this.renderTask===e&&(this.renderTask=null),pt.registerEndTiming("render (resize)"),Yt&&ep(this.window)?h0(this.window).then(()=>{this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n)}):(this.renderAllPages&&this.setReadyState("complete"),this.callback({t:"loaded"}),t.finish(n))})})})})})},(t,i)=>{if(i instanceof Fh)pt.registerEndTiming("render (resize)"),$.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=O("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:e.isLastPage,metadata:this.opf.metadata,docTitle:this.opf.spine[e.spineIndex].title};return this.opf.getEPageFromPosition(this.pagePosition).then(r=>{n.epage=r,n.epageCount=this.opf.epageCount,t&&(n.cfi=t),this.callback(n),i.finish(!0)}),i.result()}getCurrentPageProgression(){return this.opfView?this.opfView.getCurrentPageProgression(this.pagePosition):null}moveTo(e){var t;let i;if(this.readyState!=="complete"&&e.where!=="next"&&this.setReadyState("loading"),typeof e.where=="string"){let r;switch(e.where){case"next":r=this.pref.spreadView?this.opfView.nextSpread:this.opfView.nextPage;break;case"previous":r=this.pref.spreadView?this.opfView.previousSpread:this.opfView.previousPage;break;case"last":r=this.opfView.lastPage;break;case"first":r=this.opfView.firstPage;break;default:return N(!0)}r&&(i=()=>r.call(this.opfView,this.pagePosition,!this.renderAllPages))}else if(typeof e.epage=="number"){let r=e.epage;i=()=>this.opfView.navigateToEPage(r,this.pagePosition,!this.renderAllPages)}else if(typeof e.url=="string"){let r=e.url;i=()=>this.opfView.navigateTo(r,this.pagePosition,!this.renderAllPages)}else if(typeof((t=e.position)==null?void 0:t.spineIndex)=="number"){let r=e.position;i=()=>this.opfView.findPage(r,!this.renderAllPages)}else return N(!0);if(!this.opfView)return N(!0);let n=O("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=O("moveTo.showCurrent");s=o.result(),this.showCurrent(r.page,!this.renderAllPages).then(()=>{this.reportPosition().thenFinish(o)})}else s=N(!0);s.then(o=>{this.readyState==="loading"&&this.setReadyState("interactive"),n.finish(o)})}),n.result()}showTOC(e){let t=!!e.autohide,i=e.v,n=this.opfView.isTOCVisible(),r=t!=this.opfView.tocAutohide&&i!="hide";if(n){if(i=="show"&&!r)return N(!0)}else if(i=="hide")return N(!0);if(n&&i!="show")return this.opfView.hideTOC(),N(!0);{let s=O("showTOC");return this.opfView.showTOC(t).then(o=>{if(o){if(r&&(o.listeners={}),t){let a=()=>{this.opfView.hideTOC()};o.addEventListener("hyperlink",a,!1)}o.addEventListener("hyperlink",this.hyperlinkListener,!1)}s.finish(!0)}),s.result()}}runCommand(e){let t=e.a||"";return an("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):($.error("No such action:",t),i.finish(!0))},(i,n)=>{$.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=Lh(e),i=null,n=this;pg(()=>{let r=O("commandLoop"),s=uo().getScheduler();return n.hyperlinkListener=o=>{let a=o,l=a.href.charAt(0)==="#"||n.packageURL.some(h=>a.href.substr(0,h.length)==h);if(l){o.preventDefault();let h={t:"hyperlink",href:a.href,internal:l};s.run(()=>(n.callback(h),N(!0)))}},r.loopWithFrame(o=>{if(n.needResize)n.resize().then(()=>{o.continueLoop()});else if(n.needRefresh)n.currentPage&&n.showCurrent(n.currentPage,!this.renderAllPages).then(()=>{o.continueLoop()});else if(t){let a=t;t=null,n.runCommand(a).then(()=>{o.continueLoop()})}else{let a=O("waitForCommand");i=a.suspend(this),a.result().then(()=>{o.continueLoop()})}}).thenFinish(r),r.result()}),n.kick=()=>{let r=i;r&&(i=null,r.schedule(!0))},n.sendCommand=r=>t?!1:(t=Lh(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},ap=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(ap||{}),Fh=class lp extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,lp.prototype),this.stack=new Error().stack}};function Lh(e){return typeof e=="string"?ha(e):e}var Oh=la;function D0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Bh(e){let t={};return Object.keys(e).forEach(i=>{let n=e[i];switch(i){case"autoResize":t.autoresize=n;break;case"pageBorderWidth":t.pageBorder=n;break;default:t[i]=n}}),t}var hp=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),Dh(e.debug),this.adaptViewer_=new z0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=D0(),t&&this.setOptions(t),this.eventTarget=new ua,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Bh(e));this.adaptViewer_.sendCommand(t),Object.assign(this.options,e)}dispatcher(e){let t={type:e.t},i=e;Object.keys(i).forEach(n=>{n!=="t"&&(t[n]=i[n])}),this.eventTarget.dispatchEvent(t)}addListener(e,t){this.eventTarget.addEventListener(e,t,!1)}removeListener(e,t){this.eventTarget.removeEventListener(e,t,!1)}loadDocument(e,t,i){if(!e||(Array.isArray(e)?!e[0]||typeof e[0]!="string"&&!e[0].url:typeof e!="string"&&!e.url)){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(e,null,t,i)}loadPublication(e,t,i){if(!e){this.eventTarget.dispatchEvent({type:"error",content:{error:new Error("No URL specified")}});return}this.loadDocumentOrPublication(null,e,t,i)}loadDocumentOrPublication(e,t,i,n){let r=i||{};function s(h){if(h)return h.map(u=>({url:u.url||null,text:u.text||null}))}let o=s(r.authorStyleSheet),a=s(r.userStyleSheet);n&&Object.assign(this.options,n);let l=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:V0(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a},Bh(this.options));this.initialized?this.adaptViewer_.sendCommand(l):(this.initialized=!0,this.adaptViewer_.initEmbed(l))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===Oh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Oh.LTR?"next":"previous";default:return e}}navigateToPage(e,t){e==="epage"?this.adaptViewer_.sendCommand({a:"moveTo",epage:t}):this.adaptViewer_.sendCommand({a:"moveTo",where:this.resolveNavigation(e)})}navigateToInternalUrl(e){this.adaptViewer_.sendCommand({a:"moveTo",url:e})}navigateToPosition(e){var t,i;this.adaptViewer_.sendCommand({a:"moveTo",position:{spineIndex:e.spineIndex,pageIndex:(t=e.pageIndex)!=null?t:-1,offsetInItem:(i=e.offsetInItem)!=null?i:-1}})}isTOCVisible(){return this.adaptViewer_.opfView&&this.adaptViewer_.opfView.opf&&this.adaptViewer_.opfView.opf.toc?!!this.adaptViewer_.opfView.isTOCVisible():null}showTOC(e,t){let i=e==null?"toggle":e?"show":"hide";this.adaptViewer_.sendCommand({a:"toc",v:i,autohide:t})}queryZoomFactor(e){return this.adaptViewer_.queryZoomFactor(e)}getPageSizes(){return this.adaptViewer_.pageSizes}getTOC(){var e,t;return(t=(e=this.adaptViewer_.opfView)==null?void 0:e.tocView)==null?void 0:t.getTOC()}getMetadata(){return this.adaptViewer_.opf.getMetadata()}getCover(){return this.adaptViewer_.opf.cover}getCmykMap(){var e;let t=(e=this.adaptViewer_)==null?void 0:e.opfView;return t!=null&&t.cmykStore?t.cmykStore.toJSON():{}}};function V0(e){function t(n){return typeof n=="number"?n:null}function i(n){return typeof n=="string"?{url:n,startPage:null,skipPagesBefore:null}:{url:n.url,startPage:t(n.startPage),skipPagesBefore:t(n.skipPagesBefore)}}return Array.isArray(e)?e.map(i):e?[i(e)]:null}var up=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(up||{}),H0=ap,U0=op;pt.forceRegisterEndTiming("load_vivliostyle");var $0=class{constructor(e,{title:t="",printCallback:i=o=>o.print(),errorCallback:n=null,hideIframe:r=!0,removeIframe:s=!0}){c(this,"htmlDoc"),c(this,"title"),c(this,"printCallback"),c(this,"errorCallback"),c(this,"hideIframe"),c(this,"removeIframe"),c(this,"iframe"),c(this,"iframeWin"),c(this,"window"),this.htmlDoc=e,this.title=t,this.printCallback=i,this.errorCallback=n,this.hideIframe=r,this.removeIframe=s}init(){this.iframe=document.createElement("iframe"),this.hideIframe&&(this.iframe.style.width="0",this.iframe.style.height="0",this.iframe.style.borderWidth="0"),this.window=window,this.window.printInstance=this,this.iframe.srcdoc=`
|
|
1799
1800
|
<!DOCTYPE html>
|
|
1800
1801
|
<html data-vivliostyle-paginated="true">
|
|
1801
1802
|
<head>
|
|
@@ -1823,6 +1824,6 @@ span[data-viv-leader] {
|
|
|
1823
1824
|
<body onload='parent.printInstance.runInIframe(window)'>
|
|
1824
1825
|
<div id="vivliostyle-viewer-viewport"></div>
|
|
1825
1826
|
</body>
|
|
1826
|
-
</html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new
|
|
1827
|
-
`);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function
|
|
1827
|
+
</html>`,document.body.appendChild(this.iframe)}runInIframe(e){return this.iframeWin=e,this.preparePrint().then(()=>this.browserPrint()).then(()=>this.cleanUp())}preparePrint(){this.iframeWin.document.title=this.title;let e=new Blob([this.htmlDoc],{type:"text/html"}),t=URL.createObjectURL(e),i=new hp({viewportElement:this.iframeWin.document.body.firstElementChild,window:this.iframeWin,debug:!0});return new Promise(n=>{i.addListener("readystatechange",()=>{i.readyState==="complete"&&n()}),this.errorCallback&&i.addListener("error",r=>{var s,o;let a=(o=(s=r.content.error)==null?void 0:s.toString())!=null?o:r.content.messages.join(`
|
|
1828
|
+
`);this.errorCallback(a)}),i.loadDocument({url:t})})}browserPrint(){this.printCallback(this.iframeWin)}cleanUp(){delete this.window.printInstance,this.removeIframe&&this.iframe.parentElement.removeChild(this.iframe)}};function W0(e,t){new $0(e,t).init()}});var G0={};Cp(G0,{printHTML:()=>pp.printHTML});module.exports=Ep(G0);var pp=kp(dp());
|
|
1828
1829
|
//# sourceMappingURL=index.cjs.js.map
|